greenlion / PHP-SQL-Parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
BSD 3-Clause "New" or "Revised" License
601 stars 156 forks source link

Negative numbers prefixed with a space are not parsed correctly #341

Open ugwind opened 3 years ago

ugwind commented 3 years ago

I believe I have an issue similar to #24 , where the original issue was that statements such as SELECT * FROM table WHERE id IN(0,-1,-2,-3) caused the list of numbers to be parsed as 0,-,1,-,2,-,3 I think the problem is only partly fixed, and a statement such as SELECT * FROM table WHERE id IN(0, -1, -2, -3) (note the spaces) will still exhibit the same issue.

I have been able to address this locally by changing line 127 of PHPSQLLexar.php from

        if (substr($token, -1, 1) === "," || substr($token, -1, 1) === "(") {

to

        if (substr($token, -1, 1) === " " ||  substr($token, -1, 1) === "," || substr($token, -1, 1) === "(") {

but I am not familiar enough with the code to know if this is a viable fix.