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
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file pq/pq_prepare.c
22 * @brief functions to connect to libpq (PostGres)
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_pq_lib.h"
31 * Create a `struct GNUNET_PQ_PreparedStatement`.
33 * @param name name of the statement
34 * @param sql actual SQL statement
35 * @param num_args number of arguments in the statement
36 * @return initialized struct
38 struct GNUNET_PQ_PreparedStatement
39 GNUNET_PQ_make_prepare (const char *name,
41 unsigned int num_args)
43 struct GNUNET_PQ_PreparedStatement ps = {
46 .num_arguments = num_args
54 * Request creation of prepared statements @a ps from Postgres.
56 * @param connection connection to prepare the statements for
57 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
59 * @return #GNUNET_OK on success,
60 * #GNUNET_SYSERR on error
63 GNUNET_PQ_prepare_statements (PGconn *connection,
64 const struct GNUNET_PQ_PreparedStatement *ps)
66 for (unsigned int i=0;NULL != ps[i].name;i++)
70 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
72 "Preparing SQL statement `%s' as `%s'\n",
75 ret = PQprepare (connection,
80 if (PGRES_COMMAND_OK != PQresultStatus (ret))
82 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
84 _("PQprepare (`%s' as `%s') failed with error: %s\n"),
87 PQerrorMessage (connection));
97 /* end of pq/pq_prepare.c */