donau_do_insert_submitted_receipts.sql (1964B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2024 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 DROP FUNCTION IF EXISTS do_insert_submitted_receipts; 18 CREATE FUNCTION do_insert_submitted_receipts( 19 IN in_h_tax_number BYTEA, 20 IN ina_h_donation_unit_pubs BYTEA[], 21 IN ina_nonces BYTEA[], 22 IN ina_donation_unit_sigs BYTEA[], 23 IN in_donation_year INT8, 24 -- 25 OUT out_conflict BOOL[] 26 ) 27 LANGUAGE plpgsql 28 AS $$ 29 DECLARE 30 i INT4; 31 ini_nonce BYTEA; 32 ini_h_donation_unit_pub BYTEA; 33 ini_donation_unit_sig BYTEA; 34 BEGIN 35 36 -- Insert each donation receipt 37 38 FOR i IN 1..array_length(ina_h_donation_unit_pubs,1) 39 LOOP 40 ini_nonce = ina_nonces[i]; 41 ini_h_donation_unit_pub = ina_h_donation_unit_pubs[i]; 42 ini_donation_unit_sig = ina_donation_unit_sigs[i]; 43 44 out_conflict[i] = FALSE; 45 46 INSERT INTO receipts_submitted 47 (h_tax_number 48 ,nonce 49 ,h_donation_unit_pub 50 ,donation_unit_sig 51 ,donation_year 52 ) 53 VALUES 54 (in_h_tax_number 55 ,ini_nonce 56 ,ini_h_donation_unit_pub 57 ,ini_donation_unit_sig 58 ,in_donation_year 59 ) 60 ON CONFLICT DO NOTHING; 61 IF NOT FOUND 62 THEN 63 PERFORM FROM receipts_submitted 64 WHERE h_tax_number=in_h_tax_number 65 AND donation_unit_sig=ini_donation_unit_sig; -- if signature matches, everything must match 66 out_conflict[i] = NOT FOUND; 67 END IF; 68 END LOOP; -- end FOR all receipts 69 70 END $$;