Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Problems in the way Zend\Paginator\Adapter\DbSelect count()s #3647

@twmobius

Description

@twmobius

Currenty on Zend\Paginator\Adapter\DbSelect the count() method resets some parts of the Zend\Db\Sql\Select object and leaves others:

$select->reset(Select::COLUMNS);
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);

On ZF1 the same was:

$rowCount->reset(Zend_Db_Select::COLUMNS)
               ->reset(Zend_Db_Select::ORDER)
               ->reset(Zend_Db_Select::LIMIT_OFFSET)
               ->reset(Zend_Db_Select::GROUP)
               ->reset(Zend_Db_Select::DISTINCT)
               ->reset(Zend_Db_Select::HAVING)

I can understand that not resetting the ORDER doesn't make any difference, but the GROUP makes a huge difference if there is a GROUP BY expression in the Select statement.

Imagine the following query:

SELECT id, MIN(date_added) FROM Table GROUP BY id

count() would have it

SELECT COUNT(1) as c FROM Table GROUP BY id;

thus returning the number of rows per id in the Table (at least in mySQL. Might complain in others)

Similar problem would occur by not resetting HAVING as well.

Finally on a side note $select->reset(Select::COLUMNS); does not reset the columns that are a result from join(). Is this expected?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions