[open-ils-commits] r20105 - 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:13:53 EDT 2011
Author: miker
Date: 2011-04-15 12:13:50 -0400 (Fri, 15 Apr 2011)
New Revision: 20105
Added:
branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0518.schema.extract_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:
Properly support extracting MARC21 fixed fields from the leader, not just the 00x controlfields
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:32 UTC (rev 20104)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-15 16:13:50 UTC (rev 20105)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0517'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0518'); -- 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:32 UTC (rev 20104)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2011-04-15 16:13:50 UTC (rev 20105)
@@ -516,10 +516,18 @@
BEGIN
rtype := (vandelay.marc21_record_type( marc )).code;
FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE fixed_field = ff AND rec_type = rtype ORDER BY tag DESC LOOP
- FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(ff_pos.tag) || '"]/text()', marc ) ) x(value) LOOP
- val := SUBSTRING( tag_data.value, ff_pos.start_pos + 1, ff_pos.length );
- RETURN val;
- END LOOP;
+ IF ff_pos.tag = 'ldr' THEN
+ val := oils_xpath_string('//*[local-name()="leader"]', marc);
+ IF val IS NOT NULL THEN
+ val := SUBSTRING( val, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN val;
+ END IF;
+ ELSE
+ FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(ff_pos.tag) || '"]/text()', marc ) ) x(value) LOOP
+ val := SUBSTRING( tag_data.value, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN val;
+ END LOOP;
+ END IF;
val := REPEAT( ff_pos.default_val, ff_pos.length );
RETURN val;
END LOOP;
Copied: branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0518.schema.extract_fixed_fields_from_leader.sql (from rev 20104, trunk/Open-ILS/src/sql/Pg/upgrade/0518.schema.extract_fixed_fields_from_leader.sql)
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0518.schema.extract_fixed_fields_from_leader.sql (rev 0)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0518.schema.extract_fixed_fields_from_leader.sql 2011-04-15 16:13:50 UTC (rev 20105)
@@ -0,0 +1,34 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0518'); -- miker
+CREATE OR REPLACE FUNCTION vandelay.marc21_extract_fixed_field( marc TEXT, ff TEXT ) RETURNS TEXT AS $func$
+DECLARE
+ rtype TEXT;
+ ff_pos RECORD;
+ tag_data RECORD;
+ val TEXT;
+BEGIN
+ rtype := (vandelay.marc21_record_type( marc )).code;
+ FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE fixed_field = ff AND rec_type = rtype ORDER BY tag DESC LOOP
+ IF ff_pos.tag = 'ldr' THEN
+ val := oils_xpath_string('//*[local-name()="leader"]', marc);
+ IF val IS NOT NULL THEN
+ val := SUBSTRING( val, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN val;
+ END IF;
+ ELSE
+ FOR tag_data IN SELECT value FROM UNNEST( oils_xpath( '//*[@tag="' || UPPER(ff_pos.tag) || '"]/text()', marc ) ) x(value) LOOP
+ val := SUBSTRING( tag_data.value, ff_pos.start_pos + 1, ff_pos.length );
+ RETURN val;
+ END LOOP;
+ END IF;
+ val := REPEAT( ff_pos.default_val, ff_pos.length );
+ RETURN val;
+ END LOOP;
+
+ RETURN NULL;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list