Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoogleCodeExporter opened this issue Mar 23, 2016 · 6 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Thanks for the report - I'll review and incorporate your changes.

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant