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 : #include "taler/taler_pq_lib.h"
17 : #include "pg_helper.h"
18 : #include "auditor-database/delete_generic.h"
19 :
20 : struct Preparations
21 : {
22 : /**
23 : * Database reconnect counter.
24 : */
25 : unsigned long long cnt;
26 :
27 : /**
28 : * Which DB did we do prepare for.
29 : */
30 : struct TALER_AUDITORDB_PostgresContext *pg;
31 :
32 : };
33 :
34 :
35 : enum GNUNET_DB_QueryStatus
36 0 : TALER_AUDITORDB_delete_generic (
37 : struct TALER_AUDITORDB_PostgresContext *pg,
38 : enum TALER_AUDITORDB_DeletableSuppressableTables table,
39 : uint64_t row_id)
40 : {
41 0 : struct GNUNET_PQ_QueryParam params[] = {
42 0 : GNUNET_PQ_query_param_uint64 (&row_id),
43 : GNUNET_PQ_query_param_end
44 : };
45 : static struct Preparations preps[
46 : TALER_AUDITORDB_DELETABLESUPPRESSABLE_TABLES_MAX];
47 :
48 0 : struct Preparations *prep = &preps[table];
49 : const char *table_name
50 0 : = TALER_AUDITORDB_get_deletable_suppressable_table_name (
51 : table);
52 : char statement_name[256];
53 :
54 0 : if (NULL == table_name)
55 0 : return GNUNET_DB_STATUS_HARD_ERROR;
56 0 : GNUNET_snprintf (statement_name,
57 : sizeof (statement_name),
58 : "delete_%s",
59 : table_name);
60 0 : if ( (pg != prep->pg) ||
61 0 : (prep->cnt < pg->prep_gen) )
62 : {
63 : char sql[256];
64 0 : struct GNUNET_PQ_PreparedStatement ps[] = {
65 0 : GNUNET_PQ_make_prepare (statement_name,
66 : sql),
67 : GNUNET_PQ_PREPARED_STATEMENT_END
68 : };
69 :
70 0 : GNUNET_snprintf (sql,
71 : sizeof (sql),
72 : "DELETE FROM %s"
73 : " WHERE row_id=$1",
74 : table_name);
75 0 : if (GNUNET_OK !=
76 0 : GNUNET_PQ_prepare_statements (pg->conn,
77 : ps))
78 : {
79 0 : GNUNET_break (0);
80 0 : return GNUNET_DB_STATUS_HARD_ERROR;
81 : }
82 0 : prep->pg = pg;
83 0 : prep->cnt = pg->prep_gen;
84 : }
85 0 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
86 : statement_name,
87 : params);
88 : }
|