Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.0.4
-
Component/s: Zend_Db_Table
-
Labels:None
-
Fix Version Priority:Nice to Have
Description
Zend_Db_Table_Rowset_Abstract could implement SeekableIterator, instead of Iterator.
That way, we could jump from result (Zend_Db_Table_Row) to result in the Rowset container.
We could as well fetch a specific result by its position, see :
Zend_Db_Table_Rowset_Abstract.php
<?php abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Countable { // ... all the actual code ... /** * Take the Iterator to position $position * Required by interface SeekableIterator. * * @return void * @throws OutOfBoundsException */ public function seek($position) { $position = (int)$position; if ($position >= 0 && $position < $this->_count) { $this->_pointer = $position; }else{ throw new OutOfBoundsException("Illegal index '$position'"); } } /** * get a specific Zend_Db_Table_Row in the Iterator * * @return Zend_Db_Table_Row * @throws Zend_Db_Table_Rowset_Exception */ public function getRow($position) { $position = (int)$position; try{ $this->seek($position); }catch (OutOfBoundsException $e){ throw new Zend_Db_Table_Rowset_Exception("No row could be found at position $position"); } return $this->current(); }
Zend_Db_Table_Rowset_Exception.php
<?php
require_once 'Zend/Db/Table/Exception.php';
class Zend_Db_Table_Rowset_Exception extends Zend_Db_Table_Exception
{
}
Seek use-case :
<?php // ... all DB code ... $a = new AClassUsingZendDbTable(); $rowset = $a->fetchAll(); $a->seek(2); // internal rowset pointer is now set to 2 $rowNumber2 = $a->current(); // $rowNumber2 is an instance of Zend_Db_Table_Row
getRow() use-case :
<?php // ... all DB code ... $a = new AClassUsingZendDbTable(); $rowset = $a->fetchAll(); $rowNumber3 = $a->getRow(3); // $rowNumber3 is an instance of Zend_Db_Table_Row
Assigned to Bill