From 1de7e5bed179a2c1bcaf7cdb68fb377c39afd51a Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Sat, 11 Sep 2010 21:22:15 +0200 Subject: Core/DBLayer: * Example implementation of prepared statements with resultset in RealmList and AuthSocket code (selectively) * Also correct a few bobo´s from previous commit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : trunk --- src/server/authserver/Realms/RealmList.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/server/authserver/Realms') diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp index 63cadf7cb22..42b63c9e322 100644 --- a/src/server/authserver/Realms/RealmList.cpp +++ b/src/server/authserver/Realms/RealmList.cpp @@ -78,20 +78,30 @@ void RealmList::UpdateRealms(bool init) { sLog.outDetail("Updating Realm List..."); - QueryResult_AutoPtr result = LoginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name"); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_REALMLIST); + PreparedQueryResult result = LoginDatabase.Query(stmt); ///- Circle through results and add them to the realm map if (result) { do { - Field *fields = result->Fetch(); + 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); + + UpdateRealm(realmId, name, address, port, icon, color, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build); - uint8 allowedSecurityLevel = fields[7].GetUInt8(); - - UpdateRealm(fields[0].GetUInt32(), fields[1].GetCppString(),fields[2].GetCppString(),fields[3].GetUInt32(),fields[4].GetUInt8(), fields[5].GetUInt8(), fields[6].GetUInt8(), (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), fields[8].GetFloat(), fields[9].GetUInt32()); if (init) - sLog.outString("Added realm \"%s\".", fields[1].GetString()); - } while(result->NextRow()); + sLog.outString("Added realm \"%s\".", result->GetString(1).c_str()); + } + while (result->NextRow()); } } -- cgit v1.2.3