rickywu-posh / php-sql-parser

Automatically exported from code.google.com/p/php-sql-parser
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Parsing issue on INSERT query (missing space between "VALUES" and opening parenthesis #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Well, this query is well parsed :

$parser = new PHPSQLParser();
$query  = "INSERT INTO test (test2,test3) VALUES ('10','coucou')";
$result = $parser->parse($query);

But for this one :

$parser = new PHPSQLParser();
$query  = "INSERT INTO test (test2,test3) VALUES('10','coucou')";
$result = $parser->parse($query);

There is no data "RESULT" into the array. The part "('10','coucou')" is not 
parsed so I cannot know which values were affected to columns of table test.

That's just because there is not a space between "VALUES" and "(".

Original issue reported on code.google.com by johnny.c...@gmail.com on 9 May 2011 at 1:57

GoogleCodeExporter commented 8 years ago
Hmm, I've written : There is no data "RESULT" into the array.
It should be corrected to : There is no data "RESULT" or "VALUES" into the 
array.

Original comment by johnny.c...@gmail.com on 9 May 2011 at 2:04

GoogleCodeExporter commented 8 years ago
Thanks for the report.  I'll look into this ASAP.

Original comment by greenlion@gmail.com on 9 May 2011 at 6:38

GoogleCodeExporter commented 8 years ago
Here is a simple fix.  Move case 'VALUES' into its own category, and check if 
the next token is blank before consuming two tokens:

[code]
case 'VALUES':
    $token_category = $upper;
    if($tokens[$token_number+1]=="")
        continue 2;
    else
        continue;
break;
[/code]

Original comment by kbacht...@gmail.com on 20 Oct 2011 at 3:24

GoogleCodeExporter commented 8 years ago
Just in case this isn't clear how to fix.  Around line 334 in the source code, 
you see a list of case statements like this:

case 'SELECT':
case 'ORDER':
case 'LIMIT:
...

find the "case 'VALUES'" and remove it, and make a new section between the 
following "break;" statement and the next new "case" statement (as in case 
'DELETE')).  That new section should contain the code pasted in my previous 
comment.

Hope this helps!

Original comment by kbacht...@gmail.com on 20 Oct 2011 at 3:44

GoogleCodeExporter commented 8 years ago
Solved in current version on http://www.phosco.info/php-sql-parser_current.zip

Original comment by pho...@gmx.de on 2 Feb 2012 at 8:24

GoogleCodeExporter commented 8 years ago
pho...@gmx.de, this also doesn't appear to have been implemented in the link 
provided above.

Original comment by ben.swin...@gmail.com on 5 Mar 2012 at 10:39

GoogleCodeExporter commented 8 years ago
I have added a test for the this issue (see file insert.php in directory "t"). 
The test is okay, so it seems, that the solution works.

Try the repository on https://www.phosco.info/publicsvn/php-sql-parser
I have no commit rights on the original codebase, so I provide the changes on 
my own Subversion.

Original comment by pho...@gmx.de on 5 Mar 2012 at 12:10

GoogleCodeExporter commented 8 years ago
I confirm that code provided by "pho...@gmx.de" fixed my issue.

Original comment by johnny.c...@gmail.com on 7 Mar 2012 at 2:40

GoogleCodeExporter commented 8 years ago
I confirm that code provided by "pho...@gmx.de" fixed my issue, at least for 
long text. About blob, I didn't test it yet.

Original comment by johnny.c...@gmail.com on 7 Mar 2012 at 2:42

GoogleCodeExporter commented 8 years ago
I have accepted the contribution which fixes this bug.

Original comment by greenlion@gmail.com on 12 Mar 2012 at 9:49