2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file datacache/plugin_datacache_sqlite.c
23 * @brief sqlite for an implementation of a database backend for the datacache
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_datacache_plugin.h"
29 #include "gnunet_sq_lib.h"
32 #define LOG(kind,...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__)
34 #define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn)
38 * How much overhead do we assume per entry in the
41 #define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36)
44 * Context for all functions in this plugin.
49 * Our execution environment.
51 struct GNUNET_DATACACHE_PluginEnvironment *env;
54 * Handle to the sqlite database.
59 * Filename used for the DB.
64 * Prepared statement for #sqlite_plugin_put.
66 sqlite3_stmt *insert_stmt;
69 * Prepared statement for #sqlite_plugin_get.
71 sqlite3_stmt *get_count_stmt;
74 * Prepared statement for #sqlite_plugin_get.
76 sqlite3_stmt *get_stmt;
79 * Prepared statement for #sqlite_plugin_del.
81 sqlite3_stmt *del_select_stmt;
84 * Prepared statement for #sqlite_plugin_del.
86 sqlite3_stmt *del_expired_stmt;
89 * Prepared statement for #sqlite_plugin_del.
91 sqlite3_stmt *del_stmt;
94 * Prepared statement for #sqlite_plugin_get_random.
96 sqlite3_stmt *get_random_stmt;
99 * Prepared statement for #sqlite_plugin_get_closest.
101 sqlite3_stmt *get_closest_stmt;
104 * Number of key-value pairs in the database.
106 unsigned int num_items;
111 * Log an error message at log-level @a level that indicates
112 * a failure of the command @a cmd with the error from the database @a db
114 * @param db database handle
115 * @param level log level
116 * @param cmd failed command
118 #define LOG_SQLITE(db, level, cmd) do { LOG (level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); } while(0)
122 * Execute SQL statement.
124 * @param db database handle
125 * @param cmd SQL command to execute
127 #define SQLITE3_EXEC(db, cmd) do { emsg = NULL; if (SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &emsg)) { LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_exec", __FILE__, __LINE__, emsg); sqlite3_free(emsg); } } while(0)
131 * @brief Prepare a SQL statement
133 * @param dbh database handle
134 * @param zsql SQL statement text
135 * @param[out] ppStmt set to the prepared statement
136 * @return 0 on success
139 sq_prepare (sqlite3 *dbh,
140 const char *zSql, /* SQL statement, UTF-8 encoded */
141 sqlite3_stmt **ppStmt)
142 { /* OUT: Statement handle */
145 return sqlite3_prepare (dbh,
149 (const char **) &dummy);
154 * Store an item in the datastore.
156 * @param cls closure (our `struct Plugin`)
157 * @param key key to store @a data under
158 * @param xor_distance how close is @a key to our PID?
159 * @param size number of bytes in @a data
160 * @param data data to store
161 * @param type type of the value
162 * @param discard_time when to discard the value in any case
163 * @param path_info_len number of entries in @a path_info
164 * @param path_info array of peers that have processed the request
165 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
168 sqlite_plugin_put (void *cls,
169 const struct GNUNET_HashCode *key,
170 uint32_t xor_distance,
173 enum GNUNET_BLOCK_Type type,
174 struct GNUNET_TIME_Absolute discard_time,
175 unsigned int path_info_len,
176 const struct GNUNET_PeerIdentity *path_info)
178 struct Plugin *plugin = cls;
179 uint32_t type32 = type;
180 struct GNUNET_SQ_QueryParam params[] = {
181 GNUNET_SQ_query_param_uint32 (&type32),
182 GNUNET_SQ_query_param_absolute_time (&discard_time),
183 GNUNET_SQ_query_param_auto_from_type (key),
184 GNUNET_SQ_query_param_uint32 (&xor_distance),
185 GNUNET_SQ_query_param_fixed_size (data, size),
186 GNUNET_SQ_query_param_fixed_size (path_info,
187 path_info_len * sizeof (struct GNUNET_PeerIdentity)),
188 GNUNET_SQ_query_param_end
191 LOG (GNUNET_ERROR_TYPE_DEBUG,
192 "Processing PUT of %u bytes with key `%s' and expiration %s\n",
195 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (discard_time),
198 GNUNET_SQ_bind (plugin->insert_stmt,
201 LOG_SQLITE (plugin->dbh,
202 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
204 GNUNET_SQ_reset (plugin->dbh,
205 plugin->insert_stmt);
209 sqlite3_step (plugin->insert_stmt))
211 LOG_SQLITE (plugin->dbh,
212 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
214 GNUNET_SQ_reset (plugin->dbh,
215 plugin->insert_stmt);
219 GNUNET_SQ_reset (plugin->dbh,
220 plugin->insert_stmt);
221 return size + OVERHEAD;
226 * Iterate over the results for a particular key
229 * @param cls closure (our `struct Plugin`)
231 * @param type entries of which type are relevant?
232 * @param iter maybe NULL (to just count)
233 * @param iter_cls closure for @a iter
234 * @return the number of results found
237 sqlite_plugin_get (void *cls,
238 const struct GNUNET_HashCode *key,
239 enum GNUNET_BLOCK_Type type,
240 GNUNET_DATACACHE_Iterator iter,
243 struct Plugin *plugin = cls;
244 uint32_t type32 = type;
245 struct GNUNET_TIME_Absolute now;
246 struct GNUNET_TIME_Absolute exp;
253 struct GNUNET_PeerIdentity *path;
254 struct GNUNET_SQ_QueryParam params_count[] = {
255 GNUNET_SQ_query_param_auto_from_type (key),
256 GNUNET_SQ_query_param_uint32 (&type32),
257 GNUNET_SQ_query_param_absolute_time (&now),
258 GNUNET_SQ_query_param_end
260 struct GNUNET_SQ_QueryParam params_select[] = {
261 GNUNET_SQ_query_param_auto_from_type (key),
262 GNUNET_SQ_query_param_uint32 (&type32),
263 GNUNET_SQ_query_param_absolute_time (&now),
264 GNUNET_SQ_query_param_uint32 (&off),
265 GNUNET_SQ_query_param_end
267 struct GNUNET_SQ_ResultSpec rs[] = {
268 GNUNET_SQ_result_spec_variable_size (&dat,
270 GNUNET_SQ_result_spec_absolute_time (&exp),
271 GNUNET_SQ_result_spec_variable_size ((void **) &path,
273 GNUNET_SQ_result_spec_end
276 now = GNUNET_TIME_absolute_get ();
277 LOG (GNUNET_ERROR_TYPE_DEBUG,
278 "Processing GET for key `%s'\n",
282 GNUNET_SQ_bind (plugin->get_count_stmt,
285 LOG_SQLITE (plugin->dbh,
286 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
288 GNUNET_SQ_reset (plugin->dbh,
289 plugin->get_count_stmt);
293 sqlite3_step (plugin->get_count_stmt))
295 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
297 GNUNET_SQ_reset (plugin->dbh,
298 plugin->get_count_stmt);
299 LOG (GNUNET_ERROR_TYPE_DEBUG,
300 "No content found when processing GET for key `%s'\n",
304 total = sqlite3_column_int (plugin->get_count_stmt,
306 GNUNET_SQ_reset (plugin->dbh,
307 plugin->get_count_stmt);
312 LOG (GNUNET_ERROR_TYPE_DEBUG,
313 "No content found when processing GET for key `%s'\n",
319 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
323 off = (off + 1) % total;
325 GNUNET_SQ_bind (plugin->get_stmt,
328 LOG_SQLITE (plugin->dbh,
329 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
331 GNUNET_SQ_reset (plugin->dbh,
336 sqlite3_step (plugin->get_stmt))
339 GNUNET_SQ_extract_result (plugin->get_stmt,
343 GNUNET_SQ_reset (plugin->dbh,
347 if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
353 psize /= sizeof (struct GNUNET_PeerIdentity);
355 LOG (GNUNET_ERROR_TYPE_DEBUG,
356 "Found %u-byte result when processing GET for key `%s'\n",
359 if (GNUNET_OK != iter (iter_cls,
368 GNUNET_SQ_cleanup_result (rs);
369 GNUNET_SQ_reset (plugin->dbh,
373 GNUNET_SQ_cleanup_result (rs);
374 GNUNET_SQ_reset (plugin->dbh,
377 GNUNET_SQ_reset (plugin->dbh,
384 * Delete the entry with the lowest expiration value
385 * from the datacache right now.
387 * @param cls closure (our `struct Plugin`)
388 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
391 sqlite_plugin_del (void *cls)
393 struct Plugin *plugin = cls;
397 struct GNUNET_HashCode hc;
398 struct GNUNET_TIME_Absolute now;
399 struct GNUNET_SQ_ResultSpec rs[] = {
400 GNUNET_SQ_result_spec_uint64 (&rowid),
401 GNUNET_SQ_result_spec_auto_from_type (&hc),
402 GNUNET_SQ_result_spec_variable_size ((void **) &data,
404 GNUNET_SQ_result_spec_end
406 struct GNUNET_SQ_QueryParam params[] = {
407 GNUNET_SQ_query_param_uint64 (&rowid),
408 GNUNET_SQ_query_param_end
410 struct GNUNET_SQ_QueryParam time_params[] = {
411 GNUNET_SQ_query_param_absolute_time (&now),
412 GNUNET_SQ_query_param_end
415 LOG (GNUNET_ERROR_TYPE_DEBUG,
417 now = GNUNET_TIME_absolute_get ();
419 GNUNET_SQ_bind (plugin->del_expired_stmt,
422 LOG_SQLITE (plugin->dbh,
423 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
425 GNUNET_SQ_reset (plugin->dbh,
426 plugin->del_expired_stmt);
427 return GNUNET_SYSERR;
430 sqlite3_step (plugin->del_expired_stmt)) ||
432 GNUNET_SQ_extract_result (plugin->del_expired_stmt,
435 GNUNET_SQ_reset (plugin->dbh,
436 plugin->del_expired_stmt);
438 sqlite3_step (plugin->del_select_stmt))
440 LOG_SQLITE (plugin->dbh,
441 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
443 GNUNET_SQ_reset (plugin->dbh,
444 plugin->del_select_stmt);
445 return GNUNET_SYSERR;
448 GNUNET_SQ_extract_result (plugin->del_select_stmt,
451 GNUNET_SQ_reset (plugin->dbh,
452 plugin->del_select_stmt);
454 return GNUNET_SYSERR;
457 GNUNET_SQ_cleanup_result (rs);
458 GNUNET_SQ_reset (plugin->dbh,
459 plugin->del_select_stmt);
461 GNUNET_SQ_bind (plugin->del_stmt,
464 LOG_SQLITE (plugin->dbh,
465 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
467 GNUNET_SQ_reset (plugin->dbh,
469 return GNUNET_SYSERR;
472 sqlite3_step (plugin->del_stmt))
474 LOG_SQLITE (plugin->dbh,
475 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
477 GNUNET_SQ_reset (plugin->dbh,
479 return GNUNET_SYSERR;
482 plugin->env->delete_notify (plugin->env->cls,
485 GNUNET_SQ_reset (plugin->dbh,
492 * Obtain a random key-value pair from the datacache.
494 * @param cls closure (our `struct Plugin`)
495 * @param iter maybe NULL (to just count)
496 * @param iter_cls closure for @a iter
497 * @return the number of results found, zero (datacache empty) or one
500 sqlite_plugin_get_random (void *cls,
501 GNUNET_DATACACHE_Iterator iter,
504 struct Plugin *plugin = cls;
505 struct GNUNET_TIME_Absolute exp;
511 struct GNUNET_PeerIdentity *path;
512 struct GNUNET_HashCode key;
513 struct GNUNET_SQ_QueryParam params[] = {
514 GNUNET_SQ_query_param_uint32 (&off),
515 GNUNET_SQ_query_param_end
517 struct GNUNET_SQ_ResultSpec rs[] = {
518 GNUNET_SQ_result_spec_variable_size (&dat,
520 GNUNET_SQ_result_spec_absolute_time (&exp),
521 GNUNET_SQ_result_spec_variable_size ((void **) &path,
523 GNUNET_SQ_result_spec_auto_from_type (&key),
524 GNUNET_SQ_result_spec_uint32 (&type),
525 GNUNET_SQ_result_spec_end
528 if (0 == plugin->num_items)
532 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
535 GNUNET_SQ_bind (plugin->get_random_stmt,
541 sqlite3_step (plugin->get_random_stmt))
544 GNUNET_SQ_reset (plugin->dbh,
545 plugin->get_random_stmt);
549 GNUNET_SQ_extract_result (plugin->get_random_stmt,
553 GNUNET_SQ_reset (plugin->dbh,
554 plugin->get_random_stmt);
557 if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
563 psize /= sizeof (struct GNUNET_PeerIdentity);
564 LOG (GNUNET_ERROR_TYPE_DEBUG,
565 "Found %u-byte result with key %s when processing GET-RANDOM\n",
568 (void) iter (iter_cls,
572 (enum GNUNET_BLOCK_Type) type,
576 GNUNET_SQ_cleanup_result (rs);
577 GNUNET_SQ_reset (plugin->dbh,
578 plugin->get_random_stmt);
584 * Iterate over the results that are "close" to a particular key in
585 * the datacache. "close" is defined as numerically larger than @a
586 * key (when interpreted as a circular address space), with small
589 * @param cls closure (internal context for the plugin)
590 * @param key area of the keyspace to look into
591 * @param num_results number of results that should be returned to @a iter
592 * @param iter maybe NULL (to just count)
593 * @param iter_cls closure for @a iter
594 * @return the number of results found
597 sqlite_plugin_get_closest (void *cls,
598 const struct GNUNET_HashCode *key,
599 unsigned int num_results,
600 GNUNET_DATACACHE_Iterator iter,
603 struct Plugin *plugin = cls;
604 uint32_t num_results32 = num_results;
605 struct GNUNET_TIME_Absolute now;
606 struct GNUNET_TIME_Absolute exp;
612 struct GNUNET_HashCode hc;
613 struct GNUNET_PeerIdentity *path;
614 struct GNUNET_SQ_QueryParam params[] = {
615 GNUNET_SQ_query_param_auto_from_type (key),
616 GNUNET_SQ_query_param_absolute_time (&now),
617 GNUNET_SQ_query_param_uint32 (&num_results32),
618 GNUNET_SQ_query_param_end
620 struct GNUNET_SQ_ResultSpec rs[] = {
621 GNUNET_SQ_result_spec_variable_size (&dat,
623 GNUNET_SQ_result_spec_absolute_time (&exp),
624 GNUNET_SQ_result_spec_variable_size ((void **) &path,
626 GNUNET_SQ_result_spec_uint32 (&type),
627 GNUNET_SQ_result_spec_auto_from_type (&hc),
628 GNUNET_SQ_result_spec_end
631 now = GNUNET_TIME_absolute_get ();
632 LOG (GNUNET_ERROR_TYPE_DEBUG,
633 "Processing GET_CLOSEST for key `%s'\n",
636 GNUNET_SQ_bind (plugin->get_closest_stmt,
639 LOG_SQLITE (plugin->dbh,
640 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
642 GNUNET_SQ_reset (plugin->dbh,
643 plugin->get_closest_stmt);
648 sqlite3_step (plugin->get_closest_stmt))
651 GNUNET_SQ_extract_result (plugin->get_closest_stmt,
657 if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
663 psize /= sizeof (struct GNUNET_PeerIdentity);
665 LOG (GNUNET_ERROR_TYPE_DEBUG,
666 "Found %u-byte result at %s when processing GET_CLOSE\n",
669 if (GNUNET_OK != iter (iter_cls,
678 GNUNET_SQ_cleanup_result (rs);
681 GNUNET_SQ_cleanup_result (rs);
683 GNUNET_SQ_reset (plugin->dbh,
684 plugin->get_closest_stmt);
690 * Entry point for the plugin.
692 * @param cls closure (the `struct GNUNET_DATACACHE_PluginEnvironment`)
693 * @return the plugin's closure (our `struct Plugin`)
696 libgnunet_plugin_datacache_sqlite_init (void *cls)
698 struct GNUNET_DATACACHE_PluginEnvironment *env = cls;
699 struct GNUNET_DATACACHE_PluginFunctions *api;
700 struct Plugin *plugin;
707 GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
711 if (SQLITE_OK != sqlite3_open (":memory:", &dbh))
717 fn = GNUNET_DISK_mktemp ("gnunet-datacache");
723 /* fn should be UTF-8-encoded. If it isn't, it's a bug. */
724 fn_utf8 = GNUNET_strdup (fn);
725 if (SQLITE_OK != sqlite3_open (fn_utf8, &dbh))
728 GNUNET_free (fn_utf8);
734 SQLITE3_EXEC (dbh, "PRAGMA temp_store=MEMORY");
735 SQLITE3_EXEC (dbh, "PRAGMA locking_mode=EXCLUSIVE");
736 SQLITE3_EXEC (dbh, "PRAGMA journal_mode=OFF");
737 SQLITE3_EXEC (dbh, "PRAGMA synchronous=OFF");
738 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092");
740 GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
743 SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3");
746 "CREATE TABLE ds091 ("
747 " type INTEGER NOT NULL DEFAULT 0,"
748 " expire INTEGER NOT NULL,"
749 " key BLOB NOT NULL DEFAULT '',"
750 " prox INTEGER NOT NULL,"
751 " value BLOB NOT NULL,"
752 " path BLOB DEFAULT '')");
753 SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)");
754 SQLITE3_EXEC (dbh, "CREATE INDEX idx_prox_expire ON ds091 (prox,expire)");
755 SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire_only ON ds091 (expire)");
756 plugin = GNUNET_new (struct Plugin);
759 plugin->fn = fn_utf8;
762 sq_prepare (plugin->dbh,
763 "INSERT INTO ds091 (type, expire, key, prox, value, path) "
764 "VALUES (?, ?, ?, ?, ?, ?)",
765 &plugin->insert_stmt)) ||
767 sq_prepare (plugin->dbh,
768 "SELECT count(*) FROM ds091 "
769 "WHERE key=? AND type=? AND expire >= ?",
770 &plugin->get_count_stmt)) ||
772 sq_prepare (plugin->dbh,
773 "SELECT value,expire,path FROM ds091"
774 " WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?",
775 &plugin->get_stmt)) ||
777 sq_prepare (plugin->dbh,
778 "SELECT _ROWID_,key,value FROM ds091"
780 " ORDER BY expire ASC LIMIT 1",
781 &plugin->del_expired_stmt)) ||
783 sq_prepare (plugin->dbh,
784 "SELECT _ROWID_,key,value FROM ds091"
785 " ORDER BY prox ASC, expire ASC LIMIT 1",
786 &plugin->del_select_stmt)) ||
788 sq_prepare (plugin->dbh,
789 "DELETE FROM ds091 WHERE _ROWID_=?",
790 &plugin->del_stmt)) ||
792 sq_prepare (plugin->dbh,
793 "SELECT value,expire,path,key,type FROM ds091 "
794 "ORDER BY key LIMIT 1 OFFSET ?",
795 &plugin->get_random_stmt)) ||
797 sq_prepare (plugin->dbh,
798 "SELECT value,expire,path,type,key FROM ds091 "
799 "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?",
800 &plugin->get_closest_stmt))
803 LOG_SQLITE (plugin->dbh,
804 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
806 GNUNET_break (SQLITE_OK ==
807 sqlite3_close (plugin->dbh));
808 GNUNET_free (plugin);
812 api = GNUNET_new (struct GNUNET_DATACACHE_PluginFunctions);
814 api->get = &sqlite_plugin_get;
815 api->put = &sqlite_plugin_put;
816 api->del = &sqlite_plugin_del;
817 api->get_random = &sqlite_plugin_get_random;
818 api->get_closest = &sqlite_plugin_get_closest;
819 LOG (GNUNET_ERROR_TYPE_INFO,
820 "Sqlite datacache running\n");
826 * Exit point from the plugin.
828 * @param cls closure (our `struct Plugin`)
832 libgnunet_plugin_datacache_sqlite_done (void *cls)
834 struct GNUNET_DATACACHE_PluginFunctions *api = cls;
835 struct Plugin *plugin = api->cls;
838 #if SQLITE_VERSION_NUMBER >= 3007000
842 #if !WINDOWS || defined(__CYGWIN__)
843 if ( (NULL != plugin->fn) &&
844 (0 != UNLINK (plugin->fn)) )
845 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
848 GNUNET_free_non_null (plugin->fn);
850 sqlite3_finalize (plugin->insert_stmt);
851 sqlite3_finalize (plugin->get_count_stmt);
852 sqlite3_finalize (plugin->get_stmt);
853 sqlite3_finalize (plugin->del_select_stmt);
854 sqlite3_finalize (plugin->del_expired_stmt);
855 sqlite3_finalize (plugin->del_stmt);
856 sqlite3_finalize (plugin->get_random_stmt);
857 sqlite3_finalize (plugin->get_closest_stmt);
858 result = sqlite3_close (plugin->dbh);
859 #if SQLITE_VERSION_NUMBER >= 3007000
860 if (SQLITE_BUSY == result)
862 LOG (GNUNET_ERROR_TYPE_WARNING,
863 _("Tried to close sqlite without finalizing all prepared statements.\n"));
864 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
867 result = sqlite3_finalize (stmt);
868 if (result != SQLITE_OK)
869 LOG (GNUNET_ERROR_TYPE_WARNING,
870 "Failed to close statement %p: %d\n",
873 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
875 result = sqlite3_close (plugin->dbh);
878 if (SQLITE_OK != result)
879 LOG_SQLITE (plugin->dbh,
880 GNUNET_ERROR_TYPE_ERROR,
883 #if WINDOWS && !defined(__CYGWIN__)
884 if ( (NULL != plugin->fn) &&
885 (0 != UNLINK (plugin->fn)) )
886 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
889 GNUNET_free_non_null (plugin->fn);
891 GNUNET_free (plugin);
898 /* end of plugin_datacache_sqlite.c */