From f49baac34fca728a456702f7c8b98e34867ea3b8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Jul 2025 13:18:34 +0930 Subject: [PATCH 1/3] sqlite3: consistently comment where we want to upgrade. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now you can grep for 'sqlite3 version' and see where we would like to update. Debian 11 (Bullseye) and Ubuntu 20.04 (Focal) ship with SQLite 3.31.1. RHEL 9 ships with 3.34.1. Fedora 38+ uses SQLite 3.40+. Unfortunately, RHEL8 ships with 3.26.0, and is still on maintenance Support (security fixes, no new features): runs until May 31, 2029. Signed-off-by: Rusty Russell --- db/db_sqlite3.c | 1 + plugins/sql.c | 4 ++-- wallet/db.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/db/db_sqlite3.c b/db/db_sqlite3.c index 876049ed304c..8ee380a63618 100644 --- a/db/db_sqlite3.c +++ b/db/db_sqlite3.c @@ -570,6 +570,7 @@ static bool complete_table_manip(struct db *db, return true; } +/* FIXME: sqlite3 version 3.25.0 (2018-09-15) supports ALTER TABLE RENAME */ static bool db_sqlite3_rename_column(struct db *db, const char *tablename, const char *from, const char *to) diff --git a/plugins/sql.c b/plugins/sql.c index 1496d7e9cf82..9e4ca305b4b2 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -873,8 +873,8 @@ static struct command_result *channels_refresh(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Refreshing channel: %s", fmt_short_channel_id(tmpctx, scid)); - /* FIXME: sqlite 3.24.0 (2018-06-04) added UPSERT, but - * we don't require it. */ + /* FIXME: sqlite3 version 3.24.0 (2018-06-04) added + * UPSERT, but we don't require it. */ delete_channel_from_db(cmd, scid); req = jsonrpc_request_start(cmd, "listchannels", listchannels_one_done, diff --git a/wallet/db.c b/wallet/db.c index 569182d5e592..93707eb8f119 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1631,8 +1631,8 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld, /* FIXME: We cannot use ->delete_columns to remove * short_channel_id, as other tables reference the channels * (and sqlite3 has them referencing a now-deleted table!). - * When we can assume sqlite3 2021-04-19 (3.35.5), we can - * simply use DROP COLUMN (yay!) */ + * When we can assume sqlite3 version 3.35.5 (2021-04-19), + * we can simply use DROP COLUMN (yay!) */ /* So null-out the unused column, at least! */ stmt = db_prepare_v2(db, SQL("UPDATE channels" From 6db7d63f5d10eb514d9238639fb61a24908b546d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Jul 2025 13:26:23 +0930 Subject: [PATCH 2/3] db: drop support for sqlite3 < 3.14. Signed-off-by: Rusty Russell --- configure | 14 -------------- db/db_sqlite3.c | 46 ++++------------------------------------------ 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/configure b/configure index c72981610b2a..dbef04b2a6ee 100755 --- a/configure +++ b/configure @@ -415,20 +415,6 @@ int main(void) return 0; } /*END*/ -var=HAVE_SQLITE3_EXPANDED_SQL -desc=sqlite3_expanded_sql -style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE -link=$SQLITE3_LDLIBS -code= -#include -#include - -int main(void) -{ - printf("%p\n", sqlite3_expanded_sql); - return 0; -} -/*END*/ var=HAVE_SQLITE3 desc=sqlite3 style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE diff --git a/db/db_sqlite3.c b/db/db_sqlite3.c index 8ee380a63618..07ded41f6ea3 100644 --- a/db/db_sqlite3.c +++ b/db/db_sqlite3.c @@ -92,22 +92,6 @@ static bool have_same_data_version(sqlite3 *a, sqlite3 *b) return version_a == version_b; } -#if !HAVE_SQLITE3_EXPANDED_SQL -/* Prior to sqlite3 v3.14, we have to use tracing to dump statements */ -struct db_sqlite3_trace { - struct db_sqlite3 *wrapper; - struct db_stmt *stmt; -}; - -static void trace_sqlite3(void *stmtv, const char *stmt) -{ - struct db_sqlite3_trace *trace = (struct db_sqlite3_trace *)stmtv; - struct db_sqlite3 *wrapper = trace->wrapper; - struct db_stmt *s = trace->stmt; - db_sqlite3_changes_add(wrapper, s, stmt); -} -#endif - static const char *db_sqlite3_fmt_error(struct db_stmt *stmt) { return tal_fmt(stmt, "%s: %s: %s", stmt->location, stmt->query->query, @@ -269,49 +253,27 @@ static bool db_sqlite3_query(struct db_stmt *stmt) static bool db_sqlite3_exec(struct db_stmt *stmt) { int err; - bool success; + char *expanded_sql; struct db_sqlite3 *wrapper = (struct db_sqlite3 *) stmt->db->conn; -#if !HAVE_SQLITE3_EXPANDED_SQL - /* Register the tracing function if we don't have an explicit way of - * expanding the statement. */ - struct db_sqlite3_trace trace; - trace.wrapper = wrapper; - trace.stmt = stmt; - sqlite3_trace(conn2sql(stmt->db->conn), trace_sqlite3, &trace); -#endif - if (!db_sqlite3_query(stmt)) { /* If the prepare step caused an error we hand it up. */ - success = false; - goto done; + return false; } err = sqlite3_step(stmt->inner_stmt); if (err != SQLITE_DONE) { tal_free(stmt->error); stmt->error = db_sqlite3_fmt_error(stmt); - success = false; - goto done; + return false; } -#if HAVE_SQLITE3_EXPANDED_SQL /* Manually expand and call the callback */ - char *expanded_sql; expanded_sql = sqlite3_expanded_sql(stmt->inner_stmt); db_sqlite3_changes_add(wrapper, stmt, expanded_sql); sqlite3_free(expanded_sql); -#endif - success = true; - -done: -#if !HAVE_SQLITE3_EXPANDED_SQL - /* Unregister the trace callback to avoid it accessing the potentially - * stale pointer to stmt */ - sqlite3_trace(conn2sql(stmt->db->conn), NULL, NULL); -#endif - return success; + return true; } static bool db_sqlite3_step(struct db_stmt *stmt) From 06e6013427bf276201b435f10df7c6693513160f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Jul 2025 13:30:13 +0930 Subject: [PATCH 3/3] tools: enforce minimum sqlite3 version number. This is RHEL8's version. Signed-off-by: Rusty Russell Changelog-Changed: build: we now require sqlite3 version 3.26 or above (released 2018-12-01). --- tools/headerversions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/headerversions.c b/tools/headerversions.c index 4c798b43f8d5..15100bdef5f8 100644 --- a/tools/headerversions.c +++ b/tools/headerversions.c @@ -32,6 +32,10 @@ static const char template[] = " if (SQLITE_VERSION_NUMBER + 1000000 < sqlite3_libversion_number())\n" " errx(1, \"SQLITE major version mismatch: compiled %%u, now %%u\",\n" " SQLITE_VERSION_NUMBER, sqlite3_libversion_number());\n" + " /* Earliest supported sqlite3 version */\n" + " if (SQLITE_VERSION_NUMBER < 3026000)\n" + " errx(1, \"SQLITE version %%u too old (minimum 3.26)\",\n" + " SQLITE_VERSION_NUMBER);\n" ) "}\n";