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_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 "pg_select_report.h"
26 : #include "pg_helper.h"
27 :
28 : enum GNUNET_DB_QueryStatus
29 0 : TMH_PG_select_report (void *cls,
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 0 : struct PostgresClosure *pg = cls;
44 0 : struct GNUNET_PQ_QueryParam params[] = {
45 0 : GNUNET_PQ_query_param_string (instance_id),
46 0 : GNUNET_PQ_query_param_uint64 (&report_id),
47 : GNUNET_PQ_query_param_end
48 : };
49 : uint32_t code;
50 0 : struct GNUNET_PQ_ResultSpec rs[] = {
51 0 : GNUNET_PQ_result_spec_string ("report_program_section",
52 : report_program_section),
53 0 : GNUNET_PQ_result_spec_string ("report_description",
54 : report_description),
55 0 : GNUNET_PQ_result_spec_string ("mime_type",
56 : mime_type),
57 0 : GNUNET_PQ_result_spec_string ("data_source",
58 : data_source),
59 0 : GNUNET_PQ_result_spec_string ("target_address",
60 : target_address),
61 0 : GNUNET_PQ_result_spec_relative_time ("frequency",
62 : frequency),
63 0 : GNUNET_PQ_result_spec_relative_time ("frequency_shift",
64 : frequency_shift),
65 0 : GNUNET_PQ_result_spec_absolute_time ("next_transmission",
66 : next_transmission),
67 0 : GNUNET_PQ_result_spec_allow_null (
68 : GNUNET_PQ_result_spec_uint32 ("last_error_code",
69 : &code),
70 : NULL),
71 0 : GNUNET_PQ_result_spec_allow_null (
72 : GNUNET_PQ_result_spec_string ("last_error_detail",
73 : last_error_detail),
74 : NULL),
75 : GNUNET_PQ_result_spec_end
76 : };
77 : enum GNUNET_DB_QueryStatus qs;
78 :
79 0 : *last_error_detail = NULL;
80 0 : code = TALER_EC_NONE;
81 0 : check_connection (pg);
82 0 : PREPARE (pg,
83 : "select_report",
84 : "SELECT"
85 : " mr.report_program_section"
86 : " ,mr.report_description"
87 : " ,mr.mime_type"
88 : " ,mr.data_source"
89 : " ,mr.target_address"
90 : " ,mr.frequency"
91 : " ,mr.frequency_shift"
92 : " ,mr.next_transmission"
93 : " ,mr.last_error_code"
94 : " ,mr.last_error_details"
95 : " FROM merchant_reports mr"
96 : " JOIN merchant_instances mi"
97 : " USING (merchant_serial)"
98 : " WHERE merchant_id=$1"
99 : " AND report_serial=$2;");
100 0 : qs = GNUNET_PQ_eval_prepared_singleton_select (
101 : pg->conn,
102 : "select_report",
103 : params,
104 : rs);
105 0 : *last_error_code = (enum TALER_ErrorCode) code;
106 0 : return qs;
107 : }
|