[open-ils-commits] r16408 - 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
Sat May 8 16:17:48 EDT 2010
Author: scottmk
Date: 2010-05-08 16:17:42 -0400 (Sat, 08 May 2010)
New Revision: 16408
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0253.schema.query_expr_view.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:
Revise the updatable views for the various types of query.expression:
1. Rename query.expr_string to query.expr_xstr, for consistency.
2. Add a "negate" column to each view, except for query.expr_xnum
and query.expr_xstr.
3. Add a "left_operand" column to query.expr_xin, correcting an
earlier oversignt.
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/0253.schema.query_expr_view.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-07 19:31:08 UTC (rev 16407)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2010-05-08 20:17:42 UTC (rev 16408)
@@ -6703,6 +6703,7 @@
<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="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
@@ -6718,6 +6719,7 @@
<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="Literal" name="literal" reporter:datatype="text"/>
+ <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
@@ -6732,6 +6734,7 @@
<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="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
@@ -6748,6 +6751,7 @@
<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="Cast Type" name="cast_type" reporter:datatype="link"/>
+ <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
@@ -6766,6 +6770,7 @@
<field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
<field reporter:label="Table Alias" name="table_alias" reporter:datatype="text"/>
<field reporter:label="Column Name" name="column_name" reporter:datatype="text"/>
+ <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
@@ -6781,6 +6786,7 @@
<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="Subquery" name="subquery" 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"/>
@@ -6798,6 +6804,7 @@
<field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
<field reporter:label="Column Name" name="column_name" reporter:datatype="text"/>
<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="has_a" key="id" map="" class="qxp"/>
@@ -6814,6 +6821,7 @@
<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="Function ID" name="function_id" 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"/>
@@ -6829,10 +6837,13 @@
<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="Subquery" name="subquery" 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"/>
<link field="subquery" reltype="might_have" key="id" map="" class="qsq"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
@@ -6845,6 +6856,7 @@
<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="Negate?" name="negate" reporter:datatype="bool"/>
</fields>
<links>
<link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
@@ -6877,6 +6889,7 @@
<field reporter:label="Left Operand" name="left_operand" reporter:datatype="link"/>
<field reporter:label="Operator" name="operator" reporter:datatype="text"/>
<field reporter:label="Right Operand" name="right_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"/>
@@ -6887,7 +6900,7 @@
</permacrud>
</class>
- <class id="xstr" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_string" oils_persist:tablename="query.expr_string" reporter:label="String Expression">
+ <class id="xstr" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xstr" oils_persist:tablename="query.expr_xstr" reporter:label="String 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"/>
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-07 19:31:08 UTC (rev 16407)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-08 20:17:42 UTC (rev 16408)
@@ -65,7 +65,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0252'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0253'); -- 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-07 19:31:08 UTC (rev 16407)
+++ trunk/Open-ILS/src/sql/Pg/008.schema.query.sql 2010-05-08 20:17:42 UTC (rev 16408)
@@ -268,7 +268,8 @@
id,
parenthesize,
parent_expr,
- seq_no
+ seq_no,
+ negate
FROM
query.expression
WHERE
@@ -282,13 +283,15 @@
type,
parenthesize,
parent_expr,
- seq_no
+ 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.seq_no, 1),
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xbet_update_rule AS
@@ -298,7 +301,8 @@
id = NEW.id,
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
- seq_no = NEW.seq_no
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -315,7 +319,8 @@
parenthesize,
parent_expr,
seq_no,
- literal
+ literal,
+ negate
FROM
query.expression
WHERE
@@ -330,14 +335,16 @@
parenthesize,
parent_expr,
seq_no,
- literal
+ 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
+ NEW.literal,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xbool_update_rule AS
@@ -348,7 +355,8 @@
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
- literal = NEW.literal
+ literal = NEW.literal,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -364,7 +372,8 @@
id,
parenthesize,
parent_expr,
- seq_no
+ seq_no,
+ negate
FROM
query.expression
WHERE
@@ -378,13 +387,15 @@
type,
parenthesize,
parent_expr,
- seq_no
+ 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.seq_no, 1),
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xcase_update_rule AS
@@ -394,7 +405,8 @@
id = NEW.id,
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
- seq_no = NEW.seq_no
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -412,7 +424,8 @@
parent_expr,
seq_no,
left_operand,
- cast_type
+ cast_type,
+ negate
FROM
query.expression
WHERE
@@ -428,7 +441,8 @@
parent_expr,
seq_no,
left_operand,
- cast_type
+ cast_type,
+ negate
) VALUES (
COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
'xcast',
@@ -436,7 +450,8 @@
NEW.parent_expr,
COALESCE(NEW.seq_no, 1),
NEW.left_operand,
- NEW.cast_type
+ NEW.cast_type,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xcast_update_rule AS
@@ -448,7 +463,8 @@
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
left_operand = NEW.left_operand,
- cast_type = NEW.cast_type
+ cast_type = NEW.cast_type,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -466,7 +482,8 @@
parent_expr,
seq_no,
table_alias,
- column_name
+ column_name,
+ negate
FROM
query.expression
WHERE
@@ -482,7 +499,8 @@
parent_expr,
seq_no,
table_alias,
- column_name
+ column_name,
+ negate
) VALUES (
COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
'xcol',
@@ -490,7 +508,8 @@
NEW.parent_expr,
COALESCE(NEW.seq_no, 1),
NEW.table_alias,
- NEW.column_name
+ NEW.column_name,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xcol_update_rule AS
@@ -502,7 +521,8 @@
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
table_alias = NEW.table_alias,
- column_name = NEW.column_name
+ column_name = NEW.column_name,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -519,7 +539,8 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ subquery,
+ negate
FROM
query.expression
WHERE
@@ -534,14 +555,16 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ 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
+ NEW.subquery,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xex_update_rule AS
@@ -552,7 +575,8 @@
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
- subquery = NEW.subquery
+ subquery = NEW.subquery,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -570,7 +594,8 @@
parent_expr,
seq_no,
column_name,
- left_operand
+ left_operand,
+ negate
FROM
query.expression
WHERE
@@ -586,7 +611,8 @@
parent_expr,
seq_no,
column_name,
- left_operand
+ left_operand,
+ negate
) VALUES (
COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
'xfld',
@@ -594,7 +620,8 @@
NEW.parent_expr,
COALESCE(NEW.seq_no, 1),
NEW.column_name,
- NEW.left_operand
+ NEW.left_operand,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xfld_update_rule AS
@@ -606,7 +633,8 @@
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
column_name = NEW.column_name,
- left_operand = NEW.left_operand
+ left_operand = NEW.left_operand,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -623,7 +651,8 @@
parenthesize,
parent_expr,
seq_no,
- function_id
+ function_id,
+ negate
FROM
query.expression
WHERE
@@ -638,14 +667,16 @@
parenthesize,
parent_expr,
seq_no,
- function_id
+ 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
+ NEW.function_id,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xfunc_update_rule AS
@@ -656,7 +687,8 @@
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
- function_id = NEW.function_id
+ function_id = NEW.function_id,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -673,7 +705,9 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ left_operand,
+ subquery,
+ negate
FROM
query.expression
WHERE
@@ -688,14 +722,18 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ 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.subquery
+ NEW.left_operand,
+ NEW.subquery,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xin_update_rule AS
@@ -706,7 +744,9 @@
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
- subquery = NEW.subquery
+ left_operand = NEW.left_operand,
+ subquery = NEW.subquery,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -722,7 +762,8 @@
id,
parenthesize,
parent_expr,
- seq_no
+ seq_no,
+ negate
FROM
query.expression
WHERE
@@ -736,13 +777,15 @@
type,
parenthesize,
parent_expr,
- seq_no
+ 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.seq_no, 1),
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xnull_update_rule AS
@@ -752,7 +795,8 @@
id = NEW.id,
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
- seq_no = NEW.seq_no
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -821,7 +865,8 @@
seq_no,
left_operand,
operator,
- right_operand
+ right_operand,
+ negate
FROM
query.expression
WHERE
@@ -838,7 +883,8 @@
seq_no,
left_operand,
operator,
- right_operand
+ right_operand,
+ negate
) VALUES (
COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
'xop',
@@ -847,7 +893,8 @@
COALESCE(NEW.seq_no, 1),
NEW.left_operand,
NEW.operator,
- NEW.right_operand
+ NEW.right_operand,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xop_update_rule AS
@@ -860,7 +907,8 @@
seq_no = NEW.seq_no,
left_operand = NEW.left_operand,
operator = NEW.operator,
- right_operand = NEW.right_operand
+ right_operand = NEW.right_operand,
+ negate = NEW.negate
WHERE
id = OLD.id;
@@ -871,7 +919,7 @@
-- Create updatable view for string literal expressions
-CREATE OR REPLACE VIEW query.expr_string AS
+CREATE OR REPLACE VIEW query.expr_xstr AS
SELECT
id,
parenthesize,
@@ -884,7 +932,7 @@
type = 'xstr';
CREATE OR REPLACE RULE query_expr_string_insert_rule AS
- ON INSERT TO query.expr_string
+ ON INSERT TO query.expr_xstr
DO INSTEAD
INSERT INTO query.expression (
id,
@@ -903,7 +951,7 @@
);
CREATE OR REPLACE RULE query_expr_string_update_rule AS
- ON UPDATE TO query.expr_string
+ ON UPDATE TO query.expr_xstr
DO INSTEAD
UPDATE query.expression SET
id = NEW.id,
@@ -915,7 +963,7 @@
id = OLD.id;
CREATE OR REPLACE RULE query_expr_string_delete_rule AS
- ON DELETE TO query.expr_string
+ ON DELETE TO query.expr_xstr
DO INSTEAD
DELETE FROM query.expression WHERE id = OLD.id;
@@ -927,7 +975,8 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ subquery,
+ negate
FROM
query.expression
WHERE
@@ -942,14 +991,16 @@
parenthesize,
parent_expr,
seq_no,
- subquery
+ 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
+ NEW.subquery,
+ NEW.negate
);
CREATE OR REPLACE RULE query_expr_xsubq_update_rule AS
@@ -960,7 +1011,8 @@
parenthesize = NEW.parenthesize,
parent_expr = NEW.parent_expr,
seq_no = NEW.seq_no,
- subquery = NEW.subquery
+ subquery = NEW.subquery,
+ negate = NEW.negate
WHERE
id = OLD.id;
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0253.schema.query_expr_view.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0253.schema.query_expr_view.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0253.schema.query_expr_view.sql 2010-05-08 20:17:42 UTC (rev 16408)
@@ -0,0 +1,749 @@
+-- Add a negate column to most of the query expression views,
+-- plus a left_operand column in the case of query.expr_xin.
+
+-- The DROP VIEW statements will fail harmlessly if the views
+-- don't exist, and are therefore outside of the transaction.
+
+DROP VIEW query.expr_xbet CASCADE;
+
+DROP VIEW query.expr_xbool CASCADE;
+
+DROP VIEW query.expr_xcase CASCADE;
+
+DROP VIEW query.expr_xcast CASCADE;
+
+DROP VIEW query.expr_xcol CASCADE;
+
+DROP VIEW query.expr_xex CASCADE;
+
+DROP VIEW query.expr_xfld CASCADE;
+
+DROP VIEW query.expr_xfunc CASCADE;
+
+DROP VIEW query.expr_xin CASCADE;
+
+DROP VIEW query.expr_xnull CASCADE;
+
+DROP VIEW query.expr_xop CASCADE;
+
+DROP VIEW query.expr_string CASCADE;
+
+DROP VIEW query.expr_xsubq CASCADE;
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0253'); -- Scott McKellar
+
+-- Create updatable views -------------------------------------------
+
+-- Create updatable view for BETWEEN expressions
+
+CREATE OR REPLACE VIEW query.expr_xbet AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xbet';
+
+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),
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xbet_update_rule AS
+ ON UPDATE TO query.expr_xbet
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xbet_delete_rule AS
+ ON DELETE TO query.expr_xbet
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for boolean expressions
+
+CREATE OR REPLACE VIEW query.expr_xbool AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ literal,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xbool';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xbool_update_rule AS
+ ON UPDATE TO query.expr_xbool
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ literal = NEW.literal,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xbool_delete_rule AS
+ ON DELETE TO query.expr_xbool
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for CASE expressions
+
+CREATE OR REPLACE VIEW query.expr_xcase AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xcase';
+
+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),
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xcase_update_rule AS
+ ON UPDATE TO query.expr_xcase
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xcase_delete_rule AS
+ ON DELETE TO query.expr_xcase
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for cast expressions
+
+CREATE OR REPLACE VIEW query.expr_xcast AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ left_operand,
+ cast_type,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xcast';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xcast_update_rule AS
+ ON UPDATE TO query.expr_xcast
+ 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,
+ cast_type = NEW.cast_type,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xcast_delete_rule AS
+ ON DELETE TO query.expr_xcast
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for column expressions
+
+CREATE OR REPLACE VIEW query.expr_xcol AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ table_alias,
+ column_name,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xcol';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xcol_update_rule AS
+ ON UPDATE TO query.expr_xcol
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ table_alias = NEW.table_alias,
+ column_name = NEW.column_name,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xcol_delete_rule AS
+ ON DELETE TO query.expr_xcol
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for EXISTS expressions
+
+CREATE OR REPLACE VIEW query.expr_xex AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ subquery,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xex';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xex_update_rule AS
+ ON UPDATE TO query.expr_xex
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ subquery = NEW.subquery,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xex_delete_rule AS
+ ON DELETE TO query.expr_xex
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for field expressions
+
+CREATE OR REPLACE VIEW query.expr_xfld AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ column_name,
+ left_operand,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xfld';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xfld_update_rule AS
+ ON UPDATE TO query.expr_xfld
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ column_name = NEW.column_name,
+ left_operand = NEW.left_operand,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xfld_delete_rule AS
+ ON DELETE TO query.expr_xfld
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for function call expressions
+
+CREATE OR REPLACE VIEW query.expr_xfunc AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ function_id,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xfunc';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xfunc_update_rule AS
+ ON UPDATE TO query.expr_xfunc
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ function_id = NEW.function_id,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xfunc_delete_rule AS
+ ON DELETE TO query.expr_xfunc
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for IN expressions
+
+CREATE OR REPLACE VIEW query.expr_xin AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ left_operand,
+ subquery,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xin';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xin_update_rule AS
+ ON UPDATE TO query.expr_xin
+ 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,
+ subquery = NEW.subquery,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xin_delete_rule AS
+ ON DELETE TO query.expr_xin
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for NULL expressions
+
+CREATE OR REPLACE VIEW query.expr_xnull AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xnull';
+
+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),
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xnull_update_rule AS
+ ON UPDATE TO query.expr_xnull
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xnull_delete_rule AS
+ ON DELETE TO query.expr_xnull
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for operator expressions
+
+CREATE OR REPLACE VIEW query.expr_xop AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ left_operand,
+ operator,
+ right_operand,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xop';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xop_update_rule AS
+ ON UPDATE TO query.expr_xop
+ 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,
+ operator = NEW.operator,
+ right_operand = NEW.right_operand,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xop_delete_rule AS
+ ON DELETE TO query.expr_xop
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for string literal expressions
+
+CREATE OR REPLACE VIEW query.expr_xstr AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ literal
+ FROM
+ query.expression
+ WHERE
+ type = 'xstr';
+
+CREATE OR REPLACE RULE query_expr_string_insert_rule AS
+ ON INSERT TO query.expr_xstr
+ DO INSTEAD
+ INSERT INTO query.expression (
+ id,
+ type,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ literal
+ ) VALUES (
+ COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+ 'xstr',
+ COALESCE(NEW.parenthesize, FALSE),
+ NEW.parent_expr,
+ COALESCE(NEW.seq_no, 1),
+ NEW.literal
+ );
+
+CREATE OR REPLACE RULE query_expr_string_update_rule AS
+ ON UPDATE TO query.expr_xstr
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ literal = NEW.literal
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_string_delete_rule AS
+ ON DELETE TO query.expr_xstr
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+-- Create updatable view for subquery expressions
+
+CREATE OR REPLACE VIEW query.expr_xsubq AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ subquery,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xsubq';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xsubq_update_rule AS
+ ON UPDATE TO query.expr_xsubq
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ subquery = NEW.subquery,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xsubq_delete_rule AS
+ ON DELETE TO query.expr_xsubq
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+COMMIT;
More information about the open-ils-commits
mailing list