diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-17 00:45:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-17 00:45:04 +0000 |
commit | 7e3e0f1137bf93517c26300d1229fa6533f35df2 (patch) | |
tree | 0a956aab88b72233200c70fee9d3c7214f013740 /src/datastore/plugin_datastore_postgres.c | |
parent | 589fbaabd2bb6af9675243d34d244b9cb8b83dd5 (diff) | |
download | gnunet-7e3e0f1137bf93517c26300d1229fa6533f35df2.tar.gz gnunet-7e3e0f1137bf93517c26300d1229fa6533f35df2.zip |
-implementing get_keys for postgres
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 0b781485f..16393c23c 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -317,6 +317,9 @@ init_connection (struct Plugin *plugin) | |||
317 | "ORDER BY repl DESC,RANDOM() LIMIT 1", 0, __LINE__)) || | 317 | "ORDER BY repl DESC,RANDOM() LIMIT 1", 0, __LINE__)) || |
318 | (GNUNET_OK != | 318 | (GNUNET_OK != |
319 | pq_prepare (plugin, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, | 319 | pq_prepare (plugin, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, |
320 | __LINE__)) || | ||
321 | (GNUNET_OK != | ||
322 | pq_prepare (plugin, "get_keys", "SELECT hash FROM gn090", 0, | ||
320 | __LINE__))) | 323 | __LINE__))) |
321 | { | 324 | { |
322 | PQfinish (plugin->dbh); | 325 | PQfinish (plugin->dbh); |
@@ -933,6 +936,40 @@ postgres_plugin_update (void *cls, uint64_t uid, int delta, | |||
933 | } | 936 | } |
934 | 937 | ||
935 | 938 | ||
939 | |||
940 | /** | ||
941 | * Get all of the keys in the datastore. | ||
942 | * | ||
943 | * @param cls closure | ||
944 | * @param proc function to call on each key | ||
945 | * @param proc_cls closure for proc | ||
946 | */ | ||
947 | static void | ||
948 | postgres_plugin_get_keys (void *cls, | ||
949 | PluginKeyProcessor proc, | ||
950 | void *proc_cls) | ||
951 | { | ||
952 | struct Plugin *plugin = cls; | ||
953 | int ret; | ||
954 | int i; | ||
955 | GNUNET_HashCode key; | ||
956 | PGresult * res; | ||
957 | |||
958 | res = PQexecPrepared (plugin->dbh, "get_keys", 0, NULL, NULL, NULL, 1); | ||
959 | ret = PQntuples (res); | ||
960 | for (i=0;i<ret;i++) | ||
961 | { | ||
962 | if (sizeof (GNUNET_HashCode) != PQgetlength (res, i, 0)) | ||
963 | { | ||
964 | memcpy (&key, PQgetvalue (res, i, 0), sizeof (GNUNET_HashCode)); | ||
965 | proc (proc_cls, &key, 1); | ||
966 | } | ||
967 | } | ||
968 | PQclear (res); | ||
969 | } | ||
970 | |||
971 | |||
972 | |||
936 | /** | 973 | /** |
937 | * Drop database. | 974 | * Drop database. |
938 | */ | 975 | */ |
@@ -974,6 +1011,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls) | |||
974 | api->get_replication = &postgres_plugin_get_replication; | 1011 | api->get_replication = &postgres_plugin_get_replication; |
975 | api->get_expiration = &postgres_plugin_get_expiration; | 1012 | api->get_expiration = &postgres_plugin_get_expiration; |
976 | api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; | 1013 | api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; |
1014 | api->get_keys = &postgres_plugin_get_keys; | ||
977 | api->drop = &postgres_plugin_drop; | 1015 | api->drop = &postgres_plugin_drop; |
978 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres", | 1016 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres", |
979 | _("Postgres database running\n")); | 1017 | _("Postgres database running\n")); |