ODBCConnection Class Reference

Inheritance diagram for ODBCConnection:

ConnectionCommon Connection

List of all members.

Public Member Functions

 connect ($dsninfo, $flags=0)
 close ()
 __destruct ()
 Shouldn't this be in ConnectionCommon.php?
 nativeError ()
 Returns a formatted ODBC error string.
 getAdapter ()
 Returns driver-specific ODBCAdapter.
 getDatabaseInfo ()
 getIdGenerator ()
 createResultSet ($odbcresult, $fetchmode)
 Creates the appropriate ResultSet.
 prepareStatement ($sql)
 createStatement ()
 prepareCall ($sql)
 applyLimit (&$sql, $offset, $limit)
 executeQuery ($sql, $fetchmode=null)
 executeUpdate ($sql)
 getUpdateCount ()

Protected Member Functions

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

Protected Attributes

 $adapter = null
 $odbcresult = null


Detailed Description

Definition at line 33 of file ODBCConnection.php.


Constructor & Destructor Documentation

ODBCConnection::__destruct (  ) 

Shouldn't this be in ConnectionCommon.php?

Definition at line 129 of file ODBCConnection.php.

References close().

00130     {
00131         $this->close();
00132     }


Member Function Documentation

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

See also:
Connection::applyLimit()

Implements Connection.

Definition at line 213 of file ODBCConnection.php.

00214     {
00215         if ($this->adapter->hasLimitOffset())
00216             $this->adapter->applyLimit($sql, $offset, $limit);
00217     }

ODBCConnection::beginTrans (  )  [protected]

Start a database transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 260 of file ODBCConnection.php.

References nativeError().

00261     {
00262         if ($this->adapter->supportsTransactions()) {
00263             @odbc_autocommit($this->dblink, false);
00264             if (odbc_error($this->dblink) == 'S1C00') {
00265                 throw new SQLException('Could not begin transaction', $this->nativeError());
00266             }
00267         }
00268     }

ODBCConnection::close (  ) 

See also:
Connection::close()

Implements Connection.

Definition at line 110 of file ODBCConnection.php.

Referenced by __destruct().

00111     {
00112         $ret = true;
00113 
00114         $this->adapter = null;
00115         $this->odbcresult = null;
00116 
00117         if ($this->dblink !== null)
00118         {
00119             $ret = @odbc_close($this->dblink);
00120             $this->dblink = null;
00121         }
00122 
00123         return $ret;
00124     }

ODBCConnection::commitTrans (  )  [protected]

Commit the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 275 of file ODBCConnection.php.

References $result, and nativeError().

00276     {
00277         if ($this->adapter->supportsTransactions()) {
00278             $result = @odbc_commit($this->dblink);
00279             if (!$result) {
00280                 throw new SQLException('Could not commit transaction', $this->nativeError());
00281             }
00282             @odbc_autocommit($this->dblink, true);
00283             if (odbc_error($this->dblink) == 'S1C00') {
00284                 throw new SQLException('Could not commit transaction (autocommit failed)', $this->nativeError());
00285             }
00286         }
00287     }

ODBCConnection::connect ( dsninfo,
flags = 0 
)

See also:
Connection::connect()

This prevents blob fields from being fetched when a row is loaded from a recordset. Clob fields however are loaded with up to 'odbc.defaultlrl' data. This should be the default anyway, but we'll set it here just to keep things consistent.

Implements Connection.

Definition at line 50 of file ODBCConnection.php.

References ConnectionCommon::$flags, Creole::COMPAT_ASSOC_LOWER, Creole::import(), nativeError(), and Creole::PERSISTENT.

00051     {
00052     if (!function_exists('odbc_connect'))
00053             throw new SQLException('odbc extension not loaded');
00054 
00055         $adapterclass = isset($dsninfo['adapter']) ? $dsninfo['adapter'] : null;
00056 
00057         if (!$adapterclass)
00058             $adapterclass = 'ODBCAdapter';
00059         else
00060             $adapterclass .= 'Adapter';
00061 
00062         Creole::import('creole.drivers.odbc.adapters.' . $adapterclass);
00063         $this->adapter = new $adapterclass();
00064 
00065         $this->dsn = $dsninfo;
00066         $this->flags = $flags;
00067 
00068         if ( !($this->flags & Creole::COMPAT_ASSOC_LOWER) && !$this->adapter->preservesColumnCase())
00069         {
00070             trigger_error('Connection created without Creole::COMPAT_ASSOC_LOWER, ' .
00071                           'but driver does not support case preservation.',
00072                           E_USER_WARNING);
00073             $this->flags != Creole::COMPAT_ASSOC_LOWER;
00074         }
00075 
00076         $persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
00077 
00078         if ($dsninfo['database'])
00079             $odbcdsn = $dsninfo['database'];
00080         elseif ($dsninfo['hostspec'])
00081             $odbcdsn = $dsninfo['hostspec'];
00082         else
00083             $odbcdsn = 'localhost';
00084 
00085         $user = @$dsninfo['username'];
00086         $pw = @$dsninfo['password'];
00087 
00088         $connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
00089 
00090         $conn = @$connect_function($odbcdsn, $user, $pw, SQL_CUR_USE_IF_NEEDED);
00091 
00092         if (!is_resource($conn))
00093             throw new SQLException('connect failed', $this->nativeError(), $odbcdsn);
00094 
00095         $this->dblink = $conn;
00096 
00103         @odbc_binmode(0, ODBC_BINMODE_PASSTHRU);
00104         @odbc_longreadlen(0, ini_get('odbc.defaultlrl'));
00105     }

