Zend Framework

Zend_Paginator factory chokes when Zend_Db_Select has UNION

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7.2
  • Fix Version/s: 1.8.4
  • Component/s: Zend_Paginator
  • Labels:
    None

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));

Activity

Hide
Thorsten Ruf added a comment -

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

Show
Thorsten Ruf added a comment - There is no assigned developer at the moment. Is this bug not critical?
Hide
Dolf Schimmel (Freeaqingme) added a comment -

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

Show
Dolf Schimmel (Freeaqingme) added a comment - Since April 3rd this issue has been assigned to Jurrien Stutterheim.
Hide
Jurrien Stutterheim added a comment -

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
Show
Jurrien Stutterheim added a comment - 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
Hide
Thorsten Ruf added a comment -

Here are the two use-cases:

simple UNION query
$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.

count with union statement
$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

Show
Thorsten Ruf added a comment - Here are the two use-cases:
simple UNION query
$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.
count with union statement
$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
Hide
Jurrien Stutterheim added a comment -

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

Show
Jurrien Stutterheim added a comment - Resolved in revision 16144 and merged to release-1.8 in revision 16145

People

Vote (3)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: