From: Mike Rylander Date: Wed, 4 May 2011 15:52:31 +0000 (-0400) Subject: Give authority flattening the same treatment as biblio flattening X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9af9f804e7e272845b0dce09d98c1f88f0097670;p=evergreen%2Fequinox.git Give authority flattening the same treatment as biblio flattening --- diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 22bc674baf..9f00d0c59a 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -409,6 +409,27 @@ CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( BIGINT ) RETURNS SELECT * FROM biblio.extract_metabib_field_entry($1, ' '); $func$ LANGUAGE SQL; +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 vandelay.flatten_marc( auth.marc ) LOOP + output.record := rid; + output.ind1 := field.ind1; + output.ind2 := field.ind2; + output.tag := field.tag; + output.subfield := field.subfield; + output.value := field.value; + + RETURN NEXT output; + END LOOP; +END; +$func$ LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION biblio.flatten_marc ( rid BIGINT ) RETURNS SETOF metabib.full_rec AS $func$ DECLARE bib biblio.record_entry%ROWTYPE; diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 66532cb1e1..0152417784 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1378,67 +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'); -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] - }); - - } - } -} - -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; - -- authority.rec_descriptor appears to be unused currently CREATE OR REPLACE FUNCTION authority.reingest_authority_rec_descriptor( auth_id BIGINT ) RETURNS VOID AS $func$ BEGIN