Fossil SCM

Update the built-in SQLite to the first 3.44.0 release candidate, for testing.

drh 2023-10-29 22:52 trunk
Commit e4d2c1d1fc400549ccaffb694bb2e6d9593a0c71703c1f225b4d2e22eae52449
3 files changed +175 -65 +146 -79 +12 -10
+175 -65
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -465,15 +465,24 @@
465465
** Treat stdin as an interactive input if the following variable
466466
** is true. Otherwise, assume stdin is connected to a file or pipe.
467467
*/
468468
static int stdin_is_interactive = 1;
469469
470
+/*
471
+** If build is for Windows, without 3rd-party line editing, Console
472
+** input and output may be done in a UTF-8 compatible way. This is
473
+** determined by invocation option and OS installed capability.
474
+*/
470475
#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
471476
&& !defined(SHELL_OMIT_WIN_UTF8)
472477
# define SHELL_WIN_UTF8_OPT 1
473
- static int console_utf8 = sizeof(char*)/4 - 1;
478
+ static int console_utf8_in = 0;
479
+ static int console_utf8_out = 0;
480
+ static int mbcs_opted = 0;
474481
#else
482
+# define console_utf8_in 0
483
+# define console_utf8_out 0
475484
# define SHELL_WIN_UTF8_OPT 0
476485
#endif
477486
478487
/*
479488
** On Windows systems we have to know if standard output is a console
@@ -606,81 +615,155 @@
606615
return dynPrompt.dynamicPrompt;
607616
}
608617
#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
609618
610619
#if SHELL_WIN_UTF8_OPT
611
-/* Following struct is used for -utf8 operation. */
620
+/* Following struct is used for UTF-8 operation. */
612621
static struct ConsoleState {
613622
int stdinEof; /* EOF has been seen on console input */
614623
int infsMode; /* Input file stream mode upon shell start */
615624
UINT inCodePage; /* Input code page upon shell start */
616625
UINT outCodePage; /* Output code page upon shell start */
617
- HANDLE hConsoleIn; /* Console input handle */
626
+ HANDLE hConsole; /* Console input or output handle */
618627
DWORD consoleMode; /* Console mode upon shell start */
619628
} conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
620629
621630
#ifndef _O_U16TEXT /* For build environments lacking this constant: */
622631
# define _O_U16TEXT 0x20000
623632
#endif
624633
634
+
635
+#if !SQLITE_OS_WINRT
625636
/*
626
-** Prepare console, (if known to be a WIN32 console), for UTF-8
627
-** input (from either typing or suitable paste operations) and for
628
-** UTF-8 rendering. This may "fail" with a message to stderr, where
637
+** Check Windows major version against given value, returning
638
+** 1 if the OS major version is no less than the argument.
639
+** This check uses very late binding to the registry access
640
+** API so that it can operate gracefully on OS versions that
641
+** do not have that API. The Windows NT registry, for versions
642
+** through Windows 11 (at least, as of October 2023), keeps
643
+** the actual major version number at registry key/value
644
+** HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentMajorVersionNumber
645
+** where it can be read more reliably than allowed by various
646
+** version info APIs which "process" the result in a manner
647
+** incompatible with the purpose of the CLI's version check.
648
+**
649
+** If the registry API is unavailable, or the location of
650
+** the above registry value changes, or the OS major version
651
+** is less than the argument, this function returns 0.
652
+*/
653
+static int CheckAtLeastWinX(DWORD major_version){
654
+ typedef LONG (WINAPI *REG_OPEN)(HKEY,LPCSTR,DWORD,REGSAM,PHKEY);
655
+ typedef LSTATUS (WINAPI *REG_READ)(HKEY,LPCSTR,LPCSTR,DWORD,
656
+ LPDWORD,PVOID,LPDWORD);
657
+ typedef LSTATUS (WINAPI *REG_CLOSE)(HKEY);
658
+ int rv = 0;
659
+ HINSTANCE hLib = LoadLibrary(TEXT("Advapi32.dll"));
660
+ if( NULL != hLib ){
661
+ REG_OPEN rkOpen = (REG_OPEN)GetProcAddress(hLib, "RegOpenKeyExA");
662
+ REG_READ rkRead = (REG_READ)GetProcAddress(hLib, "RegGetValueA");
663
+ REG_CLOSE rkFree = (REG_CLOSE)GetProcAddress(hLib, "RegCloseKey");
664
+ if( rkOpen != NULL && rkRead != NULL && rkFree != NULL ){
665
+ HKEY hk;
666
+ const char *zsk = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
667
+ if( ERROR_SUCCESS == rkOpen(HKEY_LOCAL_MACHINE, zsk, 0, KEY_READ, &hk) ){
668
+ DWORD kv = 0, kvsize = sizeof(kv);
669
+ if( ERROR_SUCCESS == rkRead(hk, 0, "CurrentMajorVersionNumber",
670
+ RRF_RT_REG_DWORD, 0, &kv, &kvsize) ){
671
+ rv = (kv >= major_version);
672
+ }
673
+ rkFree(hk);
674
+ }
675
+ }
676
+ FreeLibrary(hLib);
677
+ }
678
+ return rv;
679
+}
680
+# define IS_WIN10_OR_LATER() CheckAtLeastWinX(10)
681
+#else /* defined(SQLITE_OS_WINRT) */
682
+# define IS_WIN10_OR_LATER() 0
683
+#endif
684
+
685
+/*
686
+** Prepare console, (if known to be a WIN32 console), for UTF-8 input
687
+** (from either typing or suitable paste operations) and/or for UTF-8
688
+** output rendering. This may "fail" with a message to stderr, where
629689
** the preparation is not done and common "code page" issues occur.
690
+**
691
+** The console state upon entry is preserved, in conState, so that
692
+** console_restore() can later restore the same console state.
693
+**
694
+** The globals console_utf8_in and console_utf8_out are set, for
695
+** later use in selecting UTF-8 or MBCS console I/O translations.
630696
*/
631
-static void console_prepare(void){
697
+static void console_prepare_utf8(void){
632698
HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
699
+ HANDLE hCO = GetStdHandle(STD_OUTPUT_HANDLE);
700
+ HANDLE hCC = INVALID_HANDLE_VALUE;
633701
DWORD consoleMode = 0;
634
- if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR
635
- && GetConsoleMode( hCI, &consoleMode) ){
636
- if( !IsValidCodePage(CP_UTF8) ){
637
- fprintf(stderr, "Cannot use UTF-8 code page.\n");
638
- console_utf8 = 0;
639
- return;
640
- }
641
- conState.hConsoleIn = hCI;
642
- conState.consoleMode = consoleMode;
643
- conState.inCodePage = GetConsoleCP();
644
- conState.outCodePage = GetConsoleOutputCP();
645
- SetConsoleCP(CP_UTF8);
646
- SetConsoleOutputCP(CP_UTF8);
702
+ u8 conI = 0, conO = 0;
703
+ struct ConsoleState csWork = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
704
+
705
+ console_utf8_in = console_utf8_out = 0;
706
+ if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR ) conI = 1;
707
+ if( isatty(1) && GetFileType(hCO)==FILE_TYPE_CHAR ) conO = 1;
708
+ if( (!conI && !conO) || mbcs_opted ) return;
709
+ if( conI ) hCC = hCI;
710
+ else hCC = hCO;
711
+ if( !IsValidCodePage(CP_UTF8) || !GetConsoleMode( hCC, &consoleMode) ){
712
+ bail:
713
+ fprintf(stderr, "Cannot use UTF-8 code page.\n");
714
+ return;
715
+ }
716
+ csWork.hConsole = hCC;
717
+ csWork.consoleMode = consoleMode;
718
+ csWork.inCodePage = GetConsoleCP();
719
+ csWork.outCodePage = GetConsoleOutputCP();
720
+ if( conI ){
721
+ if( !SetConsoleCP(CP_UTF8) ) goto bail;
647722
consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
648
- SetConsoleMode(conState.hConsoleIn, consoleMode);
649
- conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
650
- console_utf8 = 1;
651
- }else{
652
- console_utf8 = 0;
723
+ SetConsoleMode(conState.hConsole, consoleMode);
724
+ csWork.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
653725
}
726
+ if( conO ){
727
+ /* Here, it is assumed that if conI is true, this call will also
728
+ ** succeed, so there is no need to undo above setup upon failure. */
729
+ if( !SetConsoleOutputCP(CP_UTF8) ) goto bail;
730
+ }
731
+ console_utf8_in = conI;
732
+ console_utf8_out = conO;
733
+ conState = csWork;
654734
}
655735
656736
/*
657
-** Undo the effects of console_prepare(), if any.
737
+** Undo the effects of console_prepare_utf8(), if any.
658738
*/
659739
static void SQLITE_CDECL console_restore(void){
660
- if( console_utf8 && conState.inCodePage!=0
661
- && conState.hConsoleIn!=INVALID_HANDLE_VALUE ){
662
- _setmode(_fileno(stdin), conState.infsMode);
663
- SetConsoleCP(conState.inCodePage);
664
- SetConsoleOutputCP(conState.outCodePage);
665
- SetConsoleMode(conState.hConsoleIn, conState.consoleMode);
740
+ if( (console_utf8_in||console_utf8_out)
741
+ && conState.hConsole!=INVALID_HANDLE_VALUE ){
742
+ if( console_utf8_in ){
743
+ SetConsoleCP(conState.inCodePage);
744
+ _setmode(_fileno(stdin), conState.infsMode);
745
+ }
746
+ if( console_utf8_out ) SetConsoleOutputCP(conState.outCodePage);
747
+ SetConsoleMode(conState.hConsole, conState.consoleMode);
666748
/* Avoid multiple calls. */
667
- conState.hConsoleIn = INVALID_HANDLE_VALUE;
749
+ conState.hConsole = INVALID_HANDLE_VALUE;
668750
conState.consoleMode = 0;
669
- console_utf8 = 0;
751
+ console_utf8_in = 0;
752
+ console_utf8_out = 0;
670753
}
671754
}
672755
673756
/*
674757
** Collect input like fgets(...) with special provisions for input
675758
** from the Windows console to get around its strange coding issues.
676759
** Defers to plain fgets() when input is not interactive or when the
677
-** startup option, -utf8, has not been provided or taken effect.
760
+** UTF-8 input is unavailable or opted out.
678761
*/
679762
static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
680763
if( fin==0 ) fin = stdin;
681
- if( fin==stdin && stdin_is_interactive && console_utf8 ){
764
+ if( fin==stdin && stdin_is_interactive && console_utf8_in ){
682765
# define SQLITE_IALIM 150
683766
wchar_t wbuf[SQLITE_IALIM];
684767
int lend = 0;
685768
int noc = 0;
686769
if( ncmax==0 || conState.stdinEof ) return 0;
@@ -689,11 +772,11 @@
689772
/* There is room for at least 2 more characters and a 0-terminator. */
690773
int na = (ncmax > SQLITE_IALIM*4+1 + noc)
691774
? SQLITE_IALIM : (ncmax-1 - noc)/4;
692775
# undef SQLITE_IALIM
693776
DWORD nbr = 0;
694
- BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
777
+ BOOL bRC = ReadConsoleW(conState.hConsole, wbuf, na, &nbr, 0);
695778
if( !bRC || (noc==0 && nbr==0) ) return 0;
696779
if( nbr > 0 ){
697780
int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
698781
wbuf,nbr,0,0,0,0);
699782
if( nmb !=0 && noc+nmb <= ncmax ){
@@ -735,20 +818,20 @@
735818
# define fgets(b,n,f) utf8_fgets(b,n,f)
736819
#endif /* SHELL_WIN_UTF8_OPT */
737820
738821
/*
739822
** Render output like fprintf(). Except, if the output is going to the
740
-** console and if this is running on a Windows machine, and if the -utf8
741
-** option is unavailable or (available and inactive), translate the
823
+** console and if this is running on a Windows machine, and if UTF-8
824
+** output unavailable (or available but opted out), translate the
742825
** output from UTF-8 into MBCS for output through 8-bit stdout stream.
743
-** (With -utf8 active, no translation is needed and must not be done.)
826
+** (Without -no-utf8, no translation is needed and must not be done.)
744827
*/
745828
#if defined(_WIN32) || defined(WIN32)
746829
void utf8_printf(FILE *out, const char *zFormat, ...){
747830
va_list ap;
748831
va_start(ap, zFormat);
749
- if( stdout_is_console && (out==stdout || out==stderr) && !console_utf8 ){
832
+ if( stdout_is_console && (out==stdout || out==stderr) && !console_utf8_out ){
750833
char *z1 = sqlite3_vmprintf(zFormat, ap);
751834
char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
752835
sqlite3_free(z1);
753836
fputs(z2, out);
754837
sqlite3_free(z2);
@@ -955,14 +1038,14 @@
9551038
zLine[n] = 0;
9561039
break;
9571040
}
9581041
}
9591042
#if defined(_WIN32) || defined(WIN32)
960
- /* For interactive input on Windows systems, without -utf8,
1043
+ /* For interactive input on Windows systems, with -no-utf8,
9611044
** translate the multi-byte characterset characters into UTF-8.
962
- ** This is the translation that predates the -utf8 option. */
963
- if( stdin_is_interactive && in==stdin && !console_utf8 ){
1045
+ ** This is the translation that predates console UTF-8 input. */
1046
+ if( stdin_is_interactive && in==stdin && !console_utf8_in ){
9641047
char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
9651048
if( zTrans ){
9661049
i64 nTrans = strlen(zTrans)+1;
9671050
if( nTrans>nLine ){
9681051
zLine = realloc(zLine, nTrans);
@@ -8517,10 +8600,11 @@
85178600
/* #include "sqlite3ext.h" */
85188601
SQLITE_EXTENSION_INIT1
85198602
#include <stdio.h>
85208603
#include <string.h>
85218604
#include <assert.h>
8605
+#include <stdint.h>
85228606
85238607
#include <zlib.h>
85248608
85258609
#ifndef SQLITE_OMIT_VIRTUALTABLE
85268610
@@ -27823,11 +27907,11 @@
2782327907
" -multiplex enable the multiplexor VFS\n"
2782427908
#endif
2782527909
" -newline SEP set output row separator. Default: '\\n'\n"
2782627910
#if SHELL_WIN_UTF8_OPT
2782727911
" -no-utf8 do not try to set up UTF-8 output (for legacy)\n"
27828
-#endif
27912
+#endif
2782927913
" -nofollow refuse to open symbolic links to database files\n"
2783027914
" -nonce STRING set the safe-mode escape nonce\n"
2783127915
" -nullvalue TEXT set text string for NULL values. Default ''\n"
2783227916
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
2783327917
" -pcachetrace trace all page cache operations\n"
@@ -27840,11 +27924,11 @@
2784027924
#endif
2784127925
" -stats print memory stats before each finalize\n"
2784227926
" -table set output mode to 'table'\n"
2784327927
" -tabs set output mode to 'tabs'\n"
2784427928
" -unsafe-testing allow unsafe commands and modes for testing\n"
27845
-#if SHELL_WIN_UTF8_OPT
27929
+#if SHELL_WIN_UTF8_OPT && 0 /* Option is accepted, but is now the default. */
2784627930
" -utf8 setup interactive console code page for UTF-8\n"
2784727931
#endif
2784827932
" -version show SQLite version\n"
2784927933
" -vfs NAME use NAME as the default VFS\n"
2785027934
#ifdef SQLITE_ENABLE_VFSTRACE
@@ -28075,15 +28159,25 @@
2807528159
extern void SQLITE_SHELL_DBNAME_PROC(const char**);
2807628160
SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
2807728161
warnInmemoryDb = 0;
2807828162
}
2807928163
#endif
28164
+
28165
+#if SHELL_WIN_UTF8_OPT
28166
+ /* If Windows build and not RT, set default MBCS/UTF-8 translation for
28167
+ ** console according to detected Windows version. This default may be
28168
+ ** overridden by a -no-utf8 or (undocumented) -utf8 invocation option.
28169
+ ** If a runtime check for UTF-8 console I/O capability is devised,
28170
+ ** that should be preferred over this version check.
28171
+ */
28172
+ mbcs_opted = (IS_WIN10_OR_LATER())? 0 : 1;
28173
+#endif
2808028174
2808128175
/* Do an initial pass through the command-line argument to locate
2808228176
** the name of the database file, the name of the initialization file,
28083
- ** the size of the alternative malloc heap,
28084
- ** and the first command to execute.
28177
+ ** the size of the alternative malloc heap, options affecting commands
28178
+ ** or SQL run from the command line, and the first command to execute.
2808528179
*/
2808628180
#ifndef SQLITE_SHELL_FIDDLE
2808728181
verify_uninitialized();
2808828182
#endif
2808928183
for(i=1; i<argc; i++){
@@ -28113,16 +28207,30 @@
2811328207
|| cli_strcmp(z,"-cmd")==0
2811428208
){
2811528209
(void)cmdline_option_value(argc, argv, ++i);
2811628210
}else if( cli_strcmp(z,"-init")==0 ){
2811728211
zInitFile = cmdline_option_value(argc, argv, ++i);
28212
+ }else if( cli_strcmp(z,"-interactive")==0 ){
28213
+ /* Need to check for interactive override here to so that it can
28214
+ ** affect console setup (for Windows only) and testing thereof.
28215
+ */
28216
+ stdin_is_interactive = 1;
2811828217
}else if( cli_strcmp(z,"-batch")==0 ){
2811928218
/* Need to check for batch mode here to so we can avoid printing
2812028219
** informational messages (like from process_sqliterc) before
2812128220
** we do the actual processing of arguments later in a second pass.
2812228221
*/
2812328222
stdin_is_interactive = 0;
28223
+ }else if( cli_strcmp(z,"-utf8")==0 ){
28224
+#if SHELL_WIN_UTF8_OPT
28225
+ /* Option accepted, but just specifies default UTF-8 console I/O. */
28226
+ mbcs_opted = 0;
28227
+#endif /* SHELL_WIN_UTF8_OPT */
28228
+ }else if( cli_strcmp(z,"-no-utf8")==0 ){
28229
+#if SHELL_WIN_UTF8_OPT
28230
+ mbcs_opted = 1;
28231
+#endif /* SHELL_WIN_UTF8_OPT */
2812428232
}else if( cli_strcmp(z,"-heap")==0 ){
2812528233
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2812628234
const char *zSize;
2812728235
sqlite3_int64 szHeap;
2812828236
@@ -28257,10 +28365,19 @@
2825728365
}else{
2825828366
utf8_printf(stderr, "no such VFS: \"%s\"\n", zVfs);
2825928367
exit(1);
2826028368
}
2826128369
}
28370
+#if SHELL_WIN_UTF8_OPT
28371
+ /* Get indicated Windows console setup done before running invocation commands. */
28372
+ if( stdin_is_interactive || stdout_is_console ){
28373
+ console_prepare_utf8();
28374
+ }
28375
+ if( !stdin_is_interactive ){
28376
+ setBinaryMode(stdin, 0);
28377
+ }
28378
+#endif
2826228379
2826328380
if( data.pAuxDb->zDbFilename==0 ){
2826428381
#ifndef SQLITE_OMIT_MEMORYDB
2826528382
data.pAuxDb->zDbFilename = ":memory:";
2826628383
warnInmemoryDb = argc==1;
@@ -28384,21 +28501,17 @@
2838428501
}else if( cli_strcmp(z,"-version")==0 ){
2838528502
printf("%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(),
2838628503
8*(int)sizeof(char*));
2838728504
return 0;
2838828505
}else if( cli_strcmp(z,"-interactive")==0 ){
28389
- stdin_is_interactive = 1;
28506
+ /* already handled */
2839028507
}else if( cli_strcmp(z,"-batch")==0 ){
28391
- stdin_is_interactive = 0;
28508
+ /* already handled */
2839228509
}else if( cli_strcmp(z,"-utf8")==0 ){
28393
-#if SHELL_WIN_UTF8_OPT
28394
- console_utf8 = 1;
28395
-#endif /* SHELL_WIN_UTF8_OPT */
28510
+ /* already handled */
2839628511
}else if( cli_strcmp(z,"-no-utf8")==0 ){
28397
-#if SHELL_WIN_UTF8_OPT
28398
- console_utf8 = 0;
28399
-#endif /* SHELL_WIN_UTF8_OPT */
28512
+ /* already handled */
2840028513
}else if( cli_strcmp(z,"-heap")==0 ){
2840128514
i++;
2840228515
}else if( cli_strcmp(z,"-pagecache")==0 ){
2840328516
i+=2;
2840428517
}else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -28476,18 +28589,10 @@
2847628589
raw_printf(stderr,"Use -help for a list of options.\n");
2847728590
return 1;
2847828591
}
2847928592
data.cMode = data.mode;
2848028593
}
28481
-#if SHELL_WIN_UTF8_OPT
28482
- if( console_utf8 && stdin_is_interactive ){
28483
- console_prepare();
28484
- }else{
28485
- setBinaryMode(stdin, 0);
28486
- console_utf8 = 0;
28487
- }
28488
-#endif
2848928594
2849028595
if( !readStdin ){
2849128596
/* Run all arguments that do not begin with '-' as if they were separate
2849228597
** command-line inputs, except for the argToSkip argument which contains
2849328598
** the database filename.
@@ -28522,11 +28627,16 @@
2852228627
char *zHome;
2852328628
char *zHistory;
2852428629
const char *zCharset = "";
2852528630
int nHistory;
2852628631
#if SHELL_WIN_UTF8_OPT
28527
- if( console_utf8 ) zCharset = " (utf8)";
28632
+ switch( console_utf8_in+2*console_utf8_out ){
28633
+ default: case 0: break;
28634
+ case 1: zCharset = " (utf8 in)"; break;
28635
+ case 2: zCharset = " (utf8 out)"; break;
28636
+ case 3: zCharset = " (utf8 I/O)"; break;
28637
+ }
2852828638
#endif
2852928639
printf(
2853028640
"SQLite version %s %.19s%s\n" /*extra-version-info*/
2853128641
"Enter \".help\" for usage hints.\n",
2853228642
sqlite3_libversion(), sqlite3_sourceid(), zCharset
2853328643
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -465,15 +465,24 @@
465 ** Treat stdin as an interactive input if the following variable
466 ** is true. Otherwise, assume stdin is connected to a file or pipe.
467 */
468 static int stdin_is_interactive = 1;
469
 
 
 
 
 
470 #if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
471 && !defined(SHELL_OMIT_WIN_UTF8)
472 # define SHELL_WIN_UTF8_OPT 1
473 static int console_utf8 = sizeof(char*)/4 - 1;
 
 
474 #else
 
 
475 # define SHELL_WIN_UTF8_OPT 0
476 #endif
477
478 /*
479 ** On Windows systems we have to know if standard output is a console
@@ -606,81 +615,155 @@
606 return dynPrompt.dynamicPrompt;
607 }
608 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
609
610 #if SHELL_WIN_UTF8_OPT
611 /* Following struct is used for -utf8 operation. */
612 static struct ConsoleState {
613 int stdinEof; /* EOF has been seen on console input */
614 int infsMode; /* Input file stream mode upon shell start */
615 UINT inCodePage; /* Input code page upon shell start */
616 UINT outCodePage; /* Output code page upon shell start */
617 HANDLE hConsoleIn; /* Console input handle */
618 DWORD consoleMode; /* Console mode upon shell start */
619 } conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
620
621 #ifndef _O_U16TEXT /* For build environments lacking this constant: */
622 # define _O_U16TEXT 0x20000
623 #endif
624
 
 
625 /*
626 ** Prepare console, (if known to be a WIN32 console), for UTF-8
627 ** input (from either typing or suitable paste operations) and for
628 ** UTF-8 rendering. This may "fail" with a message to stderr, where
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629 ** the preparation is not done and common "code page" issues occur.
 
 
 
 
 
 
630 */
631 static void console_prepare(void){
632 HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
 
 
633 DWORD consoleMode = 0;
634 if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR
635 && GetConsoleMode( hCI, &consoleMode) ){
636 if( !IsValidCodePage(CP_UTF8) ){
637 fprintf(stderr, "Cannot use UTF-8 code page.\n");
638 console_utf8 = 0;
639 return;
640 }
641 conState.hConsoleIn = hCI;
642 conState.consoleMode = consoleMode;
643 conState.inCodePage = GetConsoleCP();
644 conState.outCodePage = GetConsoleOutputCP();
645 SetConsoleCP(CP_UTF8);
646 SetConsoleOutputCP(CP_UTF8);
 
 
 
 
 
 
 
647 consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
648 SetConsoleMode(conState.hConsoleIn, consoleMode);
649 conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
650 console_utf8 = 1;
651 }else{
652 console_utf8 = 0;
653 }
 
 
 
 
 
 
 
 
654 }
655
656 /*
657 ** Undo the effects of console_prepare(), if any.
658 */
659 static void SQLITE_CDECL console_restore(void){
660 if( console_utf8 && conState.inCodePage!=0
661 && conState.hConsoleIn!=INVALID_HANDLE_VALUE ){
662 _setmode(_fileno(stdin), conState.infsMode);
663 SetConsoleCP(conState.inCodePage);
664 SetConsoleOutputCP(conState.outCodePage);
665 SetConsoleMode(conState.hConsoleIn, conState.consoleMode);
 
 
666 /* Avoid multiple calls. */
667 conState.hConsoleIn = INVALID_HANDLE_VALUE;
668 conState.consoleMode = 0;
669 console_utf8 = 0;
 
670 }
671 }
672
673 /*
674 ** Collect input like fgets(...) with special provisions for input
675 ** from the Windows console to get around its strange coding issues.
676 ** Defers to plain fgets() when input is not interactive or when the
677 ** startup option, -utf8, has not been provided or taken effect.
678 */
679 static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
680 if( fin==0 ) fin = stdin;
681 if( fin==stdin && stdin_is_interactive && console_utf8 ){
682 # define SQLITE_IALIM 150
683 wchar_t wbuf[SQLITE_IALIM];
684 int lend = 0;
685 int noc = 0;
686 if( ncmax==0 || conState.stdinEof ) return 0;
@@ -689,11 +772,11 @@
689 /* There is room for at least 2 more characters and a 0-terminator. */
690 int na = (ncmax > SQLITE_IALIM*4+1 + noc)
691 ? SQLITE_IALIM : (ncmax-1 - noc)/4;
692 # undef SQLITE_IALIM
693 DWORD nbr = 0;
694 BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
695 if( !bRC || (noc==0 && nbr==0) ) return 0;
696 if( nbr > 0 ){
697 int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
698 wbuf,nbr,0,0,0,0);
699 if( nmb !=0 && noc+nmb <= ncmax ){
@@ -735,20 +818,20 @@
735 # define fgets(b,n,f) utf8_fgets(b,n,f)
736 #endif /* SHELL_WIN_UTF8_OPT */
737
738 /*
739 ** Render output like fprintf(). Except, if the output is going to the
740 ** console and if this is running on a Windows machine, and if the -utf8
741 ** option is unavailable or (available and inactive), translate the
742 ** output from UTF-8 into MBCS for output through 8-bit stdout stream.
743 ** (With -utf8 active, no translation is needed and must not be done.)
744 */
745 #if defined(_WIN32) || defined(WIN32)
746 void utf8_printf(FILE *out, const char *zFormat, ...){
747 va_list ap;
748 va_start(ap, zFormat);
749 if( stdout_is_console && (out==stdout || out==stderr) && !console_utf8 ){
750 char *z1 = sqlite3_vmprintf(zFormat, ap);
751 char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
752 sqlite3_free(z1);
753 fputs(z2, out);
754 sqlite3_free(z2);
@@ -955,14 +1038,14 @@
955 zLine[n] = 0;
956 break;
957 }
958 }
959 #if defined(_WIN32) || defined(WIN32)
960 /* For interactive input on Windows systems, without -utf8,
961 ** translate the multi-byte characterset characters into UTF-8.
962 ** This is the translation that predates the -utf8 option. */
963 if( stdin_is_interactive && in==stdin && !console_utf8 ){
964 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
965 if( zTrans ){
966 i64 nTrans = strlen(zTrans)+1;
967 if( nTrans>nLine ){
968 zLine = realloc(zLine, nTrans);
@@ -8517,10 +8600,11 @@
8517 /* #include "sqlite3ext.h" */
8518 SQLITE_EXTENSION_INIT1
8519 #include <stdio.h>
8520 #include <string.h>
8521 #include <assert.h>
 
8522
8523 #include <zlib.h>
8524
8525 #ifndef SQLITE_OMIT_VIRTUALTABLE
8526
@@ -27823,11 +27907,11 @@
27823 " -multiplex enable the multiplexor VFS\n"
27824 #endif
27825 " -newline SEP set output row separator. Default: '\\n'\n"
27826 #if SHELL_WIN_UTF8_OPT
27827 " -no-utf8 do not try to set up UTF-8 output (for legacy)\n"
27828 #endif
27829 " -nofollow refuse to open symbolic links to database files\n"
27830 " -nonce STRING set the safe-mode escape nonce\n"
27831 " -nullvalue TEXT set text string for NULL values. Default ''\n"
27832 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
27833 " -pcachetrace trace all page cache operations\n"
@@ -27840,11 +27924,11 @@
27840 #endif
27841 " -stats print memory stats before each finalize\n"
27842 " -table set output mode to 'table'\n"
27843 " -tabs set output mode to 'tabs'\n"
27844 " -unsafe-testing allow unsafe commands and modes for testing\n"
27845 #if SHELL_WIN_UTF8_OPT
27846 " -utf8 setup interactive console code page for UTF-8\n"
27847 #endif
27848 " -version show SQLite version\n"
27849 " -vfs NAME use NAME as the default VFS\n"
27850 #ifdef SQLITE_ENABLE_VFSTRACE
@@ -28075,15 +28159,25 @@
28075 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
28076 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
28077 warnInmemoryDb = 0;
28078 }
28079 #endif
 
 
 
 
 
 
 
 
 
 
28080
28081 /* Do an initial pass through the command-line argument to locate
28082 ** the name of the database file, the name of the initialization file,
28083 ** the size of the alternative malloc heap,
28084 ** and the first command to execute.
28085 */
28086 #ifndef SQLITE_SHELL_FIDDLE
28087 verify_uninitialized();
28088 #endif
28089 for(i=1; i<argc; i++){
@@ -28113,16 +28207,30 @@
28113 || cli_strcmp(z,"-cmd")==0
28114 ){
28115 (void)cmdline_option_value(argc, argv, ++i);
28116 }else if( cli_strcmp(z,"-init")==0 ){
28117 zInitFile = cmdline_option_value(argc, argv, ++i);
 
 
 
 
 
28118 }else if( cli_strcmp(z,"-batch")==0 ){
28119 /* Need to check for batch mode here to so we can avoid printing
28120 ** informational messages (like from process_sqliterc) before
28121 ** we do the actual processing of arguments later in a second pass.
28122 */
28123 stdin_is_interactive = 0;
 
 
 
 
 
 
 
 
 
28124 }else if( cli_strcmp(z,"-heap")==0 ){
28125 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
28126 const char *zSize;
28127 sqlite3_int64 szHeap;
28128
@@ -28257,10 +28365,19 @@
28257 }else{
28258 utf8_printf(stderr, "no such VFS: \"%s\"\n", zVfs);
28259 exit(1);
28260 }
28261 }
 
 
 
 
 
 
 
 
 
28262
28263 if( data.pAuxDb->zDbFilename==0 ){
28264 #ifndef SQLITE_OMIT_MEMORYDB
28265 data.pAuxDb->zDbFilename = ":memory:";
28266 warnInmemoryDb = argc==1;
@@ -28384,21 +28501,17 @@
28384 }else if( cli_strcmp(z,"-version")==0 ){
28385 printf("%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(),
28386 8*(int)sizeof(char*));
28387 return 0;
28388 }else if( cli_strcmp(z,"-interactive")==0 ){
28389 stdin_is_interactive = 1;
28390 }else if( cli_strcmp(z,"-batch")==0 ){
28391 stdin_is_interactive = 0;
28392 }else if( cli_strcmp(z,"-utf8")==0 ){
28393 #if SHELL_WIN_UTF8_OPT
28394 console_utf8 = 1;
28395 #endif /* SHELL_WIN_UTF8_OPT */
28396 }else if( cli_strcmp(z,"-no-utf8")==0 ){
28397 #if SHELL_WIN_UTF8_OPT
28398 console_utf8 = 0;
28399 #endif /* SHELL_WIN_UTF8_OPT */
28400 }else if( cli_strcmp(z,"-heap")==0 ){
28401 i++;
28402 }else if( cli_strcmp(z,"-pagecache")==0 ){
28403 i+=2;
28404 }else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -28476,18 +28589,10 @@
28476 raw_printf(stderr,"Use -help for a list of options.\n");
28477 return 1;
28478 }
28479 data.cMode = data.mode;
28480 }
28481 #if SHELL_WIN_UTF8_OPT
28482 if( console_utf8 && stdin_is_interactive ){
28483 console_prepare();
28484 }else{
28485 setBinaryMode(stdin, 0);
28486 console_utf8 = 0;
28487 }
28488 #endif
28489
28490 if( !readStdin ){
28491 /* Run all arguments that do not begin with '-' as if they were separate
28492 ** command-line inputs, except for the argToSkip argument which contains
28493 ** the database filename.
@@ -28522,11 +28627,16 @@
28522 char *zHome;
28523 char *zHistory;
28524 const char *zCharset = "";
28525 int nHistory;
28526 #if SHELL_WIN_UTF8_OPT
28527 if( console_utf8 ) zCharset = " (utf8)";
 
 
 
 
 
28528 #endif
28529 printf(
28530 "SQLite version %s %.19s%s\n" /*extra-version-info*/
28531 "Enter \".help\" for usage hints.\n",
28532 sqlite3_libversion(), sqlite3_sourceid(), zCharset
28533
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -465,15 +465,24 @@
465 ** Treat stdin as an interactive input if the following variable
466 ** is true. Otherwise, assume stdin is connected to a file or pipe.
467 */
468 static int stdin_is_interactive = 1;
469
470 /*
471 ** If build is for Windows, without 3rd-party line editing, Console
472 ** input and output may be done in a UTF-8 compatible way. This is
473 ** determined by invocation option and OS installed capability.
474 */
475 #if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
476 && !defined(SHELL_OMIT_WIN_UTF8)
477 # define SHELL_WIN_UTF8_OPT 1
478 static int console_utf8_in = 0;
479 static int console_utf8_out = 0;
480 static int mbcs_opted = 0;
481 #else
482 # define console_utf8_in 0
483 # define console_utf8_out 0
484 # define SHELL_WIN_UTF8_OPT 0
485 #endif
486
487 /*
488 ** On Windows systems we have to know if standard output is a console
@@ -606,81 +615,155 @@
615 return dynPrompt.dynamicPrompt;
616 }
617 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
618
619 #if SHELL_WIN_UTF8_OPT
620 /* Following struct is used for UTF-8 operation. */
621 static struct ConsoleState {
622 int stdinEof; /* EOF has been seen on console input */
623 int infsMode; /* Input file stream mode upon shell start */
624 UINT inCodePage; /* Input code page upon shell start */
625 UINT outCodePage; /* Output code page upon shell start */
626 HANDLE hConsole; /* Console input or output handle */
627 DWORD consoleMode; /* Console mode upon shell start */
628 } conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
629
630 #ifndef _O_U16TEXT /* For build environments lacking this constant: */
631 # define _O_U16TEXT 0x20000
632 #endif
633
634
635 #if !SQLITE_OS_WINRT
636 /*
637 ** Check Windows major version against given value, returning
638 ** 1 if the OS major version is no less than the argument.
639 ** This check uses very late binding to the registry access
640 ** API so that it can operate gracefully on OS versions that
641 ** do not have that API. The Windows NT registry, for versions
642 ** through Windows 11 (at least, as of October 2023), keeps
643 ** the actual major version number at registry key/value
644 ** HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentMajorVersionNumber
645 ** where it can be read more reliably than allowed by various
646 ** version info APIs which "process" the result in a manner
647 ** incompatible with the purpose of the CLI's version check.
648 **
649 ** If the registry API is unavailable, or the location of
650 ** the above registry value changes, or the OS major version
651 ** is less than the argument, this function returns 0.
652 */
653 static int CheckAtLeastWinX(DWORD major_version){
654 typedef LONG (WINAPI *REG_OPEN)(HKEY,LPCSTR,DWORD,REGSAM,PHKEY);
655 typedef LSTATUS (WINAPI *REG_READ)(HKEY,LPCSTR,LPCSTR,DWORD,
656 LPDWORD,PVOID,LPDWORD);
657 typedef LSTATUS (WINAPI *REG_CLOSE)(HKEY);
658 int rv = 0;
659 HINSTANCE hLib = LoadLibrary(TEXT("Advapi32.dll"));
660 if( NULL != hLib ){
661 REG_OPEN rkOpen = (REG_OPEN)GetProcAddress(hLib, "RegOpenKeyExA");
662 REG_READ rkRead = (REG_READ)GetProcAddress(hLib, "RegGetValueA");
663 REG_CLOSE rkFree = (REG_CLOSE)GetProcAddress(hLib, "RegCloseKey");
664 if( rkOpen != NULL && rkRead != NULL && rkFree != NULL ){
665 HKEY hk;
666 const char *zsk = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
667 if( ERROR_SUCCESS == rkOpen(HKEY_LOCAL_MACHINE, zsk, 0, KEY_READ, &hk) ){
668 DWORD kv = 0, kvsize = sizeof(kv);
669 if( ERROR_SUCCESS == rkRead(hk, 0, "CurrentMajorVersionNumber",
670 RRF_RT_REG_DWORD, 0, &kv, &kvsize) ){
671 rv = (kv >= major_version);
672 }
673 rkFree(hk);
674 }
675 }
676 FreeLibrary(hLib);
677 }
678 return rv;
679 }
680 # define IS_WIN10_OR_LATER() CheckAtLeastWinX(10)
681 #else /* defined(SQLITE_OS_WINRT) */
682 # define IS_WIN10_OR_LATER() 0
683 #endif
684
685 /*
686 ** Prepare console, (if known to be a WIN32 console), for UTF-8 input
687 ** (from either typing or suitable paste operations) and/or for UTF-8
688 ** output rendering. This may "fail" with a message to stderr, where
689 ** the preparation is not done and common "code page" issues occur.
690 **
691 ** The console state upon entry is preserved, in conState, so that
692 ** console_restore() can later restore the same console state.
693 **
694 ** The globals console_utf8_in and console_utf8_out are set, for
695 ** later use in selecting UTF-8 or MBCS console I/O translations.
696 */
697 static void console_prepare_utf8(void){
698 HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
699 HANDLE hCO = GetStdHandle(STD_OUTPUT_HANDLE);
700 HANDLE hCC = INVALID_HANDLE_VALUE;
701 DWORD consoleMode = 0;
702 u8 conI = 0, conO = 0;
703 struct ConsoleState csWork = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
704
705 console_utf8_in = console_utf8_out = 0;
706 if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR ) conI = 1;
707 if( isatty(1) && GetFileType(hCO)==FILE_TYPE_CHAR ) conO = 1;
708 if( (!conI && !conO) || mbcs_opted ) return;
709 if( conI ) hCC = hCI;
710 else hCC = hCO;
711 if( !IsValidCodePage(CP_UTF8) || !GetConsoleMode( hCC, &consoleMode) ){
712 bail:
713 fprintf(stderr, "Cannot use UTF-8 code page.\n");
714 return;
715 }
716 csWork.hConsole = hCC;
717 csWork.consoleMode = consoleMode;
718 csWork.inCodePage = GetConsoleCP();
719 csWork.outCodePage = GetConsoleOutputCP();
720 if( conI ){
721 if( !SetConsoleCP(CP_UTF8) ) goto bail;
722 consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
723 SetConsoleMode(conState.hConsole, consoleMode);
724 csWork.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
 
 
 
725 }
726 if( conO ){
727 /* Here, it is assumed that if conI is true, this call will also
728 ** succeed, so there is no need to undo above setup upon failure. */
729 if( !SetConsoleOutputCP(CP_UTF8) ) goto bail;
730 }
731 console_utf8_in = conI;
732 console_utf8_out = conO;
733 conState = csWork;
734 }
735
736 /*
737 ** Undo the effects of console_prepare_utf8(), if any.
738 */
739 static void SQLITE_CDECL console_restore(void){
740 if( (console_utf8_in||console_utf8_out)
741 && conState.hConsole!=INVALID_HANDLE_VALUE ){
742 if( console_utf8_in ){
743 SetConsoleCP(conState.inCodePage);
744 _setmode(_fileno(stdin), conState.infsMode);
745 }
746 if( console_utf8_out ) SetConsoleOutputCP(conState.outCodePage);
747 SetConsoleMode(conState.hConsole, conState.consoleMode);
748 /* Avoid multiple calls. */
749 conState.hConsole = INVALID_HANDLE_VALUE;
750 conState.consoleMode = 0;
751 console_utf8_in = 0;
752 console_utf8_out = 0;
753 }
754 }
755
756 /*
757 ** Collect input like fgets(...) with special provisions for input
758 ** from the Windows console to get around its strange coding issues.
759 ** Defers to plain fgets() when input is not interactive or when the
760 ** UTF-8 input is unavailable or opted out.
761 */
762 static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
763 if( fin==0 ) fin = stdin;
764 if( fin==stdin && stdin_is_interactive && console_utf8_in ){
765 # define SQLITE_IALIM 150
766 wchar_t wbuf[SQLITE_IALIM];
767 int lend = 0;
768 int noc = 0;
769 if( ncmax==0 || conState.stdinEof ) return 0;
@@ -689,11 +772,11 @@
772 /* There is room for at least 2 more characters and a 0-terminator. */
773 int na = (ncmax > SQLITE_IALIM*4+1 + noc)
774 ? SQLITE_IALIM : (ncmax-1 - noc)/4;
775 # undef SQLITE_IALIM
776 DWORD nbr = 0;
777 BOOL bRC = ReadConsoleW(conState.hConsole, wbuf, na, &nbr, 0);
778 if( !bRC || (noc==0 && nbr==0) ) return 0;
779 if( nbr > 0 ){
780 int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
781 wbuf,nbr,0,0,0,0);
782 if( nmb !=0 && noc+nmb <= ncmax ){
@@ -735,20 +818,20 @@
818 # define fgets(b,n,f) utf8_fgets(b,n,f)
819 #endif /* SHELL_WIN_UTF8_OPT */
820
821 /*
822 ** Render output like fprintf(). Except, if the output is going to the
823 ** console and if this is running on a Windows machine, and if UTF-8
824 ** output unavailable (or available but opted out), translate the
825 ** output from UTF-8 into MBCS for output through 8-bit stdout stream.
826 ** (Without -no-utf8, no translation is needed and must not be done.)
827 */
828 #if defined(_WIN32) || defined(WIN32)
829 void utf8_printf(FILE *out, const char *zFormat, ...){
830 va_list ap;
831 va_start(ap, zFormat);
832 if( stdout_is_console && (out==stdout || out==stderr) && !console_utf8_out ){
833 char *z1 = sqlite3_vmprintf(zFormat, ap);
834 char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
835 sqlite3_free(z1);
836 fputs(z2, out);
837 sqlite3_free(z2);
@@ -955,14 +1038,14 @@
1038 zLine[n] = 0;
1039 break;
1040 }
1041 }
1042 #if defined(_WIN32) || defined(WIN32)
1043 /* For interactive input on Windows systems, with -no-utf8,
1044 ** translate the multi-byte characterset characters into UTF-8.
1045 ** This is the translation that predates console UTF-8 input. */
1046 if( stdin_is_interactive && in==stdin && !console_utf8_in ){
1047 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
1048 if( zTrans ){
1049 i64 nTrans = strlen(zTrans)+1;
1050 if( nTrans>nLine ){
1051 zLine = realloc(zLine, nTrans);
@@ -8517,10 +8600,11 @@
8600 /* #include "sqlite3ext.h" */
8601 SQLITE_EXTENSION_INIT1
8602 #include <stdio.h>
8603 #include <string.h>
8604 #include <assert.h>
8605 #include <stdint.h>
8606
8607 #include <zlib.h>
8608
8609 #ifndef SQLITE_OMIT_VIRTUALTABLE
8610
@@ -27823,11 +27907,11 @@
27907 " -multiplex enable the multiplexor VFS\n"
27908 #endif
27909 " -newline SEP set output row separator. Default: '\\n'\n"
27910 #if SHELL_WIN_UTF8_OPT
27911 " -no-utf8 do not try to set up UTF-8 output (for legacy)\n"
27912 #endif
27913 " -nofollow refuse to open symbolic links to database files\n"
27914 " -nonce STRING set the safe-mode escape nonce\n"
27915 " -nullvalue TEXT set text string for NULL values. Default ''\n"
27916 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
27917 " -pcachetrace trace all page cache operations\n"
@@ -27840,11 +27924,11 @@
27924 #endif
27925 " -stats print memory stats before each finalize\n"
27926 " -table set output mode to 'table'\n"
27927 " -tabs set output mode to 'tabs'\n"
27928 " -unsafe-testing allow unsafe commands and modes for testing\n"
27929 #if SHELL_WIN_UTF8_OPT && 0 /* Option is accepted, but is now the default. */
27930 " -utf8 setup interactive console code page for UTF-8\n"
27931 #endif
27932 " -version show SQLite version\n"
27933 " -vfs NAME use NAME as the default VFS\n"
27934 #ifdef SQLITE_ENABLE_VFSTRACE
@@ -28075,15 +28159,25 @@
28159 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
28160 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
28161 warnInmemoryDb = 0;
28162 }
28163 #endif
28164
28165 #if SHELL_WIN_UTF8_OPT
28166 /* If Windows build and not RT, set default MBCS/UTF-8 translation for
28167 ** console according to detected Windows version. This default may be
28168 ** overridden by a -no-utf8 or (undocumented) -utf8 invocation option.
28169 ** If a runtime check for UTF-8 console I/O capability is devised,
28170 ** that should be preferred over this version check.
28171 */
28172 mbcs_opted = (IS_WIN10_OR_LATER())? 0 : 1;
28173 #endif
28174
28175 /* Do an initial pass through the command-line argument to locate
28176 ** the name of the database file, the name of the initialization file,
28177 ** the size of the alternative malloc heap, options affecting commands
28178 ** or SQL run from the command line, and the first command to execute.
28179 */
28180 #ifndef SQLITE_SHELL_FIDDLE
28181 verify_uninitialized();
28182 #endif
28183 for(i=1; i<argc; i++){
@@ -28113,16 +28207,30 @@
28207 || cli_strcmp(z,"-cmd")==0
28208 ){
28209 (void)cmdline_option_value(argc, argv, ++i);
28210 }else if( cli_strcmp(z,"-init")==0 ){
28211 zInitFile = cmdline_option_value(argc, argv, ++i);
28212 }else if( cli_strcmp(z,"-interactive")==0 ){
28213 /* Need to check for interactive override here to so that it can
28214 ** affect console setup (for Windows only) and testing thereof.
28215 */
28216 stdin_is_interactive = 1;
28217 }else if( cli_strcmp(z,"-batch")==0 ){
28218 /* Need to check for batch mode here to so we can avoid printing
28219 ** informational messages (like from process_sqliterc) before
28220 ** we do the actual processing of arguments later in a second pass.
28221 */
28222 stdin_is_interactive = 0;
28223 }else if( cli_strcmp(z,"-utf8")==0 ){
28224 #if SHELL_WIN_UTF8_OPT
28225 /* Option accepted, but just specifies default UTF-8 console I/O. */
28226 mbcs_opted = 0;
28227 #endif /* SHELL_WIN_UTF8_OPT */
28228 }else if( cli_strcmp(z,"-no-utf8")==0 ){
28229 #if SHELL_WIN_UTF8_OPT
28230 mbcs_opted = 1;
28231 #endif /* SHELL_WIN_UTF8_OPT */
28232 }else if( cli_strcmp(z,"-heap")==0 ){
28233 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
28234 const char *zSize;
28235 sqlite3_int64 szHeap;
28236
@@ -28257,10 +28365,19 @@
28365 }else{
28366 utf8_printf(stderr, "no such VFS: \"%s\"\n", zVfs);
28367 exit(1);
28368 }
28369 }
28370 #if SHELL_WIN_UTF8_OPT
28371 /* Get indicated Windows console setup done before running invocation commands. */
28372 if( stdin_is_interactive || stdout_is_console ){
28373 console_prepare_utf8();
28374 }
28375 if( !stdin_is_interactive ){
28376 setBinaryMode(stdin, 0);
28377 }
28378 #endif
28379
28380 if( data.pAuxDb->zDbFilename==0 ){
28381 #ifndef SQLITE_OMIT_MEMORYDB
28382 data.pAuxDb->zDbFilename = ":memory:";
28383 warnInmemoryDb = argc==1;
@@ -28384,21 +28501,17 @@
28501 }else if( cli_strcmp(z,"-version")==0 ){
28502 printf("%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(),
28503 8*(int)sizeof(char*));
28504 return 0;
28505 }else if( cli_strcmp(z,"-interactive")==0 ){
28506 /* already handled */
28507 }else if( cli_strcmp(z,"-batch")==0 ){
28508 /* already handled */
28509 }else if( cli_strcmp(z,"-utf8")==0 ){
28510 /* already handled */
 
 
28511 }else if( cli_strcmp(z,"-no-utf8")==0 ){
28512 /* already handled */
 
 
28513 }else if( cli_strcmp(z,"-heap")==0 ){
28514 i++;
28515 }else if( cli_strcmp(z,"-pagecache")==0 ){
28516 i+=2;
28517 }else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -28476,18 +28589,10 @@
28589 raw_printf(stderr,"Use -help for a list of options.\n");
28590 return 1;
28591 }
28592 data.cMode = data.mode;
28593 }
 
 
 
 
 
 
 
 
28594
28595 if( !readStdin ){
28596 /* Run all arguments that do not begin with '-' as if they were separate
28597 ** command-line inputs, except for the argToSkip argument which contains
28598 ** the database filename.
@@ -28522,11 +28627,16 @@
28627 char *zHome;
28628 char *zHistory;
28629 const char *zCharset = "";
28630 int nHistory;
28631 #if SHELL_WIN_UTF8_OPT
28632 switch( console_utf8_in+2*console_utf8_out ){
28633 default: case 0: break;
28634 case 1: zCharset = " (utf8 in)"; break;
28635 case 2: zCharset = " (utf8 out)"; break;
28636 case 3: zCharset = " (utf8 I/O)"; break;
28637 }
28638 #endif
28639 printf(
28640 "SQLite version %s %.19s%s\n" /*extra-version-info*/
28641 "Enter \".help\" for usage hints.\n",
28642 sqlite3_libversion(), sqlite3_sourceid(), zCharset
28643
+146 -79
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 4be9af4469d7e31ee852f67e5aa32996557.
21
+** ddc6ead6453e0f98943bd07aedd90d47bc2e.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460460
** [sqlite_version()] and [sqlite_source_id()].
461461
*/
462462
#define SQLITE_VERSION "3.44.0"
463463
#define SQLITE_VERSION_NUMBER 3044000
464
-#define SQLITE_SOURCE_ID "2023-10-24 11:06:44 54be9af4469d7e31ee852f67e5aa32996557c10de654a60103fd165d2fedf311"
464
+#define SQLITE_SOURCE_ID "2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1"
465465
466466
/*
467467
** CAPI3REF: Run-Time Library Version Numbers
468468
** KEYWORDS: sqlite3_version sqlite3_sourceid
469469
**
@@ -2438,11 +2438,11 @@
24382438
** of a table column that its values are likely to be very large - larger
24392439
** than the configured sorter-reference size threshold - then a reference
24402440
** is stored in each sorted record and the required column values loaded
24412441
** from the database as records are returned in sorted order. The default
24422442
** value for this option is to never use this optimization. Specifying a
2443
-** negative value for this option restores the default behaviour.
2443
+** negative value for this option restores the default behavior.
24442444
** This option is only available if SQLite is compiled with the
24452445
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
24462446
**
24472447
** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
24482448
** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2613,11 +2613,11 @@
26132613
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
26142614
** <dd> Usually, when a database in wal mode is closed or detached from a
26152615
** database handle, SQLite checks if this will mean that there are now no
26162616
** connections at all to the database. If so, it performs a checkpoint
26172617
** operation before closing the connection. This option may be used to
2618
-** override this behaviour. The first parameter passed to this operation
2618
+** override this behavior. The first parameter passed to this operation
26192619
** is an integer - positive to disable checkpoints-on-close, or zero (the
26202620
** default) to enable them, and negative to leave the setting unchanged.
26212621
** The second parameter is a pointer to an integer
26222622
** into which is written 0 or 1 to indicate whether checkpoints-on-close
26232623
** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -4266,10 +4266,11 @@
42664266
** <li> sqlite3_error_offset()
42674267
** </ul>
42684268
**
42694269
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
42704270
** text that describes the error, as either UTF-8 or UTF-16 respectively.
4271
+** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
42714272
** ^(Memory to hold the error message string is managed internally.
42724273
** The application does not need to worry about freeing the result.
42734274
** However, the error string might be overwritten or deallocated by
42744275
** subsequent calls to other SQLite interface functions.)^
42754276
**
@@ -6271,11 +6272,11 @@
62716272
** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
62726273
** with the same D and N parameters.
62736274
** <li> The database connection closes. SQLite does not make any guarantees
62746275
** about the order in which destructors are called, only that all
62756276
** destructors will be called exactly once at some point during the
6276
-** database connection closingi process.
6277
+** database connection closing process.
62776278
** </ul>
62786279
**
62796280
** SQLite does not do anything with client data other than invoke
62806281
** destructors on the client data at the appropriate time. The intended
62816282
** use for client data is to provide a mechanism for wrapper libraries
@@ -6935,11 +6936,11 @@
69356936
** a valid schema, then -1 is returned.
69366937
*/
69376938
SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
69386939
69396940
/*
6940
-** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6941
+** CAPI3REF: Allowed return values from sqlite3_txn_state()
69416942
** KEYWORDS: {transaction state}
69426943
**
69436944
** These constants define the current transaction state of a database file.
69446945
** ^The [sqlite3_txn_state(D,S)] interface returns one of these
69456946
** constants in order to describe the transaction state of schema S
@@ -7067,11 +7068,11 @@
70677068
**
70687069
** <p>^There is only one autovacuum pages callback per database connection.
70697070
** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
70707071
** previous invocations for that database connection. ^If the callback
70717072
** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
7072
-** then the autovacuum steps callback is cancelled. The return value
7073
+** then the autovacuum steps callback is canceled. The return value
70737074
** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
70747075
** be some other error code if something goes wrong. The current
70757076
** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
70767077
** return codes might be added in future releases.
70777078
**
@@ -7588,11 +7589,12 @@
75887589
/* The methods above are in versions 1 and 2 of the sqlite_module object.
75897590
** Those below are for version 3 and greater. */
75907591
int (*xShadowName)(const char*);
75917592
/* The methods above are in versions 1 through 3 of the sqlite_module object.
75927593
** Those below are for version 4 and greater. */
7593
- int (*xIntegrity)(sqlite3_vtab *pVTab, char**);
7594
+ int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
7595
+ const char *zTabName, int mFlags, char **pzErr);
75947596
};
75957597
75967598
/*
75977599
** CAPI3REF: Virtual Table Indexing Information
75987600
** KEYWORDS: sqlite3_index_info
@@ -8076,11 +8078,11 @@
80768078
** blob handles or active write statements, the current transaction is
80778079
** committed. ^If an error occurs while committing the transaction, an error
80788080
** code is returned and the transaction rolled back.
80798081
**
80808082
** Calling this function with an argument that is not a NULL pointer or an
8081
-** open blob handle results in undefined behaviour. ^Calling this routine
8083
+** open blob handle results in undefined behavior. ^Calling this routine
80828084
** with a null pointer (such as would be returned by a failed call to
80838085
** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
80848086
** is passed a valid open blob handle, the values returned by the
80858087
** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
80868088
*/
@@ -9618,12 +9620,12 @@
96189620
** ^(There may be at most one unlock-notify callback registered by a
96199621
** blocked connection. If sqlite3_unlock_notify() is called when the
96209622
** blocked connection already has a registered unlock-notify callback,
96219623
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
96229624
** called with a NULL pointer as its second argument, then any existing
9623
-** unlock-notify callback is cancelled. ^The blocked connections
9624
-** unlock-notify callback may also be cancelled by closing the blocked
9625
+** unlock-notify callback is canceled. ^The blocked connections
9626
+** unlock-notify callback may also be canceled by closing the blocked
96259627
** connection using [sqlite3_close()].
96269628
**
96279629
** The unlock-notify callback is not reentrant. If an application invokes
96289630
** any sqlite3_xxx API functions from within an unlock-notify callback, a
96299631
** crash or deadlock may be the result.
@@ -19870,10 +19872,11 @@
1987019872
Trigger retTrig; /* The transient trigger that implements RETURNING */
1987119873
TriggerStep retTStep; /* The trigger step */
1987219874
int iRetCur; /* Transient table holding RETURNING results */
1987319875
int nRetCol; /* Number of in pReturnEL after expansion */
1987419876
int iRetReg; /* Register array for holding a row of RETURNING */
19877
+ char zName[40]; /* Name of trigger: "sqlite_returning_%p" */
1987519878
};
1987619879
1987719880
/*
1987819881
** An objected used to accumulate the text of a string where we
1987919882
** do not necessarily know how big the string will be in the end.
@@ -40939,13 +40942,10 @@
4093940942
int rc = SQLITE_OK;
4094040943
unixFile *pFile = (unixFile*)id;
4094140944
unixInodeInfo *pInode;
4094240945
afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
4094340946
int skipShared = 0;
40944
-#ifdef SQLITE_TEST
40945
- int h = pFile->h;
40946
-#endif
4094740947
4094840948
assert( pFile );
4094940949
OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
4095040950
pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
4095140951
osGetpid(0)));
@@ -40957,13 +40957,10 @@
4095740957
pInode = pFile->pInode;
4095840958
sqlite3_mutex_enter(pInode->pLockMutex);
4095940959
assert( pInode->nShared!=0 );
4096040960
if( pFile->eFileLock>SHARED_LOCK ){
4096140961
assert( pInode->eFileLock==pFile->eFileLock );
40962
- SimulateIOErrorBenign(1);
40963
- SimulateIOError( h=(-1) )
40964
- SimulateIOErrorBenign(0);
4096540962
4096640963
#ifdef SQLITE_DEBUG
4096740964
/* When reducing a lock such that other processes can start
4096840965
** reading the database file again, make sure that the
4096940966
** transaction counter was updated if any part of the database
@@ -41008,13 +41005,10 @@
4100841005
** the lock.
4100941006
*/
4101041007
unsigned long long sharedLockByte = SHARED_FIRST+pInode->sharedByte;
4101141008
pInode->nShared--;
4101241009
if( pInode->nShared==0 ){
41013
- SimulateIOErrorBenign(1);
41014
- SimulateIOError( h=(-1) )
41015
- SimulateIOErrorBenign(0);
4101641010
if( !skipShared ){
4101741011
rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
4101841012
}
4101941013
if( !rc ){
4102041014
pInode->eFileLock = NO_LOCK;
@@ -80220,11 +80214,10 @@
8022080214
**
8022180215
** Also check that the page number is in bounds.
8022280216
*/
8022380217
static int checkRef(IntegrityCk *pCheck, Pgno iPage){
8022480218
if( iPage>pCheck->nCkPage || iPage==0 ){
80225
- if( pCheck->nCkPage==0 ) return 0; /* omit reference counting */
8022680219
checkAppendMsg(pCheck, "invalid page number %u", iPage);
8022780220
return 1;
8022880221
}
8022980222
if( getPageReferenced(pCheck, iPage) ){
8023080223
checkAppendMsg(pCheck, "2nd reference to page %u", iPage);
@@ -80726,19 +80719,14 @@
8072680719
sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
8072780720
if( sCheck.nCkPage==0 ){
8072880721
goto integrity_ck_cleanup;
8072980722
}
8073080723
80731
- if( bPartial ){
80732
- sCheck.nCkPage = 0;
80733
- sCheck.aPgRef = 0;
80734
- }else{
80735
- sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
80736
- if( !sCheck.aPgRef ){
80737
- checkOom(&sCheck);
80738
- goto integrity_ck_cleanup;
80739
- }
80724
+ sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
80725
+ if( !sCheck.aPgRef ){
80726
+ checkOom(&sCheck);
80727
+ goto integrity_ck_cleanup;
8074080728
}
8074180729
sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
8074280730
if( sCheck.heap==0 ){
8074380731
checkOom(&sCheck);
8074480732
goto integrity_ck_cleanup;
@@ -88408,10 +88396,15 @@
8840888396
** Do a comparison between a 64-bit signed integer and a 64-bit floating-point
8840988397
** number. Return negative, zero, or positive if the first (i64) is less than,
8841088398
** equal to, or greater than the second (double).
8841188399
*/
8841288400
SQLITE_PRIVATE int sqlite3IntFloatCompare(i64 i, double r){
88401
+ if( sqlite3IsNaN(r) ){
88402
+ /* SQLite considers NaN to be a NULL. And all integer values are greater
88403
+ ** than NULL */
88404
+ return 1;
88405
+ }
8841388406
if( sqlite3Config.bUseLongDouble ){
8841488407
LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
8841588408
testcase( x<r );
8841688409
testcase( x>r );
8841788410
testcase( x==r );
@@ -99047,25 +99040,33 @@
9904799040
** Disable Auth and Trace callbacks while those statements are running if
9904899041
** P1 is true.
9904999042
*/
9905099043
case OP_SqlExec: {
9905199044
char *zErr;
99045
+#ifndef SQLITE_OMIT_AUTHORIZATION
9905299046
sqlite3_xauth xAuth;
99047
+#endif
9905399048
u8 mTrace;
9905499049
9905599050
sqlite3VdbeIncrWriteCounter(p, 0);
9905699051
db->nSqlExec++;
9905799052
zErr = 0;
99053
+#ifndef SQLITE_OMIT_AUTHORIZATION
9905899054
xAuth = db->xAuth;
99055
+#endif
9905999056
mTrace = db->mTrace;
9906099057
if( pOp->p1 ){
99058
+#ifndef SQLITE_OMIT_AUTHORIZATION
9906199059
db->xAuth = 0;
99060
+#endif
9906299061
db->mTrace = 0;
9906399062
}
9906499063
rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
9906599064
db->nSqlExec--;
99065
+#ifndef SQLITE_OMIT_AUTHORIZATION
9906699066
db->xAuth = xAuth;
99067
+#endif
9906799068
db->mTrace = mTrace;
9906899069
if( zErr || rc ){
9906999070
sqlite3VdbeError(p, "%s", zErr);
9907099071
sqlite3_free(zErr);
9907199072
if( rc==SQLITE_NOMEM ) goto no_mem;
@@ -100290,17 +100291,18 @@
100290100291
break;
100291100292
}
100292100293
#endif /* SQLITE_OMIT_VIRTUALTABLE */
100293100294
100294100295
#ifndef SQLITE_OMIT_VIRTUALTABLE
100295
-/* Opcode: VCheck * P2 * P4 *
100296
+/* Opcode: VCheck P1 P2 P3 P4 *
100296100297
**
100297
-** P4 is a pointer to a Table object that is a virtual table that
100298
-** supports the xIntegrity() method. This opcode runs the xIntegrity()
100299
-** method for that virtual table. If an error is reported back, the error
100300
-** message is stored in register P2. If no errors are seen, register P2
100301
-** is set to NULL.
100298
+** P4 is a pointer to a Table object that is a virtual table in schema P1
100299
+** that supports the xIntegrity() method. This opcode runs the xIntegrity()
100300
+** method for that virtual table, using P3 as the integer argument. If
100301
+** an error is reported back, the table name is prepended to the error
100302
+** message and that message is stored in P2. If no errors are seen,
100303
+** register P2 is set to NULL.
100302100304
*/
100303100305
case OP_VCheck: { /* out2 */
100304100306
Table *pTab;
100305100307
sqlite3_vtab *pVtab;
100306100308
const sqlite3_module *pModule;
@@ -100319,11 +100321,13 @@
100319100321
assert( pModule!=0 );
100320100322
assert( pModule->iVersion>=4 );
100321100323
assert( pModule->xIntegrity!=0 );
100322100324
pTab->nTabRef++;
100323100325
sqlite3VtabLock(pTab->u.vtab.p);
100324
- rc = pModule->xIntegrity(pVtab, &zErr);
100326
+ assert( pOp->p1>=0 && pOp->p1<db->nDb );
100327
+ rc = pModule->xIntegrity(pVtab, db->aDb[pOp->p1].zDbSName, pTab->zName,
100328
+ pOp->p3, &zErr);
100325100329
sqlite3VtabUnlock(pTab->u.vtab.p);
100326100330
sqlite3DeleteTable(db, pTab);
100327100331
if( rc ){
100328100332
sqlite3_free(zErr);
100329100333
goto abort_due_to_error;
@@ -114667,20 +114671,21 @@
114667114671
assert( pExpr->pLeft->op==TK_ORDER );
114668114672
assert( ExprUseXList(pExpr->pLeft) );
114669114673
pItem->iOBTab = pParse->nTab++;
114670114674
pOBList = pExpr->pLeft->x.pList;
114671114675
assert( pOBList->nExpr>0 );
114676
+ assert( pItem->bOBUnique==0 );
114672114677
if( pOBList->nExpr==1
114673114678
&& nArg==1
114674114679
&& sqlite3ExprCompare(0,pOBList->a[0].pExpr,
114675114680
pExpr->x.pList->a[0].pExpr,0)==0
114676114681
){
114677114682
pItem->bOBPayload = 0;
114683
+ pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
114678114684
}else{
114679114685
pItem->bOBPayload = 1;
114680114686
}
114681
- pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
114682114687
}else{
114683114688
pItem->iOBTab = -1;
114684114689
}
114685114690
if( ExprHasProperty(pExpr, EP_Distinct) && !pItem->bOBUnique ){
114686114691
pItem->iDistinct = pParse->nTab++;
@@ -121468,24 +121473,17 @@
121468121473
pTab->tabFlags |= TF_OOOHidden;
121469121474
}
121470121475
}
121471121476
#endif
121472121477
121473
-/*
121474
-** Name of the special TEMP trigger used to implement RETURNING. The
121475
-** name begins with "sqlite_" so that it is guaranteed not to collide
121476
-** with any application-generated triggers.
121477
-*/
121478
-#define RETURNING_TRIGGER_NAME "sqlite_returning"
121479
-
121480121478
/*
121481121479
** Clean up the data structures associated with the RETURNING clause.
121482121480
*/
121483121481
static void sqlite3DeleteReturning(sqlite3 *db, Returning *pRet){
121484121482
Hash *pHash;
121485121483
pHash = &(db->aDb[1].pSchema->trigHash);
121486
- sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, 0);
121484
+ sqlite3HashInsert(pHash, pRet->zName, 0);
121487121485
sqlite3ExprListDelete(db, pRet->pReturnEL);
121488121486
sqlite3DbFree(db, pRet);
121489121487
}
121490121488
121491121489
/*
@@ -121524,11 +121522,13 @@
121524121522
pRet->pReturnEL = pList;
121525121523
sqlite3ParserAddCleanup(pParse,
121526121524
(void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
121527121525
testcase( pParse->earlyCleanup );
121528121526
if( db->mallocFailed ) return;
121529
- pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
121527
+ sqlite3_snprintf(sizeof(pRet->zName), pRet->zName,
121528
+ "sqlite_returning_%p", pParse);
121529
+ pRet->retTrig.zName = pRet->zName;
121530121530
pRet->retTrig.op = TK_RETURNING;
121531121531
pRet->retTrig.tr_tm = TRIGGER_AFTER;
121532121532
pRet->retTrig.bReturning = 1;
121533121533
pRet->retTrig.pSchema = db->aDb[1].pSchema;
121534121534
pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
@@ -121535,13 +121535,13 @@
121535121535
pRet->retTrig.step_list = &pRet->retTStep;
121536121536
pRet->retTStep.op = TK_RETURNING;
121537121537
pRet->retTStep.pTrig = &pRet->retTrig;
121538121538
pRet->retTStep.pExprList = pList;
121539121539
pHash = &(db->aDb[1].pSchema->trigHash);
121540
- assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0
121540
+ assert( sqlite3HashFind(pHash, pRet->zName)==0
121541121541
|| pParse->nErr || pParse->ifNotExists );
121542
- if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
121542
+ if( sqlite3HashInsert(pHash, pRet->zName, &pRet->retTrig)
121543121543
==&pRet->retTrig ){
121544121544
sqlite3OomFault(db);
121545121545
}
121546121546
}
121547121547
@@ -138973,11 +138973,11 @@
138973138973
pVTab = pTab->u.vtab.p->pVtab;
138974138974
if( NEVER(pVTab==0) ) continue;
138975138975
if( NEVER(pVTab->pModule==0) ) continue;
138976138976
if( pVTab->pModule->iVersion<4 ) continue;
138977138977
if( pVTab->pModule->xIntegrity==0 ) continue;
138978
- sqlite3VdbeAddOp2(v, OP_VCheck, 0, 3);
138978
+ sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
138979138979
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
138980138980
a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
138981138981
integrityCheckResultRow(v);
138982138982
sqlite3VdbeJumpHere(v, a1);
138983138983
#endif
@@ -147929,11 +147929,11 @@
147929147929
}else{
147930147930
assert( pF->pFExpr->pLeft!=0 );
147931147931
assert( ExprUseXList(pF->pFExpr->pLeft) );
147932147932
assert( pF->pFExpr->pLeft->x.pList!=0 );
147933147933
nKey = pF->pFExpr->pLeft->x.pList->nExpr;
147934
- if( !pF->bOBUnique ) nKey++;
147934
+ if( ALWAYS(!pF->bOBUnique) ) nKey++;
147935147935
}
147936147936
iTop = sqlite3VdbeAddOp1(v, OP_Rewind, pF->iOBTab); VdbeCoverage(v);
147937147937
for(j=nArg-1; j>=0; j--){
147938147938
sqlite3VdbeAddOp3(v, OP_Column, pF->iOBTab, nKey+j, regAgg+j);
147939147939
}
@@ -147985,10 +147985,11 @@
147985147985
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
147986147986
int nArg;
147987147987
int addrNext = 0;
147988147988
int regAgg;
147989147989
int regAggSz = 0;
147990
+ int regDistinct = 0;
147990147991
ExprList *pList;
147991147992
assert( ExprUseXList(pF->pFExpr) );
147992147993
assert( !IsWindowFunc(pF->pFExpr) );
147993147994
pList = pF->pFExpr->x.pList;
147994147995
if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
@@ -148034,22 +148035,25 @@
148034148035
if( pF->bOBPayload ){
148035148036
regAggSz += nArg;
148036148037
}
148037148038
regAggSz++; /* One extra register to hold result of MakeRecord */
148038148039
regAgg = sqlite3GetTempRange(pParse, regAggSz);
148040
+ regDistinct = regAgg;
148039148041
sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
148040148042
jj = pOBList->nExpr;
148041148043
if( !pF->bOBUnique ){
148042148044
sqlite3VdbeAddOp2(v, OP_Sequence, pF->iOBTab, regAgg+jj);
148043148045
jj++;
148044148046
}
148045148047
if( pF->bOBPayload ){
148046
- sqlite3ExprCodeExprList(pParse, pList, regAgg+jj, 0, SQLITE_ECEL_DUP);
148048
+ regDistinct = regAgg+jj;
148049
+ sqlite3ExprCodeExprList(pParse, pList, regDistinct, 0, SQLITE_ECEL_DUP);
148047148050
}
148048148051
}else if( pList ){
148049148052
nArg = pList->nExpr;
148050148053
regAgg = sqlite3GetTempRange(pParse, nArg);
148054
+ regDistinct = regAgg;
148051148055
sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
148052148056
}else{
148053148057
nArg = 0;
148054148058
regAgg = 0;
148055148059
}
@@ -148056,11 +148060,11 @@
148056148060
if( pF->iDistinct>=0 && pList ){
148057148061
if( addrNext==0 ){
148058148062
addrNext = sqlite3VdbeMakeLabel(pParse);
148059148063
}
148060148064
pF->iDistinct = codeDistinct(pParse, eDistinctType,
148061
- pF->iDistinct, addrNext, pList, regAgg);
148065
+ pF->iDistinct, addrNext, pList, regDistinct);
148062148066
}
148063148067
if( pF->iOBTab>=0 ){
148064148068
/* Insert a new record into the ORDER BY table */
148065148069
sqlite3VdbeAddOp3(v, OP_MakeRecord, regAgg, regAggSz-1,
148066148070
regAgg+regAggSz-1);
@@ -150934,14 +150938,21 @@
150934150938
Returning *pReturning;
150935150939
Select sSelect;
150936150940
SrcList sFrom;
150937150941
150938150942
assert( v!=0 );
150939
- assert( pParse->bReturning );
150943
+ if( !pParse->bReturning ){
150944
+ /* This RETURNING trigger must be for a different statement as
150945
+ ** this statement lacks a RETURNING clause. */
150946
+ return;
150947
+ }
150940150948
assert( db->pParse==pParse );
150941150949
pReturning = pParse->u1.pReturning;
150942
- assert( pTrigger == &(pReturning->retTrig) );
150950
+ if( pTrigger != &(pReturning->retTrig) ){
150951
+ /* This RETURNING trigger is for a different statement */
150952
+ return;
150953
+ }
150943150954
memset(&sSelect, 0, sizeof(sSelect));
150944150955
memset(&sFrom, 0, sizeof(sFrom));
150945150956
sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
150946150957
sSelect.pSrc = &sFrom;
150947150958
sFrom.nSrc = 1;
@@ -177852,11 +177863,13 @@
177852177863
}
177853177864
#endif
177854177865
177855177866
/* Experimentally determine if high-precision floating point is
177856177867
** available. */
177868
+#ifndef SQLITE_OMIT_WSD
177857177869
sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc);
177870
+#endif
177858177871
177859177872
return rc;
177860177873
}
177861177874
177862177875
/*
@@ -187833,31 +187846,40 @@
187833187846
187834187847
/*
187835187848
** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
187836187849
** table.
187837187850
*/
187838
-static int fts3Integrity(sqlite3_vtab *pVtab, char **pzErr){
187851
+static int fts3Integrity(
187852
+ sqlite3_vtab *pVtab, /* The virtual table to be checked */
187853
+ const char *zSchema, /* Name of schema in which pVtab lives */
187854
+ const char *zTabname, /* Name of the pVTab table */
187855
+ int isQuick, /* True if this is a quick_check */
187856
+ char **pzErr /* Write error message here */
187857
+){
187839187858
Fts3Table *p = (Fts3Table*)pVtab;
187840187859
char *zSql;
187841187860
int rc;
187842187861
char *zErr = 0;
187843187862
187863
+ assert( pzErr!=0 );
187864
+ assert( *pzErr==0 );
187865
+ UNUSED_PARAMETER(isQuick);
187844187866
zSql = sqlite3_mprintf(
187845187867
"INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
187846
- p->zDb, p->zName, p->zName);
187868
+ zSchema, zTabname, zTabname);
187847187869
if( zSql==0 ){
187848187870
return SQLITE_NOMEM;
187849187871
}
187850187872
rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr);
187851187873
sqlite3_free(zSql);
187852187874
if( (rc&0xff)==SQLITE_CORRUPT ){
187853187875
*pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
187854
- p->bFts4 ? 4 : 3, p->zDb, p->zName);
187876
+ p->bFts4 ? 4 : 3, zSchema, zTabname);
187855187877
}else if( rc!=SQLITE_OK ){
187856187878
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
187857187879
" FTS%d table %s.%s: %s",
187858
- p->bFts4 ? 4 : 3, p->zDb, p->zName, zErr);
187880
+ p->bFts4 ? 4 : 3, zSchema, zTabname, zErr);
187859187881
}
187860187882
sqlite3_free(zErr);
187861187883
return SQLITE_OK;
187862187884
}
187863187885
@@ -209716,11 +209738,11 @@
209716209738
}
209717209739
return 0;
209718209740
}
209719209741
209720209742
/* Forward declaration */
209721
-static int rtreeIntegrity(sqlite3_vtab*, char**);
209743
+static int rtreeIntegrity(sqlite3_vtab*, const char*, const char*, int, char**);
209722209744
209723209745
static sqlite3_module rtreeModule = {
209724209746
4, /* iVersion */
209725209747
rtreeCreate, /* xCreate - create a table */
209726209748
rtreeConnect, /* xConnect - connect to an existing table */
@@ -210571,13 +210593,23 @@
210571210593
}
210572210594
210573210595
/*
210574210596
** Implementation of the xIntegrity method for Rtree.
210575210597
*/
210576
-static int rtreeIntegrity(sqlite3_vtab *pVtab, char **pzErr){
210598
+static int rtreeIntegrity(
210599
+ sqlite3_vtab *pVtab, /* The virtual table to check */
210600
+ const char *zSchema, /* Schema in which the virtual table lives */
210601
+ const char *zName, /* Name of the virtual table */
210602
+ int isQuick, /* True for a quick_check */
210603
+ char **pzErr /* Write results here */
210604
+){
210577210605
Rtree *pRtree = (Rtree*)pVtab;
210578210606
int rc;
210607
+ assert( pzErr!=0 && *pzErr==0 );
210608
+ UNUSED_PARAMETER(zSchema);
210609
+ UNUSED_PARAMETER(zName);
210610
+ UNUSED_PARAMETER(isQuick);
210579210611
rc = rtreeCheckTable(pRtree->db, pRtree->zDb, pRtree->zName, pzErr);
210580210612
if( rc==SQLITE_OK && *pzErr ){
210581210613
*pzErr = sqlite3_mprintf("In RTree %s.%s:\n%z",
210582210614
pRtree->zDb, pRtree->zName, *pzErr);
210583210615
}
@@ -222168,11 +222200,11 @@
222168222200
pSession->nMaxChangesetSize -= sessionVarintLen(nOldCol);
222169222201
}
222170222202
}
222171222203
}
222172222204
222173
- sqlite3_free(azCol);
222205
+ sqlite3_free((char*)azCol);
222174222206
return pSession->rc;
222175222207
}
222176222208
222177222209
/*
222178222210
** Session-change object (*pp) contains an old.* record with fewer than
@@ -230436,19 +230468,23 @@
230436230468
/*************************************************************************
230437230469
** Start of highlight() implementation.
230438230470
*/
230439230471
typedef struct HighlightContext HighlightContext;
230440230472
struct HighlightContext {
230441
- CInstIter iter; /* Coalesced Instance Iterator */
230442
- int iPos; /* Current token offset in zIn[] */
230473
+ /* Constant parameters to fts5HighlightCb() */
230443230474
int iRangeStart; /* First token to include */
230444230475
int iRangeEnd; /* If non-zero, last token to include */
230445230476
const char *zOpen; /* Opening highlight */
230446230477
const char *zClose; /* Closing highlight */
230447230478
const char *zIn; /* Input text */
230448230479
int nIn; /* Size of input text in bytes */
230449
- int iOff; /* Current offset within zIn[] */
230480
+
230481
+ /* Variables modified by fts5HighlightCb() */
230482
+ CInstIter iter; /* Coalesced Instance Iterator */
230483
+ int iPos; /* Current token offset in zIn[] */
230484
+ int iOff; /* Have copied up to this offset in zIn[] */
230485
+ int bOpen; /* True if highlight is open */
230450230486
char *zOut; /* Output value */
230451230487
};
230452230488
230453230489
/*
230454230490
** Append text to the HighlightContext output string - p->zOut. Argument
@@ -230477,12 +230513,12 @@
230477230513
static int fts5HighlightCb(
230478230514
void *pContext, /* Pointer to HighlightContext object */
230479230515
int tflags, /* Mask of FTS5_TOKEN_* flags */
230480230516
const char *pToken, /* Buffer containing token */
230481230517
int nToken, /* Size of token in bytes */
230482
- int iStartOff, /* Start offset of token */
230483
- int iEndOff /* End offset of token */
230518
+ int iStartOff, /* Start byte offset of token */
230519
+ int iEndOff /* End byte offset of token */
230484230520
){
230485230521
HighlightContext *p = (HighlightContext*)pContext;
230486230522
int rc = SQLITE_OK;
230487230523
int iPos;
230488230524
@@ -230494,34 +230530,51 @@
230494230530
if( p->iRangeEnd>=0 ){
230495230531
if( iPos<p->iRangeStart || iPos>p->iRangeEnd ) return SQLITE_OK;
230496230532
if( p->iRangeStart && iPos==p->iRangeStart ) p->iOff = iStartOff;
230497230533
}
230498230534
230499
- if( iPos==p->iter.iStart ){
230535
+ /* If the parenthesis is open, and this token is not part of the current
230536
+ ** phrase, and the starting byte offset of this token is past the point
230537
+ ** that has currently been copied into the output buffer, close the
230538
+ ** parenthesis. */
230539
+ if( p->bOpen
230540
+ && (iPos<=p->iter.iStart || p->iter.iStart<0)
230541
+ && iStartOff>p->iOff
230542
+ ){
230543
+ fts5HighlightAppend(&rc, p, p->zClose, -1);
230544
+ p->bOpen = 0;
230545
+ }
230546
+
230547
+ /* If this is the start of a new phrase, and the highlight is not open:
230548
+ **
230549
+ ** * copy text from the input up to the start of the phrase, and
230550
+ ** * open the highlight.
230551
+ */
230552
+ if( iPos==p->iter.iStart && p->bOpen==0 ){
230500230553
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iStartOff - p->iOff);
230501230554
fts5HighlightAppend(&rc, p, p->zOpen, -1);
230502230555
p->iOff = iStartOff;
230556
+ p->bOpen = 1;
230503230557
}
230504230558
230505230559
if( iPos==p->iter.iEnd ){
230506
- if( p->iRangeEnd>=0 && p->iter.iStart<p->iRangeStart ){
230560
+ if( p->bOpen==0 ){
230561
+ assert( p->iRangeEnd>=0 );
230507230562
fts5HighlightAppend(&rc, p, p->zOpen, -1);
230563
+ p->bOpen = 1;
230508230564
}
230509230565
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
230510
- fts5HighlightAppend(&rc, p, p->zClose, -1);
230511230566
p->iOff = iEndOff;
230567
+
230512230568
if( rc==SQLITE_OK ){
230513230569
rc = fts5CInstIterNext(&p->iter);
230514230570
}
230515230571
}
230516230572
230517
- if( p->iRangeEnd>=0 && iPos==p->iRangeEnd ){
230573
+ if( iPos==p->iRangeEnd ){
230518230574
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
230519230575
p->iOff = iEndOff;
230520
- if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
230521
- fts5HighlightAppend(&rc, p, p->zClose, -1);
230522
- }
230523230576
}
230524230577
230525230578
return rc;
230526230579
}
230527230580
@@ -230558,10 +230611,13 @@
230558230611
}
230559230612
230560230613
if( rc==SQLITE_OK ){
230561230614
rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230562230615
}
230616
+ if( ctx.bOpen ){
230617
+ fts5HighlightAppend(&rc, &ctx, ctx.zClose, -1);
230618
+ }
230563230619
fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230564230620
230565230621
if( rc==SQLITE_OK ){
230566230622
sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
230567230623
}
@@ -230836,10 +230892,13 @@
230836230892
}
230837230893
230838230894
if( rc==SQLITE_OK ){
230839230895
rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230840230896
}
230897
+ if( ctx.bOpen ){
230898
+ fts5HighlightAppend(&rc, &ctx, ctx.zClose, -1);
230899
+ }
230841230900
if( ctx.iRangeEnd>=(nColSize-1) ){
230842230901
fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230843230902
}else{
230844230903
fts5HighlightAppend(&rc, &ctx, zEllips, -1);
230845230904
}
@@ -247437,11 +247496,11 @@
247437247496
int nArg, /* Number of args */
247438247497
sqlite3_value **apUnused /* Function arguments */
247439247498
){
247440247499
assert( nArg==0 );
247441247500
UNUSED_PARAM2(nArg, apUnused);
247442
- sqlite3_result_text(pCtx, "fts5: 2023-10-23 23:34:53 9d388267e4e6724e2df333fe09d509e87defcfe984c5c2ebe031152d320812d0", -1, SQLITE_TRANSIENT);
247501
+ sqlite3_result_text(pCtx, "fts5: 2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1", -1, SQLITE_TRANSIENT);
247443247502
}
247444247503
247445247504
/*
247446247505
** Return true if zName is the extension on one of the shadow tables used
247447247506
** by this module.
@@ -247460,29 +247519,37 @@
247460247519
/*
247461247520
** Run an integrity check on the FTS5 data structures. Return a string
247462247521
** if anything is found amiss. Return a NULL pointer if everything is
247463247522
** OK.
247464247523
*/
247465
-static int fts5Integrity(sqlite3_vtab *pVtab, char **pzErr){
247524
+static int fts5Integrity(
247525
+ sqlite3_vtab *pVtab, /* the FTS5 virtual table to check */
247526
+ const char *zSchema, /* Name of schema in which this table lives */
247527
+ const char *zTabname, /* Name of the table itself */
247528
+ int isQuick, /* True if this is a quick-check */
247529
+ char **pzErr /* Write error message here */
247530
+){
247466247531
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
247467247532
Fts5Config *pConfig = pTab->p.pConfig;
247468247533
char *zSql;
247469247534
char *zErr = 0;
247470247535
int rc;
247536
+ assert( pzErr!=0 && *pzErr==0 );
247537
+ UNUSED_PARAM(isQuick);
247471247538
zSql = sqlite3_mprintf(
247472247539
"INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
247473
- pConfig->zDb, pConfig->zName, pConfig->zName);
247540
+ zSchema, zTabname, pConfig->zName);
247474247541
if( zSql==0 ) return SQLITE_NOMEM;
247475247542
rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr);
247476247543
sqlite3_free(zSql);
247477247544
if( (rc&0xff)==SQLITE_CORRUPT ){
247478247545
*pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
247479
- pConfig->zDb, pConfig->zName);
247546
+ zSchema, zTabname);
247480247547
}else if( rc!=SQLITE_OK ){
247481247548
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
247482247549
" FTS5 table %s.%s: %s",
247483
- pConfig->zDb, pConfig->zName, zErr);
247550
+ zSchema, zTabname, zErr);
247484247551
}
247485247552
sqlite3_free(zErr);
247486247553
return SQLITE_OK;
247487247554
}
247488247555
247489247556
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 4be9af4469d7e31ee852f67e5aa32996557.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.44.0"
463 #define SQLITE_VERSION_NUMBER 3044000
464 #define SQLITE_SOURCE_ID "2023-10-24 11:06:44 54be9af4469d7e31ee852f67e5aa32996557c10de654a60103fd165d2fedf311"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -2438,11 +2438,11 @@
2438 ** of a table column that its values are likely to be very large - larger
2439 ** than the configured sorter-reference size threshold - then a reference
2440 ** is stored in each sorted record and the required column values loaded
2441 ** from the database as records are returned in sorted order. The default
2442 ** value for this option is to never use this optimization. Specifying a
2443 ** negative value for this option restores the default behaviour.
2444 ** This option is only available if SQLite is compiled with the
2445 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2446 **
2447 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2448 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2613,11 +2613,11 @@
2613 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2614 ** <dd> Usually, when a database in wal mode is closed or detached from a
2615 ** database handle, SQLite checks if this will mean that there are now no
2616 ** connections at all to the database. If so, it performs a checkpoint
2617 ** operation before closing the connection. This option may be used to
2618 ** override this behaviour. The first parameter passed to this operation
2619 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2620 ** default) to enable them, and negative to leave the setting unchanged.
2621 ** The second parameter is a pointer to an integer
2622 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2623 ** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -4266,10 +4266,11 @@
4266 ** <li> sqlite3_error_offset()
4267 ** </ul>
4268 **
4269 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4270 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
 
