donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

update_charity.sql (1754B)


      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 DROP FUNCTION IF EXISTS do_update_charity;
     18 CREATE FUNCTION do_update_charity (
     19    IN in_charity_id INT8
     20   ,IN in_charity_pub BYTEA
     21   ,IN in_charity_name TEXT
     22   ,IN in_charity_url TEXT
     23   ,IN in_max_per_year taler_amount
     24   ,OUT out_found BOOLEAN
     25   ,OUT out_conflict BOOLEAN
     26 )
     27 LANGUAGE plpgsql
     28 AS $$
     29 BEGIN
     30   out_conflict = FALSE;
     31   UPDATE charities
     32      SET charity_pub=in_charity_pub
     33         ,charity_name=in_charity_name
     34         ,charity_url=in_charity_url
     35         ,max_per_year=in_max_per_year
     36    WHERE charity_id=in_charity_id;
     37   out_found = FOUND;
     38 EXCEPTION
     39   WHEN unique_violation THEN
     40     -- charity_pub is the primary key of `charities' and is entirely
     41     -- client-supplied; a collision means "this key belongs to a different
     42     -- charity", NOT "no such charity_id".
     43     out_found = TRUE;
     44     out_conflict = TRUE;
     45 END $$;
     46 
     47 COMMENT ON FUNCTION do_update_charity
     48   IS 'Updates a charity. out_found is FALSE if no charity with the given charity_id exists; out_conflict is TRUE if the requested charity_pub is already used by another charity.';