ODBCConnection::createResultSet ( odbcresult,
fetchmode 
)

Creates the appropriate ResultSet.

Returns:
ResultSet

Definition at line 178 of file ODBCConnection.php.

References $odbcresult.

Referenced by executeQuery().

00179     {
00180         return $this->adapter->createResultSet($this, $odbcresult, $fetchmode);
00181     }

ODBCConnection::createStatement (  ) 

See also:
Connection::createStatement()

Implements Connection.

Definition at line 195 of file ODBCConnection.php.

00196     {
00197         require_once 'creole/drivers/odbc/ODBCStatement.php';
00198         return new ODBCStatement($this);
00199     }

ODBCConnection::executeQuery ( sql,
fetchmode = null 
)

See also:
Connection::executeQuery()

Implements Connection.

Definition at line 222 of file ODBCConnection.php.

References createResultSet(), and nativeError().

00223     {
00224         if ($this->odbcresult)
00225             $this->odbcresult = null;
00226 
00227         $r = @odbc_exec($this->dblink, $sql);
00228 
00229         if ($r === false)
00230             throw new SQLException('Could not execute query', $this->nativeError(), $sql);
00231 
00232         $this->odbcresult = new ODBCResultResource($r);
00233 
00234         return $this->createResultSet($this->odbcresult, $fetchmode);
00235     }

ODBCConnection::executeUpdate ( sql  ) 

See also:
Connection::executeUpdate()

Implements Connection.

Definition at line 240 of file ODBCConnection.php.

References getUpdateCount(), and nativeError().

00241     {
00242         if ($this->odbcresult)
00243             $this->odbcresult = null;
00244 
00245         $r = @odbc_exec($this->dblink, $sql);
00246 
00247         if ($r === false)
00248             throw new SQLException('Could not execute update', $this->nativeError(), $sql);
00249 
00250         $this->odbcresult = new ODBCResultResource($r);
00251 
00252         return $this->getUpdateCount();
00253     }

ODBCConnection::getAdapter (  ) 

Returns driver-specific ODBCAdapter.

Returns:
ODBCAdapter

Definition at line 152 of file ODBCConnection.php.

00153     {
00154         return $this->adapter;
00155     }

ODBCConnection::getDatabaseInfo (  ) 

See also:
Connection::getDatabaseInfo()

Implements Connection.

Definition at line 160 of file ODBCConnection.php.

00161     {
00162         require_once 'creole/drivers/odbc/metadata/ODBCDatabaseInfo.php';
00163         return new ODBCDatabaseInfo($this);
00164     }

ODBCConnection::getIdGenerator (  ) 

See also:
Connection::getIdGenerator()

Implements Connection.

Definition at line 169 of file ODBCConnection.php.

00170     {
00171         return $this->adapter->getIdGenerator($this);
00172     }

ODBCConnection::getUpdateCount (  ) 

See also:
Connection::getUpdateCount()

Implements Connection.

Definition at line 311 of file ODBCConnection.php.

References nativeError().

Referenced by executeUpdate().

00312     {
00313         if ($this->odbcresult === null)
00314             return 0;
00315 
00316         $n = @odbc_num_rows($this->odbcresult->getHandle());
00317 
00318         if ($n == -1)
00319             throw new SQLException('Could not retrieve update count', $this->nativeError());
00320 
00321         return (int) $n;
00322     }

ODBCConnection::nativeError (  ) 

Returns a formatted ODBC error string.

Returns:
string

Definition at line 138 of file ODBCConnection.php.

Referenced by beginTrans(), commitTrans(), connect(), executeQuery(), executeUpdate(), getUpdateCount(), and rollbackTrans().

00139     {
00140         if ($this->dblink && is_resource($this->dblink))
00141             $errstr = '[' . @odbc_error($this->dblink) . '] ' . @odbc_errormsg($this->dblink);
00142         else
00143             $errstr = '[' . @odbc_error() . '] ' . @odbc_errormsg();
00144 
00145         return $errstr;
00146     }

ODBCConnection::prepareCall ( sql  ) 

Todo:
To be implemented
See also:
Connection::prepareCall()

Reimplemented from ConnectionCommon.

Definition at line 205 of file ODBCConnection.php.

00206     {
00207         throw new SQLException('Stored procedures not currently implemented.');
00208     }

ODBCConnection::prepareStatement ( sql  ) 

See also:
Connection::prepareStatement()

Implements Connection.

Definition at line 186 of file ODBCConnection.php.

00187     {
00188         require_once 'creole/drivers/odbc/ODBCPreparedStatement.php';
00189         return new ODBCPreparedStatement($this, $sql);
00190     }

ODBCConnection::rollbackTrans (  )  [protected]

Roll back (undo) the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 294 of file ODBCConnection.php.

References $result, and nativeError().

00295     {
00296         if ($this->adapter->supportsTransactions()) {
00297             $result = @odbc_rollback($this->dblink);
00298             if (!$result) {
00299                 throw new SQLException('Could not rollback transaction', $this->nativeError());
00300             }
00301             @odbc_autocommit($this->dblink, true);
00302             if (odbc_error($this->dblink) == 'S1C00') {
00303                 throw new SQLException('Could not rollback transaction (autocommit failed)', $this->nativeError());
00304             }
00305         }
00306     }


Member Data Documentation

ODBCConnection::$adapter = null [protected]

Definition at line 39 of file ODBCConnection.php.

ODBCConnection::$odbcresult = null [protected]

Definition at line 45 of file ODBCConnection.php.

Referenced by createResultSet().


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