00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'creole/drivers/odbc/ODBCResultSetCommon.php';
00023
00045 class ODBCResultSet extends ODBCResultSetCommon implements ResultSet
00046 {
00052 protected $numRows = -1;
00053
00059 protected $hasRowCount = false;
00060
00064 public function __construct(Connection $conn, $result, $fetchmode = null)
00065 {
00066 parent::__construct($conn, $result, $fetchmode);
00067
00077 $this->numRows = @odbc_num_rows($result->getHandle());
00078 $this->hasRowCount = $this->numRows != -1;
00079 }
00080
00084 function close()
00085 {
00086 parent::close();
00087 $numRows = -1;
00088 }
00089
00093 public function seek($rownum)
00094 {
00095 if ($rownum < 0 || $this->limit > 0 && $rownum > $this->limit)
00096 return false;
00097
00098 $this->cursorPos = $rownum;
00099
00100 return true;
00101 }
00102
00106 public function next()
00107 {
00108 $this->cursorPos++;
00109
00110 if ($this->limit > 0 && $this->cursorPos > $this->limit) {
00111 $this->cursorPos = $this->limit+1;
00112 return false;
00113 }
00114
00115 $rowNum = $this->offset + $this->cursorPos;
00116 $fields = null;
00117
00118 $cols = @odbc_fetch_into($this->result->getHandle(), $fields, $rowNum);
00119
00120 if ($cols === false) {
00121 $this->cursorPos = -1;
00122 return false;
00123 }
00124
00125 $this->fields =& $this->checkFetchMode($fields);
00126
00127 return true;
00128 }
00129
00133 public function isAfterLast()
00134 {
00135
00136 if ($this->cursorPos == -1)
00137 $this->getRecordCount();
00138
00139 return parent::isAfterLast();
00140 }
00141
00145 function getRecordCount()
00146 {
00147 if ($this->hasRowCount)
00148 {
00149
00150 $numRows = $this->numRows - $this->offset;
00151
00152 if ($this->limit > 0 && $numRows > $this->limit)
00153 $numRows = $this->limit;
00154 }
00155 else
00156 {
00157
00158 if ($this->numRows == -1)
00159 {
00160 $this->numRows = 0;
00161 $this->beforeFirst();
00162
00163 while($this->next())
00164 $this->numRows++;
00165 }
00166
00167 $numRows = $this->numRows;
00168 }
00169
00170
00171
00172
00173 if ($this->cursorPos == -1)
00174 $this->cursorPos = $numRows+1;
00175
00176 return $numRows;
00177 }
00178
00182 public function getBlob($column)
00183 {
00184 require_once 'creole/util/Blob.php';
00185 $idx = (is_int($column) ? $column - 1 : $column);
00186 if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00187 $data = $this->readLobData($column, ODBC_BINMODE_RETURN, $this->fields[$idx]);
00188 if (!$data) { return null; }
00189 $b = new Blob();
00190 $b->setContents($data);
00191 return $b;
00192 }
00193
00197 public function getClob($column)
00198 {
00199 require_once 'creole/util/Clob.php';
00200 $idx = (is_int($column) ? $column - 1 : $column);
00201 if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00202 $data = $this->readLobData($column, ODBC_BINMODE_CONVERT, $this->fields[$idx]);
00203 if (!$data) { return null; }
00204 $c = new Clob();
00205 $c->setContents($data);
00206 return $c;
00207 }
00208
00209 }