Destroying database specifier

This commit is contained in:
EmosewaMC 2022-04-09 15:35:01 -07:00
parent fd13770e87
commit 3e60b9db4a
4 changed files with 8 additions and 7 deletions

View File

@ -57,7 +57,7 @@ int main(int argc, char** argv) {
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
} catch (sql::SQLException& ex) {
Game::logger->Log("AuthServer", "Got an error while connecting to the database: %s\n", ex.what());
Database::Destroy();
Database::Destroy("AuthServer");
delete Game::server;
delete Game::logger;
return 0;
@ -143,7 +143,7 @@ int main(int argc, char** argv) {
}
//Delete our objects here:
Database::Destroy();
Database::Destroy("AuthServer");
delete Game::server;
delete Game::logger;

View File

@ -61,7 +61,7 @@ int main(int argc, char** argv) {
}
catch (sql::SQLException& ex) {
Game::logger->Log("ChatServer", "Got an error while connecting to the database: %s\n", ex.what());
Database::Destroy();
Database::Destroy("ChatServer");
delete Game::server;
delete Game::logger;
return 0;
@ -150,7 +150,7 @@ int main(int argc, char** argv) {
}
//Delete our objects here:
Database::Destroy();
Database::Destroy("ChatServer");
delete Game::server;
delete Game::logger;

View File

@ -26,9 +26,10 @@ void Database::Connect(const string& host, const string& database, const string&
con->setClientOption("MYSQL_OPT_RECONNECT", &myTrue);
} //Connect
void Database::Destroy() {
void Database::Destroy(std::string source) {
if (!con) return;
Game::logger->Log("Database", "Destroying MySQL connection!\n");
if (source != "") Game::logger->Log("Database", "Destroying MySQL connection from %s!\n", source.c_str());
else Game::logger->Log("Database", "Destroying MySQL connection!\n");
con->close();
delete con;
} //Destroy

View File

@ -22,7 +22,7 @@ private:
public:
static void Connect(const std::string& host, const std::string& database, const std::string& username, const std::string& password);
static void Destroy();
static void Destroy(std::string source="");
static sql::Statement* CreateStmt();
static sql::PreparedStatement* CreatePreppedStmt(const std::string& query);
};