dongwei1895 2017-07-21 10:15
浏览 221
已采纳

为SQL参数提供占位符值

The Problem:

I am using a framework which at many points provides queries just like this one:

$sql = "select $sArticleTable.* from table_A left join " .
       "$sArticleTable on table_A.objectid=$sArticleTable.id " .
       "where table_A.articlenid = $sArticleId " .
       "and $sArticleTable.id is not null and " . $object->someMoreSQL() .
       "order by table_A.sort";

As you can see, one table name gets inserted via the $sArticleTable variable. Even though I highly detest this way of writing up an MySQL statement, there is nothing right now I can do about it.

This way of writing up the statement prevents PhpStorm from recognizing the table name correctly, so no autocomplete suggestions are being shown.

How can I give PhpStorm a placeholder value for the variable $sArticleTable so that it will in turn again provide autocomplete suggestions?

I have tried Database -> User Parameters in the settings, but I do not get prompted to enter a placeholder value.

I also know that I could simply replace the variable with the correct table name, adjust the SQL and then re-enter the variable. But this seems rather unprofessional, given that I think PhpStorm might provide the solution here.

Furthermore, since I am already adjusting the SQL, I could very well rewrite the statement in a more fitting way. Which, with a relatively small statement such as this, I might end up doing. There are however much larger statements that would eat up way to much time to rewrite.

  • 写回答

1条回答 默认 最新

  • doupengxie4195 2017-07-21 10:54
    关注

    ATM there is no way of doing that. I could be wrong here ... but it might only be supported for Joomla in latest 2017.2 version (considering their specific syntax) .. but no other generic way (it applies to both table name or table name prefix).

    Here are some related tickets on this subject -- watch them (star/vote/comment) to get notified on any progress:


    P.S. If you do not like SQL errors like these (the fact that IDE shows them) then you can tell IDE to treat this string as plain text (so no SQL colors/errors) -- place /** @lang Text */ just before the string opening quotes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真