diff --git a/db/exec.c b/db/exec.c index 68c2ced55a3c..36d1c0f887cb 100644 --- a/db/exec.c +++ b/db/exec.c @@ -50,7 +50,7 @@ u32 db_data_version_get(struct db *db) } /* This fails on uninitialized db, so "0" */ if (db_step(stmt)) - version = db_col_int(stmt, "intval"); + version = db_col_s64(stmt, "intval"); else version = 0; tal_free(stmt); @@ -61,7 +61,7 @@ void db_set_intvar(struct db *db, const char *varname, s64 val) { size_t changes; struct db_stmt *stmt = db_prepare_v2(db, SQL("UPDATE vars SET intval=? WHERE name=?;")); - db_bind_int(stmt, val); + db_bind_s64(stmt, val); db_bind_text(stmt, varname); db_exec_prepared_v2(stmt); changes = db_count_changes(stmt); @@ -70,7 +70,7 @@ void db_set_intvar(struct db *db, const char *varname, s64 val) if (changes == 0) { stmt = db_prepare_v2(db, SQL("INSERT INTO vars (name, intval) VALUES (?, ?);")); db_bind_text(stmt, varname); - db_bind_int(stmt, val); + db_bind_s64(stmt, val); db_exec_prepared_v2(stmt); tal_free(stmt); } @@ -83,7 +83,7 @@ s64 db_get_intvar(struct db *db, const char *varname, s64 defval) db, SQL("SELECT intval FROM vars WHERE name= ? LIMIT 1")); db_bind_text(stmt, varname); if (db_query_prepared_canfail(stmt) && db_step(stmt)) - res = db_col_int(stmt, "intval"); + res = db_col_s64(stmt, "intval"); tal_free(stmt); return res; diff --git a/wallet/migrations.c b/wallet/migrations.c index 66dd26ca50dc..7642bce3a70f 100644 --- a/wallet/migrations.c +++ b/wallet/migrations.c @@ -1187,6 +1187,9 @@ static const struct db_migration dbmigrations[] = { {SQL("ALTER TABLE payments ADD failmsg BLOB;"), NULL, SQL("ALTER TABLE payments DROP COLUMN failmsg"), NULL}, /* ^v26.09 */ + + {SQL("/*PSQL*/ALTER TABLE vars ALTER COLUMN intval TYPE BIGINT"), NULL, + SQL("/*PSQL*/ALTER TABLE vars ALTER COLUMN intval TYPE INTEGER"), NULL}, }; const struct db_migration *get_db_migrations(size_t *num) diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index 801839c678bb..da25f92662a9 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -502,6 +502,9 @@ static bool test_vars(struct lightningd *ld) /* Check updating */ db_set_intvar(db, varname, 2); CHECK(db_get_intvar(db, varname, 42) == 2); + + db_set_intvar(db, varname, 10000000000LL); + CHECK(db_get_intvar(db, varname, 42) == 10000000000LL); db_commit_transaction(db); tal_free(db);