mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 05:36:23 +00:00
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:
@@ -34,11 +34,11 @@ void CharacterDatabaseCleaner::CleanDatabase()
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
// check flags which clean ups are necessary
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT value FROM worldstates WHERE entry = %d", WS_CLEANING_FLAGS);
|
||||
QueryResult result = CharacterDatabase.Query("SELECT value FROM worldstates WHERE entry = {}", WS_CLEANING_FLAGS);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
uint32 flags = (*result)[0].GetUInt32();
|
||||
uint32 flags = (*result)[0].Get<uint32>();
|
||||
|
||||
// clean up
|
||||
if (flags & CLEANING_FLAG_ACHIEVEMENT_PROGRESS)
|
||||
@@ -59,7 +59,7 @@ void CharacterDatabaseCleaner::CleanDatabase()
|
||||
// NOTE: In order to have persistentFlags be set in worldstates for the next cleanup,
|
||||
// you need to define them at least once in worldstates.
|
||||
flags &= sWorld->getIntConfig(CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS);
|
||||
CharacterDatabase.DirectPExecute("UPDATE worldstates SET value = %u WHERE entry = %d", flags, WS_CLEANING_FLAGS);
|
||||
CharacterDatabase.DirectExecute("UPDATE worldstates SET value = {} WHERE entry = {}", flags, WS_CLEANING_FLAGS);
|
||||
|
||||
sWorld->SetCleaningFlags(flags);
|
||||
|
||||
@@ -69,7 +69,7 @@ void CharacterDatabaseCleaner::CleanDatabase()
|
||||
|
||||
void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table, bool (*check)(uint32))
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT DISTINCT %s FROM %s", column, table);
|
||||
QueryResult result = CharacterDatabase.Query("SELECT DISTINCT {} FROM {}", column, table);
|
||||
if (!result)
|
||||
{
|
||||
LOG_INFO("sql.sql", "Table {} is empty.", table);
|
||||
@@ -82,7 +82,7 @@ void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 id = fields[0].GetUInt32();
|
||||
uint32 id = fields[0].Get<uint32>();
|
||||
|
||||
if (!check(id))
|
||||
{
|
||||
@@ -146,7 +146,7 @@ bool CharacterDatabaseCleaner::TalentCheck(uint32 talent_id)
|
||||
|
||||
void CharacterDatabaseCleaner::CleanCharacterTalent()
|
||||
{
|
||||
CharacterDatabase.DirectPExecute("DELETE FROM character_talent WHERE specMask >= %u", 1 << MAX_TALENT_SPECS);
|
||||
CharacterDatabase.DirectExecute("DELETE FROM character_talent WHERE specMask >= {}", 1 << MAX_TALENT_SPECS);
|
||||
CheckUnique("spell", "character_talent", &TalentCheck);
|
||||
}
|
||||
|
||||
|
||||
@@ -259,14 +259,14 @@ void PlayerDump::InitializeTables()
|
||||
TableStruct t;
|
||||
t.TableName = dumpTable.Name;
|
||||
|
||||
QueryResult result = CharacterDatabase.PQuery("DESC %s", dumpTable.Name);
|
||||
QueryResult result = CharacterDatabase.Query("DESC {}", dumpTable.Name);
|
||||
// prepared statement is correct (checked at startup) so table must exist
|
||||
ASSERT(result);
|
||||
|
||||
int32 i = 0;
|
||||
do
|
||||
{
|
||||
std::string columnName = (*result)[0].GetString();
|
||||
std::string columnName = (*result)[0].Get<std::string>();
|
||||
t.FieldIndices.emplace(columnName, i++);
|
||||
|
||||
TableField f;
|
||||
@@ -538,11 +538,11 @@ inline void AppendTableDump(StringTransaction& trans, TableStruct const& tableSt
|
||||
|
||||
for (uint32 i = 0; i < fieldSize;)
|
||||
{
|
||||
char const* cString = fields[i].GetCString();
|
||||
std::string cString = fields[i].Get<std::string>();
|
||||
++i;
|
||||
|
||||
// null pointer -> we have null
|
||||
if (!cString)
|
||||
if (cString.empty())
|
||||
ss << "'NULL'";
|
||||
else
|
||||
{
|
||||
@@ -604,7 +604,7 @@ void PlayerDumpWriter::PopulateGuids(ObjectGuid::LowType guid)
|
||||
}
|
||||
|
||||
std::string whereStr = GenerateWhereStr(baseTable.PlayerGuid, guid);
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT %s FROM %s WHERE %s", baseTable.PrimaryKey, baseTable.TableName, whereStr.c_str());
|
||||
QueryResult result = CharacterDatabase.Query("SELECT {} FROM {} WHERE {}", baseTable.PrimaryKey, baseTable.TableName, whereStr);
|
||||
if (!result)
|
||||
continue;
|
||||
|
||||
@@ -613,19 +613,19 @@ void PlayerDumpWriter::PopulateGuids(ObjectGuid::LowType guid)
|
||||
switch (baseTable.StoredType)
|
||||
{
|
||||
case GUID_TYPE_ITEM:
|
||||
if (ObjectGuid::LowType itemLowGuid = (*result)[0].GetUInt32())
|
||||
if (ObjectGuid::LowType itemLowGuid = (*result)[0].Get<uint32>())
|
||||
_items.insert(itemLowGuid);
|
||||
break;
|
||||
case GUID_TYPE_MAIL:
|
||||
if (ObjectGuid::LowType mailLowGuid = (*result)[0].GetUInt32())
|
||||
if (ObjectGuid::LowType mailLowGuid = (*result)[0].Get<uint32>())
|
||||
_mails.insert(mailLowGuid);
|
||||
break;
|
||||
case GUID_TYPE_PET:
|
||||
if (ObjectGuid::LowType petLowGuid = (*result)[0].GetUInt32())
|
||||
if (ObjectGuid::LowType petLowGuid = (*result)[0].Get<uint32>())
|
||||
_pets.insert(petLowGuid);
|
||||
break;
|
||||
case GUID_TYPE_EQUIPMENT_SET:
|
||||
if (uint64 eqSetId = (*result)[0].GetUInt64())
|
||||
if (uint64 eqSetId = (*result)[0].Get<uint64>())
|
||||
_itemSets.insert(eqSetId);
|
||||
break;
|
||||
default:
|
||||
@@ -671,7 +671,7 @@ bool PlayerDumpWriter::AppendTable(StringTransaction& trans, ObjectGuid::LowType
|
||||
break;
|
||||
}
|
||||
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", dumpTable.Name, whereStr.c_str());
|
||||
QueryResult result = CharacterDatabase.Query("SELECT * FROM {} WHERE {}", dumpTable.Name, whereStr);
|
||||
switch (dumpTable.Type)
|
||||
{
|
||||
case DTT_CHARACTER:
|
||||
@@ -681,7 +681,7 @@ bool PlayerDumpWriter::AppendTable(StringTransaction& trans, ObjectGuid::LowType
|
||||
int32 index = GetColumnIndexByName(tableStruct, "deleteInfos_Account");
|
||||
ASSERT(index != -1); // checked at startup
|
||||
|
||||
if ((*result)[index].GetUInt32())
|
||||
if ((*result)[index].Get<uint32>())
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -773,7 +773,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::istream& input, uint32 account, std::
|
||||
if (guid && guid < sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed())
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID);
|
||||
stmt->setUInt32(0, guid);
|
||||
stmt->SetData(0, guid);
|
||||
|
||||
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
|
||||
guid = sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed(); // use first free if exists
|
||||
@@ -790,7 +790,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::istream& input, uint32 account, std::
|
||||
if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS)
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
|
||||
stmt->setString(0, name);
|
||||
stmt->SetData(0, name);
|
||||
|
||||
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
|
||||
name.clear(); // use the one from the dump
|
||||
|
||||
Reference in New Issue
Block a user