LCOV - code coverage report
Current view: top level - auditordb - pg_update_balance.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 28 28
Test Date: 2025-12-28 14:06:02 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2023 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 auditordb/pg_update_balance.c
      18              :  * @brief Implementation of the update_balance function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/platform.h"
      22              : #include "taler/taler_error_codes.h"
      23              : #include "taler/taler_dbevents.h"
      24              : #include "taler/taler_pq_lib.h"
      25              : #include "pg_update_balance.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           12 : TAH_PG_update_balance (
      31              :   void *cls,
      32              :   const char *balance_key,
      33              :   const struct TALER_Amount *balance_amount,
      34              :   ...)
      35              : {
      36           12 :   struct PostgresClosure *pg = cls;
      37           12 :   unsigned int cnt = 1;
      38              :   va_list ap;
      39              : 
      40           12 :   va_start (ap,
      41              :             balance_amount);
      42           88 :   while (NULL != va_arg (ap,
      43              :                          const char *))
      44              :   {
      45           76 :     cnt++;
      46           76 :     (void) va_arg (ap,
      47              :                    const struct TALER_Amount *);
      48              :   }
      49           12 :   va_end (ap);
      50           12 :   {
      51           12 :     const char *keys[cnt];
      52           12 :     struct TALER_Amount amounts[cnt];
      53           12 :     unsigned int off = 1;
      54           12 :     struct GNUNET_PQ_QueryParam params[] = {
      55           12 :       GNUNET_PQ_query_param_array_ptrs_string (cnt,
      56              :                                                keys,
      57              :                                                pg->conn),
      58           12 :       TALER_PQ_query_param_array_amount (cnt,
      59              :                                          amounts,
      60              :                                          pg->conn),
      61              :       GNUNET_PQ_query_param_end
      62              :     };
      63              :     enum GNUNET_DB_QueryStatus qs;
      64              : 
      65           12 :     keys[0] = balance_key;
      66           12 :     amounts[0] = *balance_amount;
      67              : 
      68           12 :     va_start (ap,
      69              :               balance_amount);
      70           88 :     while (off < cnt)
      71              :     {
      72           76 :       keys[off] = va_arg (ap,
      73              :                           const char *);
      74           76 :       amounts[off] = *va_arg (ap,
      75              :                               const struct TALER_Amount *);
      76           76 :       off++;
      77              :     }
      78           12 :     GNUNET_assert (NULL == va_arg (ap,
      79              :                                    const char *));
      80           12 :     va_end (ap);
      81              : 
      82           12 :     PREPARE (pg,
      83              :              "auditor_balance_update",
      84              :              "UPDATE auditor_balances"
      85              :              "  SET balance_value.val=data.val"
      86              :              "     ,balance_value.frac=data.frac"
      87              :              "  FROM ("
      88              :              "    SELECT *"
      89              :              "      FROM UNNEST (CAST($1 AS TEXT[]),"
      90              :              "                   CAST($2 AS taler_amount[]))"
      91              :              "      AS t(key,val,frac)"
      92              :              "  ) AS data"
      93              :              " WHERE auditor_balances.balance_key=data.key;");
      94           12 :     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      95              :                                              "auditor_balance_update",
      96              :                                              params);
      97           12 :     GNUNET_PQ_cleanup_query_params_closures (params);
      98           12 :     return qs;
      99              :   }
     100              : }
        

Generated by: LCOV version 2.0-1