refactor(db): use std::unique_ptr for DirectQuery
This commit is contained in:
@@ -32,7 +32,7 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
"SELECT id, pid1, pid2, pid3, pid4 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
auto msg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (msg->Get()->uiNumRows == 0)
|
||||
{
|
||||
@@ -55,13 +55,12 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
// 한 캐릭터라도 길드에 가입 되어 있다면, 제국 이동을 할 수 없다.
|
||||
DWORD dwGuildID[4];
|
||||
CGuild * pGuild[4];
|
||||
SQLMsg * pMsg = NULL;
|
||||
|
||||
for (int i = 0; i < loop; ++i)
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT guild_id FROM guild_member%s WHERE pid=%u", get_table_postfix(), dwPID[i]);
|
||||
|
||||
pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
auto pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
@@ -75,7 +74,6 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
|
||||
if (pGuild[i] != NULL)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -84,8 +82,6 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
dwGuildID[i] = 0;
|
||||
pGuild[i] = NULL;
|
||||
}
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +101,7 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
auto msg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (msg->Get()->uiAffectedRows > 0)
|
||||
{
|
||||
@@ -129,13 +125,12 @@ int CHARACTER::GetChangeEmpireCount() const
|
||||
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT change_count FROM change_empire WHERE account_id = %u", dwAID);
|
||||
|
||||
SQLMsg * pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
auto pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,8 +139,6 @@ int CHARACTER::GetChangeEmpireCount() const
|
||||
DWORD count = 0;
|
||||
str_to_number(count, row[0]);
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -173,7 +166,7 @@ void CHARACTER::SetChangeEmpireCount()
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE change_empire SET change_count=%d WHERE account_id=%u", count, dwAID);
|
||||
}
|
||||
|
||||
std::unique_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery(szQuery));
|
||||
DBManager::instance().DirectQuery(szQuery);
|
||||
}
|
||||
|
||||
DWORD CHARACTER::GetAID() const
|
||||
@@ -184,22 +177,17 @@ DWORD CHARACTER::GetAID() const
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
SQLMsg* pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
auto pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
if (pMsg)
|
||||
{
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
|
||||
|
||||
str_to_number(dwAID, row[0]);
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
|
||||
return dwAID;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user