exchange

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

update_auditor_progress.c (3152B)


      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 TALER_AUDITORDB_update_auditor_progress (struct
     28                                          TALER_AUDITORDB_PostgresContext *pg,
     29                                          const char *progress_key,
     30                                          uint64_t progress_offset,
     31                                          ...)
     32 {
     33   unsigned int cnt = 1;
     34   va_list ap;
     35 
     36   va_start (ap,
     37             progress_offset);
     38   while (NULL != va_arg (ap,
     39                          const char *))
     40   {
     41     cnt++;
     42     (void) va_arg (ap,
     43                    uint64_t);
     44   }
     45   va_end (ap);
     46   {
     47     const char *keys[cnt];
     48     uint64_t offsets[cnt];
     49     unsigned int off = 1;
     50     struct GNUNET_PQ_QueryParam params[] = {
     51       GNUNET_PQ_query_param_array_ptrs_string (cnt,
     52                                                keys,
     53                                                pg->conn),
     54       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     keys[0] = progress_key;
     62     offsets[0] = progress_offset;
     63 
     64     va_start (ap,
     65               progress_offset);
     66     while (off < cnt)
     67     {
     68       keys[off] = va_arg (ap,
     69                           const char *);
     70       offsets[off] = va_arg (ap,
     71                              uint64_t);
     72       off++;
     73     }
     74     GNUNET_assert (NULL == va_arg (ap,
     75                                    const char *));
     76     va_end (ap);
     77 
     78     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     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     90                                              "auditor_progress_update",
     91                                              params);
     92     GNUNET_PQ_cleanup_query_params_closures (params);
     93     return qs;
     94   }
     95 }