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

Function db_get_version

db/exec.c:15–39  ·  view source on GitHub ↗

* db_get_version - Determine the current DB schema version * * Will attempt to determine the current schema version of the * database @db by querying the `version` table. If the table does not * exist it'll return schema version -1, so that migration 0 is * applied, which should create the `version` table. */

Source from the content-addressed store, hash-verified

13 * applied, which should create the `version` table.
14 */
15int db_get_version(struct db *db)
16{
17 int res = -1;
18 struct db_stmt *stmt = db_prepare_v2(db, SQL("SELECT version FROM version LIMIT 1"));
19
20 /*
21 * Tentatively execute a query, but allow failures. Some databases
22 * like postgres will terminate the DB transaction if there is an
23 * error during the execution of a query, e.g., trying to access a
24 * table that doesn't exist yet, so we need to terminate and restart
25 * the DB transaction.
26 */
27 if (!db_query_prepared_canfail(stmt)) {
28 db_commit_transaction(stmt->db);
29 db_begin_transaction(stmt->db);
30 tal_free(stmt);
31 return res;
32 }
33
34 if (db_step(stmt))
35 res = db_col_int(stmt, "version");
36
37 tal_free(stmt);
38 return res;
39}
40
41u32 db_data_version_get(struct db *db)
42{

Callers 4

mainFunction · 0.85
migrate_from_account_dbFunction · 0.85
db_migrateFunction · 0.85
test_empty_db_migrateFunction · 0.85

Calls 5

tal_freeFunction · 0.85
db_stepFunction · 0.85
db_col_intFunction · 0.85
db_commit_transactionFunction · 0.70

Tested by 1

test_empty_db_migrateFunction · 0.68