aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-27 02:08:21 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-27 02:08:21 +0100
commit8b3286e953a80cf069271957ec817485ebe5b14e (patch)
treef8d013d64ad9bb0531e087234894f040f0819f70
parent34cbc615577b80ad57c706c0001123f3d5cb752d (diff)
downloadgnunet-8b3286e953a80cf069271957ec817485ebe5b14e.tar.gz
gnunet-8b3286e953a80cf069271957ec817485ebe5b14e.zip
implement sq_query_helper.c
-rw-r--r--po/POTFILES.in11
-rw-r--r--src/include/gnunet_pq_lib.h14
-rw-r--r--src/include/gnunet_sq_lib.h23
-rw-r--r--src/sq/Makefile.am2
-rw-r--r--src/sq/sq.c43
-rw-r--r--src/sq/sq_query_helper.c314
-rw-r--r--src/sq/sq_result_helper.c38
7 files changed, 402 insertions, 43 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2594104df..6c156336b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -65,6 +65,7 @@ src/cadet/gnunet-service-cadet_tunnel.c
65src/consensus/consensus_api.c 65src/consensus/consensus_api.c
66src/consensus/gnunet-consensus-profiler.c 66src/consensus/gnunet-consensus-profiler.c
67src/consensus/gnunet-service-consensus.c 67src/consensus/gnunet-service-consensus.c
68src/consensus/plugin_block_consensus.c
68src/conversation/conversation_api.c 69src/conversation/conversation_api.c
69src/conversation/conversation_api_call.c 70src/conversation/conversation_api_call.c
70src/conversation/gnunet-conversation.c 71src/conversation/gnunet-conversation.c
@@ -114,13 +115,6 @@ src/dht/gnunet-service-dht_hello.c
114src/dht/gnunet-service-dht_neighbours.c 115src/dht/gnunet-service-dht_neighbours.c
115src/dht/gnunet-service-dht_nse.c 116src/dht/gnunet-service-dht_nse.c
116src/dht/gnunet-service-dht_routing.c 117src/dht/gnunet-service-dht_routing.c
117src/dht/gnunet-service-wdht.c
118src/dht/gnunet-service-wdht_clients.c
119src/dht/gnunet-service-wdht_neighbours.c
120src/dht/gnunet-service-xdht.c
121src/dht/gnunet-service-xdht_hello.c
122src/dht/gnunet-service-xdht_neighbours.c
123src/dht/gnunet-service-xdht_routing.c
124src/dht/plugin_block_dht.c 118src/dht/plugin_block_dht.c
125src/dns/dns_api.c 119src/dns/dns_api.c
126src/dns/dnsparser.c 120src/dns/dnsparser.c
@@ -349,6 +343,9 @@ src/set/set_api.c
349src/social/gnunet-service-social.c 343src/social/gnunet-service-social.c
350src/social/gnunet-social.c 344src/social/gnunet-social.c
351src/social/social_api.c 345src/social/social_api.c
346src/sq/sq.c
347src/sq/sq_query_helper.c
348src/sq/sq_result_helper.c
352src/statistics/gnunet-service-statistics.c 349src/statistics/gnunet-service-statistics.c
353src/statistics/gnunet-statistics.c 350src/statistics/gnunet-statistics.c
354src/statistics/statistics_api.c 351src/statistics/statistics_api.c
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index e8180f286..756370b74 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -317,20 +317,6 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
317 317
318 318
319/** 319/**
320 * Variable-size result expected.
321 *
322 * @param name name of the field in the table
323 * @param[out] dst where to store the result, allocated
324 * @param[out] sptr where to store the size of @a dst
325 * @return array entry for the result specification to use
326 */
327struct GNUNET_PQ_ResultSpec
328GNUNET_PQ_result_spec_variable_size (const char *name,
329 void **dst,
330 size_t *sptr);
331
332
333/**
334 * 0-terminated string expected. 320 * 0-terminated string expected.
335 * 321 *
336 * @param name name of the field in the table 322 * @param name name of the field in the table
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index a068650ac..1606d1129 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -21,7 +21,7 @@
21#ifndef GNUNET_SQ_LIB_H 21#ifndef GNUNET_SQ_LIB_H
22#define GNUNET_SQ_LIB_H 22#define GNUNET_SQ_LIB_H
23 23
24#include <sqlite/sqlite3.h> 24#include <sqlite3.h>
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26 26
27 27
@@ -186,7 +186,8 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x);
186 * 186 *
187 * @param cls closure 187 * @param cls closure
188 * @param result where to extract data from 188 * @param result where to extract data from
189 * @param int row to extract data from 189 * @param row row to extract data from
190 * @param column column to extract data from
190 * @param[in,out] dst_size where to store size of result, may be NULL 191 * @param[in,out] dst_size where to store size of result, may be NULL
191 * @param[out] dst where to store the result 192 * @param[out] dst where to store the result
192 * @return 193 * @return
@@ -197,20 +198,25 @@ typedef int
197(*GNUNET_SQ_ResultConverter)(void *cls, 198(*GNUNET_SQ_ResultConverter)(void *cls,
198 sqlite3_stmt *result, 199 sqlite3_stmt *result,
199 int row, 200 int row,
201 unsigned int column,
200 size_t *dst_size, 202 size_t *dst_size,
201 void *dst); 203 void *dst);
202 204
203 205
204/** 206/**
207 * @brief Description of a DB result cell.
208 */
209struct GNUNET_SQ_ResultSpec;
210
211
212/**
205 * Function called to clean up memory allocated 213 * Function called to clean up memory allocated
206 * by a #GNUNET_SQ_ResultConverter. 214 * by a #GNUNET_SQ_ResultConverter.
207 * 215 *
208 * @param cls closure 216 * @param cls closure
209 * @param rd result data to clean up
210 */ 217 */
211typedef void 218typedef void
212(*GNUNET_SQ_ResultCleanup)(void *cls, 219(*GNUNET_SQ_ResultCleanup)(void *cls);
213 void *rd);
214 220
215 221
216/** 222/**
@@ -252,6 +258,11 @@ struct GNUNET_SQ_ResultSpec
252 */ 258 */
253 size_t *result_size; 259 size_t *result_size;
254 260
261 /**
262 * Number of parameters (columns) eaten by this operation.
263 */
264 unsigned int num_params;
265
255}; 266};
256 267
257 268
@@ -407,7 +418,7 @@ GNUNET_SQ_bind (sqlite3_stmt *stmt,
407 * @param[in,out] rs result specification to extract for 418 * @param[in,out] rs result specification to extract for
408 * @param row row from the result to extract 419 * @param row row from the result to extract
409 * @return 420 * @return
410 * #GNUNET_YES if all results could be extracted 421 * #GNUNET_OK if all results could be extracted
411 * #GNUNET_SYSERR if a result was invalid (non-existing field) 422 * #GNUNET_SYSERR if a result was invalid (non-existing field)
412 */ 423 */
413int 424int
diff --git a/src/sq/Makefile.am b/src/sq/Makefile.am
index 7197e7ab4..c5f80bcf6 100644
--- a/src/sq/Makefile.am
+++ b/src/sq/Makefile.am
@@ -17,7 +17,7 @@ libgnunetsq_la_SOURCES = \
17 sq.c \ 17 sq.c \
18 sq_query_helper.c \ 18 sq_query_helper.c \
19 sq_result_helper.c 19 sq_result_helper.c
20libgnunetsq_la_LIBADD = -lsq \ 20libgnunetsq_la_LIBADD = -lsqlite3 \
21 $(top_builddir)/src/util/libgnunetutil.la 21 $(top_builddir)/src/util/libgnunetutil.la
22libgnunetsq_la_LDFLAGS = \ 22libgnunetsq_la_LDFLAGS = \
23 $(POSTGRESQL_LDFLAGS) \ 23 $(POSTGRESQL_LDFLAGS) \
diff --git a/src/sq/sq.c b/src/sq/sq.c
index 524014b0f..74ab7beb5 100644
--- a/src/sq/sq.c
+++ b/src/sq/sq.c
@@ -33,6 +33,28 @@ int
33GNUNET_SQ_bind (sqlite3_stmt *stmt, 33GNUNET_SQ_bind (sqlite3_stmt *stmt,
34 const struct GNUNET_SQ_QueryParam *params) 34 const struct GNUNET_SQ_QueryParam *params)
35{ 35{
36 unsigned int j;
37
38 j = 1;
39 for (unsigned int i=0;NULL != params[i].conv; i++)
40 {
41 if (GNUNET_OK !=
42 params[i].conv (params[i].conv_cls,
43 params[i].data,
44 params[i].size,
45 stmt,
46 j))
47 {
48 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
49 "sq",
50 _("Failure to bind %u-th SQL parameter\n"),
51 i);
52 return GNUNET_SYSERR;
53 }
54 GNUNET_assert (0 != params[i].num_params);
55 j += params[i].num_params;
56 }
57 return GNUNET_OK;
36} 58}
37 59
38 60
@@ -43,7 +65,7 @@ GNUNET_SQ_bind (sqlite3_stmt *stmt,
43 * @param[in,out] rs result specification to extract for 65 * @param[in,out] rs result specification to extract for
44 * @param row row from the result to extract 66 * @param row row from the result to extract
45 * @return 67 * @return
46 * #GNUNET_YES if all results could be extracted 68 * #GNUNET_OK if all results could be extracted
47 * #GNUNET_SYSERR if a result was invalid (non-existing field) 69 * #GNUNET_SYSERR if a result was invalid (non-existing field)
48 */ 70 */
49int 71int
@@ -51,6 +73,22 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result,
51 struct GNUNET_SQ_ResultSpec *rs, 73 struct GNUNET_SQ_ResultSpec *rs,
52 int row) 74 int row)
53{ 75{
76 unsigned int j = 0;
77
78 for (unsigned int i=0;NULL != rs[i].conv; i++)
79 {
80 if (GNUNET_OK !=
81 rs[i].conv (rs[i].cls,
82 result,
83 row,
84 j,
85 rs[i].result_size,
86 rs[i].dst))
87 return GNUNET_SYSERR;
88 GNUNET_assert (0 != rs[i].num_params);
89 j += rs[i].num_params;
90 }
91 return GNUNET_OK;
54} 92}
55 93
56 94
@@ -63,6 +101,9 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result,
63void 101void
64GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) 102GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs)
65{ 103{
104 for (unsigned int i=0;NULL != rs[i].conv; i++)
105 if (NULL != rs[i].cleaner)
106 rs[i].cleaner (rs[i].cls);
66} 107}
67 108
68/* end of sq.c */ 109/* end of sq.c */
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c
index 613a0c746..5529c5e6c 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -18,10 +18,40 @@
18 * @brief helper functions for queries 18 * @brief helper functions for queries
19 * @author Christian Grothoff 19 * @author Christian Grothoff
20 */ 20 */
21#include "platform.h"
21#include "gnunet_sq_lib.h" 22#include "gnunet_sq_lib.h"
22 23
23 24
24/** 25/**
26 * Function called to convert input argument into SQL parameters.
27 *
28 * @param cls closure
29 * @param data pointer to input argument
30 * @param data_len number of bytes in @a data (if applicable)
31 * @param stmt sqlite statement to bind parameters for
32 * @param off offset of the argument to bind in @a stmt, numbered from 1,
33 * so immediately suitable for passing to `sqlite3_bind`-functions.
34 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
35 */
36static int
37bind_fixed_blob (void *cls,
38 const void *data,
39 size_t data_len,
40 sqlite3_stmt *stmt,
41 unsigned int off)
42{
43 if (SQLITE_OK !=
44 sqlite3_bind_blob64 (stmt,
45 (int) off,
46 data,
47 (sqlite3_uint64) data_len,
48 SQLITE_TRANSIENT))
49 return GNUNET_SYSERR;
50 return GNUNET_OK;
51}
52
53
54/**
25 * Generate query parameter for a buffer @a ptr of 55 * Generate query parameter for a buffer @a ptr of
26 * @a ptr_size bytes. 56 * @a ptr_size bytes.
27 * 57 *
@@ -32,6 +62,42 @@ struct GNUNET_SQ_QueryParam
32GNUNET_SQ_query_param_fixed_size (const void *ptr, 62GNUNET_SQ_query_param_fixed_size (const void *ptr,
33 size_t ptr_size) 63 size_t ptr_size)
34{ 64{
65 struct GNUNET_SQ_QueryParam qp = {
66 .conv = &bind_fixed_blob,
67 .data = ptr,
68 .size = ptr_size,
69 .num_params = 1
70 };
71 return qp;
72}
73
74
75/**
76 * Function called to convert input argument into SQL parameters.
77 *
78 * @param cls closure
79 * @param data pointer to input argument
80 * @param data_len number of bytes in @a data (if applicable)
81 * @param stmt sqlite statement to bind parameters for
82 * @param off offset of the argument to bind in @a stmt, numbered from 1,
83 * so immediately suitable for passing to `sqlite3_bind`-functions.
84 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
85 */
86static int
87bind_string (void *cls,
88 const void *data,
89 size_t data_len,
90 sqlite3_stmt *stmt,
91 unsigned int off)
92{
93 if (SQLITE_OK !=
94 sqlite3_bind_text (stmt,
95 (int) off,
96 (const char *) data,
97 -1,
98 SQLITE_TRANSIENT))
99 return GNUNET_SYSERR;
100 return GNUNET_OK;
35} 101}
36 102
37 103
@@ -43,6 +109,52 @@ GNUNET_SQ_query_param_fixed_size (const void *ptr,
43struct GNUNET_SQ_QueryParam 109struct GNUNET_SQ_QueryParam
44GNUNET_SQ_query_param_string (const char *ptr) 110GNUNET_SQ_query_param_string (const char *ptr)
45{ 111{
112 struct GNUNET_SQ_QueryParam qp = {
113 .conv = &bind_string,
114 .data = ptr,
115 .num_params = 1
116 };
117 return qp;
118}
119
120
121/**
122 * Function called to convert input argument into SQL parameters.
123 *
124 * @param cls closure
125 * @param data pointer to input argument
126 * @param data_len number of bytes in @a data (if applicable)
127 * @param stmt sqlite statement to bind parameters for
128 * @param off offset of the argument to bind in @a stmt, numbered from 1,
129 * so immediately suitable for passing to `sqlite3_bind`-functions.
130 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
131 */
132static int
133bind_rsa_pub (void *cls,
134 const void *data,
135 size_t data_len,
136 sqlite3_stmt *stmt,
137 unsigned int off)
138{
139 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
140 char *buf;
141 size_t buf_size;
142
143 GNUNET_break (NULL == cls);
144 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
145 &buf);
146 if (SQLITE_OK !=
147 sqlite3_bind_blob64 (stmt,
148 (int) off,
149 buf,
150 (sqlite3_uint64) buf_size,
151 SQLITE_TRANSIENT))
152 {
153 GNUNET_free (buf);
154 return GNUNET_SYSERR;
155 }
156 GNUNET_free (buf);
157 return GNUNET_OK;
46} 158}
47 159
48 160
@@ -55,6 +167,52 @@ GNUNET_SQ_query_param_string (const char *ptr)
55struct GNUNET_SQ_QueryParam 167struct GNUNET_SQ_QueryParam
56GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 168GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
57{ 169{
170 struct GNUNET_SQ_QueryParam qp = {
171 .conv = &bind_rsa_pub,
172 .data = x,
173 .num_params = 1
174 };
175 return qp;
176}
177
178
179/**
180 * Function called to convert input argument into SQL parameters.
181 *
182 * @param cls closure
183 * @param data pointer to input argument
184 * @param data_len number of bytes in @a data (if applicable)
185 * @param stmt sqlite statement to bind parameters for
186 * @param off offset of the argument to bind in @a stmt, numbered from 1,
187 * so immediately suitable for passing to `sqlite3_bind`-functions.
188 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
189 */
190static int
191bind_rsa_sig (void *cls,
192 const void *data,
193 size_t data_len,
194 sqlite3_stmt *stmt,
195 unsigned int off)
196{
197 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
198 char *buf;
199 size_t buf_size;
200
201 GNUNET_break (NULL == cls);
202 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
203 &buf);
204 if (SQLITE_OK !=
205 sqlite3_bind_blob64 (stmt,
206 (int) off,
207 buf,
208 (sqlite3_uint64) buf_size,
209 SQLITE_TRANSIENT))
210 {
211 GNUNET_free (buf);
212 return GNUNET_SYSERR;
213 }
214 GNUNET_free (buf);
215 return GNUNET_OK;
58} 216}
59 217
60 218
@@ -67,6 +225,12 @@ GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
67struct GNUNET_SQ_QueryParam 225struct GNUNET_SQ_QueryParam
68GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 226GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
69{ 227{
228 struct GNUNET_SQ_QueryParam qp = {
229 .conv = &bind_rsa_sig,
230 .data = x,
231 .num_params = 1
232 };
233 return qp;
70} 234}
71 235
72 236
@@ -79,6 +243,39 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
79struct GNUNET_SQ_QueryParam 243struct GNUNET_SQ_QueryParam
80GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 244GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
81{ 245{
246 return GNUNET_SQ_query_param_uint64 (&x->abs_value_us);
247}
248
249
250/**
251 * Function called to convert input argument into SQL parameters.
252 *
253 * @param cls closure
254 * @param data pointer to input argument
255 * @param data_len number of bytes in @a data (if applicable)
256 * @param stmt sqlite statement to bind parameters for
257 * @param off offset of the argument to bind in @a stmt, numbered from 1,
258 * so immediately suitable for passing to `sqlite3_bind`-functions.
259 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
260 */
261static int
262bind_nbotime (void *cls,
263 const void *data,
264 size_t data_len,
265 sqlite3_stmt *stmt,
266 unsigned int off)
267{
268 const struct GNUNET_TIME_AbsoluteNBO *u = data;
269 struct GNUNET_TIME_Absolute abs;
270
271 abs = GNUNET_TIME_absolute_ntoh (*u);
272 GNUNET_assert (sizeof (uint64_t) == data_len);
273 if (SQLITE_OK !=
274 sqlite3_bind_int64 (stmt,
275 (int) off,
276 (sqlite3_int64) abs.abs_value_us))
277 return GNUNET_SYSERR;
278 return GNUNET_OK;
82} 279}
83 280
84 281
@@ -91,6 +288,43 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
91struct GNUNET_SQ_QueryParam 288struct GNUNET_SQ_QueryParam
92GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) 289GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x)
93{ 290{
291 struct GNUNET_SQ_QueryParam qp = {
292 .conv = &bind_nbotime,
293 .data = x,
294 .size = sizeof (struct GNUNET_TIME_AbsoluteNBO),
295 .num_params = 1
296 };
297 return qp;
298}
299
300
301/**
302 * Function called to convert input argument into SQL parameters.
303 *
304 * @param cls closure
305 * @param data pointer to input argument
306 * @param data_len number of bytes in @a data (if applicable)
307 * @param stmt sqlite statement to bind parameters for
308 * @param off offset of the argument to bind in @a stmt, numbered from 1,
309 * so immediately suitable for passing to `sqlite3_bind`-functions.
310 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
311 */
312static int
313bind_u16 (void *cls,
314 const void *data,
315 size_t data_len,
316 sqlite3_stmt *stmt,
317 unsigned int off)
318{
319 const uint16_t *u = data;
320
321 GNUNET_assert (sizeof (uint16_t) == data_len);
322 if (SQLITE_OK !=
323 sqlite3_bind_int (stmt,
324 (int) off,
325 (int) *u))
326 return GNUNET_SYSERR;
327 return GNUNET_OK;
94} 328}
95 329
96 330
@@ -102,10 +336,46 @@ GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x
102struct GNUNET_SQ_QueryParam 336struct GNUNET_SQ_QueryParam
103GNUNET_SQ_query_param_uint16 (const uint16_t *x) 337GNUNET_SQ_query_param_uint16 (const uint16_t *x)
104{ 338{
339 struct GNUNET_SQ_QueryParam qp = {
340 .conv = &bind_u16,
341 .data = x,
342 .size = sizeof (uint16_t),
343 .num_params = 1
344 };
345 return qp;
105} 346}
106 347
107 348
108/** 349/**
350 * Function called to convert input argument into SQL parameters.
351 *
352 * @param cls closure
353 * @param data pointer to input argument
354 * @param data_len number of bytes in @a data (if applicable)
355 * @param stmt sqlite statement to bind parameters for
356 * @param off offset of the argument to bind in @a stmt, numbered from 1,
357 * so immediately suitable for passing to `sqlite3_bind`-functions.
358 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
359 */
360static int
361bind_u32 (void *cls,
362 const void *data,
363 size_t data_len,
364 sqlite3_stmt *stmt,
365 unsigned int off)
366{
367 const uint32_t *u = data;
368
369 GNUNET_assert (sizeof (uint32_t) == data_len);
370 if (SQLITE_OK !=
371 sqlite3_bind_int64 (stmt,
372 (int) off,
373 (sqlite3_int64) *u))
374 return GNUNET_SYSERR;
375 return GNUNET_OK;
376}
377
378/**
109 * Generate query parameter for an uint32_t in host byte order. 379 * Generate query parameter for an uint32_t in host byte order.
110 * 380 *
111 * @param x pointer to the query parameter to pass 381 * @param x pointer to the query parameter to pass
@@ -113,6 +383,43 @@ GNUNET_SQ_query_param_uint16 (const uint16_t *x)
113struct GNUNET_SQ_QueryParam 383struct GNUNET_SQ_QueryParam
114GNUNET_SQ_query_param_uint32 (const uint32_t *x) 384GNUNET_SQ_query_param_uint32 (const uint32_t *x)
115{ 385{
386 struct GNUNET_SQ_QueryParam qp = {
387 .conv = &bind_u32,
388 .data = x,
389 .size = sizeof (uint32_t),
390 .num_params = 1
391 };
392 return qp;
393}
394
395
396/**
397 * Function called to convert input argument into SQL parameters.
398 *
399 * @param cls closure
400 * @param data pointer to input argument
401 * @param data_len number of bytes in @a data (if applicable)
402 * @param stmt sqlite statement to bind parameters for
403 * @param off offset of the argument to bind in @a stmt, numbered from 1,
404 * so immediately suitable for passing to `sqlite3_bind`-functions.
405 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
406 */
407static int
408bind_u64 (void *cls,
409 const void *data,
410 size_t data_len,
411 sqlite3_stmt *stmt,
412 unsigned int off)
413{
414 const uint64_t *u = data;
415
416 GNUNET_assert (sizeof (uint64_t) == data_len);
417 if (SQLITE_OK !=
418 sqlite3_bind_int64 (stmt,
419 (int) off,
420 (sqlite3_int64) *u))
421 return GNUNET_SYSERR;
422 return GNUNET_OK;
116} 423}
117 424
118 425
@@ -124,6 +431,13 @@ GNUNET_SQ_query_param_uint32 (const uint32_t *x)
124struct GNUNET_SQ_QueryParam 431struct GNUNET_SQ_QueryParam
125GNUNET_SQ_query_param_uint64 (const uint64_t *x) 432GNUNET_SQ_query_param_uint64 (const uint64_t *x)
126{ 433{
434 struct GNUNET_SQ_QueryParam qp = {
435 .conv = &bind_u64,
436 .data = x,
437 .size = sizeof (uint64_t),
438 .num_params = 1
439 };
440 return qp;
127} 441}
128 442
129/* end of sq_query_helper.c */ 443/* end of sq_query_helper.c */
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c
index 361fea7bf..36ce53317 100644
--- a/src/sq/sq_result_helper.c
+++ b/src/sq/sq_result_helper.c
@@ -24,6 +24,30 @@
24 24
25 25
26/** 26/**
27 * Extract fixed-sized binary data from a Postgres database @a result at row @a row.
28 *
29 * @param cls closure
30 * @param result where to extract data from
31 * @param row row to extract data from
32 * @param column column to extract data from
33 * @param[in,out] dst_size where to store size of result, may be NULL
34 * @param[out] dst where to store the result
35 * @return
36 * #GNUNET_YES if all results could be extracted
37 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
38 */
39static int
40extract_fixed_blob (void *cls,
41 sqlite3_stmt *result,
42 int row,
43 unsigned int column,
44 size_t *dst_size,
45 void *dst)
46{
47}
48
49
50/**
27 * Variable-size result expected. 51 * Variable-size result expected.
28 * 52 *
29 * @param[out] dst where to store the result, allocated 53 * @param[out] dst where to store the result, allocated
@@ -52,20 +76,6 @@ GNUNET_SQ_result_spec_fixed_size (void *dst,
52 76
53 77
54/** 78/**
55 * Variable-size result expected.
56 *
57 * @param[out] dst where to store the result, allocated
58 * @param[out] sptr where to store the size of @a dst
59 * @return array entry for the result specification to use
60 */
61struct GNUNET_SQ_ResultSpec
62GNUNET_SQ_result_spec_variable_size (void **dst,
63 size_t *sptr)
64{
65}
66
67
68/**
69 * 0-terminated string expected. 79 * 0-terminated string expected.
70 * 80 *
71 * @param[out] dst where to store the result, allocated 81 * @param[out] dst where to store the result, allocated