diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-10-16 01:04:48 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-10-16 01:04:48 -0300 |
| commit | b49d7de51cf14632a5768f292b870e647cf39bf5 (patch) | |
| tree | cca1356d13a5c343c78834c12596aef278a3db49 /src/database_postgres.cc | |
| parent | 85b75f77376b5e6cf571bb6ebc34d11c167ca9cf (diff) | |
| download | querymanager-b49d7de51cf14632a5768f292b870e647cf39bf5.tar.gz querymanager-b49d7de51cf14632a5768f292b870e647cf39bf5.zip | |
gracefully handle no rows on "COUNT(*)" queries
Diffstat (limited to 'src/database_postgres.cc')
| -rw-r--r-- | src/database_postgres.cc | 30 |
1 files changed, 4 insertions, 26 deletions
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; } |
