Fossil SCM

Merge from trunk.

brickviking 2025-07-28 02:32 UTC bv-infotool merge
Commit 53010e9688857e0ea26ccc936aef470985d43fa1e78b3ec1b6fb125505f12ef7
73 files changed +442 -494 +1825 -961 +195 -150 +1 -1 +1 -1 +24 -11 +1 -1 +1 -1 +2 -2 +2 -2 +4 +1 -1 +1 -1 +7 -1 +2 -7 +11 -3 +1 -1 +5 -5 +5 -5 +6 -6 +4 -2 +1 -4 +11 +1 -1 +52 -22 +1 -1 +1 -1 +3 -3 +3 -3 +5 -3 +1 -2 +1 -1 +45 -22 +17 -7 +1 -1 +8 -5 +12 -4 +7 -4 +5 -5 +15 -2 +1 -1 +3 -3 +1 -1 +5 -3 +2 -2 +1 -1 +54 -12 +4 -4 +2 +5 -5 +2 -2 +2 -2 +5 -2 +1 -1 +59 -15 +110 -22 +82 +224 +68 +13 -7 +2 -2 +2 +2 +22 -6 +1 -1 +2 -2 +1 -1 +1 -1 +1 -1 +16 -18 +5 -1 +43 -27 +1 -1
+442 -494
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
12661266
return 0x3fffffff & (int)(z2 - z);
12671267
}
12681268
12691269
/*
12701270
** Return the length of a string in characters. Multibyte UTF8 characters
1271
-** count as a single character.
1271
+** count as a single character for single-width characters, or as two
1272
+** characters for double-width characters.
12721273
*/
12731274
static int strlenChar(const char *z){
12741275
int n = 0;
12751276
while( *z ){
1276
- if( (0xc0&*(z++))!=0x80 ) n++;
1277
+ if( (0x80&z[0])==0 ){
1278
+ n++;
1279
+ z++;
1280
+ }else{
1281
+ int u = 0;
1282
+ int len = decodeUtf8((const u8*)z, &u);
1283
+ z += len;
1284
+ n += cli_wcwidth(u);
1285
+ }
12771286
}
12781287
return n;
12791288
}
12801289
12811290
/*
@@ -1704,369 +1713,176 @@
17041713
** work here in the middle of this regular program.
17051714
*/
17061715
#define SQLITE_EXTENSION_INIT1
17071716
#define SQLITE_EXTENSION_INIT2(X) (void)(X)
17081717
1709
-#if defined(_WIN32) && defined(_MSC_VER)
1710
-/************************* Begin test_windirent.h ******************/
1718
+/************************* Begin ../ext/misc/windirent.h ******************/
17111719
/*
1712
-** 2015 November 30
1720
+** 2025-06-05
17131721
**
17141722
** The author disclaims copyright to this source code. In place of
17151723
** a legal notice, here is a blessing:
17161724
**
17171725
** May you do good and not evil.
17181726
** May you find forgiveness for yourself and forgive others.
17191727
** May you share freely, never taking more than you give.
17201728
**
17211729
*************************************************************************
1722
-** This file contains declarations for most of the opendir() family of
1723
-** 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.
17241739
*/
1725
-
17261740
#if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
17271741
#define SQLITE_WINDIRENT_H
17281742
1729
-/*
1730
-** We need several data types from the Windows SDK header.
1731
-*/
1732
-
17331743
#ifndef WIN32_LEAN_AND_MEAN
17341744
#define WIN32_LEAN_AND_MEAN
17351745
#endif
1736
-
1737
-#include "windows.h"
1738
-
1739
-/*
1740
-** We need several support functions from the SQLite core.
1741
-*/
1742
-
1743
-/* #include "sqlite3.h" */
1744
-
1745
-/*
1746
-** We need several things from the ANSI and MSVCRT headers.
1747
-*/
1748
-
1746
+#include <windows.h>
1747
+#include <io.h>
17491748
#include <stdio.h>
17501749
#include <stdlib.h>
17511750
#include <errno.h>
1752
-#include <io.h>
17531751
#include <limits.h>
17541752
#include <sys/types.h>
17551753
#include <sys/stat.h>
1756
-
1757
-/*
1758
-** We may need several defines that should have been in "sys/stat.h".
1759
-*/
1760
-
1761
-#ifndef S_ISREG
1762
-#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
1763
-#endif
1764
-
1765
-#ifndef S_ISDIR
1766
-#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
1767
-#endif
1768
-
1769
-#ifndef S_ISLNK
1770
-#define S_ISLNK(mode) (0)
1771
-#endif
1772
-
1773
-/*
1774
-** We may need to provide the "mode_t" type.
1775
-*/
1776
-
1777
-#ifndef MODE_T_DEFINED
1778
- #define MODE_T_DEFINED
1779
- typedef unsigned short mode_t;
1780
-#endif
1781
-
1782
-/*
1783
-** We may need to provide the "ino_t" type.
1784
-*/
1785
-
1786
-#ifndef INO_T_DEFINED
1787
- #define INO_T_DEFINED
1788
- typedef unsigned short ino_t;
1789
-#endif
1790
-
1791
-/*
1792
-** We need to define "NAME_MAX" if it was not present in "limits.h".
1793
-*/
1794
-
1795
-#ifndef NAME_MAX
1796
-# ifdef FILENAME_MAX
1797
-# define NAME_MAX (FILENAME_MAX)
1798
-# else
1799
-# define NAME_MAX (260)
1800
-# endif
1801
-#endif
1802
-
1803
-/*
1804
-** We need to define "NULL_INTPTR_T" and "BAD_INTPTR_T".
1805
-*/
1806
-
1807
-#ifndef NULL_INTPTR_T
1808
-# define NULL_INTPTR_T ((intptr_t)(0))
1809
-#endif
1810
-
1811
-#ifndef BAD_INTPTR_T
1812
-# define BAD_INTPTR_T ((intptr_t)(-1))
1813
-#endif
1814
-
1815
-/*
1816
-** We need to provide the necessary structures and related types.
1817
-*/
1818
-
1819
-#ifndef DIRENT_DEFINED
1820
-#define DIRENT_DEFINED
1821
-typedef struct DIRENT DIRENT;
1822
-typedef DIRENT *LPDIRENT;
1823
-struct DIRENT {
1824
- ino_t d_ino; /* Sequence number, do not use. */
1825
- unsigned d_attributes; /* Win32 file attributes. */
1826
- char d_name[NAME_MAX + 1]; /* Name within the directory. */
1827
-};
1828
-#endif
1829
-
1830
-#ifndef DIR_DEFINED
1831
-#define DIR_DEFINED
1832
-typedef struct DIR DIR;
1833
-typedef DIR *LPDIR;
1834
-struct DIR {
1835
- intptr_t d_handle; /* Value returned by "_findfirst". */
1836
- DIRENT d_first; /* DIRENT constructed based on "_findfirst". */
1837
- DIRENT d_next; /* DIRENT constructed based on "_findnext". */
1838
-};
1839
-#endif
1840
-
1841
-/*
1842
-** Provide a macro, for use by the implementation, to determine if a
1843
-** particular directory entry should be skipped over when searching for
1844
-** the next directory entry that should be returned by the readdir() or
1845
-** readdir_r() functions.
1846
-*/
1847
-
1848
-#ifndef is_filtered
1849
-# define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1850
-#endif
1851
-
1852
-/*
1853
-** Provide the function prototype for the POSIX compatible getenv()
1854
-** function. This function is not thread-safe.
1855
-*/
1856
-
1857
-extern const char *windirent_getenv(const char *name);
1858
-
1859
-/*
1860
-** Finally, we can provide the function prototypes for the opendir(),
1861
-** readdir(), readdir_r(), and closedir() POSIX functions.
1862
-*/
1863
-
1864
-extern LPDIR opendir(const char *dirname);
1865
-extern LPDIRENT readdir(LPDIR dirp);
1866
-extern INT readdir_r(LPDIR dirp, LPDIRENT entry, LPDIRENT *result);
1867
-extern INT closedir(LPDIR dirp);
1868
-
1869
-#endif /* defined(WIN32) && defined(_MSC_VER) */
1870
-
1871
-/************************* End test_windirent.h ********************/
1872
-/************************* Begin test_windirent.c ******************/
1873
-/*
1874
-** 2015 November 30
1875
-**
1876
-** The author disclaims copyright to this source code. In place of
1877
-** a legal notice, here is a blessing:
1878
-**
1879
-** May you do good and not evil.
1880
-** May you find forgiveness for yourself and forgive others.
1881
-** May you share freely, never taking more than you give.
1882
-**
1883
-*************************************************************************
1884
-** This file contains code to implement most of the opendir() family of
1885
-** POSIX functions on Win32 using the MSVCRT.
1886
-*/
1887
-
1888
-#if defined(_WIN32) && defined(_MSC_VER)
1889
-/* #include "test_windirent.h" */
1890
-
1891
-/*
1892
-** Implementation of the POSIX getenv() function using the Win32 API.
1893
-** This function is not thread-safe.
1894
-*/
1895
-const char *windirent_getenv(
1896
- const char *name
1897
-){
1898
- static char value[32768]; /* Maximum length, per MSDN */
1899
- DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
1900
- DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
1901
-
1902
- memset(value, 0, sizeof(value));
1903
- dwRet = GetEnvironmentVariableA(name, value, dwSize);
1904
- if( dwRet==0 || dwRet>dwSize ){
1905
- /*
1906
- ** The function call to GetEnvironmentVariableA() failed -OR-
1907
- ** the buffer is not large enough. Either way, return NULL.
1908
- */
1909
- return 0;
1910
- }else{
1911
- /*
1912
- ** The function call to GetEnvironmentVariableA() succeeded
1913
- ** -AND- the buffer contains the entire value.
1914
- */
1915
- return value;
1916
- }
1917
-}
1918
-
1919
-/*
1920
-** Implementation of the POSIX opendir() function using the MSVCRT.
1921
-*/
1922
-LPDIR opendir(
1923
- const char *dirname
1924
-){
1925
- struct _finddata_t data;
1926
- LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
1927
- SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
1928
-
1929
- if( dirp==NULL ) return NULL;
1930
- memset(dirp, 0, sizeof(DIR));
1931
-
1932
- /* TODO: Remove this if Unix-style root paths are not used. */
1933
- if( sqlite3_stricmp(dirname, "/")==0 ){
1934
- dirname = windirent_getenv("SystemDrive");
1935
- }
1936
-
1937
- memset(&data, 0, sizeof(struct _finddata_t));
1938
- _snprintf(data.name, namesize, "%s\\*", dirname);
1939
- dirp->d_handle = _findfirst(data.name, &data);
1940
-
1941
- if( dirp->d_handle==BAD_INTPTR_T ){
1942
- closedir(dirp);
1943
- return NULL;
1944
- }
1945
-
1946
- /* TODO: Remove this block to allow hidden and/or system files. */
1947
- if( is_filtered(data) ){
1948
-next:
1949
-
1950
- memset(&data, 0, sizeof(struct _finddata_t));
1951
- if( _findnext(dirp->d_handle, &data)==-1 ){
1952
- closedir(dirp);
1953
- return NULL;
1954
- }
1955
-
1956
- /* TODO: Remove this block to allow hidden and/or system files. */
1957
- if( is_filtered(data) ) goto next;
1958
- }
1959
-
1960
- dirp->d_first.d_attributes = data.attrib;
1961
- strncpy(dirp->d_first.d_name, data.name, NAME_MAX);
1962
- dirp->d_first.d_name[NAME_MAX] = '\0';
1963
-
1964
- return dirp;
1965
-}
1966
-
1967
-/*
1968
-** Implementation of the POSIX readdir() function using the MSVCRT.
1969
-*/
1970
-LPDIRENT readdir(
1971
- LPDIR dirp
1972
-){
1973
- struct _finddata_t data;
1974
-
1975
- if( dirp==NULL ) return NULL;
1976
-
1977
- if( dirp->d_first.d_ino==0 ){
1978
- dirp->d_first.d_ino++;
1979
- dirp->d_next.d_ino++;
1980
-
1981
- return &dirp->d_first;
1982
- }
1983
-
1984
-next:
1985
-
1986
- memset(&data, 0, sizeof(struct _finddata_t));
1987
- if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;
1988
-
1989
- /* TODO: Remove this block to allow hidden and/or system files. */
1990
- if( is_filtered(data) ) goto next;
1991
-
1992
- dirp->d_next.d_ino++;
1993
- dirp->d_next.d_attributes = data.attrib;
1994
- strncpy(dirp->d_next.d_name, data.name, NAME_MAX);
1995
- dirp->d_next.d_name[NAME_MAX] = '\0';
1996
-
1997
- return &dirp->d_next;
1998
-}
1999
-
2000
-/*
2001
-** Implementation of the POSIX readdir_r() function using the MSVCRT.
2002
-*/
2003
-INT readdir_r(
2004
- LPDIR dirp,
2005
- LPDIRENT entry,
2006
- LPDIRENT *result
2007
-){
2008
- struct _finddata_t data;
2009
-
2010
- if( dirp==NULL ) return EBADF;
2011
-
2012
- if( dirp->d_first.d_ino==0 ){
2013
- dirp->d_first.d_ino++;
2014
- dirp->d_next.d_ino++;
2015
-
2016
- entry->d_ino = dirp->d_first.d_ino;
2017
- entry->d_attributes = dirp->d_first.d_attributes;
2018
- strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX);
2019
- entry->d_name[NAME_MAX] = '\0';
2020
-
2021
- *result = entry;
2022
- return 0;
2023
- }
2024
-
2025
-next:
2026
-
2027
- memset(&data, 0, sizeof(struct _finddata_t));
2028
- if( _findnext(dirp->d_handle, &data)==-1 ){
2029
- *result = NULL;
2030
- return ENOENT;
2031
- }
2032
-
2033
- /* TODO: Remove this block to allow hidden and/or system files. */
2034
- if( is_filtered(data) ) goto next;
2035
-
2036
- entry->d_ino = (ino_t)-1; /* not available */
2037
- entry->d_attributes = data.attrib;
2038
- strncpy(entry->d_name, data.name, NAME_MAX);
2039
- entry->d_name[NAME_MAX] = '\0';
2040
-
2041
- *result = entry;
2042
- return 0;
2043
-}
2044
-
2045
-/*
2046
-** Implementation of the POSIX closedir() function using the MSVCRT.
2047
-*/
2048
-INT closedir(
2049
- LPDIR dirp
2050
-){
2051
- INT result = 0;
2052
-
2053
- if( dirp==NULL ) return EINVAL;
2054
-
2055
- if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
2056
- result = _findclose(dirp->d_handle);
2057
- }
2058
-
2059
- sqlite3_free(dirp);
2060
- return result;
2061
-}
2062
-
2063
-#endif /* defined(WIN32) && defined(_MSC_VER) */
2064
-
2065
-/************************* End test_windirent.c ********************/
2066
-#define dirent DIRENT
2067
-#endif
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 ********************/
20681884
/************************* Begin ../ext/misc/memtrace.c ******************/
20691885
/*
20701886
** 2019-01-21
20711887
**
20721888
** The author disclaims copyright to this source code. In place of
@@ -8030,10 +7846,11 @@
80307846
** mode: Value of stat.st_mode for directory entry (an integer).
80317847
** mtime: Value of stat.st_mtime for directory entry (an integer).
80327848
** data: For a regular file, a blob containing the file data. For a
80337849
** symlink, a text value containing the text of the link. For a
80347850
** directory, NULL.
7851
+** level: Directory hierarchy level. Topmost is 1.
80357852
**
80367853
** If a non-NULL value is specified for the optional $dir parameter and
80377854
** $path is a relative path, then $path is interpreted relative to $dir.
80387855
** And the paths returned in the "name" column of the table are also
80397856
** relative to directory $dir.
@@ -8055,24 +7872,17 @@
80557872
#if !defined(_WIN32) && !defined(WIN32)
80567873
# include <unistd.h>
80577874
# include <dirent.h>
80587875
# include <utime.h>
80597876
# include <sys/time.h>
7877
+# define STRUCT_STAT struct stat
80607878
#else
8061
-# include "windows.h"
8062
-# include <io.h>
7879
+/* # include "windirent.h" */
80637880
# include <direct.h>
8064
-/* # include "test_windirent.h" */
8065
-# define dirent DIRENT
8066
-# ifndef chmod
8067
-# define chmod _chmod
8068
-# endif
8069
-# ifndef stat
8070
-# define stat _stat
8071
-# endif
8072
-# define mkdir(path,mode) _mkdir(path)
8073
-# define lstat(path,buf) stat(path,buf)
7881
+# define STRUCT_STAT struct _stat
7882
+# define chmod(path,mode) fileio_chmod(path,mode)
7883
+# define mkdir(path,mode) fileio_mkdir(path)
80747884
#endif
80757885
#include <time.h>
80767886
#include <errno.h>
80777887
80787888
/* When used as part of the CLI, the sqlite3_stdio.h module will have
@@ -8084,18 +7894,54 @@
80847894
#endif
80857895
80867896
/*
80877897
** Structure of the fsdir() table-valued function
80887898
*/
8089
- /* 0 1 2 3 4 5 */
8090
-#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
+
80917902
#define FSDIR_COLUMN_NAME 0 /* Name of the file */
80927903
#define FSDIR_COLUMN_MODE 1 /* Access mode */
80937904
#define FSDIR_COLUMN_MTIME 2 /* Last modification time */
80947905
#define FSDIR_COLUMN_DATA 3 /* File content */
8095
-#define FSDIR_COLUMN_PATH 4 /* Path to top of search */
8096
-#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 */
7909
+
7910
+/*
7911
+** UTF8 chmod() function for Windows
7912
+*/
7913
+#if defined(_WIN32) || defined(WIN32)
7914
+static int fileio_chmod(const char *zPath, int pmode){
7915
+ sqlite3_int64 sz = strlen(zPath);
7916
+ wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
7917
+ int rc;
7918
+ if( b1==0 ) return -1;
7919
+ sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
7920
+ b1[sz] = 0;
7921
+ rc = _wchmod(b1, pmode);
7922
+ sqlite3_free(b1);
7923
+ return rc;
7924
+}
7925
+#endif
7926
+
7927
+/*
7928
+** UTF8 mkdir() function for Windows
7929
+*/
7930
+#if defined(_WIN32) || defined(WIN32)
7931
+static int fileio_mkdir(const char *zPath){
7932
+ sqlite3_int64 sz = strlen(zPath);
7933
+ wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
7934
+ int rc;
7935
+ if( b1==0 ) return -1;
7936
+ sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
7937
+ b1[sz] = 0;
7938
+ rc = _wmkdir(b1);
7939
+ sqlite3_free(b1);
7940
+ return rc;
7941
+}
7942
+#endif
80977943
80987944
80997945
/*
81007946
** Set the result stored by context ctx to a blob containing the
81017947
** contents of file zName. Or, leave the result unchanged (NULL)
@@ -8223,11 +8069,11 @@
82238069
** buffer to UTC. This is necessary on Win32, where the runtime library
82248070
** appears to return these values as local times.
82258071
*/
82268072
static void statTimesToUtc(
82278073
const char *zPath,
8228
- struct stat *pStatBuf
8074
+ STRUCT_STAT *pStatBuf
82298075
){
82308076
HANDLE hFindFile;
82318077
WIN32_FIND_DATAW fd;
82328078
LPWSTR zUnicodeName;
82338079
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
@@ -8251,14 +8097,20 @@
82518097
** is required in order for the included time to be returned as UTC. On all
82528098
** other systems, this function simply calls stat().
82538099
*/
82548100
static int fileStat(
82558101
const char *zPath,
8256
- struct stat *pStatBuf
8102
+ STRUCT_STAT *pStatBuf
82578103
){
82588104
#if defined(_WIN32)
8259
- int rc = stat(zPath, pStatBuf);
8105
+ sqlite3_int64 sz = strlen(zPath);
8106
+ wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
8107
+ int rc;
8108
+ if( b1==0 ) return 1;
8109
+ sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
8110
+ b1[sz] = 0;
8111
+ rc = _wstat(b1, pStatBuf);
82608112
if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
82618113
return rc;
82628114
#else
82638115
return stat(zPath, pStatBuf);
82648116
#endif
@@ -8269,16 +8121,14 @@
82698121
** is required in order for the included time to be returned as UTC. On all
82708122
** other systems, this function simply calls lstat().
82718123
*/
82728124
static int fileLinkStat(
82738125
const char *zPath,
8274
- struct stat *pStatBuf
8126
+ STRUCT_STAT *pStatBuf
82758127
){
82768128
#if defined(_WIN32)
8277
- int rc = lstat(zPath, pStatBuf);
8278
- if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
8279
- return rc;
8129
+ return fileStat(zPath, pStatBuf);
82808130
#else
82818131
return lstat(zPath, pStatBuf);
82828132
#endif
82838133
}
82848134
@@ -8304,11 +8154,11 @@
83048154
}else{
83058155
int nCopy = (int)strlen(zCopy);
83068156
int i = 1;
83078157
83088158
while( rc==SQLITE_OK ){
8309
- struct stat sStat;
8159
+ STRUCT_STAT sStat;
83108160
int rc2;
83118161
83128162
for(; zCopy[i]!='/' && i<nCopy; i++);
83138163
if( i==nCopy ) break;
83148164
zCopy[i] = '\0';
@@ -8354,11 +8204,11 @@
83548204
if( mkdir(zFile, mode) ){
83558205
/* The mkdir() call to create the directory failed. This might not
83568206
** be an error though - if there is already a directory at the same
83578207
** path and either the permissions already match or can be changed
83588208
** to do so using chmod(), it is not an error. */
8359
- struct stat sStat;
8209
+ STRUCT_STAT sStat;
83608210
if( errno!=EEXIST
83618211
|| 0!=fileStat(zFile, &sStat)
83628212
|| !S_ISDIR(sStat.st_mode)
83638213
|| ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
83648214
){
@@ -8550,17 +8400,18 @@
85508400
85518401
struct fsdir_cursor {
85528402
sqlite3_vtab_cursor base; /* Base class - must be first */
85538403
85548404
int nLvl; /* Number of entries in aLvl[] array */
8405
+ int mxLvl; /* Maximum level */
85558406
int iLvl; /* Index of current entry */
85568407
FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
85578408
85588409
const char *zBase;
85598410
int nBase;
85608411
8561
- struct stat sStat; /* Current lstat() results */
8412
+ STRUCT_STAT sStat; /* Current lstat() results */
85628413
char *zPath; /* Path to current entry */
85638414
sqlite3_int64 iRowid; /* Current rowid */
85648415
};
85658416
85668417
typedef struct fsdir_tab fsdir_tab;
@@ -8668,11 +8519,11 @@
86688519
static int fsdirNext(sqlite3_vtab_cursor *cur){
86698520
fsdir_cursor *pCur = (fsdir_cursor*)cur;
86708521
mode_t m = pCur->sStat.st_mode;
86718522
86728523
pCur->iRowid++;
8673
- if( S_ISDIR(m) ){
8524
+ if( S_ISDIR(m) && pCur->iLvl+3<pCur->mxLvl ){
86748525
/* Descend into this directory */
86758526
int iNew = pCur->iLvl + 1;
86768527
FsdirLevel *pLvl;
86778528
if( iNew>=pCur->nLvl ){
86788529
int nNew = iNew+1;
@@ -8776,11 +8627,15 @@
87768627
if( aBuf!=aStatic ) sqlite3_free(aBuf);
87778628
#endif
87788629
}else{
87798630
readFileContents(ctx, pCur->zPath);
87808631
}
8632
+ break;
87818633
}
8634
+ case FSDIR_COLUMN_LEVEL:
8635
+ sqlite3_result_int(ctx, pCur->iLvl+2);
8636
+ break;
87828637
case FSDIR_COLUMN_PATH:
87838638
default: {
87848639
/* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
87858640
** always return their values as NULL */
87868641
break;
@@ -8810,36 +8665,50 @@
88108665
}
88118666
88128667
/*
88138668
** xFilter callback.
88148669
**
8815
-** idxNum==1 PATH parameter only
8816
-** 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
88178675
*/
88188676
static int fsdirFilter(
88198677
sqlite3_vtab_cursor *cur,
88208678
int idxNum, const char *idxStr,
88218679
int argc, sqlite3_value **argv
88228680
){
88238681
const char *zDir = 0;
88248682
fsdir_cursor *pCur = (fsdir_cursor*)cur;
8683
+ int i;
88258684
(void)idxStr;
88268685
fsdirResetCursor(pCur);
88278686
88288687
if( idxNum==0 ){
88298688
fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
88308689
return SQLITE_ERROR;
88318690
}
88328691
8833
- assert( argc==idxNum && (argc==1 || argc==2) );
8692
+ assert( (idxNum & 0x01)!=0 && argc>0 );
88348693
zDir = (const char*)sqlite3_value_text(argv[0]);
88358694
if( zDir==0 ){
88368695
fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
88378696
return SQLITE_ERROR;
88388697
}
8839
- if( argc==2 ){
8840
- 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;
88418710
}
88428711
if( pCur->zBase ){
88438712
pCur->nBase = (int)strlen(pCur->zBase)+1;
88448713
pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
88458714
}else{
@@ -8864,48 +8733,75 @@
88648733
** plan.
88658734
**
88668735
** In this implementation idxNum is used to represent the
88678736
** query plan. idxStr is unused.
88688737
**
8869
-** The query plan is represented by values of idxNum:
8738
+** The query plan is represented by bits in idxNum:
88708739
**
8871
-** (1) The path value is supplied by argv[0]
8872
-** (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]
88738743
*/
88748744
static int fsdirBestIndex(
88758745
sqlite3_vtab *tab,
88768746
sqlite3_index_info *pIdxInfo
88778747
){
88788748
int i; /* Loop over constraints */
88798749
int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
88808750
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 */
88818754
int seenPath = 0; /* True if an unusable PATH= constraint is seen */
88828755
int seenDir = 0; /* True if an unusable DIR= constraint is seen */
88838756
const struct sqlite3_index_constraint *pConstraint;
88848757
88858758
(void)tab;
88868759
pConstraint = pIdxInfo->aConstraint;
88878760
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8888
- if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
8889
- switch( pConstraint->iColumn ){
8890
- case FSDIR_COLUMN_PATH: {
8891
- if( pConstraint->usable ){
8892
- idxPath = i;
8893
- seenPath = 0;
8894
- }else if( idxPath<0 ){
8895
- seenPath = 1;
8896
- }
8897
- break;
8898
- }
8899
- case FSDIR_COLUMN_DIR: {
8900
- if( pConstraint->usable ){
8901
- idxDir = i;
8902
- seenDir = 0;
8903
- }else if( idxDir<0 ){
8904
- seenDir = 1;
8905
- }
8906
- 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;
89078803
}
89088804
}
89098805
}
89108806
if( seenPath || seenDir ){
89118807
/* If input parameters are unusable, disallow this plan */
@@ -8918,18 +8814,24 @@
89188814
** number. Leave it unchanged. */
89198815
pIdxInfo->estimatedRows = 0x7fffffff;
89208816
}else{
89218817
pIdxInfo->aConstraintUsage[idxPath].omit = 1;
89228818
pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
8819
+ pIdxInfo->idxNum = 0x01;
8820
+ pIdxInfo->estimatedCost = 1.0e9;
8821
+ i = 2;
89238822
if( idxDir>=0 ){
89248823
pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8925
- pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
8926
- pIdxInfo->idxNum = 2;
8927
- pIdxInfo->estimatedCost = 10.0;
8928
- }else{
8929
- pIdxInfo->idxNum = 1;
8930
- 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;
89318833
}
89328834
}
89338835
89348836
return SQLITE_OK;
89358837
}
@@ -16784,11 +16686,11 @@
1678416686
case SQLITE_FCNTL_POWERSAFE_OVERWRITE: zOp = "POWERSAFE_OVERWRITE"; break;
1678516687
case SQLITE_FCNTL_PRAGMA: {
1678616688
const char *const* a = (const char*const*)pArg;
1678716689
if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){
1678816690
const u8 *zArg = (const u8*)a[2];
16789
- if( zArg[0]>='0' && zArg[0]<=9 ){
16691
+ if( zArg[0]>='0' && zArg[0]<='9' ){
1679016692
pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0);
1679116693
}else{
1679216694
static const struct {
1679316695
const char *z;
1679416696
unsigned int m;
@@ -25571,107 +25473,108 @@
2557125473
" --plain Show results as text/plain, not as HTML",
2557225474
#endif
2557325475
};
2557425476
2557525477
/*
25576
-** Output help text.
25478
+** Output help text for commands that match zPattern.
25479
+**
25480
+** * If zPattern is NULL, then show all documented commands, but
25481
+** only give a one-line summary of each.
25482
+**
25483
+** * If zPattern is "-a" or "-all" or "--all" then show all help text
25484
+** for all commands except undocumented commands.
25485
+**
25486
+** * If zPattern is "0" then show all help for undocumented commands.
25487
+** Undocumented commands begin with "," instead of "." in the azHelp[]
25488
+** array.
25489
+**
25490
+** * If zPattern is a prefix for one or more documented commands, then
25491
+** show help for those commands. If only a single command matches the
25492
+** prefix, show the full text of the help. If multiple commands match,
25493
+** Only show just the first line of each.
2557725494
**
25578
-** zPattern describes the set of commands for which help text is provided.
25579
-** If zPattern is NULL, then show all commands, but only give a one-line
25580
-** description of each.
25495
+** * Otherwise, show the complete text of any documented command for which
25496
+** zPattern is a LIKE match for any text within that command help
25497
+** text.
2558125498
**
25582
-** Return the number of matches.
25499
+** Return the number commands that match zPattern.
2558325500
*/
2558425501
static int showHelp(FILE *out, const char *zPattern){
2558525502
int i = 0;
2558625503
int j = 0;
2558725504
int n = 0;
2558825505
char *zPat;
25589
- if( zPattern==0
25590
- || zPattern[0]=='0'
25591
- || cli_strcmp(zPattern,"-a")==0
25592
- || cli_strcmp(zPattern,"-all")==0
25593
- || cli_strcmp(zPattern,"--all")==0
25594
- ){
25595
- enum HelpWanted { HW_NoCull = 0, HW_SummaryOnly = 1, HW_Undoc = 2 };
25596
- enum HelpHave { HH_Undoc = 2, HH_Summary = 1, HH_More = 0 };
25597
- /* Show all or most commands
25598
- ** *zPattern==0 => summary of documented commands only
25599
- ** *zPattern=='0' => whole help for undocumented commands
25600
- ** Otherwise => whole help for documented commands
25601
- */
25602
- enum HelpWanted hw = HW_SummaryOnly;
25603
- enum HelpHave hh = HH_More;
25604
- if( zPattern!=0 ){
25605
- hw = (*zPattern=='0')? HW_NoCull|HW_Undoc : HW_NoCull;
25606
- }
25607
- for(i=0; i<ArraySize(azHelp); i++){
25608
- switch( azHelp[i][0] ){
25609
- case ',':
25610
- hh = HH_Summary|HH_Undoc;
25611
- break;
25612
- case '.':
25613
- hh = HH_Summary;
25614
- break;
25615
- default:
25616
- hh &= ~HH_Summary;
25617
- break;
25618
- }
25619
- if( ((hw^hh)&HH_Undoc)==0 ){
25620
- if( (hh&HH_Summary)!=0 ){
25621
- sqlite3_fprintf(out, ".%s\n", azHelp[i]+1);
25622
- ++n;
25623
- }else if( (hw&HW_SummaryOnly)==0 ){
25624
- sqlite3_fprintf(out, "%s\n", azHelp[i]);
25625
- }
25626
- }
25627
- }
25628
- }else{
25629
- /* Seek documented commands for which zPattern is an exact prefix */
25630
- zPat = sqlite3_mprintf(".%s*", zPattern);
25631
- shell_check_oom(zPat);
25632
- for(i=0; i<ArraySize(azHelp); i++){
25633
- if( sqlite3_strglob(zPat, azHelp[i])==0 ){
25634
- sqlite3_fprintf(out, "%s\n", azHelp[i]);
25635
- j = i+1;
25636
- n++;
25637
- }
25638
- }
25639
- sqlite3_free(zPat);
25640
- if( n ){
25641
- if( n==1 ){
25642
- /* when zPattern is a prefix of exactly one command, then include
25643
- ** the details of that command, which should begin at offset j */
25644
- while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
25645
- sqlite3_fprintf(out, "%s\n", azHelp[j]);
25646
- j++;
25647
- }
25648
- }
25649
- return n;
25650
- }
25651
- /* Look for documented commands that contain zPattern anywhere.
25652
- ** Show complete text of all documented commands that match. */
25653
- zPat = sqlite3_mprintf("%%%s%%", zPattern);
25654
- shell_check_oom(zPat);
25655
- for(i=0; i<ArraySize(azHelp); i++){
25656
- if( azHelp[i][0]==',' ){
25657
- while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
25658
- continue;
25659
- }
25660
- if( azHelp[i][0]=='.' ) j = i;
25661
- if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
25662
- sqlite3_fprintf(out, "%s\n", azHelp[j]);
25663
- while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
25664
- j++;
25665
- sqlite3_fprintf(out, "%s\n", azHelp[j]);
25666
- }
25667
- i = j;
25668
- n++;
25669
- }
25670
- }
25671
- sqlite3_free(zPat);
25672
- }
25506
+ if( zPattern==0 ){
25507
+ /* Show just the first line for all help topics */
25508
+ zPattern = "[a-z]";
25509
+ }else if( cli_strcmp(zPattern,"-a")==0
25510
+ || cli_strcmp(zPattern,"-all")==0
25511
+ || cli_strcmp(zPattern,"--all")==0
25512
+ ){
25513
+ /* Show everything except undocumented commands */
25514
+ zPattern = ".";
25515
+ }else if( cli_strcmp(zPattern,"0")==0 ){
25516
+ /* Show complete help text of undocumented commands */
25517
+ int show = 0;
25518
+ for(i=0; i<ArraySize(azHelp); i++){
25519
+ if( azHelp[i][0]=='.' ){
25520
+ show = 0;
25521
+ }else if( azHelp[i][0]==',' ){
25522
+ show = 1;
25523
+ sqlite3_fprintf(out, ".%s\n", &azHelp[i][1]);
25524
+ n++;
25525
+ }else if( show ){
25526
+ sqlite3_fprintf(out, "%s\n", azHelp[i]);
25527
+ }
25528
+ }
25529
+ return n;
25530
+ }
25531
+
25532
+ /* Seek documented commands for which zPattern is an exact prefix */
25533
+ zPat = sqlite3_mprintf(".%s*", zPattern);
25534
+ shell_check_oom(zPat);
25535
+ for(i=0; i<ArraySize(azHelp); i++){
25536
+ if( sqlite3_strglob(zPat, azHelp[i])==0 ){
25537
+ sqlite3_fprintf(out, "%s\n", azHelp[i]);
25538
+ j = i+1;
25539
+ n++;
25540
+ }
25541
+ }
25542
+ sqlite3_free(zPat);
25543
+ if( n ){
25544
+ if( n==1 ){
25545
+ /* when zPattern is a prefix of exactly one command, then include
25546
+ ** the details of that command, which should begin at offset j */
25547
+ while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
25548
+ sqlite3_fprintf(out, "%s\n", azHelp[j]);
25549
+ j++;
25550
+ }
25551
+ }
25552
+ return n;
25553
+ }
25554
+
25555
+ /* Look for documented commands that contain zPattern anywhere.
25556
+ ** Show complete text of all documented commands that match. */
25557
+ zPat = sqlite3_mprintf("%%%s%%", zPattern);
25558
+ shell_check_oom(zPat);
25559
+ for(i=0; i<ArraySize(azHelp); i++){
25560
+ if( azHelp[i][0]==',' ){
25561
+ while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
25562
+ continue;
25563
+ }
25564
+ if( azHelp[i][0]=='.' ) j = i;
25565
+ if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
25566
+ sqlite3_fprintf(out, "%s\n", azHelp[j]);
25567
+ while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
25568
+ j++;
25569
+ sqlite3_fprintf(out, "%s\n", azHelp[j]);
25570
+ }
25571
+ i = j;
25572
+ n++;
25573
+ }
25574
+ }
25575
+ sqlite3_free(zPat);
2567325576
return n;
2567425577
}
2567525578
2567625579
/* Forward reference */
2567725580
static int process_input(ShellState *p);
@@ -29553,11 +29456,12 @@
2955329456
rc = sqlite3_exec(p->db,
2955429457
"SELECT sql FROM"
2955529458
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2955629459
" FROM sqlite_schema UNION ALL"
2955729460
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
29558
- "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
29461
+ "WHERE type!='meta' AND sql NOTNULL"
29462
+ " AND name NOT LIKE 'sqlite__%' ESCAPE '_' "
2955929463
"ORDER BY x",
2956029464
callback, &data, 0
2956129465
);
2956229466
if( rc==SQLITE_OK ){
2956329467
sqlite3_stmt *pStmt;
@@ -31029,11 +30933,11 @@
3102930933
}
3103030934
appendText(&sSelect, " AND ", 0);
3103130935
sqlite3_free(zQarg);
3103230936
}
3103330937
if( bNoSystemTabs ){
31034
- appendText(&sSelect, "name NOT LIKE 'sqlite_%%' AND ", 0);
30938
+ appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCAPE '_' AND ", 0);
3103530939
}
3103630940
appendText(&sSelect, "sql IS NOT NULL"
3103730941
" ORDER BY snum, rowid", 0);
3103830942
if( bDebug ){
3103930943
sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
@@ -31460,11 +31364,11 @@
3146031364
" UNION ALL SELECT 'sqlite_schema'"
3146131365
" ORDER BY 1 collate nocase";
3146231366
}else{
3146331367
zSql = "SELECT lower(name) as tname FROM sqlite_schema"
3146431368
" WHERE type='table' AND coalesce(rootpage,0)>1"
31465
- " AND name NOT LIKE 'sqlite_%'"
31369
+ " AND name NOT LIKE 'sqlite__%' ESCAPE '_'"
3146631370
" ORDER BY 1 collate nocase";
3146731371
}
3146831372
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3146931373
initText(&sQuery);
3147031374
initText(&sSql);
@@ -31525,11 +31429,11 @@
3152531429
{
3152631430
int lrc;
3152731431
char *zRevText = /* Query for reversible to-blob-to-text check */
3152831432
"SELECT lower(name) as tname FROM sqlite_schema\n"
3152931433
"WHERE type='table' AND coalesce(rootpage,0)>1\n"
31530
- "AND name NOT LIKE 'sqlite_%%'%s\n"
31434
+ "AND name NOT LIKE 'sqlite__%%' ESCAPE '_'%s\n"
3153131435
"ORDER BY 1 collate nocase";
3153231436
zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
3153331437
zRevText = sqlite3_mprintf(
3153431438
/* lower-case query is first run, producing upper-case query. */
3153531439
"with tabcols as materialized(\n"
@@ -31721,11 +31625,11 @@
3172131625
}
3172231626
appendText(&s, zDbName, '"');
3172331627
appendText(&s, ".sqlite_schema ", 0);
3172431628
if( c=='t' ){
3172531629
appendText(&s," WHERE type IN ('table','view')"
31726
- " AND name NOT LIKE 'sqlite_%'"
31630
+ " AND name NOT LIKE 'sqlite__%' ESCAPE '_'"
3172731631
" AND name LIKE ?1", 0);
3172831632
}else{
3172931633
appendText(&s," WHERE type='index'"
3173031634
" AND tbl_name LIKE ?1", 0);
3173131635
}
@@ -31815,11 +31719,11 @@
3181531719
const char *zUsage; /* Usage notes */
3181631720
} aCtrl[] = {
3181731721
{"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
3181831722
{"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
3181931723
/*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31820
- /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
31724
+ {"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "SIZE INT-ARRAY"},
3182131725
{"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
3182231726
{"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
3182331727
{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
3182431728
{"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
3182531729
{"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -31934,10 +31838,11 @@
3193431838
{ 0x02000000, 1, "Coroutines" },
3193531839
{ 0x04000000, 1, "NullUnusedCols" },
3193631840
{ 0x08000000, 1, "OnePass" },
3193731841
{ 0x10000000, 1, "OrderBySubq" },
3193831842
{ 0x20000000, 1, "StarQuery" },
31843
+ { 0x40000000, 1, "ExistsToJoin" },
3193931844
{ 0xffffffff, 0, "All" },
3194031845
};
3194131846
unsigned int curOpt;
3194231847
unsigned int newOpt;
3194331848
unsigned int m;
@@ -32153,10 +32058,53 @@
3215332058
rc2 = booleanValue(azArg[2]);
3215432059
isOk = 3;
3215532060
}
3215632061
sqlite3_test_control(testctrl, &rc2);
3215732062
break;
32063
+ case SQLITE_TESTCTRL_BITVEC_TEST: {
32064
+ /* Examples:
32065
+ ** .testctrl bitvec_test 100 6,1 -- Show BITVEC constants
32066
+ ** .testctrl bitvec_test 1000 1,12,7,3 -- Simple test
32067
+ ** ---- --------
32068
+ ** size of Bitvec -----^ ^--- aOp array. 0 added at end.
32069
+ **
32070
+ ** See comments on sqlite3BitvecBuiltinTest() for more information
32071
+ ** about the aOp[] array.
32072
+ */
32073
+ int iSize;
32074
+ const char *zTestArg;
32075
+ int nOp;
32076
+ int ii, jj, x;
32077
+ int *aOp;
32078
+ if( nArg!=4 ){
32079
+ sqlite3_fprintf(stderr,
32080
+ "ERROR - should be: \".testctrl bitvec_test SIZE INT-ARRAY\"\n"
32081
+ );
32082
+ rc = 1;
32083
+ goto meta_command_exit;
32084
+ }
32085
+ isOk = 3;
32086
+ iSize = (int)integerValue(azArg[2]);
32087
+ zTestArg = azArg[3];
32088
+ nOp = (int)strlen(zTestArg)+1;
32089
+ aOp = malloc( sizeof(int)*(nOp+1) );
32090
+ shell_check_oom(aOp);
32091
+ memset(aOp, 0, sizeof(int)*(nOp+1) );
32092
+ for(ii = jj = x = 0; zTestArg[ii]!=0; ii++){
32093
+ if( IsDigit(zTestArg[ii]) ){
32094
+ x = x*10 + zTestArg[ii] - '0';
32095
+ }else{
32096
+ aOp[jj++] = x;
32097
+ x = 0;
32098
+ }
32099
+ }
32100
+ aOp[jj] = x;
32101
+ x = sqlite3_test_control(testctrl, iSize, aOp);
32102
+ sqlite3_fprintf(p->out, "result: %d\n", x);
32103
+ free(aOp);
32104
+ break;
32105
+ }
3215832106
case SQLITE_TESTCTRL_FAULT_INSTALL: {
3215932107
int kk;
3216032108
int bShowHelp = nArg<=2;
3216132109
isOk = 3;
3216232110
for(kk=2; kk<nArg; kk++){
3216332111
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
1266 return 0x3fffffff & (int)(z2 - z);
1267 }
1268
1269 /*
1270 ** Return the length of a string in characters. Multibyte UTF8 characters
1271 ** count as a single character.
 
1272 */
1273 static int strlenChar(const char *z){
1274 int n = 0;
1275 while( *z ){
1276 if( (0xc0&*(z++))!=0x80 ) n++;
 
 
 
 
 
 
 
 
1277 }
1278 return n;
1279 }
1280
1281 /*
@@ -1704,369 +1713,176 @@
1704 ** work here in the middle of this regular program.
1705 */
1706 #define SQLITE_EXTENSION_INIT1
1707 #define SQLITE_EXTENSION_INIT2(X) (void)(X)
1708
1709 #if defined(_WIN32) && defined(_MSC_VER)
1710 /************************* Begin test_windirent.h ******************/
1711 /*
1712 ** 2015 November 30
1713 **
1714 ** The author disclaims copyright to this source code. In place of
1715 ** a legal notice, here is a blessing:
1716 **
1717 ** May you do good and not evil.
1718 ** May you find forgiveness for yourself and forgive others.
1719 ** May you share freely, never taking more than you give.
1720 **
1721 *************************************************************************
1722 ** This file contains declarations for most of the opendir() family of
1723 ** POSIX functions on Win32 using the MSVCRT.
 
 
 
 
 
 
 
1724 */
1725
1726 #if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
1727 #define SQLITE_WINDIRENT_H
1728
1729 /*
1730 ** We need several data types from the Windows SDK header.
1731 */
1732
1733 #ifndef WIN32_LEAN_AND_MEAN
1734 #define WIN32_LEAN_AND_MEAN
1735 #endif
1736
1737 #include "windows.h"
1738
1739 /*
1740 ** We need several support functions from the SQLite core.
1741 */
1742
1743 /* #include "sqlite3.h" */
1744
1745 /*
1746 ** We need several things from the ANSI and MSVCRT headers.
1747 */
1748
1749 #include <stdio.h>
1750 #include <stdlib.h>
1751 #include <errno.h>
1752 #include <io.h>
1753 #include <limits.h>
1754 #include <sys/types.h>
1755 #include <sys/stat.h>
1756
1757 /*
1758 ** We may need several defines that should have been in "sys/stat.h".
1759 */
1760
1761 #ifndef S_ISREG
1762 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
1763 #endif
1764
1765 #ifndef S_ISDIR
1766 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
1767 #endif
1768
1769 #ifndef S_ISLNK
1770 #define S_ISLNK(mode) (0)
1771 #endif
1772
1773 /*
1774 ** We may need to provide the "mode_t" type.
1775 */
1776
1777 #ifndef MODE_T_DEFINED
1778 #define MODE_T_DEFINED
1779 typedef unsigned short mode_t;
1780 #endif
1781
1782 /*
1783 ** We may need to provide the "ino_t" type.
1784 */
1785
1786 #ifndef INO_T_DEFINED
1787 #define INO_T_DEFINED
1788 typedef unsigned short ino_t;
1789 #endif
1790
1791 /*
1792 ** We need to define "NAME_MAX" if it was not present in "limits.h".
1793 */
1794
1795 #ifndef NAME_MAX
1796 # ifdef FILENAME_MAX
1797 # define NAME_MAX (FILENAME_MAX)
1798 # else
1799 # define NAME_MAX (260)
1800 # endif
1801 #endif
1802
1803 /*
1804 ** We need to define "NULL_INTPTR_T" and "BAD_INTPTR_T".
1805 */
1806
1807 #ifndef NULL_INTPTR_T
1808 # define NULL_INTPTR_T ((intptr_t)(0))
1809 #endif
1810
1811 #ifndef BAD_INTPTR_T
1812 # define BAD_INTPTR_T ((intptr_t)(-1))
1813 #endif
1814
1815 /*
1816 ** We need to provide the necessary structures and related types.
1817 */
1818
1819 #ifndef DIRENT_DEFINED
1820 #define DIRENT_DEFINED
1821 typedef struct DIRENT DIRENT;
1822 typedef DIRENT *LPDIRENT;
1823 struct DIRENT {
1824 ino_t d_ino; /* Sequence number, do not use. */
1825 unsigned d_attributes; /* Win32 file attributes. */
1826 char d_name[NAME_MAX + 1]; /* Name within the directory. */
1827 };
1828 #endif
1829
1830 #ifndef DIR_DEFINED
1831 #define DIR_DEFINED
1832 typedef struct DIR DIR;
1833 typedef DIR *LPDIR;
1834 struct DIR {
1835 intptr_t d_handle; /* Value returned by "_findfirst". */
1836 DIRENT d_first; /* DIRENT constructed based on "_findfirst". */
1837 DIRENT d_next; /* DIRENT constructed based on "_findnext". */
1838 };
1839 #endif
1840
1841 /*
1842 ** Provide a macro, for use by the implementation, to determine if a
1843 ** particular directory entry should be skipped over when searching for
1844 ** the next directory entry that should be returned by the readdir() or
1845 ** readdir_r() functions.
1846 */
1847
1848 #ifndef is_filtered
1849 # define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
1850 #endif
1851
1852 /*
1853 ** Provide the function prototype for the POSIX compatible getenv()
1854 ** function. This function is not thread-safe.
1855 */
1856
1857 extern const char *windirent_getenv(const char *name);
1858
1859 /*
1860 ** Finally, we can provide the function prototypes for the opendir(),
1861 ** readdir(), readdir_r(), and closedir() POSIX functions.
1862 */
1863
1864 extern LPDIR opendir(const char *dirname);
1865 extern LPDIRENT readdir(LPDIR dirp);
1866 extern INT readdir_r(LPDIR dirp, LPDIRENT entry, LPDIRENT *result);
1867 extern INT closedir(LPDIR dirp);
1868
1869 #endif /* defined(WIN32) && defined(_MSC_VER) */
1870
1871 /************************* End test_windirent.h ********************/
1872 /************************* Begin test_windirent.c ******************/
1873 /*
1874 ** 2015 November 30
1875 **
1876 ** The author disclaims copyright to this source code. In place of
1877 ** a legal notice, here is a blessing:
1878 **
1879 ** May you do good and not evil.
1880 ** May you find forgiveness for yourself and forgive others.
1881 ** May you share freely, never taking more than you give.
1882 **
1883 *************************************************************************
1884 ** This file contains code to implement most of the opendir() family of
1885 ** POSIX functions on Win32 using the MSVCRT.
1886 */
1887
1888 #if defined(_WIN32) && defined(_MSC_VER)
1889 /* #include "test_windirent.h" */
1890
1891 /*
1892 ** Implementation of the POSIX getenv() function using the Win32 API.
1893 ** This function is not thread-safe.
1894 */
1895 const char *windirent_getenv(
1896 const char *name
1897 ){
1898 static char value[32768]; /* Maximum length, per MSDN */
1899 DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
1900 DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
1901
1902 memset(value, 0, sizeof(value));
1903 dwRet = GetEnvironmentVariableA(name, value, dwSize);
1904 if( dwRet==0 || dwRet>dwSize ){
1905 /*
1906 ** The function call to GetEnvironmentVariableA() failed -OR-
1907 ** the buffer is not large enough. Either way, return NULL.
1908 */
1909 return 0;
1910 }else{
1911 /*
1912 ** The function call to GetEnvironmentVariableA() succeeded
1913 ** -AND- the buffer contains the entire value.
1914 */
1915 return value;
1916 }
1917 }
1918
1919 /*
1920 ** Implementation of the POSIX opendir() function using the MSVCRT.
1921 */
1922 LPDIR opendir(
1923 const char *dirname
1924 ){
1925 struct _finddata_t data;
1926 LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
1927 SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
1928
1929 if( dirp==NULL ) return NULL;
1930 memset(dirp, 0, sizeof(DIR));
1931
1932 /* TODO: Remove this if Unix-style root paths are not used. */
1933 if( sqlite3_stricmp(dirname, "/")==0 ){
1934 dirname = windirent_getenv("SystemDrive");
1935 }
1936
1937 memset(&data, 0, sizeof(struct _finddata_t));
1938 _snprintf(data.name, namesize, "%s\\*", dirname);
1939 dirp->d_handle = _findfirst(data.name, &data);
1940
1941 if( dirp->d_handle==BAD_INTPTR_T ){
1942 closedir(dirp);
1943 return NULL;
1944 }
1945
1946 /* TODO: Remove this block to allow hidden and/or system files. */
1947 if( is_filtered(data) ){
1948 next:
1949
1950 memset(&data, 0, sizeof(struct _finddata_t));
1951 if( _findnext(dirp->d_handle, &data)==-1 ){
1952 closedir(dirp);
1953 return NULL;
1954 }
1955
1956 /* TODO: Remove this block to allow hidden and/or system files. */
1957 if( is_filtered(data) ) goto next;
1958 }
1959
1960 dirp->d_first.d_attributes = data.attrib;
1961 strncpy(dirp->d_first.d_name, data.name, NAME_MAX);
1962 dirp->d_first.d_name[NAME_MAX] = '\0';
1963
1964 return dirp;
1965 }
1966
1967 /*
1968 ** Implementation of the POSIX readdir() function using the MSVCRT.
1969 */
1970 LPDIRENT readdir(
1971 LPDIR dirp
1972 ){
1973 struct _finddata_t data;
1974
1975 if( dirp==NULL ) return NULL;
1976
1977 if( dirp->d_first.d_ino==0 ){
1978 dirp->d_first.d_ino++;
1979 dirp->d_next.d_ino++;
1980
1981 return &dirp->d_first;
1982 }
1983
1984 next:
1985
1986 memset(&data, 0, sizeof(struct _finddata_t));
1987 if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;
1988
1989 /* TODO: Remove this block to allow hidden and/or system files. */
1990 if( is_filtered(data) ) goto next;
1991
1992 dirp->d_next.d_ino++;
1993 dirp->d_next.d_attributes = data.attrib;
1994 strncpy(dirp->d_next.d_name, data.name, NAME_MAX);
1995 dirp->d_next.d_name[NAME_MAX] = '\0';
1996
1997 return &dirp->d_next;
1998 }
1999
2000 /*
2001 ** Implementation of the POSIX readdir_r() function using the MSVCRT.
2002 */
2003 INT readdir_r(
2004 LPDIR dirp,
2005 LPDIRENT entry,
2006 LPDIRENT *result
2007 ){
2008 struct _finddata_t data;
2009
2010 if( dirp==NULL ) return EBADF;
2011
2012 if( dirp->d_first.d_ino==0 ){
2013 dirp->d_first.d_ino++;
2014 dirp->d_next.d_ino++;
2015
2016 entry->d_ino = dirp->d_first.d_ino;
2017 entry->d_attributes = dirp->d_first.d_attributes;
2018 strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX);
2019 entry->d_name[NAME_MAX] = '\0';
2020
2021 *result = entry;
2022 return 0;
2023 }
2024
2025 next:
2026
2027 memset(&data, 0, sizeof(struct _finddata_t));
2028 if( _findnext(dirp->d_handle, &data)==-1 ){
2029 *result = NULL;
2030 return ENOENT;
2031 }
2032
2033 /* TODO: Remove this block to allow hidden and/or system files. */
2034 if( is_filtered(data) ) goto next;
2035
2036 entry->d_ino = (ino_t)-1; /* not available */
2037 entry->d_attributes = data.attrib;
2038 strncpy(entry->d_name, data.name, NAME_MAX);
2039 entry->d_name[NAME_MAX] = '\0';
2040
2041 *result = entry;
2042 return 0;
2043 }
2044
2045 /*
2046 ** Implementation of the POSIX closedir() function using the MSVCRT.
2047 */
2048 INT closedir(
2049 LPDIR dirp
2050 ){
2051 INT result = 0;
2052
2053 if( dirp==NULL ) return EINVAL;
2054
2055 if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
2056 result = _findclose(dirp->d_handle);
2057 }
2058
2059 sqlite3_free(dirp);
2060 return result;
2061 }
2062
2063 #endif /* defined(WIN32) && defined(_MSC_VER) */
2064
2065 /************************* End test_windirent.c ********************/
2066 #define dirent DIRENT
2067 #endif
2068 /************************* Begin ../ext/misc/memtrace.c ******************/
2069 /*
2070 ** 2019-01-21
2071 **
2072 ** The author disclaims copyright to this source code. In place of
@@ -8030,10 +7846,11 @@
8030 ** mode: Value of stat.st_mode for directory entry (an integer).
8031 ** mtime: Value of stat.st_mtime for directory entry (an integer).
8032 ** data: For a regular file, a blob containing the file data. For a
8033 ** symlink, a text value containing the text of the link. For a
8034 ** directory, NULL.
 
8035 **
8036 ** If a non-NULL value is specified for the optional $dir parameter and
8037 ** $path is a relative path, then $path is interpreted relative to $dir.
8038 ** And the paths returned in the "name" column of the table are also
8039 ** relative to directory $dir.
@@ -8055,24 +7872,17 @@
8055 #if !defined(_WIN32) && !defined(WIN32)
8056 # include <unistd.h>
8057 # include <dirent.h>
8058 # include <utime.h>
8059 # include <sys/time.h>
 
8060 #else
8061 # include "windows.h"
8062 # include <io.h>
8063 # include <direct.h>
8064 /* # include "test_windirent.h" */
8065 # define dirent DIRENT
8066 # ifndef chmod
8067 # define chmod _chmod
8068 # endif
8069 # ifndef stat
8070 # define stat _stat
8071 # endif
8072 # define mkdir(path,mode) _mkdir(path)
8073 # define lstat(path,buf) stat(path,buf)
8074 #endif
8075 #include <time.h>
8076 #include <errno.h>
8077
8078 /* When used as part of the CLI, the sqlite3_stdio.h module will have
@@ -8084,18 +7894,54 @@
8084 #endif
8085
8086 /*
8087 ** Structure of the fsdir() table-valued function
8088 */
8089 /* 0 1 2 3 4 5 */
8090 #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
 
8091 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
8092 #define FSDIR_COLUMN_MODE 1 /* Access mode */
8093 #define FSDIR_COLUMN_MTIME 2 /* Last modification time */
8094 #define FSDIR_COLUMN_DATA 3 /* File content */
8095 #define FSDIR_COLUMN_PATH 4 /* Path to top of search */
8096 #define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8097
8098
8099 /*
8100 ** Set the result stored by context ctx to a blob containing the
8101 ** contents of file zName. Or, leave the result unchanged (NULL)
@@ -8223,11 +8069,11 @@
8223 ** buffer to UTC. This is necessary on Win32, where the runtime library
8224 ** appears to return these values as local times.
8225 */
8226 static void statTimesToUtc(
8227 const char *zPath,
8228 struct stat *pStatBuf
8229 ){
8230 HANDLE hFindFile;
8231 WIN32_FIND_DATAW fd;
8232 LPWSTR zUnicodeName;
8233 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
@@ -8251,14 +8097,20 @@
8251 ** is required in order for the included time to be returned as UTC. On all
8252 ** other systems, this function simply calls stat().
8253 */
8254 static int fileStat(
8255 const char *zPath,
8256 struct stat *pStatBuf
8257 ){
8258 #if defined(_WIN32)
8259 int rc = stat(zPath, pStatBuf);
 
 
 
 
 
 
8260 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
8261 return rc;
8262 #else
8263 return stat(zPath, pStatBuf);
8264 #endif
@@ -8269,16 +8121,14 @@
8269 ** is required in order for the included time to be returned as UTC. On all
8270 ** other systems, this function simply calls lstat().
8271 */
8272 static int fileLinkStat(
8273 const char *zPath,
8274 struct stat *pStatBuf
8275 ){
8276 #if defined(_WIN32)
8277 int rc = lstat(zPath, pStatBuf);
8278 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
8279 return rc;
8280 #else
8281 return lstat(zPath, pStatBuf);
8282 #endif
8283 }
8284
@@ -8304,11 +8154,11 @@
8304 }else{
8305 int nCopy = (int)strlen(zCopy);
8306 int i = 1;
8307
8308 while( rc==SQLITE_OK ){
8309 struct stat sStat;
8310 int rc2;
8311
8312 for(; zCopy[i]!='/' && i<nCopy; i++);
8313 if( i==nCopy ) break;
8314 zCopy[i] = '\0';
@@ -8354,11 +8204,11 @@
8354 if( mkdir(zFile, mode) ){
8355 /* The mkdir() call to create the directory failed. This might not
8356 ** be an error though - if there is already a directory at the same
8357 ** path and either the permissions already match or can be changed
8358 ** to do so using chmod(), it is not an error. */
8359 struct stat sStat;
8360 if( errno!=EEXIST
8361 || 0!=fileStat(zFile, &sStat)
8362 || !S_ISDIR(sStat.st_mode)
8363 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
8364 ){
@@ -8550,17 +8400,18 @@
8550
8551 struct fsdir_cursor {
8552 sqlite3_vtab_cursor base; /* Base class - must be first */
8553
8554 int nLvl; /* Number of entries in aLvl[] array */
 
8555 int iLvl; /* Index of current entry */
8556 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
8557
8558 const char *zBase;
8559 int nBase;
8560
8561 struct stat sStat; /* Current lstat() results */
8562 char *zPath; /* Path to current entry */
8563 sqlite3_int64 iRowid; /* Current rowid */
8564 };
8565
8566 typedef struct fsdir_tab fsdir_tab;
@@ -8668,11 +8519,11 @@
8668 static int fsdirNext(sqlite3_vtab_cursor *cur){
8669 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8670 mode_t m = pCur->sStat.st_mode;
8671
8672 pCur->iRowid++;
8673 if( S_ISDIR(m) ){
8674 /* Descend into this directory */
8675 int iNew = pCur->iLvl + 1;
8676 FsdirLevel *pLvl;
8677 if( iNew>=pCur->nLvl ){
8678 int nNew = iNew+1;
@@ -8776,11 +8627,15 @@
8776 if( aBuf!=aStatic ) sqlite3_free(aBuf);
8777 #endif
8778 }else{
8779 readFileContents(ctx, pCur->zPath);
8780 }
 
8781 }
 
 
 
8782 case FSDIR_COLUMN_PATH:
8783 default: {
8784 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
8785 ** always return their values as NULL */
8786 break;
@@ -8810,36 +8665,50 @@
8810 }
8811
8812 /*
8813 ** xFilter callback.
8814 **
8815 ** idxNum==1 PATH parameter only
8816 ** idxNum==2 Both PATH and DIR supplied
 
 
 
8817 */
8818 static int fsdirFilter(
8819 sqlite3_vtab_cursor *cur,
8820 int idxNum, const char *idxStr,
8821 int argc, sqlite3_value **argv
8822 ){
8823 const char *zDir = 0;
8824 fsdir_cursor *pCur = (fsdir_cursor*)cur;
 
8825 (void)idxStr;
8826 fsdirResetCursor(pCur);
8827
8828 if( idxNum==0 ){
8829 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
8830 return SQLITE_ERROR;
8831 }
8832
8833 assert( argc==idxNum && (argc==1 || argc==2) );
8834 zDir = (const char*)sqlite3_value_text(argv[0]);
8835 if( zDir==0 ){
8836 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
8837 return SQLITE_ERROR;
8838 }
8839 if( argc==2 ){
8840 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
 
 
 
 
 
 
 
 
 
 
8841 }
8842 if( pCur->zBase ){
8843 pCur->nBase = (int)strlen(pCur->zBase)+1;
8844 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
8845 }else{
@@ -8864,48 +8733,75 @@
8864 ** plan.
8865 **
8866 ** In this implementation idxNum is used to represent the
8867 ** query plan. idxStr is unused.
8868 **
8869 ** The query plan is represented by values of idxNum:
8870 **
8871 ** (1) The path value is supplied by argv[0]
8872 ** (2) Path is in argv[0] and dir is in argv[1]
 
8873 */
8874 static int fsdirBestIndex(
8875 sqlite3_vtab *tab,
8876 sqlite3_index_info *pIdxInfo
8877 ){
8878 int i; /* Loop over constraints */
8879 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
8880 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
 
 
 
8881 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
8882 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
8883 const struct sqlite3_index_constraint *pConstraint;
8884
8885 (void)tab;
8886 pConstraint = pIdxInfo->aConstraint;
8887 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8888 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
8889 switch( pConstraint->iColumn ){
8890 case FSDIR_COLUMN_PATH: {
8891 if( pConstraint->usable ){
8892 idxPath = i;
8893 seenPath = 0;
8894 }else if( idxPath<0 ){
8895 seenPath = 1;
8896 }
8897 break;
8898 }
8899 case FSDIR_COLUMN_DIR: {
8900 if( pConstraint->usable ){
8901 idxDir = i;
8902 seenDir = 0;
8903 }else if( idxDir<0 ){
8904 seenDir = 1;
8905 }
8906 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8907 }
8908 }
8909 }
8910 if( seenPath || seenDir ){
8911 /* If input parameters are unusable, disallow this plan */
@@ -8918,18 +8814,24 @@
8918 ** number. Leave it unchanged. */
8919 pIdxInfo->estimatedRows = 0x7fffffff;
8920 }else{
8921 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
8922 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
 
 
 
8923 if( idxDir>=0 ){
8924 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8925 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
8926 pIdxInfo->idxNum = 2;
8927 pIdxInfo->estimatedCost = 10.0;
8928 }else{
8929 pIdxInfo->idxNum = 1;
8930 pIdxInfo->estimatedCost = 100.0;
 
 
 
8931 }
8932 }
8933
8934 return SQLITE_OK;
8935 }
@@ -16784,11 +16686,11 @@
16784 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: zOp = "POWERSAFE_OVERWRITE"; break;
16785 case SQLITE_FCNTL_PRAGMA: {
16786 const char *const* a = (const char*const*)pArg;
16787 if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){
16788 const u8 *zArg = (const u8*)a[2];
16789 if( zArg[0]>='0' && zArg[0]<=9 ){
16790 pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0);
16791 }else{
16792 static const struct {
16793 const char *z;
16794 unsigned int m;
@@ -25571,107 +25473,108 @@
25571 " --plain Show results as text/plain, not as HTML",
25572 #endif
25573 };
25574
25575 /*
25576 ** Output help text.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25577 **
25578 ** zPattern describes the set of commands for which help text is provided.
25579 ** If zPattern is NULL, then show all commands, but only give a one-line
25580 ** description of each.
25581 **
25582 ** Return the number of matches.
25583 */
25584 static int showHelp(FILE *out, const char *zPattern){
25585 int i = 0;
25586 int j = 0;
25587 int n = 0;
25588 char *zPat;
25589 if( zPattern==0
25590 || zPattern[0]=='0'
25591 || cli_strcmp(zPattern,"-a")==0
25592 || cli_strcmp(zPattern,"-all")==0
25593 || cli_strcmp(zPattern,"--all")==0
25594 ){
25595 enum HelpWanted { HW_NoCull = 0, HW_SummaryOnly = 1, HW_Undoc = 2 };
25596 enum HelpHave { HH_Undoc = 2, HH_Summary = 1, HH_More = 0 };
25597 /* Show all or most commands
25598 ** *zPattern==0 => summary of documented commands only
25599 ** *zPattern=='0' => whole help for undocumented commands
25600 ** Otherwise => whole help for documented commands
25601 */
25602 enum HelpWanted hw = HW_SummaryOnly;
25603 enum HelpHave hh = HH_More;
25604 if( zPattern!=0 ){
25605 hw = (*zPattern=='0')? HW_NoCull|HW_Undoc : HW_NoCull;
25606 }
25607 for(i=0; i<ArraySize(azHelp); i++){
25608 switch( azHelp[i][0] ){
25609 case ',':
25610 hh = HH_Summary|HH_Undoc;
25611 break;
25612 case '.':
25613 hh = HH_Summary;
25614 break;
25615 default:
25616 hh &= ~HH_Summary;
25617 break;
25618 }
25619 if( ((hw^hh)&HH_Undoc)==0 ){
25620 if( (hh&HH_Summary)!=0 ){
25621 sqlite3_fprintf(out, ".%s\n", azHelp[i]+1);
25622 ++n;
25623 }else if( (hw&HW_SummaryOnly)==0 ){
25624 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25625 }
25626 }
25627 }
25628 }else{
25629 /* Seek documented commands for which zPattern is an exact prefix */
25630 zPat = sqlite3_mprintf(".%s*", zPattern);
25631 shell_check_oom(zPat);
25632 for(i=0; i<ArraySize(azHelp); i++){
25633 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
25634 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25635 j = i+1;
25636 n++;
25637 }
25638 }
25639 sqlite3_free(zPat);
25640 if( n ){
25641 if( n==1 ){
25642 /* when zPattern is a prefix of exactly one command, then include
25643 ** the details of that command, which should begin at offset j */
25644 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
25645 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25646 j++;
25647 }
25648 }
25649 return n;
25650 }
25651 /* Look for documented commands that contain zPattern anywhere.
25652 ** Show complete text of all documented commands that match. */
25653 zPat = sqlite3_mprintf("%%%s%%", zPattern);
25654 shell_check_oom(zPat);
25655 for(i=0; i<ArraySize(azHelp); i++){
25656 if( azHelp[i][0]==',' ){
25657 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
25658 continue;
25659 }
25660 if( azHelp[i][0]=='.' ) j = i;
25661 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
25662 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25663 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
25664 j++;
25665 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25666 }
25667 i = j;
25668 n++;
25669 }
25670 }
25671 sqlite3_free(zPat);
25672 }
25673 return n;
25674 }
25675
25676 /* Forward reference */
25677 static int process_input(ShellState *p);
@@ -29553,11 +29456,12 @@
29553 rc = sqlite3_exec(p->db,
29554 "SELECT sql FROM"
29555 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
29556 " FROM sqlite_schema UNION ALL"
29557 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
29558 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
 
29559 "ORDER BY x",
29560 callback, &data, 0
29561 );
29562 if( rc==SQLITE_OK ){
29563 sqlite3_stmt *pStmt;
@@ -31029,11 +30933,11 @@
31029 }
31030 appendText(&sSelect, " AND ", 0);
31031 sqlite3_free(zQarg);
31032 }
31033 if( bNoSystemTabs ){
31034 appendText(&sSelect, "name NOT LIKE 'sqlite_%%' AND ", 0);
31035 }
31036 appendText(&sSelect, "sql IS NOT NULL"
31037 " ORDER BY snum, rowid", 0);
31038 if( bDebug ){
31039 sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
@@ -31460,11 +31364,11 @@
31460 " UNION ALL SELECT 'sqlite_schema'"
31461 " ORDER BY 1 collate nocase";
31462 }else{
31463 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
31464 " WHERE type='table' AND coalesce(rootpage,0)>1"
31465 " AND name NOT LIKE 'sqlite_%'"
31466 " ORDER BY 1 collate nocase";
31467 }
31468 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
31469 initText(&sQuery);
31470 initText(&sSql);
@@ -31525,11 +31429,11 @@
31525 {
31526 int lrc;
31527 char *zRevText = /* Query for reversible to-blob-to-text check */
31528 "SELECT lower(name) as tname FROM sqlite_schema\n"
31529 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
31530 "AND name NOT LIKE 'sqlite_%%'%s\n"
31531 "ORDER BY 1 collate nocase";
31532 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
31533 zRevText = sqlite3_mprintf(
31534 /* lower-case query is first run, producing upper-case query. */
31535 "with tabcols as materialized(\n"
@@ -31721,11 +31625,11 @@
31721 }
31722 appendText(&s, zDbName, '"');
31723 appendText(&s, ".sqlite_schema ", 0);
31724 if( c=='t' ){
31725 appendText(&s," WHERE type IN ('table','view')"
31726 " AND name NOT LIKE 'sqlite_%'"
31727 " AND name LIKE ?1", 0);
31728 }else{
31729 appendText(&s," WHERE type='index'"
31730 " AND tbl_name LIKE ?1", 0);
31731 }
@@ -31815,11 +31719,11 @@
31815 const char *zUsage; /* Usage notes */
31816 } aCtrl[] = {
31817 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
31818 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
31819 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31820 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
31821 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
31822 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
31823 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
31824 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
31825 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -31934,10 +31838,11 @@
31934 { 0x02000000, 1, "Coroutines" },
31935 { 0x04000000, 1, "NullUnusedCols" },
31936 { 0x08000000, 1, "OnePass" },
31937 { 0x10000000, 1, "OrderBySubq" },
31938 { 0x20000000, 1, "StarQuery" },
 
31939 { 0xffffffff, 0, "All" },
31940 };
31941 unsigned int curOpt;
31942 unsigned int newOpt;
31943 unsigned int m;
@@ -32153,10 +32058,53 @@
32153 rc2 = booleanValue(azArg[2]);
32154 isOk = 3;
32155 }
32156 sqlite3_test_control(testctrl, &rc2);
32157 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32158 case SQLITE_TESTCTRL_FAULT_INSTALL: {
32159 int kk;
32160 int bShowHelp = nArg<=2;
32161 isOk = 3;
32162 for(kk=2; kk<nArg; kk++){
32163
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
1266 return 0x3fffffff & (int)(z2 - z);
1267 }
1268
1269 /*
1270 ** Return the length of a string in characters. Multibyte UTF8 characters
1271 ** count as a single character for single-width characters, or as two
1272 ** characters for double-width characters.
1273 */
1274 static int strlenChar(const char *z){
1275 int n = 0;
1276 while( *z ){
1277 if( (0x80&z[0])==0 ){
1278 n++;
1279 z++;
1280 }else{
1281 int u = 0;
1282 int len = decodeUtf8((const u8*)z, &u);
1283 z += len;
1284 n += cli_wcwidth(u);
1285 }
1286 }
1287 return n;
1288 }
1289
1290 /*
@@ -1704,369 +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
@@ -8030,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.
@@ -8055,24 +7872,17 @@
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>
7887
7888 /* When used as part of the CLI, the sqlite3_stdio.h module will have
@@ -8084,18 +7894,54 @@
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)
7914 static int fileio_chmod(const char *zPath, int pmode){
7915 sqlite3_int64 sz = strlen(zPath);
7916 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
7917 int rc;
7918 if( b1==0 ) return -1;
7919 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
7920 b1[sz] = 0;
7921 rc = _wchmod(b1, pmode);
7922 sqlite3_free(b1);
7923 return rc;
7924 }
7925 #endif
7926
7927 /*
7928 ** UTF8 mkdir() function for Windows
7929 */
7930 #if defined(_WIN32) || defined(WIN32)
7931 static int fileio_mkdir(const char *zPath){
7932 sqlite3_int64 sz = strlen(zPath);
7933 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
7934 int rc;
7935 if( b1==0 ) return -1;
7936 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
7937 b1[sz] = 0;
7938 rc = _wmkdir(b1);
7939 sqlite3_free(b1);
7940 return rc;
7941 }
7942 #endif
7943
7944
7945 /*
7946 ** Set the result stored by context ctx to a blob containing the
7947 ** contents of file zName. Or, leave the result unchanged (NULL)
@@ -8223,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*);
@@ -8251,14 +8097,20 @@
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;
8108 if( b1==0 ) return 1;
8109 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
8110 b1[sz] = 0;
8111 rc = _wstat(b1, pStatBuf);
8112 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
8113 return rc;
8114 #else
8115 return stat(zPath, pStatBuf);
8116 #endif
@@ -8269,16 +8121,14 @@
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);
8132 #endif
8133 }
8134
@@ -8304,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';
@@ -8354,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 ){
@@ -8550,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;
@@ -8668,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;
@@ -8776,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;
@@ -8810,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{
@@ -8864,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 */
@@ -8918,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 }
@@ -16784,11 +16686,11 @@
16686 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: zOp = "POWERSAFE_OVERWRITE"; break;
16687 case SQLITE_FCNTL_PRAGMA: {
16688 const char *const* a = (const char*const*)pArg;
16689 if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){
16690 const u8 *zArg = (const u8*)a[2];
16691 if( zArg[0]>='0' && zArg[0]<='9' ){
16692 pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0);
16693 }else{
16694 static const struct {
16695 const char *z;
16696 unsigned int m;
@@ -25571,107 +25473,108 @@
25473 " --plain Show results as text/plain, not as HTML",
25474 #endif
25475 };
25476
25477 /*
25478 ** Output help text for commands that match zPattern.
25479 **
25480 ** * If zPattern is NULL, then show all documented commands, but
25481 ** only give a one-line summary of each.
25482 **
25483 ** * If zPattern is "-a" or "-all" or "--all" then show all help text
25484 ** for all commands except undocumented commands.
25485 **
25486 ** * If zPattern is "0" then show all help for undocumented commands.
25487 ** Undocumented commands begin with "," instead of "." in the azHelp[]
25488 ** array.
25489 **
25490 ** * If zPattern is a prefix for one or more documented commands, then
25491 ** show help for those commands. If only a single command matches the
25492 ** prefix, show the full text of the help. If multiple commands match,
25493 ** Only show just the first line of each.
25494 **
25495 ** * Otherwise, show the complete text of any documented command for which
25496 ** zPattern is a LIKE match for any text within that command help
25497 ** text.
25498 **
25499 ** Return the number commands that match zPattern.
25500 */
25501 static int showHelp(FILE *out, const char *zPattern){
25502 int i = 0;
25503 int j = 0;
25504 int n = 0;
25505 char *zPat;
25506 if( zPattern==0 ){
25507 /* Show just the first line for all help topics */
25508 zPattern = "[a-z]";
25509 }else if( cli_strcmp(zPattern,"-a")==0
25510 || cli_strcmp(zPattern,"-all")==0
25511 || cli_strcmp(zPattern,"--all")==0
25512 ){
25513 /* Show everything except undocumented commands */
25514 zPattern = ".";
25515 }else if( cli_strcmp(zPattern,"0")==0 ){
25516 /* Show complete help text of undocumented commands */
25517 int show = 0;
25518 for(i=0; i<ArraySize(azHelp); i++){
25519 if( azHelp[i][0]=='.' ){
25520 show = 0;
25521 }else if( azHelp[i][0]==',' ){
25522 show = 1;
25523 sqlite3_fprintf(out, ".%s\n", &azHelp[i][1]);
25524 n++;
25525 }else if( show ){
25526 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25527 }
25528 }
25529 return n;
25530 }
25531
25532 /* Seek documented commands for which zPattern is an exact prefix */
25533 zPat = sqlite3_mprintf(".%s*", zPattern);
25534 shell_check_oom(zPat);
25535 for(i=0; i<ArraySize(azHelp); i++){
25536 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
25537 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25538 j = i+1;
25539 n++;
25540 }
25541 }
25542 sqlite3_free(zPat);
25543 if( n ){
25544 if( n==1 ){
25545 /* when zPattern is a prefix of exactly one command, then include
25546 ** the details of that command, which should begin at offset j */
25547 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
25548 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25549 j++;
25550 }
25551 }
25552 return n;
25553 }
25554
25555 /* Look for documented commands that contain zPattern anywhere.
25556 ** Show complete text of all documented commands that match. */
25557 zPat = sqlite3_mprintf("%%%s%%", zPattern);
25558 shell_check_oom(zPat);
25559 for(i=0; i<ArraySize(azHelp); i++){
25560 if( azHelp[i][0]==',' ){
25561 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
25562 continue;
25563 }
25564 if( azHelp[i][0]=='.' ) j = i;
25565 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
25566 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25567 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
25568 j++;
25569 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25570 }
25571 i = j;
25572 n++;
25573 }
25574 }
25575 sqlite3_free(zPat);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25576 return n;
25577 }
25578
25579 /* Forward reference */
25580 static int process_input(ShellState *p);
@@ -29553,11 +29456,12 @@
29456 rc = sqlite3_exec(p->db,
29457 "SELECT sql FROM"
29458 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
29459 " FROM sqlite_schema UNION ALL"
29460 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
29461 "WHERE type!='meta' AND sql NOTNULL"
29462 " AND name NOT LIKE 'sqlite__%' ESCAPE '_' "
29463 "ORDER BY x",
29464 callback, &data, 0
29465 );
29466 if( rc==SQLITE_OK ){
29467 sqlite3_stmt *pStmt;
@@ -31029,11 +30933,11 @@
30933 }
30934 appendText(&sSelect, " AND ", 0);
30935 sqlite3_free(zQarg);
30936 }
30937 if( bNoSystemTabs ){
30938 appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCAPE '_' AND ", 0);
30939 }
30940 appendText(&sSelect, "sql IS NOT NULL"
30941 " ORDER BY snum, rowid", 0);
30942 if( bDebug ){
30943 sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
@@ -31460,11 +31364,11 @@
31364 " UNION ALL SELECT 'sqlite_schema'"
31365 " ORDER BY 1 collate nocase";
31366 }else{
31367 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
31368 " WHERE type='table' AND coalesce(rootpage,0)>1"
31369 " AND name NOT LIKE 'sqlite__%' ESCAPE '_'"
31370 " ORDER BY 1 collate nocase";
31371 }
31372 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
31373 initText(&sQuery);
31374 initText(&sSql);
@@ -31525,11 +31429,11 @@
31429 {
31430 int lrc;
31431 char *zRevText = /* Query for reversible to-blob-to-text check */
31432 "SELECT lower(name) as tname FROM sqlite_schema\n"
31433 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
31434 "AND name NOT LIKE 'sqlite__%%' ESCAPE '_'%s\n"
31435 "ORDER BY 1 collate nocase";
31436 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
31437 zRevText = sqlite3_mprintf(
31438 /* lower-case query is first run, producing upper-case query. */
31439 "with tabcols as materialized(\n"
@@ -31721,11 +31625,11 @@
31625 }
31626 appendText(&s, zDbName, '"');
31627 appendText(&s, ".sqlite_schema ", 0);
31628 if( c=='t' ){
31629 appendText(&s," WHERE type IN ('table','view')"
31630 " AND name NOT LIKE 'sqlite__%' ESCAPE '_'"
31631 " AND name LIKE ?1", 0);
31632 }else{
31633 appendText(&s," WHERE type='index'"
31634 " AND tbl_name LIKE ?1", 0);
31635 }
@@ -31815,11 +31719,11 @@
31719 const char *zUsage; /* Usage notes */
31720 } aCtrl[] = {
31721 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
31722 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
31723 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31724 {"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "SIZE INT-ARRAY"},
31725 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
31726 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
31727 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
31728 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
31729 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
@@ -31934,10 +31838,11 @@
31838 { 0x02000000, 1, "Coroutines" },
31839 { 0x04000000, 1, "NullUnusedCols" },
31840 { 0x08000000, 1, "OnePass" },
31841 { 0x10000000, 1, "OrderBySubq" },
31842 { 0x20000000, 1, "StarQuery" },
31843 { 0x40000000, 1, "ExistsToJoin" },
31844 { 0xffffffff, 0, "All" },
31845 };
31846 unsigned int curOpt;
31847 unsigned int newOpt;
31848 unsigned int m;
@@ -32153,10 +32058,53 @@
32058 rc2 = booleanValue(azArg[2]);
32059 isOk = 3;
32060 }
32061 sqlite3_test_control(testctrl, &rc2);
32062 break;
32063 case SQLITE_TESTCTRL_BITVEC_TEST: {
32064 /* Examples:
32065 ** .testctrl bitvec_test 100 6,1 -- Show BITVEC constants
32066 ** .testctrl bitvec_test 1000 1,12,7,3 -- Simple test
32067 ** ---- --------
32068 ** size of Bitvec -----^ ^--- aOp array. 0 added at end.
32069 **
32070 ** See comments on sqlite3BitvecBuiltinTest() for more information
32071 ** about the aOp[] array.
32072 */
32073 int iSize;
32074 const char *zTestArg;
32075 int nOp;
32076 int ii, jj, x;
32077 int *aOp;
32078 if( nArg!=4 ){
32079 sqlite3_fprintf(stderr,
32080 "ERROR - should be: \".testctrl bitvec_test SIZE INT-ARRAY\"\n"
32081 );
32082 rc = 1;
32083 goto meta_command_exit;
32084 }
32085 isOk = 3;
32086 iSize = (int)integerValue(azArg[2]);
32087 zTestArg = azArg[3];
32088 nOp = (int)strlen(zTestArg)+1;
32089 aOp = malloc( sizeof(int)*(nOp+1) );
32090 shell_check_oom(aOp);
32091 memset(aOp, 0, sizeof(int)*(nOp+1) );
32092 for(ii = jj = x = 0; zTestArg[ii]!=0; ii++){
32093 if( IsDigit(zTestArg[ii]) ){
32094 x = x*10 + zTestArg[ii] - '0';
32095 }else{
32096 aOp[jj++] = x;
32097 x = 0;
32098 }
32099 }
32100 aOp[jj] = x;
32101 x = sqlite3_test_control(testctrl, iSize, aOp);
32102 sqlite3_fprintf(p->out, "result: %d\n", x);
32103 free(aOp);
32104 break;
32105 }
32106 case SQLITE_TESTCTRL_FAULT_INSTALL: {
32107 int kk;
32108 int bShowHelp = nArg<=2;
32109 isOk = 3;
32110 for(kk=2; kk<nArg; kk++){
32111
+1825 -961
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.50.0. By combining all the individual C code files into this
3
+** version 3.51.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -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
-** 20abf1ec107f942e4527901685d61283c9c2 with changes in files:
21
+** 9f184f8dfa5ef6d57e10376adc30e0060ced with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463463
**
464464
** See also: [sqlite3_libversion()],
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468
-#define SQLITE_VERSION "3.50.0"
469
-#define SQLITE_VERSION_NUMBER 3050000
470
-#define SQLITE_SOURCE_ID "2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849"
468
+#define SQLITE_VERSION "3.51.0"
469
+#define SQLITE_VERSION_NUMBER 3051000
470
+#define SQLITE_SOURCE_ID "2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -485,13 +485,13 @@
485485
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
486486
** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
487487
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
488488
** </pre></blockquote>)^
489489
**
490
-** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
491
-** macro. ^The sqlite3_libversion() function returns a pointer to the
492
-** to the sqlite3_version[] string constant. The sqlite3_libversion()
490
+** ^The sqlite3_version[] string constant contains the text of the
491
+** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a
492
+** pointer to the sqlite3_version[] string constant. The sqlite3_libversion()
493493
** function is provided for use in DLLs since DLL users usually do not have
494494
** direct access to string constants within the DLL. ^The
495495
** sqlite3_libversion_number() function returns an integer equal to
496496
** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
497497
** a pointer to a string constant whose value is the same as the
@@ -687,11 +687,11 @@
687687
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
688688
** that allows an application to run multiple statements of SQL
689689
** without having to use a lot of C code.
690690
**
691691
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
692
-** semicolon-separate SQL statements passed into its 2nd argument,
692
+** semicolon-separated SQL statements passed into its 2nd argument,
693693
** in the context of the [database connection] passed in as its 1st
694694
** argument. ^If the callback function of the 3rd argument to
695695
** sqlite3_exec() is not NULL, then it is invoked for each result row
696696
** coming out of the evaluated SQL statements. ^The 4th argument to
697697
** sqlite3_exec() is relayed through to the 1st argument of each
@@ -720,11 +720,11 @@
720720
** callback is an array of pointers to strings obtained as if from
721721
** [sqlite3_column_text()], one for each column. ^If an element of a
722722
** result row is NULL then the corresponding string pointer for the
723723
** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
724724
** sqlite3_exec() callback is an array of pointers to strings where each
725
-** entry represents the name of corresponding result column as obtained
725
+** entry represents the name of a corresponding result column as obtained
726726
** from [sqlite3_column_name()].
727727
**
728728
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
729729
** to an empty string, or a pointer that contains only whitespace and/or
730730
** SQL comments, then no SQL statements are evaluated and the database
@@ -906,11 +906,11 @@
906906
** Applications should not depend on the historical behavior.
907907
**
908908
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
909909
** [sqlite3_open_v2()] does *not* cause the underlying database file
910910
** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
911
-** [sqlite3_open_v2()] has historically be a no-op and might become an
911
+** [sqlite3_open_v2()] has historically been a no-op and might become an
912912
** error in future versions of SQLite.
913913
*/
914914
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
915915
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
916916
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -1000,11 +1000,11 @@
10001000
** CAPI3REF: File Locking Levels
10011001
**
10021002
** SQLite uses one of these integer values as the second
10031003
** argument to calls it makes to the xLock() and xUnlock() methods
10041004
** of an [sqlite3_io_methods] object. These values are ordered from
1005
-** lest restrictive to most restrictive.
1005
+** least restrictive to most restrictive.
10061006
**
10071007
** The argument to xLock() is always SHARED or higher. The argument to
10081008
** xUnlock is either SHARED or NONE.
10091009
*/
10101010
#define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -1316,11 +1316,11 @@
13161316
** reason, the entire database file will be overwritten by the current
13171317
** transaction. This is used by VACUUM operations.
13181318
**
13191319
** <li>[[SQLITE_FCNTL_VFSNAME]]
13201320
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1321
-** all [VFSes] in the VFS stack. The names are of all VFS shims and the
1321
+** all [VFSes] in the VFS stack. The names of all VFS shims and the
13221322
** final bottom-level VFS are written into memory obtained from
13231323
** [sqlite3_malloc()] and the result is stored in the char* variable
13241324
** that the fourth parameter of [sqlite3_file_control()] points to.
13251325
** The caller is responsible for freeing the memory when done. As with
13261326
** all file-control actions, there is no guarantee that this will actually
@@ -1330,11 +1330,11 @@
13301330
**
13311331
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
13321332
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
13331333
** [VFSes] currently in use. ^(The argument X in
13341334
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1335
-** of type "[sqlite3_vfs] **". This opcodes will set *X
1335
+** of type "[sqlite3_vfs] **". This opcode will set *X
13361336
** to a pointer to the top-level VFS.)^
13371337
** ^When there are multiple VFS shims in the stack, this opcode finds the
13381338
** upper-most shim only.
13391339
**
13401340
** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1520,11 +1520,11 @@
15201520
** record the fact that the pages have been checkpointed.
15211521
**
15221522
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
15231523
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
15241524
** whether or not there is a database client in another process with a wal-mode
1525
-** transaction open on the database or not. It is only available on unix.The
1525
+** transaction open on the database or not. It is only available on unix. The
15261526
** (void*) argument passed with this file-control should be a pointer to a
15271527
** value of type (int). The integer value is set to 1 if the database is a wal
15281528
** mode database and there exists at least one client in another process that
15291529
** currently has an SQL transaction open on the database. It is set to 0 if
15301530
** the database is not a wal-mode db, or if there is no such connection in any
@@ -1945,11 +1945,11 @@
19451945
**
19461946
** ^The sqlite3_initialize() routine is called internally by many other
19471947
** SQLite interfaces so that an application usually does not need to
19481948
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
19491949
** calls sqlite3_initialize() so the SQLite library will be automatically
1950
-** initialized when [sqlite3_open()] is called if it has not be initialized
1950
+** initialized when [sqlite3_open()] is called if it has not been initialized
19511951
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
19521952
** compile-time option, then the automatic calls to sqlite3_initialize()
19531953
** are omitted and the application must call sqlite3_initialize() directly
19541954
** prior to using any other SQLite interface. For maximum portability,
19551955
** it is recommended that applications always invoke sqlite3_initialize()
@@ -2202,25 +2202,25 @@
22022202
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
22032203
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
22042204
** The [sqlite3_mem_methods]
22052205
** structure is filled with the currently defined memory allocation routines.)^
22062206
** This option can be used to overload the default memory allocation
2207
-** routines with a wrapper that simulations memory allocation failure or
2207
+** routines with a wrapper that simulates memory allocation failure or
22082208
** tracks memory usage, for example. </dd>
22092209
**
22102210
** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2211
-** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
2211
+** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of
22122212
** type int, interpreted as a boolean, which if true provides a hint to
22132213
** SQLite that it should avoid large memory allocations if possible.
22142214
** SQLite will run faster if it is free to make large memory allocations,
2215
-** but some application might prefer to run slower in exchange for
2215
+** but some applications might prefer to run slower in exchange for
22162216
** guarantees about memory fragmentation that are possible if large
22172217
** allocations are avoided. This hint is normally off.
22182218
** </dd>
22192219
**
22202220
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2221
-** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
2221
+** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,
22222222
** interpreted as a boolean, which enables or disables the collection of
22232223
** memory allocation statistics. ^(When memory allocation statistics are
22242224
** disabled, the following SQLite interfaces become non-operational:
22252225
** <ul>
22262226
** <li> [sqlite3_hard_heap_limit64()]
@@ -2261,11 +2261,11 @@
22612261
** a page cache line is larger than sz bytes or if all of the pMem buffer
22622262
** is exhausted.
22632263
** ^If pMem is NULL and N is non-zero, then each database connection
22642264
** does an initial bulk allocation for page cache memory
22652265
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
2266
-** of -1024*N bytes if N is negative, . ^If additional
2266
+** of -1024*N bytes if N is negative. ^If additional
22672267
** page cache memory is needed beyond what is provided by the initial
22682268
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
22692269
** additional cache line. </dd>
22702270
**
22712271
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -2290,11 +2290,11 @@
22902290
**
22912291
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
22922292
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
22932293
** pointer to an instance of the [sqlite3_mutex_methods] structure.
22942294
** The argument specifies alternative low-level mutex routines to be used
2295
-** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
2295
+** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of
22962296
** the content of the [sqlite3_mutex_methods] structure before the call to
22972297
** [sqlite3_config()] returns. ^If SQLite is compiled with
22982298
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
22992299
** the entire mutexing subsystem is omitted from the build and hence calls to
23002300
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2332,11 +2332,11 @@
23322332
** the interface to a custom page cache implementation.)^
23332333
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
23342334
**
23352335
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
23362336
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2337
-** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
2337
+** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off
23382338
** the current page cache implementation into that object.)^ </dd>
23392339
**
23402340
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
23412341
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
23422342
** global [error log].
@@ -2349,11 +2349,11 @@
23492349
** passed through as the first parameter to the application-defined logger
23502350
** function whenever that function is invoked. ^The second parameter to
23512351
** the logger function is a copy of the first parameter to the corresponding
23522352
** [sqlite3_log()] call and is intended to be a [result code] or an
23532353
** [extended result code]. ^The third parameter passed to the logger is
2354
-** log message after formatting via [sqlite3_snprintf()].
2354
+** a log message after formatting via [sqlite3_snprintf()].
23552355
** The SQLite logging interface is not reentrant; the logger function
23562356
** supplied by the application must not invoke any SQLite interface.
23572357
** In a multi-threaded application, the application-defined logger
23582358
** function must be threadsafe. </dd>
23592359
**
@@ -2540,11 +2540,11 @@
25402540
** CAPI3REF: Database Connection Configuration Options
25412541
**
25422542
** These constants are the available integer configuration options that
25432543
** can be passed as the second parameter to the [sqlite3_db_config()] interface.
25442544
**
2545
-** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2545
+** The [sqlite3_db_config()] interface is a var-args function. It takes a
25462546
** variable number of parameters, though always at least two. The number of
25472547
** parameters passed into sqlite3_db_config() depends on which of these
25482548
** constants is given as the second parameter. This documentation page
25492549
** refers to parameters beyond the second as "arguments". Thus, when this
25502550
** page says "the N-th argument" it means "the N-th parameter past the
@@ -2674,12 +2674,12 @@
26742674
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
26752675
** There must be two additional arguments.
26762676
** When the first argument to this interface is 1, then only the C-API is
26772677
** enabled and the SQL function remains disabled. If the first argument to
26782678
** this interface is 0, then both the C-API and the SQL function are disabled.
2679
-** If the first argument is -1, then no changes are made to state of either the
2680
-** C-API or the SQL function.
2679
+** If the first argument is -1, then no changes are made to the state of either
2680
+** the C-API or the SQL function.
26812681
** The second parameter is a pointer to an integer into which
26822682
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
26832683
** is disabled or enabled following this call. The second parameter may
26842684
** be a NULL pointer, in which case the new setting is not reported back.
26852685
** </dd>
@@ -2793,11 +2793,11 @@
27932793
** </dd>
27942794
**
27952795
** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
27962796
** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
27972797
** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2798
-** the legacy behavior of the [ALTER TABLE RENAME] command such it
2798
+** the legacy behavior of the [ALTER TABLE RENAME] command such that it
27992799
** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
28002800
** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
28012801
** additional information. This feature can also be turned on and off
28022802
** using the [PRAGMA legacy_alter_table] statement.
28032803
** </dd>
@@ -2842,11 +2842,11 @@
28422842
**
28432843
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
28442844
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
28452845
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
28462846
** the legacy file format flag. When activated, this flag causes all newly
2847
-** created database file to have a schema format version number (the 4-byte
2847
+** created database files to have a schema format version number (the 4-byte
28482848
** integer found at offset 44 into the database header) of 1. This in turn
28492849
** means that the resulting database file will be readable and writable by
28502850
** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
28512851
** newly created databases are generally not understandable by SQLite versions
28522852
** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2869,11 +2869,11 @@
28692869
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
28702870
** statistics. For statistics to be collected, the flag must be set on
28712871
** the database handle both when the SQL statement is prepared and when it
28722872
** is stepped. The flag is set (collection of statistics is enabled)
28732873
** by default. <p>This option takes two arguments: an integer and a pointer to
2874
-** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2874
+** an integer. The first argument is 1, 0, or -1 to enable, disable, or
28752875
** leave unchanged the statement scanstatus option. If the second argument
28762876
** is not NULL, then the value of the statement scanstatus setting after
28772877
** processing the first argument is written into the integer that the second
28782878
** argument points to.
28792879
** </dd>
@@ -2912,12 +2912,12 @@
29122912
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
29132913
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
29142914
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
29152915
** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
29162916
** This capability is enabled by default. Applications can disable or
2917
-** reenable this capability using the current DBCONFIG option. If the
2918
-** the this capability is disabled, the [ATTACH] command will still work,
2917
+** reenable this capability using the current DBCONFIG option. If
2918
+** this capability is disabled, the [ATTACH] command will still work,
29192919
** but the database will be opened read-only. If this option is disabled,
29202920
** then the ability to create a new database using [ATTACH] is also disabled,
29212921
** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
29222922
** option.<p>
29232923
** This option takes two arguments which are an integer and a pointer
@@ -2947,11 +2947,11 @@
29472947
**
29482948
** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
29492949
**
29502950
** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
29512951
** overall call to [sqlite3_db_config()] has a total of four parameters.
2952
-** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2952
+** The first argument (the third parameter to sqlite3_db_config()) is an integer.
29532953
** The second argument is a pointer to an integer. If the first argument is 1,
29542954
** then the option becomes enabled. If the first integer argument is 0, then the
29552955
** option is disabled. If the first argument is -1, then the option setting
29562956
** is unchanged. The second argument, the pointer to an integer, may be NULL.
29572957
** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -3237,11 +3237,11 @@
32373237
** and comments that follow the final semicolon are ignored.
32383238
**
32393239
** ^These routines return 0 if the statement is incomplete. ^If a
32403240
** memory allocation fails, then SQLITE_NOMEM is returned.
32413241
**
3242
-** ^These routines do not parse the SQL statements thus
3242
+** ^These routines do not parse the SQL statements and thus
32433243
** will not detect syntactically incorrect SQL.
32443244
**
32453245
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
32463246
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
32473247
** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3354,11 +3354,11 @@
33543354
** Passing 0 to this function disables blocking locks altogether. Passing
33553355
** -1 to this function requests that the VFS blocks for a long time -
33563356
** indefinitely if possible. The results of passing any other negative value
33573357
** are undefined.
33583358
**
3359
-** Internally, each SQLite database handle store two timeout values - the
3359
+** Internally, each SQLite database handle stores two timeout values - the
33603360
** busy-timeout (used for rollback mode databases, or if the VFS does not
33613361
** support blocking locks) and the setlk-timeout (used for blocking locks
33623362
** on wal-mode databases). The sqlite3_busy_timeout() method sets both
33633363
** values, this function sets only the setlk-timeout value. Therefore,
33643364
** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3384,11 +3384,11 @@
33843384
** METHOD: sqlite3
33853385
**
33863386
** This is a legacy interface that is preserved for backwards compatibility.
33873387
** Use of this interface is not recommended.
33883388
**
3389
-** Definition: A <b>result table</b> is memory data structure created by the
3389
+** Definition: A <b>result table</b> is a memory data structure created by the
33903390
** [sqlite3_get_table()] interface. A result table records the
33913391
** complete query results from one or more queries.
33923392
**
33933393
** The table conceptually has a number of rows and columns. But
33943394
** these numbers are not part of the result table itself. These
@@ -3527,11 +3527,11 @@
35273527
** of a signed 32-bit integer.
35283528
**
35293529
** ^Calling sqlite3_free() with a pointer previously returned
35303530
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
35313531
** that it might be reused. ^The sqlite3_free() routine is
3532
-** a no-op if is called with a NULL pointer. Passing a NULL pointer
3532
+** a no-op if it is called with a NULL pointer. Passing a NULL pointer
35333533
** to sqlite3_free() is harmless. After being freed, memory
35343534
** should neither be read nor written. Even reading previously freed
35353535
** memory might result in a segmentation fault or other severe error.
35363536
** Memory corruption, a segmentation fault, or other severe error
35373537
** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3545,17 +3545,17 @@
35453545
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
35463546
** negative then the behavior is exactly the same as calling
35473547
** sqlite3_free(X).
35483548
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
35493549
** of at least N bytes in size or NULL if insufficient memory is available.
3550
-** ^If M is the size of the prior allocation, then min(N,M) bytes
3551
-** of the prior allocation are copied into the beginning of buffer returned
3550
+** ^If M is the size of the prior allocation, then min(N,M) bytes of the
3551
+** prior allocation are copied into the beginning of the buffer returned
35523552
** by sqlite3_realloc(X,N) and the prior allocation is freed.
35533553
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
35543554
** prior allocation is not freed.
35553555
**
3556
-** ^The sqlite3_realloc64(X,N) interfaces works the same as
3556
+** ^The sqlite3_realloc64(X,N) interface works the same as
35573557
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
35583558
** of a 32-bit signed integer.
35593559
**
35603560
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
35613561
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3601,11 +3601,11 @@
36013601
** ^The [sqlite3_memory_highwater()] routine returns the maximum
36023602
** value of [sqlite3_memory_used()] since the high-water mark
36033603
** was last reset. ^The values returned by [sqlite3_memory_used()] and
36043604
** [sqlite3_memory_highwater()] include any overhead
36053605
** added by SQLite in its implementation of [sqlite3_malloc()],
3606
-** but not overhead added by the any underlying system library
3606
+** but not overhead added by any underlying system library
36073607
** routines that [sqlite3_malloc()] may call.
36083608
**
36093609
** ^The memory high-water mark is reset to the current value of
36103610
** [sqlite3_memory_used()] if and only if the parameter to
36113611
** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -4053,19 +4053,19 @@
40534053
** attempt to use the same database connection at the same time.
40544054
** (Mutexes will block any actual concurrency, but in this mode
40554055
** there is no harm in trying.)
40564056
**
40574057
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
4058
-** <dd>The database is opened [shared cache] enabled, overriding
4058
+** <dd>The database is opened with [shared cache] enabled, overriding
40594059
** the default shared cache setting provided by
40604060
** [sqlite3_enable_shared_cache()].)^
40614061
** The [use of shared cache mode is discouraged] and hence shared cache
40624062
** capabilities may be omitted from many builds of SQLite. In such cases,
40634063
** this option is a no-op.
40644064
**
40654065
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
4066
-** <dd>The database is opened [shared cache] disabled, overriding
4066
+** <dd>The database is opened with [shared cache] disabled, overriding
40674067
** the default shared cache setting provided by
40684068
** [sqlite3_enable_shared_cache()].)^
40694069
**
40704070
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
40714071
** <dd>The database connection comes up in "extended result code mode".
@@ -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()],
@@ -4479,19 +4479,19 @@
44794479
** The application does not need to worry about freeing the result.
44804480
** However, the error string might be overwritten or deallocated by
44814481
** subsequent calls to other SQLite interface functions.)^
44824482
**
44834483
** ^The sqlite3_errstr(E) interface returns the English-language text
4484
-** that describes the [result code] E, as UTF-8, or NULL if E is not an
4484
+** that describes the [result code] E, as UTF-8, or NULL if E is not a
44854485
** result code for which a text error message is available.
44864486
** ^(Memory to hold the error message string is managed internally
44874487
** and must not be freed by the application)^.
44884488
**
44894489
** ^If the most recent error references a specific token in the input
44904490
** SQL, the sqlite3_error_offset() interface returns the byte offset
44914491
** of the start of that token. ^The byte offset returned by
4492
-** sqlite3_error_offset() assumes that the input SQL is UTF8.
4492
+** sqlite3_error_offset() assumes that the input SQL is UTF-8.
44934493
** ^If the most recent error does not reference a specific token in the input
44944494
** SQL, then the sqlite3_error_offset() function returns -1.
44954495
**
44964496
** When the serialized [threading mode] is in use, it might be the
44974497
** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
45864586
** CAPI3REF: Run-Time Limit Categories
45874587
** KEYWORDS: {limit category} {*limit categories}
45884588
**
45894589
** These constants define various performance limits
45904590
** that can be lowered at run-time using [sqlite3_limit()].
4591
-** The synopsis of the meanings of the various limits is shown below.
4592
-** Additional information is available at [limits | Limits in SQLite].
4591
+** A concise description of these limits follows, and additional information
4592
+** is available at [limits | Limits in SQLite].
45934593
**
45944594
** <dl>
45954595
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
45964596
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
45974597
**
@@ -4652,11 +4652,11 @@
46524652
#define SQLITE_LIMIT_WORKER_THREADS 11
46534653
46544654
/*
46554655
** CAPI3REF: Prepare Flags
46564656
**
4657
-** These constants define various flags that can be passed into
4657
+** These constants define various flags that can be passed into the
46584658
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
46594659
** [sqlite3_prepare16_v3()] interfaces.
46604660
**
46614661
** New flags may be added in future releases of SQLite.
46624662
**
@@ -4739,11 +4739,11 @@
47394739
** statement is generated.
47404740
** If the caller knows that the supplied string is nul-terminated, then
47414741
** there is a small performance advantage to passing an nByte parameter that
47424742
** is the number of bytes in the input string <i>including</i>
47434743
** the nul-terminator.
4744
-** Note that nByte measure the length of the input in bytes, not
4744
+** Note that nByte measures the length of the input in bytes, not
47454745
** characters, even for the UTF-16 interfaces.
47464746
**
47474747
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
47484748
** past the end of the first SQL statement in zSql. These routines only
47494749
** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
48734873
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
48744874
** will return "SELECT 2345,NULL".)^
48754875
**
48764876
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
48774877
** is available to hold the result, or if the result would exceed the
4878
-** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4878
+** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
48794879
**
48804880
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
48814881
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
48824882
** option causes sqlite3_expanded_sql() to always return NULL.
48834883
**
@@ -5061,11 +5061,11 @@
50615061
/*
50625062
** CAPI3REF: SQL Function Context Object
50635063
**
50645064
** The context in which an SQL function executes is stored in an
50655065
** sqlite3_context object. ^A pointer to an sqlite3_context object
5066
-** is always first parameter to [application-defined SQL functions].
5066
+** is always the first parameter to [application-defined SQL functions].
50675067
** The application-defined SQL function implementation will pass this
50685068
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
50695069
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
50705070
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
50715071
** and/or [sqlite3_set_auxdata()].
@@ -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.
@@ -5798,11 +5798,11 @@
57985798
** CAPI3REF: Destroy A Prepared Statement Object
57995799
** DESTRUCTOR: sqlite3_stmt
58005800
**
58015801
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
58025802
** ^If the most recent evaluation of the statement encountered no errors
5803
-** or if the statement is never been evaluated, then sqlite3_finalize() returns
5803
+** or if the statement has never been evaluated, then sqlite3_finalize() returns
58045804
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
58055805
** sqlite3_finalize(S) returns the appropriate [error code] or
58065806
** [extended error code].
58075807
**
58085808
** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -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
@@ -6030,11 +6030,11 @@
60306030
);
60316031
60326032
/*
60336033
** CAPI3REF: Text Encodings
60346034
**
6035
-** These constant define integer codes that represent the various
6035
+** These constants define integer codes that represent the various
60366036
** text encodings supported by SQLite.
60376037
*/
60386038
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
60396039
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
60406040
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
61226122
** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
61236123
** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
61246124
** result.
61256125
** Every function that invokes [sqlite3_result_subtype()] should have this
61266126
** property. If it does not, then the call to [sqlite3_result_subtype()]
6127
-** might become a no-op if the function is used as term in an
6127
+** might become a no-op if the function is used as a term in an
61286128
** [expression index]. On the other hand, SQL functions that never invoke
61296129
** [sqlite3_result_subtype()] should avoid setting this property, as the
61306130
** purpose of this property is to disable certain optimizations that are
61316131
** incompatible with subtypes.
61326132
**
@@ -6249,11 +6249,11 @@
62496249
**
62506250
** ^Within the [xUpdate] method of a [virtual table], the
62516251
** sqlite3_value_nochange(X) interface returns true if and only if
62526252
** the column corresponding to X is unchanged by the UPDATE operation
62536253
** that the xUpdate method call was invoked to implement and if
6254
-** and the prior [xColumn] method call that was invoked to extracted
6254
+** the prior [xColumn] method call that was invoked to extract
62556255
** the value for that column returned without setting a result (probably
62566256
** because it queried [sqlite3_vtab_nochange()] and found that the column
62576257
** was unchanging). ^Within an [xUpdate] method, any value for which
62586258
** sqlite3_value_nochange(X) is true will in all other respects appear
62596259
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6355,11 +6355,11 @@
63556355
/*
63566356
** CAPI3REF: Copy And Free SQL Values
63576357
** METHOD: sqlite3_value
63586358
**
63596359
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6360
-** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
6360
+** object V and returns a pointer to that copy. ^The [sqlite3_value] returned
63616361
** is a [protected sqlite3_value] object even if the input is not.
63626362
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
63636363
** memory allocation fails. ^If V is a [pointer value], then the result
63646364
** of sqlite3_value_dup(V) is a NULL value.
63656365
**
@@ -6393,11 +6393,11 @@
63936393
** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
63946394
** when first called if N is less than or equal to zero or if a memory
63956395
** allocation error occurs.
63966396
**
63976397
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6398
-** determined by the N parameter on first successful call. Changing the
6398
+** determined by the N parameter on the first successful call. Changing the
63996399
** value of N in any subsequent call to sqlite3_aggregate_context() within
64006400
** the same aggregate function instance will not resize the memory
64016401
** allocation.)^ Within the xFinal callback, it is customary to set
64026402
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
64036403
** pointless memory allocations occur.
@@ -6555,11 +6555,11 @@
65556555
** of as a secret key such that only code that knows the secret key is able
65566556
** to access the associated data.
65576557
**
65586558
** Security Warning: These interfaces should not be exposed in scripting
65596559
** languages or in other circumstances where it might be possible for an
6560
-** an attacker to invoke them. Any agent that can invoke these interfaces
6560
+** attacker to invoke them. Any agent that can invoke these interfaces
65616561
** can probably also take control of the process.
65626562
**
65636563
** Database connection client data is only available for SQLite
65646564
** version 3.44.0 ([dateof:3.44.0]) and later.
65656565
**
@@ -6669,11 +6669,11 @@
66696669
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
66706670
** is non-negative, then as many bytes (not characters) of the text
66716671
** pointed to by the 2nd parameter are taken as the application-defined
66726672
** function result. If the 3rd parameter is non-negative, then it
66736673
** must be the byte offset into the string where the NUL terminator would
6674
-** appear if the string where NUL terminated. If any NUL characters occur
6674
+** appear if the string were NUL terminated. If any NUL characters occur
66756675
** in the string at a byte offset that is less than the value of the 3rd
66766676
** parameter, then the resulting string will contain embedded NULs and the
66776677
** result of expressions operating on strings with embedded NULs is undefined.
66786678
** ^If the 4th parameter to the sqlite3_result_text* interfaces
66796679
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6727,11 +6727,11 @@
67276727
** for the P parameter. ^SQLite invokes D with P as its only argument
67286728
** when SQLite is finished with P. The T parameter should be a static
67296729
** string and preferably a string literal. The sqlite3_result_pointer()
67306730
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
67316731
**
6732
-** If these routines are called from within the different thread
6732
+** If these routines are called from within a different thread
67336733
** than the one containing the application-defined function that received
67346734
** the [sqlite3_context] pointer, the results are undefined.
67356735
*/
67366736
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
67376737
SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -7133,11 +7133,11 @@
71337133
/*
71347134
** CAPI3REF: Return The Schema Name For A Database Connection
71357135
** METHOD: sqlite3
71367136
**
71377137
** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
7138
-** for the N-th database on database connection D, or a NULL pointer of N is
7138
+** for the N-th database on database connection D, or a NULL pointer if N is
71397139
** out of range. An N value of 0 means the main database file. An N of 1 is
71407140
** the "temp" schema. Larger values of N correspond to various ATTACH-ed
71417141
** databases.
71427142
**
71437143
** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -7228,20 +7228,20 @@
72287228
**
72297229
** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
72307230
** <dd>The SQLITE_TXN_READ state means that the database is currently
72317231
** in a read transaction. Content has been read from the database file
72327232
** but nothing in the database file has changed. The transaction state
7233
-** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
7233
+** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are
72347234
** no other conflicting concurrent write transactions. The transaction
72357235
** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
72367236
** [COMMIT].</dd>
72377237
**
72387238
** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
72397239
** <dd>The SQLITE_TXN_WRITE state means that the database is currently
72407240
** in a write transaction. Content has been written to the database file
72417241
** but has not yet committed. The transaction state will change to
7242
-** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7242
+** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
72437243
*/
72447244
#define SQLITE_TXN_NONE 0
72457245
#define SQLITE_TXN_READ 1
72467246
#define SQLITE_TXN_WRITE 2
72477247
@@ -7518,11 +7518,11 @@
75187518
75197519
/*
75207520
** CAPI3REF: Impose A Limit On Heap Size
75217521
**
75227522
** These interfaces impose limits on the amount of heap memory that will be
7523
-** by all database connections within a single process.
7523
+** used by all database connections within a single process.
75247524
**
75257525
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
75267526
** soft limit on the amount of heap memory that may be allocated by SQLite.
75277527
** ^SQLite strives to keep heap memory utilization below the soft heap
75287528
** limit by reducing the number of pages held in the page cache
@@ -7576,11 +7576,11 @@
75767576
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
75777577
** from the heap.
75787578
** </ul>)^
75797579
**
75807580
** The circumstances under which SQLite will enforce the heap limits may
7581
-** changes in future releases of SQLite.
7581
+** change in future releases of SQLite.
75827582
*/
75837583
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
75847584
SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
75857585
75867586
/*
@@ -7691,12 +7691,12 @@
76917691
** be tried also.
76927692
**
76937693
** ^The entry point is zProc.
76947694
** ^(zProc may be 0, in which case SQLite will try to come up with an
76957695
** entry point name on its own. It first tries "sqlite3_extension_init".
7696
-** If that does not work, it constructs a name "sqlite3_X_init" where the
7697
-** X is consists of the lower-case equivalent of all ASCII alphabetic
7696
+** If that does not work, it constructs a name "sqlite3_X_init" where
7697
+** X consists of the lower-case equivalent of all ASCII alphabetic
76987698
** characters in the filename from the last "/" to the first following
76997699
** "." and omitting any initial "lib".)^
77007700
** ^The sqlite3_load_extension() interface returns
77017701
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
77027702
** ^If an error occurs and pzErrMsg is not 0, then the
@@ -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,
@@ -7927,11 +7927,11 @@
79277927
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
79287928
** is true, then the constraint is assumed to be fully handled by the
79297929
** virtual table and might not be checked again by the byte code.)^ ^(The
79307930
** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
79317931
** is left in its default setting of false, the constraint will always be
7932
-** checked separately in byte code. If the omit flag is change to true, then
7932
+** checked separately in byte code. If the omit flag is changed to true, then
79337933
** the constraint may or may not be checked in byte code. In other words,
79347934
** when the omit flag is true there is no guarantee that the constraint will
79357935
** not be checked again using byte code.)^
79367936
**
79377937
** ^The idxNum and idxStr values are recorded and passed into the
@@ -7953,11 +7953,11 @@
79537953
** will be returned by the strategy.
79547954
**
79557955
** The xBestIndex method may optionally populate the idxFlags field with a
79567956
** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
79577957
** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7958
-** output to show the idxNum has hex instead of as decimal. Another flag is
7958
+** output to show the idxNum as hex instead of as decimal. Another flag is
79597959
** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
79607960
** return at most one row.
79617961
**
79627962
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
79637963
** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -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
@@ -8529,11 +8529,11 @@
85298529
** function that calls sqlite3_initialize().
85308530
**
85318531
** ^The sqlite3_mutex_alloc() routine allocates a new
85328532
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
85338533
** routine returns NULL if it is unable to allocate the requested
8534
-** mutex. The argument to sqlite3_mutex_alloc() must one of these
8534
+** mutex. The argument to sqlite3_mutex_alloc() must be one of these
85358535
** integer constants:
85368536
**
85378537
** <ul>
85388538
** <li> SQLITE_MUTEX_FAST
85398539
** <li> SQLITE_MUTEX_RECURSIVE
@@ -8762,11 +8762,11 @@
87628762
87638763
/*
87648764
** CAPI3REF: Retrieve the mutex for a database connection
87658765
** METHOD: sqlite3
87668766
**
8767
-** ^This interface returns a pointer the [sqlite3_mutex] object that
8767
+** ^This interface returns a pointer to the [sqlite3_mutex] object that
87688768
** serializes access to the [database connection] given in the argument
87698769
** when the [threading mode] is Serialized.
87708770
** ^If the [threading mode] is Single-thread or Multi-thread then this
87718771
** routine returns a NULL pointer.
87728772
*/
@@ -8885,11 +8885,11 @@
88858885
88868886
/*
88878887
** CAPI3REF: SQL Keyword Checking
88888888
**
88898889
** These routines provide access to the set of SQL language keywords
8890
-** recognized by SQLite. Applications can uses these routines to determine
8890
+** recognized by SQLite. Applications can use these routines to determine
88918891
** whether or not a specific identifier needs to be escaped (for example,
88928892
** by enclosing in double-quotes) so as not to confuse the parser.
88938893
**
88948894
** The sqlite3_keyword_count() interface returns the number of distinct
88958895
** keywords understood by SQLite.
@@ -9053,11 +9053,11 @@
90539053
**
90549054
** ^The [sqlite3_str_value(X)] method returns a pointer to the current
90559055
** content of the dynamic string under construction in X. The value
90569056
** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
90579057
** and might be freed or altered by any subsequent method on the same
9058
-** [sqlite3_str] object. Applications must not used the pointer returned
9058
+** [sqlite3_str] object. Applications must not use the pointer returned by
90599059
** [sqlite3_str_value(X)] after any subsequent method call on the same
90609060
** object. ^Applications may change the content of the string returned
90619061
** by [sqlite3_str_value(X)] as long as they do not write into any bytes
90629062
** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
90639063
** write any byte after any subsequent sqlite3_str method call.
@@ -9139,11 +9139,11 @@
91399139
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
91409140
** <dd>This parameter returns the number of bytes of page cache
91419141
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
91429142
** buffer and where forced to overflow to [sqlite3_malloc()]. The
91439143
** returned value includes allocations that overflowed because they
9144
-** where too large (they were larger than the "sz" parameter to
9144
+** were too large (they were larger than the "sz" parameter to
91459145
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
91469146
** no space was left in the page cache.</dd>)^
91479147
**
91489148
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
91499149
** <dd>This parameter records the largest memory allocation request
@@ -9223,53 +9223,55 @@
92239223
** checked out.</dd>)^
92249224
**
92259225
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
92269226
** <dd>This parameter returns the number of malloc attempts that were
92279227
** satisfied using lookaside memory. Only the high-water value is meaningful;
9228
-** the current value is always zero.)^
9228
+** the current value is always zero.</dd>)^
92299229
**
92309230
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
92319231
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
9232
-** <dd>This parameter returns the number malloc attempts that might have
9232
+** <dd>This parameter returns the number of malloc attempts that might have
92339233
** been satisfied using lookaside memory but failed due to the amount of
92349234
** memory requested being larger than the lookaside slot size.
92359235
** Only the high-water value is meaningful;
9236
-** the current value is always zero.)^
9236
+** the current value is always zero.</dd>)^
92379237
**
92389238
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
92399239
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
9240
-** <dd>This parameter returns the number malloc attempts that might have
9240
+** <dd>This parameter returns the number of malloc attempts that might have
92419241
** been satisfied using lookaside memory but failed due to all lookaside
92429242
** memory already being in use.
92439243
** Only the high-water value is meaningful;
9244
-** the current value is always zero.)^
9244
+** the current value is always zero.</dd>)^
92459245
**
92469246
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
92479247
** <dd>This parameter returns the approximate number of bytes of heap
92489248
** memory used by all pager caches associated with the database connection.)^
92499249
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
9250
+** </dd>
92509251
**
92519252
** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
92529253
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
92539254
** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
92549255
** pager cache is shared between two or more connections the bytes of heap
92559256
** memory used by that pager cache is divided evenly between the attached
92569257
** connections.)^ In other words, if none of the pager caches associated
92579258
** with the database connection are shared, this request returns the same
9258
-** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
9259
+** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are
92599260
** shared, the value returned by this call will be smaller than that returned
92609261
** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
9261
-** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
9262
+** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
92629263
**
92639264
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
92649265
** <dd>This parameter returns the approximate number of bytes of heap
92659266
** memory used to store the schema for all databases associated
92669267
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
92679268
** ^The full amount of memory used by the schemas is reported, even if the
92689269
** schema memory is shared with other database connections due to
92699270
** [shared cache mode] being enabled.
92709271
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
9272
+** </dd>
92719273
**
92729274
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
92739275
** <dd>This parameter returns the approximate number of bytes of heap
92749276
** and lookaside memory used by all prepared statements associated with
92759277
** the database connection.)^
@@ -9302,11 +9304,11 @@
93029304
** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
93039305
** <dd>This parameter returns the number of dirty cache entries that have
93049306
** been written to disk in the middle of a transaction due to the page
93059307
** cache overflowing. Transactions are more efficient if they are written
93069308
** to disk all at once. When pages spill mid-transaction, that introduces
9307
-** additional overhead. This parameter can be used help identify
9309
+** additional overhead. This parameter can be used to help identify
93089310
** inefficiencies that can be resolved by increasing the cache size.
93099311
** </dd>
93109312
**
93119313
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
93129314
** <dd>This parameter returns zero for the current value if and only if
@@ -9373,48 +9375,48 @@
93739375
** careful use of indices.</dd>
93749376
**
93759377
** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
93769378
** <dd>^This is the number of sort operations that have occurred.
93779379
** A non-zero value in this counter may indicate an opportunity to
9378
-** improvement performance through careful use of indices.</dd>
9380
+** improve performance through careful use of indices.</dd>
93799381
**
93809382
** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
93819383
** <dd>^This is the number of rows inserted into transient indices that
93829384
** were created automatically in order to help joins run faster.
93839385
** A non-zero value in this counter may indicate an opportunity to
9384
-** improvement performance by adding permanent indices that do not
9386
+** improve performance by adding permanent indices that do not
93859387
** need to be reinitialized each time the statement is run.</dd>
93869388
**
93879389
** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
93889390
** <dd>^This is the number of virtual machine operations executed
93899391
** by the prepared statement if that number is less than or equal
93909392
** to 2147483647. The number of virtual machine operations can be
93919393
** used as a proxy for the total work done by the prepared statement.
93929394
** If the number of virtual machine operations exceeds 2147483647
9393
-** then the value returned by this statement status code is undefined.
9395
+** then the value returned by this statement status code is undefined.</dd>
93949396
**
93959397
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
93969398
** <dd>^This is the number of times that the prepare statement has been
93979399
** automatically regenerated due to schema changes or changes to
9398
-** [bound parameters] that might affect the query plan.
9400
+** [bound parameters] that might affect the query plan.</dd>
93999401
**
94009402
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
94019403
** <dd>^This is the number of times that the prepared statement has
94029404
** been run. A single "run" for the purposes of this counter is one
94039405
** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
94049406
** The counter is incremented on the first [sqlite3_step()] call of each
9405
-** cycle.
9407
+** cycle.</dd>
94069408
**
94079409
** [[SQLITE_STMTSTATUS_FILTER_MISS]]
94089410
** [[SQLITE_STMTSTATUS_FILTER HIT]]
94099411
** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
94109412
** SQLITE_STMTSTATUS_FILTER_MISS</dt>
94119413
** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
94129414
** step was bypassed because a Bloom filter returned not-found. The
94139415
** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
94149416
** times that the Bloom filter returned a find, and thus the join step
9415
-** had to be processed as normal.
9417
+** had to be processed as normal.</dd>
94169418
**
94179419
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
94189420
** <dd>^This is the approximate number of bytes of heap memory
94199421
** used to store the prepared statement. ^This value is not actually
94209422
** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9515,31 +9517,31 @@
95159517
** [[the xCreate() page cache methods]]
95169518
** ^SQLite invokes the xCreate() method to construct a new cache instance.
95179519
** SQLite will typically create one cache instance for each open database file,
95189520
** though this is not guaranteed. ^The
95199521
** first parameter, szPage, is the size in bytes of the pages that must
9520
-** be allocated by the cache. ^szPage will always a power of two. ^The
9522
+** be allocated by the cache. ^szPage will always be a power of two. ^The
95219523
** second parameter szExtra is a number of bytes of extra storage
9522
-** associated with each page cache entry. ^The szExtra parameter will
9524
+** associated with each page cache entry. ^The szExtra parameter will be
95239525
** a number less than 250. SQLite will use the
95249526
** extra szExtra bytes on each page to store metadata about the underlying
95259527
** database page on disk. The value passed into szExtra depends
95269528
** on the SQLite version, the target platform, and how SQLite was compiled.
95279529
** ^The third argument to xCreate(), bPurgeable, is true if the cache being
95289530
** created will be used to cache database pages of a file stored on disk, or
95299531
** false if it is used for an in-memory database. The cache implementation
9530
-** does not have to do anything special based with the value of bPurgeable;
9532
+** does not have to do anything special based upon the value of bPurgeable;
95319533
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
95329534
** never invoke xUnpin() except to deliberately delete a page.
95339535
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
95349536
** false will always have the "discard" flag set to true.
9535
-** ^Hence, a cache created with bPurgeable false will
9537
+** ^Hence, a cache created with bPurgeable set to false will
95369538
** never contain any unpinned pages.
95379539
**
95389540
** [[the xCachesize() page cache method]]
95399541
** ^(The xCachesize() method may be called at any time by SQLite to set the
9540
-** suggested maximum cache-size (number of pages stored by) the cache
9542
+** suggested maximum cache-size (number of pages stored) for the cache
95419543
** instance passed as the first argument. This is the value configured using
95429544
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
95439545
** parameter, the implementation is not required to do anything with this
95449546
** value; it is advisory only.
95459547
**
@@ -9562,16 +9564,16 @@
95629564
**
95639565
** If the requested page is already in the page cache, then the page cache
95649566
** implementation must return a pointer to the page buffer with its content
95659567
** intact. If the requested page is not already in the cache, then the
95669568
** cache implementation should use the value of the createFlag
9567
-** parameter to help it determined what action to take:
9569
+** parameter to help it determine what action to take:
95689570
**
95699571
** <table border=1 width=85% align=center>
95709572
** <tr><th> createFlag <th> Behavior when page is not already in cache
95719573
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9572
-** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
9574
+** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.
95739575
** Otherwise return NULL.
95749576
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
95759577
** NULL if allocating a new page is effectively impossible.
95769578
** </table>
95779579
**
@@ -9584,11 +9586,11 @@
95849586
** [[the xUnpin() page cache method]]
95859587
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
95869588
** as its second argument. If the third parameter, discard, is non-zero,
95879589
** then the page must be evicted from the cache.
95889590
** ^If the discard parameter is
9589
-** zero, then the page may be discarded or retained at the discretion of
9591
+** zero, then the page may be discarded or retained at the discretion of the
95909592
** page cache implementation. ^The page cache implementation
95919593
** may choose to evict unpinned pages at any time.
95929594
**
95939595
** The cache must not perform any reference counting. A single
95949596
** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9602,11 +9604,11 @@
96029604
** to be pinned.
96039605
**
96049606
** When SQLite calls the xTruncate() method, the cache must discard all
96059607
** existing cache entries with page numbers (keys) greater than or equal
96069608
** to the value of the iLimit parameter passed to xTruncate(). If any
9607
-** of these pages are pinned, they are implicitly unpinned, meaning that
9609
+** of these pages are pinned, they become implicitly unpinned, meaning that
96089610
** they can be safely discarded.
96099611
**
96109612
** [[the xDestroy() page cache method]]
96119613
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
96129614
** All resources associated with the specified cache should be freed. ^After
@@ -9782,11 +9784,11 @@
97829784
** sqlite3_backup_step(), the source database may be modified mid-way
97839785
** through the backup process. ^If the source database is modified by an
97849786
** external process or via a database connection other than the one being
97859787
** used by the backup operation, then the backup will be automatically
97869788
** 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
9789
+** database is modified by using the same database connection as is used
97889790
** by the backup operation, then the backup database is automatically
97899791
** updated at the same time.
97909792
**
97919793
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
97929794
**
@@ -9799,11 +9801,11 @@
97999801
** active write-transaction on the destination database is rolled back.
98009802
** The [sqlite3_backup] object is invalid
98019803
** and may not be used following a call to sqlite3_backup_finish().
98029804
**
98039805
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9804
-** sqlite3_backup_step() errors occurred, regardless or whether or not
9806
+** sqlite3_backup_step() errors occurred, regardless of whether or not
98059807
** sqlite3_backup_step() completed.
98069808
** ^If an out-of-memory condition or IO error occurred during any prior
98079809
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
98089810
** sqlite3_backup_finish() returns the corresponding [error code].
98099811
**
@@ -9901,11 +9903,11 @@
99019903
** identity of the database connection (the blocking connection) that
99029904
** has locked the required resource is stored internally. ^After an
99039905
** application receives an SQLITE_LOCKED error, it may call the
99049906
** sqlite3_unlock_notify() method with the blocked connection handle as
99059907
** the first argument to register for a callback that will be invoked
9906
-** when the blocking connections current transaction is concluded. ^The
9908
+** when the blocking connection's current transaction is concluded. ^The
99079909
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
99089910
** call that concludes the blocking connection's transaction.
99099911
**
99109912
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
99119913
** there is a chance that the blocking connection will have already
@@ -9921,11 +9923,11 @@
99219923
** ^(There may be at most one unlock-notify callback registered by a
99229924
** blocked connection. If sqlite3_unlock_notify() is called when the
99239925
** blocked connection already has a registered unlock-notify callback,
99249926
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
99259927
** called with a NULL pointer as its second argument, then any existing
9926
-** unlock-notify callback is canceled. ^The blocked connections
9928
+** unlock-notify callback is canceled. ^The blocked connection's
99279929
** unlock-notify callback may also be canceled by closing the blocked
99289930
** connection using [sqlite3_close()].
99299931
**
99309932
** The unlock-notify callback is not reentrant. If an application invokes
99319933
** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10319,11 +10321,11 @@
1031910321
** where X is an integer. If X is zero, then the [virtual table] whose
1032010322
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
1032110323
** support constraints. In this configuration (which is the default) if
1032210324
** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
1032310325
** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10324
-** specified as part of the users SQL statement, regardless of the actual
10326
+** specified as part of the user's SQL statement, regardless of the actual
1032510327
** ON CONFLICT mode specified.
1032610328
**
1032710329
** If X is non-zero, then the virtual table implementation guarantees
1032810330
** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
1032910331
** any modifications to internal or persistent data structures have been made.
@@ -10353,11 +10355,11 @@
1035310355
** </dd>
1035410356
**
1035510357
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
1035610358
** <dd>Calls of the form
1035710359
** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10358
-** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10360
+** [xConnect] or [xCreate] methods of a [virtual table] implementation
1035910361
** identify that virtual table as being safe to use from within triggers
1036010362
** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
1036110363
** virtual table can do no serious harm even if it is controlled by a
1036210364
** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
1036310365
** flag unless absolutely necessary.
@@ -10521,21 +10523,21 @@
1052110523
** <tr><td>2<td>no<td>yes<td>yes
1052210524
** <tr><td>3<td>yes<td>yes<td>yes
1052310525
** </table>
1052410526
**
1052510527
** ^For the purposes of comparing virtual table output values to see if the
10526
-** values are same value for sorting purposes, two NULL values are considered
10528
+** values are the same value for sorting purposes, two NULL values are considered
1052710529
** to be the same. In other words, the comparison operator is "IS"
1052810530
** (or "IS NOT DISTINCT FROM") and not "==".
1052910531
**
1053010532
** If a virtual table implementation is unable to meet the requirements
1053110533
** specified above, then it must not set the "orderByConsumed" flag in the
1053210534
** [sqlite3_index_info] object or an incorrect answer may result.
1053310535
**
1053410536
** ^A virtual table implementation is always free to return rows in any order
1053510537
** it wants, as long as the "orderByConsumed" flag is not set. ^When the
10536
-** the "orderByConsumed" flag is unset, the query planner will add extra
10538
+** "orderByConsumed" flag is unset, the query planner will add extra
1053710539
** [bytecode] to ensure that the final results returned by the SQL query are
1053810540
** ordered correctly. The use of the "orderByConsumed" flag and the
1053910541
** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
1054010542
** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
1054110543
** flag might help queries against a virtual table to run faster. Being
@@ -10628,11 +10630,11 @@
1062810630
**
1062910631
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
1063010632
** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
1063110633
** xFilter method which invokes these routines, and specifically
1063210634
** a parameter that was previously selected for all-at-once IN constraint
10633
-** processing use the [sqlite3_vtab_in()] interface in the
10635
+** processing using the [sqlite3_vtab_in()] interface in the
1063410636
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
1063510637
** an xFilter argument that was selected for all-at-once IN constraint
1063610638
** processing, then these routines return [SQLITE_ERROR].)^
1063710639
**
1063810640
** ^(Use these routines to access all values on the right-hand side
@@ -10683,11 +10685,11 @@
1068310685
** right-hand operand is not known, then *V is set to a NULL pointer.
1068410686
** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
1068510687
** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
1068610688
** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
1068710689
** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10688
-** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10690
+** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if
1068910691
** something goes wrong.
1069010692
**
1069110693
** The sqlite3_vtab_rhs_value() interface is usually only successful if
1069210694
** the right-hand operand of a constraint is a literal value in the original
1069310695
** SQL statement. If the right-hand operand is an expression or a reference
@@ -10711,12 +10713,12 @@
1071110713
/*
1071210714
** CAPI3REF: Conflict resolution modes
1071310715
** KEYWORDS: {conflict resolution mode}
1071410716
**
1071510717
** These constants are returned by [sqlite3_vtab_on_conflict()] to
10716
-** inform a [virtual table] implementation what the [ON CONFLICT] mode
10717
-** is for the SQL statement being evaluated.
10718
+** inform a [virtual table] implementation of the [ON CONFLICT] mode
10719
+** for the SQL statement being evaluated.
1071810720
**
1071910721
** Note that the [SQLITE_IGNORE] constant is also used as a potential
1072010722
** return value from the [sqlite3_set_authorizer()] callback and that
1072110723
** [SQLITE_ABORT] is also a [result code].
1072210724
*/
@@ -10752,43 +10754,43 @@
1075210754
** to the total number of rows examined by all iterations of the X-th loop.</dd>
1075310755
**
1075410756
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
1075510757
** <dd>^The "double" variable pointed to by the V parameter will be set to the
1075610758
** query planner's estimate for the average number of rows output from each
10757
-** iteration of the X-th loop. If the query planner's estimates was accurate,
10759
+** iteration of the X-th loop. If the query planner's estimate was accurate,
1075810760
** then this value will approximate the quotient NVISIT/NLOOP and the
1075910761
** product of this value for all prior loops with the same SELECTID will
10760
-** be the NLOOP value for the current loop.
10762
+** be the NLOOP value for the current loop.</dd>
1076110763
**
1076210764
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
1076310765
** <dd>^The "const char *" variable pointed to by the V parameter will be set
1076410766
** to a zero-terminated UTF-8 string containing the name of the index or table
10765
-** used for the X-th loop.
10767
+** used for the X-th loop.</dd>
1076610768
**
1076710769
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
1076810770
** <dd>^The "const char *" variable pointed to by the V parameter will be set
1076910771
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10770
-** description for the X-th loop.
10772
+** description for the X-th loop.</dd>
1077110773
**
1077210774
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
1077310775
** <dd>^The "int" variable pointed to by the V parameter will be set to the
1077410776
** id for the X-th query plan element. The id value is unique within the
1077510777
** statement. The select-id is the same value as is output in the first
10776
-** column of an [EXPLAIN QUERY PLAN] query.
10778
+** column of an [EXPLAIN QUERY PLAN] query.</dd>
1077710779
**
1077810780
** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
1077910781
** <dd>The "int" variable pointed to by the V parameter will be set to the
10780
-** the id of the parent of the current query element, if applicable, or
10782
+** id of the parent of the current query element, if applicable, or
1078110783
** to zero if the query element has no parent. This is the same value as
10782
-** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10784
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>
1078310785
**
1078410786
** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
1078510787
** <dd>The sqlite3_int64 output value is set to the number of cycles,
1078610788
** according to the processor time-stamp counter, that elapsed while the
1078710789
** query element was being processed. This value is not available for
1078810790
** all query elements - if it is unavailable the output variable is
10789
-** set to -1.
10791
+** set to -1.</dd>
1079010792
** </dl>
1079110793
*/
1079210794
#define SQLITE_SCANSTAT_NLOOP 0
1079310795
#define SQLITE_SCANSTAT_NVISIT 1
1079410796
#define SQLITE_SCANSTAT_EST 2
@@ -10825,12 +10827,12 @@
1082510827
** the EXPLAIN QUERY PLAN output) are available. Invoking API
1082610828
** sqlite3_stmt_scanstatus() is equivalent to calling
1082710829
** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
1082810830
**
1082910831
** Parameter "idx" identifies the specific query element to retrieve statistics
10830
-** for. Query elements are numbered starting from zero. A value of -1 may be
10831
-** to query for statistics regarding the entire query. ^If idx is out of range
10832
+** for. Query elements are numbered starting from zero. A value of -1 may
10833
+** retrieve statistics for the entire query. ^If idx is out of range
1083210834
** - less than -1 or greater than or equal to the total number of query
1083310835
** elements used to implement the statement - a non-zero value is returned and
1083410836
** the variable that pOut points to is unchanged.
1083510837
**
1083610838
** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10869,11 +10871,11 @@
1086910871
/*
1087010872
** CAPI3REF: Flush caches to disk mid-transaction
1087110873
** METHOD: sqlite3
1087210874
**
1087310875
** ^If a write-transaction is open on [database connection] D when the
10874
-** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10876
+** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
1087510877
** pages in the pager-cache that are not currently in use are written out
1087610878
** to disk. A dirty page may be in use if a database cursor created by an
1087710879
** active SQL statement is reading from it, or if it is page 1 of a database
1087810880
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
1087910881
** interface flushes caches for all schemas - "main", "temp", and
@@ -10983,12 +10985,12 @@
1098310985
** operation; or 1 for inserts, updates, or deletes invoked by top-level
1098410986
** triggers; or 2 for changes resulting from triggers called by top-level
1098510987
** triggers; and so forth.
1098610988
**
1098710989
** When the [sqlite3_blob_write()] API is used to update a blob column,
10988
-** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10989
-** in this case the new values are not available. In this case, when a
10990
+** the pre-update hook is invoked with SQLITE_DELETE, because
10991
+** the new values are not yet available. In this case, when a
1099010992
** callback made with op==SQLITE_DELETE is actually a write using the
1099110993
** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
1099210994
** the index of the column being written. In other cases, where the
1099310995
** pre-update hook is being invoked for some other reason, including a
1099410996
** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -11237,20 +11239,20 @@
1123711239
** is written into *P.
1123811240
**
1123911241
** For an ordinary on-disk database file, the serialization is just a
1124011242
** copy of the disk file. For an in-memory database or a "TEMP" database,
1124111243
** the serialization is the same sequence of bytes which would be written
11242
-** to disk if that database where backed up to disk.
11244
+** to disk if that database were backed up to disk.
1124311245
**
1124411246
** The usual case is that sqlite3_serialize() copies the serialization of
1124511247
** the database into memory obtained from [sqlite3_malloc64()] and returns
1124611248
** a pointer to that memory. The caller is responsible for freeing the
1124711249
** returned value to avoid a memory leak. However, if the F argument
1124811250
** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
1124911251
** are made, and the sqlite3_serialize() function will return a pointer
1125011252
** to the contiguous memory representation of the database that SQLite
11251
-** is currently using for that database, or NULL if the no such contiguous
11253
+** is currently using for that database, or NULL if no such contiguous
1125211254
** memory representation of the database exists. A contiguous memory
1125311255
** representation of the database will usually only exist if there has
1125411256
** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
1125511257
** values of D and S.
1125611258
** The size of the database is written into *P even if the
@@ -11317,11 +11319,11 @@
1131711319
**
1131811320
** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
1131911321
** database is currently in a read transaction or is involved in a backup
1132011322
** operation.
1132111323
**
11322
-** It is not possible to deserialized into the TEMP database. If the
11324
+** It is not possible to deserialize into the TEMP database. If the
1132311325
** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
1132411326
** function returns SQLITE_ERROR.
1132511327
**
1132611328
** The deserialized database should not be in [WAL mode]. If the database
1132711329
** is in WAL mode, then any attempt to use the database file will result
@@ -11339,19 +11341,19 @@
1133911341
*/
1134011342
SQLITE_API int sqlite3_deserialize(
1134111343
sqlite3 *db, /* The database connection */
1134211344
const char *zSchema, /* Which DB to reopen with the deserialization */
1134311345
unsigned char *pData, /* The serialized database content */
11344
- sqlite3_int64 szDb, /* Number bytes in the deserialization */
11346
+ sqlite3_int64 szDb, /* Number of bytes in the deserialization */
1134511347
sqlite3_int64 szBuf, /* Total size of buffer pData[] */
1134611348
unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
1134711349
);
1134811350
1134911351
/*
1135011352
** CAPI3REF: Flags for sqlite3_deserialize()
1135111353
**
11352
-** The following are allowed values for 6th argument (the F argument) to
11354
+** The following are allowed values for the 6th argument (the F argument) to
1135311355
** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
1135411356
**
1135511357
** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
1135611358
** in the P argument is held in memory obtained from [sqlite3_malloc64()]
1135711359
** and that SQLite should take ownership of this memory and automatically
@@ -12084,11 +12086,11 @@
1208412086
** CAPI3REF: Flags for sqlite3changeset_start_v2
1208512087
**
1208612088
** The following flags may passed via the 4th parameter to
1208712089
** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
1208812090
**
12089
-** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
12091
+** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
1209012092
** Invert the changeset while iterating through it. This is equivalent to
1209112093
** inverting a changeset using sqlite3changeset_invert() before applying it.
1209212094
** It is an error to specify this flag with a patchset.
1209312095
*/
1209412096
#define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12629,17 +12631,26 @@
1262912631
** Apply a changeset or patchset to a database. These functions attempt to
1263012632
** update the "main" database attached to handle db with the changes found in
1263112633
** the changeset passed via the second and third arguments.
1263212634
**
1263312635
** The fourth argument (xFilter) passed to these functions is the "filter
12634
-** callback". If it is not NULL, then for each table affected by at least one
12635
-** change in the changeset, the filter callback is invoked with
12636
-** the table name as the second argument, and a copy of the context pointer
12637
-** passed as the sixth argument as the first. If the "filter callback"
12638
-** returns zero, then no attempt is made to apply any changes to the table.
12639
-** Otherwise, if the return value is non-zero or the xFilter argument to
12640
-** is NULL, all changes related to the table are attempted.
12636
+** callback". This may be passed NULL, in which case all changes in the
12637
+** changeset are applied to the database. For sqlite3changeset_apply() and
12638
+** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
12639
+** for each table affected by at least one change in the changeset. In this
12640
+** case the table name is passed as the second argument, and a copy of
12641
+** the context pointer passed as the sixth argument to apply() or apply_v2()
12642
+** as the first. If the "filter callback" returns zero, then no attempt is
12643
+** made to apply any changes to the table. Otherwise, if the return value is
12644
+** non-zero, all changes related to the table are attempted.
12645
+**
12646
+** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once
12647
+** per change. The second argument in this case is an sqlite3_changeset_iter
12648
+** that may be queried using the usual APIs for the details of the current
12649
+** change. If the "filter callback" returns zero in this case, then no attempt
12650
+** is made to apply the current change. If it returns non-zero, the change
12651
+** is applied.
1264112652
**
1264212653
** For each table that is not excluded by the filter callback, this function
1264312654
** tests that the target database contains a compatible table. A table is
1264412655
** considered compatible if all of the following are true:
1264512656
**
@@ -12656,15 +12667,15 @@
1265612667
** changes associated with the table are applied. A warning message is issued
1265712668
** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
1265812669
** one such warning is issued for each table in the changeset.
1265912670
**
1266012671
** For each change for which there is a compatible table, an attempt is made
12661
-** to modify the table contents according to the UPDATE, INSERT or DELETE
12662
-** change. If a change cannot be applied cleanly, the conflict handler
12663
-** function passed as the fifth argument to sqlite3changeset_apply() may be
12664
-** invoked. A description of exactly when the conflict handler is invoked for
12665
-** each type of change is below.
12672
+** to modify the table contents according to each UPDATE, INSERT or DELETE
12673
+** change that is not excluded by a filter callback. If a change cannot be
12674
+** applied cleanly, the conflict handler function passed as the fifth argument
12675
+** to sqlite3changeset_apply() may be invoked. A description of exactly when
12676
+** the conflict handler is invoked for each type of change is below.
1266612677
**
1266712678
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
1266812679
** of passing anything other than a valid function pointer as the xConflict
1266912680
** argument are undefined.
1267012681
**
@@ -12802,10 +12813,27 @@
1280212813
void *pChangeset, /* Changeset blob */
1280312814
int(*xFilter)(
1280412815
void *pCtx, /* Copy of sixth arg to _apply() */
1280512816
const char *zTab /* Table name */
1280612817
),
12818
+ int(*xConflict)(
12819
+ void *pCtx, /* Copy of sixth arg to _apply() */
12820
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12821
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
12822
+ ),
12823
+ void *pCtx, /* First argument passed to xConflict */
12824
+ void **ppRebase, int *pnRebase, /* OUT: Rebase data */
12825
+ int flags /* SESSION_CHANGESETAPPLY_* flags */
12826
+);
12827
+SQLITE_API int sqlite3changeset_apply_v3(
12828
+ sqlite3 *db, /* Apply change to "main" db of this handle */
12829
+ int nChangeset, /* Size of changeset in bytes */
12830
+ void *pChangeset, /* Changeset blob */
12831
+ int(*xFilter)(
12832
+ void *pCtx, /* Copy of sixth arg to _apply() */
12833
+ sqlite3_changeset_iter *p /* Handle describing change */
12834
+ ),
1280712835
int(*xConflict)(
1280812836
void *pCtx, /* Copy of sixth arg to _apply() */
1280912837
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1281012838
sqlite3_changeset_iter *p /* Handle describing change and conflict */
1281112839
),
@@ -13221,10 +13249,27 @@
1322113249
void *pIn, /* First arg for xInput */
1322213250
int(*xFilter)(
1322313251
void *pCtx, /* Copy of sixth arg to _apply() */
1322413252
const char *zTab /* Table name */
1322513253
),
13254
+ int(*xConflict)(
13255
+ void *pCtx, /* Copy of sixth arg to _apply() */
13256
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
13257
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
13258
+ ),
13259
+ void *pCtx, /* First argument passed to xConflict */
13260
+ void **ppRebase, int *pnRebase,
13261
+ int flags
13262
+);
13263
+SQLITE_API int sqlite3changeset_apply_v3_strm(
13264
+ sqlite3 *db, /* Apply change to "main" db of this handle */
13265
+ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
13266
+ void *pIn, /* First arg for xInput */
13267
+ int(*xFilter)(
13268
+ void *pCtx, /* Copy of sixth arg to _apply() */
13269
+ sqlite3_changeset_iter *p
13270
+ ),
1322613271
int(*xConflict)(
1322713272
void *pCtx, /* Copy of sixth arg to _apply() */
1322813273
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1322913274
sqlite3_changeset_iter *p /* Handle describing change and conflict */
1323013275
),
@@ -15174,11 +15219,11 @@
1517415219
/*
1517515220
** GCC does not define the offsetof() macro so we'll have to do it
1517615221
** ourselves.
1517715222
*/
1517815223
#ifndef offsetof
15179
-#define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
15224
+# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
1518015225
#endif
1518115226
1518215227
/*
1518315228
** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
1518415229
** to avoid complaints from -fsanitize=strict-bounds.
@@ -15440,12 +15485,12 @@
1544015485
/*
1544115486
** Macro SMXV(n) return the maximum value that can be held in variable n,
1544215487
** assuming n is a signed integer type. UMXV(n) is similar for unsigned
1544315488
** integer types.
1544415489
*/
15445
-#define SMXV(n) ((((i64)1)<<(sizeof(n)-1))-1)
15446
-#define UMXV(n) ((((i64)1)<<(sizeof(n)))-1)
15490
+#define SMXV(n) ((((i64)1)<<(sizeof(n)*8-1))-1)
15491
+#define UMXV(n) ((((i64)1)<<(sizeof(n)*8))-1)
1544715492
1544815493
/*
1544915494
** Round up a number to the next larger multiple of 8. This is used
1545015495
** to force 8-byte alignment on 64-bit architectures.
1545115496
**
@@ -15562,10 +15607,12 @@
1556215607
** 0x00008000 After all FROM-clause analysis
1556315608
** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
1556415609
** 0x00020000 Transform DISTINCT into GROUP BY
1556515610
** 0x00040000 SELECT tree dump after all code has been generated
1556615611
** 0x00080000 NOT NULL strength reduction
15612
+** 0x00100000 Pointers are all shown as zero
15613
+** 0x00200000 EXISTS-to-JOIN optimization
1556715614
*/
1556815615
1556915616
/*
1557015617
** Macros for "wheretrace"
1557115618
*/
@@ -15606,10 +15653,11 @@
1560615653
**
1560715654
** 0x00010000 Show more detail when printing WHERE terms
1560815655
** 0x00020000 Show WHERE terms returned from whereScanNext()
1560915656
** 0x00040000 Solver overview messages
1561015657
** 0x00080000 Star-query heuristic
15658
+** 0x00100000 Pointers are all shown as zero
1561115659
*/
1561215660
1561315661
1561415662
/*
1561515663
** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15726,11 @@
1567815726
** one parameter that destructors normally want. So we have to introduce
1567915727
** this magic value that the code knows to handle differently. Any
1568015728
** pointer will work here as long as it is distinct from SQLITE_STATIC
1568115729
** and SQLITE_TRANSIENT.
1568215730
*/
15683
-#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
15731
+#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3RowSetClear)
1568415732
1568515733
/*
1568615734
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
1568715735
** not support Writable Static Data (WSD) such as global and static variables.
1568815736
** All variables must either be on the stack or dynamically allocated from
@@ -16746,10 +16794,11 @@
1674616794
};
1674716795
1674816796
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
1674916797
int flags, int seekResult);
1675016798
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
16799
+SQLITE_PRIVATE int sqlite3BtreeIsEmpty(BtCursor *pCur, int *pRes);
1675116800
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1675216801
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
1675316802
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1675416803
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
1675516804
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -17079,76 +17128,76 @@
1707917128
#define OP_Last 32 /* jump0 */
1708017129
#define OP_IfSizeBetween 33 /* jump */
1708117130
#define OP_SorterSort 34 /* jump */
1708217131
#define OP_Sort 35 /* jump */
1708317132
#define OP_Rewind 36 /* jump0 */
17084
-#define OP_SorterNext 37 /* jump */
17085
-#define OP_Prev 38 /* jump */
17086
-#define OP_Next 39 /* jump */
17087
-#define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
17088
-#define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
17089
-#define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
17133
+#define OP_IfEmpty 37 /* jump, synopsis: if( empty(P1) ) goto P2 */
17134
+#define OP_SorterNext 38 /* jump */
17135
+#define OP_Prev 39 /* jump */
17136
+#define OP_Next 40 /* jump */
17137
+#define OP_IdxLE 41 /* jump, synopsis: key=r[P3@P4] */
17138
+#define OP_IdxGT 42 /* jump, synopsis: key=r[P3@P4] */
1709017139
#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1709117140
#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
17092
-#define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
17093
-#define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
17094
-#define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
17095
-#define OP_Program 48 /* jump0 */
17096
-#define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
17097
-#define OP_IfPos 50 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
17141
+#define OP_IdxLT 45 /* jump, synopsis: key=r[P3@P4] */
17142
+#define OP_IdxGE 46 /* jump, synopsis: key=r[P3@P4] */
17143
+#define OP_RowSetRead 47 /* jump, synopsis: r[P3]=rowset(P1) */
17144
+#define OP_RowSetTest 48 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
17145
+#define OP_Program 49 /* jump0 */
17146
+#define OP_FkIfZero 50 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
1709817147
#define OP_IsNull 51 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1709917148
#define OP_NotNull 52 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1710017149
#define OP_Ne 53 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1710117150
#define OP_Eq 54 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1710217151
#define OP_Gt 55 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1710317152
#define OP_Le 56 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1710417153
#define OP_Lt 57 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1710517154
#define OP_Ge 58 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
1710617155
#define OP_ElseEq 59 /* jump, same as TK_ESCAPE */
17107
-#define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
17108
-#define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
17109
-#define OP_IncrVacuum 62 /* jump */
17110
-#define OP_VNext 63 /* jump */
17111
-#define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
17112
-#define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
17113
-#define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
17114
-#define OP_Return 67
17115
-#define OP_EndCoroutine 68
17116
-#define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
17117
-#define OP_Halt 70
17118
-#define OP_Integer 71 /* synopsis: r[P2]=P1 */
17119
-#define OP_Int64 72 /* synopsis: r[P2]=P4 */
17120
-#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */
17121
-#define OP_BeginSubrtn 74 /* synopsis: r[P2]=NULL */
17122
-#define OP_Null 75 /* synopsis: r[P2..P3]=NULL */
17123
-#define OP_SoftNull 76 /* synopsis: r[P1]=NULL */
17124
-#define OP_Blob 77 /* synopsis: r[P2]=P4 (len=P1) */
17125
-#define OP_Variable 78 /* synopsis: r[P2]=parameter(P1) */
17126
-#define OP_Move 79 /* synopsis: r[P2@P3]=r[P1@P3] */
17127
-#define OP_Copy 80 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
17128
-#define OP_SCopy 81 /* synopsis: r[P2]=r[P1] */
17129
-#define OP_IntCopy 82 /* synopsis: r[P2]=r[P1] */
17130
-#define OP_FkCheck 83
17131
-#define OP_ResultRow 84 /* synopsis: output=r[P1@P2] */
17132
-#define OP_CollSeq 85
17133
-#define OP_AddImm 86 /* synopsis: r[P1]=r[P1]+P2 */
17134
-#define OP_RealAffinity 87
17135
-#define OP_Cast 88 /* synopsis: affinity(r[P1]) */
17136
-#define OP_Permutation 89
17137
-#define OP_Compare 90 /* synopsis: r[P1@P3] <-> r[P2@P3] */
17138
-#define OP_IsTrue 91 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
17139
-#define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */
17140
-#define OP_Offset 93 /* synopsis: r[P3] = sqlite_offset(P1) */
17141
-#define OP_Column 94 /* synopsis: r[P3]=PX cursor P1 column P2 */
17142
-#define OP_TypeCheck 95 /* synopsis: typecheck(r[P1@P2]) */
17143
-#define OP_Affinity 96 /* synopsis: affinity(r[P1@P2]) */
17144
-#define OP_MakeRecord 97 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
17145
-#define OP_Count 98 /* synopsis: r[P2]=count() */
17146
-#define OP_ReadCookie 99
17147
-#define OP_SetCookie 100
17148
-#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
17149
-#define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
17156
+#define OP_IfPos 60 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
17157
+#define OP_IfNotZero 61 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
17158
+#define OP_DecrJumpZero 62 /* jump, synopsis: if (--r[P1])==0 goto P2 */
17159
+#define OP_IncrVacuum 63 /* jump */
17160
+#define OP_VNext 64 /* jump */
17161
+#define OP_Filter 65 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
17162
+#define OP_PureFunc 66 /* synopsis: r[P3]=func(r[P2@NP]) */
17163
+#define OP_Function 67 /* synopsis: r[P3]=func(r[P2@NP]) */
17164
+#define OP_Return 68
17165
+#define OP_EndCoroutine 69
17166
+#define OP_HaltIfNull 70 /* synopsis: if r[P3]=null halt */
17167
+#define OP_Halt 71
17168
+#define OP_Integer 72 /* synopsis: r[P2]=P1 */
17169
+#define OP_Int64 73 /* synopsis: r[P2]=P4 */
17170
+#define OP_String 74 /* synopsis: r[P2]='P4' (len=P1) */
17171
+#define OP_BeginSubrtn 75 /* synopsis: r[P2]=NULL */
17172
+#define OP_Null 76 /* synopsis: r[P2..P3]=NULL */
17173
+#define OP_SoftNull 77 /* synopsis: r[P1]=NULL */
17174
+#define OP_Blob 78 /* synopsis: r[P2]=P4 (len=P1) */
17175
+#define OP_Variable 79 /* synopsis: r[P2]=parameter(P1) */
17176
+#define OP_Move 80 /* synopsis: r[P2@P3]=r[P1@P3] */
17177
+#define OP_Copy 81 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
17178
+#define OP_SCopy 82 /* synopsis: r[P2]=r[P1] */
17179
+#define OP_IntCopy 83 /* synopsis: r[P2]=r[P1] */
17180
+#define OP_FkCheck 84
17181
+#define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */
17182
+#define OP_CollSeq 86
17183
+#define OP_AddImm 87 /* synopsis: r[P1]=r[P1]+P2 */
17184
+#define OP_RealAffinity 88
17185
+#define OP_Cast 89 /* synopsis: affinity(r[P1]) */
17186
+#define OP_Permutation 90
17187
+#define OP_Compare 91 /* synopsis: r[P1@P3] <-> r[P2@P3] */
17188
+#define OP_IsTrue 92 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
17189
+#define OP_ZeroOrNull 93 /* synopsis: r[P2] = 0 OR NULL */
17190
+#define OP_Offset 94 /* synopsis: r[P3] = sqlite_offset(P1) */
17191
+#define OP_Column 95 /* synopsis: r[P3]=PX cursor P1 column P2 */
17192
+#define OP_TypeCheck 96 /* synopsis: typecheck(r[P1@P2]) */
17193
+#define OP_Affinity 97 /* synopsis: affinity(r[P1@P2]) */
17194
+#define OP_MakeRecord 98 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
17195
+#define OP_Count 99 /* synopsis: r[P2]=count() */
17196
+#define OP_ReadCookie 100
17197
+#define OP_SetCookie 101
17198
+#define OP_ReopenIdx 102 /* synopsis: root=P2 iDb=P3 */
1715017199
#define OP_BitAnd 103 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
1715117200
#define OP_BitOr 104 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
1715217201
#define OP_ShiftLeft 105 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
1715317202
#define OP_ShiftRight 106 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
1715417203
#define OP_Add 107 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -17155,87 +17204,88 @@
1715517204
#define OP_Subtract 108 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
1715617205
#define OP_Multiply 109 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
1715717206
#define OP_Divide 110 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1715817207
#define OP_Remainder 111 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1715917208
#define OP_Concat 112 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
17160
-#define OP_OpenWrite 113 /* synopsis: root=P2 iDb=P3 */
17161
-#define OP_OpenDup 114
17209
+#define OP_OpenRead 113 /* synopsis: root=P2 iDb=P3 */
17210
+#define OP_OpenWrite 114 /* synopsis: root=P2 iDb=P3 */
1716217211
#define OP_BitNot 115 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
17163
-#define OP_OpenAutoindex 116 /* synopsis: nColumn=P2 */
17164
-#define OP_OpenEphemeral 117 /* synopsis: nColumn=P2 */
17212
+#define OP_OpenDup 116
17213
+#define OP_OpenAutoindex 117 /* synopsis: nColumn=P2 */
1716517214
#define OP_String8 118 /* same as TK_STRING, synopsis: r[P2]='P4' */
17166
-#define OP_SorterOpen 119
17167
-#define OP_SequenceTest 120 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
17168
-#define OP_OpenPseudo 121 /* synopsis: P3 columns in r[P2] */
17169
-#define OP_Close 122
17170
-#define OP_ColumnsUsed 123
17171
-#define OP_SeekScan 124 /* synopsis: Scan-ahead up to P1 rows */
17172
-#define OP_SeekHit 125 /* synopsis: set P2<=seekHit<=P3 */
17173
-#define OP_Sequence 126 /* synopsis: r[P2]=cursor[P1].ctr++ */
17174
-#define OP_NewRowid 127 /* synopsis: r[P2]=rowid */
17175
-#define OP_Insert 128 /* synopsis: intkey=r[P3] data=r[P2] */
17176
-#define OP_RowCell 129
17177
-#define OP_Delete 130
17178
-#define OP_ResetCount 131
17179
-#define OP_SorterCompare 132 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
17180
-#define OP_SorterData 133 /* synopsis: r[P2]=data */
17181
-#define OP_RowData 134 /* synopsis: r[P2]=data */
17182
-#define OP_Rowid 135 /* synopsis: r[P2]=PX rowid of P1 */
17183
-#define OP_NullRow 136
17184
-#define OP_SeekEnd 137
17185
-#define OP_IdxInsert 138 /* synopsis: key=r[P2] */
17186
-#define OP_SorterInsert 139 /* synopsis: key=r[P2] */
17187
-#define OP_IdxDelete 140 /* synopsis: key=r[P2@P3] */
17188
-#define OP_DeferredSeek 141 /* synopsis: Move P3 to P1.rowid if needed */
17189
-#define OP_IdxRowid 142 /* synopsis: r[P2]=rowid */
17190
-#define OP_FinishSeek 143
17191
-#define OP_Destroy 144
17192
-#define OP_Clear 145
17193
-#define OP_ResetSorter 146
17194
-#define OP_CreateBtree 147 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
17195
-#define OP_SqlExec 148
17196
-#define OP_ParseSchema 149
17197
-#define OP_LoadAnalysis 150
17198
-#define OP_DropTable 151
17199
-#define OP_DropIndex 152
17200
-#define OP_DropTrigger 153
17215
+#define OP_OpenEphemeral 119 /* synopsis: nColumn=P2 */
17216
+#define OP_SorterOpen 120
17217
+#define OP_SequenceTest 121 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
17218
+#define OP_OpenPseudo 122 /* synopsis: P3 columns in r[P2] */
17219
+#define OP_Close 123
17220
+#define OP_ColumnsUsed 124
17221
+#define OP_SeekScan 125 /* synopsis: Scan-ahead up to P1 rows */
17222
+#define OP_SeekHit 126 /* synopsis: set P2<=seekHit<=P3 */
17223
+#define OP_Sequence 127 /* synopsis: r[P2]=cursor[P1].ctr++ */
17224
+#define OP_NewRowid 128 /* synopsis: r[P2]=rowid */
17225
+#define OP_Insert 129 /* synopsis: intkey=r[P3] data=r[P2] */
17226
+#define OP_RowCell 130
17227
+#define OP_Delete 131
17228
+#define OP_ResetCount 132
17229
+#define OP_SorterCompare 133 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
17230
+#define OP_SorterData 134 /* synopsis: r[P2]=data */
17231
+#define OP_RowData 135 /* synopsis: r[P2]=data */
17232
+#define OP_Rowid 136 /* synopsis: r[P2]=PX rowid of P1 */
17233
+#define OP_NullRow 137
17234
+#define OP_SeekEnd 138
17235
+#define OP_IdxInsert 139 /* synopsis: key=r[P2] */
17236
+#define OP_SorterInsert 140 /* synopsis: key=r[P2] */
17237
+#define OP_IdxDelete 141 /* synopsis: key=r[P2@P3] */
17238
+#define OP_DeferredSeek 142 /* synopsis: Move P3 to P1.rowid if needed */
17239
+#define OP_IdxRowid 143 /* synopsis: r[P2]=rowid */
17240
+#define OP_FinishSeek 144
17241
+#define OP_Destroy 145
17242
+#define OP_Clear 146
17243
+#define OP_ResetSorter 147
17244
+#define OP_CreateBtree 148 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
17245
+#define OP_SqlExec 149
17246
+#define OP_ParseSchema 150
17247
+#define OP_LoadAnalysis 151
17248
+#define OP_DropTable 152
17249
+#define OP_DropIndex 153
1720117250
#define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
17202
-#define OP_IntegrityCk 155
17203
-#define OP_RowSetAdd 156 /* synopsis: rowset(P1)=r[P2] */
17204
-#define OP_Param 157
17205
-#define OP_FkCounter 158 /* synopsis: fkctr[P1]+=P2 */
17206
-#define OP_MemMax 159 /* synopsis: r[P1]=max(r[P1],r[P2]) */
17207
-#define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
17208
-#define OP_AggInverse 161 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
17209
-#define OP_AggStep 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */
17210
-#define OP_AggStep1 163 /* synopsis: accum=r[P3] step(r[P2@P5]) */
17211
-#define OP_AggValue 164 /* synopsis: r[P3]=value N=P2 */
17212
-#define OP_AggFinal 165 /* synopsis: accum=r[P1] N=P2 */
17213
-#define OP_Expire 166
17214
-#define OP_CursorLock 167
17215
-#define OP_CursorUnlock 168
17216
-#define OP_TableLock 169 /* synopsis: iDb=P1 root=P2 write=P3 */
17217
-#define OP_VBegin 170
17218
-#define OP_VCreate 171
17219
-#define OP_VDestroy 172
17220
-#define OP_VOpen 173
17221
-#define OP_VCheck 174
17222
-#define OP_VInitIn 175 /* synopsis: r[P2]=ValueList(P1,P3) */
17223
-#define OP_VColumn 176 /* synopsis: r[P3]=vcolumn(P2) */
17224
-#define OP_VRename 177
17225
-#define OP_Pagecount 178
17226
-#define OP_MaxPgcnt 179
17227
-#define OP_ClrSubtype 180 /* synopsis: r[P1].subtype = 0 */
17228
-#define OP_GetSubtype 181 /* synopsis: r[P2] = r[P1].subtype */
17229
-#define OP_SetSubtype 182 /* synopsis: r[P2].subtype = r[P1] */
17230
-#define OP_FilterAdd 183 /* synopsis: filter(P1) += key(P3@P4) */
17231
-#define OP_Trace 184
17232
-#define OP_CursorHint 185
17233
-#define OP_ReleaseReg 186 /* synopsis: release r[P1@P2] mask P3 */
17234
-#define OP_Noop 187
17235
-#define OP_Explain 188
17236
-#define OP_Abortable 189
17251
+#define OP_DropTrigger 155
17252
+#define OP_IntegrityCk 156
17253
+#define OP_RowSetAdd 157 /* synopsis: rowset(P1)=r[P2] */
17254
+#define OP_Param 158
17255
+#define OP_FkCounter 159 /* synopsis: fkctr[P1]+=P2 */
17256
+#define OP_MemMax 160 /* synopsis: r[P1]=max(r[P1],r[P2]) */
17257
+#define OP_OffsetLimit 161 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
17258
+#define OP_AggInverse 162 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
17259
+#define OP_AggStep 163 /* synopsis: accum=r[P3] step(r[P2@P5]) */
17260
+#define OP_AggStep1 164 /* synopsis: accum=r[P3] step(r[P2@P5]) */
17261
+#define OP_AggValue 165 /* synopsis: r[P3]=value N=P2 */
17262
+#define OP_AggFinal 166 /* synopsis: accum=r[P1] N=P2 */
17263
+#define OP_Expire 167
17264
+#define OP_CursorLock 168
17265
+#define OP_CursorUnlock 169
17266
+#define OP_TableLock 170 /* synopsis: iDb=P1 root=P2 write=P3 */
17267
+#define OP_VBegin 171
17268
+#define OP_VCreate 172
17269
+#define OP_VDestroy 173
17270
+#define OP_VOpen 174
17271
+#define OP_VCheck 175
17272
+#define OP_VInitIn 176 /* synopsis: r[P2]=ValueList(P1,P3) */
17273
+#define OP_VColumn 177 /* synopsis: r[P3]=vcolumn(P2) */
17274
+#define OP_VRename 178
17275
+#define OP_Pagecount 179
17276
+#define OP_MaxPgcnt 180
17277
+#define OP_ClrSubtype 181 /* synopsis: r[P1].subtype = 0 */
17278
+#define OP_GetSubtype 182 /* synopsis: r[P2] = r[P1].subtype */
17279
+#define OP_SetSubtype 183 /* synopsis: r[P2].subtype = r[P1] */
17280
+#define OP_FilterAdd 184 /* synopsis: filter(P1) += key(P3@P4) */
17281
+#define OP_Trace 185
17282
+#define OP_CursorHint 186
17283
+#define OP_ReleaseReg 187 /* synopsis: release r[P1@P2] mask P3 */
17284
+#define OP_Noop 188
17285
+#define OP_Explain 189
17286
+#define OP_Abortable 190
1723717287
1723817288
/* Properties such as "out2" or "jump" that are specified in
1723917289
** comments following the "case" for each opcode in the vdbe.c
1724017290
** are encoded into bitvectors as follows:
1724117291
*/
@@ -17250,38 +17300,38 @@
1725017300
#define OPFLG_INITIALIZER {\
1725117301
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
1725217302
/* 8 */ 0x81, 0x01, 0x01, 0x81, 0x83, 0x83, 0x01, 0x01,\
1725317303
/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0xc9, 0xc9, 0xc9,\
1725417304
/* 24 */ 0xc9, 0x01, 0x49, 0x49, 0x49, 0x49, 0xc9, 0x49,\
17255
-/* 32 */ 0xc1, 0x01, 0x41, 0x41, 0xc1, 0x01, 0x41, 0x41,\
17256
-/* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
17257
-/* 48 */ 0x81, 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
17258
-/* 56 */ 0x0b, 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x41,\
17259
-/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
17260
-/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
17261
-/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
17262
-/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
17263
-/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x40, 0x26,\
17305
+/* 32 */ 0xc1, 0x01, 0x41, 0x41, 0xc1, 0x01, 0x01, 0x41,\
17306
+/* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x41, 0x23,\
17307
+/* 48 */ 0x0b, 0x81, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
17308
+/* 56 */ 0x0b, 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01,\
17309
+/* 64 */ 0x41, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00,\
17310
+/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
17311
+/* 80 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02,\
17312
+/* 88 */ 0x02, 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40,\
17313
+/* 96 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26,\
1726417314
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
17265
-/* 112 */ 0x26, 0x00, 0x40, 0x12, 0x40, 0x40, 0x10, 0x00,\
17266
-/* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
17267
-/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x50,\
17268
-/* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
17269
-/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
17270
-/* 152 */ 0x00, 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04,\
17271
-/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
17272
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x50,\
17273
-/* 176 */ 0x40, 0x00, 0x10, 0x10, 0x02, 0x12, 0x12, 0x00,\
17274
-/* 184 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
17315
+/* 112 */ 0x26, 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40,\
17316
+/* 120 */ 0x00, 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10,\
17317
+/* 128 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,\
17318
+/* 136 */ 0x50, 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50,\
17319
+/* 144 */ 0x40, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\
17320
+/* 152 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00,\
17321
+/* 160 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
17322
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10,\
17323
+/* 176 */ 0x50, 0x40, 0x00, 0x10, 0x10, 0x02, 0x12, 0x12,\
17324
+/* 184 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
1727517325
1727617326
/* The resolve3P2Values() routine is able to run faster if it knows
1727717327
** the value of the largest JUMP opcode. The smaller the maximum
1727817328
** JUMP opcode the better, so the mkopcodeh.tcl script that
1727917329
** generated this include file strives to group all JUMP opcodes
1728017330
** together near the beginning of the list.
1728117331
*/
17282
-#define SQLITE_MX_JUMP_OPCODE 64 /* Maximum JUMP opcode */
17332
+#define SQLITE_MX_JUMP_OPCODE 65 /* Maximum JUMP opcode */
1728317333
1728417334
/************** End of opcodes.h *********************************************/
1728517335
/************** Continuing where we left off in vdbe.h ***********************/
1728617336
1728717337
/*
@@ -17401,11 +17451,11 @@
1740117451
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
1740217452
#endif
1740317453
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
1740417454
SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
1740517455
17406
-SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
17456
+SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*);
1740717457
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
1740817458
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
1740917459
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
1741017460
1741117461
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -17414,11 +17464,13 @@
1741417464
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
1741517465
SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe*);
1741617466
1741717467
SQLITE_PRIVATE void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val);
1741817468
17469
+#ifndef SQLITE_OMIT_DATETIME_FUNCS
1741917470
SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
17471
+#endif
1742017472
#ifdef SQLITE_ENABLE_BYTECODE_VTAB
1742117473
SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3*);
1742217474
#endif
1742317475
1742417476
/* Use SQLITE_ENABLE_EXPLAIN_COMMENTS to enable generation of extra
@@ -18296,10 +18348,11 @@
1829618348
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
1829718349
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
1829818350
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
1829918351
#define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
1830018352
#define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
18353
+#define SQLITE_ExistsToJoin 0x40000000 /* The EXISTS-to-JOIN optimization */
1830118354
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1830218355
1830318356
/*
1830418357
** Macros for testing whether or not optimizations are enabled or disabled.
1830518358
*/
@@ -18534,11 +18587,11 @@
1853418587
SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1853518588
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1853618589
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
1853718590
{nArg, SQLITE_FUNC_BUILTIN|\
1853818591
SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
18539
- pArg, 0, xFunc, 0, 0, 0, #zName, }
18592
+ pArg, 0, xFunc, 0, 0, 0, #zName, {0} }
1854018593
#define LIKEFUNC(zName, nArg, arg, flags) \
1854118594
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1854218595
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
1854318596
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
1854418597
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
@@ -18701,10 +18754,11 @@
1870118754
#define SQLITE_AFF_TEXT 0x42 /* 'B' */
1870218755
#define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
1870318756
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
1870418757
#define SQLITE_AFF_REAL 0x45 /* 'E' */
1870518758
#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18759
+#define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
1870618760
1870718761
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
1870818762
1870918763
/*
1871018764
** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19070,19 @@
1901619070
/*
1901719071
** An instance of the following structure is passed as the first
1901819072
** argument to sqlite3VdbeKeyCompare and is used to control the
1901919073
** comparison of the two index keys.
1902019074
**
19021
-** Note that aSortOrder[] and aColl[] have nField+1 slots. There
19022
-** are nField slots for the columns of an index then one extra slot
19023
-** for the rowid at the end.
19075
+** The aSortOrder[] and aColl[] arrays have nAllField slots each. There
19076
+** are nKeyField slots for the columns of an index then extra slots
19077
+** for the rowid or key at the end. The aSortOrder array is located after
19078
+** the aColl[] array.
19079
+**
19080
+** If SQLITE_ENABLE_PREUPDATE_HOOK is defined, then aSortFlags might be NULL
19081
+** to indicate that this object is for use by a preupdate hook. When aSortFlags
19082
+** is NULL, then nAllField is uninitialized and no space is allocated for
19083
+** aColl[], so those fields may not be used.
1902419084
*/
1902519085
struct KeyInfo {
1902619086
u32 nRef; /* Number of references to this KeyInfo object */
1902719087
u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
1902819088
u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19090,21 @@
1903019090
sqlite3 *db; /* The database connection */
1903119091
u8 *aSortFlags; /* Sort order for each column. */
1903219092
CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
1903319093
};
1903419094
19035
-/* The size (in bytes) of a KeyInfo object with up to N fields */
19095
+/* The size (in bytes) of a KeyInfo object with up to N fields. This includes
19096
+** the main body of the KeyInfo object and the aColl[] array of N elements,
19097
+** but does not count the memory used to hold aSortFlags[]. */
1903619098
#define SZ_KEYINFO(N) (offsetof(KeyInfo,aColl) + (N)*sizeof(CollSeq*))
19099
+
19100
+/* The size of a bare KeyInfo with no aColl[] entries */
19101
+#if FLEXARRAY+1 > 1
19102
+# define SZ_KEYINFO_0 offsetof(KeyInfo,aColl)
19103
+#else
19104
+# define SZ_KEYINFO_0 sizeof(KeyInfo)
19105
+#endif
1903719106
1903819107
/*
1903919108
** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
1904019109
*/
1904119110
#define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19120,22 @@
1905119120
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
1905219121
** OP_Column opcode.
1905319122
**
1905419123
** An instance of this object serves as a "key" for doing a search on
1905519124
** an index b+tree. The goal of the search is to find the entry that
19056
-** is closed to the key described by this object. This object might hold
19057
-** just a prefix of the key. The number of fields is given by
19058
-** pKeyInfo->nField.
19125
+** is closest to the key described by this object. This object might hold
19126
+** just a prefix of the key. The number of fields is given by nField.
1905919127
**
1906019128
** The r1 and r2 fields are the values to return if this key is less than
1906119129
** or greater than a key in the btree, respectively. These are normally
1906219130
** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
1906319131
** is in DESC order.
1906419132
**
1906519133
** The key comparison functions actually return default_rc when they find
1906619134
** an equals comparison. default_rc can be -1, 0, or +1. If there are
1906719135
** multiple entries in the b-tree with the same key (when only looking
19068
-** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to
19136
+** at the first nField elements) then default_rc can be set to -1 to
1906919137
** cause the search to find the last match, or +1 to cause the search to
1907019138
** find the first match.
1907119139
**
1907219140
** The key comparison functions will set eqSeen to true if they ever
1907319141
** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19143,12 @@
1907519143
** before the first match or immediately after the last match. The
1907619144
** eqSeen field will indicate whether or not an exact match exists in the
1907719145
** b-tree.
1907819146
*/
1907919147
struct UnpackedRecord {
19080
- KeyInfo *pKeyInfo; /* Collation and sort-order information */
19081
- Mem *aMem; /* Values */
19148
+ KeyInfo *pKeyInfo; /* Comparison info for the index that is unpacked */
19149
+ Mem *aMem; /* Values for columns of the index */
1908219150
union {
1908319151
char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
1908419152
i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
1908519153
} u;
1908619154
int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -19161,14 +19229,12 @@
1916119229
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
1916219230
unsigned isResized:1; /* True if resizeIndexObject() has been called */
1916319231
unsigned isCovering:1; /* True if this is a covering index */
1916419232
unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
1916519233
unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
19166
- unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */
1916719234
unsigned bNoQuery:1; /* Do not use this index to optimize queries */
1916819235
unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
19169
- unsigned bIdxRowid:1; /* One or more of the index keys is the ROWID */
1917019236
unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
1917119237
unsigned bHasExpr:1; /* Index contains an expression, either a literal
1917219238
** expression, or a reference to a VIRTUAL column */
1917319239
#ifdef SQLITE_ENABLE_STAT4
1917419240
int nSample; /* Number of elements in aSample[] */
@@ -19252,21 +19318,21 @@
1925219318
struct AggInfo {
1925319319
u8 directMode; /* Direct rendering mode means take data directly
1925419320
** from source tables rather than from accumulators */
1925519321
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
1925619322
** than the source table */
19257
- u16 nSortingColumn; /* Number of columns in the sorting index */
19323
+ u32 nSortingColumn; /* Number of columns in the sorting index */
1925819324
int sortingIdx; /* Cursor number of the sorting index */
1925919325
int sortingIdxPTab; /* Cursor number of pseudo-table */
1926019326
int iFirstReg; /* First register in range for aCol[] and aFunc[] */
1926119327
ExprList *pGroupBy; /* The group by clause */
1926219328
struct AggInfo_col { /* For each column used in source tables */
1926319329
Table *pTab; /* Source table */
1926419330
Expr *pCExpr; /* The original expression */
1926519331
int iTable; /* Cursor number of the source table */
19266
- i16 iColumn; /* Column number within the source table */
19267
- i16 iSorterColumn; /* Column number in the sorting index */
19332
+ int iColumn; /* Column number within the source table */
19333
+ int iSorterColumn; /* Column number in the sorting index */
1926819334
} *aCol;
1926919335
int nColumn; /* Number of used entries in aCol[] */
1927019336
int nAccumulator; /* Number of columns that show through to the output.
1927119337
** Additional columns are used only as parameters to
1927219338
** aggregate functions */
@@ -19726,10 +19792,11 @@
1972619792
unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
1972719793
unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
1972819794
unsigned rowidUsed :1; /* The ROWID of this table is referenced */
1972919795
unsigned fixedSchema :1; /* Uses u4.pSchema, not u4.zDatabase */
1973019796
unsigned hadSchema :1; /* Had u4.zDatabase before u4.pSchema */
19797
+ unsigned fromExists :1; /* Comes from WHERE EXISTS(...) */
1973119798
} fg;
1973219799
int iCursor; /* The VDBE cursor number used to access this table */
1973319800
Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
1973419801
union {
1973519802
char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
@@ -20256,10 +20323,11 @@
2025620323
u8 mayAbort; /* True if statement may throw an ABORT exception */
2025720324
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
2025820325
u8 disableLookaside; /* Number of times lookaside has been disabled */
2025920326
u8 prepFlags; /* SQLITE_PREPARE_* flags */
2026020327
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20328
+ u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
2026120329
u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
2026220330
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
2026320331
u8 bReturning; /* Coding a RETURNING trigger */
2026420332
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
2026520333
u8 disableTriggers; /* True to disable triggers */
@@ -21252,10 +21320,11 @@
2125221320
#endif
2125321321
#ifndef SQLITE_OMIT_WINDOWFUNC
2125421322
SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
2125521323
SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
2125621324
#endif
21325
+SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec*);
2125721326
#endif
2125821327
2125921328
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
2126021329
SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
2126121330
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -22425,10 +22494,13 @@
2242522494
#ifdef SQLITE_BITMASK_TYPE
2242622495
"BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
2242722496
#endif
2242822497
#ifdef SQLITE_BUG_COMPATIBLE_20160819
2242922498
"BUG_COMPATIBLE_20160819",
22499
+#endif
22500
+#ifdef SQLITE_BUG_COMPATIBLE_20250510
22501
+ "BUG_COMPATIBLE_20250510",
2243022502
#endif
2243122503
#ifdef SQLITE_CASE_SENSITIVE_LIKE
2243222504
"CASE_SENSITIVE_LIKE",
2243322505
#endif
2243422506
#ifdef SQLITE_CHECK_PAGES
@@ -23861,11 +23933,11 @@
2386123933
** * MEM_Blob A blob, stored in Mem.z length Mem.n.
2386223934
** Incompatible with MEM_Str, MEM_Null,
2386323935
** MEM_Int, MEM_Real, and MEM_IntReal.
2386423936
**
2386523937
** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
23866
-** MEM.u.i extra 0x00 bytes at the end.
23938
+** Mem.u.nZero extra 0x00 bytes at the end.
2386723939
**
2386823940
** * MEM_Int Integer stored in Mem.u.i.
2386923941
**
2387023942
** * MEM_Real Real stored in Mem.u.r.
2387123943
**
@@ -24130,11 +24202,11 @@
2413024202
Mem oldipk; /* Memory cell holding "old" IPK value */
2413124203
Mem *aNew; /* Array of new.* values */
2413224204
Table *pTab; /* Schema object being updated */
2413324205
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2413424206
sqlite3_value **apDflt; /* Array of default values, if required */
24135
- u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */
24207
+ u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
2413624208
};
2413724209
2413824210
/*
2413924211
** An instance of this object is used to pass an vector of values into
2414024212
** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -32060,10 +32132,18 @@
3206032132
}else{
3206132133
longvalue = va_arg(ap,unsigned int);
3206232134
}
3206332135
prefix = 0;
3206432136
}
32137
+
32138
+#if WHERETRACE_ENABLED
32139
+ if( xtype==etPOINTER && sqlite3WhereTrace & 0x100000 ) longvalue = 0;
32140
+#endif
32141
+#if TREETRACE_ENABLED
32142
+ if( xtype==etPOINTER && sqlite3TreeTrace & 0x100000 ) longvalue = 0;
32143
+#endif
32144
+
3206532145
if( longvalue==0 ) flag_alternateform = 0;
3206632146
if( flag_zeropad && precision<width-(prefix!=0) ){
3206732147
precision = width-(prefix!=0);
3206832148
}
3206932149
if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -35011,11 +35091,11 @@
3501135091
}
3501235092
3501335093
/*
3501435094
** Write a single UTF8 character whose value is v into the
3501535095
** buffer starting at zOut. zOut must be sized to hold at
35016
-** least for bytes. Return the number of bytes needed
35096
+** least four bytes. Return the number of bytes needed
3501735097
** to encode the new character.
3501835098
*/
3501935099
SQLITE_PRIVATE int sqlite3AppendOneUtf8Character(char *zOut, u32 v){
3502035100
if( v<0x00080 ){
3502135101
zOut[0] = (u8)(v & 0xff);
@@ -37691,76 +37771,76 @@
3769137771
/* 32 */ "Last" OpHelp(""),
3769237772
/* 33 */ "IfSizeBetween" OpHelp(""),
3769337773
/* 34 */ "SorterSort" OpHelp(""),
3769437774
/* 35 */ "Sort" OpHelp(""),
3769537775
/* 36 */ "Rewind" OpHelp(""),
37696
- /* 37 */ "SorterNext" OpHelp(""),
37697
- /* 38 */ "Prev" OpHelp(""),
37698
- /* 39 */ "Next" OpHelp(""),
37699
- /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
37700
- /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
37701
- /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
37776
+ /* 37 */ "IfEmpty" OpHelp("if( empty(P1) ) goto P2"),
37777
+ /* 38 */ "SorterNext" OpHelp(""),
37778
+ /* 39 */ "Prev" OpHelp(""),
37779
+ /* 40 */ "Next" OpHelp(""),
37780
+ /* 41 */ "IdxLE" OpHelp("key=r[P3@P4]"),
37781
+ /* 42 */ "IdxGT" OpHelp("key=r[P3@P4]"),
3770237782
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3770337783
/* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
37704
- /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
37705
- /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
37706
- /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
37707
- /* 48 */ "Program" OpHelp(""),
37708
- /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
37709
- /* 50 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
37784
+ /* 45 */ "IdxLT" OpHelp("key=r[P3@P4]"),
37785
+ /* 46 */ "IdxGE" OpHelp("key=r[P3@P4]"),
37786
+ /* 47 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
37787
+ /* 48 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
37788
+ /* 49 */ "Program" OpHelp(""),
37789
+ /* 50 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
3771037790
/* 51 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3771137791
/* 52 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3771237792
/* 53 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3771337793
/* 54 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3771437794
/* 55 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3771537795
/* 56 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3771637796
/* 57 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3771737797
/* 58 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3771837798
/* 59 */ "ElseEq" OpHelp(""),
37719
- /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
37720
- /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
37721
- /* 62 */ "IncrVacuum" OpHelp(""),
37722
- /* 63 */ "VNext" OpHelp(""),
37723
- /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
37724
- /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
37725
- /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
37726
- /* 67 */ "Return" OpHelp(""),
37727
- /* 68 */ "EndCoroutine" OpHelp(""),
37728
- /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
37729
- /* 70 */ "Halt" OpHelp(""),
37730
- /* 71 */ "Integer" OpHelp("r[P2]=P1"),
37731
- /* 72 */ "Int64" OpHelp("r[P2]=P4"),
37732
- /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
37733
- /* 74 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
37734
- /* 75 */ "Null" OpHelp("r[P2..P3]=NULL"),
37735
- /* 76 */ "SoftNull" OpHelp("r[P1]=NULL"),
37736
- /* 77 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
37737
- /* 78 */ "Variable" OpHelp("r[P2]=parameter(P1)"),
37738
- /* 79 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
37739
- /* 80 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
37740
- /* 81 */ "SCopy" OpHelp("r[P2]=r[P1]"),
37741
- /* 82 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
37742
- /* 83 */ "FkCheck" OpHelp(""),
37743
- /* 84 */ "ResultRow" OpHelp("output=r[P1@P2]"),
37744
- /* 85 */ "CollSeq" OpHelp(""),
37745
- /* 86 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
37746
- /* 87 */ "RealAffinity" OpHelp(""),
37747
- /* 88 */ "Cast" OpHelp("affinity(r[P1])"),
37748
- /* 89 */ "Permutation" OpHelp(""),
37749
- /* 90 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
37750
- /* 91 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
37751
- /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
37752
- /* 93 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
37753
- /* 94 */ "Column" OpHelp("r[P3]=PX cursor P1 column P2"),
37754
- /* 95 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"),
37755
- /* 96 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
37756
- /* 97 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
37757
- /* 98 */ "Count" OpHelp("r[P2]=count()"),
37758
- /* 99 */ "ReadCookie" OpHelp(""),
37759
- /* 100 */ "SetCookie" OpHelp(""),
37760
- /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
37761
- /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
37799
+ /* 60 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
37800
+ /* 61 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
37801
+ /* 62 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
37802
+ /* 63 */ "IncrVacuum" OpHelp(""),
37803
+ /* 64 */ "VNext" OpHelp(""),
37804
+ /* 65 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
37805
+ /* 66 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
37806
+ /* 67 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
37807
+ /* 68 */ "Return" OpHelp(""),
37808
+ /* 69 */ "EndCoroutine" OpHelp(""),
37809
+ /* 70 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
37810
+ /* 71 */ "Halt" OpHelp(""),
37811
+ /* 72 */ "Integer" OpHelp("r[P2]=P1"),
37812
+ /* 73 */ "Int64" OpHelp("r[P2]=P4"),
37813
+ /* 74 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
37814
+ /* 75 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
37815
+ /* 76 */ "Null" OpHelp("r[P2..P3]=NULL"),
37816
+ /* 77 */ "SoftNull" OpHelp("r[P1]=NULL"),
37817
+ /* 78 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
37818
+ /* 79 */ "Variable" OpHelp("r[P2]=parameter(P1)"),
37819
+ /* 80 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
37820
+ /* 81 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
37821
+ /* 82 */ "SCopy" OpHelp("r[P2]=r[P1]"),
37822
+ /* 83 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
37823
+ /* 84 */ "FkCheck" OpHelp(""),
37824
+ /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"),
37825
+ /* 86 */ "CollSeq" OpHelp(""),
37826
+ /* 87 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
37827
+ /* 88 */ "RealAffinity" OpHelp(""),
37828
+ /* 89 */ "Cast" OpHelp("affinity(r[P1])"),
37829
+ /* 90 */ "Permutation" OpHelp(""),
37830
+ /* 91 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
37831
+ /* 92 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
37832
+ /* 93 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
37833
+ /* 94 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
37834
+ /* 95 */ "Column" OpHelp("r[P3]=PX cursor P1 column P2"),
37835
+ /* 96 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"),
37836
+ /* 97 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
37837
+ /* 98 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
37838
+ /* 99 */ "Count" OpHelp("r[P2]=count()"),
37839
+ /* 100 */ "ReadCookie" OpHelp(""),
37840
+ /* 101 */ "SetCookie" OpHelp(""),
37841
+ /* 102 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
3776237842
/* 103 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
3776337843
/* 104 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
3776437844
/* 105 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
3776537845
/* 106 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
3776637846
/* 107 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -37767,87 +37847,88 @@
3776737847
/* 108 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
3776837848
/* 109 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
3776937849
/* 110 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
3777037850
/* 111 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
3777137851
/* 112 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
37772
- /* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
37773
- /* 114 */ "OpenDup" OpHelp(""),
37852
+ /* 113 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
37853
+ /* 114 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
3777437854
/* 115 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
37775
- /* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"),
37776
- /* 117 */ "OpenEphemeral" OpHelp("nColumn=P2"),
37855
+ /* 116 */ "OpenDup" OpHelp(""),
37856
+ /* 117 */ "OpenAutoindex" OpHelp("nColumn=P2"),
3777737857
/* 118 */ "String8" OpHelp("r[P2]='P4'"),
37778
- /* 119 */ "SorterOpen" OpHelp(""),
37779
- /* 120 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
37780
- /* 121 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
37781
- /* 122 */ "Close" OpHelp(""),
37782
- /* 123 */ "ColumnsUsed" OpHelp(""),
37783
- /* 124 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
37784
- /* 125 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
37785
- /* 126 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
37786
- /* 127 */ "NewRowid" OpHelp("r[P2]=rowid"),
37787
- /* 128 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
37788
- /* 129 */ "RowCell" OpHelp(""),
37789
- /* 130 */ "Delete" OpHelp(""),
37790
- /* 131 */ "ResetCount" OpHelp(""),
37791
- /* 132 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
37792
- /* 133 */ "SorterData" OpHelp("r[P2]=data"),
37793
- /* 134 */ "RowData" OpHelp("r[P2]=data"),
37794
- /* 135 */ "Rowid" OpHelp("r[P2]=PX rowid of P1"),
37795
- /* 136 */ "NullRow" OpHelp(""),
37796
- /* 137 */ "SeekEnd" OpHelp(""),
37797
- /* 138 */ "IdxInsert" OpHelp("key=r[P2]"),
37798
- /* 139 */ "SorterInsert" OpHelp("key=r[P2]"),
37799
- /* 140 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
37800
- /* 141 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
37801
- /* 142 */ "IdxRowid" OpHelp("r[P2]=rowid"),
37802
- /* 143 */ "FinishSeek" OpHelp(""),
37803
- /* 144 */ "Destroy" OpHelp(""),
37804
- /* 145 */ "Clear" OpHelp(""),
37805
- /* 146 */ "ResetSorter" OpHelp(""),
37806
- /* 147 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
37807
- /* 148 */ "SqlExec" OpHelp(""),
37808
- /* 149 */ "ParseSchema" OpHelp(""),
37809
- /* 150 */ "LoadAnalysis" OpHelp(""),
37810
- /* 151 */ "DropTable" OpHelp(""),
37811
- /* 152 */ "DropIndex" OpHelp(""),
37812
- /* 153 */ "DropTrigger" OpHelp(""),
37858
+ /* 119 */ "OpenEphemeral" OpHelp("nColumn=P2"),
37859
+ /* 120 */ "SorterOpen" OpHelp(""),
37860
+ /* 121 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
37861
+ /* 122 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
37862
+ /* 123 */ "Close" OpHelp(""),
37863
+ /* 124 */ "ColumnsUsed" OpHelp(""),
37864
+ /* 125 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
37865
+ /* 126 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
37866
+ /* 127 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
37867
+ /* 128 */ "NewRowid" OpHelp("r[P2]=rowid"),
37868
+ /* 129 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
37869
+ /* 130 */ "RowCell" OpHelp(""),
37870
+ /* 131 */ "Delete" OpHelp(""),
37871
+ /* 132 */ "ResetCount" OpHelp(""),
37872
+ /* 133 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
37873
+ /* 134 */ "SorterData" OpHelp("r[P2]=data"),
37874
+ /* 135 */ "RowData" OpHelp("r[P2]=data"),
37875
+ /* 136 */ "Rowid" OpHelp("r[P2]=PX rowid of P1"),
37876
+ /* 137 */ "NullRow" OpHelp(""),
37877
+ /* 138 */ "SeekEnd" OpHelp(""),
37878
+ /* 139 */ "IdxInsert" OpHelp("key=r[P2]"),
37879
+ /* 140 */ "SorterInsert" OpHelp("key=r[P2]"),
37880
+ /* 141 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
37881
+ /* 142 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
37882
+ /* 143 */ "IdxRowid" OpHelp("r[P2]=rowid"),
37883
+ /* 144 */ "FinishSeek" OpHelp(""),
37884
+ /* 145 */ "Destroy" OpHelp(""),
37885
+ /* 146 */ "Clear" OpHelp(""),
37886
+ /* 147 */ "ResetSorter" OpHelp(""),
37887
+ /* 148 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
37888
+ /* 149 */ "SqlExec" OpHelp(""),
37889
+ /* 150 */ "ParseSchema" OpHelp(""),
37890
+ /* 151 */ "LoadAnalysis" OpHelp(""),
37891
+ /* 152 */ "DropTable" OpHelp(""),
37892
+ /* 153 */ "DropIndex" OpHelp(""),
3781337893
/* 154 */ "Real" OpHelp("r[P2]=P4"),
37814
- /* 155 */ "IntegrityCk" OpHelp(""),
37815
- /* 156 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
37816
- /* 157 */ "Param" OpHelp(""),
37817
- /* 158 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
37818
- /* 159 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
37819
- /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
37820
- /* 161 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
37821
- /* 162 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
37822
- /* 163 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
37823
- /* 164 */ "AggValue" OpHelp("r[P3]=value N=P2"),
37824
- /* 165 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
37825
- /* 166 */ "Expire" OpHelp(""),
37826
- /* 167 */ "CursorLock" OpHelp(""),
37827
- /* 168 */ "CursorUnlock" OpHelp(""),
37828
- /* 169 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
37829
- /* 170 */ "VBegin" OpHelp(""),
37830
- /* 171 */ "VCreate" OpHelp(""),
37831
- /* 172 */ "VDestroy" OpHelp(""),
37832
- /* 173 */ "VOpen" OpHelp(""),
37833
- /* 174 */ "VCheck" OpHelp(""),
37834
- /* 175 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
37835
- /* 176 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
37836
- /* 177 */ "VRename" OpHelp(""),
37837
- /* 178 */ "Pagecount" OpHelp(""),
37838
- /* 179 */ "MaxPgcnt" OpHelp(""),
37839
- /* 180 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
37840
- /* 181 */ "GetSubtype" OpHelp("r[P2] = r[P1].subtype"),
37841
- /* 182 */ "SetSubtype" OpHelp("r[P2].subtype = r[P1]"),
37842
- /* 183 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
37843
- /* 184 */ "Trace" OpHelp(""),
37844
- /* 185 */ "CursorHint" OpHelp(""),
37845
- /* 186 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
37846
- /* 187 */ "Noop" OpHelp(""),
37847
- /* 188 */ "Explain" OpHelp(""),
37848
- /* 189 */ "Abortable" OpHelp(""),
37894
+ /* 155 */ "DropTrigger" OpHelp(""),
37895
+ /* 156 */ "IntegrityCk" OpHelp(""),
37896
+ /* 157 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
37897
+ /* 158 */ "Param" OpHelp(""),
37898
+ /* 159 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
37899
+ /* 160 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
37900
+ /* 161 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
37901
+ /* 162 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
37902
+ /* 163 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
37903
+ /* 164 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
37904
+ /* 165 */ "AggValue" OpHelp("r[P3]=value N=P2"),
37905
+ /* 166 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
37906
+ /* 167 */ "Expire" OpHelp(""),
37907
+ /* 168 */ "CursorLock" OpHelp(""),
37908
+ /* 169 */ "CursorUnlock" OpHelp(""),
37909
+ /* 170 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
37910
+ /* 171 */ "VBegin" OpHelp(""),
37911
+ /* 172 */ "VCreate" OpHelp(""),
37912
+ /* 173 */ "VDestroy" OpHelp(""),
37913
+ /* 174 */ "VOpen" OpHelp(""),
37914
+ /* 175 */ "VCheck" OpHelp(""),
37915
+ /* 176 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
37916
+ /* 177 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
37917
+ /* 178 */ "VRename" OpHelp(""),
37918
+ /* 179 */ "Pagecount" OpHelp(""),
37919
+ /* 180 */ "MaxPgcnt" OpHelp(""),
37920
+ /* 181 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
37921
+ /* 182 */ "GetSubtype" OpHelp("r[P2] = r[P1].subtype"),
37922
+ /* 183 */ "SetSubtype" OpHelp("r[P2].subtype = r[P1]"),
37923
+ /* 184 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
37924
+ /* 185 */ "Trace" OpHelp(""),
37925
+ /* 186 */ "CursorHint" OpHelp(""),
37926
+ /* 187 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
37927
+ /* 188 */ "Noop" OpHelp(""),
37928
+ /* 189 */ "Explain" OpHelp(""),
37929
+ /* 190 */ "Abortable" OpHelp(""),
3784937930
};
3785037931
return azName[i];
3785137932
}
3785237933
#endif
3785337934
@@ -43870,25 +43951,24 @@
4387043951
assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
4387143952
4387243953
/* Check that, if this to be a blocking lock, no locks that occur later
4387343954
** in the following list than the lock being obtained are already held:
4387443955
**
43875
- ** 1. Checkpointer lock (ofst==1).
43876
- ** 2. Write lock (ofst==0).
43877
- ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
43956
+ ** 1. Recovery lock (ofst==2).
43957
+ ** 2. Checkpointer lock (ofst==1).
43958
+ ** 3. Write lock (ofst==0).
43959
+ ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
4387843960
**
4387943961
** In other words, if this is a blocking lock, none of the locks that
4388043962
** occur later in the above list than the lock being obtained may be
4388143963
** held.
43882
- **
43883
- ** It is not permitted to block on the RECOVER lock.
4388443964
*/
4388543965
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
4388643966
{
4388743967
u16 lockMask = (p->exclMask|p->sharedMask);
4388843968
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43889
- (ofst!=2) /* not RECOVER */
43969
+ (ofst!=2 || lockMask==0)
4389043970
&& (ofst!=1 || lockMask==0 || lockMask==2)
4389143971
&& (ofst!=0 || lockMask<3)
4389243972
&& (ofst<3 || lockMask<(1<<ofst))
4389343973
));
4389443974
}
@@ -49845,11 +49925,15 @@
4984549925
DWORD nDelay = (nMs==0 ? INFINITE : nMs);
4984649926
DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
4984749927
if( res==WAIT_OBJECT_0 ){
4984849928
ret = TRUE;
4984949929
}else if( res==WAIT_TIMEOUT ){
49930
+#if SQLITE_ENABLE_SETLK_TIMEOUT==1
4985049931
rc = SQLITE_BUSY_TIMEOUT;
49932
+#else
49933
+ rc = SQLITE_BUSY;
49934
+#endif
4985149935
}else{
4985249936
/* Some other error has occurred */
4985349937
rc = SQLITE_IOERR_LOCK;
4985449938
}
4985549939
@@ -51331,17 +51415,17 @@
5133151415
int nChar;
5133251416
LPWSTR zWideFilename;
5133351417
5133451418
if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
5133551419
&& winIsDirSep(zFilename[2])) ){
51336
- int nByte;
51420
+ i64 nByte;
5133751421
int convertflag = CCP_POSIX_TO_WIN_W;
5133851422
if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51339
- nByte = (int)osCygwin_conv_path(convertflag,
51423
+ nByte = (i64)osCygwin_conv_path(convertflag,
5134051424
zFilename, 0, 0);
5134151425
if( nByte>0 ){
51342
- zConverted = sqlite3MallocZero(nByte+12);
51426
+ zConverted = sqlite3MallocZero(12+(u64)nByte);
5134351427
if ( zConverted==0 ){
5134451428
return zConverted;
5134551429
}
5134651430
zWideFilename = zConverted;
5134751431
/* Filenames should be prefixed, except when converted
@@ -51656,25 +51740,24 @@
5165651740
assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
5165751741
5165851742
/* Check that, if this to be a blocking lock, no locks that occur later
5165951743
** in the following list than the lock being obtained are already held:
5166051744
**
51661
- ** 1. Checkpointer lock (ofst==1).
51662
- ** 2. Write lock (ofst==0).
51663
- ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
51745
+ ** 1. Recovery lock (ofst==2).
51746
+ ** 2. Checkpointer lock (ofst==1).
51747
+ ** 3. Write lock (ofst==0).
51748
+ ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
5166451749
**
5166551750
** In other words, if this is a blocking lock, none of the locks that
5166651751
** occur later in the above list than the lock being obtained may be
5166751752
** held.
51668
- **
51669
- ** It is not permitted to block on the RECOVER lock.
5167051753
*/
5167151754
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
5167251755
{
5167351756
u16 lockMask = (p->exclMask|p->sharedMask);
5167451757
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51675
- (ofst!=2) /* not RECOVER */
51758
+ (ofst!=2 || lockMask==0)
5167651759
&& (ofst!=1 || lockMask==0 || lockMask==2)
5167751760
&& (ofst!=0 || lockMask<3)
5167851761
&& (ofst<3 || lockMask<(1<<ofst))
5167951762
));
5168051763
}
@@ -52220,31 +52303,10 @@
5222052303
**
5222152304
** This division contains the implementation of methods on the
5222252305
** sqlite3_vfs object.
5222352306
*/
5222452307
52225
-#if 0 /* No longer necessary */
52226
-/*
52227
-** Convert a filename from whatever the underlying operating system
52228
-** supports for filenames into UTF-8. Space to hold the result is
52229
-** obtained from malloc and must be freed by the calling function.
52230
-*/
52231
-static char *winConvertToUtf8Filename(const void *zFilename){
52232
- char *zConverted = 0;
52233
- if( osIsNT() ){
52234
- zConverted = winUnicodeToUtf8(zFilename);
52235
- }
52236
-#ifdef SQLITE_WIN32_HAS_ANSI
52237
- else{
52238
- zConverted = winMbcsToUtf8(zFilename, osAreFileApisANSI());
52239
- }
52240
-#endif
52241
- /* caller will handle out of memory */
52242
- return zConverted;
52243
-}
52244
-#endif
52245
-
5224652308
/*
5224752309
** This function returns non-zero if the specified UTF-8 string buffer
5224852310
** ends with a directory separator character or one was successfully
5224952311
** added to it.
5225052312
*/
@@ -52380,46 +52442,10 @@
5238052442
sqlite3_snprintf(nMax, zBuf, "%s", zDir);
5238152443
sqlite3_free(zConverted);
5238252444
break;
5238352445
}
5238452446
sqlite3_free(zConverted);
52385
-#if 0 /* No longer necessary */
52386
- }else{
52387
- zConverted = sqlite3MallocZero( nMax+1 );
52388
- if( !zConverted ){
52389
- sqlite3_free(zBuf);
52390
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52391
- return SQLITE_IOERR_NOMEM_BKPT;
52392
- }
52393
- if( osCygwin_conv_path(
52394
- CCP_POSIX_TO_WIN_W, zDir,
52395
- zConverted, nMax+1)<0 ){
52396
- sqlite3_free(zConverted);
52397
- sqlite3_free(zBuf);
52398
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
52399
- return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
52400
- "winGetTempname2", zDir);
52401
- }
52402
- if( winIsDir(zConverted) ){
52403
- /* At this point, we know the candidate directory exists and should
52404
- ** be used. However, we may need to convert the string containing
52405
- ** its name into UTF-8 (i.e. if it is UTF-16 right now).
52406
- */
52407
- char *zUtf8 = winConvertToUtf8Filename(zConverted);
52408
- if( !zUtf8 ){
52409
- sqlite3_free(zConverted);
52410
- sqlite3_free(zBuf);
52411
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52412
- return SQLITE_IOERR_NOMEM_BKPT;
52413
- }
52414
- sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
52415
- sqlite3_free(zUtf8);
52416
- sqlite3_free(zConverted);
52417
- break;
52418
- }
52419
- sqlite3_free(zConverted);
52420
-#endif /* No longer necessary */
5242152447
}
5242252448
}
5242352449
}
5242452450
#endif
5242552451
@@ -53314,38 +53340,10 @@
5331453340
winSimplifyName(zFull);
5331553341
return rc;
5331653342
}
5331753343
}
5331853344
#endif /* __CYGWIN__ */
53319
-#if 0 /* This doesn't work correctly at all! See:
53320
- <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53321
-*/
53322
- SimulateIOError( return SQLITE_ERROR );
53323
- UNUSED_PARAMETER(nFull);
53324
- assert( nFull>=pVfs->mxPathname );
53325
- char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
53326
- if( !zOut ){
53327
- return SQLITE_IOERR_NOMEM_BKPT;
53328
- }
53329
- if( osCygwin_conv_path(
53330
- CCP_POSIX_TO_WIN_W,
53331
- zRelative, zOut, pVfs->mxPathname+1)<0 ){
53332
- sqlite3_free(zOut);
53333
- return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53334
- "winFullPathname2", zRelative);
53335
- }else{
53336
- char *zUtf8 = winConvertToUtf8Filename(zOut);
53337
- if( !zUtf8 ){
53338
- sqlite3_free(zOut);
53339
- return SQLITE_IOERR_NOMEM_BKPT;
53340
- }
53341
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
53342
- sqlite3_free(zUtf8);
53343
- sqlite3_free(zOut);
53344
- }
53345
- return SQLITE_OK;
53346
-#endif
5334753345
5334853346
#if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && defined(_WIN32)
5334953347
SimulateIOError( return SQLITE_ERROR );
5335053348
/* WinCE has no concept of a relative pathname, or so I am told. */
5335153349
/* WinRT has no way to convert a relative path to an absolute one. */
@@ -53487,31 +53485,12 @@
5348753485
** Interfaces for opening a shared library, finding entry points
5348853486
** within the shared library, and closing the shared library.
5348953487
*/
5349053488
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
5349153489
HANDLE h;
53492
-#if 0 /* This doesn't work correctly at all! See:
53493
- <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53494
-*/
53495
- int nFull = pVfs->mxPathname+1;
53496
- char *zFull = sqlite3MallocZero( nFull );
53497
- void *zConverted = 0;
53498
- if( zFull==0 ){
53499
- OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53500
- return 0;
53501
- }
53502
- if( winFullPathname(pVfs, zFilename, nFull, zFull)!=SQLITE_OK ){
53503
- sqlite3_free(zFull);
53504
- OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53505
- return 0;
53506
- }
53507
- zConverted = winConvertFromUtf8Filename(zFull);
53508
- sqlite3_free(zFull);
53509
-#else
5351053490
void *zConverted = winConvertFromUtf8Filename(zFilename);
5351153491
UNUSED_PARAMETER(pVfs);
53512
-#endif
5351353492
if( zConverted==0 ){
5351453493
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
5351553494
return 0;
5351653495
}
5351753496
if( osIsNT() ){
@@ -54953,10 +54932,11 @@
5495354932
BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
5495454933
u32 aHash[BITVEC_NINT]; /* Hash table representation */
5495554934
Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
5495654935
} u;
5495754936
};
54937
+
5495854938
5495954939
/*
5496054940
** Create a new bitmap object able to handle bits between 0 and iSize,
5496154941
** inclusive. Return a pointer to the new object. Return NULL if
5496254942
** malloc fails.
@@ -55063,11 +55043,13 @@
5506355043
if( aiValues==0 ){
5506455044
return SQLITE_NOMEM_BKPT;
5506555045
}else{
5506655046
memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
5506755047
memset(p->u.apSub, 0, sizeof(p->u.apSub));
55068
- p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
55048
+ p->iDivisor = p->iSize/BITVEC_NPTR;
55049
+ if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++;
55050
+ if( p->iDivisor<BITVEC_NBIT ) p->iDivisor = BITVEC_NBIT;
5506955051
rc = sqlite3BitvecSet(p, i);
5507055052
for(j=0; j<BITVEC_NINT; j++){
5507155053
if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
5507255054
}
5507355055
sqlite3StackFree(0, aiValues);
@@ -55139,10 +55121,56 @@
5513955121
** was created.
5514055122
*/
5514155123
SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
5514255124
return p->iSize;
5514355125
}
55126
+
55127
+#ifdef SQLITE_DEBUG
55128
+/*
55129
+** Show the content of a Bitvec option and its children. Indent
55130
+** everything by n spaces. Add x to each bitvec value.
55131
+**
55132
+** From a debugger such as gdb, one can type:
55133
+**
55134
+** call sqlite3ShowBitvec(p)
55135
+**
55136
+** For some Bitvec p and see a recursive view of the Bitvec's content.
55137
+*/
55138
+static void showBitvec(Bitvec *p, int n, unsigned x){
55139
+ int i;
55140
+ if( p==0 ){
55141
+ printf("NULL\n");
55142
+ return;
55143
+ }
55144
+ printf("Bitvec 0x%p iSize=%u", p, p->iSize);
55145
+ if( p->iSize<=BITVEC_NBIT ){
55146
+ printf(" bitmap\n");
55147
+ printf("%*s bits:", n, "");
55148
+ for(i=1; i<=BITVEC_NBIT; i++){
55149
+ if( sqlite3BitvecTest(p,i) ) printf(" %u", x+(unsigned)i);
55150
+ }
55151
+ printf("\n");
55152
+ }else if( p->iDivisor==0 ){
55153
+ printf(" hash with %u entries\n", p->nSet);
55154
+ printf("%*s bits:", n, "");
55155
+ for(i=0; i<BITVEC_NINT; i++){
55156
+ if( p->u.aHash[i] ) printf(" %u", x+(unsigned)p->u.aHash[i]);
55157
+ }
55158
+ printf("\n");
55159
+ }else{
55160
+ printf(" sub-bitvec with iDivisor=%u\n", p->iDivisor);
55161
+ for(i=0; i<BITVEC_NPTR; i++){
55162
+ if( p->u.apSub[i]==0 ) continue;
55163
+ printf("%*s apSub[%d]=", n, "", i);
55164
+ showBitvec(p->u.apSub[i], n+4, i*p->iDivisor);
55165
+ }
55166
+ }
55167
+}
55168
+SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec *p){
55169
+ showBitvec(p, 0, 0);
55170
+}
55171
+#endif
5514455172
5514555173
#ifndef SQLITE_UNTESTABLE
5514655174
/*
5514755175
** Let V[] be an array of unsigned characters sufficient to hold
5514855176
** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55150,40 +55178,48 @@
5515055178
** individual bits within V.
5515155179
*/
5515255180
#define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
5515355181
#define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
5515455182
#define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55183
+
5515555184
5515655185
/*
5515755186
** This routine runs an extensive test of the Bitvec code.
5515855187
**
5515955188
** The input is an array of integers that acts as a program
5516055189
** to test the Bitvec. The integers are opcodes followed
5516155190
** by 0, 1, or 3 operands, depending on the opcode. Another
5516255191
** opcode follows immediately after the last operand.
5516355192
**
55164
-** There are 6 opcodes numbered from 0 through 5. 0 is the
55193
+** There are opcodes numbered starting with 0. 0 is the
5516555194
** "halt" opcode and causes the test to end.
5516655195
**
5516755196
** 0 Halt and return the number of errors
5516855197
** 1 N S X Set N bits beginning with S and incrementing by X
5516955198
** 2 N S X Clear N bits beginning with S and incrementing by X
5517055199
** 3 N Set N randomly chosen bits
5517155200
** 4 N Clear N randomly chosen bits
5517255201
** 5 N S X Set N bits from S increment X in array only, not in bitvec
55202
+** 6 Invoice sqlite3ShowBitvec() on the Bitvec object so far
55203
+** 7 X Show compile-time parameters and the hash of X
5517355204
**
5517455205
** The opcodes 1 through 4 perform set and clear operations are performed
5517555206
** on both a Bitvec object and on a linear array of bits obtained from malloc.
5517655207
** Opcode 5 works on the linear array only, not on the Bitvec.
5517755208
** Opcode 5 is used to deliberately induce a fault in order to
55178
-** confirm that error detection works.
55209
+** confirm that error detection works. Opcodes 6 and greater are
55210
+** state output opcodes. Opcodes 6 and greater are no-ops unless
55211
+** SQLite has been compiled with SQLITE_DEBUG.
5517955212
**
5518055213
** At the conclusion of the test the linear array is compared
5518155214
** against the Bitvec object. If there are any differences,
5518255215
** an error is returned. If they are the same, zero is returned.
5518355216
**
5518455217
** If a memory allocation error occurs, return -1.
55218
+**
55219
+** sz is the size of the Bitvec. Or if sz is negative, make the size
55220
+** 2*(unsigned)(-sz) and disabled the linear vector check.
5518555221
*/
5518655222
SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
5518755223
Bitvec *pBitvec = 0;
5518855224
unsigned char *pV = 0;
5518955225
int rc = -1;
@@ -55190,22 +55226,45 @@
5519055226
int i, nx, pc, op;
5519155227
void *pTmpSpace;
5519255228
5519355229
/* Allocate the Bitvec to be tested and a linear array of
5519455230
** bits to act as the reference */
55195
- pBitvec = sqlite3BitvecCreate( sz );
55196
- pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
55231
+ if( sz<=0 ){
55232
+ pBitvec = sqlite3BitvecCreate( 2*(unsigned)(-sz) );
55233
+ pV = 0;
55234
+ }else{
55235
+ pBitvec = sqlite3BitvecCreate( sz );
55236
+ pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
55237
+ }
5519755238
pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55198
- if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55239
+ if( pBitvec==0 || pTmpSpace==0 || (pV==0 && sz>0) ) goto bitvec_end;
5519955240
5520055241
/* NULL pBitvec tests */
5520155242
sqlite3BitvecSet(0, 1);
5520255243
sqlite3BitvecClear(0, 1, pTmpSpace);
5520355244
5520455245
/* Run the program */
5520555246
pc = i = 0;
5520655247
while( (op = aOp[pc])!=0 ){
55248
+ if( op>=6 ){
55249
+#ifdef SQLITE_DEBUG
55250
+ if( op==6 ){
55251
+ sqlite3ShowBitvec(pBitvec);
55252
+ }else if( op==7 ){
55253
+ printf("BITVEC_SZ = %d (%d by sizeof)\n",
55254
+ BITVEC_SZ, (int)sizeof(Bitvec));
55255
+ printf("BITVEC_USIZE = %d\n", (int)BITVEC_USIZE);
55256
+ printf("BITVEC_NELEM = %d\n", (int)BITVEC_NELEM);
55257
+ printf("BITVEC_NBIT = %d\n", (int)BITVEC_NBIT);
55258
+ printf("BITVEC_NINT = %d\n", (int)BITVEC_NINT);
55259
+ printf("BITVEC_MXHASH = %d\n", (int)BITVEC_MXHASH);
55260
+ printf("BITVEC_NPTR = %d\n", (int)BITVEC_NPTR);
55261
+ }
55262
+#endif
55263
+ pc++;
55264
+ continue;
55265
+ }
5520755266
switch( op ){
5520855267
case 1:
5520955268
case 2:
5521055269
case 5: {
5521155270
nx = 4;
@@ -55223,33 +55282,37 @@
5522355282
}
5522455283
if( (--aOp[pc+1]) > 0 ) nx = 0;
5522555284
pc += nx;
5522655285
i = (i & 0x7fffffff)%sz;
5522755286
if( (op & 1)!=0 ){
55228
- SETBIT(pV, (i+1));
55287
+ if( pV ) SETBIT(pV, (i+1));
5522955288
if( op!=5 ){
5523055289
if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
5523155290
}
5523255291
}else{
55233
- CLEARBIT(pV, (i+1));
55292
+ if( pV ) CLEARBIT(pV, (i+1));
5523455293
sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
5523555294
}
5523655295
}
5523755296
5523855297
/* Test to make sure the linear array exactly matches the
5523955298
** Bitvec object. Start with the assumption that they do
5524055299
** match (rc==0). Change rc to non-zero if a discrepancy
5524155300
** is found.
5524255301
*/
55243
- rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55244
- + sqlite3BitvecTest(pBitvec, 0)
55245
- + (sqlite3BitvecSize(pBitvec) - sz);
55246
- for(i=1; i<=sz; i++){
55247
- if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55248
- rc = i;
55249
- break;
55250
- }
55302
+ if( pV ){
55303
+ rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
55304
+ + sqlite3BitvecTest(pBitvec, 0)
55305
+ + (sqlite3BitvecSize(pBitvec) - sz);
55306
+ for(i=1; i<=sz; i++){
55307
+ if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
55308
+ rc = i;
55309
+ break;
55310
+ }
55311
+ }
55312
+ }else{
55313
+ rc = 0;
5525155314
}
5525255315
5525355316
/* Free allocated structure */
5525455317
bitvec_end:
5525555318
sqlite3_free(pTmpSpace);
@@ -58849,10 +58912,13 @@
5884958912
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
5885058913
PCache *pPCache; /* Pointer to page cache object */
5885158914
#ifndef SQLITE_OMIT_WAL
5885258915
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
5885358916
char *zWal; /* File name for write-ahead log */
58917
+#endif
58918
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
58919
+ sqlite3 *dbWal;
5885458920
#endif
5885558921
};
5885658922
5885758923
/*
5885858924
** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
@@ -65731,10 +65797,15 @@
6573165797
if( rc==SQLITE_OK ){
6573265798
rc = sqlite3WalOpen(pPager->pVfs,
6573365799
pPager->fd, pPager->zWal, pPager->exclusiveMode,
6573465800
pPager->journalSizeLimit, &pPager->pWal
6573565801
);
65802
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65803
+ if( rc==SQLITE_OK ){
65804
+ sqlite3WalDb(pPager->pWal, pPager->dbWal);
65805
+ }
65806
+#endif
6573665807
}
6573765808
pagerFixMaplimit(pPager);
6573865809
6573965810
return rc;
6574065811
}
@@ -65850,10 +65921,11 @@
6585065921
/*
6585165922
** Set the database handle used by the wal layer to determine if
6585265923
** blocking locks are required.
6585365924
*/
6585465925
SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
65926
+ pPager->dbWal = db;
6585565927
if( pagerUseWal(pPager) ){
6585665928
sqlite3WalDb(pPager->pWal, db);
6585765929
}
6585865930
}
6585965931
#endif
@@ -69023,11 +69095,10 @@
6902369095
assert( rc==SQLITE_OK );
6902469096
if( pWal->bShmUnreliable==0 ){
6902569097
rc = walIndexReadHdr(pWal, pChanged);
6902669098
}
6902769099
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
69028
- walDisableBlocking(pWal);
6902969100
if( rc==SQLITE_BUSY_TIMEOUT ){
6903069101
rc = SQLITE_BUSY;
6903169102
*pCnt |= WAL_RETRY_BLOCKED_MASK;
6903269103
}
6903369104
#endif
@@ -69038,10 +69109,11 @@
6903869109
** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
6903969110
** would be technically correct. But the race is benign since with
6904069111
** WAL_RETRY this routine will be called again and will probably be
6904169112
** right on the second iteration.
6904269113
*/
69114
+ (void)walEnableBlocking(pWal);
6904369115
if( pWal->apWiData[0]==0 ){
6904469116
/* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
6904569117
** We assume this is a transient condition, so return WAL_RETRY. The
6904669118
** xShmMap() implementation used by the default unix and win32 VFS
6904769119
** modules may return SQLITE_BUSY due to a race condition in the
@@ -69054,10 +69126,11 @@
6905469126
rc = WAL_RETRY;
6905569127
}else if( rc==SQLITE_BUSY ){
6905669128
rc = SQLITE_BUSY_RECOVERY;
6905769129
}
6905869130
}
69131
+ walDisableBlocking(pWal);
6905969132
if( rc!=SQLITE_OK ){
6906069133
return rc;
6906169134
}
6906269135
else if( pWal->bShmUnreliable ){
6906369136
return walBeginShmUnreliable(pWal, pChanged);
@@ -69741,10 +69814,11 @@
6974169814
rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
6974269815
}
6974369816
if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
6974469817
}
6974569818
SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69819
+ pWal->iReCksum = 0;
6974669820
}
6974769821
return rc;
6974869822
}
6974969823
6975069824
/*
@@ -69788,10 +69862,13 @@
6978869862
pWal->hdr.aFrameCksum[1] = aWalData[2];
6978969863
SEH_TRY {
6979069864
walCleanupHash(pWal);
6979169865
}
6979269866
SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69867
+ if( pWal->iReCksum>pWal->hdr.mxFrame ){
69868
+ pWal->iReCksum = 0;
69869
+ }
6979369870
}
6979469871
6979569872
return rc;
6979669873
}
6979769874
@@ -72503,11 +72580,11 @@
7250372580
if( pKey ){
7250472581
KeyInfo *pKeyInfo = pCur->pKeyInfo;
7250572582
assert( nKey==(i64)(int)nKey );
7250672583
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
7250772584
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72508
- sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
72585
+ sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey);
7250972586
if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
7251072587
rc = SQLITE_CORRUPT_BKPT;
7251172588
}else{
7251272589
rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
7251372590
}
@@ -73560,14 +73637,14 @@
7356073637
u8 *pTmp; /* Temporary ptr into data[] */
7356173638
7356273639
assert( pPage->pBt!=0 );
7356373640
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
7356473641
assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
73565
- assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
73642
+ assert( CORRUPT_DB || iEnd <= (int)pPage->pBt->usableSize );
7356673643
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
7356773644
assert( iSize>=4 ); /* Minimum cell size is 4 */
73568
- assert( CORRUPT_DB || iStart<=pPage->pBt->usableSize-4 );
73645
+ assert( CORRUPT_DB || iStart<=(int)pPage->pBt->usableSize-4 );
7356973646
7357073647
/* The list of freeblocks must be in ascending order. Find the
7357173648
** spot on the list where iStart should be inserted.
7357273649
*/
7357373650
hdr = pPage->hdrOffset;
@@ -74487,10 +74564,11 @@
7448774564
removed = 1;
7448874565
}
7448974566
sqlite3_mutex_leave(pMainMtx);
7449074567
return removed;
7449174568
#else
74569
+ UNUSED_PARAMETER( pBt );
7449274570
return 1;
7449374571
#endif
7449474572
}
7449574573
7449674574
/*
@@ -74704,10 +74782,14 @@
7470474782
BtShared *pBt = p->pBt;
7470574783
assert( nReserve>=0 && nReserve<=255 );
7470674784
sqlite3BtreeEnter(p);
7470774785
pBt->nReserveWanted = (u8)nReserve;
7470874786
x = pBt->pageSize - pBt->usableSize;
74787
+ if( x==nReserve && (pageSize==0 || (u32)pageSize==pBt->pageSize) ){
74788
+ sqlite3BtreeLeave(p);
74789
+ return SQLITE_OK;
74790
+ }
7470974791
if( nReserve<x ) nReserve = x;
7471074792
if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
7471174793
sqlite3BtreeLeave(p);
7471274794
return SQLITE_READONLY;
7471374795
}
@@ -75328,10 +75410,17 @@
7532875410
7532975411
if( rc!=SQLITE_OK ){
7533075412
(void)sqlite3PagerWalWriteLock(pPager, 0);
7533175413
unlockBtreeIfUnused(pBt);
7533275414
}
75415
+#if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
75416
+ if( rc==SQLITE_BUSY_TIMEOUT ){
75417
+ /* If a blocking lock timed out, break out of the loop here so that
75418
+ ** the busy-handler is not invoked. */
75419
+ break;
75420
+ }
75421
+#endif
7533375422
}while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
7533475423
btreeInvokeBusyHandler(pBt) );
7533575424
sqlite3PagerWalDb(pPager, 0);
7533675425
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
7533775426
if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -77285,10 +77374,34 @@
7728577374
*pRes = 1;
7728677375
rc = SQLITE_OK;
7728777376
}
7728877377
return rc;
7728977378
}
77379
+
77380
+/* Set *pRes to 1 (true) if the BTree pointed to by cursor pCur contains zero
77381
+** rows of content. Set *pRes to 0 (false) if the table contains content.
77382
+** Return SQLITE_OK on success or some error code (ex: SQLITE_NOMEM) if
77383
+** something goes wrong.
77384
+*/
77385
+SQLITE_PRIVATE int sqlite3BtreeIsEmpty(BtCursor *pCur, int *pRes){
77386
+ int rc;
77387
+
77388
+ assert( cursorOwnsBtShared(pCur) );
77389
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
77390
+ if( pCur->eState==CURSOR_VALID ){
77391
+ *pRes = 0;
77392
+ return SQLITE_OK;
77393
+ }
77394
+ rc = moveToRoot(pCur);
77395
+ if( rc==SQLITE_EMPTY ){
77396
+ *pRes = 1;
77397
+ rc = SQLITE_OK;
77398
+ }else{
77399
+ *pRes = 0;
77400
+ }
77401
+ return rc;
77402
+}
7729077403
7729177404
#ifdef SQLITE_DEBUG
7729277405
/* The cursors is CURSOR_VALID and has BTCF_AtLast set. Verify that
7729377406
** this flags are true for a consistent database.
7729477407
**
@@ -77505,12 +77618,12 @@
7750577618
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
7750677619
return rc;
7750777620
}
7750877621
7750977622
/*
77510
-** Compare the "idx"-th cell on the page the cursor pCur is currently
77511
-** pointing to to pIdxKey using xRecordCompare. Return negative or
77623
+** Compare the "idx"-th cell on the page pPage against the key
77624
+** pointing to by pIdxKey using xRecordCompare. Return negative or
7751277625
** zero if the cell is less than or equal pIdxKey. Return positive
7751377626
** if unknown.
7751477627
**
7751577628
** Return value negative: Cell at pCur[idx] less than pIdxKey
7751677629
**
@@ -77521,16 +77634,15 @@
7752177634
**
7752277635
** This routine is part of an optimization. It is always safe to return
7752377636
** a positive value as that will cause the optimization to be skipped.
7752477637
*/
7752577638
static int indexCellCompare(
77526
- BtCursor *pCur,
77639
+ MemPage *pPage,
7752777640
int idx,
7752877641
UnpackedRecord *pIdxKey,
7752977642
RecordCompare xRecordCompare
7753077643
){
77531
- MemPage *pPage = pCur->pPage;
7753277644
int c;
7753377645
int nCell; /* Size of the pCell cell in bytes */
7753477646
u8 *pCell = findCellPastPtr(pPage, idx);
7753577647
7753677648
nCell = pCell[0];
@@ -77635,18 +77747,18 @@
7763577747
&& pCur->pPage->leaf
7763677748
&& cursorOnLastPage(pCur)
7763777749
){
7763877750
int c;
7763977751
if( pCur->ix==pCur->pPage->nCell-1
77640
- && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77752
+ && (c = indexCellCompare(pCur->pPage,pCur->ix,pIdxKey,xRecordCompare))<=0
7764177753
&& pIdxKey->errCode==SQLITE_OK
7764277754
){
7764377755
*pRes = c;
7764477756
return SQLITE_OK; /* Cursor already pointing at the correct spot */
7764577757
}
7764677758
if( pCur->iPage>0
77647
- && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77759
+ && indexCellCompare(pCur->pPage, 0, pIdxKey, xRecordCompare)<=0
7764877760
&& pIdxKey->errCode==SQLITE_OK
7764977761
){
7765077762
pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
7765177763
if( !pCur->pPage->isInit ){
7765277764
return SQLITE_CORRUPT_BKPT;
@@ -77859,11 +77971,11 @@
7785977971
if( pCur->eState!=CURSOR_VALID ) return 0;
7786077972
if( NEVER(pCur->pPage->leaf==0) ) return -1;
7786177973
7786277974
n = pCur->pPage->nCell;
7786377975
for(i=0; i<pCur->iPage; i++){
77864
- n *= pCur->apPage[i]->nCell;
77976
+ n *= pCur->apPage[i]->nCell+1;
7786577977
}
7786677978
return n;
7786777979
}
7786877980
7786977981
/*
@@ -80316,11 +80428,16 @@
8031680428
8031780429
/* If the sibling pages are not leaves, ensure that the right-child pointer
8031880430
** of the right-most new sibling page is set to the value that was
8031980431
** originally in the same field of the right-most old sibling page. */
8032080432
if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
80321
- MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
80433
+ MemPage *pOld;
80434
+ if( nNew>nOld ){
80435
+ pOld = apNew[nOld-1];
80436
+ }else{
80437
+ pOld = apOld[nOld-1];
80438
+ }
8032280439
memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
8032380440
}
8032480441
8032580442
/* Make any required updates to pointer map entries associated with
8032680443
** cells stored on sibling pages following the balance operation. Pointer
@@ -82948,10 +83065,11 @@
8294883065
** btree as the argument handle holds an exclusive lock on the
8294983066
** sqlite_schema table. Otherwise SQLITE_OK.
8295083067
*/
8295183068
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
8295283069
int rc;
83070
+ UNUSED_PARAMETER(p); /* only used in DEBUG builds */
8295383071
assert( sqlite3_mutex_held(p->db->mutex) );
8295483072
sqlite3BtreeEnter(p);
8295583073
rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
8295683074
assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
8295783075
sqlite3BtreeLeave(p);
@@ -87272,10 +87390,13 @@
8727287390
** into register iDest, then add the OPFLAG_TYPEOFARG flag to that
8727387391
** opcode.
8727487392
*/
8727587393
SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe *p, int iDest){
8727687394
VdbeOp *pOp = sqlite3VdbeGetLastOp(p);
87395
+#ifdef SQLITE_DEBUG
87396
+ while( pOp->opcode==OP_ReleaseReg ) pOp--;
87397
+#endif
8727787398
if( pOp->p3==iDest && pOp->opcode==OP_Column ){
8727887399
pOp->p5 |= OPFLAG_TYPEOFARG;
8727987400
}
8728087401
}
8728187402
@@ -90165,34 +90286,26 @@
9016590286
}
9016690287
}
9016790288
return;
9016890289
}
9016990290
/*
90170
-** This routine is used to allocate sufficient space for an UnpackedRecord
90171
-** structure large enough to be used with sqlite3VdbeRecordUnpack() if
90172
-** the first argument is a pointer to KeyInfo structure pKeyInfo.
90173
-**
90174
-** The space is either allocated using sqlite3DbMallocRaw() or from within
90175
-** the unaligned buffer passed via the second and third arguments (presumably
90176
-** stack space). If the former, then *ppFree is set to a pointer that should
90177
-** be eventually freed by the caller using sqlite3DbFree(). Or, if the
90178
-** allocation comes from the pSpace/szSpace buffer, *ppFree is set to NULL
90179
-** before returning.
90180
-**
90181
-** If an OOM error occurs, NULL is returned.
90291
+** Allocate sufficient space for an UnpackedRecord structure large enough
90292
+** to hold a decoded index record for pKeyInfo.
90293
+**
90294
+** The space is allocated using sqlite3DbMallocRaw(). If an OOM error
90295
+** occurs, NULL is returned.
9018290296
*/
9018390297
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
9018490298
KeyInfo *pKeyInfo /* Description of the record */
9018590299
){
9018690300
UnpackedRecord *p; /* Unpacked record to return */
90187
- int nByte; /* Number of bytes required for *p */
90301
+ u64 nByte; /* Number of bytes required for *p */
9018890302
assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
9018990303
nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
9019090304
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
9019190305
if( !p ) return 0;
9019290306
p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
90193
- assert( pKeyInfo->aSortFlags!=0 );
9019490307
p->pKeyInfo = pKeyInfo;
9019590308
p->nField = pKeyInfo->nKeyField + 1;
9019690309
return p;
9019790310
}
9019890311
@@ -90200,11 +90313,10 @@
9020090313
** Given the nKey-byte encoding of a record in pKey[], populate the
9020190314
** UnpackedRecord structure indicated by the fourth argument with the
9020290315
** contents of the decoded record.
9020390316
*/
9020490317
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
90205
- KeyInfo *pKeyInfo, /* Information about the record format */
9020690318
int nKey, /* Size of the binary record */
9020790319
const void *pKey, /* The binary record */
9020890320
UnpackedRecord *p /* Populate this structure before returning. */
9020990321
){
9021090322
const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90211,10 +90323,11 @@
9021190323
u32 d;
9021290324
u32 idx; /* Offset in aKey[] to read from */
9021390325
u16 u; /* Unsigned loop counter */
9021490326
u32 szHdr;
9021590327
Mem *pMem = p->aMem;
90328
+ KeyInfo *pKeyInfo = p->pKeyInfo;
9021690329
9021790330
p->default_rc = 0;
9021890331
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
9021990332
idx = getVarint32(aKey, szHdr);
9022090333
d = szHdr;
@@ -90238,10 +90351,12 @@
9023890351
/* In a corrupt record entry, the last pMem might have been set up using
9023990352
** uninitialized memory. Overwrite its value with NULL, to prevent
9024090353
** warnings from MSAN. */
9024190354
sqlite3VdbeMemSetNull(pMem-1);
9024290355
}
90356
+ testcase( u == pKeyInfo->nKeyField + 1 );
90357
+ testcase( u < pKeyInfo->nKeyField + 1 );
9024390358
assert( u<=pKeyInfo->nKeyField + 1 );
9024490359
p->nField = u;
9024590360
}
9024690361
9024790362
#ifdef SQLITE_DEBUG
@@ -91097,10 +91212,11 @@
9109791212
** is an integer.
9109891213
**
9109991214
** The easiest way to enforce this limit is to consider only records with
9110091215
** 13 fields or less. If the first field is an integer, the maximum legal
9110191216
** header size is (12*5 + 1 + 1) bytes. */
91217
+ assert( p->pKeyInfo->aSortFlags!=0 );
9110291218
if( p->pKeyInfo->nAllField<=13 ){
9110391219
int flags = p->aMem[0].flags;
9110491220
if( p->pKeyInfo->aSortFlags[0] ){
9110591221
if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
9110691222
return sqlite3VdbeRecordCompare;
@@ -91346,10 +91462,11 @@
9134691462
}else{
9134791463
v->expmask |= ((u32)1 << (iVar-1));
9134891464
}
9134991465
}
9135091466
91467
+#ifndef SQLITE_OMIT_DATETIME_FUNCS
9135191468
/*
9135291469
** Cause a function to throw an error if it was call from OP_PureFunc
9135391470
** rather than OP_Function.
9135491471
**
9135591472
** OP_PureFunc means that the function must be deterministic, and should
@@ -91379,10 +91496,11 @@
9137991496
sqlite3_free(zMsg);
9138091497
return 0;
9138191498
}
9138291499
return 1;
9138391500
}
91501
+#endif /* SQLITE_OMIT_DATETIME_FUNCS */
9138491502
9138591503
#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
9138691504
/*
9138791505
** This Walker callback is used to help verify that calls to
9138891506
** sqlite3BtreeCursorHint() with opcode BTREE_HINT_RANGE have
@@ -91455,11 +91573,10 @@
9145591573
){
9145691574
sqlite3 *db = v->db;
9145791575
i64 iKey2;
9145891576
PreUpdate preupdate;
9145991577
const char *zTbl = pTab->zName;
91460
- static const u8 fakeSortOrder = 0;
9146191578
#ifdef SQLITE_DEBUG
9146291579
int nRealCol;
9146391580
if( pTab->tabFlags & TF_WithoutRowid ){
9146491581
nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
9146591582
}else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91494,11 +91611,11 @@
9149491611
preupdate.iNewReg = iReg;
9149591612
preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
9149691613
preupdate.pKeyinfo->db = db;
9149791614
preupdate.pKeyinfo->enc = ENC(db);
9149891615
preupdate.pKeyinfo->nKeyField = pTab->nCol;
91499
- preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder;
91616
+ preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
9150091617
preupdate.iKey1 = iKey1;
9150191618
preupdate.iKey2 = iKey2;
9150291619
preupdate.pTab = pTab;
9150391620
preupdate.iBlobWrite = iBlobWrite;
9150491621
@@ -93691,11 +93808,11 @@
9369193808
UnpackedRecord *pRet; /* Return value */
9369293809
9369393810
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
9369493811
if( pRet ){
9369593812
memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93696
- sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
93813
+ sqlite3VdbeRecordUnpack(nKey, pKey, pRet);
9369793814
}
9369893815
return pRet;
9369993816
}
9370093817
9370193818
/*
@@ -93720,10 +93837,13 @@
9372093837
rc = SQLITE_MISUSE_BKPT;
9372193838
goto preupdate_old_out;
9372293839
}
9372393840
if( p->pPk ){
9372493841
iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
93842
+ }else if( iIdx >= p->pTab->nCol ){
93843
+ rc = SQLITE_MISUSE_BKPT;
93844
+ goto preupdate_old_out;
9372593845
}else{
9372693846
iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
9372793847
}
9372893848
if( iStore>=p->pCsr->nField || iStore<0 ){
9372993849
rc = SQLITE_RANGE;
@@ -93875,10 +93995,12 @@
9387593995
rc = SQLITE_MISUSE_BKPT;
9387693996
goto preupdate_new_out;
9387793997
}
9387893998
if( p->pPk && p->op!=SQLITE_UPDATE ){
9387993999
iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
94000
+ }else if( iIdx >= p->pTab->nCol ){
94001
+ return SQLITE_MISUSE_BKPT;
9388094002
}else{
9388194003
iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
9388294004
}
9388394005
9388494006
if( iStore>=p->pCsr->nField || iStore<0 ){
@@ -95200,10 +95322,40 @@
9520095322
}
9520195323
pDest->flags &= ~MEM_Ephem;
9520295324
return rc;
9520395325
}
9520495326
95327
+/*
95328
+** Send a "statement aborts" message to the error log.
95329
+*/
95330
+static SQLITE_NOINLINE void sqlite3VdbeLogAbort(
95331
+ Vdbe *p, /* The statement that is running at the time of failure */
95332
+ int rc, /* Error code */
95333
+ Op *pOp, /* Opcode that filed */
95334
+ Op *aOp /* All opcodes */
95335
+){
95336
+ const char *zSql = p->zSql; /* Original SQL text */
95337
+ const char *zPrefix = ""; /* Prefix added to SQL text */
95338
+ int pc; /* Opcode address */
95339
+ char zXtra[100]; /* Buffer space to store zPrefix */
95340
+
95341
+ if( p->pFrame ){
95342
+ assert( aOp[0].opcode==OP_Init );
95343
+ if( aOp[0].p4.z!=0 ){
95344
+ assert( aOp[0].p4.z[0]=='-'
95345
+ && aOp[0].p4.z[1]=='-'
95346
+ && aOp[0].p4.z[2]==' ' );
95347
+ sqlite3_snprintf(sizeof(zXtra), zXtra,"/* %s */ ",aOp[0].p4.z+3);
95348
+ zPrefix = zXtra;
95349
+ }else{
95350
+ zPrefix = "/* unknown trigger */ ";
95351
+ }
95352
+ }
95353
+ pc = (int)(pOp - aOp);
95354
+ sqlite3_log(rc, "statement aborts at %d: %s; [%s%s]",
95355
+ pc, p->zErrMsg, zPrefix, zSql);
95356
+}
9520595357
9520695358
/*
9520795359
** Return the symbolic name for the data type of a pMem
9520895360
*/
9520995361
static const char *vdbeMemTypeName(Mem *pMem){
@@ -95725,12 +95877,11 @@
9572595877
p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
9572695878
}
9572795879
}else{
9572895880
sqlite3VdbeError(p, "%s", pOp->p4.z);
9572995881
}
95730
- pcx = (int)(pOp - aOp);
95731
- sqlite3_log(pOp->p1, "abort at %d: %s; [%s]", pcx, p->zErrMsg, p->zSql);
95882
+ sqlite3VdbeLogAbort(p, pOp->p1, pOp, aOp);
9573295883
}
9573395884
rc = sqlite3VdbeHalt(p);
9573495885
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
9573595886
if( rc==SQLITE_BUSY ){
9573695887
p->rc = SQLITE_BUSY;
@@ -96884,10 +97035,11 @@
9688497035
}
9688597036
n = pOp->p3;
9688697037
pKeyInfo = pOp->p4.pKeyInfo;
9688797038
assert( n>0 );
9688897039
assert( pKeyInfo!=0 );
97040
+ assert( pKeyInfo->aSortFlags!=0 );
9688997041
p1 = pOp->p1;
9689097042
p2 = pOp->p2;
9689197043
#ifdef SQLITE_DEBUG
9689297044
if( aPermute ){
9689397045
int k, mx = 0;
@@ -97645,10 +97797,19 @@
9764597797
** Synopsis: typecheck(r[P1@P2])
9764697798
**
9764797799
** Apply affinities to the range of P2 registers beginning with P1.
9764897800
** Take the affinities from the Table object in P4. If any value
9764997801
** cannot be coerced into the correct type, then raise an error.
97802
+**
97803
+** If P3==0, then omit checking of VIRTUAL columns.
97804
+**
97805
+** If P3==1, then omit checking of all generated column, both VIRTUAL
97806
+** and STORED.
97807
+**
97808
+** If P3>=2, then only check column number P3-2 in the table (which will
97809
+** be a VIRTUAL column) against the value in reg[P1]. In this case,
97810
+** P2 will be 1.
9765097811
**
9765197812
** This opcode is similar to OP_Affinity except that this opcode
9765297813
** forces the register type to the Table column type. This is used
9765397814
** to implement "strict affinity".
9765497815
**
@@ -97659,30 +97820,42 @@
9765997820
**
9766097821
** Preconditions:
9766197822
**
9766297823
** <ul>
9766397824
** <li> P2 should be the number of non-virtual columns in the
97664
-** table of P4.
97665
-** <li> Table P4 should be a STRICT table.
97825
+** table of P4 unless P3>1, in which case P2 will be 1.
97826
+** <li> Table P4 is a STRICT table.
9766697827
** </ul>
9766797828
**
9766897829
** If any precondition is false, an assertion fault occurs.
9766997830
*/
9767097831
case OP_TypeCheck: {
9767197832
Table *pTab;
9767297833
Column *aCol;
9767397834
int i;
97835
+ int nCol;
9767497836
9767597837
assert( pOp->p4type==P4_TABLE );
9767697838
pTab = pOp->p4.pTab;
9767797839
assert( pTab->tabFlags & TF_Strict );
97678
- assert( pTab->nNVCol==pOp->p2 );
97840
+ assert( pOp->p3>=0 && pOp->p3<pTab->nCol+2 );
9767997841
aCol = pTab->aCol;
9768097842
pIn1 = &aMem[pOp->p1];
97681
- for(i=0; i<pTab->nCol; i++){
97682
- if( aCol[i].colFlags & COLFLAG_GENERATED ){
97683
- if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
97843
+ if( pOp->p3<2 ){
97844
+ assert( pTab->nNVCol==pOp->p2 );
97845
+ i = 0;
97846
+ nCol = pTab->nCol;
97847
+ }else{
97848
+ i = pOp->p3-2;
97849
+ nCol = i+1;
97850
+ assert( i<pTab->nCol );
97851
+ assert( aCol[i].colFlags & COLFLAG_VIRTUAL );
97852
+ assert( pOp->p2==1 );
97853
+ }
97854
+ for(; i<nCol; i++){
97855
+ if( (aCol[i].colFlags & COLFLAG_GENERATED)!=0 && pOp->p3<2 ){
97856
+ if( (aCol[i].colFlags & COLFLAG_VIRTUAL)!=0 ) continue;
9768497857
if( pOp->p3 ){ pIn1++; continue; }
9768597858
}
9768697859
assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
9768797860
applyAffinity(pIn1, aCol[i].affinity, encoding);
9768897861
if( (pIn1->flags & MEM_Null)==0 ){
@@ -98119,10 +98292,11 @@
9811998292
}
9812098293
}else{
9812198294
zHdr += sqlite3PutVarint(zHdr, serial_type);
9812298295
if( pRec->n ){
9812398296
assert( pRec->z!=0 );
98297
+ assert( pRec->z!=(const char*)sqlite3CtypeMap );
9812498298
memcpy(zPayload, pRec->z, pRec->n);
9812598299
zPayload += pRec->n;
9812698300
}
9812798301
}
9812898302
if( pRec==pLast ) break;
@@ -99756,11 +99930,11 @@
9975699930
rc = ExpandBlob(r.aMem);
9975799931
assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
9975899932
if( rc ) goto no_mem;
9975999933
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
9976099934
if( pIdxKey==0 ) goto no_mem;
99761
- sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey);
99935
+ sqlite3VdbeRecordUnpack(r.aMem->n, r.aMem->z, pIdxKey);
9976299936
pIdxKey->default_rc = 0;
9976399937
rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
9976499938
sqlite3DbFreeNN(db, pIdxKey);
9976599939
}
9976699940
if( rc!=SQLITE_OK ){
@@ -100753,10 +100927,36 @@
100753100927
VdbeBranchTaken(res!=0,2);
100754100928
if( res ) goto jump_to_p2;
100755100929
}
100756100930
break;
100757100931
}
100932
+
100933
+/* Opcode: IfEmpty P1 P2 * * *
100934
+** Synopsis: if( empty(P1) ) goto P2
100935
+**
100936
+** Check to see if the b-tree table that cursor P1 references is empty
100937
+** and jump to P2 if it is.
100938
+*/
100939
+case OP_IfEmpty: { /* jump */
100940
+ VdbeCursor *pC;
100941
+ BtCursor *pCrsr;
100942
+ int res;
100943
+
100944
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
100945
+ assert( pOp->p2>=0 && pOp->p2<p->nOp );
100946
+
100947
+ pC = p->apCsr[pOp->p1];
100948
+ assert( pC!=0 );
100949
+ assert( pC->eCurType==CURTYPE_BTREE );
100950
+ pCrsr = pC->uc.pCursor;
100951
+ assert( pCrsr );
100952
+ rc = sqlite3BtreeIsEmpty(pCrsr, &res);
100953
+ if( rc ) goto abort_due_to_error;
100954
+ VdbeBranchTaken(res!=0,2);
100955
+ if( res ) goto jump_to_p2;
100956
+ break;
100957
+}
100758100958
100759100959
/* Opcode: Next P1 P2 P3 * P5
100760100960
**
100761100961
** Advance cursor P1 so that it points to the next key/data pair in its
100762100962
** table or index. If there are no more key/value pairs then fall through
@@ -102625,11 +102825,18 @@
102625102825
sqlite3_vtab_cursor *pVCur;
102626102826
sqlite3_vtab *pVtab;
102627102827
const sqlite3_module *pModule;
102628102828
102629102829
assert( p->bIsReader );
102630
- pCur = 0;
102830
+ pCur = p->apCsr[pOp->p1];
102831
+ if( pCur!=0
102832
+ && ALWAYS( pCur->eCurType==CURTYPE_VTAB )
102833
+ && ALWAYS( pCur->uc.pVCur->pVtab==pOp->p4.pVtab->pVtab )
102834
+ ){
102835
+ /* This opcode is a no-op if the cursor is already open */
102836
+ break;
102837
+ }
102631102838
pVCur = 0;
102632102839
pVtab = pOp->p4.pVtab->pVtab;
102633102840
if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102634102841
rc = SQLITE_LOCKED;
102635102842
goto abort_due_to_error;
@@ -103567,12 +103774,11 @@
103567103774
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
103568103775
}
103569103776
p->rc = rc;
103570103777
sqlite3SystemError(db, rc);
103571103778
testcase( sqlite3GlobalConfig.xLog!=0 );
103572
- sqlite3_log(rc, "statement aborts at %d: %s; [%s]",
103573
- (int)(pOp - aOp), p->zErrMsg, p->zSql);
103779
+ sqlite3VdbeLogAbort(p, rc, pOp, aOp);
103574103780
if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p);
103575103781
if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
103576103782
if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
103577103783
db->flags |= SQLITE_CorruptRdOnly;
103578103784
}
@@ -104029,11 +104235,11 @@
104029104235
void *z,
104030104236
int n,
104031104237
int iOffset,
104032104238
int (*xCall)(BtCursor*, u32, u32, void*)
104033104239
){
104034
- int rc;
104240
+ int rc = SQLITE_OK;
104035104241
Incrblob *p = (Incrblob *)pBlob;
104036104242
Vdbe *v;
104037104243
sqlite3 *db;
104038104244
104039104245
if( p==0 ) return SQLITE_MISUSE_BKPT;
@@ -104069,21 +104275,36 @@
104069104275
** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
104070104276
** slightly more efficient). Since you cannot write to a PK column
104071104277
** using the incremental-blob API, this works. For the sessions module
104072104278
** anyhow.
104073104279
*/
104074
- sqlite3_int64 iKey;
104075
- iKey = sqlite3BtreeIntegerKey(p->pCsr);
104076
- assert( v->apCsr[0]!=0 );
104077
- assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
104078
- sqlite3VdbePreUpdateHook(
104079
- v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
104080
- );
104081
- }
104082
-#endif
104083
-
104280
+ if( sqlite3BtreeCursorIsValidNN(p->pCsr)==0 ){
104281
+ /* If the cursor is not currently valid, try to reseek it. This
104282
+ ** always either fails or finds the correct row - the cursor will
104283
+ ** have been marked permanently CURSOR_INVALID if the open row has
104284
+ ** been deleted. */
104285
+ int bDiff = 0;
104286
+ rc = sqlite3BtreeCursorRestore(p->pCsr, &bDiff);
104287
+ assert( bDiff==0 || sqlite3BtreeCursorIsValidNN(p->pCsr)==0 );
104288
+ }
104289
+ if( sqlite3BtreeCursorIsValidNN(p->pCsr) ){
104290
+ sqlite3_int64 iKey;
104291
+ iKey = sqlite3BtreeIntegerKey(p->pCsr);
104292
+ assert( v->apCsr[0]!=0 );
104293
+ assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
104294
+ sqlite3VdbePreUpdateHook(
104295
+ v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
104296
+ );
104297
+ }
104298
+ }
104299
+ if( rc==SQLITE_OK ){
104300
+ rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
104301
+ }
104302
+#else
104084104303
rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
104304
+#endif
104305
+
104085104306
sqlite3BtreeLeaveCursor(p->pCsr);
104086104307
if( rc==SQLITE_ABORT ){
104087104308
sqlite3VdbeFinalize(v);
104088104309
p->pStmt = 0;
104089104310
}else{
@@ -104932,11 +105153,11 @@
104932105153
const void *pKey1, int nKey1, /* Left side of comparison */
104933105154
const void *pKey2, int nKey2 /* Right side of comparison */
104934105155
){
104935105156
UnpackedRecord *r2 = pTask->pUnpacked;
104936105157
if( *pbKey2Cached==0 ){
104937
- sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
105158
+ sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104938105159
*pbKey2Cached = 1;
104939105160
}
104940105161
return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
104941105162
}
104942105163
@@ -104959,11 +105180,11 @@
104959105180
const void *pKey1, int nKey1, /* Left side of comparison */
104960105181
const void *pKey2, int nKey2 /* Right side of comparison */
104961105182
){
104962105183
UnpackedRecord *r2 = pTask->pUnpacked;
104963105184
if( !*pbKey2Cached ){
104964
- sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
105185
+ sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104965105186
*pbKey2Cached = 1;
104966105187
}
104967105188
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
104968105189
}
104969105190
@@ -104999,10 +105220,11 @@
104999105220
res = vdbeSorterCompareTail(
105000105221
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105001105222
);
105002105223
}
105003105224
}else{
105225
+ assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
105004105226
assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
105005105227
if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
105006105228
res = res * -1;
105007105229
}
105008105230
}
@@ -105062,10 +105284,11 @@
105062105284
}else{
105063105285
if( *v2 & 0x80 ) res = +1;
105064105286
}
105065105287
}
105066105288
105289
+ assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
105067105290
if( res==0 ){
105068105291
if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
105069105292
res = vdbeSorterCompareTail(
105070105293
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105071105294
);
@@ -105135,11 +105358,12 @@
105135105358
assert( pCsr->pKeyInfo );
105136105359
assert( !pCsr->isEphemeral );
105137105360
assert( pCsr->eCurType==CURTYPE_SORTER );
105138105361
assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105139105362
< 0x7fffffff );
105140
- szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1);
105363
+ assert( pCsr->pKeyInfo->nKeyField<=pCsr->pKeyInfo->nAllField );
105364
+ szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nAllField);
105141105365
sz = SZ_VDBESORTER(nWorker+1);
105142105366
105143105367
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105144105368
pCsr->uc.pSorter = pSorter;
105145105369
if( pSorter==0 ){
@@ -105149,11 +105373,16 @@
105149105373
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105150105374
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105151105375
pKeyInfo->db = 0;
105152105376
if( nField && nWorker==0 ){
105153105377
pKeyInfo->nKeyField = nField;
105378
+ assert( nField<=pCsr->pKeyInfo->nAllField );
105154105379
}
105380
+ /* It is OK that pKeyInfo reuses the aSortFlags field from pCsr->pKeyInfo,
105381
+ ** since the pCsr->pKeyInfo->aSortFlags[] array is invariant and lives
105382
+ ** longer that pSorter. */
105383
+ assert( pKeyInfo->aSortFlags==pCsr->pKeyInfo->aSortFlags );
105155105384
sqlite3BtreeEnter(pBt);
105156105385
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105157105386
sqlite3BtreeLeave(pBt);
105158105387
pSorter->nTask = nWorker + 1;
105159105388
pSorter->iPrev = (u8)(nWorker - 1);
@@ -106929,11 +107158,11 @@
106929107158
r2->nField = nKeyCol;
106930107159
}
106931107160
assert( r2->nField==nKeyCol );
106932107161
106933107162
pKey = vdbeSorterRowkey(pSorter, &nKey);
106934
- sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
107163
+ sqlite3VdbeRecordUnpack(nKey, pKey, r2);
106935107164
for(i=0; i<nKeyCol; i++){
106936107165
if( r2->aMem[i].flags & MEM_Null ){
106937107166
*pRes = -1;
106938107167
return SQLITE_OK;
106939107168
}
@@ -109303,17 +109532,16 @@
109303109532
/* Clearly non-deterministic functions like random(), but also
109304109533
** date/time functions that use 'now', and other functions like
109305109534
** sqlite_version() that might change over time cannot be used
109306109535
** in an index or generated column. Curiously, they can be used
109307109536
** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
109308
- ** all this. */
109537
+ ** allow this. */
109309109538
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
109310109539
NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
109311109540
}else{
109312109541
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
109313109542
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
109314
- if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
109315109543
}
109316109544
if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
109317109545
&& pParse->nested==0
109318109546
&& (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
109319109547
){
@@ -109325,10 +109553,11 @@
109325109553
pDef = 0;
109326109554
}else
109327109555
if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
109328109556
&& !IN_RENAME_OBJECT
109329109557
){
109558
+ if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
109330109559
sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
109331109560
}
109332109561
}
109333109562
109334109563
if( 0==IN_RENAME_OBJECT ){
@@ -109459,22 +109688,25 @@
109459109688
** type of the function
109460109689
*/
109461109690
return WRC_Prune;
109462109691
}
109463109692
#ifndef SQLITE_OMIT_SUBQUERY
109693
+ case TK_EXISTS:
109464109694
case TK_SELECT:
109465
- case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
109466109695
#endif
109467109696
case TK_IN: {
109468109697
testcase( pExpr->op==TK_IN );
109698
+ testcase( pExpr->op==TK_EXISTS );
109699
+ testcase( pExpr->op==TK_SELECT );
109469109700
if( ExprUseXSelect(pExpr) ){
109470109701
int nRef = pNC->nRef;
109471109702
testcase( pNC->ncFlags & NC_IsCheck );
109472109703
testcase( pNC->ncFlags & NC_PartIdx );
109473109704
testcase( pNC->ncFlags & NC_IdxExpr );
109474109705
testcase( pNC->ncFlags & NC_GenCol );
109475109706
assert( pExpr->x.pSelect );
109707
+ if( pExpr->op==TK_EXISTS ) pParse->bHasExists = 1;
109476109708
if( pNC->ncFlags & NC_SelfRef ){
109477109709
notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
109478109710
}else{
109479109711
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
109480109712
}
@@ -110485,11 +110717,13 @@
110485110717
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110486110718
return sqlite3ExprAffinity(
110487110719
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110488110720
);
110489110721
}
110490
- if( op==TK_VECTOR ){
110722
+ if( op==TK_VECTOR
110723
+ || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
110724
+ ){
110491110725
assert( ExprUseXList(pExpr) );
110492110726
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110493110727
}
110494110728
if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110495110729
assert( pExpr->op==TK_COLLATE
@@ -110678,11 +110912,13 @@
110678110912
}
110679110913
if( op==TK_CAST || op==TK_UPLUS ){
110680110914
p = p->pLeft;
110681110915
continue;
110682110916
}
110683
- if( op==TK_VECTOR ){
110917
+ if( op==TK_VECTOR
110918
+ || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
110919
+ ){
110684110920
assert( ExprUseXList(p) );
110685110921
p = p->x.pList->a[0].pExpr;
110686110922
continue;
110687110923
}
110688110924
if( op==TK_COLLATE ){
@@ -111552,11 +111788,11 @@
111552111788
return pRight;
111553111789
}else if( pRight==0 ){
111554111790
return pLeft;
111555111791
}else{
111556111792
u32 f = pLeft->flags | pRight->flags;
111557
- if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse))==EP_IsFalse
111793
+ if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse|EP_HasFunc))==EP_IsFalse
111558111794
&& !IN_RENAME_OBJECT
111559111795
){
111560111796
sqlite3ExprDeferredDelete(pParse, pLeft);
111561111797
sqlite3ExprDeferredDelete(pParse, pRight);
111562111798
return sqlite3Expr(db, TK_INTEGER, "0");
@@ -112780,10 +113016,90 @@
112780113016
pExpr = pExpr->op==TK_AND ? pLeft : pRight;
112781113017
}
112782113018
}
112783113019
return pExpr;
112784113020
}
113021
+
113022
+/*
113023
+** Return true if it might be advantageous to compute the right operand
113024
+** of expression pExpr first, before the left operand.
113025
+**
113026
+** Normally the left operand is computed before the right operand. But if
113027
+** the left operand contains a subquery and the right does not, then it
113028
+** might be more efficient to compute the right operand first.
113029
+*/
113030
+static int exprEvalRhsFirst(Expr *pExpr){
113031
+ if( ExprHasProperty(pExpr->pLeft, EP_Subquery)
113032
+ && !ExprHasProperty(pExpr->pRight, EP_Subquery)
113033
+ ){
113034
+ return 1;
113035
+ }else{
113036
+ return 0;
113037
+ }
113038
+}
113039
+
113040
+/*
113041
+** Compute the two operands of a binary operator.
113042
+**
113043
+** If either operand contains a subquery, then the code strives to
113044
+** compute the operand containing the subquery second. If the other
113045
+** operand evalutes to NULL, then a jump is made. The address of the
113046
+** IsNull operand that does this jump is returned. The caller can use
113047
+** this to optimize the computation so as to avoid doing the potentially
113048
+** expensive subquery.
113049
+**
113050
+** If no optimization opportunities exist, return 0.
113051
+*/
113052
+static int exprComputeOperands(
113053
+ Parse *pParse, /* Parsing context */
113054
+ Expr *pExpr, /* The comparison expression */
113055
+ int *pR1, /* OUT: Register holding the left operand */
113056
+ int *pR2, /* OUT: Register holding the right operand */
113057
+ int *pFree1, /* OUT: Temp register to free if not zero */
113058
+ int *pFree2 /* OUT: Another temp register to free if not zero */
113059
+){
113060
+ int addrIsNull;
113061
+ int r1, r2;
113062
+ Vdbe *v = pParse->pVdbe;
113063
+
113064
+ assert( v!=0 );
113065
+ /*
113066
+ ** If the left operand contains a (possibly expensive) subquery and the
113067
+ ** right operand does not and the right operation might be NULL,
113068
+ ** then compute the right operand first and do an IsNull jump if the
113069
+ ** right operand evalutes to NULL.
113070
+ */
113071
+ if( exprEvalRhsFirst(pExpr) && sqlite3ExprCanBeNull(pExpr->pRight) ){
113072
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, pFree2);
113073
+ addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, r2);
113074
+ VdbeComment((v, "skip left operand"));
113075
+ VdbeCoverage(v);
113076
+ }else{
113077
+ r2 = 0; /* Silence a false-positive uninit-var warning in MSVC */
113078
+ addrIsNull = 0;
113079
+ }
113080
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pFree1);
113081
+ if( addrIsNull==0 ){
113082
+ /*
113083
+ ** If the right operand contains a subquery and the left operand does not
113084
+ ** and the left operand might be NULL, then check the left operand do
113085
+ ** an IsNull check on the left operand before computing the right
113086
+ ** operand.
113087
+ */
113088
+ if( ExprHasProperty(pExpr->pRight, EP_Subquery)
113089
+ && sqlite3ExprCanBeNull(pExpr->pLeft)
113090
+ ){
113091
+ addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, r1);
113092
+ VdbeComment((v, "skip right operand"));
113093
+ VdbeCoverage(v);
113094
+ }
113095
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, pFree2);
113096
+ }
113097
+ *pR1 = r1;
113098
+ *pR2 = r2;
113099
+ return addrIsNull;
113100
+}
112785113101
112786113102
/*
112787113103
** pExpr is a TK_FUNCTION node. Try to determine whether or not the
112788113104
** function is a constant function. A function is constant if all of
112789113105
** the following are true:
@@ -114225,21 +114541,27 @@
114225114541
dest.eDest = SRT_Exists;
114226114542
sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
114227114543
VdbeComment((v, "Init EXISTS result"));
114228114544
}
114229114545
if( pSel->pLimit ){
114230
- /* The subquery already has a limit. If the pre-existing limit is X
114231
- ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
114232
- sqlite3 *db = pParse->db;
114233
- pLimit = sqlite3Expr(db, TK_INTEGER, "0");
114234
- if( pLimit ){
114235
- pLimit->affExpr = SQLITE_AFF_NUMERIC;
114236
- pLimit = sqlite3PExpr(pParse, TK_NE,
114237
- sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
114238
- }
114239
- sqlite3ExprDeferredDelete(pParse, pSel->pLimit->pLeft);
114240
- pSel->pLimit->pLeft = pLimit;
114546
+ /* The subquery already has a limit. If the pre-existing limit X is
114547
+ ** not already integer value 1 or 0, then make the new limit X<>0 so that
114548
+ ** the new limit is either 1 or 0 */
114549
+ Expr *pLeft = pSel->pLimit->pLeft;
114550
+ if( ExprHasProperty(pLeft, EP_IntValue)==0
114551
+ || (pLeft->u.iValue!=1 && pLeft->u.iValue!=0)
114552
+ ){
114553
+ sqlite3 *db = pParse->db;
114554
+ pLimit = sqlite3Expr(db, TK_INTEGER, "0");
114555
+ if( pLimit ){
114556
+ pLimit->affExpr = SQLITE_AFF_NUMERIC;
114557
+ pLimit = sqlite3PExpr(pParse, TK_NE,
114558
+ sqlite3ExprDup(db, pLeft, 0), pLimit);
114559
+ }
114560
+ sqlite3ExprDeferredDelete(pParse, pLeft);
114561
+ pSel->pLimit->pLeft = pLimit;
114562
+ }
114241114563
}else{
114242114564
/* If there is no pre-existing limit add a limit of 1 */
114243114565
pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
114244114566
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
114245114567
}
@@ -114677,11 +114999,16 @@
114677114999
iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114678115000
}else{
114679115001
iAddr = 0;
114680115002
}
114681115003
sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
114682
- if( pCol->affinity>=SQLITE_AFF_TEXT ){
115004
+ if( (pCol->colFlags & COLFLAG_VIRTUAL)!=0
115005
+ && (pTab->tabFlags & TF_Strict)!=0
115006
+ ){
115007
+ int p3 = 2+(int)(pCol - pTab->aCol);
115008
+ sqlite3VdbeAddOp4(v, OP_TypeCheck, regOut, 1, p3, (char*)pTab, P4_TABLE);
115009
+ }else if( pCol->affinity>=SQLITE_AFF_TEXT ){
114683115010
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114684115011
}
114685115012
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
114686115013
if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
114687115014
}
@@ -115364,15 +115691,21 @@
115364115691
case TK_GT:
115365115692
case TK_GE:
115366115693
case TK_NE:
115367115694
case TK_EQ: {
115368115695
Expr *pLeft = pExpr->pLeft;
115696
+ int addrIsNull = 0;
115369115697
if( sqlite3ExprIsVector(pLeft) ){
115370115698
codeVectorCompare(pParse, pExpr, target, op, p5);
115371115699
}else{
115372
- r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
115373
- r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
115700
+ if( ExprHasProperty(pExpr, EP_Subquery) && p5!=SQLITE_NULLEQ ){
115701
+ addrIsNull = exprComputeOperands(pParse, pExpr,
115702
+ &r1, &r2, &regFree1, &regFree2);
115703
+ }else{
115704
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
115705
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
115706
+ }
115374115707
sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
115375115708
codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
115376115709
sqlite3VdbeCurrentAddr(v)+2, p5,
115377115710
ExprHasProperty(pExpr,EP_Commuted));
115378115711
assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
@@ -115383,13 +115716,19 @@
115383115716
assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
115384115717
if( p5==SQLITE_NULLEQ ){
115385115718
sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
115386115719
}else{
115387115720
sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2);
115721
+ if( addrIsNull ){
115722
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
115723
+ sqlite3VdbeJumpHere(v, addrIsNull);
115724
+ sqlite3VdbeAddOp2(v, OP_Null, 0, inReg);
115725
+ }
115388115726
}
115389115727
testcase( regFree1==0 );
115390115728
testcase( regFree2==0 );
115729
+
115391115730
}
115392115731
break;
115393115732
}
115394115733
case TK_AND:
115395115734
case TK_OR:
@@ -115401,10 +115740,11 @@
115401115740
case TK_BITOR:
115402115741
case TK_SLASH:
115403115742
case TK_LSHIFT:
115404115743
case TK_RSHIFT:
115405115744
case TK_CONCAT: {
115745
+ int addrIsNull;
115406115746
assert( TK_AND==OP_And ); testcase( op==TK_AND );
115407115747
assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115408115748
assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
115409115749
assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
115410115750
assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
@@ -115412,15 +115752,27 @@
115412115752
assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
115413115753
assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
115414115754
assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
115415115755
assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
115416115756
assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
115417
- r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
115418
- r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
115757
+ if( ExprHasProperty(pExpr, EP_Subquery) ){
115758
+ addrIsNull = exprComputeOperands(pParse, pExpr,
115759
+ &r1, &r2, &regFree1, &regFree2);
115760
+ }else{
115761
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
115762
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
115763
+ addrIsNull = 0;
115764
+ }
115419115765
sqlite3VdbeAddOp3(v, op, r2, r1, target);
115420115766
testcase( regFree1==0 );
115421115767
testcase( regFree2==0 );
115768
+ if( addrIsNull ){
115769
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
115770
+ sqlite3VdbeJumpHere(v, addrIsNull);
115771
+ sqlite3VdbeAddOp2(v, OP_Null, 0, target);
115772
+ VdbeComment((v, "short-circut value"));
115773
+ }
115422115774
break;
115423115775
}
115424115776
case TK_UMINUS: {
115425115777
Expr *pLeft = pExpr->pLeft;
115426115778
assert( pLeft );
@@ -116265,21 +116617,31 @@
116265116617
case TK_AND:
116266116618
case TK_OR: {
116267116619
Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116268116620
if( pAlt!=pExpr ){
116269116621
sqlite3ExprIfTrue(pParse, pAlt, dest, jumpIfNull);
116270
- }else if( op==TK_AND ){
116271
- int d2 = sqlite3VdbeMakeLabel(pParse);
116272
- testcase( jumpIfNull==0 );
116273
- sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,
116274
- jumpIfNull^SQLITE_JUMPIFNULL);
116275
- sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
116276
- sqlite3VdbeResolveLabel(v, d2);
116277116622
}else{
116278
- testcase( jumpIfNull==0 );
116279
- sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
116280
- sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
116623
+ Expr *pFirst, *pSecond;
116624
+ if( exprEvalRhsFirst(pExpr) ){
116625
+ pFirst = pExpr->pRight;
116626
+ pSecond = pExpr->pLeft;
116627
+ }else{
116628
+ pFirst = pExpr->pLeft;
116629
+ pSecond = pExpr->pRight;
116630
+ }
116631
+ if( op==TK_AND ){
116632
+ int d2 = sqlite3VdbeMakeLabel(pParse);
116633
+ testcase( jumpIfNull==0 );
116634
+ sqlite3ExprIfFalse(pParse, pFirst, d2,
116635
+ jumpIfNull^SQLITE_JUMPIFNULL);
116636
+ sqlite3ExprIfTrue(pParse, pSecond, dest, jumpIfNull);
116637
+ sqlite3VdbeResolveLabel(v, d2);
116638
+ }else{
116639
+ testcase( jumpIfNull==0 );
116640
+ sqlite3ExprIfTrue(pParse, pFirst, dest, jumpIfNull);
116641
+ sqlite3ExprIfTrue(pParse, pSecond, dest, jumpIfNull);
116642
+ }
116281116643
}
116282116644
break;
116283116645
}
116284116646
case TK_NOT: {
116285116647
testcase( jumpIfNull==0 );
@@ -116314,14 +116676,20 @@
116314116676
case TK_LE:
116315116677
case TK_GT:
116316116678
case TK_GE:
116317116679
case TK_NE:
116318116680
case TK_EQ: {
116681
+ int addrIsNull;
116319116682
if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
116320
- testcase( jumpIfNull==0 );
116321
- r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116322
- r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
116683
+ if( ExprHasProperty(pExpr, EP_Subquery) && jumpIfNull!=SQLITE_NULLEQ ){
116684
+ addrIsNull = exprComputeOperands(pParse, pExpr,
116685
+ &r1, &r2, &regFree1, &regFree2);
116686
+ }else{
116687
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116688
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
116689
+ addrIsNull = 0;
116690
+ }
116323116691
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116324116692
r1, r2, dest, jumpIfNull, ExprHasProperty(pExpr,EP_Commuted));
116325116693
assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116326116694
assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116327116695
assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116332,22 +116700,29 @@
116332116700
assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116333116701
VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116334116702
VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116335116703
testcase( regFree1==0 );
116336116704
testcase( regFree2==0 );
116705
+ if( addrIsNull ){
116706
+ if( jumpIfNull ){
116707
+ sqlite3VdbeChangeP2(v, addrIsNull, dest);
116708
+ }else{
116709
+ sqlite3VdbeJumpHere(v, addrIsNull);
116710
+ }
116711
+ }
116337116712
break;
116338116713
}
116339116714
case TK_ISNULL:
116340116715
case TK_NOTNULL: {
116341116716
assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
116342116717
assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
116343116718
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116344
- sqlite3VdbeTypeofColumn(v, r1);
116719
+ assert( regFree1==0 || regFree1==r1 );
116720
+ if( regFree1 ) sqlite3VdbeTypeofColumn(v, r1);
116345116721
sqlite3VdbeAddOp2(v, op, r1, dest);
116346116722
VdbeCoverageIf(v, op==TK_ISNULL);
116347116723
VdbeCoverageIf(v, op==TK_NOTNULL);
116348
- testcase( regFree1==0 );
116349116724
break;
116350116725
}
116351116726
case TK_BETWEEN: {
116352116727
testcase( jumpIfNull==0 );
116353116728
exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
@@ -116439,21 +116814,31 @@
116439116814
case TK_AND:
116440116815
case TK_OR: {
116441116816
Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116442116817
if( pAlt!=pExpr ){
116443116818
sqlite3ExprIfFalse(pParse, pAlt, dest, jumpIfNull);
116444
- }else if( pExpr->op==TK_AND ){
116445
- testcase( jumpIfNull==0 );
116446
- sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
116447
- sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
116448116819
}else{
116449
- int d2 = sqlite3VdbeMakeLabel(pParse);
116450
- testcase( jumpIfNull==0 );
116451
- sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2,
116452
- jumpIfNull^SQLITE_JUMPIFNULL);
116453
- sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
116454
- sqlite3VdbeResolveLabel(v, d2);
116820
+ Expr *pFirst, *pSecond;
116821
+ if( exprEvalRhsFirst(pExpr) ){
116822
+ pFirst = pExpr->pRight;
116823
+ pSecond = pExpr->pLeft;
116824
+ }else{
116825
+ pFirst = pExpr->pLeft;
116826
+ pSecond = pExpr->pRight;
116827
+ }
116828
+ if( pExpr->op==TK_AND ){
116829
+ testcase( jumpIfNull==0 );
116830
+ sqlite3ExprIfFalse(pParse, pFirst, dest, jumpIfNull);
116831
+ sqlite3ExprIfFalse(pParse, pSecond, dest, jumpIfNull);
116832
+ }else{
116833
+ int d2 = sqlite3VdbeMakeLabel(pParse);
116834
+ testcase( jumpIfNull==0 );
116835
+ sqlite3ExprIfTrue(pParse, pFirst, d2,
116836
+ jumpIfNull^SQLITE_JUMPIFNULL);
116837
+ sqlite3ExprIfFalse(pParse, pSecond, dest, jumpIfNull);
116838
+ sqlite3VdbeResolveLabel(v, d2);
116839
+ }
116455116840
}
116456116841
break;
116457116842
}
116458116843
case TK_NOT: {
116459116844
testcase( jumpIfNull==0 );
@@ -116491,14 +116876,20 @@
116491116876
case TK_LE:
116492116877
case TK_GT:
116493116878
case TK_GE:
116494116879
case TK_NE:
116495116880
case TK_EQ: {
116881
+ int addrIsNull;
116496116882
if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
116497
- testcase( jumpIfNull==0 );
116498
- r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116499
- r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
116883
+ if( ExprHasProperty(pExpr, EP_Subquery) && jumpIfNull!=SQLITE_NULLEQ ){
116884
+ addrIsNull = exprComputeOperands(pParse, pExpr,
116885
+ &r1, &r2, &regFree1, &regFree2);
116886
+ }else{
116887
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116888
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
116889
+ addrIsNull = 0;
116890
+ }
116500116891
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116501116892
r1, r2, dest, jumpIfNull,ExprHasProperty(pExpr,EP_Commuted));
116502116893
assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116503116894
assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116504116895
assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116509,20 +116900,27 @@
116509116900
assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116510116901
VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116511116902
VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116512116903
testcase( regFree1==0 );
116513116904
testcase( regFree2==0 );
116905
+ if( addrIsNull ){
116906
+ if( jumpIfNull ){
116907
+ sqlite3VdbeChangeP2(v, addrIsNull, dest);
116908
+ }else{
116909
+ sqlite3VdbeJumpHere(v, addrIsNull);
116910
+ }
116911
+ }
116514116912
break;
116515116913
}
116516116914
case TK_ISNULL:
116517116915
case TK_NOTNULL: {
116518116916
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116519
- sqlite3VdbeTypeofColumn(v, r1);
116917
+ assert( regFree1==0 || regFree1==r1 );
116918
+ if( regFree1 ) sqlite3VdbeTypeofColumn(v, r1);
116520116919
sqlite3VdbeAddOp2(v, op, r1, dest);
116521116920
testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
116522116921
testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
116523
- testcase( regFree1==0 );
116524116922
break;
116525116923
}
116526116924
case TK_BETWEEN: {
116527116925
testcase( jumpIfNull==0 );
116528116926
exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfFalse, jumpIfNull);
@@ -117418,11 +117816,13 @@
117418117816
AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
117419117817
Expr *pExpr /* Expr describing the column to find or insert */
117420117818
){
117421117819
struct AggInfo_col *pCol;
117422117820
int k;
117821
+ int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
117423117822
117823
+ assert( mxTerm <= SMXV(i16) );
117424117824
assert( pAggInfo->iFirstReg==0 );
117425117825
pCol = pAggInfo->aCol;
117426117826
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
117427117827
if( pCol->pCExpr==pExpr ) return;
117428117828
if( pCol->iTable==pExpr->iTable
@@ -117435,10 +117835,14 @@
117435117835
k = addAggInfoColumn(pParse->db, pAggInfo);
117436117836
if( k<0 ){
117437117837
/* OOM on resize */
117438117838
assert( pParse->db->mallocFailed );
117439117839
return;
117840
+ }
117841
+ if( k>mxTerm ){
117842
+ sqlite3ErrorMsg(pParse, "more than %d aggregate terms", mxTerm);
117843
+ k = mxTerm;
117440117844
}
117441117845
pCol = &pAggInfo->aCol[k];
117442117846
assert( ExprUseYTab(pExpr) );
117443117847
pCol->pTab = pExpr->y.pTab;
117444117848
pCol->iTable = pExpr->iTable;
@@ -117469,10 +117873,11 @@
117469117873
assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
117470117874
pExpr->pAggInfo = pAggInfo;
117471117875
if( pExpr->op==TK_COLUMN ){
117472117876
pExpr->op = TK_AGG_COLUMN;
117473117877
}
117878
+ assert( k <= SMXV(pExpr->iAgg) );
117474117879
pExpr->iAgg = (i16)k;
117475117880
}
117476117881
117477117882
/*
117478117883
** This is the xExprCallback for a tree walker. It is used to
@@ -117553,17 +117958,23 @@
117553117958
){
117554117959
/* Check to see if pExpr is a duplicate of another aggregate
117555117960
** function that is already in the pAggInfo structure
117556117961
*/
117557117962
struct AggInfo_func *pItem = pAggInfo->aFunc;
117963
+ int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
117964
+ assert( mxTerm <= SMXV(i16) );
117558117965
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
117559117966
if( NEVER(pItem->pFExpr==pExpr) ) break;
117560117967
if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
117561117968
break;
117562117969
}
117563117970
}
117564
- if( i>=pAggInfo->nFunc ){
117971
+ if( i>mxTerm ){
117972
+ sqlite3ErrorMsg(pParse, "more than %d aggregate terms", mxTerm);
117973
+ i = mxTerm;
117974
+ assert( i<pAggInfo->nFunc );
117975
+ }else if( i>=pAggInfo->nFunc ){
117565117976
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
117566117977
*/
117567117978
u8 enc = ENC(pParse->db);
117568117979
i = addAggInfoFunc(pParse->db, pAggInfo);
117569117980
if( i>=0 ){
@@ -117613,10 +118024,11 @@
117613118024
}
117614118025
/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
117615118026
*/
117616118027
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
117617118028
ExprSetVVAProperty(pExpr, EP_NoReduce);
118029
+ assert( i <= SMXV(pExpr->iAgg) );
117618118030
pExpr->iAgg = (i16)i;
117619118031
pExpr->pAggInfo = pAggInfo;
117620118032
return WRC_Prune;
117621118033
}else{
117622118034
return WRC_Continue;
@@ -119015,14 +119427,14 @@
119015119427
}else{
119016119428
nQuot = sqlite3Strlen30(zQuot)-1;
119017119429
}
119018119430
119019119431
assert( nQuot>=nNew && nSql>=0 && nNew>=0 );
119020
- zOut = sqlite3DbMallocZero(db, (u64)(nSql + pRename->nList*nQuot + 1));
119432
+ zOut = sqlite3DbMallocZero(db, (u64)nSql + pRename->nList*(u64)nQuot + 1);
119021119433
}else{
119022119434
assert( nSql>0 );
119023
- zOut = (char*)sqlite3DbMallocZero(db, (u64)(nSql*2+1) * 3);
119435
+ zOut = (char*)sqlite3DbMallocZero(db, (2*(u64)nSql + 1) * 3);
119024119436
if( zOut ){
119025119437
zBuf1 = &zOut[nSql*2+1];
119026119438
zBuf2 = &zOut[nSql*4+2];
119027119439
}
119028119440
}
@@ -121700,20 +122112,10 @@
121700122112
}
121701122113
#endif
121702122114
while( z[0]!=0 && z[0]!=' ' ) z++;
121703122115
while( z[0]==' ' ) z++;
121704122116
}
121705
-
121706
- /* Set the bLowQual flag if the peak number of rows obtained
121707
- ** from a full equality match is so large that a full table scan
121708
- ** seems likely to be faster than using the index.
121709
- */
121710
- if( aLog[0] > 66 /* Index has more than 100 rows */
121711
- && aLog[0] <= aLog[nOut-1] /* And only a single value seen */
121712
- ){
121713
- pIndex->bLowQual = 1;
121714
- }
121715122117
}
121716122118
}
121717122119
121718122120
/*
121719122121
** This callback is invoked once for each index when reading the
@@ -127256,11 +127658,10 @@
127256127658
}else{
127257127659
j = pCExpr->iColumn;
127258127660
assert( j<=0x7fff );
127259127661
if( j<0 ){
127260127662
j = pTab->iPKey;
127261
- pIndex->bIdxRowid = 1;
127262127663
}else{
127263127664
if( pTab->aCol[j].notNull==0 ){
127264127665
pIndex->uniqNotNull = 0;
127265127666
}
127266127667
if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -128175,20 +128576,26 @@
128175128576
** Append the contents of SrcList p2 to SrcList p1 and return the resulting
128176128577
** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
128177128578
** are deleted by this function.
128178128579
*/
128179128580
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
128180
- assert( p1 && p1->nSrc==1 );
128581
+ assert( p1 );
128582
+ assert( p2 || pParse->nErr );
128583
+ assert( p2==0 || p2->nSrc>=1 );
128584
+ testcase( p1->nSrc==0 );
128181128585
if( p2 ){
128182
- SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, 1);
128586
+ int nOld = p1->nSrc;
128587
+ SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, nOld);
128183128588
if( pNew==0 ){
128184128589
sqlite3SrcListDelete(pParse->db, p2);
128185128590
}else{
128186128591
p1 = pNew;
128187
- memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
128592
+ memcpy(&p1->a[nOld], p2->a, p2->nSrc*sizeof(SrcItem));
128593
+ assert( nOld==1 || (p2->a[0].fg.jointype & JT_LTORJ)==0 );
128594
+ assert( p1->nSrc>=1 );
128595
+ p1->a[0].fg.jointype |= (JT_LTORJ & p2->a[0].fg.jointype);
128188128596
sqlite3DbFree(pParse->db, p2);
128189
- p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
128190128597
}
128191128598
}
128192128599
return p1;
128193128600
}
128194128601
@@ -132081,11 +132488,11 @@
132081132488
int argc,
132082132489
sqlite3_value **argv,
132083132490
int nSep,
132084132491
const char *zSep
132085132492
){
132086
- i64 j, k, n = 0;
132493
+ i64 j, n = 0;
132087132494
int i;
132088132495
char *z;
132089132496
for(i=0; i<argc; i++){
132090132497
n += sqlite3_value_bytes(argv[i]);
132091132498
}
@@ -132095,12 +132502,12 @@
132095132502
sqlite3_result_error_nomem(context);
132096132503
return;
132097132504
}
132098132505
j = 0;
132099132506
for(i=0; i<argc; i++){
132100
- k = sqlite3_value_bytes(argv[i]);
132101
- if( k>0 ){
132507
+ if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){
132508
+ int k = sqlite3_value_bytes(argv[i]);
132102132509
const char *v = (const char*)sqlite3_value_text(argv[i]);
132103132510
if( v!=0 ){
132104132511
if( j>0 && nSep>0 ){
132105132512
memcpy(&z[j], zSep, nSep);
132106132513
j += nSep;
@@ -135034,16 +135441,19 @@
135034135441
if( iReg==0 ){
135035135442
/* Move the previous opcode (which should be OP_MakeRecord) forward
135036135443
** by one slot and insert a new OP_TypeCheck where the current
135037135444
** OP_MakeRecord is found */
135038135445
VdbeOp *pPrev;
135446
+ int p3;
135039135447
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135040135448
pPrev = sqlite3VdbeGetLastOp(v);
135041135449
assert( pPrev!=0 );
135042135450
assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
135043135451
pPrev->opcode = OP_TypeCheck;
135044
- sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
135452
+ p3 = pPrev->p3;
135453
+ pPrev->p3 = 0;
135454
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, p3);
135045135455
}else{
135046135456
/* Insert an isolated OP_Typecheck */
135047135457
sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
135048135458
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135049135459
}
@@ -138772,10 +139182,12 @@
138772139182
/* Version 3.43.0 and later */
138773139183
int (*stmt_explain)(sqlite3_stmt*,int);
138774139184
/* Version 3.44.0 and later */
138775139185
void *(*get_clientdata)(sqlite3*,const char*);
138776139186
int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
139187
+ /* Version 3.50.0 and later */
139188
+ int (*setlk_timeout)(sqlite3*,int,int);
138777139189
};
138778139190
138779139191
/*
138780139192
** This is the function signature used for all extension entry points. It
138781139193
** is also defined in the file "loadext.c".
@@ -139105,10 +139517,12 @@
139105139517
/* Version 3.43.0 and later */
139106139518
#define sqlite3_stmt_explain sqlite3_api->stmt_explain
139107139519
/* Version 3.44.0 and later */
139108139520
#define sqlite3_get_clientdata sqlite3_api->get_clientdata
139109139521
#define sqlite3_set_clientdata sqlite3_api->set_clientdata
139522
+/* Version 3.50.0 and later */
139523
+#define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
139110139524
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139111139525
139112139526
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139113139527
/* This case when the file really is being compiled as a loadable
139114139528
** extension */
@@ -139626,11 +140040,13 @@
139626140040
sqlite3_is_interrupted,
139627140041
/* Version 3.43.0 and later */
139628140042
sqlite3_stmt_explain,
139629140043
/* Version 3.44.0 and later */
139630140044
sqlite3_get_clientdata,
139631
- sqlite3_set_clientdata
140045
+ sqlite3_set_clientdata,
140046
+ /* Version 3.50.0 and later */
140047
+ sqlite3_setlk_timeout
139632140048
};
139633140049
139634140050
/* True if x is the directory separator character
139635140051
*/
139636140052
#if SQLITE_OS_WIN
@@ -145252,11 +145668,11 @@
145252145668
SrcList *pSrc, /* Array of tables to search */
145253145669
int iStart, /* First member of pSrc->a[] to check */
145254145670
int iEnd, /* Last member of pSrc->a[] to check */
145255145671
const char *zCol, /* Name of the column we are looking for */
145256145672
int *piTab, /* Write index of pSrc->a[] here */
145257
- int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
145673
+ int *piCol, /* Write index of pSrc->a[*piTab].pSTab->aCol[] here */
145258145674
int bIgnoreHidden /* Ignore hidden columns */
145259145675
){
145260145676
int i; /* For looping over tables in pSrc */
145261145677
int iCol; /* Index of column matching zCol */
145262145678
@@ -145464,11 +145880,11 @@
145464145880
"not present in both tables", zName);
145465145881
return 1;
145466145882
}
145467145883
pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145468145884
sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145469
- if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
145885
+ if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145470145886
/* This branch runs if the query contains one or more RIGHT or FULL
145471145887
** JOINs. If only a single table on the left side of this join
145472145888
** contains the zName column, then this branch is a no-op.
145473145889
** But if there are two or more tables on the left side
145474145890
** of the join, construct a coalesce() function that gathers all
@@ -145480,10 +145896,12 @@
145480145896
** JOIN. But older versions of SQLite do not do that, so we avoid
145481145897
** adding a new error so as to not break legacy applications.
145482145898
*/
145483145899
ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145484145900
static const Token tkCoalesce = { "coalesce", 8 };
145901
+ assert( pE1!=0 );
145902
+ ExprSetProperty(pE1, EP_CanBeNull);
145485145903
while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145486145904
pRight->fg.isSynthUsing)!=0 ){
145487145905
if( pSrc->a[iLeft].fg.isUsing==0
145488145906
|| sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145489145907
){
@@ -145496,11 +145914,17 @@
145496145914
sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145497145915
}
145498145916
if( pFuncArgs ){
145499145917
pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145500145918
pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145919
+ if( pE1 ){
145920
+ pE1->affExpr = SQLITE_AFF_DEFER;
145921
+ }
145501145922
}
145923
+ }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145924
+ assert( pE1!=0 );
145925
+ ExprSetProperty(pE1, EP_CanBeNull);
145502145926
}
145503145927
pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145504145928
sqlite3SrcItemColumnUsed(pRight, iRightCol);
145505145929
pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145506145930
assert( pE2!=0 || pEq==0 );
@@ -146973,10 +147397,14 @@
146973147397
#else
146974147398
zType = columnType(&sNC, p, 0, 0, 0);
146975147399
#endif
146976147400
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
146977147401
}
147402
+#else
147403
+ UNUSED_PARAMETER(pParse);
147404
+ UNUSED_PARAMETER(pTabList);
147405
+ UNUSED_PARAMETER(pEList);
146978147406
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
146979147407
}
146980147408
146981147409
146982147410
/*
@@ -147892,11 +148320,13 @@
147892148320
int unionTab; /* Cursor number of the temp table holding result */
147893148321
u8 op = 0; /* One of the SRT_ operations to apply to self */
147894148322
int priorOp; /* The SRT_ operation to apply to prior selects */
147895148323
Expr *pLimit; /* Saved values of p->nLimit */
147896148324
int addr;
148325
+ int emptyBypass = 0; /* IfEmpty opcode to bypass RHS */
147897148326
SelectDest uniondest;
148327
+
147898148328
147899148329
testcase( p->op==TK_EXCEPT );
147900148330
testcase( p->op==TK_UNION );
147901148331
priorOp = SRT_Union;
147902148332
if( dest.eDest==priorOp ){
@@ -147931,10 +148361,12 @@
147931148361
147932148362
/* Code the current SELECT statement
147933148363
*/
147934148364
if( p->op==TK_EXCEPT ){
147935148365
op = SRT_Except;
148366
+ emptyBypass = sqlite3VdbeAddOp1(v, OP_IfEmpty, unionTab);
148367
+ VdbeCoverage(v);
147936148368
}else{
147937148369
assert( p->op==TK_UNION );
147938148370
op = SRT_Union;
147939148371
}
147940148372
p->pPrior = 0;
@@ -147951,10 +148383,11 @@
147951148383
p->pPrior = pPrior;
147952148384
p->pOrderBy = 0;
147953148385
if( p->op==TK_UNION ){
147954148386
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
147955148387
}
148388
+ if( emptyBypass ) sqlite3VdbeJumpHere(v, emptyBypass);
147956148389
sqlite3ExprDelete(db, p->pLimit);
147957148390
p->pLimit = pLimit;
147958148391
p->iLimit = 0;
147959148392
p->iOffset = 0;
147960148393
@@ -147981,13 +148414,14 @@
147981148414
}
147982148415
default: assert( p->op==TK_INTERSECT ); {
147983148416
int tab1, tab2;
147984148417
int iCont, iBreak, iStart;
147985148418
Expr *pLimit;
147986
- int addr;
148419
+ int addr, iLimit, iOffset;
147987148420
SelectDest intersectdest;
147988148421
int r1;
148422
+ int emptyBypass;
147989148423
147990148424
/* INTERSECT is different from the others since it requires
147991148425
** two temporary tables. Hence it has its own case. Begin
147992148426
** by allocating the tables we will need.
147993148427
*/
@@ -148008,18 +148442,32 @@
148008148442
rc = sqlite3Select(pParse, pPrior, &intersectdest);
148009148443
if( rc ){
148010148444
goto multi_select_end;
148011148445
}
148012148446
148447
+ /* Initialize LIMIT counters before checking to see if the LHS
148448
+ ** is empty, in case the jump is taken */
148449
+ iBreak = sqlite3VdbeMakeLabel(pParse);
148450
+ computeLimitRegisters(pParse, p, iBreak);
148451
+ emptyBypass = sqlite3VdbeAddOp1(v, OP_IfEmpty, tab1); VdbeCoverage(v);
148452
+
148013148453
/* Code the current SELECT into temporary table "tab2"
148014148454
*/
148015148455
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
148016148456
assert( p->addrOpenEphm[1] == -1 );
148017148457
p->addrOpenEphm[1] = addr;
148018
- p->pPrior = 0;
148458
+
148459
+ /* Disable prior SELECTs and the LIMIT counters during the computation
148460
+ ** of the RHS select */
148019148461
pLimit = p->pLimit;
148462
+ iLimit = p->iLimit;
148463
+ iOffset = p->iOffset;
148464
+ p->pPrior = 0;
148020148465
p->pLimit = 0;
148466
+ p->iLimit = 0;
148467
+ p->iOffset = 0;
148468
+
148021148469
intersectdest.iSDParm = tab2;
148022148470
ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
148023148471
sqlite3SelectOpName(p->op)));
148024148472
TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
148025148473
rc = sqlite3Select(pParse, p, &intersectdest);
@@ -148028,32 +148476,35 @@
148028148476
p->pPrior = pPrior;
148029148477
if( p->nSelectRow>pPrior->nSelectRow ){
148030148478
p->nSelectRow = pPrior->nSelectRow;
148031148479
}
148032148480
sqlite3ExprDelete(db, p->pLimit);
148481
+
148482
+ /* Reinstate the LIMIT counters prior to running the final intersect */
148033148483
p->pLimit = pLimit;
148484
+ p->iLimit = iLimit;
148485
+ p->iOffset = iOffset;
148034148486
148035148487
/* Generate code to take the intersection of the two temporary
148036148488
** tables.
148037148489
*/
148038148490
if( rc ) break;
148039148491
assert( p->pEList );
148040
- iBreak = sqlite3VdbeMakeLabel(pParse);
148041
- iCont = sqlite3VdbeMakeLabel(pParse);
148042
- computeLimitRegisters(pParse, p, iBreak);
148043
- sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
148492
+ sqlite3VdbeAddOp1(v, OP_Rewind, tab1);
148044148493
r1 = sqlite3GetTempReg(pParse);
148045148494
iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
148495
+ iCont = sqlite3VdbeMakeLabel(pParse);
148046148496
sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
148047148497
VdbeCoverage(v);
148048148498
sqlite3ReleaseTempReg(pParse, r1);
148049148499
selectInnerLoop(pParse, p, tab1,
148050148500
0, 0, &dest, iCont, iBreak);
148051148501
sqlite3VdbeResolveLabel(v, iCont);
148052148502
sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
148053148503
sqlite3VdbeResolveLabel(v, iBreak);
148054148504
sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
148505
+ sqlite3VdbeJumpHere(v, emptyBypass);
148055148506
sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
148056148507
break;
148057148508
}
148058148509
}
148059148510
@@ -148728,10 +149179,11 @@
148728149179
typedef struct SubstContext {
148729149180
Parse *pParse; /* The parsing context */
148730149181
int iTable; /* Replace references to this table */
148731149182
int iNewTable; /* New table number */
148732149183
int isOuterJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
149184
+ int nSelDepth; /* Depth of sub-query recursion. Top==1 */
148733149185
ExprList *pEList; /* Replacement expressions */
148734149186
ExprList *pCList; /* Collation sequences for replacement expr */
148735149187
} SubstContext;
148736149188
148737149189
/* Forward Declarations */
@@ -148834,10 +149286,13 @@
148834149286
}
148835149287
}
148836149288
}else{
148837149289
if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
148838149290
pExpr->iTable = pSubst->iNewTable;
149291
+ }
149292
+ if( pExpr->op==TK_AGG_FUNCTION && pExpr->op2>=pSubst->nSelDepth ){
149293
+ pExpr->op2--;
148839149294
}
148840149295
pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
148841149296
pExpr->pRight = substExpr(pSubst, pExpr->pRight);
148842149297
if( ExprUseXSelect(pExpr) ){
148843149298
substSelect(pSubst, pExpr->x.pSelect, 1);
@@ -148872,10 +149327,11 @@
148872149327
){
148873149328
SrcList *pSrc;
148874149329
SrcItem *pItem;
148875149330
int i;
148876149331
if( !p ) return;