Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm - Disable SQL inspection for one line

I am using the ZendDb database adapter which doesn't bring all the tweaks SQL can do. For example if I want to do a REPLACE INTO I would have to code it like this:

$SQL = sprintf('REPLACE INTO %s (id, NAME, cache_id, compile_id, content) VALUES  (%s, %s, %s, %s, %s)' %
        array(self::TABLE_NAME, $id, $name, $cache_id, $compile_id));
$this->_zdb->query($SQL);

The problem is that PhpStorm tells me that the %s is an error inside the SQL.

When I try hotfixing it with Alt + Enter I don't get the option to suppress the inspection for this line.

I' need something like this:

/** @noinspection SqlInspection */

I googled and found this page but nothing of the options seemed to help.

Any ideas?

like image 716
Ron Avatar asked Jan 08 '18 09:01

Ron


1 Answers

Add \%\w+ pattern to Settings/Preferences | Tools | Database | User Parameters -- it will tell IDE to treat such %s as dynamic/external part of the code instead of actual SQL.

For example:

enter image description here

P.S. One day such pattern will be provided by default in PhpStorm.

https://youtrack.jetbrains.com/issue/WI-39271 -- watch this ticket (star/vote/comment) to get notified on any progress.


If you need an actual suppression .. then the most effective way is to treat the string as Plain Text instead of autodetected SQL.

For this, just place /** @lang text*/ just before the string, e.g.

$sql = /** @lang text*/'REPLACE INTO %s (id, NAME, cache_id, compile_id, content) VALUES (%s, %s, %s, %s, %s)';

enter image description here

NOTE: may not work if you are concatenating such string or perform other manipulations in place.

like image 66
LazyOne Avatar answered Nov 15 '22 07:11

LazyOne