diff OrthancServer/Upgrade4To5.sql @ 1176:f24e04838054 db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Sep 2014 14:11:37 +0200
parents 8f9d49192815
children
line wrap: on
line diff
--- a/OrthancServer/Upgrade4To5.sql	Mon Sep 22 13:57:04 2014 +0200
+++ b/OrthancServer/Upgrade4To5.sql	Mon Sep 22 14:11:37 2014 +0200
@@ -42,6 +42,7 @@
 -- Upgrade the "ResourceDeleted" trigger
 
 DROP TRIGGER ResourceDeleted;
+DROP TRIGGER ResourceDeletedParentCleaning;
 
 CREATE TRIGGER ResourceDeleted
 AFTER DELETE ON Resources
@@ -51,6 +52,13 @@
     FROM Resources AS parent WHERE internalId = old.parentId;
 END;
 
+CREATE TRIGGER ResourceDeletedParentCleaning
+AFTER DELETE ON Resources
+FOR EACH ROW WHEN (SELECT COUNT(*) FROM Resources WHERE parentId = old.parentId) = 0
+BEGIN
+  DELETE FROM Resources WHERE internalId = old.parentId;
+END;
+
 
 -- Change the database version
 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration