GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
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
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 return ps;
39}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static char * name
Name (label) of the records to list.
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
const char * sql
Actual SQL statement.

References 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 43 of file pq_prepare.c.

45{
46 PGresult *ret;
47
49 "pq",
50 "Preparing SQL: %s\n",
51 sql);
52 ret = PQprepare (pg->conn,
53 "",
54 sql,
55 0,
56 NULL);
57 if (PGRES_COMMAND_OK != PQresultStatus (ret))
58 {
60 "pq",
61 "PQprepare (`%s') failed with error: %s\n",
62 sql,
63 PQerrorMessage (pg->conn));
64 PQclear (ret);
65 return GNUNET_SYSERR;
66 }
67 PQclear (ret);
68 return GNUNET_OK;
69}
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 73 of file pq_prepare.c.

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