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

UNION ALL is not supported #88

Closed Zheness closed 9 months ago

Zheness commented 9 months ago

Hello,

When trying a query with UNION ALL like SELECT a FROM users UNION ALL SELECT a FROM users it doesn't work with magic query.

If we look at the file StatementFactory.php, we see that only UNION is supported.

Is there any reason why it was not implemented?

Thanks !

homersimpsons commented 9 months ago

Is there any reason why it was not implemented?

I do not think there is any, are you willing to submit a patch for this?

I may have time to look into it later though.

Zheness commented 9 months ago

Hi, I can try to submit a PR today.

How would you like me to do it ?

There is only one line to edit in the file, but I don't know how you prefer the code to be maintained. Thanks !

homersimpsons commented 9 months ago

I think it makes sense to have a boolean. Because we can have either UNION DISTINCT which is like UNION or UNION ALL.

Looking at SELECT we have a boolean for this: https://github.com/thecodingmachine/magic-query/blob/5107ebf5c944e62692182feab3359f1cc1fc3423/src/SQLParser/Query/Select.php#L58

So let's do the same with UNION ALL:

A simple boolean argument in the Union constructor?

Don't forget to add tests too.

homersimpsons commented 9 months ago

(published in v1.5.2)