From 9879a06983ec90ca4370d077394455f29f716983 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sun, 9 Nov 2025 08:59:08 +0100 Subject: [PATCH] Apply Pi-hole SQLite3 patches. The percentile and carray extensions are now native parts of the amalgation build. Signed-off-by: Dominik --- .../0001-print-FTL-version-in-interactive-shell.patch | 4 ++-- src/CMakeLists.txt | 4 +++- src/database/CMakeLists.txt | 2 -- src/database/shell.c | 5 ++++- src/database/sqlite3-ext.c | 3 --- src/database/sqlite3-ext.h | 3 --- src/database/sqlite3.c | 4 +--- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch b/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch index f9ea8145..3a2710e8 100644 --- a/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch +++ b/patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch @@ -20,10 +20,10 @@ index 6280ebf6..a5e82f70 100644 #else int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ char **argv; -@@ -33467,6 +33469,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ +@@ -33656,6 +33658,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ + if( stdin_is_interactive ){ char *zHome; char *zHistory; - int nHistory; + print_FTL_version(); sqlite3_fprintf(stdout, "SQLite version %s %.19s\n" /*extra-version-info*/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc265087..4059dec3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) # HAVE_FDATASYNC: This option causes SQLite to try to use the fdatasync() system call to sync the database file to disk when committing a transaction. Syncing using fdatasync() is faster than syncing using fsync() as fdatasync() does not wait for the file metadata to be written to disk. # SQLITE_DEFAULT_WORKER_THREADS=0: This option sets the default number of worker threads to use when doing parallel sorting and indexing. The default is 0 which means to use a single thread. Do not increase this value as it, ironically, can cause performance degradation and definitely increases total memory usage. # SQLITE_MAX_PREPARE_RETRY=200: This option sets the maximum number of automatic re-preparation attempts that can occur after encountering a schema change. This can be caused by running ANALYZE which is done periodically by FTL. -set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TEMP_STORE=1 -DSQLITE_DEFAULT_CACHE_SIZE=16384 -DSQLITE_DEFAULT_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DHAVE_MALLOC_H -DHAVE_MALLOC_USABLE_SIZE -DHAVE_FDATASYNC -DSQLITE_DEFAULT_WORKER_THREADS=0 -DSQLITE_MAX_PREPARE_RETRY=200") +# SQLITE_ENABLE_CARRAY: Enable the carray virtual table module +# SQLITE_ENABLE_PERCENTILE: Enable the percentile aggregate function +set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TEMP_STORE=1 -DSQLITE_DEFAULT_CACHE_SIZE=16384 -DSQLITE_DEFAULT_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DHAVE_MALLOC_H -DHAVE_MALLOC_USABLE_SIZE -DHAVE_FDATASYNC -DSQLITE_DEFAULT_WORKER_THREADS=0 -DSQLITE_MAX_PREPARE_RETRY=200 -DSQLITE_ENABLE_CARRAY=1 -DSQLITE_ENABLE_PERCENTILE=1") # Code hardening and debugging improvements # -fstack-protector-strong: The program will be resistant to having its stack overflowed diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt index e438165c..22dd578f 100644 --- a/src/database/CMakeLists.txt +++ b/src/database/CMakeLists.txt @@ -22,8 +22,6 @@ set(sqlite3_sources add_library(sqlite3 OBJECT ${sqlite3_sources}) # Define the function that will be called to initialize the sqlite3 shell target_compile_definitions(sqlite3 PRIVATE "-DSQLITE_SHELL_INIT_PROC=pihole_sqlite3_initalize") -# Define that we want to statically link the percentile extension into the sqlite3 library -target_compile_definitions(sqlite3 PRIVATE "-DSQLITE_STATIC_PERCENTILE=1") target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare -Wno-implicit-function-declaration -Wno-int-conversion) if (CMAKE_C_COMPILER_ID STREQUAL "Clang") diff --git a/src/database/shell.c b/src/database/shell.c index 18177331..fe4a1cf7 100644 --- a/src/database/shell.c +++ b/src/database/shell.c @@ -2338,6 +2338,8 @@ SQLITE_EXTENSION_INIT1 #include #include #include +// print_FTL_version() +#include "../log.h" #ifndef SQLITE_AMALGAMATION /* typedef sqlite3_uint64 u64; */ @@ -33050,7 +33052,7 @@ static int vfstraceOut(const char *z, void *pArg){ #endif #if SQLITE_SHELL_IS_UTF8 -int SQLITE_CDECL main(int argc, char **argv){ +int SQLITE_CDECL sqlite3_shell_main(int argc, char **argv){ #else int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ char **argv; @@ -33657,6 +33659,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( stdin_is_interactive ){ char *zHome; char *zHistory; + print_FTL_version(); sqlite3_fprintf(stdout, "SQLite version %s %.19s\n" /*extra-version-info*/ "Enter \".help\" for usage hints.\n", diff --git a/src/database/sqlite3-ext.c b/src/database/sqlite3-ext.c index c337f93b..eeb7c5fa 100644 --- a/src/database/sqlite3-ext.c +++ b/src/database/sqlite3-ext.c @@ -225,9 +225,6 @@ static int sqlite3_pihole_extensions_init(sqlite3 *db, char **pzErrMsg, const st sqlite3_errstr(rc)); } - // Initialize the percentile extension - sqlite3_percentile_init(db, pzErrMsg, pApi); - return rc; } diff --git a/src/database/sqlite3-ext.h b/src/database/sqlite3-ext.h index 3b249805..64d0541e 100644 --- a/src/database/sqlite3-ext.h +++ b/src/database/sqlite3-ext.h @@ -14,7 +14,4 @@ // Initialization point for SQLite3 extensions void pihole_sqlite3_initalize(void); -// Defined in shell.c -extern int sqlite3_percentile_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi); - #endif // SQLITE3_EXT_H diff --git a/src/database/sqlite3.c b/src/database/sqlite3.c index 03d65b62..a276b732 100644 --- a/src/database/sqlite3.c +++ b/src/database/sqlite3.c @@ -186351,8 +186351,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){ ** Return a static string containing the name corresponding to the error code ** specified in the argument. */ -#if defined(SQLITE_NEED_ERR_NAME) -SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ +SQLITE_API const char *sqlite3ErrName(int rc){ const char *zName = 0; int i, origRc = rc; for(i=0; i<2 && zName==0; i++, rc &= 0xff){ @@ -186461,7 +186460,6 @@ SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ } return zName; } -#endif /* ** Return a static string that describes the kind of error specified in the