aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-10 21:44:58 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:44 +0100
commit1aef9df295fb16940ce896b78618ef49423db5bd (patch)
tree67dc698127b70c493bd8957b251dbd23625cf358 /src
parent5f504f2e89e95e70d9551ae9c99009d93af157f5 (diff)
downloadusdx-1aef9df295fb16940ce896b78618ef49423db5bd.tar.gz
usdx-1aef9df295fb16940ce896b78618ef49423db5bd.tar.xz
usdx-1aef9df295fb16940ce896b78618ef49423db5bd.zip
added warpper for sqlite_prepare, sqlite3_step and sqlite3_finalize
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);