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

TRUNCATE in SELECT ends up in its own category #338

Open Herz3h opened 3 years ago

Herz3h commented 3 years ago

Consider this query:

SELECT id, date, type as type, libelle as libelle, TRUNCATE(debit, 2) as debit, TRUNCATE(credit, 2) as credit, ROUND(COALESCE(credit, 0) - COALESCE(debit, 0), 2) as solde FROM compte_cp

Is it intended that the truncate/round end up in their own category ? :

Capture d’écran 2021-05-19 à 15 37 12

I'm editing the where part using the parser, and this makes it problematic because after I make changes to the parsed Array (the one in the picture) and use the Creator, it doesn't include the TRUNCATE part anymore. Instead the creator generates the following:

SELECT id, date, type as type, libelle as libelle, FROM compte_cp

Notice the last comma before FROM.

Either way thank you for this amazing tool !

Edit: I completely forgot that you can write TRUNCATE as the first Keyword of the query (Like SELECT, UPDATE, etc), but also as a function (which is what I do in this case). That seems to be the issue. Not sure if it could be fixed.