dal::DataProvider Class Reference

An abstract data provider. More...

#include <dataprovider.h>

Inheritance diagram for dal::DataProvider:

dal::MySqlDataProvider dal::PqDataProvider dal::SqLiteDataProvider

List of all members.

Public Member Functions

 DataProvider (void) throw ()
 Constructor.
virtual ~DataProvider (void) throw ()
 Destructor.
bool isConnected (void) const throw ()
 Get the connection status.
virtual DbBackends getDbBackend (void) const =0 throw ()
 Get the name of the database backend.
virtual void connect (void)=0
 Create a connection to the database.
virtual const RecordSetexecSql (const std::string &sql, const bool refresh=false)=0
 Execute a SQL query.
virtual void disconnect (void)=0
 Close the connection to the database.
std::string getDbName (void)
 Get the Database Name.
virtual void beginTransaction (void)=0 throw (std::runtime_error)
 Starts a transaction.
virtual void commitTransaction (void)=0 throw (std::runtime_error)
 Commits a transaction.
virtual void rollbackTransaction (void)=0 throw (std::runtime_error)
 Rollback a transaction.
virtual const unsigned int getModifiedRows (void) const =0
 Returns the number of changed rows by the last executed SQL statement.
virtual const unsigned int getLastId (void) const =0
 Returns the last inserted value of an autoincrement column after an INSERT statement.
std::string & escapeSQL (std::string &sql)
 Takes a SQL snippet and escapes special caharacters like ' to prevent SQL injection attacks.

Protected Attributes

std::string mDbName
 the database name
bool mIsConnected
 the connection status
std::string mSql
 cache the last SQL query
RecordSet mRecordSet
 cache the result of the last SQL query


Detailed Description

An abstract data provider.

Notes:

Limitations:

Definition at line 56 of file dataprovider.h.


Member Function Documentation

bool dal::DataProvider::isConnected ( void   )  const throw ()

Get the connection status.

Returns:
true if connected.

Definition at line 54 of file dataprovider.cpp.

References mIsConnected.

Referenced by dal::SqLiteDataProvider::disconnect(), getDbName(), DALStorage::open(), and DALStorage::~DALStorage().

virtual DbBackends dal::DataProvider::getDbBackend ( void   )  const throw () [pure virtual]

Get the name of the database backend.

Returns:
the database backend name.

Implemented in dal::MySqlDataProvider, dal::PqDataProvider, and dal::SqLiteDataProvider.

virtual void dal::DataProvider::connect ( void   )  [pure virtual]

Create a connection to the database.

Each dataprovider is responsible to have default values and load necessary options from the config file.

Exceptions:
DbConnectionFailure if unsuccessful connection.

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::open().

virtual const RecordSet& dal::DataProvider::execSql ( const std::string &  sql,
const bool  refresh = false 
) [pure virtual]

virtual void dal::DataProvider::disconnect ( void   )  [pure virtual]

Close the connection to the database.

Exceptions:
DbDisconnectionFailure if unsuccessful disconnection.

Implemented in dal::MySqlDataProvider, dal::PqDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::close().

std::string dal::DataProvider::getDbName ( void   ) 

Get the Database Name.

Get the DataBase Name.

Definition at line 64 of file dataprovider.cpp.

References isConnected(), and mDbName.

virtual void dal::DataProvider::beginTransaction ( void   )  throw (std::runtime_error) [pure virtual]

Starts a transaction.

Exceptions:
std::runtime_error if a transaction is still open

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::addAccount(), DALStorage::delCharacter(), DALStorage::deletePost(), DALStorage::flush(), and DALStorage::updateCharacter().

virtual void dal::DataProvider::commitTransaction ( void   )  throw (std::runtime_error) [pure virtual]

Commits a transaction.

Exceptions:
std::runtime_error if no connection is currently open.

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::addAccount(), DALStorage::delCharacter(), DALStorage::deletePost(), DALStorage::flush(), and DALStorage::updateCharacter().

virtual void dal::DataProvider::rollbackTransaction ( void   )  throw (std::runtime_error) [pure virtual]

Rollback a transaction.

Exceptions:
std::runtime_error if no connection is currently open.

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::addAccount(), DALStorage::delCharacter(), DALStorage::deletePost(), DALStorage::flush(), and DALStorage::updateCharacter().

virtual const unsigned int dal::DataProvider::getModifiedRows ( void   )  const [pure virtual]

Returns the number of changed rows by the last executed SQL statement.

Returns:
Number of rows that have changed.

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::setWorldStateVar(), DALStorage::storeLetter(), and DALStorage::updateExperience().

virtual const unsigned int dal::DataProvider::getLastId ( void   )  const [pure virtual]

Returns the last inserted value of an autoincrement column after an INSERT statement.

Returns:
last autoincrement value.

Implemented in dal::MySqlDataProvider, and dal::SqLiteDataProvider.

Referenced by DALStorage::addAccount(), DALStorage::flush(), and DALStorage::storeLetter().

std::string & dal::DataProvider::escapeSQL ( std::string &  sql  ) 

Takes a SQL snippet and escapes special caharacters like ' to prevent SQL injection attacks.

Parameters:
sql SQL Snippet to escape.

Definition at line 75 of file dataprovider.cpp.


The documentation for this class was generated from the following files:

Generated on Sun Apr 26 17:30:47 2009 for TMW Server Collection by  doxygen 1.5.5