ODBCResultSet Class Reference

Inheritance diagram for ODBCResultSet:

ODBCResultSetCommon ResultSet ResultSetCommon

List of all members.

Public Member Functions

 __construct (Connection $conn, $result, $fetchmode=null)
 close ()
 seek ($rownum)
 next ()
 isAfterLast ()
 getRecordCount ()
 getBlob ($column)
 getClob ($column)

Protected Attributes

 $numRows = -1
 $hasRowCount = false


Detailed Description

Definition at line 45 of file ODBCResultSet.php.


Constructor & Destructor Documentation

ODBCResultSet::__construct ( Connection conn,
result,
fetchmode = null 
)

See also:
ResultSet::__construct()

Some ODBC drivers appear not to handle odbc_num_rows() very well when more than one result handle is active at once. For example, the MySQL ODBC driver always returns the number of rows for the last executed result. For this reason, we'll store the row count here.

Note also that many ODBC drivers do not support this method. In this case, getRecordCount() will perform a manual count.

Reimplemented from ODBCResultSetCommon.

Definition at line 64 of file ODBCResultSet.php.

References ResultSetCommon::$fetchmode, and ResultSetCommon::$result.

00065     {
00066         parent::__construct($conn, $result, $fetchmode);
00067 
00077         $this->numRows = @odbc_num_rows($result->getHandle());
00078         $this->hasRowCount = $this->numRows != -1;
00079     }


Member Function Documentation

ODBCResultSet::close (  ) 

See also:
ODBCResultSetCommon::close()

Reimplemented from ODBCResultSetCommon.

Definition at line 84 of file ODBCResultSet.php.

References $numRows.

00085     {
00086         parent::close();
00087         $numRows = -1;
00088     }

ODBCResultSet::getBlob ( column  ) 

See also:
ResultSet::getBlob()

Implements ResultSet.

Definition at line 182 of file ODBCResultSet.php.

References ODBCResultSetCommon::readLobData().

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     }

ODBCResultSet::getClob ( column  ) 

See also:
ResultSet::getClob()

Implements ResultSet.

Definition at line 197 of file ODBCResultSet.php.

References ODBCResultSetCommon::readLobData().

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     }

ODBCResultSet::getRecordCount (  ) 

See also:
ResultSet::getRecordCount()

Implements ResultSet.

Definition at line 145 of file ODBCResultSet.php.

References $numRows, ResultSet::beforeFirst(), and next().

Referenced by isAfterLast().

00146     {
00147         if ($this->hasRowCount)
00148         {
00149             // Use driver row count if provided.
00150             $numRows = $this->numRows - $this->offset;
00151 
00152             if ($this->limit > 0 && $numRows > $this->limit)
00153                 $numRows = $this->limit;
00154         }
00155         else 
00156         {
00157             // Do manual row count if driver doesn't provide one.
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         // Cursor pos is -1 when an attempt to fetch past the last row was made
00171         // (or a fetch error occured).
00172         
00173         if ($this->cursorPos == -1)
00174             $this->cursorPos = $numRows+1;
00175             
00176         return $numRows;
00177     }

ODBCResultSet::isAfterLast (  ) 

See also:
ResultSet::isAfterLast()

Implements ResultSet.

Definition at line 133 of file ODBCResultSet.php.

References getRecordCount().

00134     {
00135         // Force calculation of last record pos.
00136         if ($this->cursorPos == -1)
00137             $this->getRecordCount();
00138             
00139         return parent::isAfterLast();
00140     }

ODBCResultSet::next (  ) 

See also:
ResultSet::next()

Implements ResultSet.

Definition at line 106 of file ODBCResultSet.php.

References ResultSetCommon::$fields, and ODBCResultSetCommon::checkFetchMode().

Referenced by getRecordCount().

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     }

ODBCResultSet::seek ( rownum  ) 

See also:
ResultSet::seek()

Implements ResultSet.

Definition at line 93 of file ODBCResultSet.php.

00094     {
00095         if ($rownum < 0 || $this->limit > 0 && $rownum > $this->limit)
00096             return false;
00097         
00098         $this->cursorPos = $rownum;
00099 
00100         return true;
00101     }


Member Data Documentation

ODBCResultSet::$hasRowCount = false [protected]

Definition at line 59 of file ODBCResultSet.php.

ODBCResultSet::$numRows = -1 [protected]

Definition at line 52 of file ODBCResultSet.php.

Referenced by close(), and getRecordCount().


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:10:50 2009 for fareofficelib by  doxygen 1.5.8