mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
wallet: Look up the db_config for the given driver in db_open
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
e4ab98459c
commit
acedcc593f
2 changed files with 26 additions and 0 deletions
25
wallet/db.c
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;
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue