[Cleanuo] Only define row if we have results in Database::GetCharacterID() (#3199)

# Notes
- This is more performant and we don't unnecessarily define a variable we can't use.
- https://pvs-studio.com/en/docs/warnings/v821/
This commit is contained in:
Alex King
2023-04-05 11:25:28 -04:00
committed by GitHub
parent 7dc57c3b05
commit d142bc552a
+9 -6
View File
@@ -797,16 +797,19 @@ bool Database::SaveCharacterCreate(uint32 character_id, uint32 account_id, Playe
} }
uint32 Database::GetCharacterID(const char *name) { uint32 Database::GetCharacterID(const char *name) {
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name` = '%s'", name); const auto query = fmt::format(
"SELECT `id` FROM `character_data` WHERE `name` = '{}'",
Strings::Escape(name)
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
auto row = results.begin(); if (!results.Success() || !results.RowCount()) {
if (results.RowCount() == 1)
{
return Strings::ToUnsignedInt(row[0]);
}
return 0; return 0;
} }
auto row = results.begin();
return Strings::ToUnsignedInt(row[0]);
}
/* /*
This function returns the account_id that owns the character with This function returns the account_id that owns the character with
the name "name" or zero if no character with that name was found the name "name" or zero if no character with that name was found