check_report.sql (2013B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2026 Taler Systems SA 4 -- 5 -- TALER is free software; you can redistribute it and/or modify it under the 6 -- terms of the GNU General Public License as published by the Free Software 7 -- Foundation; either version 3, or (at your option) any later version. 8 -- 9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License along with 14 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 -- 16 17 18 DROP FUNCTION IF EXISTS merchant.check_report; 19 CREATE FUNCTION merchant.check_report( 20 IN in_report_id INT8, 21 IN in_report_token BYTEA, 22 IN in_mime_type TEXT) 23 RETURNS TABLE( 24 out_merchant_id TEXT, 25 out_data_source TEXT) 26 LANGUAGE plpgsql 27 AS $$ 28 DECLARE 29 rec RECORD; 30 s TEXT; 31 inner_rec RECORD; 32 BEGIN 33 FOR rec IN 34 SELECT merchant_serial 35 ,merchant_id 36 FROM merchant.merchant_instances 37 LOOP 38 s := 'merchant_instance_' || rec.merchant_serial::TEXT; 39 BEGIN 40 EXECUTE format( 41 'SELECT data_source AS ds' 42 ' FROM %I.merchant_reports' 43 ' WHERE report_serial=$1' 44 ' AND report_token=$2' 45 ' AND mime_type=$3', s) 46 USING in_report_id 47 ,in_report_token 48 ,in_mime_type 49 INTO inner_rec; 50 IF inner_rec IS NOT NULL 51 THEN 52 out_merchant_id := rec.merchant_id; 53 out_data_source := inner_rec.ds; 54 RETURN NEXT; 55 RETURN; 56 END IF; 57 EXCEPTION 58 WHEN undefined_table 59 THEN 60 NULL; 61 END; 62 END LOOP; 63 END 64 $$; 65 COMMENT ON FUNCTION merchant.check_report(INT8, BYTEA, TEXT) 66 IS 'Searches all instance schemas for a report matching the given' 67 ' (report_serial, report_token, mime_type). Returns at most one row' 68 ' (the first matching instance encountered).';