use big endian
[oweals/gnunet.git] / src / datastore / plugin_datastore_sqlite.c
index 6e20a74914d8606bcde938b51110475440e3ba1e..ca1f4e4ae607fda43ee135eb2130483ca79ea41e 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -29,7 +29,7 @@
 #include "plugin_datastore.h"
 #include <sqlite3.h>
 
-#define DEBUG_SQLITE GNUNET_YES
+#define DEBUG_SQLITE GNUNET_NO
 
 /**
  * After how many payload-changing operations
@@ -180,9 +180,9 @@ sq_prepare (sqlite3 * dbh, const char *zSql,
             sqlite3_stmt ** ppStmt)
 {
   char *dummy;
-  return sqlite3_prepare (dbh,
-                          zSql,
-                          strlen (zSql), ppStmt, (const char **) &dummy);
+  return sqlite3_prepare_v2 (dbh,
+                            zSql,
+                            strlen (zSql), ppStmt, (const char **) &dummy);
 }
 
 
@@ -756,7 +756,7 @@ sqlite_plugin_put (void *cls,
       (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
       (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) ||
       (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) ||
-      (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, (sqlite3_int64) expiration.value)) ||
+      (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.value)) ||
       (SQLITE_OK !=
        sqlite3_bind_blob (stmt, 6, key, sizeof (GNUNET_HashCode),
                           SQLITE_TRANSIENT)) ||
@@ -776,7 +776,7 @@ sqlite_plugin_put (void *cls,
       return GNUNET_SYSERR;
     }
   n = sqlite3_step (stmt);
-  if (n != SQLITE_DONE)
+  if (n != SQLITE_DONE) 
     {
       if (n == SQLITE_BUSY)
         {
@@ -1065,7 +1065,7 @@ basic_iter (struct Plugin *plugin,
     {
       LOG_SQLITE (plugin, NULL,
                   GNUNET_ERROR_TYPE_ERROR |
-                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
+                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
       iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
       return;
     }
@@ -1073,7 +1073,7 @@ basic_iter (struct Plugin *plugin,
     {
       LOG_SQLITE (plugin, NULL,
                   GNUNET_ERROR_TYPE_ERROR |
-                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
+                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
       sqlite3_finalize (stmt_1);
       iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
       return;
@@ -1315,7 +1315,7 @@ sqlite_plugin_iter_all_now (void *cls,
     {
       LOG_SQLITE (plugin, NULL,
                   GNUNET_ERROR_TYPE_ERROR |
-                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
+                  GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
       iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
       return;
     }
@@ -1616,14 +1616,15 @@ process_stat_done (void *cls,
   uint64_t page_size;
 
   plugin->stat_get = NULL;
-  if (plugin->stats_worked == GNUNET_NO)
-    {
+  if ( (plugin->stats_worked == GNUNET_NO) &&
+       (SQLITE_VERSION_NUMBER >= 3006000) )
+   {
       CHECK (SQLITE_OK ==
-            sq_prepare (plugin->dbh,
-                        "VACUUM;",
-                        &stmt));
-      sqlite3_step (stmt);
-      sqlite3_finalize (stmt);
+            sqlite3_exec (plugin->dbh,
+                          "VACUUM", NULL, NULL, ENULL));
+      CHECK (SQLITE_OK ==
+            sqlite3_exec (plugin->dbh,
+                          "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
       CHECK (SQLITE_OK ==
             sq_prepare (plugin->dbh,
                         "PRAGMA page_count",