summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/db/connection.h10
-rw-r--r--include/db/statement.h51
2 files changed, 56 insertions, 5 deletions
diff --git a/include/db/connection.h b/include/db/connection.h
index b3143e4..b46c133 100644
--- a/include/db/connection.h
+++ b/include/db/connection.h
@@ -46,16 +46,20 @@ public:
return Statement(m_connection, statement);
}
+ int Execute(const std::string& stmt){
+ return Prepare(stmt).Execute();
+ }
+
void BeginTransaction(){
- Prepare("BEGIN TRANSACTION").execute();
+ Execute("BEGIN TRANSACTION");
}
void CommitTransaction(){
- Prepare("COMMIT TRANSACTION").execute();
+ Execute("COMMIT TRANSACTION");
}
void RollbackTransaction(){
- Prepare("ROLLBACK TRANSACTION").execute();
+ Execute("ROLLBACK TRANSACTION");
}
};
diff --git a/include/db/statement.h b/include/db/statement.h
index 8c2ade2..22da47c 100644
--- a/include/db/statement.h
+++ b/include/db/statement.h
@@ -29,9 +29,56 @@ public:
virtual ~Statement(){}
- Statement& execute(){
- if(sqlite3_step(m_statement.get()) != SQLITE_OK)
+ void Reset(){
+ if(sqlite3_reset(m_statement.get()) != SQLITE_OK)
throw SQLiteException(sqlite3_errmsg(m_connection.get()));
+ }
+
+ int Execute(){
+ int ret = sqlite3_step(m_statement.get());
+
+ if(ret != SQLITE_OK && ret != SQLITE_DONE )
+ throw SQLiteException(sqlite3_errmsg(m_connection.get()));
+
+ int numChanges = sqlite3_changes(m_connection.get());
+
+ Reset();
+
+ return numChanges;
+ }
+
+ int GetBindIndex(const std::string& col){
+ int index = 0;
+
+ return index;
+ }
+
+ Statement& SetNull(const std::string& c){
+ int col = GetBindIndex(c);
+
+ return *this;
+ }
+
+ Statement& SetString(const std::string& c, const std::string& value){
+ int col = GetBindIndex(c);
+
+ return *this;
+ }
+
+ Statement& SetLong(const std::string& c, long value){
+ int col = GetBindIndex(c);
+
+ return *this;
+ }
+
+ Statement& SetDouble(const std::string& c, double value){
+ int col = GetBindIndex(c);
+
+ return *this;
+ }
+
+ Statement& SetBlob(const std::string& c, const char* buf, size_t bufLen){
+ int col = GetBindIndex(c);
return *this;
}