4271 ** ^(Memory to hold the error message string is managed internally.
4272 ** The application does not need to worry about freeing the result.
4273 ** However, the error string might be overwritten or deallocated by
4274 ** subsequent calls to other SQLite interface functions.)^
4275 **
@@ -6271,11 +6272,11 @@
6271 ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
6272 ** with the same D and N parameters.
6273 ** <li> The database connection closes. SQLite does not make any guarantees
6274 ** about the order in which destructors are called, only that all
6275 ** destructors will be called exactly once at some point during the
6276 ** database connection closingi process.
6277 ** </ul>
6278 **
6279 ** SQLite does not do anything with client data other than invoke
6280 ** destructors on the client data at the appropriate time. The intended
6281 ** use for client data is to provide a mechanism for wrapper libraries
@@ -6935,11 +6936,11 @@
6935 ** a valid schema, then -1 is returned.
6936 */
6937 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6938
6939 /*
6940 ** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6941 ** KEYWORDS: {transaction state}
6942 **
6943 ** These constants define the current transaction state of a database file.
6944 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6945 ** constants in order to describe the transaction state of schema S
@@ -7067,11 +7068,11 @@
7067 **
7068 ** <p>^There is only one autovacuum pages callback per database connection.
7069 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
7070 ** previous invocations for that database connection. ^If the callback
7071 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
7072 ** then the autovacuum steps callback is cancelled. The return value
7073 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
7074 ** be some other error code if something goes wrong. The current
7075 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
7076 ** return codes might be added in future releases.
7077 **
@@ -7588,11 +7589,12 @@
7588 /* The methods above are in versions 1 and 2 of the sqlite_module object.
7589 ** Those below are for version 3 and greater. */
7590 int (*xShadowName)(const char*);
7591 /* The methods above are in versions 1 through 3 of the sqlite_module object.
7592 ** Those below are for version 4 and greater. */
7593 int (*xIntegrity)(sqlite3_vtab *pVTab, char**);
 
