select_report.c (4217B)
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 src/backenddb/select_report.c 18 * @brief Implementation of the select_report 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 "merchant-database/select_report.h" 26 #include "helper.h" 27 28 enum GNUNET_DB_QueryStatus 29 TALER_MERCHANTDB_select_report (struct TALER_MERCHANTDB_PostgresContext *pg, 30 const char *instance_id, 31 uint64_t report_id, 32 char **report_program_section, 33 char **report_description, 34 char **mime_type, 35 char **data_source, 36 char **target_address, 37 struct GNUNET_TIME_Relative *frequency, 38 struct GNUNET_TIME_Relative *frequency_shift, 39 struct GNUNET_TIME_Absolute *next_transmission, 40 enum TALER_ErrorCode *last_error_code, 41 char **last_error_detail) 42 { 43 struct GNUNET_PQ_QueryParam params[] = { 44 GNUNET_PQ_query_param_string (instance_id), 45 GNUNET_PQ_query_param_uint64 (&report_id), 46 GNUNET_PQ_query_param_end 47 }; 48 uint32_t code; 49 struct GNUNET_PQ_ResultSpec rs[] = { 50 GNUNET_PQ_result_spec_string ("report_program_section", 51 report_program_section), 52 GNUNET_PQ_result_spec_string ("report_description", 53 report_description), 54 GNUNET_PQ_result_spec_string ("mime_type", 55 mime_type), 56 GNUNET_PQ_result_spec_string ("data_source", 57 data_source), 58 GNUNET_PQ_result_spec_string ("target_address", 59 target_address), 60 GNUNET_PQ_result_spec_relative_time ("frequency", 61 frequency), 62 GNUNET_PQ_result_spec_relative_time ("frequency_shift", 63 frequency_shift), 64 GNUNET_PQ_result_spec_absolute_time ("next_transmission", 65 next_transmission), 66 GNUNET_PQ_result_spec_allow_null ( 67 GNUNET_PQ_result_spec_uint32 ("last_error_code", 68 &code), 69 NULL), 70 GNUNET_PQ_result_spec_allow_null ( 71 GNUNET_PQ_result_spec_string ("last_error_detail", 72 last_error_detail), 73 NULL), 74 GNUNET_PQ_result_spec_end 75 }; 76 enum GNUNET_DB_QueryStatus qs; 77 78 *last_error_detail = NULL; 79 code = TALER_EC_NONE; 80 check_connection (pg); 81 PREPARE (pg, 82 "select_report", 83 "SELECT" 84 " mr.report_program_section" 85 " ,mr.report_description" 86 " ,mr.mime_type" 87 " ,mr.data_source" 88 " ,mr.target_address" 89 " ,mr.frequency" 90 " ,mr.frequency_shift" 91 " ,mr.next_transmission" 92 " ,mr.last_error_code" 93 " ,mr.last_error_detail" 94 " FROM merchant_reports mr" 95 " JOIN merchant_instances mi" 96 " USING (merchant_serial)" 97 " WHERE merchant_id=$1" 98 " AND report_serial=$2;"); 99 qs = GNUNET_PQ_eval_prepared_singleton_select ( 100 pg->conn, 101 "select_report", 102 params, 103 rs); 104 *last_error_code = (enum TALER_ErrorCode) code; 105 return qs; 106 }