mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
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:
parent
9bddaba8bc
commit
e3338f9d3b
@ -26,7 +26,7 @@ public:
|
||||
DatabaseManager::_unregister_db_creation_func("mysql");
|
||||
}
|
||||
|
||||
MysqlConnection() {
|
||||
MysqlConnection() : Database() {
|
||||
mysql = new MYSQL();
|
||||
}
|
||||
~MysqlConnection() {
|
||||
|
@ -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 {
|
||||
class PGSQLConnection : public Database {
|
||||
public:
|
||||
PGSQLConnection() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
15
main.cpp
15
main.cpp
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user