SQLiteConnection Class Reference

Inheritance diagram for SQLiteConnection:

ConnectionCommon Connection

List of all members.

Public Member Functions

 connect ($dsninfo, $flags=0)
 getDatabaseInfo ()
 getIdGenerator ()
 prepareStatement ($sql)
 prepareCall ($sql)
 createStatement ()
 close ()
 applyLimit (&$sql, $offset, $limit)
 executeQuery ($sql, $fetchmode=null)
 executeUpdate ($sql)
 getUpdateCount ()
 Gets the number of rows affected by the data manipulation query.

Protected Member Functions

 beginTrans ()
 Start a database transaction.
 commitTrans ()
 Commit the current transaction.
 rollbackTrans ()
 Roll back (undo) the current transaction.

Private Attributes

 $sqliteAssocCase
 The case to use for SQLite results.


Detailed Description

Definition at line 34 of file SQLiteConnection.php.


Member Function Documentation

SQLiteConnection::applyLimit ( &$  sql,
offset,
limit 
)

See also:
Connection::applyLimit()

Implements Connection.

Definition at line 158 of file SQLiteConnection.php.

00159     {
00160         if ( $limit > 0 ) {
00161             $sql .= " LIMIT " . $limit . ($offset > 0 ? " OFFSET " . $offset : "");
00162         } elseif ( $offset > 0 ) {
00163             $sql .= " LIMIT -1 OFFSET " . $offset;
00164         }
00165     } 

SQLiteConnection::beginTrans (  )  [protected]

Start a database transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 200 of file SQLiteConnection.php.

References $result.

00201     {
00202         $result = @sqlite_query($this->dblink, 'BEGIN');
00203         if (!$result) {
00204             throw new SQLException('Could not begin transaction', $php_errormsg); //sqlite_error_string(sqlite_last_error($this->dblink))
00205         }
00206     }

SQLiteConnection::close (  ) 

See also:
Connection::close()

Implements Connection.

Definition at line 148 of file SQLiteConnection.php.

00149     {
00150         $ret = @sqlite_close($this->dblink);
00151         $this->dblink = null;
00152         return $ret;
00153     }

SQLiteConnection::commitTrans (  )  [protected]

Commit the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 213 of file SQLiteConnection.php.

References $result.

00214     {
00215         $result = @sqlite_query($this->dblink, 'COMMIT');
00216         if (!$result) {
00217             throw new SQLException('Can not commit transaction', $php_errormsg); // sqlite_error_string(sqlite_last_error($this->dblink))
00218         }
00219     }

SQLiteConnection::connect ( dsninfo,
flags = 0 
)

See also:
Connection::connect()

Implements Connection.

Definition at line 47 of file SQLiteConnection.php.

References ConnectionCommon::$flags, Creole::COMPAT_ASSOC_LOWER, and Creole::PERSISTENT.

00048     {        
00049         if (!extension_loaded('sqlite')) {
00050             throw new SQLException('sqlite extension not loaded');
00051         }
00052 
00053         $file = $dsninfo['database'];
00054         
00055         $this->dsn = $dsninfo;
00056         $this->flags = $flags;
00057         
00058         $persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT);
00059         
00060         if (PHP_VERSION == '5.0.4' || PHP_VERSION == '5.0.5') {
00061             $nochange = TRUE;
00062         } else {
00063             $nochange = !(($flags & Creole::COMPAT_ASSOC_LOWER) === Creole::COMPAT_ASSOC_LOWER);
00064         }
00065         
00066         if ($nochange) {     
00067             $this->sqliteAssocCase = 0;
00068         } else {
00069             $this->sqliteAssocCase = 2;
00070         }
00071         
00072         if ($file === null) {
00073             throw new SQLException("No SQLite database specified.");
00074         }
00075         
00076         $mode = (isset($dsninfo['mode']) && is_numeric($dsninfo['mode'])) ? $dsninfo['mode'] : 0644;
00077         
00078         if ($file != ':memory:') {
00079             if (!file_exists($file)) {
00080                 touch($file);
00081                 chmod($file, $mode);
00082                 if (!file_exists($file)) {
00083                     throw new SQLException("Unable to create SQLite database.");
00084                 }
00085             }
00086             if (!is_file($file)) {
00087                 throw new SQLException("Unable to open SQLite database: not a valid file.");
00088             }
00089             if (!is_readable($file)) {
00090                 throw new SQLException("Unable to read SQLite database.");
00091             }
00092         }
00093 
00094         $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
00095         if (!($conn = @$connect_function($file, $mode, $errmsg) )) {
00096             throw new SQLException("Unable to connect to SQLite database", $errmsg);
00097         }
00098         
00099         $this->dblink = $conn;
00100     }   