7594 };
7595
7596 /*
7597 ** CAPI3REF: Virtual Table Indexing Information
7598 ** KEYWORDS: sqlite3_index_info
@@ -8076,11 +8078,11 @@
8076 ** blob handles or active write statements, the current transaction is
8077 ** committed. ^If an error occurs while committing the transaction, an error
8078 ** code is returned and the transaction rolled back.
8079 **
8080 ** Calling this function with an argument that is not a NULL pointer or an
8081 ** open blob handle results in undefined behaviour. ^Calling this routine
8082 ** with a null pointer (such as would be returned by a failed call to
8083 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
8084 ** is passed a valid open blob handle, the values returned by the
8085 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
8086 */
@@ -9618,12 +9620,12 @@
9618 ** ^(There may be at most one unlock-notify callback registered by a
9619 ** blocked connection. If sqlite3_unlock_notify() is called when the
9620 ** blocked connection already has a registered unlock-notify callback,
9621 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9622 ** called with a NULL pointer as its second argument, then any existing
9623 ** unlock-notify callback is cancelled. ^The blocked connections
9624 ** unlock-notify callback may also be cancelled by closing the blocked
9625 ** connection using [sqlite3_close()].
9626 **
9627 ** The unlock-notify callback is not reentrant. If an application invokes
9628 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9629 ** crash or deadlock may be the result.
@@ -19870,10 +19872,11 @@
19870 Trigger retTrig; /* The transient trigger that implements RETURNING */
19871 TriggerStep retTStep; /* The trigger step */
19872 int iRetCur; /* Transient table holding RETURNING results */
19873 int nRetCol; /* Number of in pReturnEL after expansion */
19874 int iRetReg; /* Register array for holding a row of RETURNING */
 
19875 };
19876
19877 /*
19878 ** An objected used to accumulate the text of a string where we
19879 ** do not necessarily know how big the string will be in the end.
@@ -40939,13 +40942,10 @@
40939 int rc = SQLITE_OK;
40940 unixFile *pFile = (unixFile*)id;
40941 unixInodeInfo *pInode;
40942 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
40943 int skipShared = 0;
40944 #ifdef SQLITE_TEST
40945 int h = pFile->h;
40946 #endif
40947
40948 assert( pFile );
40949 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
40950 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
40951 osGetpid(0)));
@@ -40957,13 +40957,10 @@
40957 pInode = pFile->pInode;
40958 sqlite3_mutex_enter(pInode->pLockMutex);
40959 assert( pInode->nShared!=0 );
40960 if( pFile->eFileLock>SHARED_LOCK ){
40961 assert( pInode->eFileLock==pFile->eFileLock );
40962 SimulateIOErrorBenign(1);
40963 SimulateIOError( h=(-1) )
40964 SimulateIOErrorBenign(0);
40965
40966 #ifdef SQLITE_DEBUG
40967 /* When reducing a lock such that other processes can start
40968 ** reading the database file again, make sure that the
40969 ** transaction counter was updated if any part of the database
@@ -41008,13 +41005,10 @@
41008 ** the lock.
41009 */
41010 unsigned long long sharedLockByte = SHARED_FIRST+pInode->sharedByte;
41011 pInode->nShared--;
41012 if( pInode->nShared==0 ){
41013 SimulateIOErrorBenign(1);
41014 SimulateIOError( h=(-1) )
41015 SimulateIOErrorBenign(0);
41016 if( !skipShared ){
41017 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
41018 }
41019 if( !rc ){
41020 pInode->eFileLock = NO_LOCK;
@@ -80220,11 +80214,10 @@
80220 **
80221 ** Also check that the page number is in bounds.
80222 */
80223 static int checkRef(IntegrityCk *pCheck, Pgno iPage){
80224 if( iPage>pCheck->nCkPage || iPage==0 ){
80225 if( pCheck->nCkPage==0 ) return 0; /* omit reference counting */
80226 checkAppendMsg(pCheck, "invalid page number %u", iPage);
80227 return 1;
80228 }
80229 if( getPageReferenced(pCheck, iPage) ){
80230 checkAppendMsg(pCheck, "2nd reference to page %u", iPage);
@@ -80726,19 +80719,14 @@
80726 sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
80727 if( sCheck.nCkPage==0 ){
80728 goto integrity_ck_cleanup;
80729 }
80730
80731 if( bPartial ){
80732 sCheck.nCkPage = 0;
80733 sCheck.aPgRef = 0;
80734 }else{
80735 sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
80736 if( !sCheck.aPgRef ){
80737 checkOom(&sCheck);
80738 goto integrity_ck_cleanup;
80739 }
80740 }
80741 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
80742 if( sCheck.heap==0 ){
80743 checkOom(&sCheck);
80744 goto integrity_ck_cleanup;
@@ -88408,10 +88396,15 @@
88408 ** Do a comparison between a 64-bit signed integer and a 64-bit floating-point
88409 ** number. Return negative, zero, or positive if the first (i64) is less than,
88410 ** equal to, or greater than the second (double).
88411 */
88412 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64 i, double r){
 
 
 
 
 
88413 if( sqlite3Config.bUseLongDouble ){
88414 LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
88415 testcase( x<r );
88416 testcase( x>r );
88417 testcase( x==r );
@@ -99047,25 +99040,33 @@
99047 ** Disable Auth and Trace callbacks while those statements are running if
99048 ** P1 is true.
99049 */
99050 case OP_SqlExec: {
99051 char *zErr;
 
99052 sqlite3_xauth xAuth;
 
99053 u8 mTrace;
99054
99055 sqlite3VdbeIncrWriteCounter(p, 0);
99056 db->nSqlExec++;
99057 zErr = 0;
 
99058 xAuth = db->xAuth;
 
99059 mTrace = db->mTrace;
99060 if( pOp->p1 ){
 
99061 db->xAuth = 0;
 
99062 db->mTrace = 0;
99063 }
99064 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
99065 db->nSqlExec--;
 
99066 db->xAuth = xAuth;
 
99067 db->mTrace = mTrace;
99068 if( zErr || rc ){
99069 sqlite3VdbeError(p, "%s", zErr);
99070 sqlite3_free(zErr);
99071 if( rc==SQLITE_NOMEM ) goto no_mem;
@@ -100290,17 +100291,18 @@
100290 break;
100291 }
100292 #endif /* SQLITE_OMIT_VIRTUALTABLE */
100293
100294 #ifndef SQLITE_OMIT_VIRTUALTABLE
100295 /* Opcode: VCheck * P2 * P4 *
100296 **
100297 ** P4 is a pointer to a Table object that is a virtual table that
100298 ** supports the xIntegrity() method. This opcode runs the xIntegrity()
100299 ** method for that virtual table. If an error is reported back, the error
100300 ** message is stored in register P2. If no errors are seen, register P2
100301 ** is set to NULL.
 
100302 */
100303 case OP_VCheck: { /* out2 */
100304 Table *pTab;
100305 sqlite3_vtab *pVtab;
100306 const sqlite3_module *pModule;
@@ -100319,11 +100321,13 @@
100319 assert( pModule!=0 );
100320 assert( pModule->iVersion>=4 );
100321 assert( pModule->xIntegrity!=0 );
100322 pTab->nTabRef++;
100323 sqlite3VtabLock(pTab->u.vtab.p);
100324 rc = pModule->xIntegrity(pVtab, &zErr);
 
 
100325 sqlite3VtabUnlock(pTab->u.vtab.p);
100326 sqlite3DeleteTable(db, pTab);
100327 if( rc ){
100328 sqlite3_free(zErr);
100329 goto abort_due_to_error;
@@ -114667,20 +114671,21 @@
114667 assert( pExpr->pLeft->op==TK_ORDER );
114668 assert( ExprUseXList(pExpr->pLeft) );
114669 pItem->iOBTab = pParse->nTab++;
114670 pOBList = pExpr->pLeft->x.pList;
114671 assert( pOBList->nExpr>0 );
 
114672 if( pOBList->nExpr==1
114673 && nArg==1
114674 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
114675 pExpr->x.pList->a[0].pExpr,0)==0
114676 ){
114677 pItem->bOBPayload = 0;
 
114678 }else{
114679 pItem->bOBPayload = 1;
114680 }
114681 pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
114682 }else{
114683 pItem->iOBTab = -1;
114684 }
114685 if( ExprHasProperty(pExpr, EP_Distinct) && !pItem->bOBUnique ){
114686 pItem->iDistinct = pParse->nTab++;
@@ -121468,24 +121473,17 @@
121468 pTab->tabFlags |= TF_OOOHidden;
121469 }
121470 }
121471 #endif
121472
121473 /*
121474 ** Name of the special TEMP trigger used to implement RETURNING. The
121475 ** name begins with "sqlite_" so that it is guaranteed not to collide
121476 ** with any application-generated triggers.
121477 */
121478 #define RETURNING_TRIGGER_NAME "sqlite_returning"
121479
121480 /*
121481 ** Clean up the data structures associated with the RETURNING clause.
121482 */
121483 static void sqlite3DeleteReturning(sqlite3 *db, Returning *pRet){
121484 Hash *pHash;
121485 pHash = &(db->aDb[1].pSchema->trigHash);
121486 sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, 0);
121487 sqlite3ExprListDelete(db, pRet->pReturnEL);
121488 sqlite3DbFree(db, pRet);
121489 }
121490
121491 /*
@@ -121524,11 +121522,13 @@
121524 pRet->pReturnEL = pList;
121525 sqlite3ParserAddCleanup(pParse,
121526 (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
121527 testcase( pParse->earlyCleanup );
121528 if( db->mallocFailed ) return;
121529 pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
 
 
121530 pRet->retTrig.op = TK_RETURNING;
121531 pRet->retTrig.tr_tm = TRIGGER_AFTER;
121532 pRet->retTrig.bReturning = 1;
121533 pRet->retTrig.pSchema = db->aDb[1].pSchema;
121534 pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
@@ -121535,13 +121535,13 @@
121535 pRet->retTrig.step_list = &pRet->retTStep;
121536 pRet->retTStep.op = TK_RETURNING;
121537 pRet->retTStep.pTrig = &pRet->retTrig;
121538 pRet->retTStep.pExprList = pList;
121539 pHash = &(db->aDb[1].pSchema->trigHash);
121540 assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0
121541 || pParse->nErr || pParse->ifNotExists );
121542 if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
121543 ==&pRet->retTrig ){
121544 sqlite3OomFault(db);
121545 }
121546 }
121547
@@ -138973,11 +138973,11 @@
138973 pVTab = pTab->u.vtab.p->pVtab;
138974 if( NEVER(pVTab==0) ) continue;
138975 if( NEVER(pVTab->pModule==0) ) continue;
138976 if( pVTab->pModule->iVersion<4 ) continue;
138977 if( pVTab->pModule->xIntegrity==0 ) continue;
138978 sqlite3VdbeAddOp2(v, OP_VCheck, 0, 3);
138979 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
138980 a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
138981 integrityCheckResultRow(v);
138982 sqlite3VdbeJumpHere(v, a1);
138983 #endif
@@ -147929,11 +147929,11 @@
147929 }else{
147930 assert( pF->pFExpr->pLeft!=0 );
147931 assert( ExprUseXList(pF->pFExpr->pLeft) );
147932 assert( pF->pFExpr->pLeft->x.pList!=0 );
147933 nKey = pF->pFExpr->pLeft->x.pList->nExpr;
147934 if( !pF->bOBUnique ) nKey++;
147935 }
147936 iTop = sqlite3VdbeAddOp1(v, OP_Rewind, pF->iOBTab); VdbeCoverage(v);
147937 for(j=nArg-1; j>=0; j--){
147938 sqlite3VdbeAddOp3(v, OP_Column, pF->iOBTab, nKey+j, regAgg+j);
147939 }
@@ -147985,10 +147985,11 @@
147985 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
147986 int nArg;
147987 int addrNext = 0;
147988 int regAgg;
147989 int regAggSz = 0;
 
147990 ExprList *pList;
147991 assert( ExprUseXList(pF->pFExpr) );
147992 assert( !IsWindowFunc(pF->pFExpr) );
147993 pList = pF->pFExpr->x.pList;
147994 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
@@ -148034,22 +148035,25 @@
148034 if( pF->bOBPayload ){
148035 regAggSz += nArg;
148036 }
148037 regAggSz++; /* One extra register to hold result of MakeRecord */
148038 regAgg = sqlite3GetTempRange(pParse, regAggSz);
 
148039 sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
148040 jj = pOBList->nExpr;
148041 if( !pF->bOBUnique ){
148042 sqlite3VdbeAddOp2(v, OP_Sequence, pF->iOBTab, regAgg+jj);
148043 jj++;
148044 }
148045 if( pF->bOBPayload ){
148046 sqlite3ExprCodeExprList(pParse, pList, regAgg+jj, 0, SQLITE_ECEL_DUP);
 
148047 }
148048 }else if( pList ){
148049 nArg = pList->nExpr;
148050 regAgg = sqlite3GetTempRange(pParse, nArg);
 
148051 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
148052 }else{
148053 nArg = 0;
148054 regAgg = 0;
148055 }
@@ -148056,11 +148060,11 @@
148056 if( pF->iDistinct>=0 && pList ){
148057 if( addrNext==0 ){
148058 addrNext = sqlite3VdbeMakeLabel(pParse);
148059 }
148060 pF->iDistinct = codeDistinct(pParse, eDistinctType,
148061 pF->iDistinct, addrNext, pList, regAgg);
148062 }
148063 if( pF->iOBTab>=0 ){
148064 /* Insert a new record into the ORDER BY table */
148065 sqlite3VdbeAddOp3(v, OP_MakeRecord, regAgg, regAggSz-1,
148066 regAgg+regAggSz-1);
@@ -150934,14 +150938,21 @@
150934 Returning *pReturning;
150935 Select sSelect;
150936 SrcList sFrom;
150937
150938 assert( v!=0 );
150939 assert( pParse->bReturning );
 
 
 
 
150940 assert( db->pParse==pParse );
150941 pReturning = pParse->u1.pReturning;
150942 assert( pTrigger == &(pReturning->retTrig) );
 
 
 
150943 memset(&sSelect, 0, sizeof(sSelect));
150944 memset(&sFrom, 0, sizeof(sFrom));
150945 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
150946 sSelect.pSrc = &sFrom;
150947 sFrom.nSrc = 1;
@@ -177852,11 +177863,13 @@
177852 }
177853 #endif
177854
177855 /* Experimentally determine if high-precision floating point is
177856 ** available. */
 
177857 sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc);
 
177858
177859 return rc;
177860 }
177861
177862 /*
@@ -187833,31 +187846,40 @@
187833
187834 /*
187835 ** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
187836 ** table.
187837 */
187838 static int fts3Integrity(sqlite3_vtab *pVtab, char **pzErr){
 
 
 
 
 
 
187839 Fts3Table *p = (Fts3Table*)pVtab;
187840 char *zSql;
187841 int rc;
187842 char *zErr = 0;
187843
 
 
 
187844 zSql = sqlite3_mprintf(
187845 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
187846 p->zDb, p->zName, p->zName);
187847 if( zSql==0 ){
187848 return SQLITE_NOMEM;
187849 }
187850 rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr);
187851 sqlite3_free(zSql);
187852 if( (rc&0xff)==SQLITE_CORRUPT ){
187853 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
187854 p->bFts4 ? 4 : 3, p->zDb, p->zName);
187855 }else if( rc!=SQLITE_OK ){
187856 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
187857 " FTS%d table %s.%s: %s",
187858 p->bFts4 ? 4 : 3, p->zDb, p->zName, zErr);
187859 }
187860 sqlite3_free(zErr);
187861 return SQLITE_OK;
187862 }
187863
@@ -209716,11 +209738,11 @@
209716 }
209717 return 0;
209718 }
209719
209720 /* Forward declaration */
209721 static int rtreeIntegrity(sqlite3_vtab*, char**);
209722
209723 static sqlite3_module rtreeModule = {
209724 4, /* iVersion */
209725 rtreeCreate, /* xCreate - create a table */
209726 rtreeConnect, /* xConnect - connect to an existing table */
@@ -210571,13 +210593,23 @@
210571 }
210572
210573 /*
210574 ** Implementation of the xIntegrity method for Rtree.
210575 */
210576 static int rtreeIntegrity(sqlite3_vtab *pVtab, char **pzErr){
 
 
 
 
 
 
210577 Rtree *pRtree = (Rtree*)pVtab;
210578 int rc;
 
 
 
 
210579 rc = rtreeCheckTable(pRtree->db, pRtree->zDb, pRtree->zName, pzErr);
210580 if( rc==SQLITE_OK && *pzErr ){
210581 *pzErr = sqlite3_mprintf("In RTree %s.%s:\n%z",
210582 pRtree->zDb, pRtree->zName, *pzErr);
210583 }
@@ -222168,11 +222200,11 @@
222168 pSession->nMaxChangesetSize -= sessionVarintLen(nOldCol);
222169 }
222170 }
222171 }
222172
222173 sqlite3_free(azCol);
222174 return pSession->rc;
222175 }
222176
222177 /*
222178 ** Session-change object (*pp) contains an old.* record with fewer than
@@ -230436,19 +230468,23 @@
230436 /*************************************************************************
230437 ** Start of highlight() implementation.
230438 */
230439 typedef struct HighlightContext HighlightContext;
230440 struct HighlightContext {
230441 CInstIter iter; /* Coalesced Instance Iterator */
230442 int iPos; /* Current token offset in zIn[] */
230443 int iRangeStart; /* First token to include */
230444 int iRangeEnd; /* If non-zero, last token to include */
230445 const char *zOpen; /* Opening highlight */
230446 const char *zClose; /* Closing highlight */
230447 const char *zIn; /* Input text */
230448 int nIn; /* Size of input text in bytes */
230449 int iOff; /* Current offset within zIn[] */
 
 
 
 
 
230450 char *zOut; /* Output value */
230451 };
230452
230453 /*
230454 ** Append text to the HighlightContext output string - p->zOut. Argument
@@ -230477,12 +230513,12 @@
230477 static int fts5HighlightCb(
230478 void *pContext, /* Pointer to HighlightContext object */
230479 int tflags, /* Mask of FTS5_TOKEN_* flags */
230480 const char *pToken, /* Buffer containing token */
230481 int nToken, /* Size of token in bytes */
230482 int iStartOff, /* Start offset of token */
230483 int iEndOff /* End offset of token */
230484 ){
230485 HighlightContext *p = (HighlightContext*)pContext;
230486 int rc = SQLITE_OK;
230487 int iPos;
230488
@@ -230494,34 +230530,51 @@
230494 if( p->iRangeEnd>=0 ){
230495 if( iPos<p->iRangeStart || iPos>p->iRangeEnd ) return SQLITE_OK;
230496 if( p->iRangeStart && iPos==p->iRangeStart ) p->iOff = iStartOff;
230497 }
230498
230499 if( iPos==p->iter.iStart ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230500 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iStartOff - p->iOff);
230501 fts5HighlightAppend(&rc, p, p->zOpen, -1);
230502 p->iOff = iStartOff;
 
230503 }
230504
230505 if( iPos==p->iter.iEnd ){
230506 if( p->iRangeEnd>=0 && p->iter.iStart<p->iRangeStart ){
 
230507 fts5HighlightAppend(&rc, p, p->zOpen, -1);
 
230508 }
230509 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
230510 fts5HighlightAppend(&rc, p, p->zClose, -1);
230511 p->iOff = iEndOff;
 
230512 if( rc==SQLITE_OK ){
230513 rc = fts5CInstIterNext(&p->iter);
230514 }
230515 }
230516
230517 if( p->iRangeEnd>=0 && iPos==p->iRangeEnd ){
230518 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
230519 p->iOff = iEndOff;
230520 if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
230521 fts5HighlightAppend(&rc, p, p->zClose, -1);
230522 }
230523 }
230524
230525 return rc;
230526 }
230527
@@ -230558,10 +230611,13 @@
230558 }
230559
230560 if( rc==SQLITE_OK ){
230561 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230562 }
 
 
 
