pg_persist_policy_details.c (3231B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 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 exchangedb/pg_persist_policy_details.c 18 * @brief Implementation of the persist_policy_details function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "taler/exchange-database/persist_policy_details.h" 23 #include "helper.h" 24 25 26 enum GNUNET_DB_QueryStatus 27 TALER_EXCHANGEDB_persist_policy_details ( 28 struct TALER_EXCHANGEDB_PostgresContext *pg, 29 const struct TALER_PolicyDetails *details, 30 uint64_t *policy_details_serial_id, 31 struct TALER_Amount *accumulated_total, 32 enum TALER_PolicyFulfillmentState *fulfillment_state) 33 { 34 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_auto_from_type (&details->hash_code), 36 TALER_PQ_query_param_json (details->policy_json), 37 GNUNET_PQ_query_param_timestamp (&details->deadline), 38 TALER_PQ_query_param_amount (pg->conn, 39 &details->commitment), 40 TALER_PQ_query_param_amount (pg->conn, 41 &details->accumulated_total), 42 TALER_PQ_query_param_amount (pg->conn, 43 &details->policy_fee), 44 TALER_PQ_query_param_amount (pg->conn, 45 &details->transferable_amount), 46 GNUNET_PQ_query_param_auto_from_type (&details->fulfillment_state), 47 (details->no_policy_fulfillment_id) 48 ? GNUNET_PQ_query_param_null () 49 : GNUNET_PQ_query_param_uint64 (&details->policy_fulfillment_id), 50 GNUNET_PQ_query_param_end 51 }; 52 struct GNUNET_PQ_ResultSpec rs[] = { 53 GNUNET_PQ_result_spec_uint64 ("policy_details_serial_id", 54 policy_details_serial_id), 55 TALER_PQ_RESULT_SPEC_AMOUNT ("accumulated_total", 56 accumulated_total), 57 GNUNET_PQ_result_spec_uint32 ("fulfillment_state", 58 fulfillment_state), 59 GNUNET_PQ_result_spec_end 60 }; 61 62 PREPARE (pg, 63 "call_insert_or_update_policy_details", 64 "SELECT" 65 " out_policy_details_serial_id AS policy_details_serial_id" 66 ",out_accumulated_total AS accumulated_total" 67 ",out_fulfillment_state AS fulfillment_state" 68 " FROM exchange_do_insert_or_update_policy_details" 69 "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); 70 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 71 "call_insert_or_update_policy_details", 72 params, 73 rs); 74 }