diff options
author | Andreas Habel <mail@exceptionfault.de> | 2008-09-17 11:32:45 +0000 |
---|---|---|
committer | Andreas Habel <mail@exceptionfault.de> | 2008-09-17 11:32:45 +0000 |
commit | a2af298fd993a129b657671a41f20e3975baf0ef (patch) | |
tree | 9e99436db881465af9738a6637ece7ef6b05fe5f /src/dal/mysqldataprovider.h | |
parent | fb677eeec95d583b8b1928a907c815c95f8c4594 (diff) | |
download | manaserv-a2af298fd993a129b657671a41f20e3975baf0ef.tar.gz manaserv-a2af298fd993a129b657671a41f20e3975baf0ef.tar.xz manaserv-a2af298fd993a129b657671a41f20e3975baf0ef.zip |
* Added installation scripts to set up database schemas for mysql, sqlite and postgresql. The create table statements have been completely removed out from the c++ source into separate, provider specific sql files. Accountserver will no longer create a sqlite file if none present.
* Added database specific config parameters to configure each provider independent.
* Simplified the connect routine of DALStorage class since every dataprovider is now responsible to retrieve its own parameters.
* Extended abstract dataprovider to support transactions, functionally implemented for SQLite and mySQL.
* Added methods to retrieve last inserted auto-increment value and the number of modified rows by the last statement.
* Rewrite of DALStorage class to be a little more transactional.
* Fixed a bug when deleting a character. Old function left data in quests table and guilds table.
* Doxygen now also includes non-documented functions and provides a dictionary for all classes
Diffstat (limited to 'src/dal/mysqldataprovider.h')
-rw-r--r-- | src/dal/mysqldataprovider.h | 94 |
1 files changed, 85 insertions, 9 deletions
diff --git a/src/dal/mysqldataprovider.h b/src/dal/mysqldataprovider.h index f246603..08c56dd 100644 --- a/src/dal/mysqldataprovider.h +++ b/src/dal/mysqldataprovider.h @@ -26,10 +26,15 @@ #include <iosfwd> - +// added to compile under windows +#ifdef WIN32 +#include <winsock2.h> +#endif #include <mysql/mysql.h> #include "dataprovider.h" +#include "common/configuration.hpp" +#include "utils/logger.h" namespace dal { @@ -41,6 +46,16 @@ namespace dal class MySqlDataProvider: public DataProvider { public: + + /** + * Replacement for mysql my_bool datatype used in mysql_autocommit() + * function. + */ + enum { + AUTOCOMMIT_OFF = 0, + AUTOCOMMIT_ON = 1 + }; + /** * Constructor. */ @@ -68,16 +83,9 @@ class MySqlDataProvider: public DataProvider /** * Create a connection to the database. * - * @param dbName the database name. - * @param userName the user name. - * @param password the user password. - * * @exception DbConnectionFailure if unsuccessful connection. */ - void - connect(const std::string& dbName, - const std::string& userName, - const std::string& password); + void connect(); /** @@ -104,8 +112,76 @@ class MySqlDataProvider: public DataProvider void disconnect(void); + /** + * Starts a transaction. + * + * @exception std::runtime_error if a transaction is still open + */ + void + beginTransaction(void) + throw (std::runtime_error); + + /** + * Commits a transaction. + * + * @exception std::runtime_error if no connection is currently open. + */ + void + commitTransaction(void) + throw (std::runtime_error); + + /** + * Rollback a transaction. + * + * @exception std::runtime_error if no connection is currently open. + */ + void + rollbackTransaction(void) + throw (std::runtime_error); + + /** + * Returns the number of changed rows by the last executed SQL + * statement. + * + * @return Number of rows that have changed. + */ + const unsigned int + getModifiedRows(void) const; + + /** + * Returns the last inserted value of an autoincrement column after an + * INSERT statement. + * + * @return last autoincrement value. + */ + const unsigned int + getLastId(void) const; private: + + /** defines the name of the hostname config parameter */ + static const std::string CFGPARAM_MYSQL_HOST; + /** defines the name of the server port config parameter */ + static const std::string CFGPARAM_MYSQL_PORT; + /** defines the name of the database config parameter */ + static const std::string CFGPARAM_MYSQL_DB; + /** defines the name of the username config parameter */ + static const std::string CFGPARAM_MYSQL_USER; + /** defines the name of the password config parameter */ + static const std::string CFGPARAM_MYSQL_PWD; + + /** defines the default value of the CFGPARAM_MYSQL_HOST parameter */ + static const std::string CFGPARAM_MYSQL_HOST_DEF; + /** defines the default value of the CFGPARAM_MYSQL_PORT parameter */ + static const unsigned int CFGPARAM_MYSQL_PORT_DEF; + /** defines the default value of the CFGPARAM_MYSQL_DB parameter */ + static const std::string CFGPARAM_MYSQL_DB_DEF; + /** defines the default value of the CFGPARAM_MYSQL_USER parameter */ + static const std::string CFGPARAM_MYSQL_USER_DEF; + /** defines the default value of the CFGPARAM_MYSQL_PWD parameter */ + static const std::string CFGPARAM_MYSQL_PWD_DEF; + + MYSQL* mDb; /**< the handle to the database connection */ }; |