GNUnet 0.22.2
pq_exec.c File Reference

functions to execute plain SQL statements (PostGres) More...

#include "platform.h"
#include "pq.h"
Include dependency graph for pq_exec.c:

Go to the source code of this file.

Functions

struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute (const char *sql)
 Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal. More...
 
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute (const char *sql)
 Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated. More...
 
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. More...
 

Detailed Description

functions to execute plain SQL statements (PostGres)

Author
Christian Grothoff

Definition in file pq_exec.c.

Function Documentation

◆ 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.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 30 of file pq_exec.c.

31{
32 struct GNUNET_PQ_ExecuteStatement es = {
33 .sql = sql,
34 .ignore_errors = GNUNET_NO
35 };
36
37 return es;
38}
@ GNUNET_NO
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
const char * sql
Actual SQL statement.

References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by postgres_plugin_drop().

Here is the caller graph for this function:

◆ 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.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 42 of file pq_exec.c.

43{
44 struct GNUNET_PQ_ExecuteStatement es = {
45 .sql = sql,
46 .ignore_errors = GNUNET_YES
47 };
48
49 return es;
50}
@ GNUNET_YES

References GNUNET_YES, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by database_connect(), namestore_postgres_begin_tx(), namestore_postgres_commit_tx(), and namestore_postgres_rollback_tx().

Here is the caller graph for this function:

◆ 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.

Parameters
dbdatabase to execute the statements in
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success (modulo statements where errors can be ignored) GNUNET_SYSERR on error

Definition at line 54 of file pq_exec.c.

56{
57 for (unsigned int i = 0; NULL != es[i].sql; i++)
58 {
59 PGresult *result;
60
62 "Running statement `%s' on %p\n",
63 es[i].sql,
64 db);
65 result = PQexec (db->conn,
66 es[i].sql);
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 {
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}
static int result
Global testing status.
static struct GNUNET_FS_DirectoryBuilder * db
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG

References db, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_PQ_ExecuteStatement::ignore_errors, result, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by GNUNET_PQ_reconnect(), namestore_postgres_begin_tx(), namestore_postgres_commit_tx(), namestore_postgres_rollback_tx(), and postgres_plugin_drop().

Here is the caller graph for this function: