![]() |
GNUnet
0.11.x
|
functions to connect to libpq (PostGres) More...
Go to the source code of this file.
Functions | |
static void | pq_notice_receiver_cb (void *arg, const PGresult *res) |
Function called by libpq whenever it wants to log something. More... | |
static void | pq_notice_processor_cb (void *arg, const char *message) |
Function called by libpq whenever it wants to log something. More... | |
struct GNUNET_PQ_Context * | GNUNET_PQ_connect (const char *config_str, const char *load_path, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps) |
Create a connection to the Postgres database using config_str for the configuration. More... | |
static int | apply_patch (struct GNUNET_PQ_Context *db, const char *load_path, unsigned int i) |
Apply patch number from path load_path. More... | |
int | GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, const char *load_path) |
Within the db context, run all the SQL files from the load_path from 0000-9999.sql (as long as the files exist contiguously). More... | |
void | GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db) |
Reinitialize the database db if the connection is down. More... | |
void | GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db) |
Reinitialize the database db. More... | |
struct GNUNET_PQ_Context * | GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps) |
Connect to a postgres database using the configuration option "CONFIG" in section. More... | |
void | GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db) |
Disconnect from the database, destroying the prepared statements and releasing other associated resources. More... | |
functions to connect to libpq (PostGres)
Definition in file pq_connect.c.
|
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 38 of file pq_connect.c.
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 55 of file pq_connect.c.
References GNUNET_ERROR_TYPE_INFO, and GNUNET_log_from.
Referenced by GNUNET_PQ_reconnect().
struct GNUNET_PQ_Context* GNUNET_PQ_connect | ( | const char * | config_str, |
const char * | load_path, | ||
const struct GNUNET_PQ_ExecuteStatement * | es, | ||
const struct GNUNET_PQ_PreparedStatement * | ps | ||
) |
Create a connection to the Postgres database using config_str for the configuration.
Initialize logging via GNUnet's log routines and disable Postgres's logger. Also ensures that the statements in load_path and es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready". If statements in fail that were created with GNUNET_PQ_make_execute(), then the entire operation fails.
In load_path, a list of "$XXXX.sql" files is expected where $XXXX must be a sequence of contiguous integer values starting at 0000. These files are then loaded in sequence using "psql $config_str" before running statements from es. The directory is inspected again on reconnect.
config_str | configuration to use |
load_path | path to directory with SQL transactions to run, can be NULL |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
Definition at line 89 of file pq_connect.c.
References GNUNET_PQ_Context::config_str, GNUNET_PQ_Context::conn, db, GNUNET_PQ_Context::es, GNUNET_free, GNUNET_new, GNUNET_new_array, GNUNET_PQ_reconnect(), GNUNET_strdup, GNUNET_PQ_Context::load_path, name, and GNUNET_PQ_Context::ps.
Referenced by GNUNET_PQ_connect_with_cfg().
|
static |
Apply patch number from path load_path.
db | database context to use |
load_path | where to find the SQL code to run |
i | patch number to append to the load_path |
Definition at line 146 of file pq_connect.c.
References buf, GNUNET_PQ_Context::config_str, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_OS_INHERIT_STD_NONE, GNUNET_OS_process_destroy(), GNUNET_OS_PROCESS_EXITED, GNUNET_OS_process_wait_status(), GNUNET_OS_start_process(), GNUNET_snprintf(), GNUNET_SYSERR, and type.
Referenced by GNUNET_PQ_reconnect(), and GNUNET_PQ_run_sql().
int GNUNET_PQ_run_sql | ( | struct GNUNET_PQ_Context * | db, |
const char * | load_path | ||
) |
Within the db context, run all the SQL files from the load_path from 0000-9999.sql (as long as the files exist contiguously).
db | database context to use |
load_path | where to find the XXXX.sql files |
Definition at line 213 of file pq_connect.c.
References apply_patch(), buf, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, 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, GNUNET_YES, and ret.
Referenced by GNUNET_PQ_reconnect().
void GNUNET_PQ_reconnect_if_down | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db if the connection is down.
db | database connection to reinitialize |
Definition at line 313 of file pq_connect.c.
References GNUNET_PQ_Context::conn, and GNUNET_PQ_reconnect().
void GNUNET_PQ_reconnect | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db.
db | database connection to reinitialize |
Definition at line 327 of file pq_connect.c.
References apply_patch(), GNUNET_PQ_Context::config_str, GNUNET_PQ_Context::conn, GNUNET_PQ_Context::es, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_exec_statements(), GNUNET_PQ_prepare_statements(), GNUNET_PQ_run_sql(), GNUNET_SYSERR, GNUNET_PQ_Context::load_path, pq_notice_processor_cb(), pq_notice_receiver_cb(), GNUNET_PQ_Context::ps, res, and ret.
Referenced by GNUNET_PQ_connect(), GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), and GNUNET_PQ_reconnect_if_down().
struct GNUNET_PQ_Context* GNUNET_PQ_connect_with_cfg | ( | const struct GNUNET_CONFIGURATION_Handle * | cfg, |
const char * | section, | ||
const char * | load_path_suffix, | ||
const struct GNUNET_PQ_ExecuteStatement * | es, | ||
const struct GNUNET_PQ_PreparedStatement * | ps | ||
) |
Connect to a postgres database using the configuration option "CONFIG" in section.
Also ensures that the statements in es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready".
The caller does not have to ensure that es and ps remain allocated and initialized in memory until GNUNET_PQ_disconnect() is called, as a copy will be made.
cfg | configuration |
section | configuration section to use to get Postgres configuration options |
load_path_suffix | suffix to append to the SQL_DIR in the configuration |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
Definition at line 469 of file pq_connect.c.
References db, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_OK, GNUNET_PQ_connect(), and GNUNET_PQ_Context::load_path.
Referenced by database_setup(), and init_connection().
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 516 of file pq_connect.c.
References GNUNET_PQ_Context::config_str, GNUNET_PQ_Context::conn, GNUNET_PQ_Context::es, GNUNET_free, GNUNET_PQ_Context::load_path, and GNUNET_PQ_Context::ps.
Referenced by database_shutdown(), libgnunet_plugin_datacache_postgres_done(), and libgnunet_plugin_datastore_postgres_done().