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

Wrong parenthesis order with CASE #73

Closed Zheness closed 4 years ago

Zheness commented 4 years ago

Hello,

There a is a wrong order of parenthesis when a use a "CASE" followed with an alias.

Here is my initial mySQL query:

SELECT bar.foo, (CASE WHEN bar.foz = 1 THEN "ok" WHEN bar.hello = "world" THEN 2 ELSE 42 END) as status FROM bar

The MagicQuery change the parenthesis order after the alias, making the query wrong.

Here is the result after build:

SELECT `bar`.`foo`, ( CASE WHEN `bar`.`foz` = 1 THEN "ok" WHEN `bar`.`hello` = "world" THEN 2 ELSE 42 END AS status) FROM `bar`

Let me know if you have questions.

moufmouf commented 4 years ago

This is already fixed in 1.4 (the issue is present in 1.3.0 only)