ZF-10947: Zend_Paginator_Adapter_DbSelect->getCountSelect() - the count query produced by this method fails if the original Zend_Db_Select contains "order by" (and using Zend_Db_Adapter_Sqlsrv)

Description

Zend_Paginator_Adapter_DbSelect->getCountSelect() - the count query produced by this method fails if the original Zend_Db_Select contains "order by" (and using Zend_Db_Adapter_Sqlsrv).

The sql generated by the Zend_Db_Select object is ok:

$select = $db->select() ->from(array('icp' => 'icn_ptnt'), array('Surname', 'Firstname')) ->join(array('apm' => 'abx_patient_medications'), 'icp.Patient_No = apm.patient_id', array()) ->group(array('Surname', 'Firstname')) ->order(array('Surname'));

SELECT "icp"."Surname", "icp"."Firstname" FROM "icn_ptnt" AS "icp" INNER JOIN "abx_patient_medications" AS "apm" ON icp.Patient_No = apm.patient_id GROUP BY "Surname", "Firstname" ORDER BY "Surname" ASC

However, an error is encoutered once this is passed to Zend_Paginator

$view->paginator = Zend_Paginator::factory($select); $view->paginator->setCurrentPageNumber((isset($_GET['page'])) ? $_GET['page'] : 1); $view->paginator->setItemCountPerPage(100);

SELECT COUNT(1) AS "zend_paginator_row_count" FROM (SELECT "icp"."Surname", "icp"."Firstname" FROM "icn_ptnt" AS "icp" INNER JOIN "abx_patient_medications" AS "apm" ON icp.Patient_No = apm.patient_id GROUP BY "Surname", "Firstname" ORDER BY "Surname" ASC) AS "t"

Msg 1033, Level 15, State 1, Line 3 The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

Comments

Fixed in trunk r23724 merged to branch release 1.11 r23725.