chenster / 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

Undefined offset error #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try an parse the following query:
2. UPDATE table1 SET field1='foo' WHERE field2='bar' AND id=(SELECT if FROM 
test1 t where t.field1=(SELECT id from test2 t2 where t2.field = 'foo'))                            

Granted, its my own typo ("if" should be "id" in the first subselect) but I 
dont think php-sql-parser should be throwing an undefined offset exception.

What is the expected output? What do you see instead?
Expected: Blank screen.
See instead: Notice: Undefined offset: 1 in /var/www/php-sql-parser.php on line 
1102

Can be fixed by changing line 1102 of php-sql-parser.php from:
 $sub_expr = $tokens[$key+1];
to:
 if(!empty($tokens[$key+1])) $sub_expr = $tokens[$key+1];

Original issue reported on code.google.com by erin....@gmail.com on 2 Jan 2011 at 2:50

GoogleCodeExporter commented 8 years ago
Thanks, I'll look into fixing this ASAP.

Original comment by greenlion@gmail.com on 4 Feb 2011 at 8:42

GoogleCodeExporter commented 8 years ago
IF is a function, and functions expect arguments.

Since this is a non-validating parser this doesn't matter, so I suppressed the 
warning as suggested.

Original comment by greenlion@gmail.com on 21 Mar 2011 at 7:42

GoogleCodeExporter commented 8 years ago

Original comment by greenlion@gmail.com on 30 Apr 2011 at 4:49