[Cleanup] Use constant reference and check for empty string properly in dbcore.cpp (#3203)

# Notes
- Passing by constant reference is more performant.
- Checking for empty string with `!= '\0'` is more performant.
- https://pvs-studio.com/en/docs/warnings/v805/
- https://pvs-studio.com/en/docs/warnings/v813/
This commit is contained in:
Alex King 2023-04-05 11:27:50 -04:00 committed by GitHub
parent ff440e16b6
commit 7d03479f41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -80,7 +80,7 @@ MySQLRequestResult DBcore::QueryDatabase(const std::string& query, bool retryOnF
return r;
}
bool DBcore::DoesTableExist(std::string table_name)
bool DBcore::DoesTableExist(const std::string& table_name)
{
auto results = QueryDatabase(fmt::format("SHOW TABLES LIKE '{}'", table_name));
@ -136,7 +136,7 @@ MySQLRequestResult DBcore::QueryDatabase(const char *query, uint32 querylen, boo
/**
* Error logging
*/
if (mysql_errno(mysql) > 0 && strlen(query) > 0) {
if (mysql_errno(mysql) > 0 && query[0] != '\0') {
LogMySQLError("[{}] [{}]\n[{}]", mysql_errno(mysql), mysql_error(mysql), query);
}

View File

@ -35,7 +35,7 @@ public:
const std::string &GetOriginHost() const;
void SetOriginHost(const std::string &origin_host);
bool DoesTableExist(std::string table_name);
bool DoesTableExist(const std::string& table_name);
void SetMySQL(const DBcore &o)
{