From c5a708a3820287388344f9a150fd51a531310b54 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Fri, 28 Jun 2024 10:41:04 +0100 Subject: [PATCH] Add in soft failure for sql delete --- root/usr/bin/mailstats.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/root/usr/bin/mailstats.py b/root/usr/bin/mailstats.py index 8be6f68..733811b 100644 --- a/root/usr/bin/mailstats.py +++ b/root/usr/bin/mailstats.py @@ -757,17 +757,20 @@ if __name__ == "__main__": """) # and prune the DB here if needed. # Delete existing records for the given date - delete_query = """ - DELETE FROM SummaryLogs - WHERE Date = %s - """ - cursor.execute(delete_query, (analysis_date)) - # Get the number of records deleted - rows_deleted = cursor.rowcount - print(rows_deleted) - #quit() - if rows_deleted > 0: - print(f"Deleted {rows_deleted} rows for {analysis_date} ") + try: + delete_query = """ + DELETE FROM SummaryLogs + WHERE Date = %s + """ + cursor.execute(delete_query, (analysis_date)) + # Get the number of records deleted + rows_deleted = cursor.rowcount + print(rows_deleted) + #quit() + if rows_deleted > 0: + print(f"Deleted {rows_deleted} rows for {analysis_date} ") + except mysql.connector.Error as e: + print(f"SQL Delete failed ({delete_query}) ({e}) ") except mysql.connector.Error as e: print(f"Unable to connect to {DBName} on {DBHost} port {DBPort} error ({e}) ") saveData = False