aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Database
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2015-01-17 17:59:13 +0100
committerShauren <shauren.trinity@gmail.com>2015-01-17 17:59:13 +0100
commit8a30b70a20dd483067d402a7966fc147ca32d18a (patch)
tree1a91e998e32ce58f7d0f20f766760240648725d0 /src/server/shared/Database
parent1c7d25238bd89dfe3a6e5824abb728b4b47e7c26 (diff)
Core/DataStores: Optimized memory usage for DB2Storage
Diffstat (limited to 'src/server/shared/Database')
-rw-r--r--src/server/shared/Database/Implementation/HotfixDatabase.cpp44
-rw-r--r--src/server/shared/Database/Implementation/HotfixDatabase.h14
2 files changed, 56 insertions, 2 deletions
diff --git a/src/server/shared/Database/Implementation/HotfixDatabase.cpp b/src/server/shared/Database/Implementation/HotfixDatabase.cpp
index a41c037e848..55f2c3e53fb 100644
--- a/src/server/shared/Database/Implementation/HotfixDatabase.cpp
+++ b/src/server/shared/Database/Implementation/HotfixDatabase.cpp
@@ -16,12 +16,52 @@
*/
#include "HotfixDatabase.h"
+#include "Util.h"
+
+/*
+ Hotfix database statements are constructed in a special way
+ Each db2 storage that contains localized string data
+ must declare a prepared statement for each locale in the same order as
+ locales are defined (enforced during compilation)
+
+ '@' character is replaced with locale index for PrepareStatement call
+*/
+
+// Force locale statments to appear exactly in locale declaration order, right after normal data fetch statement
+#define PREPARE_LOCALE_STMT(stmtBase, loc, sql, con) \
+ static_assert(stmtBase + loc == stmtBase##_##loc, "Invalid prepared statement index for " ## STRINGIZE(stmtBase##_##loc)); \
+ PrepareLocaleStatement(stmtBase##_##loc, loc, sql, con);
+
+#define PREPARE_LOCALE_STMTS(stmtBase, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_koKR, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_frFR, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_deDE, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_zhCN, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_zhTW, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_esES, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_esMX, sql, con) \
+ PREPARE_LOCALE_STMT(stmtBase, LOCALE_ruRU, sql, con)
void HotfixDatabaseConnection::DoPrepareStatements()
{
if (!m_reconnecting)
m_stmts.resize(MAX_HOTFIXDATABASE_STATEMENTS);
- PrepareStatement(HOTFIX_SEL_BROADCAST_TEXT, "SELECT * FROM broadcast_text b LEFT JOIN locales_broadcast_text lb ON b.ID = lb.ID", CONNECTION_SYNCH);
- PrepareStatement(HOTFIX_SEL_TAXI_PATH_NODE, "SELECT * FROM taxi_path_node", CONNECTION_SYNCH);
+ // BroadcastText.db2
+ PrepareStatement(HOTFIX_SEL_BROADCAST_TEXT, "SELECT * FROM broadcast_text ORDER BY ID DESC", CONNECTION_SYNCH);
+ PREPARE_LOCALE_STMTS(HOTFIX_SEL_BROADCAST_TEXT, "SELECT ID, MaleText_loc@, FemaleText_loc@ FROM locales_broadcast_text", CONNECTION_SYNCH);
+
+ // TaxiPathNode.db2
+ PrepareStatement(HOTFIX_SEL_TAXI_PATH_NODE, "SELECT * FROM taxi_path_node ORDER BY ID DESC", CONNECTION_SYNCH);
+}
+
+void HotfixDatabaseConnection::PrepareLocaleStatement(uint32 index, uint32 localeIndex, const char* sql, ConnectionFlags flags)
+{
+ Tokenizer tokens(sql, '@');
+ std::ostringstream stmt;
+ stmt << tokens[0];
+ for (std::size_t i = 1; i < tokens.size(); ++i)
+ stmt << localeIndex << tokens[i];
+
+ PrepareStatement(index, stmt.str().c_str(), flags);
}
diff --git a/src/server/shared/Database/Implementation/HotfixDatabase.h b/src/server/shared/Database/Implementation/HotfixDatabase.h
index 4e434a1dad6..37234277838 100644
--- a/src/server/shared/Database/Implementation/HotfixDatabase.h
+++ b/src/server/shared/Database/Implementation/HotfixDatabase.h
@@ -30,6 +30,9 @@ class HotfixDatabaseConnection : public MySQLConnection
//- Loads database type specific prepared statements
void DoPrepareStatements() override;
+
+ private:
+ void PrepareLocaleStatement(uint32 index, uint32 localeIndex, const char* sql, ConnectionFlags flags);
};
typedef DatabaseWorkerPool<HotfixDatabaseConnection> HotfixDatabaseWorkerPool;
@@ -40,9 +43,20 @@ enum HotfixDatabaseStatements
{DB}_{SEL/INS/UPD/DEL/REP}_{Summary of data changed}
When updating more than one field, consider looking at the calling function
name for a suiting suffix.
+
+ DB2 locale loading statements must have the name of base statement with locale enum value name suffix
*/
HOTFIX_SEL_BROADCAST_TEXT,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_koKR,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_frFR,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_deDE,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_zhCN,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_zhTW,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_esES,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_esMX,
+ HOTFIX_SEL_BROADCAST_TEXT_LOCALE_ruRU,
+
HOTFIX_SEL_TAXI_PATH_NODE,
MAX_HOTFIXDATABASE_STATEMENTS
};