[open-ils-commits] r19102 - in branches/rel_2_0/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jan 4 11:10:25 EST 2011
Author: miker
Date: 2011-01-04 11:10:23 -0500 (Tue, 04 Jan 2011)
New Revision: 19102
Added:
branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0474.schema.xpath_table-empty-fields.sql
Modified:
branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
Log:
oils_xpath_table was too strict about field nullness -- we need /some/ data, not /all/ data, to be present
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-01-04 16:09:17 UTC (rev 19101)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-01-04 16:10:23 UTC (rev 19102)
@@ -308,7 +308,7 @@
q := $q$
SELECT * FROM (
SELECT $q$ || ARRAY_TO_STRING( select_list, ', ' ) || $q$ FROM $q$ || relation_name || $q$ WHERE ($q$ || criteria || $q$)
-)x WHERE $q$ || ARRAY_TO_STRING( where_list, ' AND ' );
+)x WHERE $q$ || ARRAY_TO_STRING( where_list, ' OR ' );
-- RAISE NOTICE 'query: %', q;
FOR out_record IN EXECUTE q LOOP
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-01-04 16:09:17 UTC (rev 19101)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-01-04 16:10:23 UTC (rev 19102)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0473'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0474'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2011-01-04 16:09:17 UTC (rev 19101)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2011-01-04 16:10:23 UTC (rev 19102)
@@ -31,7 +31,7 @@
-- Highest-numbered individual upgrade script incorporated herein:
-INSERT INTO config.upgrade_log (version) VALUES ('0473');
+INSERT INTO config.upgrade_log (version) VALUES ('0474');
-- Push the auri sequence in case it's out of date
-- Add 2 as the sequence value must be 1 or higher, and seed is -1
@@ -11257,7 +11257,7 @@
q := $q$
SELECT * FROM (
SELECT $q$ || ARRAY_TO_STRING( select_list, ', ' ) || $q$ FROM $q$ || relation_name || $q$ WHERE ($q$ || criteria || $q$)
-)x WHERE $q$ || ARRAY_TO_STRING( where_list, ' AND ' );
+)x WHERE $q$ || ARRAY_TO_STRING( where_list, ' OR ' );
-- RAISE NOTICE 'query: %', q;
FOR out_record IN EXECUTE q LOOP
Copied: branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0474.schema.xpath_table-empty-fields.sql (from rev 19101, trunk/Open-ILS/src/sql/Pg/upgrade/0474.schema.xpath_table-empty-fields.sql)
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0474.schema.xpath_table-empty-fields.sql (rev 0)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0474.schema.xpath_table-empty-fields.sql 2011-01-04 16:10:23 UTC (rev 19102)
@@ -0,0 +1,67 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0474'); -- miker
+
+CREATE OR REPLACE FUNCTION oils_xpath_table ( key TEXT, document_field TEXT, relation_name TEXT, xpaths TEXT, criteria TEXT ) RETURNS SETOF RECORD AS $func$
+DECLARE
+ xpath_list TEXT[];
+ select_list TEXT[];
+ where_list TEXT[];
+ q TEXT;
+ out_record RECORD;
+ empty_test RECORD;
+BEGIN
+ xpath_list := STRING_TO_ARRAY( xpaths, '|' );
+
+ select_list := ARRAY_APPEND( select_list, key || '::INT AS key' );
+
+ FOR i IN 1 .. ARRAY_UPPER(xpath_list,1) LOOP
+ IF xpath_list[i] = 'null()' THEN
+ select_list := ARRAY_APPEND( select_list, 'NULL::TEXT AS c_' || i );
+ ELSE
+ select_list := ARRAY_APPEND(
+ select_list,
+ $sel$
+ EXPLODE_ARRAY(
+ COALESCE(
+ NULLIF(
+ oils_xpath(
+ $sel$ ||
+ quote_literal(
+ CASE
+ WHEN xpath_list[i] ~ $re$/[^/[]*@[^/]+$$re$ OR xpath_list[i] ~ $re$text\(\)$$re$ THEN xpath_list[i]
+ ELSE xpath_list[i] || '//text()'
+ END
+ ) ||
+ $sel$,
+ $sel$ || document_field || $sel$
+ ),
+ '{}'::TEXT[]
+ ),
+ '{NULL}'::TEXT[]
+ )
+ ) AS c_$sel$ || i
+ );
+ where_list := ARRAY_APPEND(
+ where_list,
+ 'c_' || i || ' IS NOT NULL'
+ );
+ END IF;
+ END LOOP;
+
+ q := $q$
+SELECT * FROM (
+ SELECT $q$ || ARRAY_TO_STRING( select_list, ', ' ) || $q$ FROM $q$ || relation_name || $q$ WHERE ($q$ || criteria || $q$)
+)x WHERE $q$ || ARRAY_TO_STRING( where_list, ' OR ' );
+ -- RAISE NOTICE 'query: %', q;
+
+ FOR out_record IN EXECUTE q LOOP
+ RETURN NEXT out_record;
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL IMMUTABLE;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list