LCOV - code coverage report
Current view: top level - auditordb - pg_delete_generic.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 19 89.5 %
Date: 2025-06-05 21:03:14 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.16