Line data Source code
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 backenddb/pg_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 "pg_update_unit.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 4 : TMH_PG_update_unit (void *cls,
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 4 : struct PostgresClosure *pg = cls;
45 4 : struct GNUNET_PQ_QueryParam params[] = {
46 4 : GNUNET_PQ_query_param_string (instance_id),
47 4 : GNUNET_PQ_query_param_string (unit_id),
48 : (NULL == unit_name_long)
49 2 : ? GNUNET_PQ_query_param_null ()
50 4 : : GNUNET_PQ_query_param_string (unit_name_long),
51 : (NULL == unit_name_long_i18n)
52 2 : ? GNUNET_PQ_query_param_null ()
53 4 : : TALER_PQ_query_param_json ((json_t *) unit_name_long_i18n),
54 : (NULL == unit_name_short)
55 2 : ? GNUNET_PQ_query_param_null ()
56 4 : : GNUNET_PQ_query_param_string (unit_name_short),
57 : (NULL == unit_name_short_i18n)
58 2 : ? GNUNET_PQ_query_param_null ()
59 4 : : TALER_PQ_query_param_json ((json_t *) unit_name_short_i18n),
60 : (NULL == unit_allow_fraction)
61 0 : ? GNUNET_PQ_query_param_null ()
62 4 : : GNUNET_PQ_query_param_bool (*unit_allow_fraction),
63 : (NULL == unit_precision_level)
64 0 : ? GNUNET_PQ_query_param_null ()
65 4 : : GNUNET_PQ_query_param_uint32 ((uint32_t *) unit_precision_level),
66 : (NULL == unit_active)
67 0 : ? GNUNET_PQ_query_param_null ()
68 4 : : GNUNET_PQ_query_param_bool (*unit_active),
69 : GNUNET_PQ_query_param_end
70 : };
71 4 : struct GNUNET_PQ_ResultSpec rs[] = {
72 4 : GNUNET_PQ_result_spec_bool ("out_no_instance",
73 : no_instance),
74 4 : GNUNET_PQ_result_spec_bool ("out_no_unit",
75 : no_unit),
76 4 : GNUNET_PQ_result_spec_bool ("out_builtin_conflict",
77 : builtin_conflict),
78 : GNUNET_PQ_result_spec_end
79 : };
80 : enum GNUNET_DB_QueryStatus qs;
81 :
82 4 : check_connection (pg);
83 4 : PREPARE (pg,
84 : "update_unit",
85 : "SELECT"
86 : " out_no_instance"
87 : " ,out_no_unit"
88 : " ,out_builtin_conflict"
89 : " FROM merchant_do_update_unit"
90 : "($1,$2,$3,$4,$5,$6,$7,$8,$9);");
91 4 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
92 : "update_unit",
93 : params,
94 : rs);
95 4 : GNUNET_PQ_cleanup_query_params_closures (params);
96 4 : return qs;
97 : }
|