php sprintf with SQL query and SQL dialect enabled throws error "expression expected"

Hi folks,
in a new projected a work on for some weeks I now face a problem since updated to PhpStorm6 (also PhpStorm5):

If I write something like:

sprintf(
     'UPDATE a_table SET %s WHERE id = %u',
     "a_column = 'somevalue'",
     12345
);



I get an "<expression> expected, found '%'" error.

Yes I know that is bad coding but it's not possible to change that in the near future (because the project exists for several years and has many code like that from the previous developers).

Has someone an idea how I can use sql dialect there without getting those errors?

best regards,
christopher
3 comments
Comment actions Permalink

Hi Christopher,

http://youtrack.jetbrains.com/issue/WI-16544  --> http://youtrack.jetbrains.com/issue/WI-3672

You may use "Keywords only" SQL Dialect -- it will not perform any validation, only basic syntax highlighting.

0
Comment actions Permalink

Hi,
thanks for your answer.

That is the setting I use atm but I would like to have the syntax validation and the possibility to define that '%s' is a valid expression or so.

I that or anything similar possible with specific settings?

best regards,
christopher

0
Comment actions Permalink

Currently there is no such extra option available (the actual WI-3672 ticket is just about that).

When you choose any "real" SQL Dialect, IDE will perform validation .. and "UPDATE a_table SET %s WHERE id = %u" is NOT a valid SQL command in any dialect.


Possible suggestion:

  • Use "Keywords only" for your project
  • Create some separate *.sql file and assign proper sql dialect for that file via "Settings | SQL Dialects"


This will allow you to create new/edit existing SQL commands (copy-paste) with full validation in that file .. while still having syntax highligting (and no errors) in other places where sprintf() or alike are used. In other words: you need to edit -- copy SQL code into that *.sql file; finished editing -- copy SQL codeback into PHP file.

0

Please sign in to leave a comment.