Removed database_postgres and database_mysql modules. (They were hard disabled.)

This commit is contained in:
Relintai 2022-12-31 19:40:46 +01:00
parent b46ab0f4a7
commit 08e502462a
14 changed files with 0 additions and 714 deletions

View File

@ -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])

View File

@ -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"

View File

@ -1,141 +0,0 @@
#include "mysql_database.h"
#include <cstdio>
#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<QueryResult> 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<QueryResult>(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<QueryBuilder> MysqlDatabase::get_query_builder() {
MysqlQueryBuilder *b = new MysqlQueryBuilder();
b->_db = this;
return Ref<QueryBuilder>(b);
}
Ref<TableBuilder> MysqlDatabase::get_table_builder() {
return Ref<TableBuilder>(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");
}

View File

@ -1,42 +0,0 @@
#ifndef MYSQL_CONNECTION
#define MYSQL_CONNECTION
#include "core/string.h"
#include "database/database.h"
#include <memory>
//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 <mysql.h>
class MysqlDatabase : public Database {
public:
void connect(const String &connection_str);
Ref<QueryResult> query(const String &query);
void query_run(const String &query);
Ref<QueryBuilder> get_query_builder();
Ref<TableBuilder> 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

View File

@ -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 &params) {
query_result += "SELECT " + params + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::nwhere(const String &params) {
query_result += "WHERE " + params + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::nfrom(const String &params) {
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 &params_str) {
query_result += "VALUES(" + params_str + ") ";
return this;
}
String MysqlQueryBuilder::escape(const String &params) {
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<QueryResult> 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() {
}

View File

@ -1,50 +0,0 @@
#ifndef MYSQL_QUERY_BUILDER_H
#define MYSQL_QUERY_BUILDER_H
#include <memory>
#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 &params);
QueryBuilder *nwhere(const String &params);
QueryBuilder *nfrom(const String &params);
QueryBuilder *ninsert(const String &table_name);
QueryBuilder *nvalues(const String &params_str);
QueryBuilder *limit(const int num);
QueryBuilder *offset(const int num);
String escape(const String &params);
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<QueryResult> run();
void run_query();
MysqlQueryBuilder();
~MysqlQueryBuilder();
MysqlDatabase *_db;
};
#endif

View File

@ -1,27 +0,0 @@
#include "mysql_query_result.h"
#include <cstdio>
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);
}
}

View File

@ -1,22 +0,0 @@
#ifndef MYSQL_QUERY_RESULT_H
#define MYSQL_QUERY_RESULT_H
#include "database/query_result.h"
#include <mysql.h>
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

View File

@ -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() {
}

View File

@ -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

View File

@ -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])

View File

@ -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++"])

View File

@ -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");
}

View File

@ -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 <libpq-fe.h>
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