ResultSetCommon Class Reference

Inheritance diagram for ResultSetCommon:

MSSQLResultSet MySQLiResultSet MySQLResultSet OCI8ResultSet ODBCResultSetCommon PgSQLResultSet SQLiteResultSet ODBCCachedResultSet ODBCResultSet

List of all members.

Public Member Functions

 __construct (Connection $conn, $result, $fetchmode=null)
 Constructor.
 __destruct ()
 Destructor.
 getIterator ()
 getResource ()
 isLowerAssocCase ()
 setFetchmode ($mode)
 getFetchmode ()
 previous ()
 relative ($offset)
 absolute ($pos)
 first ()
 last ()
 beforeFirst ()
 afterLast ()
 isAfterLast ()
 isBeforeFirst ()
 getCursorPos ()
 getRow ()
 get ($column)
 getArray ($column)
 getBoolean ($column)
 getBlob ($column)
 getClob ($column)
 getDate ($column, $format= '%x')
 getFloat ($column)
 getInt ($column)
 getString ($column)
 getTime ($column, $format= '%X')
 getTimestamp ($column, $format= 'Y-m-d H:i:s')

Protected Attributes

 $fetchmode
 $conn
 $result
 $cursorPos = 0
 $fields
 $lowerAssocCase = false
 $rtrimString = false


Detailed Description

Definition at line 53 of file ResultSetCommon.php.


Constructor & Destructor Documentation

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

Constructor.

Reimplemented in ODBCResultSet, and ODBCResultSetCommon.

Definition at line 100 of file ResultSetCommon.php.

References $fetchmode, $result, Creole::COMPAT_ASSOC_LOWER, Creole::COMPAT_RTRIM_STRING, ResultSet::FETCHMODE_ASSOC, and Connection::getFlags().

00101     {
00102         $this->conn = $conn;
00103         $this->result = $result;             
00104         if ($fetchmode !== null) {
00105             $this->fetchmode = $fetchmode;
00106         } else {
00107             $this->fetchmode = ResultSet::FETCHMODE_ASSOC; // default
00108         }
00109         $this->lowerAssocCase = (($conn->getFlags() & Creole::COMPAT_ASSOC_LOWER) === Creole::COMPAT_ASSOC_LOWER);
00110     $this->rtrimString = (($conn->getFlags() & Creole::COMPAT_RTRIM_STRING) === Creole::COMPAT_RTRIM_STRING);
00111     }

ResultSetCommon::__destruct (  ) 

Destructor.

Free db result resource.

Definition at line 118 of file ResultSetCommon.php.

00119     {
00120           $this->close();
00121     }


Member Function Documentation

ResultSetCommon::absolute ( pos  ) 

See also:
ResultSet::absolute()

Definition at line 203 of file ResultSetCommon.php.

References afterLast(), and beforeFirst().

00204     {
00205         $ok = $this->seek( $pos - 1 ); // compensate for next() factor        
00206         if ($ok === false) {
00207             if ($pos - 1 < 0) {
00208                 $this->beforeFirst();
00209             } else {
00210                 $this->afterLast();
00211             }
00212         } else {
00213             $ok = $this->next();
00214         }        
00215         return $ok;
00216     }

ResultSetCommon::afterLast (  ) 

See also:
ResultSet::afterLast()

Definition at line 249 of file ResultSetCommon.php.

Referenced by absolute(), SQLiteResultSet::next(), PgSQLResultSet::next(), OCI8ResultSet::next(), MySQLiResultSet::next(), MySQLResultSet::next(), MSSQLResultSet::next(), and relative().

00250     {
00251         $this->cursorPos = $this->getRecordCount() + 1;
00252     }

ResultSetCommon::beforeFirst (  ) 

See also:
ResultSet::beforeFirst()

Definition at line 241 of file ResultSetCommon.php.

Referenced by absolute(), previous(), and relative().

00242     {
00243         $this->cursorPos = 0;
00244     }

ResultSetCommon::first (  ) 

See also:
ResultSet::first()

Definition at line 221 of file ResultSetCommon.php.

00222     {
00223         if($this->cursorPos !== 0) { $this->seek(0); }
00224         return $this->next();
00225     }

ResultSetCommon::get ( column  ) 

See also:
ResultSet::get()

Definition at line 289 of file ResultSetCommon.php.

00290     {
00291         $idx = (is_int($column) ? $column - 1 : $column);
00292         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00293         return $this->fields[$idx];
00294     }

ResultSetCommon::getArray ( column  ) 

See also:
ResultSet::getArray()

Reimplemented in PgSQLResultSet.

Definition at line 299 of file ResultSetCommon.php.

00300     {
00301         $idx = (is_int($column) ? $column - 1 : $column);
00302         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00303         if ($this->fields[$idx] === null) { return null; }
00304         return (array) unserialize($this->fields[$idx]);
00305     } 

