thecodingmachine / magic-query

A very clever library to use SQL prepared statement with a variable number of parameters... and much more!
http://mouf-php.com/packages/mouf/magic-query/README.md
22 stars 14 forks source link

TIMESTAMPDIFF function issue #83

Open NikitaKharkov opened 3 years ago

NikitaKharkov commented 3 years ago

So the problem is pretty simple:

The original:

TIMESTAMPDIFF(SECOND, uc_call.created_at, uc_call.ended_at) - uc_call.duration as waiting

The result:

TIMESTAMPDIFF(`SECOND`, `uc_call`.`created_at`, `uc_call`.`ended_at`) - `uc_call`.`duration` AS waiting

So, it makes the first argument as a ColRef, but should as... I even don't know :) Because I didn't find any class which can be matched with the date/time reserved words.

homersimpsons commented 3 years ago

Hello @NikitaKharkov, thank you for your report.

The parser is in fact returning this as a ColRef (instead of a Reserved). You can avoid the issue using the SQL_TSI_* constants as such:

TIMESTAMPDIFF(SQL_TSI_SECOND, uc_call.created_at, uc_call.ended_at) - uc_call.duration as waiting
homersimpsons commented 3 years ago

After a bit of digging this issue comes from https://github.com/greenlion/PHP-SQL-Parser and it seems that it has already been reported: https://github.com/greenlion/PHP-SQL-Parser/issues/212.