ZF-11253: Db/Table/Abstract.php fetchRow discards any offset


The fetchRow function discards the offset, such that

$select = $teams->select()
  ->where('colour = ?', 'orange')
echo (string) $teams;
// SELECT `teams`.* FROM `teams` WHERE (colour = 'orange') ORDER BY `result` ASC LIMIT 1 OFFSET 10
// SELECT `teams`.* FROM `teams` WHERE (colour = 'orange') ORDER BY `result` ASC LIMIT 1

This is an old issue that has been marked resolved but it wasn't and has been ignored despite attempts to reawaken both old tickets.

patch from 1.10.8, but fix is still applicable:

Index: Zend/Db/Table/Abstract.php
--- Zend/Db/Table/Abstract.php  (revision 1791)
+++ Zend/Db/Table/Abstract.php  (working copy)
@@ -1358,10 +1358,10 @@
                 $this->_order($select, $order);
-            $select->limit(1);
+            $select->limit(1, $select->getPart(Zend_Db_Select::LIMIT_OFFSET));
         } else {
-            $select = $where->limit(1);
+            $select = $where->limit(1, $select->getPart(Zend_Db_Select::LIMIT_OFFSET));
         $rows = $this->_fetch($select);


I don't see the problem here. You have specified the count and offset in {{limit(1,10)}}, so why not use {{$table->fetchAll($select)}} then? In my opinion, the key use case here is do we have to assemble the select object or could we quick fetch a row like this ...

$row = $table->fetchRow(array('colour = ?' => 'orange'), null, 10);

Of course to get this work, we have to add an $offset parameter into the {{fetchRow}} method ...

public function fetchRow($where = null, $order = null, $offset = null)

Patch attached to support my suggested use case and fix the inconsistency pointed out here.

Fixed in trunk at r23993 and in release branch 1.11 at r23994