LCOV - code coverage report
Current view: top level - exchangedb - pg_select_all_purse_decisions_above_serial_id.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 46.2 % 26 12
Test Date: 2025-12-28 14:06:02 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 pg_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/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_select_all_purse_decisions_above_serial_id.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : /**
      30              :  * Closure for #all_purse_decision_serial_helper_cb().
      31              :  */
      32              : struct AllPurseDecisionSerialContext
      33              : {
      34              : 
      35              :   /**
      36              :    * Callback to call.
      37              :    */
      38              :   TALER_EXCHANGEDB_AllPurseDecisionCallback cb;
      39              : 
      40              :   /**
      41              :    * Closure for @e cb.
      42              :    */
      43              :   void *cb_cls;
      44              : 
      45              :   /**
      46              :    * Plugin context.
      47              :    */
      48              :   struct PostgresClosure *pg;
      49              : 
      50              :   /**
      51              :    * Status code, set to #GNUNET_SYSERR on hard errors.
      52              :    */
      53              :   enum GNUNET_GenericReturnValue status;
      54              : };
      55              : 
      56              : 
      57              : /**
      58              :  * Helper function to be called with the results of a SELECT statement
      59              :  * that has returned @a num_results results.
      60              :  *
      61              :  * @param cls closure of type `struct PurseRefundSerialContext`
      62              :  * @param result the postgres result
      63              :  * @param num_results the number of results in @a result
      64              :  */
      65              : static void
      66            4 : all_purse_decision_serial_helper_cb (void *cls,
      67              :                                      PGresult *result,
      68              :                                      unsigned int num_results)
      69              : {
      70            4 :   struct AllPurseDecisionSerialContext *dsc = cls;
      71              : 
      72            4 :   for (unsigned int i = 0; i<num_results; i++)
      73              :   {
      74              :     struct TALER_PurseContractPublicKeyP purse_pub;
      75              :     bool refunded;
      76              :     uint64_t rowid;
      77            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      78            0 :       GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
      79              :                                             &purse_pub),
      80            0 :       GNUNET_PQ_result_spec_bool ("refunded",
      81              :                                   &refunded),
      82            0 :       GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
      83              :                                     &rowid),
      84              :       GNUNET_PQ_result_spec_end
      85              :     };
      86              :     enum GNUNET_GenericReturnValue ret;
      87              : 
      88            0 :     if (GNUNET_OK !=
      89            0 :         GNUNET_PQ_extract_result (result,
      90              :                                   rs,
      91              :                                   i))
      92              :     {
      93            0 :       GNUNET_break (0);
      94            0 :       dsc->status = GNUNET_SYSERR;
      95            0 :       return;
      96              :     }
      97            0 :     ret = dsc->cb (dsc->cb_cls,
      98              :                    rowid,
      99              :                    &purse_pub,
     100              :                    refunded);
     101            0 :     GNUNET_PQ_cleanup_result (rs);
     102            0 :     if (GNUNET_OK != ret)
     103            0 :       break;
     104              :   }
     105              : }
     106              : 
     107              : 
     108              : enum GNUNET_DB_QueryStatus
     109            4 : TEH_PG_select_all_purse_decisions_above_serial_id (
     110              :   void *cls,
     111              :   uint64_t serial_id,
     112              :   TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
     113              :   void *cb_cls)
     114              : {
     115            4 :   struct PostgresClosure *pg = cls;
     116            4 :   struct GNUNET_PQ_QueryParam params[] = {
     117            4 :     GNUNET_PQ_query_param_uint64 (&serial_id),
     118              :     GNUNET_PQ_query_param_end
     119              :   };
     120            4 :   struct AllPurseDecisionSerialContext dsc = {
     121              :     .cb = cb,
     122              :     .cb_cls = cb_cls,
     123              :     .pg = pg,
     124              :     .status = GNUNET_OK
     125              :   };
     126              :   enum GNUNET_DB_QueryStatus qs;
     127              : 
     128            4 :   PREPARE (pg,
     129              :            "audit_select_all_purse_decisions_above_serial_id",
     130              :            "SELECT"
     131              :            " purse_pub"
     132              :            ",refunded"
     133              :            ",purse_decision_serial_id"
     134              :            " FROM purse_decision"
     135              :            " WHERE purse_decision_serial_id>=$1"
     136              :            " ORDER BY purse_decision_serial_id ASC;");
     137            4 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     138              :     pg->conn,
     139              :     "audit_select_all_purse_decisions_above_serial_id",
     140              :     params,
     141              :     &all_purse_decision_serial_helper_cb,
     142              :     &dsc);
     143            4 :   if (GNUNET_OK != dsc.status)
     144            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     145            4 :   return qs;
     146              : }
        

Generated by: LCOV version 2.0-1