From b49d7de51cf14632a5768f292b870e647cf39bf5 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Thu, 16 Oct 2025 01:04:48 -0300 Subject: gracefully handle no rows on "COUNT(*)" queries --- src/database_postgres.cc | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'src/database_postgres.cc') diff --git a/src/database_postgres.cc b/src/database_postgres.cc index 3c522c1..4638851 100644 --- a/src/database_postgres.cc +++ b/src/database_postgres.cc @@ -1554,14 +1554,7 @@ bool GetAccountOnlineCharacters(TDatabase *Database, int AccountID, int *OnlineC return false; } - // NOTE(fusion): This is intended. A `SELECT COUNT(*)` query should always - // return something. - if(PQntuples(Result) == 0){ - LOG_ERR("Query returned no rows"); - return false; - } - - *OnlineCharacters = GetResultInt(Result, 0, 0); + *OnlineCharacters = (PQntuples(Result) > 0 ? GetResultInt(Result, 0, 0) : 0); return true; } @@ -2319,12 +2312,7 @@ bool GetAccountFailedLoginAttempts(TDatabase *Database, int AccountID, int TimeW return false; } - if(PQntuples(Result) == 0){ - LOG_ERR("Query returned no rows"); - return false; - } - - *FailedAttempts = GetResultInt(Result, 0, 0); + *FailedAttempts = (PQntuples(Result) > 0 ? GetResultInt(Result, 0, 0) : 0); return true; } @@ -2352,12 +2340,7 @@ bool GetIPAddressFailedLoginAttempts(TDatabase *Database, int IPAddress, int Tim return false; } - if(PQntuples(Result) == 0){ - LOG_ERR("Query returned no rows"); - return false; - } - - *FailedAttempts = GetResultInt(Result, 0, 0); + *FailedAttempts = (PQntuples(Result) > 0 ? GetResultInt(Result, 0, 0) : 0); return true; } @@ -2971,12 +2954,7 @@ bool GetNotationCount(TDatabase *Database, int CharacterID, int *Notations){ return false; } - if(PQntuples(Result) == 0){ - LOG_ERR("Query returned no rows"); - return false; - } - - *Notations = GetResultInt(Result, 0, 0); + *Notations = (PQntuples(Result) > 0 ? GetResultInt(Result, 0, 0) : 0); return true; } -- cgit v1.2.3