Core/DBLayer: Convert PQuery() queries to prepared statements

This commit is contained in:
leak committed 2012-03-24 01:25:08 +01:00
1 parent 8e96b86715
commit 12e55a04bb
37 files changed
+1037 -457

No files matched your search

+17 -11
View File
@@ -194,8 +194,11 @@ public:
static bool HandleAccountOnlineListCommand(ChatHandler* handler, char const* /*args*/)
{
///- Get the list of accounts ID logged to the realm
QueryResult resultDB = CharacterDatabase.Query("SELECT name, account, map, zone FROM characters WHERE online > 0");
if (!resultDB)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_ONLINE);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
handler->SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
return true;
@@ -209,18 +212,15 @@ public:
///- Cycle through accounts
do
{
Field* fieldsDB = resultDB->Fetch();
Field* fieldsDB = result->Fetch();
std::string name = fieldsDB[0].GetString();
uint32 account = fieldsDB[1].GetUInt32();
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
QueryResult resultLogin =
LoginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion "
"FROM account a "
"LEFT JOIN account_access aa "
"ON (a.id = aa.id) "
"WHERE a.id = '%u'", account);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO);
stmt->setUInt32(0, account);
PreparedQueryResult resultLogin = LoginDatabase.Query(stmt);
if (resultLogin)
{
@@ -233,7 +233,7 @@ public:
else
handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR, name.c_str());
} while (resultDB->NextRow());
} while (result->NextRow());
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
@@ -469,7 +469,13 @@ public:
// 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 && !AccountMgr::IsConsoleAccount(playerSecurity))
{
QueryResult result = LoginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST);
stmt->setUInt32(0, targetAccountId);
stmt->setUInt8(1, uint8(gm));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);