aboutsummaryrefslogtreecommitdiff
path: root/src/sq/sq_query_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sq/sq_query_helper.c')
-rw-r--r--src/sq/sq_query_helper.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c
index 5529c5e6c..94a3a3f1c 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -90,6 +90,14 @@ bind_string (void *cls,
90 sqlite3_stmt *stmt, 90 sqlite3_stmt *stmt,
91 unsigned int off) 91 unsigned int off)
92{ 92{
93 if (NULL == data)
94 {
95 if (SQLITE_OK !=
96 sqlite3_bind_null (stmt,
97 (int) off))
98 return GNUNET_SYSERR;
99 return GNUNET_OK;
100 }
93 if (SQLITE_OK != 101 if (SQLITE_OK !=
94 sqlite3_bind_text (stmt, 102 sqlite3_bind_text (stmt,
95 (int) off, 103 (int) off,
@@ -235,6 +243,40 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
235 243
236 244
237/** 245/**
246 * Function called to convert input argument into SQL parameters.
247 *
248 * @param cls closure
249 * @param data pointer to input argument
250 * @param data_len number of bytes in @a data (if applicable)
251 * @param stmt sqlite statement to bind parameters for
252 * @param off offset of the argument to bind in @a stmt, numbered from 1,
253 * so immediately suitable for passing to `sqlite3_bind`-functions.
254 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
255 */
256static int
257bind_abstime (void *cls,
258 const void *data,
259 size_t data_len,
260 sqlite3_stmt *stmt,
261 unsigned int off)
262{
263 const struct GNUNET_TIME_Absolute *u = data;
264 struct GNUNET_TIME_Absolute abs;
265
266 abs = *u;
267 if (abs.abs_value_us > INT64_MAX)
268 abs.abs_value_us = INT64_MAX;
269 GNUNET_assert (sizeof (uint64_t) == data_len);
270 if (SQLITE_OK !=
271 sqlite3_bind_int64 (stmt,
272 (int) off,
273 (sqlite3_int64) abs.abs_value_us))
274 return GNUNET_SYSERR;
275 return GNUNET_OK;
276}
277
278
279/**
238 * Generate query parameter for an absolute time value. 280 * Generate query parameter for an absolute time value.
239 * The database must store a 64-bit integer. 281 * The database must store a 64-bit integer.
240 * 282 *
@@ -243,7 +285,13 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
243struct GNUNET_SQ_QueryParam 285struct GNUNET_SQ_QueryParam
244GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 286GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
245{ 287{
246 return GNUNET_SQ_query_param_uint64 (&x->abs_value_us); 288 struct GNUNET_SQ_QueryParam qp = {
289 .conv = &bind_abstime,
290 .data = x,
291 .size = sizeof (struct GNUNET_TIME_Absolute),
292 .num_params = 1
293 };
294 return qp;
247} 295}
248 296
249 297
@@ -269,6 +317,8 @@ bind_nbotime (void *cls,
269 struct GNUNET_TIME_Absolute abs; 317 struct GNUNET_TIME_Absolute abs;
270 318
271 abs = GNUNET_TIME_absolute_ntoh (*u); 319 abs = GNUNET_TIME_absolute_ntoh (*u);
320 if (abs.abs_value_us > INT64_MAX)
321 abs.abs_value_us = INT64_MAX;
272 GNUNET_assert (sizeof (uint64_t) == data_len); 322 GNUNET_assert (sizeof (uint64_t) == data_len);
273 if (SQLITE_OK != 323 if (SQLITE_OK !=
274 sqlite3_bind_int64 (stmt, 324 sqlite3_bind_int64 (stmt,