diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-09-14 09:01:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-09-14 09:01:00 +0200 |
commit | 5466b9471cc85ff5ad9719ed61aaa474ae5b4c23 (patch) | |
tree | 5253b9d525f9a4f9025221eb1847a28ac6833a4a /src/backenddb/plugin_merchantdb_postgres.c | |
parent | b9e87dd137f74864809b405ddf6a4ff719a5fedb (diff) | |
download | merchant-5466b9471cc85ff5ad9719ed61aaa474ae5b4c23.tar.gz merchant-5466b9471cc85ff5ad9719ed61aaa474ae5b4c23.tar.bz2 merchant-5466b9471cc85ff5ad9719ed61aaa474ae5b4c23.zip |
fix
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index b965b0e6..ee07245a 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -6031,17 +6031,17 @@ postgres_insert_pickup_blind_signature ( /** - * Initialize Postgres database subsystem. + * Establish connection to the database. * - * @param cls a configuration instance - * @return NULL on error, otherwise a `struct TALER_MERCHANTDB_Plugin` + * @param cls plugin context + * @param for_drop is this to drop/reset the database (so no point in + * preparing statements)? */ -void * -libtaler_plugin_merchantdb_postgres_init (void *cls) +static int +postgres_connect (void *cls, + bool for_drop) { - const struct GNUNET_CONFIGURATION_Handle *cfg = cls; - struct PostgresClosure *pg; - struct TALER_MERCHANTDB_Plugin *plugin; + struct PostgresClosure *pg = cls; struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT", @@ -8413,6 +8413,32 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) GNUNET_PQ_PREPARED_STATEMENT_END }; + pg->conn = GNUNET_PQ_connect_with_cfg (pg->cfg, + "merchantdb-postgres", + "merchant-", + NULL, + for_drop + ? NULL + : ps); + if (NULL == pg->conn) + return GNUNET_SYSERR; + return GNUNET_OK; +} + + +/** + * Initialize Postgres database subsystem. + * + * @param cls a configuration instance + * @return NULL on error, otherwise a `struct TALER_MERCHANTDB_Plugin` + */ +void * +libtaler_plugin_merchantdb_postgres_init (void *cls) +{ + const struct GNUNET_CONFIGURATION_Handle *cfg = cls; + struct PostgresClosure *pg; + struct TALER_MERCHANTDB_Plugin *plugin; + pg = GNUNET_new (struct PostgresClosure); pg->cfg = cfg; if (GNUNET_OK != @@ -8427,17 +8453,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } - pg->conn = GNUNET_PQ_connect_with_cfg (cfg, - "merchantdb-postgres", - "merchant-", - NULL, - ps); - if (NULL == pg->conn) - { - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } if (GNUNET_OK != TALER_config_get_currency (cfg, &pg->currency)) @@ -8449,6 +8464,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) } plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin); plugin->cls = pg; + plugin->connect = &postgres_connect; plugin->drop_tables = &postgres_drop_tables; plugin->preflight = &postgres_preflight; plugin->start = &postgres_start; @@ -8541,7 +8557,11 @@ libtaler_plugin_merchantdb_postgres_done (void *cls) struct TALER_MERCHANTDB_Plugin *plugin = cls; struct PostgresClosure *pg = plugin->cls; - GNUNET_PQ_disconnect (pg->conn); + if (NULL != pg->conn) + { + GNUNET_PQ_disconnect (pg->conn); + pg->conn = NULL; + } GNUNET_free (pg->sql_dir); GNUNET_free (pg->currency); GNUNET_free (pg); |