Issues

ZF-5956: Zend_Paginator factory chokes when Zend_Db_Select has UNION

Issue Type: Bug Created: 2009-03-06T09:42:38.000+0000 Last Updated: 2009-06-18T17:24:03.000+0000 Status: Resolved Fix version(s): - 1.8.4 (23/Jun/09)

Reporter: Panupan Sriautharawong (lionpeal) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Paginator

Related issues: Attachments:

Description

Lets say $select1 and $select2 are Zend_Db_Selects that give identical fields.

Then we do $select1 UNION $select2: $select = $db->select()->union(array($select1, $select2));

If we do: print_r($this->_db->fetchAll($select));

It will return arrays of the expected union of $select1 and $select2

But when we try to make our paginator: $paginator = Zend_Paginator::factory($select);

We get a crash: exception 'Zend_Db_Select_Exception' with message 'No table has been specified for the FROM clause'

The expected result is no crash.

The workaround (inefficient) right now is just to give the factory the whole array: Zend_Paginator::factory($this->_db->fetchAll($select));

Comments

Posted by Thorsten Ruf (saphir2k) on 2009-05-26T05:30:32.000+0000

There is no assigned developer at the moment. Is this bug not critical?

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-05-26T05:37:32.000+0000

Since April 3rd this issue has been assigned to Jurrien Stutterheim.

Posted by Jurrien Stutterheim (norm2782) on 2009-05-26T14:33:25.000+0000

Could you give me a simple use-case including:

  • A simple UNION query
  • A COUNT query, based on that UNION query.

This will help me greatly in formulating a patch.

Cheers,

  • JurriĆ«n

Posted by Thorsten Ruf (saphir2k) on 2009-05-27T00:34:00.000+0000

Here are the two use-cases:

<pre class="highlight">
$select1->from('user',array('firstname','lastname'));
$select1->where('id = ?',1);
        
$select2 = $this->db->select();
$select2->from('user',array('firstname','lastname'));
$select2->where('id = ?',2);
        
$selectUnion = $this->db->select();    
$selectUnion->union(array($select1,$select2));

Its hard to create a fast count with a union statement, i'm pretty sure this one is the slowest. Hopefully a database expert is watching this issue. ;-)

<pre class="highlight">
$select1->from('user',array('firstname','lastname'));
$select1->where('id = ?',1);
        
$select2 = $this->db->select();
$select2->from('user',array('firstname','lastname'));
$select2->where('id = ?',2);
        
$selectUnion = $this->db->select();    
$selectUnion->union(array($select1,$select2));

// Wrap a SELECT count(*) statement around the union 
$selectCount = $this->db->select();     
$selectCount->from($selectUnion,'count(*)');

Regards, Thorsten

Posted by Jurrien Stutterheim (norm2782) on 2009-06-18T17:24:02.000+0000

Resolved in revision 16144 and merged to release-1.8 in revision 16145

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