Fixed defect with deleting old logs not working with 0 rows

This commit is contained in:
Thomas Williams 2024-07-04 17:07:16 +01:00
parent dca95f5780
commit 264c8ccbdc
Signed by: thomas
GPG key ID: EB8F975CF60BCBFF

6
log.py
View file

@ -139,9 +139,11 @@ class logsManager:
oldestLogQuery = f"SELECT TOP 1 {logTimeColumn} FROM {tableName} ORDER BY {logTimeColumn} ASC"
cursor.execute(oldestLogQuery)
oldestLogTime = cursor.fetchone()[0]
if oldestLogTime is not None and oldestLogTime < datetime.now() - timedelta(days=int(logRetentionDays)):
if cursor.rowcount > 0:
oldestLogTime = cursor.fetchone()[0]
if cursor.rowcount > 0 and oldestLogTime < datetime.now() - timedelta(days=int(logRetentionDays)):
deleteQuery = f"DELETE FROM {tableName} WHERE {logTimeColumn} < ?"
cursor.execute(deleteQuery, datetime.now() - timedelta(days=int(logRetentionDays)))