Now the postgres and sqlite connection also inherits from Database, and made main.cpp register them if they are present.

This commit is contained in:
Relintai 2020-12-01 14:53:32 +01:00
parent 9bddaba8bc
commit e3338f9d3b
4 changed files with 58 additions and 15 deletions

View File

@ -26,7 +26,7 @@ public:
DatabaseManager::_unregister_db_creation_func("mysql");
}
MysqlConnection() {
MysqlConnection() : Database() {
mysql = new MYSQL();
}
~MysqlConnection() {

View File

@ -1,6 +1,9 @@
#ifndef PGSQL_CONNECTION
#define PGSQL_CONNECTION
#include "core/database.h"
#include "core/database_manager.h"
//Brynet has it aswell, and because of using namespace it is defined here aswell
//later this will be fixed better
//#ifdef IS_NUM
@ -9,13 +12,24 @@
#include <libpq-fe.h>
class PGSQLConnection {
public:
PGSQLConnection() {
class PGSQLConnection : public Database {
public:
static Database *_creation_func() {
return new PGSQLConnection();
}
static void _register() {
DatabaseManager::_register_db_creation_func("pgsql", PGSQLConnection::_creation_func);
}
static void _unregister() {
DatabaseManager::_unregister_db_creation_func("pgsql");
}
PGSQLConnection() : Database() {
conn = PQconnectStart("");
}
~PGSQLConnection()
{
~PGSQLConnection() {
PQfinish(conn);
}

View File

@ -1,6 +1,9 @@
#ifndef SQLITE3_CONNECTION
#define SQLITE3_CONNECTION
#include "core/database.h"
#include "core/database_manager.h"
//Brynet has it aswell, and because of using namespace it is defined here aswell
//later this will be fixed better
//#ifdef IS_NUM
@ -11,9 +14,22 @@
#include <sqlite3.h>
class SQLite3Connection {
class SQLite3Connection : public Database {
public:
SQLite3Connection() {
static Database *_creation_func() {
return new SQLite3Connection();
}
static void _register() {
DatabaseManager::_register_db_creation_func("sqlite", SQLite3Connection::_creation_func);
}
static void _unregister() {
DatabaseManager::_unregister_db_creation_func("sqlite");
}
SQLite3Connection() :
Database() {
int ret = sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
if (ret != SQLITE_OK) {

View File

@ -9,7 +9,19 @@
#include "modules/message_page/message_page.h"
#include "core/database_manager.h"
#if MYSQL_PRESENT
#include "database/mysql/mysql_connection.h"
#endif
#if PGSQL_PRESENT
#include "database/postgres/pgsql_connection.h"
#endif
#if SQLITE_PRESENT
#include "database/sqlite/sqlite3_connection.h"
#endif
#define MAIN_CLASS RDNApplication
@ -17,16 +29,17 @@ int main(int argc, char **argv) {
#if MYSQL_PRESENT
printf("mysql present\n");
MysqlConnection::_register();
#endif
#if PGSQL_PRESENT
printf("pgsql present\n");
PGSQLConnection::_register();
#endif
#if SQLITE_PRESENT
printf("sqlite present\n");
SQLite3Connection::_register();
#endif
FileCache *file_cache = new FileCache(true);