1 -- Format the output for nice TAP.
6 -- Revert all changes on failure.
7 \set ON_ERROR_ROLLBACK 1
8 \set ON_ERROR_STOP true
11 -- Load the TAP functions.
17 -- Replace the function
18 CREATE OR REPLACE FUNCTION unapi.mmr_mra (
24 depth INT DEFAULT NULL,
25 slimit HSTORE DEFAULT NULL,
26 soffset HSTORE DEFAULT NULL,
27 include_xmlns BOOL DEFAULT TRUE,
28 pref_lib INT DEFAULT NULL
33 CASE WHEN $9 THEN 'http://open-ils.org/spec/indexing/v1' ELSE NULL END AS xmlns,
34 'tag:open-ils.org:U2@mmr/' || $1 AS metarecord
39 WITH aou AS (SELECT COALESCE(id, (evergreen.org_top()).id) AS id
40 FROM actor.org_unit WHERE shortname = $5 LIMIT 1)
42 FROM metabib.metarecord_source_map, aou
43 WHERE metarecord = $1 AND (
45 SELECT 1 FROM asset.opac_visible_copies
46 WHERE record = source AND circ_lib IN (
47 SELECT id FROM actor.org_unit_descendants(aou.id, $6))
50 OR EXISTS (SELECT 1 FROM located_uris(source, aou.id, $10) LIMIT 1)
58 cmra.value AS "coded-value",
69 SELECT DISTINCT aid, attr, value, STRING_AGG(x.id::TEXT, ',') AS source_list
71 SELECT v.source AS id,
75 FROM metabib.record_attr_vector_list v
76 JOIN config.coded_value_map c ON ( c.id = ANY( v.vlist ) )
78 JOIN sourcelist ON (x.id = sourcelist.source)
81 JOIN config.record_attr_definition rad ON (cmra.attr = rad.name)
96 SELECT DISTINCT aid, attr, value
98 SELECT v.source AS id,
102 FROM metabib.record_attr_vector_list v
103 JOIN metabib.uncontrolled_record_attr_value m ON ( m.id = ANY( v.vlist ) )
105 JOIN sourcelist ON (x.id = sourcelist.source)
107 JOIN config.record_attr_definition rad ON (umra.attr = rad.name)
113 $F$ LANGUAGE SQL STABLE;
115 -- Now make sure that the a query against it doesn't break
116 PREPARE thrower AS select mmr_mra::varchar from unapi.mmr_mra
117 (15,'','',null::text[],'CONS',0,null::HSTORE,null::HSTORE,true,1);
119 SELECT performs_ok( 'thrower',250,'Generic check for unapi.mmr_mra breakage' );
121 -- Make sure that the function returns the new XML property source_list
124 select mmr_mra::varchar ~ 'source_list="15,16,17"' from unapi.mmr_mra
125 (15,'','',null::text[],'CONS',0,null::HSTORE,null::HSTORE,true,1)
126 ), true, 'unapi.mmr_mra results have source_list="15,16,17sfaf"' );
129 -- Finish the tests and clean up.
130 SELECT * FROM finish();