aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnubisss <none@none>2010-01-23 14:45:58 +0100
committerAnubisss <none@none>2010-01-23 14:45:58 +0100
commitd9cb0702158fd045285f2c0a904cb31a45a3864a (patch)
treecdc6a7c6a83c6eea603ae296a653fb9f04945aad /src
parentc784110d87666579f18620a98e1e57118db4a9cf (diff)
Implement QueryResult_AutoPtr type which is ACE's reference counted auto_ptr(ACE_Refcounted_Auto_Ptr) for QueryResult pointers.
Use this auto_ptr for every DB queries(except QueryNamedResult yet). This patch guarantees NO memory leaks from QueryResult pointers. Thanks to raczman for the idea and for the helping to make this patch. --HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/framework/Utilities/Callback.h57
-rw-r--r--src/game/AccountMgr.cpp25
-rw-r--r--src/game/AchievementMgr.cpp20
-rw-r--r--src/game/AchievementMgr.h2
-rw-r--r--src/game/AddonMgr.cpp4
-rw-r--r--src/game/ArenaTeam.cpp14
-rw-r--r--src/game/AuctionHouseBot.cpp17
-rw-r--r--src/game/AuctionHouseMgr.cpp16
-rw-r--r--src/game/Bag.cpp2
-rw-r--r--src/game/Bag.h2
-rw-r--r--src/game/BattleGroundMgr.cpp13
-rw-r--r--src/game/Channel.cpp4
-rw-r--r--src/game/CharacterHandler.cpp44
-rw-r--r--src/game/Chat.cpp3
-rw-r--r--src/game/Chat.h4
-rw-r--r--src/game/CreatureEventAIMgr.cpp12
-rw-r--r--src/game/CreatureGroups.cpp9
-rw-r--r--src/game/GameEventMgr.cpp29
-rw-r--r--src/game/GlobalEvents.cpp4
-rw-r--r--src/game/Group.cpp7
-rw-r--r--src/game/Group.h2
-rw-r--r--src/game/Guild.cpp33
-rw-r--r--src/game/InstanceSaveMgr.cpp18
-rw-r--r--src/game/Item.cpp9
-rw-r--r--src/game/Item.h2
-rw-r--r--src/game/ItemEnchantmentMgr.cpp4
-rw-r--r--src/game/Level2.cpp100
-rw-r--r--src/game/Level3.cpp80
-rw-r--r--src/game/LootMgr.cpp4
-rw-r--r--src/game/Mail.cpp3
-rw-r--r--src/game/Map.cpp3
-rw-r--r--src/game/MapManager.cpp5
-rw-r--r--src/game/MiscHandler.cpp12
-rw-r--r--src/game/NPCHandler.cpp14
-rw-r--r--src/game/ObjectMgr.cpp292
-rw-r--r--src/game/Pet.cpp42
-rw-r--r--src/game/PetitionsHandler.cpp39
-rw-r--r--src/game/Player.cpp145
-rw-r--r--src/game/Player.h42
-rw-r--r--src/game/PlayerDump.cpp23
-rw-r--r--src/game/PoolHandler.cpp11
-rw-r--r--src/game/QueryHandler.cpp6
-rw-r--r--src/game/ReputationMgr.cpp4
-rw-r--r--src/game/ReputationMgr.h3
-rw-r--r--src/game/ScriptSystem.cpp50
-rw-r--r--src/game/SkillDiscovery.cpp4
-rw-r--r--src/game/SkillExtraItems.cpp4
-rw-r--r--src/game/SocialMgr.cpp3
-rw-r--r--src/game/SocialMgr.h2
-rw-r--r--src/game/SpellHandler.cpp3
-rw-r--r--src/game/SpellMgr.cpp48
-rw-r--r--src/game/Transports.cpp5
-rw-r--r--src/game/WaypointManager.cpp8
-rw-r--r--src/game/World.cpp20
-rw-r--r--src/game/World.h3
-rw-r--r--src/game/WorldSession.cpp14
-rw-r--r--src/game/WorldSession.h13
-rw-r--r--src/game/WorldSocket.cpp10
-rw-r--r--src/shared/Database/DBCStore.h6
-rw-r--r--src/shared/Database/Database.cpp11
-rw-r--r--src/shared/Database/Database.h36
-rw-r--r--src/shared/Database/DatabaseImpl.h48
-rw-r--r--src/shared/Database/DatabaseMysql.cpp6
-rw-r--r--src/shared/Database/DatabaseMysql.h2
-rw-r--r--src/shared/Database/DatabasePostgre.cpp8
-rw-r--r--src/shared/Database/DatabasePostgre.h2
-rw-r--r--src/shared/Database/QueryResult.h7
-rw-r--r--src/shared/Database/SQLStorageImpl.h7
-rw-r--r--src/shared/Database/SqlOperations.cpp12
-rw-r--r--src/shared/Database/SqlOperations.h7
-rw-r--r--src/trinitycore/CliRunnable.cpp8
-rw-r--r--src/trinitycore/Master.cpp6
-rw-r--r--src/trinitycore/RASocket.cpp6
-rw-r--r--src/trinityrealm/AuthSocket.cpp18
-rw-r--r--src/trinityrealm/Main.cpp2
-rw-r--r--src/trinityrealm/RealmList.cpp3
76 files changed, 458 insertions, 1108 deletions
diff --git a/src/framework/Utilities/Callback.h b/src/framework/Utilities/Callback.h
index 0e58bfa0c56..d2e2c36851a 100644
--- a/src/framework/Utilities/Callback.h
+++ b/src/framework/Utilities/Callback.h
@@ -269,6 +269,7 @@ namespace Trinity
/// ---------- QUERY CALLBACKS -----------
+#include "QueryResult.h"
class QueryResult;
namespace Trinity
@@ -278,8 +279,8 @@ namespace Trinity
public:
virtual void Execute() = 0;
virtual ~IQueryCallback() {}
- virtual void SetResult(QueryResult* result) = 0;
- virtual QueryResult* GetResult() = 0;
+ virtual void SetResult(QueryResult_AutoPtr result) = 0;
+ virtual QueryResult_AutoPtr GetResult() = 0;
};
template < class CB >
@@ -288,50 +289,50 @@ namespace Trinity
public:
_IQueryCallback(CB const& cb) : CB(cb) {}
void Execute() { CB::_Execute(); }
- void SetResult(QueryResult* result) { CB::m_param1 = result; }
- QueryResult* GetResult() { return CB::m_param1; }
+ void SetResult(QueryResult_AutoPtr result) { CB::m_param1 = result; }
+ QueryResult_AutoPtr GetResult() { return CB::m_param1; }
};
template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
class QueryCallback :
- public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > >
+ public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > >
{
private:
- typedef _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > QC3;
+ typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3;
public:
- QueryCallback(Class *object, typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
+ QueryCallback(Class *object, typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
: _IQueryCallback< QC3 >(QC3(object, method, result, param1, param2, param3)) {}
};
template < class Class, typename ParamType1, typename ParamType2 >
class QueryCallback < Class, ParamType1, ParamType2 > :
- public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2 > >
+ public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > >
{
private:
- typedef _Callback < Class, QueryResult*, ParamType1, ParamType2 > QC2;
+ typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > QC2;
public:
- QueryCallback(Class *object, typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2)
+ QueryCallback(Class *object, typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
: _IQueryCallback< QC2 >(QC2(object, method, result, param1, param2)) {}
};
template < class Class, typename ParamType1 >
class QueryCallback < Class, ParamType1 > :
- public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1 > >
+ public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1 > >
{
private:
- typedef _Callback < Class, QueryResult*, ParamType1 > QC1;
+ typedef _Callback < Class, QueryResult_AutoPtr, ParamType1 > QC1;
public:
- QueryCallback(Class *object, typename QC1::Method method, QueryResult* result, ParamType1 param1)
+ QueryCallback(Class *object, typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
: _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {}
};
template < class Class >
- class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult* > >
+ class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr > >
{
private:
- typedef _Callback < Class, QueryResult* > QC0;
+ typedef _Callback < Class, QueryResult_AutoPtr > QC0;
public:
- QueryCallback(Class *object, typename QC0::Method method, QueryResult* result)
+ QueryCallback(Class *object, typename QC0::Method method, QueryResult_AutoPtr result)
: _IQueryCallback< QC0 >(QC0(object, method, result)) {}
};
@@ -339,44 +340,44 @@ namespace Trinity
template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
class SQueryCallback :
- public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > >
+ public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > >
{
private:
- typedef _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > QC3;
+ typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3;
public:
- SQueryCallback(typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
+ SQueryCallback(typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
: _IQueryCallback< QC3 >(QC3(method, result, param1, param2, param3)) {}
};
template < typename ParamType1, typename ParamType2 >
class SQueryCallback < ParamType1, ParamType2 > :
- public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2 > >
+ public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > >
{
private:
- typedef _SCallback < QueryResult*, ParamType1, ParamType2 > QC2;
+ typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > QC2;
public:
- SQueryCallback(typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2)
+ SQueryCallback(typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2)
: _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {}
};
template < typename ParamType1 >
class SQueryCallback < ParamType1 > :
- public _IQueryCallback< _SCallback < QueryResult*, ParamType1 > >
+ public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1 > >
{
private:
- typedef _SCallback < QueryResult*, ParamType1 > QC1;
+ typedef _SCallback < QueryResult_AutoPtr, ParamType1 > QC1;
public:
- SQueryCallback(typename QC1::Method method, QueryResult* result, ParamType1 param1)
+ SQueryCallback(typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1)
: _IQueryCallback< QC1 >(QC1(method, result, param1)) {}
};
template < >
- class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult* > >
+ class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult_AutoPtr > >
{
private:
- typedef _SCallback < QueryResult* > QC0;
+ typedef _SCallback < QueryResult_AutoPtr > QC0;
public:
- SQueryCallback(QC0::Method method, QueryResult* result)
+ SQueryCallback(QC0::Method method, QueryResult_AutoPtr result)
: _IQueryCallback< QC0 >(QC0(method, result)) {}
};
}
diff --git a/src/game/AccountMgr.cpp b/src/game/AccountMgr.cpp
index 4b186725451..40b1291397c 100644
--- a/src/game/AccountMgr.cpp
+++ b/src/game/AccountMgr.cpp
@@ -59,10 +59,9 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass
AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
{
- QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
if(!result)
return AOR_NAME_NOT_EXIST; // account doesn't exist
- delete result;
result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE account='%d'",accid);
if (result)
@@ -83,8 +82,6 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
Player::DeleteFromDB(guid, accid, false); // no need to update realm characters
} while (result->NextRow());
-
- delete result;
}
// table realm specific but common for all characters of account for realm
@@ -108,10 +105,9 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname, std::string new_passwd)
{
- QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
if(!result)
return AOR_NAME_NOT_EXIST; // account doesn't exist
- delete result;
if(utf8length(new_uname) > MAX_ACCOUNT_STR)
return AOR_NAME_TOO_LONG;
@@ -156,24 +152,22 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd)
uint32 AccountMgr::GetId(std::string username)
{
loginDatabase.escape_string(username);
- QueryResult *result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str());
if(!result)
return 0;
else
{
uint32 id = (*result)[0].GetUInt32();
- delete result;
return id;
}
}
uint32 AccountMgr::GetSecurity(uint32 acc_id)
{
- QueryResult *result = loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id);
if(result)
{
uint32 sec = (*result)[0].GetUInt32();
- delete result;
return sec;
}
@@ -182,13 +176,12 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id)
uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id)
{
- QueryResult *result = (realm_id == -1)
+ QueryResult_AutoPtr result = (realm_id == -1)
? loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND RealmID = '%d'", acc_id, realm_id)
: loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", acc_id, realm_id);
if(result)
{
uint32 sec = (*result)[0].GetUInt32();
- delete result;
return sec;
}
@@ -197,11 +190,10 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id)
bool AccountMgr::GetName(uint32 acc_id, std::string &name)
{
- QueryResult *result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id);
if(result)
{
name = (*result)[0].GetCppString();
- delete result;
return true;
}
@@ -217,12 +209,9 @@ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd)
normalizeString(username);
normalizeString(passwd);
- QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str());
if (result)
- {
- delete result;
return true;
- }
return false;
}
diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp
index 17818f9dfa3..66c5b2ecd30 100644
--- a/src/game/AchievementMgr.cpp
+++ b/src/game/AchievementMgr.cpp
@@ -535,7 +535,7 @@ void AchievementMgr::SaveToDB()
}
}
-void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *criteriaResult)
+void AchievementMgr::LoadFromDB(QueryResult_AutoPtr achievementResult, QueryResult_AutoPtr criteriaResult)
{
if(achievementResult)
{
@@ -553,7 +553,6 @@ void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *cri
ca.date = time_t(fields[1].GetUInt64());
ca.changed = false;
} while(achievementResult->NextRow());
- delete achievementResult;
}
if(criteriaResult)
@@ -583,7 +582,6 @@ void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *cri
progress.date = date;
progress.changed = false;
} while(criteriaResult->NextRow());
- delete criteriaResult;
}
}
@@ -1937,7 +1935,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData()
{
m_criteriaDataMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2 FROM achievement_criteria_data");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2 FROM achievement_criteria_data");
if(!result)
{
@@ -1988,8 +1986,6 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData()
++count;
} while(result->NextRow());
- delete result;
-
// post loading checks
for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId)
{
@@ -2061,7 +2057,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData()
void AchievementGlobalMgr::LoadCompletedAchievements()
{
- QueryResult *result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement");
if(!result)
{
@@ -2091,8 +2087,6 @@ void AchievementGlobalMgr::LoadCompletedAchievements()
m_allCompletedAchievements.insert(achievement_id);
} while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %lu realm completed achievements.",(unsigned long)m_allCompletedAchievements.size());
}
@@ -2102,7 +2096,7 @@ void AchievementGlobalMgr::LoadRewards()
m_achievementRewards.clear(); // need for reload case
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT entry, title_A, title_H, item, sender, subject, text FROM achievement_reward");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, title_A, title_H, item, sender, subject, text FROM achievement_reward");
if(!result)
{
@@ -2203,8 +2197,6 @@ void AchievementGlobalMgr::LoadRewards()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u achievement rewards", count );
}
@@ -2213,7 +2205,7 @@ void AchievementGlobalMgr::LoadRewardLocales()
{
m_achievementRewardLocales.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,subject_loc1,text_loc1,subject_loc2,text_loc2,subject_loc3,text_loc3,subject_loc4,text_loc4,subject_loc5,text_loc5,subject_loc6,text_loc6,subject_loc7,text_loc7,subject_loc8,text_loc8 FROM locales_achievement_reward");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,subject_loc1,text_loc1,subject_loc2,text_loc2,subject_loc3,text_loc3,subject_loc4,text_loc4,subject_loc5,text_loc5,subject_loc6,text_loc6,subject_loc7,text_loc7,subject_loc8,text_loc8 FROM locales_achievement_reward");
if (!result)
{
@@ -2273,8 +2265,6 @@ void AchievementGlobalMgr::LoadRewardLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu achievement reward locale strings", (unsigned long)m_achievementRewardLocales.size() );
}
diff --git a/src/game/AchievementMgr.h b/src/game/AchievementMgr.h
index 4e7ce2495a0..11473653fe7 100644
--- a/src/game/AchievementMgr.h
+++ b/src/game/AchievementMgr.h
@@ -232,7 +232,7 @@ class AchievementMgr
void Reset();
static void DeleteFromDB(uint32 lowguid);
- void LoadFromDB(QueryResult *achievementResult, QueryResult *criteriaResult);
+ void LoadFromDB(QueryResult_AutoPtr achievementResult, QueryResult_AutoPtr criteriaResult);
void SaveToDB();
void ResetAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0);
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0, Unit *unit=NULL, uint32 time=0);
diff --git a/src/game/AddonMgr.cpp b/src/game/AddonMgr.cpp
index 15d5633f2cb..9116f504a1d 100644
--- a/src/game/AddonMgr.cpp
+++ b/src/game/AddonMgr.cpp
@@ -42,7 +42,7 @@ AddonMgr::~AddonMgr()
void AddonMgr::LoadFromDB()
{
- QueryResult* result = CharacterDatabase.PQuery("SELECT name, crc FROM addons");
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name, crc FROM addons");
if(!result)
{
sLog.outErrorDb("The table `addons` is empty");
@@ -68,8 +68,6 @@ void AddonMgr::LoadFromDB()
m_knownAddons.push_back(addon);
} while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u known addons", count);
}
diff --git a/src/game/ArenaTeam.cpp b/src/game/ArenaTeam.cpp
index 1d9669007fc..320d8aa6b98 100644
--- a/src/game/ArenaTeam.cpp
+++ b/src/game/ArenaTeam.cpp
@@ -116,13 +116,12 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid)
else
{
// 0 1
- QueryResult *result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid));
if(!result)
return false;
plName = (*result)[0].GetCppString();
plClass = (*result)[1].GetUInt8();
- delete result;
// check if player already in arenateam of that size
if(Player::GetArenaTeamIdFromDB(PlayerGuid, GetType()) != 0)
@@ -175,7 +174,7 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid)
bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId);
if(!result)
return false;
@@ -192,8 +191,6 @@ bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId)
m_BorderStyle = fields[7].GetUInt32();
m_BorderColor = fields[8].GetUInt32();
- delete result;
-
// only load here, so additional checks can be made
LoadStatsFromDB(ArenaTeamId);
LoadMembersFromDB(ArenaTeamId);
@@ -215,7 +212,7 @@ bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId)
void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId)
{
// 0 1 2 3 4 5
- QueryResult *result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId);
if(!result)
return;
@@ -228,14 +225,12 @@ void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId)
m_stats.games_season = fields[3].GetUInt32();
m_stats.wins_season = fields[4].GetUInt32();
m_stats.rank = fields[5].GetUInt32();
-
- delete result;
}
void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId)
{
// 0 1 2 3 4 5 6 7
- QueryResult *result = CharacterDatabase.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
"FROM arena_team_member member "
"INNER JOIN characters chars on member.guid = chars.guid "
"WHERE member.arenateamid = '%u'", ArenaTeamId);
@@ -256,7 +251,6 @@ void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId)
newmember.Class = fields[7].GetUInt8();
m_members.push_back(newmember);
}while( result->NextRow() );
- delete result;
}
void ArenaTeam::SetCaptain(const uint64& guid)
diff --git a/src/game/AuctionHouseBot.cpp b/src/game/AuctionHouseBot.cpp
index 6b86f9de306..e7fc4cea8c3 100644
--- a/src/game/AuctionHouseBot.cpp
+++ b/src/game/AuctionHouseBot.cpp
@@ -485,19 +485,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
return;
}
- QueryResult* result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE itemowner<>%u AND buyguid<>%u", AHBplayerGUID, AHBplayerGUID);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE itemowner<>%u AND buyguid<>%u", AHBplayerGUID, AHBplayerGUID);
if (!result)
- {
- delete result;
return;
- }
if (result->GetRowCount() == 0)
- {
- delete result;
return;
- }
// Fetches content of selected AH
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
@@ -508,7 +502,6 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
uint32 tmpdata = result->Fetch()->GetUInt32();
possibleBids.push_back(tmpdata);
}while (result->NextRow());
- delete result;
for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count)
{
@@ -701,7 +694,7 @@ void AuctionHouseBot::Update()
WorldSession _session(AHBplayerAccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS);
Player _AHBplayer(&_session);
- _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID);
+ _AHBplayer.MinimalLoadFromDB(QueryResult_AutoPtr(NULL), AHBplayerGUID);
ObjectAccessor::Instance().AddObject(&_AHBplayer);
// Only for testing, this can likely be removed, once I know it's working as expected.
@@ -832,7 +825,7 @@ void AuctionHouseBot::Initialize()
if (AHBSeller)
{
- QueryResult* results = (QueryResult*) NULL;
+ QueryResult_AutoPtr results = QueryResult_AutoPtr(NULL);
char npcQuery[] = "SELECT distinct item FROM npc_vendor";
results = WorldDatabase.PQuery(npcQuery);
if (results != NULL)
@@ -843,8 +836,6 @@ void AuctionHouseBot::Initialize()
npcItems.push_back(fields[0].GetUInt32());
} while (results->NextRow());
-
- delete results;
}
else
{
@@ -872,8 +863,6 @@ void AuctionHouseBot::Initialize()
lootItems.push_back(fields[0].GetUInt32());
} while (results->NextRow());
-
- delete results;
}
else
{
diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp
index b2b5d250b28..f2531811205 100644
--- a/src/game/AuctionHouseMgr.cpp
+++ b/src/game/AuctionHouseMgr.cpp
@@ -267,7 +267,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry * auction)
void AuctionHouseMgr::LoadAuctionItems()
{
// data needs to be at first place for Item::LoadFromDB
- QueryResult *result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid");
if (!result)
{
@@ -310,7 +310,6 @@ void AuctionHouseMgr::LoadAuctionItems()
++count;
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString(">> Loaded %u auction items", count);
@@ -318,7 +317,7 @@ void AuctionHouseMgr::LoadAuctionItems()
void AuctionHouseMgr::LoadAuctions()
{
- QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse");
if (!result)
{
barGoLink bar(1);
@@ -330,7 +329,6 @@ void AuctionHouseMgr::LoadAuctions()
Field *fields = result->Fetch();
uint32 AuctionCount=fields[0].GetUInt32();
- delete result;
if (!AuctionCount)
{
@@ -415,7 +413,6 @@ void AuctionHouseMgr::LoadAuctions()
GetAuctionsMap(auctioneerInfo->faction_A)->AddAuction(aItem);
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString(">> Loaded %u auctions", AuctionCount);
@@ -506,19 +503,13 @@ void AuctionHouseObject::Update()
if (AuctionsMap.empty())
return;
- QueryResult* result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE time <= %u ORDER BY TIME ASC", (uint32)curTime+60);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE time <= %u ORDER BY TIME ASC", (uint32)curTime+60);
if (!result)
- {
- delete result;
return;
- }
if (result->GetRowCount() == 0)
- {
- delete result;
return;
- }
vector<uint32> expiredAuctions;
@@ -527,7 +518,6 @@ void AuctionHouseObject::Update()
uint32 tmpdata = result->Fetch()->GetUInt32();
expiredAuctions.push_back(tmpdata);
} while (result->NextRow());
- delete result;
while (!expiredAuctions.empty())
{
diff --git a/src/game/Bag.cpp b/src/game/Bag.cpp
index 37b276cf584..e71bfc02fd0 100644
--- a/src/game/Bag.cpp
+++ b/src/game/Bag.cpp
@@ -108,7 +108,7 @@ void Bag::SaveToDB()
Item::SaveToDB();
}
-bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
+bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result)
{
if(!Item::LoadFromDB(guid, owner_guid, result))
return false;
diff --git a/src/game/Bag.h b/src/game/Bag.h
index 5b36a291cd3..fc363abe538 100644
--- a/src/game/Bag.h
+++ b/src/game/Bag.h
@@ -55,7 +55,7 @@ class Bag : public Item
// overwrite virtual Item::SaveToDB
void SaveToDB();
// overwrite virtual Item::LoadFromDB
- bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result = NULL);
+ bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL));
// overwrite virtual Item::DeleteFromDB
void DeleteFromDB();
diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
index f6cf7fdddba..84ab2ba9222 100644
--- a/src/game/BattleGroundMgr.cpp
+++ b/src/game/BattleGroundMgr.cpp
@@ -1645,7 +1645,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8
- QueryResult *result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template");
if (!result)
{
@@ -1747,8 +1747,6 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u battlegrounds", count );
}
@@ -1758,7 +1756,7 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution()
if (sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS))
{
sLog.outDebug("Initializing Automatic Arena Point Distribution");
- QueryResult * result = CharacterDatabase.Query("SELECT NextArenaPointDistributionTime FROM saved_variables");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT NextArenaPointDistributionTime FROM saved_variables");
if (!result)
{
sLog.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now.");
@@ -1766,10 +1764,7 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution()
CharacterDatabase.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ('"UI64FMTD"')", m_NextAutoDistributionTime);
}
else
- {
m_NextAutoDistributionTime = time_t((*result)[0].GetUInt64());
- delete result;
- }
sLog.outDebug("Automatic Arena Point Distribution initialized.");
}
}
@@ -2054,7 +2049,7 @@ void BattleGroundMgr::LoadBattleMastersEntry()
{
mBattleMastersMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query( "SELECT entry,bg_template FROM battlemaster_entry" );
+ QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT entry,bg_template FROM battlemaster_entry" );
uint32 count = 0;
@@ -2089,8 +2084,6 @@ void BattleGroundMgr::LoadBattleMastersEntry()
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u battlemaster entries", count );
}
diff --git a/src/game/Channel.cpp b/src/game/Channel.cpp
index da125b6392b..3b32f29371c 100644
--- a/src/game/Channel.cpp
+++ b/src/game/Channel.cpp
@@ -53,7 +53,7 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team)
//load not built in channel if saved
std::string _name(name);
CharacterDatabase.escape_string(_name);
- QueryResult *result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team);
if (result)//load
{
Field *fields = result->Fetch();
@@ -64,8 +64,6 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team)
m_password = fields[4].GetString();
const char* db_BannedList = fields[5].GetString();
- delete result;
-
m_IsSaved = true;
if (db_BannedList)
diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
index 4ecde2bf5c8..1262550f808 100644
--- a/src/game/CharacterHandler.cpp
+++ b/src/game/CharacterHandler.cpp
@@ -106,17 +106,14 @@ class CharacterHandler
{
public:
- void HandleCharEnumCallback(QueryResult * result, uint32 account)
+ void HandleCharEnumCallback(QueryResult_AutoPtr result, uint32 account)
{
WorldSession * session = sWorld.FindSession(account);
if(!session)
- {
- delete result;
return;
- }
session->HandleCharEnum(result);
}
- void HandlePlayerLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder)
+ void HandlePlayerLoginCallback(QueryResult_AutoPtr /*dummy*/, SqlQueryHolder * holder)
{
if (!holder) return;
WorldSession *session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId());
@@ -129,7 +126,7 @@ class CharacterHandler
}
} chrHandler;
-void WorldSession::HandleCharEnum(QueryResult * result)
+void WorldSession::HandleCharEnum(QueryResult_AutoPtr result)
{
WorldPacket data(SMSG_CHAR_ENUM, 100); // we guess size
@@ -147,8 +144,6 @@ void WorldSession::HandleCharEnum(QueryResult * result)
++num;
}
while( result->NextRow() );
-
- delete result;
}
data.put<uint8>(0, num);
@@ -281,12 +276,11 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
return;
}
- QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
+ QueryResult_AutoPtr resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
if (resultacct)
{
Field *fields=resultacct->Fetch();
uint32 acctcharcount = fields[0].GetUInt32();
- delete resultacct;
if (acctcharcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT))
{
@@ -296,13 +290,12 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
}
}
- QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
uint8 charcount = 0;
if ( result )
{
Field *fields=result->Fetch();
charcount = fields[0].GetUInt8();
- delete result;
if (charcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_REALM))
{
@@ -340,7 +333,7 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
if(!AllowTwoSideAccounts || skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT)
{
- QueryResult *result2 = CharacterDatabase.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s",
+ QueryResult_AutoPtr result2 = CharacterDatabase.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s",
GetAccountId(), (skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT) ? "" : "LIMIT 1");
if(result2)
{
@@ -361,7 +354,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
{
data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
SendPacket( &data );
- delete result2;
return;
}
}
@@ -386,7 +378,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
{
data << (uint8)CHAR_CREATE_PVP_TEAMS_VIOLATION;
SendPacket( &data );
- delete result2;
return;
}
}
@@ -416,7 +407,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
{
data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
SendPacket( &data );
- delete result2;
return;
}
}
@@ -429,7 +419,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
}
}
}
- delete result2;
}
}
@@ -516,13 +505,12 @@ void WorldSession::HandleCharDeleteOpcode( WorldPacket & recv_data )
return;
}
- QueryResult *result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid));
if(result)
{
Field *fields = result->Fetch();
accountId = fields[0].GetUInt32();
name = fields[1].GetCppString();
- delete result;
}
// prevent deleting other players' characters using cheating tools
@@ -652,14 +640,13 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
}
//QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
- QueryResult *resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD);
+ QueryResult_AutoPtr resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD);
if(resultGuild)
{
Field *fields = resultGuild->Fetch();
pCurrChar->SetInGuild(fields[0].GetUInt32());
pCurrChar->SetRank(fields[1].GetUInt32());
- delete resultGuild;
}
else if(pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
{
@@ -977,14 +964,11 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
);
}
-void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname)
+void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string newname)
{
WorldSession * session = sWorld.FindSession(accountId);
if(!session)
- {
- if(result) delete result;
- return;
- }
+ return;
if (!result)
{
@@ -998,8 +982,6 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uin
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
std::string oldname = result->Fetch()[1].GetCppString();
- delete result;
-
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);
@@ -1187,7 +1169,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
uint8 gender, skin, face, hairStyle, hairColor, facialHair;
recv_data >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face;
- QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid));
if (!result)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
@@ -1198,7 +1180,6 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
Field *fields = result->Fetch();
uint32 at_loginFlags = fields[0].GetUInt32();
- delete result;
if (!(at_loginFlags & AT_LOGIN_CUSTOMIZE))
{
@@ -1248,12 +1229,11 @@ 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)))
+ if(QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid)))
{
std::string oldname = result->Fetch()[0].GetCppString();
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());
- delete result;
}
Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_CUSTOMIZE), GUID_LOPART(guid));
diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp
index a5cf781864e..f21e3b2511d 100644
--- a/src/game/Chat.cpp
+++ b/src/game/Chat.cpp
@@ -751,7 +751,7 @@ ChatCommand * ChatHandler::getCommandTable()
{
load_command_table = false;
- QueryResult *result = WorldDatabase.Query("SELECT name,security,help FROM command");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT name,security,help FROM command");
if (result)
{
do
@@ -762,7 +762,6 @@ ChatCommand * ChatHandler::getCommandTable()
SetDataForCommandInTable(commandTable, name.c_str(), fields[1].GetUInt16(), fields[2].GetCppString(), name);
} while(result->NextRow());
- delete result;
}
}
diff --git a/src/game/Chat.h b/src/game/Chat.h
index efde05f8c94..f4dba8b6596 100644
--- a/src/game/Chat.h
+++ b/src/game/Chat.h
@@ -605,8 +605,8 @@ class TRINITY_DLL_SPEC ChatHandler
GameObject* GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid,uint32 entry);
// Utility methods for commands
- bool LookupPlayerSearchCommand(QueryResult* result, int32 limit);
- bool HandleBanListHelper(QueryResult* result);
+ bool LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit);
+ bool HandleBanListHelper(QueryResult_AutoPtr result);
bool HandleBanHelper(BanMode mode,char const* args);
bool HandleBanInfoHelper(uint32 accountid, char const* accountname);
bool HandleUnBanHelper(BanMode mode,char const* args);
diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp
index d25862afd29..78c6885f5f2 100644
--- a/src/game/CreatureEventAIMgr.cpp
+++ b/src/game/CreatureEventAIMgr.cpp
@@ -39,7 +39,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
objmgr.LoadTrinityStrings(WorldDatabase,"creature_ai_texts",MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID);
// Gather Additional data from EventAI Texts
- QueryResult *result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
sLog.outString("Loading EventAI Texts additional data...");
if (result)
@@ -95,8 +95,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count);
}
@@ -118,7 +116,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons()
m_CreatureEventAI_Summon_Map.clear();
// Gather additional data for EventAI
- QueryResult *result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, spawntimesecs FROM creature_ai_summons");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, spawntimesecs FROM creature_ai_summons");
if (result)
{
barGoLink bar(result->GetRowCount());
@@ -149,8 +147,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons()
++Count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u CreatureEventAI summon definitions", Count);
}
@@ -171,7 +167,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
m_CreatureEventAI_Event_Map.clear();
// Gather event data
- QueryResult *result = WorldDatabase.Query("SELECT id, creature_id, event_type, event_inverse_phase_mask, event_chance, event_flags, "
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, creature_id, event_type, event_inverse_phase_mask, event_chance, event_flags, "
"event_param1, event_param2, event_param3, event_param4, "
"action1_type, action1_param1, action1_param2, action1_param3, "
"action2_type, action2_param1, action2_param2, action2_param3, "
@@ -729,8 +725,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u CreatureEventAI scripts", Count);
}
diff --git a/src/game/CreatureGroups.cpp b/src/game/CreatureGroups.cpp
index afaca9cf714..6b497129fe8 100644
--- a/src/game/CreatureGroups.cpp
+++ b/src/game/CreatureGroups.cpp
@@ -78,14 +78,13 @@ void CreatureGroupManager::LoadCreatureFormations()
CreatureGroupMap.clear();
//Check Integrity of the table
- QueryResult *result = WorldDatabase.PQuery("SELECT MAX(leaderGUID) FROM creature_formations");
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(leaderGUID) FROM creature_formations");
if(!result)
{
sLog.outErrorDb(" ...an error occured while loading the table creature_formations ( maybe it doesn't exist ?)\n");
return;
}
- delete result;
//Get group data
result = WorldDatabase.PQuery("SELECT leaderGUID, memberGUID, dist, angle, groupAI FROM creature_formations ORDER BY leaderGUID");
@@ -126,14 +125,13 @@ void CreatureGroupManager::LoadCreatureFormations()
// check data correctness
{
- QueryResult* result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", group_member->leaderGUID);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", group_member->leaderGUID);
if(!result)
{
sLog.outErrorDb("creature_formations table leader guid %u incorrect (not exist)", group_member->leaderGUID);
delete group_member;
continue;
}
- delete result;
result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", memberGUID);
if(!result)
@@ -142,7 +140,6 @@ void CreatureGroupManager::LoadCreatureFormations()
delete group_member;
continue;
}
- delete result;
}
CreatureGroupMap[memberGUID] = group_member;
@@ -152,8 +149,6 @@ void CreatureGroupManager::LoadCreatureFormations()
sLog.outString();
sLog.outString( ">> Loaded %u creatures in formations", total_records );
sLog.outString();
- //Free some heap
- delete result;
}
void CreatureGroup::AddMember(Creature *member)
diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp
index a884db5dc0f..04d0ea34842 100644
--- a/src/game/GameEventMgr.cpp
+++ b/src/game/GameEventMgr.cpp
@@ -194,7 +194,7 @@ void GameEventMgr::StopEvent( uint16 event_id, bool overwrite )
void GameEventMgr::LoadFromDB()
{
{
- QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event");
if (!result)
{
sLog.outString(">> Table game_event is empty.");
@@ -205,12 +205,11 @@ void GameEventMgr::LoadFromDB()
Field *fields = result->Fetch();
uint32 max_event_id = fields[0].GetUInt16();
- delete result;
mGameEvent.resize(max_event_id+1);
}
- QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event");
if (!result)
{
mGameEvent.clear();
@@ -267,7 +266,6 @@ void GameEventMgr::LoadFromDB()
pGameEvent.description = fields[6].GetCppString();
} while( result->NextRow() );
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u game events", count );
@@ -323,7 +321,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u game event saves in game events", count );
- delete result;
}
// load game event links (prerequisites)
@@ -378,7 +375,6 @@ void GameEventMgr::LoadFromDB()
} while (result->NextRow());
sLog.outString();
sLog.outString( ">> Loaded %u game event prerequisites in game events", count );
- delete result;
}
// Creatures
@@ -425,7 +421,6 @@ void GameEventMgr::LoadFromDB()
crelist.push_back(guid);
} while( result->NextRow() );
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u creatures in game events", count );
@@ -475,7 +470,6 @@ void GameEventMgr::LoadFromDB()
golist.push_back(guid);
} while( result->NextRow() );
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u gameobjects in game events", count );
@@ -539,7 +533,6 @@ void GameEventMgr::LoadFromDB()
equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet));
} while( result->NextRow() );
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u model/equipment changes in game events", count );
@@ -588,8 +581,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u quests additions in game events", count );
-
- delete result;
}
// GO Quests
@@ -633,7 +624,6 @@ void GameEventMgr::LoadFromDB()
questlist.push_back(QuestRelation(id, quest));
} while( result->NextRow() );
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u quests additions in game events", count );
@@ -682,8 +672,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u quest event conditions in game events", count );
-
- delete result;
}
// load conditions of the events
@@ -730,8 +718,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u conditions in game events", count );
-
- delete result;
}
// load condition saves
@@ -784,8 +770,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u condition saves in game events", count );
-
- delete result;
}
mGameEventNPCFlags.resize(mGameEvent.size());
@@ -831,8 +815,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u npcflags in game events", count );
-
- delete result;
}
// Vendor
@@ -902,8 +884,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u vendor additions in game events", count );
-
- delete result;
}
// load game event npc gossip ids
@@ -948,8 +928,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u npc gossip textids in game events", count );
-
- delete result;
}
// set all flags to 0
@@ -995,8 +973,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u battleground holidays in game events", count );
-
- delete result;
}
////////////////////////
@@ -1054,7 +1030,6 @@ void GameEventMgr::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u pools in game events", count );
- delete result;
}
}
diff --git a/src/game/GlobalEvents.cpp b/src/game/GlobalEvents.cpp
index 458933244dd..defdd96f1f9 100644
--- a/src/game/GlobalEvents.cpp
+++ b/src/game/GlobalEvents.cpp
@@ -32,7 +32,7 @@
#include "ObjectDefines.h"
#include "Corpse.h"
-static void CorpsesEraseCallBack(QueryResult *result, bool bones)
+static void CorpsesEraseCallBack(QueryResult_AutoPtr result, bool bones)
{
if(!result)
return;
@@ -68,8 +68,6 @@ static void CorpsesEraseCallBack(QueryResult *result, bool bones)
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
} while (result->NextRow());
-
- delete result;
}
/// Handle periodic erase of corpses and bones
diff --git a/src/game/Group.cpp b/src/game/Group.cpp
index c0bfc7ef182..a4ebf7bfc27 100644
--- a/src/game/Group.cpp
+++ b/src/game/Group.cpp
@@ -125,7 +125,7 @@ bool Group::Create(const uint64 &guid, const char * name)
return true;
}
-bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool loadMembers)
+bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult_AutoPtr result, bool loadMembers)
{
if(isBGGroup())
return false;
@@ -144,10 +144,7 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool
// group leader not exist
if(!objmgr.GetPlayerNameByGUID(m_leaderGuid, m_leaderName))
- {
- if(!external) delete result;
return false;
- }
m_groupType = (*result)[13].GetBool() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL;
@@ -172,7 +169,6 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool
for (int i=0; i<TARGETICONCOUNT; ++i)
m_targetIcons[i] = (*result)[5+i].GetUInt64();
- if(!external) delete result;
if(loadMembers)
{
@@ -184,7 +180,6 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool
{
LoadMemberFromDB((*result)[0].GetUInt32(), (*result)[2].GetUInt8(), (*result)[1].GetBool());
} while( result->NextRow() );
- delete result;
// group too small
if(GetMembersCount() < 2)
return false;
diff --git a/src/game/Group.h b/src/game/Group.h
index 8c5aceb3a01..61d31ce969a 100644
--- a/src/game/Group.h
+++ b/src/game/Group.h
@@ -166,7 +166,7 @@ class TRINITY_DLL_SPEC Group
// group manipulation methods
bool Create(const uint64 &guid, const char * name);
- bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result = NULL, bool loadMembers = true);
+ bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL), bool loadMembers = true);
bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant);
bool AddInvite(Player *player);
uint32 RemoveInvite(Player *player);
diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp
index 66dba877ca0..8f547d46b70 100644
--- a/src/game/Guild.cpp
+++ b/src/game/Guild.cpp
@@ -147,7 +147,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank)
}
else
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT name,zone,level,class FROM characters WHERE guid = '%u'", GUID_LOPART(plGuid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name,zone,level,class FROM characters WHERE guid = '%u'", GUID_LOPART(plGuid));
if (!result)
return false; // player doesn't exist
@@ -156,7 +156,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank)
newmember.ZoneId = fields[1].GetUInt32();
newmember.Level = fields[2].GetUInt8();
newmember.Class = fields[3].GetUInt8();
- delete result;
+
if (newmember.Level < 1 || newmember.Level > STRONG_MAX_LEVEL ||
newmember.Class < CLASS_WARRIOR || newmember.Class >= MAX_CLASSES)
{
@@ -215,14 +215,13 @@ bool Guild::LoadGuildFromDB(uint32 GuildId)
//set m_Id in case guild data are broken in DB and Guild will be Disbanded (deleted from DB)
m_Id = GuildId;
- QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(TabId) FROM guild_bank_tab WHERE guildid='%u'", GuildId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(TabId) FROM guild_bank_tab WHERE guildid='%u'", GuildId);
if (result)
{
Field *fields = result->Fetch();
m_PurchasedTabs = fields[0].GetUInt32();
if (m_PurchasedTabs > GUILD_BANK_MAX_TABS)
m_PurchasedTabs = GUILD_BANK_MAX_TABS;
- delete result;
}
if (!LoadRanksFromDB(GuildId))
@@ -256,8 +255,6 @@ bool Guild::LoadGuildFromDB(uint32 GuildId)
time_t time = fields[9].GetUInt64();
m_GuildBankMoney = fields[10].GetUInt64();
- delete result;
-
if (time > 0)
{
tm local = *(localtime(&time)); // dereference and assign
@@ -295,7 +292,7 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
{
Field *fields;
// 0 1 2 3
- QueryResult *result = CharacterDatabase.PQuery("SELECT rid,rname,rights,BankMoneyPerDay FROM guild_rank WHERE guildid = '%u' ORDER BY rid ASC", GuildId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT rid,rname,rights,BankMoneyPerDay FROM guild_rank WHERE guildid = '%u' ORDER BY rid ASC", GuildId);
if (!result)
{
@@ -329,7 +326,6 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
AddRank(rankName,rankRights,rankMoney);
}while (result->NextRow());
- delete result;
if (m_Ranks.size() < GUILD_RANKS_MIN_COUNT) // if too few ranks, renew them
{
@@ -360,7 +356,7 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
bool Guild::LoadMembersFromDB(uint32 GuildId)
{
// 0 1 2 3 4 5
- QueryResult *result = CharacterDatabase.PQuery("SELECT guild_member.guid,rank, pnote, offnote, BankResetTimeMoney,BankRemMoney,"
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guild_member.guid,rank, pnote, offnote, BankResetTimeMoney,BankRemMoney,"
// 6 7 8 9 10 11
"BankResetTimeTab0, BankRemSlotsTab0, BankResetTimeTab1, BankRemSlotsTab1, BankResetTimeTab2, BankRemSlotsTab2,"
// 12 13 14 15 16 17
@@ -422,7 +418,6 @@ bool Guild::LoadMembersFromDB(uint32 GuildId)
members[GUID_LOPART(guid)] = newmember;
}while (result->NextRow());
- delete result;
if (members.empty())
return false;
@@ -879,7 +874,7 @@ void Guild::LoadGuildEventLogFromDB()
return;
// 0 1 2 3 4 5
- QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid1, PlayerGuid2, NewRank, TimeStamp FROM guild_eventlog WHERE guildid=%u ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_EVENTLOG_MAX_RECORDS);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid1, PlayerGuid2, NewRank, TimeStamp FROM guild_eventlog WHERE guildid=%u ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_EVENTLOG_MAX_RECORDS);
if (!result)
return;
bool isNextLogGuidSet = false;
@@ -909,7 +904,6 @@ void Guild::LoadGuildEventLogFromDB()
m_GuildEventLog.push_front(NewEvent);
} while (result->NextRow());
- delete result;
m_EventLogLoaded = true;
}
@@ -1161,7 +1155,7 @@ void Guild::LoadGuildBankFromDB()
LoadGuildBankEventLogFromDB();
// 0 1 2 3
- QueryResult *result = CharacterDatabase.PQuery("SELECT TabId, TabName, TabIcon, TabText FROM guild_bank_tab WHERE guildid='%u' ORDER BY TabId", m_Id);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT TabId, TabName, TabIcon, TabText FROM guild_bank_tab WHERE guildid='%u' ORDER BY TabId", m_Id);
if (!result)
{
m_PurchasedTabs = 0;
@@ -1184,8 +1178,6 @@ void Guild::LoadGuildBankFromDB()
m_TabListMap[TabId] = NewTab;
}while (result->NextRow());
- delete result;
-
// data needs to be at first place for Item::LoadFromDB
// 0 1 2 3 4
result = CharacterDatabase.PQuery("SELECT data, TabId, SlotId, item_guid, item_entry FROM guild_bank_item JOIN item_instance ON item_guid = guid WHERE guildid='%u' ORDER BY TabId", m_Id);
@@ -1232,8 +1224,6 @@ void Guild::LoadGuildBankFromDB()
pItem->AddToWorld();
m_TabListMap[TabId]->Slots[SlotId] = pItem;
}while (result->NextRow());
-
- delete result;
}
// This unload should be called when the last member of the guild gets offline
@@ -1452,7 +1442,7 @@ uint32 Guild::GetBankSlotPerDay(uint32 rankId, uint8 TabId)
void Guild::LoadBankRightsFromDB(uint32 GuildId)
{
// 0 1 2 3
- QueryResult *result = CharacterDatabase.PQuery("SELECT TabId, rid, gbright, SlotPerDay FROM guild_bank_right WHERE guildid = '%u' ORDER BY TabId", GuildId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT TabId, rid, gbright, SlotPerDay FROM guild_bank_right WHERE guildid = '%u' ORDER BY TabId", GuildId);
if (!result)
return;
@@ -1468,7 +1458,6 @@ void Guild::LoadBankRightsFromDB(uint32 GuildId)
SetBankRightsAndSlots(rankId, TabId, right, SlotPerDay, false);
}while (result->NextRow());
- delete result;
return;
}
@@ -1485,7 +1474,7 @@ void Guild::LoadGuildBankEventLogFromDB()
for (uint32 tabId = 0; tabId < m_PurchasedTabs; tabId++)
{
// 0 1 2 3 4 5 6
- QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, tabId, GUILD_BANK_MAX_LOGS);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, tabId, GUILD_BANK_MAX_LOGS);
if (!result)
continue;
@@ -1522,12 +1511,11 @@ void Guild::LoadGuildBankEventLogFromDB()
isNextLogGuidSet = true;
}
} while (result->NextRow());
- delete result;
}
//special handle for guild bank money log
// 0 1 2 3 4 5 6
- QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_BANK_MONEY_LOGS_TAB, GUILD_BANK_MAX_LOGS);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_BANK_MONEY_LOGS_TAB, GUILD_BANK_MAX_LOGS);
if (!result)
return;
@@ -1559,7 +1547,6 @@ void Guild::LoadGuildBankEventLogFromDB()
m_GuildBankEventLog_Money.push_front(NewEvent);
} while (result->NextRow());
- delete result;
}
void Guild::UnloadGuildBankEventLog()
diff --git a/src/game/InstanceSaveMgr.cpp b/src/game/InstanceSaveMgr.cpp
index 0141396b39a..9e8cd3eb694 100644
--- a/src/game/InstanceSaveMgr.cpp
+++ b/src/game/InstanceSaveMgr.cpp
@@ -238,7 +238,7 @@ void InstanceSaveManager::_DelHelper(DatabaseType &db, const char *fields, const
int res = vsnprintf( szQueryTail, MAX_QUERY_LEN, queryTail, ap );
va_end(ap);
- QueryResult *result = db.PQuery("SELECT %s FROM %s %s", fields, table, szQueryTail);
+ QueryResult_AutoPtr result = db.PQuery("SELECT %s FROM %s %s", fields, table, szQueryTail);
if(result)
{
do
@@ -253,7 +253,6 @@ void InstanceSaveManager::_DelHelper(DatabaseType &db, const char *fields, const
}
db.DirectPExecute("DELETE FROM %s WHERE %s", table, ss.str().c_str());
} while (result->NextRow());
- delete result;
}
}
@@ -281,7 +280,7 @@ void InstanceSaveManager::CleanupInstances()
// creature_respawn and gameobject_respawn are in another database
// first, obtain total instance set
std::set<uint32> InstanceSet;
- QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id FROM instance");
if (result)
{
do
@@ -290,7 +289,6 @@ void InstanceSaveManager::CleanupInstances()
InstanceSet.insert(fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
// creature_respawn
@@ -304,7 +302,6 @@ void InstanceSaveManager::CleanupInstances()
WorldDatabase.DirectPExecute("DELETE FROM creature_respawn WHERE instance = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
// gameobject_respawn
@@ -318,7 +315,6 @@ void InstanceSaveManager::CleanupInstances()
WorldDatabase.DirectPExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
// characters
@@ -332,7 +328,6 @@ void InstanceSaveManager::CleanupInstances()
CharacterDatabase.PExecute("UPDATE characters SET instance_id = '0' WHERE instance_id = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
// corpse
@@ -346,7 +341,6 @@ void InstanceSaveManager::CleanupInstances()
CharacterDatabase.PExecute("UPDATE corpse SET instance = '0' WHERE instance = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
bar.step();
@@ -365,7 +359,7 @@ void InstanceSaveManager::PackInstances()
// all valid ids are in the instance table
// any associations to ids not in this table are assumed to be
// cleaned already in CleanupInstances
- QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id FROM instance");
if (result)
{
do
@@ -374,7 +368,6 @@ void InstanceSaveManager::PackInstances()
InstanceSet.insert(fields[0].GetUInt32());
}
while (result->NextRow());
- delete result;
}
barGoLink bar(InstanceSet.size() + 1);
@@ -422,7 +415,7 @@ void InstanceSaveManager::LoadResetTimes()
typedef std::multimap<uint32 /*PAIR32(map,difficulty)*/, uint32 /*instanceid*/ > ResetTimeMapDiffInstances;
ResetTimeMapDiffInstances mapDiffResetInstances;
- QueryResult *result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance WHERE resettime > 0");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance WHERE resettime > 0");
if( result )
{
do
@@ -437,7 +430,6 @@ void InstanceSaveManager::LoadResetTimes()
}
}
while (result->NextRow());
- delete result;
// update reset time for normal instances with the max creature respawn time + X hours
result = WorldDatabase.Query("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance");
@@ -456,7 +448,6 @@ void InstanceSaveManager::LoadResetTimes()
}
}
while (result->NextRow());
- delete result;
}
// schedule the reset times
@@ -492,7 +483,6 @@ void InstanceSaveManager::LoadResetTimes()
SetResetTimeFor(mapid,difficulty,newresettime);
} while(result->NextRow());
- delete result;
}
// clean expired instances, references to them will be deleted in CleanupInstances
diff --git a/src/game/Item.cpp b/src/game/Item.cpp
index 7d6e1cd3021..1a32bfd4107 100644
--- a/src/game/Item.cpp
+++ b/src/game/Item.cpp
@@ -339,18 +339,14 @@ void Item::SaveToDB()
SetState(ITEM_UNCHANGED);
}
-bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
+bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result)
{
// create item before any checks for store correct guid
// and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB
Object::_Create(guid, 0, HIGHGUID_ITEM);
- bool delete_result = false;
if(!result)
- {
result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid);
- delete_result = true;
- }
if (!result)
{
@@ -363,7 +359,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
if(!LoadValues(fields[0].GetString()))
{
sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.",guid);
- if (delete_result) delete result;
return false;
}
@@ -377,8 +372,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
need_save = true;
}
- if (delete_result) delete result;
-
ItemPrototype const* proto = GetProto();
if(!proto)
return false;
diff --git a/src/game/Item.h b/src/game/Item.h
index 3dcdcab95a8..bf893fcd3c3 100644
--- a/src/game/Item.h
+++ b/src/game/Item.h
@@ -240,7 +240,7 @@ class TRINITY_DLL_SPEC Item : public Object
bool IsBindedNotWith(Player const* player) const;
bool IsBoundByEnchant() const;
virtual void SaveToDB();
- virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result = NULL);
+ virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL));
virtual void DeleteFromDB();
void DeleteFromInventoryDB();
diff --git a/src/game/ItemEnchantmentMgr.cpp b/src/game/ItemEnchantmentMgr.cpp
index 790eb1699c3..e1d6135d6b0 100644
--- a/src/game/ItemEnchantmentMgr.cpp
+++ b/src/game/ItemEnchantmentMgr.cpp
@@ -55,7 +55,7 @@ void LoadRandomEnchantmentsTable()
float chance;
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template");
if (result)
{
@@ -76,8 +76,6 @@ void LoadRandomEnchantmentsTable()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u Item Enchantment definitions", count );
}
diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp
index 8d22191b25e..16fe0f48fd5 100644
--- a/src/game/Level2.cpp
+++ b/src/game/Level2.cpp
@@ -336,7 +336,7 @@ bool ChatHandler::HandleGoCreatureCommand(const char* args)
}
//sLog.outError("DEBUG: %s", whereClause.c_str());
- QueryResult *result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause.str().c_str() );
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause.str().c_str() );
if (!result)
{
SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
@@ -353,8 +353,6 @@ bool ChatHandler::HandleGoCreatureCommand(const char* args)
float ort = fields[3].GetFloat();
int mapid = fields[4].GetUInt16();
- delete result;
-
if(!MapManager::IsValidMapCoord(mapid,x,y,z,ort))
{
PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
@@ -436,7 +434,7 @@ bool ChatHandler::HandleGoObjectCommand(const char* args)
bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
{
Player* pl = m_session->GetPlayer();
- QueryResult *result;
+ QueryResult_AutoPtr result;
GameEventMgr::ActiveEvents const& activeEventsList = gameeventmgr.GetActiveEventList();
if(*args)
{
@@ -515,8 +513,6 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
found = true;
} while( result->NextRow() && (!found) );
- delete result;
-
if (!found)
{
PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
@@ -837,7 +833,7 @@ bool ChatHandler::HandleGameObjectNearCommand(const char* args)
uint32 count = 0;
Player* pl = m_session->GetPlayer();
- QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
"(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
"FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
@@ -864,8 +860,6 @@ bool ChatHandler::HandleGameObjectNearCommand(const char* args)
++count;
} while (result->NextRow());
-
- delete result;
}
PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
@@ -2170,7 +2164,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
return false;
// 0 1 2 3 4 5
- QueryResult *result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(target_guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(target_guid));
if (!result)
return false;
@@ -2181,7 +2175,6 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
accId = fields[3].GetUInt32();
race = fields[4].GetUInt8();
Class = fields[5].GetUInt8();
- delete result;
}
std::string username = GetTrinityString(LANG_ERROR);
@@ -2190,7 +2183,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
uint32 security = 0;
std::string last_login = GetTrinityString(LANG_ERROR);
- QueryResult* result = loginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
"FROM account a "
"LEFT JOIN account_access aa "
"ON (a.id = aa.id) "
@@ -2215,8 +2208,6 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
last_ip = "-";
last_login = "-";
}
-
- delete result;
}
std::string nameLink = playerLink(target_name);
@@ -2303,7 +2294,7 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
pathid = target->GetWaypointPath();
else
{
- QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(id) FROM waypoint_data");
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(id) FROM waypoint_data");
uint32 maxpathid = result->Fetch()->GetInt32();
pathid = maxpathid+1;
sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
@@ -2325,13 +2316,10 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
sLog.outDebug("DEBUG: HandleWpAddCommand - point == 0");
- QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid);
if( result )
- {
point = (*result)[0].GetUInt32();
- delete result;
- }
Player* player = m_session->GetPlayer();
Map *map = player->GetMap();
@@ -2385,13 +2373,10 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
}
guidlow = target->GetDBTableGUIDLow();
- QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow);
if( result )
- {
WorldDatabase.PExecute("UPDATE creature_addon SET path_id = '%u' WHERE guid = '%u'", pathid, guidlow);
- delete result;
- }
else
WorldDatabase.PExecute("INSERT INTO creature_addon(guid,path_id) VALUES ('%u','%u')", guidlow, pathid);
@@ -2471,7 +2456,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
if(id)
{
- QueryResult *result = WorldDatabase.PQuery( "SELECT id FROM waypoint_scripts WHERE guid = %u", id);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id FROM waypoint_scripts WHERE guid = %u", id);
if( !result )
{
@@ -2479,14 +2464,11 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id);
}
else
- {
PSendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r", id);
- delete result;
- }
}
else
{
- QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(guid) FROM waypoint_scripts");
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(guid) FROM waypoint_scripts");
id = result->Fetch()->GetUInt32();
WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id+1);
PSendSysMessage("%s%s%u|r", "|cff00ff00","Wp Event: New waypoint event added: |r|cff00ffff", id+1);
@@ -2509,7 +2491,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
float a8, a9, a10, a11;
char const* a7;
- QueryResult *result = WorldDatabase.PQuery( "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id);
if( !result )
{
@@ -2536,21 +2518,18 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
PSendSysMessage("|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
}
while(result->NextRow());
-
- delete result;
}
if(show == "del")
{
id = atoi(arg_id);
- QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
if( result )
{
WorldDatabase.PExecuteLog("DELETE FROM waypoint_scripts WHERE guid = %u", id);
PSendSysMessage("%s%s%u|r","|cff00ff00","Wp Event: Waypoint script removed: ", id);
- delete result;
}
else
PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: %u|r", id);
@@ -2613,7 +2592,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
}
else
{
- QueryResult *result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'",id);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'",id);
if(!result)
{
@@ -2621,8 +2600,6 @@ bool ChatHandler::HandleWpEventCommand(const char* args)
return true;
}
- delete result;
-
if(arg_str_2 == "posx")
{
coord = atof(arg_3);
@@ -2734,8 +2711,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
// Check the creature
if (wpCreature->GetEntry() == VISUAL_WAYPOINT )
{
- QueryResult *result =
- WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
if(!result)
{
@@ -2767,9 +2743,6 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
}
while( result->NextRow() );
- // Cleanup memory
- sLog.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
- delete result;
// We have the waypoint number and the GUID of the "master npc"
// Text is enclosed in "<>", all other arguments not
arg_str = strtok((char*)NULL, " ");
@@ -2939,7 +2912,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
return false;
}
- QueryResult *result = WorldDatabase.PQuery( "SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow());
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow());
if(!result)
{
@@ -2966,14 +2939,12 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
}
while( result->NextRow() );
- // Cleanup memory
- delete result;
return true;
}
if(show == "on")
{
- QueryResult *result = WorldDatabase.PQuery( "SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid);
if(!result)
{
@@ -2985,7 +2956,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
// Delete all visuals for this NPC
- QueryResult *result2 = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid);
+ QueryResult_AutoPtr result2 = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid);
if(result2)
{
@@ -3012,8 +2983,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
}
while( result2->NextRow() );
- delete result2;
-
if( hasError )
{
PSendSysMessage(LANG_WAYPOINT_TOOFAR1);
@@ -3041,7 +3010,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
- delete result;
return false;
}
@@ -3064,8 +3032,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
while( result->NextRow() );
SendSysMessage("|cff00ff00Showing the current creature's path.|r");
- // Cleanup memory
- delete result;
return true;
}
@@ -3073,7 +3039,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
{
PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
- QueryResult *result = WorldDatabase.PQuery( "SELECT position_x,position_y,position_z FROM waypoint_data WHERE point='1' AND id = '%u'",pathid);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT position_x,position_y,position_z FROM waypoint_data WHERE point='1' AND id = '%u'",pathid);
if(!result)
{
PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
@@ -3096,7 +3062,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete pCreature;
- delete result;
return false;
}
@@ -3110,8 +3075,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5);
}
- // Cleanup memory
- delete result;
return true;
}
@@ -3119,13 +3082,9 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
{
PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
- QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid);
if( result )
- {
Maxpoint = (*result)[0].GetUInt32();
-
- delete result;
- }
else
Maxpoint = 0;
@@ -3151,7 +3110,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
{
PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id);
delete pCreature;
- delete result;
return false;
}
@@ -3165,14 +3123,12 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5);
}
- // Cleanup memory
- delete result;
return true;
}
if(show == "off")
{
- QueryResult *result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1);
if(!result)
{
SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND);
@@ -3211,8 +3167,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
}
SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED);
- // Cleanup memory
- delete result;
return true;
}
@@ -3759,7 +3713,7 @@ bool ChatHandler::HandleLookupPlayerIpCommand(const char* args)
loginDatabase.escape_string (ip);
- QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
+ QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
return LookupPlayerSearchCommand (result,limit);
}
@@ -3778,7 +3732,7 @@ bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args)
loginDatabase.escape_string (account);
- QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
+ QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
return LookupPlayerSearchCommand (result,limit);
}
@@ -3795,12 +3749,12 @@ bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args)
loginDatabase.escape_string (email);
- QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
+ QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
return LookupPlayerSearchCommand (result,limit);
}
-bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit)
+bool ChatHandler::LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit)
{
if(!result)
{
@@ -3816,7 +3770,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit)
uint32 acc_id = fields[0].GetUInt32();
std::string acc_name = fields[1].GetCppString();
- QueryResult* chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id);
+ QueryResult_AutoPtr chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id);
if(chars)
{
PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT,acc_name.c_str(),acc_id);
@@ -3834,13 +3788,9 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit)
++i;
} while( chars->NextRow() && ( limit == -1 || i < limit ) );
-
- delete chars;
}
} while(result->NextRow());
- delete result;
-
if(i==0) // empty accounts only
{
PSendSysMessage(LANG_NO_PLAYERS_FOUND);
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index 2a01fbb2a2c..9af7c517321 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -1457,10 +1457,9 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args)
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
if (gmRealmID == -1)
{
- QueryResult *result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
if (result)
{
- delete result;
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
SetSentErrorMessage(true);
return false;
@@ -2620,7 +2619,7 @@ bool ChatHandler::HandleAddItemCommand(const char *args)
{
std::string itemName = citemName+1;
WorldDatabase.escape_string(itemName);
- QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
if (!result)
{
PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
@@ -2628,7 +2627,6 @@ bool ChatHandler::HandleAddItemCommand(const char *args)
return false;
}
itemId = result->Fetch()->GetUInt16();
- delete result;
}
else
return false;
@@ -2811,16 +2809,13 @@ bool ChatHandler::HandleListItemCommand(const char *args)
if(count < 0)
return false;
- QueryResult *result;
+ QueryResult_AutoPtr result;
// inventory case
uint32 inv_count = 0;
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
if(result)
- {
inv_count = (*result)[0].GetUInt32();
- delete result;
- }
result=CharacterDatabase.PQuery(
// 0 1 2 3 4 5
@@ -2857,8 +2852,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
int64 res_count = result->GetRowCount();
- delete result;
-
if(count > res_count)
count-=res_count;
else if(count)
@@ -2869,10 +2862,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
uint32 mail_count = 0;
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
if(result)
- {
mail_count = (*result)[0].GetUInt32();
- delete result;
- }
if(count > 0)
{
@@ -2884,7 +2874,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
item_id,uint32(count));
}
else
- result = NULL;
+ result = QueryResult_AutoPtr(NULL);
if(result)
{
@@ -2907,8 +2897,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
int64 res_count = result->GetRowCount();
- delete result;
-
if(count > res_count)
count-=res_count;
else if(count)
@@ -2919,10 +2907,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
uint32 auc_count = 0;
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
if(result)
- {
auc_count = (*result)[0].GetUInt32();
- delete result;
- }
if(count > 0)
{
@@ -2933,7 +2918,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
item_id,uint32(count));
}
else
- result = NULL;
+ result = QueryResult_AutoPtr(NULL);
if(result)
{
@@ -2949,18 +2934,13 @@ bool ChatHandler::HandleListItemCommand(const char *args)
PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
} while (result->NextRow());
-
- delete result;
}
// guild bank case
uint32 guild_count = 0;
result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
if(result)
- {
guild_count = (*result)[0].GetUInt32();
- delete result;
- }
result=CharacterDatabase.PQuery(
// 0 1 2
@@ -2984,8 +2964,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
int64 res_count = result->GetRowCount();
- delete result;
-
if(count > res_count)
count-=res_count;
else if(count)
@@ -3036,15 +3014,12 @@ bool ChatHandler::HandleListObjectCommand(const char *args)
if(count < 0)
return false;
- QueryResult *result;
+ QueryResult_AutoPtr result;
uint32 obj_count = 0;
result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
if(result)
- {
obj_count = (*result)[0].GetUInt32();
- delete result;
- }
if(m_session)
{
@@ -3072,8 +3047,6 @@ bool ChatHandler::HandleListObjectCommand(const char *args)
else
PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
} while (result->NextRow());
-
- delete result;
}
PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
@@ -3171,15 +3144,12 @@ bool ChatHandler::HandleListCreatureCommand(const char *args)
if(count < 0)
return false;
- QueryResult *result;
+ QueryResult_AutoPtr result;
uint32 cr_count = 0;
result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
if(result)
- {
cr_count = (*result)[0].GetUInt32();
- delete result;
- }
if(m_session)
{
@@ -3207,8 +3177,6 @@ bool ChatHandler::HandleListCreatureCommand(const char *args)
else
PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
} while (result->NextRow());
-
- delete result;
}
PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
@@ -5932,7 +5900,7 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args)
bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
{
- QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
if(!result)
{
PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
@@ -5954,7 +5922,6 @@ bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
}while (result->NextRow());
- delete result;
return true;
}
@@ -5973,7 +5940,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
std::string IP = cIP;
loginDatabase.escape_string(IP);
- QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
if(!result)
{
PSendSysMessage(LANG_BANINFO_NOIP);
@@ -5985,7 +5952,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
PSendSysMessage(LANG_BANINFO_IPENTRY,
fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(),
permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
- delete result;
+
return true;
}
@@ -5999,7 +5966,7 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args)
std::string filter = cFilter;
loginDatabase.escape_string(filter);
- QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
if (!result)
{
PSendSysMessage(LANG_BANLIST_NOCHARACTER);
@@ -6017,7 +5984,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args)
std::string filter = cFilter ? cFilter : "";
loginDatabase.escape_string(filter);
- QueryResult* result;
+ QueryResult_AutoPtr result;
if(filter.empty())
{
@@ -6040,7 +6007,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args)
return HandleBanListHelper(result);
}
-bool ChatHandler::HandleBanListHelper(QueryResult* result)
+bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result)
{
PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
@@ -6052,12 +6019,11 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
Field* fields = result->Fetch();
uint32 accountid = fields[0].GetUInt32();
- QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
+ QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
if(banresult)
{
Field* fields2 = banresult->Fetch();
PSendSysMessage("%s",fields2[0].GetString());
- delete banresult;
}
} while (result->NextRow());
}
@@ -6083,7 +6049,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
accmgr.GetName (account_id,account_name);
// No SQL injection. id is uint32.
- QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
+ QueryResult_AutoPtr banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
if (banInfo)
{
Field *fields2 = banInfo->Fetch();
@@ -6108,13 +6074,10 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
fields2[2].GetString(),fields2[3].GetString());
}
}while ( banInfo->NextRow() );
- delete banInfo;
}
}while( result->NextRow() );
SendSysMessage("===============================================================================");
}
-
- delete result;
return true;
}
@@ -6126,7 +6089,7 @@ bool ChatHandler::HandleBanListIPCommand(const char *args)
std::string filter = cFilter ? cFilter : "";
loginDatabase.escape_string(filter);
- QueryResult* result;
+ QueryResult_AutoPtr result;
if(filter.empty())
{
@@ -6188,7 +6151,6 @@ bool ChatHandler::HandleBanListIPCommand(const char *args)
SendSysMessage("===============================================================================");
}
- delete result;
return true;
}
@@ -6892,7 +6854,7 @@ bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
{
///- Get the accounts with GM Level >0
- QueryResult *result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
+ QueryResult_AutoPtr result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
if(result)
{
SendSysMessage(LANG_GMLIST);
@@ -6908,7 +6870,6 @@ bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
}while( result->NextRow() );
PSendSysMessage("========================");
- delete result;
}
else
PSendSysMessage(LANG_GMLIST_EMPTY);
@@ -7396,7 +7357,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
if (TargetName)
{
//check for offline players
- QueryResult *result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str());
if (!result)
{
SendSysMessage(LANG_COMMAND_FREEZE_WRONG);
@@ -7405,7 +7366,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
//if player found: delete his freeze aura
Field *fields=result->Fetch();
uint64 pguid = fields[0].GetUInt64();
- delete result;
+
CharacterDatabase.PQuery("DELETE FROM character_aura WHERE character_aura.spell = 9454 AND character_aura.guid = '%u'",pguid);
PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str());
return true;
@@ -7423,7 +7384,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
bool ChatHandler::HandleListFreezeCommand(const char *args)
{
//Get names from DB
- QueryResult *result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454");
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454");
if (!result)
{
SendSysMessage(LANG_COMMAND_NO_FROZEN_PLAYERS);
@@ -7440,7 +7401,6 @@ bool ChatHandler::HandleListFreezeCommand(const char *args)
PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str());
} while (result->NextRow());
- delete result;
return true;
}
diff --git a/src/game/LootMgr.cpp b/src/game/LootMgr.cpp
index 7288b1f0f27..502b552fbf8 100644
--- a/src/game/LootMgr.cpp
+++ b/src/game/LootMgr.cpp
@@ -100,7 +100,7 @@ void LootStore::LoadLootTable()
sLog.outString( "%s :", GetName());
// 0 1 2 3 4 5 6 7 8 9
- QueryResult *result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount, lootcondition, condition_value1, condition_value2 FROM %s",GetName());
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount, lootcondition, condition_value1, condition_value2 FROM %s",GetName());
if (result)
{
@@ -163,8 +163,6 @@ void LootStore::LoadLootTable()
} while (result->NextRow());
- delete result;
-
Verify(); // Checks validity of the loot store
sLog.outString();
diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp
index 44513c671a5..12425866090 100644
--- a/src/game/Mail.cpp
+++ b/src/game/Mail.cpp
@@ -135,11 +135,10 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data )
else
{
rc_team = objmgr.GetPlayerTeamByGUID(rc);
- if (QueryResult* result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM mail WHERE receiver = '%u'", GUID_LOPART(rc)))
+ if (QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM mail WHERE receiver = '%u'", GUID_LOPART(rc)))
{
Field *fields = result->Fetch();
mails_count = fields[0].GetUInt32();
- delete result;
}
}
//do not allow to have more than 100 mails in mailbox.. mails count is in opcode uint8!!! - so max can be 255..
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 8308a892233..0a6498e5c58 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -2761,7 +2761,7 @@ void InstanceMap::CreateInstanceData(bool load)
if (load)
{
// TODO: make a global storage for this
- QueryResult* result = CharacterDatabase.PQuery("SELECT data FROM instance WHERE map = '%u' AND id = '%u'", GetId(), i_InstanceId);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data FROM instance WHERE map = '%u' AND id = '%u'", GetId(), i_InstanceId);
if (result)
{
Field* fields = result->Fetch();
@@ -2771,7 +2771,6 @@ void InstanceMap::CreateInstanceData(bool load)
sLog.outDebug("Loading instance data for `%s` with id %u", objmgr.GetScriptName(i_script_id), i_InstanceId);
i_data->Load(data);
}
- delete result;
}
}
}
diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp
index b57f9b8d2c1..efc59aadbd1 100644
--- a/src/game/MapManager.cpp
+++ b/src/game/MapManager.cpp
@@ -358,12 +358,9 @@ void MapManager::InitMaxInstanceId()
{
i_MaxInstanceId = 0;
- QueryResult *result = CharacterDatabase.Query("SELECT MAX(id) FROM instance");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM instance");
if (result)
- {
i_MaxInstanceId = result->Fetch()[0].GetUInt32();
- delete result;
- }
}
uint32 MapManager::GetNumInstances()
diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp
index bb52ac3b52e..e1cf4165005 100644
--- a/src/game/MiscHandler.cpp
+++ b/src/game/MiscHandler.cpp
@@ -537,7 +537,7 @@ void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race, account FROM characters WHERE name = '%s'", friendName.c_str());
}
-void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
+void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string friendNote)
{
uint64 friendGuid;
uint64 friendAcctid;
@@ -558,8 +558,6 @@ void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 acc
team = Player::TeamForRace((*result)[1].GetUInt8());
friendAcctid = (*result)[2].GetUInt32();
- delete result;
-
if ( session->GetSecurity() >= SEC_MODERATOR || sWorld.getConfig(CONFIG_ALLOW_GM_FRIEND) || accmgr.GetSecurity(friendAcctid) < SEC_MODERATOR)
{
if(friendGuid)
@@ -627,7 +625,7 @@ void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
}
-void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
+void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId)
{
uint64 IgnoreGuid;
FriendsResult ignoreResult;
@@ -644,8 +642,6 @@ void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 acc
{
IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
- delete result;
-
if(IgnoreGuid)
{
if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself
@@ -1306,7 +1302,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
uint32 accid = plr->GetSession()->GetAccountId();
- QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
if(!result)
{
SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
@@ -1330,8 +1326,6 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
data << msg;
_player->GetSession()->SendPacket(&data);
- delete result;
-
sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
}
diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp
index f145456f2e4..9e674e74706 100644
--- a/src/game/NPCHandler.cpp
+++ b/src/game/NPCHandler.cpp
@@ -522,7 +522,7 @@ void WorldSession::SendStablePet(uint64 guid )
}
// 0 1 2 3 4
- QueryResult* result = CharacterDatabase.PQuery("SELECT owner, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot",
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot",
_player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT);
if(result)
@@ -539,8 +539,6 @@ void WorldSession::SendStablePet(uint64 guid )
++num;
}while( result->NextRow() );
-
- delete result;
}
data.put<uint8>(wpos, num); // set real data to placeholder
@@ -581,7 +579,7 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
uint32 free_slot = 1;
- QueryResult *result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ",
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ",
_player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT);
if(result)
{
@@ -598,8 +596,6 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
// this slot not free, skip
++free_slot;
}while( result->NextRow() );
-
- delete result;
}
WorldPacket data(SMSG_STABLE_RESULT, 1);
@@ -636,13 +632,12 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
uint32 creature_id = 0;
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot >='%u' AND slot <= '%u'",
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot >='%u' AND slot <= '%u'",
_player->GetGUIDLow(),petnumber,PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT);
if(result)
{
Field *fields = result->Fetch();
creature_id = fields[0].GetUInt32();
- delete result;
}
}
@@ -762,7 +757,7 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
return;
// find swapped pet slot in stable
- QueryResult *result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",
_player->GetGUIDLow(),pet_number);
if(!result)
return;
@@ -771,7 +766,6 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
uint32 slot = fields[0].GetUInt32();
uint32 creature_id = fields[1].GetUInt32();
- delete result;
if(!creature_id)
{
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 7c2c2e6a658..e91aefe4b31 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -319,7 +319,7 @@ void ObjectMgr::LoadCreatureLocales()
{
mCreatureLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature");
if(!result)
return;
@@ -364,8 +364,6 @@ void ObjectMgr::LoadCreatureLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu creature locale strings", (unsigned long)mCreatureLocaleMap.size() );
}
@@ -374,7 +372,7 @@ void ObjectMgr::LoadNpcOptionLocales()
{
mGossipMenuItemsLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT menu_id,id,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT menu_id,id,"
"option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2,"
"option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4,"
"option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6,"
@@ -425,8 +423,6 @@ void ObjectMgr::LoadNpcOptionLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu gossip_menu_option locale strings", (unsigned long)mGossipMenuItemsLocaleMap.size() );
}
@@ -435,7 +431,7 @@ void ObjectMgr::LoadPointOfInterestLocales()
{
mPointOfInterestLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,icon_name_loc1,icon_name_loc2,icon_name_loc3,icon_name_loc4,icon_name_loc5,icon_name_loc6,icon_name_loc7,icon_name_loc8 FROM locales_points_of_interest");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,icon_name_loc1,icon_name_loc2,icon_name_loc3,icon_name_loc4,icon_name_loc5,icon_name_loc6,icon_name_loc7,icon_name_loc8 FROM locales_points_of_interest");
if(!result)
return;
@@ -468,8 +464,6 @@ void ObjectMgr::LoadPointOfInterestLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu points_of_interest locale strings", (unsigned long)mPointOfInterestLocaleMap.size() );
}
@@ -1122,7 +1116,7 @@ bool ObjectMgr::CheckCreatureLinkedRespawn(uint32 guid, uint32 linkedGuid) const
void ObjectMgr::LoadCreatureLinkedRespawn()
{
mCreatureLinkedRespawnMap.clear();
- QueryResult *result = WorldDatabase.Query("SELECT guid, linkedGuid FROM creature_linked_respawn ORDER BY guid ASC");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid, linkedGuid FROM creature_linked_respawn ORDER BY guid ASC");
if(!result)
{
@@ -1150,8 +1144,6 @@ void ObjectMgr::LoadCreatureLinkedRespawn()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u linked respawns", mCreatureLinkedRespawnMap.size() );
}
@@ -1181,7 +1173,7 @@ void ObjectMgr::LoadCreatures()
{
uint32 count = 0;
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
// 4 5 6 7 8 9 10 11
"equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
// 12 13 14 15 16 17 18 19
@@ -1357,8 +1349,6 @@ void ObjectMgr::LoadCreatures()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu creatures", (unsigned long)mCreatureDataMap.size() );
}
@@ -1537,7 +1527,7 @@ void ObjectMgr::LoadGameobjects()
uint32 count = 0;
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
// 7 8 9 10 11 12 13 14 15 16 17
"rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
"FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
@@ -1674,8 +1664,6 @@ void ObjectMgr::LoadGameobjects()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu gameobjects", (unsigned long)mGameObjectDataMap.size());
}
@@ -1716,7 +1704,7 @@ void ObjectMgr::LoadCreatureRespawnTimes()
{
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM creature_respawn");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM creature_respawn");
if (!result)
{
@@ -1745,8 +1733,6 @@ void ObjectMgr::LoadCreatureRespawnTimes()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu creature respawn times", (unsigned long)mCreatureRespawnTimes.size() );
}
@@ -1758,7 +1744,7 @@ void ObjectMgr::LoadGameobjectRespawnTimes()
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM gameobject_respawn");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM gameobject_respawn");
if(!result)
{
@@ -1787,8 +1773,6 @@ void ObjectMgr::LoadGameobjectRespawnTimes()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString( ">> Loaded %lu gameobject respawn times", (unsigned long)mGORespawnTimes.size() );
sLog.outString();
}
@@ -1801,14 +1785,10 @@ uint64 ObjectMgr::GetPlayerGUIDByName(std::string name) const
CharacterDatabase.escape_string(name);
// Player name safe to sending to DB (checked at login) and this function using
- QueryResult *result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE name = '%s'", name.c_str());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE name = '%s'", name.c_str());
if(result)
- {
guid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
- delete result;
- }
-
return guid;
}
@@ -1821,12 +1801,11 @@ bool ObjectMgr::GetPlayerNameByGUID(const uint64 &guid, std::string &name) const
return true;
}
- QueryResult *result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
if(result)
{
name = (*result)[0].GetCppString();
- delete result;
return true;
}
@@ -1841,12 +1820,11 @@ uint32 ObjectMgr::GetPlayerTeamByGUID(const uint64 &guid) const
return Player::TeamForRace(player->getRace());
}
- QueryResult *result = CharacterDatabase.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
if(result)
{
uint8 race = (*result)[0].GetUInt8();
- delete result;
return Player::TeamForRace(race);
}
@@ -1861,11 +1839,10 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(const uint64 &guid) const
return player->GetSession()->GetAccountId();
}
- QueryResult *result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
if(result)
{
uint32 acc = (*result)[0].GetUInt32();
- delete result;
return acc;
}
@@ -1874,11 +1851,10 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(const uint64 &guid) const
uint32 ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string& name) const
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", name.c_str());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", name.c_str());
if(result)
{
uint32 acc = (*result)[0].GetUInt32();
- delete result;
return acc;
}
@@ -1889,7 +1865,7 @@ void ObjectMgr::LoadItemLocales()
{
mItemLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item");
if(!result)
return;
@@ -1935,8 +1911,6 @@ void ObjectMgr::LoadItemLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu Item locale strings", (unsigned long)mItemLocaleMap.size() );
}
@@ -2359,7 +2333,7 @@ void ObjectMgr::LoadItemRequiredTarget()
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM item_required_target");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM item_required_target");
if (!result)
{
@@ -2450,8 +2424,6 @@ void ObjectMgr::LoadItemRequiredTarget()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u Item required targets", count);
}
@@ -2461,7 +2433,7 @@ void ObjectMgr::LoadPetLevelInfo()
// Loading levels data
{
// 0 1 2 3 4 5 6 7 8 9
- QueryResult *result = WorldDatabase.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats");
uint32 count = 0;
@@ -2528,8 +2500,6 @@ void ObjectMgr::LoadPetLevelInfo()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u level pet stats definitions", count );
}
@@ -2575,7 +2545,7 @@ void ObjectMgr::LoadPlayerInfo()
// Load playercreate
{
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo");
uint32 count = 0;
@@ -2657,8 +2627,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u player create definitions", count );
}
@@ -2667,7 +2635,7 @@ void ObjectMgr::LoadPlayerInfo()
sLog.outString("Loading Player Create Items Data...");
{
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item");
uint32 count = 0;
@@ -2727,8 +2695,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u custom player create items", count );
}
@@ -2738,7 +2704,7 @@ void ObjectMgr::LoadPlayerInfo()
sLog.outString("Loading Player Create Spell Data...");
{
- QueryResult *result = NULL;
+ QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL);
if(sWorld.getConfig(CONFIG_START_ALL_SPELLS))
result = WorldDatabase.Query("SELECT race, class, Spell, Active FROM playercreateinfo_spell_custom");
else
@@ -2794,8 +2760,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u player create spells", count );
}
@@ -2805,7 +2769,7 @@ void ObjectMgr::LoadPlayerInfo()
sLog.outString("Loading Player Create Action Data...");
{
// 0 1 2 3 4
- QueryResult *result = WorldDatabase.Query("SELECT race, class, button, action, type FROM playercreateinfo_action");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, button, action, type FROM playercreateinfo_action");
uint32 count = 0;
@@ -2847,8 +2811,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u player create actions", count );
}
@@ -2858,7 +2820,7 @@ void ObjectMgr::LoadPlayerInfo()
sLog.outString("Loading Player Create Level HP/Mana Data...");
{
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats");
uint32 count = 0;
@@ -2913,8 +2875,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u level health/mana definitions", count );
}
@@ -2950,7 +2910,7 @@ void ObjectMgr::LoadPlayerInfo()
sLog.outString("Loading Player Create Level Stats Data...");
{
// 0 1 2 3 4 5 6 7
- QueryResult *result = WorldDatabase.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats");
uint32 count = 0;
@@ -3014,8 +2974,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u level stats definitions", count );
}
@@ -3074,7 +3032,7 @@ void ObjectMgr::LoadPlayerInfo()
mPlayerXPperLevel[level] = 0;
// 0 1
- QueryResult *result = WorldDatabase.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level");
uint32 count = 0;
@@ -3115,8 +3073,6 @@ void ObjectMgr::LoadPlayerInfo()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u xp for level definitions", count );
}
@@ -3241,7 +3197,7 @@ void ObjectMgr::LoadGuilds()
Guild *newguild;
uint32 count = 0;
- QueryResult *result = CharacterDatabase.Query( "SELECT guildid FROM guild" );
+ QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT guildid FROM guild" );
if (!result)
{
@@ -3275,8 +3231,6 @@ void ObjectMgr::LoadGuilds()
}while (result->NextRow());
- delete result;
-
//delete unused LogGuid records in guild_eventlog and guild_bank_eventlog table
//you can comment these lines if you don't plan to change CONFIG_GUILD_EVENT_LOG_COUNT and CONFIG_GUILD_BANK_EVENT_LOG_COUNT
CharacterDatabase.PQuery("DELETE FROM guild_eventlog WHERE LogGuid > '%u'", sWorld.getConfig(CONFIG_GUILD_EVENT_LOG_COUNT));
@@ -3290,7 +3244,7 @@ void ObjectMgr::LoadArenaTeams()
{
uint32 count = 0;
- QueryResult *result = CharacterDatabase.Query( "SELECT arenateamid FROM arena_team" );
+ QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT arenateamid FROM arena_team" );
if( !result )
{
@@ -3322,8 +3276,6 @@ void ObjectMgr::LoadArenaTeams()
AddArenaTeam(newarenateam);
}while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u arenateam definitions", count );
}
@@ -3335,7 +3287,7 @@ void ObjectMgr::LoadGroups()
uint64 leaderGuid = 0;
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
- QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
if( !result )
{
@@ -3367,8 +3319,6 @@ void ObjectMgr::LoadGroups()
AddGroup(group);
}while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u group definitions", count );
@@ -3409,7 +3359,6 @@ void ObjectMgr::LoadGroups()
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields[0].GetUInt32());
}
}while( result->NextRow() );
- delete result;
}
// clean groups
@@ -3479,7 +3428,6 @@ void ObjectMgr::LoadGroups()
InstanceSave *save = sInstanceSaveManager.AddInstanceSave(mapEntry->MapID, fields[2].GetUInt32(), Difficulty(diff), (time_t)fields[5].GetUInt64(), (fields[6].GetUInt32() == 0), true);
group->BindToInstance(save, fields[3].GetBool(), true);
}while( result->NextRow() );
- delete result;
}
sLog.outString();
@@ -3499,7 +3447,7 @@ void ObjectMgr::LoadQuests()
mExclusiveQuestGroups.clear();
// 0 1 2 3 4 5 6 7 8
- QueryResult *result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
// 9 10 11 12 13 14 15 16 17 18
"RepObjectiveFaction, RepObjectiveValue, RepObjectiveFaction2, RepObjectiveValue2, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime,"
// 19 20 21 22 23 24 25 26 27 28 29 30
@@ -3557,8 +3505,6 @@ void ObjectMgr::LoadQuests()
mQuestTemplates[newQuest->GetQuestId()] = newQuest;
} while( result->NextRow() );
- delete result;
-
std::map<uint32,uint32> usedMailTemplates;
// Post processing
@@ -4173,7 +4119,7 @@ void ObjectMgr::LoadQuestLocales()
{
mQuestLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,"
"Title_loc1,Details_loc1,Objectives_loc1,OfferRewardText_loc1,RequestItemsText_loc1,EndText_loc1,ObjectiveText1_loc1,ObjectiveText2_loc1,ObjectiveText3_loc1,ObjectiveText4_loc1,"
"Title_loc2,Details_loc2,Objectives_loc2,OfferRewardText_loc2,RequestItemsText_loc2,EndText_loc2,ObjectiveText1_loc2,ObjectiveText2_loc2,ObjectiveText3_loc2,ObjectiveText4_loc2,"
"Title_loc3,Details_loc3,Objectives_loc3,OfferRewardText_loc3,RequestItemsText_loc3,EndText_loc3,ObjectiveText1_loc3,ObjectiveText2_loc3,ObjectiveText3_loc3,ObjectiveText4_loc3,"
@@ -4291,8 +4237,6 @@ void ObjectMgr::LoadQuestLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap.size() );
}
@@ -4306,7 +4250,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
scripts.clear(); // need for reload support
- QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename );
+ QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename );
uint32 count = 0;
@@ -4555,8 +4499,6 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
++count;
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u script definitions", count );
}
@@ -4694,10 +4636,9 @@ void ObjectMgr::LoadWaypointScripts()
for (ScriptMapMap::const_iterator itr = sWaypointScripts.begin(); itr != sWaypointScripts.end(); ++itr)
{
- QueryResult *query = WorldDatabase.PQuery("SELECT * FROM waypoint_scripts WHERE id = %u", itr->first);
+ QueryResult_AutoPtr query = WorldDatabase.PQuery("SELECT * FROM waypoint_scripts WHERE id = %u", itr->first);
if(!query || !query->GetRowCount())
sLog.outErrorDb("There is no waypoint which links to the waypoint script %u", itr->first);
- delete query;
}
}
@@ -4710,7 +4651,7 @@ void ObjectMgr::LoadGossipScripts()
void ObjectMgr::LoadItemTexts()
{
- QueryResult *result = CharacterDatabase.Query("SELECT id, text FROM item_text");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id, text FROM item_text");
uint32 count = 0;
@@ -4739,8 +4680,6 @@ void ObjectMgr::LoadItemTexts()
} while ( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u item texts", count );
}
@@ -4793,7 +4732,7 @@ void ObjectMgr::LoadPageTextLocales()
{
mPageTextLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text");
if(!result)
return;
@@ -4827,8 +4766,6 @@ void ObjectMgr::LoadPageTextLocales()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu PageText locale strings", (unsigned long)mPageTextLocaleMap.size() );
}
@@ -4877,7 +4814,7 @@ GossipText const *ObjectMgr::GetGossipText(uint32 Text_ID) const
void ObjectMgr::LoadGossipText()
{
- QueryResult *result = WorldDatabase.Query( "SELECT * FROM npc_text" );
+ QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT * FROM npc_text" );
int count = 0;
if( !result )
@@ -4930,14 +4867,13 @@ void ObjectMgr::LoadGossipText()
sLog.outString();
sLog.outString( ">> Loaded %u npc texts", count );
- delete result;
}
void ObjectMgr::LoadNpcTextLocales()
{
mNpcTextLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,"
"Text0_0_loc1,Text0_1_loc1,Text1_0_loc1,Text1_1_loc1,Text2_0_loc1,Text2_1_loc1,Text3_0_loc1,Text3_1_loc1,Text4_0_loc1,Text4_1_loc1,Text5_0_loc1,Text5_1_loc1,Text6_0_loc1,Text6_1_loc1,Text7_0_loc1,Text7_1_loc1,"
"Text0_0_loc2,Text0_1_loc2,Text1_0_loc2,Text1_1_loc2,Text2_0_loc2,Text2_1_loc2,Text3_0_loc2,Text3_1_loc1,Text4_0_loc2,Text4_1_loc2,Text5_0_loc2,Text5_1_loc2,Text6_0_loc2,Text6_1_loc2,Text7_0_loc2,Text7_1_loc2,"
"Text0_0_loc3,Text0_1_loc3,Text1_0_loc3,Text1_1_loc3,Text2_0_loc3,Text2_1_loc3,Text3_0_loc3,Text3_1_loc1,Text4_0_loc3,Text4_1_loc3,Text5_0_loc3,Text5_1_loc3,Text6_0_loc3,Text6_1_loc3,Text7_0_loc3,Text7_1_loc3,"
@@ -4994,8 +4930,6 @@ void ObjectMgr::LoadNpcTextLocales()
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu NpcText locale strings", (unsigned long)mNpcTextLocaleMap.size() );
}
@@ -5009,7 +4943,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
if (!serverUp)
CharacterDatabase.PExecute("DELETE FROM mail WHERE expire_time < '" UI64FMTD "' AND has_items = '0' AND itemTextId = 0", (uint64)basetime);
// 0 1 2 3 4 5 6 7 8 9
- QueryResult* result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,itemTextId,has_items,expire_time,cod,checked,mailTemplateId FROM mail WHERE expire_time < '" UI64FMTD "'", (uint64)basetime);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,itemTextId,has_items,expire_time,cod,checked,mailTemplateId FROM mail WHERE expire_time < '" UI64FMTD "'", (uint64)basetime);
if ( !result )
{
barGoLink bar(1);
@@ -5058,7 +4992,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
//delete or return mail:
if (has_items)
{
- QueryResult *resultItems = CharacterDatabase.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m->messageID);
+ QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m->messageID);
if(resultItems)
{
do
@@ -5071,8 +5005,6 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
m->AddItem(item_guid_low, item_template);
}
while (resultItems->NextRow());
-
- delete resultItems;
}
//if it is mail from AH, it shouldn't be returned, but deleted
if (m->messageType != MAIL_NORMAL || (m->checked & (MAIL_CHECK_MASK_AUCTION | MAIL_CHECK_MASK_COD_PAYMENT | MAIL_CHECK_MASK_RETURNED)))
@@ -5099,7 +5031,6 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
delete m;
++count;
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u mails", count );
@@ -5109,7 +5040,7 @@ void ObjectMgr::LoadQuestAreaTriggers()
{
mQuestAreaTriggerMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query( "SELECT id,quest FROM areatrigger_involvedrelation" );
+ QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT id,quest FROM areatrigger_involvedrelation" );
uint32 count = 0;
@@ -5164,8 +5095,6 @@ void ObjectMgr::LoadQuestAreaTriggers()
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u quest trigger points", count );
}
@@ -5174,7 +5103,7 @@ void ObjectMgr::LoadTavernAreaTriggers()
{
mTavernAreaTriggerSet.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT id FROM areatrigger_tavern");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id FROM areatrigger_tavern");
uint32 count = 0;
@@ -5209,8 +5138,6 @@ void ObjectMgr::LoadTavernAreaTriggers()
mTavernAreaTriggerSet.insert(Trigger_ID);
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u tavern triggers", count );
}
@@ -5218,7 +5145,7 @@ void ObjectMgr::LoadTavernAreaTriggers()
void ObjectMgr::LoadAreaTriggerScripts()
{
mAreaTriggerScripts.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts");
uint32 count = 0;
@@ -5253,8 +5180,6 @@ void ObjectMgr::LoadAreaTriggerScripts()
mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName);
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u areatrigger scripts", count );
}
@@ -5407,7 +5332,7 @@ void ObjectMgr::LoadGraveyardZones()
{
mGraveYardMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone");
uint32 count = 0;
@@ -5464,8 +5389,6 @@ void ObjectMgr::LoadGraveyardZones()
sLog.outErrorDb("Table `game_graveyard_zone` has a duplicate record for Graveyard (ID: %u) and Zone (ID: %u), skipped.",safeLocId,zoneId);
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u graveyard-zone links", count );
}
@@ -5676,7 +5599,7 @@ void ObjectMgr::LoadAreaTriggerTeleports()
uint32 count = 0;
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT id, access_id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, access_id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport");
if( !result )
{
@@ -5734,8 +5657,6 @@ void ObjectMgr::LoadAreaTriggerTeleports()
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u area trigger teleport definitions", count );
}
@@ -5747,7 +5668,7 @@ void ObjectMgr::LoadAccessRequirements()
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9 10 11
- QueryResult *result = WorldDatabase.Query("SELECT id, level_min, level_max, item, item2, heroic_key, heroic_key2, quest_done, quest_failed_text, heroic_quest_done, heroic_quest_failed_text, heroic_level_min FROM access_requirement");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, level_min, level_max, item, item2, heroic_key, heroic_key2, quest_done, quest_failed_text, heroic_quest_done, heroic_quest_failed_text, heroic_level_min FROM access_requirement");
if( !result )
{
@@ -5850,8 +5771,6 @@ void ObjectMgr::LoadAccessRequirements()
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u access requirement definitions", count );
}
@@ -5894,26 +5813,17 @@ AreaTrigger const* ObjectMgr::GetMapEntranceTrigger(uint32 Map) const
void ObjectMgr::SetHighestGuids()
{
- QueryResult *result = CharacterDatabase.Query( "SELECT MAX(guid) FROM characters" );
+ QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT MAX(guid) FROM characters" );
if( result )
- {
m_hiCharGuid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = WorldDatabase.Query( "SELECT MAX(guid) FROM creature" );
if( result )
- {
m_hiCreatureGuid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" );
if( result )
- {
m_hiItemGuid = (*result)[0].GetUInt32()+1;
- delete result;
- }
// Cleanup other tables from not existed guids (>=m_hiItemGuid)
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid);
@@ -5923,59 +5833,35 @@ void ObjectMgr::SetHighestGuids()
result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject" );
if( result )
- {
m_hiGoGuid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse" );
if( result )
- {
m_auctionid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" );
if( result )
- {
m_mailid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" );
if( result )
- {
m_ItemTextId = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" );
if( result )
- {
m_hiCorpseGuid = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team");
if (result)
- {
m_arenaTeamId = (*result)[0].GetUInt32()+1;
- delete result;
- }
result = CharacterDatabase.Query("SELECT MAX(setguid) FROM character_equipmentsets");
if (result)
- {
m_equipmentSetGuid = (*result)[0].GetUInt64()+1;
- delete result;
- }
result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" );
if (result)
- {
m_guildId = (*result)[0].GetUInt32()+1;
- delete result;
- }
}
uint32 ObjectMgr::GenerateArenaTeamId()
@@ -6124,7 +6010,7 @@ void ObjectMgr::LoadGameObjectLocales()
{
mGameObjectLocaleMap.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT entry,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,"
"name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8,"
"castbarcaption_loc1,castbarcaption_loc2,castbarcaption_loc3,castbarcaption_loc4,"
"castbarcaption_loc5,castbarcaption_loc6,castbarcaption_loc7,castbarcaption_loc8 FROM locales_gameobject");
@@ -6177,8 +6063,6 @@ void ObjectMgr::LoadGameObjectLocales()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %lu gameobject locale strings", (unsigned long)mGameObjectLocaleMap.size() );
}
@@ -6422,7 +6306,7 @@ void ObjectMgr::LoadGameobjectInfo()
void ObjectMgr::LoadExplorationBaseXP()
{
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT level,basexp FROM exploration_basexp");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level,basexp FROM exploration_basexp");
if (!result)
{
@@ -6449,8 +6333,6 @@ void ObjectMgr::LoadExplorationBaseXP()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u BaseXP definitions", count );
}
@@ -6470,7 +6352,7 @@ uint32 ObjectMgr::GetXPForLevel(uint8 level)
void ObjectMgr::LoadPetNames()
{
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT word,entry,half FROM pet_name_generation");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT word,entry,half FROM pet_name_generation");
if (!result)
{
@@ -6500,7 +6382,6 @@ void ObjectMgr::LoadPetNames()
++count;
}
while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u pet name parts", count );
@@ -6508,12 +6389,11 @@ void ObjectMgr::LoadPetNames()
void ObjectMgr::LoadPetNumber()
{
- QueryResult* result = CharacterDatabase.Query("SELECT MAX(id) FROM character_pet");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM character_pet");
if (result)
{
Field *fields = result->Fetch();
m_hiPetNumber = fields[0].GetUInt32()+1;
- delete result;
}
barGoLink bar(1);
@@ -6549,7 +6429,7 @@ void ObjectMgr::LoadCorpses()
{
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 10
- QueryResult *result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0");
if(!result)
{
@@ -6584,7 +6464,6 @@ void ObjectMgr::LoadCorpses()
++count;
}
while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString(">> Loaded %u corpses", count);
@@ -6595,7 +6474,7 @@ void ObjectMgr::LoadReputationOnKill()
uint32 count = 0;
// 0 1 2
- QueryResult *result = WorldDatabase.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2,"
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2,"
// 3 4 5 6 7 8 9
"IsTeamAward1, MaxStanding1, RewOnKillRepValue1, IsTeamAward2, MaxStanding2, RewOnKillRepValue2, TeamDependent "
"FROM creature_onkill_reputation");
@@ -6662,8 +6541,6 @@ void ObjectMgr::LoadReputationOnKill()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u creature award reputation definitions", count);
}
@@ -6673,7 +6550,7 @@ void ObjectMgr::LoadPointsOfInterest()
uint32 count = 0;
// 0 1 2 3 4 5 6
- QueryResult *result = WorldDatabase.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest");
if(!result)
{
@@ -6714,8 +6591,6 @@ void ObjectMgr::LoadPointsOfInterest()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u Points of Interest definitions", count);
}
@@ -6726,7 +6601,7 @@ void ObjectMgr::LoadNPCSpellClickSpells()
mSpellClickInfoMap.clear();
// 0 1 2 3 4 5 6 7 8
- QueryResult *result = WorldDatabase.Query("SELECT npc_entry, spell_id, quest_start, quest_start_active, quest_end, cast_flags, aura_required, aura_forbidden, user_type FROM npc_spellclick_spells");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT npc_entry, spell_id, quest_start, quest_start_active, quest_end, cast_flags, aura_required, aura_forbidden, user_type FROM npc_spellclick_spells");
if(!result)
{
@@ -6834,8 +6709,6 @@ void ObjectMgr::LoadNPCSpellClickSpells()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u spellclick definitions", count);
}
@@ -6845,7 +6718,7 @@ void ObjectMgr::LoadWeatherZoneChances()
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9 10 11 12
- QueryResult *result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance FROM game_weather");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance FROM game_weather");
if(!result)
{
@@ -6897,8 +6770,6 @@ void ObjectMgr::LoadWeatherZoneChances()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u weather definitions", count);
}
@@ -6985,7 +6856,7 @@ void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table)
uint32 count = 0;
- QueryResult *result = WorldDatabase.PQuery("SELECT id,quest FROM %s",table);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id,quest FROM %s",table);
if (!result)
{
@@ -7019,8 +6890,6 @@ void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table)
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u quest relations from %s", count,table);
}
@@ -7085,7 +6954,7 @@ void ObjectMgr::LoadReservedPlayersNames()
{
m_ReservedNames.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT name FROM reserved_name");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT name FROM reserved_name");
uint32 count = 0;
@@ -7121,8 +6990,6 @@ void ObjectMgr::LoadReservedPlayersNames()
++count;
} while ( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u reserved player names", count );
}
@@ -7395,7 +7262,7 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi
++itr;
}
- QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table);
+ QueryResult_AutoPtr result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table);
if (!result)
{
@@ -7465,8 +7332,6 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi
}
} while (result->NextRow());
- delete result;
-
sLog.outString();
if (min_value == MIN_TRINITY_STRING_ID)
sLog.outString( ">> Loaded %u Trinity strings from table %s", count,table);
@@ -7500,7 +7365,7 @@ void ObjectMgr::LoadSpellDisabledEntrys()
m_DisabledPlayerSpells.clear(); // need for reload case
m_DisabledCreatureSpells.clear();
m_DisabledPetSpells.clear();
- QueryResult *result = WorldDatabase.Query("SELECT entry, disable_mask FROM spell_disabled");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, disable_mask FROM spell_disabled");
uint32 total_count = 0;
@@ -7537,8 +7402,6 @@ void ObjectMgr::LoadSpellDisabledEntrys()
++total_count;
} while ( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u disabled spells from `spell_disabled`", total_count);
}
@@ -7548,7 +7411,7 @@ void ObjectMgr::LoadFishingBaseSkillLevel()
mFishingBaseForArea.clear(); // for reload case
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT entry,skill FROM skill_fishing_base_level");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,skill FROM skill_fishing_base_level");
if( !result )
{
@@ -7583,8 +7446,6 @@ void ObjectMgr::LoadFishingBaseSkillLevel()
}
while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u areas for fishing base skill level", count );
}
@@ -7875,7 +7736,7 @@ void ObjectMgr::LoadGameTele()
m_GameTeleMap.clear(); // for reload case
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele");
if( !result )
{
@@ -7926,7 +7787,6 @@ void ObjectMgr::LoadGameTele()
++count;
}
while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u GameTeleports", count );
@@ -8005,7 +7865,7 @@ void ObjectMgr::LoadMailLevelRewards()
m_mailLevelRewardMap.clear(); // for reload case
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward");
if( !result )
{
@@ -8060,7 +7920,6 @@ void ObjectMgr::LoadMailLevelRewards()
++count;
}
while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u level dependent mail rewards,", count );
@@ -8075,7 +7934,7 @@ void ObjectMgr::LoadTrainerSpell()
std::set<uint32> skip_trainers;
- QueryResult *result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
if( !result )
{
@@ -8174,7 +8033,6 @@ void ObjectMgr::LoadTrainerSpell()
++count;
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %d Trainers", count );
@@ -8189,7 +8047,7 @@ void ObjectMgr::LoadVendors()
std::set<uint32> skip_vendors;
- QueryResult *result = WorldDatabase.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor");
if( !result )
{
barGoLink bar( 1 );
@@ -8224,7 +8082,6 @@ void ObjectMgr::LoadVendors()
++count;
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %d Vendors ", count );
@@ -8235,7 +8092,7 @@ void ObjectMgr::LoadNpcTextId()
m_mCacheNpcTextIdMap.clear();
- QueryResult* result = WorldDatabase.Query("SELECT npc_guid, textid FROM npc_gossip");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT npc_guid, textid FROM npc_gossip");
if( !result )
{
barGoLink bar( 1 );
@@ -8275,7 +8132,6 @@ void ObjectMgr::LoadNpcTextId()
++count;
} while (result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %d NpcTextId ", count );
@@ -8285,7 +8141,7 @@ void ObjectMgr::LoadGossipMenu()
{
m_mGossipMenusMap.clear();
- QueryResult* result = WorldDatabase.Query("SELECT entry, text_id, "
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, text_id, "
"cond_1, cond_1_val_1, cond_1_val_2, cond_2, cond_2_val_1, cond_2_val_2 FROM gossip_menu");
if(!result)
@@ -8348,8 +8204,6 @@ void ObjectMgr::LoadGossipMenu()
}
while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u gossip_menu entries", count);
}
@@ -8358,7 +8212,7 @@ void ObjectMgr::LoadGossipMenuItems()
{
m_mGossipMenuItemsMap.clear();
- QueryResult *result = WorldDatabase.Query(
+ QueryResult_AutoPtr result = WorldDatabase.Query(
"SELECT menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, "
"action_menu_id, action_poi_id, action_script_id, box_coded, box_money, box_text, "
"cond_1, cond_1_val_1, cond_1_val_2, "
@@ -8476,8 +8330,6 @@ void ObjectMgr::LoadGossipMenuItems()
}
while(result->NextRow());
- delete result;
-
if (!gossipScriptSet.empty())
{
for(std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr)
@@ -8600,7 +8452,7 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, int32 ma
void ObjectMgr::LoadScriptNames()
{
m_scriptNames.push_back("");
- QueryResult *result = WorldDatabase.Query(
+ QueryResult_AutoPtr result = WorldDatabase.Query(
"SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
@@ -8632,7 +8484,6 @@ void ObjectMgr::LoadScriptNames()
m_scriptNames.push_back((*result)[0].GetString());
++count;
} while (result->NextRow());
- delete result;
std::sort(m_scriptNames.begin(), m_scriptNames.end());
sLog.outString();
@@ -8735,7 +8586,7 @@ CreatureInfo const *GetCreatureInfo(uint32 id)
void ObjectMgr::LoadTransportEvents()
{
- QueryResult *result = WorldDatabase.Query("SELECT entry, waypoint_id, event_id FROM transport_events");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, waypoint_id, event_id FROM transport_events");
if( !result )
{
@@ -8764,8 +8615,6 @@ void ObjectMgr::LoadTransportEvents()
while(result->NextRow());
sLog.outString( "\n>> Loaded %u transport events \n", result->GetRowCount() );
-
- delete result;
}
CreatureInfo const* GetCreatureTemplateStore(uint32 entry)
@@ -8792,7 +8641,7 @@ void ObjectMgr::LoadGMTickets()
}
m_GMTicketList.clear();
- QueryResult *result = CharacterDatabase.Query( "SELECT guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment FROM gm_tickets" );
+ QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment FROM gm_tickets" );
if(!result)
{
@@ -8830,8 +8679,6 @@ void ObjectMgr::LoadGMTickets()
} while( result->NextRow() );
- delete result;
-
result = CharacterDatabase.PQuery("SELECT MAX(guid) from gm_tickets");
m_GMticketid = 0;
@@ -8840,7 +8687,6 @@ void ObjectMgr::LoadGMTickets()
Field *fields = result->Fetch();
m_GMticketid = fields[0].GetUInt64();
}
- delete result;
sLog.outString(">> Loaded %u GM Tickets from the database.", count);
}
@@ -8917,7 +8763,7 @@ CreatureBaseStats const* ObjectMgr::GetCreatureBaseStats(uint32 level, uint8 uni
void ObjectMgr::LoadCreatureClassLevelStats()
{
- QueryResult *result = WorldDatabase.Query("SELECT level, class, basehp0, basehp1, basehp2, basemana, basearmor FROM creature_classlevelstats");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level, class, basehp0, basehp1, basehp2, basemana, basearmor FROM creature_classlevelstats");
if (!result)
{
@@ -8970,8 +8816,6 @@ void ObjectMgr::LoadCreatureClassLevelStats()
}
while (result->NextRow());
- delete result;
-
for (uint32 i = 0; i < sCreatureStorage.MaxEntry; ++i)
{
CreatureInfo const* info = sCreatureStorage.LookupEntry<CreatureInfo>(i);
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
index b1a058690e1..b5a42b2101f 100644
--- a/src/game/Pet.cpp
+++ b/src/game/Pet.cpp
@@ -108,7 +108,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
uint32 ownerid = owner->GetGUIDLow();
- QueryResult *result;
+ QueryResult_AutoPtr result;
if (petnumber)
// known petnumber entry 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
@@ -141,10 +141,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
// update for case of current pet "slot = 0"
petentry = fields[1].GetUInt32();
if (!petentry)
- {
- delete result;
return false;
- }
uint32 summon_spell_id = fields[17].GetUInt32();
SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id);
@@ -153,20 +150,14 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
// check temporary summoned pets like mage water elemental
if (current && is_temporary_summoned)
- {
- delete result;
return false;
- }
PetType pet_type = PetType(fields[18].GetUInt8());
if(pet_type==HUNTER_PET)
{
CreatureInfo const* creatureInfo = objmgr.GetCreatureTemplate(petentry);
if(!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets()))
- {
- delete result;
return false;
- }
}
uint32 pet_number = fields[0].GetUInt32();
@@ -174,17 +165,13 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
if (current && owner->IsPetNeedBeTemporaryUnsummoned())
{
owner->SetTemporaryUnsummonedPetNumber(pet_number);
- delete result;
return false;
}
Map *map = owner->GetMap();
uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_PET);
if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number))
- {
- delete result;
return false;
- }
float px, py, pz;
owner->GetClosePoint(px, py, pz, GetObjectSize(), PET_FOLLOW_DIST, GetFollowAngle());
@@ -194,7 +181,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
{
sLog.outError("Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",
GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
- delete result;
return false;
}
@@ -206,7 +192,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
if (cinfo->type == CREATURE_TYPE_CRITTER)
{
map->Add((Creature*)this);
- delete result;
return true;
}
@@ -324,7 +309,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
CleanupActionBar(); // remove unknown spells from action bar after load
- delete result;
sLog.outDebug("New Pet has guid %u", GetGUIDLow());
owner->PetSpellInitialize();
@@ -349,7 +333,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
{
m_declinedname->name[i] = fields2[i].GetCppString();
}
- delete result;
}
}
@@ -1067,7 +1050,7 @@ void Pet::_LoadSpellCooldowns()
m_CreatureSpellCooldowns.clear();
m_CreatureCategoryCooldowns.clear();
- QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber());
if(result)
{
@@ -1103,8 +1086,6 @@ void Pet::_LoadSpellCooldowns()
}
while (result->NextRow());
- delete result;
-
if(!m_CreatureSpellCooldowns.empty() && GetOwner())
((Player*)GetOwner())->GetSession()->SendPacket(&data);
}
@@ -1131,7 +1112,7 @@ void Pet::_SaveSpellCooldowns()
void Pet::_LoadSpells()
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT spell,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber());
if (result)
{
@@ -1142,8 +1123,6 @@ void Pet::_LoadSpells()
addSpell(fields[0].GetUInt32(), ActiveStates(fields[1].GetUInt8()), PETSPELL_UNCHANGED);
}
while (result->NextRow());
-
- delete result;
}
}
@@ -1182,7 +1161,7 @@ void Pet::_LoadAuras(uint32 timediff)
{
sLog.outDebug("Loading auras for pet %u",GetGUIDLow());
- QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_mask,recalculate_mask,stackcount,amount0,amount1,amount2,base_amount0,base_amount1,base_amount2,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_mask,recalculate_mask,stackcount,amount0,amount1,amount2,base_amount0,base_amount1,base_amount2,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber());
if (result)
{
@@ -1244,8 +1223,6 @@ void Pet::_LoadAuras(uint32 timediff)
}
}
while (result->NextRow());
-
- delete result;
}
}
@@ -1669,7 +1646,7 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/)
// now need only reset for offline pets (all pets except online case)
uint32 except_petnumber = online_pet ? online_pet->GetCharmInfo()->GetPetNumber() : 0;
- QueryResult *resultPets = CharacterDatabase.PQuery(
+ QueryResult_AutoPtr resultPets = CharacterDatabase.PQuery(
"SELECT id FROM character_pet WHERE owner = '%u' AND id <> '%u'",
owner->GetGUIDLow(),except_petnumber);
@@ -1677,16 +1654,13 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/)
if (!resultPets)
return;
- QueryResult *result = CharacterDatabase.PQuery(
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery(
"SELECT DISTINCT pet_spell.spell FROM pet_spell, character_pet "
"WHERE character_pet.owner = '%u' AND character_pet.id = pet_spell.guid AND character_pet.id <> %u",
owner->GetGUIDLow(),except_petnumber);
if (!result)
- {
- delete resultPets;
return;
- }
bool need_comma = false;
std::ostringstream ss;
@@ -1707,8 +1681,6 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/)
}
while (resultPets->NextRow());
- delete resultPets;
-
ss << ") AND spell IN (";
bool need_execute = false;
@@ -1730,8 +1702,6 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/)
}
while (result->NextRow());
- delete result;
-
if (!need_execute)
return;
diff --git a/src/game/PetitionsHandler.cpp b/src/game/PetitionsHandler.cpp
index 13d36b467d5..74a6f56705f 100644
--- a/src/game/PetitionsHandler.cpp
+++ b/src/game/PetitionsHandler.cpp
@@ -207,7 +207,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data)
// a petition is invalid, if both the owner and the type matches
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
- QueryResult *result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type);
std::ostringstream ssInvalidPetitionGUIDs;
@@ -218,8 +218,6 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data)
Field *fields = result->Fetch();
ssInvalidPetitionGUIDs << "'" << fields[0].GetUInt32() << "' , ";
} while (result->NextRow());
-
- delete result;
}
// delete petitions with the same guid as this one
@@ -248,7 +246,7 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data)
// solve (possible) some strange compile problems with explicit use GUID_LOPART(petitionguid) at some GCC versions (wrong code optimization in compiler?)
uint32 petitionguid_low = GUID_LOPART(petitionguid);
- QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionguid_low);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionguid_low);
if(!result)
{
sLog.outError("Petition %u is not found for player %u %s", GUID_LOPART(petitionguid), GetPlayer()->GetGUIDLow(), GetPlayer()->GetName());
@@ -256,7 +254,6 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data)
}
Field *fields = result->Fetch();
uint32 type = fields[0].GetUInt32();
- delete result;
// if guild petition and has guild => error, return;
if(type==9 && _player->GetGuildId())
@@ -286,7 +283,6 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data)
result->NextRow();
}
- delete result;
SendPacket(&data);
}
@@ -311,7 +307,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
std::string name = "NO_NAME_FOR_GUID";
uint8 signs = 0;
- QueryResult *result = CharacterDatabase.PQuery(
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery(
"SELECT ownerguid, name, "
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
@@ -324,7 +320,6 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
name = fields[1].GetCppString();
signs = fields[2].GetUInt8();
type = fields[3].GetUInt32();
- delete result;
}
else
{
@@ -387,13 +382,12 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data)
if(!item)
return;
- QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(result)
{
Field* fields = result->Fetch();
type = fields[0].GetUInt32();
- delete result;
}
else
{
@@ -451,7 +445,7 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
recv_data >> petitionguid; // petition guid
recv_data >> unk;
- QueryResult *result = CharacterDatabase.PQuery(
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery(
"SELECT ownerguid, "
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
@@ -468,8 +462,6 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
uint8 signs = fields[1].GetUInt8();
uint32 type = fields[2].GetUInt32();
- delete result;
-
uint32 plguidlo = _player->GetGUIDLow();
if(GUID_LOPART(ownerguid) == plguidlo)
return;
@@ -531,7 +523,6 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
if(result)
{
- delete result;
WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4));
data << petitionguid;
data << _player->GetGUID();
@@ -578,13 +569,12 @@ void WorldSession::HandlePetitionDeclineOpcode(WorldPacket & recv_data)
recv_data >> petitionguid; // petition guid
sLog.outDebug("Petition %u declined by %u", GUID_LOPART(petitionguid), _player->GetGUIDLow());
- QueryResult *result = CharacterDatabase.PQuery("SELECT ownerguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT ownerguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(!result)
return;
Field *fields = result->Fetch();
ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
- delete result;
Player *owner = objmgr.GetPlayer(ownerguid);
if(owner) // petition owner online
@@ -612,13 +602,12 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)
if (!player)
return;
- QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if (!result)
return;
Field *fields = result->Fetch();
type = fields[0].GetUInt32();
- delete result;
sLog.outDebug("OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, GUID_LOPART(petitionguid), GUID_LOPART(plguid));
@@ -694,7 +683,6 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)
result->NextRow();
}
- delete result;
player->GetSession()->SendPacket(&data);
}
@@ -715,14 +703,13 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
sLog.outDebug("Petition %u turned in by %u", GUID_LOPART(petitionguid), _player->GetGUIDLow());
// data
- QueryResult *result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(result)
{
Field *fields = result->Fetch();
ownerguidlo = fields[0].GetUInt32();
name = fields[1].GetCppString();
type = fields[2].GetUInt32();
- delete result;
}
else
{
@@ -778,7 +765,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data << (uint32)PETITION_TURN_NEED_MORE_SIGNATURES; // need more signatures...
SendPacket(&data);
- delete result;
return;
}
@@ -787,7 +773,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
if(objmgr.GetGuildByName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, GUILD_NAME_EXISTS);
- delete result;
return;
}
}
@@ -796,7 +781,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
if(objmgr.GetArenaTeamByName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
- delete result;
return;
}
}
@@ -804,10 +788,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
// and at last charter item check
Item *item = _player->GetItemByGuid(petitionguid);
if(!item)
- {
- delete result;
return;
- }
// OK!
@@ -820,7 +801,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
if(!guild->Create(_player, name))
{
delete guild;
- delete result;
return;
}
@@ -842,7 +822,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
{
sLog.outError("PetitionsHandler: arena team create failed.");
delete at;
- delete result;
return;
}
@@ -866,8 +845,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
}
}
- delete result;
-
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 4e23b0c1e50..a444bb79fbd 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -1468,7 +1468,7 @@ void Player::setDeathState(DeathState s)
}
}
-bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
+bool Player::BuildEnumData( QueryResult_AutoPtr result, WorldPacket * p_data )
{
// 0 1 2 3 4 5 6 7
// "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
@@ -3690,7 +3690,7 @@ void Player::RemoveAllSpellCooldown()
}
}
-void Player::_LoadSpellCooldowns(QueryResult *result)
+void Player::_LoadSpellCooldowns(QueryResult_AutoPtr result)
{
// some cooldowns can be already set at aura loading...
@@ -3723,8 +3723,6 @@ void Player::_LoadSpellCooldowns(QueryResult *result)
sLog.outDebug("Player (GUID: %u) spell %u, item %u cooldown loaded (%u secs).", GetGUIDLow(), spell_id, item_id, uint32(db_time-curTime));
}
while( result->NextRow() );
-
- delete result;
}
}
@@ -4166,11 +4164,10 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
LeaveAllArenaTeams(playerguid);
// the player was uninvited already on logout so just remove from group
- QueryResult *resultGroup = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid);
+ QueryResult_AutoPtr resultGroup = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid);
if(resultGroup)
{
uint64 leaderGuid = MAKE_NEW_GUID((*resultGroup)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
- delete resultGroup;
Group* group = objmgr.GetGroupByLeader(leaderGuid);
if(group)
{
@@ -4182,7 +4179,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
RemovePetitionsAndSigns(playerguid, 10);
// return back all mails with COD and Item 0 1 2 3 4 5 6 7
- QueryResult *resultMail = CharacterDatabase.PQuery("SELECT id,messageType,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid);
+ QueryResult_AutoPtr resultMail = CharacterDatabase.PQuery("SELECT id,messageType,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid);
if(resultMail)
{
do
@@ -4217,7 +4214,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
if(has_items)
{
// data needs to be at first place for Item::LoadFromDB
- QueryResult *resultItems = CharacterDatabase.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
+ QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
if(resultItems)
{
do
@@ -4245,8 +4242,6 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
draft.AddItem(pItem);
}
while (resultItems->NextRow());
-
- delete resultItems;
}
}
@@ -4257,13 +4252,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
draft.AddMoney(money).SendReturnToSender(pl_account, guid, sender);
}
while (resultMail->NextRow());
-
- delete resultMail;
}
// unsummon and delete for pets in world is not required: player deleted from CLI or character list with not loaded pet.
// Get guids of character's pets, will deleted in transaction
- QueryResult *resultPets = CharacterDatabase.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid);
+ QueryResult_AutoPtr resultPets = CharacterDatabase.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid);
// NOW we can finally clear other DB data related to character
CharacterDatabase.BeginTransaction();
@@ -4275,7 +4268,6 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
uint32 petguidlow = fields3[0].GetUInt32();
Pet::DeleteFromDB(petguidlow);
} while (resultPets->NextRow());
- delete resultPets;
}
CharacterDatabase.PExecute("DELETE FROM characters WHERE guid = '%u'",guid);
@@ -6545,22 +6537,20 @@ void Player::ModifyArenaPoints(int32 value)
uint32 Player::GetGuildIdFromDB(uint64 guid)
{
- QueryResult* result = CharacterDatabase.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid));
if(!result)
return 0;
uint32 id = result->Fetch()[0].GetUInt32();
- delete result;
return id;
}
uint32 Player::GetRankFromDB(uint64 guid)
{
- QueryResult *result = CharacterDatabase.PQuery( "SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid) );
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid) );
if( result )
{
uint32 v = result->Fetch()[0].GetUInt32();
- delete result;
return v;
}
else
@@ -6569,24 +6559,22 @@ uint32 Player::GetRankFromDB(uint64 guid)
uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid), type);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid), type);
if(!result)
return 0;
uint32 id = (*result)[0].GetUInt32();
- delete result;
return id;
}
uint32 Player::GetZoneIdFromDB(uint64 guid)
{
uint32 guidLow = GUID_LOPART(guid);
- QueryResult *result = CharacterDatabase.PQuery( "SELECT zone FROM characters WHERE guid='%u'", guidLow );
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT zone FROM characters WHERE guid='%u'", guidLow );
if (!result)
return 0;
Field* fields = result->Fetch();
uint32 zone = fields[0].GetUInt32();
- delete result;
if (!zone)
{
@@ -6599,7 +6587,6 @@ uint32 Player::GetZoneIdFromDB(uint64 guid)
float posx = fields[1].GetFloat();
float posy = fields[2].GetFloat();
float posz = fields[3].GetFloat();
- delete result;
zone = MapManager::Instance().GetZoneId(map,posx,posy,posz);
@@ -6612,13 +6599,12 @@ uint32 Player::GetZoneIdFromDB(uint64 guid)
uint32 Player::GetLevelFromDB(uint64 guid)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT level FROM characters WHERE guid='%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT level FROM characters WHERE guid='%u'", GUID_LOPART(guid));
if (!result)
return 0;
Field* fields = result->Fetch();
uint8 level = fields[0].GetUInt8();
- delete result;
return level;
}
@@ -15158,9 +15144,8 @@ void Player::SendQuestUpdateAddCreatureOrGo( Quest const* pQuest, uint64 guid, u
/*** LOAD SYSTEM ***/
/*********************************************************/
-bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid )
+bool Player::MinimalLoadFromDB( QueryResult_AutoPtr result, uint32 guid )
{
- bool delete_result = true;
if (!result)
{
// 0 1 2 3 4 5 6 7 8 9 10 11
@@ -15168,16 +15153,12 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid )
if (!result)
return false;
}
- else
- delete_result = false;
Field *fields = result->Fetch();
if (!LoadValues( fields[1].GetString()))
{
sLog.outError("Player #%d have broken data in `data` field. Can't be loaded for character list.",GUID_LOPART(guid));
- if (delete_result)
- delete result;
return false;
}
@@ -15206,9 +15187,6 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid )
_LoadBoundInstances();*/
- if (delete_result)
- delete result;
-
for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; i++)
m_items[i] = NULL;
@@ -15218,7 +15196,7 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid )
return true;
}
-void Player::_LoadDeclinedNames(QueryResult* result)
+void Player::_LoadDeclinedNames(QueryResult_AutoPtr result)
{
if(!result)
return;
@@ -15230,11 +15208,9 @@ void Player::_LoadDeclinedNames(QueryResult* result)
Field *fields = result->Fetch();
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
m_declinedname->name[i] = fields[i].GetCppString();
-
- delete result;
}
-void Player::_LoadArenaTeamInfo(QueryResult *result)
+void Player::_LoadArenaTeamInfo(QueryResult_AutoPtr result)
{
// arenateamid, played_week, played_season, personal_rating
memset((void*)&m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1], 0, sizeof(uint32) * MAX_ARENA_SLOT * ARENA_TEAM_END);
@@ -15268,10 +15244,9 @@ void Player::_LoadArenaTeamInfo(QueryResult *result)
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (arenaSlot * ARENA_TEAM_END) + ARENA_TEAM_PERSONAL_RATING] = personal_rating; // Personal Rating
}while (result->NextRow());
- delete result;
}
-void Player::_LoadEquipmentSets(QueryResult *result)
+void Player::_LoadEquipmentSets(QueryResult_AutoPtr result)
{
// SetPQuery(PLAYER_LOGIN_QUERY_LOADEQUIPMENTSETS, "SELECT setguid, setindex, name, iconname, item0, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18 FROM character_equipmentsets WHERE guid = '%u' ORDER BY setindex", GUID_LOPART(m_guid));
if (!result)
@@ -15300,10 +15275,9 @@ void Player::_LoadEquipmentSets(QueryResult *result)
if(count >= MAX_EQUIPMENT_SET_INDEX) // client limit
break;
} while (result->NextRow());
- delete result;
}
-void Player::_LoadBGData(QueryResult* result)
+void Player::_LoadBGData(QueryResult_AutoPtr result)
{
if (!result)
return;
@@ -15321,13 +15295,11 @@ void Player::_LoadBGData(QueryResult* result)
m_bgData.taxiPath[0] = fields[7].GetUInt32();
m_bgData.taxiPath[1] = fields[8].GetUInt32();
m_bgData.mountSpell = fields[9].GetUInt32();
-
- delete result;
}
bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid));
if(!result)
return false;
@@ -15340,13 +15312,12 @@ bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float&
mapid = fields[4].GetUInt32();
in_flight = !fields[5].GetCppString().empty();
- delete result;
return true;
}
bool Player::LoadValuesArrayFromDB(Tokens& data, uint64 guid)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid));
if( !result )
return false;
@@ -15354,8 +15325,6 @@ bool Player::LoadValuesArrayFromDB(Tokens& data, uint64 guid)
data = StrSplit(fields[0].GetCppString(), " ");
- delete result;
-
return true;
}
@@ -15398,7 +15367,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
{
//// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//QueryResult *result = CharacterDatabase.PQuery("SELECT guid, account, data, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points, instance_id, speccount, activespec FROM characters WHERE guid = '%u'", guid);
- QueryResult *result = holder->GetResult(PLAYER_LOGIN_QUERY_LOADFROM);
+ QueryResult_AutoPtr result = holder->GetResult(PLAYER_LOGIN_QUERY_LOADFROM);
if(!result)
{
@@ -15415,7 +15384,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
if( dbAccountId != GetSession()->GetAccountId() )
{
sLog.outError("Player (GUID: %u) loading from wrong account (is: %u, should be: %u)",guid,GetSession()->GetAccountId(),dbAccountId);
- delete result;
return false;
}
@@ -15427,7 +15395,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
(GetSession()->GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(m_name)))
{
- delete result;
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME),guid);
return false;
}
@@ -15435,7 +15402,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
if(!LoadValues( fields[2].GetString()))
{
sLog.outError("Player #%d have broken data in `data` field. Can't be loaded.", GUID_LOPART(guid));
- delete result;
return false;
}
@@ -15485,10 +15451,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
// load home bind and check in same time class/race pair, it used later for restore broken positions
if(!_LoadHomeBind(holder->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND)))
- {
- delete result;
return false;
- }
InitPrimaryProfessions(); // to max set before any spell loaded
@@ -15720,7 +15683,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
if (!map)
{
sLog.outError("ERROR: Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created",guid,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
- delete result;
return false;
}
}
@@ -15860,7 +15822,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
m_specsCount = fields[42].GetUInt8();
m_activeSpec = fields[43].GetUInt8();
- delete result;
// sanity check
if (m_specsCount > MAX_TALENT_SPECS || m_activeSpec > MAX_TALENT_SPEC ||
@@ -16023,7 +15984,7 @@ bool Player::isAllowedToLoot(Creature* creature)
return !creature->hasLootRecipient();
}
-void Player::_LoadActions(QueryResult *result, bool startup)
+void Player::_LoadActions(QueryResult_AutoPtr result, bool startup)
{
if (result)
{
@@ -16050,12 +16011,10 @@ void Player::_LoadActions(QueryResult *result, bool startup)
}
}
while (result->NextRow());
-
- delete result;
}
}
-void Player::_LoadAuras(QueryResult *result, uint32 timediff)
+void Player::_LoadAuras(QueryResult_AutoPtr result, uint32 timediff)
{
sLog.outDebug("Loading auras for player %u",GetGUIDLow());
@@ -16121,8 +16080,6 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff)
}
}
while (result->NextRow());
-
- delete result;
}
if(getClass() == CLASS_WARRIOR && !HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
@@ -16173,7 +16130,7 @@ void Player::LoadCorpse()
}
}
-void Player::_LoadInventory(QueryResult *result, uint32 timediff)
+void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
{
//QueryResult *result = CharacterDatabase.PQuery("SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GetGUIDLow());
std::map<uint64, Bag*> bagMap; // fast guid lookup for bags
@@ -16309,7 +16266,6 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff)
}
} while (result->NextRow());
- delete result;
m_itemUpdateQueueBlocked = false;
// send by mail problematic items
@@ -16339,7 +16295,7 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff)
void Player::_LoadMailedItems(Mail *mail)
{
// data needs to be at first place for Item::LoadFromDB
- QueryResult* result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
if (!result)
return;
@@ -16374,11 +16330,9 @@ void Player::_LoadMailedItems(Mail *mail)
AddMItem(item);
} while (result->NextRow());
-
- delete result;
}
-void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery)
+void Player::_LoadMailInit(QueryResult_AutoPtr resultUnread, QueryResult_AutoPtr resultDelivery)
{
//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);
@@ -16386,7 +16340,6 @@ void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDeliver
{
Field *fieldMail = resultUnread->Fetch();
unReadMails = fieldMail[0].GetUInt8();
- delete resultUnread;
}
// store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called)
@@ -16395,7 +16348,6 @@ void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDeliver
{
Field *fieldMail = resultDelivery->Fetch();
m_nextMailDelivereTime = (time_t)fieldMail[0].GetUInt64();
- delete resultDelivery;
}
}
@@ -16403,7 +16355,7 @@ void Player::_LoadMail()
{
m_mail.clear();
//mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13
- QueryResult *result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow());
if (result)
{
do
@@ -16438,7 +16390,6 @@ void Player::_LoadMail()
m_mail.push_back(m);
} while (result->NextRow());
- delete result;
}
m_mailsLoaded = true;
}
@@ -16455,7 +16406,7 @@ void Player::LoadPet()
}
}
-void Player::_LoadQuestStatus(QueryResult *result)
+void Player::_LoadQuestStatus(QueryResult_AutoPtr result)
{
mQuestStatus.clear();
@@ -16557,8 +16508,6 @@ void Player::_LoadQuestStatus(QueryResult *result)
}
}
while (result->NextRow());
-
- delete result;
}
// clear quest log tail
@@ -16566,7 +16515,7 @@ void Player::_LoadQuestStatus(QueryResult *result)
SetQuestSlot(i, 0);
}
-void Player::_LoadDailyQuestStatus(QueryResult *result)
+void Player::_LoadDailyQuestStatus(QueryResult_AutoPtr result)
{
for (uint32 quest_daily_idx = 0; quest_daily_idx < PLAYER_MAX_DAILY_QUESTS; ++quest_daily_idx)
SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx,0);
@@ -16602,14 +16551,12 @@ void Player::_LoadDailyQuestStatus(QueryResult *result)
sLog.outDebug("Daily quest {%u} cooldown for player (GUID: %u)", quest_id, GetGUIDLow());
}
while (result->NextRow());
-
- delete result;
}
m_DailyQuestChanged = false;
}
-void Player::_LoadSpells(QueryResult *result)
+void Player::_LoadSpells(QueryResult_AutoPtr result)
{
//QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'",GetGUIDLow());
@@ -16622,18 +16569,15 @@ void Player::_LoadSpells(QueryResult *result)
addSpell(fields[0].GetUInt32(), fields[1].GetBool(), false, false, fields[2].GetBool());
}
while (result->NextRow());
-
- delete result;
}
}
-void Player::_LoadGroup(QueryResult *result)
+void Player::_LoadGroup(QueryResult_AutoPtr result)
{
//QueryResult *result = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", GetGUIDLow());
if (result)
{
uint64 leaderGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
- delete result;
if (Group* group = objmgr.GetGroupByLeader(leaderGuid))
{
uint8 subgroup = group->GetMemberGroup(GetGUID());
@@ -16648,7 +16592,7 @@ void Player::_LoadGroup(QueryResult *result)
}
}
-void Player::_LoadBoundInstances(QueryResult *result)
+void Player::_LoadBoundInstances(QueryResult_AutoPtr result)
{
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
m_boundInstances[i].clear();
@@ -16706,7 +16650,6 @@ void Player::_LoadBoundInstances(QueryResult *result)
if (InstanceSave *save = sInstanceSaveManager.AddInstanceSave(mapId, instanceId, Difficulty(difficulty), resetTime, !perm, true))
BindToInstance(save, perm, true);
} while (result->NextRow());
- delete result;
}
}
@@ -16986,7 +16929,7 @@ bool Player::Satisfy(AccessRequirement const *ar, uint32 target_map, bool report
return true;
}
-bool Player::_LoadHomeBind(QueryResult *result)
+bool Player::_LoadHomeBind(QueryResult_AutoPtr result)
{
PlayerInfo const *info = objmgr.GetPlayerInfo(getRace(), getClass());
if (!info)
@@ -17005,7 +16948,6 @@ bool Player::_LoadHomeBind(QueryResult *result)
m_homebindX = fields[2].GetFloat();
m_homebindY = fields[3].GetFloat();
m_homebindZ = fields[4].GetFloat();
- delete result;
MapEntry const* bindMapEntry = sMapStore.LookupEntry(m_homebindMapId);
@@ -17638,7 +17580,7 @@ void Player::SetFloatValueInDB(uint16 index, float value, uint64 guid)
void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair)
{
// 0
- QueryResult* result = CharacterDatabase.PQuery("SELECT playerBytes2 FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT playerBytes2 FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
if(!result)
return;
@@ -17649,8 +17591,6 @@ void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8
player_bytes2 |= facialHair;
CharacterDatabase.PExecute("UPDATE characters SET gender = '%u', playerBytes = '%u', playerBytes2 = '%u' WHERE guid = '%u'", gender, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24), player_bytes2, GUID_LOPART(guid));
-
- delete result;
}
void Player::SendAttackSwingDeadTarget()
@@ -18448,7 +18388,7 @@ void Player::SendProficiency(uint8 pr1, uint32 pr2)
void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
{
- QueryResult *result = NULL;
+ QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL);
if(type==10)
result = CharacterDatabase.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid));
else
@@ -18468,8 +18408,6 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
} while ( result->NextRow() );
- delete result;
-
if(type==10)
CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid));
else
@@ -18492,7 +18430,7 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
void Player::LeaveAllArenaTeams(uint64 guid)
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid));
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid));
if(!result)
return;
@@ -18507,8 +18445,6 @@ void Player::LeaveAllArenaTeams(uint64 guid)
at->DelMember(guid);
}
} while (result->NextRow());
-
- delete result;
}
void Player::SetRestBonus (float rest_bonus_new)
@@ -21906,7 +21842,7 @@ void Player::learnSpellHighRank(uint32 spellid)
learnSpellHighRank(next);
}
-void Player::_LoadSkills(QueryResult *result)
+void Player::_LoadSkills(QueryResult_AutoPtr result)
{
// 0 1 2
// SetPQuery(PLAYER_LOGIN_QUERY_LOADSKILLS, "SELECT skill, value, max FROM character_skills WHERE guid = '%u'", GUID_LOPART(m_guid));
@@ -21969,7 +21905,6 @@ void Player::_LoadSkills(QueryResult *result)
break;
}
} while (result->NextRow());
- delete result;
}
for (; count < PLAYER_MAX_SKILLS; ++count)
@@ -22813,7 +22748,7 @@ void Player::SetMap(Map * map)
m_mapRef.link(map, this);
}
-void Player::_LoadGlyphs(QueryResult *result)
+void Player::_LoadGlyphs(QueryResult_AutoPtr result)
{
// SetPQuery(PLAYER_LOGIN_QUERY_LOADGLYPHS, "SELECT spec, glyph1, glyph2, glyph3, glyph4, glyph5, glyph6 from character_glyphs WHERE guid = '%u'", GUID_LOPART(m_guid));
if (!result)
@@ -22835,8 +22770,6 @@ void Player::_LoadGlyphs(QueryResult *result)
m_Glyphs[spec][5] = fields[6].GetUInt32();
} while (result->NextRow());
-
- delete result;
}
void Player::_SaveGlyphs()
@@ -22849,7 +22782,7 @@ void Player::_SaveGlyphs()
}
}
-void Player::_LoadTalents(QueryResult *result)
+void Player::_LoadTalents(QueryResult_AutoPtr result)
{
// SetPQuery(PLAYER_LOGIN_QUERY_LOADTALENTS, "SELECT spell, spec FROM character_talent WHERE guid = '%u'", GUID_LOPART(m_guid));
if (result)
@@ -22861,8 +22794,6 @@ void Player::_LoadTalents(QueryResult *result)
AddTalent(fields[0].GetUInt32(), fields[1].GetUInt32(), false);
}
while( result->NextRow() );
-
- delete result;
}
}
@@ -23046,7 +22977,7 @@ void Player::ActivateSpec(uint8 spec)
// Let client clear his current Actions
SendActionButtons(2);
m_actionButtons.clear();
- if (QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' AND spec = '%u' ORDER BY button", GetGUIDLow(), m_activeSpec))
+ if (QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' AND spec = '%u' ORDER BY button", GetGUIDLow(), m_activeSpec))
_LoadActions(result, false);
ResummonPetTemporaryUnSummonedIfAny();
diff --git a/src/game/Player.h b/src/game/Player.h
index 4f3728de1a6..8c17670700a 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -1002,7 +1002,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player>
void Update( uint32 time );
- static bool BuildEnumData( QueryResult * result, WorldPacket * p_data );
+ static bool BuildEnumData( QueryResult_AutoPtr result, WorldPacket * p_data );
void SetInWater(bool apply);
@@ -1377,7 +1377,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player>
bool LoadFromDB(uint32 guid, SqlQueryHolder *holder);
bool isBeingLoaded() const { return GetSession()->PlayerLoading();}
- bool MinimalLoadFromDB(QueryResult *result, uint32 guid);
+ bool MinimalLoadFromDB(QueryResult_AutoPtr result, uint32 guid);
static bool LoadValuesArrayFromDB(Tokens& data,uint64 guid);
static uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
static float GetFloatValueFromArray(Tokens const& data, uint16 index);
@@ -1596,7 +1596,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player>
void RemoveCategoryCooldown(uint32 cat);
void RemoveArenaSpellCooldowns();
void RemoveAllSpellCooldown();
- void _LoadSpellCooldowns(QueryResult *result);
+ void _LoadSpellCooldowns(QueryResult_AutoPtr result);
void _SaveSpellCooldowns();
void SetLastPotionId(uint32 item_id) { m_lastPotionId = item_id; }
void UpdatePotionCooldown(Spell* spell = NULL);
@@ -2326,27 +2326,27 @@ Spell * m_spellModTakingSpell;
/*** LOAD SYSTEM ***/
/*********************************************************/
- void _LoadActions(QueryResult *result, bool startup);
- void _LoadAuras(QueryResult *result, uint32 timediff);
+ void _LoadActions(QueryResult_AutoPtr result, bool startup);
+ void _LoadAuras(QueryResult_AutoPtr result, uint32 timediff);
void _LoadGlyphAuras();
- void _LoadBoundInstances(QueryResult *result);
- void _LoadInventory(QueryResult *result, uint32 timediff);
- void _LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery);
+ void _LoadBoundInstances(QueryResult_AutoPtr result);
+ void _LoadInventory(QueryResult_AutoPtr result, uint32 timediff);
+ void _LoadMailInit(QueryResult_AutoPtr resultUnread, QueryResult_AutoPtr resultDelivery);
void _LoadMail();
void _LoadMailedItems(Mail *mail);
- void _LoadQuestStatus(QueryResult *result);
- void _LoadDailyQuestStatus(QueryResult *result);
- void _LoadGroup(QueryResult *result);
- void _LoadSkills(QueryResult *result);
- void _LoadSpells(QueryResult *result);
- void _LoadFriendList(QueryResult *result);
- bool _LoadHomeBind(QueryResult *result);
- void _LoadDeclinedNames(QueryResult *result);
- void _LoadArenaTeamInfo(QueryResult *result);
- void _LoadEquipmentSets(QueryResult *result);
- void _LoadBGData(QueryResult* result);
- void _LoadGlyphs(QueryResult *result);
- void _LoadTalents(QueryResult *result);
+ void _LoadQuestStatus(QueryResult_AutoPtr result);
+ void _LoadDailyQuestStatus(QueryResult_AutoPtr result);
+ void _LoadGroup(QueryResult_AutoPtr result);
+ void _LoadSkills(QueryResult_AutoPtr result);
+ void _LoadSpells(QueryResult_AutoPtr result);
+ void _LoadFriendList(QueryResult_AutoPtr result);
+ bool _LoadHomeBind(QueryResult_AutoPtr result);
+ void _LoadDeclinedNames(QueryResult_AutoPtr result);
+ void _LoadArenaTeamInfo(QueryResult_AutoPtr result);
+ void _LoadEquipmentSets(QueryResult_AutoPtr result);
+ void _LoadBGData(QueryResult_AutoPtr result);
+ void _LoadGlyphs(QueryResult_AutoPtr result);
+ void _LoadTalents(QueryResult_AutoPtr result);
/*********************************************************/
/*** SAVE SYSTEM ***/
diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp
index 107b282f9dd..26574d6280b 100644
--- a/src/game/PlayerDump.cpp
+++ b/src/game/PlayerDump.cpp
@@ -198,7 +198,7 @@ bool changetokGuid(std::string &str, int n, std::map<uint32, uint32> &guidMap, u
return changetoknth(str, n, chritem, false, nonzero);
}
-std::string CreateDumpString(char const* tableName, QueryResult *result)
+std::string CreateDumpString(char const* tableName, QueryResult_AutoPtr result)
{
if(!tableName || !result) return "";
std::ostringstream ss;
@@ -248,7 +248,7 @@ std::string PlayerDumpWriter::GenerateWhereStr(char const* field, GUIDs const& g
return wherestr.str();
}
-void StoreGUID(QueryResult *result,uint32 field,std::set<uint32>& guids)
+void StoreGUID(QueryResult_AutoPtr result,uint32 field,std::set<uint32>& guids)
{
Field* fields = result->Fetch();
uint32 guid = fields[field].GetUInt32();
@@ -256,7 +256,7 @@ void StoreGUID(QueryResult *result,uint32 field,std::set<uint32>& guids)
guids.insert(guid);
}
-void StoreGUID(QueryResult *result,uint32 data,uint32 field, std::set<uint32>& guids)
+void StoreGUID(QueryResult_AutoPtr result,uint32 data,uint32 field, std::set<uint32>& guids)
{
Field* fields = result->Fetch();
std::string dataStr = fields[data].GetCppString();
@@ -301,7 +301,7 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl
else // not set case, get single guid string
wherestr = GenerateWhereStr(fieldname,guid);
- QueryResult *result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
if(!result)
return;
@@ -329,8 +329,6 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl
dump += "\n";
}
while (result->NextRow());
-
- delete result;
}
while(guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids
}
@@ -400,13 +398,12 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
{
// check character count
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account);
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account);
uint8 charcount = 0;
if (result)
{
Field *fields=result->Fetch();
charcount = fields[0].GetUInt8();
- delete result;
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
@@ -417,7 +414,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
if (!fin)
return DUMP_FILE_OPEN_ERROR;
- QueryResult * result = NULL;
+ QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL);
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
// make sure the same guid doesn't already exist and is safe to use
@@ -426,10 +423,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
{
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE guid = '%d'", guid);
if (result)
- {
guid = objmgr.m_hiCharGuid; // use first free if exists
- delete result;
- }
else incHighest = false;
}
else
@@ -444,10 +438,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str());
if (result)
- {
name = ""; // use the one from the dump
- delete result;
- }
}
else
name = "";
@@ -557,8 +548,6 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str());
if (result)
{
- delete result;
-
if(!changenth(line, 37, "1")) // rename on login: `at_login` field 37 in raw field list
ROLLBACK(DUMP_FILE_BROKEN);
}
diff --git a/src/game/PoolHandler.cpp b/src/game/PoolHandler.cpp
index c2cb8045b81..15afb656805 100644
--- a/src/game/PoolHandler.cpp
+++ b/src/game/PoolHandler.cpp
@@ -350,7 +350,7 @@ PoolHandler::PoolHandler()
void PoolHandler::LoadFromDB()
{
- QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template");
if (!result)
{
sLog.outString(">> Table pool_template is empty.");
@@ -361,7 +361,6 @@ void PoolHandler::LoadFromDB()
{
Field *fields = result->Fetch();
max_pool_id = fields[0].GetUInt16();
- delete result;
}
mPoolTemplate.resize(max_pool_id + 1);
@@ -392,8 +391,6 @@ void PoolHandler::LoadFromDB()
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u objects pools", count );
@@ -458,7 +455,6 @@ void PoolHandler::LoadFromDB()
} while (result->NextRow());
sLog.outString();
sLog.outString( ">> Loaded %u creatures in pools", count );
- delete result;
}
// Gameobjects
@@ -530,7 +526,6 @@ void PoolHandler::LoadFromDB()
} while( result->NextRow() );
sLog.outString();
sLog.outString( ">> Loaded %u gameobject in pools", count );
- delete result;
}
// Pool of pools
@@ -619,7 +614,6 @@ void PoolHandler::LoadFromDB()
}
}
}
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u pools in mother pools", count );
@@ -629,7 +623,7 @@ void PoolHandler::LoadFromDB()
// The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks
void PoolHandler::Initialize()
{
- QueryResult *result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry FROM pool_template LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL AND pool_pool.pool_id IS NULL");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry FROM pool_template LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL AND pool_pool.pool_id IS NULL");
uint32 count=0;
if (result)
{
@@ -647,7 +641,6 @@ void PoolHandler::Initialize()
SpawnPool(pool_entry, 0, TYPEID_UNIT);
count++;
} while (result->NextRow());
- delete result;
}
sLog.outBasic("Pool handling system initialized, %u pools spawned.", count);
diff --git a/src/game/QueryHandler.cpp b/src/game/QueryHandler.cpp
index c0a9cfd8f87..af2ffbb7272 100644
--- a/src/game/QueryHandler.cpp
+++ b/src/game/QueryHandler.cpp
@@ -77,17 +77,14 @@ void WorldSession::SendNameQueryOpcodeFromDB(uint64 guid)
GUID_LOPART(guid));
}
-void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 accountId)
+void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult_AutoPtr result, uint32 accountId)
{
if(!result)
return;
WorldSession * session = sWorld.FindSession(accountId);
if(!session)
- {
- delete result;
return;
- }
Field *fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
@@ -122,7 +119,6 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32
data << uint8(0); // is not declined
session->SendPacket( &data );
- delete result;
}
void WorldSession::HandleNameQueryOpcode( WorldPacket & recv_data )
diff --git a/src/game/ReputationMgr.cpp b/src/game/ReputationMgr.cpp
index bdd6af49ccc..9027ed8b426 100644
--- a/src/game/ReputationMgr.cpp
+++ b/src/game/ReputationMgr.cpp
@@ -459,7 +459,7 @@ void ReputationMgr::SetInactive(FactionState* faction, bool inactive)
faction->Changed = true;
}
-void ReputationMgr::LoadFromDB(QueryResult *result)
+void ReputationMgr::LoadFromDB(QueryResult_AutoPtr result)
{
// Set initial reputations (so everything is nifty before DB data load)
Initialize();
@@ -513,8 +513,6 @@ void ReputationMgr::LoadFromDB(QueryResult *result)
}
}
while( result->NextRow() );
-
- delete result;
}
}
diff --git a/src/game/ReputationMgr.h b/src/game/ReputationMgr.h
index 6c78e0fa3b5..bb997e5ea11 100644
--- a/src/game/ReputationMgr.h
+++ b/src/game/ReputationMgr.h
@@ -23,6 +23,7 @@
#include "SharedDefines.h"
#include "Language.h"
#include "DBCStructure.h"
+#include "QueryResult.h"
#include <map>
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] =
@@ -68,7 +69,7 @@ class ReputationMgr
~ReputationMgr() {}
void SaveToDB();
- void LoadFromDB(QueryResult *result);
+ void LoadFromDB(QueryResult_AutoPtr result);
public: // statics
static const int32 PointsInRank[MAX_REPUTATION_RANK];
static const int32 Reputation_Cap = 42999;
diff --git a/src/game/ScriptSystem.cpp b/src/game/ScriptSystem.cpp
index 8645d19bcff..261852b27de 100644
--- a/src/game/ScriptSystem.cpp
+++ b/src/game/ScriptSystem.cpp
@@ -39,15 +39,14 @@ SystemMgr& SystemMgr::Instance()
void SystemMgr::LoadVersion()
{
//Get Version information
- QueryResult* pResult = TScriptDB.PQuery("SELECT script_version FROM version LIMIT 1");
+ QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT script_version FROM version LIMIT 1");
- if (pResult)
+ if (Result)
{
- Field* pFields = pResult->Fetch();
+ Field* pFields = Result->Fetch();
outstring_log("TSCR: Database version is: %s", pFields[0].GetString());
outstring_log("");
- delete pResult;
}
else
{
@@ -61,19 +60,19 @@ void SystemMgr::LoadScriptTexts()
outstring_log("TSCR: Loading Script Texts...");
LoadTrinityStrings(TScriptDB,"script_texts",TEXT_SOURCE_RANGE,1+(TEXT_SOURCE_RANGE*2));
- QueryResult* pResult = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM script_texts");
+ QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM script_texts");
outstring_log("TSCR: Loading Script Texts additional data...");
- if (pResult)
+ if (Result)
{
- barGoLink bar(pResult->GetRowCount());
+ barGoLink bar(Result->GetRowCount());
uint32 uiCount = 0;
do
{
bar.step();
- Field* pFields = pResult->Fetch();
+ Field* pFields = Result->Fetch();
StringTextData pTemp;
int32 iId = pFields[0].GetInt32();
@@ -108,8 +107,7 @@ void SystemMgr::LoadScriptTexts()
m_mTextDataMap[iId] = pTemp;
++uiCount;
- } while (pResult->NextRow());
- delete pResult;
+ } while (Result->NextRow());
outstring_log("");
outstring_log(">> Loaded %u additional Script Texts data.", uiCount);
@@ -128,19 +126,19 @@ void SystemMgr::LoadScriptTextsCustom()
outstring_log("TSCR: Loading Custom Texts...");
LoadTrinityStrings(TScriptDB,"custom_texts",TEXT_SOURCE_RANGE*2,1+(TEXT_SOURCE_RANGE*3));
- QueryResult* pResult = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM custom_texts");
+ QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM custom_texts");
outstring_log("TSCR: Loading Custom Texts additional data...");
- if (pResult)
+ if (Result)
{
- barGoLink bar(pResult->GetRowCount());
+ barGoLink bar(Result->GetRowCount());
uint32 uiCount = 0;
do
{
bar.step();
- Field* pFields = pResult->Fetch();
+ Field* pFields = Result->Fetch();
StringTextData pTemp;
int32 iId = pFields[0].GetInt32();
@@ -175,8 +173,7 @@ void SystemMgr::LoadScriptTextsCustom()
m_mTextDataMap[iId] = pTemp;
++uiCount;
- } while (pResult->NextRow());
- delete pResult;
+ } while (Result->NextRow());
outstring_log("");
outstring_log(">> Loaded %u additional Custom Texts data.", uiCount);
@@ -198,26 +195,23 @@ void SystemMgr::LoadScriptWaypoints()
uint64 uiCreatureCount = 0;
// Load Waypoints
- QueryResult* pResult = TScriptDB.PQuery("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry");
- if (pResult)
- {
- uiCreatureCount = pResult->GetRowCount();
- delete pResult;
- }
+ QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry");
+ if (Result)
+ uiCreatureCount = Result->GetRowCount();
outstring_log("TSCR: Loading Script Waypoints for %u creature(s)...", uiCreatureCount);
- pResult = TScriptDB.PQuery("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid");
+ Result = TScriptDB.PQuery("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid");
- if (pResult)
+ if (Result)
{
- barGoLink bar(pResult->GetRowCount());
+ barGoLink bar(Result->GetRowCount());
uint32 uiNodeCount = 0;
do
{
bar.step();
- Field* pFields = pResult->Fetch();
+ Field* pFields = Result->Fetch();
ScriptPointMove pTemp;
pTemp.uiCreatureEntry = pFields[0].GetUInt32();
@@ -241,9 +235,7 @@ void SystemMgr::LoadScriptWaypoints()
m_mPointMoveMap[uiEntry].push_back(pTemp);
++uiNodeCount;
- } while (pResult->NextRow());
-
- delete pResult;
+ } while (Result->NextRow());
outstring_log("");
outstring_log(">> Loaded %u Script Waypoint nodes.", uiNodeCount);
diff --git a/src/game/SkillDiscovery.cpp b/src/game/SkillDiscovery.cpp
index 280a713afa5..610e925ae31 100644
--- a/src/game/SkillDiscovery.cpp
+++ b/src/game/SkillDiscovery.cpp
@@ -55,7 +55,7 @@ void LoadSkillDiscoveryTable()
uint32 count = 0;
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template");
if (!result)
{
@@ -138,8 +138,6 @@ void LoadSkillDiscoveryTable()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u skill discovery definitions", count );
if (!ssNonDiscoverableEntries.str().empty())
diff --git a/src/game/SkillExtraItems.cpp b/src/game/SkillExtraItems.cpp
index b13db542c16..8c7dfffa871 100644
--- a/src/game/SkillExtraItems.cpp
+++ b/src/game/SkillExtraItems.cpp
@@ -59,7 +59,7 @@ void LoadSkillExtraItemTable()
SkillExtraItemStore.clear(); // need for reload
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
if (result)
{
@@ -108,8 +108,6 @@ void LoadSkillExtraItemTable()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell specialization definitions", count );
}
diff --git a/src/game/SocialMgr.cpp b/src/game/SocialMgr.cpp
index 830c3959071..c619da3178d 100644
--- a/src/game/SocialMgr.cpp
+++ b/src/game/SocialMgr.cpp
@@ -291,7 +291,7 @@ void SocialMgr::BroadcastToFriendListers(Player *player, WorldPacket *packet)
}
}
-PlayerSocial *SocialMgr::LoadFromDB(QueryResult *result, uint32 guid)
+PlayerSocial *SocialMgr::LoadFromDB(QueryResult_AutoPtr result, uint32 guid)
{
PlayerSocial *social = &m_socialMap[guid];
social->SetPlayerGUID(guid);
@@ -318,7 +318,6 @@ PlayerSocial *SocialMgr::LoadFromDB(QueryResult *result, uint32 guid)
break;
}
while (result->NextRow());
- delete result;
return social;
}
diff --git a/src/game/SocialMgr.h b/src/game/SocialMgr.h
index 4be1462c2f5..40f0066ec2e 100644
--- a/src/game/SocialMgr.h
+++ b/src/game/SocialMgr.h
@@ -151,7 +151,7 @@ class SocialMgr
void SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, bool broadcast);
void BroadcastToFriendListers(Player *player, WorldPacket *packet);
// Loading
- PlayerSocial *LoadFromDB(QueryResult *result, uint32 guid);
+ PlayerSocial *LoadFromDB(QueryResult_AutoPtr result, uint32 guid);
private:
SocialMap m_socialMap;
};
diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp
index ff9852fe7de..7abb9820d71 100644
--- a/src/game/SpellHandler.cpp
+++ b/src/game/SpellHandler.cpp
@@ -216,7 +216,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
if(pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))// wrapped?
{
- QueryResult *result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow());
if (result)
{
Field *fields = result->Fetch();
@@ -227,7 +227,6 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
pItem->SetEntry(entry);
pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags);
pItem->SetState(ITEM_CHANGED, pUser);
- delete result;
}
else
{
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 1a17bc5a301..ea98dab2c99 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -1107,7 +1107,7 @@ void SpellMgr::LoadSpellTargetPositions()
uint32 count = 0;
// 0 1 2 3 4 5
- QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
if( !result )
{
@@ -1212,8 +1212,6 @@ void SpellMgr::LoadSpellTargetPositions()
}
}
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell teleport coordinates", count );
}
@@ -1243,7 +1241,7 @@ void SpellMgr::LoadSpellProcEvents()
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9 10
- QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
if( !result )
{
barGoLink bar( 1 );
@@ -1297,8 +1295,6 @@ void SpellMgr::LoadSpellProcEvents()
++count;
} while( result->NextRow() );
- delete result;
-
sLog.outString();
if (customProc)
sLog.outString( ">> Loaded %u extra spell proc event conditions + %u custom", count, customProc );
@@ -1311,7 +1307,7 @@ void SpellMgr::LoadSpellBonusess()
mSpellBonusMap.clear(); // need for reload case
uint32 count = 0;
// 0 1 2 3 4
- QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus, ap_dot_bonus FROM spell_bonus_data");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus, ap_dot_bonus FROM spell_bonus_data");
if( !result )
{
barGoLink bar( 1 );
@@ -1346,8 +1342,6 @@ void SpellMgr::LoadSpellBonusess()
++count;
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u extra spell bonus data", count);
}
@@ -1488,7 +1482,7 @@ void SpellMgr::LoadSpellElixirs()
uint32 count = 0;
// 0 1
- QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
if( !result )
{
@@ -1525,8 +1519,6 @@ void SpellMgr::LoadSpellElixirs()
++count;
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell elixir definitions", count );
}
@@ -1538,7 +1530,7 @@ void SpellMgr::LoadSpellThreats()
uint32 count = 0;
// 0 1
- QueryResult *result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat");
if (!result)
{
@@ -1573,8 +1565,6 @@ void SpellMgr::LoadSpellThreats()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u aggro generating spells", count );
}
@@ -1776,7 +1766,7 @@ void SpellMgr::LoadSpellLearnSpells()
mSpellLearnSpells.clear(); // need for reload case
// 0 1 2
- QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
if (!result)
{
barGoLink bar(1);
@@ -1826,8 +1816,6 @@ void SpellMgr::LoadSpellLearnSpells()
++count;
} while (result->NextRow());
- delete result;
-
// search auto-learned spells and add its to map also for use in unlearn spells/talents
uint32 dbc_count = 0;
for (uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
@@ -1887,7 +1875,7 @@ void SpellMgr::LoadSpellScriptTarget()
uint32 count = 0;
- QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
if (!result)
{
@@ -1989,8 +1977,6 @@ void SpellMgr::LoadSpellScriptTarget()
++count;
} while (result->NextRow());
- delete result;
-
// Check all spells
for (uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
{
@@ -2047,7 +2033,7 @@ void SpellMgr::LoadSpellPetAuras()
uint32 count = 0;
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT spell, effectId, pet, aura FROM spell_pet_auras");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell, effectId, pet, aura FROM spell_pet_auras");
if (!result)
{
barGoLink bar(1);
@@ -2105,8 +2091,6 @@ void SpellMgr::LoadSpellPetAuras()
++count;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell pet auras", count );
}
@@ -2387,7 +2371,7 @@ void SpellMgr::LoadSpellAreas()
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8
- QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
if (!result)
{
@@ -2579,8 +2563,6 @@ void SpellMgr::LoadSpellAreas()
++count;
} while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell area requirements", count );
}
@@ -3124,7 +3106,7 @@ void SpellMgr::LoadSpellEnchantProcData()
uint32 count = 0;
// 0 1 2 3
- QueryResult *result = WorldDatabase.Query("SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data");
if (!result)
{
barGoLink bar(1);
@@ -3163,8 +3145,6 @@ void SpellMgr::LoadSpellEnchantProcData()
++count;
} while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u enchant proc data definitions", count);
}
@@ -3174,7 +3154,7 @@ void SpellMgr::LoadSpellRequired()
mSpellsReqSpell.clear(); // need for reload case
mSpellReq.clear(); // need for reload case
- QueryResult *result = WorldDatabase.Query("SELECT spell_id, req_spell from spell_required");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell_id, req_spell from spell_required");
if (!result)
{
@@ -3202,8 +3182,6 @@ void SpellMgr::LoadSpellRequired()
++rows;
} while (result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u spell required records", rows );
}
@@ -3927,7 +3905,7 @@ void SpellMgr::LoadSpellLinked()
uint32 count = 0;
// 0 1 2
- QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell");
if (!result)
{
barGoLink bar(1);
@@ -3988,8 +3966,6 @@ void SpellMgr::LoadSpellLinked()
++count;
} while( result->NextRow() );
- delete result;
-
sLog.outString();
sLog.outString( ">> Loaded %u linked spells", count );
}
diff --git a/src/game/Transports.cpp b/src/game/Transports.cpp
index f0efef5ee20..8e7eb82597e 100644
--- a/src/game/Transports.cpp
+++ b/src/game/Transports.cpp
@@ -33,7 +33,7 @@
void MapManager::LoadTransports()
{
- QueryResult *result = WorldDatabase.Query("SELECT entry, name, period FROM transports");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, name, period FROM transports");
uint32 count = 0;
@@ -111,7 +111,6 @@ void MapManager::LoadTransports()
//t->GetMap()->Add<GameObject>((GameObject *)t);
++count;
} while(result->NextRow());
- delete result;
sLog.outString();
sLog.outString( ">> Loaded %u transports", count );
@@ -130,8 +129,6 @@ void MapManager::LoadTransports()
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());
-
- delete result;
}
}
diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp
index f4d14eb00d1..61d2b041092 100644
--- a/src/game/WaypointManager.cpp
+++ b/src/game/WaypointManager.cpp
@@ -34,7 +34,7 @@ void WaypointStore::Free()
void WaypointStore::Load()
{
- QueryResult *result = WorldDatabase.PQuery("SELECT COUNT(id) FROM waypoint_data");
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT COUNT(id) FROM waypoint_data");
if (!result)
{
sLog.outError("an error occured while loading the table `waypoint_data` (maybe it doesn't exist ?)");
@@ -42,7 +42,6 @@ void WaypointStore::Load()
}
records = (*result)[0].GetUInt32();
- delete result;
result = WorldDatabase.PQuery("SELECT id,point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data ORDER BY id, point");
if(!result)
@@ -96,7 +95,6 @@ void WaypointStore::Load()
} while(result->NextRow()) ;
- delete result;
sLog.outString();
sLog.outString(">> Loaded %u waypoints", count);
}
@@ -106,7 +104,7 @@ void WaypointStore::UpdatePath(uint32 id)
if(waypoint_map.find(id)!= waypoint_map.end())
waypoint_map[id]->clear();
- QueryResult *result;
+ QueryResult_AutoPtr result;
result = WorldDatabase.PQuery("SELECT id,point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data WHERE id = %u ORDER BY point", id);
@@ -147,7 +145,5 @@ void WaypointStore::UpdatePath(uint32 id)
while (result->NextRow());
waypoint_map[id] = path_data;
-
- delete result;
}
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 7779fbdee6c..9c68dca848f 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1748,7 +1748,7 @@ void World::LoadAutobroadcasts()
{
m_Autobroadcasts.clear();
- QueryResult *result = WorldDatabase.Query("SELECT text FROM autobroadcast");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT text FROM autobroadcast");
if (!result)
{
@@ -1777,8 +1777,6 @@ void World::LoadAutobroadcasts()
count++;
} while(result->NextRow());
- delete result;
-
sLog.outString();
sLog.outString(">> Loaded %u autobroadcasts definitions", count);
}
@@ -2154,7 +2152,7 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
loginDatabase.escape_string(safe_author);
uint32 duration_secs = TimeStringToSecs(duration);
- QueryResult *resultAccounts = NULL; //used for kicking
+ QueryResult_AutoPtr resultAccounts = QueryResult_AutoPtr(NULL); //used for kicking
///- Update the database with ban information
switch(mode)
@@ -2203,7 +2201,6 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
}
while(resultAccounts->NextRow());
- delete resultAccounts;
return BAN_SUCCESS;
}
@@ -2449,13 +2446,13 @@ void World::UpdateRealmCharCount(uint32 accountId)
"SELECT COUNT(guid) FROM characters WHERE account = '%u'", accountId);
}
-void World::_UpdateRealmCharCount(QueryResult *resultCharCount, uint32 accountId)
+void World::_UpdateRealmCharCount(QueryResult_AutoPtr resultCharCount, uint32 accountId)
{
if (resultCharCount)
{
Field *fields = resultCharCount->Fetch();
uint32 charCount = fields[0].GetUInt32();
- delete resultCharCount;
+
loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", accountId, realmID);
loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charCount, accountId, realmID);
}
@@ -2465,13 +2462,12 @@ void World::InitDailyQuestResetTime()
{
time_t mostRecentQuestTime;
- QueryResult* result = CharacterDatabase.Query("SELECT MAX(time) FROM character_queststatus_daily");
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(time) FROM character_queststatus_daily");
if (result)
{
Field *fields = result->Fetch();
mostRecentQuestTime = (time_t)fields[0].GetUInt64();
- delete result;
}
else
mostRecentQuestTime = 0;
@@ -2511,12 +2507,11 @@ void World::ResetDailyQuests()
void World::UpdateAllowedSecurity()
{
- QueryResult *result = loginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID);
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID);
if (result)
{
m_allowedSecurityLevel = AccountTypes(result->Fetch()->GetUInt16());
sLog.outDebug("Allowed Level: %u Result %u", m_allowedSecurityLevel, result->Fetch()->GetUInt16());
- delete result;
}
}
@@ -2533,7 +2528,7 @@ void World::UpdateMaxSessionCounters()
void World::LoadDBVersion()
{
- QueryResult* result = WorldDatabase.Query("SELECT db_version, script_version, cache_id FROM version LIMIT 1");
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT db_version, script_version, cache_id FROM version LIMIT 1");
//QueryResult* result = WorldDatabase.Query("SELECT version, creature_ai_version, cache_id FROM db_version LIMIT 1");
if (result)
{
@@ -2544,7 +2539,6 @@ void World::LoadDBVersion()
// will be overwrite by config values if different and non-0
m_configs[CONFIG_CLIENTCACHE_VERSION] = fields[2].GetUInt32();
- delete result;
}
if (m_DBVersion.empty())
diff --git a/src/game/World.h b/src/game/World.h
index 7fdd520a2dc..68684e1896b 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -30,6 +30,7 @@
#include "Policies/Singleton.h"
#include "SharedDefines.h"
#include "ace/Atomic_Op.h"
+#include "QueryResult.h"
#include <map>
#include <set>
@@ -645,7 +646,7 @@ class World
protected:
void _UpdateGameTime();
// callback for UpdateRealmCharacters
- void _UpdateRealmCharCount(QueryResult *resultCharCount, uint32 accountId);
+ void _UpdateRealmCharCount(QueryResult_AutoPtr resultCharCount, uint32 accountId);
void InitDailyQuestResetTime();
void ResetDailyQuests();
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
index 7b7dac2c31b..c87421e4d59 100644
--- a/src/game/WorldSession.cpp
+++ b/src/game/WorldSession.cpp
@@ -566,7 +566,7 @@ void WorldSession::LoadGlobalAccountData()
);
}
-void WorldSession::LoadAccountData(QueryResult* result, uint32 mask)
+void WorldSession::LoadAccountData(QueryResult_AutoPtr result, uint32 mask)
{
for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i)
if (mask & (1 << i))
@@ -598,8 +598,6 @@ void WorldSession::LoadAccountData(QueryResult* result, uint32 mask)
m_accountData[type].Data = fields[2].GetCppString();
} while (result->NextRow());
-
- delete result;
}
void WorldSession::SetAccountData(AccountDataType type, time_t time_, std::string data)
@@ -648,7 +646,7 @@ void WorldSession::LoadTutorialsData()
for (int aX = 0 ; aX < 8 ; ++aX )
m_Tutorials[ aX ] = 0;
- QueryResult *result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u'", GetAccountId());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u'", GetAccountId());
if(result)
{
@@ -660,10 +658,7 @@ void WorldSession::LoadTutorialsData()
m_Tutorials[iI] = fields[iI].GetUInt32();
}
while( result->NextRow() );
-
- delete result;
}
-
m_TutorialsChanged = false;
}
@@ -682,12 +677,9 @@ void WorldSession::SaveTutorialsData()
uint32 Rows=0;
// it's better than rebuilding indexes multiple times
- QueryResult *result = CharacterDatabase.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u'", GetAccountId());
+ QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u'", GetAccountId());
if(result)
- {
Rows = result->Fetch()[0].GetUInt32();
- delete result;
- }
if (Rows)
{
diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
index 6a6121385b7..40021262fd1 100644
--- a/src/game/WorldSession.h
+++ b/src/game/WorldSession.h
@@ -28,6 +28,7 @@
#include "Common.h"
#include "SharedDefines.h"
#include "AddonMgr.h"
+#include "QueryResult.h"
struct ItemPrototype;
struct AuctionEntry;
@@ -162,7 +163,7 @@ class TRINITY_DLL_SPEC WorldSession
//void SendTestCreatureQueryOpcode( uint32 entry, uint64 guid, uint32 testvalue );
void SendNameQueryOpcode(Player* p);
void SendNameQueryOpcodeFromDB(uint64 guid);
- static void SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 accountId);
+ static void SendNameQueryOpcodeFromDBCallBack(QueryResult_AutoPtr result, uint32 accountId);
void SendTrainerList( uint64 guid );
void SendTrainerList( uint64 guid, const std::string& strTitle );
@@ -191,7 +192,7 @@ class TRINITY_DLL_SPEC WorldSession
void SetAccountData(AccountDataType type, time_t time_, std::string data);
void SendAccountDataTimes(uint32 mask);
void LoadGlobalAccountData();
- void LoadAccountData(QueryResult* result, uint32 mask);
+ void LoadAccountData(QueryResult_AutoPtr result, uint32 mask);
void LoadTutorialsData();
void SendTutorialsData();
void SaveTutorialsData();
@@ -269,7 +270,7 @@ class TRINITY_DLL_SPEC WorldSession
void HandleCharDeleteOpcode(WorldPacket& recvPacket);
void HandleCharCreateOpcode(WorldPacket& recvPacket);
void HandlePlayerLoginOpcode(WorldPacket& recvPacket);
- void HandleCharEnum(QueryResult * result);
+ void HandleCharEnum(QueryResult_AutoPtr result);
void HandlePlayerLogin(LoginQueryHolder * holder);
// played time
@@ -338,10 +339,10 @@ class TRINITY_DLL_SPEC WorldSession
void HandleEmoteOpcode(WorldPacket& recvPacket);
void HandleContactListOpcode(WorldPacket& recvPacket);
void HandleAddFriendOpcode(WorldPacket& recvPacket);
- static void HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote);
+ static void HandleAddFriendOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string friendNote);
void HandleDelFriendOpcode(WorldPacket& recvPacket);
void HandleAddIgnoreOpcode(WorldPacket& recvPacket);
- static void HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId);
+ static void HandleAddIgnoreOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId);
void HandleDelIgnoreOpcode(WorldPacket& recvPacket);
void HandleSetContactNotesOpcode(WorldPacket& recvPacket);
void HandleBugOpcode(WorldPacket& recvPacket);
@@ -610,7 +611,7 @@ class TRINITY_DLL_SPEC WorldSession
void HandleSetActionBarToggles(WorldPacket& recv_data);
void HandleCharRenameOpcode(WorldPacket& recv_data);
- static void HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname);
+ static void HandleChangePlayerNameOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string newname);
void HandleSetPlayerDeclinedNames(WorldPacket& recv_data);
void HandleTotemDestroyed(WorldPacket& recv_data);
diff --git a/src/game/WorldSocket.cpp b/src/game/WorldSocket.cpp
index 3480fd57718..af6ddd4f0e5 100644
--- a/src/game/WorldSocket.cpp
+++ b/src/game/WorldSocket.cpp
@@ -738,7 +738,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
loginDatabase.escape_string (safe_account);
// No SQL injection, username escaped.
- QueryResult *result =
+ QueryResult_AutoPtr result =
loginDatabase.PQuery ("SELECT "
"id, " //0
"sessionkey, " //1
@@ -798,7 +798,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
packet << uint8 (AUTH_FAILED);
SendPacket (packet);
- delete result;
sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs).");
return -1;
}
@@ -818,8 +817,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
if (locale >= MAX_LOCALE)
locale = LOCALE_enUS;
- delete result;
-
// Checks gmlevel per Realm
result =
loginDatabase.PQuery ("SELECT "
@@ -836,11 +833,10 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
{
fields = result->Fetch ();
security = fields[1].GetInt32();
- delete result;
}
// Re-check account ban (same check as in realmd)
- QueryResult *banresult =
+ QueryResult_AutoPtr banresult =
loginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 "
"UNION "
"SELECT 1 FROM ip_banned WHERE ip = '%s'",
@@ -852,8 +848,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
packet << uint8 (AUTH_BANNED);
SendPacket (packet);
- delete banresult;
-
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
return -1;
}
diff --git a/src/shared/Database/DBCStore.h b/src/shared/Database/DBCStore.h
index ea4ce109e27..4344b6e6450 100644
--- a/src/shared/Database/DBCStore.h
+++ b/src/shared/Database/DBCStore.h
@@ -83,7 +83,7 @@ class DBCStorage
uint32 sqlRecordCount = 0;
uint32 sqlHighestIndex = 0;
Field *fields = NULL;
- QueryResult *result = NULL;
+ QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL);
// Load data from sql
if (sql)
{
@@ -188,7 +188,6 @@ class DBCStorage
break;
case FT_STRING:
sLog.outError("Unsupported data type in table '%s' at char %d", sql->sqlTableName.c_str(), columnNumber);
- delete result;
return false;
case FT_SORT:
break;
@@ -201,14 +200,12 @@ class DBCStorage
else
{
sLog.outError("Incorrect sql format string '%s' at char %d", sql->sqlTableName.c_str(), columnNumber);
- delete result;
return false;
}
}
if (sqlColumnNumber != (result->GetFieldCount()-1))
{
sLog.outError("SQL and DBC format strings are not matching for table: '%s'", sql->sqlTableName.c_str());
- delete result;
return false;
}
@@ -216,7 +213,6 @@ class DBCStorage
++rowIndex;
}while (result->NextRow());
}
- delete result;
}
// error in dbc file at loading if NULL
diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp
index ac2cdfa4163..da214e71650 100644
--- a/src/shared/Database/Database.cpp
+++ b/src/shared/Database/Database.cpp
@@ -117,9 +117,9 @@ void Database::SetResultQueue(SqlResultQueue * queue)
}
-QueryResult* Database::PQuery(const char *format,...)
+QueryResult_AutoPtr Database::PQuery(const char *format,...)
{
- if(!format) return NULL;
+ if(!format) return QueryResult_AutoPtr(NULL);
va_list ap;
char szQuery [MAX_QUERY_LEN];
@@ -130,7 +130,7 @@ QueryResult* Database::PQuery(const char *format,...)
if(res==-1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
- return false;
+ return QueryResult_AutoPtr(NULL);
}
return Query(szQuery);
@@ -217,12 +217,9 @@ bool Database::DirectPExecute(const char * format,...)
bool Database::CheckRequiredField( char const* table_name, char const* required_name )
{
// check required field
- QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
+ QueryResult_AutoPtr result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
if(result)
- {
- delete result;
return true;
- }
// check fail, prepare readabale error message
diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h
index 804501cd7f9..e1b44c99057 100644
--- a/src/shared/Database/Database.h
+++ b/src/shared/Database/Database.h
@@ -52,8 +52,8 @@ class TRINITY_DLL_SPEC Database
virtual void InitDelayThread() = 0;
virtual void HaltDelayThread() = 0;
- virtual QueryResult* Query(const char *sql) = 0;
- QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3);
+ virtual QueryResult_AutoPtr Query(const char *sql) = 0;
+ QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2,3);
virtual QueryNamedResult* QueryNamed(const char *sql) = 0;
QueryNamedResult* PQueryNamed(const char *format,...) ATTR_PRINTF(2,3);
@@ -61,41 +61,41 @@ class TRINITY_DLL_SPEC Database
// Query / member
template<class Class>
- bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
+ bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql);
template<class Class, typename ParamType1>
- bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
+ bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql);
template<class Class, typename ParamType1, typename ParamType2>
- bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
+ bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
+ bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
// Query / static
template<typename ParamType1>
- bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
+ bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql);
template<typename ParamType1, typename ParamType2>
- bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
+ bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
template<typename ParamType1, typename ParamType2, typename ParamType3>
- bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
+ bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
// PQuery / member
template<class Class>
- bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
+ bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...) ATTR_PRINTF(4,5);
template<class Class, typename ParamType1>
- bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
+ bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
template<class Class, typename ParamType1, typename ParamType2>
- bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7);
+ bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7);
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8);
+ bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8);
// PQuery / static
template<typename ParamType1>
- bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5);
+ bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5);
template<typename ParamType1, typename ParamType2>
- bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
+ bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
template<typename ParamType1, typename ParamType2, typename ParamType3>
- bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7);
+ bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7);
template<class Class>
// QueryHolder
- bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder);
+ bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder);
template<class Class, typename ParamType1>
- bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1);
+ bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1);
virtual bool Execute(const char *sql) = 0;
bool PExecute(const char *format,...) ATTR_PRINTF(2,3);
diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h
index 01ee52065fa..d77b16c8ea6 100644
--- a/src/shared/Database/DatabaseImpl.h
+++ b/src/shared/Database/DatabaseImpl.h
@@ -68,7 +68,7 @@
template<class Class>
bool
-Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
+Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second));
@@ -76,59 +76,59 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const c
template<class Class, typename ParamType1>
bool
-Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
+Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, param1), itr->second));
}
template<class Class, typename ParamType1, typename ParamType2>
bool
-Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
+Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
}
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
+Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
}
// -- Query / static --
template<typename ParamType1>
bool
-Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
+Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult_AutoPtr)NULL, param1), itr->second));
}
template<typename ParamType1, typename ParamType2>
bool
-Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
+Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
}
template<typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
+Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
{
ASYNC_QUERY_BODY(sql, itr)
- return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), itr->second));
+ return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
}
// -- PQuery / member --
template<class Class>
bool
-Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, szQuery);
@@ -136,7 +136,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const
template<class Class, typename ParamType1>
bool
-Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, szQuery);
@@ -144,7 +144,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
template<class Class, typename ParamType1, typename ParamType2>
bool
-Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, param2, szQuery);
@@ -152,7 +152,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, param2, param3, szQuery);
@@ -162,7 +162,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
template<typename ParamType1>
bool
-Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
+Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, szQuery);
@@ -170,7 +170,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param
template<typename ParamType1, typename ParamType2>
bool
-Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
+Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, param2, szQuery);
@@ -178,7 +178,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), Para
template<typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
+Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, param2, param3, szQuery);
@@ -188,18 +188,18 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, Param
template<class Class>
bool
-Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder)
+Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder)
{
ASYNC_DELAYHOLDER_BODY(holder, itr)
- return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
+ return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult_AutoPtr)NULL, holder), m_threadBody, itr->second);
}
template<class Class, typename ParamType1>
bool
-Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
+Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
{
ASYNC_DELAYHOLDER_BODY(holder, itr)
- return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second);
+ return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, holder, param1), m_threadBody, itr->second);
}
#undef ASYNC_QUERY_BODY
diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp
index 6412ed9312f..cc94ca3540d 100644
--- a/src/shared/Database/DatabaseMysql.cpp
+++ b/src/shared/Database/DatabaseMysql.cpp
@@ -235,7 +235,7 @@ bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **p
return true;
}
-QueryResult* DatabaseMysql::Query(const char *sql)
+QueryResult_AutoPtr DatabaseMysql::Query(const char *sql)
{
MYSQL_RES *result = NULL;
MYSQL_FIELD *fields = NULL;
@@ -243,13 +243,13 @@ QueryResult* DatabaseMysql::Query(const char *sql)
uint32 fieldCount = 0;
if(!_Query(sql,&result,&fields,&rowCount,&fieldCount))
- return NULL;
+ return QueryResult_AutoPtr(NULL);
QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
queryResult->NextRow();
- return queryResult;
+ return QueryResult_AutoPtr(queryResult);
}
QueryNamedResult* DatabaseMysql::QueryNamed(const char *sql)
diff --git a/src/shared/Database/DatabaseMysql.h b/src/shared/Database/DatabaseMysql.h
index d4e440f96f6..4f7ab2b88b7 100644
--- a/src/shared/Database/DatabaseMysql.h
+++ b/src/shared/Database/DatabaseMysql.h
@@ -49,7 +49,7 @@ class TRINITY_DLL_SPEC DatabaseMysql : public Database
bool Initialize(const char *infoString);
void InitDelayThread();
void HaltDelayThread();
- QueryResult* Query(const char *sql);
+ QueryResult_AutoPtr Query(const char *sql);
QueryNamedResult* QueryNamed(const char *sql);
bool Execute(const char *sql);
bool DirectExecute(const char* sql);
diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp
index 983932dc03d..a1283538b20 100644
--- a/src/shared/Database/DatabasePostgre.cpp
+++ b/src/shared/Database/DatabasePostgre.cpp
@@ -158,22 +158,22 @@ bool DatabasePostgre::_Query(const char *sql, PGresult** pResult, uint64* pRowCo
return true;
}
-QueryResult* DatabasePostgre::Query(const char *sql)
+QueryResult_AutoPtr DatabasePostgre::Query(const char *sql)
{
if (!mPGconn)
- return 0;
+ return QueryResult_AutoPtr(NULL);
PGresult* result = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
if(!_Query(sql,&result,&rowCount,&fieldCount))
- return NULL;
+ return QueryResult_AutoPtr(NULL);
QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
queryResult->NextRow();
- return queryResult;
+ return QueryResult_AutoPtr(queryResult);
}
QueryNamedResult* DatabasePostgre::QueryNamed(const char *sql)
diff --git a/src/shared/Database/DatabasePostgre.h b/src/shared/Database/DatabasePostgre.h
index fcd420ef8e4..cd93f416bfe 100644
--- a/src/shared/Database/DatabasePostgre.h
+++ b/src/shared/Database/DatabasePostgre.h
@@ -45,7 +45,7 @@ class DatabasePostgre : public Database
bool Initialize(const char *infoString);
void InitDelayThread();
void HaltDelayThread();
- QueryResult* Query(const char *sql);
+ QueryResult_AutoPtr Query(const char *sql);
QueryNamedResult* QueryNamed(const char *sql);
bool Execute(const char *sql);
bool DirectExecute(const char* sql);
diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h
index a0c77752300..f9488f5a030 100644
--- a/src/shared/Database/QueryResult.h
+++ b/src/shared/Database/QueryResult.h
@@ -21,6 +21,11 @@
#if !defined(QUERYRESULT_H)
#define QUERYRESULT_H
+#include <ace/Refcounted_Auto_Ptr.h>
+#include <ace/Null_Mutex.h>
+
+#include "Field.h"
+
class TRINITY_DLL_SPEC QueryResult
{
public:
@@ -44,6 +49,8 @@ class TRINITY_DLL_SPEC QueryResult
uint64 mRowCount;
};
+typedef ACE_Refcounted_Auto_Ptr<QueryResult, ACE_Null_Mutex> QueryResult_AutoPtr;
+
typedef std::vector<std::string> QueryFieldNames;
class TRINITY_DLL_SPEC QueryNamedResult
diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h
index 5ad8a66679a..c74be48c34c 100644
--- a/src/shared/Database/SQLStorageImpl.h
+++ b/src/shared/Database/SQLStorageImpl.h
@@ -122,7 +122,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
{
uint32 maxi;
Field *fields;
- QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
+ QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
if(!result)
{
sLog.outError("Error loading %s table (not exist?)\n", store.table);
@@ -130,14 +130,12 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
}
maxi = (*result)[0].GetUInt32()+1;
- delete result;
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
if(result)
{
fields = result->Fetch();
store.RecordCount = fields[0].GetUInt32();
- delete result;
}
else
store.RecordCount = 0;
@@ -158,7 +156,6 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
{
store.RecordCount = 0;
sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields);
- delete result;
exit(1); // Stop server at loading broken or non-compatible table.
}
@@ -206,8 +203,6 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
++count;
}while( result->NextRow() );
- delete result;
-
store.pIndex = newIndex;
store.MaxEntry = maxi;
store.data = _data;
diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp
index 1012c94cbdd..793fabecde7 100644
--- a/src/shared/Database/SqlOperations.cpp
+++ b/src/shared/Database/SqlOperations.cpp
@@ -109,7 +109,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
}
/// not executed yet, just stored (it's not called a holder for nothing)
- m_queries[index] = SqlResultPair(strdup(sql), NULL);
+ m_queries[index] = SqlResultPair(strdup(sql), QueryResult_AutoPtr(NULL));
return true;
}
@@ -136,7 +136,7 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
return SetQuery(index,szQuery);
}
-QueryResult* SqlQueryHolder::GetResult(size_t index)
+QueryResult_AutoPtr SqlQueryHolder::GetResult(size_t index)
{
if(index < m_queries.size())
{
@@ -150,10 +150,10 @@ QueryResult* SqlQueryHolder::GetResult(size_t index)
return m_queries[index].second;
}
else
- return NULL;
+ return QueryResult_AutoPtr(NULL);
}
-void SqlQueryHolder::SetResult(size_t index, QueryResult *result)
+void SqlQueryHolder::SetResult(size_t index, QueryResult_AutoPtr result)
{
/// store the result in the holder
if(index < m_queries.size())
@@ -167,11 +167,7 @@ SqlQueryHolder::~SqlQueryHolder()
/// if the result was never used, free the resources
/// results used already (getresult called) are expected to be deleted
if(m_queries[i].first != NULL)
- {
free((void*)(const_cast<char*>(m_queries[i].first)));
- if(m_queries[i].second)
- delete m_queries[i].second;
- }
}
}
diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h
index acaffb29c70..18641c743e1 100644
--- a/src/shared/Database/SqlOperations.h
+++ b/src/shared/Database/SqlOperations.h
@@ -27,6 +27,7 @@
#include "LockedQueue.h"
#include <queue>
#include "Utilities/Callback.h"
+#include "QueryResult.h"
/// ---- BASE ---
@@ -95,7 +96,7 @@ class SqlQueryHolder
{
friend class SqlQueryHolderEx;
private:
- typedef std::pair<const char*, QueryResult*> SqlResultPair;
+ typedef std::pair<const char*, QueryResult_AutoPtr> SqlResultPair;
std::vector<SqlResultPair> m_queries;
public:
SqlQueryHolder() {}
@@ -103,8 +104,8 @@ class SqlQueryHolder
bool SetQuery(size_t index, const char *sql);
bool SetPQuery(size_t index, const char *format, ...) ATTR_PRINTF(3,4);
void SetSize(size_t size);
- QueryResult* GetResult(size_t index);
- void SetResult(size_t index, QueryResult *result);
+ QueryResult_AutoPtr GetResult(size_t index);
+ void SetResult(size_t index, QueryResult_AutoPtr result);
bool Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
};
diff --git a/src/trinitycore/CliRunnable.cpp b/src/trinitycore/CliRunnable.cpp
index e074594de72..4549ffcf03e 100644
--- a/src/trinitycore/CliRunnable.cpp
+++ b/src/trinitycore/CliRunnable.cpp
@@ -215,7 +215,7 @@ bool ChatHandler::HandleServerExitCommand(const char* /*args*/)
bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
{
///- Get the list of accounts ID logged to the realm
- QueryResult *resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0");
+ QueryResult_AutoPtr resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0");
if (!resultDB)
{
SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
@@ -236,7 +236,7 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
- QueryResult *resultLogin =
+ QueryResult_AutoPtr resultLogin =
loginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion "
"FROM account a "
"LEFT JOIN account_access aa "
@@ -247,16 +247,12 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
Field *fieldsLogin = resultLogin->Fetch();
PSendSysMessage(LANG_ACCOUNT_LIST_LINE,
fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsLogin[2].GetUInt32(),fieldsLogin[3].GetUInt32());
-
- delete resultLogin;
}
else
PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
}while(resultDB->NextRow());
- delete resultDB;
-
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp
index 221ce4967a9..41169565565 100644
--- a/src/trinitycore/Master.cpp
+++ b/src/trinitycore/Master.cpp
@@ -135,9 +135,9 @@ public:
{
loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive");
- delete WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
- delete loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
- delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
+ WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
+ loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
+ CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
diff --git a/src/trinitycore/RASocket.cpp b/src/trinitycore/RASocket.cpp
index bed7fbf57ca..a55af0e270a 100644
--- a/src/trinitycore/RASocket.cpp
+++ b/src/trinitycore/RASocket.cpp
@@ -154,7 +154,7 @@ void RASocket::OnRead()
///- Escape the Login to allow quotes in names
loginDatabase.escape_string(login);
- QueryResult* result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ());
///- If the user is not found, deny access
if(!result)
@@ -187,7 +187,6 @@ void RASocket::OnRead()
{
stage=LG;
}
- delete result;
}
}
break;
@@ -204,13 +203,12 @@ void RASocket::OnRead()
loginDatabase.escape_string(login);
loginDatabase.escape_string(pw);
- QueryResult *check = loginDatabase.PQuery(
+ QueryResult_AutoPtr check = loginDatabase.PQuery(
"SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT('%s',':','%s'))",
login.c_str(), login.c_str(), pw.c_str());
if(check)
{
- delete check;
r=GetSocket();
stage=OK;
++iUsers;
diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp
index f9aa40af629..b5fe5f040c1 100644
--- a/src/trinityrealm/AuthSocket.cpp
+++ b/src/trinityrealm/AuthSocket.cpp
@@ -399,12 +399,11 @@ bool AuthSocket::_HandleLogonChallenge()
std::string address = GetRemoteAddress();
loginDatabase.escape_string(address);
- QueryResult *result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str());
if (result)
{
pkt << (uint8)REALM_AUTH_ACCOUNT_BANNED;
sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!",GetRemoteAddress().c_str ());
- delete result;
}
else
{
@@ -446,7 +445,7 @@ bool AuthSocket::_HandleLogonChallenge()
//set expired bans to inactive
loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
///- If the account is banned, reject the logon attempt
- QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32());
+ QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32());
if (banresult)
{
if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64())
@@ -459,8 +458,6 @@ bool AuthSocket::_HandleLogonChallenge()
pkt << (uint8) REALM_AUTH_ACCOUNT_FREEZED;
sLog.outBasic("[AuthChallenge] Temporarily banned account %s tries to login!",_login.c_str ());
}
-
- delete banresult;
}
else
{
@@ -535,7 +532,6 @@ bool AuthSocket::_HandleLogonChallenge()
sLog.outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName));
}
}
- delete result;
}
else //no account
{
@@ -737,7 +733,7 @@ bool AuthSocket::_HandleLogonProof()
//Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP
loginDatabase.PExecute("UPDATE account SET failed_logins = failed_logins + 1 WHERE username = '%s'",_safelogin.c_str());
- if (QueryResult *loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str()))
+ if (QueryResult_AutoPtr loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str()))
{
Field* fields = loginfail->Fetch();
uint32 failed_logins = fields[1].GetUInt32();
@@ -765,7 +761,6 @@ bool AuthSocket::_HandleLogonProof()
current_ip.c_str(), WrongPassBanTime, _login.c_str(), failed_logins);
}
}
- delete loginfail;
}
}
}
@@ -805,7 +800,7 @@ bool AuthSocket::_HandleReconnectChallenge()
_login = (const char*)ch->I;
_safelogin = _login;
- QueryResult *result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ());
+ QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ());
// Stop if the account is not found
if (!result)
@@ -817,7 +812,6 @@ bool AuthSocket::_HandleReconnectChallenge()
Field* fields = result->Fetch ();
K.SetHexStr (fields[0].GetString ());
- delete result;
///- Sending response
ByteBuffer pkt;
@@ -885,7 +879,7 @@ bool AuthSocket::_HandleRealmList()
///- Get the user id (else close the connection)
// No SQL injection (escaped user name)
- QueryResult *result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str());
+ QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str());
if (!result)
{
sLog.outError("[ERROR] user %s tried to login and we cannot find him in the database.",_login.c_str());
@@ -895,7 +889,6 @@ bool AuthSocket::_HandleRealmList()
uint32 id = (*result)[0].GetUInt32();
std::string rI = (*result)[1].GetCppString();
- delete result;
///- Update realm list if need
m_realmList.UpdateIfNeed();
@@ -935,7 +928,6 @@ bool AuthSocket::_HandleRealmList()
{
Field *fields = result->Fetch();
AmountOfCharacters = fields[0].GetUInt8();
- delete result;
}
else
AmountOfCharacters = 0;
diff --git a/src/trinityrealm/Main.cpp b/src/trinityrealm/Main.cpp
index 9b94c61afe2..68e200969e3 100644
--- a/src/trinityrealm/Main.cpp
+++ b/src/trinityrealm/Main.cpp
@@ -288,7 +288,7 @@ extern int main(int argc, char **argv)
{
loopCounter = 0;
sLog.outDetail("Ping MySQL to keep connection alive");
- delete loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1");
+ loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1");
}
#ifdef WIN32
if (m_ServiceStatus == 0) stopEvent = true;
diff --git a/src/trinityrealm/RealmList.cpp b/src/trinityrealm/RealmList.cpp
index a04a4fd7bfb..5a441de8012 100644
--- a/src/trinityrealm/RealmList.cpp
+++ b/src/trinityrealm/RealmList.cpp
@@ -83,7 +83,7 @@ void RealmList::UpdateRealms(bool init)
{
sLog.outDetail("Updating Realm List...");
- QueryResult *result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name");
+ QueryResult_AutoPtr result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name");
///- Circle through results and add them to the realm map
if (result)
@@ -98,6 +98,5 @@ void RealmList::UpdateRealms(bool init)
if (init)
sLog.outString("Added realm \"%s\".", fields[1].GetString());
} while(result->NextRow());
- delete result;
}
}