GNUnet  0.10.x
Functions
pq_prepare.c File Reference

functions to connect to libpq (PostGres) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
Include dependency graph for pq_prepare.c:

Go to the source code of this file.

Functions

struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare (const char *name, const char *sql, unsigned int num_args)
 Create a struct GNUNET_PQ_PreparedStatement. More...
 
int GNUNET_PQ_prepare_statements (PGconn *connection, const struct GNUNET_PQ_PreparedStatement *ps)
 Request creation of prepared statements ps from Postgres. More...
 

Detailed Description

functions to connect to libpq (PostGres)

Author
Christian Grothoff

Definition in file pq_prepare.c.

Function Documentation

◆ GNUNET_PQ_make_prepare()

struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare ( const char *  name,
const char *  sql,
unsigned int  num_args 
)

Create a struct GNUNET_PQ_PreparedStatement.

Parameters
namename of the statement
sqlactual SQL statement
num_argsnumber of arguments in the statement
Returns
initialized struct

Definition at line 39 of file pq_prepare.c.

References name, GNUNET_PQ_PreparedStatement::name, and GNUNET_PQ_PreparedStatement::sql.

Referenced by database_setup(), and init_connection().

42 {
43  struct GNUNET_PQ_PreparedStatement ps = {
44  .name = name,
45  .sql = sql,
46  .num_arguments = num_args
47  };
48 
49  return ps;
50 }
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
const char * name
Name of the statement.
const char * sql
Actual SQL statement.
const char * name
Here is the caller graph for this function:

◆ GNUNET_PQ_prepare_statements()

int GNUNET_PQ_prepare_statements ( PGconn *  connection,
const struct GNUNET_PQ_PreparedStatement ps 
)

Request creation of prepared statements ps from Postgres.

Parameters
connectionconnection to prepare the statements for
psGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 63 of file pq_prepare.c.

References _, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, GNUNET_PQ_PreparedStatement::name, GNUNET_PQ_PreparedStatement::num_arguments, ret, and GNUNET_PQ_PreparedStatement::sql.

Referenced by database_setup(), and init_connection().

65 {
66  for (unsigned int i = 0; NULL != ps[i].name; i++)
67  {
68  PGresult *ret;
69 
71  "pq",
72  "Preparing SQL statement `%s' as `%s'\n",
73  ps[i].sql,
74  ps[i].name);
75  ret = PQprepare(connection,
76  ps[i].name,
77  ps[i].sql,
78  ps[i].num_arguments,
79  NULL);
80  if (PGRES_COMMAND_OK != PQresultStatus(ret))
81  {
83  "pq",
84  _("PQprepare (`%s' as `%s') failed with error: %s\n"),
85  ps[i].sql,
86  ps[i].name,
87  PQerrorMessage(connection));
88  PQclear(ret);
89  return GNUNET_SYSERR;
90  }
91  PQclear(ret);
92  }
93  return GNUNET_OK;
94 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * name
Name of the statement.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
const char * sql
Actual SQL statement.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
const char * name
unsigned int num_arguments
Number of arguments included in sql.
#define GNUNET_log_from(kind, comp,...)
Here is the caller graph for this function: