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 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_pq_lib.h>
23 : #include "merchant-database/update_unit.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 10 : TALER_MERCHANTDB_update_unit (
29 : struct TALER_MERCHANTDB_PostgresContext *pg,
30 : const char *instance_id,
31 : const char *unit_id,
32 : const char *unit_name_long,
33 : const json_t *unit_name_long_i18n,
34 : const char *unit_name_short,
35 : const json_t *unit_name_short_i18n,
36 : const bool *unit_allow_fraction,
37 : const uint32_t *unit_precision_level,
38 : const bool *unit_active,
39 : bool *no_unit,
40 : bool *builtin_conflict)
41 : {
42 10 : struct GNUNET_PQ_QueryParam params[] = {
43 10 : GNUNET_PQ_query_param_string (unit_id),
44 : (NULL == unit_name_long)
45 6 : ? GNUNET_PQ_query_param_null ()
46 10 : : GNUNET_PQ_query_param_string (unit_name_long),
47 : (NULL == unit_name_long_i18n)
48 8 : ? GNUNET_PQ_query_param_null ()
49 10 : : TALER_PQ_query_param_json ((json_t *) unit_name_long_i18n),
50 : (NULL == unit_name_short)
51 6 : ? GNUNET_PQ_query_param_null ()
52 10 : : GNUNET_PQ_query_param_string (unit_name_short),
53 : (NULL == unit_name_short_i18n)
54 8 : ? GNUNET_PQ_query_param_null ()
55 10 : : TALER_PQ_query_param_json ((json_t *) unit_name_short_i18n),
56 : (NULL == unit_allow_fraction)
57 0 : ? GNUNET_PQ_query_param_null ()
58 10 : : GNUNET_PQ_query_param_bool (*unit_allow_fraction),
59 : (NULL == unit_precision_level)
60 0 : ? GNUNET_PQ_query_param_null ()
61 10 : : GNUNET_PQ_query_param_uint32 ((uint32_t *) unit_precision_level),
62 : (NULL == unit_active)
63 0 : ? GNUNET_PQ_query_param_null ()
64 10 : : GNUNET_PQ_query_param_bool (*unit_active),
65 : GNUNET_PQ_query_param_end
66 : };
67 10 : struct GNUNET_PQ_ResultSpec rs[] = {
68 10 : GNUNET_PQ_result_spec_bool ("out_no_unit",
69 : no_unit),
70 10 : GNUNET_PQ_result_spec_bool ("out_builtin_conflict",
71 : builtin_conflict),
72 : GNUNET_PQ_result_spec_end
73 : };
74 : enum GNUNET_DB_QueryStatus qs;
75 :
76 10 : GNUNET_assert (NULL != pg->current_merchant_id);
77 10 : GNUNET_assert (0 == strcmp (instance_id,
78 : pg->current_merchant_id));
79 10 : TMH_PQ_prepare_anon (pg,
80 : "SELECT"
81 : " out_no_unit"
82 : " ,out_builtin_conflict"
83 : " FROM merchant_do_update_unit"
84 : "($1,$2,$3,$4,$5,$6,$7,$8);");
85 10 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
86 : "",
87 : params,
88 : rs);
89 10 : GNUNET_PQ_cleanup_query_params_closures (params);
90 10 : return qs;
91 : }
|