mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 10:05:32 +01:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user