keep sqlite3.h dependency in Connection.cpp and PreparedStatement.cpp only II v_0 v0.15
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 31 Jan 2020 23:22:56 +0100
branchv_0
changeset 30 629565ff82d3
parent 29 b0ef1e1dc9c8
child 31 e047122fe52b
keep sqlite3.h dependency in Connection.cpp and PreparedStatement.cpp only II
src/Connection.cpp
src/Connection.h
src/PreparedStatement.cpp
src/PreparedStatement.h
--- a/src/Connection.cpp	Wed Dec 25 01:37:05 2019 +0100
+++ b/src/Connection.cpp	Fri Jan 31 23:22:56 2020 +0100
@@ -24,32 +24,32 @@
 namespace sql {
 
 void Connection::begin() {
-	sqlite3_exec(db, "BEGIN", nullptr, nullptr, nullptr);
+	sqlite3_exec((sqlite3*) db, "BEGIN", nullptr, nullptr, nullptr);
 }
 
 Connection::Connection(const char* filename) {
-	int result = sqlite3_open(filename, &db);
+	int result = sqlite3_open(filename, (sqlite3**) & db);
 	if (result != SQLITE_OK) {
-		sqlite3_close(db);
+		sqlite3_close((sqlite3*) db);
 		throw SqlException(L"Unable to open SQLite database.");
 	}
 	begin();
 }
 
 Connection::~Connection() {
-	sqlite3_close(db);
+	sqlite3_close((sqlite3*) db);
 }
 
 PreparedStatement* Connection::prepareStatement(const char* sql) {
 	const char* remaining;
 	sqlite3_stmt *stmt;
-	int result = sqlite3_prepare(db, sql, -1, &stmt, &remaining);
+	int result = sqlite3_prepare((sqlite3*) db, sql, -1, &stmt, &remaining);
 	if (result == SQLITE_OK) return new PreparedStatement(stmt);
 	else throw SqlException(L"Unable to prepare SQLite statement.");
 }
 
 bool Connection::getAutoCommit() {
-	return sqlite3_get_autocommit(db);
+	return sqlite3_get_autocommit((sqlite3*) db);
 }
 
 void Connection::setAutoCommit(bool autoCommit) {
@@ -59,11 +59,11 @@
 }
 
 void Connection::commit() {
-	sqlite3_exec(db, "COMMIT", nullptr, nullptr, nullptr);
+	sqlite3_exec((sqlite3*) db, "COMMIT", nullptr, nullptr, nullptr);
 }
 
 void Connection::rollback() {
-	sqlite3_exec(db, "ROLLBACK", nullptr, nullptr, nullptr);
+	sqlite3_exec((sqlite3*) db, "ROLLBACK", nullptr, nullptr, nullptr);
 }
 
 }
