diff --git a/modules/database_mysql/SCsub b/modules/database_mysql/SCsub deleted file mode 100644 index d3e797aa8..000000000 --- a/modules/database_mysql/SCsub +++ /dev/null @@ -1,36 +0,0 @@ -#import os -#import version - -#Import('env') - -#module_env = env.Clone() - -#sources = [ - #"register_types.cpp", -#] - -#if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes': - # Shared lib compilation -# module_env.Append(CCFLAGS=['-fPIC']) -# module_env['LIBS'] = [] -# shared_lib = module_env.SharedLibrary(target='#bin/database', source=sources) -# shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0] -# env.Append(LIBS=[shared_lib_shim]) -# env.Append(LIBPATH=['#bin']) -#else: - # Static compilation -# module_env.add_source_files(env.modules_sources, sources) - - -#Import("env_db") -#Import("env") - -#env_db.core_sources = [] - -#env_db.add_source_files(env_db.core_sources, "*.cpp") - -# Build it all as a library -#lib = env_db.add_library("database_mysql", env_db.core_sources) -#env.Prepend(LIBS=[lib]) - - diff --git a/modules/database_mysql/config.py b/modules/database_mysql/config.py deleted file mode 100644 index 25f758969..000000000 --- a/modules/database_mysql/config.py +++ /dev/null @@ -1,61 +0,0 @@ -import os - -def can_build(env, platform): - return False - -def _can_build(): - if os.name == "posix" or sys.platform == "darwin": - x11_error = os.system("pkg-config --version > /dev/null") - if x11_error: - return False - - mariadb_error = os.system("pkg-config mariadb --modversion --silence-errors > /dev/null ") - mysql_error = os.system("pkg-config mysql --modversion --silence-errors > /dev/null ") - - if mariadb_error and mysql_error: - print("mysql and mariadb not found..") - return False - - if not mariadb_error: - print("mariadb found!") - - return True - - if not mysql_error: - print("mysql found!") - - return True - - #todo - return False - - -def configure(env): - pass - -def _configure(env): - mariadb_error = os.system("pkg-config mariadb --modversion --silence-errors > /dev/null ") - mysql_error = os.system("pkg-config mysql --modversion --silence-errors > /dev/null ") - - if not mariadb_error: - env.ParseConfig("pkg-config mariadb --cflags --libs") - env.Append(CPPDEFINES=["MYSQL_PRESENT"]) - return - - if not mysql_error: - env.ParseConfig("pkg-config mysql --cflags --libs") - - env.Append(CPPDEFINES=["MYSQL_PRESENT"]) - - # Link those statically for portability - #if env["use_static_cpp"]: - #env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"]) - - -def get_doc_classes(): - return [ - ] - -def get_doc_path(): - return "doc_classes" - diff --git a/modules/database_mysql/mysql_database.cpp b/modules/database_mysql/mysql_database.cpp deleted file mode 100644 index 6916efcb2..000000000 --- a/modules/database_mysql/mysql_database.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "mysql_database.h" - -#include - -#include "database/database_manager.h" - -#include "mysql_query_builder.h" -#include "mysql_query_result.h" -#include "mysql_table_builder.h" - -void MysqlDatabase::connect(const String &connection_str) { - mysql = mysql_init(mysql); - mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); - - String host = "127.0.0.1"; - String user = ""; - String password = ""; - String dbname = "testappdb"; - int port = 3306; - - mysql = mysql_real_connect(mysql, host.get_data(), user.get_data(), password.get_data(), dbname.get_data(), port, NULL, 0); - - if (mysql) { - printf("mysql connected\n"); - } -} - -Ref MysqlDatabase::query(const String &query) { - if (!mysql) - return nullptr; - - //printf("%s\n", query.get_data()); - - int error = mysql_real_query(mysql, query.get_data(), query.capacity()); - - if (error) { - const char *merr = mysql_error(mysql); - - printf("MySQL error: %s\n", merr); - - return nullptr; - } - - MYSQL_RES *result = mysql_use_result(mysql); - - MysqlQueryResult *res = new MysqlQueryResult(); - - res->result = result; - //res->next_row(); - - return Ref(res); -} - -void MysqlDatabase::query_run(const String &query) { - if (!mysql) - return; - - //printf("%s\n", query.get_data()); - - int error = mysql_real_query(mysql, query.get_data(), query.capacity()); - - if (error) { - const char *merr = mysql_error(mysql); - - printf("MySQL error: %s\n", merr); - return; - } - - //printf("query OK\n"); - //printf("----------------\n"); - - /* - printf("----------------\n"); - - MYSQL_RES *result = mysql_use_result(mysql); - //MYSQL_RES *result = mysql_store_result(mysql); - - MYSQL_ROW row; - while (row = mysql_fetch_row(result)) { - printf("%s\n", row[0]); - //printf("%s\n", row[1]); - } - - printf("----------------\n"); - - mysql_free_result(result); - */ -} - -Ref MysqlDatabase::get_query_builder() { - MysqlQueryBuilder *b = new MysqlQueryBuilder(); - b->_db = this; - - return Ref(b); -} - -Ref MysqlDatabase::get_table_builder() { - return Ref(new MysqlTableBuilder()); -} - -String MysqlDatabase::escape(const String str) { - String res; - //https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-escape-string.html - //You must allocate the to buffer to be at least length*2+1 bytes long. - res.ensure_capacity(str.size() * 2 + 1); - - mysql_real_escape_string(mysql, res.dataw(), str.get_data(), str.size()); - - return res; -} -void MysqlDatabase::escape(const String str, String *to) { - //https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-escape-string.html - //You must allocate the to buffer to be at least length*2+1 bytes long. - to->ensure_capacity(str.size() * 2 + 1); - - mysql_real_escape_string(mysql, to->dataw(), str.get_data(), str.size()); -} - -MysqlDatabase::MysqlDatabase() : - Database() { - - mysql = nullptr; -} - -MysqlDatabase::~MysqlDatabase() { - mysql_close(mysql); - - delete mysql; -} - -Database *MysqlDatabase::_creation_func() { - return new MysqlDatabase(); -} - -void MysqlDatabase::_register() { - DatabaseManager::_register_db_creation_func("mysql", MysqlDatabase::_creation_func); -} - -void MysqlDatabase::_unregister() { - DatabaseManager::_unregister_db_creation_func("mysql"); -} \ No newline at end of file diff --git a/modules/database_mysql/mysql_database.h b/modules/database_mysql/mysql_database.h deleted file mode 100644 index 9ce795d33..000000000 --- a/modules/database_mysql/mysql_database.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MYSQL_CONNECTION -#define MYSQL_CONNECTION - -#include "core/string.h" - -#include "database/database.h" - -#include - -//Brynet has it as well, and because of using namespace it is defined here as well -//later this will be fixed better -#ifdef IS_NUM -#undef IS_NUM -#endif - -#include - -class MysqlDatabase : public Database { -public: - void connect(const String &connection_str); - Ref query(const String &query); - void query_run(const String &query); - - Ref get_query_builder(); - Ref get_table_builder(); - - String escape(const String str); - void escape(const String str, String *to); - - static Database *_creation_func(); - static void _register(); - static void _unregister(); - - MysqlDatabase(); - ~MysqlDatabase(); - - MYSQL *mysql; -}; - -#undef IS_NUM - -#endif \ No newline at end of file diff --git a/modules/database_mysql/mysql_query_builder.cpp b/modules/database_mysql/mysql_query_builder.cpp deleted file mode 100644 index 953986300..000000000 --- a/modules/database_mysql/mysql_query_builder.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "mysql_query_builder.h" - -#include "mysql_database.h" -#include "mysql_query_result.h" - -QueryBuilder *MysqlQueryBuilder::select() { - query_result += "SELECT "; - - return this; -} -QueryBuilder *MysqlQueryBuilder::where() { - query_result += "WHERE "; - - return this; -} -QueryBuilder *MysqlQueryBuilder::from() { - query_result += "FROM "; - - return this; -} -QueryBuilder *MysqlQueryBuilder::insert() { - query_result += "INSERT INTO "; - - return this; -} -QueryBuilder *MysqlQueryBuilder::values() { - query_result += "VALUES("; - - return this; -} -QueryBuilder *MysqlQueryBuilder::cvalues() { - query_result += ") "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::nselect(const String ¶ms) { - query_result += "SELECT " + params + " "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::nwhere(const String ¶ms) { - query_result += "WHERE " + params + " "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::nfrom(const String ¶ms) { - query_result += "FROM " + params + " "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::ninsert(const String &table_name) { - query_result += "INSERT INTO " + table_name + " "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::nvalues(const String ¶ms_str) { - query_result += "VALUES(" + params_str + ") "; - - return this; -} - -String MysqlQueryBuilder::escape(const String ¶ms) { - if (!_db) { - printf("MysqlQueryBuilder::escape !db!\n"); - - return ""; - } - - return _db->escape(params); -} - -QueryBuilder *MysqlQueryBuilder::prepare() { - return this; -} - -QueryBuilder *MysqlQueryBuilder::set_param(const int index, const String &value) { - return this; -} -QueryBuilder *MysqlQueryBuilder::set_param(const int index, const int value) { - return this; -} -QueryBuilder *MysqlQueryBuilder::set_param(const int index, const float value) { - return this; -} - -QueryBuilder *MysqlQueryBuilder::end_command() { - query_result += ";"; - - return this; -} - -Ref MysqlQueryBuilder::run() { - end_command(); - - if (!_db) { - printf("MysqlQueryBuilder::run !db!\n"); - - return nullptr; - } - - return _db->query(query_result); -} - -void MysqlQueryBuilder::run_query() { - end_command(); - - if (!_db) { - printf("MysqlQueryBuilder::run_query !db!\n"); - - return; - } - - _db->query_run(query_result); -} - -QueryBuilder *MysqlQueryBuilder::limit(const int num) { - //query_result += "LIMIT " + num + " "; - - return this; -} - -QueryBuilder *MysqlQueryBuilder::offset(const int num) { - //query_result += "OFFSET " + num + " "; - - return this; -} - -MysqlQueryBuilder::MysqlQueryBuilder() { -} -MysqlQueryBuilder::~MysqlQueryBuilder() { -} \ No newline at end of file diff --git a/modules/database_mysql/mysql_query_builder.h b/modules/database_mysql/mysql_query_builder.h deleted file mode 100644 index 9bef10a4c..000000000 --- a/modules/database_mysql/mysql_query_builder.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef MYSQL_QUERY_BUILDER_H -#define MYSQL_QUERY_BUILDER_H - -#include -#include "core/string.h" - -#include "database/query_builder.h" - -class MysqlDatabase; -class MysqlQueryResult; - -class MysqlQueryBuilder : public QueryBuilder { - RCPP_OBJECT(MysqlQueryBuilder, QueryBuilder); - -public: - QueryBuilder *select(); - QueryBuilder *where(); - QueryBuilder *from(); - QueryBuilder *insert(); - QueryBuilder *values(); - QueryBuilder *cvalues(); - - QueryBuilder *nselect(const String ¶ms); - QueryBuilder *nwhere(const String ¶ms); - QueryBuilder *nfrom(const String ¶ms); - QueryBuilder *ninsert(const String &table_name); - QueryBuilder *nvalues(const String ¶ms_str); - - QueryBuilder *limit(const int num); - QueryBuilder *offset(const int num); - - String escape(const String ¶ms); - - QueryBuilder *prepare(); - QueryBuilder *set_param(const int index, const String &value); - QueryBuilder *set_param(const int index, const int value); - QueryBuilder *set_param(const int index, const float value); - - QueryBuilder *end_command(); - - Ref run(); - void run_query(); - - MysqlQueryBuilder(); - ~MysqlQueryBuilder(); - - MysqlDatabase *_db; -}; - -#endif \ No newline at end of file diff --git a/modules/database_mysql/mysql_query_result.cpp b/modules/database_mysql/mysql_query_result.cpp deleted file mode 100644 index 0ffc87086..000000000 --- a/modules/database_mysql/mysql_query_result.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "mysql_query_result.h" - -#include - -bool MysqlQueryResult::next_row() { - current_row = mysql_fetch_row(result); - - //null if no result - return current_row; -} - -const char* MysqlQueryResult::get_cell(const int index) { - if (!current_row) - return ""; - - return current_row[index]; -} - -MysqlQueryResult::MysqlQueryResult() : QueryResult() { - result = nullptr; -} - -MysqlQueryResult::~MysqlQueryResult() { - if(result) { - mysql_free_result(result); - } -} \ No newline at end of file diff --git a/modules/database_mysql/mysql_query_result.h b/modules/database_mysql/mysql_query_result.h deleted file mode 100644 index 6f612199d..000000000 --- a/modules/database_mysql/mysql_query_result.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MYSQL_QUERY_RESULT_H -#define MYSQL_QUERY_RESULT_H - -#include "database/query_result.h" - -#include - -class MysqlQueryResult : public QueryResult { - RCPP_OBJECT(MysqlQueryResult, QueryResult); - -public: - bool next_row(); - const char* get_cell(const int index); - - MysqlQueryResult(); - ~MysqlQueryResult(); - - MYSQL_ROW current_row; - MYSQL_RES *result; -}; - -#endif \ No newline at end of file diff --git a/modules/database_mysql/mysql_table_builder.cpp b/modules/database_mysql/mysql_table_builder.cpp deleted file mode 100644 index da5b11270..000000000 --- a/modules/database_mysql/mysql_table_builder.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "mysql_table_builder.h" - -TableBuilder *MysqlTableBuilder::create_table(const String &name) { - result += "CREATE TABLE " + name + " ( "; - - return this; -} - -TableBuilder *MysqlTableBuilder::integer(const String &name) { - result += name + " INTEGER "; - - return this; -} - -TableBuilder *MysqlTableBuilder::date(const String &name) { - result += name + " DATE "; - - return this; -} - -TableBuilder *MysqlTableBuilder::varchar(const String &name, const int length) { - result += name + " VARCHAR(" + std::to_string(length) + ")"; - - return this; -} - -TableBuilder *MysqlTableBuilder::not_null() { - result += "NOT NULL "; - - return this; -} - -TableBuilder *MysqlTableBuilder::null() { - result += "NULL "; - - return this; -} - -TableBuilder *MysqlTableBuilder::auto_increment() { - result += "AUTO_INCREMENT "; - - return this; -} - -TableBuilder *MysqlTableBuilder::primary_key(const String &name) { - result += "PRIMARY KEY (" + name + ") "; - - return this; -} - -TableBuilder *MysqlTableBuilder::primary_key() { - result += "PRIMARY KEY "; - - return this; -} - -TableBuilder *MysqlTableBuilder::next_row() { - result += ", "; - - return this; -} - -TableBuilder *MysqlTableBuilder::drop_table(const String &name) { - result += "DROP TABLE " + name + ";"; - - return this; -} - -MysqlTableBuilder::MysqlTableBuilder() { -} - -MysqlTableBuilder::~MysqlTableBuilder() { -} \ No newline at end of file diff --git a/modules/database_mysql/mysql_table_builder.h b/modules/database_mysql/mysql_table_builder.h deleted file mode 100644 index d836a8b3f..000000000 --- a/modules/database_mysql/mysql_table_builder.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MYSQL_TABLE_BUILDER_H -#define MYSQL_TABLE_BUILDER_H - -#include "core/string.h" - -#include "database/table_builder.h" - -class MysqlTableBuilder : public TableBuilder { - RCPP_OBJECT(MysqlTableBuilder, TableBuilder); - -public: - TableBuilder *create_table(const String &name); - TableBuilder *integer(const String &name); - TableBuilder *date(const String &name); - TableBuilder *varchar(const String &name, const int length); - TableBuilder *not_null(); - TableBuilder *null(); - TableBuilder *auto_increment(); - TableBuilder *primary_key(const String &name); - TableBuilder *primary_key(); - TableBuilder *next_row(); - - TableBuilder *drop_table(const String &name); - - MysqlTableBuilder(); - virtual ~MysqlTableBuilder(); -}; - -#endif \ No newline at end of file diff --git a/modules/database_postgres/SCsub b/modules/database_postgres/SCsub deleted file mode 100644 index 3e592abc0..000000000 --- a/modules/database_postgres/SCsub +++ /dev/null @@ -1,11 +0,0 @@ - -#Import("env_db") -#Import("env") - -#env_db.core_sources = [] - -#env_db.add_source_files(env_db.core_sources, "*.cpp") - -# Build it all as a library -#lib = env_db.add_library("database_pgsql", env_db.core_sources) -#env.Prepend(LIBS=[lib]) diff --git a/modules/database_postgres/config.py b/modules/database_postgres/config.py deleted file mode 100644 index 8e0aa357b..000000000 --- a/modules/database_postgres/config.py +++ /dev/null @@ -1,38 +0,0 @@ -import os -import platform -import sys - - -def can_build(env, platform): - return False - -def _can_build(): - if os.name == "posix" or sys.platform == "darwin": - x11_error = os.system("pkg-config --version > /dev/null") - if x11_error: - return False - - libpg_error = os.system("pkg-config libpq --modversion --silence-errors > /dev/null ") - - if libpg_error: - print("postgres not found!") - return False - - print("postgres found!") - - return True - - #todo - return False - -def configure(env): - pass - -def _configure(env): - env.ParseConfig("pkg-config libpq --cflags --libs") - - env.Append(CPPDEFINES=["PGSQL_PRESENT"]) - - # Link those statically for portability - #if env["use_static_cpp"]: - #env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"]) diff --git a/modules/database_postgres/pgsql_database.cpp b/modules/database_postgres/pgsql_database.cpp deleted file mode 100644 index 49a1cd99b..000000000 --- a/modules/database_postgres/pgsql_database.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "pgsql_database.h" - -#include "database/database_manager.h" - -Database *PGSQLDatabase::_creation_func() { - return new PGSQLDatabase(); -} - -void PGSQLDatabase::_register() { - DatabaseManager::_register_db_creation_func("pgsql", PGSQLDatabase::_creation_func); -} - -void PGSQLDatabase::_unregister() { - DatabaseManager::_unregister_db_creation_func("pgsql"); -} diff --git a/modules/database_postgres/pgsql_database.h b/modules/database_postgres/pgsql_database.h deleted file mode 100644 index c2526f2db..000000000 --- a/modules/database_postgres/pgsql_database.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PGSQL_CONNECTION -#define PGSQL_CONNECTION - -#include "database/database.h" - -//Brynet has it as well, and because of using namespace it is defined here as well -//later this will be fixed better -//#ifdef IS_NUM -//#undef IS_NUM -//#endif - -#include - -class PGSQLDatabase : public Database { -public: - static Database *_creation_func(); - static void _register(); - static void _unregister(); - - PGSQLDatabase() : - Database() { - conn = PQconnectStart(""); - } - ~PGSQLDatabase() { - PQfinish(conn); - } - - PGconn *conn; -}; - -//#undef IS_NUM - -#endif \ No newline at end of file