From 25073fa927597301d943f7cd2d302f8ba5c8cbb8 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Tue, 7 Jul 2020 13:59:13 +0200 Subject: [PATCH] Core/Datastores: cleaned up some master exclusive code and fixed an issue that was causing default localized strings being sent for all remaining fields, despite having available locales --- .../shared/DataStores/DB2StorageLoader.cpp | 24 +++++++------------ src/server/shared/DataStores/DB2Store.h | 7 +++--- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/server/shared/DataStores/DB2StorageLoader.cpp b/src/server/shared/DataStores/DB2StorageLoader.cpp index 32b889f20d5..0c8f4d60c5d 100644 --- a/src/server/shared/DataStores/DB2StorageLoader.cpp +++ b/src/server/shared/DataStores/DB2StorageLoader.cpp @@ -325,15 +325,13 @@ char* DB2FileLoader::AutoProduceStringsArrayHolders(char const* format, char* da return nullptr; // we store flat holders pool as single memory block - std::size_t stringFields = GetFormatStringFieldCount(format); - if (!stringFields) - return nullptr; - std::size_t localizedStringFields = GetFormatStringFieldCount(format); + if (!localizedStringFields) + return nullptr; // each string field at load have array of string for each locale std::size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; - std::size_t stringHoldersRecordPoolSize = localizedStringFields * stringHolderSize + (stringFields - localizedStringFields) * sizeof(char*); + std::size_t stringHoldersRecordPoolSize = localizedStringFields * stringHolderSize; std::size_t stringHoldersPoolSize = stringHoldersRecordPoolSize * recordCount; char* stringHoldersPool = new char[stringHoldersPoolSize]; @@ -366,11 +364,7 @@ char* DB2FileLoader::AutoProduceStringsArrayHolders(char const* format, char* da // init db2 string field slots by pointers to string holders char const*** slot = (char const***)(&dataTable[offset]); *slot = (char const**)(&stringHoldersPool[stringHoldersRecordPoolSize * y + stringFieldOffset]); - if (format[x] == FT_STRING) - stringFieldOffset += stringHolderSize; - else - ++stringFieldOffset; - + stringFieldOffset += stringHolderSize; offset += sizeof(char*); break; } @@ -444,19 +438,19 @@ char* DB2DatabaseLoader::Load(const char* format, int32 preparedStatement, uint3 uint32 recordSize = DB2FileLoader::GetFormatRecordSize(format, &indexField); // we store flat holders pool as single memory block - size_t stringFields = DB2FileLoader::GetFormatStringFieldCount(format); + std::size_t stringFields = DB2FileLoader::GetFormatStringFieldCount(format); // each string field at load have array of string for each locale - size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; - size_t stringHoldersRecordPoolSize = stringFields * stringHolderSize; + std::size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; + std::size_t stringHoldersRecordPoolSize = stringFields * stringHolderSize; if (stringFields) { - size_t stringHoldersPoolSize = stringHoldersRecordPoolSize * result->GetRowCount(); + std::size_t stringHoldersPoolSize = stringHoldersRecordPoolSize * result->GetRowCount(); stringHolders = new char[stringHoldersPoolSize]; // DB2 strings expected to have at least empty string - for (size_t i = 0; i < stringHoldersPoolSize / sizeof(char*); ++i) + for (std::size_t i = 0; i < stringHoldersPoolSize / sizeof(char*); ++i) ((char const**)stringHolders)[i] = nullStr; } else diff --git a/src/server/shared/DataStores/DB2Store.h b/src/server/shared/DataStores/DB2Store.h index c8f21785cc6..49ee6a2a2dc 100644 --- a/src/server/shared/DataStores/DB2Store.h +++ b/src/server/shared/DataStores/DB2Store.h @@ -92,11 +92,12 @@ public: break; case FT_STRING: { + uint32 selectedLocale = locale; LocalizedString* locStr = *(LocalizedString**)entry; - if (locStr->Str[locale][0] == '\0') - locale = 0; + if (locStr->Str[selectedLocale][0] == '\0') + selectedLocale = 0; - char const* str = locStr->Str[locale]; + char const* str = locStr->Str[selectedLocale]; std::size_t len = strlen(str); buffer << uint16(len ? len : 0); if (len)