- indent
[oweals/gnunet.git] / src / namestore / plugin_namestore_postgres.c
index 1daf0c7c1bfe57d54f83fcba0472f98857c1ad93..3cddc952de5c9d3092bded12029e3124b436c19e 100644 (file)
@@ -113,7 +113,28 @@ database_setup (struct Plugin *plugin)
                                         "namestore-postgres");
   if (NULL == plugin->dbh)
     return GNUNET_SYSERR;
-  res =
+  if (GNUNET_YES == 
+      GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg,
+                                           "namestore-postgres",
+                                           "TEMPORARY_TABLE"))
+  {
+    res =
+      PQexec (plugin->dbh,
+              "CREATE TEMPORARY TABLE ns091records ("
+             " zone_key BYTEA NOT NULL DEFAULT ''," 
+             " zone_delegation BYTEA NOT NULL DEFAULT ''," 
+             " zone_hash BYTEA NOT NULL DEFAULT ''," 
+             " record_count INTEGER NOT NULL DEFAULT 0,"
+             " record_data BYTEA NOT NULL DEFAULT '',"
+             " block_expiration_time BIGINT NOT NULL DEFAULT 0," 
+             " signature BYTEA NOT NULL DEFAULT '',"
+             " record_name TEXT NOT NULL DEFAULT ''," 
+             " record_name_hash BYTEA NOT NULL DEFAULT ''," 
+             " rvalue BIGINT NOT NULL DEFAULT 0"
+             ")" "WITH OIDS");
+  }
+  else
+    res =
       PQexec (plugin->dbh,
               "CREATE TABLE ns091records ("
              " zone_key BYTEA NOT NULL DEFAULT ''," 
@@ -127,6 +148,7 @@ database_setup (struct Plugin *plugin)
              " record_name_hash BYTEA NOT NULL DEFAULT ''," 
              " rvalue BIGINT NOT NULL DEFAULT 0"
              ")" "WITH OIDS");
+
   if ((NULL == res) || ((PQresultStatus (res) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07",    /* duplicate table */
                                                                                     PQresultErrorField
                                                                                     (res,
@@ -142,11 +164,10 @@ database_setup (struct Plugin *plugin)
     create_indices (plugin->dbh);
   PQclear (res);
 
-#define ALL "zone_key, record_name, record_count, record_data, block_expiration_time, signature"
   if ((GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "put_records",
-                               "INSERT INTO ns091records (" ALL 
+                               "INSERT INTO ns091records (zone_key, record_name, record_count, record_data, block_expiration_time, signature" 
                                ", zone_delegation, zone_hash, record_name_hash, rvalue) VALUES "
                                "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", 10)) ||
       (GNUNET_OK !=
@@ -156,27 +177,27 @@ database_setup (struct Plugin *plugin)
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "iterate_records",
-                               "SELECT " ALL
+                               "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" 
                                " FROM ns091records WHERE zone_hash=$1 AND record_name_hash=$2 ORDER BY rvalue LIMIT 1 OFFSET $3", 3)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "iterate_by_zone",
-                               "SELECT " ALL
+                               "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" 
                                " FROM ns091records WHERE zone_hash=$1 ORDER BY rvalue  LIMIT 1 OFFSET $2", 2)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "iterate_by_name",
-                               "SELECT " ALL 
+                               "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" 
                                " FROM ns091records WHERE record_name_hash=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "iterate_all",
-                               "SELECT " ALL
+                               "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" 
                                " FROM ns091records ORDER BY rvalue LIMIT 1 OFFSET $1", 1)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
                                "zone_to_name",
-                               "SELECT " ALL
+                               "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature"
                                " FROM ns091records WHERE zone_hash=$1 AND zone_delegation=$2", 2)) ||
       (GNUNET_OK !=
        GNUNET_POSTGRES_prepare (plugin->dbh,
@@ -187,7 +208,6 @@ database_setup (struct Plugin *plugin)
     plugin->dbh = NULL;
     return GNUNET_SYSERR;
   }
-#undef ALL
   return GNUNET_OK;
 }
 
@@ -348,6 +368,7 @@ namestore_postgres_put_records (void *cls,
  * @param iter iterator to call with the result
  * @param iter_cls closure for 'iter'
  * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
+ *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
  */
 static int
 get_record_and_call_iterator (struct Plugin *plugin,
@@ -380,6 +401,7 @@ get_record_and_call_iterator (struct Plugin *plugin,
     LOG (GNUNET_ERROR_TYPE_DEBUG, 
         "Ending iteration (no more results)\n");
     PQclear (res);
+    iter (iter_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
     return GNUNET_NO;
   }
   GNUNET_assert (1 == cnt);
@@ -443,6 +465,7 @@ get_record_and_call_iterator (struct Plugin *plugin,
  * @param iter function to call with the result
  * @param iter_cls closure for iter
  * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
+ *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
  */
 static int 
 namestore_postgres_iterate_records (void *cls, 
@@ -521,6 +544,7 @@ namestore_postgres_iterate_records (void *cls,
  * @param iter function to call with the result
  * @param iter_cls closure for iter
  * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
+ *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
  */
 static int
 namestore_postgres_zone_to_name (void *cls,