GNUnet  0.10.x
Functions
pq_exec.c File Reference

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

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.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 (PGconn *connection, 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 37 of file pq_exec.c.

References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.

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

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

References GNUNET_YES, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by database_setup(), and init_connection().

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

◆ GNUNET_PQ_exec_statements()

int GNUNET_PQ_exec_statements ( PGconn *  connection,
const struct GNUNET_PQ_ExecuteStatement es 
)

Request execution of an array of statements es from Postgres.

Parameters
connectionconnection to execute the statements over
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 77 of file pq_exec.c.

References 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 database_setup(), init_connection(), and postgres_plugin_drop().

79 {
80  for (unsigned int i=0; NULL != es[i].sql; i++)
81  {
82  PGresult *result;
83 
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  {
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);
108  }
109  return GNUNET_OK;
110 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
int ignore_errors
Should we ignore errors?
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
const char * sql
Actual SQL statement.
Here is the caller graph for this function: