functions to execute SQL statements with arguments and/or results (PostGres) More...
Go to the source code of this file.
Macros | |
#define | PQ_DIAG_SQLSTATE_DEADLOCK "40P01" |
Error code returned by Postgres for deadlock. More... | |
#define | PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION "23505" |
Error code returned by Postgres for uniqueness violation. More... | |
#define | PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE "40001" |
Error code returned by Postgres on serialization failure. More... | |
Functions | |
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. More... | |
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 params. More... | |
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 connection using the given params. More... | |
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 connection using the given params. More... | |
functions to execute SQL statements with arguments and/or results (PostGres)
Definition in file pq_eval.c.
#define PQ_DIAG_SQLSTATE_DEADLOCK "40P01" |
#define PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION "23505" |
#define PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE "40001" |
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.
Also logs errors.
db | database to execute the statement in |
statement_name | name of the statement that created result |
result | result to check |
enum GNUNET_DB_QueryStatus
. Never returns positive values as this function does not look at the result set. Definition at line 46 of file pq_eval.c.
References db, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_PQ_reconnect(), PQ_DIAG_SQLSTATE_DEADLOCK, PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE, PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION, result, and status.
Referenced by GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_eval_prepared_non_select(), and GNUNET_PQ_eval_prepared_singleton_select().
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 params.
Returns the resulting session state.
db | database to execute the statement with |
statement_name | name of the statement |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) |
enum GNUNET_DB_QueryStatus
. If the statement was a DELETE or UPDATE statement, the number of affected rows is returned; if the statement was an INSERT statement, and no row was added due to a UNIQUE violation, we return zero; if INSERT was successful, we return one. Definition at line 135 of file pq_eval.c.
References db, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), and result.
Referenced by delete_old_block(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), namestore_postgres_clear_editor_hint(), namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_put(), postgres_plugin_remove_key(), process_result(), and repl_proc().
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 connection using the given params.
Call rh with the results. Returns the query status including the number of results given to rh (possibly zero). rh will not have been called if the return value is negative.
db | database to execute the statement with |
statement_name | name of the statement |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) |
rh | function to call with the result set, NULL to ignore |
rh_cls | closure to pass to rh |
enum GNUNET_DB_QueryStatus
. Definition at line 165 of file pq_eval.c.
References db, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), result, and ret.
Referenced by namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_zone_to_name(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), postgres_plugin_get_key(), postgres_plugin_get_keys(), postgres_plugin_get_replication(), and postgres_plugin_get_zero_anonymity().
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 connection using the given params.
Stores the result (if any) in rs, which the caller must then clean up using GNUNET_PQ_cleanup_result() if the return value was GNUNET_DB_STATUS_SUCCESS_ONE_RESULT. Returns the resulting session status.
db | database to execute the statement with | |
statement_name | name of the statement | |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) | |
[in,out] | rs | result specification to use for storing the result of the query |
enum GNUNET_DB_QueryStatus
. Definition at line 199 of file pq_eval.c.
References db, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), GNUNET_PQ_extract_result(), and result.
Referenced by check_patch_applied(), GNUNET_PQ_get_oid_by_name(), namecache_postgres_lookup_block(), postgres_plugin_del(), and postgres_plugin_estimate_size().