Core/DBLayer: Convert PQuery() queries to prepared statements
This commit is contained in:
1 parent
8e96b86715
commit
12e55a04bb
37 files changed
+1037
-457
No files matched your search
@@ -4787,7 +4787,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 guid FROM group_member WHERE memberGuid=%u", guid);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER);
|
||||
stmt->setUInt32(0, guid);
|
||||
PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (resultGroup)
|
||||
if (Group* group = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32()))
|
||||
RemoveFromGroup(group, playerguid);
|
||||
@@ -4801,8 +4804,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
||||
case CHAR_DELETE_REMOVE:
|
||||
{
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
// 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, body, money, has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_COD_ITEM_MAIL);
|
||||
stmt->setUInt32(0, guid);
|
||||
PreparedQueryResult resultMail = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (resultMail)
|
||||
{
|
||||
do
|
||||
@@ -4882,7 +4888,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
||||
|
||||
// Unsummon and delete for pets in world is not required: player deleted from CLI or character list with not loaded pet.
|
||||
// NOW we can finally clear other DB data related to character
|
||||
if (QueryResult resultPets = CharacterDatabase.PQuery("SELECT id FROM character_pet WHERE owner = '%u'", guid))
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PETS);
|
||||
stmt->setUInt32(0, guid);
|
||||
PreparedQueryResult resultPets = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (resultPets)
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -4892,7 +4902,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
||||
}
|
||||
|
||||
// Delete char from social list of online chars
|
||||
if (QueryResult resultFriends = CharacterDatabase.PQuery("SELECT DISTINCT guid FROM character_social WHERE friend = '%u'", guid))
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_SOCIAL);
|
||||
stmt->setUInt32(0, guid);
|
||||
PreparedQueryResult resultFriends = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (resultFriends)
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -4996,15 +5010,19 @@ void Player::DeleteOldCharacters(uint32 keepDays)
|
||||
{
|
||||
sLog->outString("Player::DeleteOldChars: Deleting all characters which have been deleted %u days before...", keepDays);
|
||||
|
||||
QueryResult resultChars = CharacterDatabase.PQuery("SELECT guid, deleteInfos_Account FROM characters WHERE deleteDate IS NOT NULL AND deleteDate < '%u'", uint32(time(NULL) - time_t(keepDays * DAY)));
|
||||
if (resultChars)
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_OLD_CHARS);
|
||||
stmt->setUInt32(0, uint32(time(NULL) - time_t(keepDays * DAY)));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
sLog->outString("Player::DeleteOldChars: Found " UI64FMTD " character(s) to delete", resultChars->GetRowCount());
|
||||
sLog->outString("Player::DeleteOldChars: Found " UI64FMTD " character(s) to delete", result->GetRowCount());
|
||||
do
|
||||
{
|
||||
Field* charFields = resultChars->Fetch();
|
||||
Player::DeleteFromDB(charFields[0].GetUInt64(), charFields[1].GetUInt32(), true, true);
|
||||
} while (resultChars->NextRow());
|
||||
Field* fields = result->Fetch();
|
||||
Player::DeleteFromDB(fields[0].GetUInt64(), fields[1].GetUInt32(), true, true);
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7274,7 +7292,10 @@ void Player::ModifyArenaPoints(int32 value, SQLTransaction* trans /*=NULL*/)
|
||||
|
||||
uint32 Player::GetGuildIdFromDB(uint64 guid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
@@ -7284,10 +7305,13 @@ uint32 Player::GetGuildIdFromDB(uint64 guid)
|
||||
|
||||
uint8 Player::GetRankFromDB(uint64 guid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
uint32 v = result->Fetch()[0].GetUInt8();
|
||||
uint32 v = result->Fetch()[1].GetUInt8();
|
||||
return v;
|
||||
}
|
||||
else
|
||||
@@ -7296,7 +7320,11 @@ uint8 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);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ARENA_TEAM_ID_BY_PLAYER_GUID);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
stmt->setUInt8(1, type);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
@@ -7307,7 +7335,10 @@ uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type)
|
||||
uint32 Player::GetZoneIdFromDB(uint64 guid)
|
||||
{
|
||||
uint32 guidLow = GUID_LOPART(guid);
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT zone FROM characters WHERE guid='%u'", guidLow);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_ZONE);
|
||||
stmt->setUInt32(0, guidLow);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
Field* fields = result->Fetch();
|
||||
@@ -7316,7 +7347,10 @@ uint32 Player::GetZoneIdFromDB(uint64 guid)
|
||||
if (!zone)
|
||||
{
|
||||
// stored zone is zero, use generic and slow zone detection
|
||||
result = CharacterDatabase.PQuery("SELECT map, position_x, position_y, position_z FROM characters WHERE guid='%u'", guidLow);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_POSITION_XYZ);
|
||||
stmt->setUInt32(0, guidLow);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
fields = result->Fetch();
|
||||
@@ -7343,7 +7377,10 @@ uint32 Player::GetZoneIdFromDB(uint64 guid)
|
||||
|
||||
uint32 Player::GetLevelFromDB(uint64 guid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT level FROM characters WHERE guid='%u'", GUID_LOPART(guid));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_LEVEL);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
@@ -16537,7 +16574,10 @@ void Player::_LoadBGData(PreparedQueryResult 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));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_POSITION);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
@@ -17723,27 +17763,31 @@ void Player::_LoadMailInit(PreparedQueryResult resultUnread, PreparedQueryResult
|
||||
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, body, has_items, expire_time, deliver_time, money, cod, checked, stationery, mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC", GetGUIDLow());
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL);
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
Mail* m = new Mail;
|
||||
m->messageID = fields[0].GetUInt32();
|
||||
m->messageType = fields[1].GetUInt8();
|
||||
m->sender = fields[2].GetUInt32();
|
||||
m->receiver = fields[3].GetUInt32();
|
||||
m->subject = fields[4].GetString();
|
||||
m->body = fields[5].GetString();
|
||||
bool has_items = fields[6].GetBool();
|
||||
m->expire_time = time_t(fields[7].GetUInt32());
|
||||
m->deliver_time = time_t(fields[8].GetUInt32());
|
||||
m->money = fields[9].GetUInt32();
|
||||
m->COD = fields[10].GetUInt32();
|
||||
m->checked = fields[11].GetUInt32();
|
||||
m->stationery = fields[12].GetUInt8();
|
||||
|
||||
m->messageID = fields[0].GetUInt32();
|
||||
m->messageType = fields[1].GetUInt8();
|
||||
m->sender = fields[2].GetUInt32();
|
||||
m->receiver = fields[3].GetUInt32();
|
||||
m->subject = fields[4].GetString();
|
||||
m->body = fields[5].GetString();
|
||||
bool has_items = fields[6].GetBool();
|
||||
m->expire_time = time_t(fields[7].GetUInt32());
|
||||
m->deliver_time = time_t(fields[8].GetUInt32());
|
||||
m->money = fields[9].GetUInt32();
|
||||
m->COD = fields[10].GetUInt32();
|
||||
m->checked = fields[11].GetUInt32();
|
||||
m->stationery = fields[12].GetUInt8();
|
||||
m->mailTemplateId = fields[13].GetInt16();
|
||||
|
||||
if (m->mailTemplateId && !sMailTemplateStore.LookupEntry(m->mailTemplateId))
|
||||
@@ -19351,8 +19395,10 @@ void Player::SetUInt32ValueInArray(Tokens& tokens, uint16 index, uint32 value)
|
||||
|
||||
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));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PLAYERBYTES2);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
@@ -19362,7 +19408,7 @@ void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8
|
||||
playerBytes2 &= ~0xFF;
|
||||
playerBytes2 |= facialHair;
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_PLAYERBYTES);
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_PLAYERBYTES);
|
||||
|
||||
stmt->setUInt8(0, gender);
|
||||
stmt->setUInt32(1, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24));
|
||||
@@ -20200,11 +20246,19 @@ void Player::SendProficiency(ItemClass itemClass, uint32 itemSubclassMask)
|
||||
|
||||
void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
|
||||
{
|
||||
QueryResult result = QueryResult(NULL);
|
||||
PreparedStatement* stmt;
|
||||
|
||||
if (type == 10)
|
||||
result = CharacterDatabase.PQuery("SELECT ownerguid, petitionguid FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid));
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_SIG_BY_GUID);
|
||||
else
|
||||
result = CharacterDatabase.PQuery("SELECT ownerguid, petitionguid FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid), type);
|
||||
{
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_SIG_BY_GUID_TYPE);
|
||||
stmt->setUInt8(0, uint8(type));
|
||||
}
|
||||
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
do // this part effectively does nothing, since the deletion / modification only takes place _after_ the PetitionQuery. Though I don't know if the result remains intact if I execute the delete query beforehand.
|
||||
@@ -25197,8 +25251,8 @@ void Player::SendMovementSetCanFly(bool apply)
|
||||
|
||||
void Player::SendMovementSetCanTransitionBetweenSwimAndFly(bool apply)
|
||||
{
|
||||
WorldPacket data(apply ?
|
||||
SMSG_MOVE_SET_CAN_TRANSITION_BETWEEN_SWIM_AND_FLY :
|
||||
WorldPacket data(apply ?
|
||||
SMSG_MOVE_SET_CAN_TRANSITION_BETWEEN_SWIM_AND_FLY :
|
||||
SMSG_MOVE_UNSET_CAN_TRANSITION_BETWEEN_SWIM_AND_FLY, 12);
|
||||
data.append(GetPackGUID());
|
||||
data << uint32(0); //! movement counter
|
||||
|
||||
Reference in new issue
Block a user