LCOV - code coverage report
Current view: top level - backenddb - pg_select_unit.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 27 24
Test Date: 2025-12-02 20:17:27 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2025 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_select_unit.c
      18              :  * @brief Implementation of the select_unit function for Postgres
      19              :  * @author Bohdan Potuzhnyi
      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_select_unit.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           42 : TMH_PG_select_unit (void *cls,
      31              :                     const char *instance_id,
      32              :                     const char *unit_id,
      33              :                     struct TALER_MERCHANTDB_UnitDetails *ud)
      34              : {
      35              :   enum GNUNET_DB_QueryStatus qs;
      36           42 :   struct PostgresClosure *pg = cls;
      37           42 :   struct GNUNET_PQ_QueryParam params[] = {
      38           42 :     GNUNET_PQ_query_param_string (instance_id),
      39           42 :     GNUNET_PQ_query_param_string (unit_id),
      40              :     GNUNET_PQ_query_param_end
      41              :   };
      42              : 
      43           42 :   if (NULL == ud)
      44              :   {
      45            0 :     struct GNUNET_PQ_ResultSpec rs_null[] = {
      46              :       GNUNET_PQ_result_spec_end
      47              :     };
      48              : 
      49            0 :     check_connection (pg);
      50            0 :     return GNUNET_PQ_eval_prepared_singleton_select (
      51              :       pg->conn,
      52              :       "select_unit",
      53              :       params,
      54              :       rs_null);
      55              :   }
      56              :   else
      57              :   {
      58           42 :     struct GNUNET_PQ_ResultSpec rs[] = {
      59           42 :       GNUNET_PQ_result_spec_uint64 ("unit_serial",
      60              :                                     &ud->unit_serial),
      61           42 :       GNUNET_PQ_result_spec_string ("unit",
      62              :                                     &ud->unit),
      63           42 :       GNUNET_PQ_result_spec_string ("unit_name_long",
      64              :                                     &ud->unit_name_long),
      65           42 :       GNUNET_PQ_result_spec_string ("unit_name_short",
      66              :                                     &ud->unit_name_short),
      67           42 :       TALER_PQ_result_spec_json ("unit_name_long_i18n",
      68              :                                  &ud->unit_name_long_i18n),
      69           42 :       TALER_PQ_result_spec_json ("unit_name_short_i18n",
      70              :                                  &ud->unit_name_short_i18n),
      71           42 :       GNUNET_PQ_result_spec_bool ("unit_allow_fraction",
      72              :                                   &ud->unit_allow_fraction),
      73           42 :       GNUNET_PQ_result_spec_uint32 ("unit_precision_level",
      74              :                                     &ud->unit_precision_level),
      75           42 :       GNUNET_PQ_result_spec_bool ("unit_active",
      76              :                                   &ud->unit_active),
      77           42 :       GNUNET_PQ_result_spec_bool ("unit_builtin",
      78              :                                   &ud->unit_builtin),
      79              :       GNUNET_PQ_result_spec_end
      80              :     };
      81              : 
      82           42 :     check_connection (pg);
      83              : 
      84           42 :     PREPARE (pg,
      85              :              "select_unit_custom",
      86              :              "SELECT"
      87              :              "  cu.unit_serial"
      88              :              " ,cu.unit"
      89              :              " ,cu.unit_name_long"
      90              :              " ,cu.unit_name_short"
      91              :              " ,cu.unit_name_long_i18n"
      92              :              " ,cu.unit_name_short_i18n"
      93              :              " ,cu.unit_allow_fraction"
      94              :              " ,cu.unit_precision_level"
      95              :              " ,cu.unit_active"
      96              :              " ,FALSE AS unit_builtin"
      97              :              " FROM merchant_custom_units cu"
      98              :              " JOIN merchant_instances inst"
      99              :              "   USING (merchant_serial)"
     100              :              " WHERE inst.merchant_id=$1"
     101              :              "   AND cu.unit=$2");
     102           42 :     qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     103              :                                                    "select_unit_custom",
     104              :                                                    params,
     105              :                                                    rs);
     106           42 :     if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
     107            6 :       return qs;
     108              : 
     109           36 :     PREPARE (pg,
     110              :              "select_unit_builtin",
     111              :              "SELECT"
     112              :              "  bu.unit_serial"
     113              :              " ,bu.unit"
     114              :              " ,bu.unit_name_long"
     115              :              " ,bu.unit_name_short"
     116              :              " ,bu.unit_name_long_i18n"
     117              :              " ,bu.unit_name_short_i18n"
     118              :              " ,COALESCE(bo.override_allow_fraction, bu.unit_allow_fraction)"
     119              :              " ,COALESCE(bo.override_precision_level, bu.unit_precision_level)"
     120              :              " ,COALESCE(bo.override_active, bu.unit_active)"
     121              :              " ,TRUE AS unit_builtin"
     122              :              " FROM merchant_builtin_units bu"
     123              :              " JOIN merchant_instances inst"
     124              :              "   ON TRUE"
     125              :              " LEFT JOIN merchant_builtin_unit_overrides bo"
     126              :              "   ON bo.builtin_unit_serial = bu.unit_serial"
     127              :              "  AND bo.merchant_serial = inst.merchant_serial"
     128              :              " WHERE inst.merchant_id=$1"
     129              :              "   AND bu.unit=$2");
     130           36 :     return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     131              :                                                      "select_unit_builtin",
     132              :                                                      params,
     133              :                                                      rs);
     134              :   }
     135              : }
        

Generated by: LCOV version 2.0-1