[open-ils-commits] r16536 - in trunk/Open-ILS/src/sql/Pg: . upgrade (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat May 29 23:50:50 EDT 2010


Author: scottmk
Date: 2010-05-29 23:50:47 -0400 (Sat, 29 May 2010)
New Revision: 16536

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0286.schema.query-coalesce-negate.sql
Modified:
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/008.schema.query.sql
Log:
For various updatable views based on query.expression:
add COALESCE to the insert rule so that we don't always
have to specify a value for the "negate" column.

Also: eliminate a harmless but annoying duplication of
the create statements for the query.expr_xbind view.

M    Open-ILS/src/sql/Pg/002.schema.config.sql
M    Open-ILS/src/sql/Pg/008.schema.query.sql
A    Open-ILS/src/sql/Pg/upgrade/0286.schema.query-coalesce-negate.sql


Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-05-28 21:35:04 UTC (rev 16535)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-05-30 03:50:47 UTC (rev 16536)
@@ -65,7 +65,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0285'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0286'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,

Modified: trunk/Open-ILS/src/sql/Pg/008.schema.query.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/008.schema.query.sql	2010-05-28 21:35:04 UTC (rev 16535)
+++ trunk/Open-ILS/src/sql/Pg/008.schema.query.sql	2010-05-30 03:50:47 UTC (rev 16536)
@@ -306,7 +306,7 @@
         COALESCE(NEW.parenthesize, FALSE),
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xbet_update_rule AS
@@ -376,56 +376,6 @@
     DO INSTEAD
     DELETE FROM query.expression WHERE id = OLD.id;
 
--- Create updatable view for bind variable expressions
-
-CREATE OR REPLACE VIEW query.expr_xbind AS
-    SELECT
-		id,
-		parenthesize,
-		parent_expr,
-		seq_no,
-		bind_variable
-    FROM
-        query.expression
-    WHERE
-        type = 'xbind';
-
-CREATE OR REPLACE RULE query_expr_xbind_insert_rule AS
-    ON INSERT TO query.expr_xbind
-    DO INSTEAD
-    INSERT INTO query.expression (
-		id,
-		type,
-		parenthesize,
-		parent_expr,
-		seq_no,
-		bind_variable
-    ) VALUES (
-        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
-        'xbind',
-        COALESCE(NEW.parenthesize, FALSE),
-        NEW.parent_expr,
-        COALESCE(NEW.seq_no, 1),
-		NEW.bind_variable
-    );
-
-CREATE OR REPLACE RULE query_expr_xbind_update_rule AS
-    ON UPDATE TO query.expr_xbind
-    DO INSTEAD
-    UPDATE query.expression SET
-        id = NEW.id,
-        parenthesize = NEW.parenthesize,
-        parent_expr = NEW.parent_expr,
-        seq_no = NEW.seq_no,
-		bind_variable = NEW.bind_variable
-    WHERE
-        id = OLD.id;
-
-CREATE OR REPLACE RULE query_expr_xbind_delete_rule AS
-    ON DELETE TO query.expr_xbind
-    DO INSTEAD
-    DELETE FROM query.expression WHERE id = OLD.id;
-
 -- Create updatable view for boolean expressions
 
 CREATE OR REPLACE VIEW query.expr_xbool AS
@@ -459,7 +409,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
         NEW.literal,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xbool_update_rule AS
@@ -510,7 +460,7 @@
         COALESCE(NEW.parenthesize, FALSE),
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xcase_update_rule AS
@@ -566,7 +516,7 @@
         COALESCE(NEW.seq_no, 1),
 		NEW.left_operand,
 		NEW.cast_type,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xcast_update_rule AS
@@ -624,7 +574,7 @@
         COALESCE(NEW.seq_no, 1),
 		NEW.table_alias,
 		NEW.column_name,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xcol_update_rule AS
@@ -679,7 +629,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
 		NEW.subquery,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xex_update_rule AS
@@ -736,7 +686,7 @@
         COALESCE(NEW.seq_no, 1),
 		NEW.column_name,
 		NEW.left_operand,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xfld_update_rule AS
@@ -791,7 +741,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
 		NEW.function_id,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xfunc_update_rule AS
@@ -848,7 +798,7 @@
         COALESCE(NEW.seq_no, 1),
 		NEW.left_operand,
 		NEW.subquery,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xin_update_rule AS
@@ -903,7 +853,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
 		NEW.left_operand,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xisnull_update_rule AS
@@ -954,7 +904,7 @@
         COALESCE(NEW.parenthesize, FALSE),
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xnull_update_rule AS
@@ -1063,7 +1013,7 @@
 		NEW.left_operand,
 		NEW.operator,
 		NEW.right_operand,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xop_update_rule AS
@@ -1120,7 +1070,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
 		NEW.operator,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xser_update_rule AS
@@ -1224,7 +1174,7 @@
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
 		NEW.subquery,
-		NEW.negate
+		COALESCE(NEW.negate, false)
     );
 
 CREATE OR REPLACE RULE query_expr_xsubq_update_rule AS

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0286.schema.query-coalesce-negate.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0286.schema.query-coalesce-negate.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0286.schema.query-coalesce-negate.sql	2010-05-30 03:50:47 UTC (rev 16536)
@@ -0,0 +1,309 @@
+BEGIN;
+
+-- For various updatable views based on query.expression:
+-- add COALESCE to the insert rule so that we don't always
+-- have to specify a value for the "negate" column.
+
+INSERT INTO config.upgrade_log (version) VALUES ('0286'); -- Scott McKellar
+
+CREATE OR REPLACE RULE query_expr_xbet_insert_rule AS
+    ON INSERT TO query.expr_xbet
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xbet',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xbool_insert_rule AS
+    ON INSERT TO query.expr_xbool
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		literal,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xbool',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+        NEW.literal,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xcase_insert_rule AS
+    ON INSERT TO query.expr_xcase
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xcase',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xcast_insert_rule AS
+    ON INSERT TO query.expr_xcast
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		left_operand,
+		cast_type,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xcast',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.left_operand,
+		NEW.cast_type,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xcol_insert_rule AS
+    ON INSERT TO query.expr_xcol
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		table_alias,
+		column_name,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xcol',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.table_alias,
+		NEW.column_name,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xex_insert_rule AS
+    ON INSERT TO query.expr_xex
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		subquery,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xex',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.subquery,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xfld_insert_rule AS
+    ON INSERT TO query.expr_xfld
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		column_name,
+		left_operand,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xfld',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.column_name,
+		NEW.left_operand,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xfunc_insert_rule AS
+    ON INSERT TO query.expr_xfunc
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		function_id,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xfunc',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.function_id,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xin_insert_rule AS
+    ON INSERT TO query.expr_xin
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		left_operand,
+		subquery,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xin',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.left_operand,
+		NEW.subquery,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xisnull_insert_rule AS
+    ON INSERT TO query.expr_xisnull
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		left_operand,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xisnull',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.left_operand,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xnull_insert_rule AS
+    ON INSERT TO query.expr_xnull
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xnull',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xop_insert_rule AS
+    ON INSERT TO query.expr_xop
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		left_operand,
+		operator,
+		right_operand,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xop',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.left_operand,
+		NEW.operator,
+		NEW.right_operand,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xser_insert_rule AS
+    ON INSERT TO query.expr_xser
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		operator,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xser',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.operator,
+		COALESCE(NEW.negate, false)
+    );
+
+CREATE OR REPLACE RULE query_expr_xsubq_insert_rule AS
+    ON INSERT TO query.expr_xsubq
+    DO INSTEAD
+    INSERT INTO query.expression (
+		id,
+		type,
+		parenthesize,
+		parent_expr,
+		seq_no,
+		subquery,
+		negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xsubq',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+		NEW.subquery,
+		COALESCE(NEW.negate, false)
+    );
+
+COMMIT;



More information about the open-ils-commits mailing list