MCPcopy Create free account
hub / github.com/ElementsProject/lightning / db_open_

Function db_open_

db/utils.c:336–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336struct db *db_open_(const tal_t *ctx, const char *filename,
337 bool developer,
338 bool create,
339 void (*errorfn)(void *arg, bool fatal, const char *fmt, va_list ap),
340 void *arg)
341{
342 struct db *db;
343
344 db = tal(ctx, struct db);
345 db->filename = tal_strdup(db, filename);
346 db->developer = developer;
347 db->errorfn = errorfn;
348 db->errorfn_arg = arg;
349 db->readonly = false;
350 list_head_init(&db->pending_statements);
351 if (!strstr(db->filename, "://"))
352 db_fatal(db, "Could not extract driver name from \"%s\"", db->filename);
353
354 db->config = db_config_find(db, db->filename);
355 if (!db->config)
356 db_fatal(db, "Unable to find DB driver for %s", db->filename);
357
358 db->queries = db_queries_find(db->config);
359 if (!db->queries)
360 db_fatal(db, "Unable to find DB queries for %s", db->config->name);
361
362 db->in_transaction = NULL;
363 db->transaction_started = false;
364 db->changes = NULL;
365 db->in_migration = false;
366
367 /* This must be outside a transaction, so catch it */
368 assert(!db->in_transaction);
369
370 trace_span_start("db_setup", db);
371 db_prepare_for_changes(db);
372 if (!db->config->setup_fn(db, create)) {
373 if (create)
374 db_fatal(db, "Error calling DB setup: %s", db->error);
375 trace_span_end(db);
376 return tal_free(db);
377 }
378 db_report_changes(db, NULL, 0);
379 trace_span_end(db);
380
381 tal_add_destructor(db, destroy_db);
382 return db;
383}

Callers

nothing calls this directly

Calls 8

list_head_initFunction · 0.85
db_fatalFunction · 0.85
db_config_findFunction · 0.85
db_queries_findFunction · 0.85
db_prepare_for_changesFunction · 0.85
trace_span_endFunction · 0.85
tal_freeFunction · 0.85
db_report_changesFunction · 0.85

Tested by

no test coverage detected