From f90876889db3e050933a41991c166ce07a90c0a7 Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 10 May 2010 19:48:15 +0000 Subject: [PATCH] Define an updatable view query.expr_xbind as those rows in query.expression where type = 'xbind'. 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/0256.schema.query-bind-expr-view.sql M Open-ILS/examples/fm_IDL.xml git-svn-id: svn://svn.open-ils.org/ILS/trunk@16414 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 16 ++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/008.schema.query.sql | 100 +++++++++++++++++++++ .../upgrade/0256.schema.query-bind-expr-view.sql | 55 ++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0256.schema.query-bind-expr-view.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index cf889ea5a6..3f61007c04 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -6727,6 +6727,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index fc1a1d99e2..432719a02b 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0255'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0256'); -- Scott McKellar CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/008.schema.query.sql b/Open-ILS/src/sql/Pg/008.schema.query.sql index bf96b8d20e..67494977f3 100644 --- a/Open-ILS/src/sql/Pg/008.schema.query.sql +++ b/Open-ILS/src/sql/Pg/008.schema.query.sql @@ -323,6 +323,106 @@ CREATE OR REPLACE RULE query_expr_xbet_delete_rule AS 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 bind variable expressions + +CREATE OR REPLACE VIEW query.expr_xbind AS + SELECT + id, + parenthesize, + parent_expr, + seq_no, + bind_value + 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 diff --git a/Open-ILS/src/sql/Pg/upgrade/0256.schema.query-bind-expr-view.sql b/Open-ILS/src/sql/Pg/upgrade/0256.schema.query-bind-expr-view.sql new file mode 100644 index 0000000000..c49d316a0c --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0256.schema.query-bind-expr-view.sql @@ -0,0 +1,55 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0256'); -- Scott McKellar + +-- 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; + +COMMIT; -- 2.11.0