2020-12-01 15:28:59 +01:00
|
|
|
#include "sqlite3_database.h"
|
|
|
|
|
2021-05-15 13:54:28 +02:00
|
|
|
#include "core/database/database_manager.h"
|
2020-12-01 15:28:59 +01:00
|
|
|
|
2021-05-01 21:53:01 +02:00
|
|
|
#include "sqlite3_query_result.h"
|
|
|
|
|
2020-12-01 15:28:59 +01:00
|
|
|
Database *SQLite3Database::_creation_func() {
|
|
|
|
return new SQLite3Database();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SQLite3Database::_register() {
|
|
|
|
DatabaseManager::_register_db_creation_func("sqlite", SQLite3Database::_creation_func);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SQLite3Database::_unregister() {
|
|
|
|
DatabaseManager::_unregister_db_creation_func("sqlite");
|
|
|
|
}
|
2021-05-01 20:31:52 +02:00
|
|
|
|
|
|
|
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) {
|
2021-05-01 21:53:01 +02:00
|
|
|
Sqlite3QueryResult *res = new Sqlite3QueryResult();
|
|
|
|
|
|
|
|
res->query(query, conn);
|
|
|
|
|
|
|
|
return res;
|
2021-05-01 20:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SQLite3Database::query_run(const std::string &query) {
|
2021-05-01 21:53:01 +02:00
|
|
|
char *err_msg;
|
|
|
|
|
|
|
|
if (sqlite3_exec(conn, query.c_str(), NULL, NULL, &err_msg) != SQLITE_OK) {
|
|
|
|
printf("SQLite3Database::query_run error: \nQuery: %s \n Error:\n %s\n", query.c_str(), err_msg);
|
|
|
|
sqlite3_free(err_msg);
|
|
|
|
}
|
2021-05-01 20:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SQLite3Database::SQLite3Database() :
|
|
|
|
Database() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SQLite3Database::~SQLite3Database() {
|
|
|
|
if (conn)
|
|
|
|
sqlite3_close(conn);
|
|
|
|
}
|