mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-13 19:58:21 +00:00
Make changes to certain database functions and a debug assert (#804)
- Replace all interaction of std::string and sqlString. - Add a return before a debug assertion can be triggered by lvl chunks being loaded on server start.
This commit is contained in:
parent
8edade5f98
commit
b974eed8f5
@ -35,8 +35,8 @@ void Database::Connect(const string& host, const string& database, const string&
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Database::Connect() {
|
void Database::Connect() {
|
||||||
con = driver->connect(Database::props);
|
con = driver->connect(Database::props["hostName"].c_str(), Database::props["user"].c_str(), Database::props["password"].c_str());
|
||||||
con->setSchema(Database::database);
|
con->setSchema(Database::database.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::Destroy(std::string source, bool log) {
|
void Database::Destroy(std::string source, bool log) {
|
||||||
|
@ -45,7 +45,7 @@ void MigrationRunner::RunMigrations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stmt = Database::CreatePreppedStmt("SELECT name FROM migration_history WHERE name = ?;");
|
stmt = Database::CreatePreppedStmt("SELECT name FROM migration_history WHERE name = ?;");
|
||||||
stmt->setString(1, migration.name);
|
stmt->setString(1, migration.name.c_str());
|
||||||
auto* res = stmt->executeQuery();
|
auto* res = stmt->executeQuery();
|
||||||
bool doExit = res->next();
|
bool doExit = res->next();
|
||||||
delete res;
|
delete res;
|
||||||
@ -56,11 +56,11 @@ void MigrationRunner::RunMigrations() {
|
|||||||
if (migration.name == "5_brick_model_sd0.sql") {
|
if (migration.name == "5_brick_model_sd0.sql") {
|
||||||
runSd0Migrations = true;
|
runSd0Migrations = true;
|
||||||
} else {
|
} else {
|
||||||
finalSQL.append(migration.data);
|
finalSQL.append(migration.data.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = Database::CreatePreppedStmt("INSERT INTO migration_history (name) VALUES (?);");
|
stmt = Database::CreatePreppedStmt("INSERT INTO migration_history (name) VALUES (?);");
|
||||||
stmt->setString(1, migration.name);
|
stmt->setString(1, migration.name.c_str());
|
||||||
stmt->execute();
|
stmt->execute();
|
||||||
delete stmt;
|
delete stmt;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ void MigrationRunner::RunMigrations() {
|
|||||||
for (auto& query : migration) {
|
for (auto& query : migration) {
|
||||||
try {
|
try {
|
||||||
if (query.empty()) continue;
|
if (query.empty()) continue;
|
||||||
simpleStatement->execute(query);
|
simpleStatement->execute(query.c_str());
|
||||||
} catch (sql::SQLException& e) {
|
} catch (sql::SQLException& e) {
|
||||||
Game::logger->Log("MigrationRunner", "Encountered error running migration: %s", e.what());
|
Game::logger->Log("MigrationRunner", "Encountered error running migration: %s", e.what());
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ void MigrationRunner::RunSQLiteMigrations() {
|
|||||||
if (migration.data.empty()) continue;
|
if (migration.data.empty()) continue;
|
||||||
|
|
||||||
stmt = Database::CreatePreppedStmt("SELECT name FROM migration_history WHERE name = ?;");
|
stmt = Database::CreatePreppedStmt("SELECT name FROM migration_history WHERE name = ?;");
|
||||||
stmt->setString(1, migration.name);
|
stmt->setString(1, migration.name.c_str());
|
||||||
auto* res = stmt->executeQuery();
|
auto* res = stmt->executeQuery();
|
||||||
bool doExit = res->next();
|
bool doExit = res->next();
|
||||||
delete res;
|
delete res;
|
||||||
|
@ -237,7 +237,7 @@ int main(int argc, char** argv) {
|
|||||||
//If we found a server, update it's IP and port to the current one.
|
//If we found a server, update it's IP and port to the current one.
|
||||||
if (result->next()) {
|
if (result->next()) {
|
||||||
auto* updateStatement = Database::CreatePreppedStmt("UPDATE `servers` SET `ip` = ?, `port` = ? WHERE `id` = ?");
|
auto* updateStatement = Database::CreatePreppedStmt("UPDATE `servers` SET `ip` = ?, `port` = ? WHERE `id` = ?");
|
||||||
updateStatement->setString(1, master_server_ip);
|
updateStatement->setString(1, master_server_ip.c_str());
|
||||||
updateStatement->setInt(2, Game::server->GetPort());
|
updateStatement->setInt(2, Game::server->GetPort());
|
||||||
updateStatement->setInt(3, result->getInt("id"));
|
updateStatement->setInt(3, result->getInt("id"));
|
||||||
updateStatement->execute();
|
updateStatement->execute();
|
||||||
@ -245,7 +245,7 @@ int main(int argc, char** argv) {
|
|||||||
} else {
|
} else {
|
||||||
//If we didn't find a server, create one.
|
//If we didn't find a server, create one.
|
||||||
auto* insertStatement = Database::CreatePreppedStmt("INSERT INTO `servers` (`name`, `ip`, `port`, `state`, `version`) VALUES ('master', ?, ?, 0, 171023)");
|
auto* insertStatement = Database::CreatePreppedStmt("INSERT INTO `servers` (`name`, `ip`, `port`, `state`, `version`) VALUES ('master', ?, ?, 0, 171023)");
|
||||||
insertStatement->setString(1, master_server_ip);
|
insertStatement->setString(1, master_server_ip.c_str());
|
||||||
insertStatement->setInt(2, Game::server->GetPort());
|
insertStatement->setInt(2, Game::server->GetPort());
|
||||||
insertStatement->execute();
|
insertStatement->execute();
|
||||||
delete insertStatement;
|
delete insertStatement;
|
||||||
|
Loading…
Reference in New Issue
Block a user