GNUnet  0.10.x
sq_exec.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2018 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero 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.
9 
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.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
25 #include "platform.h"
26 #include "gnunet_sq_lib.h"
27 
28 
37 {
38  struct GNUNET_SQ_ExecuteStatement es = {
39  .sql = sql,
40  .ignore_errors = GNUNET_NO
41  };
42 
43  return es;
44 }
45 
46 
47 
57 {
58  struct GNUNET_SQ_ExecuteStatement es = {
59  .sql = sql,
60  .ignore_errors = GNUNET_YES
61  };
62 
63  return es;
64 }
65 
66 
76 int
78  const struct GNUNET_SQ_ExecuteStatement *es)
79 {
80  for (unsigned int i = 0; NULL != es[i].sql; i++)
81  {
82  char *emsg = NULL;
83 
84  if (SQLITE_OK !=
85  sqlite3_exec(dbh,
86  es[i].sql,
87  NULL,
88  NULL,
89  &emsg))
90  {
91  if (es[i].ignore_errors)
92  {
94  "Failed to run SQL `%s': %s\n",
95  es[i].sql,
96  emsg);
97  }
98  else
99  {
101  "Failed to run SQL `%s': %s\n",
102  es[i].sql,
103  emsg);
104  sqlite3_free(emsg);
105  return GNUNET_SYSERR;
106  }
107  sqlite3_free(emsg);
108  }
109  }
110  return GNUNET_OK;
111 }
112 
113 /* end of sq_exec */
int ignore_errors
Should we ignore errors?
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.
Definition: sq_exec.c:56
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
helper functions for Sqlite3 DB interactions
int GNUNET_SQ_exec_statements(sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: sq_exec.c:77
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.
Definition: sq_exec.c:36
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77