select_report.c (3871B)
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_pq_lib.h> 23 #include "merchant-database/select_report.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_MERCHANTDB_select_report ( 29 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_uint64 (&report_id), 45 GNUNET_PQ_query_param_end 46 }; 47 uint32_t code; 48 struct GNUNET_PQ_ResultSpec rs[] = { 49 GNUNET_PQ_result_spec_string ("report_program_section", 50 report_program_section), 51 GNUNET_PQ_result_spec_string ("report_description", 52 report_description), 53 GNUNET_PQ_result_spec_string ("mime_type", 54 mime_type), 55 GNUNET_PQ_result_spec_string ("data_source", 56 data_source), 57 GNUNET_PQ_result_spec_string ("target_address", 58 target_address), 59 GNUNET_PQ_result_spec_relative_time ("frequency", 60 frequency), 61 GNUNET_PQ_result_spec_relative_time ("frequency_shift", 62 frequency_shift), 63 GNUNET_PQ_result_spec_absolute_time ("next_transmission", 64 next_transmission), 65 GNUNET_PQ_result_spec_allow_null ( 66 GNUNET_PQ_result_spec_uint32 ("last_error_code", 67 &code), 68 NULL), 69 GNUNET_PQ_result_spec_allow_null ( 70 GNUNET_PQ_result_spec_string ("last_error_detail", 71 last_error_detail), 72 NULL), 73 GNUNET_PQ_result_spec_end 74 }; 75 enum GNUNET_DB_QueryStatus qs; 76 77 GNUNET_assert (NULL != pg->current_merchant_id); 78 GNUNET_assert (0 == strcmp (instance_id, 79 pg->current_merchant_id)); 80 *last_error_detail = NULL; 81 code = TALER_EC_NONE; 82 check_connection (pg); 83 TMH_PQ_prepare_anon (pg, 84 "SELECT" 85 " report_program_section" 86 " ,report_description" 87 " ,mime_type" 88 " ,data_source" 89 " ,target_address" 90 " ,frequency" 91 " ,frequency_shift" 92 " ,next_transmission" 93 " ,last_error_code" 94 " ,last_error_detail" 95 " FROM merchant_reports" 96 " WHERE report_serial=$1;"); 97 qs = GNUNET_PQ_eval_prepared_singleton_select ( 98 pg->conn, 99 "", 100 params, 101 rs); 102 *last_error_code = (enum TALER_ErrorCode) code; 103 return qs; 104 }