Browse Source

wallet: Look up the db_config for the given driver in db_open

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2803/head
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
acedcc593f
  1. 25
      wallet/db.c
  2. 1
      wallet/test/Makefile

25
wallet/db.c

@ -28,6 +28,14 @@ struct db {
char *filename;
const char *in_transaction;
sqlite3 *sql;
/* DB-specific context */
void *conn;
/* The configuration, including translated queries for the current
* instance. */
const struct db_config *config;
const char **changes;
};
@ -759,6 +767,9 @@ static struct db *db_open(const tal_t *ctx, char *filename)
int err;
struct db *db;
sqlite3 *sql;
size_t num_configs;
struct db_config **configs = autodata_get(db_backends, &num_configs);
const char *driver_name = "sqlite3";
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
err = sqlite3_open_v2(filename, &sql, flags, NULL);
@ -771,6 +782,20 @@ static struct db *db_open(const tal_t *ctx, char *filename)
db = tal(ctx, struct db);
db->filename = tal_strdup(db, filename);
db->sql = sql;
for (size_t i=0; i<num_configs; i++)
if (streq(driver_name, configs[i]->name)) {
db->config = configs[i];
break;
}
if (!db->config)
db_fatal("Unable to find DB driver for %s", driver_name);
// FIXME(cdecker) Once we parse DB connection strings this needs to be
// instantiated correctly.
db->conn = sql;
tal_add_destructor(db, destroy_db);
db->in_transaction = NULL;
db->changes = NULL;

1
wallet/test/Makefile

@ -17,6 +17,7 @@ WALLET_TEST_COMMON_OBJS := \
common/utils.o \
common/wireaddr.o \
common/version.o \
wallet/db_sqlite3.o \
wire/towire.o \
wire/fromwire.o

Loading…
Cancel
Save