From 8569fc04d0fe959a90bdf1dbe967011bfe915edd Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 11 Jul 2011 09:52:26 -0400 Subject: [PATCH] Merge/rebase cleanup -- remove useless/incorrect versions of the MARC flattener for different record types Signed-off-by: Mike Rylander --- Open-ILS/src/sql/Pg/030.schema.metabib.sql | 71 -------------------- Open-ILS/src/sql/Pg/999.functions.global.sql | 58 ---------------- 2 files changed, 129 deletions(-) diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index b70fae4768..f8c3d1618f 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -451,77 +451,6 @@ BEGIN END; $func$ LANGUAGE PLPGSQL; -/* Old form of biblio.flatten_marc() relied on contrib/xml2 functions that got all crashy in PostgreSQL 8.4 */ --- CREATE OR REPLACE FUNCTION biblio.flatten_marc ( TEXT, BIGINT ) RETURNS SETOF metabib.full_rec AS $func$ --- SELECT NULL::bigint AS id, NULL::bigint, 'LDR'::char(3), NULL::TEXT, NULL::TEXT, NULL::TEXT, oils_xpath_string( '//*[local-name()="leader"]', $1 ), NULL::tsvector AS index_vector --- UNION --- SELECT NULL::bigint AS id, NULL::bigint, x.tag::char(3), NULL::TEXT, NULL::TEXT, NULL::TEXT, x.value, NULL::tsvector AS index_vector --- FROM oils_xpath_table( --- 'id', --- 'marc', --- 'biblio.record_entry', --- '//*[local-name()="controlfield"]/@tag|//*[local-name()="controlfield"]', --- 'id=' || $2::TEXT --- )x(record int, tag text, value text) --- UNION --- SELECT NULL::bigint AS id, NULL::bigint, x.tag::char(3), x.ind1, x.ind2, x.subfield, x.value, NULL::tsvector AS index_vector --- FROM oils_xpath_table( --- 'id', --- 'marc', --- 'biblio.record_entry', --- '//*[local-name()="datafield"]/@tag|' || --- '//*[local-name()="datafield"]/@ind1|' || --- '//*[local-name()="datafield"]/@ind2|' || --- '//*[local-name()="datafield"]/*/@code|' || --- '//*[local-name()="datafield"]/*[@code]', --- 'id=' || $2::TEXT --- )x(record int, tag text, ind1 text, ind2 text, subfield text, value text); --- $func$ LANGUAGE SQL; - -CREATE OR REPLACE FUNCTION biblio.flatten_marc ( TEXT ) RETURNS SETOF metabib.full_rec AS $func$ - -use MARC::Record; -use MARC::File::XML (BinaryEncoding => 'UTF-8'); -use MARC::Charset; - -MARC::Charset->assume_unicode(1); - -my $xml = shift; -my $r = MARC::Record->new_from_xml( $xml ); - -return_next( { tag => 'LDR', value => $r->leader } ); - -for my $f ( $r->fields ) { - if ($f->is_control_field) { - return_next({ tag => $f->tag, value => $f->data }); - } else { - for my $s ($f->subfields) { - return_next({ - tag => $f->tag, - ind1 => $f->indicator(1), - ind2 => $f->indicator(2), - subfield => $s->[0], - value => $s->[1] - }); - - if ( $f->tag eq '245' and $s->[0] eq 'a' ) { - my $trim = $f->indicator(2) || 0; - return_next({ - tag => 'tnf', - ind1 => $f->indicator(1), - ind2 => $f->indicator(2), - subfield => 'a', - value => substr( $s->[1], $trim ) - }); - } - } - } -} - -return undef; - -$func$ LANGUAGE PLPERLU; - CREATE OR REPLACE FUNCTION vandelay.marc21_record_type( marc TEXT ) RETURNS config.marc21_rec_type_map AS $func$ DECLARE ldr TEXT; diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 0561596a3e..f0d95e5c82 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1378,64 +1378,6 @@ CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT) RETURNS SETO SELECT authority.propagate_changes( authority, bib ) FROM authority.bib_linking WHERE authority = $1; $func$ LANGUAGE SQL; -CREATE OR REPLACE FUNCTION authority.flatten_marc ( TEXT ) RETURNS SETOF authority.full_rec AS $func$ - -use MARC::Record; -use MARC::File::XML (BinaryEncoding => 'UTF-8'); - -my $xml = shift; -my $r = MARC::Record->new_from_xml( $xml ); - -return_next( { tag => 'LDR', value => $r->leader } ); - -for my $f ( $r->fields ) { - if ($f->is_control_field) { - return_next({ tag => $f->tag, value => $f->data }); - } else { - for my $s ($f->subfields) { - return_next({ - tag => $f->tag, - ind1 => $f->indicator(1), - ind2 => $f->indicator(2), - subfield => $s->[0], - value => $s->[1] - }); - - } - } -} - -return undef; - -$func$ LANGUAGE PLPERLU; - -CREATE OR REPLACE FUNCTION authority.flatten_marc ( rid BIGINT ) RETURNS SETOF authority.full_rec AS $func$ -DECLARE - auth authority.record_entry%ROWTYPE; - output authority.full_rec%ROWTYPE; - field RECORD; -BEGIN - SELECT INTO auth * FROM authority.record_entry WHERE id = rid; - - FOR field IN SELECT * FROM authority.flatten_marc( auth.marc ) LOOP - output.record := rid; - output.ind1 := field.ind1; - output.ind2 := field.ind2; - output.tag := field.tag; - output.subfield := field.subfield; - IF field.subfield IS NOT NULL THEN - output.value := naco_normalize(field.value, field.subfield); - ELSE - output.value := field.value; - END IF; - - CONTINUE WHEN output.value IS NULL; - - RETURN NEXT output; - END LOOP; -END; -$func$ LANGUAGE PLPGSQL; - CREATE OR REPLACE FUNCTION authority.map_thesaurus_to_control_set () RETURNS TRIGGER AS $func$ BEGIN IF NEW.control_set IS NULL THEN -- 2.43.2