GNUnet  0.20.0
sq_prepare.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 "gnunet_common.h"
26 #include "platform.h"
27 #include "gnunet_sq_lib.h"
28 
29 
38 GNUNET_SQ_make_prepare (const char *sql,
39  sqlite3_stmt **pstmt)
40 {
41  struct GNUNET_SQ_PrepareStatement ps = {
42  .sql = sql,
43  .pstmt = pstmt
44  };
45 
46  return ps;
47 }
48 
49 
51 GNUNET_SQ_prepare (sqlite3 *dbh,
52  const struct GNUNET_SQ_PrepareStatement *ps)
53 {
54  for (unsigned int i = 0; NULL != ps[i].sql; i++)
55  {
56  const char *epos = NULL;
57  int ret;
58 
59  if (SQLITE_OK !=
60  (ret = sqlite3_prepare_v2 (dbh,
61  ps[i].sql,
62  strlen (ps[i].sql),
63  ps[i].pstmt,
64  &epos)))
65  {
67  "Failed to prepare SQL `%s': error %d at %s\n",
68  ps[i].sql,
69  ret,
70  epos);
71  return GNUNET_SYSERR;
72  }
73  }
74  return GNUNET_OK;
75 }
76 
77 
78 /* end of sq_prepare.c */
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
helper functions for Sqlite3 DB interactions
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare(const char *sql, sqlite3_stmt **pstmt)
Create a struct GNUNET_SQ_PrepareStatement
Definition: sq_prepare.c:38
enum GNUNET_GenericReturnValue GNUNET_SQ_prepare(sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
Prepare all statements given in the (NULL,NULL)-terminated array at ps.
Definition: sq_prepare.c:51
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
sqlite3_stmt ** pstmt
Where to store handle?