LCOV - code coverage report
Current view: top level - backenddb - pg_delete_order.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 69.6 % 23 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_delete_order.c
      18              :  * @brief Implementation of the delete_order function for Postgres
      19              :  * @author Iván Ávalos
      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_delete_order.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : enum GNUNET_DB_QueryStatus
      29            6 : TMH_PG_delete_order (void *cls,
      30              :                      const char *instance_id,
      31              :                      const char *order_id,
      32              :                      bool force)
      33              : {
      34            6 :   struct PostgresClosure *pg = cls;
      35            6 :   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
      36            6 :   struct GNUNET_PQ_QueryParam params[] = {
      37            6 :     GNUNET_PQ_query_param_string (instance_id),
      38            6 :     GNUNET_PQ_query_param_string (order_id),
      39            6 :     GNUNET_PQ_query_param_absolute_time (&now),
      40            6 :     GNUNET_PQ_query_param_bool (force),
      41              :     GNUNET_PQ_query_param_end
      42              :   };
      43            6 :   struct GNUNET_PQ_QueryParam params2[] = {
      44            6 :     GNUNET_PQ_query_param_string (instance_id),
      45            6 :     GNUNET_PQ_query_param_string (order_id),
      46              :     GNUNET_PQ_query_param_end
      47              :   };
      48              :   enum GNUNET_DB_QueryStatus qs;
      49              :   enum GNUNET_DB_QueryStatus qs2;
      50              : 
      51            6 :   check_connection (pg);
      52            6 :   PREPARE (pg,
      53              :            "delete_order",
      54              :            "WITH ms AS"
      55              :            "(SELECT merchant_serial "
      56              :            "   FROM merchant_instances"
      57              :            "  WHERE merchant_id=$1)"
      58              :            ", mc AS"
      59              :            "(SELECT paid"
      60              :            "   FROM merchant_contract_terms"
      61              :            "   JOIN ms USING (merchant_serial)"
      62              :            "  WHERE order_id=$2) "
      63              :            "DELETE"
      64              :            " FROM merchant_orders mo"
      65              :            " WHERE order_id=$2"
      66              :            "   AND merchant_serial=(SELECT merchant_serial FROM ms)"
      67              :            "   AND (  (pay_deadline < $3)"
      68              :            "       OR (NOT EXISTS (SELECT paid FROM mc))"
      69              :            "       OR ($4 AND (FALSE=(SELECT paid FROM mc))) );");
      70            6 :   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      71              :                                            "delete_order",
      72              :                                            params);
      73            6 :   if ( (qs < 0) || (! force) )
      74            6 :     return qs;
      75            0 :   PREPARE (pg,
      76              :            "delete_contract",
      77              :            "DELETE"
      78              :            " FROM merchant_contract_terms"
      79              :            " WHERE order_id=$2 AND"
      80              :            "   merchant_serial="
      81              :            "     (SELECT merchant_serial "
      82              :            "        FROM merchant_instances"
      83              :            "        WHERE merchant_id=$1)"
      84              :            "   AND NOT paid;");
      85            0 :   qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      86              :                                             "delete_contract",
      87              :                                             params2);
      88            0 :   if (qs2 < 0)
      89            0 :     return qs2;
      90            0 :   if (qs2 > 0)
      91            0 :     return qs2;
      92            0 :   return qs;
      93              : }
        

Generated by: LCOV version 2.0-1