00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00031 class PgSQLResultSetIterator implements SeekableIterator, Countable {
00032
00033 private $result;
00034 private $pos = 0;
00035 private $fetchmode;
00036 private $row_count;
00037 private $rs;
00038
00043 public function __construct(PgSQLResultSet $rs)
00044 {
00045 $this->result = $rs->getResource();
00046 $this->fetchmode = $rs->getFetchmode();
00047 $this->row_count = $rs->getRecordCount();
00048 $this->rs = $rs;
00049 }
00050
00054 function rewind()
00055 {
00056 $this->pos = 0;
00057 }
00058
00059 function valid()
00060 {
00061 return ( $this->pos < $this->row_count );
00062 }
00063
00070 function key()
00071 {
00072 return $this->pos;
00073 }
00074
00079 function current()
00080 {
00081 return pg_fetch_array($this->result, $this->pos, $this->fetchmode);
00082 }
00083
00087 function next()
00088 {
00089 $this->pos++;
00090 }
00091
00095 function seek ( $index )
00096 {
00097 if ( ! is_int ( $index ) ) {
00098 throw new InvalidArgumentException ( 'Invalid arguement to seek' );
00099 }
00100 if ( $index < 0 || $index > $this->row_count ) {
00101 throw new OutOfBoundsException ( 'Invalid seek position' );
00102 }
00103 $this->pos = $index;
00104 }
00105
00106 function count ( ) {
00107 return $this->row_count;
00108 }
00109 }