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

1. please turn off debug print_r() 2. probbaly, some bug in parser triggers it #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
WHAT STEPS WILL REPRODUCE THE PROBLEM?

1. $sql = "SELECT SQL_CALC_FOUND_ROWS SmTable.*, MATCH 
(SmTable.fulltextsearch_keyword) AGAINST ('google googles') AS keyword_score 
FROM SmTable WHERE SmTable.status = 'A' AND (SmTable.country_id = 1 AND 
SmTable.state_id = 10) AND MATCH (SmTable.fulltextsearch_keyword) AGAINST 
('google googles') ORDER BY SmTable.level DESC, keyword_score DESC LIMIT 0,10"

2. $parser = new PHPSQLParser($sql);

WHAT IS THE EXPECTED OUTPUT? WHAT DO YOU SEE INSTEAD?

No output expected.

Instead, it hits line 1242 and prints smth:
if(!is_array($processed)) {
    print_r($processed);   // 1242
    $processed = false;
}

What version of the product are you using? On what operating system?
http://php-sql-parser.googlecode.com/svn/trunk/php-sql-parser.php

uname -a
Linux ********* #1 SMP Tue Sep 1 10:25:30 EDT 2009 x86_64 GNU/Linux

Original issue reported on code.google.com by rel...@gmail.com on 19 Jun 2011 at 1:31

GoogleCodeExporter commented 9 years ago
Looks like the parser expects every expression tree to be an array, but the 
code for parsing an "AGAINST" clause will return a single value rather than an 
array if the contents are a single value (on line 1112):

$processed = $list[0];

Changing this to return an array will fix the glitch for your particular code 
sample:

$processed = array($list[0]);

Regarding the print_r: It looks like the author put the print_r in there 
because that is an exceptional case that should normally never occur and 
signals a parsing bug.  But since you have the source code you can just comment 
it out :-)

It looks like there's another debug statement that occurs on lines 165-169 if 
the argument to parse is not a string:

if(!is_string($sql)) {
    echo "SQL:\n";
    print_r($sql);
    exit;
}

Original comment by kbacht...@gmail.com on 20 Oct 2011 at 5:16

GoogleCodeExporter commented 9 years ago
I think, I have solved the parsing problem described by this issue.
Check out the bleeding edge on 
https://www.phosco.info/publicsvn/php-sql-parser/trunk/

Original comment by pho...@gmx.de on 17 Feb 2012 at 1:09

GoogleCodeExporter commented 9 years ago
Accepted fixed codebase.

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