Core/CharDB Cleanup: alter character_homebind table making column names lowerCamel and move all queries to prepared statements.

This commit is contained in:
Azazel
2011-04-08 17:04:51 +06:00
parent 37a6fe2ae7
commit 9f1cc4407a
7 changed files with 72 additions and 18 deletions
+25 -7
View File
@@ -4876,7 +4876,9 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
trans->PAppend("DELETE FROM character_action WHERE guid = '%u'",guid);
trans->PAppend("DELETE FROM character_aura WHERE guid = '%u'",guid);
trans->PAppend("DELETE FROM character_gifts WHERE guid = '%u'",guid);
trans->PAppend("DELETE FROM character_homebind WHERE guid = '%u'",guid);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_HOMEBIND);
stmt->setUInt32(0, guid);
trans->Append(stmt);
trans->PAppend("DELETE FROM character_instance WHERE guid = '%u'",guid);
trans->PAppend("DELETE FROM character_inventory WHERE guid = '%u'",guid);
trans->PAppend("DELETE FROM character_queststatus WHERE guid = '%u'",guid);
@@ -16357,8 +16359,14 @@ void Player::SetHomebind(WorldLocation const& /*loc*/, uint32 /*area_id*/)
m_homebindZ = GetPositionZ();
// update sql homebind
CharacterDatabase.PExecute("UPDATE character_homebind SET map = '%u', zone = '%u', position_x = '%f', position_y = '%f', position_z = '%f' WHERE guid = '%u'",
m_homebindMapId, m_homebindAreaId, m_homebindX, m_homebindY, m_homebindZ, GetGUIDLow());
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_PLAYER_HOMEBIND);
stmt->setUInt16(0, m_homebindMapId);
stmt->setUInt16(1, m_homebindAreaId);
stmt->setFloat (2, m_homebindX);
stmt->setFloat (3, m_homebindY);
stmt->setFloat (4, m_homebindZ);
stmt->setUInt32(5, GetGUIDLow());
CharacterDatabase.Execute(stmt);
}
uint32 Player::GetUInt32ValueFromArray(Tokens const& data, uint16 index)
@@ -18115,7 +18123,7 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
}
bool ok = false;
//QueryResult *result = CharacterDatabase.PQuery("SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(playerGuid));
// SELECT mapId, zoneId, posX, posY, posZ FROM character_homebind WHERE guid = ?
if (result)
{
Field* fields = result->Fetch();
@@ -18133,7 +18141,11 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
!bindMapEntry->Instanceable() && GetSession()->Expansion() >= bindMapEntry->Expansion())
ok = true;
else
CharacterDatabase.PExecute("DELETE FROM character_homebind WHERE guid = '%u'", GetGUIDLow());
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_HOMEBIND);
stmt->setUInt32(0, GetGUIDLow());
CharacterDatabase.Execute(stmt);
}
}
if (!ok)
@@ -18144,8 +18156,14 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
m_homebindY = info->positionY;
m_homebindZ = info->positionZ;
CharacterDatabase.PExecute("INSERT INTO character_homebind (guid,map,zone,position_x,position_y,position_z) VALUES ('%u', '%u', '%u', '%f', '%f', '%f')",
GetGUIDLow(), m_homebindMapId, m_homebindAreaId, m_homebindX, m_homebindY, m_homebindZ);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_PLAYER_HOMEBIND);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt16(1, m_homebindMapId);
stmt->setUInt16(2, m_homebindAreaId);
stmt->setFloat (3, m_homebindX);
stmt->setFloat (4, m_homebindY);
stmt->setFloat (5, m_homebindZ);
CharacterDatabase.Execute(stmt);
}
sLog->outStaticDebug("Setting player home position - mapid: %u, areaid: %u, X: %f, Y: %f, Z: %f",
@@ -1710,17 +1710,31 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
Player::LeaveAllArenaTeams(guid);
// Reset homebind and position
trans->PAppend("DELETE FROM `character_homebind` WHERE guid = '%u'", lowGuid);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_HOMEBIND);
stmt->setUInt32(0, lowGuid);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_PLAYER_HOMEBIND);
stmt->setUInt32(0, lowGuid);
if (team == BG_TEAM_ALLIANCE)
{
trans->PAppend("INSERT INTO `character_homebind` VALUES (%u,0,1519,-8867.68,673.373,97.9034)", lowGuid);
stmt->setUInt16(1, 0);
stmt->setUInt16(2, 1519);
stmt->setFloat (3, -8867.68f);
stmt->setFloat (4, 673.373f);
stmt->setFloat (5, 97.9034f);
Player::SavePositionInDB(0, -8867.68f, 673.373f, 97.9034f, 0.0f, 1519, lowGuid);
}
else
{
trans->PAppend("INSERT INTO `character_homebind` VALUES (%u,1,1637,1633.33,-4439.11,15.7588)", lowGuid);
stmt->setUInt16(1, 1);
stmt->setUInt16(2, 1637);
stmt->setFloat (3, 1633.33f);
stmt->setFloat (4, -4439.11f);
stmt->setFloat (5, 15.7588f);
Player::SavePositionInDB(1, 1633.33f, -4439.11f, 15.7588f, 0.0f, 1637, lowGuid);
}
trans->Append(stmt);
// Achievement conversion
for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->factionchange_achievements.begin(); it != sObjectMgr->factionchange_achievements.end(); ++it)
@@ -474,8 +474,15 @@ void WorldSession::SendBindPoint(Creature *npc)
uint32 bindspell = 3286;
// update sql homebind
CharacterDatabase.PExecute("UPDATE character_homebind SET map = '%u', zone = '%u', position_x = '%f', position_y = '%f', position_z = '%f' WHERE guid = '%u'",
_player->GetMapId(), _player->GetAreaId(), _player->GetPositionX(), _player->GetPositionY(), _player->GetPositionZ(), _player->GetGUIDLow());
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_PLAYER_HOMEBIND);
stmt->setUInt16(0, _player->GetMapId());
stmt->setUInt16(1, _player->GetAreaId());
stmt->setFloat (2, _player->GetPositionX());
stmt->setFloat (3, _player->GetPositionY());
stmt->setFloat (4, _player->GetPositionZ());
stmt->setUInt32(5, _player->GetGUIDLow());
CharacterDatabase.Execute(stmt);
_player->m_homebindMapId = _player->GetMapId();
_player->m_homebindAreaId = _player->GetAreaId();
_player->m_homebindX = _player->GetPositionX();