[open-ils-commits] r16466 - in trunk/Open-ILS: examples src/sql/Pg src/sql/Pg/upgrade (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu May 20 16:35:18 EDT 2010
Author: scottmk
Date: 2010-05-20 16:35:12 -0400 (Thu, 20 May 2010)
New Revision: 16466
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0269.schema.query-xisnull.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/008.schema.query.sql
Log:
Create database support for IS [NOT] NULL expressions
in stored queries.
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/0269.schema.query-xisnull.sql
M Open-ILS/examples/fm_IDL.xml
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2010-05-20 16:01:51 UTC (rev 16465)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2010-05-20 20:35:12 UTC (rev 16466)
@@ -6905,6 +6905,23 @@
</permacrud>
</class>
+ <class id="xisnull" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xisnull" oils_persist:tablename="query.expr_xisnull" reporter:label="IS NULL Expression">
+ <fields oils_persist:primary="id" oils_persist:sequence="expression_id_seq">
+ <field reporter:label="Expression ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Is Parenthesized" name="parenthesize" reporter:datatype="bool"/>
+ <field reporter:label="Parent Expression" name="parent_expr" reporter:datatype="link"/>
+ <field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
+ <field reporter:label="Left Operand" name="left_operand" reporter:datatype="link"/>
+ <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
+ </fields>
+ <links>
+ <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="left_operand" reltype="might_have" key="id" map="" class="qxp"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
<class id="xnull" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xnull" oils_persist:tablename="query.expr_xnull" reporter:label="Null Expression">
<fields oils_persist:primary="id" oils_persist:sequence="expression_id_seq">
<field reporter:label="Expression ID" name="id" reporter:datatype="id"/>
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-20 16:01:51 UTC (rev 16465)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-20 20:35:12 UTC (rev 16466)
@@ -65,7 +65,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0268'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0269'); -- 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-20 16:01:51 UTC (rev 16465)
+++ trunk/Open-ILS/src/sql/Pg/008.schema.query.sql 2010-05-20 20:35:12 UTC (rev 16466)
@@ -134,6 +134,7 @@
'xfld', -- field
'xfunc', -- function
'xin', -- in
+ 'xisnull' -- is null
'xnull', -- null
'xnum', -- number
'xop', -- operator
@@ -868,6 +869,60 @@
DO INSTEAD
DELETE FROM query.expression WHERE id = OLD.id;
+-- Create updatable view for IS NULL expressions
+
+CREATE OR REPLACE VIEW query.expr_xisnull AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ left_operand,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xisnull';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xisnull_update_rule AS
+ ON UPDATE TO query.expr_xisnull
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ left_operand = NEW.left_operand,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xisnull_delete_rule AS
+ ON DELETE TO query.expr_xisnull
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
-- Create updatable view for NULL expressions
CREATE OR REPLACE VIEW query.expr_xnull AS
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0269.schema.query-xisnull.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0269.schema.query-xisnull.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0269.schema.query-xisnull.sql 2010-05-20 20:35:12 UTC (rev 16466)
@@ -0,0 +1,85 @@
+BEGIN;
+
+-- Create new expression type for IS [NOT] NULL
+
+INSERT INTO config.upgrade_log (version) VALUES ('0269'); -- Scott McKellar
+
+ALTER TABLE query.expression
+ DROP CONSTRAINT expression_type;
+
+ALTER TABLE query.expression
+ ADD CONSTRAINT expression_type CHECK
+ ( type IN (
+ 'xbet', -- between
+ 'xbind', -- bind variable
+ 'xbool', -- boolean
+ 'xcase', -- case
+ 'xcast', -- cast
+ 'xcol', -- column
+ 'xex', -- exists
+ 'xfld', -- field
+ 'xfunc', -- function
+ 'xin', -- in
+ 'xisnull' -- is null
+ 'xnull', -- null
+ 'xnum', -- number
+ 'xop', -- operator
+ 'xstr', -- string
+ 'xsubq' -- subquery
+ ) );
+
+-- Create updatable view for IS NULL expressions
+
+CREATE OR REPLACE VIEW query.expr_xisnull AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ left_operand,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xisnull';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xisnull_update_rule AS
+ ON UPDATE TO query.expr_xisnull
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ left_operand = NEW.left_operand,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xisnull_delete_rule AS
+ ON DELETE TO query.expr_xisnull
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+COMMIT;
More information about the open-ils-commits
mailing list