From: Jason Etheridge Date: Mon, 15 Jun 2020 15:53:00 +0000 (-0400) Subject: m_insert_tag for kmig X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=527cb1392086c1b65320dc9eb8d8a580c02b0115 m_insert_tag for kmig Signed-off-by: Jason Etheridge --- diff --git a/kmig.d/sql/init/030-marc_functions.sql b/kmig.d/sql/init/030-marc_functions.sql index 35df163..cb917f2 100644 --- a/kmig.d/sql/init/030-marc_functions.sql +++ b/kmig.d/sql/init/030-marc_functions.sql @@ -75,3 +75,41 @@ CREATE FUNCTION END $ DELIMITER ; + +-- Pass it the biblionumber, tag number, subfield, value and it'll add a MARC field to the end of the record accordingly +-- Be sure to escape the value if needed +-- Example: SELECT m_insert_tag(1,'909','a','foo'); +DROP FUNCTION IF EXISTS m_insert_tag; +DELIMITER $ +CREATE FUNCTION + m_insert_tag(bnumber INTEGER, tag TEXT COLLATE utf8mb4_unicode_ci, subfield TEXT COLLATE utf8mb4_unicode_ci, value TEXT COLLATE utf8mb4_unicode_ci) + RETURNS BOOLEAN + DETERMINISTIC + BEGIN + DECLARE marcxml TEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL; + + SELECT metadata INTO marcxml FROM biblio_metadata WHERE biblionumber = bnumber; + + IF NULLIF(marcxml,'') IS NULL THEN -- whaaa? + RETURN FALSE; + END IF; + + SET marcxml = replace(marcxml,'', + CONCAT( + ' \n ' + ,value + ,'\n \n' + ,'' + ) + ); + + UPDATE biblio_metadata SET metadata = marcxml where biblionumber = bnumber; + RETURN TRUE; + + END +$ +DELIMITER ;