diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 63419b1b..d1359a8a 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -176,13 +176,14 @@ class DibiResult extends DibiObject implements IDataSource /** * Required by the IteratorAggregate interface. - * @param int offset - * @param int limit * @return DibiResultIterator */ - final public function getIterator($offset = NULL, $limit = NULL) + final public function getIterator() { - return new DibiResultIterator($this, $offset, $limit); + if (func_num_args()) { + trigger_error(__METHOD__ . ' arguments $offset & $limit have been dropped; use SQL clauses instead.', E_USER_WARNING); + } + return new DibiResultIterator($this); } diff --git a/dibi/libs/DibiResultIterator.php b/dibi/libs/DibiResultIterator.php index f288eec5..c5584543 100644 --- a/dibi/libs/DibiResultIterator.php +++ b/dibi/libs/DibiResultIterator.php @@ -24,13 +24,6 @@ * unset($result); * * - * Optionally you can specify offset and limit: - * - * foreach ($result->getIterator(2, 3) as $row) { - * print_r($row); - * } - * - * * @copyright Copyright (c) 2005, 2010 David Grudl * @package dibi */ @@ -39,12 +32,6 @@ class DibiResultIterator implements Iterator, Countable /** @var DibiResult */ private $result; - /** @var int */ - private $offset; - - /** @var int */ - private $limit; - /** @var int */ private $row; @@ -54,14 +41,10 @@ class DibiResultIterator implements Iterator, Countable /** * @param DibiResult - * @param int offset - * @param int limit */ - public function __construct(DibiResult $result, $offset = NULL, $limit = NULL) + public function __construct(DibiResult $result) { $this->result = $result; - $this->offset = (int) $offset; - $this->limit = $limit === NULL ? -1 : (int) $limit; } @@ -73,7 +56,7 @@ class DibiResultIterator implements Iterator, Countable public function rewind() { $this->pointer = 0; - $this->result->seek($this->offset); + $this->result->seek(0); $this->row = $this->result->fetch(); } @@ -107,7 +90,6 @@ class DibiResultIterator implements Iterator, Countable */ public function next() { - //$this->result->seek($this->offset + $this->pointer + 1); $this->row = $this->result->fetch(); $this->pointer++; } @@ -120,7 +102,7 @@ class DibiResultIterator implements Iterator, Countable */ public function valid() { - return !empty($this->row) && ($this->limit < 0 || $this->pointer < $this->limit); + return !empty($this->row); } diff --git a/examples/fetching-examples.php b/examples/fetching-examples.php index a434b71f..ef7ed7ec 100644 --- a/examples/fetching-examples.php +++ b/examples/fetching-examples.php @@ -64,19 +64,6 @@ foreach ($res as $n => $row) { } -// fetch row by row with defined offset -echo "

getIterator(2)

\n"; -foreach ($res->getIterator(2) as $n => $row) { - Debug::dump($row); -} - -// fetch row by row with defined offset and limit -echo "

getIterator(2, 1)

\n"; -foreach ($res->getIterator(2, 1) as $n => $row) { - Debug::dump($row); -} - - // more complex association array $res = dibi::query(' SELECT *