add db config

This commit is contained in:
Guillermo Roche 2020-06-03 19:00:32 +02:00
parent 8a50e7c476
commit a01363cf4b
6 changed files with 25 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-06-02T15:21:19. --> <!-- Written by QtCreator 4.8.2, 2020-06-03T18:58:43. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -11,7 +11,9 @@ void conexion_client(int client);
conexion::conexion(config_reader &config) conexion::conexion(config_reader &config)
{ {
this->config=&config; this->config=&config;
this->data=new msql_acces(); config.get_param("db_user",msql_acces::user);
config.get_param("db_pass",msql_acces::pass);
this->data=msql_acces::get_instance();
} }
int conexion::create_socket(int port) int conexion::create_socket(int port)

View File

@ -4,10 +4,21 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <string.h> #include <string.h>
std::string msql_acces::user="root";
std::string msql_acces::pass="1234";
msql_acces* msql_acces::instance=nullptr;
msql_acces* msql_acces::get_instance(){
if(msql_acces::instance==nullptr){
msql_acces::instance=new msql_acces();
}
return msql_acces::instance;
}
msql_acces::msql_acces() msql_acces::msql_acces()
{ {
driver = get_driver_instance(); driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "1234"); con = driver->connect("tcp://127.0.0.1:3306", msql_acces::user, msql_acces::pass);
con->setSchema("bin_database"); con->setSchema("bin_database");
} }

View File

@ -11,7 +11,9 @@
class msql_acces : public data_acces class msql_acces : public data_acces
{ {
public: public:
msql_acces(); static msql_acces* get_instance();
static std::string user;
static std::string pass;
std::string get_passwd(std::string username); std::string get_passwd(std::string username);
bool get_admin(std::string); bool get_admin(std::string);
std::list<std::string> get_pinfo(); std::list<std::string> get_pinfo();
@ -22,6 +24,8 @@ public:
void create_user(std::string user, std::string pass, bool admin); void create_user(std::string user, std::string pass, bool admin);
void remove_user(std::string user); void remove_user(std::string user);
private: private:
msql_acces();
static msql_acces* instance;
sql::Connection *con; sql::Connection *con;
sql::Driver *driver; sql::Driver *driver;
}; };

View File

@ -11,7 +11,7 @@
session_manager::session_manager(int fd) session_manager::session_manager(int fd)
{ {
this->fd=fd; this->fd=fd;
this->data=new msql_acces(); this->data=msql_acces::get_instance();
} }
bool session_manager::validate_pass(){ bool session_manager::validate_pass(){

View File

@ -6,7 +6,9 @@
void test_basic::setUp(){ void test_basic::setUp(){
this->conf=new config_reader("config"); this->conf=new config_reader("config");
this->data=new msql_acces(); conf->get_param("db_user",msql_acces::user);
conf->get_param("db_pass",msql_acces::pass);
this->data=msql_acces::get_instance();
} }
void test_basic::test_initial(){ void test_basic::test_initial(){