ODBCCachedResultSet Class Reference

Inheritance diagram for ODBCCachedResultSet:

ODBCResultSetCommon ResultSet ResultSetCommon

List of all members.

Public Member Functions

 __construct (Connection $conn, $result, $fetchmode=null, $cacheLobs=false)
 close ()
 loadCache ($recPos=-1)
 Caches specified records up to and including the specified 1-based record position.
 seek ($rownum)
 next ()
 getRecordCount ()
 isAfterLast ()

Protected Attributes

 $recs = array()
 $lastPos = -1
 $cacheLobs = false


Detailed Description

Definition at line 51 of file ODBCCachedResultSet.php.


Constructor & Destructor Documentation

ODBCCachedResultSet::__construct ( Connection conn,
result,
fetchmode = null,
cacheLobs = false 
)

See also:
ResultSet::__construct()

Definition at line 74 of file ODBCCachedResultSet.php.

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

00075     {
00076         parent::__construct($conn, $result, $fetchmode);
00077 
00078         $this->cacheLobs = $cacheLobs;
00079     }


Member Function Documentation

ODBCCachedResultSet::close (  ) 

See also:
ODBCResultSetCommon::close()

Reimplemented from ODBCResultSetCommon.

Definition at line 84 of file ODBCCachedResultSet.php.

00085     {
00086         parent::close();
00087         $this->recs = null;
00088         $this->lastPos = -1;
00089         $this->cacheLobs = false;
00090     }

ODBCCachedResultSet::getRecordCount (  ) 

See also:
ResultSet::getRecordCount()

Implements ResultSet.

Definition at line 198 of file ODBCCachedResultSet.php.

References loadCache().

00199     {
00200         if ($this->lastPos == -1)
00201             $this->loadCache(-1);
00202 
00203         return $this->lastPos;
00204     }

ODBCCachedResultSet::isAfterLast (  ) 

See also:
ResultSet::isAfterLast()

Implements ResultSet.

Definition at line 209 of file ODBCCachedResultSet.php.

Referenced by next().

00210     {
00211         // All records cached yet?
00212         if ($this->lastPos == -1)
00213             return false;
00214 
00215         return ($this->cursorPos > $this->lastPos);
00216     }

ODBCCachedResultSet::loadCache ( recPos = -1  ) 

Caches specified records up to and including the specified 1-based record position.

If -1 is specified, all records will be cached.

Parameters:
integer Maximum record position to cache.
Returns:
void
Exceptions:
SQLException 

Definition at line 99 of file ODBCCachedResultSet.php.

References ResultSetCommon::$result, CreoleTypes::BLOB, CreoleTypes::CLOB, ODBCTypes::getType(), ODBCTypes::loadTypeMap(), CreoleTypes::LONGVARBINARY, CreoleTypes::LONGVARCHAR, and ODBCResultSetCommon::readLobData().

Referenced by getRecordCount(), next(), and seek().

00100     {
00101         $rid = $this->result->getHandle();
00102 
00103         $curRecs = count($this->recs);
00104         $totRecs = ($curRecs ? $this->offset + $curRecs : 0);
00105 
00106         while (1)
00107         {
00108             // Is record already cached?
00109             if ($this->lastPos != -1 || ($recPos > -1 && $recPos <= $curRecs))
00110                 return;
00111 
00112             // Fetch row (no buffers copied yet).
00113             $rowNum = ++$totRecs;
00114             $result = @odbc_fetch_row($rid, $rowNum);
00115 
00116             // All records cached?
00117             if ($result === false || ($this->limit > 0 && $curRecs+1 > $this->limit))
00118             {
00119                 $this->lastPos = $curRecs;
00120                 continue;
00121             }
00122 
00123             // Ignore offset records.
00124             if ($totRecs <= $this->offset)
00125                 continue;
00126 
00127             // Load row array.
00128             $row = array();
00129             for ($i = 0, $n = @odbc_num_fields($rid); $i < $n; $i++)
00130             {
00131                 $fldNum = $i+1;
00132                 $row[$i] = odbc_result($rid, $fldNum);
00133                 
00134                 // Cache lobs if necessary
00135                 if ($this->cacheLobs)
00136                 {
00137                     ODBCTypes::loadTypeMap($this->conn);
00138 
00139                     $nativeType = @odbc_field_type($rid, $fldNum);
00140                     $creoleType = ODBCTypes::getType($nativeType);
00141 
00142                     $isBlob = ($creoleType == CreoleTypes::BLOB ||
00143                                $creoleType == CreoleTypes::LONGVARBINARY);
00144 
00145                     $isClob = ($creoleType == CreoleTypes::CLOB ||
00146                                $creoleType == CreoleTypes::LONGVARCHAR);
00147 
00148                     if (($isBlob || $isClob) && $row[$i] !== null)
00149                     {
00150                         $binmode = ($isBlob ? ODBC_BINMODE_RETURN : ODBC_BINMODE_CONVERT);
00151                         $curdata = $row[$i];
00152                         $row[$i] = $this->readLobData($fldNum, $binmode, $curdata);
00153                     }
00154                 }
00155             }
00156                         
00157             // Add record to cache.
00158             $this->recs[++$curRecs] = $row;
00159         }
00160     }

ODBCCachedResultSet::next (  ) 

See also:
ResultSet::next()

Implements ResultSet.

Definition at line 180 of file ODBCCachedResultSet.php.

References ResultSet::afterLast(), ODBCResultSetCommon::checkFetchMode(), isAfterLast(), and loadCache().

00181     {
00182         $this->loadCache(++$this->cursorPos);
00183 
00184         if ($this->isAfterLast())
00185         {
00186             $this->afterLast();
00187             return false;
00188         }
00189 
00190         $this->fields =& $this->checkFetchMode($this->recs[$this->cursorPos]);
00191 
00192         return true;
00193     }

ODBCCachedResultSet::seek ( rownum  ) 

See also:
ResultSet::seek()

Implements ResultSet.

Definition at line 165 of file ODBCCachedResultSet.php.

References loadCache().

00166     {
00167         $this->loadCache($rownum);
00168 
00169         if ($rownum < 0 || $rownum > count($this->recs)+1)
00170             return false;
00171 
00172         $this->cursorPos = $rownum;
00173 
00174         return true;
00175     }


Member Data Documentation

ODBCCachedResultSet::$cacheLobs = false [protected]

Definition at line 69 of file ODBCCachedResultSet.php.

Referenced by __construct().

ODBCCachedResultSet::$lastPos = -1 [protected]

Definition at line 63 of file ODBCCachedResultSet.php.

ODBCCachedResultSet::$recs = array() [protected]

Definition at line 57 of file ODBCCachedResultSet.php.


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