ZF-10884: Zend_Paginator - Row count column not found

Description

When using custom $rowCount as shown on example in manual:


$row_count->from(
  array('table_name'),
  array(
    Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => new Zend_Db_Expr('COUNT(DISTINCT id)')
  )
);

it throws 'Row count column not found' exception, because there is wrong checking for ROW_COUNT_COLUMN when using 'AS_field' => 'db_expr'. Current assigment:


$columns = $rowCount->getPart(Zend_Db_Select::COLUMNS);
$countColumnPart = $columns[0][1];

is not aware of 'AS' part, which is stored in $columns[0][2], and throws exception.

Possible solution is to check whether $columns[0][2] field is present or not, and use it as $countColumnPart when it's present.

Comments

My patch for that problem:

Index: library/Zend/Paginator/Adapter/DbSelect.php
===================================================================
--- library/Zend/Paginator/Adapter/DbSelect.php (revision 23595)
+++ library/Zend/Paginator/Adapter/DbSelect.php (working copy)
@@ -100,7 +100,7 @@
         if ($rowCount instanceof Zend_Db_Select) {
             $columns = $rowCount->getPart(Zend_Db_Select::COLUMNS);
 
-            $countColumnPart = $columns[0][1];
+            $countColumnPart = empty($columns[0][2]) ? $columns[0][1] : $columns[0][2];
 
             if ($countColumnPart instanceof Zend_Db_Expr) {
                 $countColumnPart = $countColumnPart->__toString();

Fixed in trunk r23658 merged to release branch 1.11 r23659 - thanks.