ZF-11253: Db/Table/Abstract.php fetchRow discards any offset
Description
The fetchRow function discards the offset, such that
$select = $teams->select()
->where('colour = ?', 'orange')
->order('result')
->limit(1,10);
echo (string) $teams;
// SELECT `teams`.* FROM `teams` WHERE (colour = 'orange') ORDER BY `result` ASC LIMIT 1 OFFSET 10
$teams->fetchRow($teams);
// 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);
Comments
Posted by The Lone Coder (loconut) on 2011-04-01T21:57:32.000+0000
related tickets: http://framework.zend.com/issues/browse/ZF-8944 and http://framework.zend.com/issues/browse/ZF-10598
Posted by Kim Blomqvist (kblomqvist) on 2011-04-22T22:40:09.000+0000
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 ...
Of course to get this work, we have to add an $offset parameter into the {{fetchRow}} method ...
Posted by Kim Blomqvist (kblomqvist) on 2011-04-23T07:42:52.000+0000
Patch attached to support my suggested use case and fix the inconsistency pointed out here.
Posted by Ralph Schindler (ralph) on 2011-05-04T06:10:12.000+0000
Fixed in trunk at r23993 and in release branch 1.11 at r23994