LCOV - code coverage report
Current view: top level - auditordb - insert_balance.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 27 27
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 1 1

            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              : /**
      17              :  * @file insert_balance.c
      18              :  * @brief Implementation of the insert_balance function
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "auditor-database/insert_balance.h"
      23              : #include "pg_helper.h"
      24              : 
      25              : 
      26              : enum GNUNET_DB_QueryStatus
      27           16 : TALER_AUDITORDB_insert_balance (struct TALER_AUDITORDB_PostgresContext *pg,
      28              :                                 const char *balance_key,
      29              :                                 const struct TALER_Amount *balance_value,
      30              :                                 ...)
      31              : {
      32           16 :   unsigned int cnt = 1;
      33              :   va_list ap;
      34              : 
      35           16 :   va_start (ap,
      36              :             balance_value);
      37          142 :   while (NULL != va_arg (ap,
      38              :                          const char *))
      39              :   {
      40          126 :     cnt++;
      41          126 :     (void) va_arg (ap,
      42              :                    const struct TALER_Amount *);
      43              :   }
      44           16 :   va_end (ap);
      45           16 :   {
      46           16 :     const char *keys[cnt];
      47           16 :     struct TALER_Amount amounts[cnt];
      48           16 :     unsigned int off = 1;
      49           16 :     struct GNUNET_PQ_QueryParam params[] = {
      50           16 :       GNUNET_PQ_query_param_array_ptrs_string (cnt,
      51              :                                                keys,
      52              :                                                pg->conn),
      53           16 :       TALER_PQ_query_param_array_amount (cnt,
      54              :                                          amounts,
      55              :                                          pg->conn),
      56              :       GNUNET_PQ_query_param_end
      57              :     };
      58              :     enum GNUNET_DB_QueryStatus qs;
      59              : 
      60           16 :     keys[0] = balance_key;
      61           16 :     amounts[0] = *balance_value;
      62              : 
      63           16 :     va_start (ap,
      64              :               balance_value);
      65          142 :     while (off < cnt)
      66              :     {
      67          126 :       keys[off] = va_arg (ap,
      68              :                           const char *);
      69          126 :       amounts[off] = *va_arg (ap,
      70              :                               const struct TALER_Amount *);
      71          126 :       off++;
      72              :     }
      73           16 :     GNUNET_assert (NULL == va_arg (ap,
      74              :                                    const char *));
      75           16 :     va_end (ap);
      76              : 
      77           16 :     PREPARE (pg,
      78              :              "auditor_balance_insert",
      79              :              "INSERT INTO auditor_balances "
      80              :              "(balance_key"
      81              :              ",balance_value.val"
      82              :              ",balance_value.frac"
      83              :              ") SELECT *"
      84              :              " FROM UNNEST (CAST($1 AS TEXT[]),"
      85              :              "              CAST($2 AS taler_amount[]))"
      86              :              " ON CONFLICT DO NOTHING;");
      87           16 :     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      88              :                                              "auditor_balance_insert",
      89              :                                              params);
      90           16 :     GNUNET_PQ_cleanup_query_params_closures (params);
      91           16 :     return qs;
      92              :   }
      93              : }
        

Generated by: LCOV version 2.0-1