aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-05 11:41:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-05 11:41:39 +0000
commit6d021e2931dbe18230ab763ca1251012fa753ced (patch)
treed14cad9f8b665a40efbbfdaac6cd1358163b6848 /src/namestore/plugin_namestore_sqlite.c
parentacb2568116de77fcac08ab1ac8b4df81a886f4be (diff)
downloadgnunet-6d021e2931dbe18230ab763ca1251012fa753ced.tar.gz
gnunet-6d021e2931dbe18230ab763ca1251012fa753ced.zip
-implement iteration over all zones (#3016)
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 437a2efd6..370ed0873 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -102,6 +102,11 @@ struct Plugin
102 sqlite3_stmt *iterate_zone; 102 sqlite3_stmt *iterate_zone;
103 103
104 /** 104 /**
105 * Precompiled SQL for iterate all records within all zones.
106 */
107 sqlite3_stmt *iterate_all_zones;
108
109 /**
105 * Precompiled SQL to for reverse lookup based on PKEY. 110 * Precompiled SQL to for reverse lookup based on PKEY.
106 */ 111 */
107 sqlite3_stmt *zone_to_name; 112 sqlite3_stmt *zone_to_name;
@@ -152,6 +157,9 @@ create_indices (sqlite3 * dbh)
152 NULL, NULL, NULL)) || 157 NULL, NULL, NULL)) ||
153 (SQLITE_OK != 158 (SQLITE_OK !=
154 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns096records (zone_private_key,rvalue)", 159 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns096records (zone_private_key,rvalue)",
160 NULL, NULL, NULL)) ||
161 (SQLITE_OK !=
162 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS it_iter ON ns096records (rvalue)",
155 NULL, NULL, NULL)) ) 163 NULL, NULL, NULL)) )
156 LOG (GNUNET_ERROR_TYPE_ERROR, 164 LOG (GNUNET_ERROR_TYPE_ERROR,
157 "Failed to create indices: %s\n", sqlite3_errmsg (dbh)); 165 "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
@@ -174,7 +182,7 @@ create_indices (sqlite3 * dbh)
174 * as needed as well). 182 * as needed as well).
175 * 183 *
176 * @param plugin the plugin context (state for this module) 184 * @param plugin the plugin context (state for this module)
177 * @return GNUNET_OK on success 185 * @return #GNUNET_OK on success
178 */ 186 */
179static int 187static int
180database_setup (struct Plugin *plugin) 188database_setup (struct Plugin *plugin)
@@ -317,7 +325,13 @@ database_setup (struct Plugin *plugin)
317 (plugin->dbh, 325 (plugin->dbh,
318 "SELECT record_count,record_data,label" 326 "SELECT record_count,record_data,label"
319 " FROM ns096records WHERE zone_private_key=? ORDER BY rvalue LIMIT 1 OFFSET ?", 327 " FROM ns096records WHERE zone_private_key=? ORDER BY rvalue LIMIT 1 OFFSET ?",
320 &plugin->iterate_zone) != SQLITE_OK) ) 328 &plugin->iterate_zone) != SQLITE_OK) ||
329 (sq_prepare
330 (plugin->dbh,
331 "SELECT record_count,record_data,label"
332 " FROM ns096records ORDER BY rvalue LIMIT 1 OFFSET ?",
333 &plugin->iterate_all_zones) != SQLITE_OK)
334 )
321 { 335 {
322 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); 336 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling");
323 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
@@ -760,14 +774,24 @@ namestore_sqlite_iterate_records (void *cls,
760{ 774{
761 struct Plugin *plugin = cls; 775 struct Plugin *plugin = cls;
762 sqlite3_stmt *stmt; 776 sqlite3_stmt *stmt;
777 int err;
763 778
764 stmt = plugin->iterate_zone; 779 if (NULL == zone)
765 // FIXME: does not hanlde NULL for zone! 780 {
766 if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, 781 stmt = plugin->iterate_all_zones;
767 zone, sizeof (struct GNUNET_CRYPTO_EccPrivateKey), 782 err = (SQLITE_OK != sqlite3_bind_int64 (stmt, 1,
768 SQLITE_STATIC)) || 783 offset));
769 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, 784 }
770 offset)) ) 785 else
786 {
787 stmt = plugin->iterate_zone;
788 err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1,
789 zone, sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
790 SQLITE_STATIC)) ||
791 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2,
792 offset)) );
793 }
794 if (err)
771 { 795 {
772 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 796 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
773 "sqlite3_bind_XXXX"); 797 "sqlite3_bind_XXXX");