Просмотр исходного кода

ZF-11253
Fixed Zend_Db_Table::fetchRow to utilize offset when provided


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23993 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 14 лет назад
Родитель
Сommit
5fc77ec1df
2 измененных файлов с 42 добавлено и 3 удалено
  1. 4 3
      library/Zend/Db/Table/Abstract.php
  2. 38 0
      tests/Zend/Db/Table/TestCommon.php

+ 4 - 3
library/Zend/Db/Table/Abstract.php

@@ -1363,10 +1363,11 @@ abstract class Zend_Db_Table_Abstract
      *
      * @param string|array|Zend_Db_Table_Select $where  OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
      * @param string|array                      $order  OPTIONAL An SQL ORDER clause.
+     * @param int                               $offset OPTIONAL An SQL OFFSET value.
      * @return Zend_Db_Table_Row_Abstract|null The row results per the
      *     Zend_Db_Adapter fetch mode, or null if no row found.
      */
-    public function fetchRow($where = null, $order = null)
+    public function fetchRow($where = null, $order = null, $offset = null)
     {
         if (!($where instanceof Zend_Db_Table_Select)) {
             $select = $this->select();
@@ -1379,10 +1380,10 @@ abstract class Zend_Db_Table_Abstract
                 $this->_order($select, $order);
             }
 
-            $select->limit(1);
+            $select->limit(1, ((is_numeric($offset)) ? (int) $offset : null));
 
         } else {
-            $select = $where->limit(1);
+            $select = $where->limit(1, $where->getPart(Zend_Db_Select::LIMIT_OFFSET));
         }
 
         $rows = $this->_fetch($select);

+ 38 - 0
tests/Zend/Db/Table/TestCommon.php

@@ -1035,6 +1035,44 @@ abstract class Zend_Db_Table_TestCommon extends Zend_Db_Table_TestSetup
         $this->assertEquals('New bug', $row->bug_description);
     }
 
+    /**
+     * @group ZF-8944
+     * @group ZF-10598
+     * @group ZF-11253
+     */
+    public function testTableFetchRowOffset()
+    {
+        $reported_by = $this->_db->quoteIdentifier('reported_by', true);
+
+        $table = $this->_table['bugs'];
+        $row = $table->fetchRow(array("$reported_by = ?" => 'goofy'), null, 1);
+        $this->assertType('Zend_Db_Table_Row_Abstract', $row,
+            'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($row));
+        $bug_id = $this->_db->foldCase('bug_id');
+        $this->assertEquals(2, $row->$bug_id);
+    }
+
+    /**
+     * @group ZF-8944
+     * @group ZF-10598
+     * @group ZF-11253
+     */
+    public function testTableFetchRowOffsetSelect()
+    {
+        $reported_by = $this->_db->quoteIdentifier('reported_by', true);
+
+        $table = $this->_table['bugs'];
+        $select = $table->select()
+            ->where("$reported_by = ?", 'goofy')
+            ->limit(1, 1);
+
+        $row = $table->fetchRow($select);
+        $this->assertType('Zend_Db_Table_Row_Abstract', $row,
+            'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($row));
+        $bug_id = $this->_db->foldCase('bug_id');
+        $this->assertEquals(2, $row->$bug_id);
+    }
+
     public function testTableFetchRow()
     {
         $table = $this->_table['bugs'];