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
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @brief helper functions for executing SQL statements
18 * @author Christian Grothoff
21 #include "gnunet_sq_lib.h"
25 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
27 * @param sql actual SQL statement
28 * @return initialized struct
30 struct GNUNET_SQ_ExecuteStatement
31 GNUNET_SQ_make_execute (const char *sql)
33 struct GNUNET_SQ_ExecuteStatement es = {
35 .ignore_errors = GNUNET_NO
44 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
47 * @param sql actual SQL statement
48 * @return initialized struct
50 struct GNUNET_SQ_ExecuteStatement
51 GNUNET_SQ_make_try_execute (const char *sql)
53 struct GNUNET_SQ_ExecuteStatement es = {
55 .ignore_errors = GNUNET_YES
63 * Request execution of an array of statements @a es from Postgres.
65 * @param dbh database to execute the statements over
66 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
68 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
69 * #GNUNET_SYSERR on error
72 GNUNET_SQ_exec_statements (sqlite3 *dbh,
73 const struct GNUNET_SQ_ExecuteStatement *es)
75 for (unsigned int i=0;NULL != es[i].sql;i++)
86 if (es[i].ignore_errors)
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Failed to run SQL `%s': %s\n",
95 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
96 "Failed to run SQL `%s': %s\n",
100 return GNUNET_SYSERR;