Confirmed database connectivity
This commit is contained in:
@@ -15,6 +15,8 @@ namespace database
|
||||
BaseRepository();
|
||||
BaseRepository(const std::string&);
|
||||
BaseRepository(const model::BinaryPath&);
|
||||
|
||||
bool testConnection();
|
||||
protected:
|
||||
MYSQL* setupMysqlConnection();
|
||||
MYSQL* setupMysqlConnection(model::DatabaseConnection);
|
||||
|
||||
@@ -13,11 +13,29 @@ database::BaseRepository::BaseRepository(const std::string& path) : path(path)
|
||||
{
|
||||
intitalizeDetails();
|
||||
}
|
||||
|
||||
database::BaseRepository::BaseRepository(const model::BinaryPath& bConf)
|
||||
{
|
||||
initializeDetails(bConf);
|
||||
}
|
||||
|
||||
|
||||
bool database::BaseRepository::testConnection()
|
||||
{
|
||||
auto conn = mysql_init(nullptr);
|
||||
if (!mysql_real_connect(conn, details.server.c_str(), details.username.c_str(),
|
||||
details.password.c_str(), details.database.c_str(), 0,
|
||||
nullptr, 0)) {
|
||||
std::cout << "failed to connect to the database" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
mysql_close(conn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* database::BaseRepository::setupMysqlConnection()
|
||||
{
|
||||
MYSQL *conn = mysql_init(nullptr);
|
||||
@@ -29,6 +47,7 @@ MYSQL* database::BaseRepository::setupMysqlConnection()
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
MYSQL* database::BaseRepository::setupMysqlConnection(model::DatabaseConnection details)
|
||||
{
|
||||
MYSQL *connection = mysql_init(NULL);
|
||||
@@ -41,6 +60,7 @@ MYSQL* database::BaseRepository::setupMysqlConnection(model::DatabaseConnection
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
MYSQL_RES* database::BaseRepository::performMysqlQuery(MYSQL *conn, const std::string& query)
|
||||
{
|
||||
// send the query to the database
|
||||
@@ -53,6 +73,7 @@ MYSQL_RES* database::BaseRepository::performMysqlQuery(MYSQL *conn, const std::s
|
||||
return mysql_use_result(conn);
|
||||
}
|
||||
|
||||
|
||||
void database::BaseRepository::intitalizeDetails()
|
||||
{
|
||||
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(path);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "database/BaseRepository.h"
|
||||
#include "manager/DirectoryManager.h"
|
||||
#include "type/PathType.h"
|
||||
|
||||
@@ -33,8 +34,9 @@ bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf)
|
||||
// verifies if database connectivity can be established
|
||||
bool verify::Initialization::confirmConfigDatabase(const model::BinaryPath& bConf)
|
||||
{
|
||||
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(bConf);
|
||||
return true;
|
||||
database::BaseRepository baseRepo(bConf);
|
||||
|
||||
return baseRepo.testConnection();
|
||||
}
|
||||
|
||||
// verifies if the paths found in the config files exists
|
||||
|
||||
Reference in New Issue
Block a user