dtl


DBConnection

Category: utilities Component type: type

Description

The DBConnection class provides a mechanism to manage ODBC connections to a database.

Definition

Defined in the DBConnection.h header file.

Refinement of

None.

Associated types

None.

Example: Connecting to a database

int main(int argc, char **argv)
{
  DBConnection::GetDefaultConnection().Connect("UID=example;PWD=example;DSN=example;");

}

Public Base Classes

ValidatedObject

Notation

X A type that is a model of DBConnection
a Object of type X

Expression semantics

Name Expression Precondition Semantics Postcondition
Constructor
X a()
  Creates an empty database connection object. The connection object cannot be used until it has been intialized with a Connect() call  
Connect with DSN string
void Connect(const string &s)
  Creates a database connection using the ODBC connect string contained in s valid database connection - throw if error encountered
Connect using previous DSN void Connect()   Connects using the previous DSN. valid database connection - throw if error encountered
Get the default connection object
static DBConnection &
   GetDefaultConnection()
  Get the default connection object. Returns a static member of the DBConnection class used to hold the default connection object for the library. This default connection object is used as the default connection object by DBStmt, DBView and IndexedDBView if no explicit connection parameter is specified in their constructors.  
Get the default environment object
static DBEnvironment &
   GetDefaultEnvironment()
  Get the environment object for this connection. Returns a static member of the DBConnection class used to hold the default environment object for the library. To manually release the environment, simply call DBEnvironment::Release().
Connection status bool IsConnected() const   Is this object referencing an active connection?  
Toggle autocommit void SetAutoCommit(bool commit)   Turns autocommit on or off for this connection.  
Get autocommit bool GetAutoCommit() const   Is autocommit enabled for this connection?  
Commit all outstanding transactions
void CommitAll()
  Commit all outstanding transactions against the database.  
Commit all outstanding transactions
void RollbackAll()
  Rollback all outstanding transactions against the database.  
Release this connection void Release()   Releases the connecton and all associated ODBC resources.  
Get the raw ODBC HENV handle for the connection
HENV GetHENV() const
  Returns the raw ODBC HENV handle.  
Get the raw ODBC HDBC handle for the connection
HDBC GetHDBC() const
  Returns the raw ODBC HDBC handle.  
Get the DSN string used by the connection.
string GetDSN() const
  Returns the raw ODBC DSN string used by the connection.  
Swap with another connection
void swap(DBConnection &other)
  Swap *this with other.  
Reference another connection void Share(HENV new_henv, HDBC new_hdbc)   Releases old connection and makes *this refer to the already active connection denoted by the passed in environment and connection handle pair. Once this connection is released, in order to reconnect using this same object, you must use the Connect(const string &) member.  

Notes

See also

DBStmt, DBView, IndexedDBView, ValidatedObject


[DTL Home]

Copyright © 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

This site written using the ORB. [The ORB]

1