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