Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::DbConnection Class Reference

A class for managing a database connection. More...

#include <dbconnection.h>

List of all members.

Public Types

enum  ConnectionStyle { DEFAULT, AUTO_COMMIT, PERSISTENT_READ_ONLY }
 Connection Style. More...


Public Methods

 DbConnection (const LookString &theDatabaseName="", const LookString &theUser="", const LookString &thePassword="")
 Constructor. More...

 DbConnection (const DbConnection &theConnection)
 Copy Constructor. More...

virtual ~DbConnection ()
 Destructor.

bool Connect (void)
 Open a connection to the database. More...

void Disconnect (void)
 Disconnect a connection from the database. More...

bool Commit (void) const
 Commit a transaction. More...

bool Rollback (void) const
 Rollback a transaction. More...

void SetConnectionStyle (ConnectionStyle theConnectionStyle)
ConnectionStyle GetConnectionStyle (void)
LOOK_DBC GetSession (void)
 Get the session for use in interface layer functions.


Static Public Methods

void TerminateConnections (void)
 Tidy up all my connections. More...

DbConnection* GetGlobalConnection (void)
 Access to the global connection. More...

void SetGlobalConnection (DbConnection *theConnection)
 Set the global connection. More...


Protected Attributes

LookString itsDatabaseName
LookString itsUser
LookString itsPassword
LOOK_DBC itsSessionNumber
bool itIsConnected
ConnectionStyle itsConnectionStyle

Static Protected Attributes

DbConnection* itsGlobalConnection
ConnectionList itsConnections


Detailed Description

A class for managing a database connection.

This class manages connections to a database. Methods are provided for connecting, disconnecting, managing transactions, and switching between different connections.


Member Enumeration Documentation

enum look::DbConnection::ConnectionStyle
 

Connection Style.

Enumeration values:
DEFAULT   Normal
AUTO_COMMIT   Commit after every SQL statement
PERSISTENT_READ_ONLY   This does not enforce read only, but it is for a connection which will be around a long time (eg global connection).

Under unix a new connection is created for each new query.

(this is necessary for Ingres otherwise the database fills up with all the prepared statements. This is really the only reason this exists!


Constructor & Destructor Documentation

look::DbConnection::DbConnection ( const LookString & theDatabaseName = "",
const LookString & theUser = "",
const LookString & thePassword = "" )
 

Constructor.

The constructor makes a DbConnection object ready for use. It does not establish a connection - this is done via the Connect() method.

Parameters:
theDatabaseName   The name of the database
theUser   The username to use for connecting. If empty, the current login name will be used.
thePassword   The password to use for the connection if required.
Returns:
None (constructor)

look::DbConnection::DbConnection ( const DbConnection & theConnection )
 

Copy Constructor.

The copy constructor makes the new one based on the old one apart from the connection style.

Parameters:
theConnection   The connection to be copied.
Returns:
None (constructor)


Member Function Documentation

bool look::DbConnection::Commit ( void ) const
 

Commit a transaction.

Commit the current transaction on the current database connection.

Returns:
true if successful

bool look::DbConnection::Connect ( void )
 

Open a connection to the database.

Returns:
true if successful

void look::DbConnection::Disconnect ( void )
 

Disconnect a connection from the database.

The connection to the database is closed. There is no explicit commit or rollback.

Returns:
none

DbConnection * look::DbConnection::GetGlobalConnection ( void ) [static]
 

Access to the global connection.

Returns:
A pointer to the global connection

bool look::DbConnection::Rollback ( void ) const
 

Rollback a transaction.

Rollback the current transaction on the current database connection.

Returns:
true if successful

void look::DbConnection::SetGlobalConnection ( DbConnection * theConnection ) [static]
 

Set the global connection.

The global connection is used by default by the library. There is no error checking (for example as to whether the connection is open).

This must be set before you use DbQuery and DbField.

Parameters:
theConnection   A pointer to the global connection
Returns:
none

void look::DbConnection::TerminateConnections ( void ) [static]
 

Tidy up all my connections.

All connections are recorded by DbConnection. This disconnects and deletes them.

Because of the delete, this should only be called when you no longer know about any of the connections, eg if you're in trouble.

It will probably crash if you have any DbConnections on the stack.

Returns:
none


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:07 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001