Fossil SCM

Update the built-in SQLite to the latest trunk version.

drh 2025-06-19 20:24 trunk
Commit b10fbd8047eb98514536a3e4798b46bbc46078d1016fad9d945500451b2afa62
3 files changed +268 -335 +265 -104 +16 -16
+268 -335
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1713,339 +1713,176 @@
17131713
** work here in the middle of this regular program.
17141714
*/
17151715
#define SQLITE_EXTENSION_INIT1
17161716
#define SQLITE_EXTENSION_INIT2(X) (void)(X)
17171717
1718
-#if defined(_WIN32) && defined(_MSC_VER)
1719
-/************************* Begin test_windirent.h ******************/
1718
+/************************* Begin ../ext/misc/windirent.h ******************/
17201719
/*
1721
-** 2015 November 30
1720
+** 2025-06-05
17221721
**
17231722
** The author disclaims copyright to this source code. In place of
17241723
** a legal notice, here is a blessing:
17251724
**
17261725
** May you do good and not evil.
17271726
** May you find forgiveness for yourself and forgive others.
17281727
** May you share freely, never taking more than you give.
17291728
**
17301729
*************************************************************************
1731
-** This file contains declarations for most of the opendir() family of
1732
-** POSIX functions on Win32 using the MSVCRT.
1730
+**
1731
+** An implementation of opendir(), readdir(), and closedir() for Windows,
1732
+** based on the FindFirstFile(), FindNextFile(), and FindClose() APIs
1733
+** of Win32.
1734
+**
1735
+** #include this file inside any C-code module that needs to use
1736
+** opendir()/readdir()/closedir(). This file is a no-op on non-Windows
1737
+** machines. On Windows, static functions are defined that implement
1738
+** those standard interfaces.
17331739
*/
1734
-
17351740
#if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
17361741
#define SQLITE_WINDIRENT_H
17371742
1738
-/*
1739
-** We need several data types from the Windows SDK header.
1740
-*/
1741
-
17421743
#ifndef WIN32_LEAN_AND_MEAN
17431744
#define WIN32_LEAN_AND_MEAN
17441745
#endif
1745
-
1746
-#include "windows.h"
1747
-
1748
-/*
1749
-** We need several support functions from the SQLite core.
1750
-*/
1751
-
1752
-/* #include "sqlite3.h" */
1753
-
1754
-/*
1755
-** We need several things from the ANSI and MSVCRT headers.
1756
-*/
1757
-
1746
+#include <windows.h>
1747
+#include <io.h>
17581748
#include <stdio.h>
17591749
#include <stdlib.h>
17601750
#include <errno.h>
1761
-#include <io.h>
17621751
#include <limits.h>
17631752
#include <sys/types.h>
17641753
#include <sys/stat.h>
1765
-
1766
-/*
1767
-** We may need several defines that should have been in "sys/stat.h".
1768
-*/
1769
-
1754
+#include <string.h>
1755
+#ifndef FILENAME_MAX
1756
+# define FILENAME_MAX (260)
1757
+#endif
17701758
#ifndef S_ISREG
1771
-#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
1759
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
17721760
#endif
1773
-
17741761
#ifndef S_ISDIR
1775
-#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
1762
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
17761763
#endif
1777
-
17781764
#ifndef S_ISLNK
1779
-#define S_ISLNK(mode) (0)
1780
-#endif
1781
-
1782
-/*
1783
-** We may need to provide the "mode_t" type.
1784
-*/
1785
-
1786
-#ifndef MODE_T_DEFINED
1787
- #define MODE_T_DEFINED
1788
- typedef unsigned short mode_t;
1789
-#endif
1790
-
1791
-/*
1792
-** We may need to provide the "ino_t" type.
1793
-*/
1794
-
1795
-#ifndef INO_T_DEFINED
1796
- #define INO_T_DEFINED
1797
- typedef unsigned short ino_t;
1798
-#endif
1799
-
1800
-/*
1801
-** We need to define "NAME_MAX" if it was not present in "limits.h".
1802
-*/
1803
-
1804
-#ifndef NAME_MAX
1805
-# ifdef FILENAME_MAX
1806
-# define NAME_MAX (FILENAME_MAX)
1807
-# else
1808
-# define NAME_MAX (260)
1809
-# endif
1810
-# define DIRENT_NAME_MAX (NAME_MAX)
1811
-#endif
1812
-
1813
-/*
1814
-** We need to define "NULL_INTPTR_T" and "BAD_INTPTR_T".
1815
-*/
1816
-
1817
-#ifndef NULL_INTPTR_T
1818
-# define NULL_INTPTR_T ((intptr_t)(0))
1819
-#endif
1820
-
1821
-#ifndef BAD_INTPTR_T
1822
-# define BAD_INTPTR_T ((intptr_t)(-1))
1823
-#endif
1824
-
1825
-/*
1826
-** We need to provide the necessary structures and related types.
1827
-*/
1828
-
1829
-#ifndef DIRENT_DEFINED
1830
-#define DIRENT_DEFINED
1831
-typedef struct DIRENT DIRENT;
1832
-typedef DIRENT *LPDIRENT;
1833
-struct DIRENT {
1834
- ino_t d_ino; /* Sequence number, do not use. */
1835
- unsigned d_attributes; /* Win32 file attributes. */
1836
- char d_name[NAME_MAX + 1]; /* Name within the directory. */
1837
-};
1838
-#endif
1839
-
1840
-#ifndef DIR_DEFINED
1841
-#define DIR_DEFINED
1842
-typedef struct DIR DIR;
1843
-typedef DIR *LPDIR;
1765
+#define S_ISLNK(m) (0)
1766
+#endif
1767
+typedef unsigned short mode_t;
1768
+
1769
+/* The dirent object for Windows is abbreviated. The only field really
1770
+** usable by applications is d_name[].
1771
+*/
1772
+struct dirent {
1773
+ int d_ino; /* Inode number (synthesized) */
1774
+ unsigned d_attributes; /* File attributes */
1775
+ char d_name[FILENAME_MAX]; /* Null-terminated filename */
1776
+};
1777
+
1778
+/* The internals of DIR are opaque according to standards. So it
1779
+** does not matter what we put here. */
1780
+typedef struct DIR DIR;
18441781
struct DIR {
1845
- intptr_t d_handle; /* Value returned by "_findfirst". */
1846
- DIRENT d_first; /* DIRENT constructed based on "_findfirst". */
1847
- DIRENT d_next; /* DIRENT constructed based on "_findnext". */
1848
-};
1849
-#endif
1850
-
1851
-/*
1852
-** Provide a macro, for use by the implementation, to determine if a
1853
-** particular directory entry should be skipped over when searching for
1854
-** the next directory entry that should be returned by the readdir().
1855
-*/
1856
-
1857
-#ifndef is_filtered
1858
-# define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1859
-#endif
1860
-
1861
-/*
1862
-** Provide the function prototype for the POSIX compatible getenv()
1863
-** function. This function is not thread-safe.
1864
-*/
1865
-
1866
-extern const char *windirent_getenv(const char *name);
1867
-
1868
-/*
1869
-** Finally, we can provide the function prototypes for the opendir(),
1870
-** readdir(), and closedir() POSIX functions.
1871
-*/
1872
-
1873
-extern LPDIR opendir(const char *dirname);
1874
-extern LPDIRENT readdir(LPDIR dirp);
1875
-extern INT closedir(LPDIR dirp);
1876
-
1877
-#endif /* defined(WIN32) && defined(_MSC_VER) */
1878
-
1879
-/************************* End test_windirent.h ********************/
1880
-/************************* Begin test_windirent.c ******************/
1881
-/*
1882
-** 2015 November 30
1883
-**
1884
-** The author disclaims copyright to this source code. In place of
1885
-** a legal notice, here is a blessing:
1886
-**
1887
-** May you do good and not evil.
1888
-** May you find forgiveness for yourself and forgive others.
1889
-** May you share freely, never taking more than you give.
1890
-**
1891
-*************************************************************************
1892
-** This file contains code to implement most of the opendir() family of
1893
-** POSIX functions on Win32 using the MSVCRT.
1894
-*/
1895
-
1896
-#if defined(_WIN32) && defined(_MSC_VER)
1897
-/* #include "test_windirent.h" */
1898
-
1899
-/*
1900
-** Implementation of the POSIX getenv() function using the Win32 API.
1901
-** This function is not thread-safe.
1902
-*/
1903
-const char *windirent_getenv(
1904
- const char *name
1905
-){
1906
- static char value[32768]; /* Maximum length, per MSDN */
1907
- DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
1908
- DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
1909
-
1910
- memset(value, 0, sizeof(value));
1911
- dwRet = GetEnvironmentVariableA(name, value, dwSize);
1912
- if( dwRet==0 || dwRet>dwSize ){
1913
- /*
1914
- ** The function call to GetEnvironmentVariableA() failed -OR-
1915
- ** the buffer is not large enough. Either way, return NULL.
1916
- */
1917
- return 0;
1918
- }else{
1919
- /*
1920
- ** The function call to GetEnvironmentVariableA() succeeded
1921
- ** -AND- the buffer contains the entire value.
1922
- */
1923
- return value;
1924
- }
1925
-}
1926
-
1927
-/*
1928
-** Implementation of the POSIX opendir() function using the MSVCRT.
1929
-*/
1930
-LPDIR opendir(
1931
- const char *dirname /* Directory name, UTF8 encoding */
1932
-){
1933
- struct _wfinddata_t data;
1934
- LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
1935
- SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
1782
+ intptr_t d_handle; /* Handle for findfirst()/findnext() */
1783
+ struct dirent cur; /* Current entry */
1784
+};
1785
+
1786
+/* Ignore hidden and system files */
1787
+#define WindowsFileToIgnore(a) \
1788
+ ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1789
+
1790
+/*
1791
+** Close a previously opened directory
1792
+*/
1793
+static int closedir(DIR *pDir){
1794
+ int rc = 0;
1795
+ if( pDir==0 ){
1796
+ return EINVAL;
1797
+ }
1798
+ if( pDir->d_handle!=0 && pDir->d_handle!=(-1) ){
1799
+ rc = _findclose(pDir->d_handle);
1800
+ }
1801
+ sqlite3_free(pDir);
1802
+ return rc;
1803
+}
1804
+
1805
+/*
1806
+** Open a new directory. The directory name should be UTF-8 encoded.
1807
+** appropriate translations happen automatically.
1808
+*/
1809
+static DIR *opendir(const char *zDirName){
1810
+ DIR *pDir;
19361811
wchar_t *b1;
19371812
sqlite3_int64 sz;
1938
-
1939
- if( dirp==NULL ) return NULL;
1940
- memset(dirp, 0, sizeof(DIR));
1941
-
1942
- /* TODO: Remove this if Unix-style root paths are not used. */
1943
- if( sqlite3_stricmp(dirname, "/")==0 ){
1944
- dirname = windirent_getenv("SystemDrive");
1945
- }
1946
-
1813
+ struct _wfinddata_t data;
1814
+
1815
+ pDir = sqlite3_malloc64( sizeof(DIR) );
1816
+ if( pDir==0 ) return 0;
1817
+ memset(pDir, 0, sizeof(DIR));
19471818
memset(&data, 0, sizeof(data));
1948
- sz = strlen(dirname);
1819
+ sz = strlen(zDirName);
19491820
b1 = sqlite3_malloc64( (sz+3)*sizeof(b1[0]) );
19501821
if( b1==0 ){
1951
- closedir(dirp);
1822
+ closedir(pDir);
19521823
return NULL;
19531824
}
1954
- sz = MultiByteToWideChar(CP_UTF8, 0, dirname, sz, b1, sz);
1825
+ sz = MultiByteToWideChar(CP_UTF8, 0, zDirName, sz, b1, sz);
19551826
b1[sz++] = '\\';
19561827
b1[sz++] = '*';
19571828
b1[sz] = 0;
1958
- if( sz+1>(sqlite3_int64)namesize ){
1959
- closedir(dirp);
1829
+ if( sz+1>sizeof(data.name)/sizeof(data.name[0]) ){
1830
+ closedir(pDir);
19601831
sqlite3_free(b1);
19611832
return NULL;
19621833
}
19631834
memcpy(data.name, b1, (sz+1)*sizeof(b1[0]));
19641835
sqlite3_free(b1);
1965
- dirp->d_handle = _wfindfirst(data.name, &data);
1966
-
1967
- if( dirp->d_handle==BAD_INTPTR_T ){
1968
- closedir(dirp);
1969
- return NULL;
1970
- }
1971
-
1972
- /* TODO: Remove this block to allow hidden and/or system files. */
1973
- if( is_filtered(data) ){
1974
-next:
1975
-
1976
- memset(&data, 0, sizeof(data));
1977
- if( _wfindnext(dirp->d_handle, &data)==-1 ){
1978
- closedir(dirp);
1979
- return NULL;
1980
- }
1981
-
1982
- /* TODO: Remove this block to allow hidden and/or system files. */
1983
- if( is_filtered(data) ) goto next;
1984
- }
1985
-
1986
- dirp->d_first.d_attributes = data.attrib;
1987
- WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1988
- dirp->d_first.d_name, DIRENT_NAME_MAX, 0, 0);
1989
- return dirp;
1990
-}
1991
-
1992
-/*
1993
-** Implementation of the POSIX readdir() function using the MSVCRT.
1994
-*/
1995
-LPDIRENT readdir(
1996
- LPDIR dirp
1997
-){
1998
- struct _wfinddata_t data;
1999
-
2000
- if( dirp==NULL ) return NULL;
2001
-
2002
- if( dirp->d_first.d_ino==0 ){
2003
- dirp->d_first.d_ino++;
2004
- dirp->d_next.d_ino++;
2005
-
2006
- return &dirp->d_first;
2007
- }
2008
-
2009
-next:
2010
-
2011
- memset(&data, 0, sizeof(data));
2012
- if( _wfindnext(dirp->d_handle, &data)==-1 ) return NULL;
2013
-
2014
- /* TODO: Remove this block to allow hidden and/or system files. */
2015
- if( is_filtered(data) ) goto next;
2016
-
2017
- dirp->d_next.d_ino++;
2018
- dirp->d_next.d_attributes = data.attrib;
2019
- WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
2020
- dirp->d_next.d_name, DIRENT_NAME_MAX, 0, 0);
2021
- return &dirp->d_next;
2022
-}
2023
-
2024
-/*
2025
-** Implementation of the POSIX closedir() function using the MSVCRT.
2026
-*/
2027
-INT closedir(
2028
- LPDIR dirp
2029
-){
2030
- INT result = 0;
2031
-
2032
- if( dirp==NULL ) return EINVAL;
2033
-
2034
- if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
2035
- result = _findclose(dirp->d_handle);
2036
- }
2037
-
2038
- sqlite3_free(dirp);
2039
- return result;
2040
-}
2041
-
2042
-#endif /* defined(WIN32) && defined(_MSC_VER) */
2043
-
2044
-/************************* End test_windirent.c ********************/
2045
-#define dirent DIRENT
2046
-#endif
1836
+ pDir->d_handle = _wfindfirst(data.name, &data);
1837
+ if( pDir->d_handle<0 ){
1838
+ closedir(pDir);
1839
+ return NULL;
1840
+ }
1841
+ while( WindowsFileToIgnore(data) ){
1842
+ memset(&data, 0, sizeof(data));
1843
+ if( _wfindnext(pDir->d_handle, &data)==-1 ){
1844
+ closedir(pDir);
1845
+ return NULL;
1846
+ }
1847
+ }
1848
+ pDir->cur.d_ino = 0;
1849
+ pDir->cur.d_attributes = data.attrib;
1850
+ WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1851
+ pDir->cur.d_name, FILENAME_MAX, 0, 0);
1852
+ return pDir;
1853
+}
1854
+
1855
+/*
1856
+** Read the next entry from a directory.
1857
+**
1858
+** The returned struct-dirent object is managed by DIR. It is only
1859
+** valid until the next readdir() or closedir() call. Only the
1860
+** d_name[] field is meaningful. The d_name[] value has been
1861
+** translated into UTF8.
1862
+*/
1863
+static struct dirent *readdir(DIR *pDir){
1864
+ struct _wfinddata_t data;
1865
+ if( pDir==0 ) return 0;
1866
+ if( (pDir->cur.d_ino++)==0 ){
1867
+ return &pDir->cur;
1868
+ }
1869
+ do{
1870
+ memset(&data, 0, sizeof(data));
1871
+ if( _wfindnext(pDir->d_handle, &data)==-1 ){
1872
+ return NULL;
1873
+ }
1874
+ }while( WindowsFileToIgnore(data) );
1875
+ pDir->cur.d_attributes = data.attrib;
1876
+ WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1877
+ pDir->cur.d_name, FILENAME_MAX, 0, 0);
1878
+ return &pDir->cur;
1879
+}
1880
+
1881
+#endif /* defined(_WIN32) && defined(_MSC_VER) */
1882
+
1883
+/************************* End ../ext/misc/windirent.h ********************/
20471884
/************************* Begin ../ext/misc/memtrace.c ******************/
20481885
/*
20491886
** 2019-01-21
20501887
**
20511888
** The author disclaims copyright to this source code. In place of
@@ -8009,10 +7846,11 @@
80097846
** mode: Value of stat.st_mode for directory entry (an integer).
80107847
** mtime: Value of stat.st_mtime for directory entry (an integer).
80117848
** data: For a regular file, a blob containing the file data. For a
80127849
** symlink, a text value containing the text of the link. For a
80137850
** directory, NULL.
7851
+** level: Directory hierarchy level. Topmost is 1.
80147852
**
80157853
** If a non-NULL value is specified for the optional $dir parameter and
80167854
** $path is a relative path, then $path is interpreted relative to $dir.
80177855
** And the paths returned in the "name" column of the table are also
80187856
** relative to directory $dir.
@@ -8034,17 +7872,15 @@
80347872
#if !defined(_WIN32) && !defined(WIN32)
80357873
# include <unistd.h>
80367874
# include <dirent.h>
80377875
# include <utime.h>
80387876
# include <sys/time.h>
7877
+# define STRUCT_STAT struct stat
80397878
#else
8040
-# include "windows.h"
8041
-# include <io.h>
7879
+/* # include "windirent.h" */
80427880
# include <direct.h>
8043
-/* # include "test_windirent.h" */
8044
-# define dirent DIRENT
8045
-# define stat _stat
7881
+# define STRUCT_STAT struct _stat
80467882
# define chmod(path,mode) fileio_chmod(path,mode)
80477883
# define mkdir(path,mode) fileio_mkdir(path)
80487884
#endif
80497885
#include <time.h>
80507886
#include <errno.h>
@@ -8058,18 +7894,20 @@
80587894
#endif
80597895
80607896
/*
80617897
** Structure of the fsdir() table-valued function
80627898
*/
8063
- /* 0 1 2 3 4 5 */
8064
-#define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
7899
+ /* 0 1 2 3 4 5 6 */
7900
+#define FSDIR_SCHEMA "(name,mode,mtime,data,level,path HIDDEN,dir HIDDEN)"
7901
+
80657902
#define FSDIR_COLUMN_NAME 0 /* Name of the file */
80667903
#define FSDIR_COLUMN_MODE 1 /* Access mode */
80677904
#define FSDIR_COLUMN_MTIME 2 /* Last modification time */
80687905
#define FSDIR_COLUMN_DATA 3 /* File content */
8069
-#define FSDIR_COLUMN_PATH 4 /* Path to top of search */
8070
-#define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
7906
+#define FSDIR_COLUMN_LEVEL 4 /* Level. Topmost is 1 */
7907
+#define FSDIR_COLUMN_PATH 5 /* Path to top of search */
7908
+#define FSDIR_COLUMN_DIR 6 /* Path is relative to this directory */
80717909
80727910
/*
80737911
** UTF8 chmod() function for Windows
80747912
*/
80757913
#if defined(_WIN32) || defined(WIN32)
@@ -8231,11 +8069,11 @@
82318069
** buffer to UTC. This is necessary on Win32, where the runtime library
82328070
** appears to return these values as local times.
82338071
*/
82348072
static void statTimesToUtc(
82358073
const char *zPath,
8236
- struct stat *pStatBuf
8074
+ STRUCT_STAT *pStatBuf
82378075
){
82388076
HANDLE hFindFile;
82398077
WIN32_FIND_DATAW fd;
82408078
LPWSTR zUnicodeName;
82418079
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
@@ -8259,11 +8097,11 @@
82598097
** is required in order for the included time to be returned as UTC. On all
82608098
** other systems, this function simply calls stat().
82618099
*/
82628100
static int fileStat(
82638101
const char *zPath,
8264
- struct stat *pStatBuf
8102
+ STRUCT_STAT *pStatBuf
82658103
){
82668104
#if defined(_WIN32)
82678105
sqlite3_int64 sz = strlen(zPath);
82688106
wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
82698107
int rc;
@@ -8283,11 +8121,11 @@
82838121
** is required in order for the included time to be returned as UTC. On all
82848122
** other systems, this function simply calls lstat().
82858123
*/
82868124
static int fileLinkStat(
82878125
const char *zPath,
8288
- struct stat *pStatBuf
8126
+ STRUCT_STAT *pStatBuf
82898127
){
82908128
#if defined(_WIN32)
82918129
return fileStat(zPath, pStatBuf);
82928130
#else
82938131
return lstat(zPath, pStatBuf);
@@ -8316,11 +8154,11 @@
83168154
}else{
83178155
int nCopy = (int)strlen(zCopy);
83188156
int i = 1;
83198157
83208158
while( rc==SQLITE_OK ){
8321
- struct stat sStat;
8159
+ STRUCT_STAT sStat;
83228160
int rc2;
83238161
83248162
for(; zCopy[i]!='/' && i<nCopy; i++);
83258163
if( i==nCopy ) break;
83268164
zCopy[i] = '\0';
@@ -8366,11 +8204,11 @@
83668204
if( mkdir(zFile, mode) ){
83678205
/* The mkdir() call to create the directory failed. This might not
83688206
** be an error though - if there is already a directory at the same
83698207
** path and either the permissions already match or can be changed
83708208
** to do so using chmod(), it is not an error. */
8371
- struct stat sStat;
8209
+ STRUCT_STAT sStat;
83728210
if( errno!=EEXIST
83738211
|| 0!=fileStat(zFile, &sStat)
83748212
|| !S_ISDIR(sStat.st_mode)
83758213
|| ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
83768214
){
@@ -8562,17 +8400,18 @@
85628400
85638401
struct fsdir_cursor {
85648402
sqlite3_vtab_cursor base; /* Base class - must be first */
85658403
85668404
int nLvl; /* Number of entries in aLvl[] array */
8405
+ int mxLvl; /* Maximum level */
85678406
int iLvl; /* Index of current entry */
85688407
FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
85698408
85708409
const char *zBase;
85718410
int nBase;
85728411
8573
- struct stat sStat; /* Current lstat() results */
8412
+ STRUCT_STAT sStat; /* Current lstat() results */
85748413
char *zPath; /* Path to current entry */
85758414
sqlite3_int64 iRowid; /* Current rowid */
85768415
};
85778416
85788417
typedef struct fsdir_tab fsdir_tab;
@@ -8680,11 +8519,11 @@
86808519
static int fsdirNext(sqlite3_vtab_cursor *cur){
86818520
fsdir_cursor *pCur = (fsdir_cursor*)cur;
86828521
mode_t m = pCur->sStat.st_mode;
86838522
86848523
pCur->iRowid++;
8685
- if( S_ISDIR(m) ){
8524
+ if( S_ISDIR(m) && pCur->iLvl+3<pCur->mxLvl ){
86868525
/* Descend into this directory */
86878526
int iNew = pCur->iLvl + 1;
86888527
FsdirLevel *pLvl;
86898528
if( iNew>=pCur->nLvl ){
86908529
int nNew = iNew+1;
@@ -8788,11 +8627,15 @@
87888627
if( aBuf!=aStatic ) sqlite3_free(aBuf);
87898628
#endif
87908629
}else{
87918630
readFileContents(ctx, pCur->zPath);
87928631
}
8632
+ break;
87938633
}
8634
+ case FSDIR_COLUMN_LEVEL:
8635
+ sqlite3_result_int(ctx, pCur->iLvl+2);
8636
+ break;
87948637
case FSDIR_COLUMN_PATH:
87958638
default: {
87968639
/* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
87978640
** always return their values as NULL */
87988641
break;
@@ -8822,36 +8665,50 @@
88228665
}
88238666
88248667
/*
88258668
** xFilter callback.
88268669
**
8827
-** idxNum==1 PATH parameter only
8828
-** idxNum==2 Both PATH and DIR supplied
8670
+** idxNum bit Meaning
8671
+** 0x01 PATH=N
8672
+** 0x02 DIR=N
8673
+** 0x04 LEVEL<N
8674
+** 0x08 LEVEL<=N
88298675
*/
88308676
static int fsdirFilter(
88318677
sqlite3_vtab_cursor *cur,
88328678
int idxNum, const char *idxStr,
88338679
int argc, sqlite3_value **argv
88348680
){
88358681
const char *zDir = 0;
88368682
fsdir_cursor *pCur = (fsdir_cursor*)cur;
8683
+ int i;
88378684
(void)idxStr;
88388685
fsdirResetCursor(pCur);
88398686
88408687
if( idxNum==0 ){
88418688
fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
88428689
return SQLITE_ERROR;
88438690
}
88448691
8845
- assert( argc==idxNum && (argc==1 || argc==2) );
8692
+ assert( (idxNum & 0x01)!=0 && argc>0 );
88468693
zDir = (const char*)sqlite3_value_text(argv[0]);
88478694
if( zDir==0 ){
88488695
fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
88498696
return SQLITE_ERROR;
88508697
}
8851
- if( argc==2 ){
8852
- pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
8698
+ i = 1;
8699
+ if( (idxNum & 0x02)!=0 ){
8700
+ assert( argc>i );
8701
+ pCur->zBase = (const char*)sqlite3_value_text(argv[i++]);
8702
+ }
8703
+ if( (idxNum & 0x0c)!=0 ){
8704
+ assert( argc>i );
8705
+ pCur->mxLvl = sqlite3_value_int(argv[i++]);
8706
+ if( idxNum & 0x08 ) pCur->mxLvl++;
8707
+ if( pCur->mxLvl<=0 ) pCur->mxLvl = 1000000000;
8708
+ }else{
8709
+ pCur->mxLvl = 1000000000;
88538710
}
88548711
if( pCur->zBase ){
88558712
pCur->nBase = (int)strlen(pCur->zBase)+1;
88568713
pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
88578714
}else{
@@ -8876,48 +8733,75 @@
88768733
** plan.
88778734
**
88788735
** In this implementation idxNum is used to represent the
88798736
** query plan. idxStr is unused.
88808737
**
8881
-** The query plan is represented by values of idxNum:
8738
+** The query plan is represented by bits in idxNum:
88828739
**
8883
-** (1) The path value is supplied by argv[0]
8884
-** (2) Path is in argv[0] and dir is in argv[1]
8740
+** 0x01 The path value is supplied by argv[0]
8741
+** 0x02 dir is in argv[1]
8742
+** 0x04 maxdepth is in argv[1] or [2]
88858743
*/
88868744
static int fsdirBestIndex(
88878745
sqlite3_vtab *tab,
88888746
sqlite3_index_info *pIdxInfo
88898747
){
88908748
int i; /* Loop over constraints */
88918749
int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
88928750
int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
8751
+ int idxLevel = -1; /* Index in pIdxInfo->aConstraint of LEVEL< or <= */
8752
+ int idxLevelEQ = 0; /* 0x08 for LEVEL<= or LEVEL=. 0x04 for LEVEL< */
8753
+ int omitLevel = 0; /* omit the LEVEL constraint */
88938754
int seenPath = 0; /* True if an unusable PATH= constraint is seen */
88948755
int seenDir = 0; /* True if an unusable DIR= constraint is seen */
88958756
const struct sqlite3_index_constraint *pConstraint;
88968757
88978758
(void)tab;
88988759
pConstraint = pIdxInfo->aConstraint;
88998760
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8900
- if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
8901
- switch( pConstraint->iColumn ){
8902
- case FSDIR_COLUMN_PATH: {
8903
- if( pConstraint->usable ){
8904
- idxPath = i;
8905
- seenPath = 0;
8906
- }else if( idxPath<0 ){
8907
- seenPath = 1;
8908
- }
8909
- break;
8910
- }
8911
- case FSDIR_COLUMN_DIR: {
8912
- if( pConstraint->usable ){
8913
- idxDir = i;
8914
- seenDir = 0;
8915
- }else if( idxDir<0 ){
8916
- seenDir = 1;
8917
- }
8918
- break;
8761
+ if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
8762
+ switch( pConstraint->iColumn ){
8763
+ case FSDIR_COLUMN_PATH: {
8764
+ if( pConstraint->usable ){
8765
+ idxPath = i;
8766
+ seenPath = 0;
8767
+ }else if( idxPath<0 ){
8768
+ seenPath = 1;
8769
+ }
8770
+ break;
8771
+ }
8772
+ case FSDIR_COLUMN_DIR: {
8773
+ if( pConstraint->usable ){
8774
+ idxDir = i;
8775
+ seenDir = 0;
8776
+ }else if( idxDir<0 ){
8777
+ seenDir = 1;
8778
+ }
8779
+ break;
8780
+ }
8781
+ case FSDIR_COLUMN_LEVEL: {
8782
+ if( pConstraint->usable && idxLevel<0 ){
8783
+ idxLevel = i;
8784
+ idxLevelEQ = 0x08;
8785
+ omitLevel = 0;
8786
+ }
8787
+ break;
8788
+ }
8789
+ }
8790
+ }else
8791
+ if( pConstraint->iColumn==FSDIR_COLUMN_LEVEL
8792
+ && pConstraint->usable
8793
+ && idxLevel<0
8794
+ ){
8795
+ if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LE ){
8796
+ idxLevel = i;
8797
+ idxLevelEQ = 0x08;
8798
+ omitLevel = 1;
8799
+ }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT ){
8800
+ idxLevel = i;
8801
+ idxLevelEQ = 0x04;
8802
+ omitLevel = 1;
89198803
}
89208804
}
89218805
}
89228806
if( seenPath || seenDir ){
89238807
/* If input parameters are unusable, disallow this plan */
@@ -8930,18 +8814,24 @@
89308814
** number. Leave it unchanged. */
89318815
pIdxInfo->estimatedRows = 0x7fffffff;
89328816
}else{
89338817
pIdxInfo->aConstraintUsage[idxPath].omit = 1;
89348818
pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
8819
+ pIdxInfo->idxNum = 0x01;
8820
+ pIdxInfo->estimatedCost = 1.0e9;
8821
+ i = 2;
89358822
if( idxDir>=0 ){
89368823
pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8937
- pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
8938
- pIdxInfo->idxNum = 2;
8939
- pIdxInfo->estimatedCost = 10.0;
8940
- }else{
8941
- pIdxInfo->idxNum = 1;
8942
- pIdxInfo->estimatedCost = 100.0;
8824
+ pIdxInfo->aConstraintUsage[idxDir].argvIndex = i++;
8825
+ pIdxInfo->idxNum |= 0x02;
8826
+ pIdxInfo->estimatedCost /= 1.0e4;
8827
+ }
8828
+ if( idxLevel>=0 ){
8829
+ pIdxInfo->aConstraintUsage[idxLevel].omit = omitLevel;
8830
+ pIdxInfo->aConstraintUsage[idxLevel].argvIndex = i++;
8831
+ pIdxInfo->idxNum |= idxLevelEQ;
8832
+ pIdxInfo->estimatedCost /= 1.0e4;
89438833
}
89448834
}
89458835
89468836
return SQLITE_OK;
89478837
}
@@ -31828,11 +31718,11 @@
3182831718
const char *zUsage; /* Usage notes */
3182931719
} aCtrl[] = {
3183031720
{"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
3183131721
{"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
3183231722
/*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31833
- /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
31723
+ {"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "SIZE INT-ARRAY"},
3183431724
{"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
3183531725
{"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
3183631726
{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
3183731727
{"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
3183831728
{"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -32166,10 +32056,53 @@
3216632056
rc2 = booleanValue(azArg[2]);
3216732057
isOk = 3;
3216832058
}
3216932059
sqlite3_test_control(testctrl, &rc2);
3217032060
break;
32061
+ case SQLITE_TESTCTRL_BITVEC_TEST: {
32062
+ /* Examples:
32063
+ ** .testctrl bitvec_test 100 6,1 -- Show BITVEC constants
32064
+ ** .testctrl bitvec_test 1000 1,12,7,3 -- Simple test
32065
+ ** ---- --------
32066
+ ** size of Bitvec -----^ ^--- aOp array. 0 added at end.
32067
+ **
32068
+ ** See comments on sqlite3BitvecBuiltinTest() for more information
32069
+ ** about the aOp[] array.
32070
+ */
32071
+ int iSize;
32072
+ const char *zTestArg;
32073
+ int nOp;
32074
+ int ii, jj, x;
32075
+ int *aOp;
32076
+ if( nArg!=4 ){
32077
+ sqlite3_fprintf(stderr,
32078
+ "ERROR - should be: \".testctrl bitvec_test SIZE INT-ARRAY\"\n"
32079
+ );
32080
+ rc = 1;
32081
+ goto meta_command_exit;
32082
+ }
32083
+ isOk = 3;
32084
+ iSize = (int)integerValue(azArg[2]);
32085
+ zTestArg = azArg[3];
32086
+ nOp = (int)strlen(zTestArg)+1;
32087
+ aOp = malloc( sizeof(int)*(nOp+1) );
32088
+ shell_check_oom(aOp);
32089
+ memset(aOp, 0, sizeof(int)*(nOp+1) );
32090
+ for(ii = jj = x = 0; zTestArg[ii]!=0; ii++){
32091
+ if( IsDigit(zTestArg[ii]) ){
32092
+ x = x*10 + zTestArg[ii] - '0';
32093
+ }else{
32094
+ aOp[jj++] = x;
32095
+ x = 0;
32096
+ }
32097
+ }
32098
+ aOp[jj] = x;
32099
+ x = sqlite3_test_control(testctrl, iSize, aOp);
32100
+ sqlite3_fprintf(p->out, "result: %d\n", x);
32101
+ free(aOp);
32102
+ break;
32103
+ }
3217132104
case SQLITE_TESTCTRL_FAULT_INSTALL: {
3217232105
int kk;
3217332106
int bShowHelp = nArg<=2;
3217432107
isOk = 3;
3217532108
for(kk=2; kk<nArg; kk++){
3217632109
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1713,339 +1713,176 @@
1713 ** work here in the middle of this regular program.
1714 */
1715 #define SQLITE_EXTENSION_INIT1
1716 #define SQLITE_EXTENSION_INIT2(X) (void)(X)
1717
1718 #if defined(_WIN32) && defined(_MSC_VER)
1719 /************************* Begin test_windirent.h ******************/
1720 /*
1721 ** 2015 November 30
1722 **
1723 ** The author disclaims copyright to this source code. In place of
1724 ** a legal notice, here is a blessing:
1725 **
1726 ** May you do good and not evil.
1727 ** May you find forgiveness for yourself and forgive others.
1728 ** May you share freely, never taking more than you give.
1729 **
1730 *************************************************************************
1731 ** This file contains declarations for most of the opendir() family of
1732 ** POSIX functions on Win32 using the MSVCRT.
 
 
 
 
 
 
 
1733 */
1734
1735 #if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
1736 #define SQLITE_WINDIRENT_H
1737
1738 /*
1739 ** We need several data types from the Windows SDK header.
1740 */
1741
1742 #ifndef WIN32_LEAN_AND_MEAN
1743 #define WIN32_LEAN_AND_MEAN
1744 #endif
1745
1746 #include "windows.h"
1747
1748 /*
1749 ** We need several support functions from the SQLite core.
1750 */
1751
1752 /* #include "sqlite3.h" */
1753
1754 /*
1755 ** We need several things from the ANSI and MSVCRT headers.
1756 */
1757
1758 #include <stdio.h>
1759 #include <stdlib.h>
1760 #include <errno.h>
1761 #include <io.h>
1762 #include <limits.h>
1763 #include <sys/types.h>
1764 #include <sys/stat.h>
1765
1766 /*
1767 ** We may need several defines that should have been in "sys/stat.h".
1768 */
1769
1770 #ifndef S_ISREG
1771 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
1772 #endif
1773
1774 #ifndef S_ISDIR
1775 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
1776 #endif
1777
1778 #ifndef S_ISLNK
1779 #define S_ISLNK(mode) (0)
1780 #endif
1781
1782 /*
1783 ** We may need to provide the "mode_t" type.
1784 */
1785
1786 #ifndef MODE_T_DEFINED
1787 #define MODE_T_DEFINED
1788 typedef unsigned short mode_t;
1789 #endif
1790
1791 /*
1792 ** We may need to provide the "ino_t" type.
1793 */
1794
1795 #ifndef INO_T_DEFINED
1796 #define INO_T_DEFINED
1797 typedef unsigned short ino_t;
1798 #endif
1799
1800 /*
1801 ** We need to define "NAME_MAX" if it was not present in "limits.h".
1802 */
1803
1804 #ifndef NAME_MAX
1805 # ifdef FILENAME_MAX
1806 # define NAME_MAX (FILENAME_MAX)
1807 # else
1808 # define NAME_MAX (260)
1809 # endif
1810 # define DIRENT_NAME_MAX (NAME_MAX)
1811 #endif
1812
1813 /*
1814 ** We need to define "NULL_INTPTR_T" and "BAD_INTPTR_T".
1815 */
1816
1817 #ifndef NULL_INTPTR_T
1818 # define NULL_INTPTR_T ((intptr_t)(0))
1819 #endif
1820
1821 #ifndef BAD_INTPTR_T
1822 # define BAD_INTPTR_T ((intptr_t)(-1))
1823 #endif
1824
1825 /*
1826 ** We need to provide the necessary structures and related types.
1827 */
1828
1829 #ifndef DIRENT_DEFINED
1830 #define DIRENT_DEFINED
1831 typedef struct DIRENT DIRENT;
1832 typedef DIRENT *LPDIRENT;
1833 struct DIRENT {
1834 ino_t d_ino; /* Sequence number, do not use. */
1835 unsigned d_attributes; /* Win32 file attributes. */
1836 char d_name[NAME_MAX + 1]; /* Name within the directory. */
1837 };
1838 #endif
1839
1840 #ifndef DIR_DEFINED
1841 #define DIR_DEFINED
1842 typedef struct DIR DIR;
1843 typedef DIR *LPDIR;
1844 struct DIR {
1845 intptr_t d_handle; /* Value returned by "_findfirst". */
1846 DIRENT d_first; /* DIRENT constructed based on "_findfirst". */
1847 DIRENT d_next; /* DIRENT constructed based on "_findnext". */
1848 };
1849 #endif
1850
1851 /*
1852 ** Provide a macro, for use by the implementation, to determine if a
1853 ** particular directory entry should be skipped over when searching for
1854 ** the next directory entry that should be returned by the readdir().
1855 */
1856
1857 #ifndef is_filtered
1858 # define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1859 #endif
1860
1861 /*
1862 ** Provide the function prototype for the POSIX compatible getenv()
1863 ** function. This function is not thread-safe.
1864 */
1865
1866 extern const char *windirent_getenv(const char *name);
1867
1868 /*
1869 ** Finally, we can provide the function prototypes for the opendir(),
1870 ** readdir(), and closedir() POSIX functions.
1871 */
1872
1873 extern LPDIR opendir(const char *dirname);
1874 extern LPDIRENT readdir(LPDIR dirp);
1875 extern INT closedir(LPDIR dirp);
1876
1877 #endif /* defined(WIN32) && defined(_MSC_VER) */
1878
1879 /************************* End test_windirent.h ********************/
1880 /************************* Begin test_windirent.c ******************/
1881 /*
1882 ** 2015 November 30
1883 **
1884 ** The author disclaims copyright to this source code. In place of
1885 ** a legal notice, here is a blessing:
1886 **
1887 ** May you do good and not evil.
1888 ** May you find forgiveness for yourself and forgive others.
1889 ** May you share freely, never taking more than you give.
1890 **
1891 *************************************************************************
1892 ** This file contains code to implement most of the opendir() family of
1893 ** POSIX functions on Win32 using the MSVCRT.
1894 */
1895
1896 #if defined(_WIN32) && defined(_MSC_VER)
1897 /* #include "test_windirent.h" */
1898
1899 /*
1900 ** Implementation of the POSIX getenv() function using the Win32 API.
1901 ** This function is not thread-safe.
1902 */
1903 const char *windirent_getenv(
1904 const char *name
1905 ){
1906 static char value[32768]; /* Maximum length, per MSDN */
1907 DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
1908 DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
1909
1910 memset(value, 0, sizeof(value));
1911 dwRet = GetEnvironmentVariableA(name, value, dwSize);
1912 if( dwRet==0 || dwRet>dwSize ){
1913 /*
1914 ** The function call to GetEnvironmentVariableA() failed -OR-
1915 ** the buffer is not large enough. Either way, return NULL.
1916 */
1917 return 0;
1918 }else{
1919 /*
1920 ** The function call to GetEnvironmentVariableA() succeeded
1921 ** -AND- the buffer contains the entire value.
1922 */
1923 return value;
1924 }
1925 }
1926
1927 /*
1928 ** Implementation of the POSIX opendir() function using the MSVCRT.
1929 */
1930 LPDIR opendir(
1931 const char *dirname /* Directory name, UTF8 encoding */
1932 ){
1933 struct _wfinddata_t data;
1934 LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
1935 SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
1936 wchar_t *b1;
1937 sqlite3_int64 sz;
1938
1939 if( dirp==NULL ) return NULL;
1940 memset(dirp, 0, sizeof(DIR));
1941
1942 /* TODO: Remove this if Unix-style root paths are not used. */
1943 if( sqlite3_stricmp(dirname, "/")==0 ){
1944 dirname = windirent_getenv("SystemDrive");
1945 }
1946
1947 memset(&data, 0, sizeof(data));
1948 sz = strlen(dirname);
1949 b1 = sqlite3_malloc64( (sz+3)*sizeof(b1[0]) );
1950 if( b1==0 ){
1951 closedir(dirp);
1952 return NULL;
1953 }
1954 sz = MultiByteToWideChar(CP_UTF8, 0, dirname, sz, b1, sz);
1955 b1[sz++] = '\\';
1956 b1[sz++] = '*';
1957 b1[sz] = 0;
1958 if( sz+1>(sqlite3_int64)namesize ){
1959 closedir(dirp);
1960 sqlite3_free(b1);
1961 return NULL;
1962 }
1963 memcpy(data.name, b1, (sz+1)*sizeof(b1[0]));
1964 sqlite3_free(b1);
1965 dirp->d_handle = _wfindfirst(data.name, &data);
1966
1967 if( dirp->d_handle==BAD_INTPTR_T ){
1968 closedir(dirp);
1969 return NULL;
1970 }
1971
1972 /* TODO: Remove this block to allow hidden and/or system files. */
1973 if( is_filtered(data) ){
1974 next:
1975
1976 memset(&data, 0, sizeof(data));
1977 if( _wfindnext(dirp->d_handle, &data)==-1 ){
1978 closedir(dirp);
1979 return NULL;
1980 }
1981
1982 /* TODO: Remove this block to allow hidden and/or system files. */
1983 if( is_filtered(data) ) goto next;
1984 }
1985
1986 dirp->d_first.d_attributes = data.attrib;
1987 WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1988 dirp->d_first.d_name, DIRENT_NAME_MAX, 0, 0);
1989 return dirp;
1990 }
1991
1992 /*
1993 ** Implementation of the POSIX readdir() function using the MSVCRT.
1994 */
1995 LPDIRENT readdir(
1996 LPDIR dirp
1997 ){
1998 struct _wfinddata_t data;
1999
2000 if( dirp==NULL ) return NULL;
2001
2002 if( dirp->d_first.d_ino==0 ){
2003 dirp->d_first.d_ino++;
2004 dirp->d_next.d_ino++;
2005
2006 return &dirp->d_first;
2007 }
2008
2009 next:
2010
2011 memset(&data, 0, sizeof(data));
2012 if( _wfindnext(dirp->d_handle, &data)==-1 ) return NULL;
2013
2014 /* TODO: Remove this block to allow hidden and/or system files. */
2015 if( is_filtered(data) ) goto next;
2016
2017 dirp->d_next.d_ino++;
2018 dirp->d_next.d_attributes = data.attrib;
2019 WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
2020 dirp->d_next.d_name, DIRENT_NAME_MAX, 0, 0);
2021 return &dirp->d_next;
2022 }
2023
2024 /*
2025 ** Implementation of the POSIX closedir() function using the MSVCRT.
2026 */
2027 INT closedir(
2028 LPDIR dirp
2029 ){
2030 INT result = 0;
2031
2032 if( dirp==NULL ) return EINVAL;
2033
2034 if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
2035 result = _findclose(dirp->d_handle);
2036 }
2037
2038 sqlite3_free(dirp);
2039 return result;
2040 }
2041
2042 #endif /* defined(WIN32) && defined(_MSC_VER) */
2043
2044 /************************* End test_windirent.c ********************/
2045 #define dirent DIRENT
2046 #endif
2047 /************************* Begin ../ext/misc/memtrace.c ******************/
2048 /*
2049 ** 2019-01-21
2050 **
2051 ** The author disclaims copyright to this source code. In place of
@@ -8009,10 +7846,11 @@
8009 ** mode: Value of stat.st_mode for directory entry (an integer).
8010 ** mtime: Value of stat.st_mtime for directory entry (an integer).
8011 ** data: For a regular file, a blob containing the file data. For a
8012 ** symlink, a text value containing the text of the link. For a
8013 ** directory, NULL.
 
8014 **
8015 ** If a non-NULL value is specified for the optional $dir parameter and
8016 ** $path is a relative path, then $path is interpreted relative to $dir.
8017 ** And the paths returned in the "name" column of the table are also
8018 ** relative to directory $dir.
@@ -8034,17 +7872,15 @@
8034 #if !defined(_WIN32) && !defined(WIN32)
8035 # include <unistd.h>
8036 # include <dirent.h>
8037 # include <utime.h>
8038 # include <sys/time.h>
 
8039 #else
8040 # include "windows.h"
8041 # include <io.h>
8042 # include <direct.h>
8043 /* # include "test_windirent.h" */
8044 # define dirent DIRENT
8045 # define stat _stat
8046 # define chmod(path,mode) fileio_chmod(path,mode)
8047 # define mkdir(path,mode) fileio_mkdir(path)
8048 #endif
8049 #include <time.h>
8050 #include <errno.h>
@@ -8058,18 +7894,20 @@
8058 #endif
8059
8060 /*
8061 ** Structure of the fsdir() table-valued function
8062 */
8063 /* 0 1 2 3 4 5 */
8064 #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
 
8065 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
8066 #define FSDIR_COLUMN_MODE 1 /* Access mode */
8067 #define FSDIR_COLUMN_MTIME 2 /* Last modification time */
8068 #define FSDIR_COLUMN_DATA 3 /* File content */
8069 #define FSDIR_COLUMN_PATH 4 /* Path to top of search */
8070 #define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
 
8071
8072 /*
8073 ** UTF8 chmod() function for Windows
8074 */
8075 #if defined(_WIN32) || defined(WIN32)
@@ -8231,11 +8069,11 @@
8231 ** buffer to UTC. This is necessary on Win32, where the runtime library
8232 ** appears to return these values as local times.
8233 */
8234 static void statTimesToUtc(
8235 const char *zPath,
8236 struct stat *pStatBuf
8237 ){
8238 HANDLE hFindFile;
8239 WIN32_FIND_DATAW fd;
8240 LPWSTR zUnicodeName;
8241 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
@@ -8259,11 +8097,11 @@
8259 ** is required in order for the included time to be returned as UTC. On all
8260 ** other systems, this function simply calls stat().
8261 */
8262 static int fileStat(
8263 const char *zPath,
8264 struct stat *pStatBuf
8265 ){
8266 #if defined(_WIN32)
8267 sqlite3_int64 sz = strlen(zPath);
8268 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
8269 int rc;
@@ -8283,11 +8121,11 @@
8283 ** is required in order for the included time to be returned as UTC. On all
8284 ** other systems, this function simply calls lstat().
8285 */
8286 static int fileLinkStat(
8287 const char *zPath,
8288 struct stat *pStatBuf
8289 ){
8290 #if defined(_WIN32)
8291 return fileStat(zPath, pStatBuf);
8292 #else
8293 return lstat(zPath, pStatBuf);
@@ -8316,11 +8154,11 @@
8316 }else{
8317 int nCopy = (int)strlen(zCopy);
8318 int i = 1;
8319
8320 while( rc==SQLITE_OK ){
8321 struct stat sStat;
8322 int rc2;
8323
8324 for(; zCopy[i]!='/' && i<nCopy; i++);
8325 if( i==nCopy ) break;
8326 zCopy[i] = '\0';
@@ -8366,11 +8204,11 @@
8366 if( mkdir(zFile, mode) ){
8367 /* The mkdir() call to create the directory failed. This might not
8368 ** be an error though - if there is already a directory at the same
8369 ** path and either the permissions already match or can be changed
8370 ** to do so using chmod(), it is not an error. */
8371 struct stat sStat;
8372 if( errno!=EEXIST
8373 || 0!=fileStat(zFile, &sStat)
8374 || !S_ISDIR(sStat.st_mode)
8375 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
8376 ){
@@ -8562,17 +8400,18 @@
8562
8563 struct fsdir_cursor {
8564 sqlite3_vtab_cursor base; /* Base class - must be first */
8565
8566 int nLvl; /* Number of entries in aLvl[] array */
 
8567 int iLvl; /* Index of current entry */
8568 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
8569
8570 const char *zBase;
8571 int nBase;
8572
8573 struct stat sStat; /* Current lstat() results */
8574 char *zPath; /* Path to current entry */
8575 sqlite3_int64 iRowid; /* Current rowid */
8576 };
8577
8578 typedef struct fsdir_tab fsdir_tab;
@@ -8680,11 +8519,11 @@
8680 static int fsdirNext(sqlite3_vtab_cursor *cur){
8681 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8682 mode_t m = pCur->sStat.st_mode;
8683
8684 pCur->iRowid++;
8685 if( S_ISDIR(m) ){
8686 /* Descend into this directory */
8687 int iNew = pCur->iLvl + 1;
8688 FsdirLevel *pLvl;
8689 if( iNew>=pCur->nLvl ){
8690 int nNew = iNew+1;
@@ -8788,11 +8627,15 @@
8788 if( aBuf!=aStatic ) sqlite3_free(aBuf);
8789 #endif
8790 }else{
8791 readFileContents(ctx, pCur->zPath);
8792 }
 
8793 }
 
 
 
8794 case FSDIR_COLUMN_PATH:
8795 default: {
8796 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
8797 ** always return their values as NULL */
8798 break;
@@ -8822,36 +8665,50 @@
8822 }
8823
8824 /*
8825 ** xFilter callback.
8826 **
8827 ** idxNum==1 PATH parameter only
8828 ** idxNum==2 Both PATH and DIR supplied
 
 
 
8829 */
8830 static int fsdirFilter(
8831 sqlite3_vtab_cursor *cur,
8832 int idxNum, const char *idxStr,
8833 int argc, sqlite3_value **argv
8834 ){
8835 const char *zDir = 0;
8836 fsdir_cursor *pCur = (fsdir_cursor*)cur;
 
8837 (void)idxStr;
8838 fsdirResetCursor(pCur);
8839
8840 if( idxNum==0 ){
8841 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
8842 return SQLITE_ERROR;
8843 }
8844
8845 assert( argc==idxNum && (argc==1 || argc==2) );
8846 zDir = (const char*)sqlite3_value_text(argv[0]);
8847 if( zDir==0 ){
8848 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
8849 return SQLITE_ERROR;
8850 }
8851 if( argc==2 ){
8852 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
 
 
 
 
 
 
 
 
 
 
8853 }
8854 if( pCur->zBase ){
8855 pCur->nBase = (int)strlen(pCur->zBase)+1;
8856 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
8857 }else{
@@ -8876,48 +8733,75 @@
8876 ** plan.
8877 **
8878 ** In this implementation idxNum is used to represent the
8879 ** query plan. idxStr is unused.
8880 **
8881 ** The query plan is represented by values of idxNum:
8882 **
8883 ** (1) The path value is supplied by argv[0]
8884 ** (2) Path is in argv[0] and dir is in argv[1]
 
8885 */
8886 static int fsdirBestIndex(
8887 sqlite3_vtab *tab,
8888 sqlite3_index_info *pIdxInfo
8889 ){
8890 int i; /* Loop over constraints */
8891 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
8892 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
 
 
 
8893 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
8894 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
8895 const struct sqlite3_index_constraint *pConstraint;
8896
8897 (void)tab;
8898 pConstraint = pIdxInfo->aConstraint;
8899 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8900 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
8901 switch( pConstraint->iColumn ){
8902 case FSDIR_COLUMN_PATH: {
8903 if( pConstraint->usable ){
8904 idxPath = i;
8905 seenPath = 0;
8906 }else if( idxPath<0 ){
8907 seenPath = 1;
8908 }
8909 break;
8910 }
8911 case FSDIR_COLUMN_DIR: {
8912 if( pConstraint->usable ){
8913 idxDir = i;
8914 seenDir = 0;
8915 }else if( idxDir<0 ){
8916 seenDir = 1;
8917 }
8918 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8919 }
8920 }
8921 }
8922 if( seenPath || seenDir ){
8923 /* If input parameters are unusable, disallow this plan */
@@ -8930,18 +8814,24 @@
8930 ** number. Leave it unchanged. */
8931 pIdxInfo->estimatedRows = 0x7fffffff;
8932 }else{
8933 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
8934 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
 
 
 
8935 if( idxDir>=0 ){
8936 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8937 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
8938 pIdxInfo->idxNum = 2;
8939 pIdxInfo->estimatedCost = 10.0;
8940 }else{
8941 pIdxInfo->idxNum = 1;
8942 pIdxInfo->estimatedCost = 100.0;
 
 
 
8943 }
8944 }
8945
8946 return SQLITE_OK;
8947 }
@@ -31828,11 +31718,11 @@
31828 const char *zUsage; /* Usage notes */
31829 } aCtrl[] = {
31830 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
31831 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
31832 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31833 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
31834 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
31835 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
31836 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
31837 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
31838 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -32166,10 +32056,53 @@
32166 rc2 = booleanValue(azArg[2]);
32167 isOk = 3;
32168 }
32169 sqlite3_test_control(testctrl, &rc2);
32170 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32171 case SQLITE_TESTCTRL_FAULT_INSTALL: {
32172 int kk;
32173 int bShowHelp = nArg<=2;
32174 isOk = 3;
32175 for(kk=2; kk<nArg; kk++){
32176
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1713,339 +1713,176 @@
1713 ** work here in the middle of this regular program.
1714 */
1715 #define SQLITE_EXTENSION_INIT1
1716 #define SQLITE_EXTENSION_INIT2(X) (void)(X)
1717
1718 /************************* Begin ../ext/misc/windirent.h ******************/
 
1719 /*
1720 ** 2025-06-05
1721 **
1722 ** The author disclaims copyright to this source code. In place of
1723 ** a legal notice, here is a blessing:
1724 **
1725 ** May you do good and not evil.
1726 ** May you find forgiveness for yourself and forgive others.
1727 ** May you share freely, never taking more than you give.
1728 **
1729 *************************************************************************
1730 **
1731 ** An implementation of opendir(), readdir(), and closedir() for Windows,
1732 ** based on the FindFirstFile(), FindNextFile(), and FindClose() APIs
1733 ** of Win32.
1734 **
1735 ** #include this file inside any C-code module that needs to use
1736 ** opendir()/readdir()/closedir(). This file is a no-op on non-Windows
1737 ** machines. On Windows, static functions are defined that implement
1738 ** those standard interfaces.
1739 */
 
1740 #if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
1741 #define SQLITE_WINDIRENT_H
1742
 
 
 
 
1743 #ifndef WIN32_LEAN_AND_MEAN
1744 #define WIN32_LEAN_AND_MEAN
1745 #endif
1746 #include <windows.h>
1747 #include <io.h>
 
 
 
 
 
 
 
 
 
 
 
1748 #include <stdio.h>
1749 #include <stdlib.h>
1750 #include <errno.h>
 
1751 #include <limits.h>
1752 #include <sys/types.h>
1753 #include <sys/stat.h>
1754 #include <string.h>
1755 #ifndef FILENAME_MAX
1756 # define FILENAME_MAX (260)
1757 #endif
 
1758 #ifndef S_ISREG
1759 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
1760 #endif
 
1761 #ifndef S_ISDIR
1762 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1763 #endif
 
1764 #ifndef S_ISLNK
1765 #define S_ISLNK(m) (0)
1766 #endif
1767 typedef unsigned short mode_t;
1768
1769 /* The dirent object for Windows is abbreviated. The only field really
1770 ** usable by applications is d_name[].
1771 */
1772 struct dirent {
1773 int d_ino; /* Inode number (synthesized) */
1774 unsigned d_attributes; /* File attributes */
1775 char d_name[FILENAME_MAX]; /* Null-terminated filename */
1776 };
1777
1778 /* The internals of DIR are opaque according to standards. So it
1779 ** does not matter what we put here. */
1780 typedef struct DIR DIR;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1781 struct DIR {
1782 intptr_t d_handle; /* Handle for findfirst()/findnext() */
1783 struct dirent cur; /* Current entry */
1784 };
1785
1786 /* Ignore hidden and system files */
1787 #define WindowsFileToIgnore(a) \
1788 ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1789
1790 /*
1791 ** Close a previously opened directory
1792 */
1793 static int closedir(DIR *pDir){
1794 int rc = 0;
1795 if( pDir==0 ){
1796 return EINVAL;
1797 }
1798 if( pDir->d_handle!=0 && pDir->d_handle!=(-1) ){
1799 rc = _findclose(pDir->d_handle);
1800 }
1801 sqlite3_free(pDir);
1802 return rc;
1803 }
1804
1805 /*
1806 ** Open a new directory. The directory name should be UTF-8 encoded.
1807 ** appropriate translations happen automatically.
1808 */
1809 static DIR *opendir(const char *zDirName){
1810 DIR *pDir;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1811 wchar_t *b1;
1812 sqlite3_int64 sz;
1813 struct _wfinddata_t data;
1814
1815 pDir = sqlite3_malloc64( sizeof(DIR) );
1816 if( pDir==0 ) return 0;
1817 memset(pDir, 0, sizeof(DIR));
 
 
 
 
1818 memset(&data, 0, sizeof(data));
1819 sz = strlen(zDirName);
1820 b1 = sqlite3_malloc64( (sz+3)*sizeof(b1[0]) );
1821 if( b1==0 ){
1822 closedir(pDir);
1823 return NULL;
1824 }
1825 sz = MultiByteToWideChar(CP_UTF8, 0, zDirName, sz, b1, sz);
1826 b1[sz++] = '\\';
1827 b1[sz++] = '*';
1828 b1[sz] = 0;
1829 if( sz+1>sizeof(data.name)/sizeof(data.name[0]) ){
1830 closedir(pDir);
1831 sqlite3_free(b1);
1832 return NULL;
1833 }
1834 memcpy(data.name, b1, (sz+1)*sizeof(b1[0]));
1835 sqlite3_free(b1);
1836 pDir->d_handle = _wfindfirst(data.name, &data);
1837 if( pDir->d_handle<0 ){
1838 closedir(pDir);
1839 return NULL;
1840 }
1841 while( WindowsFileToIgnore(data) ){
1842 memset(&data, 0, sizeof(data));
1843 if( _wfindnext(pDir->d_handle, &data)==-1 ){
1844 closedir(pDir);
1845 return NULL;
1846 }
1847 }
1848 pDir->cur.d_ino = 0;
1849 pDir->cur.d_attributes = data.attrib;
1850 WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1851 pDir->cur.d_name, FILENAME_MAX, 0, 0);
1852 return pDir;
1853 }
1854
1855 /*
1856 ** Read the next entry from a directory.
1857 **
1858 ** The returned struct-dirent object is managed by DIR. It is only
1859 ** valid until the next readdir() or closedir() call. Only the
1860 ** d_name[] field is meaningful. The d_name[] value has been
1861 ** translated into UTF8.
1862 */
1863 static struct dirent *readdir(DIR *pDir){
1864 struct _wfinddata_t data;
1865 if( pDir==0 ) return 0;
1866 if( (pDir->cur.d_ino++)==0 ){
1867 return &pDir->cur;
1868 }
1869 do{
1870 memset(&data, 0, sizeof(data));
1871 if( _wfindnext(pDir->d_handle, &data)==-1 ){
1872 return NULL;
1873 }
1874 }while( WindowsFileToIgnore(data) );
1875 pDir->cur.d_attributes = data.attrib;
1876 WideCharToMultiByte(CP_UTF8, 0, data.name, -1,
1877 pDir->cur.d_name, FILENAME_MAX, 0, 0);
1878 return &pDir->cur;
1879 }
1880
1881 #endif /* defined(_WIN32) && defined(_MSC_VER) */
1882
1883 /************************* End ../ext/misc/windirent.h ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1884 /************************* Begin ../ext/misc/memtrace.c ******************/
1885 /*
1886 ** 2019-01-21
1887 **
1888 ** The author disclaims copyright to this source code. In place of
@@ -8009,10 +7846,11 @@
7846 ** mode: Value of stat.st_mode for directory entry (an integer).
7847 ** mtime: Value of stat.st_mtime for directory entry (an integer).
7848 ** data: For a regular file, a blob containing the file data. For a
7849 ** symlink, a text value containing the text of the link. For a
7850 ** directory, NULL.
7851 ** level: Directory hierarchy level. Topmost is 1.
7852 **
7853 ** If a non-NULL value is specified for the optional $dir parameter and
7854 ** $path is a relative path, then $path is interpreted relative to $dir.
7855 ** And the paths returned in the "name" column of the table are also
7856 ** relative to directory $dir.
@@ -8034,17 +7872,15 @@
7872 #if !defined(_WIN32) && !defined(WIN32)
7873 # include <unistd.h>
7874 # include <dirent.h>
7875 # include <utime.h>
7876 # include <sys/time.h>
7877 # define STRUCT_STAT struct stat
7878 #else
7879 /* # include "windirent.h" */
 
7880 # include <direct.h>
7881 # define STRUCT_STAT struct _stat
 
 
7882 # define chmod(path,mode) fileio_chmod(path,mode)
7883 # define mkdir(path,mode) fileio_mkdir(path)
7884 #endif
7885 #include <time.h>
7886 #include <errno.h>
@@ -8058,18 +7894,20 @@
7894 #endif
7895
7896 /*
7897 ** Structure of the fsdir() table-valued function
7898 */
7899 /* 0 1 2 3 4 5 6 */
7900 #define FSDIR_SCHEMA "(name,mode,mtime,data,level,path HIDDEN,dir HIDDEN)"
7901
7902 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
7903 #define FSDIR_COLUMN_MODE 1 /* Access mode */
7904 #define FSDIR_COLUMN_MTIME 2 /* Last modification time */
7905 #define FSDIR_COLUMN_DATA 3 /* File content */
7906 #define FSDIR_COLUMN_LEVEL 4 /* Level. Topmost is 1 */
7907 #define FSDIR_COLUMN_PATH 5 /* Path to top of search */
7908 #define FSDIR_COLUMN_DIR 6 /* Path is relative to this directory */
7909
7910 /*
7911 ** UTF8 chmod() function for Windows
7912 */
7913 #if defined(_WIN32) || defined(WIN32)
@@ -8231,11 +8069,11 @@
8069 ** buffer to UTC. This is necessary on Win32, where the runtime library
8070 ** appears to return these values as local times.
8071 */
8072 static void statTimesToUtc(
8073 const char *zPath,
8074 STRUCT_STAT *pStatBuf
8075 ){
8076 HANDLE hFindFile;
8077 WIN32_FIND_DATAW fd;
8078 LPWSTR zUnicodeName;
8079 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
@@ -8259,11 +8097,11 @@
8097 ** is required in order for the included time to be returned as UTC. On all
8098 ** other systems, this function simply calls stat().
8099 */
8100 static int fileStat(
8101 const char *zPath,
8102 STRUCT_STAT *pStatBuf
8103 ){
8104 #if defined(_WIN32)
8105 sqlite3_int64 sz = strlen(zPath);
8106 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
8107 int rc;
@@ -8283,11 +8121,11 @@
8121 ** is required in order for the included time to be returned as UTC. On all
8122 ** other systems, this function simply calls lstat().
8123 */
8124 static int fileLinkStat(
8125 const char *zPath,
8126 STRUCT_STAT *pStatBuf
8127 ){
8128 #if defined(_WIN32)
8129 return fileStat(zPath, pStatBuf);
8130 #else
8131 return lstat(zPath, pStatBuf);
@@ -8316,11 +8154,11 @@
8154 }else{
8155 int nCopy = (int)strlen(zCopy);
8156 int i = 1;
8157
8158 while( rc==SQLITE_OK ){
8159 STRUCT_STAT sStat;
8160 int rc2;
8161
8162 for(; zCopy[i]!='/' && i<nCopy; i++);
8163 if( i==nCopy ) break;
8164 zCopy[i] = '\0';
@@ -8366,11 +8204,11 @@
8204 if( mkdir(zFile, mode) ){
8205 /* The mkdir() call to create the directory failed. This might not
8206 ** be an error though - if there is already a directory at the same
8207 ** path and either the permissions already match or can be changed
8208 ** to do so using chmod(), it is not an error. */
8209 STRUCT_STAT sStat;
8210 if( errno!=EEXIST
8211 || 0!=fileStat(zFile, &sStat)
8212 || !S_ISDIR(sStat.st_mode)
8213 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
8214 ){
@@ -8562,17 +8400,18 @@
8400
8401 struct fsdir_cursor {
8402 sqlite3_vtab_cursor base; /* Base class - must be first */
8403
8404 int nLvl; /* Number of entries in aLvl[] array */
8405 int mxLvl; /* Maximum level */
8406 int iLvl; /* Index of current entry */
8407 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
8408
8409 const char *zBase;
8410 int nBase;
8411
8412 STRUCT_STAT sStat; /* Current lstat() results */
8413 char *zPath; /* Path to current entry */
8414 sqlite3_int64 iRowid; /* Current rowid */
8415 };
8416
8417 typedef struct fsdir_tab fsdir_tab;
@@ -8680,11 +8519,11 @@
8519 static int fsdirNext(sqlite3_vtab_cursor *cur){
8520 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8521 mode_t m = pCur->sStat.st_mode;
8522
8523 pCur->iRowid++;
8524 if( S_ISDIR(m) && pCur->iLvl+3<pCur->mxLvl ){
8525 /* Descend into this directory */
8526 int iNew = pCur->iLvl + 1;
8527 FsdirLevel *pLvl;
8528 if( iNew>=pCur->nLvl ){
8529 int nNew = iNew+1;
@@ -8788,11 +8627,15 @@
8627 if( aBuf!=aStatic ) sqlite3_free(aBuf);
8628 #endif
8629 }else{
8630 readFileContents(ctx, pCur->zPath);
8631 }
8632 break;
8633 }
8634 case FSDIR_COLUMN_LEVEL:
8635 sqlite3_result_int(ctx, pCur->iLvl+2);
8636 break;
8637 case FSDIR_COLUMN_PATH:
8638 default: {
8639 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
8640 ** always return their values as NULL */
8641 break;
@@ -8822,36 +8665,50 @@
8665 }
8666
8667 /*
8668 ** xFilter callback.
8669 **
8670 ** idxNum bit Meaning
8671 ** 0x01 PATH=N
8672 ** 0x02 DIR=N
8673 ** 0x04 LEVEL<N
8674 ** 0x08 LEVEL<=N
8675 */
8676 static int fsdirFilter(
8677 sqlite3_vtab_cursor *cur,
8678 int idxNum, const char *idxStr,
8679 int argc, sqlite3_value **argv
8680 ){
8681 const char *zDir = 0;
8682 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8683 int i;
8684 (void)idxStr;
8685 fsdirResetCursor(pCur);
8686
8687 if( idxNum==0 ){
8688 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
8689 return SQLITE_ERROR;
8690 }
8691
8692 assert( (idxNum & 0x01)!=0 && argc>0 );
8693 zDir = (const char*)sqlite3_value_text(argv[0]);
8694 if( zDir==0 ){
8695 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
8696 return SQLITE_ERROR;
8697 }
8698 i = 1;
8699 if( (idxNum & 0x02)!=0 ){
8700 assert( argc>i );
8701 pCur->zBase = (const char*)sqlite3_value_text(argv[i++]);
8702 }
8703 if( (idxNum & 0x0c)!=0 ){
8704 assert( argc>i );
8705 pCur->mxLvl = sqlite3_value_int(argv[i++]);
8706 if( idxNum & 0x08 ) pCur->mxLvl++;
8707 if( pCur->mxLvl<=0 ) pCur->mxLvl = 1000000000;
8708 }else{
8709 pCur->mxLvl = 1000000000;
8710 }
8711 if( pCur->zBase ){
8712 pCur->nBase = (int)strlen(pCur->zBase)+1;
8713 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
8714 }else{
@@ -8876,48 +8733,75 @@
8733 ** plan.
8734 **
8735 ** In this implementation idxNum is used to represent the
8736 ** query plan. idxStr is unused.
8737 **
8738 ** The query plan is represented by bits in idxNum:
8739 **
8740 ** 0x01 The path value is supplied by argv[0]
8741 ** 0x02 dir is in argv[1]
8742 ** 0x04 maxdepth is in argv[1] or [2]
8743 */
8744 static int fsdirBestIndex(
8745 sqlite3_vtab *tab,
8746 sqlite3_index_info *pIdxInfo
8747 ){
8748 int i; /* Loop over constraints */
8749 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
8750 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
8751 int idxLevel = -1; /* Index in pIdxInfo->aConstraint of LEVEL< or <= */
8752 int idxLevelEQ = 0; /* 0x08 for LEVEL<= or LEVEL=. 0x04 for LEVEL< */
8753 int omitLevel = 0; /* omit the LEVEL constraint */
8754 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
8755 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
8756 const struct sqlite3_index_constraint *pConstraint;
8757
8758 (void)tab;
8759 pConstraint = pIdxInfo->aConstraint;
8760 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8761 if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
8762 switch( pConstraint->iColumn ){
8763 case FSDIR_COLUMN_PATH: {
8764 if( pConstraint->usable ){
8765 idxPath = i;
8766 seenPath = 0;
8767 }else if( idxPath<0 ){
8768 seenPath = 1;
8769 }
8770 break;
8771 }
8772 case FSDIR_COLUMN_DIR: {
8773 if( pConstraint->usable ){
8774 idxDir = i;
8775 seenDir = 0;
8776 }else if( idxDir<0 ){
8777 seenDir = 1;
8778 }
8779 break;
8780 }
8781 case FSDIR_COLUMN_LEVEL: {
8782 if( pConstraint->usable && idxLevel<0 ){
8783 idxLevel = i;
8784 idxLevelEQ = 0x08;
8785 omitLevel = 0;
8786 }
8787 break;
8788 }
8789 }
8790 }else
8791 if( pConstraint->iColumn==FSDIR_COLUMN_LEVEL
8792 && pConstraint->usable
8793 && idxLevel<0
8794 ){
8795 if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LE ){
8796 idxLevel = i;
8797 idxLevelEQ = 0x08;
8798 omitLevel = 1;
8799 }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT ){
8800 idxLevel = i;
8801 idxLevelEQ = 0x04;
8802 omitLevel = 1;
8803 }
8804 }
8805 }
8806 if( seenPath || seenDir ){
8807 /* If input parameters are unusable, disallow this plan */
@@ -8930,18 +8814,24 @@
8814 ** number. Leave it unchanged. */
8815 pIdxInfo->estimatedRows = 0x7fffffff;
8816 }else{
8817 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
8818 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
8819 pIdxInfo->idxNum = 0x01;
8820 pIdxInfo->estimatedCost = 1.0e9;
8821 i = 2;
8822 if( idxDir>=0 ){
8823 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8824 pIdxInfo->aConstraintUsage[idxDir].argvIndex = i++;
8825 pIdxInfo->idxNum |= 0x02;
8826 pIdxInfo->estimatedCost /= 1.0e4;
8827 }
8828 if( idxLevel>=0 ){
8829 pIdxInfo->aConstraintUsage[idxLevel].omit = omitLevel;
8830 pIdxInfo->aConstraintUsage[idxLevel].argvIndex = i++;
8831 pIdxInfo->idxNum |= idxLevelEQ;
8832 pIdxInfo->estimatedCost /= 1.0e4;
8833 }
8834 }
8835
8836 return SQLITE_OK;
8837 }
@@ -31828,11 +31718,11 @@
31718 const char *zUsage; /* Usage notes */
31719 } aCtrl[] = {
31720 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
31721 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
31722 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31723 {"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "SIZE INT-ARRAY"},
31724 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
31725 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
31726 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
31727 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
31728 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -32166,10 +32056,53 @@
32056 rc2 = booleanValue(azArg[2]);
32057 isOk = 3;
32058 }
32059 sqlite3_test_control(testctrl, &rc2);
32060 break;
32061 case SQLITE_TESTCTRL_BITVEC_TEST: {
32062 /* Examples:
32063 ** .testctrl bitvec_test 100 6,1 -- Show BITVEC constants
32064 ** .testctrl bitvec_test 1000 1,12,7,3 -- Simple test
32065 ** ---- --------
32066 ** size of Bitvec -----^ ^--- aOp array. 0 added at end.
32067 **
32068 ** See comments on sqlite3BitvecBuiltinTest() for more information
32069 ** about the aOp[] array.
32070 */
32071 int iSize;
32072 const char *zTestArg;
32073 int nOp;
32074 int ii, jj, x;
32075 int *aOp;
32076 if( nArg!=4 ){
32077 sqlite3_fprintf(stderr,
32078 "ERROR - should be: \".testctrl bitvec_test SIZE INT-ARRAY\"\n"
32079 );
32080 rc = 1;
32081 goto meta_command_exit;
32082 }
32083 isOk = 3;
32084 iSize = (int)integerValue(azArg[2]);
32085 zTestArg = azArg[3];
32086 nOp = (int)strlen(zTestArg)+1;
32087 aOp = malloc( sizeof(int)*(nOp+1) );
32088 shell_check_oom(aOp);
32089 memset(aOp, 0, sizeof(int)*(nOp+1) );
32090 for(ii = jj = x = 0; zTestArg[ii]!=0; ii++){
32091 if( IsDigit(zTestArg[ii]) ){
32092 x = x*10 + zTestArg[ii] - '0';
32093 }else{
32094 aOp[jj++] = x;
32095 x = 0;
32096 }
32097 }
32098 aOp[jj] = x;
32099 x = sqlite3_test_control(testctrl, iSize, aOp);
32100 sqlite3_fprintf(p->out, "result: %d\n", x);
32101 free(aOp);
32102 break;
32103 }
32104 case SQLITE_TESTCTRL_FAULT_INSTALL: {
32105 int kk;
32106 int bShowHelp = nArg<=2;
32107 isOk = 3;
32108 for(kk=2; kk<nArg; kk++){
32109
+265 -104
--- 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
-** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files:
21
+** a88bb75288a06492a04ab1278e8a2101a74f with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468468
#define SQLITE_VERSION "3.51.0"
469469
#define SQLITE_VERSION_NUMBER 3051000
470
-#define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
470
+#define SQLITE_SOURCE_ID "2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -4396,11 +4396,11 @@
43964396
** These interfaces are provided for use by [VFS shim] implementations and
43974397
** are not useful outside of that context.
43984398
**
43994399
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
44004400
** database filename D with corresponding journal file J and WAL file W and
4401
-** with N URI parameters key/values pairs in the array P. The result from
4401
+** an array P of N URI Key/Value pairs. The result from
44024402
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
44034403
** is safe to pass to routines like:
44044404
** <ul>
44054405
** <li> [sqlite3_uri_parameter()],
44064406
** <li> [sqlite3_uri_boolean()],
@@ -5077,11 +5077,11 @@
50775077
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
50785078
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
50795079
** METHOD: sqlite3_stmt
50805080
**
50815081
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
5082
-** literals may be replaced by a [parameter] that matches one of following
5082
+** literals may be replaced by a [parameter] that matches one of the following
50835083
** templates:
50845084
**
50855085
** <ul>
50865086
** <li> ?
50875087
** <li> ?NNN
@@ -5122,11 +5122,11 @@
51225122
** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
51235123
** otherwise.
51245124
**
51255125
** [[byte-order determination rules]] ^The byte-order of
51265126
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5127
-** found in first character, which is removed, or in the absence of a BOM
5127
+** found in the first character, which is removed, or in the absence of a BOM
51285128
** the byte order is the native byte order of the host
51295129
** machine for sqlite3_bind_text16() or the byte order specified in
51305130
** the 6th parameter for sqlite3_bind_text64().)^
51315131
** ^If UTF16 input text contains invalid unicode
51325132
** characters, then SQLite might change those invalid characters
@@ -5142,11 +5142,11 @@
51425142
** the behavior is undefined.
51435143
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
51445144
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
51455145
** that parameter must be the byte offset
51465146
** where the NUL terminator would occur assuming the string were NUL
5147
-** terminated. If any NUL characters occurs at byte offsets less than
5147
+** terminated. If any NUL characters occur at byte offsets less than
51485148
** the value of the fourth parameter then the resulting string value will
51495149
** contain embedded NULs. The result of expressions involving strings
51505150
** with embedded NULs is undefined.
51515151
**
51525152
** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5354,11 +5354,11 @@
53545354
/*
53555355
** CAPI3REF: Source Of Data In A Query Result
53565356
** METHOD: sqlite3_stmt
53575357
**
53585358
** ^These routines provide a means to determine the database, table, and
5359
-** table column that is the origin of a particular result column in
5359
+** table column that is the origin of a particular result column in a
53605360
** [SELECT] statement.
53615361
** ^The name of the database or table or column can be returned as
53625362
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
53635363
** the database name, the _table_ routines return the table name, and
53645364
** the origin_ routines return the column name.
@@ -5923,12 +5923,12 @@
59235923
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
59245924
** index expressions, or the WHERE clause of partial indexes.
59255925
**
59265926
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
59275927
** all application-defined SQL functions that do not need to be
5928
-** used inside of triggers, view, CHECK constraints, or other elements of
5929
-** the database schema. This flags is especially recommended for SQL
5928
+** used inside of triggers, views, CHECK constraints, or other elements of
5929
+** the database schema. This flag is especially recommended for SQL
59305930
** functions that have side effects or reveal internal application state.
59315931
** Without this flag, an attacker might be able to modify the schema of
59325932
** a database file to include invocations of the function with parameters
59335933
** chosen by the attacker, which the application will then execute when
59345934
** the database file is opened and read.
@@ -5955,11 +5955,11 @@
59555955
** or aggregate window function. More details regarding the implementation
59565956
** of aggregate window functions are
59575957
** [user-defined window functions|available here].
59585958
**
59595959
** ^(If the final parameter to sqlite3_create_function_v2() or
5960
-** sqlite3_create_window_function() is not NULL, then it is destructor for
5960
+** sqlite3_create_window_function() is not NULL, then it is the destructor for
59615961
** the application data pointer. The destructor is invoked when the function
59625962
** is deleted, either by being overloaded or when the database connection
59635963
** closes.)^ ^The destructor is also invoked if the call to
59645964
** sqlite3_create_function_v2() fails. ^When the destructor callback is
59655965
** invoked, it is passed a single argument which is a copy of the application
@@ -7763,11 +7763,11 @@
77637763
** that is to be automatically loaded into all new database connections.
77647764
**
77657765
** ^(Even though the function prototype shows that xEntryPoint() takes
77667766
** no arguments and returns void, SQLite invokes xEntryPoint() with three
77677767
** arguments and expects an integer result as if the signature of the
7768
-** entry point where as follows:
7768
+** entry point were as follows:
77697769
**
77707770
** <blockquote><pre>
77717771
** &nbsp; int xEntryPoint(
77727772
** &nbsp; sqlite3 *db,
77737773
** &nbsp; const char **pzErrMsg,
@@ -8094,11 +8094,11 @@
80948094
** by the first parameter. ^The name of the module is given by the
80958095
** second parameter. ^The third parameter is a pointer to
80968096
** the implementation of the [virtual table module]. ^The fourth
80978097
** parameter is an arbitrary client data pointer that is passed through
80988098
** into the [xCreate] and [xConnect] methods of the virtual table module
8099
-** when a new virtual table is be being created or reinitialized.
8099
+** when a new virtual table is being created or reinitialized.
81008100
**
81018101
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
81028102
** is a pointer to a destructor for the pClientData. ^SQLite will
81038103
** invoke the destructor function (if it is not NULL) when SQLite
81048104
** no longer needs the pClientData pointer. ^The destructor will also
@@ -8259,11 +8259,11 @@
82598259
**
82608260
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
82618261
** in *ppBlob. Otherwise an [error code] is returned and, unless the error
82628262
** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
82638263
** the API is not misused, it is always safe to call [sqlite3_blob_close()]
8264
-** on *ppBlob after this function it returns.
8264
+** on *ppBlob after this function returns.
82658265
**
82668266
** This function fails with SQLITE_ERROR if any of the following are true:
82678267
** <ul>
82688268
** <li> ^(Database zDb does not exist)^,
82698269
** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8379,11 +8379,11 @@
83798379
** CAPI3REF: Return The Size Of An Open BLOB
83808380
** METHOD: sqlite3_blob
83818381
**
83828382
** ^Returns the size in bytes of the BLOB accessible via the
83838383
** successfully opened [BLOB handle] in its only argument. ^The
8384
-** incremental blob I/O routines can only read or overwriting existing
8384
+** incremental blob I/O routines can only read or overwrite existing
83858385
** blob content; they cannot change the size of a blob.
83868386
**
83878387
** This routine only works on a [BLOB handle] which has been created
83888388
** by a prior successful call to [sqlite3_blob_open()] and which has not
83898389
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9782,11 +9782,11 @@
97829782
** sqlite3_backup_step(), the source database may be modified mid-way
97839783
** through the backup process. ^If the source database is modified by an
97849784
** external process or via a database connection other than the one being
97859785
** used by the backup operation, then the backup will be automatically
97869786
** restarted by the next call to sqlite3_backup_step(). ^If the source
9787
-** database is modified by the using the same database connection as is used
9787
+** database is modified by using the same database connection as is used
97889788
** by the backup operation, then the backup database is automatically
97899789
** updated at the same time.
97909790
**
97919791
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
97929792
**
@@ -9799,11 +9799,11 @@
97999799
** active write-transaction on the destination database is rolled back.
98009800
** The [sqlite3_backup] object is invalid
98019801
** and may not be used following a call to sqlite3_backup_finish().
98029802
**
98039803
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9804
-** sqlite3_backup_step() errors occurred, regardless or whether or not
9804
+** sqlite3_backup_step() errors occurred, regardless of whether or not
98059805
** sqlite3_backup_step() completed.
98069806
** ^If an out-of-memory condition or IO error occurred during any prior
98079807
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
98089808
** sqlite3_backup_finish() returns the corresponding [error code].
98099809
**
@@ -10869,11 +10869,11 @@
1086910869
/*
1087010870
** CAPI3REF: Flush caches to disk mid-transaction
1087110871
** METHOD: sqlite3
1087210872
**
1087310873
** ^If a write-transaction is open on [database connection] D when the
10874
-** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10874
+** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
1087510875
** pages in the pager-cache that are not currently in use are written out
1087610876
** to disk. A dirty page may be in use if a database cursor created by an
1087710877
** active SQL statement is reading from it, or if it is page 1 of a database
1087810878
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
1087910879
** interface flushes caches for all schemas - "main", "temp", and
@@ -15562,10 +15562,11 @@
1556215562
** 0x00008000 After all FROM-clause analysis
1556315563
** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
1556415564
** 0x00020000 Transform DISTINCT into GROUP BY
1556515565
** 0x00040000 SELECT tree dump after all code has been generated
1556615566
** 0x00080000 NOT NULL strength reduction
15567
+** 0x00100000 Pointers are all shown as zero
1556715568
*/
1556815569
1556915570
/*
1557015571
** Macros for "wheretrace"
1557115572
*/
@@ -15606,10 +15607,11 @@
1560615607
**
1560715608
** 0x00010000 Show more detail when printing WHERE terms
1560815609
** 0x00020000 Show WHERE terms returned from whereScanNext()
1560915610
** 0x00040000 Solver overview messages
1561015611
** 0x00080000 Star-query heuristic
15612
+** 0x00100000 Pointers are all shown as zero
1561115613
*/
1561215614
1561315615
1561415616
/*
1561515617
** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15680,11 @@
1567815680
** one parameter that destructors normally want. So we have to introduce
1567915681
** this magic value that the code knows to handle differently. Any
1568015682
** pointer will work here as long as it is distinct from SQLITE_STATIC
1568115683
** and SQLITE_TRANSIENT.
1568215684
*/
15683
-#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
15685
+#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3RowSetClear)
1568415686
1568515687
/*
1568615688
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
1568715689
** not support Writable Static Data (WSD) such as global and static variables.
1568815690
** All variables must either be on the stack or dynamically allocated from
@@ -21266,10 +21268,11 @@
2126621268
#endif
2126721269
#ifndef SQLITE_OMIT_WINDOWFUNC
2126821270
SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
2126921271
SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
2127021272
#endif
21273
+SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec*);
2127121274
#endif
2127221275
2127321276
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
2127421277
SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
2127521278
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -32077,10 +32080,18 @@
3207732080
}else{
3207832081
longvalue = va_arg(ap,unsigned int);
3207932082
}
3208032083
prefix = 0;
3208132084
}
32085
+
32086
+#if WHERETRACE_ENABLED
32087
+ if( xtype==etPOINTER && sqlite3WhereTrace & 0x100000 ) longvalue = 0;
32088
+#endif
32089
+#if TREETRACE_ENABLED
32090
+ if( xtype==etPOINTER && sqlite3TreeTrace & 0x100000 ) longvalue = 0;
32091
+#endif
32092
+
3208232093
if( longvalue==0 ) flag_alternateform = 0;
3208332094
if( flag_zeropad && precision<width-(prefix!=0) ){
3208432095
precision = width-(prefix!=0);
3208532096
}
3208632097
if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -54868,10 +54879,11 @@
5486854879
BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
5486954880
u32 aHash[BITVEC_NINT]; /* Hash table representation */
5487054881
Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
5487154882
} u;
5487254883
};
54884
+
5487354885
5487454886
/*
5487554887
** Create a new bitmap object able to handle bits between 0 and iSize,
5487654888
** inclusive. Return a pointer to the new object. Return NULL if
5487754889
** malloc fails.
@@ -54978,11 +54990,13 @@
5497854990
if( aiValues==0 ){
5497954991
return SQLITE_NOMEM_BKPT;
5498054992
}else{
5498154993
memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
5498254994
memset(p->u.apSub, 0, sizeof(p->u.apSub));
54983
- p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
54995
+ p->iDivisor = p->iSize/BITVEC_NPTR;
54996
+ if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++;
54997
+ if( p->iDivisor<BITVEC_NBIT ) p->iDivisor = BITVEC_NBIT;
5498454998
rc = sqlite3BitvecSet(p, i);
5498554999
for(j=0; j<BITVEC_NINT; j++){
5498655000
if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
5498755001
}
5498855002
sqlite3StackFree(0, aiValues);
@@ -55054,10 +55068,56 @@
5505455068
** was created.
5505555069
*/
5505655070
SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
5505755071
return p->iSize;
5505855072
}
55073
+
55074
+#ifdef SQLITE_DEBUG
55075
+/*
55076
+** Show the content of a Bitvec option and its children. Indent
55077
+** everything by n spaces. Add x to each bitvec value.
55078
+**
55079
+** From a debugger such as gdb, one can type:
55080
+**
55081
+** call sqlite3ShowBitvec(p)
55082
+**
55083
+** For some Bitvec p and see a recursive view of the Bitvec's content.
55084
+*/
55085
+static void showBitvec(Bitvec *p, int n, unsigned x){
55086
+ int i;
55087
+ if( p==0 ){
55088
+ printf("NULL\n");
55089
+ return;
55090
+ }
55091
+ printf("Bitvec 0x%p iSize=%u", p, p->iSize);
55092
+ if( p->iSize<=BITVEC_NBIT ){
55093
+ printf(" bitmap\n");
55094
+ printf("%*s bits:", n, "");
55095
+ for(i=1; i<=BITVEC_NBIT; i++){
55096
+ if( sqlite3BitvecTest(p,i) ) printf(" %u", x+(unsigned)i);
55097
+ }
55098
+ printf("\n");
55099
+ }else if( p->iDivisor==0 ){
55100
+ printf(" hash with %u entries\n", p->nSet);
55101
+ printf("%*s bits:", n, "");
55102
+ for(i=0; i<BITVEC_NINT; i++){
55103
+ if( p->u.aHash[i] ) printf(" %u", x+(unsigned)p->u.aHash[i]);
55104
+ }
55105
+ printf("\n");
55106
+ }else{
55107
+ printf(" sub-bitvec with iDivisor=%u\n", p->iDivisor);
55108
+ for(i=0; i<BITVEC_NPTR; i++){
55109
+ if( p->u.apSub[i]==0 ) continue;
55110
+ printf("%*s apSub[%d]=", n, "", i);
55111
+ showBitvec(p->u.apSub[i], n+4, i*p->iDivisor);
55112
+ }
55113
+ }
55114
+}
55115
+SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec *p){
55116
+ showBitvec(p, 0, 0);
55117
+}
55118
+#endif
5505955119
5506055120
#ifndef SQLITE_UNTESTABLE
5506155121
/*
5506255122
** Let V[] be an array of unsigned characters sufficient to hold
5506355123
** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55065,40 +55125,48 @@
5506555125
** individual bits within V.
5506655126
*/
5506755127
#define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
5506855128
#define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
5506955129
#define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55130
+
5507055131
5507155132
/*
5507255133
** This routine runs an extensive test of the Bitvec code.
5507355134
**
5507455135
** The input is an array of integers that acts as a program
5507555136
** to test the Bitvec. The integers are opcodes followed
5507655137
** by 0, 1, or 3 operands, depending on the opcode. Another
5507755138
** opcode follows immediately after the last operand.
5507855139
**
55079
-** There are 6 opcodes numbered from 0 through 5. 0 is the
55140
+** There are opcodes numbered starting with 0. 0 is the
5508055141
** "halt" opcode and causes the test to end.
5508155142
**
5508255143
** 0 Halt and return the number of errors
5508355144
** 1 N S X Set N bits beginning with S and incrementing by X
5508455145
** 2 N S X Clear N bits beginning with S and incrementing by X
5508555146
** 3 N Set N randomly chosen bits
5508655147
** 4 N Clear N randomly chosen bits
5508755148
** 5 N S X Set N bits from S increment X in array only, not in bitvec
55149
+** 6 Invoice sqlite3ShowBitvec() on the Bitvec object so far
55150
+** 7 X Show compile-time parameters and the hash of X
5508855151
**
5508955152
** The opcodes 1 through 4 perform set and clear operations are performed
5509055153
** on both a Bitvec object and on a linear array of bits obtained from malloc.
5509155154
** Opcode 5 works on the linear array only, not on the Bitvec.
5509255155
** Opcode 5 is used to deliberately induce a fault in order to
55093
-** confirm that error detection works.
55156
+** confirm that error detection works. Opcodes 6 and greater are
55157
+** state output opcodes. Opcodes 6 and greater are no-ops unless
55158
+** SQLite has been compiled with SQLITE_DEBUG.
5509455159
**
5509555160
** At the conclusion of the test the linear array is compared
5509655161
** against the Bitvec object. If there are any differences,
5509755162
** an error is returned. If they are the same, zero is returned.
5509855163
**
5509955164
** If a memory allocation error occurs, return -1.
55165
+**
55166
+** sz is the size of the Bitvec. Or if sz is negative, make the size
55167
+** 2*(unsigned)(-sz) and disabled the linear vector check.
5510055168
*/
5510155169
SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
5510255170
Bitvec *pBitvec = 0;
5510355171
unsigned char *pV = 0;
5510455172
int rc = -1;
@@ -55105,22 +55173,45 @@
5510555173
int i, nx, pc, op;
5510655174
void *pTmpSpace;
5510755175
5510855176
/* Allocate the Bitvec to be tested and a linear array of
5510955177
** bits to act as the reference */
55110
- pBitvec = sqlite3BitvecCreate( sz );
55111
- pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
55178
+ if( sz<=0 ){
55179
+ pBitvec = sqlite3BitvecCreate( 2*(unsigned)(-sz) );
55180
+ pV = 0;
55181
+ }else{
55182
+ pBitvec = sqlite3BitvecCreate( sz );
55183
+ pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
55184
+ }
5511255185
pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55113
- if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55186
+ if( pBitvec==0 || pTmpSpace==0 || (pV==0 && sz>0) ) goto bitvec_end;
5511455187
5511555188
/* NULL pBitvec tests */
5511655189
sqlite3BitvecSet(0, 1);
5511755190
sqlite3BitvecClear(0, 1, pTmpSpace);
5511855191
5511955192
/* Run the program */
5512055193
pc = i = 0;
5512155194
while( (op = aOp[pc])!=0 ){
55195
+ if( op>=6 ){
55196
+#ifdef SQLITE_DEBUG
55197
+ if( op==6 ){
55198
+ sqlite3ShowBitvec(pBitvec);
55199
+ }else if( op==7 ){
55200
+ printf("BITVEC_SZ = %d (%d by sizeof)\n",
55201
+ BITVEC_SZ, (int)sizeof(Bitvec));
55202
+ printf("BITVEC_USIZE = %d\n", (int)BITVEC_USIZE);
55203
+ printf("BITVEC_NELEM = %d\n", (int)BITVEC_NELEM);
55204
+ printf("BITVEC_NBIT = %d\n", (int)BITVEC_NBIT);
55205
+ printf("BITVEC_NINT = %d\n", (int)BITVEC_NINT);
55206
+ printf("BITVEC_MXHASH = %d\n", (int)BITVEC_MXHASH);
55207
+ printf("BITVEC_NPTR = %d\n", (int)BITVEC_NPTR);
55208
+ }
55209
+#endif
55210
+ pc++;
55211
+ continue;
55212
+ }
5512255213
switch( op ){
5512355214
case 1:
5512455215
case 2:
5512555216
case 5: {
5512655217
nx = 4;
@@ -55138,33 +55229,37 @@
5513855229
}
5513955230
if( (--aOp[pc+1]) > 0 ) nx = 0;
5514055231
pc += nx;
5514155232
i = (i & 0x7fffffff)%sz;
5514255233
if( (op & 1)!=0 ){
55143
- SETBIT(pV, (i+1));
55234
+ if( pV ) SETBIT(pV, (i+1));
5514455235
if( op!=5 ){
5514555236
if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
5514655237
}
5514755238
}else{
55148
- CLEARBIT(pV, (i+1));
55239
+ if( pV ) CLEARBIT(pV, (i+1));
5514955240
sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
5515055241
}
5515155242
}
5515255243
5515355244
/* Test to make sure the linear array exactly matches the
5515455245
** Bitvec object. Start with the assumption that they do
5515555246
** match (rc==0). Change rc to non-zero if a discrepancy
5515655247
** is found.
5515755248
*/
55158
- rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55159
- + sqlite3BitvecTest(pBitvec, 0)
55160
- + (sqlite3BitvecSize(pBitvec) - sz);
55161
- for(i=1; i<=sz; i++){
55162
- if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55163
- rc = i;
55164
- break;
55165
- }
55249
+ if( pV ){
55250
+ rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55251
+ + sqlite3BitvecTest(pBitvec, 0)
55252
+ + (sqlite3BitvecSize(pBitvec) - sz);
55253
+ for(i=1; i<=sz; i++){
55254
+ if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55255
+ rc = i;
55256
+ break;
55257
+ }
55258
+ }
55259
+ }else{
55260
+ rc = 0;
5516655261
}
5516755262
5516855263
/* Free allocated structure */
5516955264
bitvec_end:
5517055265
sqlite3_free(pTmpSpace);
@@ -69666,10 +69761,11 @@
6966669761
rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
6966769762
}
6966869763
if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
6966969764
}
6967069765
SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69766
+ pWal->iReCksum = 0;
6967169767
}
6967269768
return rc;
6967369769
}
6967469770
6967569771
/*
@@ -69713,10 +69809,13 @@
6971369809
pWal->hdr.aFrameCksum[1] = aWalData[2];
6971469810
SEH_TRY {
6971569811
walCleanupHash(pWal);
6971669812
}
6971769813
SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69814
+ if( pWal->iReCksum>pWal->hdr.mxFrame ){
69815
+ pWal->iReCksum = 0;
69816
+ }
6971869817
}
6971969818
6972069819
return rc;
6972169820
}
6972269821
@@ -77438,12 +77537,12 @@
7743877537
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
7743977538
return rc;
7744077539
}
7744177540
7744277541
/*
77443
-** Compare the "idx"-th cell on the page the cursor pCur is currently
77444
-** pointing to to pIdxKey using xRecordCompare. Return negative or
77542
+** Compare the "idx"-th cell on the page pPage against the key
77543
+** pointing to by pIdxKey using xRecordCompare. Return negative or
7744577544
** zero if the cell is less than or equal pIdxKey. Return positive
7744677545
** if unknown.
7744777546
**
7744877547
** Return value negative: Cell at pCur[idx] less than pIdxKey
7744977548
**
@@ -77454,16 +77553,15 @@
7745477553
**
7745577554
** This routine is part of an optimization. It is always safe to return
7745677555
** a positive value as that will cause the optimization to be skipped.
7745777556
*/
7745877557
static int indexCellCompare(
77459
- BtCursor *pCur,
77558
+ MemPage *pPage,
7746077559
int idx,
7746177560
UnpackedRecord *pIdxKey,
7746277561
RecordCompare xRecordCompare
7746377562
){
77464
- MemPage *pPage = pCur->pPage;
7746577563
int c;
7746677564
int nCell; /* Size of the pCell cell in bytes */
7746777565
u8 *pCell = findCellPastPtr(pPage, idx);
7746877566
7746977567
nCell = pCell[0];
@@ -77568,18 +77666,18 @@
7756877666
&& pCur->pPage->leaf
7756977667
&& cursorOnLastPage(pCur)
7757077668
){
7757177669
int c;
7757277670
if( pCur->ix==pCur->pPage->nCell-1
77573
- && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77671
+ && (c = indexCellCompare(pCur->pPage,pCur->ix,pIdxKey,xRecordCompare))<=0
7757477672
&& pIdxKey->errCode==SQLITE_OK
7757577673
){
7757677674
*pRes = c;
7757777675
return SQLITE_OK; /* Cursor already pointing at the correct spot */
7757877676
}
7757977677
if( pCur->iPage>0
77580
- && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77678
+ && indexCellCompare(pCur->pPage, 0, pIdxKey, xRecordCompare)<=0
7758177679
&& pIdxKey->errCode==SQLITE_OK
7758277680
){
7758377681
pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
7758477682
if( !pCur->pPage->isInit ){
7758577683
return SQLITE_CORRUPT_BKPT;
@@ -77792,11 +77890,11 @@
7779277890
if( pCur->eState!=CURSOR_VALID ) return 0;
7779377891
if( NEVER(pCur->pPage->leaf==0) ) return -1;
7779477892
7779577893
n = pCur->pPage->nCell;
7779677894
for(i=0; i<pCur->iPage; i++){
77797
- n *= pCur->apPage[i]->nCell;
77895
+ n *= pCur->apPage[i]->nCell+1;
7779877896
}
7779977897
return n;
7780077898
}
7780177899
7780277900
/*
@@ -97577,10 +97675,19 @@
9757797675
** Synopsis: typecheck(r[P1@P2])
9757897676
**
9757997677
** Apply affinities to the range of P2 registers beginning with P1.
9758097678
** Take the affinities from the Table object in P4. If any value
9758197679
** cannot be coerced into the correct type, then raise an error.
97680
+**
97681
+** If P3==0, then omit checking of VIRTUAL columns.
97682
+**
97683
+** If P3==1, then omit checking of all generated column, both VIRTUAL
97684
+** and STORED.
97685
+**
97686
+** If P3>=2, then only check column number P3-2 in the table (which will
97687
+** be a VIRTUAL column) against the value in reg[P1]. In this case,
97688
+** P2 will be 1.
9758297689
**
9758397690
** This opcode is similar to OP_Affinity except that this opcode
9758497691
** forces the register type to the Table column type. This is used
9758597692
** to implement "strict affinity".
9758697693
**
@@ -97591,30 +97698,42 @@
9759197698
**
9759297699
** Preconditions:
9759397700
**
9759497701
** <ul>
9759597702
** <li> P2 should be the number of non-virtual columns in the
97596
-** table of P4.
97597
-** <li> Table P4 should be a STRICT table.
97703
+** table of P4 unless P3>1, in which case P2 will be 1.
97704
+** <li> Table P4 is a STRICT table.
9759897705
** </ul>
9759997706
**
9760097707
** If any precondition is false, an assertion fault occurs.
9760197708
*/
9760297709
case OP_TypeCheck: {
9760397710
Table *pTab;
9760497711
Column *aCol;
9760597712
int i;
97713
+ int nCol;
9760697714
9760797715
assert( pOp->p4type==P4_TABLE );
9760897716
pTab = pOp->p4.pTab;
9760997717
assert( pTab->tabFlags & TF_Strict );
97610
- assert( pTab->nNVCol==pOp->p2 );
97718
+ assert( pOp->p3>=0 && pOp->p3<pTab->nCol+2 );
9761197719
aCol = pTab->aCol;
9761297720
pIn1 = &aMem[pOp->p1];
97613
- for(i=0; i<pTab->nCol; i++){
97614
- if( aCol[i].colFlags & COLFLAG_GENERATED ){
97615
- if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
97721
+ if( pOp->p3<2 ){
97722
+ assert( pTab->nNVCol==pOp->p2 );
97723
+ i = 0;
97724
+ nCol = pTab->nCol;
97725
+ }else{
97726
+ i = pOp->p3-2;
97727
+ nCol = i+1;
97728
+ assert( i<pTab->nCol );
97729
+ assert( aCol[i].colFlags & COLFLAG_VIRTUAL );
97730
+ assert( pOp->p2==1 );
97731
+ }
97732
+ for(; i<nCol; i++){
97733
+ if( (aCol[i].colFlags & COLFLAG_GENERATED)!=0 && pOp->p3<2 ){
97734
+ if( (aCol[i].colFlags & COLFLAG_VIRTUAL)!=0 ) continue;
9761697735
if( pOp->p3 ){ pIn1++; continue; }
9761797736
}
9761897737
assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
9761997738
applyAffinity(pIn1, aCol[i].affinity, encoding);
9762097739
if( (pIn1->flags & MEM_Null)==0 ){
@@ -114622,11 +114741,16 @@
114622114741
iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114623114742
}else{
114624114743
iAddr = 0;
114625114744
}
114626114745
sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
114627
- if( pCol->affinity>=SQLITE_AFF_TEXT ){
114746
+ if( (pCol->colFlags & COLFLAG_VIRTUAL)!=0
114747
+ && (pTab->tabFlags & TF_Strict)!=0
114748
+ ){
114749
+ int p3 = 2+(int)(pCol - pTab->aCol);
114750
+ sqlite3VdbeAddOp4(v, OP_TypeCheck, regOut, 1, p3, (char*)pTab, P4_TABLE);
114751
+ }else if( pCol->affinity>=SQLITE_AFF_TEXT ){
114628114752
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114629114753
}
114630114754
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
114631114755
if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
114632114756
}
@@ -132016,11 +132140,11 @@
132016132140
int argc,
132017132141
sqlite3_value **argv,
132018132142
int nSep,
132019132143
const char *zSep
132020132144
){
132021
- i64 j, k, n = 0;
132145
+ i64 j, n = 0;
132022132146
int i;
132023132147
char *z;
132024132148
for(i=0; i<argc; i++){
132025132149
n += sqlite3_value_bytes(argv[i]);
132026132150
}
@@ -132030,12 +132154,12 @@
132030132154
sqlite3_result_error_nomem(context);
132031132155
return;
132032132156
}
132033132157
j = 0;
132034132158
for(i=0; i<argc; i++){
132035
- k = sqlite3_value_bytes(argv[i]);
132036
- if( k>0 ){
132159
+ if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){
132160
+ int k = sqlite3_value_bytes(argv[i]);
132037132161
const char *v = (const char*)sqlite3_value_text(argv[i]);
132038132162
if( v!=0 ){
132039132163
if( j>0 && nSep>0 ){
132040132164
memcpy(&z[j], zSep, nSep);
132041132165
j += nSep;
@@ -134969,16 +135093,19 @@
134969135093
if( iReg==0 ){
134970135094
/* Move the previous opcode (which should be OP_MakeRecord) forward
134971135095
** by one slot and insert a new OP_TypeCheck where the current
134972135096
** OP_MakeRecord is found */
134973135097
VdbeOp *pPrev;
135098
+ int p3;
134974135099
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
134975135100
pPrev = sqlite3VdbeGetLastOp(v);
134976135101
assert( pPrev!=0 );
134977135102
assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
134978135103
pPrev->opcode = OP_TypeCheck;
134979
- sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
135104
+ p3 = pPrev->p3;
135105
+ pPrev->p3 = 0;
135106
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, p3);
134980135107
}else{
134981135108
/* Insert an isolated OP_Typecheck */
134982135109
sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
134983135110
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
134984135111
}
@@ -159209,10 +159336,13 @@
159209159336
u16 eOperator; /* A WO_xx value describing <op> */
159210159337
u8 nChild; /* Number of children that must disable us */
159211159338
u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159212159339
int iParent; /* Disable pWC->a[iParent] when this term disabled */
159213159340
int leftCursor; /* Cursor number of X in "X <op> <expr>" */
159341
+#ifdef SQLITE_DEBUG
159342
+ int iTerm; /* Which WhereTerm is this, for debug purposes */
159343
+#endif
159214159344
union {
159215159345
struct {
159216159346
int leftColumn; /* Column number of X in "X <op> <expr>" */
159217159347
int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159218159348
} x; /* Opcode other than OP_OR or OP_AND */
@@ -161406,40 +161536,40 @@
161406161536
VdbeCoverageIf(v, testOp==OP_Ge);
161407161537
VdbeCoverageIf(v, testOp==OP_Gt);
161408161538
sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161409161539
}
161410161540
}else if( pLoop->wsFlags & WHERE_INDEXED ){
161411
- /* Case 4: A scan using an index.
161412
- **
161413
- ** The WHERE clause may contain zero or more equality
161414
- ** terms ("==" or "IN" operators) that refer to the N
161415
- ** left-most columns of the index. It may also contain
161416
- ** inequality constraints (>, <, >= or <=) on the indexed
161417
- ** column that immediately follows the N equalities. Only
161418
- ** the right-most column can be an inequality - the rest must
161419
- ** use the "==" and "IN" operators. For example, if the
161420
- ** index is on (x,y,z), then the following clauses are all
161421
- ** optimized:
161422
- **
161423
- ** x=5
161424
- ** x=5 AND y=10
161425
- ** x=5 AND y<10
161426
- ** x=5 AND y>5 AND y<10
161427
- ** x=5 AND y=5 AND z<=10
161428
- **
161429
- ** The z<10 term of the following cannot be used, only
161430
- ** the x=5 term:
161431
- **
161432
- ** x=5 AND z<10
161433
- **
161434
- ** N may be zero if there are inequality constraints.
161435
- ** If there are no inequality constraints, then N is at
161436
- ** least one.
161437
- **
161438
- ** This case is also used when there are no WHERE clause
161439
- ** constraints but an index is selected anyway, in order
161440
- ** to force the output order to conform to an ORDER BY.
161541
+ /* Case 4: Search using an index.
161542
+ **
161543
+ ** The WHERE clause may contain zero or more equality
161544
+ ** terms ("==" or "IN" or "IS" operators) that refer to the N
161545
+ ** left-most columns of the index. It may also contain
161546
+ ** inequality constraints (>, <, >= or <=) on the indexed
161547
+ ** column that immediately follows the N equalities. Only
161548
+ ** the right-most column can be an inequality - the rest must
161549
+ ** use the "==", "IN", or "IS" operators. For example, if the
161550
+ ** index is on (x,y,z), then the following clauses are all
161551
+ ** optimized:
161552
+ **
161553
+ ** x=5
161554
+ ** x=5 AND y=10
161555
+ ** x=5 AND y<10
161556
+ ** x=5 AND y>5 AND y<10
161557
+ ** x=5 AND y=5 AND z<=10
161558
+ **
161559
+ ** The z<10 term of the following cannot be used, only
161560
+ ** the x=5 term:
161561
+ **
161562
+ ** x=5 AND z<10
161563
+ **
161564
+ ** N may be zero if there are inequality constraints.
161565
+ ** If there are no inequality constraints, then N is at
161566
+ ** least one.
161567
+ **
161568
+ ** This case is also used when there are no WHERE clause
161569
+ ** constraints but an index is selected anyway, in order
161570
+ ** to force the output order to conform to an ORDER BY.
161441161571
*/
161442161572
static const u8 aStartOp[] = {
161443161573
0,
161444161574
0,
161445161575
OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -163455,34 +163585,46 @@
163455163585
** column references. This routine checks to see if pExpr is an equivalence
163456163586
** relation:
163457163587
** 1. The SQLITE_Transitive optimization must be enabled
163458163588
** 2. Must be either an == or an IS operator
163459163589
** 3. Not originating in the ON clause of an OUTER JOIN
163460
-** 4. The affinities of A and B must be compatible
163461
-** 5a. Both operands use the same collating sequence OR
163462
-** 5b. The overall collating sequence is BINARY
163590
+** 4. The operator is not IS or else the query does not contain RIGHT JOIN
163591
+** 5. The affinities of A and B must be compatible
163592
+** 6a. Both operands use the same collating sequence OR
163593
+** 6b. The overall collating sequence is BINARY
163463163594
** If this routine returns TRUE, that means that the RHS can be substituted
163464163595
** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
163465163596
** This is an optimization. No harm comes from returning 0. But if 1 is
163466163597
** returned when it should not be, then incorrect answers might result.
163467163598
*/
163468
-static int termIsEquivalence(Parse *pParse, Expr *pExpr){
163599
+static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
163469163600
char aff1, aff2;
163470163601
CollSeq *pColl;
163471
- if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
163472
- if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
163473
- if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
163602
+ if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
163603
+ if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
163604
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
163605
+ assert( pSrc!=0 );
163606
+ if( pExpr->op==TK_IS
163607
+ && pSrc->nSrc
163608
+ && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
163609
+ ){
163610
+ return 0; /* (4) */
163611
+ }
163474163612
aff1 = sqlite3ExprAffinity(pExpr->pLeft);
163475163613
aff2 = sqlite3ExprAffinity(pExpr->pRight);
163476163614
if( aff1!=aff2
163477163615
&& (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
163478163616
){
163479
- return 0;
163617
+ return 0; /* (5) */
163480163618
}
163481163619
pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
163482
- if( sqlite3IsBinary(pColl) ) return 1;
163483
- return sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight);
163620
+ if( !sqlite3IsBinary(pColl)
163621
+ && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
163622
+ ){
163623
+ return 0; /* (6) */
163624
+ }
163625
+ return 1;
163484163626
}
163485163627
163486163628
/*
163487163629
** Recursively walk the expressions of a SELECT statement and generate
163488163630
** a bitmask indicating which tables are used in that expression
@@ -163636,10 +163778,13 @@
163636163778
if( db->mallocFailed ){
163637163779
return;
163638163780
}
163639163781
assert( pWC->nTerm > idxTerm );
163640163782
pTerm = &pWC->a[idxTerm];
163783
+#ifdef SQLITE_DEBUG
163784
+ pTerm->iTerm = idxTerm;
163785
+#endif
163641163786
pMaskSet = &pWInfo->sMaskSet;
163642163787
pExpr = pTerm->pExpr;
163643163788
assert( pExpr!=0 ); /* Because malloc() has not failed */
163644163789
assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
163645163790
pMaskSet->bVarSelect = 0;
@@ -163743,12 +163888,12 @@
163743163888
pNew = &pWC->a[idxNew];
163744163889
markTermAsChild(pWC, idxNew, idxTerm);
163745163890
if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
163746163891
pTerm = &pWC->a[idxTerm];
163747163892
pTerm->wtFlags |= TERM_COPIED;
163748
-
163749
- if( termIsEquivalence(pParse, pDup) ){
163893
+ assert( pWInfo->pTabList!=0 );
163894
+ if( termIsEquivalence(pParse, pDup, pWInfo->pTabList) ){
163750163895
pTerm->eOperator |= WO_EQUIV;
163751163896
eExtraOp = WO_EQUIV;
163752163897
}
163753163898
}else{
163754163899
pDup = pExpr;
@@ -164863,15 +165008,15 @@
164863165008
continue;
164864165009
}
164865165010
pScan->pWC = pWC;
164866165011
pScan->k = k+1;
164867165012
#ifdef WHERETRACE_ENABLED
164868
- if( sqlite3WhereTrace & 0x20000 ){
165013
+ if( (sqlite3WhereTrace & 0x20000)!=0 && pScan->nEquiv>1 ){
164869165014
int ii;
164870
- sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
164871
- pTerm, pScan->nEquiv);
164872
- for(ii=0; ii<pScan->nEquiv; ii++){
165015
+ sqlite3DebugPrintf("EQUIVALENT TO {%d:%d} (due to TERM-%d):",
165016
+ pScan->aiCur[0], pScan->aiColumn[0], pTerm->iTerm);
165017
+ for(ii=1; ii<pScan->nEquiv; ii++){
164873165018
sqlite3DebugPrintf(" {%d:%d}",
164874165019
pScan->aiCur[ii], pScan->aiColumn[ii]);
164875165020
}
164876165021
sqlite3DebugPrintf("\n");
164877165022
}
@@ -166822,10 +166967,11 @@
166822166967
sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166823166968
pTerm->u.pOrInfo->indexable);
166824166969
}else{
166825166970
sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
166826166971
}
166972
+ iTerm = pTerm->iTerm = MAX(iTerm,pTerm->iTerm);
166827166973
sqlite3DebugPrintf(
166828166974
"TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
166829166975
iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
166830166976
/* The 0x10000 .wheretrace flag causes extra information to be
166831166977
** shown about each Term */
@@ -184446,10 +184592,11 @@
184446184592
#ifdef SQLITE_ENABLE_API_ARMOR
184447184593
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
184448184594
#endif
184449184595
if( ms<-1 ) return SQLITE_RANGE;
184450184596
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
184597
+ sqlite3_mutex_enter(db->mutex);
184451184598
db->setlkTimeout = ms;
184452184599
db->setlkFlags = flags;
184453184600
sqlite3BtreeEnterAll(db);
184454184601
for(iDb=0; iDb<db->nDb; iDb++){
184455184602
Btree *pBt = db->aDb[iDb].pBt;
@@ -184457,10 +184604,11 @@
184457184604
sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
184458184605
sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
184459184606
}
184460184607
}
184461184608
sqlite3BtreeLeaveAll(db);
184609
+ sqlite3_mutex_leave(db->mutex);
184462184610
#endif
184463184611
#if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
184464184612
UNUSED_PARAMETER(db);
184465184613
UNUSED_PARAMETER(flags);
184466184614
#endif
@@ -257253,11 +257401,11 @@
257253257401
int nArg, /* Number of args */
257254257402
sqlite3_value **apUnused /* Function arguments */
257255257403
){
257256257404
assert( nArg==0 );
257257257405
UNUSED_PARAM2(nArg, apUnused);
257258
- sqlite3_result_text(pCtx, "fts5: 2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5", -1, SQLITE_TRANSIENT);
257406
+ sqlite3_result_text(pCtx, "fts5: 2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d", -1, SQLITE_TRANSIENT);
257259257407
}
257260257408
257261257409
/*
257262257410
** Implementation of fts5_locale(LOCALE, TEXT) function.
257263257411
**
@@ -258068,10 +258216,11 @@
258068258216
ctx.pStorage = p;
258069258217
ctx.iCol = -1;
258070258218
for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258071258219
if( pConfig->abUnindexed[iCol-1]==0 ){
258072258220
sqlite3_value *pVal = 0;
258221
+ sqlite3_value *pFree = 0;
258073258222
const char *pText = 0;
258074258223
int nText = 0;
258075258224
const char *pLoc = 0;
258076258225
int nLoc = 0;
258077258226
@@ -258084,15 +258233,26 @@
258084258233
}
258085258234
258086258235
if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258087258236
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258088258237
}else{
258089
- pText = (const char*)sqlite3_value_text(pVal);
258090
- nText = sqlite3_value_bytes(pVal);
258091
- if( pConfig->bLocale && pSeek ){
258092
- pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol);
258093
- nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258238
+ if( sqlite3_value_type(pVal)!=SQLITE_TEXT ){
258239
+ /* Make a copy of the value to work with. This is because the call
258240
+ ** to sqlite3_value_text() below forces the type of the value to
258241
+ ** SQLITE_TEXT, and we may need to use it again later. */
258242
+ pFree = pVal = sqlite3_value_dup(pVal);
258243
+ if( pVal==0 ){
258244
+ rc = SQLITE_NOMEM;
258245
+ }
258246
+ }
258247
+ if( rc==SQLITE_OK ){
258248
+ pText = (const char*)sqlite3_value_text(pVal);
258249
+ nText = sqlite3_value_bytes(pVal);
258250
+ if( pConfig->bLocale && pSeek ){
258251
+ pLoc = (const char*)sqlite3_column_text(pSeek, iCol+pConfig->nCol);
258252
+ nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258253
+ }
258094258254
}
258095258255
}
258096258256
258097258257
if( rc==SQLITE_OK ){
258098258258
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258104,10 +258264,11 @@
258104258264
if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258105258265
rc = FTS5_CORRUPT;
258106258266
}
258107258267
sqlite3Fts5ClearLocale(pConfig);
258108258268
}
258269
+ sqlite3_value_free(pFree);
258109258270
}
258110258271
}
258111258272
if( rc==SQLITE_OK && p->nTotalRow<1 ){
258112258273
rc = FTS5_CORRUPT;
258113258274
}else{
258114258275
--- 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 ** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -4396,11 +4396,11 @@
4396 ** These interfaces are provided for use by [VFS shim] implementations and
4397 ** are not useful outside of that context.
4398 **
4399 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4400 ** database filename D with corresponding journal file J and WAL file W and
4401 ** with N URI parameters key/values pairs in the array P. The result from
4402 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4403 ** is safe to pass to routines like:
4404 ** <ul>
4405 ** <li> [sqlite3_uri_parameter()],
4406 ** <li> [sqlite3_uri_boolean()],
@@ -5077,11 +5077,11 @@
5077 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
5078 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
5079 ** METHOD: sqlite3_stmt
5080 **
5081 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
5082 ** literals may be replaced by a [parameter] that matches one of following
5083 ** templates:
5084 **
5085 ** <ul>
5086 ** <li> ?
5087 ** <li> ?NNN
@@ -5122,11 +5122,11 @@
5122 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5123 ** otherwise.
5124 **
5125 ** [[byte-order determination rules]] ^The byte-order of
5126 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5127 ** found in first character, which is removed, or in the absence of a BOM
5128 ** the byte order is the native byte order of the host
5129 ** machine for sqlite3_bind_text16() or the byte order specified in
5130 ** the 6th parameter for sqlite3_bind_text64().)^
5131 ** ^If UTF16 input text contains invalid unicode
5132 ** characters, then SQLite might change those invalid characters
@@ -5142,11 +5142,11 @@
5142 ** the behavior is undefined.
5143 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5144 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5145 ** that parameter must be the byte offset
5146 ** where the NUL terminator would occur assuming the string were NUL
5147 ** terminated. If any NUL characters occurs at byte offsets less than
5148 ** the value of the fourth parameter then the resulting string value will
5149 ** contain embedded NULs. The result of expressions involving strings
5150 ** with embedded NULs is undefined.
5151 **
5152 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5354,11 +5354,11 @@
5354 /*
5355 ** CAPI3REF: Source Of Data In A Query Result
5356 ** METHOD: sqlite3_stmt
5357 **
5358 ** ^These routines provide a means to determine the database, table, and
5359 ** table column that is the origin of a particular result column in
5360 ** [SELECT] statement.
5361 ** ^The name of the database or table or column can be returned as
5362 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5363 ** the database name, the _table_ routines return the table name, and
5364 ** the origin_ routines return the column name.
@@ -5923,12 +5923,12 @@
5923 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5924 ** index expressions, or the WHERE clause of partial indexes.
5925 **
5926 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5927 ** all application-defined SQL functions that do not need to be
5928 ** used inside of triggers, view, CHECK constraints, or other elements of
5929 ** the database schema. This flags is especially recommended for SQL
5930 ** functions that have side effects or reveal internal application state.
5931 ** Without this flag, an attacker might be able to modify the schema of
5932 ** a database file to include invocations of the function with parameters
5933 ** chosen by the attacker, which the application will then execute when
5934 ** the database file is opened and read.
@@ -5955,11 +5955,11 @@
5955 ** or aggregate window function. More details regarding the implementation
5956 ** of aggregate window functions are
5957 ** [user-defined window functions|available here].
5958 **
5959 ** ^(If the final parameter to sqlite3_create_function_v2() or
5960 ** sqlite3_create_window_function() is not NULL, then it is destructor for
5961 ** the application data pointer. The destructor is invoked when the function
5962 ** is deleted, either by being overloaded or when the database connection
5963 ** closes.)^ ^The destructor is also invoked if the call to
5964 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5965 ** invoked, it is passed a single argument which is a copy of the application
@@ -7763,11 +7763,11 @@
7763 ** that is to be automatically loaded into all new database connections.
7764 **
7765 ** ^(Even though the function prototype shows that xEntryPoint() takes
7766 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7767 ** arguments and expects an integer result as if the signature of the
7768 ** entry point where as follows:
7769 **
7770 ** <blockquote><pre>
7771 ** &nbsp; int xEntryPoint(
7772 ** &nbsp; sqlite3 *db,
7773 ** &nbsp; const char **pzErrMsg,
@@ -8094,11 +8094,11 @@
8094 ** by the first parameter. ^The name of the module is given by the
8095 ** second parameter. ^The third parameter is a pointer to
8096 ** the implementation of the [virtual table module]. ^The fourth
8097 ** parameter is an arbitrary client data pointer that is passed through
8098 ** into the [xCreate] and [xConnect] methods of the virtual table module
8099 ** when a new virtual table is be being created or reinitialized.
8100 **
8101 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
8102 ** is a pointer to a destructor for the pClientData. ^SQLite will
8103 ** invoke the destructor function (if it is not NULL) when SQLite
8104 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -8259,11 +8259,11 @@
8259 **
8260 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
8261 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
8262 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
8263 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
8264 ** on *ppBlob after this function it returns.
8265 **
8266 ** This function fails with SQLITE_ERROR if any of the following are true:
8267 ** <ul>
8268 ** <li> ^(Database zDb does not exist)^,
8269 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8379,11 +8379,11 @@
8379 ** CAPI3REF: Return The Size Of An Open BLOB
8380 ** METHOD: sqlite3_blob
8381 **
8382 ** ^Returns the size in bytes of the BLOB accessible via the
8383 ** successfully opened [BLOB handle] in its only argument. ^The
8384 ** incremental blob I/O routines can only read or overwriting existing
8385 ** blob content; they cannot change the size of a blob.
8386 **
8387 ** This routine only works on a [BLOB handle] which has been created
8388 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8389 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9782,11 +9782,11 @@
9782 ** sqlite3_backup_step(), the source database may be modified mid-way
9783 ** through the backup process. ^If the source database is modified by an
9784 ** external process or via a database connection other than the one being
9785 ** used by the backup operation, then the backup will be automatically
9786 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9787 ** database is modified by the using the same database connection as is used
9788 ** by the backup operation, then the backup database is automatically
9789 ** updated at the same time.
9790 **
9791 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9792 **
@@ -9799,11 +9799,11 @@
9799 ** active write-transaction on the destination database is rolled back.
9800 ** The [sqlite3_backup] object is invalid
9801 ** and may not be used following a call to sqlite3_backup_finish().
9802 **
9803 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9804 ** sqlite3_backup_step() errors occurred, regardless or whether or not
9805 ** sqlite3_backup_step() completed.
9806 ** ^If an out-of-memory condition or IO error occurred during any prior
9807 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9808 ** sqlite3_backup_finish() returns the corresponding [error code].
9809 **
@@ -10869,11 +10869,11 @@
10869 /*
10870 ** CAPI3REF: Flush caches to disk mid-transaction
10871 ** METHOD: sqlite3
10872 **
10873 ** ^If a write-transaction is open on [database connection] D when the
10874 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10875 ** pages in the pager-cache that are not currently in use are written out
10876 ** to disk. A dirty page may be in use if a database cursor created by an
10877 ** active SQL statement is reading from it, or if it is page 1 of a database
10878 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10879 ** interface flushes caches for all schemas - "main", "temp", and
@@ -15562,10 +15562,11 @@
15562 ** 0x00008000 After all FROM-clause analysis
15563 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15564 ** 0x00020000 Transform DISTINCT into GROUP BY
15565 ** 0x00040000 SELECT tree dump after all code has been generated
15566 ** 0x00080000 NOT NULL strength reduction
 
15567 */
15568
15569 /*
15570 ** Macros for "wheretrace"
15571 */
@@ -15606,10 +15607,11 @@
15606 **
15607 ** 0x00010000 Show more detail when printing WHERE terms
15608 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15609 ** 0x00040000 Solver overview messages
15610 ** 0x00080000 Star-query heuristic
 
15611 */
15612
15613
15614 /*
15615 ** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15680,11 @@
15678 ** one parameter that destructors normally want. So we have to introduce
15679 ** this magic value that the code knows to handle differently. Any
15680 ** pointer will work here as long as it is distinct from SQLITE_STATIC
15681 ** and SQLITE_TRANSIENT.
15682 */
15683 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
15684
15685 /*
15686 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
15687 ** not support Writable Static Data (WSD) such as global and static variables.
15688 ** All variables must either be on the stack or dynamically allocated from
@@ -21266,10 +21268,11 @@
21266 #endif
21267 #ifndef SQLITE_OMIT_WINDOWFUNC
21268 SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
21269 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
21270 #endif
 
21271 #endif
21272
21273 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
21274 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
21275 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -32077,10 +32080,18 @@
32077 }else{
32078 longvalue = va_arg(ap,unsigned int);
32079 }
32080 prefix = 0;
32081 }
 
 
 
 
 
 
 
 
32082 if( longvalue==0 ) flag_alternateform = 0;
32083 if( flag_zeropad && precision<width-(prefix!=0) ){
32084 precision = width-(prefix!=0);
32085 }
32086 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -54868,10 +54879,11 @@
54868 BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
54869 u32 aHash[BITVEC_NINT]; /* Hash table representation */
54870 Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
54871 } u;
54872 };
 
54873
54874 /*
54875 ** Create a new bitmap object able to handle bits between 0 and iSize,
54876 ** inclusive. Return a pointer to the new object. Return NULL if
54877 ** malloc fails.
@@ -54978,11 +54990,13 @@
54978 if( aiValues==0 ){
54979 return SQLITE_NOMEM_BKPT;
54980 }else{
54981 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
54982 memset(p->u.apSub, 0, sizeof(p->u.apSub));
54983 p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
 
 
54984 rc = sqlite3BitvecSet(p, i);
54985 for(j=0; j<BITVEC_NINT; j++){
54986 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
54987 }
54988 sqlite3StackFree(0, aiValues);
@@ -55054,10 +55068,56 @@
55054 ** was created.
55055 */
55056 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
55057 return p->iSize;
55058 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55059
55060 #ifndef SQLITE_UNTESTABLE
55061 /*
55062 ** Let V[] be an array of unsigned characters sufficient to hold
55063 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55065,40 +55125,48 @@
55065 ** individual bits within V.
55066 */
55067 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
55068 #define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
55069 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
 
55070
55071 /*
55072 ** This routine runs an extensive test of the Bitvec code.
55073 **
55074 ** The input is an array of integers that acts as a program
55075 ** to test the Bitvec. The integers are opcodes followed
55076 ** by 0, 1, or 3 operands, depending on the opcode. Another
55077 ** opcode follows immediately after the last operand.
55078 **
55079 ** There are 6 opcodes numbered from 0 through 5. 0 is the
55080 ** "halt" opcode and causes the test to end.
55081 **
55082 ** 0 Halt and return the number of errors
55083 ** 1 N S X Set N bits beginning with S and incrementing by X
55084 ** 2 N S X Clear N bits beginning with S and incrementing by X
55085 ** 3 N Set N randomly chosen bits
55086 ** 4 N Clear N randomly chosen bits
55087 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
 
 
55088 **
55089 ** The opcodes 1 through 4 perform set and clear operations are performed
55090 ** on both a Bitvec object and on a linear array of bits obtained from malloc.
55091 ** Opcode 5 works on the linear array only, not on the Bitvec.
55092 ** Opcode 5 is used to deliberately induce a fault in order to
55093 ** confirm that error detection works.
 
 
55094 **
55095 ** At the conclusion of the test the linear array is compared
55096 ** against the Bitvec object. If there are any differences,
55097 ** an error is returned. If they are the same, zero is returned.
55098 **
55099 ** If a memory allocation error occurs, return -1.
 
 
 
55100 */
55101 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
55102 Bitvec *pBitvec = 0;
55103 unsigned char *pV = 0;
55104 int rc = -1;
@@ -55105,22 +55173,45 @@
55105 int i, nx, pc, op;
55106 void *pTmpSpace;
55107
55108 /* Allocate the Bitvec to be tested and a linear array of
55109 ** bits to act as the reference */
55110 pBitvec = sqlite3BitvecCreate( sz );
55111 pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
 
 
 
 
 
55112 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55113 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55114
55115 /* NULL pBitvec tests */
55116 sqlite3BitvecSet(0, 1);
55117 sqlite3BitvecClear(0, 1, pTmpSpace);
55118
55119 /* Run the program */
55120 pc = i = 0;
55121 while( (op = aOp[pc])!=0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55122 switch( op ){
55123 case 1:
55124 case 2:
55125 case 5: {
55126 nx = 4;
@@ -55138,33 +55229,37 @@
55138 }
55139 if( (--aOp[pc+1]) > 0 ) nx = 0;
55140 pc += nx;
55141 i = (i & 0x7fffffff)%sz;
55142 if( (op & 1)!=0 ){
55143 SETBIT(pV, (i+1));
55144 if( op!=5 ){
55145 if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
55146 }
55147 }else{
55148 CLEARBIT(pV, (i+1));
55149 sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
55150 }
55151 }
55152
55153 /* Test to make sure the linear array exactly matches the
55154 ** Bitvec object. Start with the assumption that they do
55155 ** match (rc==0). Change rc to non-zero if a discrepancy
55156 ** is found.
55157 */
55158 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55159 + sqlite3BitvecTest(pBitvec, 0)
55160 + (sqlite3BitvecSize(pBitvec) - sz);
55161 for(i=1; i<=sz; i++){
55162 if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55163 rc = i;
55164 break;
55165 }
 
 
 
 
55166 }
55167
55168 /* Free allocated structure */
55169 bitvec_end:
55170 sqlite3_free(pTmpSpace);
@@ -69666,10 +69761,11 @@
69666 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
69667 }
69668 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
69669 }
69670 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
 
69671 }
69672 return rc;
69673 }
69674
69675 /*
@@ -69713,10 +69809,13 @@
69713 pWal->hdr.aFrameCksum[1] = aWalData[2];
69714 SEH_TRY {
69715 walCleanupHash(pWal);
69716 }
69717 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
 
 
 
69718 }
69719
69720 return rc;
69721 }
69722
@@ -77438,12 +77537,12 @@
77438 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77439 return rc;
77440 }
77441
77442 /*
77443 ** Compare the "idx"-th cell on the page the cursor pCur is currently
77444 ** pointing to to pIdxKey using xRecordCompare. Return negative or
77445 ** zero if the cell is less than or equal pIdxKey. Return positive
77446 ** if unknown.
77447 **
77448 ** Return value negative: Cell at pCur[idx] less than pIdxKey
77449 **
@@ -77454,16 +77553,15 @@
77454 **
77455 ** This routine is part of an optimization. It is always safe to return
77456 ** a positive value as that will cause the optimization to be skipped.
77457 */
77458 static int indexCellCompare(
77459 BtCursor *pCur,
77460 int idx,
77461 UnpackedRecord *pIdxKey,
77462 RecordCompare xRecordCompare
77463 ){
77464 MemPage *pPage = pCur->pPage;
77465 int c;
77466 int nCell; /* Size of the pCell cell in bytes */
77467 u8 *pCell = findCellPastPtr(pPage, idx);
77468
77469 nCell = pCell[0];
@@ -77568,18 +77666,18 @@
77568 && pCur->pPage->leaf
77569 && cursorOnLastPage(pCur)
77570 ){
77571 int c;
77572 if( pCur->ix==pCur->pPage->nCell-1
77573 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77574 && pIdxKey->errCode==SQLITE_OK
77575 ){
77576 *pRes = c;
77577 return SQLITE_OK; /* Cursor already pointing at the correct spot */
77578 }
77579 if( pCur->iPage>0
77580 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77581 && pIdxKey->errCode==SQLITE_OK
77582 ){
77583 pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
77584 if( !pCur->pPage->isInit ){
77585 return SQLITE_CORRUPT_BKPT;
@@ -77792,11 +77890,11 @@
77792 if( pCur->eState!=CURSOR_VALID ) return 0;
77793 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77794
77795 n = pCur->pPage->nCell;
77796 for(i=0; i<pCur->iPage; i++){
77797 n *= pCur->apPage[i]->nCell;
77798 }
77799 return n;
77800 }
77801
77802 /*
@@ -97577,10 +97675,19 @@
97577 ** Synopsis: typecheck(r[P1@P2])
97578 **
97579 ** Apply affinities to the range of P2 registers beginning with P1.
97580 ** Take the affinities from the Table object in P4. If any value
97581 ** cannot be coerced into the correct type, then raise an error.
 
 
 
 
 
 
 
 
 
97582 **
97583 ** This opcode is similar to OP_Affinity except that this opcode
97584 ** forces the register type to the Table column type. This is used
97585 ** to implement "strict affinity".
97586 **
@@ -97591,30 +97698,42 @@
97591 **
97592 ** Preconditions:
97593 **
97594 ** <ul>
97595 ** <li> P2 should be the number of non-virtual columns in the
97596 ** table of P4.
97597 ** <li> Table P4 should be a STRICT table.
97598 ** </ul>
97599 **
97600 ** If any precondition is false, an assertion fault occurs.
97601 */
97602 case OP_TypeCheck: {
97603 Table *pTab;
97604 Column *aCol;
97605 int i;
 
97606
97607 assert( pOp->p4type==P4_TABLE );
97608 pTab = pOp->p4.pTab;
97609 assert( pTab->tabFlags & TF_Strict );
97610 assert( pTab->nNVCol==pOp->p2 );
97611 aCol = pTab->aCol;
97612 pIn1 = &aMem[pOp->p1];
97613 for(i=0; i<pTab->nCol; i++){
97614 if( aCol[i].colFlags & COLFLAG_GENERATED ){
97615 if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
 
 
 
 
 
 
 
 
 
 
 
97616 if( pOp->p3 ){ pIn1++; continue; }
97617 }
97618 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
97619 applyAffinity(pIn1, aCol[i].affinity, encoding);
97620 if( (pIn1->flags & MEM_Null)==0 ){
@@ -114622,11 +114741,16 @@
114622 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114623 }else{
114624 iAddr = 0;
114625 }
114626 sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
114627 if( pCol->affinity>=SQLITE_AFF_TEXT ){
 
 
 
 
 
114628 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114629 }
114630 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
114631 if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
114632 }
@@ -132016,11 +132140,11 @@
132016 int argc,
132017 sqlite3_value **argv,
132018 int nSep,
132019 const char *zSep
132020 ){
132021 i64 j, k, n = 0;
132022 int i;
132023 char *z;
132024 for(i=0; i<argc; i++){
132025 n += sqlite3_value_bytes(argv[i]);
132026 }
@@ -132030,12 +132154,12 @@
132030 sqlite3_result_error_nomem(context);
132031 return;
132032 }
132033 j = 0;
132034 for(i=0; i<argc; i++){
132035 k = sqlite3_value_bytes(argv[i]);
132036 if( k>0 ){
132037 const char *v = (const char*)sqlite3_value_text(argv[i]);
132038 if( v!=0 ){
132039 if( j>0 && nSep>0 ){
132040 memcpy(&z[j], zSep, nSep);
132041 j += nSep;
@@ -134969,16 +135093,19 @@
134969 if( iReg==0 ){
134970 /* Move the previous opcode (which should be OP_MakeRecord) forward
134971 ** by one slot and insert a new OP_TypeCheck where the current
134972 ** OP_MakeRecord is found */
134973 VdbeOp *pPrev;
 
134974 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
134975 pPrev = sqlite3VdbeGetLastOp(v);
134976 assert( pPrev!=0 );
134977 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
134978 pPrev->opcode = OP_TypeCheck;
134979 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
 
 
134980 }else{
134981 /* Insert an isolated OP_Typecheck */
134982 sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
134983 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
134984 }
@@ -159209,10 +159336,13 @@
159209 u16 eOperator; /* A WO_xx value describing <op> */
159210 u8 nChild; /* Number of children that must disable us */
159211 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159212 int iParent; /* Disable pWC->a[iParent] when this term disabled */
159213 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
 
 
 
159214 union {
159215 struct {
159216 int leftColumn; /* Column number of X in "X <op> <expr>" */
159217 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159218 } x; /* Opcode other than OP_OR or OP_AND */
@@ -161406,40 +161536,40 @@
161406 VdbeCoverageIf(v, testOp==OP_Ge);
161407 VdbeCoverageIf(v, testOp==OP_Gt);
161408 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161409 }
161410 }else if( pLoop->wsFlags & WHERE_INDEXED ){
161411 /* Case 4: A scan using an index.
161412 **
161413 ** The WHERE clause may contain zero or more equality
161414 ** terms ("==" or "IN" operators) that refer to the N
161415 ** left-most columns of the index. It may also contain
161416 ** inequality constraints (>, <, >= or <=) on the indexed
161417 ** column that immediately follows the N equalities. Only
161418 ** the right-most column can be an inequality - the rest must
161419 ** use the "==" and "IN" operators. For example, if the
161420 ** index is on (x,y,z), then the following clauses are all
161421 ** optimized:
161422 **
161423 ** x=5
161424 ** x=5 AND y=10
161425 ** x=5 AND y<10
161426 ** x=5 AND y>5 AND y<10
161427 ** x=5 AND y=5 AND z<=10
161428 **
161429 ** The z<10 term of the following cannot be used, only
161430 ** the x=5 term:
161431 **
161432 ** x=5 AND z<10
161433 **
161434 ** N may be zero if there are inequality constraints.
161435 ** If there are no inequality constraints, then N is at
161436 ** least one.
161437 **
161438 ** This case is also used when there are no WHERE clause
161439 ** constraints but an index is selected anyway, in order
161440 ** to force the output order to conform to an ORDER BY.
161441 */
161442 static const u8 aStartOp[] = {
161443 0,
161444 0,
161445 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -163455,34 +163585,46 @@
163455 ** column references. This routine checks to see if pExpr is an equivalence
163456 ** relation:
163457 ** 1. The SQLITE_Transitive optimization must be enabled
163458 ** 2. Must be either an == or an IS operator
163459 ** 3. Not originating in the ON clause of an OUTER JOIN
163460 ** 4. The affinities of A and B must be compatible
163461 ** 5a. Both operands use the same collating sequence OR
163462 ** 5b. The overall collating sequence is BINARY
 
163463 ** If this routine returns TRUE, that means that the RHS can be substituted
163464 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
163465 ** This is an optimization. No harm comes from returning 0. But if 1 is
163466 ** returned when it should not be, then incorrect answers might result.
163467 */
163468 static int termIsEquivalence(Parse *pParse, Expr *pExpr){
163469 char aff1, aff2;
163470 CollSeq *pColl;
163471 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
163472 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
163473 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
 
 
 
 
 
 
 
163474 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
163475 aff2 = sqlite3ExprAffinity(pExpr->pRight);
163476 if( aff1!=aff2
163477 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
163478 ){
163479 return 0;
163480 }
163481 pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
163482 if( sqlite3IsBinary(pColl) ) return 1;
163483 return sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight);
 
 
 
 
163484 }
163485
163486 /*
163487 ** Recursively walk the expressions of a SELECT statement and generate
163488 ** a bitmask indicating which tables are used in that expression
@@ -163636,10 +163778,13 @@
163636 if( db->mallocFailed ){
163637 return;
163638 }
163639 assert( pWC->nTerm > idxTerm );
163640 pTerm = &pWC->a[idxTerm];
 
 
 
163641 pMaskSet = &pWInfo->sMaskSet;
163642 pExpr = pTerm->pExpr;
163643 assert( pExpr!=0 ); /* Because malloc() has not failed */
163644 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
163645 pMaskSet->bVarSelect = 0;
@@ -163743,12 +163888,12 @@
163743 pNew = &pWC->a[idxNew];
163744 markTermAsChild(pWC, idxNew, idxTerm);
163745 if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
163746 pTerm = &pWC->a[idxTerm];
163747 pTerm->wtFlags |= TERM_COPIED;
163748
163749 if( termIsEquivalence(pParse, pDup) ){
163750 pTerm->eOperator |= WO_EQUIV;
163751 eExtraOp = WO_EQUIV;
163752 }
163753 }else{
163754 pDup = pExpr;
@@ -164863,15 +165008,15 @@
164863 continue;
164864 }
164865 pScan->pWC = pWC;
164866 pScan->k = k+1;
164867 #ifdef WHERETRACE_ENABLED
164868 if( sqlite3WhereTrace & 0x20000 ){
164869 int ii;
164870 sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
164871 pTerm, pScan->nEquiv);
164872 for(ii=0; ii<pScan->nEquiv; ii++){
164873 sqlite3DebugPrintf(" {%d:%d}",
164874 pScan->aiCur[ii], pScan->aiColumn[ii]);
164875 }
164876 sqlite3DebugPrintf("\n");
164877 }
@@ -166822,10 +166967,11 @@
166822 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166823 pTerm->u.pOrInfo->indexable);
166824 }else{
166825 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
166826 }
 
166827 sqlite3DebugPrintf(
166828 "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
166829 iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
166830 /* The 0x10000 .wheretrace flag causes extra information to be
166831 ** shown about each Term */
@@ -184446,10 +184592,11 @@
184446 #ifdef SQLITE_ENABLE_API_ARMOR
184447 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
184448 #endif
184449 if( ms<-1 ) return SQLITE_RANGE;
184450 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
 
184451 db->setlkTimeout = ms;
184452 db->setlkFlags = flags;
184453 sqlite3BtreeEnterAll(db);
184454 for(iDb=0; iDb<db->nDb; iDb++){
184455 Btree *pBt = db->aDb[iDb].pBt;
@@ -184457,10 +184604,11 @@
184457 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
184458 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
184459 }
184460 }
184461 sqlite3BtreeLeaveAll(db);
 
184462 #endif
184463 #if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
184464 UNUSED_PARAMETER(db);
184465 UNUSED_PARAMETER(flags);
184466 #endif
@@ -257253,11 +257401,11 @@
257253 int nArg, /* Number of args */
257254 sqlite3_value **apUnused /* Function arguments */
257255 ){
257256 assert( nArg==0 );
257257 UNUSED_PARAM2(nArg, apUnused);
257258 sqlite3_result_text(pCtx, "fts5: 2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5", -1, SQLITE_TRANSIENT);
257259 }
257260
257261 /*
257262 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257263 **
@@ -258068,10 +258216,11 @@
258068 ctx.pStorage = p;
258069 ctx.iCol = -1;
258070 for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258071 if( pConfig->abUnindexed[iCol-1]==0 ){
258072 sqlite3_value *pVal = 0;
 
258073 const char *pText = 0;
258074 int nText = 0;
258075 const char *pLoc = 0;
258076 int nLoc = 0;
258077
@@ -258084,15 +258233,26 @@
258084 }
258085
258086 if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258087 rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258088 }else{
258089 pText = (const char*)sqlite3_value_text(pVal);
258090 nText = sqlite3_value_bytes(pVal);
258091 if( pConfig->bLocale && pSeek ){
258092 pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol);
258093 nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
 
 
 
 
 
 
 
 
 
 
 
258094 }
258095 }
258096
258097 if( rc==SQLITE_OK ){
258098 sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258104,10 +258264,11 @@
258104 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258105 rc = FTS5_CORRUPT;
258106 }
258107 sqlite3Fts5ClearLocale(pConfig);
258108 }
 
258109 }
258110 }
258111 if( rc==SQLITE_OK && p->nTotalRow<1 ){
258112 rc = FTS5_CORRUPT;
258113 }else{
258114
--- 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 ** a88bb75288a06492a04ab1278e8a2101a74f with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -4396,11 +4396,11 @@
4396 ** These interfaces are provided for use by [VFS shim] implementations and
4397 ** are not useful outside of that context.
4398 **
4399 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4400 ** database filename D with corresponding journal file J and WAL file W and
4401 ** an array P of N URI Key/Value pairs. The result from
4402 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4403 ** is safe to pass to routines like:
4404 ** <ul>
4405 ** <li> [sqlite3_uri_parameter()],
4406 ** <li> [sqlite3_uri_boolean()],
@@ -5077,11 +5077,11 @@
5077 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
5078 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
5079 ** METHOD: sqlite3_stmt
5080 **
5081 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
5082 ** literals may be replaced by a [parameter] that matches one of the following
5083 ** templates:
5084 **
5085 ** <ul>
5086 ** <li> ?
5087 ** <li> ?NNN
@@ -5122,11 +5122,11 @@
5122 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5123 ** otherwise.
5124 **
5125 ** [[byte-order determination rules]] ^The byte-order of
5126 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5127 ** found in the first character, which is removed, or in the absence of a BOM
5128 ** the byte order is the native byte order of the host
5129 ** machine for sqlite3_bind_text16() or the byte order specified in
5130 ** the 6th parameter for sqlite3_bind_text64().)^
5131 ** ^If UTF16 input text contains invalid unicode
5132 ** characters, then SQLite might change those invalid characters
@@ -5142,11 +5142,11 @@
5142 ** the behavior is undefined.
5143 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5144 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5145 ** that parameter must be the byte offset
5146 ** where the NUL terminator would occur assuming the string were NUL
5147 ** terminated. If any NUL characters occur at byte offsets less than
5148 ** the value of the fourth parameter then the resulting string value will
5149 ** contain embedded NULs. The result of expressions involving strings
5150 ** with embedded NULs is undefined.
5151 **
5152 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5354,11 +5354,11 @@
5354 /*
5355 ** CAPI3REF: Source Of Data In A Query Result
5356 ** METHOD: sqlite3_stmt
5357 **
5358 ** ^These routines provide a means to determine the database, table, and
5359 ** table column that is the origin of a particular result column in a
5360 ** [SELECT] statement.
5361 ** ^The name of the database or table or column can be returned as
5362 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5363 ** the database name, the _table_ routines return the table name, and
5364 ** the origin_ routines return the column name.
@@ -5923,12 +5923,12 @@
5923 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5924 ** index expressions, or the WHERE clause of partial indexes.
5925 **
5926 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5927 ** all application-defined SQL functions that do not need to be
5928 ** used inside of triggers, views, CHECK constraints, or other elements of
5929 ** the database schema. This flag is especially recommended for SQL
5930 ** functions that have side effects or reveal internal application state.
5931 ** Without this flag, an attacker might be able to modify the schema of
5932 ** a database file to include invocations of the function with parameters
5933 ** chosen by the attacker, which the application will then execute when
5934 ** the database file is opened and read.
@@ -5955,11 +5955,11 @@
5955 ** or aggregate window function. More details regarding the implementation
5956 ** of aggregate window functions are
5957 ** [user-defined window functions|available here].
5958 **
5959 ** ^(If the final parameter to sqlite3_create_function_v2() or
5960 ** sqlite3_create_window_function() is not NULL, then it is the destructor for
5961 ** the application data pointer. The destructor is invoked when the function
5962 ** is deleted, either by being overloaded or when the database connection
5963 ** closes.)^ ^The destructor is also invoked if the call to
5964 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5965 ** invoked, it is passed a single argument which is a copy of the application
@@ -7763,11 +7763,11 @@
7763 ** that is to be automatically loaded into all new database connections.
7764 **
7765 ** ^(Even though the function prototype shows that xEntryPoint() takes
7766 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7767 ** arguments and expects an integer result as if the signature of the
7768 ** entry point were as follows:
7769 **
7770 ** <blockquote><pre>
7771 ** &nbsp; int xEntryPoint(
7772 ** &nbsp; sqlite3 *db,
7773 ** &nbsp; const char **pzErrMsg,
@@ -8094,11 +8094,11 @@
8094 ** by the first parameter. ^The name of the module is given by the
8095 ** second parameter. ^The third parameter is a pointer to
8096 ** the implementation of the [virtual table module]. ^The fourth
8097 ** parameter is an arbitrary client data pointer that is passed through
8098 ** into the [xCreate] and [xConnect] methods of the virtual table module
8099 ** when a new virtual table is being created or reinitialized.
8100 **
8101 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
8102 ** is a pointer to a destructor for the pClientData. ^SQLite will
8103 ** invoke the destructor function (if it is not NULL) when SQLite
8104 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -8259,11 +8259,11 @@
8259 **
8260 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
8261 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
8262 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
8263 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
8264 ** on *ppBlob after this function returns.
8265 **
8266 ** This function fails with SQLITE_ERROR if any of the following are true:
8267 ** <ul>
8268 ** <li> ^(Database zDb does not exist)^,
8269 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8379,11 +8379,11 @@
8379 ** CAPI3REF: Return The Size Of An Open BLOB
8380 ** METHOD: sqlite3_blob
8381 **
8382 ** ^Returns the size in bytes of the BLOB accessible via the
8383 ** successfully opened [BLOB handle] in its only argument. ^The
8384 ** incremental blob I/O routines can only read or overwrite existing
8385 ** blob content; they cannot change the size of a blob.
8386 **
8387 ** This routine only works on a [BLOB handle] which has been created
8388 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8389 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9782,11 +9782,11 @@
9782 ** sqlite3_backup_step(), the source database may be modified mid-way
9783 ** through the backup process. ^If the source database is modified by an
9784 ** external process or via a database connection other than the one being
9785 ** used by the backup operation, then the backup will be automatically
9786 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9787 ** database is modified by using the same database connection as is used
9788 ** by the backup operation, then the backup database is automatically
9789 ** updated at the same time.
9790 **
9791 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9792 **
@@ -9799,11 +9799,11 @@
9799 ** active write-transaction on the destination database is rolled back.
9800 ** The [sqlite3_backup] object is invalid
9801 ** and may not be used following a call to sqlite3_backup_finish().
9802 **
9803 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9804 ** sqlite3_backup_step() errors occurred, regardless of whether or not
9805 ** sqlite3_backup_step() completed.
9806 ** ^If an out-of-memory condition or IO error occurred during any prior
9807 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9808 ** sqlite3_backup_finish() returns the corresponding [error code].
9809 **
@@ -10869,11 +10869,11 @@
10869 /*
10870 ** CAPI3REF: Flush caches to disk mid-transaction
10871 ** METHOD: sqlite3
10872 **
10873 ** ^If a write-transaction is open on [database connection] D when the
10874 ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
10875 ** pages in the pager-cache that are not currently in use are written out
10876 ** to disk. A dirty page may be in use if a database cursor created by an
10877 ** active SQL statement is reading from it, or if it is page 1 of a database
10878 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10879 ** interface flushes caches for all schemas - "main", "temp", and
@@ -15562,10 +15562,11 @@
15562 ** 0x00008000 After all FROM-clause analysis
15563 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15564 ** 0x00020000 Transform DISTINCT into GROUP BY
15565 ** 0x00040000 SELECT tree dump after all code has been generated
15566 ** 0x00080000 NOT NULL strength reduction
15567 ** 0x00100000 Pointers are all shown as zero
15568 */
15569
15570 /*
15571 ** Macros for "wheretrace"
15572 */
@@ -15606,10 +15607,11 @@
15607 **
15608 ** 0x00010000 Show more detail when printing WHERE terms
15609 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15610 ** 0x00040000 Solver overview messages
15611 ** 0x00080000 Star-query heuristic
15612 ** 0x00100000 Pointers are all shown as zero
15613 */
15614
15615
15616 /*
15617 ** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15680,11 @@
15680 ** one parameter that destructors normally want. So we have to introduce
15681 ** this magic value that the code knows to handle differently. Any
15682 ** pointer will work here as long as it is distinct from SQLITE_STATIC
15683 ** and SQLITE_TRANSIENT.
15684 */
15685 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3RowSetClear)
15686
15687 /*
15688 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
15689 ** not support Writable Static Data (WSD) such as global and static variables.
15690 ** All variables must either be on the stack or dynamically allocated from
@@ -21266,10 +21268,11 @@
21268 #endif
21269 #ifndef SQLITE_OMIT_WINDOWFUNC
21270 SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
21271 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
21272 #endif
21273 SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec*);
21274 #endif
21275
21276 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
21277 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
21278 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -32077,10 +32080,18 @@
32080 }else{
32081 longvalue = va_arg(ap,unsigned int);
32082 }
32083 prefix = 0;
32084 }
32085
32086 #if WHERETRACE_ENABLED
32087 if( xtype==etPOINTER && sqlite3WhereTrace & 0x100000 ) longvalue = 0;
32088 #endif
32089 #if TREETRACE_ENABLED
32090 if( xtype==etPOINTER && sqlite3TreeTrace & 0x100000 ) longvalue = 0;
32091 #endif
32092
32093 if( longvalue==0 ) flag_alternateform = 0;
32094 if( flag_zeropad && precision<width-(prefix!=0) ){
32095 precision = width-(prefix!=0);
32096 }
32097 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -54868,10 +54879,11 @@
54879 BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
54880 u32 aHash[BITVEC_NINT]; /* Hash table representation */
54881 Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
54882 } u;
54883 };
54884
54885
54886 /*
54887 ** Create a new bitmap object able to handle bits between 0 and iSize,
54888 ** inclusive. Return a pointer to the new object. Return NULL if
54889 ** malloc fails.
@@ -54978,11 +54990,13 @@
54990 if( aiValues==0 ){
54991 return SQLITE_NOMEM_BKPT;
54992 }else{
54993 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
54994 memset(p->u.apSub, 0, sizeof(p->u.apSub));
54995 p->iDivisor = p->iSize/BITVEC_NPTR;
54996 if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++;
54997 if( p->iDivisor<BITVEC_NBIT ) p->iDivisor = BITVEC_NBIT;
54998 rc = sqlite3BitvecSet(p, i);
54999 for(j=0; j<BITVEC_NINT; j++){
55000 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
55001 }
55002 sqlite3StackFree(0, aiValues);
@@ -55054,10 +55068,56 @@
55068 ** was created.
55069 */
55070 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
55071 return p->iSize;
55072 }
55073
55074 #ifdef SQLITE_DEBUG
55075 /*
55076 ** Show the content of a Bitvec option and its children. Indent
55077 ** everything by n spaces. Add x to each bitvec value.
55078 **
55079 ** From a debugger such as gdb, one can type:
55080 **
55081 ** call sqlite3ShowBitvec(p)
55082 **
55083 ** For some Bitvec p and see a recursive view of the Bitvec's content.
55084 */
55085 static void showBitvec(Bitvec *p, int n, unsigned x){
55086 int i;
55087 if( p==0 ){
55088 printf("NULL\n");
55089 return;
55090 }
55091 printf("Bitvec 0x%p iSize=%u", p, p->iSize);
55092 if( p->iSize<=BITVEC_NBIT ){
55093 printf(" bitmap\n");
55094 printf("%*s bits:", n, "");
55095 for(i=1; i<=BITVEC_NBIT; i++){
55096 if( sqlite3BitvecTest(p,i) ) printf(" %u", x+(unsigned)i);
55097 }
55098 printf("\n");
55099 }else if( p->iDivisor==0 ){
55100 printf(" hash with %u entries\n", p->nSet);
55101 printf("%*s bits:", n, "");
55102 for(i=0; i<BITVEC_NINT; i++){
55103 if( p->u.aHash[i] ) printf(" %u", x+(unsigned)p->u.aHash[i]);
55104 }
55105 printf("\n");
55106 }else{
55107 printf(" sub-bitvec with iDivisor=%u\n", p->iDivisor);
55108 for(i=0; i<BITVEC_NPTR; i++){
55109 if( p->u.apSub[i]==0 ) continue;
55110 printf("%*s apSub[%d]=", n, "", i);
55111 showBitvec(p->u.apSub[i], n+4, i*p->iDivisor);
55112 }
55113 }
55114 }
55115 SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec *p){
55116 showBitvec(p, 0, 0);
55117 }
55118 #endif
55119
55120 #ifndef SQLITE_UNTESTABLE
55121 /*
55122 ** Let V[] be an array of unsigned characters sufficient to hold
55123 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55065,40 +55125,48 @@
55125 ** individual bits within V.
55126 */
55127 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
55128 #define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
55129 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55130
55131
55132 /*
55133 ** This routine runs an extensive test of the Bitvec code.
55134 **
55135 ** The input is an array of integers that acts as a program
55136 ** to test the Bitvec. The integers are opcodes followed
55137 ** by 0, 1, or 3 operands, depending on the opcode. Another
55138 ** opcode follows immediately after the last operand.
55139 **
55140 ** There are opcodes numbered starting with 0. 0 is the
55141 ** "halt" opcode and causes the test to end.
55142 **
55143 ** 0 Halt and return the number of errors
55144 ** 1 N S X Set N bits beginning with S and incrementing by X
55145 ** 2 N S X Clear N bits beginning with S and incrementing by X
55146 ** 3 N Set N randomly chosen bits
55147 ** 4 N Clear N randomly chosen bits
55148 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
55149 ** 6 Invoice sqlite3ShowBitvec() on the Bitvec object so far
55150 ** 7 X Show compile-time parameters and the hash of X
55151 **
55152 ** The opcodes 1 through 4 perform set and clear operations are performed
55153 ** on both a Bitvec object and on a linear array of bits obtained from malloc.
55154 ** Opcode 5 works on the linear array only, not on the Bitvec.
55155 ** Opcode 5 is used to deliberately induce a fault in order to
55156 ** confirm that error detection works. Opcodes 6 and greater are
55157 ** state output opcodes. Opcodes 6 and greater are no-ops unless
55158 ** SQLite has been compiled with SQLITE_DEBUG.
55159 **
55160 ** At the conclusion of the test the linear array is compared
55161 ** against the Bitvec object. If there are any differences,
55162 ** an error is returned. If they are the same, zero is returned.
55163 **
55164 ** If a memory allocation error occurs, return -1.
55165 **
55166 ** sz is the size of the Bitvec. Or if sz is negative, make the size
55167 ** 2*(unsigned)(-sz) and disabled the linear vector check.
55168 */
55169 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
55170 Bitvec *pBitvec = 0;
55171 unsigned char *pV = 0;
55172 int rc = -1;
@@ -55105,22 +55173,45 @@
55173 int i, nx, pc, op;
55174 void *pTmpSpace;
55175
55176 /* Allocate the Bitvec to be tested and a linear array of
55177 ** bits to act as the reference */
55178 if( sz<=0 ){
55179 pBitvec = sqlite3BitvecCreate( 2*(unsigned)(-sz) );
55180 pV = 0;
55181 }else{
55182 pBitvec = sqlite3BitvecCreate( sz );
55183 pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
55184 }
55185 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55186 if( pBitvec==0 || pTmpSpace==0 || (pV==0 && sz>0) ) goto bitvec_end;
55187
55188 /* NULL pBitvec tests */
55189 sqlite3BitvecSet(0, 1);
55190 sqlite3BitvecClear(0, 1, pTmpSpace);
55191
55192 /* Run the program */
55193 pc = i = 0;
55194 while( (op = aOp[pc])!=0 ){
55195 if( op>=6 ){
55196 #ifdef SQLITE_DEBUG
55197 if( op==6 ){
55198 sqlite3ShowBitvec(pBitvec);
55199 }else if( op==7 ){
55200 printf("BITVEC_SZ = %d (%d by sizeof)\n",
55201 BITVEC_SZ, (int)sizeof(Bitvec));
55202 printf("BITVEC_USIZE = %d\n", (int)BITVEC_USIZE);
55203 printf("BITVEC_NELEM = %d\n", (int)BITVEC_NELEM);
55204 printf("BITVEC_NBIT = %d\n", (int)BITVEC_NBIT);
55205 printf("BITVEC_NINT = %d\n", (int)BITVEC_NINT);
55206 printf("BITVEC_MXHASH = %d\n", (int)BITVEC_MXHASH);
55207 printf("BITVEC_NPTR = %d\n", (int)BITVEC_NPTR);
55208 }
55209 #endif
55210 pc++;
55211 continue;
55212 }
55213 switch( op ){
55214 case 1:
55215 case 2:
55216 case 5: {
55217 nx = 4;
@@ -55138,33 +55229,37 @@
55229 }
55230 if( (--aOp[pc+1]) > 0 ) nx = 0;
55231 pc += nx;
55232 i = (i & 0x7fffffff)%sz;
55233 if( (op & 1)!=0 ){
55234 if( pV ) SETBIT(pV, (i+1));
55235 if( op!=5 ){
55236 if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
55237 }
55238 }else{
55239 if( pV ) CLEARBIT(pV, (i+1));
55240 sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
55241 }
55242 }
55243
55244 /* Test to make sure the linear array exactly matches the
55245 ** Bitvec object. Start with the assumption that they do
55246 ** match (rc==0). Change rc to non-zero if a discrepancy
55247 ** is found.
55248 */
55249 if( pV ){
55250 rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55251 + sqlite3BitvecTest(pBitvec, 0)
55252 + (sqlite3BitvecSize(pBitvec) - sz);
55253 for(i=1; i<=sz; i++){
55254 if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55255 rc = i;
55256 break;
55257 }
55258 }
55259 }else{
55260 rc = 0;
55261 }
55262
55263 /* Free allocated structure */
55264 bitvec_end:
55265 sqlite3_free(pTmpSpace);
@@ -69666,10 +69761,11 @@
69761 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
69762 }
69763 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
69764 }
69765 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69766 pWal->iReCksum = 0;
69767 }
69768 return rc;
69769 }
69770
69771 /*
@@ -69713,10 +69809,13 @@
69809 pWal->hdr.aFrameCksum[1] = aWalData[2];
69810 SEH_TRY {
69811 walCleanupHash(pWal);
69812 }
69813 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69814 if( pWal->iReCksum>pWal->hdr.mxFrame ){
69815 pWal->iReCksum = 0;
69816 }
69817 }
69818
69819 return rc;
69820 }
69821
@@ -77438,12 +77537,12 @@
77537 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77538 return rc;
77539 }
77540
77541 /*
77542 ** Compare the "idx"-th cell on the page pPage against the key
77543 ** pointing to by pIdxKey using xRecordCompare. Return negative or
77544 ** zero if the cell is less than or equal pIdxKey. Return positive
77545 ** if unknown.
77546 **
77547 ** Return value negative: Cell at pCur[idx] less than pIdxKey
77548 **
@@ -77454,16 +77553,15 @@
77553 **
77554 ** This routine is part of an optimization. It is always safe to return
77555 ** a positive value as that will cause the optimization to be skipped.
77556 */
77557 static int indexCellCompare(
77558 MemPage *pPage,
77559 int idx,
77560 UnpackedRecord *pIdxKey,
77561 RecordCompare xRecordCompare
77562 ){
 
77563 int c;
77564 int nCell; /* Size of the pCell cell in bytes */
77565 u8 *pCell = findCellPastPtr(pPage, idx);
77566
77567 nCell = pCell[0];
@@ -77568,18 +77666,18 @@
77666 && pCur->pPage->leaf
77667 && cursorOnLastPage(pCur)
77668 ){
77669 int c;
77670 if( pCur->ix==pCur->pPage->nCell-1
77671 && (c = indexCellCompare(pCur->pPage,pCur->ix,pIdxKey,xRecordCompare))<=0
77672 && pIdxKey->errCode==SQLITE_OK
77673 ){
77674 *pRes = c;
77675 return SQLITE_OK; /* Cursor already pointing at the correct spot */
77676 }
77677 if( pCur->iPage>0
77678 && indexCellCompare(pCur->pPage, 0, pIdxKey, xRecordCompare)<=0
77679 && pIdxKey->errCode==SQLITE_OK
77680 ){
77681 pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
77682 if( !pCur->pPage->isInit ){
77683 return SQLITE_CORRUPT_BKPT;
@@ -77792,11 +77890,11 @@
77890 if( pCur->eState!=CURSOR_VALID ) return 0;
77891 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77892
77893 n = pCur->pPage->nCell;
77894 for(i=0; i<pCur->iPage; i++){
77895 n *= pCur->apPage[i]->nCell+1;
77896 }
77897 return n;
77898 }
77899
77900 /*
@@ -97577,10 +97675,19 @@
97675 ** Synopsis: typecheck(r[P1@P2])
97676 **
97677 ** Apply affinities to the range of P2 registers beginning with P1.
97678 ** Take the affinities from the Table object in P4. If any value
97679 ** cannot be coerced into the correct type, then raise an error.
97680 **
97681 ** If P3==0, then omit checking of VIRTUAL columns.
97682 **
97683 ** If P3==1, then omit checking of all generated column, both VIRTUAL
97684 ** and STORED.
97685 **
97686 ** If P3>=2, then only check column number P3-2 in the table (which will
97687 ** be a VIRTUAL column) against the value in reg[P1]. In this case,
97688 ** P2 will be 1.
97689 **
97690 ** This opcode is similar to OP_Affinity except that this opcode
97691 ** forces the register type to the Table column type. This is used
97692 ** to implement "strict affinity".
97693 **
@@ -97591,30 +97698,42 @@
97698 **
97699 ** Preconditions:
97700 **
97701 ** <ul>
97702 ** <li> P2 should be the number of non-virtual columns in the
97703 ** table of P4 unless P3>1, in which case P2 will be 1.
97704 ** <li> Table P4 is a STRICT table.
97705 ** </ul>
97706 **
97707 ** If any precondition is false, an assertion fault occurs.
97708 */
97709 case OP_TypeCheck: {
97710 Table *pTab;
97711 Column *aCol;
97712 int i;
97713 int nCol;
97714
97715 assert( pOp->p4type==P4_TABLE );
97716 pTab = pOp->p4.pTab;
97717 assert( pTab->tabFlags & TF_Strict );
97718 assert( pOp->p3>=0 && pOp->p3<pTab->nCol+2 );
97719 aCol = pTab->aCol;
97720 pIn1 = &aMem[pOp->p1];
97721 if( pOp->p3<2 ){
97722 assert( pTab->nNVCol==pOp->p2 );
97723 i = 0;
97724 nCol = pTab->nCol;
97725 }else{
97726 i = pOp->p3-2;
97727 nCol = i+1;
97728 assert( i<pTab->nCol );
97729 assert( aCol[i].colFlags & COLFLAG_VIRTUAL );
97730 assert( pOp->p2==1 );
97731 }
97732 for(; i<nCol; i++){
97733 if( (aCol[i].colFlags & COLFLAG_GENERATED)!=0 && pOp->p3<2 ){
97734 if( (aCol[i].colFlags & COLFLAG_VIRTUAL)!=0 ) continue;
97735 if( pOp->p3 ){ pIn1++; continue; }
97736 }
97737 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
97738 applyAffinity(pIn1, aCol[i].affinity, encoding);
97739 if( (pIn1->flags & MEM_Null)==0 ){
@@ -114622,11 +114741,16 @@
114741 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114742 }else{
114743 iAddr = 0;
114744 }
114745 sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
114746 if( (pCol->colFlags & COLFLAG_VIRTUAL)!=0
114747 && (pTab->tabFlags & TF_Strict)!=0
114748 ){
114749 int p3 = 2+(int)(pCol - pTab->aCol);
114750 sqlite3VdbeAddOp4(v, OP_TypeCheck, regOut, 1, p3, (char*)pTab, P4_TABLE);
114751 }else if( pCol->affinity>=SQLITE_AFF_TEXT ){
114752 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114753 }
114754 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
114755 if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
114756 }
@@ -132016,11 +132140,11 @@
132140 int argc,
132141 sqlite3_value **argv,
132142 int nSep,
132143 const char *zSep
132144 ){
132145 i64 j, n = 0;
132146 int i;
132147 char *z;
132148 for(i=0; i<argc; i++){
132149 n += sqlite3_value_bytes(argv[i]);
132150 }
@@ -132030,12 +132154,12 @@
132154 sqlite3_result_error_nomem(context);
132155 return;
132156 }
132157 j = 0;
132158 for(i=0; i<argc; i++){
132159 if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){
132160 int k = sqlite3_value_bytes(argv[i]);
132161 const char *v = (const char*)sqlite3_value_text(argv[i]);
132162 if( v!=0 ){
132163 if( j>0 && nSep>0 ){
132164 memcpy(&z[j], zSep, nSep);
132165 j += nSep;
@@ -134969,16 +135093,19 @@
135093 if( iReg==0 ){
135094 /* Move the previous opcode (which should be OP_MakeRecord) forward
135095 ** by one slot and insert a new OP_TypeCheck where the current
135096 ** OP_MakeRecord is found */
135097 VdbeOp *pPrev;
135098 int p3;
135099 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135100 pPrev = sqlite3VdbeGetLastOp(v);
135101 assert( pPrev!=0 );
135102 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
135103 pPrev->opcode = OP_TypeCheck;
135104 p3 = pPrev->p3;
135105 pPrev->p3 = 0;
135106 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, p3);
135107 }else{
135108 /* Insert an isolated OP_Typecheck */
135109 sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
135110 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135111 }
@@ -159209,10 +159336,13 @@
159336 u16 eOperator; /* A WO_xx value describing <op> */
159337 u8 nChild; /* Number of children that must disable us */
159338 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159339 int iParent; /* Disable pWC->a[iParent] when this term disabled */
159340 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
159341 #ifdef SQLITE_DEBUG
159342 int iTerm; /* Which WhereTerm is this, for debug purposes */
159343 #endif
159344 union {
159345 struct {
159346 int leftColumn; /* Column number of X in "X <op> <expr>" */
159347 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159348 } x; /* Opcode other than OP_OR or OP_AND */
@@ -161406,40 +161536,40 @@
161536 VdbeCoverageIf(v, testOp==OP_Ge);
161537 VdbeCoverageIf(v, testOp==OP_Gt);
161538 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161539 }
161540 }else if( pLoop->wsFlags & WHERE_INDEXED ){
161541 /* Case 4: Search using an index.
161542 **
161543 ** The WHERE clause may contain zero or more equality
161544 ** terms ("==" or "IN" or "IS" operators) that refer to the N
161545 ** left-most columns of the index. It may also contain
161546 ** inequality constraints (>, <, >= or <=) on the indexed
161547 ** column that immediately follows the N equalities. Only
161548 ** the right-most column can be an inequality - the rest must
161549 ** use the "==", "IN", or "IS" operators. For example, if the
161550 ** index is on (x,y,z), then the following clauses are all
161551 ** optimized:
161552 **
161553 ** x=5
161554 ** x=5 AND y=10
161555 ** x=5 AND y<10
161556 ** x=5 AND y>5 AND y<10
161557 ** x=5 AND y=5 AND z<=10
161558 **
161559 ** The z<10 term of the following cannot be used, only
161560 ** the x=5 term:
161561 **
161562 ** x=5 AND z<10
161563 **
161564 ** N may be zero if there are inequality constraints.
161565 ** If there are no inequality constraints, then N is at
161566 ** least one.
161567 **
161568 ** This case is also used when there are no WHERE clause
161569 ** constraints but an index is selected anyway, in order
161570 ** to force the output order to conform to an ORDER BY.
161571 */
161572 static const u8 aStartOp[] = {
161573 0,
161574 0,
161575 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -163455,34 +163585,46 @@
163585 ** column references. This routine checks to see if pExpr is an equivalence
163586 ** relation:
163587 ** 1. The SQLITE_Transitive optimization must be enabled
163588 ** 2. Must be either an == or an IS operator
163589 ** 3. Not originating in the ON clause of an OUTER JOIN
163590 ** 4. The operator is not IS or else the query does not contain RIGHT JOIN
163591 ** 5. The affinities of A and B must be compatible
163592 ** 6a. Both operands use the same collating sequence OR
163593 ** 6b. The overall collating sequence is BINARY
163594 ** If this routine returns TRUE, that means that the RHS can be substituted
163595 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
163596 ** This is an optimization. No harm comes from returning 0. But if 1 is
163597 ** returned when it should not be, then incorrect answers might result.
163598 */
163599 static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
163600 char aff1, aff2;
163601 CollSeq *pColl;
163602 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
163603 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
163604 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
163605 assert( pSrc!=0 );
163606 if( pExpr->op==TK_IS
163607 && pSrc->nSrc
163608 && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
163609 ){
163610 return 0; /* (4) */
163611 }
163612 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
163613 aff2 = sqlite3ExprAffinity(pExpr->pRight);
163614 if( aff1!=aff2
163615 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
163616 ){
163617 return 0; /* (5) */
163618 }
163619 pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
163620 if( !sqlite3IsBinary(pColl)
163621 && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
163622 ){
163623 return 0; /* (6) */
163624 }
163625 return 1;
163626 }
163627
163628 /*
163629 ** Recursively walk the expressions of a SELECT statement and generate
163630 ** a bitmask indicating which tables are used in that expression
@@ -163636,10 +163778,13 @@
163778 if( db->mallocFailed ){
163779 return;
163780 }
163781 assert( pWC->nTerm > idxTerm );
163782 pTerm = &pWC->a[idxTerm];
163783 #ifdef SQLITE_DEBUG
163784 pTerm->iTerm = idxTerm;
163785 #endif
163786 pMaskSet = &pWInfo->sMaskSet;
163787 pExpr = pTerm->pExpr;
163788 assert( pExpr!=0 ); /* Because malloc() has not failed */
163789 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
163790 pMaskSet->bVarSelect = 0;
@@ -163743,12 +163888,12 @@
163888 pNew = &pWC->a[idxNew];
163889 markTermAsChild(pWC, idxNew, idxTerm);
163890 if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
163891 pTerm = &pWC->a[idxTerm];
163892 pTerm->wtFlags |= TERM_COPIED;
163893 assert( pWInfo->pTabList!=0 );
163894 if( termIsEquivalence(pParse, pDup, pWInfo->pTabList) ){
163895 pTerm->eOperator |= WO_EQUIV;
163896 eExtraOp = WO_EQUIV;
163897 }
163898 }else{
163899 pDup = pExpr;
@@ -164863,15 +165008,15 @@
165008 continue;
165009 }
165010 pScan->pWC = pWC;
165011 pScan->k = k+1;
165012 #ifdef WHERETRACE_ENABLED
165013 if( (sqlite3WhereTrace & 0x20000)!=0 && pScan->nEquiv>1 ){
165014 int ii;
165015 sqlite3DebugPrintf("EQUIVALENT TO {%d:%d} (due to TERM-%d):",
165016 pScan->aiCur[0], pScan->aiColumn[0], pTerm->iTerm);
165017 for(ii=1; ii<pScan->nEquiv; ii++){
165018 sqlite3DebugPrintf(" {%d:%d}",
165019 pScan->aiCur[ii], pScan->aiColumn[ii]);
165020 }
165021 sqlite3DebugPrintf("\n");
165022 }
@@ -166822,10 +166967,11 @@
166967 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166968 pTerm->u.pOrInfo->indexable);
166969 }else{
166970 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
166971 }
166972 iTerm = pTerm->iTerm = MAX(iTerm,pTerm->iTerm);
166973 sqlite3DebugPrintf(
166974 "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
166975 iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
166976 /* The 0x10000 .wheretrace flag causes extra information to be
166977 ** shown about each Term */
@@ -184446,10 +184592,11 @@
184592 #ifdef SQLITE_ENABLE_API_ARMOR
184593 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
184594 #endif
184595 if( ms<-1 ) return SQLITE_RANGE;
184596 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
184597 sqlite3_mutex_enter(db->mutex);
184598 db->setlkTimeout = ms;
184599 db->setlkFlags = flags;
184600 sqlite3BtreeEnterAll(db);
184601 for(iDb=0; iDb<db->nDb; iDb++){
184602 Btree *pBt = db->aDb[iDb].pBt;
@@ -184457,10 +184604,11 @@
184604 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
184605 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
184606 }
184607 }
184608 sqlite3BtreeLeaveAll(db);
184609 sqlite3_mutex_leave(db->mutex);
184610 #endif
184611 #if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
184612 UNUSED_PARAMETER(db);
184613 UNUSED_PARAMETER(flags);
184614 #endif
@@ -257253,11 +257401,11 @@
257401 int nArg, /* Number of args */
257402 sqlite3_value **apUnused /* Function arguments */
257403 ){
257404 assert( nArg==0 );
257405 UNUSED_PARAM2(nArg, apUnused);
257406 sqlite3_result_text(pCtx, "fts5: 2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d", -1, SQLITE_TRANSIENT);
257407 }
257408
257409 /*
257410 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257411 **
@@ -258068,10 +258216,11 @@
258216 ctx.pStorage = p;
258217 ctx.iCol = -1;
258218 for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258219 if( pConfig->abUnindexed[iCol-1]==0 ){
258220 sqlite3_value *pVal = 0;
258221 sqlite3_value *pFree = 0;
258222 const char *pText = 0;
258223 int nText = 0;
258224 const char *pLoc = 0;
258225 int nLoc = 0;
258226
@@ -258084,15 +258233,26 @@
258233 }
258234
258235 if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258236 rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258237 }else{
258238 if( sqlite3_value_type(pVal)!=SQLITE_TEXT ){
258239 /* Make a copy of the value to work with. This is because the call
258240 ** to sqlite3_value_text() below forces the type of the value to
258241 ** SQLITE_TEXT, and we may need to use it again later. */
258242 pFree = pVal = sqlite3_value_dup(pVal);
258243 if( pVal==0 ){
258244 rc = SQLITE_NOMEM;
258245 }
258246 }
258247 if( rc==SQLITE_OK ){
258248 pText = (const char*)sqlite3_value_text(pVal);
258249 nText = sqlite3_value_bytes(pVal);
258250 if( pConfig->bLocale && pSeek ){
258251 pLoc = (const char*)sqlite3_column_text(pSeek, iCol+pConfig->nCol);
258252 nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258253 }
258254 }
258255 }
258256
258257 if( rc==SQLITE_OK ){
258258 sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258104,10 +258264,11 @@
258264 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258265 rc = FTS5_CORRUPT;
258266 }
258267 sqlite3Fts5ClearLocale(pConfig);
258268 }
258269 sqlite3_value_free(pFree);
258270 }
258271 }
258272 if( rc==SQLITE_OK && p->nTotalRow<1 ){
258273 rc = FTS5_CORRUPT;
258274 }else{
258275
+16 -16
--- 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.51.0"
150150
#define SQLITE_VERSION_NUMBER 3051000
151
-#define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
151
+#define SQLITE_SOURCE_ID "2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -4077,11 +4077,11 @@
40774077
** These interfaces are provided for use by [VFS shim] implementations and
40784078
** are not useful outside of that context.
40794079
**
40804080
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
40814081
** database filename D with corresponding journal file J and WAL file W and
4082
-** with N URI parameters key/values pairs in the array P. The result from
4082
+** an array P of N URI Key/Value pairs. The result from
40834083
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
40844084
** is safe to pass to routines like:
40854085
** <ul>
40864086
** <li> [sqlite3_uri_parameter()],
40874087
** <li> [sqlite3_uri_boolean()],
@@ -4758,11 +4758,11 @@
47584758
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
47594759
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
47604760
** METHOD: sqlite3_stmt
47614761
**
47624762
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763
-** literals may be replaced by a [parameter] that matches one of following
4763
+** literals may be replaced by a [parameter] that matches one of the following
47644764
** templates:
47654765
**
47664766
** <ul>
47674767
** <li> ?
47684768
** <li> ?NNN
@@ -4803,11 +4803,11 @@
48034803
** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
48044804
** otherwise.
48054805
**
48064806
** [[byte-order determination rules]] ^The byte-order of
48074807
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808
-** found in first character, which is removed, or in the absence of a BOM
4808
+** found in the first character, which is removed, or in the absence of a BOM
48094809
** the byte order is the native byte order of the host
48104810
** machine for sqlite3_bind_text16() or the byte order specified in
48114811
** the 6th parameter for sqlite3_bind_text64().)^
48124812
** ^If UTF16 input text contains invalid unicode
48134813
** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
48234823
** the behavior is undefined.
48244824
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
48254825
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
48264826
** that parameter must be the byte offset
48274827
** where the NUL terminator would occur assuming the string were NUL
4828
-** terminated. If any NUL characters occurs at byte offsets less than
4828
+** terminated. If any NUL characters occur at byte offsets less than
48294829
** the value of the fourth parameter then the resulting string value will
48304830
** contain embedded NULs. The result of expressions involving strings
48314831
** with embedded NULs is undefined.
48324832
**
48334833
** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
50355035
/*
50365036
** CAPI3REF: Source Of Data In A Query Result
50375037
** METHOD: sqlite3_stmt
50385038
**
50395039
** ^These routines provide a means to determine the database, table, and
5040
-** table column that is the origin of a particular result column in
5040
+** table column that is the origin of a particular result column in a
50415041
** [SELECT] statement.
50425042
** ^The name of the database or table or column can be returned as
50435043
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
50445044
** the database name, the _table_ routines return the table name, and
50455045
** the origin_ routines return the column name.
@@ -5604,12 +5604,12 @@
56045604
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
56055605
** index expressions, or the WHERE clause of partial indexes.
56065606
**
56075607
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
56085608
** all application-defined SQL functions that do not need to be
5609
-** used inside of triggers, view, CHECK constraints, or other elements of
5610
-** the database schema. This flags is especially recommended for SQL
5609
+** used inside of triggers, views, CHECK constraints, or other elements of
5610
+** the database schema. This flag is especially recommended for SQL
56115611
** functions that have side effects or reveal internal application state.
56125612
** Without this flag, an attacker might be able to modify the schema of
56135613
** a database file to include invocations of the function with parameters
56145614
** chosen by the attacker, which the application will then execute when
56155615
** the database file is opened and read.
@@ -5636,11 +5636,11 @@
56365636
** or aggregate window function. More details regarding the implementation
56375637
** of aggregate window functions are
56385638
** [user-defined window functions|available here].
56395639
**
56405640
** ^(If the final parameter to sqlite3_create_function_v2() or
5641
-** sqlite3_create_window_function() is not NULL, then it is destructor for
5641
+** sqlite3_create_window_function() is not NULL, then it is the destructor for
56425642
** the application data pointer. The destructor is invoked when the function
56435643
** is deleted, either by being overloaded or when the database connection
56445644
** closes.)^ ^The destructor is also invoked if the call to
56455645
** sqlite3_create_function_v2() fails. ^When the destructor callback is
56465646
** invoked, it is passed a single argument which is a copy of the application
@@ -7444,11 +7444,11 @@
74447444
** that is to be automatically loaded into all new database connections.
74457445
**
74467446
** ^(Even though the function prototype shows that xEntryPoint() takes
74477447
** no arguments and returns void, SQLite invokes xEntryPoint() with three
74487448
** arguments and expects an integer result as if the signature of the
7449
-** entry point where as follows:
7449
+** entry point were as follows:
74507450
**
74517451
** <blockquote><pre>
74527452
** &nbsp; int xEntryPoint(
74537453
** &nbsp; sqlite3 *db,
74547454
** &nbsp; const char **pzErrMsg,
@@ -7775,11 +7775,11 @@
77757775
** by the first parameter. ^The name of the module is given by the
77767776
** second parameter. ^The third parameter is a pointer to
77777777
** the implementation of the [virtual table module]. ^The fourth
77787778
** parameter is an arbitrary client data pointer that is passed through
77797779
** into the [xCreate] and [xConnect] methods of the virtual table module
7780
-** when a new virtual table is be being created or reinitialized.
7780
+** when a new virtual table is being created or reinitialized.
77817781
**
77827782
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
77837783
** is a pointer to a destructor for the pClientData. ^SQLite will
77847784
** invoke the destructor function (if it is not NULL) when SQLite
77857785
** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
79407940
**
79417941
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
79427942
** in *ppBlob. Otherwise an [error code] is returned and, unless the error
79437943
** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
79447944
** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945
-** on *ppBlob after this function it returns.
7945
+** on *ppBlob after this function returns.
79467946
**
79477947
** This function fails with SQLITE_ERROR if any of the following are true:
79487948
** <ul>
79497949
** <li> ^(Database zDb does not exist)^,
79507950
** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
80608060
** CAPI3REF: Return The Size Of An Open BLOB
80618061
** METHOD: sqlite3_blob
80628062
**
80638063
** ^Returns the size in bytes of the BLOB accessible via the
80648064
** successfully opened [BLOB handle] in its only argument. ^The
8065
-** incremental blob I/O routines can only read or overwriting existing
8065
+** incremental blob I/O routines can only read or overwrite existing
80668066
** blob content; they cannot change the size of a blob.
80678067
**
80688068
** This routine only works on a [BLOB handle] which has been created
80698069
** by a prior successful call to [sqlite3_blob_open()] and which has not
80708070
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9463,11 +9463,11 @@
94639463
** sqlite3_backup_step(), the source database may be modified mid-way
94649464
** through the backup process. ^If the source database is modified by an
94659465
** external process or via a database connection other than the one being
94669466
** used by the backup operation, then the backup will be automatically
94679467
** restarted by the next call to sqlite3_backup_step(). ^If the source
9468
-** database is modified by the using the same database connection as is used
9468
+** database is modified by using the same database connection as is used
94699469
** by the backup operation, then the backup database is automatically
94709470
** updated at the same time.
94719471
**
94729472
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
94739473
**
@@ -9480,11 +9480,11 @@
94809480
** active write-transaction on the destination database is rolled back.
94819481
** The [sqlite3_backup] object is invalid
94829482
** and may not be used following a call to sqlite3_backup_finish().
94839483
**
94849484
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9485
-** sqlite3_backup_step() errors occurred, regardless or whether or not
9485
+** sqlite3_backup_step() errors occurred, regardless of whether or not
94869486
** sqlite3_backup_step() completed.
94879487
** ^If an out-of-memory condition or IO error occurred during any prior
94889488
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
94899489
** sqlite3_backup_finish() returns the corresponding [error code].
94909490
**
@@ -10550,11 +10550,11 @@
1055010550
/*
1055110551
** CAPI3REF: Flush caches to disk mid-transaction
1055210552
** METHOD: sqlite3
1055310553
**
1055410554
** ^If a write-transaction is open on [database connection] D when the
10555
-** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10555
+** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
1055610556
** pages in the pager-cache that are not currently in use are written out
1055710557
** to disk. A dirty page may be in use if a database cursor created by an
1055810558
** active SQL statement is reading from it, or if it is page 1 of a database
1055910559
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
1056010560
** interface flushes caches for all schemas - "main", "temp", and
1056110561
--- 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.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4077,11 +4077,11 @@
4077 ** These interfaces are provided for use by [VFS shim] implementations and
4078 ** are not useful outside of that context.
4079 **
4080 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4081 ** database filename D with corresponding journal file J and WAL file W and
4082 ** with N URI parameters key/values pairs in the array P. The result from
4083 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4084 ** is safe to pass to routines like:
4085 ** <ul>
4086 ** <li> [sqlite3_uri_parameter()],
4087 ** <li> [sqlite3_uri_boolean()],
@@ -4758,11 +4758,11 @@
4758 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4759 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4760 ** METHOD: sqlite3_stmt
4761 **
4762 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763 ** literals may be replaced by a [parameter] that matches one of following
4764 ** templates:
4765 **
4766 ** <ul>
4767 ** <li> ?
4768 ** <li> ?NNN
@@ -4803,11 +4803,11 @@
4803 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4804 ** otherwise.
4805 **
4806 ** [[byte-order determination rules]] ^The byte-order of
4807 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808 ** found in first character, which is removed, or in the absence of a BOM
4809 ** the byte order is the native byte order of the host
4810 ** machine for sqlite3_bind_text16() or the byte order specified in
4811 ** the 6th parameter for sqlite3_bind_text64().)^
4812 ** ^If UTF16 input text contains invalid unicode
4813 ** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
4823 ** the behavior is undefined.
4824 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4825 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4826 ** that parameter must be the byte offset
4827 ** where the NUL terminator would occur assuming the string were NUL
4828 ** terminated. If any NUL characters occurs at byte offsets less than
4829 ** the value of the fourth parameter then the resulting string value will
4830 ** contain embedded NULs. The result of expressions involving strings
4831 ** with embedded NULs is undefined.
4832 **
4833 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
5035 /*
5036 ** CAPI3REF: Source Of Data In A Query Result
5037 ** METHOD: sqlite3_stmt
5038 **
5039 ** ^These routines provide a means to determine the database, table, and
5040 ** table column that is the origin of a particular result column in
5041 ** [SELECT] statement.
5042 ** ^The name of the database or table or column can be returned as
5043 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5044 ** the database name, the _table_ routines return the table name, and
5045 ** the origin_ routines return the column name.
@@ -5604,12 +5604,12 @@
5604 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5605 ** index expressions, or the WHERE clause of partial indexes.
5606 **
5607 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5608 ** all application-defined SQL functions that do not need to be
5609 ** used inside of triggers, view, CHECK constraints, or other elements of
5610 ** the database schema. This flags is especially recommended for SQL
5611 ** functions that have side effects or reveal internal application state.
5612 ** Without this flag, an attacker might be able to modify the schema of
5613 ** a database file to include invocations of the function with parameters
5614 ** chosen by the attacker, which the application will then execute when
5615 ** the database file is opened and read.
@@ -5636,11 +5636,11 @@
5636 ** or aggregate window function. More details regarding the implementation
5637 ** of aggregate window functions are
5638 ** [user-defined window functions|available here].
5639 **
5640 ** ^(If the final parameter to sqlite3_create_function_v2() or
5641 ** sqlite3_create_window_function() is not NULL, then it is destructor for
5642 ** the application data pointer. The destructor is invoked when the function
5643 ** is deleted, either by being overloaded or when the database connection
5644 ** closes.)^ ^The destructor is also invoked if the call to
5645 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5646 ** invoked, it is passed a single argument which is a copy of the application
@@ -7444,11 +7444,11 @@
7444 ** that is to be automatically loaded into all new database connections.
7445 **
7446 ** ^(Even though the function prototype shows that xEntryPoint() takes
7447 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7448 ** arguments and expects an integer result as if the signature of the
7449 ** entry point where as follows:
7450 **
7451 ** <blockquote><pre>
7452 ** &nbsp; int xEntryPoint(
7453 ** &nbsp; sqlite3 *db,
7454 ** &nbsp; const char **pzErrMsg,
@@ -7775,11 +7775,11 @@
7775 ** by the first parameter. ^The name of the module is given by the
7776 ** second parameter. ^The third parameter is a pointer to
7777 ** the implementation of the [virtual table module]. ^The fourth
7778 ** parameter is an arbitrary client data pointer that is passed through
7779 ** into the [xCreate] and [xConnect] methods of the virtual table module
7780 ** when a new virtual table is be being created or reinitialized.
7781 **
7782 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
7783 ** is a pointer to a destructor for the pClientData. ^SQLite will
7784 ** invoke the destructor function (if it is not NULL) when SQLite
7785 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
7940 **
7941 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
7942 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
7943 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
7944 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945 ** on *ppBlob after this function it returns.
7946 **
7947 ** This function fails with SQLITE_ERROR if any of the following are true:
7948 ** <ul>
7949 ** <li> ^(Database zDb does not exist)^,
7950 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
8060 ** CAPI3REF: Return The Size Of An Open BLOB
8061 ** METHOD: sqlite3_blob
8062 **
8063 ** ^Returns the size in bytes of the BLOB accessible via the
8064 ** successfully opened [BLOB handle] in its only argument. ^The
8065 ** incremental blob I/O routines can only read or overwriting existing
8066 ** blob content; they cannot change the size of a blob.
8067 **
8068 ** This routine only works on a [BLOB handle] which has been created
8069 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8070 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9463,11 +9463,11 @@
9463 ** sqlite3_backup_step(), the source database may be modified mid-way
9464 ** through the backup process. ^If the source database is modified by an
9465 ** external process or via a database connection other than the one being
9466 ** used by the backup operation, then the backup will be automatically
9467 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9468 ** database is modified by the using the same database connection as is used
9469 ** by the backup operation, then the backup database is automatically
9470 ** updated at the same time.
9471 **
9472 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9473 **
@@ -9480,11 +9480,11 @@
9480 ** active write-transaction on the destination database is rolled back.
9481 ** The [sqlite3_backup] object is invalid
9482 ** and may not be used following a call to sqlite3_backup_finish().
9483 **
9484 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9485 ** sqlite3_backup_step() errors occurred, regardless or whether or not
9486 ** sqlite3_backup_step() completed.
9487 ** ^If an out-of-memory condition or IO error occurred during any prior
9488 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9489 ** sqlite3_backup_finish() returns the corresponding [error code].
9490 **
@@ -10550,11 +10550,11 @@
10550 /*
10551 ** CAPI3REF: Flush caches to disk mid-transaction
10552 ** METHOD: sqlite3
10553 **
10554 ** ^If a write-transaction is open on [database connection] D when the
10555 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10556 ** pages in the pager-cache that are not currently in use are written out
10557 ** to disk. A dirty page may be in use if a database cursor created by an
10558 ** active SQL statement is reading from it, or if it is page 1 of a database
10559 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10560 ** interface flushes caches for all schemas - "main", "temp", and
10561
--- 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.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4077,11 +4077,11 @@
4077 ** These interfaces are provided for use by [VFS shim] implementations and
4078 ** are not useful outside of that context.
4079 **
4080 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4081 ** database filename D with corresponding journal file J and WAL file W and
4082 ** an array P of N URI Key/Value pairs. The result from
4083 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4084 ** is safe to pass to routines like:
4085 ** <ul>
4086 ** <li> [sqlite3_uri_parameter()],
4087 ** <li> [sqlite3_uri_boolean()],
@@ -4758,11 +4758,11 @@
4758 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4759 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4760 ** METHOD: sqlite3_stmt
4761 **
4762 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763 ** literals may be replaced by a [parameter] that matches one of the following
4764 ** templates:
4765 **
4766 ** <ul>
4767 ** <li> ?
4768 ** <li> ?NNN
@@ -4803,11 +4803,11 @@
4803 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4804 ** otherwise.
4805 **
4806 ** [[byte-order determination rules]] ^The byte-order of
4807 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808 ** found in the first character, which is removed, or in the absence of a BOM
4809 ** the byte order is the native byte order of the host
4810 ** machine for sqlite3_bind_text16() or the byte order specified in
4811 ** the 6th parameter for sqlite3_bind_text64().)^
4812 ** ^If UTF16 input text contains invalid unicode
4813 ** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
4823 ** the behavior is undefined.
4824 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4825 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4826 ** that parameter must be the byte offset
4827 ** where the NUL terminator would occur assuming the string were NUL
4828 ** terminated. If any NUL characters occur at byte offsets less than
4829 ** the value of the fourth parameter then the resulting string value will
4830 ** contain embedded NULs. The result of expressions involving strings
4831 ** with embedded NULs is undefined.
4832 **
4833 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
5035 /*
5036 ** CAPI3REF: Source Of Data In A Query Result
5037 ** METHOD: sqlite3_stmt
5038 **
5039 ** ^These routines provide a means to determine the database, table, and
5040 ** table column that is the origin of a particular result column in a
5041 ** [SELECT] statement.
5042 ** ^The name of the database or table or column can be returned as
5043 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5044 ** the database name, the _table_ routines return the table name, and
5045 ** the origin_ routines return the column name.
@@ -5604,12 +5604,12 @@
5604 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5605 ** index expressions, or the WHERE clause of partial indexes.
5606 **
5607 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5608 ** all application-defined SQL functions that do not need to be
5609 ** used inside of triggers, views, CHECK constraints, or other elements of
5610 ** the database schema. This flag is especially recommended for SQL
5611 ** functions that have side effects or reveal internal application state.
5612 ** Without this flag, an attacker might be able to modify the schema of
5613 ** a database file to include invocations of the function with parameters
5614 ** chosen by the attacker, which the application will then execute when
5615 ** the database file is opened and read.
@@ -5636,11 +5636,11 @@
5636 ** or aggregate window function. More details regarding the implementation
5637 ** of aggregate window functions are
5638 ** [user-defined window functions|available here].
5639 **
5640 ** ^(If the final parameter to sqlite3_create_function_v2() or
5641 ** sqlite3_create_window_function() is not NULL, then it is the destructor for
5642 ** the application data pointer. The destructor is invoked when the function
5643 ** is deleted, either by being overloaded or when the database connection
5644 ** closes.)^ ^The destructor is also invoked if the call to
5645 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5646 ** invoked, it is passed a single argument which is a copy of the application
@@ -7444,11 +7444,11 @@
7444 ** that is to be automatically loaded into all new database connections.
7445 **
7446 ** ^(Even though the function prototype shows that xEntryPoint() takes
7447 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7448 ** arguments and expects an integer result as if the signature of the
7449 ** entry point were as follows:
7450 **
7451 ** <blockquote><pre>
7452 ** &nbsp; int xEntryPoint(
7453 ** &nbsp; sqlite3 *db,
7454 ** &nbsp; const char **pzErrMsg,
@@ -7775,11 +7775,11 @@
7775 ** by the first parameter. ^The name of the module is given by the
7776 ** second parameter. ^The third parameter is a pointer to
7777 ** the implementation of the [virtual table module]. ^The fourth
7778 ** parameter is an arbitrary client data pointer that is passed through
7779 ** into the [xCreate] and [xConnect] methods of the virtual table module
7780 ** when a new virtual table is being created or reinitialized.
7781 **
7782 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
7783 ** is a pointer to a destructor for the pClientData. ^SQLite will
7784 ** invoke the destructor function (if it is not NULL) when SQLite
7785 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
7940 **
7941 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
7942 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
7943 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
7944 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945 ** on *ppBlob after this function returns.
7946 **
7947 ** This function fails with SQLITE_ERROR if any of the following are true:
7948 ** <ul>
7949 ** <li> ^(Database zDb does not exist)^,
7950 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
8060 ** CAPI3REF: Return The Size Of An Open BLOB
8061 ** METHOD: sqlite3_blob
8062 **
8063 ** ^Returns the size in bytes of the BLOB accessible via the
8064 ** successfully opened [BLOB handle] in its only argument. ^The
8065 ** incremental blob I/O routines can only read or overwrite existing
8066 ** blob content; they cannot change the size of a blob.
8067 **
8068 ** This routine only works on a [BLOB handle] which has been created
8069 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8070 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -9463,11 +9463,11 @@
9463 ** sqlite3_backup_step(), the source database may be modified mid-way
9464 ** through the backup process. ^If the source database is modified by an
9465 ** external process or via a database connection other than the one being
9466 ** used by the backup operation, then the backup will be automatically
9467 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9468 ** database is modified by using the same database connection as is used
9469 ** by the backup operation, then the backup database is automatically
9470 ** updated at the same time.
9471 **
9472 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9473 **
@@ -9480,11 +9480,11 @@
9480 ** active write-transaction on the destination database is rolled back.
9481 ** The [sqlite3_backup] object is invalid
9482 ** and may not be used following a call to sqlite3_backup_finish().
9483 **
9484 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9485 ** sqlite3_backup_step() errors occurred, regardless of whether or not
9486 ** sqlite3_backup_step() completed.
9487 ** ^If an out-of-memory condition or IO error occurred during any prior
9488 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9489 ** sqlite3_backup_finish() returns the corresponding [error code].
9490 **
@@ -10550,11 +10550,11 @@
10550 /*
10551 ** CAPI3REF: Flush caches to disk mid-transaction
10552 ** METHOD: sqlite3
10553 **
10554 ** ^If a write-transaction is open on [database connection] D when the
10555 ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
10556 ** pages in the pager-cache that are not currently in use are written out
10557 ** to disk. A dirty page may be in use if a database cursor created by an
10558 ** active SQL statement is reading from it, or if it is page 1 of a database
10559 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10560 ** interface flushes caches for all schemas - "main", "temp", and
10561

Keyboard Shortcuts

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