diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:02:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:02:30 +0000 |
commit | 0664750ce887ed3b6be4ab8006165ffdbe16e50e (patch) | |
tree | 32c75a919c15cd2daf1f0fbf44d0d496569a3655 /src/datacache/plugin_datacache_sqlite.c | |
parent | 52da6d84a2eba2eee2803734c3cb81ff6b82bd3e (diff) | |
download | gnunet-0664750ce887ed3b6be4ab8006165ffdbe16e50e.tar.gz gnunet-0664750ce887ed3b6be4ab8006165ffdbe16e50e.zip |
-doxygen
Diffstat (limited to 'src/datacache/plugin_datacache_sqlite.c')
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 1e313c686..3d21df5a9 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c | |||
@@ -101,7 +101,9 @@ sq_prepare (sqlite3 *dbh, | |||
101 | { /* OUT: Statement handle */ | 101 | { /* OUT: Statement handle */ |
102 | char *dummy; | 102 | char *dummy; |
103 | 103 | ||
104 | return sqlite3_prepare (dbh, zSql, strlen (zSql), ppStmt, | 104 | return sqlite3_prepare (dbh, |
105 | zSql, strlen (zSql), | ||
106 | ppStmt, | ||
105 | (const char **) &dummy); | 107 | (const char **) &dummy); |
106 | } | 108 | } |
107 | 109 | ||
@@ -110,7 +112,7 @@ sq_prepare (sqlite3 *dbh, | |||
110 | * Store an item in the datastore. | 112 | * Store an item in the datastore. |
111 | * | 113 | * |
112 | * @param cls closure (our `struct Plugin`) | 114 | * @param cls closure (our `struct Plugin`) |
113 | * @param key key to store data under | 115 | * @param key key to store @a data under |
114 | * @param size number of bytes in @a data | 116 | * @param size number of bytes in @a data |
115 | * @param data data to store | 117 | * @param data data to store |
116 | * @param type type of the value | 118 | * @param type type of the value |
@@ -261,7 +263,7 @@ sqlite_plugin_get (void *cls, | |||
261 | } | 263 | } |
262 | total = sqlite3_column_int (stmt, 0); | 264 | total = sqlite3_column_int (stmt, 0); |
263 | sqlite3_finalize (stmt); | 265 | sqlite3_finalize (stmt); |
264 | if ((total == 0) || (iter == NULL)) | 266 | if ((0 == total) || (NULL == iter)) |
265 | { | 267 | { |
266 | if (0 == total) | 268 | if (0 == total) |
267 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 269 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -323,7 +325,14 @@ sqlite_plugin_get (void *cls, | |||
323 | "Found %u-byte result when processing GET for key `%4s'\n", | 325 | "Found %u-byte result when processing GET for key `%4s'\n", |
324 | (unsigned int) size, | 326 | (unsigned int) size, |
325 | GNUNET_h2s (key)); | 327 | GNUNET_h2s (key)); |
326 | if (GNUNET_OK != iter (iter_cls, key, size, dat, type, exp, psize, path)) | 328 | if (GNUNET_OK != iter (iter_cls, |
329 | key, | ||
330 | size, | ||
331 | dat, | ||
332 | type, | ||
333 | exp, | ||
334 | psize, | ||
335 | path)) | ||
327 | { | 336 | { |
328 | sqlite3_finalize (stmt); | 337 | sqlite3_finalize (stmt); |
329 | break; | 338 | break; |
@@ -351,15 +360,17 @@ sqlite_plugin_del (void *cls) | |||
351 | sqlite3_stmt *dstmt; | 360 | sqlite3_stmt *dstmt; |
352 | struct GNUNET_HashCode hc; | 361 | struct GNUNET_HashCode hc; |
353 | 362 | ||
354 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s'\n", "DEL"); | 363 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
364 | "Processing DEL\n"); | ||
355 | stmt = NULL; | 365 | stmt = NULL; |
356 | dstmt = NULL; | 366 | dstmt = NULL; |
357 | if (sq_prepare | 367 | if (SQLITE_OK != |
358 | (plugin->dbh, | 368 | sq_prepare (plugin->dbh, |
359 | "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", | 369 | "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", |
360 | &stmt) != SQLITE_OK) | 370 | &stmt)) |
361 | { | 371 | { |
362 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 372 | LOG_SQLITE (plugin->dbh, |
373 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
363 | "sq_prepare"); | 374 | "sq_prepare"); |
364 | if (stmt != NULL) | 375 | if (stmt != NULL) |
365 | (void) sqlite3_finalize (stmt); | 376 | (void) sqlite3_finalize (stmt); |
@@ -367,7 +378,8 @@ sqlite_plugin_del (void *cls) | |||
367 | } | 378 | } |
368 | if (SQLITE_ROW != sqlite3_step (stmt)) | 379 | if (SQLITE_ROW != sqlite3_step (stmt)) |
369 | { | 380 | { |
370 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 381 | LOG_SQLITE (plugin->dbh, |
382 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
371 | "sqlite3_step"); | 383 | "sqlite3_step"); |
372 | (void) sqlite3_finalize (stmt); | 384 | (void) sqlite3_finalize (stmt); |
373 | return GNUNET_SYSERR; | 385 | return GNUNET_SYSERR; |
@@ -377,12 +389,15 @@ sqlite_plugin_del (void *cls) | |||
377 | memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (struct GNUNET_HashCode)); | 389 | memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (struct GNUNET_HashCode)); |
378 | dsize = sqlite3_column_bytes (stmt, 2); | 390 | dsize = sqlite3_column_bytes (stmt, 2); |
379 | if (SQLITE_OK != sqlite3_finalize (stmt)) | 391 | if (SQLITE_OK != sqlite3_finalize (stmt)) |
380 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 392 | LOG_SQLITE (plugin->dbh, |
393 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
381 | "sqlite3_step"); | 394 | "sqlite3_step"); |
382 | if (sq_prepare (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt) != | 395 | if (SQLITE_OK != |
383 | SQLITE_OK) | 396 | sq_prepare (plugin->dbh, |
397 | "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt)) | ||
384 | { | 398 | { |
385 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 399 | LOG_SQLITE (plugin->dbh, |
400 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
386 | "sq_prepare"); | 401 | "sq_prepare"); |
387 | if (stmt != NULL) | 402 | if (stmt != NULL) |
388 | (void) sqlite3_finalize (stmt); | 403 | (void) sqlite3_finalize (stmt); |
@@ -390,22 +405,27 @@ sqlite_plugin_del (void *cls) | |||
390 | } | 405 | } |
391 | if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid)) | 406 | if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid)) |
392 | { | 407 | { |
393 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 408 | LOG_SQLITE (plugin->dbh, |
409 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
394 | "sqlite3_bind"); | 410 | "sqlite3_bind"); |
395 | (void) sqlite3_finalize (dstmt); | 411 | (void) sqlite3_finalize (dstmt); |
396 | return GNUNET_SYSERR; | 412 | return GNUNET_SYSERR; |
397 | } | 413 | } |
398 | if (sqlite3_step (dstmt) != SQLITE_DONE) | 414 | if (SQLITE_DONE != sqlite3_step (dstmt)) |
399 | { | 415 | { |
400 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 416 | LOG_SQLITE (plugin->dbh, |
417 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
401 | "sqlite3_step"); | 418 | "sqlite3_step"); |
402 | (void) sqlite3_finalize (dstmt); | 419 | (void) sqlite3_finalize (dstmt); |
403 | return GNUNET_SYSERR; | 420 | return GNUNET_SYSERR; |
404 | } | 421 | } |
405 | plugin->num_items--; | 422 | plugin->num_items--; |
406 | plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); | 423 | plugin->env->delete_notify (plugin->env->cls, |
424 | &hc, | ||
425 | dsize + OVERHEAD); | ||
407 | if (SQLITE_OK != sqlite3_finalize (dstmt)) | 426 | if (SQLITE_OK != sqlite3_finalize (dstmt)) |
408 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 427 | LOG_SQLITE (plugin->dbh, |
428 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
409 | "sqlite3_finalize"); | 429 | "sqlite3_finalize"); |
410 | return GNUNET_OK; | 430 | return GNUNET_OK; |
411 | } | 431 | } |
@@ -439,6 +459,8 @@ sqlite_plugin_get_random (void *cls, | |||
439 | 459 | ||
440 | if (0 == plugin->num_items) | 460 | if (0 == plugin->num_items) |
441 | return 0; | 461 | return 0; |
462 | if (NULL == iter) | ||
463 | return 1; | ||
442 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 464 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
443 | plugin->num_items); | 465 | plugin->num_items); |
444 | GNUNET_snprintf (scratch, | 466 | GNUNET_snprintf (scratch, |