diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-12-21 20:43:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-12-21 20:43:14 +0000 |
commit | b84021702a5ad8b8930764c42e6721d6cf0168b2 (patch) | |
tree | eb8759463518e4d4e1ef7b6b904e4c058747b6a0 /src/datacache | |
parent | 4cf31a506ae49f14f86fb9b6ab01e42c732ab980 (diff) | |
download | gnunet-b84021702a5ad8b8930764c42e6721d6cf0168b2.tar.gz gnunet-b84021702a5ad8b8930764c42e6721d6cf0168b2.zip |
fix
Diffstat (limited to 'src/datacache')
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index b8fdca397..cb6e48f91 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c | |||
@@ -283,6 +283,8 @@ sqlite_plugin_del (void *cls) | |||
283 | unsigned int dtype; | 283 | unsigned int dtype; |
284 | sqlite3_stmt *stmt; | 284 | sqlite3_stmt *stmt; |
285 | sqlite3_stmt *dstmt; | 285 | sqlite3_stmt *dstmt; |
286 | char blob[65536]; | ||
287 | GNUNET_HashCode hc; | ||
286 | 288 | ||
287 | #if DEBUG_DATACACHE_SQLITE | 289 | #if DEBUG_DATACACHE_SQLITE |
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -291,21 +293,15 @@ sqlite_plugin_del (void *cls) | |||
291 | #endif | 293 | #endif |
292 | stmt = NULL; | 294 | stmt = NULL; |
293 | dstmt = NULL; | 295 | dstmt = NULL; |
294 | if ((sq_prepare (plugin->dbh, | 296 | if (sq_prepare (plugin->dbh, |
295 | "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", | 297 | "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", |
296 | &stmt) != SQLITE_OK) || | 298 | &stmt) != SQLITE_OK) |
297 | (sq_prepare (plugin->dbh, | ||
298 | "DELETE FROM ds090 " | ||
299 | "WHERE key=? AND value=? AND type=?", | ||
300 | &dstmt) != SQLITE_OK)) | ||
301 | { | 299 | { |
302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
303 | _("`%s' failed at %s:%d with error: %s\n"), | 301 | _("`%s' failed at %s:%d with error: %s\n"), |
304 | "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); | 302 | "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); |
305 | if (dstmt != NULL) | ||
306 | sqlite3_finalize (dstmt); | ||
307 | if (stmt != NULL) | 303 | if (stmt != NULL) |
308 | sqlite3_finalize (stmt); | 304 | (void) sqlite3_finalize (stmt); |
309 | return GNUNET_SYSERR; | 305 | return GNUNET_SYSERR; |
310 | } | 306 | } |
311 | if (SQLITE_ROW != sqlite3_step (stmt)) | 307 | if (SQLITE_ROW != sqlite3_step (stmt)) |
@@ -314,37 +310,69 @@ sqlite_plugin_del (void *cls) | |||
314 | _("`%s' failed at %s:%d with error: %s\n"), | 310 | _("`%s' failed at %s:%d with error: %s\n"), |
315 | "sqlite3_step", __FILE__, __LINE__, | 311 | "sqlite3_step", __FILE__, __LINE__, |
316 | sqlite3_errmsg (plugin->dbh)); | 312 | sqlite3_errmsg (plugin->dbh)); |
317 | sqlite3_finalize (dstmt); | 313 | (void) sqlite3_finalize (stmt); |
318 | sqlite3_finalize (stmt); | ||
319 | return GNUNET_SYSERR; | 314 | return GNUNET_SYSERR; |
320 | } | 315 | } |
321 | dtype = sqlite3_column_int (stmt, 0); | 316 | dtype = sqlite3_column_int (stmt, 0); |
322 | GNUNET_break (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode)); | 317 | GNUNET_break (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode)); |
323 | dsize = sqlite3_column_bytes (stmt, 2); | 318 | dsize = sqlite3_column_bytes (stmt, 2); |
324 | sqlite3_bind_blob (dstmt, | 319 | GNUNET_assert (dsize <= sizeof (blob)); |
325 | 1, sqlite3_column_blob (stmt, 1), | 320 | memcpy (blob, sqlite3_column_blob (stmt, 2), dsize); |
326 | sizeof (GNUNET_HashCode), | 321 | memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); |
327 | SQLITE_TRANSIENT); | 322 | if (SQLITE_OK != sqlite3_finalize (stmt)) |
328 | sqlite3_bind_blob (dstmt, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
329 | 2, sqlite3_column_blob (stmt, 2), | 324 | _("`%s' failed at %s:%d with error: %s\n"), |
330 | dsize, | 325 | "sqlite3_step", __FILE__, __LINE__, |
331 | SQLITE_TRANSIENT); | 326 | sqlite3_errmsg (plugin->dbh)); |
332 | sqlite3_bind_int (dstmt, 3, dtype); | 327 | if (sq_prepare (plugin->dbh, |
328 | "DELETE FROM ds090 " | ||
329 | "WHERE key=? AND value=? AND type=?", | ||
330 | &dstmt) != SQLITE_OK) | ||
331 | { | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
333 | _("`%s' failed at %s:%d with error: %s\n"), | ||
334 | "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); | ||
335 | if (stmt != NULL) | ||
336 | (void) sqlite3_finalize (stmt); | ||
337 | return GNUNET_SYSERR; | ||
338 | } | ||
339 | if ( (SQLITE_OK != | ||
340 | sqlite3_bind_blob (dstmt, | ||
341 | 1, &hc, | ||
342 | sizeof (GNUNET_HashCode), | ||
343 | SQLITE_TRANSIENT)) || | ||
344 | (SQLITE_OK != | ||
345 | sqlite3_bind_blob (dstmt, | ||
346 | 2, blob, | ||
347 | dsize, | ||
348 | SQLITE_TRANSIENT)) || | ||
349 | (SQLITE_OK != | ||
350 | sqlite3_bind_int (dstmt, 3, dtype)) ) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
353 | _("`%s' failed at %s:%d with error: %s\n"), | ||
354 | "sqlite3_bind", __FILE__, __LINE__, | ||
355 | sqlite3_errmsg (plugin->dbh)); | ||
356 | (void) sqlite3_finalize (dstmt); | ||
357 | return GNUNET_SYSERR; | ||
358 | } | ||
333 | if (sqlite3_step (dstmt) != SQLITE_DONE) | 359 | if (sqlite3_step (dstmt) != SQLITE_DONE) |
334 | { | 360 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
336 | _("`%s' failed at %s:%d with error: %s\n"), | 362 | _("`%s' failed at %s:%d with error: %s\n"), |
337 | "sqlite3_step", __FILE__, __LINE__, | 363 | "sqlite3_step", __FILE__, __LINE__, |
338 | sqlite3_errmsg (plugin->dbh)); | 364 | sqlite3_errmsg (plugin->dbh)); |
339 | sqlite3_finalize (dstmt); | 365 | (void) sqlite3_finalize (dstmt); |
340 | sqlite3_finalize (stmt); | ||
341 | return GNUNET_SYSERR; | 366 | return GNUNET_SYSERR; |
342 | } | 367 | } |
343 | plugin->env->delete_notify (plugin->env->cls, | 368 | plugin->env->delete_notify (plugin->env->cls, |
344 | sqlite3_column_blob (stmt, 1), | 369 | &hc, |
345 | dsize + OVERHEAD); | 370 | dsize + OVERHEAD); |
346 | sqlite3_finalize (dstmt); | 371 | if (SQLITE_OK != sqlite3_finalize (dstmt)) |
347 | sqlite3_finalize (stmt); | 372 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
373 | _("`%s' failed at %s:%d with error: %s\n"), | ||
374 | "sqlite3_finalize", __FILE__, __LINE__, | ||
375 | sqlite3_errmsg (plugin->dbh)); | ||
348 | return GNUNET_OK; | 376 | return GNUNET_OK; |
349 | } | 377 | } |
350 | 378 | ||