Core/DBLayer: Convert PExecute() queries to prepared statements No. 3
This commit is contained in:
@@ -16507,7 +16507,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder)
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
|
||||
(AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && sObjectMgr->IsReservedName(m_name)))
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
||||
|
||||
stmt->setUInt16(0, uint16(AT_LOGIN_RENAME));
|
||||
stmt->setUInt32(1, guid);
|
||||
@@ -17560,7 +17560,13 @@ void Player::_LoadMailedItems(Mail* mail)
|
||||
if (!item->LoadFromDB(itemGuid, MAKE_NEW_GUID(fields[13].GetUInt32(), 0, HIGHGUID_PLAYER), fields, itemTemplate))
|
||||
{
|
||||
sLog->outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, itemGuid);
|
||||
CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", itemGuid);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM);
|
||||
|
||||
stmt->setUInt32(0, itemGuid);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
item->FSetState(ITEM_REMOVED);
|
||||
|
||||
SQLTransaction temp = SQLTransaction(NULL);
|
||||
@@ -17895,33 +17901,43 @@ void Player::_LoadBoundInstances(PreparedQueryResult result)
|
||||
// so the value read from the DB may be wrong here but only if the InstanceSave is loaded
|
||||
// and in that case it is not used
|
||||
|
||||
bool deleteInstance = false;
|
||||
|
||||
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
|
||||
if (!mapEntry || !mapEntry->IsDungeon())
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed or not dungeon map %d", GetName(), GetGUIDLow(), mapId);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId);
|
||||
continue;
|
||||
deleteInstance = true;
|
||||
}
|
||||
|
||||
if (difficulty >= MAX_DIFFICULTY)
|
||||
else if (difficulty >= MAX_DIFFICULTY)
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId);
|
||||
continue;
|
||||
deleteInstance = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
|
||||
if (!mapDiff)
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId);
|
||||
deleteInstance = true;
|
||||
}
|
||||
else if (!perm && group)
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d, %d, %d", GetName(), GetGUIDLow(), GUID_LOPART(group->GetGUID()), mapId, instanceId, difficulty);
|
||||
deleteInstance = true;
|
||||
}
|
||||
}
|
||||
|
||||
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
|
||||
if (!mapDiff)
|
||||
if (deleteInstance)
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId);
|
||||
continue;
|
||||
}
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE);
|
||||
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
stmt->setUInt32(1, instanceId);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
if (!perm && group)
|
||||
{
|
||||
sLog->outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d, %d, %d", GetName(), GetGUIDLow(), GUID_LOPART(group->GetGUID()), mapId, instanceId, difficulty);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17970,7 +17986,15 @@ void Player::UnbindInstance(BoundInstancesMap::iterator &itr, Difficulty difficu
|
||||
if (itr != m_boundInstances[difficulty].end())
|
||||
{
|
||||
if (!unload)
|
||||
CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%u' AND instance = '%u'", GetGUIDLow(), itr->second.save->GetInstanceId());
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE);
|
||||
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
stmt->setUInt32(1, itr->second.save->GetInstanceId());
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
itr->second.save->RemovePlayer(this); // save can become invalid
|
||||
m_boundInstances[difficulty].erase(itr++);
|
||||
}
|
||||
@@ -17986,11 +18010,28 @@ InstancePlayerBind* Player::BindToInstance(InstanceSave* save, bool permanent, b
|
||||
// update the save when the group kills a boss
|
||||
if (permanent != bind.perm || save != bind.save)
|
||||
if (!load)
|
||||
CharacterDatabase.PExecute("UPDATE character_instance SET instance = '%u', permanent = '%u' WHERE guid = '%u' AND instance = '%u'", save->GetInstanceId(), permanent, GetGUIDLow(), bind.save->GetInstanceId());
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INSTANCE);
|
||||
|
||||
stmt->setUInt32(0, save->GetInstanceId());
|
||||
stmt->setBool(1, permanent);
|
||||
stmt->setUInt32(2, GetGUIDLow());
|
||||
stmt->setUInt32(3, bind.save->GetInstanceId());
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!load)
|
||||
CharacterDatabase.PExecute("INSERT INTO character_instance (guid, instance, permanent) VALUES ('%u', '%u', '%u')", GetGUIDLow(), save->GetInstanceId(), permanent);
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_INSTANCE);
|
||||
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
stmt->setUInt32(1, save->GetInstanceId());
|
||||
stmt->setBool(2, permanent);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
if (bind.save != save)
|
||||
{
|
||||
@@ -19102,11 +19143,18 @@ void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 player_bytes2 = fields[0].GetUInt32();
|
||||
player_bytes2 &= ~0xFF;
|
||||
player_bytes2 |= facialHair;
|
||||
uint32 playerBytes2 = fields[0].GetUInt32();
|
||||
playerBytes2 &= ~0xFF;
|
||||
playerBytes2 |= 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));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_PLAYERBYTES);
|
||||
|
||||
stmt->setUInt8(0, gender);
|
||||
stmt->setUInt32(1, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24));
|
||||
stmt->setUInt32(2, playerBytes2);
|
||||
stmt->setUInt32(3, GUID_LOPART(guid));
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
void Player::SendAttackSwingDeadTarget()
|
||||
@@ -19953,9 +20001,22 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
|
||||
} while (result->NextRow());
|
||||
|
||||
if (type == 10)
|
||||
CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid));
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_PETITION_SIGNATURES);
|
||||
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
else
|
||||
CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid), type);
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PETITION_SIGNATURE);
|
||||
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
stmt->setUInt8(1, uint8(type));
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
@@ -23383,7 +23444,14 @@ void Player::_LoadSkills(PreparedQueryResult result)
|
||||
if (value == 0)
|
||||
{
|
||||
sLog->outError("Character %u has skill %u with value 0. Will be deleted.", GetGUIDLow(), skill);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_skills WHERE guid = '%u' AND skill = '%u' ", GetGUIDLow(), skill);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_SKILL);
|
||||
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
stmt->setUInt16(1, skill);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -24243,12 +24311,19 @@ void Player::DeleteEquipmentSet(uint64 setGuid)
|
||||
}
|
||||
}
|
||||
|
||||
void Player::RemoveAtLoginFlag(AtLoginFlags f, bool in_db_also /*= false*/)
|
||||
void Player::RemoveAtLoginFlag(AtLoginFlags flags, bool persist /*= false*/)
|
||||
{
|
||||
m_atLoginFlags &= ~f;
|
||||
m_atLoginFlags &= ~flags;
|
||||
|
||||
if (in_db_also)
|
||||
CharacterDatabase.PExecute("UPDATE characters set at_login = at_login & ~ %u WHERE guid ='%u'", uint32(f), GetGUIDLow());
|
||||
if (persist)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_REM_AT_LOGIN_FLAG);
|
||||
|
||||
stmt->setUInt16(0, uint16(flags));
|
||||
stmt->setUInt32(1, GetGUIDLow());
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::SendClearCooldown(uint32 spell_id, Unit* target)
|
||||
@@ -24760,7 +24835,13 @@ void Player::SetRandomWinner(bool isWinner)
|
||||
{
|
||||
m_IsBGRandomWinner = isWinner;
|
||||
if (m_IsBGRandomWinner)
|
||||
CharacterDatabase.PExecute("INSERT INTO character_battleground_random (guid) VALUES ('%u')", GetGUIDLow());
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_BATTLEGROUND_RANDOM);
|
||||
|
||||
stmt->setUInt32(0, GetGUIDLow());
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_LoadRandomBGStatus(PreparedQueryResult result)
|
||||
|
||||
Reference in New Issue
Block a user