Apply Pi-hole SQLite3 patches. The percentile and carray extensions are now native parts of the amalgation build.

Signed-off-by: Dominik <dl6er@dl6er.de>
This commit is contained in:
Dominik
2025-11-09 08:59:08 +01:00
parent a98fcbf21d
commit 9879a06983
7 changed files with 10 additions and 15 deletions

View File

@@ -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*/

View File

@@ -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

View File

@@ -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")

View File

@@ -2338,6 +2338,8 @@ SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
#include <stdarg.h>
// 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",

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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