--- a/src/Connection.h	Wed Dec 25 01:37:05 2019 +0100
+++ b/src/Connection.h	Fri Jan 31 23:22:56 2020 +0100
@@ -25,7 +25,7 @@
 
 class Connection {
 private:
-	sqlite3* db;
+	void* db;
 	void begin();
 public:
 	Connection(const char* filename); // TODO: add DriverManager class + support connecting using a DSN or a connectString
--- a/src/PreparedStatement.cpp	Wed Dec 25 01:37:05 2019 +0100
+++ b/src/PreparedStatement.cpp	Fri Jan 31 23:22:56 2020 +0100
@@ -25,57 +25,57 @@
 namespace tr {
 namespace sql {
 
-PreparedStatement::PreparedStatement(sqlite3_stmt* stmt) : stmt(stmt) {
+PreparedStatement::PreparedStatement(void* stmt) : stmt(stmt) {
 }
 
 PreparedStatement::~PreparedStatement() {
-	sqlite3_finalize(stmt);
+	sqlite3_finalize((sqlite3_stmt*) stmt);
 }
 
 void PreparedStatement::setBoolean(int parameterIndex, relpipe::reader::boolean_t value) {
-	int result = sqlite3_bind_int(stmt, parameterIndex, value);
+	int result = sqlite3_bind_int((sqlite3_stmt*) stmt, parameterIndex, value);
 	if (result != SQLITE_OK) throw SqlException(L"Unable to set SQLite parameter.");
 }
 
 void PreparedStatement::setInteger(int parameterIndex, relpipe::reader::integer_t value) {
-	int result = sqlite3_bind_int64(stmt, parameterIndex, value);
+	int result = sqlite3_bind_int64((sqlite3_stmt*) stmt, parameterIndex, value);
 	if (result != SQLITE_OK) throw SqlException(L"Unable to set SQLite parameter.");
 }
 
 void PreparedStatement::setString(int parameterIndex, std::string value) {
-	int result = sqlite3_bind_text(stmt, parameterIndex, value.c_str(), -1, SQLITE_TRANSIENT);
+	int result = sqlite3_bind_text((sqlite3_stmt*) stmt, parameterIndex, value.c_str(), -1, SQLITE_TRANSIENT);
 	if (result != SQLITE_OK) throw SqlException(L"Unable to set SQLite parameter.");
 }
 
 void PreparedStatement::setNull(int parameterIndex) {
-	int result = sqlite3_bind_null(stmt, parameterIndex);
+	int result = sqlite3_bind_null((sqlite3_stmt*) stmt, parameterIndex);
 	if (result != SQLITE_OK) throw SqlException(L"Unable to set SQLite parameter.");
 }
 
 bool PreparedStatement::next() {
-	int result = sqlite3_step(stmt);
+	int result = sqlite3_step((sqlite3_stmt*) stmt);
 	if (result == SQLITE_ROW) return true;
 	else if (result == SQLITE_DONE) return false;
 	else throw SqlException(L"Error while iterating over SQLite result.");
 }
 
 void PreparedStatement::reset() {
-	int result = sqlite3_reset(stmt);
+	int result = sqlite3_reset((sqlite3_stmt*) stmt);
 	if (result != SQLITE_OK) throw SqlException(L"Unable to reset SQLite prepared statement.");
 }
 
 int PreparedStatement::getColumnCount() {
-	return sqlite3_column_count(stmt);
+	return sqlite3_column_count((sqlite3_stmt*) stmt);
 }
 
 std::string PreparedStatement::getColumName(int columnIndex) {
-	const char* name = sqlite3_column_name(stmt, columnIndex);
+	const char* name = sqlite3_column_name((sqlite3_stmt*) stmt, columnIndex);
 	if (name) return name;
 	else throw SqlException(L"Unable to get SQLite column name.");
 }
 
 relpipe::writer::TypeId PreparedStatement::getColumType(int columnIndex, relpipe::writer::TypeId defaultType) {
-	const char* type = sqlite3_column_decltype(stmt, columnIndex);
+	const char* type = sqlite3_column_decltype((sqlite3_stmt*) stmt, columnIndex);
 
 	// TODO: sqlite3_column_decltype returns value only for columns of existing tables, not for dynamic expressions – SQLite uses dynamic types
 	// maybe we could write a function/module that returns result set metadata for given query (before executing it)
@@ -97,7 +97,7 @@
 }
 
 std::string PreparedStatement::getString(int columnIndex) {
-	const char* value = (const char*) sqlite3_column_text(stmt, columnIndex);
+	const char* value = (const char*) sqlite3_column_text((sqlite3_stmt*) stmt, columnIndex);
 	return value ? value : ""; // TODO: support NULL values (when supported in relpipe format)
 }
 
--- a/src/PreparedStatement.h	Wed Dec 25 01:37:05 2019 +0100
+++ b/src/PreparedStatement.h	Fri Jan 31 23:22:56 2020 +0100
@@ -27,9 +27,9 @@
 
 class PreparedStatement {
 private:
-	sqlite3_stmt* stmt;
+	void* stmt;
 public:
-	PreparedStatement(sqlite3_stmt* stmt);
+	PreparedStatement(void* stmt);
 	virtual ~PreparedStatement();
 	void setBoolean(int parameterIndex, relpipe::reader::boolean_t value);
 	void setInteger(int parameterIndex, relpipe::reader::integer_t value);