syncdb_pg.h (3069B)
1 /* 2 This file is part of TALER 3 (C) 2014--2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file syncdb/syncdb_pg.h 18 * @brief internal shared state for sync postgres database 19 * @author Christian Grothoff 20 */ 21 #ifndef SYNCDB_PG_H 22 #define SYNCDB_PG_H 23 24 #include "platform.h" 25 #include <gnunet/gnunet_util_lib.h> 26 #include <gnunet/gnunet_db_lib.h> 27 #include <gnunet/gnunet_pq_lib.h> 28 #include <taler/taler_pq_lib.h> 29 #include "sync/sync_database_lib.h" 30 31 /** 32 * Type of the shared database closure. 33 */ 34 struct PostgresClosure 35 { 36 37 /** 38 * Postgres connection handle. 39 */ 40 struct GNUNET_PQ_Context *conn; 41 42 /** 43 * Underlying configuration. 44 */ 45 const struct GNUNET_CONFIGURATION_Handle *cfg; 46 47 /** 48 * Name of the currently active transaction, NULL if none is active. 49 */ 50 const char *transaction_name; 51 52 /** 53 * Currency we accept payments in. 54 */ 55 char *currency; 56 57 /** 58 * How often did we (re)establish @a conn so far? 59 */ 60 uint64_t prep_gen; 61 62 }; 63 64 65 /** 66 * Global database closure, initialized by SYNCDB_init(). 67 */ 68 extern struct PostgresClosure *pg; 69 70 71 /** 72 * Prepares SQL statement @a sql under @a name for 73 * connection @a pg once. 74 * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. 75 * 76 * @param name name to prepare the statement under 77 * @param sql actual SQL text 78 */ 79 #define PREPARE(name,sql) \ 80 do { \ 81 static unsigned long long gen; \ 82 \ 83 if (gen < pg->prep_gen) \ 84 { \ 85 struct GNUNET_PQ_PreparedStatement ps[] = { \ 86 GNUNET_PQ_make_prepare (name, sql), \ 87 GNUNET_PQ_PREPARED_STATEMENT_END \ 88 }; \ 89 \ 90 if (GNUNET_OK != \ 91 GNUNET_PQ_prepare_statements (pg->conn, \ 92 ps)) \ 93 { \ 94 GNUNET_break (0); \ 95 return GNUNET_DB_STATUS_HARD_ERROR; \ 96 } \ 97 gen = pg->prep_gen; \ 98 } \ 99 } while (0) 100 101 #endif