donau

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

pg_insert_charity.c (2522B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2023--2025 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  * @file donaudb/pg_insert_charity.c
     18  * @brief Implementation of the insert_charity function for Postgres
     19  * @author Johannes Casaburi
     20  * @author Lukas Matyja
     21  * @author Christian Grothoff
     22  */
     23 #include <donau_config.h>
     24 #include <taler/taler_error_codes.h>
     25 #include <taler/taler_dbevents.h>
     26 #include <taler/taler_pq_lib.h>
     27 #include "pg_insert_charity.h"
     28 #include "pg_helper.h"
     29 
     30 
     31 enum GNUNET_DB_QueryStatus
     32 DH_PG_insert_charity (
     33   void *cls,
     34   const struct DONAU_CharityPublicKeyP *charity_pub,
     35   const char *charity_name,
     36   const char *charity_url,
     37   const struct TALER_Amount *max_per_year,
     38   uint64_t *charity_id)
     39 {
     40   struct PostgresClosure *pg = cls;
     41   uint32_t current_year
     42     = GNUNET_TIME_get_current_year ();
     43   struct GNUNET_PQ_QueryParam params[] = {
     44     GNUNET_PQ_query_param_auto_from_type (charity_pub),
     45     GNUNET_PQ_query_param_string (charity_name),
     46     GNUNET_PQ_query_param_string (charity_url),
     47     TALER_PQ_query_param_amount (pg->conn,
     48                                  max_per_year),
     49     GNUNET_PQ_query_param_uint32 (&current_year),
     50     GNUNET_PQ_query_param_end
     51   };
     52   struct GNUNET_PQ_ResultSpec rs[] = {
     53     GNUNET_PQ_result_spec_uint64 ("charity_id",
     54                                   charity_id),
     55     GNUNET_PQ_result_spec_end
     56   };
     57   enum GNUNET_DB_QueryStatus qs;
     58 
     59   PREPARE (pg,
     60            "insert_charity",
     61            "SELECT out_charity_id AS charity_id"
     62            " FROM do_insert_charity"
     63            " ($1, $2, $3, $4, $5);");
     64   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     65                                                  "insert_charity",
     66                                                  params,
     67                                                  rs);
     68   if (qs <= 0)
     69     return qs;
     70   if (0 == *charity_id)
     71     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     72   return qs;
     73 }