pg_insert_donau_instance.c (2694B)
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 * @file backenddb/pg_insert_donau_instance.c 18 * @brief Implementation of the insert_donau_instance function for Postgres 19 * @author Bohdan Potuzhnyi 20 * @author Vlada Svirsh 21 */ 22 #include "platform.h" 23 #include <taler/taler_error_codes.h> 24 #include <taler/taler_dbevents.h> 25 #include <taler/taler_pq_lib.h> 26 #include "donau/donau_service.h" 27 #include "pg_insert_donau_instance.h" 28 #include "pg_helper.h" 29 30 31 enum GNUNET_DB_QueryStatus 32 TMH_PG_insert_donau_instance ( 33 void *cls, 34 const char *donau_url, 35 const struct DONAU_Charity *charity, 36 uint64_t charity_id) 37 { 38 struct PostgresClosure *pg = cls; 39 struct GNUNET_PQ_QueryParam params[] = { 40 GNUNET_PQ_query_param_string (donau_url), 41 GNUNET_PQ_query_param_string (charity->name), 42 GNUNET_PQ_query_param_auto_from_type (&charity->charity_pub), 43 GNUNET_PQ_query_param_uint64 (&charity_id), 44 TALER_PQ_query_param_amount_with_currency (pg->conn, 45 &charity->max_per_year), 46 TALER_PQ_query_param_amount_with_currency (pg->conn, 47 &charity->receipts_to_date), 48 GNUNET_PQ_query_param_uint64 (&charity->current_year), 49 GNUNET_PQ_query_param_end 50 }; 51 52 check_connection (pg); 53 PREPARE (pg, 54 "insert_donau_instance", 55 "INSERT INTO merchant_donau_instances" 56 " (donau_url" 57 " ,charity_name" 58 " ,merchant_instance_serial" 59 " ,charity_id" 60 " ,charity_max_per_year" 61 " ,charity_receipts_to_date" 62 " ,current_year)" 63 "VALUES" 64 " ($1, $2," 65 " (SELECT merchant_serial" 66 " FROM merchant_instances mi" 67 " WHERE mi.merchant_pub = $3)," 68 " $4, $5, $6, $7)" 69 " ON CONFLICT DO NOTHING;"); 70 return GNUNET_PQ_eval_prepared_non_select (pg->conn, 71 "insert_donau_instance", 72 params); 73 }