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
607 stars 156 forks source link

JOIN surrounded by brackets in the latter part of a UNION #305

Closed leochab closed 5 years ago

leochab commented 5 years ago

Trying to parse the following query (simplified on purpose):

SELECT
    'John' as first_name,
    'Doe' as last_name,
    'M' as gender 
FROM
    dual
UNION
SELECT
    first_name,
    last_name,
    a.gender 
FROM
    users
JOIN ( SELECT * FROM user_infos WHERE gender = 'M' ) a ON a.user_id = users.user_id

crashes since we upgraded the version 4.2.0 of PHP-SQL-Parser. It was not the case in former versions.

It seems that the function splitUnionRemainder in UnionProcessor introduced a regression, only when there is a JOIN with parenthesis in the last part of a UNION.

leochab commented 5 years ago

This issue has been resolved by the following PR : https://github.com/greenlion/PHP-SQL-Parser/pull/272

I'll update the library and close this issue.