LCOV - code coverage report
Current view: top level - backenddb - pg_insert_exchange_keys.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 16 16
Test Date: 2025-11-06 19:31:41 Functions: 100.0 % 1 1

            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 backenddb/pg_insert_exchange_keys.c
      18              :  * @brief Implementation of the insert_exchange_keys function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "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_insert_exchange_keys.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           11 : TMH_PG_insert_exchange_keys (
      31              :   void *cls,
      32              :   const struct TALER_EXCHANGE_Keys *keys,
      33              :   struct GNUNET_TIME_Absolute first_retry)
      34              : {
      35           11 :   struct PostgresClosure *pg = cls;
      36           11 :   json_t *jkeys = TALER_EXCHANGE_keys_to_json (keys);
      37           11 :   struct GNUNET_PQ_QueryParam params[] = {
      38           11 :     TALER_PQ_query_param_json (jkeys),
      39           11 :     GNUNET_PQ_query_param_absolute_time (&first_retry),
      40           11 :     GNUNET_PQ_query_param_timestamp (&keys->last_denom_issue_date),
      41           11 :     GNUNET_PQ_query_param_string (keys->exchange_url),
      42              :     GNUNET_PQ_query_param_end
      43              :   };
      44              :   enum GNUNET_DB_QueryStatus qs;
      45              : 
      46           11 :   check_connection (pg);
      47           11 :   PREPARE (pg,
      48              :            "insert_exchange_keys",
      49              :            "INSERT INTO merchant_exchange_keys"
      50              :            "(keys_json"
      51              :            ",first_retry"
      52              :            ",expiration_time"
      53              :            ",exchange_url"
      54              :            ") VALUES ($1::TEXT::JSONB, $2, $3, $4);");
      55           11 :   PREPARE (pg,
      56              :            "update_exchange_keys",
      57              :            "UPDATE merchant_exchange_keys SET"
      58              :            " keys_json=$1::TEXT::JSONB"
      59              :            ",first_retry=$2"
      60              :            ",expiration_time=$3"
      61              :            " WHERE"
      62              :            " exchange_url=$4;");
      63           11 :   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      64              :                                            "update_exchange_keys",
      65              :                                            params);
      66           11 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      67           11 :     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      68              :                                              "insert_exchange_keys",
      69              :                                              params);
      70           11 :   json_decref (jkeys);
      71           11 :   return qs;
      72              : }
        

Generated by: LCOV version 2.0-1