GNUnet  0.11.x
Functions
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...
 
int 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 36 of file pq_exec.c.

References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by database_setup(), init_connection(), and postgres_plugin_drop().

37 {
38  struct GNUNET_PQ_ExecuteStatement es = {
39  .sql = sql,
40  .ignore_errors = GNUNET_NO
41  };
42 
43  return es;
44 }
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * sql
Actual SQL statement.
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 55 of file pq_exec.c.

References GNUNET_YES, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by database_setup(), and init_connection().

56 {
57  struct GNUNET_PQ_ExecuteStatement es = {
58  .sql = sql,
59  .ignore_errors = GNUNET_YES
60  };
61 
62  return es;
63 }
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * sql
Actual SQL statement.
Here is the caller graph for this function:

◆ GNUNET_PQ_exec_statements()

int 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 with
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 76 of file pq_exec.c.

References GNUNET_PQ_Context::conn, 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(), and postgres_plugin_drop().

78 {
79  for (unsigned int i = 0; NULL != es[i].sql; i++)
80  {
81  PGresult *result;
82 
84  "Running statement `%s' on %p\n",
85  es[i].sql,
86  db);
87  result = PQexec (db->conn,
88  es[i].sql);
89  if ((GNUNET_NO == es[i].ignore_errors) &&
90  (PGRES_COMMAND_OK != PQresultStatus (result)))
91  {
93  "pq",
94  "Failed to execute `%s': %s/%s/%s/%s/%s",
95  es[i].sql,
96  PQresultErrorField (result,
97  PG_DIAG_MESSAGE_PRIMARY),
98  PQresultErrorField (result,
99  PG_DIAG_MESSAGE_DETAIL),
100  PQresultErrorMessage (result),
101  PQresStatus (PQresultStatus (result)),
102  PQerrorMessage (db->conn));
103  PQclear (result);
104  return GNUNET_SYSERR;
105  }
106  PQclear (result);
107  }
108  return GNUNET_OK;
109 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int ignore_errors
Should we ignore errors?
PGconn * conn
Actual connection.
Definition: pq.h:39
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
const char * sql
Actual SQL statement.
Here is the caller graph for this function: