. */ /** * Optimized iterator for SQLite. * * @author Hans Lellelid * @version $Revision: 1.6 $ * @package creole.drivers.sqlite */ class SQLiteResultSetIterator implements Iterator { private $result; private $pos = 0; private $fetchmode; private $row_count; /** * Construct the iterator. * @param SQLiteResultSet $rs */ public function __construct(SQLiteResultSet $rs) { $this->result = $rs->getResource(); $this->fetchmode = $rs->getFetchmode(); $this->row_count = $rs->getRecordCount(); } /** * This method actually has no effect, since we do not rewind ResultSet for iteration. */ function rewind() { sqlite_rewind($this->result); } function valid() { return ( $this->pos < $this->row_count ); } /** * Returns the cursor position. Note that this will not necessarily * be 1 for the first row, since no rewind is performed at beginning * of iteration. * @return int */ function key() { return $this->pos; } /** * Returns the row (assoc array) at current cursor pos. * @return array */ function current() { return sqlite_fetch_array($this->result, $this->fetchmode); } /** * Advances internal cursor pos. */ function next() { $this->pos++; } }