230563 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230564
230565 if( rc==SQLITE_OK ){
230566 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
230567 }
@@ -230836,10 +230892,13 @@
230836 }
230837
230838 if( rc==SQLITE_OK ){
230839 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230840 }
 
 
 
230841 if( ctx.iRangeEnd>=(nColSize-1) ){
230842 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230843 }else{
230844 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
230845 }
@@ -247437,11 +247496,11 @@
247437 int nArg, /* Number of args */
247438 sqlite3_value **apUnused /* Function arguments */
247439 ){
247440 assert( nArg==0 );
247441 UNUSED_PARAM2(nArg, apUnused);
247442 sqlite3_result_text(pCtx, "fts5: 2023-10-23 23:34:53 9d388267e4e6724e2df333fe09d509e87defcfe984c5c2ebe031152d320812d0", -1, SQLITE_TRANSIENT);
247443 }
247444
247445 /*
247446 ** Return true if zName is the extension on one of the shadow tables used
247447 ** by this module.
@@ -247460,29 +247519,37 @@
247460 /*
247461 ** Run an integrity check on the FTS5 data structures. Return a string
247462 ** if anything is found amiss. Return a NULL pointer if everything is
247463 ** OK.
247464 */
247465 static int fts5Integrity(sqlite3_vtab *pVtab, char **pzErr){
 
 
 
 
 
 
247466 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
247467 Fts5Config *pConfig = pTab->p.pConfig;
247468 char *zSql;
247469 char *zErr = 0;
247470 int rc;
 
 
247471 zSql = sqlite3_mprintf(
247472 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
247473 pConfig->zDb, pConfig->zName, pConfig->zName);
247474 if( zSql==0 ) return SQLITE_NOMEM;
247475 rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr);
247476 sqlite3_free(zSql);
247477 if( (rc&0xff)==SQLITE_CORRUPT ){
247478 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
247479 pConfig->zDb, pConfig->zName);
247480 }else if( rc!=SQLITE_OK ){
247481 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
247482 " FTS5 table %s.%s: %s",
247483 pConfig->zDb, pConfig->zName, zErr);
247484 }
247485 sqlite3_free(zErr);
247486 return SQLITE_OK;
247487 }
247488
247489
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** ddc6ead6453e0f98943bd07aedd90d47bc2e.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.44.0"
463 #define SQLITE_VERSION_NUMBER 3044000
464 #define SQLITE_SOURCE_ID "2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -2438,11 +2438,11 @@
2438 ** of a table column that its values are likely to be very large - larger
2439 ** than the configured sorter-reference size threshold - then a reference
2440 ** is stored in each sorted record and the required column values loaded
2441 ** from the database as records are returned in sorted order. The default
2442 ** value for this option is to never use this optimization. Specifying a
2443 ** negative value for this option restores the default behavior.
2444 ** This option is only available if SQLite is compiled with the
2445 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2446 **
2447 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2448 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2613,11 +2613,11 @@
2613 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2614 ** <dd> Usually, when a database in wal mode is closed or detached from a
2615 ** database handle, SQLite checks if this will mean that there are now no
2616 ** connections at all to the database. If so, it performs a checkpoint
2617 ** operation before closing the connection. This option may be used to
2618 ** override this behavior. The first parameter passed to this operation
2619 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2620 ** default) to enable them, and negative to leave the setting unchanged.
2621 ** The second parameter is a pointer to an integer
2622 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2623 ** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -4266,10 +4266,11 @@
4266 ** <li> sqlite3_error_offset()
4267 ** </ul>
4268 **
4269 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4270 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
4271 ** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
4272 ** ^(Memory to hold the error message string is managed internally.
4273 ** The application does not need to worry about freeing the result.
4274 ** However, the error string might be overwritten or deallocated by
4275 ** subsequent calls to other SQLite interface functions.)^
4276 **
@@ -6271,11 +6272,11 @@
6272 ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
6273 ** with the same D and N parameters.
6274 ** <li> The database connection closes. SQLite does not make any guarantees
6275 ** about the order in which destructors are called, only that all
6276 ** destructors will be called exactly once at some point during the
6277 ** database connection closing process.
6278 ** </ul>
6279 **
6280 ** SQLite does not do anything with client data other than invoke
6281 ** destructors on the client data at the appropriate time. The intended
6282 ** use for client data is to provide a mechanism for wrapper libraries
@@ -6935,11 +6936,11 @@
6936 ** a valid schema, then -1 is returned.
6937 */
6938 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6939
6940 /*
6941 ** CAPI3REF: Allowed return values from sqlite3_txn_state()
6942 ** KEYWORDS: {transaction state}
6943 **
6944 ** These constants define the current transaction state of a database file.
6945 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6946 ** constants in order to describe the transaction state of schema S
@@ -7067,11 +7068,11 @@
7068 **
7069 ** <p>^There is only one autovacuum pages callback per database connection.
7070 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
7071 ** previous invocations for that database connection. ^If the callback
7072 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
7073 ** then the autovacuum steps callback is canceled. The return value
7074 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
7075 ** be some other error code if something goes wrong. The current
7076 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
7077 ** return codes might be added in future releases.
7078 **
@@ -7588,11 +7589,12 @@
7589 /* The methods above are in versions 1 and 2 of the sqlite_module object.
7590 ** Those below are for version 3 and greater. */
7591 int (*xShadowName)(const char*);
7592 /* The methods above are in versions 1 through 3 of the sqlite_module object.
7593 ** Those below are for version 4 and greater. */
7594 int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
7595 const char *zTabName, int mFlags, char **pzErr);
7596 };
7597
7598 /*
7599 ** CAPI3REF: Virtual Table Indexing Information
7600 ** KEYWORDS: sqlite3_index_info
@@ -8076,11 +8078,11 @@
8078 ** blob handles or active write statements, the current transaction is
8079 ** committed. ^If an error occurs while committing the transaction, an error
8080 ** code is returned and the transaction rolled back.
8081 **
8082 ** Calling this function with an argument that is not a NULL pointer or an
8083 ** open blob handle results in undefined behavior. ^Calling this routine
8084 ** with a null pointer (such as would be returned by a failed call to
8085 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
8086 ** is passed a valid open blob handle, the values returned by the
8087 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
8088 */
@@ -9618,12 +9620,12 @@
9620 ** ^(There may be at most one unlock-notify callback registered by a
9621 ** blocked connection. If sqlite3_unlock_notify() is called when the
9622 ** blocked connection already has a registered unlock-notify callback,
9623 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9624 ** called with a NULL pointer as its second argument, then any existing
9625 ** unlock-notify callback is canceled. ^The blocked connections
9626 ** unlock-notify callback may also be canceled by closing the blocked
9627 ** connection using [sqlite3_close()].
9628 **
9629 ** The unlock-notify callback is not reentrant. If an application invokes
9630 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9631 ** crash or deadlock may be the result.
@@ -19870,10 +19872,11 @@
19872 Trigger retTrig; /* The transient trigger that implements RETURNING */
19873 TriggerStep retTStep; /* The trigger step */
19874 int iRetCur; /* Transient table holding RETURNING results */
19875 int nRetCol; /* Number of in pReturnEL after expansion */
19876 int iRetReg; /* Register array for holding a row of RETURNING */
19877 char zName[40]; /* Name of trigger: "sqlite_returning_%p" */
19878 };
19879
19880 /*
19881 ** An objected used to accumulate the text of a string where we
19882 ** do not necessarily know how big the string will be in the end.
@@ -40939,13 +40942,10 @@
40942 int rc = SQLITE_OK;
40943 unixFile *pFile = (unixFile*)id;
40944 unixInodeInfo *pInode;
40945 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
40946 int skipShared = 0;
 
 
 
40947
40948 assert( pFile );
40949 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
40950 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
40951 osGetpid(0)));
@@ -40957,13 +40957,10 @@
40957 pInode = pFile->pInode;
40958 sqlite3_mutex_enter(pInode->pLockMutex);
40959 assert( pInode->nShared!=0 );
40960 if( pFile->eFileLock>SHARED_LOCK ){
40961 assert( pInode->eFileLock==pFile->eFileLock );
 
 
 
40962
40963 #ifdef SQLITE_DEBUG
40964 /* When reducing a lock such that other processes can start
40965 ** reading the database file again, make sure that the
40966 ** transaction counter was updated if any part of the database
@@ -41008,13 +41005,10 @@
41005 ** the lock.
41006 */
41007 unsigned long long sharedLockByte = SHARED_FIRST+pInode->sharedByte;
41008 pInode->nShared--;
41009 if( pInode->nShared==0 ){
 
 
 
41010 if( !skipShared ){
41011 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
41012 }
41013 if( !rc ){
41014 pInode->eFileLock = NO_LOCK;
@@ -80220,11 +80214,10 @@
80214 **
80215 ** Also check that the page number is in bounds.
80216 */
80217 static int checkRef(IntegrityCk *pCheck, Pgno iPage){
80218 if( iPage>pCheck->nCkPage || iPage==0 ){
 
80219 checkAppendMsg(pCheck, "invalid page number %u", iPage);
80220 return 1;
80221 }
80222 if( getPageReferenced(pCheck, iPage) ){
80223 checkAppendMsg(pCheck, "2nd reference to page %u", iPage);
@@ -80726,19 +80719,14 @@
80719 sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
80720 if( sCheck.nCkPage==0 ){
80721 goto integrity_ck_cleanup;
80722 }
80723
80724 sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
80725 if( !sCheck.aPgRef ){
80726 checkOom(&sCheck);
80727 goto integrity_ck_cleanup;
 
 
 
 
 
80728 }
80729 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
80730 if( sCheck.heap==0 ){
80731 checkOom(&sCheck);
80732 goto integrity_ck_cleanup;
@@ -88408,10 +88396,15 @@
88396 ** Do a comparison between a 64-bit signed integer and a 64-bit floating-point
88397 ** number. Return negative, zero, or positive if the first (i64) is less than,
88398 ** equal to, or greater than the second (double).
88399 */
88400 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64 i, double r){
88401 if( sqlite3IsNaN(r) ){
88402 /* SQLite considers NaN to be a NULL. And all integer values are greater
88403 ** than NULL */
88404 return 1;
88405 }
88406 if( sqlite3Config.bUseLongDouble ){
88407 LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
88408 testcase( x<r );
88409 testcase( x>r );
88410 testcase( x==r );
@@ -99047,25 +99040,33 @@
99040 ** Disable Auth and Trace callbacks while those statements are running if
99041 ** P1 is true.
99042 */
99043 case OP_SqlExec: {
99044 char *zErr;
99045 #ifndef SQLITE_OMIT_AUTHORIZATION
99046 sqlite3_xauth xAuth;
99047 #endif
99048 u8 mTrace;
99049
99050 sqlite3VdbeIncrWriteCounter(p, 0);
99051 db->nSqlExec++;
99052 zErr = 0;
99053 #ifndef SQLITE_OMIT_AUTHORIZATION
99054 xAuth = db->xAuth;
99055 #endif
99056 mTrace = db->mTrace;
99057 if( pOp->p1 ){
99058 #ifndef SQLITE_OMIT_AUTHORIZATION
99059 db->xAuth = 0;
99060 #endif
99061 db->mTrace = 0;
99062 }
99063 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
99064 db->nSqlExec--;
99065 #ifndef SQLITE_OMIT_AUTHORIZATION
99066 db->xAuth = xAuth;
99067 #endif
99068 db->mTrace = mTrace;
99069 if( zErr || rc ){
99070 sqlite3VdbeError(p, "%s", zErr);
99071 sqlite3_free(zErr);
99072 if( rc==SQLITE_NOMEM ) goto no_mem;
@@ -100290,17 +100291,18 @@
100291 break;
100292 }
100293 #endif /* SQLITE_OMIT_VIRTUALTABLE */
100294
100295 #ifndef SQLITE_OMIT_VIRTUALTABLE
100296 /* Opcode: VCheck P1 P2 P3 P4 *
100297 **
100298 ** P4 is a pointer to a Table object that is a virtual table in schema P1
100299 ** that supports the xIntegrity() method. This opcode runs the xIntegrity()
100300 ** method for that virtual table, using P3 as the integer argument. If
100301 ** an error is reported back, the table name is prepended to the error
100302 ** message and that message is stored in P2. If no errors are seen,
100303 ** register P2 is set to NULL.
100304 */
100305 case OP_VCheck: { /* out2 */
100306 Table *pTab;
100307 sqlite3_vtab *pVtab;
100308 const sqlite3_module *pModule;
@@ -100319,11 +100321,13 @@
100321 assert( pModule!=0 );
100322 assert( pModule->iVersion>=4 );
100323 assert( pModule->xIntegrity!=0 );
100324 pTab->nTabRef++;
100325 sqlite3VtabLock(pTab->u.vtab.p);
100326 assert( pOp->p1>=0 && pOp->p1<db->nDb );
100327 rc = pModule->xIntegrity(pVtab, db->aDb[pOp->p1].zDbSName, pTab->zName,
100328 pOp->p3, &zErr);
100329 sqlite3VtabUnlock(pTab->u.vtab.p);
100330 sqlite3DeleteTable(db, pTab);
100331 if( rc ){
100332 sqlite3_free(zErr);
100333 goto abort_due_to_error;
@@ -114667,20 +114671,21 @@
114671 assert( pExpr->pLeft->op==TK_ORDER );
114672 assert( ExprUseXList(pExpr->pLeft) );
114673 pItem->iOBTab = pParse->nTab++;
114674 pOBList = pExpr->pLeft->x.pList;
114675 assert( pOBList->nExpr>0 );
114676 assert( pItem->bOBUnique==0 );
114677 if( pOBList->nExpr==1
114678 && nArg==1
114679 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
114680 pExpr->x.pList->a[0].pExpr,0)==0
114681 ){
114682 pItem->bOBPayload = 0;
114683 pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
114684 }else{
114685 pItem->bOBPayload = 1;
114686 }
 
114687 }else{
114688 pItem->iOBTab = -1;
114689 }
114690 if( ExprHasProperty(pExpr, EP_Distinct) && !pItem->bOBUnique ){
114691 pItem->iDistinct = pParse->nTab++;
@@ -121468,24 +121473,17 @@
121473 pTab->tabFlags |= TF_OOOHidden;
121474 }
121475 }
121476 #endif
121477
 
 
 
 
 
 
 
121478 /*
121479 ** Clean up the data structures associated with the RETURNING clause.
121480 */
121481 static void sqlite3DeleteReturning(sqlite3 *db, Returning *pRet){
121482 Hash *pHash;
121483 pHash = &(db->aDb[1].pSchema->trigHash);
121484 sqlite3HashInsert(pHash, pRet->zName, 0);
121485 sqlite3ExprListDelete(db, pRet->pReturnEL);
121486 sqlite3DbFree(db, pRet);
121487 }
121488
121489 /*
@@ -121524,11 +121522,13 @@
121522 pRet->pReturnEL = pList;
121523 sqlite3ParserAddCleanup(pParse,
121524 (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
121525 testcase( pParse->earlyCleanup );
121526 if( db->mallocFailed ) return;
121527 sqlite3_snprintf(sizeof(pRet->zName), pRet->zName,
121528 "sqlite_returning_%p", pParse);
121529 pRet->retTrig.zName = pRet->zName;
121530 pRet->retTrig.op = TK_RETURNING;
121531 pRet->retTrig.tr_tm = TRIGGER_AFTER;
121532 pRet->retTrig.bReturning = 1;
121533 pRet->retTrig.pSchema = db->aDb[1].pSchema;
121534 pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
@@ -121535,13 +121535,13 @@
121535 pRet->retTrig.step_list = &pRet->retTStep;
121536 pRet->retTStep.op = TK_RETURNING;
121537 pRet->retTStep.pTrig = &pRet->retTrig;
121538 pRet->retTStep.pExprList = pList;
121539 pHash = &(db->aDb[1].pSchema->trigHash);
121540 assert( sqlite3HashFind(pHash, pRet->zName)==0
121541 || pParse->nErr || pParse->ifNotExists );
121542 if( sqlite3HashInsert(pHash, pRet->zName, &pRet->retTrig)
121543 ==&pRet->retTrig ){
121544 sqlite3OomFault(db);
121545 }
121546 }
121547
@@ -138973,11 +138973,11 @@
138973 pVTab = pTab->u.vtab.p->pVtab;
138974 if( NEVER(pVTab==0) ) continue;
138975 if( NEVER(pVTab->pModule==0) ) continue;
138976 if( pVTab->pModule->iVersion<4 ) continue;
138977 if( pVTab->pModule->xIntegrity==0 ) continue;
138978 sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
138979 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
138980 a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
138981 integrityCheckResultRow(v);
138982 sqlite3VdbeJumpHere(v, a1);
138983 #endif
@@ -147929,11 +147929,11 @@
147929 }else{
147930 assert( pF->pFExpr->pLeft!=0 );
147931 assert( ExprUseXList(pF->pFExpr->pLeft) );
147932 assert( pF->pFExpr->pLeft->x.pList!=0 );
147933 nKey = pF->pFExpr->pLeft->x.pList->nExpr;
147934 if( ALWAYS(!pF->bOBUnique) ) nKey++;
147935 }
147936 iTop = sqlite3VdbeAddOp1(v, OP_Rewind, pF->iOBTab); VdbeCoverage(v);
147937 for(j=nArg-1; j>=0; j--){
147938 sqlite3VdbeAddOp3(v, OP_Column, pF->iOBTab, nKey+j, regAgg+j);
147939 }
@@ -147985,10 +147985,11 @@
147985 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
147986 int nArg;
147987 int addrNext = 0;
147988 int regAgg;
147989 int regAggSz = 0;
147990 int regDistinct = 0;
147991 ExprList *pList;
147992 assert( ExprUseXList(pF->pFExpr) );
147993 assert( !IsWindowFunc(pF->pFExpr) );
147994 pList = pF->pFExpr->x.pList;
147995 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
@@ -148034,22 +148035,25 @@
148035 if( pF->bOBPayload ){
148036 regAggSz += nArg;
148037 }
148038 regAggSz++; /* One extra register to hold result of MakeRecord */
148039 regAgg = sqlite3GetTempRange(pParse, regAggSz);
148040 regDistinct = regAgg;
148041 sqlite3ExprCodeExprList(pParse, pOBList, regAgg, 0, SQLITE_ECEL_DUP);
148042 jj = pOBList->nExpr;
148043 if( !pF->bOBUnique ){
148044 sqlite3VdbeAddOp2(v, OP_Sequence, pF->iOBTab, regAgg+jj);
148045 jj++;
148046 }
148047 if( pF->bOBPayload ){
148048 regDistinct = regAgg+jj;
148049 sqlite3ExprCodeExprList(pParse, pList, regDistinct, 0, SQLITE_ECEL_DUP);
148050 }
148051 }else if( pList ){
148052 nArg = pList->nExpr;
148053 regAgg = sqlite3GetTempRange(pParse, nArg);
148054 regDistinct = regAgg;
148055 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
148056 }else{
148057 nArg = 0;
148058 regAgg = 0;
148059 }
@@ -148056,11 +148060,11 @@
148060 if( pF->iDistinct>=0 && pList ){
148061 if( addrNext==0 ){
148062 addrNext = sqlite3VdbeMakeLabel(pParse);
148063 }
148064 pF->iDistinct = codeDistinct(pParse, eDistinctType,
148065 pF->iDistinct, addrNext, pList, regDistinct);
148066 }
148067 if( pF->iOBTab>=0 ){
148068 /* Insert a new record into the ORDER BY table */
148069 sqlite3VdbeAddOp3(v, OP_MakeRecord, regAgg, regAggSz-1,
148070 regAgg+regAggSz-1);
@@ -150934,14 +150938,21 @@
150938 Returning *pReturning;
150939 Select sSelect;
150940 SrcList sFrom;
150941
150942 assert( v!=0 );
150943 if( !pParse->bReturning ){
150944 /* This RETURNING trigger must be for a different statement as
150945 ** this statement lacks a RETURNING clause. */
150946 return;
150947 }
150948 assert( db->pParse==pParse );
150949 pReturning = pParse->u1.pReturning;
150950 if( pTrigger != &(pReturning->retTrig) ){
150951 /* This RETURNING trigger is for a different statement */
150952 return;
150953 }
150954 memset(&sSelect, 0, sizeof(sSelect));
150955 memset(&sFrom, 0, sizeof(sFrom));
150956 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
150957 sSelect.pSrc = &sFrom;
150958 sFrom.nSrc = 1;
@@ -177852,11 +177863,13 @@
177863 }
177864 #endif
177865
177866 /* Experimentally determine if high-precision floating point is
177867 ** available. */
177868 #ifndef SQLITE_OMIT_WSD
177869 sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc);
177870 #endif
177871
177872 return rc;
177873 }
177874
177875 /*
@@ -187833,31 +187846,40 @@
187846
187847 /*
187848 ** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
187849 ** table.
187850 */
187851 static int fts3Integrity(
187852 sqlite3_vtab *pVtab, /* The virtual table to be checked */
187853 const char *zSchema, /* Name of schema in which pVtab lives */
187854 const char *zTabname, /* Name of the pVTab table */
187855 int isQuick, /* True if this is a quick_check */
187856 char **pzErr /* Write error message here */
187857 ){
187858 Fts3Table *p = (Fts3Table*)pVtab;
187859 char *zSql;
187860 int rc;
187861 char *zErr = 0;
187862
187863 assert( pzErr!=0 );
187864 assert( *pzErr==0 );
187865 UNUSED_PARAMETER(isQuick);
187866 zSql = sqlite3_mprintf(
187867 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
187868 zSchema, zTabname, zTabname);
187869 if( zSql==0 ){
187870 return SQLITE_NOMEM;
187871 }
187872 rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr);
187873 sqlite3_free(zSql);
187874 if( (rc&0xff)==SQLITE_CORRUPT ){
187875 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
187876 p->bFts4 ? 4 : 3, zSchema, zTabname);
187877 }else if( rc!=SQLITE_OK ){
187878 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
187879 " FTS%d table %s.%s: %s",
187880 p->bFts4 ? 4 : 3, zSchema, zTabname, zErr);
187881 }
187882 sqlite3_free(zErr);
187883 return SQLITE_OK;
187884 }
187885
@@ -209716,11 +209738,11 @@
209738 }
209739 return 0;
209740 }
209741
209742 /* Forward declaration */
209743 static int rtreeIntegrity(sqlite3_vtab*, const char*, const char*, int, char**);
209744
209745 static sqlite3_module rtreeModule = {
209746 4, /* iVersion */
209747 rtreeCreate, /* xCreate - create a table */
209748 rtreeConnect, /* xConnect - connect to an existing table */
@@ -210571,13 +210593,23 @@
210593 }
210594
210595 /*
210596 ** Implementation of the xIntegrity method for Rtree.
210597 */
210598 static int rtreeIntegrity(
210599 sqlite3_vtab *pVtab, /* The virtual table to check */
210600 const char *zSchema, /* Schema in which the virtual table lives */
210601 const char *zName, /* Name of the virtual table */
210602 int isQuick, /* True for a quick_check */
210603 char **pzErr /* Write results here */
210604 ){
210605 Rtree *pRtree = (Rtree*)pVtab;
210606 int rc;
210607 assert( pzErr!=0 && *pzErr==0 );
210608 UNUSED_PARAMETER(zSchema);
210609 UNUSED_PARAMETER(zName);
210610 UNUSED_PARAMETER(isQuick);
210611 rc = rtreeCheckTable(pRtree->db, pRtree->zDb, pRtree->zName, pzErr);
210612 if( rc==SQLITE_OK && *pzErr ){
210613 *pzErr = sqlite3_mprintf("In RTree %s.%s:\n%z",
210614 pRtree->zDb, pRtree->zName, *pzErr);
210615 }
@@ -222168,11 +222200,11 @@
222200 pSession->nMaxChangesetSize -= sessionVarintLen(nOldCol);
222201 }
222202 }
222203 }
222204
222205 sqlite3_free((char*)azCol);
222206 return pSession->rc;
222207 }
222208
222209 /*
222210 ** Session-change object (*pp) contains an old.* record with fewer than
@@ -230436,19 +230468,23 @@
230468 /*************************************************************************
230469 ** Start of highlight() implementation.
230470 */
230471 typedef struct HighlightContext HighlightContext;
230472 struct HighlightContext {
230473 /* Constant parameters to fts5HighlightCb() */
 
230474 int iRangeStart; /* First token to include */
230475 int iRangeEnd; /* If non-zero, last token to include */
230476 const char *zOpen; /* Opening highlight */
230477 const char *zClose; /* Closing highlight */
230478 const char *zIn; /* Input text */
230479 int nIn; /* Size of input text in bytes */
230480
230481 /* Variables modified by fts5HighlightCb() */
230482 CInstIter iter; /* Coalesced Instance Iterator */
230483 int iPos; /* Current token offset in zIn[] */
230484 int iOff; /* Have copied up to this offset in zIn[] */
230485 int bOpen; /* True if highlight is open */
230486 char *zOut; /* Output value */
230487 };
230488
230489 /*
230490 ** Append text to the HighlightContext output string - p->zOut. Argument
@@ -230477,12 +230513,12 @@
230513 static int fts5HighlightCb(
230514 void *pContext, /* Pointer to HighlightContext object */
230515 int tflags, /* Mask of FTS5_TOKEN_* flags */
230516 const char *pToken, /* Buffer containing token */
230517 int nToken, /* Size of token in bytes */
230518 int iStartOff, /* Start byte offset of token */
230519 int iEndOff /* End byte offset of token */
230520 ){
230521 HighlightContext *p = (HighlightContext*)pContext;
230522 int rc = SQLITE_OK;
230523 int iPos;
230524
@@ -230494,34 +230530,51 @@
230530 if( p->iRangeEnd>=0 ){
230531 if( iPos<p->iRangeStart || iPos>p->iRangeEnd ) return SQLITE_OK;
230532 if( p->iRangeStart && iPos==p->iRangeStart ) p->iOff = iStartOff;
230533 }
230534
230535 /* If the parenthesis is open, and this token is not part of the current
230536 ** phrase, and the starting byte offset of this token is past the point
230537 ** that has currently been copied into the output buffer, close the
230538 ** parenthesis. */
230539 if( p->bOpen
230540 && (iPos<=p->iter.iStart || p->iter.iStart<0)
230541 && iStartOff>p->iOff
230542 ){
230543 fts5HighlightAppend(&rc, p, p->zClose, -1);
230544 p->bOpen = 0;
230545 }
230546
230547 /* If this is the start of a new phrase, and the highlight is not open:
230548 **
230549 ** * copy text from the input up to the start of the phrase, and
230550 ** * open the highlight.
230551 */
230552 if( iPos==p->iter.iStart && p->bOpen==0 ){
230553 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iStartOff - p->iOff);
230554 fts5HighlightAppend(&rc, p, p->zOpen, -1);
230555 p->iOff = iStartOff;
230556 p->bOpen = 1;
230557 }
230558
230559 if( iPos==p->iter.iEnd ){
230560 if( p->bOpen==0 ){
230561 assert( p->iRangeEnd>=0 );
230562 fts5HighlightAppend(&rc, p, p->zOpen, -1);
230563 p->bOpen = 1;
230564 }
230565 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
 
230566 p->iOff = iEndOff;
230567
230568 if( rc==SQLITE_OK ){
230569 rc = fts5CInstIterNext(&p->iter);
230570 }
230571 }
230572
230573 if( iPos==p->iRangeEnd ){
230574 fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
230575 p->iOff = iEndOff;
 
 
 
230576 }
230577
230578 return rc;
230579 }
230580
@@ -230558,10 +230611,13 @@
230611 }
230612
230613 if( rc==SQLITE_OK ){
230614 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230615 }
230616 if( ctx.bOpen ){
230617 fts5HighlightAppend(&rc, &ctx, ctx.zClose, -1);
230618 }
230619 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230620
230621 if( rc==SQLITE_OK ){
230622 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
230623 }
@@ -230836,10 +230892,13 @@
230892 }
230893
230894 if( rc==SQLITE_OK ){
230895 rc = pApi->xTokenize(pFts, ctx.zIn, ctx.nIn, (void*)&ctx,fts5HighlightCb);
230896 }
230897 if( ctx.bOpen ){
230898 fts5HighlightAppend(&rc, &ctx, ctx.zClose, -1);
230899 }
230900 if( ctx.iRangeEnd>=(nColSize-1) ){
230901 fts5HighlightAppend(&rc, &ctx, &ctx.zIn[ctx.iOff], ctx.nIn - ctx.iOff);
230902 }else{
230903 fts5HighlightAppend(&rc, &ctx, zEllips, -1);
230904 }
@@ -247437,11 +247496,11 @@
247496 int nArg, /* Number of args */
247497 sqlite3_value **apUnused /* Function arguments */
247498 ){
247499 assert( nArg==0 );
247500 UNUSED_PARAM2(nArg, apUnused);
247501 sqlite3_result_text(pCtx, "fts5: 2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1", -1, SQLITE_TRANSIENT);
247502 }
247503
247504 /*
247505 ** Return true if zName is the extension on one of the shadow tables used
247506 ** by this module.
@@ -247460,29 +247519,37 @@
247519 /*
247520 ** Run an integrity check on the FTS5 data structures. Return a string
247521 ** if anything is found amiss. Return a NULL pointer if everything is
247522 ** OK.
247523 */
247524 static int fts5Integrity(
247525 sqlite3_vtab *pVtab, /* the FTS5 virtual table to check */
247526 const char *zSchema, /* Name of schema in which this table lives */
247527 const char *zTabname, /* Name of the table itself */
247528 int isQuick, /* True if this is a quick-check */
247529 char **pzErr /* Write error message here */
247530 ){
247531 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
247532 Fts5Config *pConfig = pTab->p.pConfig;
247533 char *zSql;
247534 char *zErr = 0;
247535 int rc;
247536 assert( pzErr!=0 && *pzErr==0 );
247537 UNUSED_PARAM(isQuick);
247538 zSql = sqlite3_mprintf(
247539 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
247540 zSchema, zTabname, pConfig->zName);
247541 if( zSql==0 ) return SQLITE_NOMEM;
247542 rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr);
247543 sqlite3_free(zSql);
247544 if( (rc&0xff)==SQLITE_CORRUPT ){
247545 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
247546 zSchema, zTabname);
247547 }else if( rc!=SQLITE_OK ){
247548 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
247549 " FTS5 table %s.%s: %s",
247550 zSchema, zTabname, zErr);
247551 }
247552 sqlite3_free(zErr);
247553 return SQLITE_OK;
247554 }
247555
247556
+12 -10
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.44.0"
150150
#define SQLITE_VERSION_NUMBER 3044000
151
-#define SQLITE_SOURCE_ID "2023-10-24 11:06:44 54be9af4469d7e31ee852f67e5aa32996557c10de654a60103fd165d2fedf311"
151
+#define SQLITE_SOURCE_ID "2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -2125,11 +2125,11 @@
21252125
** of a table column that its values are likely to be very large - larger
21262126
** than the configured sorter-reference size threshold - then a reference
21272127
** is stored in each sorted record and the required column values loaded
21282128
** from the database as records are returned in sorted order. The default
21292129
** value for this option is to never use this optimization. Specifying a
2130
-** negative value for this option restores the default behaviour.
2130
+** negative value for this option restores the default behavior.
21312131
** This option is only available if SQLite is compiled with the
21322132
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
21332133
**
21342134
** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
21352135
** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2300,11 +2300,11 @@
23002300
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
23012301
** <dd> Usually, when a database in wal mode is closed or detached from a
23022302
** database handle, SQLite checks if this will mean that there are now no
23032303
** connections at all to the database. If so, it performs a checkpoint
23042304
** operation before closing the connection. This option may be used to
2305
-** override this behaviour. The first parameter passed to this operation
2305
+** override this behavior. The first parameter passed to this operation
23062306
** is an integer - positive to disable checkpoints-on-close, or zero (the
23072307
** default) to enable them, and negative to leave the setting unchanged.
23082308
** The second parameter is a pointer to an integer
23092309
** into which is written 0 or 1 to indicate whether checkpoints-on-close
23102310
** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -3953,10 +3953,11 @@
39533953
** <li> sqlite3_error_offset()
39543954
** </ul>
39553955
**
39563956
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
39573957
** text that describes the error, as either UTF-8 or UTF-16 respectively.
3958
+** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
39583959
** ^(Memory to hold the error message string is managed internally.
39593960
** The application does not need to worry about freeing the result.
39603961
** However, the error string might be overwritten or deallocated by
39613962
** subsequent calls to other SQLite interface functions.)^
39623963
**
@@ -5958,11 +5959,11 @@
59585959
** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
59595960
** with the same D and N parameters.
59605961
** <li> The database connection closes. SQLite does not make any guarantees
59615962
** about the order in which destructors are called, only that all
59625963
** destructors will be called exactly once at some point during the
5963
-** database connection closingi process.
5964
+** database connection closing process.
59645965
** </ul>
59655966
**
59665967
** SQLite does not do anything with client data other than invoke
59675968
** destructors on the client data at the appropriate time. The intended
59685969
** use for client data is to provide a mechanism for wrapper libraries
@@ -6622,11 +6623,11 @@
66226623
** a valid schema, then -1 is returned.
66236624
*/
66246625
SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
66256626
66266627
/*
6627
-** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6628
+** CAPI3REF: Allowed return values from sqlite3_txn_state()
66286629
** KEYWORDS: {transaction state}
66296630
**
66306631
** These constants define the current transaction state of a database file.
66316632
** ^The [sqlite3_txn_state(D,S)] interface returns one of these
66326633
** constants in order to describe the transaction state of schema S
@@ -6754,11 +6755,11 @@
67546755
**
67556756
** <p>^There is only one autovacuum pages callback per database connection.
67566757
** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
67576758
** previous invocations for that database connection. ^If the callback
67586759
** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6759
-** then the autovacuum steps callback is cancelled. The return value
6760
+** then the autovacuum steps callback is canceled. The return value
67606761
** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
67616762
** be some other error code if something goes wrong. The current
67626763
** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
67636764
** return codes might be added in future releases.
67646765
**
@@ -7275,11 +7276,12 @@
72757276
/* The methods above are in versions 1 and 2 of the sqlite_module object.
72767277
** Those below are for version 3 and greater. */
72777278
int (*xShadowName)(const char*);
72787279
/* The methods above are in versions 1 through 3 of the sqlite_module object.
72797280
** Those below are for version 4 and greater. */
7280
- int (*xIntegrity)(sqlite3_vtab *pVTab, char**);
7281
+ int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
7282
+ const char *zTabName, int mFlags, char **pzErr);
72817283
};
72827284
72837285
/*
72847286
** CAPI3REF: Virtual Table Indexing Information
72857287
** KEYWORDS: sqlite3_index_info
@@ -7763,11 +7765,11 @@
77637765
** blob handles or active write statements, the current transaction is
77647766
** committed. ^If an error occurs while committing the transaction, an error
77657767
** code is returned and the transaction rolled back.
77667768
**
77677769
** Calling this function with an argument that is not a NULL pointer or an
7768
-** open blob handle results in undefined behaviour. ^Calling this routine
7770
+** open blob handle results in undefined behavior. ^Calling this routine
77697771
** with a null pointer (such as would be returned by a failed call to
77707772
** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
77717773
** is passed a valid open blob handle, the values returned by the
77727774
** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
77737775
*/
@@ -9305,12 +9307,12 @@
93059307
** ^(There may be at most one unlock-notify callback registered by a
93069308
** blocked connection. If sqlite3_unlock_notify() is called when the
93079309
** blocked connection already has a registered unlock-notify callback,
93089310
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
93099311
** called with a NULL pointer as its second argument, then any existing
9310
-** unlock-notify callback is cancelled. ^The blocked connections
9311
-** unlock-notify callback may also be cancelled by closing the blocked
9312
+** unlock-notify callback is canceled. ^The blocked connections
9313
+** unlock-notify callback may also be canceled by closing the blocked
93129314
** connection using [sqlite3_close()].
93139315
**
93149316
** The unlock-notify callback is not reentrant. If an application invokes
93159317
** any sqlite3_xxx API functions from within an unlock-notify callback, a
93169318
** crash or deadlock may be the result.
93179319
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.44.0"
150 #define SQLITE_VERSION_NUMBER 3044000
151 #define SQLITE_SOURCE_ID "2023-10-24 11:06:44 54be9af4469d7e31ee852f67e5aa32996557c10de654a60103fd165d2fedf311"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2125,11 +2125,11 @@
2125 ** of a table column that its values are likely to be very large - larger
2126 ** than the configured sorter-reference size threshold - then a reference
2127 ** is stored in each sorted record and the required column values loaded
2128 ** from the database as records are returned in sorted order. The default
2129 ** value for this option is to never use this optimization. Specifying a
2130 ** negative value for this option restores the default behaviour.
2131 ** This option is only available if SQLite is compiled with the
2132 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2133 **
2134 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2135 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2300,11 +2300,11 @@
2300 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2301 ** <dd> Usually, when a database in wal mode is closed or detached from a
2302 ** database handle, SQLite checks if this will mean that there are now no
2303 ** connections at all to the database. If so, it performs a checkpoint
2304 ** operation before closing the connection. This option may be used to
2305 ** override this behaviour. The first parameter passed to this operation
2306 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2307 ** default) to enable them, and negative to leave the setting unchanged.
2308 ** The second parameter is a pointer to an integer
2309 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2310 ** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -3953,10 +3953,11 @@
3953 ** <li> sqlite3_error_offset()
3954 ** </ul>
3955 **
3956 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
3957 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
 
