summaryrefslogtreecommitdiff
path: root/src/dal/sqlitedataprovider.h
diff options
context:
space:
mode:
authorAndreas Habel <mail@exceptionfault.de>2008-09-17 11:32:45 +0000
committerAndreas Habel <mail@exceptionfault.de>2008-09-17 11:32:45 +0000
commita2af298fd993a129b657671a41f20e3975baf0ef (patch)
tree9e99436db881465af9738a6637ece7ef6b05fe5f /src/dal/sqlitedataprovider.h
parentfb677eeec95d583b8b1928a907c815c95f8c4594 (diff)
downloadmanaserv-a2af298fd993a129b657671a41f20e3975baf0ef.tar.gz
manaserv-a2af298fd993a129b657671a41f20e3975baf0ef.tar.bz2
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/sqlitedataprovider.h')
-rw-r--r--src/dal/sqlitedataprovider.h78
1 files changed, 69 insertions, 9 deletions
diff --git a/src/dal/sqlitedataprovider.h b/src/dal/sqlitedataprovider.h
index b791025b..ea85d027 100644
--- a/src/dal/sqlitedataprovider.h
+++ b/src/dal/sqlitedataprovider.h
@@ -25,13 +25,21 @@
#include <iosfwd>
#include <sqlite3.h>
+#include "common/configuration.hpp"
+
+
+// sqlite3_int64 is the preferred new datatype for 64-bit int values.
+// see: http://www.sqlite.org/capi3ref.html#sqlite3_int64
+#ifndef sqlite3_int64
+typedef sqlite_int64 sqlite3_int64;
+#endif
+
#include "dataprovider.h"
namespace dal
{
-
/**
* A SQLite Data Provider.
*/
@@ -65,16 +73,9 @@ class SqLiteDataProvider: 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();
/**
@@ -101,8 +102,67 @@ class SqLiteDataProvider: 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 database config parameter */
+ static const std::string CFGPARAM_SQLITE_DB;
+ /** defines the default value of the CFGPARAM_SQLITE_DB parameter */
+ static const std::string CFGPARAM_SQLITE_DB_DEF;
+
+ /**
+ * Returns wheter the connection has a open transaction or is in auto-
+ * commit mode.
+ *
+ * @return true, if a transaction is open.
+ */
+ const bool
+ inTransaction(void) const;
+
sqlite3* mDb; /**< the handle to the database connection */
};