X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=kmig.d%2Fsql%2Finit%2F030-marc_functions.sql;h=cb917f269e2a669b959b815906a0d8163fc94150;hp=35df163e4518204ac61e51fc115504ad7144fbe0;hb=527cb1392086c1b65320dc9eb8d8a580c02b0115;hpb=0c9aaf56bdac190f5134d900817902b45b407c80 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 ;