3958 ** ^(Memory to hold the error message string is managed internally.
3959 ** The application does not need to worry about freeing the result.
3960 ** However, the error string might be overwritten or deallocated by
3961 ** subsequent calls to other SQLite interface functions.)^
3962 **
@@ -5958,11 +5959,11 @@
5958 ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
5959 ** with the same D and N parameters.
5960 ** <li> The database connection closes. SQLite does not make any guarantees
5961 ** about the order in which destructors are called, only that all
5962 ** destructors will be called exactly once at some point during the
5963 ** database connection closingi process.
5964 ** </ul>
5965 **
5966 ** SQLite does not do anything with client data other than invoke
5967 ** destructors on the client data at the appropriate time. The intended
5968 ** use for client data is to provide a mechanism for wrapper libraries
@@ -6622,11 +6623,11 @@
6622 ** a valid schema, then -1 is returned.
6623 */
6624 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6625
6626 /*
6627 ** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6628 ** KEYWORDS: {transaction state}
6629 **
6630 ** These constants define the current transaction state of a database file.
6631 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6632 ** constants in order to describe the transaction state of schema S
@@ -6754,11 +6755,11 @@
6754 **
6755 ** <p>^There is only one autovacuum pages callback per database connection.
6756 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6757 ** previous invocations for that database connection. ^If the callback
6758 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6759 ** then the autovacuum steps callback is cancelled. The return value
6760 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6761 ** be some other error code if something goes wrong. The current
6762 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6763 ** return codes might be added in future releases.
6764 **
@@ -7275,11 +7276,12 @@
7275 /* The methods above are in versions 1 and 2 of the sqlite_module object.
7276 ** Those below are for version 3 and greater. */
7277 int (*xShadowName)(const char*);
7278 /* The methods above are in versions 1 through 3 of the sqlite_module object.
7279 ** Those below are for version 4 and greater. */
7280 int (*xIntegrity)(sqlite3_vtab *pVTab, char**);
 
