[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 02/02: Do singleton select statements
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 02/02: Do singleton select statements |
Date: |
Sat, 03 Jun 2017 23:18:11 +0200 |
This is an automated email from the git hooks/post-receive script.
burdges pushed a commit to branch master
in repository gnunet.
commit 1a90e7878a8fa1f5b30421bd3045cf5d6d3e13e4
Author: Jeffrey Burdges <address@hidden>
AuthorDate: Sat Jun 3 23:16:28 2017 +0200
Do singleton select statements
---
src/psycstore/plugin_psycstore_postgres.c | 119 +++++-------------------------
1 file changed, 20 insertions(+), 99 deletions(-)
diff --git a/src/psycstore/plugin_psycstore_postgres.c
b/src/psycstore/plugin_psycstore_postgres.c
index cd933667f..f23b75a0c 100644
--- a/src/psycstore/plugin_psycstore_postgres.c
+++ b/src/psycstore/plugin_psycstore_postgres.c
@@ -556,13 +556,10 @@ membership_test (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id)
{
- PGresult *res;
struct Plugin *plugin = cls;
uint32_t did_join = 0;
- int ret = GNUNET_SYSERR;
-
struct GNUNET_PQ_QueryParam params_select[] = {
GNUNET_PQ_query_param_auto_from_type (channel_key),
GNUNET_PQ_query_param_auto_from_type (slave_key),
@@ -570,35 +567,17 @@ membership_test (void *cls,
GNUNET_PQ_query_param_end
};
- res = GNUNET_PQ_exec_prepared (plugin->dbh, "select_membership",
params_select);
- if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", "select_membership"))
- {
- return GNUNET_SYSERR;
- }
-
struct GNUNET_PQ_ResultSpec results_select[] = {
GNUNET_PQ_result_spec_uint32 ("did_join", &did_join),
GNUNET_PQ_result_spec_end
};
- switch (GNUNET_PQ_extract_result (res, results_select, 0))
- {
- case GNUNET_OK:
- ret = GNUNET_YES;
- break;
+ if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh,
"select_membership",
+ params_select, results_select))
+ return GNUNET_SYSERR;
- default:
- ret = GNUNET_NO;
- break;
- }
-
- PQclear (res);
-
- return ret;
+ return GNUNET_OK;
}
/**
@@ -1002,7 +981,6 @@ counters_message_get (void *cls,
uint64_t *max_message_id,
uint64_t *max_group_generation)
{
- PGresult *res;
struct Plugin *plugin = cls;
const char *stmt = "select_counters_message";
@@ -1012,15 +990,6 @@ counters_message_get (void *cls,
GNUNET_PQ_query_param_end
};
- res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
- if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", stmt))
- {
- return GNUNET_SYSERR;
- }
-
struct GNUNET_PQ_ResultSpec results_select[] = {
GNUNET_PQ_result_spec_uint64 ("fragment_id", max_fragment_id),
GNUNET_PQ_result_spec_uint64 ("message_id", max_message_id),
@@ -1028,14 +997,10 @@ counters_message_get (void *cls,
GNUNET_PQ_result_spec_end
};
- if (GNUNET_OK != GNUNET_PQ_extract_result (res, results_select, 0))
- {
- PQclear (res);
- return GNUNET_SYSERR;
- }
-
- GNUNET_PQ_cleanup_result(results_select);
- PQclear (res);
+ if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
+ params_select, results_select))
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -1052,44 +1017,26 @@ counters_state_get (void *cls,
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
uint64_t *max_state_message_id)
{
- PGresult *res;
struct Plugin *plugin = cls;
const char *stmt = "select_counters_state";
- int ret = GNUNET_SYSERR;
-
struct GNUNET_PQ_QueryParam params_select[] = {
GNUNET_PQ_query_param_auto_from_type (channel_key),
GNUNET_PQ_query_param_end
};
- res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
- if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", stmt))
- {
- return GNUNET_SYSERR;
- }
-
struct GNUNET_PQ_ResultSpec results_select[] = {
GNUNET_PQ_result_spec_uint64 ("max_state_message_id",
max_state_message_id),
GNUNET_PQ_result_spec_end
};
- ret = GNUNET_PQ_extract_result (res, results_select, 0);
-
- if (GNUNET_OK != ret)
- {
- PQclear (res);
- return GNUNET_SYSERR;
- }
-
- GNUNET_PQ_cleanup_result(results_select);
- PQclear (res);
+ if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
+ params_select, results_select))
+ return GNUNET_SYSERR;
- return ret;
+ return GNUNET_OK;
}
@@ -1343,10 +1290,7 @@ static int
state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
const char *name, GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls)
{
- PGresult *res;
-
struct Plugin *plugin = cls;
- int ret = GNUNET_SYSERR;
const char *stmt = "select_state_one";
@@ -1359,41 +1303,18 @@ state_get (void *cls, const struct
GNUNET_CRYPTO_EddsaPublicKey *channel_key,
void *value_current = NULL;
size_t value_size = 0;
- struct GNUNET_PQ_ResultSpec results[] = {
+ struct GNUNET_PQ_ResultSpec results_select[] = {
GNUNET_PQ_result_spec_variable_size ("value_current", &value_current,
&value_size),
GNUNET_PQ_result_spec_end
};
- res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
- if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", stmt))
- {
- return GNUNET_SYSERR;
- }
-
- if (PQntuples (res) == 0)
- {
- PQclear (res);
- ret = GNUNET_NO;
- }
+ if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
+ params_select, results_select))
+ return GNUNET_SYSERR;
- ret = GNUNET_PQ_extract_result (res, results, 0);
-
- if (GNUNET_OK != ret)
- {
- PQclear (res);
- return GNUNET_SYSERR;
- }
-
- ret = cb (cb_cls, name, value_current,
+ return cb (cb_cls, name, value_current,
value_size);
-
- GNUNET_PQ_cleanup_result(results);
- PQclear (res);
-
- return ret;
}
--
To stop receiving notification emails like this one, please contact
address@hidden