From 98504642aacf785ee36dbfa4f88969e378776640 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 23 Dec 2010 01:27:30 +0000 Subject: [PATCH] allow vandelay.replace_field() to handle a complex field spec by splitting and looping; bringing 1.6.1-2.0 upgrade script up to date git-svn-id: svn://svn.open-ils.org/ILS/trunk@19043 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 29 +++++++++++------- Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql | 33 ++++++++++++-------- .../upgrade/0473.schema.vandelay-replace_field.sql | 35 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0473.schema.vandelay-replace_field.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 9144971514..dcfebc3118 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -70,7 +70,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- dbs +INSERT INTO config.upgrade_log (version) VALUES ('0473'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 769e790451..0add48df0e 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -445,17 +445,26 @@ CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml DECLARE xml_output TEXT; parsed_target TEXT; + curr_field TEXT; BEGIN - parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below - xml_output := vandelay.strip_field( parsed_target, field); - - IF xml_output <> parsed_target AND field ~ E'~' THEN - -- we removed something, and there was a regexp restriction in the field definition, so proceed - xml_output := vandelay.add_field( xml_output, source_xml, field, 1 ); - ELSIF field !~ E'~' THEN - -- No regexp restriction, add the field - xml_output := vandelay.add_field( xml_output, source_xml, field, 0 ); - END IF; + + parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalizes the format of the xml for the IF below + + FOR curr_field IN SELECT UNNEST( STRING_TO_ARRAY(field, ',') ) LOOP -- naive split, but it's the same we use in the perl + + xml_output := vandelay.strip_field( parsed_target, curr_field); + + IF xml_output <> parsed_target AND curr_field ~ E'~' THEN + -- we removed something, and there was a regexp restriction in the curr_field definition, so proceed + xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 1 ); + ELSIF curr_field !~ E'~' THEN + -- No regexp restriction, add the curr_field + xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 0 ); + END IF; + + parsed_target := xml_output; -- in prep for any following loop iterations + + END LOOP; RETURN xml_output; END; diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index 7cf50411e4..2dc7043be9 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -31,7 +31,7 @@ UPDATE biblio.record_entry SET marc = '