diff options
Diffstat (limited to 'src/mint/mint_db.c')
-rw-r--r-- | src/mint/mint_db.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index c07490805..35f803e1b 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c | |||
@@ -2007,7 +2007,7 @@ db_conn_destroy (void *cls) | |||
2007 | * Initialize database subsystem. | 2007 | * Initialize database subsystem. |
2008 | * | 2008 | * |
2009 | * @param connection_cfg configuration to use to talk to DB | 2009 | * @param connection_cfg configuration to use to talk to DB |
2010 | * @return GNUNET_OK on success | 2010 | * @return #GNUNET_OK on success |
2011 | */ | 2011 | */ |
2012 | int | 2012 | int |
2013 | TALER_MINT_DB_init (const char *connection_cfg) | 2013 | TALER_MINT_DB_init (const char *connection_cfg) |
@@ -2022,3 +2022,42 @@ TALER_MINT_DB_init (const char *connection_cfg) | |||
2022 | TALER_MINT_db_connection_cfg_str = GNUNET_strdup (connection_cfg); | 2022 | TALER_MINT_db_connection_cfg_str = GNUNET_strdup (connection_cfg); |
2023 | return GNUNET_OK; | 2023 | return GNUNET_OK; |
2024 | } | 2024 | } |
2025 | |||
2026 | |||
2027 | int | ||
2028 | TALER_TALER_DB_extract_amount_nbo (PGresult *result, | ||
2029 | unsigned int row, | ||
2030 | int indices[3], | ||
2031 | struct TALER_AmountNBO *denom_nbo) | ||
2032 | { | ||
2033 | if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0)) | ||
2034 | return GNUNET_NO; | ||
2035 | if (sizeof (uint32_t) != PQgetlength (result, row, indices[0])) | ||
2036 | return GNUNET_SYSERR; | ||
2037 | if (sizeof (uint32_t) != PQgetlength (result, row, indices[1])) | ||
2038 | return GNUNET_SYSERR; | ||
2039 | if (PQgetlength (result, row, indices[2]) > TALER_CURRENCY_LEN) | ||
2040 | return GNUNET_SYSERR; | ||
2041 | denom_nbo->value = *(uint32_t *) PQgetvalue (result, row, indices[0]); | ||
2042 | denom_nbo->fraction = *(uint32_t *) PQgetvalue (result, row, indices[1]); | ||
2043 | memset (denom_nbo->currency, 0, TALER_CURRENCY_LEN); | ||
2044 | memcpy (denom_nbo->currency, PQgetvalue (result, row, indices[2]), PQgetlength (result, row, indices[2])); | ||
2045 | return GNUNET_OK; | ||
2046 | } | ||
2047 | |||
2048 | |||
2049 | int | ||
2050 | TALER_TALER_DB_extract_amount (PGresult *result, | ||
2051 | unsigned int row, | ||
2052 | int indices[3], | ||
2053 | struct TALER_Amount *denom) | ||
2054 | { | ||
2055 | struct TALER_AmountNBO denom_nbo; | ||
2056 | int res; | ||
2057 | |||
2058 | res = TALER_TALER_DB_extract_amount_nbo (result, row, indices, &denom_nbo); | ||
2059 | if (GNUNET_OK != res) | ||
2060 | return res; | ||
2061 | *denom = TALER_amount_ntoh (denom_nbo); | ||
2062 | return GNUNET_OK; | ||
2063 | } | ||