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 update_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/update_auditor_progress.h"
23 : #include "pg_helper.h"
24 :
25 :
26 : enum GNUNET_DB_QueryStatus
27 14 : TALER_AUDITORDB_update_auditor_progress (struct
28 : TALER_AUDITORDB_PostgresContext *pg,
29 : const char *progress_key,
30 : uint64_t progress_offset,
31 : ...)
32 : {
33 14 : unsigned int cnt = 1;
34 : va_list ap;
35 :
36 14 : va_start (ap,
37 : progress_offset);
38 68 : while (NULL != va_arg (ap,
39 : const char *))
40 : {
41 54 : cnt++;
42 54 : (void) va_arg (ap,
43 : uint64_t);
44 : }
45 14 : va_end (ap);
46 14 : {
47 14 : const char *keys[cnt];
48 14 : uint64_t offsets[cnt];
49 14 : unsigned int off = 1;
50 14 : struct GNUNET_PQ_QueryParam params[] = {
51 14 : GNUNET_PQ_query_param_array_ptrs_string (cnt,
52 : keys,
53 : pg->conn),
54 14 : 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 14 : keys[0] = progress_key;
62 14 : offsets[0] = progress_offset;
63 :
64 14 : va_start (ap,
65 : progress_offset);
66 68 : while (off < cnt)
67 : {
68 54 : keys[off] = va_arg (ap,
69 : const char *);
70 54 : offsets[off] = va_arg (ap,
71 : uint64_t);
72 54 : off++;
73 : }
74 14 : GNUNET_assert (NULL == va_arg (ap,
75 : const char *));
76 14 : va_end (ap);
77 :
78 14 : PREPARE (pg,
79 : "auditor_progress_update",
80 : "UPDATE auditor_progress"
81 : " SET progress_offset=data.off"
82 : " FROM ("
83 : " SELECT *"
84 : " FROM UNNEST (CAST($1 AS TEXT[]),"
85 : " CAST($2 AS INT8[]))"
86 : " AS t(key,off)"
87 : " ) AS data"
88 : " WHERE auditor_progress.progress_key=data.key;");
89 14 : qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
90 : "auditor_progress_update",
91 : params);
92 14 : GNUNET_PQ_cleanup_query_params_closures (params);
93 14 : return qs;
94 : }
95 : }
|