GNUnet 0.26.2-113-ged4734898
 
Loading...
Searching...
No Matches
pq_connect.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2017, 2019, 2020, 2021, 2023 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "pq.h"
28#include <pthread.h>
29
30
36static void
38{
39 if (NULL == db->conn)
40 return;
41 PQfinish (db->conn);
42 db->conn = NULL;
43 db->prepared_check_patch = false;
44 db->prepared_get_oid_by_name = false;
45}
46
47
57{
58 PGresult *res;
59
60 if (db->prepared_check_patch)
61 return GNUNET_OK;
62 res = PQprepare (db->conn,
63 "gnunet_pq_check_patch",
64 "SELECT"
65 " applied_by"
66 " FROM _v.patches"
67 " WHERE patch_name = $1"
68 " LIMIT 1",
69 1,
70 NULL);
71 if (PGRES_COMMAND_OK !=
72 PQresultStatus (res))
73 {
75 "Failed to run SQL logic to setup database versioning logic: %s/%s\n",
76 PQresultErrorMessage (res),
77 PQerrorMessage (db->conn));
78 PQclear (res);
80 return GNUNET_SYSERR;
81 }
82 PQclear (res);
83 db->prepared_check_patch = true;
84 return GNUNET_OK;
85}
86
87
97{
98 PGresult *res;
99
100 if (db->prepared_get_oid_by_name)
101 return GNUNET_OK;
102 res = PQprepare (db->conn,
103 "gnunet_pq_get_oid_by_name",
104 "SELECT typname, oid"
105 " FROM pg_type"
106 " WHERE oid = to_regtype($1)",
107 1,
108 NULL);
109 if (PGRES_COMMAND_OK != PQresultStatus (res))
110 {
112 "Failed to run SQL statement prepare OID lookups: %s/%s\n",
113 PQresultErrorMessage (res),
114 PQerrorMessage (db->conn));
115 PQclear (res);
117 return GNUNET_SYSERR;
118 }
119 PQclear (res);
120 db->prepared_get_oid_by_name = true;
121 return GNUNET_OK;
122}
123
124
138 const char *load_path,
139 unsigned int patch_number)
140{
141 const char *load_path_suffix;
142 size_t slen = strlen (load_path) + 10;
143 char patch_name[slen];
144
145 load_path_suffix = strrchr (load_path,
146 '/');
147 if (NULL == load_path_suffix)
148 load_path_suffix = load_path;
149 else
150 load_path_suffix++; /* skip '/' */
151 GNUNET_snprintf (patch_name,
152 sizeof (patch_name),
153 "%s%04u",
154 load_path_suffix,
155 patch_number);
156 {
157 struct GNUNET_PQ_QueryParam params[] = {
158 GNUNET_PQ_query_param_string (patch_name),
160 };
161 char *applied_by;
162 struct GNUNET_PQ_ResultSpec rs[] = {
163 GNUNET_PQ_result_spec_string ("applied_by",
164 &applied_by),
166 };
167 enum GNUNET_DB_QueryStatus qs;
168
169 if (GNUNET_OK !=
171 {
172 GNUNET_break (0);
173 return GNUNET_SYSERR;
174 }
176 "gnunet_pq_check_patch",
177 params,
178 rs);
179 switch (qs)
180 {
183 "Database version %s already applied by %s\n",
184 patch_name,
185 applied_by);
187 return GNUNET_OK;
189 return GNUNET_NO;
191 GNUNET_break (0);
192 return GNUNET_SYSERR;
194 GNUNET_break (0);
195 return GNUNET_SYSERR;
196 }
197 GNUNET_assert (0);
198 return GNUNET_SYSERR;
199 }
200}
201
202
211static void
213 const PGresult *res)
214{
215 /* do nothing, intentionally */
216 (void) arg;
217 (void) res;
218}
219
220
228static void
230 const char *message)
231{
232 (void) arg;
234 "pq",
235 "%s",
236 message);
237}
238
239
240struct GNUNET_PQ_Context *
242 const char *load_path,
243 const struct GNUNET_PQ_ExecuteStatement *es,
244 const struct GNUNET_PQ_PreparedStatement *ps)
245{
247 load_path,
248 NULL == load_path
249 ? NULL
250 : "",
251 es,
252 ps,
254}
255
256
257struct GNUNET_PQ_Context *
259 const char *load_path,
260 const char *auto_suffix,
261 const struct GNUNET_PQ_ExecuteStatement *es,
262 const struct GNUNET_PQ_PreparedStatement *ps,
264{
265 struct GNUNET_PQ_Context *db;
266 unsigned int elen = 0;
267 unsigned int plen = 0;
268
269 if (NULL != es)
270 while (NULL != es[elen].sql)
271 elen++;
272 if (NULL != ps)
273 while (NULL != ps[plen].name)
274 plen++;
275
277 db->flags = flags;
278 db->config_str = GNUNET_strdup (config_str);
279 if (NULL != load_path)
280 db->load_path = GNUNET_strdup (load_path);
281 if (NULL != auto_suffix)
282 db->auto_suffix = GNUNET_strdup (auto_suffix);
283 if (0 != elen)
284 {
285 db->es = GNUNET_new_array (elen + 1,
287 memcpy (db->es,
288 es,
289 elen * sizeof (struct GNUNET_PQ_ExecuteStatement));
290 }
291 if (0 != plen)
292 {
293 db->ps = GNUNET_new_array (plen + 1,
295 memcpy (db->ps,
296 ps,
297 plen * sizeof (struct GNUNET_PQ_PreparedStatement));
298 }
299 db->channel_map = GNUNET_CONTAINER_multishortmap_create (16,
300 GNUNET_YES);
302 if (NULL == db->conn)
303 {
305 GNUNET_free (db->load_path);
306 GNUNET_free (db->auto_suffix);
307 GNUNET_free (db->config_str);
308 GNUNET_free (db);
309 return NULL;
310 }
311 return db;
312}
313
314
317 const char *buf)
318{
319 struct GNUNET_Process *psql;
321 unsigned long code;
322 char *fn;
323
324 GNUNET_asprintf (&fn,
325 "%s%s.sql",
326 db->load_path,
327 buf);
328 if (GNUNET_YES !=
330 {
331 if (0 == (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
333 "Attempted to load SQL resource `%s', which does not exist. This could be perfectly normal.\n",
334 fn);
335 GNUNET_free (fn);
336 return GNUNET_NO;
337 }
338 if (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
339 return GNUNET_SYSERR;
341 "Applying SQL file `%s' on database %s\n",
342 fn,
343 db->config_str);
345 if (GNUNET_OK !=
347 "psql",
348 "psql",
349 db->config_str,
350 "-f",
351 fn,
352 "-q",
353 "--set",
354 "ON_ERROR_STOP=1",
355 NULL))
356 {
358 "exec",
359 "psql");
361 GNUNET_free (fn);
362 return GNUNET_SYSERR;
363 }
366 true,
367 &type,
368 &code));
370 if ( (GNUNET_OS_PROCESS_EXITED != type) ||
371 (0 != code) )
372 {
374 "Could not run PSQL on file %s: psql exit code was %d\n",
375 fn,
376 (int) code);
377 GNUNET_free (fn);
378 return GNUNET_SYSERR;
379 }
380 GNUNET_free (fn);
381 return GNUNET_OK;
382}
383
384
387 const char *load_suffix)
388{
389 size_t slen = strlen (load_suffix) + 10;
390 char patch_name[slen];
391
393 "Loading SQL resources from `%s'\n",
394 load_suffix);
395 for (unsigned int i = 1; i<10000; i++)
396 {
398
400 load_suffix,
401 i);
402 if (GNUNET_SYSERR == ret)
403 {
404 GNUNET_break (0);
405 return GNUNET_SYSERR;
406 }
407 if (GNUNET_OK == ret)
408 continue; /* patch already applied, skip it */
409
410 GNUNET_snprintf (patch_name,
411 sizeof (patch_name),
412 "%s%04u",
413 load_suffix,
414 i);
416 patch_name);
417 if (GNUNET_NO == ret)
418 break;
419 if ( (GNUNET_SYSERR == ret) &&
420 (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags)) )
421 {
422 /* We are only checking, found unapplied patch, bad! */
424 "Database outdated, patch %s missing. Aborting!\n",
425 patch_name);
426 }
427 if (GNUNET_SYSERR == ret)
428 return GNUNET_SYSERR;
429 }
430 return GNUNET_OK;
431}
432
433
434void
436{
437 if (1 ==
438 PQconsumeInput (db->conn))
439 return;
440 if (CONNECTION_BAD != PQstatus (db->conn))
441 return;
443}
444
445
448 struct GNUNET_PQ_Context *db,
449 const char *name,
450 Oid *oid)
451{
452 /* Check if the entry is in the cache already */
453 for (unsigned int i = 0; i < db->oids.num; i++)
454 {
455 /* Pointer comparison */
456 if (name == db->oids.table[i].name)
457 {
458 *oid = db->oids.table[i].oid;
459 return GNUNET_OK;
460 }
461 }
462
463 /* No entry found in cache, ask database */
464 {
465 enum GNUNET_DB_QueryStatus qs;
466 struct GNUNET_PQ_QueryParam params[] = {
469 };
470 struct GNUNET_PQ_ResultSpec spec[] = {
472 oid),
474 };
475
476 GNUNET_assert (NULL != db);
477
479 "gnunet_pq_get_oid_by_name",
480 params,
481 spec);
483 return GNUNET_SYSERR;
484 }
485
486 /* Add the entry to the cache */
487 if (NULL == db->oids.table)
488 {
489 db->oids.table = GNUNET_new_array (8,
490 typeof(*db->oids.table));
491 db->oids.cap = 8;
492 db->oids.num = 0;
493 }
494
495 if (db->oids.cap <= db->oids.num)
496 GNUNET_array_grow (db->oids.table,
497 db->oids.cap,
498 db->oids.cap + 8);
499
500 db->oids.table[db->oids.num].name = name;
501 db->oids.table[db->oids.num].oid = *oid;
502 db->oids.num++;
503
504 return GNUNET_OK;
505}
506
507
518{
519 static const char *typnames[] = {
520 "bool",
521 "int2",
522 "int4",
523 "int8",
524 "bytea",
525 "varchar"
526 };
527 Oid oid;
528
529 for (size_t i = 0; i< sizeof(typnames) / sizeof(*typnames); i++)
530 {
531 if (GNUNET_OK !=
533 typnames[i],
534 &oid))
535 {
537 "pq",
538 "Couldn't retrieve OID for type %s\n",
539 typnames[i]);
540 return GNUNET_SYSERR;
541 }
542 }
543 return GNUNET_OK;
544}
545
546
547void
549{
551 -1);
553 db->conn = PQconnectdb (db->config_str);
554 if ( (NULL == db->conn) ||
555 (CONNECTION_OK != PQstatus (db->conn)) )
556 {
558 "pq",
559 "Database connection to '%s' failed: %s\n",
560 db->config_str,
561 (NULL != db->conn)
562 ? PQerrorMessage (db->conn)
563 : "PQconnectdb returned NULL");
565 return;
566 }
567 PQsetNoticeReceiver (db->conn,
569 db);
570 PQsetNoticeProcessor (db->conn,
572 db);
573 if ( (NULL != db->load_path) &&
574 (NULL != db->auto_suffix) )
575 {
576 PGresult *res;
577 ExecStatusType est;
578
579 res = PQexec (db->conn,
580 "SELECT"
581 " schema_name"
582 " FROM information_schema.schemata"
583 " WHERE schema_name='_v';");
584 est = PQresultStatus (res);
585 if ( (PGRES_COMMAND_OK != est) &&
586 (PGRES_TUPLES_OK != est) )
587 {
589 "Failed to run statement to check versioning schema. Bad!\n");
590 PQclear (res);
592 return;
593 }
594 if (0 == PQntuples (res))
595 {
597
598 PQclear (res);
599 if (0 != (db->flags & GNUNET_PQ_FLAG_DROP))
600 {
602 "Versioning schema does not exist yet. Not attempting drop!\n");
604 return;
605 }
607 "versioning");
608 if (GNUNET_NO == ret)
609 {
611 "Failed to find SQL file to load database versioning logic\n");
613 return;
614 }
615 if (GNUNET_SYSERR == ret)
616 {
618 "Failed to run SQL logic to setup database versioning logic\n");
620 return;
621 }
622 }
623 else
624 {
625 PQclear (res);
626 }
627 }
628
629 /* Prepare statement for OID lookup by name */
630 if (GNUNET_OK !=
632 return;
633
634 /* Reset the OID-cache and retrieve the OIDs for the supported Array types */
635 db->oids.num = 0;
637 {
639 "Failed to retrieve OID information for array types!\n");
641 return;
642 }
643
644 if (NULL != db->auto_suffix)
645 {
646 GNUNET_assert (NULL != db->load_path);
647 if (GNUNET_OK !=
649 return;
650
651 if (GNUNET_SYSERR ==
653 db->auto_suffix))
654 {
655 if (0 == (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
657 "Failed to load SQL statements from `%s*'\n",
658 db->auto_suffix);
660 return;
661 }
662 }
663
664 if ( (NULL != db->es) &&
665 (GNUNET_OK !=
667 db->es)) )
668 {
670 return;
671 }
672 if ( (NULL != db->ps) &&
673 (GNUNET_OK !=
675 db->ps)) )
676 {
678 return;
679 }
681 PQsocket (db->conn));
682}
683
684
685struct GNUNET_PQ_Context *
687 const char *section,
688 const char *load_path_suffix,
689 const struct GNUNET_PQ_ExecuteStatement *es,
690 const struct GNUNET_PQ_PreparedStatement *ps)
691{
693 section,
694 load_path_suffix,
695 es,
696 ps,
698}
699
700
701struct GNUNET_PQ_Context *
703 const char *section,
704 const char *load_path_suffix,
705 const struct GNUNET_PQ_ExecuteStatement *es,
706 const struct GNUNET_PQ_PreparedStatement *ps,
708{
709 struct GNUNET_PQ_Context *db;
710 char *conninfo;
711 char *load_path;
712
713 if (GNUNET_OK !=
715 section,
716 "CONFIG",
717 &conninfo))
718 conninfo = NULL;
719 load_path = NULL;
720 if (GNUNET_OK !=
722 section,
723 "SQL_DIR",
724 &load_path))
725 {
727 section,
728 "SQL_DIR");
729 }
730 if ( (NULL != load_path_suffix) &&
731 (NULL == load_path) )
732 {
734 section,
735 "SQL_DIR");
736 return NULL;
737 }
738 db = GNUNET_PQ_connect2 (conninfo == NULL ? "" : conninfo,
739 load_path,
740 load_path_suffix,
741 es,
742 ps,
743 flags);
745 GNUNET_free (conninfo);
746 return db;
747}
748
749
750void
752{
753 if (NULL == db)
754 return;
755 GNUNET_assert (0 ==
758 if (NULL != db->poller_task)
759 {
760 GNUNET_SCHEDULER_cancel (db->poller_task);
761 db->poller_task = NULL;
762 }
763 GNUNET_free (db->es);
764 GNUNET_free (db->ps);
765 GNUNET_free (db->load_path);
766 GNUNET_free (db->auto_suffix);
767 GNUNET_free (db->config_str);
768 GNUNET_free (db->oids.table);
769 db->oids.table = NULL;
770 db->oids.num = 0;
771 db->oids.cap = 0;
772 PQfinish (db->conn);
773 GNUNET_free (db);
774}
775
776
777/* end of pq/pq_connect.c */
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_FS_DirectoryBuilder * db
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
@ GNUNET_DB_STATUS_HARD_ERROR
A hard error occurred, retrying will not help.
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
@ GNUNET_DB_STATUS_SOFT_ERROR
A soft error occurred, retrying the transaction may succeed.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
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 co...
Definition pq_eval.c:199
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition pq_exec.c:54
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_PreparedStatement *ps)
Request creation of prepared statements ps from Postgres.
Definition pq_prepare.c:88
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string expected.
#define GNUNET_PQ_query_param_end
End of query parameter specification.
GNUNET_PQ_Options
Flags to control PQ operation.
@ GNUNET_PQ_FLAG_DROP
Dropping database.
@ GNUNET_PQ_FLAG_CHECK_CURRENT
Check database version is current.
@ GNUNET_PQ_FLAG_NONE
Traditional default.
void GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_PQ_extract_result().
Definition pq.c:142
uint32_t oid
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string(const char *ptr)
Generate query parameter for a string.
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition disk.c:565
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_va(struct GNUNET_Process *p, const char *filename,...)
Set the command and start a process.
Definition os_process.c:903
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
GNUNET_OS_ProcessStatusType
Process status types.
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
shared internal data structures of libgnunetpq
void GNUNET_PQ_event_reconnect_(struct GNUNET_PQ_Context *db, int fd)
Internal API.
Definition pq_event.c:434
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.
Definition pq_connect.c:137
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
Definition pq_connect.c:548
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.
Definition pq_connect.c:686
static enum GNUNET_GenericReturnValue prepare_check_patch(struct GNUNET_PQ_Context *db)
Prepare the "gnunet_pq_check_patch" statement.
Definition pq_connect.c:56
struct GNUNET_PQ_Context * GNUNET_PQ_connect2(const char *config_str, const char *load_path, const char *auto_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps, enum GNUNET_PQ_Options flags)
Create a connection to the Postgres database using config_str for the configuration.
Definition pq_connect.c:258
static void pq_notice_receiver_cb(void *arg, const PGresult *res)
Function called by libpq whenever it wants to log something.
Definition pq_connect.c:212
static void reset_connection(struct GNUNET_PQ_Context *db)
Close connection to db and mark it as uninitialized.
Definition pq_connect.c:37
static enum GNUNET_GenericReturnValue prepare_get_oid_by_name(struct GNUNET_PQ_Context *db)
Prepare the "gnunet_pq_get_oid_by_name" statement.
Definition pq_connect.c:96
void GNUNET_PQ_reconnect_if_down(struct GNUNET_PQ_Context *db)
Reinitialize the database db if the connection is down.
Definition pq_connect.c:435
void GNUNET_PQ_disconnect(struct GNUNET_PQ_Context *db)
Disconnect from the database, destroying the prepared statements and releasing other associated resou...
Definition pq_connect.c:751
struct GNUNET_PQ_Context * GNUNET_PQ_connect_with_cfg2(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, enum GNUNET_PQ_Options flags)
Connect to a postgres database using the configuration option "CONFIG" in section.
Definition pq_connect.c:702
static void pq_notice_processor_cb(void *arg, const char *message)
Function called by libpq whenever it wants to log something.
Definition pq_connect.c:229
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.
Definition pq_connect.c:447
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql(struct GNUNET_PQ_Context *db, const char *buf)
Execute SQL statements from buf against db.
Definition pq_connect.c:316
static enum GNUNET_GenericReturnValue load_initial_oids(struct GNUNET_PQ_Context *db)
Load the initial set of OIDs for the supported array-datatypes.
Definition pq_connect.c:517
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.
Definition pq_connect.c:241
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_suf...
Definition pq_connect.c:386
Handle to Postgres database.
Definition pq.h:36
struct GNUNET_PQ_ExecuteStatement * es
Statements to execute upon connection.
Definition pq.h:45
enum GNUNET_PQ_Options flags
Flags controlling the connection.
Definition pq.h:106
char * load_path
Path to load SQL files from.
Definition pq.h:70
char * config_str
Configuration to use to connect to the DB.
Definition pq.h:65
char * auto_suffix
Suffix to append to path to load on startup.
Definition pq.h:75
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
Description of a DB query parameter.
Description of a DB result cell.