7281 };
7282
7283 /*
7284 ** CAPI3REF: Virtual Table Indexing Information
7285 ** KEYWORDS: sqlite3_index_info
@@ -7763,11 +7765,11 @@
7763 ** blob handles or active write statements, the current transaction is
7764 ** committed. ^If an error occurs while committing the transaction, an error
7765 ** code is returned and the transaction rolled back.
7766 **
7767 ** Calling this function with an argument that is not a NULL pointer or an
7768 ** open blob handle results in undefined behaviour. ^Calling this routine
7769 ** with a null pointer (such as would be returned by a failed call to
7770 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
7771 ** is passed a valid open blob handle, the values returned by the
7772 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
7773 */
@@ -9305,12 +9307,12 @@
9305 ** ^(There may be at most one unlock-notify callback registered by a
9306 ** blocked connection. If sqlite3_unlock_notify() is called when the
9307 ** blocked connection already has a registered unlock-notify callback,
9308 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9309 ** called with a NULL pointer as its second argument, then any existing
9310 ** unlock-notify callback is cancelled. ^The blocked connections
9311 ** unlock-notify callback may also be cancelled by closing the blocked
9312 ** connection using [sqlite3_close()].
9313 **
9314 ** The unlock-notify callback is not reentrant. If an application invokes
9315 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9316 ** crash or deadlock may be the result.
9317
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.44.0"
150 #define SQLITE_VERSION_NUMBER 3044000
151 #define SQLITE_SOURCE_ID "2023-10-29 20:05:18 ddc6ead6453e0f98943bd07aedd90d47bc2e9e9e27b008d493491168bea2b3f1"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2125,11 +2125,11 @@
2125 ** of a table column that its values are likely to be very large - larger
2126 ** than the configured sorter-reference size threshold - then a reference
2127 ** is stored in each sorted record and the required column values loaded
2128 ** from the database as records are returned in sorted order. The default
2129 ** value for this option is to never use this optimization. Specifying a
2130 ** negative value for this option restores the default behavior.
2131 ** This option is only available if SQLite is compiled with the
2132 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2133 **
2134 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2135 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
@@ -2300,11 +2300,11 @@
2300 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2301 ** <dd> Usually, when a database in wal mode is closed or detached from a
2302 ** database handle, SQLite checks if this will mean that there are now no
2303 ** connections at all to the database. If so, it performs a checkpoint
2304 ** operation before closing the connection. This option may be used to
2305 ** override this behavior. The first parameter passed to this operation
2306 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2307 ** default) to enable them, and negative to leave the setting unchanged.
2308 ** The second parameter is a pointer to an integer
2309 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2310 ** have been disabled - 0 if they are not disabled, 1 if they are.
@@ -3953,10 +3953,11 @@
3953 ** <li> sqlite3_error_offset()
3954 ** </ul>
3955 **
3956 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
3957 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
3958 ** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
3959 ** ^(Memory to hold the error message string is managed internally.
3960 ** The application does not need to worry about freeing the result.
3961 ** However, the error string might be overwritten or deallocated by
3962 ** subsequent calls to other SQLite interface functions.)^
3963 **
@@ -5958,11 +5959,11 @@
5959 ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
5960 ** with the same D and N parameters.
5961 ** <li> The database connection closes. SQLite does not make any guarantees
5962 ** about the order in which destructors are called, only that all
5963 ** destructors will be called exactly once at some point during the
5964 ** database connection closing process.
5965 ** </ul>
5966 **
5967 ** SQLite does not do anything with client data other than invoke
5968 ** destructors on the client data at the appropriate time. The intended
5969 ** use for client data is to provide a mechanism for wrapper libraries
@@ -6622,11 +6623,11 @@
6623 ** a valid schema, then -1 is returned.
6624 */
6625 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6626
6627 /*
6628 ** CAPI3REF: Allowed return values from sqlite3_txn_state()
6629 ** KEYWORDS: {transaction state}
6630 **
6631 ** These constants define the current transaction state of a database file.
6632 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6633 ** constants in order to describe the transaction state of schema S
@@ -6754,11 +6755,11 @@
6755 **
6756 ** <p>^There is only one autovacuum pages callback per database connection.
6757 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6758 ** previous invocations for that database connection. ^If the callback
6759 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6760 ** then the autovacuum steps callback is canceled. The return value
6761 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6762 ** be some other error code if something goes wrong. The current
6763 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6764 ** return codes might be added in future releases.
6765 **
@@ -7275,11 +7276,12 @@
7276 /* The methods above are in versions 1 and 2 of the sqlite_module object.
7277 ** Those below are for version 3 and greater. */
7278 int (*xShadowName)(const char*);
7279 /* The methods above are in versions 1 through 3 of the sqlite_module object.
7280 ** Those below are for version 4 and greater. */
7281 int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
7282 const char *zTabName, int mFlags, char **pzErr);
7283 };
7284
7285 /*
7286 ** CAPI3REF: Virtual Table Indexing Information
7287 ** KEYWORDS: sqlite3_index_info
@@ -7763,11 +7765,11 @@
7765 ** blob handles or active write statements, the current transaction is
7766 ** committed. ^If an error occurs while committing the transaction, an error
7767 ** code is returned and the transaction rolled back.
7768 **
7769 ** Calling this function with an argument that is not a NULL pointer or an
7770 ** open blob handle results in undefined behavior. ^Calling this routine
7771 ** with a null pointer (such as would be returned by a failed call to
7772 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
7773 ** is passed a valid open blob handle, the values returned by the
7774 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
7775 */
@@ -9305,12 +9307,12 @@
9307 ** ^(There may be at most one unlock-notify callback registered by a
9308 ** blocked connection. If sqlite3_unlock_notify() is called when the
9309 ** blocked connection already has a registered unlock-notify callback,
9310 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9311 ** called with a NULL pointer as its second argument, then any existing
9312 ** unlock-notify callback is canceled. ^The blocked connections
9313 ** unlock-notify callback may also be canceled by closing the blocked
9314 ** connection using [sqlite3_close()].
9315 **
9316 ** The unlock-notify callback is not reentrant. If an application invokes
9317 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9318 ** crash or deadlock may be the result.
9319

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button