aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-12-17 00:45:04 +0000
committerChristian Grothoff <christian@grothoff.org>2011-12-17 00:45:04 +0000
commit7e3e0f1137bf93517c26300d1229fa6533f35df2 (patch)
tree0a956aab88b72233200c70fee9d3c7214f013740 /src/datastore/plugin_datastore_postgres.c
parent589fbaabd2bb6af9675243d34d244b9cb8b83dd5 (diff)
-implementing get_keys for postgres
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r--src/datastore/plugin_datastore_postgres.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 0b781485fb..16393c23c2 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -317,6 +317,9 @@ init_connection (struct Plugin *plugin)
"ORDER BY repl DESC,RANDOM() LIMIT 1", 0, __LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1,
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_prepare (plugin, "get_keys", "SELECT hash FROM gn090", 0,
__LINE__)))
{
PQfinish (plugin->dbh);
@@ -933,6 +936,40 @@ postgres_plugin_update (void *cls, uint64_t uid, int delta,
}
+
+/**
+ * Get all of the keys in the datastore.
+ *
+ * @param cls closure
+ * @param proc function to call on each key
+ * @param proc_cls closure for proc
+ */
+static void
+postgres_plugin_get_keys (void *cls,
+ PluginKeyProcessor proc,
+ void *proc_cls)
+{
+ struct Plugin *plugin = cls;
+ int ret;
+ int i;
+ GNUNET_HashCode key;
+ PGresult * res;
+
+ res = PQexecPrepared (plugin->dbh, "get_keys", 0, NULL, NULL, NULL, 1);
+ ret = PQntuples (res);
+ for (i=0;i<ret;i++)
+ {
+ if (sizeof (GNUNET_HashCode) != PQgetlength (res, i, 0))
+ {
+ memcpy (&key, PQgetvalue (res, i, 0), sizeof (GNUNET_HashCode));
+ proc (proc_cls, &key, 1);
+ }
+ }
+ PQclear (res);
+}
+
+
+
/**
* Drop database.
*/
@@ -974,6 +1011,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
api->get_replication = &postgres_plugin_get_replication;
api->get_expiration = &postgres_plugin_get_expiration;
api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
+ api->get_keys = &postgres_plugin_get_keys;
api->drop = &postgres_plugin_drop;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres",
_("Postgres database running\n"));