32#define PQ_DIAG_SQLSTATE_DEADLOCK "40P01"
37#define PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION "23505"
42#define PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE "40001"
47 const char *statement_name,
54 est = PQresultStatus (
result);
55 if ((PGRES_COMMAND_OK != est) &&
56 (PGRES_TUPLES_OK != est))
61 if (CONNECTION_OK != (
status = PQstatus (
db->conn)))
65 "Database connection failed during query `%s': %d (reconnecting)\n",
72 sqlstate = PQresultErrorField (
result,
80 if ((0 == strcmp (sqlstate,
82 (0 == strcmp (sqlstate,
89 "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
91 PQresultErrorField (
result,
92 PG_DIAG_MESSAGE_PRIMARY),
93 PQresultErrorField (
result,
94 PG_DIAG_MESSAGE_DETAIL),
95 PQresultErrorMessage (
result),
96 PQresStatus (PQresultStatus (
result)),
97 PQerrorMessage (
db->conn));
100 if (0 == strcmp (sqlstate,
106 "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n",
108 PQresultErrorField (
result,
109 PG_DIAG_MESSAGE_PRIMARY),
110 PQresultErrorField (
result,
111 PG_DIAG_MESSAGE_DETAIL),
112 PQresultErrorMessage (
result),
113 PQresStatus (PQresultStatus (
result)),
114 PQerrorMessage (
db->conn));
119 "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
121 PQresultErrorField (
result,
122 PG_DIAG_MESSAGE_PRIMARY),
123 PQresultErrorField (
result,
124 PG_DIAG_MESSAGE_DETAIL),
125 PQresultErrorMessage (
result),
126 PQresStatus (PQresultStatus (
result)),
127 PQerrorMessage (
db->conn));
136 const char *statement_name,
155 tuples = PQcmdTuples (
result);
157 qs = strtol (tuples, NULL, 10);
166 const char *statement_name,
201 const char *statement_name,
222 ntuples = PQntuples (
result);
231 "Statement %s returned more than one result, but there must be at most one when using %s\n",
static int ret
Final status code.
static int status
The program status; 0 for success.
static int result
Global testing status.
static struct GNUNET_FS_DirectoryBuilder * db
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
@ GNUNET_DB_STATUS_HARD_ERROR
A hard error occurred, retrying will not help.
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
@ GNUNET_DB_STATUS_SOFT_ERROR
A soft error occurred, retrying the transaction may succeed.
void(* GNUNET_PQ_PostgresResultHandler)(void *cls, PGresult *result, unsigned int num_results)
Function to be called with the results of a SELECT statement that has returned num_results results.
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
PGresult * GNUNET_PQ_exec_prepared(struct GNUNET_PQ_Context *db, const char *name, const struct GNUNET_PQ_QueryParam *params)
Execute a prepared statement.
enum GNUNET_GenericReturnValue GNUNET_PQ_extract_result(PGresult *result, struct GNUNET_PQ_ResultSpec *rs, int row)
Extract results from a query result according to the given specification.
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
shared internal data structures of libgnunetpq
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_multi_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, GNUNET_PQ_PostgresResultHandler rh, void *rh_cls)
Execute a named prepared statement that is a SELECT statement which may return multiple results in co...
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_singleton_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, struct GNUNET_PQ_ResultSpec *rs)
Execute a named prepared statement that is a SELECT statement which must return a single result in co...
#define PQ_DIAG_SQLSTATE_DEADLOCK
Error code returned by Postgres for deadlock.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_result(struct GNUNET_PQ_Context *db, const char *statement_name, PGresult *result)
Check the result's error code to see what happened.
#define PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE
Error code returned by Postgres on serialization failure.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_non_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params)
Execute a named prepared statement that is NOT a SELECT statement in connection using the given param...
#define PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION
Error code returned by Postgres for uniqueness violation.
Handle to Postgres database.
Description of a DB query parameter.
Description of a DB result cell.