summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-03-04 11:19:04 +0100
committerChristian Grothoff <christian@grothoff.org>2021-03-04 11:19:04 +0100
commit39232092eb3038d720d81e6b7891f6bdd7c048f0 (patch)
tree6144b4c0f12f7074a2e8971048ac05657c2ce259
parent9f9d2470b6363fc1070fe3004154e65746cd9ea5 (diff)
downloadmerchant-39232092eb3038d720d81e6b7891f6bdd7c048f0.tar.gz
merchant-39232092eb3038d720d81e6b7891f6bdd7c048f0.tar.bz2
merchant-39232092eb3038d720d81e6b7891f6bdd7c048f0.zip
fix #6782
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c133
1 files changed, 86 insertions, 47 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index f4394a7e..e39d8498 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4301,37 +4301,6 @@ postgres_lookup_transfers (void *cls,
{
struct PostgresClosure *pg = cls;
uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
- struct GNUNET_PQ_QueryParam params_payto_et[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_absolute_time (&before),
- GNUNET_PQ_query_param_absolute_time (&after),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_QueryParam params_et[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_absolute_time (&before),
- GNUNET_PQ_query_param_absolute_time (&after),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_QueryParam params_payto[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_QueryParam params_none[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_uint64 (&offset),
- GNUNET_PQ_query_param_uint64 (&plimit),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_QueryParam *params;
struct LookupTransfersContext ltc = {
.cb = cb,
.cb_cls = cb_cls,
@@ -4339,27 +4308,97 @@ postgres_lookup_transfers (void *cls,
.verified = verified
};
enum GNUNET_DB_QueryStatus qs;
- char stmt[128];
bool by_time;
by_time = ( (before.abs_value_us !=
GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) ||
- (after.abs_value_us != GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us) );
+ (after.abs_value_us !=
+ GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us) );
check_connection (pg);
- GNUNET_snprintf (stmt,
- sizeof (stmt),
- "lookup_transfers%s%s%s",
- (by_time) ? "_time" : "",
- (NULL != payto_uri) ? "_payto" : "",
- (limit > 0) ? "_asc" : "_desc");
- params = (by_time)
- ? ( (NULL != payto_uri) ? params_payto_et : params_et)
- : ( (NULL != payto_uri) ? params_payto : params_none);
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- stmt,
- params,
- &lookup_transfers_cb,
- &ltc);
+ if (by_time)
+ {
+ if (NULL != payto_uri)
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_absolute_time (&before),
+ GNUNET_PQ_query_param_absolute_time (&after),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "lookup_transfers_time_payto_asc"
+ : "lookup_transfers_time_payto_desc",
+ params,
+ &lookup_transfers_cb,
+ &ltc);
+ }
+ else
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_absolute_time (&before),
+ GNUNET_PQ_query_param_absolute_time (&after),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "lookup_transfers_time_asc"
+ : "lookup_transfers_time_desc",
+ params,
+ &lookup_transfers_cb,
+ &ltc);
+ }
+ }
+ else
+ {
+ if (NULL != payto_uri)
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "lookup_transfers_payto_asc"
+ : "lookup_transfers_payto_desc",
+ params,
+ &lookup_transfers_cb,
+ &ltc);
+ }
+ else
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_uint64 (&offset),
+ GNUNET_PQ_query_param_uint64 (&plimit),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ (limit > 0)
+ ? "lookup_transfers_asc"
+ : "lookup_transfers_desc",
+ params,
+ &lookup_transfers_cb,
+ &ltc);
+ }
+ }
if (0 >= qs)
return qs;
return ltc.qs;