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");
|
DatabaseManager::_unregister_db_creation_func("mysql");
|
||||||
}
|
}
|
||||||
|
|
||||||
MysqlConnection() {
|
MysqlConnection() : Database() {
|
||||||
mysql = new MYSQL();
|
mysql = new MYSQL();
|
||||||
}
|
}
|
||||||
~MysqlConnection() {
|
~MysqlConnection() {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#ifndef PGSQL_CONNECTION
|
#ifndef PGSQL_CONNECTION
|
||||||
#define 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
|
//Brynet has it aswell, and because of using namespace it is defined here aswell
|
||||||
//later this will be fixed better
|
//later this will be fixed better
|
||||||
//#ifdef IS_NUM
|
//#ifdef IS_NUM
|
||||||
@ -9,17 +12,28 @@
|
|||||||
|
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
class PGSQLConnection {
|
class PGSQLConnection : public Database {
|
||||||
public:
|
public:
|
||||||
PGSQLConnection() {
|
static Database *_creation_func() {
|
||||||
conn = PQconnectStart("");
|
return new PGSQLConnection();
|
||||||
}
|
}
|
||||||
~PGSQLConnection()
|
|
||||||
{
|
|
||||||
PQfinish(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
PGconn *conn;
|
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() {
|
||||||
|
PQfinish(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
PGconn *conn;
|
||||||
};
|
};
|
||||||
|
|
||||||
//#undef IS_NUM
|
//#undef IS_NUM
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#ifndef SQLITE3_CONNECTION
|
#ifndef SQLITE3_CONNECTION
|
||||||
#define 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
|
//Brynet has it aswell, and because of using namespace it is defined here aswell
|
||||||
//later this will be fixed better
|
//later this will be fixed better
|
||||||
//#ifdef IS_NUM
|
//#ifdef IS_NUM
|
||||||
@ -11,9 +14,22 @@
|
|||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
class SQLite3Connection {
|
class SQLite3Connection : public Database {
|
||||||
public:
|
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);
|
int ret = sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
|
||||||
if (ret != SQLITE_OK) {
|
if (ret != SQLITE_OK) {
|
||||||
|
15
main.cpp
15
main.cpp
@ -9,7 +9,19 @@
|
|||||||
|
|
||||||
#include "modules/message_page/message_page.h"
|
#include "modules/message_page/message_page.h"
|
||||||
|
|
||||||
|
#include "core/database_manager.h"
|
||||||
|
|
||||||
|
#if MYSQL_PRESENT
|
||||||
#include "database/mysql/mysql_connection.h"
|
#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
|
#define MAIN_CLASS RDNApplication
|
||||||
|
|
||||||
@ -17,16 +29,17 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
#if MYSQL_PRESENT
|
#if MYSQL_PRESENT
|
||||||
printf("mysql present\n");
|
printf("mysql present\n");
|
||||||
|
|
||||||
MysqlConnection::_register();
|
MysqlConnection::_register();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PGSQL_PRESENT
|
#if PGSQL_PRESENT
|
||||||
printf("pgsql present\n");
|
printf("pgsql present\n");
|
||||||
|
PGSQLConnection::_register();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SQLITE_PRESENT
|
#if SQLITE_PRESENT
|
||||||
printf("sqlite present\n");
|
printf("sqlite present\n");
|
||||||
|
SQLite3Connection::_register();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FileCache *file_cache = new FileCache(true);
|
FileCache *file_cache = new FileCache(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user