PHPStorm: How to disable this SQL inspection error & how to embed SQL
I use string concatenation to construct SQL statements in PHPStorm.
PS seems to give inspection errors always on the last space before the double quote (see attached files), this is despite me having turned off SQL inspection.
1) How do I turn off this Inspection error?
2) It looks as if PS is expecting SQL to be embedded in some other way so Inspection could run properly. How am I meant to embed SQL statement with PS?
thanks
Johnathan
Attachment(s):
Screen Shot 2015-01-13 at 11.39.18 am.png
Screen Shot 2015-01-13 at 11.35.51 am.png
Please sign in to leave a comment.
Hi there,
What is your IDE version (exactly, including build number) ?
This is SQL parser/lexer and not inspection. Inspections only run on top of valid code .. and you do not have a valid SQL here -- it's incomplete (due to concatenation done in PHP).
But you can turn it off leaving basic syntax highlighting only by using "Generic" as SQL dialect instead of specific dialect (MySQL, SQL Server etc) in "Settings | Languages & Frameworks | SQL Dialects"
Generally speaking: try to write complete SQL statements and not assemble them from parts this way.
In any case: 8.0.2 should handle such situations -- does for me -- I see no warnings in my simple test code (see below). Would be great if you could provide some simple code to reproduce it (test it first in brand new empty project).
Thanks Andriy. Changing to Generic solved it.
We're using PS 8.0.2 build 139.732
But once switched to MySQL Dialect, even simple SQL statements will cause issues...
Check screenshot & sample project.
Oddly enough, a line like this is fine - taking out the trailing space from the SQL statement
$sql_external = 'SELECT FROM' . ' ' .CONSTANT_EXTERNAL;
Attachment(s):
PHPStorm_SQLTest.zip
Screen Shot 2015-01-14 at 1.20.10 am.png
That's because the injection rule for SQL (Settings | Editor | Language Injections) requires a space after "FROM" otherwise it may also treat string like ("SELECT FROMAGE", for example) as an SQL fragment as well.
But.. "SELECT FROM" is not valid -- should it not be "SELECT %FIELD_NAMES_HERE% FROM", (e.g. "SELECT * FROM") ??
Now it works: