LCOV - code coverage report
Current view: top level - exchangedb - select_all_purse_decisions_above_serial_id.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 44.0 % 25 11
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022 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 select_all_purse_decisions_above_serial_id.c
      18              :  * @brief Implementation of the select_all_purse_decisions_above_serial_id function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/select_all_purse_decisions_above_serial_id.h"
      23              : #include "helper.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Closure for #all_purse_decision_serial_helper_cb().
      28              :  */
      29              : struct AllPurseDecisionSerialContext
      30              : {
      31              : 
      32              :   /**
      33              :    * Callback to call.
      34              :    */
      35              :   TALER_EXCHANGEDB_AllPurseDecisionCallback cb;
      36              : 
      37              :   /**
      38              :    * Closure for @e cb.
      39              :    */
      40              :   void *cb_cls;
      41              : 
      42              :   /**
      43              :    * Plugin context.
      44              :    */
      45              :   struct TALER_EXCHANGEDB_PostgresContext *pg;
      46              : 
      47              :   /**
      48              :    * Status code, set to #GNUNET_SYSERR on hard errors.
      49              :    */
      50              :   enum GNUNET_GenericReturnValue status;
      51              : };
      52              : 
      53              : 
      54              : /**
      55              :  * Helper function to be called with the results of a SELECT statement
      56              :  * that has returned @a num_results results.
      57              :  *
      58              :  * @param cls closure of type `struct PurseRefundSerialContext`
      59              :  * @param result the postgres result
      60              :  * @param num_results the number of results in @a result
      61              :  */
      62              : static void
      63            4 : all_purse_decision_serial_helper_cb (void *cls,
      64              :                                      PGresult *result,
      65              :                                      unsigned int num_results)
      66              : {
      67            4 :   struct AllPurseDecisionSerialContext *dsc = cls;
      68              : 
      69            4 :   for (unsigned int i = 0; i<num_results; i++)
      70              :   {
      71              :     struct TALER_PurseContractPublicKeyP purse_pub;
      72              :     bool refunded;
      73              :     uint64_t rowid;
      74            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      75            0 :       GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
      76              :                                             &purse_pub),
      77            0 :       GNUNET_PQ_result_spec_bool ("refunded",
      78              :                                   &refunded),
      79            0 :       GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
      80              :                                     &rowid),
      81              :       GNUNET_PQ_result_spec_end
      82              :     };
      83              :     enum GNUNET_GenericReturnValue ret;
      84              : 
      85            0 :     if (GNUNET_OK !=
      86            0 :         GNUNET_PQ_extract_result (result,
      87              :                                   rs,
      88              :                                   i))
      89              :     {
      90            0 :       GNUNET_break (0);
      91            0 :       dsc->status = GNUNET_SYSERR;
      92            0 :       return;
      93              :     }
      94            0 :     ret = dsc->cb (dsc->cb_cls,
      95              :                    rowid,
      96              :                    &purse_pub,
      97              :                    refunded);
      98            0 :     GNUNET_PQ_cleanup_result (rs);
      99            0 :     if (GNUNET_OK != ret)
     100            0 :       break;
     101              :   }
     102              : }
     103              : 
     104              : 
     105              : enum GNUNET_DB_QueryStatus
     106            4 : TALER_EXCHANGEDB_select_all_purse_decisions_above_serial_id (
     107              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
     108              :   uint64_t serial_id,
     109              :   TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
     110              :   void *cb_cls)
     111              : {
     112            4 :   struct GNUNET_PQ_QueryParam params[] = {
     113            4 :     GNUNET_PQ_query_param_uint64 (&serial_id),
     114              :     GNUNET_PQ_query_param_end
     115              :   };
     116            4 :   struct AllPurseDecisionSerialContext dsc = {
     117              :     .cb = cb,
     118              :     .cb_cls = cb_cls,
     119              :     .pg = pg,
     120              :     .status = GNUNET_OK
     121              :   };
     122              :   enum GNUNET_DB_QueryStatus qs;
     123              : 
     124            4 :   PREPARE (pg,
     125              :            "audit_select_all_purse_decisions_above_serial_id",
     126              :            "SELECT"
     127              :            " purse_pub"
     128              :            ",refunded"
     129              :            ",purse_decision_serial_id"
     130              :            " FROM purse_decision"
     131              :            " WHERE purse_decision_serial_id>=$1"
     132              :            " ORDER BY purse_decision_serial_id ASC;");
     133            4 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     134              :     pg->conn,
     135              :     "audit_select_all_purse_decisions_above_serial_id",
     136              :     params,
     137              :     &all_purse_decision_serial_helper_cb,
     138              :     &dsc);
     139            4 :   if (GNUNET_OK != dsc.status)
     140            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     141            4 :   return qs;
     142              : }
        

Generated by: LCOV version 2.0-1