feat(Core/DBLayer): replace char const* to std::string_view (#10211)

* feat(Core/DBLayer): replace `char const*` to `std::string_view`

* CString

* 1

* chore(Core/Misc): code cleanup

* cl

* db fix

* fmt style sql

* to fmt

* py

* del old

* 1

* 2

* 3

* 1

* 1
This commit is contained in:
Kargatum
2022-02-05 06:37:11 +07:00
committed by GitHub
parent d6ead1d1e0
commit de13bf426e
140 changed files with 5055 additions and 4882 deletions

View File

@@ -3305,10 +3305,10 @@ void Map::SaveCreatureRespawnTime(ObjectGuid::LowType spawnId, time_t& respawnTi
_creatureRespawnTimes[spawnId] = respawnTime;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CREATURE_RESPAWN);
stmt->setUInt32(0, spawnId);
stmt->setUInt32(1, uint32(respawnTime));
stmt->setUInt16(2, GetId());
stmt->setUInt32(3, GetInstanceId());
stmt->SetData(0, spawnId);
stmt->SetData(1, uint32(respawnTime));
stmt->SetData(2, GetId());
stmt->SetData(3, GetInstanceId());
CharacterDatabase.Execute(stmt);
}
@@ -3317,9 +3317,9 @@ void Map::RemoveCreatureRespawnTime(ObjectGuid::LowType spawnId)
_creatureRespawnTimes.erase(spawnId);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN);
stmt->setUInt32(0, spawnId);
stmt->setUInt16(1, GetId());
stmt->setUInt32(2, GetInstanceId());
stmt->SetData(0, spawnId);
stmt->SetData(1, GetId());
stmt->SetData(2, GetInstanceId());
CharacterDatabase.Execute(stmt);
}
@@ -3339,10 +3339,10 @@ void Map::SaveGORespawnTime(ObjectGuid::LowType spawnId, time_t& respawnTime)
_goRespawnTimes[spawnId] = respawnTime;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GO_RESPAWN);
stmt->setUInt32(0, spawnId);
stmt->setUInt32(1, uint32(respawnTime));
stmt->setUInt16(2, GetId());
stmt->setUInt32(3, GetInstanceId());
stmt->SetData(0, spawnId);
stmt->SetData(1, uint32(respawnTime));
stmt->SetData(2, GetId());
stmt->SetData(3, GetInstanceId());
CharacterDatabase.Execute(stmt);
}
@@ -3351,39 +3351,39 @@ void Map::RemoveGORespawnTime(ObjectGuid::LowType spawnId)
_goRespawnTimes.erase(spawnId);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GO_RESPAWN);
stmt->setUInt32(0, spawnId);
stmt->setUInt16(1, GetId());
stmt->setUInt32(2, GetInstanceId());
stmt->SetData(0, spawnId);
stmt->SetData(1, GetId());
stmt->SetData(2, GetInstanceId());
CharacterDatabase.Execute(stmt);
}
void Map::LoadRespawnTimes()
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CREATURE_RESPAWNS);
stmt->setUInt16(0, GetId());
stmt->setUInt32(1, GetInstanceId());
stmt->SetData(0, GetId());
stmt->SetData(1, GetInstanceId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
{
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType lowguid = fields[0].GetUInt32();
uint32 respawnTime = fields[1].GetUInt32();
ObjectGuid::LowType lowguid = fields[0].Get<uint32>();
uint32 respawnTime = fields[1].Get<uint32>();
_creatureRespawnTimes[lowguid] = time_t(respawnTime);
} while (result->NextRow());
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GO_RESPAWNS);
stmt->setUInt16(0, GetId());
stmt->setUInt32(1, GetInstanceId());
stmt->SetData(0, GetId());
stmt->SetData(1, GetInstanceId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
{
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType lowguid = fields[0].GetUInt32();
uint32 respawnTime = fields[1].GetUInt32();
ObjectGuid::LowType lowguid = fields[0].Get<uint32>();
uint32 respawnTime = fields[1].Get<uint32>();
_goRespawnTimes[lowguid] = time_t(respawnTime);
} while (result->NextRow());
@@ -3401,13 +3401,13 @@ void Map::DeleteRespawnTimes()
void Map::DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN_BY_INSTANCE);
stmt->setUInt16(0, mapId);
stmt->setUInt32(1, instanceId);
stmt->SetData(0, mapId);
stmt->SetData(1, instanceId);
CharacterDatabase.Execute(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GO_RESPAWN_BY_INSTANCE);
stmt->setUInt16(0, mapId);
stmt->setUInt32(1, instanceId);
stmt->SetData(0, mapId);
stmt->SetData(1, instanceId);
CharacterDatabase.Execute(stmt);
}
@@ -3502,7 +3502,7 @@ void Map::LogEncounterFinished(EncounterCreditType type, uint32 creditEntry)
playersInfo += buffer;
}
CleanStringForMysqlQuery(playersInfo);
CharacterDatabase.PExecute("INSERT INTO log_encounter VALUES(NOW(), %u, %u, %u, %u, '%s')", GetId(), (uint32)GetDifficulty(), type, creditEntry, playersInfo.c_str());
CharacterDatabase.Execute("INSERT INTO log_encounter VALUES(NOW(), {}, {}, {}, {}, '{}')", GetId(), (uint32)GetDifficulty(), type, creditEntry, playersInfo);
}
bool Map::AllTransportsEmpty() const
@@ -3950,8 +3950,8 @@ bool Map::CheckCollisionAndGetValidCoords(const WorldObject* source, float start
void Map::LoadCorpseData()
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CORPSES);
stmt->setUInt32(0, GetId());
stmt->setUInt32(1, GetInstanceId());
stmt->SetData(0, GetId());
stmt->SetData(1, GetInstanceId());
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, guildId, flags, dynFlags, time, corpseType, instanceId, phaseMask, guid FROM corpse WHERE mapId = ? AND instanceId = ?
@@ -3962,8 +3962,8 @@ void Map::LoadCorpseData()
do
{
Field* fields = result->Fetch();
CorpseType type = CorpseType(fields[13].GetUInt8());
uint32 guid = fields[16].GetUInt32();
CorpseType type = CorpseType(fields[13].Get<uint8>());
uint32 guid = fields[16].Get<uint32>();
if (type >= MAX_CORPSE_TYPE || type == CORPSE_BONES)
{
LOG_ERROR("maps", "Corpse (guid: {}) have wrong corpse type ({}), not loading.", guid, type);
@@ -3988,7 +3988,7 @@ void Map::DeleteCorpseData()
{
// DELETE FROM corpse WHERE mapId = ? AND instanceId = ?
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CORPSES_FROM_MAP);
stmt->setUInt32(0, GetId());
stmt->setUInt32(1, GetInstanceId());
stmt->SetData(0, GetId());
stmt->SetData(1, GetInstanceId());
CharacterDatabase.Execute(stmt);
}