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

Function db_get_version

db/exec.c:16–40  ·  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

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

Callers 4

db_migrateFunction · 0.85
test_empty_db_migrateFunction · 0.85
db_migrateFunction · 0.85
test_db_migrateFunction · 0.85

Calls 5

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

Tested by 2

test_empty_db_migrateFunction · 0.68
test_db_migrateFunction · 0.68