aboutsummaryrefslogtreecommitdiff
path: root/src/include/taler_db_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/taler_db_lib.h')
-rw-r--r--src/include/taler_db_lib.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/include/taler_db_lib.h b/src/include/taler_db_lib.h
new file mode 100644
index 000000000..41b46264e
--- /dev/null
+++ b/src/include/taler_db_lib.h
@@ -0,0 +1,132 @@
1/*
2 This file is part of TALER
3 (C) 2014 Christian Grothoff (and other contributing authors)
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, If not, see <http://www.gnu.org/licenses/>
15*/
16
17
18/**
19 * @file include/taler_db_lib.h
20 * @brief helper functions for DB interactions
21 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
22 * @author Florian Dold
23 */
24
25#ifndef TALER_DB_LIB_H_
26#define TALER_DB_LIB_H_
27
28#include <libpq-fe.h>
29#include "taler_util.h"
30
31#define TALER_DB_QUERY_PARAM_END { NULL, 0, 0 }
32#define TALER_DB_QUERY_PARAM_PTR(x) { (x), sizeof (*(x)), 1 }
33#define TALER_DB_QUERY_PARAM_PTR_SIZED(x, s) { (x), (s), 1 }
34
35
36#define TALER_DB_RESULT_SPEC_END { NULL, 0, NULL }
37#define TALER_DB_RESULT_SPEC(name, dst) { (void *) (dst), sizeof (*(dst)), (name) }
38#define TALER_DB_RESULT_SPEC_SIZED(name, dst, s) { (void *) (dst), (s), (name) }
39
40
41/**
42 * Description of a DB query parameter.
43 */
44struct TALER_DB_QueryParam
45{
46 /**
47 * Data or NULL
48 */
49 const void *data;
50 /**
51 * Size of 'data'
52 */
53 size_t size;
54 /**
55 * Non-null if this is not the last parameter.
56 * This allows for null as sentinal value.
57 */
58 int more;
59};
60
61
62/**
63 * Description of a DB result cell.
64 */
65struct TALER_DB_ResultSpec
66{
67 /**
68 * Destination for the data.
69 */
70 void *dst;
71
72 /**
73 * Allowed size for the data.
74 */
75 size_t dst_size;
76
77 /**
78 * Field name of the desired result.
79 */
80 char *fname;
81};
82
83
84/**
85 * Execute a prepared statement.
86 */
87PGresult *
88TALER_DB_exec_prepared (PGconn *db_conn,
89 const char *name,
90 const struct TALER_DB_QueryParam *params);
91
92
93/**
94 * Extract results from a query result according to the given specification.
95 * If colums are NULL, the destination is not modified, and GNUNET_NO
96 * is returned.
97 *
98 * @return
99 * GNUNET_YES if all results could be extracted
100 * GNUNET_NO if at least one result was NULL
101 * GNUNET_SYSERR if a result was invalid (non-existing field)
102 */
103int
104TALER_DB_extract_result (PGresult *result, struct TALER_DB_ResultSpec *rs, int row);
105
106
107int
108TALER_DB_field_isnull (PGresult *result,
109 int row,
110 const char *fname);
111
112
113int
114TALER_DB_extract_amount_nbo (PGresult *result,
115 int row,
116 const char *val_name,
117 const char *frac_name,
118 const char *curr_name,
119 struct TALER_AmountNBO *r_amount_nbo);
120
121
122int
123TALER_DB_extract_amount (PGresult *result,
124 int row,
125 const char *val_name,
126 const char *frac_name,
127 const char *curr_name,
128 struct TALER_Amount *r_amount);
129
130#endif /* TALER_DB_LIB_H_ */
131
132/* end of include/taler_db_lib.h */