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/>
17 * @file pq/pq_prepare.c
18 * @brief functions to connect to libpq (PostGres)
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
23 #include "gnunet_pq_lib.h"
27 * Create a `struct GNUNET_PQ_PreparedStatement`.
29 * @param name name of the statement
30 * @param sql actual SQL statement
31 * @param num_args number of arguments in the statement
32 * @return initialized struct
34 struct GNUNET_PQ_PreparedStatement
35 GNUNET_PQ_make_prepare (const char *name,
37 unsigned int num_args)
39 struct GNUNET_PQ_PreparedStatement ps = {
42 .num_arguments = num_args
50 * Request creation of prepared statements @a ps from Postgres.
52 * @param connection connection to prepare the statements for
53 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
55 * @return #GNUNET_OK on success,
56 * #GNUNET_SYSERR on error
59 GNUNET_PQ_prepare_statements (PGconn *connection,
60 const struct GNUNET_PQ_PreparedStatement *ps)
62 for (unsigned int i=0;NULL != ps[i].name;i++)
66 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
68 "Preparing SQL statement `%s' as `%s'\n",
71 ret = PQprepare (connection,
76 if (PGRES_COMMAND_OK != PQresultStatus (ret))
78 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
80 _("PQprepare (`%s' as `%s') failed with error: %s\n"),
83 PQerrorMessage (connection));
93 /* end of pq/pq_prepare.c */