Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2025, 2026 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/insert_unit.c
18 : * @brief Implementation of the insert_unit function for Postgres
19 : * @author Bohdan Potuzhnyi
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_pq_lib.h>
23 : #include "merchant-database/insert_unit.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 8 : TALER_MERCHANTDB_insert_unit (
29 : struct TALER_MERCHANTDB_PostgresContext *pg,
30 : const char *instance_id,
31 : const struct TALER_MERCHANTDB_UnitDetails *ud,
32 : bool *conflict,
33 : uint64_t *unit_serial)
34 : {
35 8 : struct GNUNET_PQ_QueryParam params[] = {
36 8 : GNUNET_PQ_query_param_string (ud->unit),
37 8 : GNUNET_PQ_query_param_string (ud->unit_name_long),
38 8 : GNUNET_PQ_query_param_string (ud->unit_name_short),
39 8 : TALER_PQ_query_param_json (ud->unit_name_long_i18n),
40 8 : TALER_PQ_query_param_json (ud->unit_name_short_i18n),
41 8 : GNUNET_PQ_query_param_bool (ud->unit_allow_fraction),
42 8 : GNUNET_PQ_query_param_uint32 (&ud->unit_precision_level),
43 8 : GNUNET_PQ_query_param_bool (ud->unit_active),
44 : GNUNET_PQ_query_param_end
45 : };
46 8 : bool unit_serial_present = true;
47 8 : struct GNUNET_PQ_ResultSpec rs[] = {
48 8 : GNUNET_PQ_result_spec_bool ("conflict",
49 : conflict),
50 8 : GNUNET_PQ_result_spec_allow_null (
51 : GNUNET_PQ_result_spec_uint64 ("unit_serial",
52 : unit_serial),
53 : &unit_serial_present),
54 : GNUNET_PQ_result_spec_end
55 : };
56 : enum GNUNET_DB_QueryStatus qs;
57 :
58 8 : *conflict = false;
59 8 : GNUNET_assert (NULL != pg->current_merchant_id);
60 8 : GNUNET_assert (0 == strcmp (instance_id,
61 : pg->current_merchant_id));
62 8 : TMH_PQ_prepare_anon (pg,
63 : "SELECT"
64 : " out_conflict AS conflict"
65 : " ,out_unit_serial AS unit_serial"
66 : " FROM merchant_do_insert_unit"
67 : " ($1,$2,$3,$4,$5,$6,$7,$8);");
68 8 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
69 : "",
70 : params,
71 : rs);
72 8 : GNUNET_PQ_cleanup_query_params_closures (params);
73 8 : if (! unit_serial_present)
74 6 : *unit_serial = 0;
75 8 : return qs;
76 : }
|