<expression> expected, unexpected end of file

In PhpStorm 8.0.1, when I write this SQL command ($q is updated after with fields to update):
$q = "UPDATE games SET ";

I have this error "<expression> expected, unexpected end of file" in the right column, and I don't know how to ignore this message.

If I add just after:
$q .= "name='$name'";

I still have the error.

Note that, when I used PhpStorm 7, I didn't have this problem.

8 comments
Comment actions Permalink

Please check in the latest EAP version, I can not reproduce the issue there: http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program

0
Comment actions Permalink

Unfortunatelly, it is still there. I just made a test file in 8.0.2 with this code:

2014-12-01 12_15_52-www - [D__Dev_GNG_www] - ..._test.php - PhpStorm 8.0.2.png

I understand the utility of this feature (check SQL command), but in my case, I would love to be able to disable it.

Here the version I used for this test:
2014-12-01 12_21_57-.png

Thanks.

0
Comment actions Permalink

What's your SQL dialect?

0
Comment actions Permalink

Hi there,

That's because you are splitting your SQL into multiple assignment operations and IDE looses the context -- it sees first incomplete statement only (and the error is correct in such case). Try single assignment with concatenations or multi-line declaration -- works just fine:

$z = "UPDATE book SET " .
    "title='$name'";

or

$z = <<<SQL
UPDATE book SET
title='$name'
SQL;


If you want just basic syntax highlighting without checking against real DB / check for errors -- then change SQL Dialect to "Generic" at "Settings (Preferences on Mac)  | Languages & Frameworks | SQL Dialects"

0
Comment actions Permalink

Yes I understand, but my problem is when I try to build a SQL query programatically like:

$q = "INSERT INTO games (game_id,name) VALUES ";
for ($i=0; $i<count($games); $i++)
{
     if ($i > 0)
     {
          $q .= ',';
     }

     $game_id = $games[i]['id'];
     $name = $games[i]['name'];
     $q .= "($game_id,'$name')";
}

Also, I tried to set SQL dialect to generic, and there are no more errors. However, in this case, there is now a warning "SQL dialect not configured" for each query.

Nevertheless I can deal with this problem if there is no solution, but I like this feature where I can check quickly if there are errors or warnings.

Thanks.

0
Comment actions Permalink

I understand that ... but from SQL point of view this is just an incomplete statement.

So either disable extra SQL checks  (e.g. by switching to "Generic" dialect) or build query properly so that SQL inspections do not generate errors.


For example: use prepared statements (1) (2) (it will be even more secure):

$sql = "INSERT INTO games (game_id, name) VALUES (?, ?)";
$rs = $pdo->prepare($sql);
$rs->execute([$game_id, $name]);


----

Also, I tried to set SQL dialect to generic, and there are no more errors. However, in this case, there is now a warning "SQL dialect not configured" for each query.

Disable that inspection in "Settings | Inspections | SQL" (or Alt+Enter while having caret inside problematic place and choosing correct option -- each entry has submenu -- use "arrow right" key (or click on small triangle arrow) to expand it)

0
Comment actions Permalink

Thanks, it works :)! I have no more errors nor warnings!

Also you're right about prepared statements, I should definitelly use them, my code would be better. I'll modify my queries this way, and then, I'll be able to turn on again SQL syntax check.

Thanks again.

0

Please sign in to leave a comment.