diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-24 16:30:45 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-24 16:30:45 +0100 |
commit | 2fd320bc7263b1dadd8fbead1004e9ee8b822f45 (patch) | |
tree | d94235b28665834c8b82175fa30360cd0ec6acb0 /src/pq | |
parent | f69dbeee28ec0cacf4ed1ffc4601b59a9178c794 (diff) | |
download | gnunet-2fd320bc7263b1dadd8fbead1004e9ee8b822f45.tar.gz gnunet-2fd320bc7263b1dadd8fbead1004e9ee8b822f45.zip |
modify GNUNET_PQ_connect_with_cfg to enable flexible loading of .sql files
Diffstat (limited to 'src/pq')
-rw-r--r-- | src/pq/pq_connect.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index 1ef2da762..7cd7d8787 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -267,12 +267,12 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db) | |||
267 | * statements in @a es are executed whenever we (re)connect to the | 267 | * statements in @a es are executed whenever we (re)connect to the |
268 | * database, and that the prepared statements in @a ps are "ready". | 268 | * database, and that the prepared statements in @a ps are "ready". |
269 | * | 269 | * |
270 | * The caller MUST ensure that @a es and @a ps remain allocated and | 270 | * The caller does not have to ensure that @a es and @a ps remain allocated |
271 | * initialized in memory until #GNUNET_PQ_disconnect() is called, | 271 | * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. |
272 | * as they may be needed repeatedly and no copy will be made. | ||
273 | * | 272 | * |
274 | * @param cfg configuration | 273 | * @param cfg configuration |
275 | * @param section configuration section to use to get Postgres configuration options | 274 | * @param section configuration section to use to get Postgres configuration options |
275 | * @param load_path_suffix suffix to append to the SQL_DIR in the configuration | ||
276 | * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated | 276 | * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated |
277 | * array of statements to execute upon EACH connection, can be NULL | 277 | * array of statements to execute upon EACH connection, can be NULL |
278 | * @param ps array of prepared statements to prepare, can be NULL | 278 | * @param ps array of prepared statements to prepare, can be NULL |
@@ -281,12 +281,14 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db) | |||
281 | struct GNUNET_PQ_Context * | 281 | struct GNUNET_PQ_Context * |
282 | GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, | 282 | GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, |
283 | const char *section, | 283 | const char *section, |
284 | const char *load_path_suffix, | ||
284 | const struct GNUNET_PQ_ExecuteStatement *es, | 285 | const struct GNUNET_PQ_ExecuteStatement *es, |
285 | const struct GNUNET_PQ_PreparedStatement *ps) | 286 | const struct GNUNET_PQ_PreparedStatement *ps) |
286 | { | 287 | { |
287 | struct GNUNET_PQ_Context *db; | 288 | struct GNUNET_PQ_Context *db; |
288 | char *conninfo; | 289 | char *conninfo; |
289 | char *load_path; | 290 | char *load_path; |
291 | char *sp; | ||
290 | 292 | ||
291 | if (GNUNET_OK != | 293 | if (GNUNET_OK != |
292 | GNUNET_CONFIGURATION_get_value_string (cfg, | 294 | GNUNET_CONFIGURATION_get_value_string (cfg, |
@@ -294,17 +296,23 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
294 | "CONFIG", | 296 | "CONFIG", |
295 | &conninfo)) | 297 | &conninfo)) |
296 | conninfo = NULL; | 298 | conninfo = NULL; |
297 | if (GNUNET_OK != | 299 | load_path = NULL; |
298 | GNUNET_CONFIGURATION_get_value_string (cfg, | 300 | sp = NULL; |
299 | section, | 301 | if (GNUNET_OK == |
300 | "SQL_PATH", | 302 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
301 | &load_path)) | 303 | section, |
302 | load_path = NULL; | 304 | "SQL_DIR", |
305 | &sp)) | ||
306 | GNUNET_asprintf (&load_path, | ||
307 | "%s%s", | ||
308 | sp, | ||
309 | load_path_suffix); | ||
303 | db = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo, | 310 | db = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo, |
304 | load_path, | 311 | load_path, |
305 | es, | 312 | es, |
306 | ps); | 313 | ps); |
307 | GNUNET_free_non_null (load_path); | 314 | GNUNET_free_non_null (load_path); |
315 | GNUNET_free_non_null (sp); | ||
308 | GNUNET_free_non_null (conninfo); | 316 | GNUNET_free_non_null (conninfo); |
309 | return db; | 317 | return db; |
310 | } | 318 | } |