GNUnet 0.28.1-dev.3-2-g4c5d45bb5
 
Loading...
Searching...
No Matches
pq_prepare.c File Reference

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

#include "platform.h"
#include "pq.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)
 Create a struct GNUNET_PQ_PreparedStatement.
 
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_anon (struct GNUNET_PQ_Context *pg, const char *sql)
 Prepares SQL statement sql under no name ("") for connection pg.
 
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_statements (struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_PreparedStatement *ps)
 Request creation of prepared statements ps from Postgres.
 

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 
)

Create a struct GNUNET_PQ_PreparedStatement.

Parameters
namename of the statement, at most 64 characters allowed
sqlactual SQL statement
Returns
initialized struct

Definition at line 30 of file pq_prepare.c.

32{
34 .name = name,
35 .sql = sql
36 };
37
38 /* PostgreSQL truncates prepared statements at 63 characters,
39 assert this one is short enough or at least fail hard if
40 it is not. */
41 GNUNET_assert (strlen (name) < 64);
42 return ps;
43}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static char * name
Name (label) of the records to list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
const char * sql
Actual SQL statement.

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

Referenced by reconnect_setup(), reconnect_setup(), reconnect_setup(), and reconnect_setup().

Here is the caller graph for this function:

◆ GNUNET_PQ_prepare_anon()

enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_anon ( struct GNUNET_PQ_Context pg,
const char *  sql 
)

Prepares SQL statement sql under no name ("") for connection pg.

Useful for prepared statements that should not be cached.

Parameters
pgdatabase handle
sqlactual SQL text
Returns
GNUNET_OK on success

Definition at line 47 of file pq_prepare.c.

49{
50 PGresult *ret;
51
53 "pq",
54 "Preparing SQL: %s\n",
55 sql);
56 ret = PQprepare (pg->conn,
57 "",
58 sql,
59 0,
60 NULL);
61 if (PGRES_COMMAND_OK != PQresultStatus (ret))
62 {
64 "pq",
65 "PQprepare (`%s') failed with error: %s\n",
66 sql,
67 PQerrorMessage (pg->conn));
68 PQclear (ret);
69 return GNUNET_SYSERR;
70 }
71 PQclear (ret);
72 return GNUNET_OK;
73}
static int ret
Final status code.
Definition gnunet-arm.c:93
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
PGconn * conn
Actual connection.
Definition pq.h:40

References GNUNET_PQ_Context::conn, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, ret, and GNUNET_PQ_PreparedStatement::sql.

◆ GNUNET_PQ_prepare_statements()

enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_statements ( struct GNUNET_PQ_Context db,
const struct GNUNET_PQ_PreparedStatement ps 
)

Request creation of prepared statements ps from Postgres.

Parameters
dbdatabase 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 77 of file pq_prepare.c.

79{
80 for (unsigned int i = 0;
81 NULL != ps[i].name;
82 i++)
83 {
84 PGresult *ret;
85
87 "pq",
88 "Preparing SQL statement `%s' as `%s'\n",
89 ps[i].sql,
90 ps[i].name);
91 ret = PQprepare (db->conn,
92 ps[i].name,
93 ps[i].sql,
94 0,
95 NULL);
96 if (PGRES_COMMAND_OK != PQresultStatus (ret))
97 {
99 "pq",
100 "PQprepare (`%s' as `%s') failed with error: %s\n",
101 ps[i].sql,
102 ps[i].name,
103 PQerrorMessage (db->conn));
104 PQclear (ret);
105 ret = PQdescribePrepared (db->conn,
106 ps[i].name);
107 if (PGRES_COMMAND_OK != PQresultStatus (ret))
108 {
109 PQclear (ret);
110 return GNUNET_SYSERR;
111 }
113 "pq",
114 "Statement `%s' already known. Ignoring the issue in the hope that you are using connection pooling...\n",
115 ps[i].name);
116 }
117 PQclear (ret);
118 }
119 return GNUNET_OK;
120}
static struct GNUNET_FS_DirectoryBuilder * db
@ GNUNET_ERROR_TYPE_WARNING

References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, name, ps, ret, and GNUNET_PQ_PreparedStatement::sql.

Referenced by reconnect_setup(), reconnect_setup(), reconnect_setup(), and reconnect_setup().

Here is the caller graph for this function: