[open-ils-commits] r16824 - 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
Mon Jun 28 15:45:48 EDT 2010


Author: scottmk
Date: 2010-06-28 15:45:43 -0400 (Mon, 28 Jun 2010)
New Revision: 16824

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0322.schema.query.no-xfld-expr.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:
Represent a subfield expression as a variant of a function call
expression, rather than a function call in its own right.

1. Eliminate 'xfld' as a valid value for query.expression.type.

2. Eliminate the query.expr_xfld view.

3. Expand the query.expr_xfunc view to include the column_name column.

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/0322.schema.query.no-xfld-expr.sql
M    Open-ILS/examples/fm_IDL.xml


Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2010-06-28 17:52:49 UTC (rev 16823)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2010-06-28 19:45:43 UTC (rev 16824)
@@ -7144,30 +7144,13 @@
 		</permacrud>
 	</class>
 
-	<class id="xfld" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xfld" oils_persist:tablename="query.expr_xfld" reporter:label="Field 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="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"/>
-			<link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
-		</links>
-		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
-		</permacrud>
-	</class>
-
 	<class id="xfunc" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xfunc" oils_persist:tablename="query.expr_xfunc" reporter:label="Function 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="Column Name" name="column_name" reporter:datatype="text"/>
 			<field reporter:label="Function ID" name="function_id" reporter:datatype="link"/>
 			<field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
 		</fields>

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-06-28 17:52:49 UTC (rev 16823)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-06-28 19:45:43 UTC (rev 16824)
@@ -68,7 +68,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0321'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0322'); -- 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-06-28 17:52:49 UTC (rev 16823)
+++ trunk/Open-ILS/src/sql/Pg/008.schema.query.sql	2010-06-28 19:45:43 UTC (rev 16824)
@@ -135,7 +135,6 @@
 									'xcast',   -- cast
 									'xcol',    -- column
 									'xex',     -- exists
-									'xfld',    -- field
 									'xfunc',   -- function
 									'xin',     -- in
 									'xisnull', -- is null
@@ -662,64 +661,6 @@
     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,
-		COALESCE(NEW.negate, false)
-    );
-
-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
@@ -728,6 +669,7 @@
 		parenthesize,
 		parent_expr,
 		seq_no,
+		column_name,
 		function_id,
 		negate
     FROM
@@ -744,6 +686,7 @@
 		parenthesize,
 		parent_expr,
 		seq_no,
+		column_name,
 		function_id,
 		negate
     ) VALUES (
@@ -752,6 +695,7 @@
         COALESCE(NEW.parenthesize, FALSE),
         NEW.parent_expr,
         COALESCE(NEW.seq_no, 1),
+		NEW.column_name,
 		NEW.function_id,
 		COALESCE(NEW.negate, false)
     );
@@ -764,6 +708,7 @@
         parenthesize = NEW.parenthesize,
         parent_expr = NEW.parent_expr,
         seq_no = NEW.seq_no,
+		column_name = NEW.column_name,
 		function_id = NEW.function_id,
 		negate = NEW.negate
     WHERE

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0322.schema.query.no-xfld-expr.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0322.schema.query.no-xfld-expr.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0322.schema.query.no-xfld-expr.sql	2010-06-28 19:45:43 UTC (rev 16824)
@@ -0,0 +1,112 @@
+-- Instead of representing a subfield as a distinct expression type in its
+-- own right, express it as a variant of the xfunc type -- i.e. a function
+-- call with a column name.  In consequence:
+
+-- 1. Eliminate the query.expr_xfld view;
+
+-- 2. Expand the query.expr_xfunc view to include column_name;
+
+-- 3. Eliminate 'xfld' as a valid value for expression.type.
+
+-- Theoretically, the latter change could create a problem if you already
+-- have xfld rows in your expression table.  You would have to delete them,
+-- and represent the corresponding expressions by other means.  In practice
+-- this is exceedingly unlikely, since subfields were never even
+-- supported until earlier today.
+
+-- We start by dropping two views; the first for good, and the second so that
+-- we can replace it.  We drop them outside the transaction so that the
+-- script won't fail if the views don't exist yet.
+
+DROP VIEW query.expr_xfld;
+
+DROP VIEW query.expr_xfunc;
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0322'); -- Scott McKellar
+
+-- Eliminate 'xfld' as an expression type
+
+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
+        'xfunc',   -- function
+        'xin',     -- in
+        'xisnull', -- is null
+        'xnull',   -- null
+        'xnum',    -- number
+        'xop',     -- operator
+        'xser',    -- series
+        'xstr',    -- string
+        'xsubq'    -- subquery
+    ) );
+
+-- Create updatable view for function call expressions
+
+CREATE OR REPLACE VIEW query.expr_xfunc AS
+    SELECT
+        id,
+        parenthesize,
+        parent_expr,
+        seq_no,
+        column_name,
+        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,
+        column_name,
+        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.column_name,
+        NEW.function_id,
+        COALESCE(NEW.negate, false)
+    );
+
+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,
+        column_name = NEW.column_name,
+        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;
+
+COMMIT;



More information about the open-ils-commits mailing list