Open Jarkaruus opened 2 years ago
Could you provide your Combine object so one can actually reproduce your error?
Of course, here it is:
$select1 = new \Laminas\Db\Sql\Select('articoli');
$select1->where->equalTo('id_articolo', 1);
$select2 = new \Laminas\Db\Sql\Select('articoli');
$select2->where->equalTo('id_articolo', 2);
$select3 = new \Laminas\Db\Sql\Select('articoli');
$select3->where->equalTo('id_articolo', 3);
$combine = new \Laminas\Db\Sql\Combine();
$combine->combine([$select1, $select2, $select3]);
$select = new \Laminas\Db\Sql\Select();
$select->from(['i' => $combine->getSqlString()]);
Below the results
SELECT i
. FROM `(SELECT articoli
. FROM articoli
WHERE id_articolo
= '1') UNION (SELECT articoli
. FROM articoli
WHERE id_articolo
= '2') UNION (SELECT articoli
. FROM articoli
WHERE id_articolo
= '3')AS
i`
Instead I expect something like:
SELECT i
. FROM ( (SELECT articoli
. FROM articoli
WHERE id_articolo
= '1') UNION (SELECT articoli
. FROM articoli
WHERE id_articolo
= '2') UNION (SELECT articoli
. FROM articoli
WHERE id_articolo
= '3') ) AS i
Just realised I've never noticed your answer, I'm sorry.
I am not sure what you want to achieve with this specific way of using unions but I think what you want to do is this:
$select1 = new Select('articoli');
$select1->where->equalTo('id_articolo', 1);
$select2 = new Select('articoli');
$select2->where->equalTo('id_articolo', 2);
$select2->combine($select1);
$select3 = new Select('articoli');
$select3->where->equalTo('id_articolo', 3);
$select3->combine($select2);
$select = new Select();
$select->from(['i' => $select3]);
Given your use case I think the following would make more sense, though:
$select = new Select('articoli');
$select->where
->isEqualTo('id_articolo', 1)
->or
->isEqualTo('id_articolo', 2)
->or
->isEqualTo('id_articolo', 3);
Bug Report
Summary
Writing the code below I obtain this error. If I create a workaround to class Combine, I obtain a wrong query like
SELECT * FROM "( (SELECT * FROM table1) UNION (SELECT * FROM table12 UNION (SELECT * FROM table3) ) "AS i
Current behavior
'PHP message: PHP Recoverable fatal error: Object of class Laminas\\Db\\Sql\\Combine could not be converted to string laminas/laminas-db/src/Adapter/Platform/AbstractPlatform.php
on line 75'How to reproduce
Expected behavior
I expect a query like SELECT FROM ( (SELECT FROM table1) UNION (SELECT FROM table12 UNION (SELECT FROM table3) ) AS i