diff options
-rw-r--r-- | src/datastore/Makefile.am | 1 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 203 | ||||
-rw-r--r-- | src/include/gnunet_sq_lib.h | 24 |
3 files changed, 110 insertions, 118 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am index 1285020de..9b8cf365f 100644 --- a/src/datastore/Makefile.am +++ b/src/datastore/Makefile.am | |||
@@ -115,6 +115,7 @@ noinst_LTLIBRARIES = \ | |||
115 | libgnunet_plugin_datastore_sqlite_la_SOURCES = \ | 115 | libgnunet_plugin_datastore_sqlite_la_SOURCES = \ |
116 | plugin_datastore_sqlite.c | 116 | plugin_datastore_sqlite.c |
117 | libgnunet_plugin_datastore_sqlite_la_LIBADD = \ | 117 | libgnunet_plugin_datastore_sqlite_la_LIBADD = \ |
118 | $(top_builddir)/src/sq/libgnunetsq.la \ | ||
118 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 119 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
119 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ | 120 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ |
120 | $(LTLIBINTL) | 121 | $(LTLIBINTL) |
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 9ab50714f..9c67d242e 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of GNUnet | 2 | * This file is part of GNUnet |
3 | * Copyright (C) 2009, 2011 GNUnet e.V. | 3 | * Copyright (C) 2009, 2011, 2017 GNUnet e.V. |
4 | * | 4 | * |
5 | * GNUnet is free software; you can redistribute it and/or modify | 5 | * GNUnet is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published | 6 | * it under the terms of the GNU General Public License as published |
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_datastore_plugin.h" | 28 | #include "gnunet_datastore_plugin.h" |
29 | #include "gnunet_sq_lib.h" | ||
29 | #include <sqlite3.h> | 30 | #include <sqlite3.h> |
30 | 31 | ||
31 | 32 | ||
@@ -456,18 +457,17 @@ database_shutdown (struct Plugin *plugin) | |||
456 | */ | 457 | */ |
457 | static int | 458 | static int |
458 | delete_by_rowid (struct Plugin *plugin, | 459 | delete_by_rowid (struct Plugin *plugin, |
459 | unsigned long long rid) | 460 | uint64_t rid) |
460 | { | 461 | { |
461 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) | 462 | struct GNUNET_SQ_QueryParam params[] = { |
462 | { | 463 | GNUNET_SQ_query_param_uint64 (&rid), |
463 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 464 | GNUNET_SQ_query_param_end |
464 | "sqlite3_bind_XXXX"); | 465 | }; |
465 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) | 466 | |
466 | LOG_SQLITE (plugin, | 467 | if (GNUNET_OK != |
467 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 468 | GNUNET_SQ_bind (plugin->delRow, |
468 | "sqlite3_reset"); | 469 | params)) |
469 | return GNUNET_SYSERR; | 470 | return GNUNET_SYSERR; |
470 | } | ||
471 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) | 471 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) |
472 | { | 472 | { |
473 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 473 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -513,12 +513,24 @@ sqlite_plugin_put (void *cls, | |||
513 | PluginPutCont cont, | 513 | PluginPutCont cont, |
514 | void *cont_cls) | 514 | void *cont_cls) |
515 | { | 515 | { |
516 | uint64_t rvalue; | ||
517 | struct GNUNET_HashCode vhash; | ||
518 | struct GNUNET_SQ_QueryParam params[] = { | ||
519 | GNUNET_SQ_query_param_uint32 (&replication), | ||
520 | GNUNET_SQ_query_param_uint32 (&type), | ||
521 | GNUNET_SQ_query_param_uint32 (&priority), | ||
522 | GNUNET_SQ_query_param_uint32 (&anonymity), | ||
523 | GNUNET_SQ_query_param_absolute_time (&expiration), | ||
524 | GNUNET_SQ_query_param_uint64 (&rvalue), | ||
525 | GNUNET_SQ_query_param_auto_from_type (key), | ||
526 | GNUNET_SQ_query_param_auto_from_type (&vhash), | ||
527 | GNUNET_SQ_query_param_fixed_size (data, size), | ||
528 | GNUNET_SQ_query_param_end | ||
529 | }; | ||
516 | struct Plugin *plugin = cls; | 530 | struct Plugin *plugin = cls; |
517 | int n; | 531 | int n; |
518 | int ret; | 532 | int ret; |
519 | sqlite3_stmt *stmt; | 533 | sqlite3_stmt *stmt; |
520 | struct GNUNET_HashCode vhash; | ||
521 | uint64_t rvalue; | ||
522 | char *msg = NULL; | 534 | char *msg = NULL; |
523 | 535 | ||
524 | if (size > MAX_ITEM_SIZE) | 536 | if (size > MAX_ITEM_SIZE) |
@@ -537,26 +549,10 @@ sqlite_plugin_put (void *cls, | |||
537 | GNUNET_CRYPTO_hash (data, size, &vhash); | 549 | GNUNET_CRYPTO_hash (data, size, &vhash); |
538 | stmt = plugin->insertContent; | 550 | stmt = plugin->insertContent; |
539 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 551 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
540 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, replication)) || | 552 | if (GNUNET_OK != |
541 | (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || | 553 | GNUNET_SQ_bind (stmt, |
542 | (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) || | 554 | params)) |
543 | (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) || | ||
544 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value_us)) || | ||
545 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 6, rvalue)) || | ||
546 | (SQLITE_OK != | ||
547 | sqlite3_bind_blob (stmt, 7, key, sizeof (struct GNUNET_HashCode), | ||
548 | SQLITE_TRANSIENT)) || | ||
549 | (SQLITE_OK != | ||
550 | sqlite3_bind_blob (stmt, 8, &vhash, sizeof (struct GNUNET_HashCode), | ||
551 | SQLITE_TRANSIENT)) || | ||
552 | (SQLITE_OK != sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT))) | ||
553 | { | 555 | { |
554 | LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
555 | "sqlite3_bind_XXXX"); | ||
556 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
557 | LOG_SQLITE (plugin, | ||
558 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
559 | "sqlite3_reset"); | ||
560 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); | 556 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); |
561 | GNUNET_free_non_null(msg); | 557 | GNUNET_free_non_null(msg); |
562 | return; | 558 | return; |
@@ -619,7 +615,7 @@ sqlite_plugin_put (void *cls, | |||
619 | * MAX of any existing expiration time and | 615 | * MAX of any existing expiration time and |
620 | * this value | 616 | * this value |
621 | * @param cont continuation called with success or failure status | 617 | * @param cont continuation called with success or failure status |
622 | * @param cons_cls continuation closure | 618 | * @param cons_cls closure for @a cont |
623 | */ | 619 | */ |
624 | static void | 620 | static void |
625 | sqlite_plugin_update (void *cls, | 621 | sqlite_plugin_update (void *cls, |
@@ -630,19 +626,19 @@ sqlite_plugin_update (void *cls, | |||
630 | void *cont_cls) | 626 | void *cont_cls) |
631 | { | 627 | { |
632 | struct Plugin *plugin = cls; | 628 | struct Plugin *plugin = cls; |
629 | struct GNUNET_SQ_QueryParam params[] = { | ||
630 | GNUNET_SQ_query_param_uint32 (&delta), | ||
631 | GNUNET_SQ_query_param_absolute_time (&expire), | ||
632 | GNUNET_SQ_query_param_uint64 (&uid), | ||
633 | GNUNET_SQ_query_param_end | ||
634 | }; | ||
633 | int n; | 635 | int n; |
634 | char *msg = NULL; | 636 | char *msg = NULL; |
635 | 637 | ||
636 | if ((SQLITE_OK != sqlite3_bind_int (plugin->updPrio, 1, delta)) || | 638 | if (GNUNET_OK != |
637 | (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value_us)) | 639 | GNUNET_SQ_bind (plugin->updPrio, |
638 | || (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid))) | 640 | params)) |
639 | { | 641 | { |
640 | LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
641 | "sqlite3_bind_XXXX"); | ||
642 | if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) | ||
643 | LOG_SQLITE (plugin, | ||
644 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
645 | "sqlite3_reset"); | ||
646 | cont (cont_cls, GNUNET_SYSERR, msg); | 642 | cont (cont_cls, GNUNET_SYSERR, msg); |
647 | GNUNET_free_non_null(msg); | 643 | GNUNET_free_non_null(msg); |
648 | return; | 644 | return; |
@@ -780,22 +776,22 @@ execute_get (struct Plugin *plugin, | |||
780 | static void | 776 | static void |
781 | sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, | 777 | sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
782 | enum GNUNET_BLOCK_Type type, | 778 | enum GNUNET_BLOCK_Type type, |
783 | PluginDatumProcessor proc, void *proc_cls) | 779 | PluginDatumProcessor proc, |
780 | void *proc_cls) | ||
784 | { | 781 | { |
785 | struct Plugin *plugin = cls; | 782 | struct Plugin *plugin = cls; |
786 | sqlite3_stmt *stmt; | 783 | struct GNUNET_SQ_QueryParam params[] = { |
784 | GNUNET_SQ_query_param_uint32 (&type), | ||
785 | GNUNET_SQ_query_param_uint64 (&offset), | ||
786 | GNUNET_SQ_query_param_end | ||
787 | }; | ||
788 | sqlite3_stmt *stmt = plugin->selZeroAnon; | ||
787 | 789 | ||
788 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); | 790 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); |
789 | stmt = plugin->selZeroAnon; | 791 | if (GNUNET_OK != |
790 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || | 792 | GNUNET_SQ_bind (stmt, |
791 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset))) | 793 | params)) |
792 | { | 794 | { |
793 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
794 | "sqlite3_bind_XXXX"); | ||
795 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
796 | LOG_SQLITE (plugin, | ||
797 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
798 | "sqlite3_reset"); | ||
799 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 795 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
800 | return; | 796 | return; |
801 | } | 797 | } |
@@ -1018,17 +1014,25 @@ sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
1018 | struct ReplCtx rc; | 1014 | struct ReplCtx rc; |
1019 | uint64_t rvalue; | 1015 | uint64_t rvalue; |
1020 | uint32_t repl; | 1016 | uint32_t repl; |
1021 | sqlite3_stmt *stmt; | 1017 | struct GNUNET_SQ_QueryParam params_sel_repl[] = { |
1022 | 1018 | GNUNET_SQ_query_param_uint64 (&rvalue), | |
1023 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 1019 | GNUNET_SQ_query_param_uint32 (&repl), |
1020 | GNUNET_SQ_query_param_end | ||
1021 | }; | ||
1022 | struct GNUNET_SQ_QueryParam params_upd_repl[] = { | ||
1023 | GNUNET_SQ_query_param_uint64 (&rc.uid), | ||
1024 | GNUNET_SQ_query_param_end | ||
1025 | }; | ||
1026 | |||
1027 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
1028 | "datastore-sqlite", | ||
1024 | "Getting random block based on replication order.\n"); | 1029 | "Getting random block based on replication order.\n"); |
1025 | rc.have_uid = GNUNET_NO; | 1030 | rc.have_uid = GNUNET_NO; |
1026 | rc.proc = proc; | 1031 | rc.proc = proc; |
1027 | rc.proc_cls = proc_cls; | 1032 | rc.proc_cls = proc_cls; |
1028 | stmt = plugin->maxRepl; | 1033 | if (SQLITE_ROW != sqlite3_step (plugin->maxRepl)) |
1029 | if (SQLITE_ROW != sqlite3_step (stmt)) | ||
1030 | { | 1034 | { |
1031 | if (SQLITE_OK != sqlite3_reset (stmt)) | 1035 | if (SQLITE_OK != sqlite3_reset (plugin->maxRepl)) |
1032 | LOG_SQLITE (plugin, | 1036 | LOG_SQLITE (plugin, |
1033 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1037 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1034 | "sqlite3_reset"); | 1038 | "sqlite3_reset"); |
@@ -1036,46 +1040,26 @@ sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
1036 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1040 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1037 | return; | 1041 | return; |
1038 | } | 1042 | } |
1039 | repl = sqlite3_column_int (stmt, 0); | 1043 | repl = sqlite3_column_int (plugin->maxRepl, 0); |
1040 | if (SQLITE_OK != sqlite3_reset (stmt)) | 1044 | if (SQLITE_OK != sqlite3_reset (plugin->maxRepl)) |
1041 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1045 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1042 | "sqlite3_reset"); | 1046 | "sqlite3_reset"); |
1043 | stmt = plugin->selRepl; | ||
1044 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 1047 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
1045 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue)) | 1048 | if (GNUNET_OK != |
1049 | GNUNET_SQ_bind (plugin->selRepl, | ||
1050 | params_sel_repl)) | ||
1046 | { | 1051 | { |
1047 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1048 | "sqlite3_bind_XXXX"); | ||
1049 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
1050 | LOG_SQLITE (plugin, | ||
1051 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1052 | "sqlite3_reset"); | ||
1053 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1052 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1054 | return; | 1053 | return; |
1055 | } | 1054 | } |
1056 | if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl)) | 1055 | execute_get (plugin, plugin->selRepl, &repl_proc, &rc); |
1057 | { | ||
1058 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1059 | "sqlite3_bind_XXXX"); | ||
1060 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
1061 | LOG_SQLITE (plugin, | ||
1062 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1063 | "sqlite3_reset"); | ||
1064 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
1065 | return; | ||
1066 | } | ||
1067 | execute_get (plugin, stmt, &repl_proc, &rc); | ||
1068 | if (GNUNET_YES == rc.have_uid) | 1056 | if (GNUNET_YES == rc.have_uid) |
1069 | { | 1057 | { |
1070 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid)) | 1058 | if (GNUNET_OK != |
1059 | GNUNET_SQ_bind (plugin->updRepl, | ||
1060 | params_upd_repl)) | ||
1071 | { | 1061 | { |
1072 | LOG_SQLITE (plugin, | 1062 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1073 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1074 | "sqlite3_bind_XXXX"); | ||
1075 | if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) | ||
1076 | LOG_SQLITE (plugin, | ||
1077 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1078 | "sqlite3_reset"); | ||
1079 | return; | 1063 | return; |
1080 | } | 1064 | } |
1081 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) | 1065 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) |
@@ -1105,19 +1089,19 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
1105 | struct Plugin *plugin = cls; | 1089 | struct Plugin *plugin = cls; |
1106 | sqlite3_stmt *stmt; | 1090 | sqlite3_stmt *stmt; |
1107 | struct GNUNET_TIME_Absolute now; | 1091 | struct GNUNET_TIME_Absolute now; |
1092 | struct GNUNET_SQ_QueryParam params[] = { | ||
1093 | GNUNET_SQ_query_param_absolute_time (&now), | ||
1094 | GNUNET_SQ_query_param_end | ||
1095 | }; | ||
1108 | 1096 | ||
1109 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 1097 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1110 | "Getting random block based on expiration and priority order.\n"); | 1098 | "Getting random block based on expiration and priority order.\n"); |
1111 | now = GNUNET_TIME_absolute_get (); | 1099 | now = GNUNET_TIME_absolute_get (); |
1112 | stmt = plugin->selExpi; | 1100 | stmt = plugin->selExpi; |
1113 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value_us)) | 1101 | if (GNUNET_OK != |
1102 | GNUNET_SQ_bind (stmt, | ||
1103 | params)) | ||
1114 | { | 1104 | { |
1115 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1116 | "sqlite3_bind_XXXX"); | ||
1117 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
1118 | LOG_SQLITE (plugin, | ||
1119 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1120 | "sqlite3_reset"); | ||
1121 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1105 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1122 | return; | 1106 | return; |
1123 | } | 1107 | } |
@@ -1138,11 +1122,15 @@ sqlite_plugin_get_keys (void *cls, | |||
1138 | void *proc_cls) | 1122 | void *proc_cls) |
1139 | { | 1123 | { |
1140 | struct Plugin *plugin = cls; | 1124 | struct Plugin *plugin = cls; |
1141 | const struct GNUNET_HashCode *key; | 1125 | struct GNUNET_HashCode key; |
1126 | struct GNUNET_SQ_ResultSpec results[] = { | ||
1127 | GNUNET_SQ_result_spec_auto_from_type (&key), | ||
1128 | GNUNET_SQ_result_spec_end | ||
1129 | }; | ||
1142 | sqlite3_stmt *stmt; | 1130 | sqlite3_stmt *stmt; |
1143 | int ret; | 1131 | int ret; |
1144 | 1132 | ||
1145 | GNUNET_assert (proc != NULL); | 1133 | GNUNET_assert (NULL != proc); |
1146 | if (sq_prepare (plugin->dbh, "SELECT hash FROM gn090", &stmt) != SQLITE_OK) | 1134 | if (sq_prepare (plugin->dbh, "SELECT hash FROM gn090", &stmt) != SQLITE_OK) |
1147 | { | 1135 | { |
1148 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1136 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -1152,9 +1140,10 @@ sqlite_plugin_get_keys (void *cls, | |||
1152 | } | 1140 | } |
1153 | while (SQLITE_ROW == (ret = sqlite3_step (stmt))) | 1141 | while (SQLITE_ROW == (ret = sqlite3_step (stmt))) |
1154 | { | 1142 | { |
1155 | key = sqlite3_column_blob (stmt, 0); | 1143 | if (GNUNET_OK == |
1156 | if (sizeof (struct GNUNET_HashCode) == sqlite3_column_bytes (stmt, 0)) | 1144 | GNUNET_SQ_extract_result (stmt, |
1157 | proc (proc_cls, key, 1); | 1145 | results)) |
1146 | proc (proc_cls, &key, 1); | ||
1158 | else | 1147 | else |
1159 | GNUNET_break (0); | 1148 | GNUNET_break (0); |
1160 | } | 1149 | } |
@@ -1223,8 +1212,7 @@ sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
1223 | page_size = sqlite3_column_int64 (stmt, 0); | 1212 | page_size = sqlite3_column_int64 (stmt, 0); |
1224 | sqlite3_finalize (stmt); | 1213 | sqlite3_finalize (stmt); |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1226 | _ | 1215 | _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), |
1227 | ("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), | ||
1228 | (unsigned long long) pages, (unsigned long long) page_size); | 1216 | (unsigned long long) pages, (unsigned long long) page_size); |
1229 | *estimate = pages * page_size; | 1217 | *estimate = pages * page_size; |
1230 | } | 1218 | } |
@@ -1292,13 +1280,16 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) | |||
1292 | database_shutdown (plugin); | 1280 | database_shutdown (plugin); |
1293 | plugin->env = NULL; | 1281 | plugin->env = NULL; |
1294 | GNUNET_free (api); | 1282 | GNUNET_free (api); |
1295 | if (fn != NULL) | 1283 | if (NULL != fn) |
1296 | { | 1284 | { |
1297 | if (0 != UNLINK (fn)) | 1285 | if (0 != UNLINK (fn)) |
1298 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1286 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1287 | "unlink", | ||
1288 | fn); | ||
1299 | GNUNET_free (fn); | 1289 | GNUNET_free (fn); |
1300 | } | 1290 | } |
1301 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 1291 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1292 | "sqlite", | ||
1302 | "sqlite plugin is finished\n"); | 1293 | "sqlite plugin is finished\n"); |
1303 | return NULL; | 1294 | return NULL; |
1304 | } | 1295 | } |
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h index c03f83e07..4d2510ee5 100644 --- a/src/include/gnunet_sq_lib.h +++ b/src/include/gnunet_sq_lib.h | |||
@@ -182,6 +182,18 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x); | |||
182 | 182 | ||
183 | 183 | ||
184 | /** | 184 | /** |
185 | * Execute binding operations for a prepared statement. | ||
186 | * | ||
187 | * @param db_conn database connection | ||
188 | * @param params parameters to the statement | ||
189 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
190 | */ | ||
191 | int | ||
192 | GNUNET_SQ_bind (sqlite3_stmt *stmt, | ||
193 | const struct GNUNET_SQ_QueryParam *params); | ||
194 | |||
195 | |||
196 | /** | ||
185 | * Extract data from a Postgres database @a result at row @a row. | 197 | * Extract data from a Postgres database @a result at row @a row. |
186 | * | 198 | * |
187 | * @param cls closure | 199 | * @param cls closure |
@@ -400,18 +412,6 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64); | |||
400 | 412 | ||
401 | 413 | ||
402 | /** | 414 | /** |
403 | * Execute a prepared statement. | ||
404 | * | ||
405 | * @param db_conn database connection | ||
406 | * @param params parameters to the statement | ||
407 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
408 | */ | ||
409 | int | ||
410 | GNUNET_SQ_bind (sqlite3_stmt *stmt, | ||
411 | const struct GNUNET_SQ_QueryParam *params); | ||
412 | |||
413 | |||
414 | /** | ||
415 | * Extract results from a query result according to the given specification. | 415 | * Extract results from a query result according to the given specification. |
416 | * | 416 | * |
417 | * @param result result to process | 417 | * @param result result to process |