diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-04 14:47:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-04 14:47:36 +0200 |
commit | 4af6cbb3757a3be555b8dfec58cf1bd50afcd609 (patch) | |
tree | 1468cd91ff48c16733c0767fe390affba8256300 | |
parent | ad237521e982352d41127f8c19576a5a242dbbbd (diff) | |
download | exchange-4af6cbb3757a3be555b8dfec58cf1bd50afcd609.tar.xz |
-working a bit on DB, starting to adjust libtalerpq API, not done yet
-rw-r--r-- | src/include/taler_pq_lib.h | 54 | ||||
-rw-r--r-- | src/mintdb/plugin_mintdb_postgres.c | 52 |
2 files changed, 100 insertions, 6 deletions
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h index 0db30f1a0..6d4ac8cb8 100644 --- a/src/include/taler_pq_lib.h +++ b/src/include/taler_pq_lib.h @@ -72,10 +72,45 @@ struct TALER_PQ_QueryParam /** + * Different formats of results that can be extracted. + */ +enum TALER_PQ_ResultFormat +{ + + /** + * List terminator. + */ + TALER_PQ_RF_END, + + /** + * We have a fixed-size result (binary blob, no endianess conversion). + */ + TALER_PQ_RF_FIXED_BLOB, + + /** + * We have a variable-size result (binary blob, no endianess conversion). + */ + TALER_PQ_RF_VARSIZE_BLOB, + + /** + * We have a currency amount (with endianess conversion). + * Data points to a `struct TALER_Amount`, size is not used. + */ + TALER_PQ_RF_AMOUNT +}; + + +/** * @brief Description of a DB result cell. */ struct TALER_PQ_ResultSpec { + + /** + * What is the format of the result? + */ + enum TALER_PQ_ResultFormat format; + /** * Destination for the data. */ @@ -104,7 +139,7 @@ struct TALER_PQ_ResultSpec /** * End of result parameter specification. */ -#define TALER_PQ_RESULT_SPEC_END { NULL, 0, NULL, NULL } +#define TALER_PQ_RESULT_SPEC_END { TALER_PQ_RF_END, NULL, 0, NULL, NULL } /** * We expect a fixed-size result, with size given explicitly @@ -113,7 +148,7 @@ struct TALER_PQ_ResultSpec * @param dst point to where to store the result * @param s number of bytes we should use in @a dst */ -#define TALER_PQ_RESULT_SPEC_SIZED(name, dst, s) { (void *) (dst), (s), (name), NULL } +#define TALER_PQ_RESULT_SPEC_SIZED(name, dst, s) { TALER_PQ_RF_FIXED_BLOB, (void *) (dst), (s), (name), NULL } /** @@ -132,7 +167,16 @@ struct TALER_PQ_ResultSpec * @param dst where to store the result (of type void **), to be allocated * @param sptr pointer to a `size_t` for where to store the size of @a dst */ -#define TALER_PQ_RESULT_SPEC_VAR(name, dst, sptr) { (void *) (dst), 0, (name), sptr } +#define TALER_PQ_RESULT_SPEC_VAR(name, dst, sptr) {TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, (name), sptr } + + +/** + * Currency amount expected. + * + * @param name name of the field in the table + * @param amount a `struct TALER_Amount` where to store the result + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT(name, amount) {TALER_PQ_RF_AMOUNT, (void *) (&dst), 0, (name), sptr } /** @@ -170,7 +214,7 @@ TALER_PQ_extract_result (PGresult *result, /** * Extract a currency amount from a query result according to the - * given specification. + * given specification. * * @param result the result to extract the amount from * @param row which row of the result to extract the amount from (needed as results can have multiple rows) @@ -194,7 +238,7 @@ TALER_PQ_extract_amount_nbo (PGresult *result, /** * Extract a currency amount from a query result according to the - * given specification. + * given specification. * * @param result the result to extract the amount from * @param row which row of the result to extract the amount from (needed as results can have multiple rows) diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index 56ba1bbde..e9c127d62 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -292,7 +292,15 @@ postgres_create_tables (void *cls, "(" " session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) " ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) " + ",coin_sig BYTEA NOT NULL " ",denom_pub BYTEA NOT NULL " + ",denom_sig BYTEA NOT NULL " + ",amount_value INT8 NOT NULL " + ",amount_fraction INT8 NOT NULL " + ",amount_currency VARCHAR(4) NOT NULL " + ",fee_value INT8 NOT NULL " + ",fee_fraction INT8 NOT NULL " + ",fee_currency VARCHAR(4) NOT NULL " ",oldcoin_index INT2 NOT NULL" ")"); SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_collectable" @@ -513,7 +521,15 @@ postgres_prepare (PGconn *db_conn) " session_hash " ",oldcoin_index " ",coin_pub " + ",coin_sig " ",denom_pub " + ",denom_sig " + ",amount_value " + ",amount_fraction " + ",amount_currency " + ",fee_value " + ",fee_fraction " + ",fee_currency " ") " "VALUES ($1, $2, $3, $4) ", 3, NULL); @@ -528,7 +544,7 @@ postgres_prepare (PGconn *db_conn) "WHERE session_hash = $1 AND newcoin_index = $2", 2, NULL); PREPARE ("get_refresh_melt", - "SELECT coin_pub " + "SELECT coin_pub,coin_sig,denom_pub,denom_sig,amount_value,amount_fraction,amount_currency,free_value,fee_fraction,fee_currency " "FROM refresh_melt " "WHERE session_hash = $1 AND oldcoin_index = $2", 2, NULL); @@ -1740,7 +1756,41 @@ postgres_get_refresh_melt (void *cls, uint16_t oldcoin_index, struct TALER_MINTDB_RefreshMelt *melt) { +#if 0 // FIXME: check logic! + uint16_t oldcoin_index_nbo = htons (oldcoin_index); + struct TALER_PQ_Query params[] = { + TALER_PQ_QUERY_PARAM_PTR (session_hash), + TALER_PQ_QUERY_PARAM_PTR (&oldcoin_index_nbo), + TALER_PQ_QUERY_PARAM_END + }; + struct TALER_PQ_ResultSpec rs[] = { + TALER_PQ_RESULT_SPEC ("coin_pub", &melt->coin), + TALER_PQ_RESULT_SPEC ("coin_sig", &melt->coin_sig), + TALER_PQ_RESULT_SPEC ("denom_pub", &melt->coin), + TALER_PQ_RESULT_SPEC ("denom_sig", &melt->coin), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &melt->amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee", &melt->melt_fee), + TALER_PQ_RESULT_SPEC_END + }; + + result = TALER_PQ_exec_prepared (session->conn, + "get_refresh_melt", + params); + if (0 == PQntuples (result)) + { + PQclear (result); + return GNUNET_SYSERR; + } + if (1 != PQntuples (result)) + { + PQclear (result); + GNUNET_break (0); + return GNUNET_SYSERR; + } +#endif + melt->session_hash = *session_hash; + GNUNET_break (0); return GNUNET_SYSERR; } |