#include <dataprovider.h>
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 RecordSet & | execSql (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 |
Notes:
Limitations:
Definition at line 56 of file dataprovider.h.
bool dal::DataProvider::isConnected | ( | void | ) | const throw () |
Get the connection status.
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.
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.
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] |
Execute a SQL query.
sql | the SQL query. | |
refresh | if true, refresh the cache (default = false). |
DbSqlQueryExecFailure | if unsuccessful execution. | |
std::runtime_error | if trying to query a closed database. |
Implemented in dal::MySqlDataProvider, dal::PqDataProvider, and dal::SqLiteDataProvider.
Referenced by DALStorage::addAccount(), DALStorage::addGuild(), DALStorage::addGuildMember(), DALStorage::addTransaction(), DALStorage::banCharacter(), DALStorage::checkBannedAccounts(), DALStorage::delAccount(), DALStorage::delCharacter(), DALStorage::deletePost(), DALStorage::doesCharacterNameExist(), DALStorage::doesEmailAddressExist(), DALStorage::doesUserNameExist(), DALStorage::flush(), DALStorage::getGuildList(), DALStorage::getQuestVar(), DALStorage::getStoredPost(), DALStorage::getTransactions(), DALStorage::getWorldStateVar(), DALStorage::open(), DALStorage::removeGuild(), DALStorage::removeGuildMember(), DALStorage::setAccountLevel(), DALStorage::setMemberRights(), DALStorage::setOnlineStatus(), DALStorage::setPlayerLevel(), DALStorage::setQuestVar(), DALStorage::setWorldStateVar(), DALStorage::storeLetter(), DALStorage::updateCharacter(), DALStorage::updateCharacterPoints(), DALStorage::updateExperience(), and DALStorage::updateLastLogin().
virtual void dal::DataProvider::disconnect | ( | void | ) | [pure virtual] |
Close the connection to the database.
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.
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.
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.
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.
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.
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.
sql | SQL Snippet to escape. |
Definition at line 75 of file dataprovider.cpp.