commit c5cad65c87b7e41f2549c6ba83be6714f290e0dc
parent b783ce987fd5543532d61d9fbd483af9394ddc30
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Tue, 18 Apr 2017 13:42:34 +0200
adding db method to query proposal data "in the future"
Diffstat:
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
@@ -341,6 +341,21 @@ postgres_initialize (void *cls)
" LIMIT $4",
4);
+ PG_PREPARE (pg,
+ "find_proposal_data_by_date_and_range_future",
+ "SELECT"
+ " proposal_data"
+ ",order_id"
+ ",row_id"
+ " FROM merchant_proposal_data"
+ " WHERE"
+ " timestamp>$1"
+ " AND merchant_pub=$2"
+ " AND row_id>$3"
+ " ORDER BY row_id DESC, timestamp DESC"
+ " LIMIT $4",
+ 4);
+
/* Setup prepared "SELECT" statements */
PG_PREPARE (pg,
"find_transaction",
@@ -862,9 +877,14 @@ postgres_find_proposal_data_by_date_and_range (void *cls,
GNUNET_PQ_query_param_end
};
- result = GNUNET_PQ_exec_prepared (pg->conn,
- "find_proposal_data_by_date_and_range",
- params);
+ if (GNUNET_YES == future)
+ result = GNUNET_PQ_exec_prepared (pg->conn,
+ "find_proposal_data_by_date_and_range_future",
+ params);
+ else
+ result = GNUNET_PQ_exec_prepared (pg->conn,
+ "find_proposal_data_by_date_and_range",
+ params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result);
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
@@ -71,6 +71,12 @@ static struct GNUNET_HashCode h_wire;
const char *order_id;
/**
+ * Transaction ID used to test the db query
+ * `find_proposal_data_by_date_and_range_future`
+ */
+const char *order_id_future;
+
+/**
* Proposal's hash
*/
struct GNUNET_HashCode h_proposal_data;
@@ -326,10 +332,11 @@ run (void *cls)
RND_BLK (&h_wire);
RND_BLK (&h_proposal_data);
order_id = "test_ID";
+ order_id_future = "test_ID_future";
RND_BLK (&signkey_pub);
RND_BLK (&merchant_pub);
RND_BLK (&wtid);
- timestamp = GNUNET_TIME_absolute_get();
+ timestamp = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (×tamp);
delta = GNUNET_TIME_UNIT_MINUTES;
fake_now = GNUNET_TIME_absolute_add (timestamp, delta);
@@ -387,6 +394,25 @@ run (void *cls)
GNUNET_NO,
pd_cb,
NULL));
+ timestamp = GNUNET_TIME_absolute_get ();
+ GNUNET_TIME_round_abs (×tamp);
+
+ FAILIF (GNUNET_OK !=
+ plugin->insert_proposal_data (plugin->cls,
+ order_id_future,
+ &merchant_pub,
+ timestamp,
+ proposal_data));
+
+ FAILIF (1 !=
+ plugin->find_proposal_data_by_date_and_range (plugin->cls,
+ fake_now,
+ &merchant_pub,
+ 0,
+ 5,
+ GNUNET_YES,
+ pd_cb,
+ NULL));
FAILIF (1 !=
plugin->find_proposal_data_by_date (plugin->cls,