syncdb_pg.h (3159B)
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 * Directory with SQL statements to run to create tables. 44 */ 45 char *sql_dir; 46 47 /** 48 * Underlying configuration. 49 */ 50 const struct GNUNET_CONFIGURATION_Handle *cfg; 51 52 /** 53 * Name of the currently active transaction, NULL if none is active. 54 */ 55 const char *transaction_name; 56 57 /** 58 * Currency we accept payments in. 59 */ 60 char *currency; 61 62 /** 63 * How often did we (re)establish @a conn so far? 64 */ 65 uint64_t prep_gen; 66 67 }; 68 69 70 /** 71 * Global database closure, initialized by SYNCDB_init(). 72 */ 73 extern struct PostgresClosure *pg; 74 75 76 /** 77 * Prepares SQL statement @a sql under @a name for 78 * connection @a pg once. 79 * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. 80 * 81 * @param name name to prepare the statement under 82 * @param sql actual SQL text 83 */ 84 #define PREPARE(name,sql) \ 85 do { \ 86 static unsigned long long gen; \ 87 \ 88 if (gen < pg->prep_gen) \ 89 { \ 90 struct GNUNET_PQ_PreparedStatement ps[] = { \ 91 GNUNET_PQ_make_prepare (name, sql), \ 92 GNUNET_PQ_PREPARED_STATEMENT_END \ 93 }; \ 94 \ 95 if (GNUNET_OK != \ 96 GNUNET_PQ_prepare_statements (pg->conn, \ 97 ps)) \ 98 { \ 99 GNUNET_break (0); \ 100 return GNUNET_DB_STATUS_HARD_ERROR; \ 101 } \ 102 gen = pg->prep_gen; \ 103 } \ 104 } while (0) 105 106 #endif