GNUnet
debian-0.24.3-28-g4f2a77692
Loading...
Searching...
No Matches
pq_exec.c
Go to the documentation of this file.
1
/*
2
This file is part of GNUnet
3
Copyright (C) 2017, 2019 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 "
pq.h
"
27
28
29
struct
GNUNET_PQ_ExecuteStatement
30
GNUNET_PQ_make_execute
(const char *
sql
)
31
{
32
struct
GNUNET_PQ_ExecuteStatement
es = {
33
.
sql
=
sql
,
34
.ignore_errors =
GNUNET_NO
35
};
36
37
return
es;
38
}
39
40
41
struct
GNUNET_PQ_ExecuteStatement
42
GNUNET_PQ_make_try_execute
(const char *
sql
)
43
{
44
struct
GNUNET_PQ_ExecuteStatement
es = {
45
.
sql
=
sql
,
46
.ignore_errors =
GNUNET_YES
47
};
48
49
return
es;
50
}
51
52
53
enum
GNUNET_GenericReturnValue
54
GNUNET_PQ_exec_statements
(
struct
GNUNET_PQ_Context
*
db
,
55
const
struct
GNUNET_PQ_ExecuteStatement
*es)
56
{
57
for
(
unsigned
int
i = 0; NULL != es[i].
sql
; i++)
58
{
59
PGresult *
result
;
60
61
GNUNET_log
(
GNUNET_ERROR_TYPE_DEBUG
,
62
"Running statement `%s' on %p\n"
,
63
es[i].
sql
,
64
db
);
65
result
= PQexec (
db
->conn,
66
es[i].
sql
);
67
GNUNET_log
(
GNUNET_ERROR_TYPE_DEBUG
,
68
"Running statement `%s' on %p finished (%s)\n"
,
69
es[i].
sql
,
70
db
,
71
PQresStatus (PQresultStatus (
result
)));
72
if
((
GNUNET_NO
== es[i].
ignore_errors
) &&
73
(PGRES_COMMAND_OK != PQresultStatus (
result
)))
74
{
75
GNUNET_log_from
(
GNUNET_ERROR_TYPE_ERROR
,
76
"pq"
,
77
"Failed to execute `%s': %s/%s/%s/%s/%s"
,
78
es[i].
sql
,
79
PQresultErrorField (
result
,
80
PG_DIAG_MESSAGE_PRIMARY),
81
PQresultErrorField (
result
,
82
PG_DIAG_MESSAGE_DETAIL),
83
PQresultErrorMessage (
result
),
84
PQresStatus (PQresultStatus (
result
)),
85
PQerrorMessage (
db
->conn));
86
PQclear (
result
);
87
return
GNUNET_SYSERR
;
88
}
89
PQclear (
result
);
90
}
91
return
GNUNET_OK
;
92
}
93
94
95
/* end of pq/pq_exec.c */
result
static int result
Global testing status.
Definition
gnunet-regex-profiler.c:240
db
static struct GNUNET_FS_DirectoryBuilder * db
Definition
gnunet-search.c:103
GNUNET_log
#define GNUNET_log(kind,...)
Definition
gnunet_common.h:548
GNUNET_log_from
#define GNUNET_log_from(kind, comp,...)
Definition
gnunet_common.h:522
GNUNET_GenericReturnValue
GNUNET_GenericReturnValue
Named constants for return values.
Definition
gnunet_common.h:108
GNUNET_OK
@ GNUNET_OK
Definition
gnunet_common.h:111
GNUNET_YES
@ GNUNET_YES
Definition
gnunet_common.h:113
GNUNET_NO
@ GNUNET_NO
Definition
gnunet_common.h:110
GNUNET_SYSERR
@ GNUNET_SYSERR
Definition
gnunet_common.h:109
GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_ERROR
Definition
gnunet_common.h:414
GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_DEBUG
Definition
gnunet_common.h:421
platform.h
pq.h
shared internal data structures of libgnunetpq
GNUNET_PQ_make_execute
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal.
Definition
pq_exec.c:30
GNUNET_PQ_exec_statements
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition
pq_exec.c:54
GNUNET_PQ_make_try_execute
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated.
Definition
pq_exec.c:42
GNUNET_PQ_Context
Handle to Postgres database.
Definition
pq.h:36
GNUNET_PQ_ExecuteStatement
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
Definition
gnunet_pq_lib.h:1485
GNUNET_PQ_ExecuteStatement::sql
const char * sql
Actual SQL statement.
Definition
gnunet_pq_lib.h:1489
GNUNET_PQ_ExecuteStatement::ignore_errors
int ignore_errors
Should we ignore errors?
Definition
gnunet_pq_lib.h:1494
src
lib
pq
pq_exec.c
Generated by
1.9.8