ResultSetCommon::getBlob ( column  ) 

See also:
ResultSet::getBlob()

Reimplemented in ODBCResultSet, PgSQLResultSet, and SQLiteResultSet.

Definition at line 321 of file ResultSetCommon.php.

00322     {
00323         $idx = (is_int($column) ? $column - 1 : $column);
00324         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00325         if ($this->fields[$idx] === null) { return null; }
00326         require_once 'creole/util/Blob.php';
00327         $b = new Blob();
00328         $b->setContents($this->fields[$idx]);
00329         return $b;
00330     }    

ResultSetCommon::getBoolean ( column  ) 

See also:
ResultSet::getBoolean()

Reimplemented in PgSQLResultSet.

Definition at line 310 of file ResultSetCommon.php.

00311     {
00312         $idx = (is_int($column) ? $column - 1 : $column);
00313         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00314         if ($this->fields[$idx] === null) { return null; }
00315         return (boolean) $this->fields[$idx];
00316     }

ResultSetCommon::getClob ( column  ) 

See also:
ResultSet::getClob()

Reimplemented in ODBCResultSet.

Definition at line 335 of file ResultSetCommon.php.

00336     {
00337         $idx = (is_int($column) ? $column - 1 : $column);
00338         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00339         if ($this->fields[$idx] === null) { return null; }
00340         require_once 'creole/util/Clob.php';
00341         $c = new Clob();
00342         $c->setContents($this->fields[$idx]);
00343         return $c;
00344     } 

ResultSetCommon::getCursorPos (  ) 

See also:
ResultSet::getCursorPos()

Definition at line 273 of file ResultSetCommon.php.

00274     {
00275         return $this->cursorPos;
00276     }

ResultSetCommon::getDate ( column,
format = '%x' 
)

See also:
ResultSet::getDate()

Definition at line 349 of file ResultSetCommon.php.

00350     {
00351         $idx = (is_int($column) ? $column - 1 : $column);
00352         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00353         if ($this->fields[$idx] === null) { return null; }
00354         $ts = strtotime($this->fields[$idx]);        
00355         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
00356             throw new SQLException("Unable to convert value at column " . $column . " to timestamp: " . $this->fields[$idx]);
00357         }
00358         if ($format === null) {
00359             return $ts;
00360         }
00361         if (strpos($format, '%') !== false) {
00362             return strftime($format, $ts);
00363         } else {
00364             return date($format, $ts);
00365         }
00366     }    

ResultSetCommon::getFetchmode (  ) 

See also:
ResultSet::getFetchmode()

Definition at line 159 of file ResultSetCommon.php.

Referenced by SQLiteResultSetIterator::__construct(), and PgSQLResultSetIterator::__construct().

00160     {
00161         return $this->fetchmode;
00162     }                

ResultSetCommon::getFloat ( column  ) 

See also:
ResultSet::getFloat()

Definition at line 371 of file ResultSetCommon.php.

00372     {
00373         $idx = (is_int($column) ? $column - 1 : $column);
00374         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00375         if ($this->fields[$idx] === null) { return null; }
00376         return (float) $this->fields[$idx];
00377     }

ResultSetCommon::getInt ( column  ) 

See also:
ResultSet::getInt()

Definition at line 382 of file ResultSetCommon.php.

00383     {
00384         $idx = (is_int($column) ? $column - 1 : $column);
00385         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00386         if ($this->fields[$idx] === null) { return null; }
00387         return (int) $this->fields[$idx];
00388     }

ResultSetCommon::getIterator (  ) 

See also:
ResultSet::getIterator()

Reimplemented in SQLiteResultSet.

Definition at line 126 of file ResultSetCommon.php.

00127     {
00128         require_once 'creole/ResultSetIterator.php';
00129         return new ResultSetIterator($this);
00130     }

ResultSetCommon::getResource (  ) 

See also:
ResultSet::getResource()

Definition at line 135 of file ResultSetCommon.php.

Referenced by SQLiteResultSetIterator::__construct(), and PgSQLResultSetIterator::__construct().

00136     {
00137         return $this->result;
00138     }

ResultSetCommon::getRow (  ) 

See also:
ResultSet::getRow()

Definition at line 281 of file ResultSetCommon.php.

00282     {
00283         return $this->fields;
00284     }

ResultSetCommon::getString ( column  ) 

See also:
ResultSet::getString()

Reimplemented in MySQLResultSet, and MySQLiResultSet.

Definition at line 393 of file ResultSetCommon.php.

00394     {
00395         $idx = (is_int($column) ? $column - 1 : $column);
00396         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00397         if ($this->fields[$idx] === null) { return null; }
00398     return ($this->rtrimString ? rtrim($this->fields[$idx]) : (string) $this->fields[$idx]);
00399     }

