From 73f7026643dff448fbf00d059eea0ea3269d3c84 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 3 Feb 2018 11:01:33 -0500 Subject: [PATCH] use COALESCE to ensure integer values --- db/zm_update-1.31.33.sql | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 db/zm_update-1.31.33.sql diff --git a/db/zm_update-1.31.33.sql b/db/zm_update-1.31.33.sql new file mode 100644 index 000000000..92ed1275d --- /dev/null +++ b/db/zm_update-1.31.33.sql @@ -0,0 +1,31 @@ +drop trigger if exists event_delete_trigger; + +delimiter // + +CREATE TRIGGER event_delete_trigger BEFORE DELETe on Events + +FOR EACH ROW + BEGIN + call update_storage_stats(OLD.StorageId, -OLD.DiskSpace); + DELETE FROM Events_Hour WHERE EventId=OLD.Id; + DELETE FROM Events_Day WHERE EventId=OLD.Id; + DELETE FROM Events_Week WHERE EventId=OLD.Id; + DELETE FROM Events_Month WHERE EventId=OLD.Id; + IF ( OLD.Archived ) THEN + DELETE FROM Events_Archived WHERE EventId=OLD.Id; + UPDATE Monitors SET + ArchivedEvents = ArchivedEvents - 1, + ArchivedEventDiskSpace = COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0), + TotalEvents = TotalEvents - 1, + TotalEventDiskSpace = COALESCE(TotalEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0) + WHERE Id=OLD.MonitorId; + ELSE + UPDATE Monitors SET + TotalEvents = TotalEvents-1, + TotalEventDiskSpace=COALESCE(TotalEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0) + WHERE Id=OLD.MonitorId; + END IF; +END; + +// +