changeset 106:b559af8fe6e0

Remove "ASSERT" in SQL for compatibility with older releases of PostgreSQL
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Jan 2019 15:35:52 +0100
parents eefbcee7bd78
children 5765cc5fd268
files PostgreSQL/NEWS PostgreSQL/Plugins/CreateInstance.sql
diffstat 2 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/PostgreSQL/NEWS	Tue Jan 22 15:16:05 2019 +0100
+++ b/PostgreSQL/NEWS	Tue Jan 22 15:35:52 2019 +0100
@@ -2,6 +2,7 @@
 ===============================
 
 * Fix build on Debian Buster
+* Remove "ASSERT" in SQL for compatibility with older releases of PostgreSQL
 
 
 Release 3.0 (2019-01-21)
--- a/PostgreSQL/Plugins/CreateInstance.sql	Tue Jan 22 15:16:05 2019 +0100
+++ b/PostgreSQL/Plugins/CreateInstance.sql	Tue Jan 22 15:35:52 2019 +0100
@@ -29,40 +29,51 @@
 
     IF patientKey IS NULL THEN
       -- Must create a new patient
-      ASSERT studyKey IS NULL;
-      ASSERT seriesKey IS NULL;
-      ASSERT instanceKey IS NULL;
+      IF NOT (studyKey IS NULL AND seriesKey IS NULL AND instanceKey IS NULL) THEN
+         RAISE EXCEPTION 'Broken invariant';
+      END IF;
+
       INSERT INTO Resources VALUES (DEFAULT, 0, patient, NULL) RETURNING internalId INTO patientKey;
       isNewPatient := 1;
     ELSE
       isNewPatient := 0;
     END IF;
   
-    ASSERT NOT patientKey IS NULL;
+    IF (patientKey IS NULL) THEN
+       RAISE EXCEPTION 'Broken invariant';
+    END IF;
 
     IF studyKey IS NULL THEN
       -- Must create a new study
-      ASSERT seriesKey IS NULL;
-      ASSERT instanceKey IS NULL;
+      IF NOT (seriesKey IS NULL AND instanceKey IS NULL) THEN
+         RAISE EXCEPTION 'Broken invariant';
+      END IF;
+
       INSERT INTO Resources VALUES (DEFAULT, 1, study, patientKey) RETURNING internalId INTO studyKey;
       isNewStudy := 1;
     ELSE
       isNewStudy := 0;
     END IF;
 
-    ASSERT NOT studyKey IS NULL;
-    
+    IF (studyKey IS NULL) THEN
+       RAISE EXCEPTION 'Broken invariant';
+    END IF;
+
     IF seriesKey IS NULL THEN
       -- Must create a new series
-      ASSERT instanceKey IS NULL;
+      IF NOT (instanceKey IS NULL) THEN
+         RAISE EXCEPTION 'Broken invariant';
+      END IF;
+
       INSERT INTO Resources VALUES (DEFAULT, 2, series, studyKey) RETURNING internalId INTO seriesKey;
       isNewSeries := 1;
     ELSE
       isNewSeries := 0;
     END IF;
   
-    ASSERT NOT seriesKey IS NULL;
-    ASSERT instanceKey IS NULL;
+    IF (seriesKey IS NULL OR NOT instanceKey IS NULL) THEN
+       RAISE EXCEPTION 'Broken invariant';
+    END IF;
 
     INSERT INTO Resources VALUES (DEFAULT, 3, instance, seriesKey) RETURNING internalId INTO instanceKey;
     isNewInstance := 1;