From ec8de9482750e117a4d76ab79668c8e06053691d Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 1 May 2021 20:31:52 +0200 Subject: [PATCH] Little work on the sqlite database backend. --- database/sqlite/sqlite3_database.cpp | 25 ++++++++++++++++++++++++ database/sqlite/sqlite3_database.h | 18 +++++------------ database/sqlite/sqlite3_query_result.cpp | 17 ++++++++++++++++ database/sqlite/sqlite3_query_result.h | 17 ++++++++++++++++ 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 database/sqlite/sqlite3_query_result.cpp create mode 100644 database/sqlite/sqlite3_query_result.h diff --git a/database/sqlite/sqlite3_database.cpp b/database/sqlite/sqlite3_database.cpp index acc299c..2570fd9 100644 --- a/database/sqlite/sqlite3_database.cpp +++ b/database/sqlite/sqlite3_database.cpp @@ -13,3 +13,28 @@ void SQLite3Database::_register() { void SQLite3Database::_unregister() { DatabaseManager::_unregister_db_creation_func("sqlite"); } + +void SQLite3Database::connect(const std::string &connection_str) { + int ret = sqlite3_config(SQLITE_CONFIG_MULTITHREAD); + if (ret != SQLITE_OK) { + printf("SQLITE3 multithreading is not supported!\n"); + } + + ret = sqlite3_open(connection_str.c_str(), &conn); +} + +QueryResult *SQLite3Database::query(const std::string &query) { + return nullptr; +} + +void SQLite3Database::query_run(const std::string &query) { +} + +SQLite3Database::SQLite3Database() : + Database() { +} + +SQLite3Database::~SQLite3Database() { + if (conn) + sqlite3_close(conn); +} diff --git a/database/sqlite/sqlite3_database.h b/database/sqlite/sqlite3_database.h index 96624eb..55564fb 100644 --- a/database/sqlite/sqlite3_database.h +++ b/database/sqlite/sqlite3_database.h @@ -19,20 +19,12 @@ public: static void _register(); static void _unregister(); - SQLite3Database() : - Database() { + void connect(const std::string &connection_str); + QueryResult *query(const std::string &query); + void query_run(const std::string &query); - int ret = sqlite3_config(SQLITE_CONFIG_MULTITHREAD); - if (ret != SQLITE_OK) { - printf("SQLITE3 multithreading is not supported!\n"); - } - - ret = sqlite3_open("", &conn); - } - - ~SQLite3Database() { - sqlite3_close(conn); - } + SQLite3Database(); + ~SQLite3Database(); sqlite3 *conn; }; diff --git a/database/sqlite/sqlite3_query_result.cpp b/database/sqlite/sqlite3_query_result.cpp new file mode 100644 index 0000000..d772199 --- /dev/null +++ b/database/sqlite/sqlite3_query_result.cpp @@ -0,0 +1,17 @@ +#include "sqlite3_query_result.h" + +#include + +bool Sqlite3QueryResult::next_row() { + return false; +} + +const char* Sqlite3QueryResult::get_cell(const int index) { + return nullptr; +} + +Sqlite3QueryResult::Sqlite3QueryResult() : QueryResult() { +} + +Sqlite3QueryResult::~Sqlite3QueryResult() { +} \ No newline at end of file diff --git a/database/sqlite/sqlite3_query_result.h b/database/sqlite/sqlite3_query_result.h new file mode 100644 index 0000000..c5e71ae --- /dev/null +++ b/database/sqlite/sqlite3_query_result.h @@ -0,0 +1,17 @@ +#ifndef MYSQL_QUERY_RESULT_H +#define MYSQL_QUERY_RESULT_H + +#include "core/query_result.h" + +#include + +class Sqlite3QueryResult : public QueryResult { +public: + bool next_row(); + const char* get_cell(const int index); + + Sqlite3QueryResult(); + ~Sqlite3QueryResult(); +}; + +#endif \ No newline at end of file