[open-ils-commits] r15849 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 15 12:47:17 EDT 2010
Author: miker
Date: 2010-03-15 12:47:14 -0400 (Mon, 15 Mar 2010)
New Revision: 15849
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0196.schema.vandelay.bib-tcn-extraction-function.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
Log:
function to pull possible tcn values out of a bib xml record
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-03-15 15:57:57 UTC (rev 15848)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-03-15 16:47:14 UTC (rev 15849)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0195'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0196'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-03-15 15:57:57 UTC (rev 15848)
+++ trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-03-15 16:47:14 UTC (rev 15849)
@@ -141,6 +141,168 @@
CONSTRAINT add_replace_strip_or_preserve CHECK ((preserve_spec IS NOT NULL OR replace_spec IS NOT NULL) OR (preserve_spec IS NULL AND replace_spec IS NULL))
);
+
+CREATE TYPE vandelay.tcn_data AS (tcn TEXT, tcn_source TEXT, used BOOL);
+CREATE OR REPLACE FUNCTION vandelay.find_bib_tcn_data ( xml TEXT ) RETURNS SETOF vandelay.tcn_data AS $_$
+DECLARE
+ eg_tcn TEXT;
+ eg_tcn_source TEXT;
+ output vandelay.tcn_data%ROWTYPE;
+BEGIN
+
+ -- 001/003
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="001"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="003"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 901 ab
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="a"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="b"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 039 ab
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="a"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="b"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 020 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="020"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'ISBN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 022 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="022"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'ISSN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 010 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="010"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'LCCN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 035 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="035"]/*[@code="a"]/text()',xml))[1], $re$^.*?(\w+)$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'System Legacy';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ RETURN;
+END;
+$_$ LANGUAGE PLPGSQL;
+
CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
use MARC::Record;
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0196.schema.vandelay.bib-tcn-extraction-function.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0196.schema.vandelay.bib-tcn-extraction-function.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0196.schema.vandelay.bib-tcn-extraction-function.sql 2010-03-15 16:47:14 UTC (rev 15849)
@@ -0,0 +1,168 @@
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0196'); -- miker
+
+CREATE TYPE vandelay.tcn_data AS (tcn TEXT, tcn_source TEXT, used BOOL);
+CREATE OR REPLACE FUNCTION vandelay.find_bib_tcn_data ( xml TEXT ) RETURNS SETOF vandelay.tcn_data AS $_$
+DECLARE
+ eg_tcn TEXT;
+ eg_tcn_source TEXT;
+ output vandelay.tcn_data%ROWTYPE;
+BEGIN
+
+ -- 001/003
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="001"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="003"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 901 ab
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="a"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="b"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 039 ab
+ eg_tcn := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="a"]/text()',xml))[1]);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="b"]/text()',xml))[1]);
+ IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
+ eg_tcn_source := 'System Local';
+ END IF;
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 020 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="020"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'ISBN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 022 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="022"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'ISSN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 010 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="010"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'LCCN';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ -- 035 a
+ eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="035"]/*[@code="a"]/text()',xml))[1], $re$^.*?(\w+)$$re$, $re$\1$re$);
+ IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
+
+ eg_tcn_source := 'System Legacy';
+
+ PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
+
+ IF NOT FOUND THEN
+ output.used := FALSE;
+ ELSE
+ output.used := TRUE;
+ END IF;
+
+ output.tcn := eg_tcn;
+ output.tcn_source := eg_tcn_source;
+ RETURN NEXT output;
+
+ END IF;
+
+ RETURN;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list