SQLiteConnection::createStatement (  ) 

See also:
Connection::createStatement()

Implements Connection.

Definition at line 139 of file SQLiteConnection.php.

00140     {
00141         require_once 'creole/drivers/sqlite/SQLiteStatement.php';
00142         return new SQLiteStatement($this);
00143     }

SQLiteConnection::executeQuery ( sql,
fetchmode = null 
)

See also:
Connection::executeQuery()

Implements Connection.

Definition at line 170 of file SQLiteConnection.php.

References $result.

00171     {    
00172         ini_set('sqlite.assoc_case', $this->sqliteAssocCase);
00173         $this->lastQuery = $sql;
00174         $result = @sqlite_query($this->dblink, $this->lastQuery);
00175         if (!$result) {
00176             throw new SQLException('Could not execute query', $php_errormsg, $this->lastQuery); //sqlite_error_string(sqlite_last_error($this->dblink))
00177         }
00178         require_once 'creole/drivers/sqlite/SQLiteResultSet.php';
00179         return new SQLiteResultSet($this, $result, $fetchmode);    
00180     }    

SQLiteConnection::executeUpdate ( sql  ) 

See also:
Connection::executeUpdate()

Implements Connection.

Definition at line 185 of file SQLiteConnection.php.

References $result.

00186     {
00187         $this->lastQuery = $sql;
00188         $result = @sqlite_query($this->dblink, $this->lastQuery);
00189         if (!$result) {            
00190             throw new SQLException('Could not execute update', $php_errormsg, $this->lastQuery); //sqlite_error_string(sqlite_last_error($this->dblink))
00191         }
00192         return (int) @sqlite_changes($this->dblink);
00193     }

SQLiteConnection::getDatabaseInfo (  ) 

See also:
Connection::getDatabaseInfo()

Implements Connection.

Definition at line 105 of file SQLiteConnection.php.

00106     {
00107         require_once 'creole/drivers/sqlite/metadata/SQLiteDatabaseInfo.php';
00108         return new SQLiteDatabaseInfo($this);
00109     }

SQLiteConnection::getIdGenerator (  ) 

See also:
Connection::getIdGenerator()

Implements Connection.

Definition at line 114 of file SQLiteConnection.php.

00115     {
00116         require_once 'creole/drivers/sqlite/SQLiteIdGenerator.php';
00117         return new SQLiteIdGenerator($this);
00118     }

SQLiteConnection::getUpdateCount (  ) 

Gets the number of rows affected by the data manipulation query.

Returns:
int Number of rows affected by the last query.

Implements Connection.

Definition at line 240 of file SQLiteConnection.php.

00241     {
00242         return (int) @sqlite_changes($this->dblink);
00243     }

SQLiteConnection::prepareCall ( sql  ) 

See also:
Connection::prepareCall()

Reimplemented from ConnectionCommon.

Definition at line 132 of file SQLiteConnection.php.

00132                                       {
00133         throw new SQLException('SQLite does not support stored procedures using CallableStatement.');        
00134     }

SQLiteConnection::prepareStatement ( sql  ) 

See also:
Connection::prepareStatement()

Implements Connection.

Definition at line 123 of file SQLiteConnection.php.

00124     {
00125         require_once 'creole/drivers/sqlite/SQLitePreparedStatement.php';
00126         return new SQLitePreparedStatement($this, $sql);
00127     }

SQLiteConnection::rollbackTrans (  )  [protected]

Roll back (undo) the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 226 of file SQLiteConnection.php.

References $result.

00227     {
00228         $result = @sqlite_query($this->dblink, 'ROLLBACK');
00229         if (!$result) {
00230             throw new SQLException('Could not rollback transaction', $php_errormsg); // sqlite_error_string(sqlite_last_error($this->dblink))
00231         }
00232     }


Member Data Documentation

SQLiteConnection::$sqliteAssocCase [private]

The case to use for SQLite results.

(0=nochange, 1=upper, 2=lower) This is set in each call to executeQuery() in order to ensure that different Connections do not overwrite each other's settings

Definition at line 42 of file SQLiteConnection.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