2 This file is part of GNUnet
3 Copyright (C) 2018 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 executing SQL statements
19 * @author Christian Grothoff
22 #include "gnunet_sq_lib.h"
26 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
28 * @param sql actual SQL statement
29 * @return initialized struct
31 struct GNUNET_SQ_ExecuteStatement
32 GNUNET_SQ_make_execute (const char *sql)
34 struct GNUNET_SQ_ExecuteStatement es = {
36 .ignore_errors = GNUNET_NO
45 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
48 * @param sql actual SQL statement
49 * @return initialized struct
51 struct GNUNET_SQ_ExecuteStatement
52 GNUNET_SQ_make_try_execute (const char *sql)
54 struct GNUNET_SQ_ExecuteStatement es = {
56 .ignore_errors = GNUNET_YES
64 * Request execution of an array of statements @a es from Postgres.
66 * @param dbh database to execute the statements over
67 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
69 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
70 * #GNUNET_SYSERR on error
73 GNUNET_SQ_exec_statements (sqlite3 *dbh,
74 const struct GNUNET_SQ_ExecuteStatement *es)
76 for (unsigned int i=0;NULL != es[i].sql;i++)
87 if (es[i].ignore_errors)
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90 "Failed to run SQL `%s': %s\n",
96 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
97 "Failed to run SQL `%s': %s\n",
101 return GNUNET_SYSERR;