aboutsummaryrefslogtreecommitdiffstats
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/base/database.cpp20
-rw-r--r--src/base/database.hpp6
2 files changed, 14 insertions, 12 deletions
diff --git a/src/base/database.cpp b/src/base/database.cpp
index 3d1580e2..ed19a399 100644
--- a/src/base/database.cpp
+++ b/src/base/database.cpp
@@ -75,6 +75,13 @@ namespace usdx
return sqliteStatement;
}
+ void StatDatabase::sqlite_exec(const std::string sqlStatement)
+ {
+ sqlite3_stmt *sqliteStatement = sqlite_prepare(sqlStatement);
+ sqlite3_step(sqliteStatement);
+ sqlite3_finalize(sqliteStatement);
+ }
+
void StatDatabase::init(const std::string filename)
{
LOG4CXX_DEBUG(log, "Initializing Database: " << filename);
@@ -197,19 +204,8 @@ namespace usdx
// format the PRAGMA statement (PRAGMA does _not_ support parameters)
std::ostringstream sqlStatementBuffer (std::ostringstream::out);
sqlStatementBuffer << "PRAGMA user_version = " << version << ";";
- std::string sqlStatement = sqlStatementBuffer.str();
-
- sqlite3_stmt *sqliteStatement;
- if (SQLITE_OK != sqlite3_prepare_v2(database, sqlStatement.c_str(), sqlStatement.length(), &sqliteStatement, NULL)) {
- sqlite3_finalize(sqliteStatement);
-
- LOG4CXX_ERROR(log, "Error '" << sqlite3_errmsg(database) << "' in SQL '" << sqlStatement << "'");
- throw "Error preparing statement.";
- }
- sqlite3_bind_int(sqliteStatement, 1, version);
- sqlite3_step(sqliteStatement);
- sqlite3_finalize(sqliteStatement);
+ sqlite_exec(sqlStatementBuffer.str());
}
/* void StatDatabase::read_score(Song *song)
diff --git a/src/base/database.hpp b/src/base/database.hpp
index c984fcfd..3bf699ad 100644
--- a/src/base/database.hpp
+++ b/src/base/database.hpp
@@ -66,6 +66,12 @@ namespace usdx
*/
sqlite3_stmt *sqlite_prepare(const std::string sqlStatement);
+ /**
+ * Just a quick alias for sqlite_prepare, sqlite3_step and
+ * sqlite3_finalize.
+ */
+ void sqlite_exec(const std::string sqlStatement);
+
// Singleton
StatDatabase(std::string filename);