LCOV - code coverage report
Current view: top level - backenddb - pg_lookup_template.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.2 % 17 15
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, 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 backenddb/pg_lookup_template.c
      18              :  * @brief Implementation of the lookup_template 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_lookup_template.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : /**
      30              :  * Lookup details about a particular template.
      31              :  *
      32              :  * @param cls closure
      33              :  * @param instance_id instance to lookup template for
      34              :  * @param template_id template to lookup
      35              :  * @param[out] td set to the template details on success, can be NULL
      36              :  *             (in that case we only want to check if the template exists)
      37              :  * @return database result code
      38              :  */
      39              : enum GNUNET_DB_QueryStatus
      40           26 : TMH_PG_lookup_template (void *cls,
      41              :                         const char *instance_id,
      42              :                         const char *template_id,
      43              :                         struct TALER_MERCHANTDB_TemplateDetails *td)
      44              : {
      45           26 :   struct PostgresClosure *pg = cls;
      46           26 :   struct GNUNET_PQ_QueryParam params[] = {
      47           26 :     GNUNET_PQ_query_param_string (instance_id),
      48           26 :     GNUNET_PQ_query_param_string (template_id),
      49              :     GNUNET_PQ_query_param_end
      50              :   };
      51              : 
      52           26 :   check_connection (pg);
      53           26 :   PREPARE (pg,
      54              :            "lookup_template",
      55              :            "SELECT"
      56              :            " mt.template_description"
      57              :            ",mod.otp_id"
      58              :            ",mt.template_contract::TEXT"
      59              :            ",mt.editable_defaults::TEXT"
      60              :            " FROM merchant_template mt"
      61              :            " JOIN merchant_instances mi"
      62              :            "   ON (mi.merchant_serial = mt.merchant_serial)"
      63              :            " LEFT JOIN merchant_otp_devices mod"
      64              :            "   ON (mod.otp_serial = mt.otp_device_id)"
      65              :            " WHERE mi.merchant_id=$1"
      66              :            "   AND mt.template_id=$2");
      67           26 :   if (NULL == td)
      68              :   {
      69            0 :     struct GNUNET_PQ_ResultSpec rs_null[] = {
      70              :       GNUNET_PQ_result_spec_end
      71              :     };
      72              : 
      73            0 :     return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      74              :                                                      "lookup_template",
      75              :                                                      params,
      76              :                                                      rs_null);
      77              :   }
      78              :   else
      79              :   {
      80           26 :     struct GNUNET_PQ_ResultSpec rs[] = {
      81           26 :       GNUNET_PQ_result_spec_string ("template_description",
      82              :                                     &td->template_description),
      83           26 :       GNUNET_PQ_result_spec_allow_null (
      84              :         GNUNET_PQ_result_spec_string ("otp_id",
      85              :                                       &td->otp_id),
      86              :         NULL),
      87           26 :       TALER_PQ_result_spec_json ("template_contract",
      88              :                                  &td->template_contract),
      89           26 :       GNUNET_PQ_result_spec_allow_null (
      90              :         TALER_PQ_result_spec_json ("editable_defaults",
      91              :                                    &td->editable_defaults),
      92              :         NULL),
      93              :       GNUNET_PQ_result_spec_end
      94              :     };
      95              : 
      96           26 :     memset (td,
      97              :             0,
      98              :             sizeof (*td));
      99           26 :     return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     100              :                                                      "lookup_template",
     101              :                                                      params,
     102              :                                                      rs);
     103              :   }
     104              : }
        

Generated by: LCOV version 2.0-1