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 insert_auditor_progress.c
18 : * @brief Low-level (statement-level) Postgres database access for the exchange
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "auditor-database/insert_auditor_progress.h"
23 : #include "pg_helper.h"
24 :
25 :
26 : enum GNUNET_DB_QueryStatus
27 10 : TALER_AUDITORDB_insert_auditor_progress (struct
28 : TALER_AUDITORDB_PostgresContext *pg,
29 : const char *progress_key,
30 : uint64_t progress_offset,
31 : ...)
32 : {
33 10 : unsigned int cnt = 1;
34 : va_list ap;
35 :
36 10 : va_start (ap,
37 : progress_offset);
38 54 : while (NULL != va_arg (ap,
39 : const char *))
40 : {
41 44 : cnt++;
42 44 : (void) va_arg (ap,
43 : uint64_t);
44 : }
45 10 : va_end (ap);
46 10 : {
47 10 : const char *keys[cnt];
48 10 : uint64_t offsets[cnt];
49 10 : unsigned int off = 1;
50 10 : struct GNUNET_PQ_QueryParam params[] = {
51 10 : GNUNET_PQ_query_param_array_ptrs_string (cnt,
52 : keys,
53 : pg->conn),
54 10 : GNUNET_PQ_query_param_array_uint64 (cnt,
55 : offsets,
56 : pg->conn),
57 : GNUNET_PQ_query_param_end
58 : };
59 : enum GNUNET_DB_QueryStatus qs;
60 :
61 10 : keys[0] = progress_key;
62 10 : offsets[0] = progress_offset;
63 :
64 10 : va_start (ap,
65 : progress_offset);
66 54 : while (off < cnt)
67 : {
68 44 : keys[off] = va_arg (ap,
69 : const char *);
70 44 : offsets[off] = va_arg (ap,
71 : uint64_t);
72 44 : off++;
73 : }
74 10 : GNUNET_assert (NULL == va_arg (ap,
75 : const char *));
76 10 : va_end (ap);
77 :
78 10 : PREPARE (pg,
79 : "auditor_progress_insert",
80 : "INSERT INTO auditor_progress "
81 : "(progress_key"
82 : ",progress_offset"
83 : ") SELECT *"
84 : " FROM UNNEST (CAST($1 AS TEXT[]),"
85 : " CAST($2 AS INT8[]))"
86 : " ON CONFLICT DO NOTHING;");
87 10 : qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
88 : "auditor_progress_insert",
89 : params);
90 10 : GNUNET_PQ_cleanup_query_params_closures (params);
91 10 : return qs;
92 : }
93 : }
|