diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-08-17 03:07:48 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-08-17 03:07:48 +0200 |
commit | 81af01a209b557a4996a50824ae2f1ec75c25eb5 (patch) | |
tree | d6b4411b42053350d39e422325113aeab73c68ad /src/mintdb/plugin_mintdb_postgres.c | |
parent | 86665a7c9fa0492353b22c18e1af47396038bc73 (diff) | |
download | exchange-81af01a209b557a4996a50824ae2f1ec75c25eb5.tar.xz |
fix DB logic: actually iterate where we need to
Diffstat (limited to 'src/mintdb/plugin_mintdb_postgres.c')
-rw-r--r-- | src/mintdb/plugin_mintdb_postgres.c | 115 |
1 files changed, 61 insertions, 54 deletions
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index beb1efb3e..aaa1c9016 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -2648,33 +2648,36 @@ postgres_insert_refresh_commit_links (void *cls, uint16_t num_links, const struct TALER_RefreshCommitLinkP *links) { - // FIXME: check logic! links is array! - struct TALER_PQ_QueryParam params[] = { - TALER_PQ_query_param_auto_from_type (session_hash), - TALER_PQ_query_param_auto_from_type (&links->transfer_pub), - TALER_PQ_query_param_uint16 (&cnc_index), - TALER_PQ_query_param_uint16 (&num_links), - TALER_PQ_query_param_auto_from_type (&links->shared_secret_enc), - TALER_PQ_query_param_end - }; + uint16_t i; - PGresult *result = TALER_PQ_exec_prepared (session->conn, - "insert_refresh_commit_link", - params); - if (PGRES_COMMAND_OK != PQresultStatus (result)) + for (i=0;i<num_links;i++) { - BREAK_DB_ERR (result); - PQclear (result); - return GNUNET_SYSERR; - } + struct TALER_PQ_QueryParam params[] = { + TALER_PQ_query_param_auto_from_type (session_hash), + TALER_PQ_query_param_auto_from_type (&links[i].transfer_pub), + TALER_PQ_query_param_uint16 (&cnc_index), + TALER_PQ_query_param_uint16 (&i), + TALER_PQ_query_param_auto_from_type (&links[i].shared_secret_enc), + TALER_PQ_query_param_end + }; - if (0 != strcmp ("1", PQcmdTuples (result))) - { - GNUNET_break (0); - return GNUNET_SYSERR; + PGresult *result = TALER_PQ_exec_prepared (session->conn, + "insert_refresh_commit_link", + params); + if (PGRES_COMMAND_OK != PQresultStatus (result)) + { + BREAK_DB_ERR (result); + PQclear (result); + return GNUNET_SYSERR; + } + + if (0 != strcmp ("1", PQcmdTuples (result))) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + PQclear (result); } - - PQclear (result); return GNUNET_OK; } @@ -2701,46 +2704,50 @@ postgres_get_refresh_commit_links (void *cls, uint16_t num_links, struct TALER_RefreshCommitLinkP *links) { - // FIXME: check logic: was written for a single link! - struct TALER_PQ_QueryParam params[] = { - TALER_PQ_query_param_auto_from_type (session_hash), - TALER_PQ_query_param_uint16 (&cnc_index), - TALER_PQ_query_param_uint16 (&num_links), - TALER_PQ_query_param_end - }; - PGresult *result; + uint16_t i; - result = TALER_PQ_exec_prepared (session->conn, - "get_refresh_commit_link", - params); - if (PGRES_TUPLES_OK != PQresultStatus (result)) - { - BREAK_DB_ERR (result); - PQclear (result); - return GNUNET_SYSERR; - } - if (0 == PQntuples (result)) + for (i=0;i<num_links;i++) { - PQclear (result); - return GNUNET_NO; - } - { - struct TALER_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_auto_from_type ("transfer_pub", - &links->transfer_pub), - TALER_PQ_result_spec_auto_from_type ("link_secret_enc", - &links->shared_secret_enc), - TALER_PQ_result_spec_end + struct TALER_PQ_QueryParam params[] = { + TALER_PQ_query_param_auto_from_type (session_hash), + TALER_PQ_query_param_uint16 (&cnc_index), + TALER_PQ_query_param_uint16 (&i), + TALER_PQ_query_param_end }; + PGresult *result; - if (GNUNET_YES != - TALER_PQ_extract_result (result, rs, 0)) + result = TALER_PQ_exec_prepared (session->conn, + "get_refresh_commit_link", + params); + if (PGRES_TUPLES_OK != PQresultStatus (result)) { + BREAK_DB_ERR (result); PQclear (result); return GNUNET_SYSERR; } + if (0 == PQntuples (result)) + { + PQclear (result); + return GNUNET_NO; + } + { + struct TALER_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_auto_from_type ("transfer_pub", + &links[i].transfer_pub), + TALER_PQ_result_spec_auto_from_type ("link_secret_enc", + &links[i].shared_secret_enc), + TALER_PQ_result_spec_end + }; + + if (GNUNET_YES != + TALER_PQ_extract_result (result, rs, 0)) + { + PQclear (result); + return GNUNET_SYSERR; + } + } + PQclear (result); } - PQclear (result); return GNUNET_OK; } |