Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2024 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 pg_insert_balance.c
18 : * @brief Implementation of the insert_balance function
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/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_insert_balance.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 16 : TAH_PG_insert_balance (void *cls,
31 : const char *balance_key,
32 : const struct TALER_Amount *balance_value,
33 : ...)
34 : {
35 16 : struct PostgresClosure *pg = cls;
36 16 : unsigned int cnt = 1;
37 : va_list ap;
38 :
39 16 : va_start (ap,
40 : balance_value);
41 142 : while (NULL != va_arg (ap,
42 : const char *))
43 : {
44 126 : cnt++;
45 126 : (void) va_arg (ap,
46 : const struct TALER_Amount *);
47 : }
48 16 : va_end (ap);
49 16 : {
50 16 : const char *keys[cnt];
51 16 : struct TALER_Amount amounts[cnt];
52 16 : unsigned int off = 1;
53 16 : struct GNUNET_PQ_QueryParam params[] = {
54 16 : GNUNET_PQ_query_param_array_ptrs_string (cnt,
55 : keys,
56 : pg->conn),
57 16 : TALER_PQ_query_param_array_amount (cnt,
58 : amounts,
59 : pg->conn),
60 : GNUNET_PQ_query_param_end
61 : };
62 : enum GNUNET_DB_QueryStatus qs;
63 :
64 16 : keys[0] = balance_key;
65 16 : amounts[0] = *balance_value;
66 :
67 16 : va_start (ap,
68 : balance_value);
69 142 : while (off < cnt)
70 : {
71 126 : keys[off] = va_arg (ap,
72 : const char *);
73 126 : amounts[off] = *va_arg (ap,
74 : const struct TALER_Amount *);
75 126 : off++;
76 : }
77 16 : GNUNET_assert (NULL == va_arg (ap,
78 : const char *));
79 16 : va_end (ap);
80 :
81 16 : PREPARE (pg,
82 : "auditor_balance_insert",
83 : "INSERT INTO auditor_balances "
84 : "(balance_key"
85 : ",balance_value.val"
86 : ",balance_value.frac"
87 : ") SELECT *"
88 : " FROM UNNEST (CAST($1 AS TEXT[]),"
89 : " CAST($2 AS taler_amount[]))"
90 : " ON CONFLICT DO NOTHING;");
91 16 : qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
92 : "auditor_balance_insert",
93 : params);
94 16 : GNUNET_PQ_cleanup_query_params_closures (params);
95 16 : return qs;
96 : }
97 : }
|