diff options
author | Machiavelli <none@none> | 2010-09-24 22:16:21 +0200 |
---|---|---|
committer | Machiavelli <none@none> | 2010-09-24 22:16:21 +0200 |
commit | 3c6dc320308880bde4ef9eddd695db28a74aa0d9 (patch) | |
tree | f209e6c487e436fc1cd978487dddf3604ce2b594 /src | |
parent | b46b498141cc167163c6112e8e2bfa32fec2d7dc (diff) |
Core/DBLayer:
- Rewrite Field class to be able to store both binary prepared statement data and data from adhoc query resultsets
- Buffer the data of prepared statements using ResultSet and Field classes and let go of mysql c api structures after PreparedResultSet constructor. Fixes a race condition and thus a possible crash/data corruption (issue pointed out to Derex, basic suggestion by raczman)
- Conform PreparedResultSet and ResultSet to the same design standards, and using Field class as data buffer class for both
* NOTE: This means the fetching methods are uniform again, using ¨Field* fields = result->Fetch();¨ and access to elements trough fields[x].
* NOTE: for access to the correct row in prepared statements, ¨Field* fields = result->Fetch();¨ must ALWAYS be called inside the do { }while(result->NextRow()) loop.
* NOTE: This means that Field::GetString() returns std::string object and Field::GetCString() returns const char* pointer.
Still experimental and all that jazz, not recommended for production servers until feedback is given.
--HG--
branch : trunk
Diffstat (limited to 'src')
47 files changed, 970 insertions, 842 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp index 493614bc963..665fe7b6aee 100644 --- a/src/server/authserver/Realms/RealmList.cpp +++ b/src/server/authserver/Realms/RealmList.cpp @@ -86,21 +86,22 @@ void RealmList::UpdateRealms(bool init) { do { - uint32 realmId = result->GetUInt32(0); - const std::string& name = result->GetString(1); - const std::string& address = result->GetString(2); - uint32 port = result->GetUInt32(3); - uint8 icon = result->GetUInt8(4); - uint8 color = result->GetUInt8(5); - uint8 timezone = result->GetUInt8(6); - uint8 allowedSecurityLevel = result->GetUInt8(7); - float pop = result->GetFloat(8); - uint32 build = result->GetUInt32(9); + Field* fields = result->Fetch(); + uint32 realmId = fields[0].GetUInt32(); + const std::string& name = fields[1].GetString(); + const std::string& address = fields[2].GetString(); + uint32 port = fields[3].GetUInt32(); + uint8 icon = fields[4].GetUInt8(); + uint8 color = fields[5].GetUInt8(); + uint8 timezone = fields[6].GetUInt8(); + uint8 allowedSecurityLevel = fields[7].GetUInt8(); + float pop = fields[8].GetFloat(); + uint32 build = fields[9].GetUInt32(); UpdateRealm(realmId, name, address, port, icon, color, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build); if (init) - sLog.outString("Added realm \"%s\".", result->GetString(1).c_str()); + sLog.outString("Added realm \"%s\".", fields[1].GetCString()); } while (result->NextRow()); } diff --git a/src/server/authserver/Server/AuthSocket.cpp b/src/server/authserver/Server/AuthSocket.cpp index d908f60ef52..529cfc8ff3d 100644 --- a/src/server/authserver/Server/AuthSocket.cpp +++ b/src/server/authserver/Server/AuthSocket.cpp @@ -383,13 +383,15 @@ bool AuthSocket::_HandleLogonChallenge() PreparedQueryResult res2 = LoginDatabase.Query(stmt); if (res2) { + Field* fields = res2->Fetch(); + ///- If the IP is 'locked', check that the player comes indeed from the correct IP address bool locked = false; - if (res2->GetUInt8(2) == 1) // if ip is locked + if (fields[2].GetUInt8() == 1) // if ip is locked { - sLog.outStaticDebug("[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), res2->GetCString(3)); + sLog.outStaticDebug("[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[3].GetCString()); sLog.outStaticDebug("[AuthChallenge] Player address is '%s'", ip_address.c_str()); - if (strcmp(res2->GetCString(3), ip_address.c_str())) + if (strcmp(fields[3].GetCString(), ip_address.c_str())) { sLog.outStaticDebug("[AuthChallenge] Account IP differs"); pkt << (uint8) WOW_FAIL_SUSPENDED; @@ -410,11 +412,11 @@ bool AuthSocket::_HandleLogonChallenge() ///- If the account is banned, reject the logon attempt stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCBANNED); - stmt->setUInt32(0, res2->GetUInt32(1)); + stmt->setUInt32(0, fields[1].GetUInt32()); PreparedQueryResult banresult = LoginDatabase.Query(stmt); if (banresult) { - if (banresult->GetUInt64(0) == banresult->GetUInt64(1)) + if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) { pkt << (uint8) WOW_FAIL_BANNED; sLog.outBasic("[AuthChallenge] Banned account %s tries to login!", _login.c_str()); @@ -428,11 +430,11 @@ bool AuthSocket::_HandleLogonChallenge() else { ///- Get the password from the account table, upper it, and make the SRP6 calculation - std::string rI = res2->GetString(0); + std::string rI = fields[0].GetString(); ///- Don't calculate (v, s) if there are already some in the database - std::string databaseV = res2->GetString(5); - std::string databaseS = res2->GetString(6); + std::string databaseV = fields[5].GetString(); + std::string databaseS = fields[6].GetString(); sLog.outDebug("database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str()); @@ -486,7 +488,7 @@ bool AuthSocket::_HandleLogonChallenge() if (securityFlags & 0x04) // Security token input pkt << uint8(1); - uint8 secLevel = res2->GetUInt8(4); + uint8 secLevel = fields[4].GetUInt8(); _accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR; _localizationName.resize(4); @@ -658,6 +660,7 @@ bool AuthSocket::_HandleLogonProof() { char data[4]= { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0}; socket().send(data, sizeof(data)); + sLog.outBasic("[AuthChallenge] account %s tried to login with wrong password!",_login.c_str ()); uint32 MaxWrongPassCount = sConfig.GetIntDefault("WrongPass.MaxCount", 0); @@ -673,7 +676,7 @@ bool AuthSocket::_HandleLogonProof() if (PreparedQueryResult loginfail = LoginDatabase.Query(stmt)) { - uint32 failed_logins = loginfail->GetUInt32(1); + uint32 failed_logins = (*loginfail)[1].GetUInt32(); if (failed_logins >= MaxWrongPassCount) { @@ -682,7 +685,7 @@ bool AuthSocket::_HandleLogonProof() if (WrongPassBanType) { - uint32 acc_id = loginfail->GetUInt32(0); + uint32 acc_id = (*loginfail)[0].GetUInt32(); stmt = LoginDatabase.GetPreparedStatement(LOGIN_SET_ACCAUTOBANNED); stmt->setUInt32(0, acc_id); stmt->setUInt32(1, WrongPassBanTime); @@ -753,7 +756,7 @@ bool AuthSocket::_HandleReconnectChallenge() return false; } - K.SetHexStr (result->GetCString(0)); + K.SetHexStr ((*result)[0].GetCString()); ///- Sending response ByteBuffer pkt; @@ -831,7 +834,8 @@ bool AuthSocket::_HandleRealmList() return false; } - uint32 id = result->GetUInt32(0); + Field* fields = result->Fetch(); + uint32 id = fields[0].GetUInt32(); ///- Update realm list if need sRealmList->UpdateIfNeed(); @@ -862,7 +866,7 @@ bool AuthSocket::_HandleRealmList() stmt->setUInt32(1, id); result = LoginDatabase.Query(stmt); if (result) - AmountOfCharacters = result->GetUInt8(0); + AmountOfCharacters = (*result)[0].GetUInt8(); else AmountOfCharacters = 0; diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index e74349deb43..3800cf91abf 100644 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -183,7 +183,7 @@ bool AccountMgr::GetName(uint32 acc_id, std::string &name) QueryResult result = LoginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id); if (result) { - name = (*result)[0].GetCppString(); + name = (*result)[0].GetString(); return true; } diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index 1bd69e7333c..559b5e1797e 100644 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -559,27 +559,30 @@ void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQ { if (achievementResult) { + Field* fields = achievementResult->Fetch(); do { - uint32 achievement_id = achievementResult->GetUInt32(0); + uint32 achievement_id = fields[0].GetUInt32(); // don't must happen: cleanup at server startup in sAchievementMgr.LoadCompletedAchievements() if (!sAchievementStore.LookupEntry(achievement_id)) continue; CompletedAchievementData& ca = m_completedAchievements[achievement_id]; - ca.date = time_t(achievementResult->GetUInt64(1)); + ca.date = time_t(fields[1].GetUInt64()); ca.changed = false; - } while (achievementResult->NextRow()); + } + while (achievementResult->NextRow()); } if (criteriaResult) { + Field* fields = criteriaResult->Fetch(); do { - uint32 id = criteriaResult->GetUInt32(0); - uint32 counter = criteriaResult->GetUInt32(1); - time_t date = time_t(criteriaResult->GetUInt64(2)); + uint32 id = fields[0].GetUInt32(); + uint32 counter = fields[1].GetUInt32(); + time_t date = time_t(fields[2].GetUInt64()); AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(id); if (!criteria) @@ -597,9 +600,9 @@ void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQ progress.counter = counter; progress.date = date; progress.changed = false; - } while (criteriaResult->NextRow()); + } + while (criteriaResult->NextRow()); } - } void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement) @@ -2129,7 +2132,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData() } uint32 dataType = fields[1].GetUInt32(); - const char* scriptName = fields[4].GetString(); + const char* scriptName = fields[4].GetCString(); uint32 scriptId = 0; if (strcmp(scriptName, "")) // not empty { @@ -2312,8 +2315,8 @@ void AchievementGlobalMgr::LoadRewards() reward.titleId[1] = fields[2].GetUInt32(); reward.itemId = fields[3].GetUInt32(); reward.sender = fields[4].GetUInt32(); - reward.subject = fields[5].GetCppString(); - reward.text = fields[6].GetCppString(); + reward.subject = fields[5].GetString(); + reward.text = fields[6].GetString(); // must be title or mail at least if (!reward.titleId[0] && !reward.titleId[1] && !reward.sender) @@ -2422,10 +2425,10 @@ void AchievementGlobalMgr::LoadRewardLocales() for (int i = 1; i < MAX_LOCALE; ++i) { LocaleConstant locale = (LocaleConstant) i; - std::string str = fields[1 + 2 * (i - 1)].GetCppString(); + std::string str = fields[1 + 2 * (i - 1)].GetString(); sObjectMgr.AddLocaleString(str, locale, data.subject); - str = fields[1 + 2 * (i - 1) + 1].GetCppString(); + str = fields[1 + 2 * (i - 1) + 1].GetString(); sObjectMgr.AddLocaleString(str, locale, data.text); } } while (result->NextRow()); diff --git a/src/server/game/Addons/AddonMgr.cpp b/src/server/game/Addons/AddonMgr.cpp index 3a4b0e062b0..478e3d9307b 100644 --- a/src/server/game/Addons/AddonMgr.cpp +++ b/src/server/game/Addons/AddonMgr.cpp @@ -52,7 +52,7 @@ void AddonMgr::LoadFromDB() bar.step(); count++; - std::string name = fields[0].GetCppString(); + std::string name = fields[0].GetString(); uint32 crc = fields[1].GetUInt32(); SavedAddon addon(name, crc); diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 5c027e7b00b..28ceecf4684 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -324,9 +324,11 @@ void AuctionHouseMgr::LoadAuctionItems() do { bar.step(); + + Field* fields = result->Fetch(); - uint32 item_guid = result->GetUInt32(11); - uint32 item_template = result->GetUInt32(12); + uint32 item_guid = fields[11].GetUInt32(); + uint32 item_template = fields[12].GetUInt32(); ItemPrototype const *proto = sObjectMgr.GetItemPrototype(item_template); @@ -346,7 +348,8 @@ void AuctionHouseMgr::LoadAuctionItems() AddAItem(item); ++count; - } while (result->NextRow()); + } + while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u auction items", count); diff --git a/src/server/game/Battlegrounds/ArenaTeam.cpp b/src/server/game/Battlegrounds/ArenaTeam.cpp index c1d0590eedf..3e90e3fa01a 100644 --- a/src/server/game/Battlegrounds/ArenaTeam.cpp +++ b/src/server/game/Battlegrounds/ArenaTeam.cpp @@ -128,7 +128,7 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid) if (!result) return false; - plName = (*result)[0].GetCppString(); + plName = (*result)[0].GetString(); plClass = (*result)[1].GetUInt8(); // check if player already in arenateam of that size @@ -186,7 +186,7 @@ bool ArenaTeam::LoadArenaTeamFromDB(QueryResult arenaTeamDataResult) Field *fields = arenaTeamDataResult->Fetch(); m_TeamId = fields[0].GetUInt32(); - m_Name = fields[1].GetCppString(); + m_Name = fields[1].GetString(); m_CaptainGuid = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER); m_Type = fields[3].GetUInt32(); m_BackgroundColor = fields[4].GetUInt32(); @@ -251,7 +251,7 @@ bool ArenaTeam::LoadMembersFromDB(QueryResult arenaTeamMembersResult) newmember.wins_week = fields[3].GetUInt32(); newmember.games_season = fields[4].GetUInt32(); newmember.wins_season = fields[5].GetUInt32(); - newmember.name = fields[6].GetCppString(); + newmember.name = fields[6].GetString(); newmember.Class = fields[7].GetUInt8(); newmember.personal_rating = personalrating; newmember.matchmaker_rating = matchmakerrating; diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index 899ef6074b7..868c6b80018 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -774,7 +774,7 @@ void BattlegroundMgr::CreateInitialBattlegrounds() } selectionWeight = fields[9].GetUInt8(); - scriptId = sObjectMgr.GetScriptId(fields[10].GetString()); + scriptId = sObjectMgr.GetScriptId(fields[10].GetCString()); //sLog.outDetail("Creating battleground %s, %u-%u", bl->name[sWorld.GetDBClang()], MinLvl, MaxLvl); if (!CreateBattleground(bgTypeID, IsArena, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, bl->name[sWorld.GetDefaultDbcLocale()], bl->mapid[0], AStartLoc[0], AStartLoc[1], AStartLoc[2], AStartLoc[3], HStartLoc[0], HStartLoc[1], HStartLoc[2], HStartLoc[3], scriptId)) continue; diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index ccb797e6491..2ec6a040b91 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -62,7 +62,7 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) m_moderate = fields[1].GetBool(); m_public = fields[2].GetBool(); m_password = fields[3].GetString(); - const char* db_BannedList = fields[4].GetString(); + const char* db_BannedList = fields[4].GetCString(); m_IsSaved = true; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index fd855fc82e1..a0175b43533 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -814,9 +814,9 @@ ChatCommand * ChatHandler::getCommandTable() do { Field *fields = result->Fetch(); - std::string name = fields[0].GetCppString(); + std::string name = fields[0].GetString(); - SetDataForCommandInTable(commandTable, name.c_str(), fields[1].GetUInt16(), fields[2].GetCppString(), name); + SetDataForCommandInTable(commandTable, name.c_str(), fields[1].GetUInt16(), fields[2].GetString(), name); } while (result->NextRow()); } diff --git a/src/server/game/Chat/Commands/Level2.cpp b/src/server/game/Chat/Commands/Level2.cpp index 4c58d7c4775..1916b77bb88 100644 --- a/src/server/game/Chat/Commands/Level2.cpp +++ b/src/server/game/Chat/Commands/Level2.cpp @@ -2210,17 +2210,17 @@ bool ChatHandler::HandlePInfoCommand(const char* args) if (result) { Field* fields = result->Fetch(); - username = fields[0].GetCppString(); + username = fields[0].GetString(); security = fields[1].GetUInt32(); - email = fields[2].GetCppString(); + email = fields[2].GetString(); if (email.empty()) email = "-"; if (!m_session || m_session->GetSecurity() >= AccountTypes(security)) { - last_ip = fields[3].GetCppString(); - last_login = fields[4].GetCppString(); + last_ip = fields[3].GetString(); + last_login = fields[4].GetString(); } else { @@ -2528,7 +2528,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args) a4 = fields[2].GetUInt32(); a5 = fields[3].GetUInt32(); a6 = fields[4].GetUInt32(); - a7 = fields[5].GetString(); + a7 = fields[5].GetCString(); a8 = fields[6].GetFloat(); a9 = fields[7].GetFloat(); a10 = fields[8].GetFloat(); @@ -3856,7 +3856,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult result, int32 limit) Field* fields = result->Fetch(); uint32 acc_id = fields[0].GetUInt32(); - std::string acc_name = fields[1].GetCppString(); + std::string acc_name = fields[1].GetString(); QueryResult chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id); if (chars) @@ -3870,7 +3870,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult result, int32 limit) { Field* charfields = chars->Fetch(); guid = charfields[0].GetUInt64(); - name = charfields[1].GetCppString(); + name = charfields[1].GetString(); PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER,name.c_str(),guid); ++i; diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 01f696f9b3b..7be52c0b9ff 100644 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -324,21 +324,21 @@ bool ChatHandler::HandleReloadCreatureTemplateCommand(const char* args) const_cast<CreatureInfo*>(cInfo)->Modelid3 = fields[7].GetUInt32(); const_cast<CreatureInfo*>(cInfo)->Modelid4 = fields[8].GetUInt32(); size_t len = 0; - if (const char* temp = fields[9].GetString()) + if (const char* temp = fields[9].GetCString()) { delete[] cInfo->Name; len = strlen(temp)+1; const_cast<CreatureInfo*>(cInfo)->Name = new char[len]; strncpy(cInfo->Name, temp, len); } - if (const char* temp = fields[10].GetString()) + if (const char* temp = fields[10].GetCString()) { delete[] cInfo->SubName; len = strlen(temp)+1; const_cast<CreatureInfo*>(cInfo)->SubName = new char[len]; strncpy(cInfo->SubName, temp, len); } - if (const char* temp = fields[11].GetString()) + if (const char* temp = fields[11].GetCString()) { delete[] cInfo->IconName; len = strlen(temp)+1; @@ -397,7 +397,7 @@ bool ChatHandler::HandleReloadCreatureTemplateCommand(const char* args) const_cast<CreatureInfo*>(cInfo)->VehicleId = fields[61].GetUInt32(); const_cast<CreatureInfo*>(cInfo)->mingold = fields[62].GetUInt32(); const_cast<CreatureInfo*>(cInfo)->maxgold = fields[63].GetUInt32(); - if (const char* temp = fields[64].GetString()) + if (const char* temp = fields[64].GetCString()) { delete[] cInfo->AIName; len = strlen(temp)+1; @@ -421,7 +421,7 @@ bool ChatHandler::HandleReloadCreatureTemplateCommand(const char* args) const_cast<CreatureInfo*>(cInfo)->equipmentId = fields[79].GetUInt32(); const_cast<CreatureInfo*>(cInfo)->MechanicImmuneMask = fields[80].GetUInt32(); const_cast<CreatureInfo*>(cInfo)->flags_extra = fields[81].GetUInt32(); - const_cast<CreatureInfo*>(cInfo)->ScriptID = sObjectMgr.GetScriptId(fields[82].GetString()); + const_cast<CreatureInfo*>(cInfo)->ScriptID = sObjectMgr.GetScriptId(fields[82].GetCString()); sObjectMgr.CheckCreatureTemplate(cInfo); @@ -2649,7 +2649,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) uint32 item_slot = fields[2].GetUInt32(); uint32 owner_guid = fields[3].GetUInt32(); uint32 owner_acc = fields[4].GetUInt32(); - std::string owner_name = fields[5].GetCppString(); + std::string owner_name = fields[5].GetString(); char const* item_pos = 0; if (Player::IsEquipmentPos(item_bag,item_slot)) @@ -2700,9 +2700,9 @@ bool ChatHandler::HandleListItemCommand(const char *args) uint32 item_s = fields[1].GetUInt32(); uint32 item_r = fields[2].GetUInt32(); uint32 item_s_acc = fields[3].GetUInt32(); - std::string item_s_name = fields[4].GetCppString(); + std::string item_s_name = fields[4].GetString(); uint32 item_r_acc = fields[5].GetUInt32(); - std::string item_r_name = fields[6].GetCppString(); + std::string item_r_name = fields[6].GetString(); char const* item_pos = "[in mail]"; @@ -2743,7 +2743,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) uint32 item_guid = fields[0].GetUInt32(); uint32 owner = fields[1].GetUInt32(); uint32 owner_acc = fields[2].GetUInt32(); - std::string owner_name = fields[3].GetCppString(); + std::string owner_name = fields[3].GetString(); char const* item_pos = "[in auction]"; @@ -2770,7 +2770,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) Field *fields = result->Fetch(); uint32 item_guid = fields[0].GetUInt32(); uint32 guild_guid = fields[1].GetUInt32(); - std::string guild_name = fields[2].GetCppString(); + std::string guild_name = fields[2].GetString(); char const* item_pos = "[in guild bank]"; @@ -5895,7 +5895,7 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args) return false; } - target_guid = resultCharacter->GetUInt32(0); + target_guid = (*resultCharacter)[0].GetUInt32(); } else target_guid = target->GetGUIDLow(); @@ -5909,15 +5909,17 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args) PSendSysMessage(LANG_BANINFO_BANHISTORY, name.c_str()); do { - time_t unbandate = time_t(result->GetUInt64(3)); + Field* fields = result->Fetch(); + time_t unbandate = time_t(fields[3].GetUInt64()); bool active = false; - if (result->GetUInt8(2) && (!result->GetUInt64(1) || unbandate >= time(NULL))) + if (fields[2].GetUInt8() && (!fields[1].GetUInt64() || unbandate >= time(NULL))) active = true; - bool permanent = (result->GetUInt64(1) == uint64(0)); - std::string bantime = permanent ? GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(result->GetUInt64(1), true); + bool permanent = (fields[1].GetUInt64() == uint64(0)); + std::string bantime = permanent ? GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true); PSendSysMessage(LANG_BANINFO_HISTORYENTRY, - result->GetCString(0), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES) : GetTrinityString(LANG_BANINFO_NO), result->GetCString(4), result->GetCString(5)); - } while (result->NextRow()); + fields[0].GetCString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES) : GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString()); + } + while (result->NextRow()); return true; } @@ -6006,12 +6008,14 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args) { do { + Field* fields = result->Fetch(); PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_GET_BANNED_NAME); - stmt2->setUInt32(0, result->GetUInt32(0)); + stmt2->setUInt32(0, fields[0].GetUInt32()); PreparedQueryResult banresult = CharacterDatabase.Query(stmt2); if (banresult) - PSendSysMessage("%s", banresult->GetCString(0)); - } while (result->NextRow()); + PSendSysMessage("%s", (*banresult)[0].GetCString()); + } + while (result->NextRow()); } // Console wide output else @@ -6023,38 +6027,41 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args) { SendSysMessage("-------------------------------------------------------------------------------"); - std::string char_name; + Field* fields = result->Fetch(); - char_name = result->GetString(1); + std::string char_name = fields[1].GetString(); PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_GET_BANINFO_LIST); - stmt2->setUInt32(0, result->GetUInt32(0)); + stmt2->setUInt32(0, fields[0].GetUInt32()); PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2); if (banInfo) { + Field* banFields = banInfo->Fetch(); do { - time_t t_ban = banInfo->GetUInt64(0); + time_t t_ban = banFields[0].GetUInt64(); tm* aTm_ban = localtime(&t_ban); - if (banInfo->GetUInt64(0) == banInfo->GetUInt64(1)) + if (banFields[0].GetUInt64() == banFields[1].GetUInt64()) { PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|", char_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, - banInfo->GetCString(2), banInfo->GetCString(3)); + banFields[2].GetCString(), banFields[3].GetCString()); } else { - time_t t_unban = banInfo->GetUInt64(1); + time_t t_unban = banFields[1].GetUInt64(); tm* aTm_unban = localtime(&t_unban); PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", char_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min, - banInfo->GetCString(2), banInfo->GetCString(3)); + banFields[2].GetCString(), banFields[3].GetCString()); } - } while (banInfo->NextRow()); + } + while (banInfo->NextRow()); } - } while (result->NextRow()); + } + while (result->NextRow()); SendSysMessage(" =============================================================================== "); } @@ -6128,7 +6135,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult result) // "account" case, name can be get in same query if (result->GetFieldCount() > 1) - account_name = fields[1].GetCppString(); + account_name = fields[1].GetString(); // "character" case, name need extract from another DB else sAccountMgr.GetName (account_id,account_name); @@ -7537,7 +7544,7 @@ bool ChatHandler::HandleListFreezeCommand(const char * /*args*/) do { Field *fields = result->Fetch(); - std::string fplayers = fields[0].GetCppString(); + std::string fplayers = fields[0].GetString(); PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str()); } while (result->NextRow()); diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index f212789098f..41fe265161d 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -353,7 +353,7 @@ void ConditionMgr::LoadConditions(bool isReload) cond->mConditionValue2 = fields[6].GetUInt32(); cond->mConditionValue3 = fields[7].GetUInt32(); cond->ErrorTextd = fields[8].GetUInt32(); - cond->mScriptId = sObjectMgr.GetScriptId(fields[9].GetString()); + cond->mScriptId = sObjectMgr.GetScriptId(fields[9].GetCString()); if (iConditionTypeOrReference >= 0) cond->mConditionType = ConditionType(iConditionTypeOrReference); diff --git a/src/server/game/Entities/Corpse/Corpse.cpp b/src/server/game/Entities/Corpse/Corpse.cpp index dff6caf5d94..4b8bf87b4cc 100644 --- a/src/server/game/Entities/Corpse/Corpse.cpp +++ b/src/server/game/Entities/Corpse/Corpse.cpp @@ -172,7 +172,7 @@ bool Corpse::LoadFromDB(uint32 guid, Field *fields) Object::_Create(guid, 0, HIGHGUID_CORPSE); SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32()); - _LoadIntoDataField(fields[6].GetString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END); + _LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END); SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32()); SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32()); SetUInt32Value(CORPSE_FIELD_GUILD, fields[9].GetUInt32()); diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp index ccd06764bb1..e34c8dfeeeb 100644 --- a/src/server/game/Entities/Item/Item.cpp +++ b/src/server/game/Entities/Item/Item.cpp @@ -408,16 +408,18 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, PreparedQueryResult result return false; } + Field* fields = result->Fetch(); + // set owner (not if item is only loaded for gbank/auction/mail if (owner_guid != 0) SetOwnerGUID(owner_guid); bool need_save = false; // need explicit save data at load fixes - SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(result->GetUInt32(0), 0, HIGHGUID_PLAYER)); - SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(result->GetUInt32(1), 0, HIGHGUID_PLAYER)); - SetCount(result->GetUInt32(2)); + SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER)); + SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER)); + SetCount(fields[2].GetUInt32()); - uint32 duration = result->GetUInt32(3); + uint32 duration = fields[3].GetUInt32(); SetUInt32Value(ITEM_FIELD_DURATION, duration); // update duration if need, and remove if not need if ((proto->Duration == 0) != (duration == 0)) @@ -426,12 +428,12 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, PreparedQueryResult result need_save = true; } - Tokens tokens = StrSplit(result->GetString(4), " "); + Tokens tokens = StrSplit(fields[4].GetString(), " "); if (tokens.size() == MAX_ITEM_PROTO_SPELLS) for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i, atoi(tokens[i].c_str())); - SetUInt32Value(ITEM_FIELD_FLAGS, result->GetUInt32(5)); + SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32()); // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { @@ -439,13 +441,13 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, PreparedQueryResult result need_save = true; } - _LoadIntoDataField(result->GetString(6).c_str(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET); - SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, result->GetInt32(7)); + _LoadIntoDataField(fields[6].GetCString(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET); + SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt32()); // recalculate suffix factor if (GetItemRandomPropertyId() < 0) UpdateItemSuffixFactor(); - uint32 durability = result->GetUInt32(8); + uint32 durability = fields[8].GetUInt32(); SetUInt32Value(ITEM_FIELD_DURABILITY, durability); // update max durability (and durability) if need SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); @@ -455,8 +457,8 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, PreparedQueryResult result need_save = true; } - SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, result->GetUInt32(9)); - SetText(result->GetString(10)); + SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32()); + SetText(fields[10].GetString()); if (need_save) // normal item changed state set not work at loading { diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 277e7e04956..a85147ce4c5 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -299,7 +299,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c // load action bar, if data broken will fill later by default spells. if (!is_temporary_summoned) { - m_charmInfo->LoadPetActionBar(fields[13].GetCppString()); + m_charmInfo->LoadPetActionBar(fields[13].GetString()); _LoadSpells(); InitTalentForLevel(); // re-init to check talent count @@ -331,7 +331,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c Field *fields2 = result->Fetch(); for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) { - m_declinedname->name[i] = fields2[i].GetCppString(); + m_declinedname->name[i] = fields2[i].GetString(); } } } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 37e55170d03..1e2cdd86295 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1652,7 +1652,7 @@ bool Player::BuildEnumData(QueryResult result, WorldPacket * p_data) char_flags |= CHARACTER_FLAG_LOCKED_BY_BILLING; if (sWorld.getBoolConfig(CONFIG_DECLINED_NAMES_USED)) { - if (!fields[21].GetCppString().empty()) + if (!fields[21].GetString().empty()) char_flags |= CHARACTER_FLAG_DECLINED; } else @@ -1697,7 +1697,7 @@ bool Player::BuildEnumData(QueryResult result, WorldPacket * p_data) *p_data << uint32(petFamily); } - Tokens data = StrSplit(fields[19].GetCppString(), " "); + Tokens data = StrSplit(fields[19].GetString(), " "); for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot) { uint32 visualbase = slot * 2; @@ -3940,13 +3940,14 @@ void Player::_LoadSpellCooldowns(PreparedQueryResult result) do { - uint32 spell_id = result->GetUInt32(0); - uint32 item_id = result->GetUInt32(1); - time_t db_time = (time_t)result->GetUInt64(2); + Field* fields = result->Fetch(); + uint32 spell_id = fields[0].GetUInt32(); + uint32 item_id = fields[1].GetUInt32(); + time_t db_time = (time_t)fields[2].GetUInt64(); if (!sSpellStore.LookupEntry(spell_id)) { - sLog.outError("Player %u has unknown spell %u in `character_spell_cooldown`, skipping.",GetGUIDLow(),spell_id); + sLog.outError("Player %u has unknown spell %u in `character_spell_cooldown`, skipping.", GetGUIDLow(), spell_id); continue; } @@ -4469,8 +4470,8 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC uint16 mailType = fields[1].GetUInt16(); uint16 mailTemplateId= fields[2].GetUInt16(); uint32 sender = fields[3].GetUInt32(); - std::string subject = fields[4].GetCppString(); - std::string body = fields[5].GetCppString(); + std::string subject = fields[4].GetString(); + std::string body = fields[5].GetString(); uint32 money = fields[6].GetUInt32(); bool has_items = fields[7].GetBool(); @@ -4500,8 +4501,8 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC { do { - uint32 item_guidlow = resultItems->GetUInt32(11); - uint32 item_template = resultItems->GetUInt32(12); + uint32 item_guidlow = (*resultItems)[11].GetUInt32(); + uint32 item_template = (*resultItems)[12].GetUInt32(); ItemPrototype const* itemProto = sObjectMgr.GetItemPrototype(item_template); if (!itemProto) @@ -15768,7 +15769,7 @@ void Player::_LoadDeclinedNames(PreparedQueryResult result) delete m_declinedname; m_declinedname = new DeclinedName; for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - m_declinedname->name[i] = result->GetString(i); + m_declinedname->name[i] = (*result)[i].GetString(); } void Player::_LoadArenaTeamInfo(PreparedQueryResult result) @@ -15780,10 +15781,12 @@ void Player::_LoadArenaTeamInfo(PreparedQueryResult result) do { - uint32 arenateamid = result->GetUInt32(0); - uint32 played_week = result->GetUInt32(1); - uint32 played_season = result->GetUInt32(2); - uint32 wons_season = result->GetUInt32(3); + Field* fields = result->Fetch(); + + uint32 arenateamid = fields[0].GetUInt32(); + uint32 played_week = fields[1].GetUInt32(); + uint32 played_season = fields[2].GetUInt32(); + uint32 wons_season = fields[3].GetUInt32(); ArenaTeam* aTeam = sObjectMgr.GetArenaTeamById(arenateamid); if (!aTeam) @@ -15800,7 +15803,8 @@ void Player::_LoadArenaTeamInfo(PreparedQueryResult result) SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_WEEK, played_week); SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_SEASON, played_season); SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_WINS_SEASON, wons_season); - } while (result->NextRow()); + } + while (result->NextRow()); } void Player::_LoadArenaStatsInfo(PreparedQueryResult result) @@ -15818,9 +15822,11 @@ void Player::_LoadArenaStatsInfo(PreparedQueryResult result) do { + Field* fields = result->Fetch(); + uint32 personalrating = 0; uint32 matchmakerrating = 1500; - if (result->GetUInt8(0) > slot) + if (fields[0].GetUInt8() > slot) { CharacterDatabase.PExecute("INSERT INTO character_arena_stats (guid, slot, personal_rating, matchmaker_rating) VALUES (%u, %u, %u, %u)", GetGUIDLow(), slot, personalrating, matchmakerrating); SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, personalrating); @@ -15828,11 +15834,12 @@ void Player::_LoadArenaStatsInfo(PreparedQueryResult result) continue; } - personalrating = result->GetUInt32(1); - matchmakerrating = result->GetUInt32(2); + personalrating = fields[1].GetUInt32(); + matchmakerrating = fields[2].GetUInt32(); SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, personalrating); slot++; - } while (result->NextRow()); + } + while (result->NextRow()); } void Player::_LoadEquipmentSets(PreparedQueryResult result) @@ -15844,16 +15851,17 @@ void Player::_LoadEquipmentSets(PreparedQueryResult result) uint32 count = 0; do { + Field* fields = result->Fetch(); EquipmentSet eqSet; - eqSet.Guid = result->GetUInt64(0); - uint32 index = result->GetUInt32(1); - eqSet.Name = result->GetString(2); - eqSet.IconName = result->GetString(3); + eqSet.Guid = fields[0].GetUInt64(); + uint32 index = fields[1].GetUInt32(); + eqSet.Name = fields[2].GetString(); + eqSet.IconName = fields[3].GetString(); eqSet.state = EQUIPMENT_SET_UNCHANGED; for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i) - eqSet.Items[i] = result->GetUInt32(4+i); + eqSet.Items[i] = fields[4+i].GetUInt32(); m_EquipmentSets[index] = eqSet; @@ -15861,7 +15869,8 @@ void Player::_LoadEquipmentSets(PreparedQueryResult result) if (count >= MAX_EQUIPMENT_SET_INDEX) // client limit break; - } while (result->NextRow()); + } + while (result->NextRow()); } void Player::_LoadBGData(PreparedQueryResult result) @@ -15869,18 +15878,19 @@ void Player::_LoadBGData(PreparedQueryResult result) if (!result) return; + Field* fields = result->Fetch(); // Expecting only one row /* bgInstanceID, bgTeam, x, y, z, o, map, taxi[0], taxi[1], mountSpell */ - m_bgData.bgInstanceID = result->GetUInt32(0); - m_bgData.bgTeam = result->GetUInt32(1); - m_bgData.joinPos = WorldLocation(result->GetUInt32(6), // Map - result->GetFloat(2), // X - result->GetFloat(3), // Y - result->GetFloat(4), // Z - result->GetFloat(5)); // Orientation - m_bgData.taxiPath[0] = result->GetUInt32(7); - m_bgData.taxiPath[1] = result->GetUInt32(8); - m_bgData.mountSpell = result->GetUInt32(9); + m_bgData.bgInstanceID = fields[0].GetUInt32(); + m_bgData.bgTeam = fields[1].GetUInt32(); + m_bgData.joinPos = WorldLocation(fields[6].GetUInt32(), // Map + fields[2].GetFloat(), // X + fields[3].GetFloat(), // Y + fields[4].GetFloat(), // Z + fields[5].GetFloat()); // Orientation + m_bgData.taxiPath[0] = fields[7].GetUInt32(); + m_bgData.taxiPath[1] = fields[8].GetUInt32(); + m_bgData.mountSpell = fields[9].GetUInt32(); } bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid) @@ -15896,7 +15906,7 @@ bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& z = fields[2].GetFloat(); o = fields[3].GetFloat(); mapid = fields[4].GetUInt32(); - in_flight = !fields[5].GetCppString().empty(); + in_flight = !fields[5].GetString().empty(); return true; } @@ -15950,8 +15960,10 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) sLog.outError("Player (GUID: %u) not found in table `characters`, can't load. ",guid); return false; } + + Field* fields = result->Fetch(); - uint32 dbAccountId = result->GetUInt32(1); + uint32 dbAccountId = fields[1].GetUInt32(); // check if the character's account in the db and the logged in account match. // player should be able to load/delete character only with correct account! @@ -15969,7 +15981,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) Object::_Create(guid, 0, HIGHGUID_PLAYER); - m_name = result->GetString(2); + m_name = fields[2].GetString(); // check name limitations if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS || @@ -15984,38 +15996,38 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) // overwrite some data fields uint32 bytes0 = 0; - bytes0 |= result->GetUInt8(3); // race - bytes0 |= result->GetUInt8(4) << 8; // class - bytes0 |= result->GetUInt8(5) << 16; // gender + bytes0 |= fields[3].GetUInt8(); // race + bytes0 |= fields[4].GetUInt8() << 8; // class + bytes0 |= fields[5].GetUInt8() << 16; // gender SetUInt32Value(UNIT_FIELD_BYTES_0, bytes0); - SetUInt32Value(UNIT_FIELD_LEVEL, result->GetUInt8(6)); - SetUInt32Value(PLAYER_XP, result->GetUInt32(7)); + SetUInt32Value(UNIT_FIELD_LEVEL, fields[6].GetUInt8()); + SetUInt32Value(PLAYER_XP, fields[7].GetUInt32()); - _LoadIntoDataField(result->GetString(61).c_str(), PLAYER_EXPLORED_ZONES_1, PLAYER_EXPLORED_ZONES_SIZE); - _LoadIntoDataField(result->GetString(64).c_str(), PLAYER__FIELD_KNOWN_TITLES, KNOWN_TITLES_SIZE*2); + _LoadIntoDataField(fields[61].GetCString(), PLAYER_EXPLORED_ZONES_1, PLAYER_EXPLORED_ZONES_SIZE); + _LoadIntoDataField(fields[64].GetCString(), PLAYER__FIELD_KNOWN_TITLES, KNOWN_TITLES_SIZE*2); SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE); SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f); SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f); - uint32 money = result->GetUInt32(8); + uint32 money = fields[8].GetUInt32(); if (money > MAX_MONEY_AMOUNT) money = MAX_MONEY_AMOUNT; SetMoney(money); - SetUInt32Value(PLAYER_BYTES, result->GetUInt32(9)); - SetUInt32Value(PLAYER_BYTES_2, result->GetUInt32(10)); - SetUInt32Value(PLAYER_BYTES_3, (result->GetUInt16(49) & 0xFFFE) | result->GetUInt8(5)); - SetUInt32Value(PLAYER_FLAGS, result->GetUInt32(11)); - SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, result->GetUInt32(48)); + SetUInt32Value(PLAYER_BYTES, fields[9].GetUInt32()); + SetUInt32Value(PLAYER_BYTES_2, fields[10].GetUInt32()); + SetUInt32Value(PLAYER_BYTES_3, (fields[49].GetUInt16() & 0xFFFE) | fields[5].GetUInt8()); + SetUInt32Value(PLAYER_FLAGS, fields[11].GetUInt32()); + SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fields[48].GetUInt32()); - SetUInt64Value(PLAYER_FIELD_KNOWN_CURRENCIES, result->GetUInt64(47)); + SetUInt64Value(PLAYER_FIELD_KNOWN_CURRENCIES, fields[47].GetUInt64()); - SetUInt32Value(PLAYER_AMMO_ID, result->GetUInt32(63)); + SetUInt32Value(PLAYER_AMMO_ID, fields[63].GetUInt32()); // set which actionbars the client has active - DO NOT REMOVE EVER AGAIN (can be changed though, if it does change fieldwise) - SetByteValue(PLAYER_FIELD_BYTES, 2, result->GetUInt8(65)); + SetByteValue(PLAYER_FIELD_BYTES, 2, fields[65].GetUInt8()); InitDisplayIds(); @@ -16043,21 +16055,21 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) InitPrimaryProfessions(); // to max set before any spell loaded // init saved position, and fix it later if problematic - uint32 transGUID = uint32(result->GetUInt64(30)); // field type is uint64 but lowguid is saved - Relocate(result->GetFloat(12), result->GetFloat(13), result->GetFloat(14), result->GetFloat(16)); - uint32 mapId = result->GetUInt32(15); - uint32 instanceId = result->GetUInt8(58); + uint32 transGUID = uint32(fields[30].GetUInt64()); // field type is uint64 but lowguid is saved + Relocate(fields[12].GetFloat(), fields[13].GetFloat(), fields[14].GetFloat(), fields[16].GetFloat()); + uint32 mapId = fields[15].GetUInt32(); + uint32 instanceId = fields[58].GetUInt8(); - uint32 dungeonDiff = result->GetUInt32(38) & 0x0F; + uint32 dungeonDiff = fields[38].GetUInt32() & 0x0F; if (dungeonDiff >= MAX_DUNGEON_DIFFICULTY) dungeonDiff = DUNGEON_DIFFICULTY_NORMAL; - uint32 raidDiff = (result->GetUInt8(38) >> 4) & 0x0F; + uint32 raidDiff = (fields[38].GetUInt8() >> 4) & 0x0F; if (raidDiff >= MAX_RAID_DIFFICULTY) raidDiff = RAID_DIFFICULTY_10MAN_NORMAL; SetDungeonDifficulty(Difficulty(dungeonDiff)); // may be changed in _LoadGroup SetRaidDifficulty(Difficulty(raidDiff)); // may be changed in _LoadGroup - std::string taxi_nodes = result->GetString(37); + std::string taxi_nodes = fields[37].GetString(); #define RelocateToHomebind(){ mapId = m_homebindMapId; instanceId = 0; Relocate(m_homebindX, m_homebindY, m_homebindZ); } @@ -16066,7 +16078,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) _LoadArenaTeamInfo(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADARENAINFO)); _LoadArenaStatsInfo(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADARENASTATS)); - uint32 arena_currency = result->GetUInt32(39); + uint32 arena_currency = fields[39].GetUInt32(); if (arena_currency > sWorld.getIntConfig(CONFIG_MAX_ARENA_POINTS)) arena_currency = sWorld.getIntConfig(CONFIG_MAX_ARENA_POINTS); @@ -16088,12 +16100,12 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SetArenaTeamInfoField(arena_slot, ArenaTeamInfoType(j), 0); } - SetHonorPoints(result->GetUInt32(40)); - SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, result->GetUInt32(41)); - SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, result->GetUInt32(42)); - SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, result->GetUInt32(43)); - SetUInt16Value(PLAYER_FIELD_KILLS, 0, result->GetUInt16(44)); - SetUInt16Value(PLAYER_FIELD_KILLS, 1, result->GetUInt16(45)); + SetHonorPoints(fields[40].GetUInt32()); + SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, fields[41].GetUInt32()); + SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, fields[42].GetUInt32()); + SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, fields[43].GetUInt32()); + SetUInt16Value(PLAYER_FIELD_KILLS, 0, fields[44].GetUInt16()); + SetUInt16Value(PLAYER_FIELD_KILLS, 1, fields[45].GetUInt16()); _LoadBoundInstances(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES)); _LoadBGData(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADBGDATA)); @@ -16153,7 +16165,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) else if (transGUID) { m_movementInfo.t_guid = MAKE_NEW_GUID(transGUID, 0, HIGHGUID_MO_TRANSPORT); - m_movementInfo.t_pos.Relocate(result->GetFloat(26), result->GetFloat(27), result->GetFloat(28), result->GetFloat(29)); + m_movementInfo.t_pos.Relocate(fields[26].GetFloat(), fields[27].GetFloat(), fields[28].GetFloat(), fields[29].GetFloat()); if (!Trinity::IsValidMapCoord( GetPositionX()+m_movementInfo.t_pos.m_positionX,GetPositionY()+m_movementInfo.t_pos.m_positionY, @@ -16312,7 +16324,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SaveRecallPosition(); time_t now = time(NULL); - time_t logoutTime = time_t(result->GetUInt64(22)); + time_t logoutTime = time_t(fields[22].GetUInt64()); // since last logout (in seconds) uint32 time_diff = uint32(now - logoutTime); //uint64 is excessive for a time_diff in seconds.. uint32 allows for 136~ year difference. @@ -16327,12 +16339,12 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) uint16 newDrunkenValue = uint16(soberFactor*(GetUInt32Value(PLAYER_BYTES_3) & 0xFFFE)); SetDrunkValue(newDrunkenValue); - m_cinematic = result->GetUInt8(18); - m_Played_time[PLAYED_TIME_TOTAL]= result->GetUInt32(19); - m_Played_time[PLAYED_TIME_LEVEL]= result->GetUInt32(20); + m_cinematic = fields[18].GetUInt8(); + m_Played_time[PLAYED_TIME_TOTAL]= fields[19].GetUInt32(); + m_Played_time[PLAYED_TIME_LEVEL]= fields[20].GetUInt32(); - m_resetTalentsCost = result->GetUInt32(24); - m_resetTalentsTime = time_t(result->GetUInt64(25)); + m_resetTalentsCost = fields[24].GetUInt32(); + m_resetTalentsTime = time_t(fields[25].GetUInt64()); // reserve some flags uint32 old_safe_flags = GetUInt32Value(PLAYER_FLAGS) & (PLAYER_FLAGS_HIDE_CLOAK | PLAYER_FLAGS_HIDE_HELM); @@ -16340,25 +16352,25 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GM)) SetUInt32Value(PLAYER_FLAGS, 0 | old_safe_flags); - m_taxi.LoadTaxiMask(result->GetString(17).c_str()); // must be before InitTaxiNodesForLevel + m_taxi.LoadTaxiMask(fields[17].GetCString()); // must be before InitTaxiNodesForLevel - uint32 extraflags = result->GetUInt32(31); + uint32 extraflags = fields[31].GetUInt32(); - m_stableSlots = result->GetUInt8(32); + m_stableSlots = fields[32].GetUInt8(); if (m_stableSlots > MAX_PET_STABLES) { sLog.outError("Player can have not more %u stable slots, but have in DB %u",MAX_PET_STABLES,uint32(m_stableSlots)); m_stableSlots = MAX_PET_STABLES; } - m_atLoginFlags = result->GetUInt32(33); + m_atLoginFlags = fields[33].GetUInt32(); // Honor system // Update Honor kills data m_lastHonorUpdateTime = logoutTime; UpdateHonorFields(); - m_deathExpireTime = (time_t)result->GetUInt64(36); + m_deathExpireTime = (time_t)fields[36].GetUInt64(); if (m_deathExpireTime > now+MAX_DEATH_COUNT*DEATH_EXPIRE_STEP) m_deathExpireTime = now+MAX_DEATH_COUNT*DEATH_EXPIRE_STEP-1; @@ -16394,7 +16406,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) InitRunes(); // rest bonus can only be calculated after InitStatsForLevel() - m_rest_bonus = result->GetFloat(21); + m_rest_bonus = fields[21].GetFloat(); if (time_diff > 0) { @@ -16402,7 +16414,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) float bubble0 = 0.031f; //speed collect rest bonus in offline, in logout, in tavern, city (section/in hour) float bubble1 = 0.125f; - float bubble = result->GetUInt32(23) > 0 + float bubble = fields[23].GetUInt32() > 0 ? bubble1*sWorld.getRate(RATE_REST_OFFLINE_IN_TAVERN_OR_CITY) : bubble0*sWorld.getRate(RATE_REST_OFFLINE_IN_WILDERNESS); @@ -16418,8 +16430,8 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) //mails are loaded only when needed ;-) - when player in game click on mailbox. //_LoadMail(); - m_specsCount = result->GetUInt8(59); - m_activeSpec = result->GetUInt8(60); + m_specsCount = fields[59].GetUInt8(); + m_activeSpec = fields[60].GetUInt8(); // sanity check if (m_specsCount > MAX_TALENT_SPECS || m_activeSpec > MAX_TALENT_SPEC || m_specsCount < MIN_TALENT_SPECS) @@ -16465,7 +16477,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) // check PLAYER_CHOSEN_TITLE compatibility with PLAYER__FIELD_KNOWN_TITLES // note: PLAYER__FIELD_KNOWN_TITLES updated at quest status loaded - uint32 curTitle = result->GetUInt32(46); + uint32 curTitle = fields[46].GetUInt32(); if (curTitle && !HasTitle(curTitle)) curTitle = 0; @@ -16488,11 +16500,11 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) UpdateAllStats(); // restore remembered power/health values (but not more max values) - uint32 savedHealth = result->GetUInt32(50); + uint32 savedHealth = fields[50].GetUInt32(); SetHealth(savedHealth > GetMaxHealth() ? GetMaxHealth() : savedHealth); for (uint8 i = 0; i < MAX_POWERS; ++i) { - uint32 savedPower = result->GetUInt32(51+i); + uint32 savedPower = fields[51+i].GetUInt32(); SetPower(Powers(i),savedPower > GetMaxPower(Powers(i)) ? GetMaxPower(Powers(i)) : savedPower); } @@ -16621,10 +16633,11 @@ void Player::_LoadActions(PreparedQueryResult result) { do { - uint8 button = result->GetUInt8(0); - uint32 action = result->GetUInt32(1); - uint8 type = result->GetUInt8(2); - uint8 spec = result->GetUInt8(3); + Field* fields = result->Fetch(); + uint8 button = fields[0].GetUInt8(); + uint32 action = fields[1].GetUInt32(); + uint8 type = fields[2].GetUInt8(); + uint8 spec = fields[3].GetUInt8(); if (spec >= MAX_TALENT_SPECS) continue; @@ -16638,7 +16651,8 @@ void Player::_LoadActions(PreparedQueryResult result) // Will deleted in DB at next save (it can create data until save but marked as deleted) m_actionButtons[spec][button].uState = ACTIONBUTTON_DELETED; } - } while (result->NextRow()); + } + while (result->NextRow()); } } @@ -16652,22 +16666,23 @@ void Player::_LoadAuras(PreparedQueryResult result, uint32 timediff) { do { + Field* fields = result->Fetch(); int32 damage[3]; int32 baseDamage[3]; - uint64 caster_guid = result->GetUInt64(0); - uint32 spellid = result->GetUInt32(1); - uint8 effmask = result->GetUInt8(2); - uint8 recalculatemask = result->GetUInt8(3); - uint8 stackcount = result->GetUInt8(4); - damage[0] = result->GetInt32(5); - damage[1] = result->GetInt32(6); - damage[2] = result->GetInt32(7); - baseDamage[0] = result->GetInt32(8); - baseDamage[1] = result->GetInt32(9); - baseDamage[2] = result->GetInt32(10); - int32 maxduration = result->GetInt32(11); - int32 remaintime = result->GetInt32(12); - uint8 remaincharges = result->GetUInt8(13); + uint64 caster_guid = fields[0].GetUInt64(); + uint32 spellid = fields[1].GetUInt32(); + uint8 effmask = fields[2].GetUInt8(); + uint8 recalculatemask = fields[3].GetUInt8(); + uint8 stackcount = fields[4].GetUInt8(); + damage[0] = fields[5].GetInt32(); + damage[1] = fields[6].GetInt32(); + damage[2] = fields[7].GetInt32(); + baseDamage[0] = fields[8].GetInt32(); + baseDamage[1] = fields[9].GetInt32(); + baseDamage[2] = fields[10].GetInt32(); + int32 maxduration = fields[11].GetInt32(); + int32 remaintime = fields[12].GetInt32(); + uint8 remaincharges = fields[13].GetUInt8(); SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); if (!spellproto) @@ -16777,10 +16792,12 @@ void Player::_LoadInventory(PreparedQueryResult result, uint32 timediff) m_itemUpdateQueueBlocked = true; do { - uint32 bag_guid = result->GetUInt32(11); - uint8 slot = result->GetUInt8(12); - uint32 item_guid = result->GetUInt32(13); - uint32 item_id = result->GetUInt32(14); + Field* fields = result->Fetch(); + + uint32 bag_guid = fields[11].GetUInt32(); + uint8 slot = fields[12].GetUInt8(); + uint32 item_guid = fields[13].GetUInt32(); + uint32 item_id = fields[14].GetUInt32(); ItemPrototype const * proto = sObjectMgr.GetItemPrototype(item_id); @@ -16852,9 +16869,10 @@ void Player::_LoadInventory(PreparedQueryResult result, uint32 timediff) } else { - item->SetRefundRecipient(result2->GetUInt32(0)); - item->SetPaidMoney(result2->GetUInt32(1)); - item->SetPaidExtendedCost(result2->GetUInt32(2)); + Field* fields2 = result2->Fetch(); + item->SetRefundRecipient(fields2[0].GetUInt32()); + item->SetPaidMoney(fields2[1].GetUInt32()); + item->SetPaidExtendedCost(fields2[2].GetUInt32()); AddRefundReference(item->GetGUIDLow()); } } @@ -16871,7 +16889,8 @@ void Player::_LoadInventory(PreparedQueryResult result, uint32 timediff) } else { - std::string strGUID = result2->GetString(0); + Field* fields2 = result2->Fetch(); + std::string strGUID = fields[2].GetString(); Tokens GUIDlist = StrSplit(strGUID, " "); AllowedLooterSet looters; for (Tokens::iterator itr = GUIDlist.begin(); itr != GUIDlist.end(); ++itr) @@ -16994,8 +17013,10 @@ void Player::_LoadMailedItems(Mail *mail) SQLTransaction trans = CharacterDatabase.BeginTransaction(); do { - uint32 item_guid_low = result->GetUInt32(11); - uint32 item_template = result->GetUInt32(12); + Field* fields = result->Fetch(); + + uint32 item_guid_low = fields[11].GetUInt32(); + uint32 item_template = fields[12].GetUInt32(); mail->AddItem(item_guid_low, item_template); @@ -17013,7 +17034,7 @@ void Player::_LoadMailedItems(Mail *mail) Item *item = NewItemOrBag(proto); - if (!item->LoadFromDB(item_guid_low, MAKE_NEW_GUID(result->GetUInt32(13), 0, HIGHGUID_PLAYER), result, item_template)) + if (!item->LoadFromDB(item_guid_low, MAKE_NEW_GUID(fields[13].GetUInt32(), 0, HIGHGUID_PLAYER), result, item_template)) { sLog.outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, item_guid_low); CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low); @@ -17023,7 +17044,8 @@ void Player::_LoadMailedItems(Mail *mail) } AddMItem(item); - } while (result->NextRow()); + } + while (result->NextRow()); CharacterDatabase.CommitTransaction(trans); } @@ -17033,12 +17055,12 @@ void Player::_LoadMailInit(PreparedQueryResult resultUnread, PreparedQueryResult //set a count of unread mails //QueryResult *resultMails = CharacterDatabase.PQuery("SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(playerGuid),(uint64)cTime); if (resultUnread) - unReadMails = resultUnread->GetUInt8(0); + unReadMails = (*resultUnread)[0].GetUInt8(); // store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called) //resultMails = CharacterDatabase.PQuery("SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(playerGuid)); if (resultDelivery) - m_nextMailDelivereTime = (time_t)resultDelivery->GetUInt64(0); + m_nextMailDelivereTime = (time_t)(*resultDelivery)[0].GetUInt64(); } void Player::_LoadMail() @@ -17056,8 +17078,8 @@ void Player::_LoadMail() m->messageType = fields[1].GetUInt8(); m->sender = fields[2].GetUInt32(); m->receiver = fields[3].GetUInt32(); - m->subject = fields[4].GetCppString(); - m->body = fields[5].GetCppString(); + m->subject = fields[4].GetString(); + m->body = fields[5].GetString(); bool has_items = fields[6].GetBool(); m->expire_time = (time_t)fields[7].GetUInt64(); m->deliver_time = (time_t)fields[8].GetUInt64(); @@ -17109,7 +17131,9 @@ void Player::_LoadQuestStatus(PreparedQueryResult result) { do { - uint32 quest_id = result->GetUInt32(0); + Field* fields = result->Fetch(); + + uint32 quest_id = fields[0].GetUInt32(); // used to be new, no delete? Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id); if (pQuest) @@ -17117,7 +17141,7 @@ void Player::_LoadQuestStatus(PreparedQueryResult result) // find or create QuestStatusData& questStatusData = mQuestStatus[quest_id]; - uint32 qstatus = result->GetUInt32(1); + uint32 qstatus = fields[1].GetUInt32(); if (qstatus < MAX_QUEST_STATUS) questStatusData.m_status = QuestStatus(qstatus); else @@ -17126,10 +17150,10 @@ void Player::_LoadQuestStatus(PreparedQueryResult result) sLog.outError("Player %s have invalid quest %d status (%d), replaced by QUEST_STATUS_NONE(0).",GetName(),quest_id,qstatus); } - questStatusData.m_rewarded = (result->GetUInt8(2) > 0); - questStatusData.m_explored = (result->GetUInt8(3) > 0); + questStatusData.m_rewarded = (fields[2].GetUInt8() > 0); + questStatusData.m_explored = (fields[3].GetUInt8() > 0); - time_t quest_time = time_t(result->GetUInt64(4)); + time_t quest_time = time_t(fields[4].GetUInt64()); if (pQuest->HasFlag(QUEST_TRINITY_FLAGS_TIMED) && !GetQuestRewardStatus(quest_id) && questStatusData.m_status != QUEST_STATUS_NONE) { @@ -17143,14 +17167,14 @@ void Player::_LoadQuestStatus(PreparedQueryResult result) else quest_time = 0; - questStatusData.m_creatureOrGOcount[0] = result->GetUInt32(5); - questStatusData.m_creatureOrGOcount[1] = result->GetUInt32(6); - questStatusData.m_creatureOrGOcount[2] = result->GetUInt32(7); - questStatusData.m_creatureOrGOcount[3] = result->GetUInt32(8); - questStatusData.m_itemcount[0] = result->GetUInt32(9); - questStatusData.m_itemcount[1] = result->GetUInt32(10); - questStatusData.m_itemcount[2] = result->GetUInt32(11); - questStatusData.m_itemcount[3] = result->GetUInt32(12); + questStatusData.m_creatureOrGOcount[0] = fields[5].GetUInt32(); + questStatusData.m_creatureOrGOcount[1] = fields[6].GetUInt32(); + questStatusData.m_creatureOrGOcount[2] = fields[7].GetUInt32(); + questStatusData.m_creatureOrGOcount[3] = fields[8].GetUInt32(); + questStatusData.m_itemcount[0] = fields[9].GetUInt32(); + questStatusData.m_itemcount[1] = fields[10].GetUInt32(); + questStatusData.m_itemcount[2] = fields[11].GetUInt32(); + questStatusData.m_itemcount[3] = fields[12].GetUInt32(); questStatusData.uState = QUEST_UNCHANGED; @@ -17222,10 +17246,12 @@ void Player::_LoadDailyQuestStatus(PreparedQueryResult result) break; } - uint32 quest_id = result->GetUInt32(0); + Field* fields = result->Fetch(); + + uint32 quest_id = fields[0].GetUInt32(); // save _any_ from daily quest times (it must be after last reset anyway) - m_lastDailyQuestTime = (time_t)result->GetUInt64(1); + m_lastDailyQuestTime = (time_t)fields[1].GetUInt64(); Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id); if (!pQuest) @@ -17235,7 +17261,8 @@ void Player::_LoadDailyQuestStatus(PreparedQueryResult result) ++quest_daily_idx; sLog.outDebug("Daily quest (%u) cooldown for player (GUID: %u)", quest_id, GetGUIDLow()); - } while (result->NextRow()); + } + while (result->NextRow()); } m_DailyQuestChanged = false; @@ -17249,14 +17276,15 @@ void Player::_LoadWeeklyQuestStatus(PreparedQueryResult result) { do { - uint32 quest_id = result->GetUInt32(0); + uint32 quest_id = (*result)[0].GetUInt32(); Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id); if (!pQuest) continue; m_weeklyquests.insert(quest_id); sLog.outDebug("Weekly quest {%u} cooldown for player (GUID: %u)", quest_id, GetGUIDLow()); - } while (result->NextRow()); + } + while (result->NextRow()); } m_WeeklyQuestChanged = false; @@ -17269,7 +17297,7 @@ void Player::_LoadSpells(PreparedQueryResult result) if (result) { do - addSpell(result->GetUInt32(0), result->GetBool(1), false, false, result->GetBool(2)); + addSpell((*result)[0].GetUInt32(), (*result)[1].GetBool(), false, false, (*result)[2].GetBool()); while (result->NextRow()); } } @@ -17279,7 +17307,7 @@ void Player::_LoadGroup(PreparedQueryResult result) //QueryResult *result = CharacterDatabase.PQuery("SELECT guid FROM group_member WHERE memberGuid=%u", GetGUIDLow()); if (result) { - if (Group* group = sObjectMgr.GetGroupByGUID(result->GetUInt32(0))) + if (Group* group = sObjectMgr.GetGroupByGUID((*result)[0].GetUInt32())) { uint8 subgroup = group->GetMemberGroup(GetGUID()); SetGroup(group, subgroup); @@ -17305,12 +17333,14 @@ void Player::_LoadBoundInstances(PreparedQueryResult result) { do { - bool perm = result->GetBool(1); - uint32 mapId = result->GetUInt32(2); - uint32 instanceId = result->GetUInt32(0); - uint8 difficulty = result->GetUInt8(3); + Field* fields = result->Fetch(); + + bool perm = fields[1].GetBool(); + uint32 mapId = fields[2].GetUInt32(); + uint32 instanceId = fields[0].GetUInt32(); + uint8 difficulty = fields[3].GetUInt8(); - time_t resetTime = (time_t)result->GetUInt64(4); + time_t resetTime = (time_t)fields[4].GetUInt64(); // the resettime for normal instances is only saved when the InstanceSave is unloaded // so the value read from the DB may be wrong here but only if the InstanceSave is loaded // and in that case it is not used @@ -17338,7 +17368,6 @@ void Player::_LoadBoundInstances(PreparedQueryResult result) continue; } - if (!perm && group) { sLog.outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d,%d,%d", GetName(), GetGUIDLow(), GUID_LOPART(group->GetGUID()), mapId, instanceId, difficulty); @@ -17349,7 +17378,8 @@ void Player::_LoadBoundInstances(PreparedQueryResult result) // since non permanent binds are always solo bind, they can always be reset if (InstanceSave *save = sInstanceSaveMgr.AddInstanceSave(mapId, instanceId, Difficulty(difficulty), resetTime, !perm, true)) BindToInstance(save, perm, true); - } while (result->NextRow()); + } + while (result->NextRow()); } } @@ -17656,11 +17686,13 @@ bool Player::_LoadHomeBind(PreparedQueryResult result) //QueryResult *result = CharacterDatabase.PQuery("SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(playerGuid)); if (result) { - m_homebindMapId = result->GetUInt32(0); - m_homebindAreaId = result->GetUInt16(1); - m_homebindX = result->GetFloat(2); - m_homebindY = result->GetFloat(3); - m_homebindZ = result->GetFloat(4); + Field* fields = result->Fetch(); + + m_homebindMapId = fields[0].GetUInt32(); + m_homebindAreaId = fields[1].GetUInt16(); + m_homebindX = fields[2].GetFloat(); + m_homebindY = fields[3].GetFloat(); + m_homebindZ = fields[4].GetFloat(); MapEntry const* bindMapEntry = sMapStore.LookupEntry(m_homebindMapId); @@ -22927,9 +22959,10 @@ void Player::_LoadSkills(PreparedQueryResult result) { do { - uint16 skill = result->GetUInt16(0); - uint16 value = result->GetUInt16(1); - uint16 max = result->GetUInt16(2); + Field* fields = result->Fetch(); + uint16 skill = fields[0].GetUInt16(); + uint16 value = fields[1].GetUInt16(); + uint16 max = fields[2].GetUInt16(); SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); if (!pSkill) @@ -22977,7 +23010,8 @@ void Player::_LoadSkills(PreparedQueryResult result) sLog.outError("Character %u has more than %u skills.", GetGUIDLow(), PLAYER_MAX_SKILLS); break; } - } while (result->NextRow()); + } + while (result->NextRow()); } for (; count < PLAYER_MAX_SKILLS; ++count) @@ -23061,7 +23095,7 @@ uint8 Player::CanEquipUniqueItem(Item* pItem, uint8 eslot, uint32 limit_count) c uint32 gem_limit_count = !pItem->IsEquipped() && pGem->ItemLimitCategory ? pItem->GetGemCountWithLimitCategory(pGem->ItemLimitCategory) : 1; - if (uint8 res = CanEquipUniqueItem(pGem, eslot,gem_limit_count)) + if (uint8 res = CanEquipUniqueItem(pGem, eslot, gem_limit_count)) return res; } @@ -23074,7 +23108,7 @@ uint8 Player::CanEquipUniqueItem(ItemPrototype const* itemProto, uint8 except_sl if (itemProto->Flags & ITEM_PROTO_FLAG_UNIQUE_EQUIPPED) { // there is an equip limit on this item - if (HasItemOrGemWithIdEquipped(itemProto->ItemId,1,except_slot)) + if (HasItemOrGemWithIdEquipped(itemProto->ItemId, 1, except_slot)) return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE; } @@ -23092,7 +23126,7 @@ uint8 Player::CanEquipUniqueItem(ItemPrototype const* itemProto, uint8 except_sl // there is an equip limit on this item if (HasItemOrGemWithLimitCategoryEquipped(itemProto->ItemLimitCategory, limitEntry->maxCount - limit_count + 1, except_slot)) - return EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_EQUIPPED_EXCEEDED; + return EQUIP_ERR_ITEM_MAX_COUNT_EQUIPPED_SOCKETED; } return EQUIP_ERR_OK; @@ -23833,17 +23867,20 @@ void Player::_LoadGlyphs(PreparedQueryResult result) do { - uint8 spec = result->GetUInt8(0); + Field* fields = result->Fetch(); + + uint8 spec = fields[0].GetUInt8(); if (spec >= m_specsCount) continue; - m_Glyphs[spec][0] = result->GetUInt32(1); - m_Glyphs[spec][1] = result->GetUInt32(2); - m_Glyphs[spec][2] = result->GetUInt32(3); - m_Glyphs[spec][3] = result->GetUInt32(4); - m_Glyphs[spec][4] = result->GetUInt32(5); - m_Glyphs[spec][5] = result->GetUInt32(6); - } while (result->NextRow()); + m_Glyphs[spec][0] = fields[1].GetUInt32(); + m_Glyphs[spec][1] = fields[2].GetUInt32(); + m_Glyphs[spec][2] = fields[3].GetUInt32(); + m_Glyphs[spec][3] = fields[4].GetUInt32(); + m_Glyphs[spec][4] = fields[5].GetUInt32(); + m_Glyphs[spec][5] = fields[6].GetUInt32(); + } + while (result->NextRow()); } void Player::_SaveGlyphs(SQLTransaction& trans) @@ -23862,7 +23899,7 @@ void Player::_LoadTalents(PreparedQueryResult result) if (result) { do - AddTalent(result->GetUInt32(0), result->GetUInt32(1), false); + AddTalent((*result)[0].GetUInt32(), (*result)[1].GetUInt32(), false); while (result->NextRow()); } } diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp index 36c750377c9..e80fa300ca5 100644 --- a/src/server/game/Entities/Player/SocialMgr.cpp +++ b/src/server/game/Entities/Player/SocialMgr.cpp @@ -303,16 +303,19 @@ PlayerSocial *SocialMgr::LoadFromDB(PreparedQueryResult result, uint32 guid) do { - friend_guid = result->GetUInt32(0); - flags = result->GetUInt32(1); - note = result->GetString(2); + Field* fields = result->Fetch(); + + friend_guid = fields[0].GetUInt32(); + flags = fields[1].GetUInt32(); + note = fields[2].GetString(); social->m_playerSocialMap[friend_guid] = FriendInfo(flags, note); // client's friends list and ignore list limit if (social->m_playerSocialMap.size() >= (SOCIALMGR_FRIEND_LIMIT + SOCIALMGR_IGNORE_LIMIT)) break; - } while (result->NextRow()); + } + while (result->NextRow()); return social; } diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 595ee8dea8e..af5ff1bf3e2 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -54,9 +54,9 @@ void MapManager::LoadTransports() Field *fields = result->Fetch(); uint32 lowguid = fields[0].GetUInt32(); uint32 entry = fields[1].GetUInt32(); - std::string name = fields[2].GetCppString(); + std::string name = fields[2].GetString(); uint32 period = fields[3].GetUInt32(); - uint32 scriptId = sObjectMgr.GetScriptId(fields[4].GetString()); + uint32 scriptId = sObjectMgr.GetScriptId(fields[4].GetCString()); Transport *t = new Transport(period, scriptId); @@ -133,7 +133,7 @@ void MapManager::LoadTransports() uint32 guid = fields[0].GetUInt32(); uint32 entry = fields[1].GetUInt32(); - std::string name = fields[2].GetCppString(); + std::string name = fields[2].GetString(); sLog.outErrorDb("Transport %u '%s' have record (GUID: %u) in `gameobject`. Transports DON'T must have any records in `gameobject` or its behavior will be unpredictable/bugged.",entry,name.c_str(),guid); } while (result->NextRow()); diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index ae71dce5ee0..0f6e88e8f47 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -266,7 +266,7 @@ void GameEventMgr::LoadFromDB() } } - pGameEvent.description = fields[6].GetCppString(); + pGameEvent.description = fields[6].GetString(); } while (result->NextRow()); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 4d2eac5b898..a015b05360b 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -445,10 +445,10 @@ void ObjectMgr::LoadCreatureLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { LocaleConstant locale = (LocaleConstant) i; - std::string str = fields[1 + 2 * (i - 1)].GetCppString(); + std::string str = fields[1 + 2 * (i - 1)].GetString(); AddLocaleString(str, locale, data.Name); - str = fields[1 + 2 * (i - 1) + 1].GetCppString(); + str = fields[1 + 2 * (i - 1) + 1].GetString(); AddLocaleString(str, locale, data.SubName); } } while (result->NextRow()); @@ -486,10 +486,10 @@ void ObjectMgr::LoadGossipMenuItemsLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { LocaleConstant locale = (LocaleConstant) i; - std::string str = fields[2 + 2 * (i - 1)].GetCppString(); + std::string str = fields[2 + 2 * (i - 1)].GetString(); AddLocaleString(str, locale, data.OptionText); - str = fields[2 + 2 * (i - 1) + 1].GetCppString(); + str = fields[2 + 2 * (i - 1) + 1].GetString(); AddLocaleString(str, locale, data.BoxText); } } while (result->NextRow()); @@ -520,7 +520,7 @@ void ObjectMgr::LoadPointOfInterestLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { - std::string str = fields[i].GetCppString(); + std::string str = fields[i].GetString(); AddLocaleString(str, LocaleConstant(i), data.IconName); } } while (result->NextRow()); @@ -1878,7 +1878,7 @@ bool ObjectMgr::GetPlayerNameByGUID(const uint64 &guid, std::string &name) const if (result) { - name = (*result)[0].GetCppString(); + name = (*result)[0].GetString(); return true; } @@ -1957,10 +1957,10 @@ void ObjectMgr::LoadItemLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { LocaleConstant locale = (LocaleConstant) i; - std::string str = fields[1 + 2 * (i - 1)].GetCppString(); + std::string str = fields[1 + 2 * (i - 1)].GetString(); AddLocaleString(str, locale, data.Name); - str = fields[1 + 2 * (i - 1) + 1].GetCppString(); + str = fields[1 + 2 * (i - 1) + 1].GetString(); AddLocaleString(str, locale, data.Description); } } while (result->NextRow()); @@ -2452,7 +2452,7 @@ void ObjectMgr::LoadItemSetNameLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { - std::string str = fields[i].GetCppString(); + std::string str = fields[i].GetString(); AddLocaleString(str, LocaleConstant(i), data.Name); } } while (result->NextRow()); @@ -2498,7 +2498,7 @@ void ObjectMgr::LoadItemSetNames() } ItemSetNameEntry &data = mItemSetNameMap[entry]; - data.name = fields[1].GetCppString(); + data.name = fields[1].GetString(); uint32 invType = fields[2].GetUInt32(); if (invType >= MAX_INVTYPE) @@ -3677,9 +3677,9 @@ void ObjectMgr::LoadGuildBanks(std::vector<Guild*>& GuildVector, QueryResult& re { GuildBankTab *NewTab = new GuildBankTab; - NewTab->Name = fields[1].GetCppString(); - NewTab->Icon = fields[2].GetCppString(); - NewTab->Text = fields[3].GetCppString(); + NewTab->Name = fields[1].GetString(); + NewTab->Icon = fields[2].GetString(); + NewTab->Text = fields[3].GetString(); GuildVector[guildid]->m_TabListMap[TabId] = NewTab; } @@ -3691,11 +3691,12 @@ void ObjectMgr::LoadGuildBanks(std::vector<Guild*>& GuildVector, QueryResult& re { do { - uint8 TabId = itemResult->GetUInt8(11); - uint8 SlotId = itemResult->GetUInt8(12); - uint32 ItemGuid = itemResult->GetUInt32(13); - uint32 ItemId = itemResult->GetUInt32(14); - uint32 guildid = itemResult->GetUInt32(15); + Field *fields = itemResult->Fetch(); + uint8 TabId = fields[11].GetUInt8(); + uint8 SlotId = fields[12].GetUInt8(); + uint32 ItemGuid = fields[13].GetUInt32(); + uint32 ItemId = fields[14].GetUInt32(); + uint32 guildid = fields[15].GetUInt32(); if (guildid >= GuildVector.size() || GuildVector[guildid] == NULL) return; @@ -4651,30 +4652,30 @@ void ObjectMgr::LoadQuestLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { LocaleConstant locale = (LocaleConstant) i; - std::string str = fields[1 + 11 * (i - 1)].GetCppString(); + std::string str = fields[1 + 11 * (i - 1)].GetString(); AddLocaleString(str, locale, data.Title); - str = fields[1 + 11 * (i - 1) + 1].GetCppString(); + str = fields[1 + 11 * (i - 1) + 1].GetString(); AddLocaleString(str, locale, data.Details); - str = fields[1 + 11 * (i - 1) + 2].GetCppString(); + str = fields[1 + 11 * (i - 1) + 2].GetString(); AddLocaleString(str, locale, data.Objectives); - str = fields[1 + 11 * (i - 1) + 3].GetCppString(); + str = fields[1 + 11 * (i - 1) + 3].GetString(); AddLocaleString(str, locale, data.OfferRewardText); - str = fields[1 + 11 * (i - 1) + 4].GetCppString(); + str = fields[1 + 11 * (i - 1) + 4].GetString(); AddLocaleString(str, locale, data.RequestItemsText); - str = fields[1 + 11 * (i - 1) + 5].GetCppString(); + str = fields[1 + 11 * (i - 1) + 5].GetString(); AddLocaleString(str, locale, data.EndText); - str = fields[1 + 11 * (i - 1) + 6].GetCppString(); + str = fields[1 + 11 * (i - 1) + 6].GetString(); AddLocaleString(str, locale, data.CompletedText); for (uint8 k = 0; k < 4; ++k) { - str = fields[1 + 11 * (i - 1) + 7 + k].GetCppString(); + str = fields[1 + 11 * (i - 1) + 7 + k].GetString(); AddLocaleString(str, locale, data.ObjectiveText[k]); } } @@ -5162,7 +5163,7 @@ void ObjectMgr::LoadSpellScriptNames() Field *fields = result->Fetch(); int32 spellId = fields[0].GetInt32(); - const char *scriptName = fields[1].GetString(); + const char *scriptName = fields[1].GetCString(); bool allRanks = false; if (spellId <=0) @@ -5328,7 +5329,7 @@ void ObjectMgr::LoadPageTextLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { - std::string str = fields[i].GetCppString(); + std::string str = fields[i].GetString(); AddLocaleString(str, LocaleConstant(i), data.Text); } @@ -5419,8 +5420,8 @@ void ObjectMgr::LoadGossipText() for (int i=0; i< 8; i++) { - gText.Options[i].Text_0 = fields[cic++].GetCppString(); - gText.Options[i].Text_1 = fields[cic++].GetCppString(); + gText.Options[i].Text_0 = fields[cic++].GetString(); + gText.Options[i].Text_1 = fields[cic++].GetString(); gText.Options[i].Language = fields[cic++].GetUInt32(); gText.Options[i].Probability = fields[cic++].GetFloat(); @@ -5471,10 +5472,10 @@ void ObjectMgr::LoadNpcTextLocales() LocaleConstant locale = (LocaleConstant) i; for (uint8 j = 0; j < 8; ++j) { - std::string str0 = fields[1 + 8 * 2 * (i - 1) + 2 * j].GetCppString(); + std::string str0 = fields[1 + 8 * 2 * (i - 1) + 2 * j].GetString(); AddLocaleString(str0, locale, data.Text_0[j]); - std::string str1 = fields[1 + 8 * 2 * (i - 1) + 2 * j + 1].GetCppString(); + std::string str1 = fields[1 + 8 * 2 * (i - 1) + 2 * j + 1].GetString(); AddLocaleString(str1, locale, data.Text_1[j]); } } @@ -5714,7 +5715,7 @@ void ObjectMgr::LoadAreaTriggerScripts() Field *fields = result->Fetch(); uint32 Trigger_ID = fields[0].GetUInt32(); - const char *scriptName = fields[1].GetString(); + const char *scriptName = fields[1].GetCString(); AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); if (!atEntry) @@ -6209,7 +6210,7 @@ void ObjectMgr::LoadAccessRequirements() ar.quest_A = fields[6].GetUInt32(); ar.quest_H = fields[7].GetUInt32(); ar.achievement = fields[8].GetUInt32(); - ar.questFailedText = fields[9].GetCppString(); + ar.questFailedText = fields[9].GetString(); if (ar.item) { @@ -6529,13 +6530,13 @@ void ObjectMgr::LoadGameObjectLocales() for (uint8 i = 1; i < MAX_LOCALE; ++i) { - std::string str = fields[i].GetCppString(); + std::string str = fields[i].GetString(); AddLocaleString(str, LocaleConstant(i), data.Name); } for (uint8 i = 1; i < MAX_LOCALE; ++i) { - std::string str = fields[i + (MAX_LOCALE - 1)].GetCppString(); + std::string str = fields[i + (MAX_LOCALE - 1)].GetString(); AddLocaleString(str, LocaleConstant(i), data.CastBarCaption); } @@ -7229,7 +7230,7 @@ void ObjectMgr::LoadPointsOfInterest() POI.icon = fields[3].GetUInt32(); POI.flags = fields[4].GetUInt32(); POI.data = fields[5].GetUInt32(); - POI.icon_name = fields[6].GetCppString(); + POI.icon_name = fields[6].GetString(); if (!Trinity::IsValidMapCoord(POI.x,POI.y)) { @@ -7676,7 +7677,7 @@ void ObjectMgr::LoadReservedPlayersNames() { bar.step(); fields = result->Fetch(); - std::string name= fields[0].GetCppString(); + std::string name= fields[0].GetString(); std::wstring wstr; if (!Utf8toWStr (name,wstr)) @@ -7981,7 +7982,7 @@ bool ObjectMgr::LoadTrinityStrings(char const* table, int32 min_value, int32 max for (uint8 i = 0; i < MAX_LOCALE; ++i) { - std::string str = fields[i + 1].GetCppString(); + std::string str = fields[i + 1].GetString(); AddLocaleString(str, LocaleConstant(i), data.Content); } } while (result->NextRow()); @@ -8150,7 +8151,7 @@ void ObjectMgr::LoadGameTele() gt.position_z = fields[3].GetFloat(); gt.orientation = fields[4].GetFloat(); gt.mapId = fields[5].GetUInt32(); - gt.name = fields[6].GetCppString(); + gt.name = fields[6].GetString(); if (!MapManager::IsValidMapCoord(gt.mapId,gt.position_x,gt.position_y,gt.position_z,gt.orientation)) { @@ -8697,7 +8698,7 @@ void ObjectMgr::LoadGossipMenuItems() gMenuItem.menu_id = fields[0].GetUInt32(); gMenuItem.id = fields[1].GetUInt32(); gMenuItem.option_icon = fields[2].GetUInt8(); - gMenuItem.option_text = fields[3].GetCppString(); + gMenuItem.option_text = fields[3].GetString(); gMenuItem.option_id = fields[4].GetUInt32(); gMenuItem.npc_option_npcflag = fields[5].GetUInt32(); gMenuItem.action_menu_id = fields[6].GetUInt32(); @@ -8705,7 +8706,7 @@ void ObjectMgr::LoadGossipMenuItems() gMenuItem.action_script_id = fields[8].GetUInt32(); gMenuItem.box_coded = fields[9].GetUInt8() != 0; gMenuItem.box_money = fields[10].GetUInt32(); - gMenuItem.box_text = fields[11].GetCppString(); + gMenuItem.box_text = fields[11].GetString(); if (gMenuItem.option_icon >= GOSSIP_ICON_MAX) { diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index 127f3cd604b..9ee04a53483 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -152,7 +152,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank) return false; // player doesn't exist Field *fields = result->Fetch(); - newmember.Name = fields[0].GetCppString(); + newmember.Name = fields[0].GetString(); newmember.ZoneId = fields[1].GetUInt32(); newmember.Level = fields[2].GetUInt8(); newmember.Class = fields[3].GetUInt8(); @@ -226,15 +226,15 @@ bool Guild::LoadGuildFromDB(QueryResult guildDataResult) Field *fields = guildDataResult->Fetch(); m_Id = fields[0].GetUInt32(); - m_Name = fields[1].GetCppString(); + m_Name = fields[1].GetString(); m_LeaderGuid = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER); m_EmblemStyle = fields[3].GetUInt32(); m_EmblemColor = fields[4].GetUInt32(); m_BorderStyle = fields[5].GetUInt32(); m_BorderColor = fields[6].GetUInt32(); m_BackgroundColor = fields[7].GetUInt32(); - GINFO = fields[8].GetCppString(); - MOTD = fields[9].GetCppString(); + GINFO = fields[8].GetString(); + MOTD = fields[9].GetString(); m_CreatedDate = fields[10].GetUInt64(); m_GuildBankMoney = fields[11].GetUInt64(); @@ -311,7 +311,7 @@ bool Guild::LoadRanksFromDB(QueryResult guildRanksResult) //we loaded all ranks for this guild already, break cycle break; uint32 rankID = fields[1].GetUInt32(); - std::string rankName = fields[2].GetCppString(); + std::string rankName = fields[2].GetString(); uint32 rankRights = fields[3].GetUInt32(); uint32 rankMoney = fields[4].GetUInt32(); @@ -385,8 +385,8 @@ bool Guild::LoadMembersFromDB(QueryResult guildMembersResult) if (newmember.RankId >= m_Ranks.size()) newmember.RankId = GetLowestRank(); - newmember.Pnote = fields[3].GetCppString(); - newmember.OFFnote = fields[4].GetCppString(); + newmember.Pnote = fields[3].GetString(); + newmember.OFFnote = fields[4].GetString(); newmember.BankResetTimeMoney = fields[5].GetUInt32(); newmember.BankRemMoney = fields[6].GetUInt32(); for (uint8 i = 0; i < GUILD_BANK_MAX_TABS; ++i) @@ -395,7 +395,7 @@ bool Guild::LoadMembersFromDB(QueryResult guildMembersResult) newmember.BankRemSlotsTab[i] = fields[8+(2*i)].GetUInt32(); } - newmember.Name = fields[19].GetCppString(); + newmember.Name = fields[19].GetString(); newmember.Level = fields[20].GetUInt8(); newmember.Class = fields[21].GetUInt8(); newmember.ZoneId = fields[22].GetUInt32(); diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index de1c301423d..b9b988f7a3d 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -239,7 +239,7 @@ void InstanceSaveManager::_DelHelper(const char *fields, const char *table, cons std::ostringstream ss; for (size_t i = 0; i < fieldTokens.size(); i++) { - std::string fieldValue = fields[i].GetCppString(); + std::string fieldValue = fields[i].GetString(); CharacterDatabase.escape_string(fieldValue); ss << (i != 0 ? " AND " : "") << fieldTokens[i] << " = '" << fieldValue << "'"; } diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp index fe33622b9d2..66217bbfb53 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp @@ -111,7 +111,7 @@ void OutdoorPvPMgr::LoadTemplates() OutdoorPvPData* data = new OutdoorPvPData(); OutdoorPvPTypes realTypeId = OutdoorPvPTypes(typeId); data->TypeId = realTypeId; - data->ScriptId = sObjectMgr.GetScriptId(fields[1].GetString()); + data->ScriptId = sObjectMgr.GetScriptId(fields[1].GetCString()); m_OutdoorPvPDatas[realTypeId] = data; ++count; diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index 9eb21c63e56..9944c360bc4 100644 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -852,8 +852,10 @@ void PoolMgr::LoadQuestPools() { bar.step(); - uint32 entry = result->GetUInt32(0); - uint32 pool_id = result->GetUInt32(1); + Field* fields = result->Fetch(); + + uint32 entry = fields[0].GetUInt32(); + uint32 pool_id = fields[1].GetUInt32(); Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry); if (!pQuest) @@ -905,7 +907,9 @@ void PoolMgr::LoadQuestPools() SearchPair p(entry, pool_id); mQuestSearchMap.insert(p); - } while (result->NextRow()); + } + while (result->NextRow()); + sLog.outString(); sLog.outString(">> Loaded %u quests in pools", count); } diff --git a/src/server/game/Quests/QuestDef.cpp b/src/server/game/Quests/QuestDef.cpp index 54ed32e4d58..0b88a0ebdaa 100644 --- a/src/server/game/Quests/QuestDef.cpp +++ b/src/server/game/Quests/QuestDef.cpp @@ -58,16 +58,16 @@ Quest::Quest(Field * questRecord) SrcItemId = questRecord[31].GetUInt32(); SrcItemCount = questRecord[32].GetUInt32(); SrcSpell = questRecord[33].GetUInt32(); - Title = questRecord[34].GetCppString(); - Details = questRecord[35].GetCppString(); - Objectives = questRecord[36].GetCppString(); - OfferRewardText = questRecord[37].GetCppString(); - RequestItemsText = questRecord[38].GetCppString(); - EndText = questRecord[39].GetCppString(); - CompletedText = questRecord[40].GetCppString(); + Title = questRecord[34].GetString(); + Details = questRecord[35].GetString(); + Objectives = questRecord[36].GetString(); + OfferRewardText = questRecord[37].GetString(); + RequestItemsText = questRecord[38].GetString(); + EndText = questRecord[39].GetString(); + CompletedText = questRecord[40].GetString(); for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i) - ObjectiveText[i] = questRecord[41+i].GetCppString(); + ObjectiveText[i] = questRecord[41+i].GetString(); for (int i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; ++i) ReqItemId[i] = questRecord[45+i].GetUInt32(); diff --git a/src/server/game/Reputation/ReputationMgr.cpp b/src/server/game/Reputation/ReputationMgr.cpp index 7e91191f413..1e2d167f103 100644 --- a/src/server/game/Reputation/ReputationMgr.cpp +++ b/src/server/game/Reputation/ReputationMgr.cpp @@ -463,13 +463,15 @@ void ReputationMgr::LoadFromDB(PreparedQueryResult result) { do { - FactionEntry const *factionEntry = sFactionStore.LookupEntry(result->GetUInt32(0)); + Field* fields = result->Fetch(); + + FactionEntry const *factionEntry = sFactionStore.LookupEntry(fields[0].GetUInt32()); if (factionEntry && (factionEntry->reputationListID >= 0)) { FactionState* faction = &m_factions[factionEntry->reputationListID]; // update standing to current - faction->Standing = int32(result->GetUInt32(1)); + faction->Standing = int32(fields[1].GetUInt32()); // update counters int32 BaseRep = GetBaseReputation(factionEntry); @@ -477,7 +479,7 @@ void ReputationMgr::LoadFromDB(PreparedQueryResult result) ReputationRank new_rank = ReputationToRank(BaseRep + faction->Standing); UpdateRankCounters(old_rank, new_rank); - uint32 dbFactionFlags = result->GetUInt32(2); + uint32 dbFactionFlags = fields[2].GetUInt32(); if (dbFactionFlags & FACTION_FLAG_VISIBLE) SetVisible(faction); // have internal checks for forced invisibility diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index c62e8d6a833..c9831f926d9 100644 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -607,7 +607,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket & recv_data) { Field *fields = result->Fetch(); accountId = fields[0].GetUInt32(); - name = fields[1].GetCppString(); + name = fields[1].GetString(); } // prevent deleting other players' characters using cheating tools @@ -741,8 +741,9 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow()); if (PreparedQueryResult resultGuild = holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADGUILD)) { - pCurrChar->SetInGuild(resultGuild->GetUInt32(0)); - pCurrChar->SetRank(resultGuild->GetUInt8(1)); + Field* fields = resultGuild->Fetch(); + pCurrChar->SetInGuild(fields[0].GetUInt32()); + pCurrChar->SetRank(fields[1].GetUInt8()); } else if (pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership { @@ -1067,7 +1068,7 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult result, std: uint32 guidLow = result->Fetch()[0].GetUInt32(); uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER); - std::string oldname = result->Fetch()[1].GetCppString(); + std::string oldname = result->Fetch()[1].GetString(); CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME), guidLow); CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow); @@ -1318,7 +1319,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) CharacterDatabase.escape_string(newname); if (QueryResult result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid))) { - std::string oldname = result->Fetch()[0].GetCppString(); + std::string oldname = result->Fetch()[0].GetString(); std::string IP_str = GetRemoteAddress(); sLog.outChar("Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), IP_str.c_str(), oldname.c_str(), GUID_LOPART(guid), newname.c_str()); } diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index 0ed2a90b25c..935fe523621 100644 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -1331,13 +1331,13 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) } Field *fields = result->Fetch(); - std::string acc = fields[0].GetCppString(); + std::string acc = fields[0].GetString(); if (acc.empty()) acc = "Unknown"; - std::string email = fields[1].GetCppString(); + std::string email = fields[1].GetString(); if (email.empty()) email = "Unknown"; - std::string lastip = fields[2].GetCppString(); + std::string lastip = fields[2].GetString(); if (lastip.empty()) lastip = "Unknown"; diff --git a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp index 482ea587d8d..4b57d6d2292 100644 --- a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp @@ -334,7 +334,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid) { Field* fields = result->Fetch(); ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); - name = fields[1].GetCppString(); + name = fields[1].GetString(); signs = fields[2].GetUInt8(); type = fields[3].GetUInt32(); } @@ -725,7 +725,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) { Field *fields = result->Fetch(); ownerguidlo = fields[0].GetUInt32(); - name = fields[1].GetCppString(); + name = fields[1].GetString(); type = fields[2].GetUInt32(); } else diff --git a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp index f8e9342b49d..85aa0e55e64 100644 --- a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp @@ -89,7 +89,7 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult result) Field *fields = result->Fetch(); uint32 guid = fields[0].GetUInt32(); - std::string name = fields[1].GetCppString(); + std::string name = fields[1].GetString(); uint8 pRace = 0, pGender = 0, pClass = 0; if (name == "") name = GetTrinityString(LANG_NON_EXIST_CHARACTER); @@ -110,11 +110,11 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult result) data << uint8(pClass); // class // if the first declined name field (5) is empty, the rest must be too - if (sWorld.getBoolConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetCppString() != "") + if (sWorld.getBoolConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetString() != "") { data << uint8(1); // is declined for (int i = 5; i < MAX_DECLINED_NAME_CASES+5; ++i) - data << fields[i].GetCppString(); + data << fields[i].GetString(); } else data << uint8(0); // is not declined diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 1f278fd63fd..cdd8470854d 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -600,7 +600,8 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask) do { - uint32 type = result->GetUInt32(0); + Field* fields = result->Fetch(); + uint32 type = fields[0].GetUInt32(); if (type >= NUM_ACCOUNT_DATA_TYPES) { sLog.outError("Table `%s` have invalid account data type (%u), ignore.", @@ -615,10 +616,11 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask) continue; } - m_accountData[type].Time = result->GetUInt32(1); - m_accountData[type].Data = result->GetString(2); + m_accountData[type].Time = fields[1].GetUInt32(); + m_accountData[type].Data = fields[2].GetString(); - } while (result->NextRow()); + } + while (result->NextRow()); } void WorldSession::SetAccountData(AccountDataType type, time_t time_, std::string data) diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 90a969bc99d..e43ab13d2c0 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -851,8 +851,8 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) N.SetHexStr ("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7"); g.SetDword (7); - v.SetHexStr(fields[4].GetString()); - s.SetHexStr (fields[5].GetString()); + v.SetHexStr(fields[4].GetCString()); + s.SetHexStr (fields[5].GetCString()); const char* sStr = s.AsHexStr(); //Must be freed by OPENSSL_free() const char* vStr = v.AsHexStr(); //Must be freed by OPENSSL_free() @@ -867,7 +867,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) ///- Re-check ip locking (same check as in realmd). if (fields[3].GetUInt8() == 1) // if ip is locked { - if (strcmp (fields[2].GetString(), GetRemoteAddress().c_str())) + if (strcmp (fields[2].GetCString(), GetRemoteAddress().c_str())) { packet.Initialize (SMSG_AUTH_RESPONSE, 1); packet << uint8 (AUTH_FAILED); @@ -884,7 +884,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) security = SEC_ADMINISTRATOR; */ - K.SetHexStr (fields[1].GetString()); + K.SetHexStr (fields[1].GetCString()); time_t mutetime = time_t (fields[7].GetUInt64()); diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index 63023bb7cfe..9be0e2425e5 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -72,8 +72,8 @@ void TicketMgr::LoadGMTickets() ticket = new GM_Ticket; ticket->guid = fields[0].GetUInt64(); ticket->playerGuid = fields[1].GetUInt64(); - ticket->name = fields[2].GetCppString(); - ticket->message = fields[3].GetCppString(); + ticket->name = fields[2].GetString(); + ticket->message = fields[3].GetString(); ticket->createtime = fields[4].GetUInt64(); ticket->map = fields[5].GetUInt32(); ticket->pos_x = fields[6].GetFloat(); @@ -85,7 +85,7 @@ void TicketMgr::LoadGMTickets() m_openTickets++; ticket->assignedToGM = fields[11].GetUInt64(); - ticket->comment = fields[12].GetCppString(); + ticket->comment = fields[12].GetString(); ticket->completed = fields[13].GetBool(); ticket->escalated = fields[14].GetUInt8(); ticket->viewed = fields[15].GetBool(); diff --git a/src/server/game/Tools/PlayerDump.cpp b/src/server/game/Tools/PlayerDump.cpp index e49cb2e9fe5..96c6cd87338 100644 --- a/src/server/game/Tools/PlayerDump.cpp +++ b/src/server/game/Tools/PlayerDump.cpp @@ -207,7 +207,7 @@ std::string CreateDumpString(char const* tableName, QueryResult result) if (i == 0) ss << "'"; else ss << ", '"; - std::string s = fields[i].GetCppString(); + std::string s = fields[i].GetString(); CharacterDatabase.escape_string(s); ss << s; @@ -257,7 +257,7 @@ void StoreGUID(QueryResult result,uint32 field,std::set<uint32>& guids) void StoreGUID(QueryResult result,uint32 data,uint32 field, std::set<uint32>& guids) { Field* fields = result->Fetch(); - std::string dataStr = fields[data].GetCppString(); + std::string dataStr = fields[data].GetString(); uint32 guid = atoi(gettoknth(dataStr, field).c_str()); if (guid) guids.insert(guid); diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index 9e462b8a544..ff961153038 100644 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -130,7 +130,7 @@ void WeatherMgr::LoadWeatherData() } } - wzc.ScriptId = sObjectMgr.GetScriptId(fields[13].GetString()); + wzc.ScriptId = sObjectMgr.GetScriptId(fields[13].GetCString()); ++count; } diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 4a31abf94dc..dc8797b717c 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1845,7 +1845,7 @@ void World::LoadAutobroadcasts() Field *fields = result->Fetch(); - std::string message = fields[0].GetCppString(); + std::string message = fields[0].GetString(); m_Autobroadcasts.push_back(message); @@ -2319,7 +2319,7 @@ BanReturn World::BanCharacter(std::string name, std::string duration, std::strin if (!resultCharacter) return BAN_NOTFOUND; // Nobody to ban - guid = resultCharacter->GetUInt32(0); + guid = (*resultCharacter)[0].GetUInt32(); } else guid = pBanned->GetGUIDLow(); @@ -2353,7 +2353,7 @@ bool World::RemoveBanCharacter(std::string name) if (!resultCharacter) return false; - guid = resultCharacter->GetUInt32(0); + guid = (*resultCharacter)[0].GetUInt32(); } else guid = pBanned->GetGUIDLow(); @@ -2728,8 +2728,8 @@ void World::LoadDBVersion() { Field* fields = result->Fetch(); - m_DBVersion = fields[0].GetCppString(); - m_CreatureEventAIVersion = fields[1].GetCppString(); + m_DBVersion = fields[0].GetString(); + m_CreatureEventAIVersion = fields[1].GetString(); // will be overwrite by config values if different and non-0 m_int_configs[CONFIG_CLIENTCACHE_VERSION] = fields[2].GetUInt32(); diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index 2d55a6f1b6b..b2afdbd3bad 100644 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -301,7 +301,6 @@ class DatabaseWorkerPool if (!ret || !ret->GetRowCount()) return PreparedQueryResult(NULL); - ret->NextRow(); return PreparedQueryResult(ret); } diff --git a/src/server/shared/Database/Field.cpp b/src/server/shared/Database/Field.cpp index ac83bf055fb..9ef23f3ad17 100644 --- a/src/server/shared/Database/Field.cpp +++ b/src/server/shared/Database/Field.cpp @@ -1,6 +1,4 @@ /* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify @@ -20,58 +18,42 @@ #include "Field.h" -Field::Field() : -mValue(NULL), mType(DB_TYPE_UNKNOWN) +Field::Field() { + data.value = NULL; + data.type = MYSQL_TYPE_NULL; + data.length = 0; } -Field::Field(Field &f) +Field::~Field() { - const char *value; - - value = f.GetString(); - - if (value) - { - mValue = new char[strlen(value) + 1]; - if (mValue) - strcpy(mValue, value); - } - else - mValue = NULL; - - mType = f.GetType(); + CleanUp(); } -Field::Field(const char *value, enum Field::DataTypes type) : -mType(type) +void Field::SetByteValue(void* newValue, const size_t newSize, enum_field_types newType, uint32 length) { - if (value) + // This value stores raw bytes that have to be explicitly casted later + if (newValue) { - mValue = new char[strlen(value) + 1]; - if (mValue) - strcpy(mValue, value); + data.value = new char [newSize]; + memcpy(data.value, newValue, newSize); + data.length = length; } - else - mValue = NULL; + data.type = newType; + data.raw = true; } -Field::~Field() -{ - if (mValue) - delete [] mValue; -} - -void Field::SetValue(const char *value) +void Field::SetStructuredValue(char* newValue, enum_field_types newType, const size_t newSize) { - if (mValue) - delete [] mValue; - - if (value) + // This value stores somewhat structured data that needs function style casting + if (newValue) { - mValue = new char[strlen(value) + 1]; - strcpy(mValue, value); + size_t size = strlen(newValue); + data.value = new char [size+1]; + strcpy(data.value, newValue); + data.length = size; } - else - mValue = NULL; + + data.type = newType; + data.raw = false; } diff --git a/src/server/shared/Database/Field.h b/src/server/shared/Database/Field.h index 2885d9eff8b..0870f1c8562 100644 --- a/src/server/shared/Database/Field.h +++ b/src/server/shared/Database/Field.h @@ -1,6 +1,4 @@ /* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify @@ -18,74 +16,308 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#if !defined(FIELD_H) -#define FIELD_H -#include <iostream> +#ifndef _FIELD_H +#define _FIELD_H + #include "Common.h" +#include "Log.h" + +#include <mysql.h> class Field { + friend class ResultSet; + friend class PreparedResultSet; + public: + + bool GetBool() const // Wrapper, actually gets integer + { + return GetUInt8() == 1 ? true : false; + } - enum DataTypes + uint8 GetUInt8() const { - DB_TYPE_UNKNOWN = 0x00, - DB_TYPE_STRING = 0x01, - DB_TYPE_INTEGER = 0x02, - DB_TYPE_FLOAT = 0x03, - DB_TYPE_BOOL = 0x04 - }; + if (!data.value) + return 0; - Field(); - Field(Field &f); - Field(const char *value, enum DataTypes type); + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetUInt8() on non-numeric field."); + return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<uint8*>(data.value); + return static_cast<uint8>(atol((char*)data.value)); + } - ~Field(); + int8 GetInt8() const + { + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GeInt8() on non-numeric field."); + return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<int8*>(data.value); + return static_cast<int8>(atol((char*)data.value)); + } + + uint16 GetUInt16() const + { + if (!data.value) + return 0; - enum DataTypes GetType() const { return mType; } + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetUInt16() on non-numeric field."); + return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<uint16*>(data.value); + return static_cast<uint16>(atol((char*)data.value)); + } - const char *GetString() const { return mValue; } - std::string GetCppString() const + int16 GetInt16() const { - return mValue ? mValue : ""; // std::string s = 0 have undefine result in C++ + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetInt16() on non-numeric field."); + return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<int16*>(data.value); + return static_cast<int16>(atol((char*)data.value)); } - float GetFloat() const { return mValue ? static_cast<float>(atof(mValue)) : 0.0f; } - bool GetBool() const { return mValue ? atoi(mValue) > 0 : false; } - int32 GetInt32() const { return mValue ? static_cast<int32>(atol(mValue)) : int32(0); } - uint8 GetUInt8() const { return mValue ? static_cast<uint8>(atol(mValue)) : uint8(0); } - uint16 GetUInt16() const { return mValue ? static_cast<uint16>(atol(mValue)) : uint16(0); } - int16 GetInt16() const { return mValue ? static_cast<int16>(atol(mValue)) : int16(0); } - uint32 GetUInt32() const { return mValue ? static_cast<uint32>(atol(mValue)) : uint32(0); } - uint64 GetUInt64() const + + uint32 GetUInt32() const { - if(mValue) + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) { - uint64 value; - sscanf(mValue,UI64FMTD,&value); - return value; + sLog.outSQLDriver("Error: GetUInt32() on non-numeric field."); + return 0; } - else + #endif + if (data.raw) + return *reinterpret_cast<uint32*>(data.value); + return static_cast<uint32>(atol((char*)data.value)); + } + + int32 GetInt32() const + { + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetInt32() on non-numeric field."); return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<int32*>(data.value); + return static_cast<int32>(atol((char*)data.value)); } - uint64 GetInt64() const + + uint64 GetUInt64() const { - if(mValue) + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) { - int64 value; - sscanf(mValue,SI64FMTD,&value); - return value; + sLog.outSQLDriver("Error: GetUInt64() on non-numeric field."); + return 0; } - else + #endif + if (data.raw) + return *reinterpret_cast<uint64*>(data.value); + return static_cast<uint64>(atol((char*)data.value)); + } + + int64 GetInt64() const + { + if (!data.value) + return 0; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetInt64() on non-numeric field."); return 0; + } + #endif + if (data.raw) + return *reinterpret_cast<int64*>(data.value); + return static_cast<int64>(atol((char*)data.value)); + } + + float GetFloat() const + { + if (!data.value) + return 0.0f; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetFloat() on non-numeric field."); + return 0.0f; + } + #endif + if (data.raw) + return *reinterpret_cast<float*>(data.value); + return static_cast<float>(atof((char*)data.value)); + } + + double GetDouble() const + { + if (!data.value) + return 0.0f; + + #ifdef TRINITY_DEBUG + if (!IsNumeric()) + { + sLog.outSQLDriver("Error: GetDouble() on non-numeric field."); + return 0.0f; + } + #endif + if (data.raw) + return *reinterpret_cast<double*>(data.value); + return static_cast<double>(atof((char*)data.value)); + } + + const char* GetCString() const + { + if (!data.value) + return NULL; + + #ifdef TRINITY_DEBUG + if (IsNumeric()) + { + sLog.outSQLDriver("Error: GetCString() on numeric field."); + return NULL; + } + #endif + return static_cast<const char*>(data.value); + } + + std::string GetString() const + { + if (!data.value) + return ""; + + if (data.raw) + { + const char* string = GetCString(); + if (!string) + string = ""; + return std::string(string, data.length); + } + return std::string((char*)data.value); + } + + protected: + Field(); + ~Field(); + + struct + { + enum_field_types type; // Field type + void* value; // Actual data in memory + bool raw; // Raw bytes? (Prepared statement or adhoc) + uint32 length; // Length (prepared strings only) + } data; + + void SetByteValue(void* newValue, const size_t newSize, enum_field_types newType, uint32 length); + void SetStructuredValue(char* newValue, enum_field_types newType, const size_t newSize); + + void CleanUp() + { + delete[] (data.value); + data.value = NULL; } - void SetType(enum DataTypes type) { mType = type; } + static size_t SizeForType(MYSQL_FIELD* field) + { + switch (field->type) + { + case MYSQL_TYPE_NULL: + return 0; + case MYSQL_TYPE_TINY: + return 1; + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_SHORT: + return 2; + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + return 4; + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_BIT: + return 8; + + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATETIME: + return sizeof(MYSQL_TIME); + + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_VAR_STRING: + return field->max_length + 1; - void SetValue(const char *value); + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + return 64; - private: - char *mValue; - enum DataTypes mType; + case MYSQL_TYPE_GEOMETRY: + /* + Following types are not sent over the wire: + MYSQL_TYPE_ENUM: + MYSQL_TYPE_SET: + */ + default: + sLog.outSQLDriver("SQL::SizeForType(): invalid field type %u", uint32(field->type)); + return 0; + } + } + + bool IsNumeric() const + { + return (data.type == MYSQL_TYPE_TINY || + data.type == MYSQL_TYPE_SHORT || + data.type == MYSQL_TYPE_INT24 || + data.type == MYSQL_TYPE_LONG || + data.type == MYSQL_TYPE_FLOAT || + data.type == MYSQL_TYPE_DOUBLE || + data.type == MYSQL_TYPE_LONGLONG ); + } }; + #endif diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp index 54bf97ce601..f3fa2f352da 100644 --- a/src/server/shared/Database/MySQLConnection.cpp +++ b/src/server/shared/Database/MySQLConnection.cpp @@ -222,14 +222,63 @@ bool MySQLConnection::Execute(PreparedStatement* stmt) m_mStmt->ClearParameters(); return false; } - else + + #ifdef SQLQUERY_LOG + sLog.outSQLDriver("[%u ms] Prepared SQL: %u", getMSTimeDiff(_s, getMSTime()), index); + #endif + m_mStmt->ClearParameters(); + return true; + } +} + +bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount) +{ + if (!m_Mysql) + return false; + + uint32 index = stmt->m_index; + { + // guarded block for thread-safe mySQL request + ACE_Guard<ACE_Thread_Mutex> query_connection_guard(m_Mutex); + + MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index); + ASSERT(m_mStmt); // Can only be null if preparation failed, server side error or bad query + m_mStmt->m_stmt = stmt; // Cross reference them for debug output + stmt->m_stmt = m_mStmt; // TODO: Cleaner way + + stmt->BindParameters(); + + MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT(); + MYSQL_BIND* msql_BIND = m_mStmt->GetBind(); + + #ifdef SQLQUERY_LOG + uint32 _s = getMSTime(); + #endif + if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) { - #ifdef SQLQUERY_LOG - sLog.outSQLDriver("[%u ms] Prepared SQL: %u", getMSTimeDiff(_s, getMSTime()), index); - #endif + sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u) error binding params: %s", index, mysql_stmt_error(msql_STMT)); + m_mStmt->ClearParameters(); + return false; + } + + if (mysql_stmt_execute(msql_STMT)) + { + sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u) error executing: %s", index, mysql_stmt_error(msql_STMT)); m_mStmt->ClearParameters(); - return true; + return false; } + + #ifdef SQLQUERY_LOG + sLog.outSQLDriver("[%u ms] Prepared SQL: %u", getMSTimeDiff(_s, getMSTime()), index); + #endif + m_mStmt->ClearParameters(); + + *pResult = mysql_stmt_result_metadata(msql_STMT); + *pRowCount = /*mysql_affected_rows(m_Mysql); //* or*/ mysql_stmt_num_rows(msql_STMT); + *pFieldCount = mysql_stmt_field_count(msql_STMT); + + return true; + } } @@ -336,10 +385,17 @@ void MySQLConnection::PrepareStatement(uint32 index, const char* sql) PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt) { - this->Execute(stmt); + MYSQL_RES *result = NULL; + MYSQL_FIELD *fields = NULL; + uint64 rowCount = 0; + uint32 fieldCount = 0; + + if (!_Query(stmt, &result, &fields, &rowCount, &fieldCount)) + return NULL; + if (mysql_more_results(m_Mysql)) { mysql_next_result(m_Mysql); } - return new PreparedResultSet(stmt->m_stmt->GetSTMT()); + return new PreparedResultSet(stmt->m_stmt->GetSTMT(), result, fields, rowCount, fieldCount); } diff --git a/src/server/shared/Database/MySQLConnection.h b/src/server/shared/Database/MySQLConnection.h index b707f8a4675..09c30e7073e 100644 --- a/src/server/shared/Database/MySQLConnection.h +++ b/src/server/shared/Database/MySQLConnection.h @@ -43,6 +43,7 @@ class MySQLConnection ResultSet* Query(const char* sql); PreparedResultSet* Query(PreparedStatement* stmt); bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount); + bool _Query(PreparedStatement* stmt, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount); void BeginTransaction(); void RollbackTransaction(); diff --git a/src/server/shared/Database/QueryHolder.cpp b/src/server/shared/Database/QueryHolder.cpp index 26ccce3853c..6c152f478f8 100644 --- a/src/server/shared/Database/QueryHolder.cpp +++ b/src/server/shared/Database/QueryHolder.cpp @@ -89,13 +89,6 @@ QueryResult SQLQueryHolder::GetResult(size_t index) // Don't call to this function if the index is of an ad-hoc statement if (index < m_queries.size()) { - /// the query strings are freed on the first GetResult or in the destructor - if (SQLElementData* data = &m_queries[index].first) - { - free((void*)(const_cast<char*>(data->element.query))); - data->element.query = NULL; - } - ResultSet* result = m_queries[index].second.qresult; if (!result || !result->GetRowCount()) return QueryResult(NULL); @@ -112,18 +105,10 @@ PreparedQueryResult SQLQueryHolder::GetPreparedResult(size_t index) // Don't call to this function if the index is of a prepared statement if (index < m_queries.size()) { - /// the query strings are freed on the first GetResult or in the destructor - if (SQLElementData* data = &m_queries[index].first) - { - delete data->element.stmt; - data->element.stmt = NULL; - } - PreparedResultSet* result = m_queries[index].second.presult; if (!result || !result->GetRowCount()) return PreparedQueryResult(NULL); - result->NextRow(); return PreparedQueryResult(result); } else diff --git a/src/server/shared/Database/QueryResult.cpp b/src/server/shared/Database/QueryResult.cpp index 283734b80b7..b6a4e8477c9 100644 --- a/src/server/shared/Database/QueryResult.cpp +++ b/src/server/shared/Database/QueryResult.cpp @@ -21,106 +21,29 @@ #include "DatabaseEnv.h" #include "Log.h" -ResultSet::ResultSet(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) -: mFieldCount(fieldCount) -, mRowCount(rowCount) -, mResult(result) +ResultSet::ResultSet(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) : +m_result(result), +m_fields(fields), +m_rowCount(rowCount), +m_fieldCount(fieldCount) +{ + m_currentRow = new Field[m_fieldCount]; + ASSERT(m_currentRow); +} + +PreparedResultSet::PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) : +m_rBind(NULL), +m_stmt(stmt), +m_res(result), +m_isNull(NULL), +m_length(NULL), +m_rowCount(rowCount), +m_fieldCount(fieldCount), +m_rowPosition(0) { - mCurrentRow = new Field[mFieldCount]; - ASSERT(mCurrentRow); - - for (uint32 i = 0; i < mFieldCount; i++) - mCurrentRow[i].SetType(ConvertNativeType(fields[i].type)); -} - -ResultSet::~ResultSet() -{ - EndQuery(); -} - -bool ResultSet::NextRow() -{ - MYSQL_ROW row; - - if (!mResult) - return false; - - row = mysql_fetch_row(mResult); - if (!row) - { - EndQuery(); - return false; - } - - for (uint32 i = 0; i < mFieldCount; i++) - mCurrentRow[i].SetValue(row[i]); - - return true; -} - -void ResultSet::EndQuery() -{ - if (mCurrentRow) - { - delete [] mCurrentRow; - mCurrentRow = 0; - } - - if (mResult) - { - mysql_free_result(mResult); - mResult = 0; - } -} - -enum Field::DataTypes ResultSet::ConvertNativeType(enum_field_types mysqlType) const -{ - switch (mysqlType) - { - case FIELD_TYPE_TIMESTAMP: - case FIELD_TYPE_DATE: - case FIELD_TYPE_TIME: - case FIELD_TYPE_DATETIME: - case FIELD_TYPE_YEAR: - case FIELD_TYPE_STRING: - case FIELD_TYPE_VAR_STRING: - case FIELD_TYPE_BLOB: - case FIELD_TYPE_SET: - case FIELD_TYPE_NULL: - return Field::DB_TYPE_STRING; - case FIELD_TYPE_TINY: - - case FIELD_TYPE_SHORT: - case FIELD_TYPE_LONG: - case FIELD_TYPE_INT24: - case FIELD_TYPE_LONGLONG: - case FIELD_TYPE_ENUM: - return Field::DB_TYPE_INTEGER; - case FIELD_TYPE_DECIMAL: - case FIELD_TYPE_FLOAT: - case FIELD_TYPE_DOUBLE: - return Field::DB_TYPE_FLOAT; - default: - return Field::DB_TYPE_UNKNOWN; - } -} - -void ResultBind::BindResult(uint64& num_rows) -{ - FreeBindBuffer(); - - m_res = mysql_stmt_result_metadata(m_stmt); if (!m_res) return; - m_fieldCount = mysql_stmt_field_count(m_stmt); - - if (m_stmt->bind_result_done) - { - delete[] m_stmt->bind->length; - delete[] m_stmt->bind->is_null; - } - m_rBind = new MYSQL_BIND[m_fieldCount]; m_isNull = new my_bool[m_fieldCount]; m_length = new unsigned long[m_fieldCount]; @@ -141,7 +64,7 @@ void ResultBind::BindResult(uint64& num_rows) MYSQL_FIELD* field; while ((field = mysql_fetch_field(m_res))) { - size_t size = SizeForType(field); + size_t size = Field::SizeForType(field); m_rBind[i].buffer_type = field->type; m_rBind[i].buffer = malloc(size); @@ -165,133 +88,136 @@ void ResultBind::BindResult(uint64& num_rows) return; } - num_rows = mysql_stmt_num_rows(m_stmt); -} - -void ResultBind::FreeBindBuffer() -{ - for (uint32 i = 0; i < m_fieldCount; ++i) - free (m_rBind[i].buffer); -} - -void ResultBind::CleanUp() -{ - if (m_res) - mysql_free_result(m_res); + m_rowCount = mysql_stmt_num_rows(m_stmt); - FreeBindBuffer(); - mysql_stmt_free_result(m_stmt); + m_rows.resize(m_rowCount); + while (_NextRow()) + { + m_rows[m_rowPosition] = new Field[m_fieldCount]; + for (uint64 fIndex = 0; fIndex < m_fieldCount; ++fIndex) + { + if (!*m_rBind[fIndex].is_null) + m_rows[m_rowPosition][fIndex].SetByteValue( m_rBind[fIndex].buffer, + m_rBind[fIndex].buffer_length, + m_rBind[fIndex].buffer_type, + *m_rBind[fIndex].length ); + else + switch (m_rBind[fIndex].buffer_type) + { + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_VAR_STRING: + m_rows[m_rowPosition][fIndex].SetByteValue( "", + m_rBind[fIndex].buffer_length, + m_rBind[fIndex].buffer_type, + *m_rBind[fIndex].length ); + break; + default: + m_rows[m_rowPosition][fIndex].SetByteValue( 0, + m_rBind[fIndex].buffer_length, + m_rBind[fIndex].buffer_type, + *m_rBind[fIndex].length ); + } + } + m_rowPosition++; + } + m_rowPosition = 0; - delete[] m_rBind; + /// All data is buffered, let go of mysql c api structures + CleanUp(); } -bool PreparedResultSet::GetBool(uint32 index) +ResultSet::~ResultSet() { - // TODO: Perhaps start storing data in genuine bool formats in tables - return GetUInt8(index) == 1 ? true : false; + CleanUp(); } -uint8 PreparedResultSet::GetUInt8(uint32 index) +PreparedResultSet::~PreparedResultSet() { - if (!CheckFieldIndex(index)) - return 0; - - return *reinterpret_cast<uint8*>(rbind->m_rBind[index].buffer); + for (uint64 i = 0; i < m_rowCount; ++i) + delete[] m_rows[i]; } -int8 PreparedResultSet::GetInt8(uint32 index) +bool ResultSet::NextRow() { - if (!CheckFieldIndex(index)) - return 0; - - return *reinterpret_cast<int8*>(rbind->m_rBind[index].buffer); -} + MYSQL_ROW row; -uint16 PreparedResultSet::GetUInt16(uint32 index) -{ - if (!CheckFieldIndex(index)) - return 0; + if (!m_result) + return false; - return *reinterpret_cast<uint16*>(rbind->m_rBind[index].buffer); -} + row = mysql_fetch_row(m_result); + if (!row) + { + CleanUp(); + return false; + } -int16 PreparedResultSet::GetInt16(uint32 index) -{ - if (!CheckFieldIndex(index)) - return 0; + for (uint32 i = 0; i < m_fieldCount; i++) + m_currentRow[i].SetStructuredValue(row[i], m_fields[i].type, Field::SizeForType(&m_fields[i])); - return *reinterpret_cast<int16*>(rbind->m_rBind[index].buffer); + return true; } -uint32 PreparedResultSet::GetUInt32(uint32 index) +bool PreparedResultSet::NextRow() { - if (!CheckFieldIndex(index)) - return 0; + /// Only updates the m_rowPosition so upper level code knows in which element + /// of the rows vector to look + if (++m_rowPosition >= m_rowCount) + return false; - return *reinterpret_cast<uint32*>(rbind->m_rBind[index].buffer); + return true; } -int32 PreparedResultSet::GetInt32(uint32 index) +bool PreparedResultSet::_NextRow() { - if (!CheckFieldIndex(index)) - return 0; - - return *reinterpret_cast<int32*>(rbind->m_rBind[index].buffer); -} + /// Only called in low-level code, namely the constructor + /// Will iterate over every row of data and buffer it + if (m_rowPosition >= m_rowCount) + return false; -float PreparedResultSet::GetFloat(uint32 index) -{ - if (!CheckFieldIndex(index)) - return 0; + int retval = mysql_stmt_fetch( m_stmt ); - return *reinterpret_cast<float*>(rbind->m_rBind[index].buffer); -} + if (!retval || retval == MYSQL_DATA_TRUNCATED) + retval = true; -uint64 PreparedResultSet::GetUInt64(uint32 index) -{ - if (!CheckFieldIndex(index)) - return 0; + if (retval == MYSQL_NO_DATA) + retval = false; - return *reinterpret_cast<uint64*>(rbind->m_rBind[index].buffer); + return retval; } -int64 PreparedResultSet::GetInt64(uint32 index) +void ResultSet::CleanUp() { - if (!CheckFieldIndex(index)) - return 0; + if (m_currentRow) + { + delete [] m_currentRow; + m_currentRow = NULL; + } - return *reinterpret_cast<int64*>(rbind->m_rBind[index].buffer); + if (m_result) + { + mysql_free_result(m_result); + m_result = NULL; + } } -std::string PreparedResultSet::GetString(uint32 index) +void PreparedResultSet::CleanUp() { - if (!CheckFieldIndex(index)) - return std::string(""); - - return std::string(static_cast<char const*>(rbind->m_rBind[index].buffer), *rbind->m_rBind[index].length); -} + /// More of the in our code allocated sources are deallocated by the poorly documented mysql c api + if (m_res) + mysql_free_result(m_res); -const char* PreparedResultSet::GetCString(uint32 index) -{ - if (!CheckFieldIndex(index)) - return '\0'; + FreeBindBuffer(); + mysql_stmt_free_result(m_stmt); - return static_cast<char const*>(rbind->m_rBind[index].buffer); + delete[] m_rBind; } -bool PreparedResultSet::NextRow() +void PreparedResultSet::FreeBindBuffer() { - if (row_position >= num_rows) - return false; - - int retval = mysql_stmt_fetch( rbind->m_stmt ); - - if (!retval || retval == MYSQL_DATA_TRUNCATED) - retval = true; - - if (retval == MYSQL_NO_DATA) - retval = false; - - ++row_position; - return retval; -}
\ No newline at end of file + for (uint32 i = 0; i < m_fieldCount; ++i) + free (m_rBind[i].buffer); +} diff --git a/src/server/shared/Database/QueryResult.h b/src/server/shared/Database/QueryResult.h index 22cd8bbf19e..aa088b5f121 100755 --- a/src/server/shared/Database/QueryResult.h +++ b/src/server/shared/Database/QueryResult.h @@ -39,193 +39,70 @@ class ResultSet ~ResultSet(); bool NextRow(); - - Field *Fetch() const { return mCurrentRow; } - - const Field & operator [] (int index) const { return mCurrentRow[index]; } - - uint32 GetFieldCount() const { return mFieldCount; } - uint64 GetRowCount() const { return mRowCount; } + uint64 GetRowCount() const { return m_rowCount; } + uint32 GetFieldCount() const { return m_fieldCount; } + + Field *Fetch() const { return m_currentRow; } + const Field & operator [] (uint32 index) const + { + ASSERT(index < m_rowCount); + return m_currentRow[index]; + } protected: - Field *mCurrentRow; - uint32 mFieldCount; - uint64 mRowCount; + Field *m_currentRow; + uint64 m_rowCount; + uint32 m_fieldCount; private: - enum Field::DataTypes ConvertNativeType(enum_field_types mysqlType) const; - void EndQuery(); - MYSQL_RES *mResult; - + void CleanUp(); + MYSQL_RES *m_result; + MYSQL_FIELD *m_fields; }; typedef ACE_Refcounted_Auto_Ptr<ResultSet, ACE_Null_Mutex> QueryResult; -typedef std::vector<std::string> QueryFieldNames; - -class QueryNamedResult +class PreparedResultSet { public: - explicit QueryNamedResult(ResultSet* query, QueryFieldNames const& names) : mQuery(query), mFieldNames(names) {} - ~QueryNamedResult() { delete mQuery; } - - // compatible interface with ResultSet - bool NextRow() { return mQuery->NextRow(); } - Field *Fetch() const { return mQuery->Fetch(); } - uint32 GetFieldCount() const { return mQuery->GetFieldCount(); } - uint64 GetRowCount() const { return mQuery->GetRowCount(); } - Field const& operator[] (int index) const { return (*mQuery)[index]; } + PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount); + ~PreparedResultSet(); - // named access - Field const& operator[] (const std::string &name) const { return mQuery->Fetch()[GetField_idx(name)]; } - QueryFieldNames const& GetFieldNames() const { return mFieldNames; } + bool NextRow(); + uint64 GetRowCount() const { return m_rowCount; } + uint32 GetFieldCount() const { return m_fieldCount; } - uint32 GetField_idx(const std::string &name) const + Field* Fetch() const { - for (size_t idx = 0; idx < mFieldNames.size(); ++idx) - { - if(mFieldNames[idx] == name) - return idx; - } - ASSERT(false && "unknown field name"); - return uint32(-1); + ASSERT(m_rowPosition < m_rowCount); + return m_rows[m_rowPosition]; } - protected: - ResultSet *mQuery; - QueryFieldNames mFieldNames; -}; - -class ResultBind -{ - friend class PreparedResultSet; - public: - - ResultBind(MYSQL_STMT* stmt) : m_rBind(NULL), m_stmt(stmt), m_res(NULL), m_isNull(NULL), m_length(NULL), m_fieldCount(0) {} - - ~ResultBind() + const Field & operator [] (uint32 index) const { - CleanUp(); // Clean up buffer + ASSERT(m_rowPosition < m_rowCount); + ASSERT(index < m_fieldCount); + return m_rows[m_rowPosition][index]; } - void BindResult(uint64& num_rows); - protected: + uint64 m_rowCount; + uint64 m_rowPosition; + std::vector<Field*> m_rows; + uint32 m_fieldCount; + + private: MYSQL_BIND* m_rBind; MYSQL_STMT* m_stmt; MYSQL_RES* m_res; - void FreeBindBuffer(); - bool IsValidIndex(uint32 index) { return index < m_fieldCount; } - - private: - - void CleanUp(); - - size_t SizeForType(MYSQL_FIELD* field) - { - switch (field->type) - { - case MYSQL_TYPE_NULL: - return 0; - case MYSQL_TYPE_TINY: - return 1; - case MYSQL_TYPE_YEAR: - case MYSQL_TYPE_SHORT: - return 2; - case MYSQL_TYPE_INT24: - case MYSQL_TYPE_LONG: - case MYSQL_TYPE_FLOAT: - return 4; - case MYSQL_TYPE_DOUBLE: - case MYSQL_TYPE_LONGLONG: - case MYSQL_TYPE_BIT: - return 8; - - case MYSQL_TYPE_TIMESTAMP: - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATETIME: - return sizeof(MYSQL_TIME); - - case MYSQL_TYPE_TINY_BLOB: - case MYSQL_TYPE_MEDIUM_BLOB: - case MYSQL_TYPE_LONG_BLOB: - case MYSQL_TYPE_BLOB: - case MYSQL_TYPE_STRING: - case MYSQL_TYPE_VAR_STRING: - return field->max_length + 1; - - case MYSQL_TYPE_DECIMAL: - case MYSQL_TYPE_NEWDECIMAL: - return 64; - - case MYSQL_TYPE_GEOMETRY: - /* - Following types are not sent over the wire: - MYSQL_TYPE_ENUM: - MYSQL_TYPE_SET: - */ - default: - sLog.outSQLDriver("ResultBind::SizeForType(): invalid field type %u", uint32(field->type)); - return 0; - } - } - my_bool* m_isNull; unsigned long* m_length; - uint32 m_fieldCount; -}; -class PreparedResultSet -{ - template<class T> friend class DatabaseWorkerPool; - public: - PreparedResultSet(MYSQL_STMT* stmt) - { - num_rows = 0; - row_position = 0; - rbind = new ResultBind(stmt); - rbind->BindResult(num_rows); - } - ~PreparedResultSet() - { - delete rbind; - } - - operator bool() { return num_rows > 0; } - - bool GetBool(uint32 index); - uint8 GetUInt8(uint32 index); - int8 GetInt8(uint32 index); - uint16 GetUInt16(uint32 index); - int16 GetInt16(uint32 index); - uint32 GetUInt32(uint32 index); - int32 GetInt32(uint32 index); - uint64 GetUInt64(uint32 index); - int64 GetInt64(uint32 index); - float GetFloat(uint32 index); - std::string GetString(uint32 index); - const char* GetCString(uint32 index); - - bool NextRow(); - uint64 GetRowCount() const { return num_rows; } - - private: - bool CheckFieldIndex(uint32 index) const - { - if (!rbind->IsValidIndex(index)) - return false; - - if (rbind->m_isNull[index]) - return false; - - return true; - } + void FreeBindBuffer(); + void CleanUp(); + bool _NextRow(); - ResultBind* rbind; - uint64 row_position; - uint64 num_rows; }; typedef ACE_Refcounted_Auto_Ptr<PreparedResultSet, ACE_Null_Mutex> PreparedQueryResult; diff --git a/src/server/shared/Database/SQLStorageImpl.h b/src/server/shared/Database/SQLStorageImpl.h index 533ce7a37c3..04e905e4aa3 100644 --- a/src/server/shared/Database/SQLStorageImpl.h +++ b/src/server/shared/Database/SQLStorageImpl.h @@ -198,7 +198,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) case FT_FLOAT: storeValue((float)fields[x].GetFloat(), store, p, x, offset); break; case FT_STRING: - storeValue((char*)fields[x].GetString(), store, p, x, offset); break; + storeValue((char*)fields[x].GetCString(), store, p, x, offset); break; } ++count; }while( result->NextRow() ); diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index 0a5b16563f5..226f22f647c 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -212,7 +212,7 @@ bool ChatHandler::GetDeletedCharacterInfoList(DeletedInfoList& foundList, std::s DeletedInfo info; info.lowguid = fields[0].GetUInt32(); - info.name = fields[1].GetCppString(); + info.name = fields[1].GetString(); info.accountId = fields[2].GetUInt32(); // account name will be empty for not existed account @@ -562,7 +562,7 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/) do { Field *fieldsDB = resultDB->Fetch(); - std::string name = fieldsDB[0].GetCppString(); + std::string name = fieldsDB[0].GetString(); uint32 account = fieldsDB[1].GetUInt32(); ///- Get the username, last IP and GM level of each account |