functions to connect to libpq (PostGres) More...
Go to the source code of this file.
Functions | |
| static void | reset_connection (struct GNUNET_PQ_Context *db) |
| Close connection to db and mark it as uninitialized. | |
| static enum GNUNET_GenericReturnValue | prepare_check_patch (struct GNUNET_PQ_Context *db) |
| Prepare the "gnunet_pq_check_patch" statement. | |
| static enum GNUNET_GenericReturnValue | prepare_get_oid_by_name (struct GNUNET_PQ_Context *db) |
| Prepare the "gnunet_pq_get_oid_by_name" statement. | |
| static enum GNUNET_GenericReturnValue | check_versioning_ok (struct GNUNET_PQ_Context *db) |
| Check if the "_v" versioning schema exists (and cache the result in db). | |
| static enum GNUNET_GenericReturnValue | check_patch_applied (struct GNUNET_PQ_Context *db, const char *load_path, unsigned int patch_number) |
| Check if the patch with patch_number from the given load_path was already applied on the db. | |
| static void | pq_notice_receiver_cb (void *arg, const PGresult *res) |
| Function called by libpq whenever it wants to log something. | |
| static void | pq_notice_processor_cb (void *arg, const char *message) |
| Function called by libpq whenever it wants to log something. | |
| enum GNUNET_GenericReturnValue | GNUNET_PQ_exec_sql (struct GNUNET_PQ_Context *db, const char *buf) |
| Execute SQL statements from buf against db. | |
| enum GNUNET_GenericReturnValue | GNUNET_PQ_check_current (struct GNUNET_PQ_Context *db, const char *load_suffix) |
| Check if the database is current with respect to database migrations using prefix. | |
| enum GNUNET_GenericReturnValue | GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, const char *load_suffix) |
| Within the db context, run all the SQL files in the load path where the name starts with the load_suffix and ends with consecutive numbers from "[0000-9999].sql". | |
| void | GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db) |
| Reinitialize the database db if the connection is down. | |
| enum GNUNET_GenericReturnValue | GNUNET_PQ_get_oid_by_name (struct GNUNET_PQ_Context *db, const char *name, Oid *oid) |
| Returns the oid for a given datatype by name. | |
| static enum GNUNET_GenericReturnValue | load_initial_oids (struct GNUNET_PQ_Context *db) |
| Load the initial set of OIDs for the supported array-datatypes. | |
| void | GNUNET_PQ_reconnect_ (struct GNUNET_PQ_Context *db) |
| Reinitialize the database db. | |
| enum GNUNET_GenericReturnValue | GNUNET_PQ_load_versioning (struct GNUNET_PQ_Context *db) |
| Setup database versioning. | |
| struct GNUNET_PQ_Context * | GNUNET_PQ_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_PQ_ReconnectCallback rc, GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE *rc_cls) |
| void | GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db) |
| Disconnect from the database, destroying the prepared statements and releasing other associated resources. | |
functions to connect to libpq (PostGres)
Definition in file pq_connect.c.
|
static |
Close connection to db and mark it as uninitialized.
| [in,out] | db | connection to close |
Definition at line 37 of file pq_connect.c.
References db.
Referenced by GNUNET_PQ_reconnect_(), prepare_check_patch(), and prepare_get_oid_by_name().
|
static |
Prepare the "gnunet_pq_check_patch" statement.
| [in,out] | db | database to prepare statement for |
Definition at line 56 of file pq_connect.c.
References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, res, and reset_connection().
Referenced by check_patch_applied().
|
static |
Prepare the "gnunet_pq_get_oid_by_name" statement.
| [in,out] | db | database to prepare statement for |
Definition at line 96 of file pq_connect.c.
References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, res, and reset_connection().
Referenced by GNUNET_PQ_reconnect_().
|
static |
Check if the "_v" versioning schema exists (and cache the result in db).
| [in,out] | db | connection to check |
Definition at line 135 of file pq_connect.c.
References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, and res.
Referenced by check_patch_applied(), and GNUNET_PQ_load_versioning().
|
static |
Check if the patch with patch_number from the given load_path was already applied on the db.
| [in] | db | database to check |
| load_path | file system path to database setup files | |
| patch_number | number of the patch to check |
Definition at line 184 of file pq_connect.c.
References check_versioning_ok(), db, GNUNET_assert, 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_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_string(), GNUNET_snprintf(), GNUNET_SYSERR, and prepare_check_patch().
Referenced by GNUNET_PQ_check_current(), and GNUNET_PQ_run_sql().
|
static |
Function called by libpq whenever it wants to log something.
We already log whenever we care, so this function does nothing and merely exists to silence the libpq logging.
| arg | the SQL connection that was used |
| res | information about some libpq event |
Definition at line 265 of file pq_connect.c.
References res.
Referenced by GNUNET_PQ_reconnect_().
|
static |
Function called by libpq whenever it wants to log something.
We log those using the GNUnet logger.
| arg | the SQL connection that was used |
| message | information about some libpq event |
Definition at line 282 of file pq_connect.c.
References GNUNET_ERROR_TYPE_INFO, and GNUNET_log_from.
Referenced by GNUNET_PQ_reconnect_().
| enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql | ( | struct GNUNET_PQ_Context * | db, |
| const char * | buf | ||
| ) |
Execute SQL statements from buf against db.
The given filename infix in buf is prefixed with the "load_path" and ".sql" is appended to construct the full filename.
| [in,out] | db | database context to use |
| buf | filename infix (!) with the SQL code to run |
Definition at line 294 of file pq_connect.c.
References db, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_test_read(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_OS_INHERIT_STD_NONE, GNUNET_OS_PROCESS_EXITED, GNUNET_process_create(), GNUNET_process_destroy(), GNUNET_process_run_command_va(), GNUNET_process_wait(), GNUNET_SYSERR, GNUNET_YES, and type.
Referenced by GNUNET_PQ_load_versioning(), GNUNET_PQ_run_sql(), libgnunet_plugin_datacache_postgres_done(), and namestore_postgres_drop_tables().
| enum GNUNET_GenericReturnValue GNUNET_PQ_check_current | ( | struct GNUNET_PQ_Context * | db, |
| const char * | prefix | ||
| ) |
Check if the database is current with respect to database migrations using prefix.
| [in,out] | db | database to check versioning for |
| prefix | prefix to use to check migrations |
Definition at line 358 of file pq_connect.c.
References check_patch_applied(), db, GNUNET_asprintf(), GNUNET_break, GNUNET_DISK_file_test_read(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and ret.
| enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql | ( | struct GNUNET_PQ_Context * | db, |
| const char * | load_suffix | ||
| ) |
Within the db context, run all the SQL files in the load path where the name starts with the load_suffix and ends with consecutive numbers from "[0000-9999].sql".
| db | database context to use |
| load_suffix | suffix to append to the load path to find the XXXX.sql files, usually "subsystem-". |
Definition at line 398 of file pq_connect.c.
References check_patch_applied(), db, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PQ_exec_sql(), GNUNET_snprintf(), GNUNET_SYSERR, and ret.
Referenced by reconnect_cb(), reconnect_setup(), reconnect_setup(), and reconnect_setup().
| void GNUNET_PQ_reconnect_if_down | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db if the connection is down.
| [in,out] | db | database connection to reinitialize |
Definition at line 439 of file pq_connect.c.
References db, and GNUNET_PQ_reconnect_().
| enum GNUNET_GenericReturnValue GNUNET_PQ_get_oid_by_name | ( | struct GNUNET_PQ_Context * | db, |
| const char * | name, | ||
| Oid * | oid | ||
| ) |
Returns the oid for a given datatype by name.
| db | The db-connection | |
| name | The name of the datatype | |
| [out] | oid | The OID of the datatype. |
Definition at line 451 of file pq_connect.c.
References db, GNUNET_array_grow, GNUNET_assert, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_new_array, GNUNET_OK, GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_SYSERR, name, and oid.
Referenced by GNUNET_PQ_query_param_array_abs_time(), GNUNET_PQ_query_param_array_bool(), GNUNET_PQ_query_param_array_bytes(), GNUNET_PQ_query_param_array_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_abs_time(), GNUNET_PQ_query_param_array_ptrs_bytes(), GNUNET_PQ_query_param_array_ptrs_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_rel_time(), GNUNET_PQ_query_param_array_ptrs_string(), GNUNET_PQ_query_param_array_ptrs_timestamp(), GNUNET_PQ_query_param_array_rel_time(), GNUNET_PQ_query_param_array_string(), GNUNET_PQ_query_param_array_timestamp(), GNUNET_PQ_query_param_array_uint16(), GNUNET_PQ_query_param_array_uint32(), GNUNET_PQ_query_param_array_uint64(), GNUNET_PQ_result_spec_array_abs_time(), GNUNET_PQ_result_spec_array_bool(), GNUNET_PQ_result_spec_array_fixed_size(), GNUNET_PQ_result_spec_array_rel_time(), GNUNET_PQ_result_spec_array_string(), GNUNET_PQ_result_spec_array_timestamp(), GNUNET_PQ_result_spec_array_uint16(), GNUNET_PQ_result_spec_array_uint32(), GNUNET_PQ_result_spec_array_uint64(), GNUNET_PQ_result_spec_array_variable_size(), and load_initial_oids().
|
static |
Load the initial set of OIDs for the supported array-datatypes.
| db | The database context |
Definition at line 521 of file pq_connect.c.
References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_from, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_SYSERR, and oid.
Referenced by GNUNET_PQ_reconnect_().
| void GNUNET_PQ_reconnect_ | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db.
| db | database connection to reinitialize |
Definition at line 552 of file pq_connect.c.
References db, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_from, GNUNET_OK, GNUNET_PQ_event_reconnect_(), GNUNET_SYSERR, load_initial_oids(), pq_notice_processor_cb(), pq_notice_receiver_cb(), prepare_get_oid_by_name(), and reset_connection().
Referenced by do_scheduler_notify(), GNUNET_PQ_eval_result(), GNUNET_PQ_event_do_poll(), GNUNET_PQ_exec_prepared(), GNUNET_PQ_init(), and GNUNET_PQ_reconnect_if_down().
| enum GNUNET_GenericReturnValue GNUNET_PQ_load_versioning | ( | struct GNUNET_PQ_Context * | db | ) |
Setup database versioning.
| [in,out] | db | database to load versioning for |
Definition at line 602 of file pq_connect.c.
References check_versioning_ok(), db, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PQ_exec_sql(), GNUNET_SYSERR, GNUNET_YES, and ret.
Referenced by reconnect_setup(), and reconnect_setup().
| struct GNUNET_PQ_Context * GNUNET_PQ_init | ( | const struct GNUNET_CONFIGURATION_Handle * | cfg, |
| const char * | section, | ||
| GNUNET_PQ_ReconnectCallback | rc, | ||
| GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE * | rc_cls | ||
| ) |
Definition at line 631 of file pq_connect.c.
References cfg, db, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_config_missing(), GNUNET_new, GNUNET_OK, GNUNET_PQ_reconnect_(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_PQ_Context::load_path, GNUNET_PQ_Context::rc, and GNUNET_PQ_Context::rc_cls.
| void GNUNET_PQ_disconnect | ( | struct GNUNET_PQ_Context * | db | ) |
Disconnect from the database, destroying the prepared statements and releasing other associated resources.
| db | database handle to disconnect (will be free'd) |
Definition at line 678 of file pq_connect.c.
References db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_free, and GNUNET_SCHEDULER_cancel().
Referenced by database_shutdown(), database_shutdown(), libgnunet_plugin_datacache_postgres_done(), libgnunet_plugin_datastore_postgres_done(), namestore_postgres_create_tables(), and namestore_postgres_drop_tables().