[open-ils-commits] r15978 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Mar 25 12:06:06 EDT 2010
Author: miker
Date: 2010-03-25 12:06:03 -0400 (Thu, 25 Mar 2010)
New Revision: 15978
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0212.schema.acq.lineitem_attr_ingest_multivalue.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
Log:
capture multiple values (on pg 8.4) of an attr def
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-03-25 16:03:48 UTC (rev 15977)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-03-25 16:06:03 UTC (rev 15978)
@@ -59,7 +59,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0211'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0212'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql 2010-03-25 16:03:48 UTC (rev 15977)
+++ trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql 2010-03-25 16:06:03 UTC (rev 15978)
@@ -939,11 +939,12 @@
vendor_identifier
*/
-CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $$
+CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$
DECLARE
value TEXT;
atype TEXT;
prov INT;
+ pos INT;
adef RECORD;
xpath_string TEXT;
BEGIN
@@ -965,20 +966,30 @@
SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
END IF;
- SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
+ xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
- IF (value IS NOT NULL AND value <> '') THEN
- INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
- VALUES (NEW.id, adef.id, atype, adef.code, value);
- END IF;
+ pos := 1;
+ LOOP
+ SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
+
+ IF (value IS NOT NULL AND value <> '') THEN
+ INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
+ VALUES (NEW.id, adef.id, atype, adef.code, value);
+ ELSE
+ EXIT;
+ END IF;
+
+ pos := pos + 1;
+ END LOOP;
+
END IF;
END LOOP;
RETURN NULL;
END;
-$$ LANGUAGE PLPGSQL;
+$function$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION public.cleanup_acq_marc ( ) RETURNS TRIGGER AS $$
BEGIN
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0212.schema.acq.lineitem_attr_ingest_multivalue.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0212.schema.acq.lineitem_attr_ingest_multivalue.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0212.schema.acq.lineitem_attr_ingest_multivalue.sql 2010-03-25 16:06:03 UTC (rev 15978)
@@ -0,0 +1,58 @@
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0212');
+
+CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$
+DECLARE
+ value TEXT;
+ atype TEXT;
+ prov INT;
+ pos INT;
+ adef RECORD;
+ xpath_string TEXT;
+BEGIN
+ FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP
+
+ SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
+
+ IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN
+ IF (atype = 'lineitem_provider_attr_definition') THEN
+ SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
+ CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
+ END IF;
+
+ IF (atype = 'lineitem_provider_attr_definition') THEN
+ SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
+ ELSIF (atype = 'lineitem_marc_attr_definition') THEN
+ SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id;
+ ELSIF (atype = 'lineitem_generated_attr_definition') THEN
+ SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
+ END IF;
+
+ xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
+
+ pos := 1;
+
+ LOOP
+ SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
+
+ IF (value IS NOT NULL AND value <> '') THEN
+ INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
+ VALUES (NEW.id, adef.id, atype, adef.code, value);
+ ELSE
+ EXIT;
+ END IF;
+
+ pos := pos + 1;
+ END LOOP;
+
+ END IF;
+
+ END LOOP;
+
+ RETURN NULL;
+END;
+$function$ LANGUAGE PLPGSQL;
+
+COMMIT;
More information about the open-ils-commits
mailing list