aboutsummaryrefslogtreecommitdiff
path: root/src/pq/pq_exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pq/pq_exec.c')
-rw-r--r--src/pq/pq_exec.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c
index 99eb2b270..6c8002aff 100644
--- a/src/pq/pq_exec.c
+++ b/src/pq/pq_exec.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file pq/pq_exec.c 21 * @file pq/pq_exec.c
22 * @brief functions to execute plain SQL statements (PostGres) 22 * @brief functions to execute plain SQL statements (PostGres)
@@ -34,7 +34,7 @@
34 * @return initialized struct 34 * @return initialized struct
35 */ 35 */
36struct GNUNET_PQ_ExecuteStatement 36struct GNUNET_PQ_ExecuteStatement
37GNUNET_PQ_make_execute (const char *sql) 37GNUNET_PQ_make_execute(const char *sql)
38{ 38{
39 struct GNUNET_PQ_ExecuteStatement es = { 39 struct GNUNET_PQ_ExecuteStatement es = {
40 .sql = sql, 40 .sql = sql,
@@ -53,7 +53,7 @@ GNUNET_PQ_make_execute (const char *sql)
53 * @return initialized struct 53 * @return initialized struct
54 */ 54 */
55struct GNUNET_PQ_ExecuteStatement 55struct GNUNET_PQ_ExecuteStatement
56GNUNET_PQ_make_try_execute (const char *sql) 56GNUNET_PQ_make_try_execute(const char *sql)
57{ 57{
58 struct GNUNET_PQ_ExecuteStatement es = { 58 struct GNUNET_PQ_ExecuteStatement es = {
59 .sql = sql, 59 .sql = sql,
@@ -74,38 +74,38 @@ GNUNET_PQ_make_try_execute (const char *sql)
74 * #GNUNET_SYSERR on error 74 * #GNUNET_SYSERR on error
75 */ 75 */
76int 76int
77GNUNET_PQ_exec_statements (PGconn *connection, 77GNUNET_PQ_exec_statements(PGconn *connection,
78 const struct GNUNET_PQ_ExecuteStatement *es) 78 const struct GNUNET_PQ_ExecuteStatement *es)
79{ 79{
80 for (unsigned int i=0; NULL != es[i].sql; i++) 80 for (unsigned int i = 0; NULL != es[i].sql; i++)
81 {
82 PGresult *result;
83
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Running statement `%s' on %p\n",
86 es[i].sql,
87 connection);
88 result = PQexec (connection,
89 es[i].sql);
90 if ( (GNUNET_NO == es[i].ignore_errors) &&
91 (PGRES_COMMAND_OK != PQresultStatus (result)) )
92 { 81 {
93 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 82 PGresult *result;
94 "pq", 83
95 "Failed to execute `%s': %s/%s/%s/%s/%s", 84 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
96 es[i].sql, 85 "Running statement `%s' on %p\n",
97 PQresultErrorField (result, 86 es[i].sql,
98 PG_DIAG_MESSAGE_PRIMARY), 87 connection);
99 PQresultErrorField (result, 88 result = PQexec(connection,
100 PG_DIAG_MESSAGE_DETAIL), 89 es[i].sql);
101 PQresultErrorMessage (result), 90 if ((GNUNET_NO == es[i].ignore_errors) &&
102 PQresStatus (PQresultStatus (result)), 91 (PGRES_COMMAND_OK != PQresultStatus(result)))
103 PQerrorMessage (connection)); 92 {
104 PQclear (result); 93 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
105 return GNUNET_SYSERR; 94 "pq",
95 "Failed to execute `%s': %s/%s/%s/%s/%s",
96 es[i].sql,
97 PQresultErrorField(result,
98 PG_DIAG_MESSAGE_PRIMARY),
99 PQresultErrorField(result,
100 PG_DIAG_MESSAGE_DETAIL),
101 PQresultErrorMessage(result),
102 PQresStatus(PQresultStatus(result)),
103 PQerrorMessage(connection));
104 PQclear(result);
105 return GNUNET_SYSERR;
106 }
107 PQclear(result);
106 } 108 }
107 PQclear (result);
108 }
109 return GNUNET_OK; 109 return GNUNET_OK;
110} 110}
111 111