DB::Connection Class Reference

#include <db.h>

Inheritance diagram for DB::Connection:

DB::MySQL_Connection DB::Sqlite3_Connection List of all members.

Public Types

typedef Connection *(*) Connection_Creator (void)
 READ_UNCOMMITTED
 READ_COMMITTED
 REPEATABLE_READ
 SERIALIZABLE
enum  TRANS_MODE { READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE }

Public Member Functions

virtual ~Connection (void)
virtual bool open (const char *database, const char *host, const int port, const char *user, const char *pass)=0
virtual bool close (void)=0
virtual bool isConnected (void)=0
virtual bool execute (const char *sql)=0
virtual ResultSetexecuteQuery (const char *sql)=0
virtual char * escape (const char *)=0
virtual const char * unixtimeToSql (const time_t)=0
virtual const unsigned long insertId (void)=0
virtual bool beginTrans (void)=0
virtual bool commitTrans (void)=0
virtual bool rollbackTrans (void)=0
virtual bool setTransactionMode (const enum TRANS_MODE mode)=0
virtual unsigned int errorno (void) const =0
virtual const char * errormsg (void) const =0
virtual const char * version (void) const =0

Static Public Member Functions

static Connectionfactory (const char *db_dll_name)

Detailed Description

A Connection object is the base layer of database abstraction and are created by using the factory interface. When the Connection object returned from the factory is deleted, the class handles closing the database connection, although the user may do so if desired.

The classes are partially thread-safe in that a Connection object may be used in a single thread, but many Connection objects may be created in different threads. This is due to most database implementations following this same style of interface. For best portability, one should follow this same style of usage.

Definition at line 87 of file db.h.


Member Typedef Documentation

typedef Connection*(*) DB::Connection::Connection_Creator(void)

Definition at line 235 of file db.h.


Member Enumeration Documentation

enum DB::Connection::TRANS_MODE

Enumerator:
READ_UNCOMMITTED 
READ_COMMITTED  allows dirty reads, but fastest
REPEATABLE_READ  default postgres, mssql, and oci8
SERIALIZABLE  slowest and most restrictive

Definition at line 196 of file db.h.

00196                         {
00197             READ_UNCOMMITTED, 
00198             READ_COMMITTED, 
00199             REPEATABLE_READ, 
00200             SERIALIZABLE 
00201         };


Constructor & Destructor Documentation

virtual DB::Connection::~Connection ( void   )  [inline, virtual]

Definition at line 90 of file db.h.

00090 {};


Member Function Documentation

virtual bool DB::Connection::beginTrans ( void   )  [pure virtual]

Begins a new transaction. If for some reason it fails, false will be returned (for instance, if the underlying driver does not support transactions.)

Returns:
bool

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual bool DB::Connection::close ( void   )  [pure virtual]

Close the database connection

Returns:
bool True if successful.

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual bool DB::Connection::commitTrans ( void   )  [pure virtual]

Attempts to commit the current transaction

Returns:
bool

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual const char* DB::Connection::errormsg ( void   )  const [pure virtual]

Returns a textual representation of the last error to occur. The value returned should NOT be freed.

Returns:
const char*

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual unsigned int DB::Connection::errorno ( void   )  const [pure virtual]

Returns the last error code to occur.

Returns:
unsigned int

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual char* DB::Connection::escape ( const char *   )  [pure virtual]

Returns a database specific escaped string from the input. The string returned must be freed by the caller. This is used by the Query class.

Returns:
char*

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

Referenced by DB::qstr_impl().

virtual bool DB::Connection::execute ( const char *  sql  )  [pure virtual]

Executes a query to the database, discarding any result data. This function is typically used for non-SELECT statements.

Parameters:
sql 
Returns:
bool

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual ResultSet* DB::Connection::executeQuery ( const char *  sql  )  [pure virtual]

Executes a query to the database which returns row data. The row data is manipulated using the ResultSet object returned by this method. If the database wasn't able to return row data or an error occurs, then zero is returned. Therefore be careful to check the returned value, before using it - or a seg. fault is possible!

Parameters:
sql 
Returns:
ResultSet*

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

static Connection* DB::Connection::factory ( const char *  db_dll_name  )  [inline, static]

Factory method for creating a new Connection object for a database connection. This method shields the logic for DLL manipulation from the caller.

Warning: The returned Connection pointer may be NULL if an error condition occurred!

Parameters:
db_dll_name The database type to create
Returns:
Connection* Pointer to new Connection object

Definition at line 250 of file db.h.

References open().

00251         {
00252             ACE_DLL dll;
00253 
00254             int ret = dll.open(ACE_TEXT(db_dll_name),
00255                         ACE_DEFAULT_SHLIB_MODE,
00256                         0);
00257             if (ret != 0) {
00258                 ACE_ERROR_RETURN((LM_ERROR, "%p", "dll.open"), 0);
00259             }
00260             Connection_Creator cc;
00261             void *void_ptr = dll.symbol(ACE_TEXT("create_connection"));
00262             ptrdiff_t tmp = reinterpret_cast<ptrdiff_t>(void_ptr);
00263             cc = reinterpret_cast<Connection_Creator>(tmp);
00264             if (cc == NULL) {
00265                 ACE_ERROR_RETURN((LM_ERROR, "%p", "dll.symbol"), 0);
00266             }
00267             return (cc());
00268         }

virtual const unsigned long DB::Connection::insertId ( void   )  [pure virtual]

Returns the last SQL INSERT unique identifier if the underlying database supports this feature.

Returns:
const unsigned long

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual bool DB::Connection::isConnected ( void   )  [pure virtual]

Attempts to tell if we are still connected to the database.

Returns:
bool

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual bool DB::Connection::open ( const char *  database,
const char *  host,
const int  port,
const char *  user,
const char *  pass 
) [pure virtual]

Open a connection to a database.

Parameters:
database Database name. Sqlite3 uses this for the filename.
host Hostname
port Port
user Username
pass Password
Returns:
bool True if successful.

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

Referenced by factory().

virtual bool DB::Connection::rollbackTrans ( void   )  [pure virtual]

Attempts to rollback the current transaction

Returns:
bool

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

virtual bool DB::Connection::setTransactionMode ( const enum TRANS_MODE  mode  )  [pure virtual]

Sets the database transaction mode.

Parameters:
mode 
Returns:
bool True or False if it succeeded.

virtual const char* DB::Connection::unixtimeToSql ( const   time_t  )  [pure virtual]

Returns a database specific representation of the time_t value. This is used by the Query class. The string returned must be freed by the caller.

Parameters:
time_t 
Returns:
const char*

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.

Referenced by DB::unixtime_impl().

virtual const char* DB::Connection::version ( void   )  const [pure virtual]

Returns the DB abstraction module's version number and possibly the version of the underlying database client library used. The returned value should NOT be freed.

Returns:
const char*

Implemented in DB::MySQL_Connection, and DB::Sqlite3_Connection.


The documentation for this class was generated from the following file:
Generated on Tue Apr 24 18:59:42 2007 for DbAbstract by  doxygen 1.4.7