GNUnet  0.17.6
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...
 
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 1 of file pq_exec.c.

37 {
38  struct GNUNET_PQ_ExecuteStatement es = {
39  .sql = sql,
40  .ignore_errors = GNUNET_NO
41  };
42 
43  return es;
44 }
@ GNUNET_NO
Definition: gnunet_common.h:98
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
const char * sql
Actual SQL statement.

Referenced by database_setup(), init_connection(), init_database(), and 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 1 of file pq_exec.c.

56 {
57  struct GNUNET_PQ_ExecuteStatement es = {
58  .sql = sql,
59  .ignore_errors = GNUNET_YES
60  };
61 
62  return es;
63 }
@ GNUNET_YES

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

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 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 1 of file pq_exec.c.

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);
90  "Running statement `%s' on %p finished (%s)\n",
91  es[i].sql,
92  db,
93  PQresStatus (PQresultStatus (result)));
94  if ((GNUNET_NO == es[i].ignore_errors) &&
95  (PGRES_COMMAND_OK != PQresultStatus (result)))
96  {
98  "pq",
99  "Failed to execute `%s': %s/%s/%s/%s/%s",
100  es[i].sql,
101  PQresultErrorField (result,
102  PG_DIAG_MESSAGE_PRIMARY),
103  PQresultErrorField (result,
104  PG_DIAG_MESSAGE_DETAIL),
105  PQresultErrorMessage (result),
106  PQresStatus (PQresultStatus (result)),
107  PQerrorMessage (db->conn));
108  PQclear (result);
109  return GNUNET_SYSERR;
110  }
111  PQclear (result);
112  }
113  return GNUNET_OK;
114 }
static int result
Global testing status.
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:94
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by GNUNET_PQ_reconnect(), and postgres_plugin_drop().

Here is the caller graph for this function: