mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 05:27:19 +00:00
adc9cd2876
* saving from a test works * testing works * Update SavingTests.cpp * test dServer stuff * tests * use dummy database and add missing pure fns * add more tests * add more tests * add rocket tests * Update BuffComponent.h * Update test_xml_data.xml * Update SavingTests.cpp * update
46 lines
880 B
C++
46 lines
880 B
C++
#include "Database.h"
|
|
#include "Game.h"
|
|
#include "dConfig.h"
|
|
#include "Logger.h"
|
|
#include "MySQLDatabase.h"
|
|
#include "DluAssert.h"
|
|
|
|
#pragma warning (disable:4251) //Disables SQL warnings
|
|
|
|
namespace {
|
|
GameDatabase* database = nullptr;
|
|
}
|
|
|
|
void Database::Connect() {
|
|
if (database) {
|
|
LOG("Tried to connect to database when it's already connected!");
|
|
return;
|
|
}
|
|
|
|
database = new MySQLDatabase();
|
|
database->Connect();
|
|
}
|
|
|
|
GameDatabase* Database::Get() {
|
|
if (!database) {
|
|
LOG("Tried to get database when it's not connected!");
|
|
Connect();
|
|
}
|
|
return database;
|
|
}
|
|
|
|
void Database::Destroy(std::string source) {
|
|
if (database) {
|
|
database->Destroy(source);
|
|
delete database;
|
|
database = nullptr;
|
|
} else {
|
|
LOG("Trying to destroy database when it's not connected!");
|
|
}
|
|
}
|
|
|
|
void Database::_setDatabase(GameDatabase* const db) {
|
|
if (database) delete database;
|
|
database = db;
|
|
}
|