/*
* This file is part of GNUnet
- * Copyright (C) 2009, 2011 Christian Grothoff (and other contributing authors)
+ * Copyright (C) 2009, 2011 GNUnet e.V.
*
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
#else
#define ENULL &e
#define ENULL_DEFINED 1
-#define CHECK(a) if (! a) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
+#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
#endif
{
sqlite3_stmt *stmt;
char *afsdir;
-
#if ENULL_DEFINED
char *e;
#endif
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "datastore-sqlite",
- "FILENAME", &afsdir))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datastore-sqlite",
+ "FILENAME",
+ &afsdir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "datastore-sqlite", "FILENAME");
+ "datastore-sqlite",
+ "FILENAME");
return GNUNET_SYSERR;
}
if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
{
- if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
+ if (GNUNET_OK !=
+ GNUNET_DISK_directory_create_for_file (afsdir))
{
GNUNET_break (0);
GNUNET_free (afsdir);
return GNUNET_SYSERR;
}
/* database is new or got deleted, reset payload to zero! */
- plugin->env->duc (plugin->env->cls, 0);
+ if (NULL != plugin->env->duc)
+ plugin->env->duc (plugin->env->cls,
+ 0);
}
/* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
plugin->fn = afsdir;
/* Open database and precompile statements */
- if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
+ if (SQLITE_OK !=
+ sqlite3_open (plugin->fn, &plugin->dbh))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
_("Unable to initialize SQLite: %s.\n"),
return GNUNET_SYSERR;
}
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA temp_store=MEMORY", NULL, NULL,
ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA synchronous=OFF", NULL, NULL,
ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA legacy_file_format=OFF", NULL, NULL,
ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL", NULL,
NULL, ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL,
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA page_size=4092", NULL, NULL,
ENULL));
- CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
+ CHECK (SQLITE_OK ==
+ sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
/* We have to do it here, because otherwise precompiling SQL might fail */
sq_prepare (plugin->dbh,
"SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
&stmt));
+
+ /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because
+ * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel
+ * we do math or inequality tests, so we can't handle the entire range of uint32_t.
+ * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
+ */
if ((sqlite3_step (stmt) == SQLITE_DONE) &&
(sqlite3_exec
(plugin->dbh,
switch (n)
{
case SQLITE_DONE:
- plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ if (NULL != plugin->env->duc)
+ plugin->env->duc (plugin->env->cls,
+ size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
"Stored new entry (%u bytes)\n",
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
* @param cls the plugin context (state for this module)
* @param uid unique identifier of the datum
* @param delta by how much should the priority
- * change? If priority + delta < 0 the
- * priority should be set to 0 (never go
- * negative).
+ * change?
* @param expire new expiration time should be the
* MAX of any existing expiration time and
* this value
static void
sqlite_plugin_update (void *cls,
uint64_t uid,
- int delta,
+ uint32_t delta,
struct GNUNET_TIME_Absolute expire,
PluginUpdateCont cont,
void *cont_cls)
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- if (GNUNET_OK == delete_by_rowid (plugin, rowid))
+ if ( (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
+ (NULL != plugin->env->duc) )
plugin->env->duc (plugin->env->cls,
-(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
break;
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)))
+ if ( (GNUNET_NO == ret) &&
+ (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
+ (NULL != plugin->env->duc) )
plugin->env->duc (plugin->env->cls,
-(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
return;