aboutsummaryrefslogtreecommitdiff
path: root/src/sq/sq_query_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-12 02:51:36 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-12 02:51:36 +0100
commita707b513688690a3dad9dc39535900da73a79f28 (patch)
tree0439c267fc54960441ae09f0ca5c62e0c41f2cb7 /src/sq/sq_query_helper.c
parent538d7fde8cb1c0d079f01f2290aa3e3e2744beff (diff)
downloadgnunet-a707b513688690a3dad9dc39535900da73a79f28.tar.gz
gnunet-a707b513688690a3dad9dc39535900da73a79f28.zip
converting datacache to sqlite, fixing misc. issues in libgnunetsq
Diffstat (limited to 'src/sq/sq_query_helper.c')
-rw-r--r--src/sq/sq_query_helper.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c
index 5529c5e6c..a04b4ced4 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -235,6 +235,40 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
235 235
236 236
237/** 237/**
238 * Function called to convert input argument into SQL parameters.
239 *
240 * @param cls closure
241 * @param data pointer to input argument
242 * @param data_len number of bytes in @a data (if applicable)
243 * @param stmt sqlite statement to bind parameters for
244 * @param off offset of the argument to bind in @a stmt, numbered from 1,
245 * so immediately suitable for passing to `sqlite3_bind`-functions.
246 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
247 */
248static int
249bind_abstime (void *cls,
250 const void *data,
251 size_t data_len,
252 sqlite3_stmt *stmt,
253 unsigned int off)
254{
255 const struct GNUNET_TIME_Absolute *u = data;
256 struct GNUNET_TIME_Absolute abs;
257
258 abs = *u;
259 if (abs.abs_value_us > INT64_MAX)
260 abs.abs_value_us = INT64_MAX;
261 GNUNET_assert (sizeof (uint64_t) == data_len);
262 if (SQLITE_OK !=
263 sqlite3_bind_int64 (stmt,
264 (int) off,
265 (sqlite3_int64) abs.abs_value_us))
266 return GNUNET_SYSERR;
267 return GNUNET_OK;
268}
269
270
271/**
238 * Generate query parameter for an absolute time value. 272 * Generate query parameter for an absolute time value.
239 * The database must store a 64-bit integer. 273 * The database must store a 64-bit integer.
240 * 274 *
@@ -243,7 +277,13 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
243struct GNUNET_SQ_QueryParam 277struct GNUNET_SQ_QueryParam
244GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 278GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
245{ 279{
246 return GNUNET_SQ_query_param_uint64 (&x->abs_value_us); 280 struct GNUNET_SQ_QueryParam qp = {
281 .conv = &bind_abstime,
282 .data = x,
283 .size = sizeof (struct GNUNET_TIME_Absolute),
284 .num_params = 1
285 };
286 return qp;
247} 287}
248 288
249 289
@@ -269,6 +309,8 @@ bind_nbotime (void *cls,
269 struct GNUNET_TIME_Absolute abs; 309 struct GNUNET_TIME_Absolute abs;
270 310
271 abs = GNUNET_TIME_absolute_ntoh (*u); 311 abs = GNUNET_TIME_absolute_ntoh (*u);
312 if (abs.abs_value_us > INT64_MAX)
313 abs.abs_value_us = INT64_MAX;
272 GNUNET_assert (sizeof (uint64_t) == data_len); 314 GNUNET_assert (sizeof (uint64_t) == data_len);
273 if (SQLITE_OK != 315 if (SQLITE_OK !=
274 sqlite3_bind_int64 (stmt, 316 sqlite3_bind_int64 (stmt,