Issues

ZF-7592: Union syntax error

Issue Type: Bug Created: 2009-08-14T02:31:09.000+0000 Last Updated: 2010-02-02T15:32:03.000+0000 Status: Resolved Fix version(s): Reporter: Alexandr Kovalenko (sander) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

Related issues: - ZF-4338

Attachments:

Description

File: Zend/Db/Select.php Line: 1088

// wrong $sql .= $target;

// right $sql .= '('; $sql .= $target; $sql .= ')';

<pre class="highlight">
$select = $db->select()->union(array($select1, $select2))->order('field1ASC')->limit(3);
// expected (SELECT table1.id FROM table1  WHERE foo = 'bar') UNION (SELECT table2.id FROM table2 WHERE foo = 'bar') ORDER BY field1 ASC LIMIT 3 
// receive SELECT table1.id FROM table1  WHERE foo = 'bar' UNION SELECT table2.id FROM table2 WHERE foo = 'bar' ORDER BY field1 ASC LIMIT 3 

To fixed it i must do next:

<pre class="highlight">
$select->union(array('(' . $select1 . ')', '(' . $select2 . ')'))->order('field1ASC')->limit(3);

it is wrong

Comments

Posted by Alexandr Kovalenko (sander) on 2009-08-14T02:51:46.000+0000

also you may change this 2 line: from $parts = count($this->_parts[self::UNION]); to $parts = count($this->_parts[self::UNION]) - 1; and from $cnt < $parts - 1 to $cnt < $parts

Posted by Denis Baklikov (denis.baklikov) on 2009-08-18T08:52:31.000+0000

Which database are you using? MySQL or PostgreSQL? I have just checked this syntax (without bracket sign) in Oracle and it works OK.

Posted by Alexandr Kovalenko (sander) on 2009-08-18T10:53:20.000+0000

MySQL

SELECT * FROM test WHERE test_status = 4 ORDER BY r_id DESC UNION SELECT * FROM test WHERE test_status = 3 ORDER BY r_id ASC

#

Error Code : 1221 Incorrect usage of UNION and ORDER BY

#

(SELECT * FROM test WHERE test_status = 4 ORDER BY r_id DESC) UNION (SELECT * FROM test WHERE test_status = 3 ORDER BY r_id ASC)

#

OK

#

Posted by Jordan Ryan Moore (jordanryanmoore) on 2009-10-23T09:06:58.000+0000

This is a duplicate of ZF-4338.

Posted by Mario Ferreira (ztrange) on 2010-02-02T15:25:17.000+0000

Hello... Is this not a critical bug? No one is assigned to it.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-02-02T15:32:03.000+0000

Someone is assigned to it. However, because this issue has already been reported before, this issue was closed (hence the term 'duplicate'). Please also see ZF-4338 .

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts