2015-01-08 18:37:20 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2020-01-19 19:21:58 +01:00
|
|
|
Copyright (C) 2014, 2015, 2016 Taler Systems SA
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2016-07-07 17:55:25 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
|
|
|
/**
|
2015-03-28 15:42:07 +01:00
|
|
|
* @file include/taler_pq_lib.h
|
2015-01-08 18:37:20 +01:00
|
|
|
* @brief helper functions for DB interactions
|
|
|
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
|
|
|
* @author Florian Dold
|
2015-01-26 11:04:46 +01:00
|
|
|
* @author Christian Grothoff
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
2015-03-27 19:58:40 +01:00
|
|
|
#ifndef TALER_PQ_LIB_H_
|
|
|
|
#define TALER_PQ_LIB_H_
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
#include <libpq-fe.h>
|
2016-03-19 15:23:11 +01:00
|
|
|
#include <jansson.h>
|
2016-02-06 17:39:18 +01:00
|
|
|
#include <gnunet/gnunet_pq_lib.h>
|
2015-01-08 18:37:20 +01:00
|
|
|
#include "taler_util.h"
|
|
|
|
|
2015-05-06 11:13:09 +02:00
|
|
|
/**
|
2015-05-06 11:47:12 +02:00
|
|
|
* Generate query parameter for a currency, consisting of the three
|
|
|
|
* components "value", "fraction" and "currency" in this order. The
|
|
|
|
* types must be a 64-bit integer, 32-bit integer and a
|
2015-06-10 16:31:29 +02:00
|
|
|
* #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
|
2015-05-06 11:13:09 +02:00
|
|
|
*
|
2015-05-09 17:04:56 +02:00
|
|
|
* @param x pointer to the query parameter to pass
|
2015-05-06 11:13:09 +02:00
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_QueryParam
|
2016-01-27 18:28:52 +01:00
|
|
|
TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
|
2015-01-26 11:04:46 +01:00
|
|
|
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-05-06 17:05:24 +02:00
|
|
|
/**
|
|
|
|
* Generate query parameter for a currency, consisting of the three
|
|
|
|
* components "value", "fraction" and "currency" in this order. The
|
|
|
|
* types must be a 64-bit integer, 32-bit integer and a
|
2015-06-10 16:31:29 +02:00
|
|
|
* #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
|
2015-05-06 17:05:24 +02:00
|
|
|
*
|
2015-05-09 17:04:56 +02:00
|
|
|
* @param x pointer to the query parameter to pass
|
2015-05-06 17:05:24 +02:00
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_QueryParam
|
2016-01-27 18:28:52 +01:00
|
|
|
TALER_PQ_query_param_amount (const struct TALER_Amount *x);
|
2015-05-06 17:05:24 +02:00
|
|
|
|
|
|
|
|
2015-06-10 16:31:29 +02:00
|
|
|
/**
|
|
|
|
* Generate query parameter for a JSON object (stored as a string
|
2015-06-10 17:39:34 +02:00
|
|
|
* in the DB). Note that @a x must really be a JSON object or array,
|
|
|
|
* passing just a value (string, integer) is not supported and will
|
|
|
|
* result in an abort.
|
2015-06-10 16:31:29 +02:00
|
|
|
*
|
|
|
|
* @param x pointer to the json object to pass
|
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_QueryParam
|
2015-06-10 16:31:29 +02:00
|
|
|
TALER_PQ_query_param_json (const json_t *x);
|
|
|
|
|
|
|
|
|
2017-11-30 17:17:37 +01:00
|
|
|
/**
|
|
|
|
* Generate query parameter for an absolute time value.
|
|
|
|
* In contrast to
|
|
|
|
* #GNUNET_PQ_query_param_absolute_time(), this function
|
|
|
|
* will abort (!) if the time given is not rounded!
|
|
|
|
* The database must store a 64-bit integer.
|
|
|
|
*
|
|
|
|
* @param x pointer to the query parameter to pass
|
|
|
|
*/
|
|
|
|
struct GNUNET_PQ_QueryParam
|
|
|
|
TALER_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate query parameter for an absolute time value.
|
|
|
|
* In contrast to
|
|
|
|
* #GNUNET_PQ_query_param_absolute_time(), this function
|
|
|
|
* will abort (!) if the time given is not rounded!
|
|
|
|
* The database must store a 64-bit integer.
|
|
|
|
*
|
|
|
|
* @param x pointer to the query parameter to pass
|
|
|
|
*/
|
|
|
|
struct GNUNET_PQ_QueryParam
|
2019-08-25 16:18:24 +02:00
|
|
|
TALER_PQ_query_param_absolute_time_nbo (const struct
|
|
|
|
GNUNET_TIME_AbsoluteNBO *x);
|
2017-11-30 17:17:37 +01:00
|
|
|
|
|
|
|
|
2015-05-06 11:47:12 +02:00
|
|
|
/**
|
|
|
|
* Currency amount expected.
|
|
|
|
*
|
|
|
|
* @param name name of the field in the table
|
2020-01-18 14:13:28 +01:00
|
|
|
* @param currency currency to use for @a amount
|
2015-05-10 22:38:34 +02:00
|
|
|
* @param[out] amount where to store the result
|
|
|
|
* @return array entry for the result specification to use
|
2015-05-06 11:47:12 +02:00
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_ResultSpec
|
2015-05-16 20:33:01 +02:00
|
|
|
TALER_PQ_result_spec_amount_nbo (const char *name,
|
2019-08-17 21:35:21 +02:00
|
|
|
const char *currency,
|
|
|
|
struct TALER_AmountNBO *amount);
|
2015-05-10 22:38:34 +02:00
|
|
|
|
2015-05-06 11:47:12 +02:00
|
|
|
|
2015-05-04 14:47:36 +02:00
|
|
|
/**
|
|
|
|
* Currency amount expected.
|
|
|
|
*
|
|
|
|
* @param name name of the field in the table
|
2020-01-18 14:13:28 +01:00
|
|
|
* @param currency currency to use for @a amount
|
2015-05-10 22:38:34 +02:00
|
|
|
* @param[out] amount where to store the result
|
|
|
|
* @return array entry for the result specification to use
|
2015-05-04 14:47:36 +02:00
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_ResultSpec
|
2015-05-16 20:33:01 +02:00
|
|
|
TALER_PQ_result_spec_amount (const char *name,
|
2019-08-17 21:35:21 +02:00
|
|
|
const char *currency,
|
|
|
|
struct TALER_Amount *amount);
|
2015-05-10 22:38:34 +02:00
|
|
|
|
2015-01-26 11:04:46 +01:00
|
|
|
|
2015-06-10 16:31:29 +02:00
|
|
|
/**
|
|
|
|
* json_t expected.
|
|
|
|
*
|
|
|
|
* @param name name of the field in the table
|
|
|
|
* @param[out] jp where to store the result
|
|
|
|
* @return array entry for the result specification to use
|
|
|
|
*/
|
2016-02-06 17:39:18 +01:00
|
|
|
struct GNUNET_PQ_ResultSpec
|
2015-06-10 16:31:29 +02:00
|
|
|
TALER_PQ_result_spec_json (const char *name,
|
|
|
|
json_t **jp);
|
|
|
|
|
|
|
|
|
2017-11-30 17:17:37 +01:00
|
|
|
/**
|
|
|
|
* Rounded absolute time expected.
|
|
|
|
* In contrast to #GNUNET_PQ_query_param_absolute_time_nbo(),
|
|
|
|
* this function ensures that the result is rounded and can
|
|
|
|
* be converted to JSON.
|
|
|
|
*
|
|
|
|
* @param name name of the field in the table
|
|
|
|
* @param[out] at where to store the result
|
|
|
|
* @return array entry for the result specification to use
|
|
|
|
*/
|
|
|
|
struct GNUNET_PQ_ResultSpec
|
|
|
|
TALER_PQ_result_spec_absolute_time (const char *name,
|
|
|
|
struct GNUNET_TIME_Absolute *at);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounded absolute time expected.
|
|
|
|
* In contrast to #GNUNET_PQ_result_spec_absolute_time_nbo(),
|
|
|
|
* this function ensures that the result is rounded and can
|
|
|
|
* be converted to JSON.
|
|
|
|
*
|
|
|
|
* @param name name of the field in the table
|
|
|
|
* @param[out] at where to store the result
|
|
|
|
* @return array entry for the result specification to use
|
|
|
|
*/
|
|
|
|
struct GNUNET_PQ_ResultSpec
|
|
|
|
TALER_PQ_result_spec_absolute_time_nbo (const char *name,
|
|
|
|
struct GNUNET_TIME_AbsoluteNBO *at);
|
|
|
|
|
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
#endif /* TALER_PQ_LIB_H_ */
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-05-06 11:13:09 +02:00
|
|
|
/* end of include/taler_pq_lib.h */
|