From e333599ab88c1ec1c8de83afc32a8c55911de0d2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Dec 2010 20:06:27 +0000 Subject: [PATCH] fix --- src/datacache/plugin_datacache_sqlite.c | 34 ++++++++++++++++++++++++- src/datastore/plugin_datastore_sqlite.c | 16 +++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index e3f0dcb24..1e293a4ba 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -423,6 +423,8 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) { struct GNUNET_DATACACHE_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; + int result; + sqlite3_stmt *stmt; #if !WINDOWS || defined(__CYGWIN__) if (0 != UNLINK (plugin->fn)) @@ -431,7 +433,37 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) plugin->fn); GNUNET_free (plugin->fn); #endif - sqlite3_close (plugin->dbh); + result = sqlite3_close (plugin->dbh); +#if SQLITE_VERSION_NUMBER >= 3007000 + if (result == SQLITE_BUSY) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, + "sqlite", + _("Tried to close sqlite without finalizing all prepared statements.\n")); + stmt = sqlite3_next_stmt(plugin->dbh, NULL); + while (stmt != NULL) + { +#if DEBUG_SQLITE + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", "Closing statement %p\n", stmt); +#endif + result = sqlite3_finalize(stmt); +#if DEBUG_SQLITE + if (result != SQLITE_OK) + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Failed to close statement %p: %d\n", stmt, result); +#endif + stmt = sqlite3_next_stmt(plugin->dbh, NULL); + } + result = sqlite3_close(plugin->dbh); + } +#endif + if (SQLITE_OK != result) + LOG_SQLITE (plugin->dbh, + GNUNET_ERROR_TYPE_ERROR, + "sqlite3_close"); + #if WINDOWS && !defined(__CYGWIN__) if (0 != UNLINK (plugin->fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 1b8382537..1f7348a98 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -359,6 +359,8 @@ static void database_shutdown (struct Plugin *plugin) { int result; + sqlite3_stmt *stmt; + if (plugin->delRow != NULL) sqlite3_finalize (plugin->delRow); if (plugin->updPrio != NULL) @@ -366,13 +368,14 @@ database_shutdown (struct Plugin *plugin) if (plugin->insertContent != NULL) sqlite3_finalize (plugin->insertContent); result = sqlite3_close(plugin->dbh); - while (result == SQLITE_BUSY) +#if SQLITE_VERSION_NUMBER >= 3007000 + if (result == SQLITE_BUSY) { - sqlite3_stmt *stmt; GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", _("Tried to close sqlite without finalizing all prepared statements.\n")); - for (stmt = sqlite3_next_stmt(plugin->dbh, NULL); stmt != NULL; stmt = sqlite3_next_stmt(plugin->dbh, NULL)) + stmt = sqlite3_next_stmt(plugin->dbh, NULL); + while (stmt != NULL) { #if DEBUG_SQLITE GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, @@ -385,9 +388,16 @@ database_shutdown (struct Plugin *plugin) "sqlite", "Failed to close statement %p: %d\n", stmt, result); #endif + stmt = sqlite3_next_stmt(plugin->dbh, NULL); } result = sqlite3_close(plugin->dbh); } +#endif + if (SQLITE_OK != result) + LOG_SQLITE (plugin, NULL, + GNUNET_ERROR_TYPE_ERROR, + "sqlite3_close"); + GNUNET_free_non_null (plugin->fn); } -- 2.25.1