2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
18 * @brief helper functions for Sqlite3 DB interactions
19 * @author Christian Grothoff
22 #include "gnunet_sq_lib.h"
26 * Execute a prepared statement.
28 * @param db_conn database connection
29 * @param params parameters to the statement
30 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
33 GNUNET_SQ_bind (sqlite3_stmt *stmt,
34 const struct GNUNET_SQ_QueryParam *params)
39 for (unsigned int i=0;NULL != params[i].conv; i++)
42 params[i].conv (params[i].conv_cls,
48 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
50 _("Failure to bind %u-th SQL parameter\n"),
54 GNUNET_assert (0 != params[i].num_params);
55 j += params[i].num_params;
62 * Extract results from a query result according to the given specification.
64 * @param result result to process
65 * @param[in,out] rs result specification to extract for
67 * #GNUNET_OK if all results could be extracted
68 * #GNUNET_SYSERR if a result was invalid (non-existing field)
71 GNUNET_SQ_extract_result (sqlite3_stmt *result,
72 struct GNUNET_SQ_ResultSpec *rs)
76 for (unsigned int i=0;NULL != rs[i].conv; i++)
78 if (NULL == rs[i].result_size)
79 rs[i].result_size = &rs[i].dst_size;
81 rs[i].conv (rs[i].cls,
87 GNUNET_assert (0 != rs[i].num_params);
88 j += rs[i].num_params;
95 * Free all memory that was allocated in @a rs during
96 * #GNUNET_SQ_extract_result().
98 * @param rs reult specification to clean up
101 GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs)
103 for (unsigned int i=0;NULL != rs[i].conv; i++)
104 if (NULL != rs[i].cleaner)
105 rs[i].cleaner (rs[i].cls);