2 // +----------------------------------------------------------------------+
 
   4 // +----------------------------------------------------------------------+
 
   5 // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox,                 |
 
   6 // | Stig. S. Bakken, Lukas Smith                                         |
 
   7 // | All rights reserved.                                                 |
 
   8 // +----------------------------------------------------------------------+
 
   9 // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
 
  10 // | API as well as database abstraction for PHP applications.            |
 
  11 // | This LICENSE is in the BSD license style.                            |
 
  13 // | Redistribution and use in source and binary forms, with or without   |
 
  14 // | modification, are permitted provided that the following conditions   |
 
  17 // | Redistributions of source code must retain the above copyright       |
 
  18 // | notice, this list of conditions and the following disclaimer.        |
 
  20 // | Redistributions in binary form must reproduce the above copyright    |
 
  21 // | notice, this list of conditions and the following disclaimer in the  |
 
  22 // | documentation and/or other materials provided with the distribution. |
 
  24 // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
 
  25 // | Lukas Smith nor the names of his contributors may be used to endorse |
 
  26 // | or promote products derived from this software without specific prior|
 
  27 // | written permission.                                                  |
 
  29 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
 
  30 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
 
  31 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
 
  32 // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
 
  33 // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
 
  34 // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
 
  35 // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
 
  36 // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
 
  37 // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
 
  38 // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
 
  39 // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
 
  40 // | POSSIBILITY OF SUCH DAMAGE.                                          |
 
  41 // +----------------------------------------------------------------------+
 
  42 // | Author: Lukas Smith <smith@pooteeweet.org>                           |
 
  43 // +----------------------------------------------------------------------+
 
  45 // $Id: Iterator.php 327310 2012-08-27 15:16:18Z danielc $
 
  52  * @author   Lukas Smith <smith@pooteeweet.org>
 
  54 class MDB2_Iterator implements Iterator
 
  58      * @var MDB2_Result_Common
 
  68     public function __construct(MDB2_Result_Common $result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
 
  70         $this->result = $result;
 
  71         $this->fetchmode = $fetchmode;
 
  78      * Seek forward to a specific row in a result set
 
  80      * @param int number of the row where the data can be found
 
  85     public function seek($rownum)
 
  89             $this->result->seek($rownum);
 
  97      * Fetch next row of data
 
 102     public function next()
 
 111      * return a row of data
 
 116     public function current()
 
 118         if (null === $this->row) {
 
 119             $row = $this->result->fetchRow($this->fetchmode);
 
 120             if (MDB2::isError($row)) {
 
 132      * Check if the end of the result set has been reached
 
 134      * @return bool true/false, false is also returned on failure
 
 137     public function valid()
 
 139         return (bool)$this->current();
 
 146      * Free the internal resources associated with result.
 
 148      * @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
 
 151     public function free()
 
 154             return $this->result->free();
 
 156         $this->result = false;
 
 165      * Returns the row number
 
 167      * @return int|bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
 
 170     public function key()
 
 173             return $this->result->rowCount();
 
 182      * Seek to the first row in a result set
 
 187     public function rewind()
 
 197     public function __destruct()
 
 205  * PHP5 buffered Iterator
 
 209  * @author   Lukas Smith <smith@pooteeweet.org>
 
 211 class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator
 
 216      * Check if the end of the result set has been reached
 
 218      * @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
 
 221     public function valid()
 
 224             return $this->result->valid();
 
 233      * Returns the number of rows in a result object
 
 235      * @return int|MDB2_Error number of rows, false|MDB2_Error if result is invalid
 
 238     public function count()
 
 241             return $this->result->numRows();
 
 250      * Seek to the first row in a result set
 
 255     public function rewind()