From 2ff1fd0e950970e973c26eda96abb60ac52c2538 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 13 Jul 2020 21:30:33 +0200 Subject: [PATCH] Core/DataStores: Replace harcoded prepared statement offsets with named constants --- .../database/Database/Implementation/HotfixDatabase.cpp | 4 ++-- src/server/database/Database/Implementation/HotfixDatabase.h | 3 +++ src/server/shared/DataStores/DB2DatabaseLoader.cpp | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/server/database/Database/Implementation/HotfixDatabase.cpp b/src/server/database/Database/Implementation/HotfixDatabase.cpp index b4a3a5ae12..098f3679a2 100644 --- a/src/server/database/Database/Implementation/HotfixDatabase.cpp +++ b/src/server/database/Database/Implementation/HotfixDatabase.cpp @@ -23,12 +23,12 @@ // Force max id statements to appear exactly right after normal data fetch statement #define PREPARE_MAX_ID_STMT(stmtBase, sql, con) \ - static_assert(stmtBase + 1 == stmtBase##_MAX_ID, "Invalid prepared statement index for " #stmtBase "_MAX_ID"); \ + static_assert(stmtBase + HOTFIX_MAX_ID_STMT_OFFSET == stmtBase##_MAX_ID, "Invalid prepared statement index for " #stmtBase "_MAX_ID"); \ PrepareStatement(stmtBase##_MAX_ID, sql, con); // Force locale statements to be right after max id fetch statement #define PREPARE_LOCALE_STMT(stmtBase, sql, con) \ - static_assert(stmtBase + 2 == stmtBase##_LOCALE, "Invalid prepared statement index for " #stmtBase "_LOCALE"); \ + static_assert(stmtBase + HOTFIX_LOCALE_STMT_OFFSET == stmtBase##_LOCALE, "Invalid prepared statement index for " #stmtBase "_LOCALE"); \ PrepareStatement(stmtBase##_LOCALE, sql, con); void HotfixDatabaseConnection::DoPrepareStatements() diff --git a/src/server/database/Database/Implementation/HotfixDatabase.h b/src/server/database/Database/Implementation/HotfixDatabase.h index df374496ed..57e797b225 100644 --- a/src/server/database/Database/Implementation/HotfixDatabase.h +++ b/src/server/database/Database/Implementation/HotfixDatabase.h @@ -858,6 +858,9 @@ enum HotfixDatabaseStatements : uint32 MAX_HOTFIXDATABASE_STATEMENTS }; +uint32 constexpr HOTFIX_MAX_ID_STMT_OFFSET = 1; +uint32 constexpr HOTFIX_LOCALE_STMT_OFFSET = 2; + class TC_DATABASE_API HotfixDatabaseConnection : public MySQLConnection { public: diff --git a/src/server/shared/DataStores/DB2DatabaseLoader.cpp b/src/server/shared/DataStores/DB2DatabaseLoader.cpp index 3c46fb6650..d6ecc279d7 100644 --- a/src/server/shared/DataStores/DB2DatabaseLoader.cpp +++ b/src/server/shared/DataStores/DB2DatabaseLoader.cpp @@ -66,7 +66,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable, // Resize index table uint32 indexTableSize = records; - if (PreparedQueryResult maxIdResult = HotfixDatabase.Query(HotfixDatabase.GetPreparedStatement(HotfixDatabaseStatements(_loadInfo->Statement + 1)))) + if (PreparedQueryResult maxIdResult = HotfixDatabase.Query(HotfixDatabase.GetPreparedStatement(HotfixDatabaseStatements(_loadInfo->Statement + HOTFIX_MAX_ID_STMT_OFFSET)))) if (uint32((*maxIdResult)[0].GetUInt64()) > records) indexTableSize = uint32((*maxIdResult)[0].GetUInt64()); @@ -204,7 +204,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable, void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 records, char** indexTable, std::vector& stringPool) { - HotfixDatabasePreparedStatement* stmt = HotfixDatabase.GetPreparedStatement(HotfixDatabaseStatements(_loadInfo->Statement + 2)); + HotfixDatabasePreparedStatement* stmt = HotfixDatabase.GetPreparedStatement(HotfixDatabaseStatements(_loadInfo->Statement + HOTFIX_LOCALE_STMT_OFFSET)); stmt->setBool(0, !custom); stmt->setString(1, localeNames[locale]); PreparedQueryResult result = HotfixDatabase.Query(stmt);