gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29020 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r29020 - gnunet/src/namestore
Date: Thu, 5 Sep 2013 13:41:39 +0200

Author: grothoff
Date: 2013-09-05 13:41:39 +0200 (Thu, 05 Sep 2013)
New Revision: 29020

Modified:
   gnunet/src/namestore/plugin_namestore_sqlite.c
Log:
-implement iteration over all zones (#3016)

Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c      2013-09-05 11:40:07 UTC 
(rev 29019)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c      2013-09-05 11:41:39 UTC 
(rev 29020)
@@ -102,6 +102,11 @@
   sqlite3_stmt *iterate_zone;
 
   /**
+   * Precompiled SQL for iterate all records within all zones.
+   */
+  sqlite3_stmt *iterate_all_zones;
+
+  /**
    * Precompiled SQL to for reverse lookup based on PKEY.
    */
   sqlite3_stmt *zone_to_name;
@@ -152,6 +157,9 @@
                      NULL, NULL, NULL)) ||
        (SQLITE_OK !=
        sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON 
ns096records (zone_private_key,rvalue)",
+                     NULL, NULL, NULL)) ||
+       (SQLITE_OK !=
+       sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS it_iter ON ns096records 
(rvalue)",
                      NULL, NULL, NULL)) )
     LOG (GNUNET_ERROR_TYPE_ERROR, 
         "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
@@ -174,7 +182,7 @@
  * as needed as well).
  *
  * @param plugin the plugin context (state for this module)
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
  */
 static int
 database_setup (struct Plugin *plugin)
@@ -317,7 +325,13 @@
        (plugin->dbh,
        "SELECT record_count,record_data,label" 
        " FROM ns096records WHERE zone_private_key=? ORDER BY rvalue LIMIT 1 
OFFSET ?",
-       &plugin->iterate_zone) != SQLITE_OK) )
+       &plugin->iterate_zone) != SQLITE_OK) ||
+      (sq_prepare
+       (plugin->dbh,
+       "SELECT record_count,record_data,label" 
+       " FROM ns096records ORDER BY rvalue LIMIT 1 OFFSET ?",
+       &plugin->iterate_all_zones) != SQLITE_OK) 
+      )
   {
     LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling");
     return GNUNET_SYSERR;
@@ -760,15 +774,25 @@
 {
   struct Plugin *plugin = cls;
   sqlite3_stmt *stmt;
+  int err;
 
-  stmt = plugin->iterate_zone;
-  // FIXME: does not hanlde NULL for zone!
-  if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, 
-                                       zone, sizeof (struct 
GNUNET_CRYPTO_EccPrivateKey),
-                                       SQLITE_STATIC)) ||
-       (SQLITE_OK != sqlite3_bind_int64 (stmt, 2,
-                                        offset)) ) 
+  if (NULL == zone)
   {
+    stmt = plugin->iterate_all_zones;
+    err = (SQLITE_OK != sqlite3_bind_int64 (stmt, 1,
+                                           offset));
+  }
+  else
+  {
+    stmt = plugin->iterate_zone;
+    err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, 
+                                            zone, sizeof (struct 
GNUNET_CRYPTO_EccPrivateKey),
+                                            SQLITE_STATIC)) ||
+           (SQLITE_OK != sqlite3_bind_int64 (stmt, 2,
+                                             offset)) );
+  }
+  if (err)
+  {
     LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                "sqlite3_bind_XXXX");
     if (SQLITE_OK != sqlite3_reset (stmt))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]