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

Parser fails when it finds a newline after SELECT statement #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If I try :

$parser = new PHPSQLParser('SELECT
name, 1, test;');

PHP is giving me error (see method process_select_expr):
- Warning: E_WARNING array_pop() expects parameter 1 to be array, string given
- Fatal error: Cannot use string offset as an array 

A newline after between SELECT and field list makes the parser to fail.

Original issue reported on code.google.com by johnny.c...@gmail.com on 14 Dec 2010 at 4:06

GoogleCodeExporter commented 9 years ago
I've done a temporary patch into my code.

$sql = 'SELECT
name, 1, test;'

$parser = new PHPSQLParser($sql); // Fail

$sql    = preg_replace('/^(SELECT)(\s)(\s+)/si', '$1 ', $sql);
$parser = new PHPSQLParser($sql); // Success

Original comment by johnny.c...@gmail.com on 14 Dec 2010 at 4:37

GoogleCodeExporter commented 9 years ago
i did it in "split_sql($sql)"

change 
$sql = str_replace(array('\\\'','\\"'),array("''",'""'), $sql)

to
$sql = str_replace(array("\n","\r",'\\\'','\\"'),array(' ',' ',"''",'""'), 
$sql);

Original comment by patrik.p...@gmail.com on 17 Jan 2011 at 8:08

GoogleCodeExporter commented 9 years ago
here is a diff which 

* makes the reserved and functions array static (results in faster parsing)
* newlines are being replaced with ' ' before parse;
* the sql syntax regarding fulltext i.e. 'match mycol against ('+*foobar*' IN 
BOOLEAN MODE)' is handled better (at least for my needs)

regards 
  Patrik

Original comment by patrik.p...@gmail.com on 17 Jan 2011 at 9:58

Attachments:

GoogleCodeExporter commented 9 years ago
Thank, I will patch my own version and try it.

Original comment by johnny.c...@gmail.com on 17 Jan 2011 at 11:58

GoogleCodeExporter commented 9 years ago
Thanks for the report - I'll review and incorporate your changes.

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

GoogleCodeExporter commented 9 years ago
Thanks again for your contribution.

I incorporated your match/against improvement.  I had already made a newline 
fix.

I have not yet switched to static arrays.  

I updated the t/select.php test.

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