exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

pg_update_generic_suppressed.c (2658B)


      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/platform.h"
     17 #include "taler/taler_pq_lib.h"
     18 #include "pg_helper.h"
     19 #include "pg_update_generic_suppressed.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 
     36 enum GNUNET_DB_QueryStatus
     37 TAH_PG_update_generic_suppressed (
     38   void *cls,
     39   enum TALER_AUDITORDB_DeletableSuppressableTables table,
     40   uint64_t row_id,
     41   bool suppressed)
     42 {
     43   struct PostgresClosure *pg = cls;
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_uint64 (&row_id),
     46     GNUNET_PQ_query_param_bool (suppressed),
     47     GNUNET_PQ_query_param_end
     48   };
     49   static struct Preparations preps[
     50     TALER_AUDITORDB_DELETABLESUPPRESSABLE_TABLES_MAX];
     51 
     52   struct Preparations *prep = &preps[table];
     53   const char *table_name = TAH_PG_get_deletable_suppressable_table_name (table);
     54   char statement_name[256];
     55 
     56   GNUNET_snprintf (statement_name,
     57                    sizeof (statement_name),
     58                    "update_%s",
     59                    table_name);
     60   if ( (pg != prep->pg) ||
     61        (prep->cnt < pg->prep_gen) )
     62   {
     63     char sql[256];
     64     struct GNUNET_PQ_PreparedStatement ps[] = {
     65       GNUNET_PQ_make_prepare (statement_name,
     66                               sql),
     67       GNUNET_PQ_PREPARED_STATEMENT_END
     68     };
     69 
     70     GNUNET_snprintf (sql,
     71                      sizeof (sql),
     72                      "UPDATE %s SET"
     73                      " suppressed=$2"
     74                      " WHERE row_id=$1",
     75                      table_name);
     76     if (GNUNET_OK !=
     77         GNUNET_PQ_prepare_statements (pg->conn,
     78                                       ps))
     79     {
     80       GNUNET_break (0);
     81       return GNUNET_DB_STATUS_HARD_ERROR;
     82     }
     83     prep->pg = pg;
     84     prep->cnt = pg->prep_gen;
     85   }
     86   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     87                                              statement_name,
     88                                              params);
     89 }