<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="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
<link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<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="function_id" reltype="might_have" key="id" map="" class="qfs"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="function_id" reltype="has_a" key="id" map="" class="qfs"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<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"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<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="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>
<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="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<field reporter:label="Literal" name="literal" reporter:datatype="text"/>
</fields>
<links>
- <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<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="right_operand" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="right_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="xser" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xser" oils_persist:tablename="query.expr_xser" reporter:label="Operator 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="Operator" name="operator" 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"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<field reporter:label="Literal" name="literal" reporter:datatype="text"/>
</fields>
<links>
- <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
<field reporter:label="Subquery" name="subquery" reporter:datatype="link"/>
</fields>
<links>
- <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
- <link field="subquery" reltype="might_have" key="id" map="" class="qsq"/>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
</permacrud>
'xnull', -- null
'xnum', -- number
'xop', -- operator
+ 'xser', -- series
'xstr', -- string
'xsubq' -- subquery
) ),
DO INSTEAD
DELETE FROM query.expression WHERE id = OLD.id;
+-- Create updatable view for series expressions,
+-- i.e. series of expressions separated by operators
+
+CREATE OR REPLACE VIEW query.expr_xser AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ operator,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xser';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xser_update_rule AS
+ ON UPDATE TO query.expr_xser
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ operator = NEW.operator,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
+ ON DELETE TO query.expr_xser
+ 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
--- /dev/null
+BEGIN;
+
+-- Create new expression type 'xser' for serial expressions,
+-- i.e. series of expressions separated by operators
+
+INSERT INTO config.upgrade_log (version) VALUES ('0280'); -- 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
+ 'xser', -- series
+ 'xstr', -- string
+ 'xsubq' -- subquery
+ ) );
+
+-- Create updatable view for series expressions
+
+CREATE OR REPLACE VIEW query.expr_xser AS
+ SELECT
+ id,
+ parenthesize,
+ parent_expr,
+ seq_no,
+ operator,
+ negate
+ FROM
+ query.expression
+ WHERE
+ type = 'xser';
+
+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,
+ NEW.negate
+ );
+
+CREATE OR REPLACE RULE query_expr_xser_update_rule AS
+ ON UPDATE TO query.expr_xser
+ DO INSTEAD
+ UPDATE query.expression SET
+ id = NEW.id,
+ parenthesize = NEW.parenthesize,
+ parent_expr = NEW.parent_expr,
+ seq_no = NEW.seq_no,
+ operator = NEW.operator,
+ negate = NEW.negate
+ WHERE
+ id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
+ ON DELETE TO query.expr_xser
+ DO INSTEAD
+ DELETE FROM query.expression WHERE id = OLD.id;
+
+COMMIT;