insert_charity.c (2619B)
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 src/donaudb/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 "insert_charity.h" 28 #include "helper.h" 29 30 31 enum GNUNET_DB_QueryStatus 32 DONAUDB_insert_charity (struct DONAUDB_PostgresContext *ctx, 33 const struct DONAU_CharityPublicKeyP *charity_pub, 34 const char *charity_name, 35 const char *charity_url, 36 const struct TALER_Amount *max_per_year, 37 uint64_t *charity_id) 38 { 39 uint32_t current_year 40 = GNUNET_TIME_get_current_year (); 41 struct GNUNET_PQ_QueryParam params[] = { 42 GNUNET_PQ_query_param_auto_from_type (charity_pub), 43 GNUNET_PQ_query_param_string (charity_name), 44 GNUNET_PQ_query_param_string (charity_url), 45 TALER_PQ_query_param_amount (ctx->conn, 46 max_per_year), 47 GNUNET_PQ_query_param_uint32 (¤t_year), 48 GNUNET_PQ_query_param_end 49 }; 50 struct GNUNET_PQ_ResultSpec rs[] = { 51 GNUNET_PQ_result_spec_uint64 ("charity_id", 52 charity_id), 53 GNUNET_PQ_result_spec_end 54 }; 55 enum GNUNET_DB_QueryStatus qs; 56 57 PREPARE (ctx, 58 "insert_charity", 59 "SELECT out_charity_id AS charity_id" 60 " FROM do_insert_charity" 61 " ($1, $2, $3, $4, $5);"); 62 qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 63 "insert_charity", 64 params, 65 rs); 66 if (qs <= 0) 67 return qs; 68 if (0 == *charity_id) 69 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 70 return qs; 71 }