Different SQL dialect in a query? (how to ignore error?)

I am using the Sphinx search engine and am using it's SQL dialect called SphinxSQL. I have queries like this:

 
$stmt = $sphinxDb->prepare('
SELECT * FROM my_index
WHERE MATCH(\'@name "' . sphinxapi_EscapeString($_POST['query']) . '"\')
');


Aside: I know I should be binding the query instead of injecting it, but that's another issue.

PhpStorm detects that the syntax is not valid MySQL and shows an error:

http://imagizer.imageshack.us/a/img913/1681/1ag9TA.png

The fact that there's an error in the file causes things like code reformatting not to work (ctrl+alt+l).

So I have two questions:

1. Is there a way, in general (not specifically for sql queries) to ignore an error on a line? (such as a way to place a marker there so the inspection engine just ignores it)

2. Is there a way to let PhpStorm know this query is a different SQL dialect?

Thanks.

0
7 comments

Hi there,

1. Is there a way, in general (not specifically for sql queries) to ignore an error on a line? (such as a way to place a marker there so the inspection engine just ignores it)

It depends on error.

If it's done by annotator/lexer (or whatever the proper term is) then no -- because it's low level

If it's separate inspection which you can turn off in Settings .. then quite possibly (depends on inspection and context). I'd say "yes" .. but not so sure for such cases like this where error is in injected fragment instead of top level PHP. I mean -- IDE allows to suppress warnings ... but
1) it adds it as a special comment  and I'm not sure if this works for SQL and
2) It does inserts such comment into actual injected fragment and not outside .. which may simply break your injected fragment / have side effects.

In any case: Alt+Enter while having caret on error place, choose correct entry from appeared menu and then arrow-right to see submenu (for example: just to give you an idea of menu)

screen01.png

2. Is there a way to let PhpStorm know this query is a different SQL dialect?


Do all queries in this file belong to another dialect or just one (few) out of few?

If all -- just change SQL Dialect for that file (to Generic) in "Settings | Languages &  Frameworks | SQL Dialects"

If only some of them -- in v8 only by using custom HEREDOCS (permanent) or by manually injecting different dialects (temp -- most likely will be forgotten by the end of session) -- https://devnet.jetbrains.com/message/5535921#5535921

In v9 it will be better (you can try EAP build even right now) -- you can specify what language to inject via PHPDoc comment (e.g. /** @lang text */ for plain text (no injection at all))

0

>> Do all queries in this file belong to another dialect or just one (few) out of few?

Only one or two queries in the file are SphinxQL, all of the others are MySQL (which is what the file dialect is set to).

>> In v9 it will be better (you can try EAP build even right now) -- you can specify what language to inject via PHPDoc comment (e.g. /** @lang text */ for plain text (no injection at all))

v9 looks great! I installed it and tried adding the phpdoc comment before the line, but the error still displays:

http://imagizer.imageshack.us/a/img673/4100/Phd3B5.png

Did I use the PHPDoc incorrectly?

Thanks again!

0

Accordignly to the screenshots by devs .. the comment should be just before the string, i.e. ->prepare(/** @lang text */ '....

Try that way (I have not tried this yet -- still using v8)

0

It works with an echo statement, but not with a prepared statement. So I guess I'll have to use one of the other methods you used in your post.

Thanks.

0

It should be supported: https://youtrack.jetbrains.com/issue/WI-26867

Worked for me just now (using PDO).

Maybe it's because you are doing concatenation..?

How does it look for you? For me text went green (standard color for ordinary text).

0

Okay, apparently it doesn't work when a string is injected (concatenated) into the it.

No worky:

Clipboard Image (31).png

Worky:

Clipboard Image (32).png
Due to a SphinxQL issue I currently can't bind the query as parameter and need to inject it as shown in the first image.

0

Well .. in such case I may only suggest to submit a ticket to the Issue Tracker with your details and code to reproduce (try it in brand new project with minimal code).

I've tried some very basic concatenation and it worked -- you case could be different though.

0

Please sign in to leave a comment.