[open-ils-commits] r20106 - in branches/rel_2_1/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Apr 15 12:24:20 EDT 2011
Author: miker
Date: 2011-04-15 12:24:17 -0400 (Fri, 15 Apr 2011)
New Revision: 20106
Added:
branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0519.schema.extract_all_fixed_fields_from_leader.sql
Modified:
branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_1/Open-ILS/src/sql/Pg/030.schema.metabib.sql
Log:
MORE: Properly support extracting MARC21 fixed fields from the leader, not just the 00x controlfields, in the "all fixed fields" version
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-15 16:13:50 UTC (rev 20105)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-15 16:24:17 UTC (rev 20106)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0518'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0519'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/030.schema.metabib.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2011-04-15 16:13:50 UTC (rev 20105)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2011-04-15 16:24:17 UTC (rev 20106)
@@ -554,12 +554,21 @@
output.ff_name := ff_pos.fixed_field;
output.ff_value := NULL;
- FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(tag) || '"]/text()', marc ) ) x(value) LOOP
- output.ff_value := SUBSTRING( tag_data.value, ff_pos.start_pos + 1, ff_pos.length );
- IF output.ff_value IS NULL THEN output.ff_value := REPEAT( ff_pos.default_val, ff_pos.length ); END IF;
- RETURN NEXT output;
- output.ff_value := NULL;
- END LOOP;
+ IF ff_pos.tag = 'ldr' THEN
+ output.ff_value := oils_xpath_string('//*[local-name()="leader"]', marc);
+ IF output.ff_value IS NOT NULL THEN
+ output.ff_value := SUBSTRING( output.ff_value, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN NEXT output;
+ output.ff_value := NULL;
+ END IF;
+ ELSE
+ FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(ff_pos.tag) || '"]/text()', marc ) ) x(value) LOOP
+ output.ff_value := SUBSTRING( tag_data, ff_pos.start_pos + 1, ff_pos.length );
+ IF output.ff_value IS NULL THEN output.ff_value := REPEAT( ff_pos.default_val, ff_pos.length ); END IF;
+ RETURN NEXT output;
+ output.ff_value := NULL;
+ END LOOP;
+ END IF;
END LOOP;
Added: branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0519.schema.extract_all_fixed_fields_from_leader.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0519.schema.extract_all_fixed_fields_from_leader.sql (rev 0)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0519.schema.extract_all_fixed_fields_from_leader.sql 2011-04-15 16:24:17 UTC (rev 20106)
@@ -0,0 +1,41 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0519'); -- miker
+
+CREATE OR REPLACE FUNCTION vandelay.marc21_extract_all_fixed_fields( marc TEXT ) RETURNS SETOF biblio.record_ff_map AS $func$
+DECLARE
+ tag_data TEXT;
+ rtype TEXT;
+ ff_pos RECORD;
+ output biblio.record_ff_map%ROWTYPE;
+BEGIN
+ rtype := (vandelay.marc21_record_type( marc )).code;
+
+ FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE rec_type = rtype ORDER BY tag DESC LOOP
+ output.ff_name := ff_pos.fixed_field;
+ output.ff_value := NULL;
+
+ IF ff_pos.tag = 'ldr' THEN
+ output.ff_value := oils_xpath_string('//*[local-name()="leader"]', marc);
+ IF output.ff_value IS NOT NULL THEN
+ output.ff_value := SUBSTRING( output.ff_value, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN NEXT output;
+ output.ff_value := NULL;
+ END IF;
+ ELSE
+ FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(ff_pos.tag) || '"]/text()', marc ) ) x(value) LOOP
+ output.ff_value := SUBSTRING( tag_data, ff_pos.start_pos + 1, ff_pos.length );
+ IF output.ff_value IS NULL THEN output.ff_value := REPEAT( ff_pos.default_val, ff_pos.length ); END IF;
+ RETURN NEXT output;
+ output.ff_value := NULL;
+ END LOOP;
+ END IF;
+
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list