update_unit.c (3849B)
1 /* 2 This file is part of TALER 3 Copyright (C) 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/backenddb/update_unit.c 18 * @brief Implementation of the update_unit function for Postgres 19 * @author Bohdan Potuzhnyi 20 */ 21 #include "platform.h" 22 #include <taler/taler_error_codes.h> 23 #include <taler/taler_dbevents.h> 24 #include <taler/taler_pq_lib.h> 25 #include "merchant-database/update_unit.h" 26 #include "helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 TALER_MERCHANTDB_update_unit (struct TALER_MERCHANTDB_PostgresContext *pg, 31 const char *instance_id, 32 const char *unit_id, 33 const char *unit_name_long, 34 const json_t *unit_name_long_i18n, 35 const char *unit_name_short, 36 const json_t *unit_name_short_i18n, 37 const bool *unit_allow_fraction, 38 const uint32_t *unit_precision_level, 39 const bool *unit_active, 40 bool *no_instance, 41 bool *no_unit, 42 bool *builtin_conflict) 43 { 44 struct GNUNET_PQ_QueryParam params[] = { 45 GNUNET_PQ_query_param_string (instance_id), 46 GNUNET_PQ_query_param_string (unit_id), 47 (NULL == unit_name_long) 48 ? GNUNET_PQ_query_param_null () 49 : GNUNET_PQ_query_param_string (unit_name_long), 50 (NULL == unit_name_long_i18n) 51 ? GNUNET_PQ_query_param_null () 52 : TALER_PQ_query_param_json ((json_t *) unit_name_long_i18n), 53 (NULL == unit_name_short) 54 ? GNUNET_PQ_query_param_null () 55 : GNUNET_PQ_query_param_string (unit_name_short), 56 (NULL == unit_name_short_i18n) 57 ? GNUNET_PQ_query_param_null () 58 : TALER_PQ_query_param_json ((json_t *) unit_name_short_i18n), 59 (NULL == unit_allow_fraction) 60 ? GNUNET_PQ_query_param_null () 61 : GNUNET_PQ_query_param_bool (*unit_allow_fraction), 62 (NULL == unit_precision_level) 63 ? GNUNET_PQ_query_param_null () 64 : GNUNET_PQ_query_param_uint32 ((uint32_t *) unit_precision_level), 65 (NULL == unit_active) 66 ? GNUNET_PQ_query_param_null () 67 : GNUNET_PQ_query_param_bool (*unit_active), 68 GNUNET_PQ_query_param_end 69 }; 70 struct GNUNET_PQ_ResultSpec rs[] = { 71 GNUNET_PQ_result_spec_bool ("out_no_instance", 72 no_instance), 73 GNUNET_PQ_result_spec_bool ("out_no_unit", 74 no_unit), 75 GNUNET_PQ_result_spec_bool ("out_builtin_conflict", 76 builtin_conflict), 77 GNUNET_PQ_result_spec_end 78 }; 79 enum GNUNET_DB_QueryStatus qs; 80 81 check_connection (pg); 82 PREPARE (pg, 83 "update_unit", 84 "SELECT" 85 " out_no_instance" 86 " ,out_no_unit" 87 " ,out_builtin_conflict" 88 " FROM merchant_do_update_unit" 89 "($1,$2,$3,$4,$5,$6,$7,$8,$9);"); 90 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 91 "update_unit", 92 params, 93 rs); 94 GNUNET_PQ_cleanup_query_params_closures (params); 95 return qs; 96 }