ResultSetCommon::getTime ( column,
format = '%X' 
)

See also:
ResultSet::getTime()

Definition at line 404 of file ResultSetCommon.php.

00405     {
00406         $idx = (is_int($column) ? $column - 1 : $column);
00407         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00408         if ($this->fields[$idx] === null) { return null; }
00409         
00410         $ts = strtotime($this->fields[$idx]);
00411         
00412         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
00413             throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$idx]);
00414         }
00415         if ($format === null) {
00416             return $ts;
00417         }        
00418         if (strpos($format, '%') !== false) {
00419             return strftime($format, $ts);
00420         } else {
00421             return date($format, $ts);
00422         }        
00423     }

ResultSetCommon::getTimestamp ( column,
format = 'Y-m-d H:i:s' 
)

See also:
ResultSet::getTimestamp()

Reimplemented in MySQLResultSet, and MySQLiResultSet.

Definition at line 428 of file ResultSetCommon.php.

00428                                                             :i:s') 
00429     {
00430         $idx = (is_int($column) ? $column - 1 : $column);
00431         if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
00432         if ($this->fields[$idx] === null) { return null; }
00433         
00434         $ts = strtotime($this->fields[$idx]);
00435         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
00436             throw new SQLException("Unable to convert value at column " . $column . " to timestamp: " . $this->fields[$idx]);
00437         }
00438         if ($format === null) {
00439             return $ts;
00440         }
00441         if (strpos($format, '%') !== false) {
00442             return strftime($format, $ts);
00443         } else {
00444             return date($format, $ts);
00445         }        
00446     }  

ResultSetCommon::isAfterLast (  ) 

See also:
ResultSet::isAfterLast()

Reimplemented in ODBCCachedResultSet, and ODBCResultSet.

Definition at line 257 of file ResultSetCommon.php.

00258     {
00259         return ($this->cursorPos === $this->getRecordCount() + 1);
00260     }

ResultSetCommon::isBeforeFirst (  ) 

See also:
ResultSet::isBeforeFirst()

Definition at line 265 of file ResultSetCommon.php.

00266     {
00267         return ($this->cursorPos === 0);
00268     }    

ResultSetCommon::isLowerAssocCase (  ) 

See also:
ResultSet::isLowereAssocCase()

Definition at line 143 of file ResultSetCommon.php.

00144     {
00145         return $this->lowerAssocCase;
00146     }        

ResultSetCommon::last (  ) 

See also:
ResultSet::last()

Definition at line 230 of file ResultSetCommon.php.

00231     {
00232         if($this->cursorPos !==  ($last = $this->getRecordCount() - 1)) {
00233             $this->seek( $last );
00234         }
00235         return $this->next();
00236     }

ResultSetCommon::previous (  ) 

See also:
ResultSet::previous()

Definition at line 167 of file ResultSetCommon.php.

References beforeFirst().

00168     {
00169         // Go back 2 spaces so that we can then advance 1 space.
00170         $ok = $this->seek($this->cursorPos - 2);
00171         if ($ok === false) {
00172             $this->beforeFirst();
00173             return false;
00174         }        
00175         return $this->next();      
00176     }

ResultSetCommon::relative ( offset  ) 

See also:
ResultSet::isBeforeFirst()

Definition at line 181 of file ResultSetCommon.php.

References afterLast(), and beforeFirst().

00182     {
00183         // which absolute row number are we seeking
00184         $pos = $this->cursorPos + ($offset - 1);
00185         $ok = $this->seek($pos);
00186                 
00187         if ($ok === false) {
00188             if ($pos < 0) {
00189                 $this->beforeFirst();
00190             } else {
00191                 $this->afterLast();
00192             }
00193         } else {
00194             $ok = $this->next();
00195         }
00196         
00197         return $ok;
00198     }

ResultSetCommon::setFetchmode ( mode  ) 

See also:
ResultSet::setFetchmode()

Definition at line 151 of file ResultSetCommon.php.

00152     {
00153         $this->fetchmode = $mode;
00154     }


Member Data Documentation

ResultSetCommon::$conn [protected]

Definition at line 65 of file ResultSetCommon.php.

ResultSetCommon::$cursorPos = 0 [protected]

Definition at line 77 of file ResultSetCommon.php.

ResultSetCommon::$fetchmode [protected]

ResultSetCommon::$fields [protected]

Definition at line 83 of file ResultSetCommon.php.

Referenced by ODBCResultSet::next().

ResultSetCommon::$lowerAssocCase = false [protected]

Definition at line 89 of file ResultSetCommon.php.

ResultSetCommon::$result [protected]

ResultSetCommon::$rtrimString = false [protected]

Definition at line 95 of file ResultSetCommon.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