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

Issue Type: Patch Created: 2011-04-01T21:56:25.000+0000 Last Updated: 2011-05-04T06:10:12.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: The Lone Coder (loconut) Assignee: Kim Blomqvist (kblomqvist) Tags: - Zend_Db_Table

Related issues: Attachments: - Abstract.php.patch


The fetchRow function discards the offset, such that

<pre class="highlight">
$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:

<pre class="highlight">
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);


Posted by The Lone Coder (loconut) on 2011-04-01T21:57:32.000+0000

related tickets: and

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 ...

<pre class="highlight">
$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 ...

<pre class="highlight">
public function fetchRow($where = null, $order = null, $offset = null)

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.