diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/datacache/plugin_datacache_sqlite.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/datacache/plugin_datacache_sqlite.c')
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 85 |
1 files changed, 35 insertions, 50 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 44799be63..f852d3b06 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c | |||
@@ -123,9 +123,8 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, | |||
123 | "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)", | 123 | "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)", |
124 | &stmt) != SQLITE_OK) | 124 | &stmt) != SQLITE_OK) |
125 | { | 125 | { |
126 | LOG_SQLITE (plugin->dbh, | 126 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
127 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 127 | "sq_prepare"); |
128 | "sq_prepare"); | ||
129 | return 0; | 128 | return 0; |
130 | } | 129 | } |
131 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || | 130 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || |
@@ -192,9 +191,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, | |||
192 | "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", | 191 | "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", |
193 | &stmt) != SQLITE_OK) | 192 | &stmt) != SQLITE_OK) |
194 | { | 193 | { |
195 | LOG_SQLITE (plugin->dbh, | 194 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
196 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 195 | "sq_prepare"); |
197 | "sq_prepare"); | ||
198 | return 0; | 196 | return 0; |
199 | } | 197 | } |
200 | ntime = (int64_t) now.abs_value; | 198 | ntime = (int64_t) now.abs_value; |
@@ -218,8 +216,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, | |||
218 | sqlite3_finalize (stmt); | 216 | sqlite3_finalize (stmt); |
219 | #if DEBUG_DATACACHE_SQLITE | 217 | #if DEBUG_DATACACHE_SQLITE |
220 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 218 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
221 | "No content found when processing `%s' for key `%4s'\n", | 219 | "No content found when processing `%s' for key `%4s'\n", "GET", |
222 | "GET", GNUNET_h2s (key)); | 220 | GNUNET_h2s (key)); |
223 | #endif | 221 | #endif |
224 | return 0; | 222 | return 0; |
225 | } | 223 | } |
@@ -230,8 +228,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, | |||
230 | #if DEBUG_DATACACHE_SQLITE | 228 | #if DEBUG_DATACACHE_SQLITE |
231 | if (0 == total) | 229 | if (0 == total) |
232 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 230 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
233 | "No content found when processing `%s' for key `%4s'\n", | 231 | "No content found when processing `%s' for key `%4s'\n", "GET", |
234 | "GET", GNUNET_h2s (key)); | 232 | GNUNET_h2s (key)); |
235 | #endif | 233 | #endif |
236 | return total; | 234 | return total; |
237 | } | 235 | } |
@@ -246,9 +244,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, | |||
246 | off); | 244 | off); |
247 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) | 245 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) |
248 | { | 246 | { |
249 | LOG_SQLITE (plugin->dbh, | 247 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
250 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 248 | "sq_prepare"); |
251 | "sq_prepare"); | ||
252 | return cnt; | 249 | return cnt; |
253 | } | 250 | } |
254 | if ((SQLITE_OK != | 251 | if ((SQLITE_OK != |
@@ -273,10 +270,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, | |||
273 | cnt++; | 270 | cnt++; |
274 | #if DEBUG_DATACACHE_SQLITE | 271 | #if DEBUG_DATACACHE_SQLITE |
275 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 272 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
276 | "Found %u-byte result when processing `%s' for key `%4s'\n", | 273 | "Found %u-byte result when processing `%s' for key `%4s'\n", |
277 | (unsigned int) size, | 274 | (unsigned int) size, "GET", GNUNET_h2s (key)); |
278 | "GET", | ||
279 | GNUNET_h2s (key)); | ||
280 | #endif | 275 | #endif |
281 | if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type)) | 276 | if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type)) |
282 | { | 277 | { |
@@ -316,18 +311,16 @@ sqlite_plugin_del (void *cls) | |||
316 | "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", | 311 | "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", |
317 | &stmt) != SQLITE_OK) | 312 | &stmt) != SQLITE_OK) |
318 | { | 313 | { |
319 | LOG_SQLITE (plugin->dbh, | 314 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
320 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 315 | "sq_prepare"); |
321 | "sq_prepare"); | ||
322 | if (stmt != NULL) | 316 | if (stmt != NULL) |
323 | (void) sqlite3_finalize (stmt); | 317 | (void) sqlite3_finalize (stmt); |
324 | return GNUNET_SYSERR; | 318 | return GNUNET_SYSERR; |
325 | } | 319 | } |
326 | if (SQLITE_ROW != sqlite3_step (stmt)) | 320 | if (SQLITE_ROW != sqlite3_step (stmt)) |
327 | { | 321 | { |
328 | LOG_SQLITE (plugin->dbh, | 322 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
329 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 323 | "sqlite3_step"); |
330 | "sqlite3_step"); | ||
331 | (void) sqlite3_finalize (stmt); | 324 | (void) sqlite3_finalize (stmt); |
332 | return GNUNET_SYSERR; | 325 | return GNUNET_SYSERR; |
333 | } | 326 | } |
@@ -336,42 +329,35 @@ sqlite_plugin_del (void *cls) | |||
336 | memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); | 329 | memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); |
337 | dsize = sqlite3_column_bytes (stmt, 2); | 330 | dsize = sqlite3_column_bytes (stmt, 2); |
338 | if (SQLITE_OK != sqlite3_finalize (stmt)) | 331 | if (SQLITE_OK != sqlite3_finalize (stmt)) |
339 | LOG_SQLITE (plugin->dbh, | 332 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
340 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 333 | "sqlite3_step"); |
341 | "sqlite3_step"); | 334 | if (sq_prepare (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt) != |
342 | if (sq_prepare | 335 | SQLITE_OK) |
343 | (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", | ||
344 | &dstmt) != SQLITE_OK) | ||
345 | { | 336 | { |
346 | LOG_SQLITE (plugin->dbh, | 337 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
347 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 338 | "sq_prepare"); |
348 | "sq_prepare"); | ||
349 | if (stmt != NULL) | 339 | if (stmt != NULL) |
350 | (void) sqlite3_finalize (stmt); | 340 | (void) sqlite3_finalize (stmt); |
351 | return GNUNET_SYSERR; | 341 | return GNUNET_SYSERR; |
352 | } | 342 | } |
353 | if (SQLITE_OK != | 343 | if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid)) |
354 | sqlite3_bind_int64 (dstmt, 1, rowid)) | ||
355 | { | 344 | { |
356 | LOG_SQLITE (plugin->dbh, | 345 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
357 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 346 | "sqlite3_bind"); |
358 | "sqlite3_bind"); | ||
359 | (void) sqlite3_finalize (dstmt); | 347 | (void) sqlite3_finalize (dstmt); |
360 | return GNUNET_SYSERR; | 348 | return GNUNET_SYSERR; |
361 | } | 349 | } |
362 | if (sqlite3_step (dstmt) != SQLITE_DONE) | 350 | if (sqlite3_step (dstmt) != SQLITE_DONE) |
363 | { | 351 | { |
364 | LOG_SQLITE (plugin->dbh, | 352 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
365 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 353 | "sqlite3_step"); |
366 | "sqlite3_step"); | ||
367 | (void) sqlite3_finalize (dstmt); | 354 | (void) sqlite3_finalize (dstmt); |
368 | return GNUNET_SYSERR; | 355 | return GNUNET_SYSERR; |
369 | } | 356 | } |
370 | plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); | 357 | plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); |
371 | if (SQLITE_OK != sqlite3_finalize (dstmt)) | 358 | if (SQLITE_OK != sqlite3_finalize (dstmt)) |
372 | LOG_SQLITE (plugin->dbh, | 359 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
373 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 360 | "sqlite3_finalize"); |
374 | "sqlite3_finalize"); | ||
375 | return GNUNET_OK; | 361 | return GNUNET_OK; |
376 | } | 362 | } |
377 | 363 | ||
@@ -435,8 +421,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) | |||
435 | api->get = &sqlite_plugin_get; | 421 | api->get = &sqlite_plugin_get; |
436 | api->put = &sqlite_plugin_put; | 422 | api->put = &sqlite_plugin_put; |
437 | api->del = &sqlite_plugin_del; | 423 | api->del = &sqlite_plugin_del; |
438 | LOG (GNUNET_ERROR_TYPE_INFO, | 424 | LOG (GNUNET_ERROR_TYPE_INFO, _("Sqlite datacache running\n")); |
439 | _("Sqlite datacache running\n")); | ||
440 | return api; | 425 | return api; |
441 | } | 426 | } |
442 | 427 | ||
@@ -468,19 +453,19 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) | |||
468 | if (result == SQLITE_BUSY) | 453 | if (result == SQLITE_BUSY) |
469 | { | 454 | { |
470 | LOG (GNUNET_ERROR_TYPE_WARNING, | 455 | LOG (GNUNET_ERROR_TYPE_WARNING, |
471 | _("Tried to close sqlite without finalizing all prepared statements.\n")); | 456 | _ |
457 | ("Tried to close sqlite without finalizing all prepared statements.\n")); | ||
472 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 458 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
473 | while (stmt != NULL) | 459 | while (stmt != NULL) |
474 | { | 460 | { |
475 | #if DEBUG_SQLITE | 461 | #if DEBUG_SQLITE |
476 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 462 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing statement %p\n", stmt); |
477 | "Closing statement %p\n", stmt); | ||
478 | #endif | 463 | #endif |
479 | result = sqlite3_finalize (stmt); | 464 | result = sqlite3_finalize (stmt); |
480 | #if DEBUG_SQLITE | 465 | #if DEBUG_SQLITE |
481 | if (result != SQLITE_OK) | 466 | if (result != SQLITE_OK) |
482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 467 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to close statement %p: %d\n", |
483 | "Failed to close statement %p: %d\n", stmt, result); | 468 | stmt, result); |
484 | #endif | 469 | #endif |
485 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 470 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
486 | } | 471 | } |