src/SqlHandler.h
branchv_0
changeset 27 9441a517fa1f
parent 26 49919a60c747
child 29 b0ef1e1dc9c8
--- a/src/SqlHandler.h	Wed Dec 25 00:57:26 2019 +0100
+++ b/src/SqlHandler.h	Wed Dec 25 01:07:41 2019 +0100
@@ -39,6 +39,7 @@
 #include "Configuration.h"
 #include "SqlException.h"
 #include "PreparedStatement.h"
+#include "Connection.h"
 
 namespace relpipe {
 namespace tr {
@@ -49,57 +50,6 @@
 using namespace relpipe::reader;
 using namespace relpipe::reader::handlers;
 
-class Connection {
-private:
-	sqlite3* db;
-
-	void begin() {
-		sqlite3_exec(db, "BEGIN", nullptr, nullptr, nullptr);
-	}
-
-public:
-
-	Connection(const char* filename) {
-		int result = sqlite3_open(filename, &db);
-		if (result != SQLITE_OK) {
-			sqlite3_close(db);
-			throw SqlException(L"Unable to open SQLite database.");
-		}
-		begin();
-	}
-
-	virtual ~Connection() {
-		sqlite3_close(db);
-	}
-
-	PreparedStatement* prepareStatement(const char* sql) {
-		const char* remaining;
-		sqlite3_stmt *stmt;
-		int result = sqlite3_prepare(db, sql, -1, &stmt, &remaining);
-		if (result == SQLITE_OK) return new PreparedStatement(stmt);
-		else throw SqlException(L"Unable to prepare SQLite statement.");
-	}
-
-	bool getAutoCommit() {
-		return sqlite3_get_autocommit(db);
-	}
-
-	void setAutoCommit(bool autoCommit) {
-		bool autoCommitOld = getAutoCommit();
-		if (autoCommit && !autoCommitOld) commit();
-		else if (!autoCommit && autoCommitOld) begin();
-	}
-
-	void commit() {
-		sqlite3_exec(db, "COMMIT", nullptr, nullptr, nullptr);
-	}
-
-	void rollback() {
-		sqlite3_exec(db, "ROLLBACK", nullptr, nullptr, nullptr);
-	}
-
-};
-
 class SqlHandler : public RelationalReaderValueHandler {
 private:
 	Configuration configuration;