Fossil SCM

Merge from trunk.

brickviking 2025-07-28 02:32 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;
149332
+ pSubst->nSelDepth++;
148877149333
do{
148878149334
substExprList(pSubst, p->pEList);
148879149335
substExprList(pSubst, p->pGroupBy);
148880149336
substExprList(pSubst, p->pOrderBy);
148881149337
p->pHaving = substExpr(pSubst, p->pHaving);
@@ -148889,10 +149345,11 @@
148889149345
if( pItem->fg.isTabFunc ){
148890149346
substExprList(pSubst, pItem->u1.pFuncArg);
148891149347
}
148892149348
}
148893149349
}while( doPrior && (p = p->pPrior)!=0 );
149350
+ pSubst->nSelDepth--;
148894149351
}
148895149352
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
148896149353
148897149354
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
148898149355
/*
@@ -149104,13 +149561,13 @@
149104149561
** other than the one FROM-clause subquery that is a candidate
149105149562
** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149106149563
** from 2015-02-09.)
149107149564
**
149108149565
** (3) If the subquery is the right operand of a LEFT JOIN then
149109
-** (3a) the subquery may not be a join and
149110
-** (3b) the FROM clause of the subquery may not contain a virtual
149111
-** table and
149566
+** (3a) the subquery may not be a join
149567
+** (**) Was (3b): "the FROM clause of the subquery may not contain
149568
+** a virtual table"
149112149569
** (**) Was: "The outer query may not have a GROUP BY." This case
149113149570
** is now managed correctly
149114149571
** (3d) the outer query may not be DISTINCT.
149115149572
** See also (26) for restrictions on RIGHT JOIN.
149116149573
**
@@ -149322,11 +149779,11 @@
149322149779
**
149323149780
** See also tickets #306, #350, and #3300.
149324149781
*/
149325149782
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149326149783
if( pSubSrc->nSrc>1 /* (3a) */
149327
- || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */
149784
+ /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149328149785
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
149329149786
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149330149787
){
149331149788
return 0;
149332149789
}
@@ -149500,11 +149957,11 @@
149500149957
/* Defer deleting the Table object associated with the
149501149958
** subquery until code generation is
149502149959
** complete, since there may still exist Expr.pTab entries that
149503149960
** refer to the subquery even after flattening. Ticket #3346.
149504149961
**
149505
- ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
149962
+ ** pSubitem->pSTab is always non-NULL by test restrictions and tests above.
149506149963
*/
149507149964
if( ALWAYS(pSubitem->pSTab!=0) ){
149508149965
Table *pTabToDel = pSubitem->pSTab;
149509149966
if( pTabToDel->nTabRef==1 ){
149510149967
Parse *pToplevel = sqlite3ParseToplevel(pParse);
@@ -149630,10 +150087,11 @@
149630150087
SubstContext x;
149631150088
x.pParse = pParse;
149632150089
x.iTable = iParent;
149633150090
x.iNewTable = iNewParent;
149634150091
x.isOuterJoin = isOuterJoin;
150092
+ x.nSelDepth = 0;
149635150093
x.pEList = pSub->pEList;
149636150094
x.pCList = findLeftmostExprlist(pSub);
149637150095
substSelect(&x, pParent, 0);
149638150096
}
149639150097
@@ -150215,10 +150673,11 @@
150215150673
unsetJoinExpr(pNew, -1, 1);
150216150674
x.pParse = pParse;
150217150675
x.iTable = pSrc->iCursor;
150218150676
x.iNewTable = pSrc->iCursor;
150219150677
x.isOuterJoin = 0;
150678
+ x.nSelDepth = 0;
150220150679
x.pEList = pSubq->pEList;
150221150680
x.pCList = findLeftmostExprlist(pSubq);
150222150681
pNew = substExpr(&x, pNew);
150223150682
#ifndef SQLITE_OMIT_WINDOWFUNC
150224150683
if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -150612,11 +151071,11 @@
150612151071
** a WITH clause on the stack currently maintained by the parser (on the
150613151072
** pParse->pWith linked list). And if currently processing a CTE
150614151073
** CTE expression, through routine checks to see if the reference is
150615151074
** a recursive reference to the CTE.
150616151075
**
150617
-** If pFrom matches a CTE according to either of these two above, pFrom->pTab
151076
+** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
150618151077
** and other fields are populated accordingly.
150619151078
**
150620151079
** Return 0 if no match is found.
150621151080
** Return 1 if a match is found.
150622151081
** Return 2 if an error condition is detected.
@@ -152238,10 +152697,87 @@
152238152697
pItem--;
152239152698
if( pItem->fg.isSubquery ) return 0; /* (1c-i) */
152240152699
}
152241152700
return 1;
152242152701
}
152702
+
152703
+/*
152704
+** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
152705
+** function attempts to transform expressions of the form:
152706
+**
152707
+** EXISTS (SELECT ...)
152708
+**
152709
+** into joins. For example, given
152710
+**
152711
+** CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
152712
+** CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
152713
+**
152714
+** SELECT name FROM sailors AS S WHERE EXISTS (
152715
+** SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
152716
+** );
152717
+**
152718
+** the SELECT statement may be transformed as follows:
152719
+**
152720
+** SELECT name FROM sailors AS S, reserves AS R
152721
+** WHERE S.sid = R.sid AND R.day = '2022-10-25';
152722
+**
152723
+** **Approximately**. Really, we have to ensure that the FROM-clause term
152724
+** that was formerly inside the EXISTS is only executed once. This is handled
152725
+** by setting the SrcItem.fg.fromExists flag, which then causes code in
152726
+** the where.c file to exit the corresponding loop after the first successful
152727
+** match (if any).
152728
+*/
152729
+static SQLITE_NOINLINE void existsToJoin(
152730
+ Parse *pParse, /* Parsing context */
152731
+ Select *p, /* The SELECT statement being optimized */
152732
+ Expr *pWhere /* part of the WHERE clause currently being examined */
152733
+){
152734
+ if( pParse->nErr==0
152735
+ && pWhere!=0
152736
+ && !ExprHasProperty(pWhere, EP_OuterON|EP_InnerON)
152737
+ && ALWAYS(p->pSrc!=0)
152738
+ && p->pSrc->nSrc<BMS
152739
+ ){
152740
+ if( pWhere->op==TK_AND ){
152741
+ Expr *pRight = pWhere->pRight;
152742
+ existsToJoin(pParse, p, pWhere->pLeft);
152743
+ existsToJoin(pParse, p, pRight);
152744
+ }
152745
+ else if( pWhere->op==TK_EXISTS ){
152746
+ Select *pSub = pWhere->x.pSelect;
152747
+ Expr *pSubWhere = pSub->pWhere;
152748
+ if( pSub->pSrc->nSrc==1
152749
+ && (pSub->selFlags & SF_Aggregate)==0
152750
+ && !pSub->pSrc->a[0].fg.isSubquery
152751
+ ){
152752
+ memset(pWhere, 0, sizeof(*pWhere));
152753
+ pWhere->op = TK_INTEGER;
152754
+ pWhere->u.iValue = 1;
152755
+ ExprSetProperty(pWhere, EP_IntValue);
152756
+
152757
+ assert( p->pWhere!=0 );
152758
+ pSub->pSrc->a[0].fg.fromExists = 1;
152759
+ pSub->pSrc->a[0].fg.jointype |= JT_CROSS;
152760
+ p->pSrc = sqlite3SrcListAppendList(pParse, p->pSrc, pSub->pSrc);
152761
+ if( pSubWhere ){
152762
+ p->pWhere = sqlite3PExpr(pParse, TK_AND, p->pWhere, pSubWhere);
152763
+ pSub->pWhere = 0;
152764
+ }
152765
+ pSub->pSrc = 0;
152766
+ sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pSub);
152767
+#if TREETRACE_ENABLED
152768
+ if( sqlite3TreeTrace & 0x100000 ){
152769
+ TREETRACE(0x100000,pParse,p,
152770
+ ("After EXISTS-to-JOIN optimization:\n"));
152771
+ sqlite3TreeViewSelect(0, p, 0);
152772
+ }
152773
+#endif
152774
+ existsToJoin(pParse, p, pSubWhere);
152775
+ }
152776
+ }
152777
+ }
152778
+}
152243152779
152244152780
/*
152245152781
** Generate byte-code for the SELECT statement given in the p argument.
152246152782
**
152247152783
** The results are returned according to the SelectDest structure.
@@ -152606,10 +153142,17 @@
152606153142
#endif
152607153143
if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
152608153144
return rc;
152609153145
}
152610153146
#endif
153147
+
153148
+ /* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
153149
+ ** to change it into a join. */
153150
+ if( pParse->bHasExists && OptimizationEnabled(db,SQLITE_ExistsToJoin) ){
153151
+ existsToJoin(pParse, p, p->pWhere);
153152
+ pTabList = p->pSrc;
153153
+ }
152611153154
152612153155
/* Do the WHERE-clause constant propagation optimization if this is
152613153156
** a join. No need to spend time on this operation for non-join queries
152614153157
** as the equivalent optimization will be handled by query planner in
152615153158
** sqlite3WhereBegin(). tag-select-0330
@@ -153366,10 +153909,14 @@
153366153909
}
153367153910
153368153911
if( iOrderByCol ){
153369153912
Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
153370153913
Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
153914
+ while( ALWAYS(pBase!=0) && pBase->op==TK_IF_NULL_ROW ){
153915
+ pX = pBase->pLeft;
153916
+ pBase = sqlite3ExprSkipCollateAndLikely(pX);
153917
+ }
153371153918
if( ALWAYS(pBase!=0)
153372153919
&& pBase->op!=TK_AGG_COLUMN
153373153920
&& pBase->op!=TK_REGISTER
153374153921
){
153375153922
sqlite3ExprToRegister(pX, iAMem+j);
@@ -153389,24 +153936,24 @@
153389153936
** over to a0,a1,a2. It then calls the output subroutine
153390153937
** and resets the aggregate accumulator registers in preparation
153391153938
** for the next GROUP BY batch.
153392153939
*/
153393153940
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153394
- VdbeComment((v, "output one row"));
153941
+ VdbeComment((v, "output one row of %d", p->selId));
153395153942
sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
153396153943
sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
153397153944
VdbeComment((v, "check abort flag"));
153398153945
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
153399
- VdbeComment((v, "reset accumulator"));
153946
+ VdbeComment((v, "reset accumulator %d", p->selId));
153400153947
153401153948
/* Update the aggregate accumulators based on the content of
153402153949
** the current row
153403153950
*/
153404153951
sqlite3VdbeJumpHere(v, addr1);
153405153952
updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
153406153953
sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
153407
- VdbeComment((v, "indicate data in accumulator"));
153954
+ VdbeComment((v, "indicate data in accumulator %d", p->selId));
153408153955
153409153956
/* End of the loop
153410153957
*/
153411153958
if( groupBySort ){
153412153959
sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx,addrTopOfLoop);
@@ -153419,11 +153966,11 @@
153419153966
sqlite3ExprListDelete(db, pDistinct);
153420153967
153421153968
/* Output the final row of result
153422153969
*/
153423153970
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153424
- VdbeComment((v, "output final row"));
153971
+ VdbeComment((v, "output final row of %d", p->selId));
153425153972
153426153973
/* Jump over the subroutines
153427153974
*/
153428153975
sqlite3VdbeGoto(v, addrEnd);
153429153976
@@ -153440,26 +153987,26 @@
153440153987
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153441153988
sqlite3VdbeResolveLabel(v, addrOutputRow);
153442153989
addrOutputRow = sqlite3VdbeCurrentAddr(v);
153443153990
sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
153444153991
VdbeCoverage(v);
153445
- VdbeComment((v, "Groupby result generator entry point"));
153992
+ VdbeComment((v, "Groupby result generator entry point %d", p->selId));
153446153993
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153447153994
finalizeAggFunctions(pParse, pAggInfo);
153448153995
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
153449153996
selectInnerLoop(pParse, p, -1, &sSort,
153450153997
&sDistinct, pDest,
153451153998
addrOutputRow+1, addrSetAbort);
153452153999
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153453
- VdbeComment((v, "end groupby result generator"));
154000
+ VdbeComment((v, "end groupby result generator %d", p->selId));
153454154001
153455154002
/* Generate a subroutine that will reset the group-by accumulator
153456154003
*/
153457154004
sqlite3VdbeResolveLabel(v, addrReset);
153458154005
resetAccumulator(pParse, pAggInfo);
153459154006
sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
153460
- VdbeComment((v, "indicate accumulator empty"));
154007
+ VdbeComment((v, "indicate accumulator %d empty", p->selId));
153461154008
sqlite3VdbeAddOp1(v, OP_Return, regReset);
153462154009
153463154010
if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
153464154011
struct AggInfo_func *pF = &pAggInfo->aFunc[0];
153465154012
fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
@@ -157343,11 +157890,12 @@
157343157890
saved_flags = db->flags;
157344157891
saved_mDbFlags = db->mDbFlags;
157345157892
saved_nChange = db->nChange;
157346157893
saved_nTotalChange = db->nTotalChange;
157347157894
saved_mTrace = db->mTrace;
157348
- db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments;
157895
+ db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments
157896
+ | SQLITE_AttachCreate | SQLITE_AttachWrite;
157349157897
db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157350157898
db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157351157899
| SQLITE_Defensive | SQLITE_CountRows);
157352157900
db->mTrace = 0;
157353157901
@@ -159046,10 +159594,11 @@
159046159594
struct WhereLevel {
159047159595
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
159048159596
int iTabCur; /* The VDBE cursor used to access the table */
159049159597
int iIdxCur; /* The VDBE cursor used to access pIdx */
159050159598
int addrBrk; /* Jump here to break out of the loop */
159599
+ int addrHalt; /* Abort the query due to empty table or similar */
159051159600
int addrNxt; /* Jump here to start the next IN combination */
159052159601
int addrSkip; /* Jump here for next iteration of skip-scan */
159053159602
int addrCont; /* Jump here to continue with the next loop cycle */
159054159603
int addrFirst; /* First instruction of interior of the loop */
159055159604
int addrBody; /* Beginning of the body of this loop */
@@ -159251,10 +159800,13 @@
159251159800
u16 eOperator; /* A WO_xx value describing <op> */
159252159801
u8 nChild; /* Number of children that must disable us */
159253159802
u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159254159803
int iParent; /* Disable pWC->a[iParent] when this term disabled */
159255159804
int leftCursor; /* Cursor number of X in "X <op> <expr>" */
159805
+#ifdef SQLITE_DEBUG
159806
+ int iTerm; /* Which WhereTerm is this, for debug purposes */
159807
+#endif
159256159808
union {
159257159809
struct {
159258159810
int leftColumn; /* Column number of X in "X <op> <expr>" */
159259159811
int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159260159812
} x; /* Opcode other than OP_OR or OP_AND */
@@ -159743,11 +160295,10 @@
159743160295
#if !defined(SQLITE_DEBUG)
159744160296
if( sqlite3ParseToplevel(pParse)->explain==2 || IS_STMT_SCANSTATUS(pParse->db) )
159745160297
#endif
159746160298
{
159747160299
VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe, addr);
159748
-
159749160300
SrcItem *pItem = &pTabList->a[pLevel->iFrom];
159750160301
sqlite3 *db = pParse->db; /* Database handle */
159751160302
int isSearch; /* True for a SEARCH. False for SCAN. */
159752160303
WhereLoop *pLoop; /* The controlling WhereLoop object */
159753160304
u32 flags; /* Flags that describe this loop */
@@ -159766,11 +160317,14 @@
159766160317
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
159767160318
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
159768160319
159769160320
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
159770160321
str.printfFlags = SQLITE_PRINTF_INTERNAL;
159771
- sqlite3_str_appendf(&str, "%s %S", isSearch ? "SEARCH" : "SCAN", pItem);
160322
+ sqlite3_str_appendf(&str, "%s %S%s",
160323
+ isSearch ? "SEARCH" : "SCAN",
160324
+ pItem,
160325
+ pItem->fg.fromExists ? " EXISTS" : "");
159772160326
if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
159773160327
const char *zFmt = 0;
159774160328
Index *pIdx;
159775160329
159776160330
assert( pLoop->u.btree.pIndex!=0 );
@@ -160215,11 +160769,13 @@
160215160769
for(i=iEq; i<pLoop->nLTerm; i++){
160216160770
if( pLoop->aLTerm[i]->pExpr==pX ){
160217160771
int iField;
160218160772
assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
160219160773
iField = pLoop->aLTerm[i]->u.x.iField - 1;
160220
- if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
160774
+ if( NEVER(pOrigRhs->a[iField].pExpr==0) ){
160775
+ continue; /* Duplicate PK column */
160776
+ }
160221160777
pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
160222160778
pOrigRhs->a[iField].pExpr = 0;
160223160779
if( pRhs ) pRhs->a[pRhs->nExpr-1].u.x.iOrderByCol = iField+1;
160224160780
if( pOrigLhs ){
160225160781
assert( pOrigLhs->a[iField].pExpr!=0 );
@@ -160312,35 +160868,26 @@
160312160868
if( pLoop->aLTerm[i] && pLoop->aLTerm[i]->pExpr==pX ){
160313160869
disableTerm(pLevel, pTerm);
160314160870
return;
160315160871
}
160316160872
}
160317
- for(i=iEq;i<pLoop->nLTerm; i++){
160873
+ for(i=iEq; i<pLoop->nLTerm; i++){
160318160874
assert( pLoop->aLTerm[i]!=0 );
160319160875
if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
160320160876
}
160321160877
160322160878
iTab = 0;
160323160879
if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
160324160880
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
160325160881
}else{
160326
- Expr *pExpr = pTerm->pExpr;
160327
- if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
160328
- sqlite3 *db = pParse->db;
160329
- pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
160330
- if( !db->mallocFailed ){
160331
- aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
160332
- eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
160333
- pExpr->iTable = iTab;
160334
- }
160335
- sqlite3ExprDelete(db, pX);
160336
- }else{
160337
- int n = sqlite3ExprVectorSize(pX->pLeft);
160338
- aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*MAX(nEq,n));
160339
- eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
160340
- }
160341
- pX = pExpr;
160882
+ sqlite3 *db = pParse->db;
160883
+ Expr *pXMod = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
160884
+ if( !db->mallocFailed ){
160885
+ aiMap = (int*)sqlite3DbMallocZero(db, sizeof(int)*nEq);
160886
+ eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
160887
+ }
160888
+ sqlite3ExprDelete(db, pXMod);
160342160889
}
160343160890
160344160891
if( eType==IN_INDEX_INDEX_DESC ){
160345160892
testcase( bRev );
160346160893
bRev = !bRev;
@@ -160366,11 +160913,11 @@
160366160913
sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
160367160914
pIn = pLevel->u.in.aInLoop;
160368160915
if( pIn ){
160369160916
int iMap = 0; /* Index in aiMap[] */
160370160917
pIn += i;
160371
- for(i=iEq;i<pLoop->nLTerm; i++){
160918
+ for(i=iEq; i<pLoop->nLTerm; i++){
160372160919
if( pLoop->aLTerm[i]->pExpr==pX ){
160373160920
int iOut = iTarget + i - iEq;
160374160921
if( eType==IN_INDEX_ROWID ){
160375160922
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
160376160923
}else{
@@ -161017,19 +161564,20 @@
161017161564
WhereInfo *pWInfo, /* Complete information about the WHERE clause */
161018161565
int iLevel, /* Which level of pWInfo->a[] should be coded */
161019161566
int addrNxt, /* Jump here to bypass inner loops */
161020161567
Bitmask notReady /* Loops that are not ready */
161021161568
){
161569
+ int saved_addrBrk;
161022161570
while( ++iLevel < pWInfo->nLevel ){
161023161571
WhereLevel *pLevel = &pWInfo->a[iLevel];
161024161572
WhereLoop *pLoop = pLevel->pWLoop;
161025161573
if( pLevel->regFilter==0 ) continue;
161026161574
if( pLevel->pWLoop->nSkip ) continue;
161027161575
/* ,--- Because sqlite3ConstructBloomFilter() has will not have set
161028161576
** vvvvv--' pLevel->regFilter if this were true. */
161029161577
if( NEVER(pLoop->prereq & notReady) ) continue;
161030
- assert( pLevel->addrBrk==0 );
161578
+ saved_addrBrk = pLevel->addrBrk;
161031161579
pLevel->addrBrk = addrNxt;
161032161580
if( pLoop->wsFlags & WHERE_IPK ){
161033161581
WhereTerm *pTerm = pLoop->aLTerm[0];
161034161582
int regRowid;
161035161583
assert( pTerm!=0 );
@@ -161055,11 +161603,11 @@
161055161603
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
161056161604
addrNxt, r1, nEq);
161057161605
VdbeCoverage(pParse->pVdbe);
161058161606
}
161059161607
pLevel->regFilter = 0;
161060
- pLevel->addrBrk = 0;
161608
+ pLevel->addrBrk = saved_addrBrk;
161061161609
}
161062161610
}
161063161611
161064161612
/*
161065161613
** Loop pLoop is a WHERE_INDEXED level that uses at least one IN(...)
@@ -161102,11 +161650,10 @@
161102161650
WhereClause *pWC; /* Decomposition of the entire WHERE clause */
161103161651
WhereTerm *pTerm; /* A WHERE clause term */
161104161652
sqlite3 *db; /* Database connection */
161105161653
SrcItem *pTabItem; /* FROM clause term being coded */
161106161654
int addrBrk; /* Jump here to break out of the loop */
161107
- int addrHalt; /* addrBrk for the outermost loop */
161108161655
int addrCont; /* Jump here to continue with next cycle */
161109161656
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
161110161657
int iReleaseReg = 0; /* Temp register to free before returning */
161111161658
Index *pIdx = 0; /* Index used by loop (if any) */
161112161659
int iLoop; /* Iteration of constraint generator loop */
@@ -161146,11 +161693,11 @@
161146161693
** When there is an IN operator, we also have a "addrNxt" label that
161147161694
** means to continue with the next IN value combination. When
161148161695
** there are no IN operators in the constraints, the "addrNxt" label
161149161696
** is the same as "addrBrk".
161150161697
*/
161151
- addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
161698
+ addrBrk = pLevel->addrNxt = pLevel->addrBrk;
161152161699
addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
161153161700
161154161701
/* If this is the right table of a LEFT OUTER JOIN, allocate and
161155161702
** initialize a memory cell that records if this table matches any
161156161703
** row of the left table of the join.
@@ -161162,18 +161709,10 @@
161162161709
pLevel->iLeftJoin = ++pParse->nMem;
161163161710
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
161164161711
VdbeComment((v, "init LEFT JOIN match flag"));
161165161712
}
161166161713
161167
- /* Compute a safe address to jump to if we discover that the table for
161168
- ** this loop is empty and can never contribute content. */
161169
- for(j=iLevel; j>0; j--){
161170
- if( pWInfo->a[j].iLeftJoin ) break;
161171
- if( pWInfo->a[j].pRJ ) break;
161172
- }
161173
- addrHalt = pWInfo->a[j].addrBrk;
161174
-
161175161714
/* Special case of a FROM clause subquery implemented as a co-routine */
161176161715
if( pTabItem->fg.viaCoroutine ){
161177161716
int regYield;
161178161717
Subquery *pSubq;
161179161718
assert( pTabItem->fg.isSubquery && pTabItem->u4.pSubq!=0 );
@@ -161408,11 +161947,11 @@
161408161947
VdbeCoverageIf(v, pX->op==TK_LE);
161409161948
VdbeCoverageIf(v, pX->op==TK_LT);
161410161949
VdbeCoverageIf(v, pX->op==TK_GE);
161411161950
sqlite3ReleaseTempReg(pParse, rTemp);
161412161951
}else{
161413
- sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt);
161952
+ sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, pLevel->addrHalt);
161414161953
VdbeCoverageIf(v, bRev==0);
161415161954
VdbeCoverageIf(v, bRev!=0);
161416161955
}
161417161956
if( pEnd ){
161418161957
Expr *pX;
@@ -161448,40 +161987,40 @@
161448161987
VdbeCoverageIf(v, testOp==OP_Ge);
161449161988
VdbeCoverageIf(v, testOp==OP_Gt);
161450161989
sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161451161990
}
161452161991
}else if( pLoop->wsFlags & WHERE_INDEXED ){
161453
- /* Case 4: A scan using an index.
161454
- **
161455
- ** The WHERE clause may contain zero or more equality
161456
- ** terms ("==" or "IN" operators) that refer to the N
161457
- ** left-most columns of the index. It may also contain
161458
- ** inequality constraints (>, <, >= or <=) on the indexed
161459
- ** column that immediately follows the N equalities. Only
161460
- ** the right-most column can be an inequality - the rest must
161461
- ** use the "==" and "IN" operators. For example, if the
161462
- ** index is on (x,y,z), then the following clauses are all
161463
- ** optimized:
161464
- **
161465
- ** x=5
161466
- ** x=5 AND y=10
161467
- ** x=5 AND y<10
161468
- ** x=5 AND y>5 AND y<10
161469
- ** x=5 AND y=5 AND z<=10
161470
- **
161471
- ** The z<10 term of the following cannot be used, only
161472
- ** the x=5 term:
161473
- **
161474
- ** x=5 AND z<10
161475
- **
161476
- ** N may be zero if there are inequality constraints.
161477
- ** If there are no inequality constraints, then N is at
161478
- ** least one.
161479
- **
161480
- ** This case is also used when there are no WHERE clause
161481
- ** constraints but an index is selected anyway, in order
161482
- ** to force the output order to conform to an ORDER BY.
161992
+ /* Case 4: Search using an index.
161993
+ **
161994
+ ** The WHERE clause may contain zero or more equality
161995
+ ** terms ("==" or "IN" or "IS" operators) that refer to the N
161996
+ ** left-most columns of the index. It may also contain
161997
+ ** inequality constraints (>, <, >= or <=) on the indexed
161998
+ ** column that immediately follows the N equalities. Only
161999
+ ** the right-most column can be an inequality - the rest must
162000
+ ** use the "==", "IN", or "IS" operators. For example, if the
162001
+ ** index is on (x,y,z), then the following clauses are all
162002
+ ** optimized:
162003
+ **
162004
+ ** x=5
162005
+ ** x=5 AND y=10
162006
+ ** x=5 AND y<10
162007
+ ** x=5 AND y>5 AND y<10
162008
+ ** x=5 AND y=5 AND z<=10
162009
+ **
162010
+ ** The z<10 term of the following cannot be used, only
162011
+ ** the x=5 term:
162012
+ **
162013
+ ** x=5 AND z<10
162014
+ **
162015
+ ** N may be zero if there are inequality constraints.
162016
+ ** If there are no inequality constraints, then N is at
162017
+ ** least one.
162018
+ **
162019
+ ** This case is also used when there are no WHERE clause
162020
+ ** constraints but an index is selected anyway, in order
162021
+ ** to force the output order to conform to an ORDER BY.
161483162022
*/
161484162023
static const u8 aStartOp[] = {
161485162024
0,
161486162025
0,
161487162026
OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -161818,16 +162357,17 @@
161818162357
}
161819162358
161820162359
if( pLevel->iLeftJoin==0 ){
161821162360
/* If a partial index is driving the loop, try to eliminate WHERE clause
161822162361
** terms from the query that must be true due to the WHERE clause of
161823
- ** the partial index.
162362
+ ** the partial index. This optimization does not work on an outer join,
162363
+ ** as shown by:
161824162364
**
161825
- ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
161826
- ** for a LEFT JOIN.
162365
+ ** 2019-11-02 ticket 623eff57e76d45f6 (LEFT JOIN)
162366
+ ** 2025-05-29 forum post 7dee41d32506c4ae (RIGHT JOIN)
161827162367
*/
161828
- if( pIdx->pPartIdxWhere ){
162368
+ if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161829162369
whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161830162370
}
161831162371
}else{
161832162372
testcase( pIdx->pPartIdxWhere );
161833162373
/* The following assert() is not a requirement, merely an observation:
@@ -162202,11 +162742,11 @@
162202162742
pLevel->op = OP_Noop;
162203162743
}else{
162204162744
codeCursorHint(pTabItem, pWInfo, pLevel, 0);
162205162745
pLevel->op = aStep[bRev];
162206162746
pLevel->p1 = iCur;
162207
- pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt);
162747
+ pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev],iCur,pLevel->addrHalt);
162208162748
VdbeCoverageIf(v, bRev==0);
162209162749
VdbeCoverageIf(v, bRev!=0);
162210162750
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
162211162751
}
162212162752
}
@@ -163496,34 +164036,46 @@
163496164036
** column references. This routine checks to see if pExpr is an equivalence
163497164037
** relation:
163498164038
** 1. The SQLITE_Transitive optimization must be enabled
163499164039
** 2. Must be either an == or an IS operator
163500164040
** 3. Not originating in the ON clause of an OUTER JOIN
163501
-** 4. The affinities of A and B must be compatible
163502
-** 5a. Both operands use the same collating sequence OR
163503
-** 5b. The overall collating sequence is BINARY
164041
+** 4. The operator is not IS or else the query does not contain RIGHT JOIN
164042
+** 5. The affinities of A and B must be compatible
164043
+** 6a. Both operands use the same collating sequence OR
164044
+** 6b. The overall collating sequence is BINARY
163504164045
** If this routine returns TRUE, that means that the RHS can be substituted
163505164046
** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
163506164047
** This is an optimization. No harm comes from returning 0. But if 1 is
163507164048
** returned when it should not be, then incorrect answers might result.
163508164049
*/
163509
-static int termIsEquivalence(Parse *pParse, Expr *pExpr){
164050
+static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
163510164051
char aff1, aff2;
163511164052
CollSeq *pColl;
163512
- if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
163513
- if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
163514
- if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
164053
+ if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
164054
+ if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
164055
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
164056
+ assert( pSrc!=0 );
164057
+ if( pExpr->op==TK_IS
164058
+ && pSrc->nSrc>=2
164059
+ && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
164060
+ ){
164061
+ return 0; /* (4) */
164062
+ }
163515164063
aff1 = sqlite3ExprAffinity(pExpr->pLeft);
163516164064
aff2 = sqlite3ExprAffinity(pExpr->pRight);
163517164065
if( aff1!=aff2
163518164066
&& (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
163519164067
){
163520
- return 0;
164068
+ return 0; /* (5) */
163521164069
}
163522164070
pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
163523
- if( sqlite3IsBinary(pColl) ) return 1;
163524
- return sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight);
164071
+ if( !sqlite3IsBinary(pColl)
164072
+ && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
164073
+ ){
164074
+ return 0; /* (6) */
164075
+ }
164076
+ return 1;
163525164077
}
163526164078
163527164079
/*
163528164080
** Recursively walk the expressions of a SELECT statement and generate
163529164081
** a bitmask indicating which tables are used in that expression
@@ -163677,10 +164229,13 @@
163677164229
if( db->mallocFailed ){
163678164230
return;
163679164231
}
163680164232
assert( pWC->nTerm > idxTerm );
163681164233
pTerm = &pWC->a[idxTerm];
164234
+#ifdef SQLITE_DEBUG
164235
+ pTerm->iTerm = idxTerm;
164236
+#endif
163682164237
pMaskSet = &pWInfo->sMaskSet;
163683164238
pExpr = pTerm->pExpr;
163684164239
assert( pExpr!=0 ); /* Because malloc() has not failed */
163685164240
assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
163686164241
pMaskSet->bVarSelect = 0;
@@ -163784,12 +164339,12 @@
163784164339
pNew = &pWC->a[idxNew];
163785164340
markTermAsChild(pWC, idxNew, idxTerm);
163786164341
if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
163787164342
pTerm = &pWC->a[idxTerm];
163788164343
pTerm->wtFlags |= TERM_COPIED;
163789
-
163790
- if( termIsEquivalence(pParse, pDup) ){
164344
+ assert( pWInfo->pTabList!=0 );
164345
+ if( termIsEquivalence(pParse, pDup, pWInfo->pTabList) ){
163791164346
pTerm->eOperator |= WO_EQUIV;
163792164347
eExtraOp = WO_EQUIV;
163793164348
}
163794164349
}else{
163795164350
pDup = pExpr;
@@ -164091,11 +164646,11 @@
164091164646
pNewExpr->w.iJoin = pExpr->w.iJoin;
164092164647
}
164093164648
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
164094164649
testcase( idxNew==0 );
164095164650
pNewTerm = &pWC->a[idxNew];
164096
- pNewTerm->prereqRight = prereqExpr;
164651
+ pNewTerm->prereqRight = prereqExpr | extraRight;
164097164652
pNewTerm->leftCursor = pLeft->iTable;
164098164653
pNewTerm->u.x.leftColumn = pLeft->iColumn;
164099164654
pNewTerm->eOperator = WO_AUX;
164100164655
pNewTerm->eMatchOp = eOp2;
164101164656
markTermAsChild(pWC, idxNew, idxTerm);
@@ -164202,11 +164757,11 @@
164202164757
** SELECT statement passed as the second argument. These terms are only
164203164758
** added if:
164204164759
**
164205164760
** 1. The SELECT statement has a LIMIT clause, and
164206164761
** 2. The SELECT statement is not an aggregate or DISTINCT query, and
164207
-** 3. The SELECT statement has exactly one object in its from clause, and
164762
+** 3. The SELECT statement has exactly one object in its FROM clause, and
164208164763
** that object is a virtual table, and
164209164764
** 4. There are no terms in the WHERE clause that will not be passed
164210164765
** to the virtual table xBestIndex method.
164211164766
** 5. The ORDER BY clause, if any, will be made available to the xBestIndex
164212164767
** method.
@@ -164239,12 +164794,26 @@
164239164794
** pWC->a[] array. So this term can be ignored, as a LIMIT clause
164240164795
** will only be added if each of the child terms passes the
164241164796
** (leftCursor==iCsr) test below. */
164242164797
continue;
164243164798
}
164244
- if( pWC->a[ii].leftCursor!=iCsr ) return;
164245
- if( pWC->a[ii].prereqRight!=0 ) return;
164799
+ if( pWC->a[ii].leftCursor==iCsr && pWC->a[ii].prereqRight==0 ) continue;
164800
+
164801
+ /* If this term has a parent with exactly one child, and the parent will
164802
+ ** be passed through to xBestIndex, then this term can be ignored. */
164803
+ if( pWC->a[ii].iParent>=0 ){
164804
+ WhereTerm *pParent = &pWC->a[ pWC->a[ii].iParent ];
164805
+ if( pParent->leftCursor==iCsr
164806
+ && pParent->prereqRight==0
164807
+ && pParent->nChild==1
164808
+ ){
164809
+ continue;
164810
+ }
164811
+ }
164812
+
164813
+ /* This term will not be passed through. Do not add a LIMIT clause. */
164814
+ return;
164246164815
}
164247164816
164248164817
/* Check condition (5). Return early if it is not met. */
164249164818
if( pOrderBy ){
164250164819
for(ii=0; ii<pOrderBy->nExpr; ii++){
@@ -164904,15 +165473,15 @@
164904165473
continue;
164905165474
}
164906165475
pScan->pWC = pWC;
164907165476
pScan->k = k+1;
164908165477
#ifdef WHERETRACE_ENABLED
164909
- if( sqlite3WhereTrace & 0x20000 ){
165478
+ if( (sqlite3WhereTrace & 0x20000)!=0 && pScan->nEquiv>1 ){
164910165479
int ii;
164911
- sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
164912
- pTerm, pScan->nEquiv);
164913
- for(ii=0; ii<pScan->nEquiv; ii++){
165480
+ sqlite3DebugPrintf("EQUIVALENT TO {%d:%d} (due to TERM-%d):",
165481
+ pScan->aiCur[0], pScan->aiColumn[0], pTerm->iTerm);
165482
+ for(ii=1; ii<pScan->nEquiv; ii++){
164914165483
sqlite3DebugPrintf(" {%d:%d}",
164915165484
pScan->aiCur[ii], pScan->aiColumn[ii]);
164916165485
}
164917165486
sqlite3DebugPrintf("\n");
164918165487
}
@@ -165679,11 +166248,13 @@
165679166248
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
165680166249
addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
165681166250
VdbeCoverage(v);
165682166251
VdbeComment((v, "next row of %s", pSrc->pSTab->zName));
165683166252
}else{
165684
- addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
166253
+ assert( pLevel->addrHalt );
166254
+ addrTop = sqlite3VdbeAddOp2(v, OP_Rewind,pLevel->iTabCur,pLevel->addrHalt);
166255
+ VdbeCoverage(v);
165685166256
}
165686166257
if( pPartial ){
165687166258
iContinue = sqlite3VdbeMakeLabel(pParse);
165688166259
sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
165689166260
pLoop->wsFlags |= WHERE_PARTIALIDX;
@@ -165707,15 +166278,18 @@
165707166278
assert( pLevel->iIdxCur>0 );
165708166279
translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
165709166280
pSrc->u4.pSubq->regResult, pLevel->iIdxCur);
165710166281
sqlite3VdbeGoto(v, addrTop);
165711166282
pSrc->fg.viaCoroutine = 0;
166283
+ sqlite3VdbeJumpHere(v, addrTop);
165712166284
}else{
165713166285
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
165714166286
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
166287
+ if( (pSrc->fg.jointype & JT_LEFT)!=0 ){
166288
+ sqlite3VdbeJumpHere(v, addrTop);
166289
+ }
165715166290
}
165716
- sqlite3VdbeJumpHere(v, addrTop);
165717166291
sqlite3ReleaseTempReg(pParse, regRecord);
165718166292
165719166293
/* Jump here when skipping the initialization */
165720166294
sqlite3VdbeJumpHere(v, addrInit);
165721166295
sqlite3VdbeScanStatusRange(v, addrExp, addrExp, -1);
@@ -166863,10 +167437,11 @@
166863167437
sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166864167438
pTerm->u.pOrInfo->indexable);
166865167439
}else{
166866167440
sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
166867167441
}
167442
+ iTerm = pTerm->iTerm = MAX(iTerm,pTerm->iTerm);
166868167443
sqlite3DebugPrintf(
166869167444
"TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
166870167445
iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
166871167446
/* The 0x10000 .wheretrace flag causes extra information to be
166872167447
** shown about each Term */
@@ -167637,15 +168212,12 @@
167637168212
opMask = WO_LT|WO_LE;
167638168213
}else{
167639168214
assert( pNew->u.btree.nBtm==0 );
167640168215
opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
167641168216
}
167642
- if( pProbe->bUnordered || pProbe->bLowQual ){
167643
- if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
167644
- if( pProbe->bLowQual && pSrc->fg.isIndexedBy==0 ){
167645
- opMask &= ~(WO_EQ|WO_IN|WO_IS);
167646
- }
168217
+ if( pProbe->bUnordered ){
168218
+ opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
167647168219
}
167648168220
167649168221
assert( pNew->u.btree.nEq<pProbe->nColumn );
167650168222
assert( pNew->u.btree.nEq<pProbe->nKeyCol
167651168223
|| pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY );
@@ -167714,19 +168286,33 @@
167714168286
if( eOp & WO_IN ){
167715168287
Expr *pExpr = pTerm->pExpr;
167716168288
if( ExprUseXSelect(pExpr) ){
167717168289
/* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
167718168290
int i;
168291
+ int bRedundant = 0;
167719168292
nIn = 46; assert( 46==sqlite3LogEst(25) );
167720168293
167721168294
/* The expression may actually be of the form (x, y) IN (SELECT...).
167722168295
** In this case there is a separate term for each of (x) and (y).
167723168296
** However, the nIn multiplier should only be applied once, not once
167724168297
** for each such term. The following loop checks that pTerm is the
167725168298
** first such term in use, and sets nIn back to 0 if it is not. */
167726168299
for(i=0; i<pNew->nLTerm-1; i++){
167727
- if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
168300
+ if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ){
168301
+ nIn = 0;
168302
+ if( pNew->aLTerm[i]->u.x.iField == pTerm->u.x.iField ){
168303
+ /* Detect when two or more columns of an index match the same
168304
+ ** column of a vector IN operater, and avoid adding the column
168305
+ ** to the WhereLoop more than once. See tag-20250707-01
168306
+ ** in test/rowvalue.test */
168307
+ bRedundant = 1;
168308
+ }
168309
+ }
168310
+ }
168311
+ if( bRedundant ){
168312
+ pNew->nLTerm--;
168313
+ continue;
167728168314
}
167729168315
}else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
167730168316
/* "x IN (value, value, ...)" */
167731168317
nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
167732168318
}
@@ -167954,11 +168540,11 @@
167954168540
}
167955168541
167956168542
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167957168543
&& pNew->u.btree.nEq<pProbe->nColumn
167958168544
&& (pNew->u.btree.nEq<pProbe->nKeyCol ||
167959
- (pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY && !pProbe->bIdxRowid))
168545
+ pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
167960168546
){
167961168547
if( pNew->u.btree.nEq>3 ){
167962168548
sqlite3ProgressCheck(pParse);
167963168549
}
167964168550
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -167993,10 +168579,11 @@
167993168579
&& saved_nEq==pNew->nLTerm
167994168580
&& pProbe->noSkipScan==0
167995168581
&& pProbe->hasStat1!=0
167996168582
&& OptimizationEnabled(db, SQLITE_SkipScan)
167997168583
&& pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
168584
+ && pSrc->fg.fromExists==0
167998168585
&& (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
167999168586
){
168000168587
LogEst nIter;
168001168588
pNew->u.btree.nEq++;
168002168589
pNew->nSkip++;
@@ -168083,10 +168670,11 @@
168083168670
Expr *pExpr;
168084168671
pExpr = pTerm->pExpr;
168085168672
if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
168086168673
&& ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
168087168674
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
168675
+ && !sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, -1)
168088168676
&& (pTerm->wtFlags & TERM_VNULL)==0
168089168677
){
168090168678
return 1;
168091168679
}
168092168680
}
@@ -168578,11 +169166,11 @@
168578169166
}
168579169167
}else if( m==0
168580169168
&& (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
168581169169
){
168582169170
WHERETRACE(0x200,
168583
- ("-> %s a covering index according to bitmasks\n",
169171
+ ("-> %s is a covering index according to bitmasks\n",
168584169172
pProbe->zName, m==0 ? "is" : "is not"));
168585169173
pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
168586169174
}
168587169175
}
168588169176
@@ -171549,10 +172137,18 @@
171549172137
171550172138
pTabItem = &pTabList->a[pLevel->iFrom];
171551172139
pTab = pTabItem->pSTab;
171552172140
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
171553172141
pLoop = pLevel->pWLoop;
172142
+ pLevel->addrBrk = sqlite3VdbeMakeLabel(pParse);
172143
+ if( ii==0 || (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
172144
+ pLevel->addrHalt = pLevel->addrBrk;
172145
+ }else if( pWInfo->a[ii-1].pRJ ){
172146
+ pLevel->addrHalt = pWInfo->a[ii-1].addrBrk;
172147
+ }else{
172148
+ pLevel->addrHalt = pWInfo->a[ii-1].addrHalt;
172149
+ }
171554172150
if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
171555172151
/* Do nothing */
171556172152
}else
171557172153
#ifndef SQLITE_OMIT_VIRTUALTABLE
171558172154
if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -171600,10 +172196,17 @@
171600172196
}
171601172197
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
171602172198
sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
171603172199
(const u8*)&pTabItem->colUsed, P4_INT64);
171604172200
#endif
172201
+ if( ii>=2
172202
+ && (pTabItem[0].fg.jointype & (JT_LTORJ|JT_LEFT))==0
172203
+ && pLevel->addrHalt==pWInfo->a[0].addrHalt
172204
+ ){
172205
+ sqlite3VdbeAddOp2(v, OP_IfEmpty, pTabItem->iCursor, pWInfo->iBreak);
172206
+ VdbeCoverage(v);
172207
+ }
171605172208
}else{
171606172209
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
171607172210
}
171608172211
if( pLoop->wsFlags & WHERE_INDEXED ){
171609172212
Index *pIx = pLoop->u.btree.pIndex;
@@ -171856,10 +172459,13 @@
171856172459
VdbeCoverageIf(v, op==OP_SeekLT);
171857172460
VdbeCoverageIf(v, op==OP_SeekGT);
171858172461
sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
171859172462
}
171860172463
#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
172464
+ if( pTabList->a[pLevel->iFrom].fg.fromExists ){
172465
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
172466
+ }
171861172467
/* The common case: Advance to the next row */
171862172468
if( pLevel->addrCont ) sqlite3VdbeResolveLabel(v, pLevel->addrCont);
171863172469
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
171864172470
sqlite3VdbeChangeP5(v, pLevel->p5);
171865172471
VdbeCoverage(v);
@@ -179928,16 +180534,25 @@
179928180534
/* Expressions of the form
179929180535
**
179930180536
** expr1 IN ()
179931180537
** expr1 NOT IN ()
179932180538
**
179933
- ** simplify to constants 0 (false) and 1 (true), respectively,
179934
- ** regardless of the value of expr1.
180539
+ ** simplify to constants 0 (false) and 1 (true), respectively.
180540
+ **
180541
+ ** Except, do not apply this optimization if expr1 contains a function
180542
+ ** because that function might be an aggregate (we don't know yet whether
180543
+ ** it is or not) and if it is an aggregate, that could change the meaning
180544
+ ** of the whole query.
179935180545
*/
179936
- sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy590);
179937
- yymsp[-4].minor.yy590 = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy502 ? "true" : "false");
179938
- if( yymsp[-4].minor.yy590 ) sqlite3ExprIdToTrueFalse(yymsp[-4].minor.yy590);
180546
+ Expr *pB = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy502 ? "true" : "false");
180547
+ if( pB ) sqlite3ExprIdToTrueFalse(pB);
180548
+ if( !ExprHasProperty(yymsp[-4].minor.yy590, EP_HasFunc) ){
180549
+ sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy590);
180550
+ yymsp[-4].minor.yy590 = pB;
180551
+ }else{
180552
+ yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, yymsp[-3].minor.yy502 ? TK_OR : TK_AND, pB, yymsp[-4].minor.yy590);
180553
+ }
179939180554
}else{
179940180555
Expr *pRHS = yymsp[-1].minor.yy402->a[0].pExpr;
179941180556
if( yymsp[-1].minor.yy402->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && yymsp[-4].minor.yy590->op!=TK_VECTOR ){
179942180557
yymsp[-1].minor.yy402->a[0].pExpr = 0;
179943180558
sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy402);
@@ -181539,11 +182154,11 @@
181539182154
static int getToken(const unsigned char **pz){
181540182155
const unsigned char *z = *pz;
181541182156
int t; /* Token type to return */
181542182157
do {
181543182158
z += sqlite3GetToken(z, &t);
181544
- }while( t==TK_SPACE );
182159
+ }while( t==TK_SPACE || t==TK_COMMENT );
181545182160
if( t==TK_ID
181546182161
|| t==TK_STRING
181547182162
|| t==TK_JOIN_KW
181548182163
|| t==TK_WINDOW
181549182164
|| t==TK_OVER
@@ -184489,10 +185104,11 @@
184489185104
#ifdef SQLITE_ENABLE_API_ARMOR
184490185105
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
184491185106
#endif
184492185107
if( ms<-1 ) return SQLITE_RANGE;
184493185108
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
185109
+ sqlite3_mutex_enter(db->mutex);
184494185110
db->setlkTimeout = ms;
184495185111
db->setlkFlags = flags;
184496185112
sqlite3BtreeEnterAll(db);
184497185113
for(iDb=0; iDb<db->nDb; iDb++){
184498185114
Btree *pBt = db->aDb[iDb].pBt;
@@ -184500,10 +185116,11 @@
184500185116
sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
184501185117
sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
184502185118
}
184503185119
}
184504185120
sqlite3BtreeLeaveAll(db);
185121
+ sqlite3_mutex_leave(db->mutex);
184505185122
#endif
184506185123
#if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
184507185124
UNUSED_PARAMETER(db);
184508185125
UNUSED_PARAMETER(flags);
184509185126
#endif
@@ -188886,11 +189503,11 @@
188886189503
188887189504
/*
188888189505
** Macros needed to provide flexible arrays in a portable way
188889189506
*/
188890189507
#ifndef offsetof
188891
-# define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
189508
+# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
188892189509
#endif
188893189510
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
188894189511
# define FLEXARRAY
188895189512
#else
188896189513
# define FLEXARRAY 1
@@ -209119,12 +209736,14 @@
209119209736
nExtra = 0;
209120209737
}else if( szType==12 ){
209121209738
nExtra = 1;
209122209739
}else if( szType==13 ){
209123209740
nExtra = 2;
209124
- }else{
209741
+ }else if( szType==14 ){
209125209742
nExtra = 4;
209743
+ }else{
209744
+ nExtra = 8;
209126209745
}
209127209746
if( szPayload<=11 ){
209128209747
nNeeded = 0;
209129209748
}else if( szPayload<=0xff ){
209130209749
nNeeded = 1;
@@ -209590,11 +210209,16 @@
209590210209
c = z[++j];
209591210210
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
209592210211
|| c=='n' || c=='r' || c=='t'
209593210212
|| (c=='u' && jsonIs4Hex(&z[j+1])) ){
209594210213
if( opcode==JSONB_TEXT ) opcode = JSONB_TEXTJ;
209595
- }else if( c=='\'' || c=='0' || c=='v' || c=='\n'
210214
+ }else if( c=='\'' || c=='v' || c=='\n'
210215
+#ifdef SQLITE_BUG_COMPATIBLE_20250510
210216
+ || (c=='0') /* Legacy bug compatible */
210217
+#else
210218
+ || (c=='0' && !sqlite3Isdigit(z[j+1])) /* Correct implementation */
210219
+#endif
209596210220
|| (0xe2==(u8)c && 0x80==(u8)z[j+1]
209597210221
&& (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
209598210222
|| (c=='x' && jsonIs2Hex(&z[j+1])) ){
209599210223
opcode = JSONB_TEXT5;
209600210224
pParse->hasNonstd = 1;
@@ -209977,11 +210601,11 @@
209977210601
|| pParse->aBlob[i+4]!=0
209978210602
){
209979210603
*pSz = 0;
209980210604
return 0;
209981210605
}
209982
- sz = (pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
210606
+ sz = ((u32)pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
209983210607
(pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
209984210608
n = 9;
209985210609
}
209986210610
if( (i64)i+sz+n > pParse->nBlob
209987210611
&& (i64)i+sz+n > pParse->nBlob-pParse->delta
@@ -210558,11 +211182,25 @@
210558211182
case 'f': { *piOut = '\f'; return 2; }
210559211183
case 'n': { *piOut = '\n'; return 2; }
210560211184
case 'r': { *piOut = '\r'; return 2; }
210561211185
case 't': { *piOut = '\t'; return 2; }
210562211186
case 'v': { *piOut = '\v'; return 2; }
210563
- case '0': { *piOut = 0; return 2; }
211187
+ case '0': {
211188
+ /* JSON5 requires that the \0 escape not be followed by a digit.
211189
+ ** But SQLite did not enforce this restriction in versions 3.42.0
211190
+ ** through 3.49.2. That was a bug. But some applications might have
211191
+ ** come to depend on that bug. Use the SQLITE_BUG_COMPATIBLE_20250510
211192
+ ** option to restore the old buggy behavior. */
211193
+#ifdef SQLITE_BUG_COMPATIBLE_20250510
211194
+ /* Legacy bug-compatible behavior */
211195
+ *piOut = 0;
211196
+#else
211197
+ /* Correct behavior */
211198
+ *piOut = (n>2 && sqlite3Isdigit(z[2])) ? JSON_INVALID_CHAR : 0;
211199
+#endif
211200
+ return 2;
211201
+ }
210564211202
case '\'':
210565211203
case '"':
210566211204
case '/':
210567211205
case '\\':{ *piOut = z[1]; return 2; }
210568211206
case 'x': {
@@ -212665,22 +213303,24 @@
212665213303
const char *z;
212666213304
u32 n;
212667213305
UNUSED_PARAMETER(argc);
212668213306
pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
212669213307
if( pStr ){
213308
+ z = (const char*)sqlite3_value_text(argv[0]);
213309
+ n = sqlite3Strlen30(z);
212670213310
if( pStr->zBuf==0 ){
212671213311
jsonStringInit(pStr, ctx);
212672213312
jsonAppendChar(pStr, '{');
212673
- }else if( pStr->nUsed>1 ){
213313
+ }else if( pStr->nUsed>1 && z!=0 ){
212674213314
jsonAppendChar(pStr, ',');
212675213315
}
212676213316
pStr->pCtx = ctx;
212677
- z = (const char*)sqlite3_value_text(argv[0]);
212678
- n = sqlite3Strlen30(z);
212679
- jsonAppendString(pStr, z, n);
212680
- jsonAppendChar(pStr, ':');
212681
- jsonAppendSqlValue(pStr, argv[1]);
213317
+ if( z!=0 ){
213318
+ jsonAppendString(pStr, z, n);
213319
+ jsonAppendChar(pStr, ':');
213320
+ jsonAppendSqlValue(pStr, argv[1]);
213321
+ }
212682213322
}
212683213323
}
212684213324
static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
212685213325
JsonString *pStr;
212686213326
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
@@ -213484,10 +214124,12 @@
213484214124
#else
213485214125
/* #include "sqlite3.h" */
213486214126
#endif
213487214127
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213488214128
214129
+/* #include <stddef.h> */
214130
+
213489214131
/*
213490214132
** If building separately, we will need some setup that is normally
213491214133
** found in sqliteInt.h
213492214134
*/
213493214135
#if !defined(SQLITE_AMALGAMATION)
@@ -213515,11 +214157,11 @@
213515214157
#else
213516214158
# define ALWAYS(X) (X)
213517214159
# define NEVER(X) (X)
213518214160
#endif
213519214161
#ifndef offsetof
213520
-#define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
214162
+# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
213521214163
#endif
213522214164
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
213523214165
# define FLEXARRAY
213524214166
#else
213525214167
# define FLEXARRAY 1
@@ -214553,10 +215195,16 @@
214553215195
pStmt = pCsr->pReadAux;
214554215196
memset(pCsr, 0, sizeof(RtreeCursor));
214555215197
pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
214556215198
pCsr->pReadAux = pStmt;
214557215199
215200
+ /* The following will only fail if the previous sqlite3_step() call failed,
215201
+ ** in which case the error has already been caught. This statement never
215202
+ ** encounters an error within an sqlite3_column_xxx() function, as it
215203
+ ** calls sqlite3_column_value(), which does not use malloc(). So it is safe
215204
+ ** to ignore the error code here. */
215205
+ sqlite3_reset(pStmt);
214558215206
}
214559215207
214560215208
/*
214561215209
** Rtree virtual table module xClose method.
214562215210
*/
@@ -227832,11 +228480,12 @@
227832228480
DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
227833228481
int rc;
227834228482
sqlite3 *db = pTab->db;
227835228483
Btree *pBt;
227836228484
227837
- (void)idxStr;
228485
+ UNUSED_PARAMETER(idxStr);
228486
+ UNUSED_PARAMETER(argc);
227838228487
227839228488
/* Default setting is no rows of result */
227840228489
pCsr->pgno = 1;
227841228490
pCsr->mxPgno = 0;
227842228491
@@ -231494,18 +232143,19 @@
231494232143
/*
231495232144
** If the SessionInput object passed as the only argument is a streaming
231496232145
** object and the buffer is full, discard some data to free up space.
231497232146
*/
231498232147
static void sessionDiscardData(SessionInput *pIn){
231499
- if( pIn->xInput && pIn->iNext>=sessions_strm_chunk_size ){
231500
- int nMove = pIn->buf.nBuf - pIn->iNext;
232148
+ if( pIn->xInput && pIn->iCurrent>=sessions_strm_chunk_size ){
232149
+ int nMove = pIn->buf.nBuf - pIn->iCurrent;
231501232150
assert( nMove>=0 );
231502232151
if( nMove>0 ){
231503
- memmove(pIn->buf.aBuf, &pIn->buf.aBuf[pIn->iNext], nMove);
232152
+ memmove(pIn->buf.aBuf, &pIn->buf.aBuf[pIn->iCurrent], nMove);
231504232153
}
231505
- pIn->buf.nBuf -= pIn->iNext;
231506
- pIn->iNext = 0;
232154
+ pIn->buf.nBuf -= pIn->iCurrent;
232155
+ pIn->iNext -= pIn->iCurrent;
232156
+ pIn->iCurrent = 0;
231507232157
pIn->nData = pIn->buf.nBuf;
231508232158
}
231509232159
}
231510232160
231511232161
/*
@@ -231855,12 +232505,12 @@
231855232505
** sufficient either for the 'T' or 'P' byte and the varint that follows
231856232506
** it, or for the two single byte values otherwise. */
231857232507
p->rc = sessionInputBuffer(&p->in, 2);
231858232508
if( p->rc!=SQLITE_OK ) return p->rc;
231859232509
231860
- sessionDiscardData(&p->in);
231861232510
p->in.iCurrent = p->in.iNext;
232511
+ sessionDiscardData(&p->in);
231862232512
231863232513
/* If the iterator is already at the end of the changeset, return DONE. */
231864232514
if( p->in.iNext>=p->in.nData ){
231865232515
return SQLITE_DONE;
231866232516
}
@@ -233279,10 +233929,14 @@
233279233929
sqlite3_changeset_iter *pIter, /* Changeset to apply */
233280233930
int(*xFilter)(
233281233931
void *pCtx, /* Copy of sixth arg to _apply() */
233282233932
const char *zTab /* Table name */
233283233933
),
233934
+ int(*xFilterIter)(
233935
+ void *pCtx, /* Copy of sixth arg to _apply() */
233936
+ sqlite3_changeset_iter *p
233937
+ ),
233284233938
int(*xConflict)(
233285233939
void *pCtx, /* Copy of fifth arg to _apply() */
233286233940
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233287233941
sqlite3_changeset_iter *p /* Handle describing change and conflict */
233288233942
),
@@ -233418,10 +234072,13 @@
233418234072
}
233419234073
233420234074
/* If there is a schema mismatch on the current table, proceed to the
233421234075
** next change. A log message has already been issued. */
233422234076
if( schemaMismatch ) continue;
234077
+
234078
+ /* If this is a call to apply_v3(), invoke xFilterIter here. */
234079
+ if( xFilterIter && 0==xFilterIter(pCtx, pIter) ) continue;
233423234080
233424234081
rc = sessionApplyOneWithRetry(db, pIter, &sApply, xConflict, pCtx);
233425234082
}
233426234083
233427234084
bPatchset = pIter->bPatchset;
@@ -233485,10 +234142,91 @@
233485234142
db->aDb[0].pSchema->schema_cookie -= 32;
233486234143
}
233487234144
sqlite3_mutex_leave(sqlite3_db_mutex(db));
233488234145
return rc;
233489234146
}
234147
+
234148
+/*
234149
+** This function is called by all six sqlite3changeset_apply() variants:
234150
+**
234151
+** + sqlite3changeset_apply()
234152
+** + sqlite3changeset_apply_v2()
234153
+** + sqlite3changeset_apply_v3()
234154
+** + sqlite3changeset_apply_strm()
234155
+** + sqlite3changeset_apply_strm_v2()
234156
+** + sqlite3changeset_apply_strm_v3()
234157
+**
234158
+** Arguments passed to this function are as follows:
234159
+**
234160
+** db:
234161
+** Database handle to apply changeset to main database of.
234162
+**
234163
+** nChangeset/pChangeset:
234164
+** These are both passed zero for the streaming variants. For the normal
234165
+** apply() functions, these are passed the size of and the buffer containing
234166
+** the changeset, respectively.
234167
+**
234168
+** xInput/pIn:
234169
+** These are both passed zero for the normal variants. For the streaming
234170
+** apply() functions, these are passed the input callback and context
234171
+** pointer, respectively.
234172
+**
234173
+** xFilter:
234174
+** The filter function as passed to apply() or apply_v2() (to filter by
234175
+** table name), if any. This is always NULL for apply_v3() calls.
234176
+**
234177
+** xFilterIter:
234178
+** The filter function as passed to apply_v3(), if any.
234179
+**
234180
+** xConflict:
234181
+** The conflict handler callback (must not be NULL).
234182
+**
234183
+** pCtx:
234184
+** The context pointer passed to the xFilter and xConflict handler callbacks.
234185
+**
234186
+** ppRebase, pnRebase:
234187
+** Zero for apply(). The rebase changeset output pointers, if any, for
234188
+** apply_v2() and apply_v3().
234189
+**
234190
+** flags:
234191
+** Zero for apply(). The flags parameter for apply_v2() and apply_v3().
234192
+*/
234193
+static int sessionChangesetApplyV23(
234194
+ sqlite3 *db, /* Apply change to "main" db of this handle */
234195
+ int nChangeset, /* Size of changeset in bytes */
234196
+ void *pChangeset, /* Changeset blob */
234197
+ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234198
+ void *pIn, /* First arg for xInput */
234199
+ int(*xFilter)(
234200
+ void *pCtx, /* Copy of sixth arg to _apply() */
234201
+ const char *zTab /* Table name */
234202
+ ),
234203
+ int(*xFilterIter)(
234204
+ void *pCtx, /* Copy of sixth arg to _apply() */
234205
+ sqlite3_changeset_iter *p /* Handle describing current change */
234206
+ ),
234207
+ int(*xConflict)(
234208
+ void *pCtx, /* Copy of sixth arg to _apply() */
234209
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234210
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
234211
+ ),
234212
+ void *pCtx, /* First argument passed to xConflict */
234213
+ void **ppRebase, int *pnRebase,
234214
+ int flags
234215
+){
234216
+ sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
234217
+ int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
234218
+ int rc = sessionChangesetStart(
234219
+ &pIter, xInput, pIn, nChangeset, pChangeset, bInverse, 1
234220
+ );
234221
+ if( rc==SQLITE_OK ){
234222
+ rc = sessionChangesetApply(db, pIter,
234223
+ xFilter, xFilterIter, xConflict, pCtx, ppRebase, pnRebase, flags
234224
+ );
234225
+ }
234226
+ return rc;
234227
+}
233490234228
233491234229
/*
233492234230
** Apply the changeset passed via pChangeset/nChangeset to the main
233493234231
** database attached to handle "db".
233494234232
*/
@@ -233507,21 +234245,43 @@
233507234245
),
233508234246
void *pCtx, /* First argument passed to xConflict */
233509234247
void **ppRebase, int *pnRebase,
233510234248
int flags
233511234249
){
233512
- sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
233513
- int bInv = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
233514
- int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
233515
-
233516
- if( rc==SQLITE_OK ){
233517
- rc = sessionChangesetApply(
233518
- db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
233519
- );
233520
- }
233521
-
233522
- return rc;
234250
+ return sessionChangesetApplyV23(db,
234251
+ nChangeset, pChangeset, 0, 0,
234252
+ xFilter, 0, xConflict, pCtx,
234253
+ ppRebase, pnRebase, flags
234254
+ );
234255
+}
234256
+
234257
+/*
234258
+** Apply the changeset passed via pChangeset/nChangeset to the main
234259
+** database attached to handle "db".
234260
+*/
234261
+SQLITE_API int sqlite3changeset_apply_v3(
234262
+ sqlite3 *db, /* Apply change to "main" db of this handle */
234263
+ int nChangeset, /* Size of changeset in bytes */
234264
+ void *pChangeset, /* Changeset blob */
234265
+ int(*xFilter)(
234266
+ void *pCtx, /* Copy of sixth arg to _apply() */
234267
+ sqlite3_changeset_iter *p /* Handle describing current change */
234268
+ ),
234269
+ int(*xConflict)(
234270
+ void *pCtx, /* Copy of sixth arg to _apply() */
234271
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234272
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
234273
+ ),
234274
+ void *pCtx, /* First argument passed to xConflict */
234275
+ void **ppRebase, int *pnRebase,
234276
+ int flags
234277
+){
234278
+ return sessionChangesetApplyV23(db,
234279
+ nChangeset, pChangeset, 0, 0,
234280
+ 0, xFilter, xConflict, pCtx,
234281
+ ppRebase, pnRebase, flags
234282
+ );
233523234283
}
233524234284
233525234285
/*
233526234286
** Apply the changeset passed via pChangeset/nChangeset to the main database
233527234287
** attached to handle "db". Invoke the supplied conflict handler callback
@@ -233540,20 +234300,45 @@
233540234300
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233541234301
sqlite3_changeset_iter *p /* Handle describing change and conflict */
233542234302
),
233543234303
void *pCtx /* First argument passed to xConflict */
233544234304
){
233545
- return sqlite3changeset_apply_v2(
233546
- db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
234305
+ return sessionChangesetApplyV23(db,
234306
+ nChangeset, pChangeset, 0, 0,
234307
+ xFilter, 0, xConflict, pCtx,
234308
+ 0, 0, 0
233547234309
);
233548234310
}
233549234311
233550234312
/*
233551234313
** Apply the changeset passed via xInput/pIn to the main database
233552234314
** attached to handle "db". Invoke the supplied conflict handler callback
233553234315
** to resolve any conflicts encountered while applying the change.
233554234316
*/
234317
+SQLITE_API int sqlite3changeset_apply_v3_strm(
234318
+ sqlite3 *db, /* Apply change to "main" db of this handle */
234319
+ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234320
+ void *pIn, /* First arg for xInput */
234321
+ int(*xFilter)(
234322
+ void *pCtx, /* Copy of sixth arg to _apply() */
234323
+ sqlite3_changeset_iter *p
234324
+ ),
234325
+ int(*xConflict)(
234326
+ void *pCtx, /* Copy of sixth arg to _apply() */
234327
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234328
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
234329
+ ),
234330
+ void *pCtx, /* First argument passed to xConflict */
234331
+ void **ppRebase, int *pnRebase,
234332
+ int flags
234333
+){
234334
+ return sessionChangesetApplyV23(db,
234335
+ 0, 0, xInput, pIn,
234336
+ 0, xFilter, xConflict, pCtx,
234337
+ ppRebase, pnRebase, flags
234338
+ );
234339
+}
233555234340
SQLITE_API int sqlite3changeset_apply_v2_strm(
233556234341
sqlite3 *db, /* Apply change to "main" db of this handle */
233557234342
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
233558234343
void *pIn, /* First arg for xInput */
233559234344
int(*xFilter)(
@@ -233567,19 +234352,15 @@
233567234352
),
233568234353
void *pCtx, /* First argument passed to xConflict */
233569234354
void **ppRebase, int *pnRebase,
233570234355
int flags
233571234356
){
233572
- sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
233573
- int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
233574
- int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
233575
- if( rc==SQLITE_OK ){
233576
- rc = sessionChangesetApply(
233577
- db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
233578
- );
233579
- }
233580
- return rc;
234357
+ return sessionChangesetApplyV23(db,
234358
+ 0, 0, xInput, pIn,
234359
+ xFilter, 0, xConflict, pCtx,
234360
+ ppRebase, pnRebase, flags
234361
+ );
233581234362
}
233582234363
SQLITE_API int sqlite3changeset_apply_strm(
233583234364
sqlite3 *db, /* Apply change to "main" db of this handle */
233584234365
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
233585234366
void *pIn, /* First arg for xInput */
@@ -233592,12 +234373,14 @@
233592234373
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233593234374
sqlite3_changeset_iter *p /* Handle describing change and conflict */
233594234375
),
233595234376
void *pCtx /* First argument passed to xConflict */
233596234377
){
233597
- return sqlite3changeset_apply_v2_strm(
233598
- db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
234378
+ return sessionChangesetApplyV23(db,
234379
+ 0, 0, xInput, pIn,
234380
+ xFilter, 0, xConflict, pCtx,
234381
+ 0, 0, 0
233599234382
);
233600234383
}
233601234384
233602234385
/*
233603234386
** sqlite3_changegroup handle.
@@ -234215,18 +234998,23 @@
234215234998
*/
234216234999
SQLITE_API int sqlite3changegroup_add_change(
234217235000
sqlite3_changegroup *pGrp,
234218235001
sqlite3_changeset_iter *pIter
234219235002
){
235003
+ int rc = SQLITE_OK;
235004
+
234220235005
if( pIter->in.iCurrent==pIter->in.iNext
234221235006
|| pIter->rc!=SQLITE_OK
234222235007
|| pIter->bInvert
234223235008
){
234224235009
/* Iterator does not point to any valid entry or is an INVERT iterator. */
234225
- return SQLITE_ERROR;
235010
+ rc = SQLITE_ERROR;
235011
+ }else{
235012
+ pIter->in.bNoDiscard = 1;
235013
+ rc = sessionOneChangeToHash(pGrp, pIter, 0);
234226235014
}
234227
- return sessionOneChangeToHash(pGrp, pIter, 0);
235015
+ return rc;
234228235016
}
234229235017
234230235018
/*
234231235019
** Obtain a buffer containing a changeset representing the concatenation
234232235020
** of all changesets added to the group so far.
@@ -235520,10 +236308,11 @@
235520236308
/* #include "sqlite3ext.h" */
235521236309
SQLITE_EXTENSION_INIT1
235522236310
235523236311
/* #include <string.h> */
235524236312
/* #include <assert.h> */
236313
+/* #include <stddef.h> */
235525236314
235526236315
#ifndef SQLITE_AMALGAMATION
235527236316
235528236317
typedef unsigned char u8;
235529236318
typedef unsigned int u32;
@@ -235579,11 +236368,11 @@
235579236368
235580236369
/*
235581236370
** Macros needed to provide flexible arrays in a portable way
235582236371
*/
235583236372
#ifndef offsetof
235584
-# define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
236373
+# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
235585236374
#endif
235586236375
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235587236376
# define FLEXARRAY
235588236377
#else
235589236378
# define FLEXARRAY 1
@@ -244763,10 +245552,40 @@
244763245552
Fts5Buffer term; /* Current term */
244764245553
i64 iRowid; /* Current rowid */
244765245554
int nPos; /* Number of bytes in current position list */
244766245555
u8 bDel; /* True if the delete flag is set */
244767245556
};
245557
+
245558
+static int fts5IndexCorruptRowid(Fts5Index *pIdx, i64 iRowid){
245559
+ pIdx->rc = FTS5_CORRUPT;
245560
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245561
+ "fts5: corruption found reading blob %lld from table \"%s\"",
245562
+ iRowid, pIdx->pConfig->zName
245563
+ );
245564
+ return SQLITE_CORRUPT_VTAB;
245565
+}
245566
+#define FTS5_CORRUPT_ROWID(pIdx, iRowid) fts5IndexCorruptRowid(pIdx, iRowid)
245567
+
245568
+static int fts5IndexCorruptIter(Fts5Index *pIdx, Fts5SegIter *pIter){
245569
+ pIdx->rc = FTS5_CORRUPT;
245570
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245571
+ "fts5: corruption on page %d, segment %d, table \"%s\"",
245572
+ pIter->iLeafPgno, pIter->pSeg->iSegid, pIdx->pConfig->zName
245573
+ );
245574
+ return SQLITE_CORRUPT_VTAB;
245575
+}
245576
+#define FTS5_CORRUPT_ITER(pIdx, pIter) fts5IndexCorruptIter(pIdx, pIter)
245577
+
245578
+static int fts5IndexCorruptIdx(Fts5Index *pIdx){
245579
+ pIdx->rc = FTS5_CORRUPT;
245580
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245581
+ "fts5: corruption in table \"%s\"", pIdx->pConfig->zName
245582
+ );
245583
+ return SQLITE_CORRUPT_VTAB;
245584
+}
245585
+#define FTS5_CORRUPT_IDX(pIdx) fts5IndexCorruptIdx(pIdx)
245586
+
244768245587
244769245588
/*
244770245589
** Array of tombstone pages. Reference counted.
244771245590
*/
244772245591
struct Fts5TombstoneArray {
@@ -245053,11 +245872,11 @@
245053245872
/* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245054245873
** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245055245874
** All the reasons those functions might return SQLITE_ERROR - missing
245056245875
** table, missing row, non-blob/text in block column - indicate
245057245876
** backing store corruption. */
245058
- if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;
245877
+ if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT_ROWID(p, iRowid);
245059245878
245060245879
if( rc==SQLITE_OK ){
245061245880
u8 *aOut = 0; /* Read blob data into this buffer */
245062245881
int nByte = sqlite3_blob_bytes(p->pReader);
245063245882
int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245103,11 +245922,11 @@
245103245922
245104245923
static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245105245924
Fts5Data *pRet = fts5DataRead(p, iRowid);
245106245925
if( pRet ){
245107245926
if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245108
- p->rc = FTS5_CORRUPT;
245927
+ FTS5_CORRUPT_ROWID(p, iRowid);
245109245928
fts5DataRelease(pRet);
245110245929
pRet = 0;
245111245930
}
245112245931
}
245113245932
return pRet;
@@ -245462,12 +246281,18 @@
245462246281
pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
245463246282
if( p->rc==SQLITE_OK ){
245464246283
/* TODO: Do we need this if the leaf-index is appended? Probably... */
245465246284
memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245466246285
p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
245467
- if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245468
- p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
246286
+ if( p->rc==SQLITE_OK ){
246287
+ if( (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
246288
+ p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
246289
+ }
246290
+ }else if( p->rc==SQLITE_CORRUPT_VTAB ){
246291
+ sqlite3Fts5ConfigErrmsg(p->pConfig,
246292
+ "fts5: corrupt structure record for table \"%s\"", p->pConfig->zName
246293
+ );
245469246294
}
245470246295
fts5DataRelease(pData);
245471246296
if( p->rc!=SQLITE_OK ){
245472246297
fts5StructureRelease(pRet);
245473246298
pRet = 0;
@@ -246086,11 +246911,11 @@
246086246911
246087246912
ASSERT_SZLEAF_OK(pIter->pLeaf);
246088246913
while( iOff>=pIter->pLeaf->szLeaf ){
246089246914
fts5SegIterNextPage(p, pIter);
246090246915
if( pIter->pLeaf==0 ){
246091
- if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
246916
+ if( p->rc==SQLITE_OK ) FTS5_CORRUPT_ITER(p, pIter);
246092246917
return;
246093246918
}
246094246919
iOff = 4;
246095246920
a = pIter->pLeaf->p;
246096246921
}
@@ -246118,11 +246943,11 @@
246118246943
i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246119246944
int nNew; /* Bytes of new data */
246120246945
246121246946
iOff += fts5GetVarint32(&a[iOff], nNew);
246122246947
if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246123
- p->rc = FTS5_CORRUPT;
246948
+ FTS5_CORRUPT_ITER(p, pIter);
246124246949
return;
246125246950
}
246126246951
pIter->term.n = nKeep;
246127246952
fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246128246953
assert( pIter->term.n<=pIter->term.nSpace );
@@ -246160,13 +246985,13 @@
246160246985
** Allocate a tombstone hash page array object (pIter->pTombArray) for
246161246986
** the iterator passed as the second argument. If an OOM error occurs,
246162246987
** leave an error in the Fts5Index object.
246163246988
*/
246164246989
static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
246165
- const int nTomb = pIter->pSeg->nPgTombstone;
246990
+ const i64 nTomb = (i64)pIter->pSeg->nPgTombstone;
246166246991
if( nTomb>0 ){
246167
- int nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
246992
+ i64 nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
246168246993
Fts5TombstoneArray *pNew;
246169246994
pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
246170246995
if( pNew ){
246171246996
pNew->nTombstone = nTomb;
246172246997
pNew->nRef = 1;
@@ -246313,11 +247138,11 @@
246313247138
}else{
246314247139
int iRowidOff;
246315247140
iRowidOff = fts5LeafFirstRowidOff(pNew);
246316247141
if( iRowidOff ){
246317247142
if( iRowidOff>=pNew->szLeaf ){
246318
- p->rc = FTS5_CORRUPT;
247143
+ FTS5_CORRUPT_ITER(p, pIter);
246319247144
}else{
246320247145
pIter->pLeaf = pNew;
246321247146
pIter->iLeafOffset = iRowidOff;
246322247147
}
246323247148
}
@@ -246547,11 +247372,11 @@
246547247372
pIter->iEndofDoclist = iOff;
246548247373
bNewTerm = 1;
246549247374
}
246550247375
assert_nc( iOff<pLeaf->szLeaf );
246551247376
if( iOff>pLeaf->szLeaf ){
246552
- p->rc = FTS5_CORRUPT;
247377
+ FTS5_CORRUPT_ITER(p, pIter);
246553247378
return;
246554247379
}
246555247380
}
246556247381
}
246557247382
@@ -246655,22 +247480,24 @@
246655247480
if( pLast ){
246656247481
int iOff;
246657247482
fts5DataRelease(pIter->pLeaf);
246658247483
pIter->pLeaf = pLast;
246659247484
pIter->iLeafPgno = pgnoLast;
246660
- iOff = fts5LeafFirstRowidOff(pLast);
246661
- if( iOff>pLast->szLeaf ){
246662
- p->rc = FTS5_CORRUPT;
246663
- return;
246664
- }
246665
- iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
246666
- pIter->iLeafOffset = iOff;
246667
-
246668
- if( fts5LeafIsTermless(pLast) ){
246669
- pIter->iEndofDoclist = pLast->nn+1;
246670
- }else{
246671
- pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
247485
+ if( p->rc==SQLITE_OK ){
247486
+ iOff = fts5LeafFirstRowidOff(pLast);
247487
+ if( iOff>pLast->szLeaf ){
247488
+ FTS5_CORRUPT_ITER(p, pIter);
247489
+ return;
247490
+ }
247491
+ iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
247492
+ pIter->iLeafOffset = iOff;
247493
+
247494
+ if( fts5LeafIsTermless(pLast) ){
247495
+ pIter->iEndofDoclist = pLast->nn+1;
247496
+ }else{
247497
+ pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
247498
+ }
246672247499
}
246673247500
}
246674247501
246675247502
fts5SegIterReverseInitPage(p, pIter);
246676247503
}
@@ -246736,11 +247563,11 @@
246736247563
246737247564
iPgidx = (u32)pIter->pLeaf->szLeaf;
246738247565
iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
246739247566
iOff = iTermOff;
246740247567
if( iOff>n ){
246741
- p->rc = FTS5_CORRUPT;
247568
+ FTS5_CORRUPT_ITER(p, pIter);
246742247569
return;
246743247570
}
246744247571
246745247572
while( 1 ){
246746247573
@@ -246779,11 +247606,11 @@
246779247606
iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
246780247607
iTermOff += nKeep;
246781247608
iOff = iTermOff;
246782247609
246783247610
if( iOff>=n ){
246784
- p->rc = FTS5_CORRUPT;
247611
+ FTS5_CORRUPT_ITER(p, pIter);
246785247612
return;
246786247613
}
246787247614
246788247615
/* Read the nKeep field of the next term. */
246789247616
fts5FastGetVarint32(a, iOff, nKeep);
@@ -246801,11 +247628,11 @@
246801247628
a = pIter->pLeaf->p;
246802247629
if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246803247630
iPgidx = (u32)pIter->pLeaf->szLeaf;
246804247631
iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
246805247632
if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
246806
- p->rc = FTS5_CORRUPT;
247633
+ FTS5_CORRUPT_ITER(p, pIter);
246807247634
return;
246808247635
}else{
246809247636
nKeep = 0;
246810247637
iTermOff = iOff;
246811247638
n = (u32)pIter->pLeaf->nn;
@@ -246816,11 +247643,11 @@
246816247643
}while( 1 );
246817247644
}
246818247645
246819247646
search_success:
246820247647
if( (i64)iOff+nNew>n || nNew<1 ){
246821
- p->rc = FTS5_CORRUPT;
247648
+ FTS5_CORRUPT_ITER(p, pIter);
246822247649
return;
246823247650
}
246824247651
pIter->iLeafOffset = iOff + nNew;
246825247652
pIter->iTermLeafOffset = pIter->iLeafOffset;
246826247653
pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247281,11 +248108,11 @@
247281248108
int iLeafPgno
247282248109
){
247283248110
assert( iLeafPgno>pIter->iLeafPgno );
247284248111
247285248112
if( iLeafPgno>pIter->pSeg->pgnoLast ){
247286
- p->rc = FTS5_CORRUPT;
248113
+ FTS5_CORRUPT_IDX(p);
247287248114
}else{
247288248115
fts5DataRelease(pIter->pNextLeaf);
247289248116
pIter->pNextLeaf = 0;
247290248117
pIter->iLeafPgno = iLeafPgno-1;
247291248118
@@ -247296,11 +248123,11 @@
247296248123
iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
247297248124
if( iOff>0 ){
247298248125
u8 *a = pIter->pLeaf->p;
247299248126
int n = pIter->pLeaf->szLeaf;
247300248127
if( iOff<4 || iOff>=n ){
247301
- p->rc = FTS5_CORRUPT;
248128
+ FTS5_CORRUPT_IDX(p);
247302248129
}else{
247303248130
iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
247304248131
pIter->iLeafOffset = iOff;
247305248132
fts5SegIterLoadNPos(p, pIter);
247306248133
}
@@ -247775,11 +248602,11 @@
247775248602
nRem -= nChunk;
247776248603
fts5DataRelease(pData);
247777248604
if( nRem<=0 ){
247778248605
break;
247779248606
}else if( pSeg->pSeg==0 ){
247780
- p->rc = FTS5_CORRUPT;
248607
+ FTS5_CORRUPT_IDX(p);
247781248608
return;
247782248609
}else{
247783248610
pgno++;
247784248611
pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
247785248612
if( pData==0 ) break;
@@ -248878,11 +249705,11 @@
248878249705
if( iOff>pData->szLeaf ){
248879249706
/* This can occur if the pages that the segments occupy overlap - if
248880249707
** a single page has been assigned to more than one segment. In
248881249708
** this case a prior iteration of this loop may have corrupted the
248882249709
** segment currently being trimmed. */
248883
- p->rc = FTS5_CORRUPT;
249710
+ FTS5_CORRUPT_ROWID(p, iLeafRowid);
248884249711
}else{
248885249712
fts5BufferZero(&buf);
248886249713
fts5BufferGrow(&p->rc, &buf, pData->nn);
248887249714
fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
248888249715
fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249345,11 +250172,11 @@
249345250172
fts5DataRelease(pLeaf);
249346250173
pLeaf = 0;
249347250174
}else if( bDetailNone ){
249348250175
break;
249349250176
}else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
249350
- p->rc = FTS5_CORRUPT;
250177
+ FTS5_CORRUPT_ROWID(p, iRowid);
249351250178
break;
249352250179
}else{
249353250180
int nShift = iNext - 4;
249354250181
int nPg;
249355250182
@@ -249365,11 +250192,11 @@
249365250192
int i1 = pLeaf->szLeaf;
249366250193
int i2 = 0;
249367250194
249368250195
i1 += fts5GetVarint32(&aPg[i1], iFirst);
249369250196
if( iFirst<iNext ){
249370
- p->rc = FTS5_CORRUPT;
250197
+ FTS5_CORRUPT_ROWID(p, iRowid);
249371250198
break;
249372250199
}
249373250200
aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
249374250201
if( aIdx==0 ) break;
249375250202
i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249588,18 +250415,18 @@
249588250415
249589250416
nPrefix = MIN(nPrefix, nPrefix2);
249590250417
nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
249591250418
249592250419
if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
249593
- p->rc = FTS5_CORRUPT;
250420
+ FTS5_CORRUPT_IDX(p);
249594250421
}else{
249595250422
if( iKey!=1 ){
249596250423
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
249597250424
}
249598250425
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
249599250426
if( nPrefix2>pSeg->term.n ){
249600
- p->rc = FTS5_CORRUPT;
250427
+ FTS5_CORRUPT_IDX(p);
249601250428
}else if( nPrefix2>nPrefix ){
249602250429
memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
249603250430
iOff += (nPrefix2-nPrefix);
249604250431
}
249605250432
memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250019,11 +250846,11 @@
250019250846
}
250020250847
assert( pStruct->aLevel[i].nMerge<=nThis );
250021250848
}
250022250849
250023250850
nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
250024
- assert( nByte==SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
250851
+ assert( nByte==(i64)SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
250025250852
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
250026250853
250027250854
if( pNew ){
250028250855
Fts5StructureLevel *pLvl;
250029250856
nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -250388,11 +251215,11 @@
250388251215
fts5PrefixMergerInsertByPosition(&pHead, pSave);
250389251216
pSave = pNext;
250390251217
}
250391251218
250392251219
if( pHead==0 || pHead->pNext==0 ){
250393
- p->rc = FTS5_CORRUPT;
251220
+ FTS5_CORRUPT_IDX(p);
250394251221
break;
250395251222
}
250396251223
250397251224
/* See the earlier comment in this function for an explanation of why
250398251225
** corrupt input position lists might cause the output to consume
@@ -250425,11 +251252,11 @@
250425251252
250426251253
/* WRITEPOSLISTSIZE */
250427251254
assert_nc( tmp.n+nTail<=nTmp );
250428251255
assert( tmp.n+nTail<=nTmp+nMerge*10 );
250429251256
if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
250430
- if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
251257
+ if( p->rc==SQLITE_OK ) FTS5_CORRUPT_IDX(p);
250431251258
break;
250432251259
}
250433251260
fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
250434251261
fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
250435251262
if( nTail>0 ){
@@ -252458,23 +253285,31 @@
252458253285
}
252459253286
252460253287
/*
252461253288
** This function is also purely an internal test. It does not contribute to
252462253289
** FTS functionality, or even the integrity-check, in any way.
253290
+**
253291
+** This function sets output variable (*pbFail) to true if the test fails. Or
253292
+** leaves it unchanged if the test succeeds.
252463253293
*/
252464253294
static void fts5TestTerm(
252465253295
Fts5Index *p,
252466253296
Fts5Buffer *pPrev, /* Previous term */
252467253297
const char *z, int n, /* Possibly new term to test */
252468253298
u64 expected,
252469
- u64 *pCksum
253299
+ u64 *pCksum,
253300
+ int *pbFail
252470253301
){
252471253302
int rc = p->rc;
252472253303
if( pPrev->n==0 ){
252473253304
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
252474253305
}else
252475
- if( rc==SQLITE_OK && (pPrev->n!=n || memcmp(pPrev->p, z, n)) ){
253306
+ if( *pbFail==0
253307
+ && rc==SQLITE_OK
253308
+ && (pPrev->n!=n || memcmp(pPrev->p, z, n))
253309
+ && (p->pHash==0 || p->pHash->nEntry==0)
253310
+ ){
252476253311
u64 cksum3 = *pCksum;
252477253312
const char *zTerm = (const char*)&pPrev->p[1]; /* term sans prefix-byte */
252478253313
int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
252479253314
int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
252480253315
int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
@@ -252520,20 +253355,20 @@
252520253355
252521253356
cksum3 ^= ck1;
252522253357
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
252523253358
252524253359
if( rc==SQLITE_OK && cksum3!=expected ){
252525
- rc = FTS5_CORRUPT;
253360
+ *pbFail = 1;
252526253361
}
252527253362
*pCksum = cksum3;
252528253363
}
252529253364
p->rc = rc;
252530253365
}
252531253366
252532253367
#else
252533253368
# define fts5TestDlidxReverse(x,y,z)
252534
-# define fts5TestTerm(u,v,w,x,y,z)
253369
+# define fts5TestTerm(t,u,v,w,x,y,z)
252535253370
#endif
252536253371
252537253372
/*
252538253373
** Check that:
252539253374
**
@@ -252554,18 +253389,21 @@
252554253389
/* Now check that the iter.nEmpty leaves following the current leaf
252555253390
** (a) exist and (b) contain no terms. */
252556253391
for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
252557253392
Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252558253393
if( pLeaf ){
252559
- if( !fts5LeafIsTermless(pLeaf) ) p->rc = FTS5_CORRUPT;
252560
- if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
253394
+ if( !fts5LeafIsTermless(pLeaf)
253395
+ || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
253396
+ ){
253397
+ FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
253398
+ }
252561253399
}
252562253400
fts5DataRelease(pLeaf);
252563253401
}
252564253402
}
252565253403
252566
-static void fts5IntegrityCheckPgidx(Fts5Index *p, Fts5Data *pLeaf){
253404
+static void fts5IntegrityCheckPgidx(Fts5Index *p, i64 iRowid, Fts5Data *pLeaf){
252567253405
i64 iTermOff = 0;
252568253406
int ii;
252569253407
252570253408
Fts5Buffer buf1 = {0,0,0};
252571253409
Fts5Buffer buf2 = {0,0,0};
@@ -252579,33 +253417,33 @@
252579253417
ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
252580253418
iTermOff += nIncr;
252581253419
iOff = iTermOff;
252582253420
252583253421
if( iOff>=pLeaf->szLeaf ){
252584
- p->rc = FTS5_CORRUPT;
253422
+ FTS5_CORRUPT_ROWID(p, iRowid);
252585253423
}else if( iTermOff==nIncr ){
252586253424
int nByte;
252587253425
iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252588253426
if( (iOff+nByte)>pLeaf->szLeaf ){
252589
- p->rc = FTS5_CORRUPT;
253427
+ FTS5_CORRUPT_ROWID(p, iRowid);
252590253428
}else{
252591253429
fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252592253430
}
252593253431
}else{
252594253432
int nKeep, nByte;
252595253433
iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
252596253434
iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252597253435
if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
252598
- p->rc = FTS5_CORRUPT;
253436
+ FTS5_CORRUPT_ROWID(p, iRowid);
252599253437
}else{
252600253438
buf1.n = nKeep;
252601253439
fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252602253440
}
252603253441
252604253442
if( p->rc==SQLITE_OK ){
252605253443
res = fts5BufferCompare(&buf1, &buf2);
252606
- if( res<=0 ) p->rc = FTS5_CORRUPT;
253444
+ if( res<=0 ) FTS5_CORRUPT_ROWID(p, iRowid);
252607253445
}
252608253446
}
252609253447
fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
252610253448
}
252611253449
@@ -252662,11 +253500,11 @@
252662253500
){
252663253501
/* special case - the very first page in a segment keeps its %_idx
252664253502
** entry even if all the terms are removed from it by secure-delete
252665253503
** operations. */
252666253504
}else{
252667
- p->rc = FTS5_CORRUPT;
253505
+ FTS5_CORRUPT_ROWID(p, iRow);
252668253506
}
252669253507
252670253508
}else{
252671253509
int iOff; /* Offset of first term on leaf */
252672253510
int iRowidOff; /* Offset of first rowid on leaf */
@@ -252674,19 +253512,19 @@
252674253512
int res; /* Comparison of term and split-key */
252675253513
252676253514
iOff = fts5LeafFirstTermOff(pLeaf);
252677253515
iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252678253516
if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
252679
- p->rc = FTS5_CORRUPT;
253517
+ FTS5_CORRUPT_ROWID(p, iRow);
252680253518
}else{
252681253519
iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
252682253520
res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
252683253521
if( res==0 ) res = nTerm - nIdxTerm;
252684
- if( res<0 ) p->rc = FTS5_CORRUPT;
253522
+ if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
252685253523
}
252686253524
252687
- fts5IntegrityCheckPgidx(p, pLeaf);
253525
+ fts5IntegrityCheckPgidx(p, iRow, pLeaf);
252688253526
}
252689253527
fts5DataRelease(pLeaf);
252690253528
if( p->rc ) break;
252691253529
252692253530
/* Now check that the iter.nEmpty leaves following the current leaf
@@ -252712,11 +253550,11 @@
252712253550
/* Check any rowid-less pages that occur before the current leaf. */
252713253551
for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
252714253552
iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
252715253553
pLeaf = fts5DataRead(p, iKey);
252716253554
if( pLeaf ){
252717
- if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
253555
+ if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey);
252718253556
fts5DataRelease(pLeaf);
252719253557
}
252720253558
}
252721253559
iPrevLeaf = fts5DlidxIterPgno(pDlidx);
252722253560
@@ -252727,16 +253565,16 @@
252727253565
if( pLeaf ){
252728253566
i64 iRowid;
252729253567
int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252730253568
ASSERT_SZLEAF_OK(pLeaf);
252731253569
if( iRowidOff>=pLeaf->szLeaf ){
252732
- p->rc = FTS5_CORRUPT;
253570
+ FTS5_CORRUPT_ROWID(p, iKey);
252733253571
}else if( bSecureDelete==0 || iRowidOff>0 ){
252734253572
i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
252735253573
fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
252736253574
if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252737
- p->rc = FTS5_CORRUPT;
253575
+ FTS5_CORRUPT_ROWID(p, iKey);
252738253576
}
252739253577
}
252740253578
fts5DataRelease(pLeaf);
252741253579
}
252742253580
}
@@ -252784,10 +253622,11 @@
252784253622
252785253623
#ifdef SQLITE_DEBUG
252786253624
/* Used by extra internal tests only run if NDEBUG is not defined */
252787253625
u64 cksum3 = 0; /* Checksum based on contents of indexes */
252788253626
Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
253627
+ int bTestFail = 0;
252789253628
#endif
252790253629
const int flags = FTS5INDEX_QUERY_NOOUTPUT;
252791253630
252792253631
/* Load the FTS index structure */
252793253632
pStruct = fts5StructureRead(p);
@@ -252826,11 +253665,11 @@
252826253665
int iOff = 0; /* Offset within poslist */
252827253666
i64 iRowid = fts5MultiIterRowid(pIter);
252828253667
char *z = (char*)fts5MultiIterTerm(pIter, &n);
252829253668
252830253669
/* If this is a new term, query for it. Update cksum3 with the results. */
252831
- fts5TestTerm(p, &term, z, n, cksum2, &cksum3);
253670
+ fts5TestTerm(p, &term, z, n, cksum2, &cksum3, &bTestFail);
252832253671
if( p->rc ) break;
252833253672
252834253673
if( eDetail==FTS5_DETAIL_NONE ){
252835253674
if( 0==fts5MultiIterIsEmpty(p, pIter) ){
252836253675
cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
@@ -252844,19 +253683,30 @@
252844253683
int iTokOff = FTS5_POS2OFFSET(iPos);
252845253684
cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, iCol, iTokOff, -1, z, n);
252846253685
}
252847253686
}
252848253687
}
252849
- fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
253688
+ fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3, &bTestFail);
252850253689
252851253690
fts5MultiIterFree(pIter);
252852
- if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ) p->rc = FTS5_CORRUPT;
252853
-
252854
- fts5StructureRelease(pStruct);
253691
+ if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
253692
+ p->rc = FTS5_CORRUPT;
253693
+ sqlite3Fts5ConfigErrmsg(p->pConfig,
253694
+ "fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
253695
+ );
253696
+ }
252855253697
#ifdef SQLITE_DEBUG
253698
+ /* In SQLITE_DEBUG builds, expensive extra checks were run as part of
253699
+ ** the integrity-check above. If no other errors were detected, but one
253700
+ ** of these tests failed, set the result to SQLITE_CORRUPT_VTAB here. */
253701
+ if( p->rc==SQLITE_OK && bTestFail ){
253702
+ p->rc = FTS5_CORRUPT;
253703
+ }
252856253704
fts5BufferFree(&term);
252857253705
#endif
253706
+
253707
+ fts5StructureRelease(pStruct);
252858253708
fts5BufferFree(&poslist);
252859253709
return fts5IndexReturn(p);
252860253710
}
252861253711
252862253712
/*************************************************************************
@@ -257263,11 +258113,11 @@
257263258113
int nArg, /* Number of args */
257264258114
sqlite3_value **apUnused /* Function arguments */
257265258115
){
257266258116
assert( nArg==0 );
257267258117
UNUSED_PARAM2(nArg, apUnused);
257268
- sqlite3_result_text(pCtx, "fts5: 2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849", -1, SQLITE_TRANSIENT);
258118
+ sqlite3_result_text(pCtx, "fts5: 2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839", -1, SQLITE_TRANSIENT);
257269258119
}
257270258120
257271258121
/*
257272258122
** Implementation of fts5_locale(LOCALE, TEXT) function.
257273258123
**
@@ -257386,12 +258236,13 @@
257386258236
}else{
257387258237
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
257388258238
" FTS5 table %s.%s: %s",
257389258239
zSchema, zTabname, sqlite3_errstr(rc));
257390258240
}
258241
+ }else if( (rc&0xff)==SQLITE_CORRUPT ){
258242
+ rc = SQLITE_OK;
257391258243
}
257392
-
257393258244
sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
257394258245
pTab->p.pConfig->pzErrmsg = 0;
257395258246
257396258247
return rc;
257397258248
}
@@ -258078,10 +258929,11 @@
258078258929
ctx.pStorage = p;
258079258930
ctx.iCol = -1;
258080258931
for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258081258932
if( pConfig->abUnindexed[iCol-1]==0 ){
258082258933
sqlite3_value *pVal = 0;
258934
+ sqlite3_value *pFree = 0;
258083258935
const char *pText = 0;
258084258936
int nText = 0;
258085258937
const char *pLoc = 0;
258086258938
int nLoc = 0;
258087258939
@@ -258094,15 +258946,26 @@
258094258946
}
258095258947
258096258948
if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258097258949
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258098258950
}else{
258099
- pText = (const char*)sqlite3_value_text(pVal);
258100
- nText = sqlite3_value_bytes(pVal);
258101
- if( pConfig->bLocale && pSeek ){
258102
- pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol);
258103
- nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258951
+ if( sqlite3_value_type(pVal)!=SQLITE_TEXT ){
258952
+ /* Make a copy of the value to work with. This is because the call
258953
+ ** to sqlite3_value_text() below forces the type of the value to
258954
+ ** SQLITE_TEXT, and we may need to use it again later. */
258955
+ pFree = pVal = sqlite3_value_dup(pVal);
258956
+ if( pVal==0 ){
258957
+ rc = SQLITE_NOMEM;
258958
+ }
258959
+ }
258960
+ if( rc==SQLITE_OK ){
258961
+ pText = (const char*)sqlite3_value_text(pVal);
258962
+ nText = sqlite3_value_bytes(pVal);
258963
+ if( pConfig->bLocale && pSeek ){
258964
+ pLoc = (const char*)sqlite3_column_text(pSeek, iCol+pConfig->nCol);
258965
+ nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258966
+ }
258104258967
}
258105258968
}
258106258969
258107258970
if( rc==SQLITE_OK ){
258108258971
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258114,10 +258977,11 @@
258114258977
if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258115258978
rc = FTS5_CORRUPT;
258116258979
}
258117258980
sqlite3Fts5ClearLocale(pConfig);
258118258981
}
258982
+ sqlite3_value_free(pFree);
258119258983
}
258120258984
}
258121258985
if( rc==SQLITE_OK && p->nTotalRow<1 ){
258122258986
rc = FTS5_CORRUPT;
258123258987
}else{
258124258988
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** 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
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 20abf1ec107f942e4527901685d61283c9c2 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
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"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -485,13 +485,13 @@
485 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
486 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
487 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
488 ** </pre></blockquote>)^
489 **
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()
493 ** function is provided for use in DLLs since DLL users usually do not have
494 ** direct access to string constants within the DLL. ^The
495 ** sqlite3_libversion_number() function returns an integer equal to
496 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
497 ** a pointer to a string constant whose value is the same as the
@@ -687,11 +687,11 @@
687 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
688 ** that allows an application to run multiple statements of SQL
689 ** without having to use a lot of C code.
690 **
691 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
692 ** semicolon-separate SQL statements passed into its 2nd argument,
693 ** in the context of the [database connection] passed in as its 1st
694 ** argument. ^If the callback function of the 3rd argument to
695 ** sqlite3_exec() is not NULL, then it is invoked for each result row
696 ** coming out of the evaluated SQL statements. ^The 4th argument to
697 ** sqlite3_exec() is relayed through to the 1st argument of each
@@ -720,11 +720,11 @@
720 ** callback is an array of pointers to strings obtained as if from
721 ** [sqlite3_column_text()], one for each column. ^If an element of a
722 ** result row is NULL then the corresponding string pointer for the
723 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
724 ** sqlite3_exec() callback is an array of pointers to strings where each
725 ** entry represents the name of corresponding result column as obtained
726 ** from [sqlite3_column_name()].
727 **
728 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
729 ** to an empty string, or a pointer that contains only whitespace and/or
730 ** SQL comments, then no SQL statements are evaluated and the database
@@ -906,11 +906,11 @@
906 ** Applications should not depend on the historical behavior.
907 **
908 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
909 ** [sqlite3_open_v2()] does *not* cause the underlying database file
910 ** 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
912 ** error in future versions of SQLite.
913 */
914 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
915 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
916 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -1000,11 +1000,11 @@
1000 ** CAPI3REF: File Locking Levels
1001 **
1002 ** SQLite uses one of these integer values as the second
1003 ** argument to calls it makes to the xLock() and xUnlock() methods
1004 ** of an [sqlite3_io_methods] object. These values are ordered from
1005 ** lest restrictive to most restrictive.
1006 **
1007 ** The argument to xLock() is always SHARED or higher. The argument to
1008 ** xUnlock is either SHARED or NONE.
1009 */
1010 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -1316,11 +1316,11 @@
1316 ** reason, the entire database file will be overwritten by the current
1317 ** transaction. This is used by VACUUM operations.
1318 **
1319 ** <li>[[SQLITE_FCNTL_VFSNAME]]
1320 ** ^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
1322 ** final bottom-level VFS are written into memory obtained from
1323 ** [sqlite3_malloc()] and the result is stored in the char* variable
1324 ** that the fourth parameter of [sqlite3_file_control()] points to.
1325 ** The caller is responsible for freeing the memory when done. As with
1326 ** all file-control actions, there is no guarantee that this will actually
@@ -1330,11 +1330,11 @@
1330 **
1331 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1332 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1333 ** [VFSes] currently in use. ^(The argument X in
1334 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1335 ** of type "[sqlite3_vfs] **". This opcodes will set *X
1336 ** to a pointer to the top-level VFS.)^
1337 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1338 ** upper-most shim only.
1339 **
1340 ** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1520,11 +1520,11 @@
1520 ** record the fact that the pages have been checkpointed.
1521 **
1522 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1523 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1524 ** 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
1526 ** (void*) argument passed with this file-control should be a pointer to a
1527 ** value of type (int). The integer value is set to 1 if the database is a wal
1528 ** mode database and there exists at least one client in another process that
1529 ** currently has an SQL transaction open on the database. It is set to 0 if
1530 ** the database is not a wal-mode db, or if there is no such connection in any
@@ -1945,11 +1945,11 @@
1945 **
1946 ** ^The sqlite3_initialize() routine is called internally by many other
1947 ** SQLite interfaces so that an application usually does not need to
1948 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1949 ** calls sqlite3_initialize() so the SQLite library will be automatically
1950 ** initialized when [sqlite3_open()] is called if it has not be initialized
1951 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1952 ** compile-time option, then the automatic calls to sqlite3_initialize()
1953 ** are omitted and the application must call sqlite3_initialize() directly
1954 ** prior to using any other SQLite interface. For maximum portability,
1955 ** it is recommended that applications always invoke sqlite3_initialize()
@@ -2202,25 +2202,25 @@
2202 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
2203 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
2204 ** The [sqlite3_mem_methods]
2205 ** structure is filled with the currently defined memory allocation routines.)^
2206 ** This option can be used to overload the default memory allocation
2207 ** routines with a wrapper that simulations memory allocation failure or
2208 ** tracks memory usage, for example. </dd>
2209 **
2210 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2211 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
2212 ** type int, interpreted as a boolean, which if true provides a hint to
2213 ** SQLite that it should avoid large memory allocations if possible.
2214 ** 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
2216 ** guarantees about memory fragmentation that are possible if large
2217 ** allocations are avoided. This hint is normally off.
2218 ** </dd>
2219 **
2220 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2221 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
2222 ** interpreted as a boolean, which enables or disables the collection of
2223 ** memory allocation statistics. ^(When memory allocation statistics are
2224 ** disabled, the following SQLite interfaces become non-operational:
2225 ** <ul>
2226 ** <li> [sqlite3_hard_heap_limit64()]
@@ -2261,11 +2261,11 @@
2261 ** a page cache line is larger than sz bytes or if all of the pMem buffer
2262 ** is exhausted.
2263 ** ^If pMem is NULL and N is non-zero, then each database connection
2264 ** does an initial bulk allocation for page cache memory
2265 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
2266 ** of -1024*N bytes if N is negative, . ^If additional
2267 ** page cache memory is needed beyond what is provided by the initial
2268 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
2269 ** additional cache line. </dd>
2270 **
2271 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -2290,11 +2290,11 @@
2290 **
2291 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
2292 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
2293 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
2294 ** 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
2296 ** the content of the [sqlite3_mutex_methods] structure before the call to
2297 ** [sqlite3_config()] returns. ^If SQLite is compiled with
2298 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2299 ** the entire mutexing subsystem is omitted from the build and hence calls to
2300 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2332,11 +2332,11 @@
2332 ** the interface to a custom page cache implementation.)^
2333 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2334 **
2335 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2336 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2337 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
2338 ** the current page cache implementation into that object.)^ </dd>
2339 **
2340 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2341 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2342 ** global [error log].
@@ -2349,11 +2349,11 @@
2349 ** passed through as the first parameter to the application-defined logger
2350 ** function whenever that function is invoked. ^The second parameter to
2351 ** the logger function is a copy of the first parameter to the corresponding
2352 ** [sqlite3_log()] call and is intended to be a [result code] or an
2353 ** [extended result code]. ^The third parameter passed to the logger is
2354 ** log message after formatting via [sqlite3_snprintf()].
2355 ** The SQLite logging interface is not reentrant; the logger function
2356 ** supplied by the application must not invoke any SQLite interface.
2357 ** In a multi-threaded application, the application-defined logger
2358 ** function must be threadsafe. </dd>
2359 **
@@ -2540,11 +2540,11 @@
2540 ** CAPI3REF: Database Connection Configuration Options
2541 **
2542 ** These constants are the available integer configuration options that
2543 ** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2544 **
2545 ** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2546 ** variable number of parameters, though always at least two. The number of
2547 ** parameters passed into sqlite3_db_config() depends on which of these
2548 ** constants is given as the second parameter. This documentation page
2549 ** refers to parameters beyond the second as "arguments". Thus, when this
2550 ** page says "the N-th argument" it means "the N-th parameter past the
@@ -2674,12 +2674,12 @@
2674 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2675 ** There must be two additional arguments.
2676 ** When the first argument to this interface is 1, then only the C-API is
2677 ** enabled and the SQL function remains disabled. If the first argument to
2678 ** 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.
2681 ** The second parameter is a pointer to an integer into which
2682 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2683 ** is disabled or enabled following this call. The second parameter may
2684 ** be a NULL pointer, in which case the new setting is not reported back.
2685 ** </dd>
@@ -2793,11 +2793,11 @@
2793 ** </dd>
2794 **
2795 ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2796 ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2797 ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2798 ** the legacy behavior of the [ALTER TABLE RENAME] command such it
2799 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2800 ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2801 ** additional information. This feature can also be turned on and off
2802 ** using the [PRAGMA legacy_alter_table] statement.
2803 ** </dd>
@@ -2842,11 +2842,11 @@
2842 **
2843 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2844 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2845 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2846 ** 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
2848 ** integer found at offset 44 into the database header) of 1. This in turn
2849 ** means that the resulting database file will be readable and writable by
2850 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2851 ** newly created databases are generally not understandable by SQLite versions
2852 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2869,11 +2869,11 @@
2869 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2870 ** statistics. For statistics to be collected, the flag must be set on
2871 ** the database handle both when the SQL statement is prepared and when it
2872 ** is stepped. The flag is set (collection of statistics is enabled)
2873 ** 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
2875 ** leave unchanged the statement scanstatus option. If the second argument
2876 ** is not NULL, then the value of the statement scanstatus setting after
2877 ** processing the first argument is written into the integer that the second
2878 ** argument points to.
2879 ** </dd>
@@ -2912,12 +2912,12 @@
2912 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2913 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2914 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2915 ** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2916 ** 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,
2919 ** but the database will be opened read-only. If this option is disabled,
2920 ** then the ability to create a new database using [ATTACH] is also disabled,
2921 ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2922 ** option.<p>
2923 ** This option takes two arguments which are an integer and a pointer
@@ -2947,11 +2947,11 @@
2947 **
2948 ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2949 **
2950 ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2951 ** 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.
2953 ** The second argument is a pointer to an integer. If the first argument is 1,
2954 ** then the option becomes enabled. If the first integer argument is 0, then the
2955 ** option is disabled. If the first argument is -1, then the option setting
2956 ** is unchanged. The second argument, the pointer to an integer, may be NULL.
2957 ** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -3237,11 +3237,11 @@
3237 ** and comments that follow the final semicolon are ignored.
3238 **
3239 ** ^These routines return 0 if the statement is incomplete. ^If a
3240 ** memory allocation fails, then SQLITE_NOMEM is returned.
3241 **
3242 ** ^These routines do not parse the SQL statements thus
3243 ** will not detect syntactically incorrect SQL.
3244 **
3245 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
3246 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
3247 ** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3354,11 +3354,11 @@
3354 ** Passing 0 to this function disables blocking locks altogether. Passing
3355 ** -1 to this function requests that the VFS blocks for a long time -
3356 ** indefinitely if possible. The results of passing any other negative value
3357 ** are undefined.
3358 **
3359 ** Internally, each SQLite database handle store two timeout values - the
3360 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3361 ** support blocking locks) and the setlk-timeout (used for blocking locks
3362 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3363 ** values, this function sets only the setlk-timeout value. Therefore,
3364 ** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3384,11 +3384,11 @@
3384 ** METHOD: sqlite3
3385 **
3386 ** This is a legacy interface that is preserved for backwards compatibility.
3387 ** Use of this interface is not recommended.
3388 **
3389 ** Definition: A <b>result table</b> is memory data structure created by the
3390 ** [sqlite3_get_table()] interface. A result table records the
3391 ** complete query results from one or more queries.
3392 **
3393 ** The table conceptually has a number of rows and columns. But
3394 ** these numbers are not part of the result table itself. These
@@ -3527,11 +3527,11 @@
3527 ** of a signed 32-bit integer.
3528 **
3529 ** ^Calling sqlite3_free() with a pointer previously returned
3530 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3531 ** 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
3533 ** to sqlite3_free() is harmless. After being freed, memory
3534 ** should neither be read nor written. Even reading previously freed
3535 ** memory might result in a segmentation fault or other severe error.
3536 ** Memory corruption, a segmentation fault, or other severe error
3537 ** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3545,17 +3545,17 @@
3545 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3546 ** negative then the behavior is exactly the same as calling
3547 ** sqlite3_free(X).
3548 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3549 ** 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
3552 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
3553 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3554 ** prior allocation is not freed.
3555 **
3556 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
3557 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3558 ** of a 32-bit signed integer.
3559 **
3560 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3561 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3601,11 +3601,11 @@
3601 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
3602 ** value of [sqlite3_memory_used()] since the high-water mark
3603 ** was last reset. ^The values returned by [sqlite3_memory_used()] and
3604 ** [sqlite3_memory_highwater()] include any overhead
3605 ** added by SQLite in its implementation of [sqlite3_malloc()],
3606 ** but not overhead added by the any underlying system library
3607 ** routines that [sqlite3_malloc()] may call.
3608 **
3609 ** ^The memory high-water mark is reset to the current value of
3610 ** [sqlite3_memory_used()] if and only if the parameter to
3611 ** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -4053,19 +4053,19 @@
4053 ** attempt to use the same database connection at the same time.
4054 ** (Mutexes will block any actual concurrency, but in this mode
4055 ** there is no harm in trying.)
4056 **
4057 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
4058 ** <dd>The database is opened [shared cache] enabled, overriding
4059 ** the default shared cache setting provided by
4060 ** [sqlite3_enable_shared_cache()].)^
4061 ** The [use of shared cache mode is discouraged] and hence shared cache
4062 ** capabilities may be omitted from many builds of SQLite. In such cases,
4063 ** this option is a no-op.
4064 **
4065 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
4066 ** <dd>The database is opened [shared cache] disabled, overriding
4067 ** the default shared cache setting provided by
4068 ** [sqlite3_enable_shared_cache()].)^
4069 **
4070 ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
4071 ** <dd>The database connection comes up in "extended result code mode".
@@ -4396,11 +4396,11 @@
4396 ** These interfaces are provided for use by [VFS shim] implementations and
4397 ** are not useful outside of that context.
4398 **
4399 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4400 ** database filename D with corresponding journal file J and WAL file W and
4401 ** with N URI parameters key/values pairs in the array P. The result from
4402 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4403 ** is safe to pass to routines like:
4404 ** <ul>
4405 ** <li> [sqlite3_uri_parameter()],
4406 ** <li> [sqlite3_uri_boolean()],
@@ -4479,19 +4479,19 @@
4479 ** The application does not need to worry about freeing the result.
4480 ** However, the error string might be overwritten or deallocated by
4481 ** subsequent calls to other SQLite interface functions.)^
4482 **
4483 ** ^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
4485 ** result code for which a text error message is available.
4486 ** ^(Memory to hold the error message string is managed internally
4487 ** and must not be freed by the application)^.
4488 **
4489 ** ^If the most recent error references a specific token in the input
4490 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4491 ** of the start of that token. ^The byte offset returned by
4492 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4493 ** ^If the most recent error does not reference a specific token in the input
4494 ** SQL, then the sqlite3_error_offset() function returns -1.
4495 **
4496 ** When the serialized [threading mode] is in use, it might be the
4497 ** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
4586 ** CAPI3REF: Run-Time Limit Categories
4587 ** KEYWORDS: {limit category} {*limit categories}
4588 **
4589 ** These constants define various performance limits
4590 ** 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].
4593 **
4594 ** <dl>
4595 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4596 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4597 **
@@ -4652,11 +4652,11 @@
4652 #define SQLITE_LIMIT_WORKER_THREADS 11
4653
4654 /*
4655 ** CAPI3REF: Prepare Flags
4656 **
4657 ** These constants define various flags that can be passed into
4658 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4659 ** [sqlite3_prepare16_v3()] interfaces.
4660 **
4661 ** New flags may be added in future releases of SQLite.
4662 **
@@ -4739,11 +4739,11 @@
4739 ** statement is generated.
4740 ** If the caller knows that the supplied string is nul-terminated, then
4741 ** there is a small performance advantage to passing an nByte parameter that
4742 ** is the number of bytes in the input string <i>including</i>
4743 ** the nul-terminator.
4744 ** Note that nByte measure the length of the input in bytes, not
4745 ** characters, even for the UTF-16 interfaces.
4746 **
4747 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4748 ** past the end of the first SQL statement in zSql. These routines only
4749 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
4873 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4874 ** will return "SELECT 2345,NULL".)^
4875 **
4876 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4877 ** is available to hold the result, or if the result would exceed the
4878 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4879 **
4880 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4881 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4882 ** option causes sqlite3_expanded_sql() to always return NULL.
4883 **
@@ -5061,11 +5061,11 @@
5061 /*
5062 ** CAPI3REF: SQL Function Context Object
5063 **
5064 ** The context in which an SQL function executes is stored in an
5065 ** sqlite3_context object. ^A pointer to an sqlite3_context object
5066 ** is always first parameter to [application-defined SQL functions].
5067 ** The application-defined SQL function implementation will pass this
5068 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
5069 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
5070 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
5071 ** and/or [sqlite3_set_auxdata()].
@@ -5077,11 +5077,11 @@
5077 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
5078 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
5079 ** METHOD: sqlite3_stmt
5080 **
5081 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
5082 ** literals may be replaced by a [parameter] that matches one of following
5083 ** templates:
5084 **
5085 ** <ul>
5086 ** <li> ?
5087 ** <li> ?NNN
@@ -5122,11 +5122,11 @@
5122 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5123 ** otherwise.
5124 **
5125 ** [[byte-order determination rules]] ^The byte-order of
5126 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5127 ** found in first character, which is removed, or in the absence of a BOM
5128 ** the byte order is the native byte order of the host
5129 ** machine for sqlite3_bind_text16() or the byte order specified in
5130 ** the 6th parameter for sqlite3_bind_text64().)^
5131 ** ^If UTF16 input text contains invalid unicode
5132 ** characters, then SQLite might change those invalid characters
@@ -5142,11 +5142,11 @@
5142 ** the behavior is undefined.
5143 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5144 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5145 ** that parameter must be the byte offset
5146 ** where the NUL terminator would occur assuming the string were NUL
5147 ** terminated. If any NUL characters occurs at byte offsets less than
5148 ** the value of the fourth parameter then the resulting string value will
5149 ** contain embedded NULs. The result of expressions involving strings
5150 ** with embedded NULs is undefined.
5151 **
5152 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5354,11 +5354,11 @@
5354 /*
5355 ** CAPI3REF: Source Of Data In A Query Result
5356 ** METHOD: sqlite3_stmt
5357 **
5358 ** ^These routines provide a means to determine the database, table, and
5359 ** table column that is the origin of a particular result column in
5360 ** [SELECT] statement.
5361 ** ^The name of the database or table or column can be returned as
5362 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5363 ** the database name, the _table_ routines return the table name, and
5364 ** the origin_ routines return the column name.
@@ -5798,11 +5798,11 @@
5798 ** CAPI3REF: Destroy A Prepared Statement Object
5799 ** DESTRUCTOR: sqlite3_stmt
5800 **
5801 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5802 ** ^If the most recent evaluation of the statement encountered no errors
5803 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
5804 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5805 ** sqlite3_finalize(S) returns the appropriate [error code] or
5806 ** [extended error code].
5807 **
5808 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5923,12 +5923,12 @@
5923 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5924 ** index expressions, or the WHERE clause of partial indexes.
5925 **
5926 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5927 ** all application-defined SQL functions that do not need to be
5928 ** used inside of triggers, view, CHECK constraints, or other elements of
5929 ** the database schema. This flags is especially recommended for SQL
5930 ** functions that have side effects or reveal internal application state.
5931 ** Without this flag, an attacker might be able to modify the schema of
5932 ** a database file to include invocations of the function with parameters
5933 ** chosen by the attacker, which the application will then execute when
5934 ** the database file is opened and read.
@@ -5955,11 +5955,11 @@
5955 ** or aggregate window function. More details regarding the implementation
5956 ** of aggregate window functions are
5957 ** [user-defined window functions|available here].
5958 **
5959 ** ^(If the final parameter to sqlite3_create_function_v2() or
5960 ** sqlite3_create_window_function() is not NULL, then it is destructor for
5961 ** the application data pointer. The destructor is invoked when the function
5962 ** is deleted, either by being overloaded or when the database connection
5963 ** closes.)^ ^The destructor is also invoked if the call to
5964 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5965 ** invoked, it is passed a single argument which is a copy of the application
@@ -6030,11 +6030,11 @@
6030 );
6031
6032 /*
6033 ** CAPI3REF: Text Encodings
6034 **
6035 ** These constant define integer codes that represent the various
6036 ** text encodings supported by SQLite.
6037 */
6038 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
6039 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
6040 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
6122 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
6123 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
6124 ** result.
6125 ** Every function that invokes [sqlite3_result_subtype()] should have this
6126 ** 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
6128 ** [expression index]. On the other hand, SQL functions that never invoke
6129 ** [sqlite3_result_subtype()] should avoid setting this property, as the
6130 ** purpose of this property is to disable certain optimizations that are
6131 ** incompatible with subtypes.
6132 **
@@ -6249,11 +6249,11 @@
6249 **
6250 ** ^Within the [xUpdate] method of a [virtual table], the
6251 ** sqlite3_value_nochange(X) interface returns true if and only if
6252 ** the column corresponding to X is unchanged by the UPDATE operation
6253 ** that the xUpdate method call was invoked to implement and if
6254 ** and the prior [xColumn] method call that was invoked to extracted
6255 ** the value for that column returned without setting a result (probably
6256 ** because it queried [sqlite3_vtab_nochange()] and found that the column
6257 ** was unchanging). ^Within an [xUpdate] method, any value for which
6258 ** sqlite3_value_nochange(X) is true will in all other respects appear
6259 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6355,11 +6355,11 @@
6355 /*
6356 ** CAPI3REF: Copy And Free SQL Values
6357 ** METHOD: sqlite3_value
6358 **
6359 ** ^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
6361 ** is a [protected sqlite3_value] object even if the input is not.
6362 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
6363 ** memory allocation fails. ^If V is a [pointer value], then the result
6364 ** of sqlite3_value_dup(V) is a NULL value.
6365 **
@@ -6393,11 +6393,11 @@
6393 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
6394 ** when first called if N is less than or equal to zero or if a memory
6395 ** allocation error occurs.
6396 **
6397 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6398 ** determined by the N parameter on first successful call. Changing the
6399 ** value of N in any subsequent call to sqlite3_aggregate_context() within
6400 ** the same aggregate function instance will not resize the memory
6401 ** allocation.)^ Within the xFinal callback, it is customary to set
6402 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6403 ** pointless memory allocations occur.
@@ -6555,11 +6555,11 @@
6555 ** of as a secret key such that only code that knows the secret key is able
6556 ** to access the associated data.
6557 **
6558 ** Security Warning: These interfaces should not be exposed in scripting
6559 ** 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
6561 ** can probably also take control of the process.
6562 **
6563 ** Database connection client data is only available for SQLite
6564 ** version 3.44.0 ([dateof:3.44.0]) and later.
6565 **
@@ -6669,11 +6669,11 @@
6669 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6670 ** is non-negative, then as many bytes (not characters) of the text
6671 ** pointed to by the 2nd parameter are taken as the application-defined
6672 ** function result. If the 3rd parameter is non-negative, then it
6673 ** 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
6675 ** in the string at a byte offset that is less than the value of the 3rd
6676 ** parameter, then the resulting string will contain embedded NULs and the
6677 ** result of expressions operating on strings with embedded NULs is undefined.
6678 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6679 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6727,11 +6727,11 @@
6727 ** for the P parameter. ^SQLite invokes D with P as its only argument
6728 ** when SQLite is finished with P. The T parameter should be a static
6729 ** string and preferably a string literal. The sqlite3_result_pointer()
6730 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6731 **
6732 ** If these routines are called from within the different thread
6733 ** than the one containing the application-defined function that received
6734 ** the [sqlite3_context] pointer, the results are undefined.
6735 */
6736 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
6737 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -7133,11 +7133,11 @@
7133 /*
7134 ** CAPI3REF: Return The Schema Name For A Database Connection
7135 ** METHOD: sqlite3
7136 **
7137 ** ^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
7139 ** out of range. An N value of 0 means the main database file. An N of 1 is
7140 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
7141 ** databases.
7142 **
7143 ** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -7228,20 +7228,20 @@
7228 **
7229 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
7230 ** <dd>The SQLITE_TXN_READ state means that the database is currently
7231 ** in a read transaction. Content has been read from the database file
7232 ** 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
7234 ** no other conflicting concurrent write transactions. The transaction
7235 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
7236 ** [COMMIT].</dd>
7237 **
7238 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
7239 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
7240 ** in a write transaction. Content has been written to the database file
7241 ** but has not yet committed. The transaction state will change to
7242 ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7243 */
7244 #define SQLITE_TXN_NONE 0
7245 #define SQLITE_TXN_READ 1
7246 #define SQLITE_TXN_WRITE 2
7247
@@ -7518,11 +7518,11 @@
7518
7519 /*
7520 ** CAPI3REF: Impose A Limit On Heap Size
7521 **
7522 ** These interfaces impose limits on the amount of heap memory that will be
7523 ** by all database connections within a single process.
7524 **
7525 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
7526 ** soft limit on the amount of heap memory that may be allocated by SQLite.
7527 ** ^SQLite strives to keep heap memory utilization below the soft heap
7528 ** limit by reducing the number of pages held in the page cache
@@ -7576,11 +7576,11 @@
7576 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
7577 ** from the heap.
7578 ** </ul>)^
7579 **
7580 ** The circumstances under which SQLite will enforce the heap limits may
7581 ** changes in future releases of SQLite.
7582 */
7583 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7584 SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
7585
7586 /*
@@ -7691,12 +7691,12 @@
7691 ** be tried also.
7692 **
7693 ** ^The entry point is zProc.
7694 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7695 ** 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
7698 ** characters in the filename from the last "/" to the first following
7699 ** "." and omitting any initial "lib".)^
7700 ** ^The sqlite3_load_extension() interface returns
7701 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7702 ** ^If an error occurs and pzErrMsg is not 0, then the
@@ -7763,11 +7763,11 @@
7763 ** that is to be automatically loaded into all new database connections.
7764 **
7765 ** ^(Even though the function prototype shows that xEntryPoint() takes
7766 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7767 ** arguments and expects an integer result as if the signature of the
7768 ** entry point where as follows:
7769 **
7770 ** <blockquote><pre>
7771 ** &nbsp; int xEntryPoint(
7772 ** &nbsp; sqlite3 *db,
7773 ** &nbsp; const char **pzErrMsg,
@@ -7927,11 +7927,11 @@
7927 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7928 ** is true, then the constraint is assumed to be fully handled by the
7929 ** virtual table and might not be checked again by the byte code.)^ ^(The
7930 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7931 ** 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
7933 ** the constraint may or may not be checked in byte code. In other words,
7934 ** when the omit flag is true there is no guarantee that the constraint will
7935 ** not be checked again using byte code.)^
7936 **
7937 ** ^The idxNum and idxStr values are recorded and passed into the
@@ -7953,11 +7953,11 @@
7953 ** will be returned by the strategy.
7954 **
7955 ** The xBestIndex method may optionally populate the idxFlags field with a
7956 ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7957 ** [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
7959 ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7960 ** return at most one row.
7961 **
7962 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7963 ** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -8094,11 +8094,11 @@
8094 ** by the first parameter. ^The name of the module is given by the
8095 ** second parameter. ^The third parameter is a pointer to
8096 ** the implementation of the [virtual table module]. ^The fourth
8097 ** parameter is an arbitrary client data pointer that is passed through
8098 ** into the [xCreate] and [xConnect] methods of the virtual table module
8099 ** when a new virtual table is be being created or reinitialized.
8100 **
8101 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
8102 ** is a pointer to a destructor for the pClientData. ^SQLite will
8103 ** invoke the destructor function (if it is not NULL) when SQLite
8104 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -8259,11 +8259,11 @@
8259 **
8260 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
8261 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
8262 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
8263 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
8264 ** on *ppBlob after this function it returns.
8265 **
8266 ** This function fails with SQLITE_ERROR if any of the following are true:
8267 ** <ul>
8268 ** <li> ^(Database zDb does not exist)^,
8269 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8379,11 +8379,11 @@
8379 ** CAPI3REF: Return The Size Of An Open BLOB
8380 ** METHOD: sqlite3_blob
8381 **
8382 ** ^Returns the size in bytes of the BLOB accessible via the
8383 ** successfully opened [BLOB handle] in its only argument. ^The
8384 ** incremental blob I/O routines can only read or overwriting existing
8385 ** blob content; they cannot change the size of a blob.
8386 **
8387 ** This routine only works on a [BLOB handle] which has been created
8388 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8389 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -8529,11 +8529,11 @@
8529 ** function that calls sqlite3_initialize().
8530 **
8531 ** ^The sqlite3_mutex_alloc() routine allocates a new
8532 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8533 ** routine returns NULL if it is unable to allocate the requested
8534 ** mutex. The argument to sqlite3_mutex_alloc() must one of these
8535 ** integer constants:
8536 **
8537 ** <ul>
8538 ** <li> SQLITE_MUTEX_FAST
8539 ** <li> SQLITE_MUTEX_RECURSIVE
@@ -8762,11 +8762,11 @@
8762
8763 /*
8764 ** CAPI3REF: Retrieve the mutex for a database connection
8765 ** METHOD: sqlite3
8766 **
8767 ** ^This interface returns a pointer the [sqlite3_mutex] object that
8768 ** serializes access to the [database connection] given in the argument
8769 ** when the [threading mode] is Serialized.
8770 ** ^If the [threading mode] is Single-thread or Multi-thread then this
8771 ** routine returns a NULL pointer.
8772 */
@@ -8885,11 +8885,11 @@
8885
8886 /*
8887 ** CAPI3REF: SQL Keyword Checking
8888 **
8889 ** These routines provide access to the set of SQL language keywords
8890 ** recognized by SQLite. Applications can uses these routines to determine
8891 ** whether or not a specific identifier needs to be escaped (for example,
8892 ** by enclosing in double-quotes) so as not to confuse the parser.
8893 **
8894 ** The sqlite3_keyword_count() interface returns the number of distinct
8895 ** keywords understood by SQLite.
@@ -9053,11 +9053,11 @@
9053 **
9054 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
9055 ** content of the dynamic string under construction in X. The value
9056 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
9057 ** and might be freed or altered by any subsequent method on the same
9058 ** [sqlite3_str] object. Applications must not used the pointer returned
9059 ** [sqlite3_str_value(X)] after any subsequent method call on the same
9060 ** object. ^Applications may change the content of the string returned
9061 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
9062 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
9063 ** write any byte after any subsequent sqlite3_str method call.
@@ -9139,11 +9139,11 @@
9139 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
9140 ** <dd>This parameter returns the number of bytes of page cache
9141 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
9142 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
9143 ** returned value includes allocations that overflowed because they
9144 ** where too large (they were larger than the "sz" parameter to
9145 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
9146 ** no space was left in the page cache.</dd>)^
9147 **
9148 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
9149 ** <dd>This parameter records the largest memory allocation request
@@ -9223,53 +9223,55 @@
9223 ** checked out.</dd>)^
9224 **
9225 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
9226 ** <dd>This parameter returns the number of malloc attempts that were
9227 ** satisfied using lookaside memory. Only the high-water value is meaningful;
9228 ** the current value is always zero.)^
9229 **
9230 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
9231 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
9232 ** <dd>This parameter returns the number malloc attempts that might have
9233 ** been satisfied using lookaside memory but failed due to the amount of
9234 ** memory requested being larger than the lookaside slot size.
9235 ** Only the high-water value is meaningful;
9236 ** the current value is always zero.)^
9237 **
9238 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
9239 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
9240 ** <dd>This parameter returns the number malloc attempts that might have
9241 ** been satisfied using lookaside memory but failed due to all lookaside
9242 ** memory already being in use.
9243 ** Only the high-water value is meaningful;
9244 ** the current value is always zero.)^
9245 **
9246 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
9247 ** <dd>This parameter returns the approximate number of bytes of heap
9248 ** memory used by all pager caches associated with the database connection.)^
9249 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 
9250 **
9251 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
9252 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
9253 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
9254 ** pager cache is shared between two or more connections the bytes of heap
9255 ** memory used by that pager cache is divided evenly between the attached
9256 ** connections.)^ In other words, if none of the pager caches associated
9257 ** 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 ** shared, the value returned by this call will be smaller than that returned
9260 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
9261 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
9262 **
9263 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
9264 ** <dd>This parameter returns the approximate number of bytes of heap
9265 ** memory used to store the schema for all databases associated
9266 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
9267 ** ^The full amount of memory used by the schemas is reported, even if the
9268 ** schema memory is shared with other database connections due to
9269 ** [shared cache mode] being enabled.
9270 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
 
9271 **
9272 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
9273 ** <dd>This parameter returns the approximate number of bytes of heap
9274 ** and lookaside memory used by all prepared statements associated with
9275 ** the database connection.)^
@@ -9302,11 +9304,11 @@
9302 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
9303 ** <dd>This parameter returns the number of dirty cache entries that have
9304 ** been written to disk in the middle of a transaction due to the page
9305 ** cache overflowing. Transactions are more efficient if they are written
9306 ** to disk all at once. When pages spill mid-transaction, that introduces
9307 ** additional overhead. This parameter can be used help identify
9308 ** inefficiencies that can be resolved by increasing the cache size.
9309 ** </dd>
9310 **
9311 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
9312 ** <dd>This parameter returns zero for the current value if and only if
@@ -9373,48 +9375,48 @@
9373 ** careful use of indices.</dd>
9374 **
9375 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
9376 ** <dd>^This is the number of sort operations that have occurred.
9377 ** A non-zero value in this counter may indicate an opportunity to
9378 ** improvement performance through careful use of indices.</dd>
9379 **
9380 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
9381 ** <dd>^This is the number of rows inserted into transient indices that
9382 ** were created automatically in order to help joins run faster.
9383 ** A non-zero value in this counter may indicate an opportunity to
9384 ** improvement performance by adding permanent indices that do not
9385 ** need to be reinitialized each time the statement is run.</dd>
9386 **
9387 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
9388 ** <dd>^This is the number of virtual machine operations executed
9389 ** by the prepared statement if that number is less than or equal
9390 ** to 2147483647. The number of virtual machine operations can be
9391 ** used as a proxy for the total work done by the prepared statement.
9392 ** If the number of virtual machine operations exceeds 2147483647
9393 ** then the value returned by this statement status code is undefined.
9394 **
9395 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9396 ** <dd>^This is the number of times that the prepare statement has been
9397 ** automatically regenerated due to schema changes or changes to
9398 ** [bound parameters] that might affect the query plan.
9399 **
9400 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9401 ** <dd>^This is the number of times that the prepared statement has
9402 ** been run. A single "run" for the purposes of this counter is one
9403 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
9404 ** The counter is incremented on the first [sqlite3_step()] call of each
9405 ** cycle.
9406 **
9407 ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
9408 ** [[SQLITE_STMTSTATUS_FILTER HIT]]
9409 ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
9410 ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
9411 ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
9412 ** step was bypassed because a Bloom filter returned not-found. The
9413 ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
9414 ** times that the Bloom filter returned a find, and thus the join step
9415 ** had to be processed as normal.
9416 **
9417 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
9418 ** <dd>^This is the approximate number of bytes of heap memory
9419 ** used to store the prepared statement. ^This value is not actually
9420 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9515,31 +9517,31 @@
9515 ** [[the xCreate() page cache methods]]
9516 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
9517 ** SQLite will typically create one cache instance for each open database file,
9518 ** though this is not guaranteed. ^The
9519 ** 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
9521 ** second parameter szExtra is a number of bytes of extra storage
9522 ** associated with each page cache entry. ^The szExtra parameter will
9523 ** a number less than 250. SQLite will use the
9524 ** extra szExtra bytes on each page to store metadata about the underlying
9525 ** database page on disk. The value passed into szExtra depends
9526 ** on the SQLite version, the target platform, and how SQLite was compiled.
9527 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
9528 ** created will be used to cache database pages of a file stored on disk, or
9529 ** 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;
9531 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
9532 ** never invoke xUnpin() except to deliberately delete a page.
9533 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
9534 ** false will always have the "discard" flag set to true.
9535 ** ^Hence, a cache created with bPurgeable false will
9536 ** never contain any unpinned pages.
9537 **
9538 ** [[the xCachesize() page cache method]]
9539 ** ^(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
9541 ** instance passed as the first argument. This is the value configured using
9542 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
9543 ** parameter, the implementation is not required to do anything with this
9544 ** value; it is advisory only.
9545 **
@@ -9562,16 +9564,16 @@
9562 **
9563 ** If the requested page is already in the page cache, then the page cache
9564 ** implementation must return a pointer to the page buffer with its content
9565 ** intact. If the requested page is not already in the cache, then the
9566 ** cache implementation should use the value of the createFlag
9567 ** parameter to help it determined what action to take:
9568 **
9569 ** <table border=1 width=85% align=center>
9570 ** <tr><th> createFlag <th> Behavior when page is not already in cache
9571 ** <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.
9573 ** Otherwise return NULL.
9574 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
9575 ** NULL if allocating a new page is effectively impossible.
9576 ** </table>
9577 **
@@ -9584,11 +9586,11 @@
9584 ** [[the xUnpin() page cache method]]
9585 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9586 ** as its second argument. If the third parameter, discard, is non-zero,
9587 ** then the page must be evicted from the cache.
9588 ** ^If the discard parameter is
9589 ** zero, then the page may be discarded or retained at the discretion of
9590 ** page cache implementation. ^The page cache implementation
9591 ** may choose to evict unpinned pages at any time.
9592 **
9593 ** The cache must not perform any reference counting. A single
9594 ** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9602,11 +9604,11 @@
9602 ** to be pinned.
9603 **
9604 ** When SQLite calls the xTruncate() method, the cache must discard all
9605 ** existing cache entries with page numbers (keys) greater than or equal
9606 ** to the value of the iLimit parameter passed to xTruncate(). If any
9607 ** of these pages are pinned, they are implicitly unpinned, meaning that
9608 ** they can be safely discarded.
9609 **
9610 ** [[the xDestroy() page cache method]]
9611 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
9612 ** All resources associated with the specified cache should be freed. ^After
@@ -9782,11 +9784,11 @@
9782 ** sqlite3_backup_step(), the source database may be modified mid-way
9783 ** through the backup process. ^If the source database is modified by an
9784 ** external process or via a database connection other than the one being
9785 ** used by the backup operation, then the backup will be automatically
9786 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9787 ** database is modified by the using the same database connection as is used
9788 ** by the backup operation, then the backup database is automatically
9789 ** updated at the same time.
9790 **
9791 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9792 **
@@ -9799,11 +9801,11 @@
9799 ** active write-transaction on the destination database is rolled back.
9800 ** The [sqlite3_backup] object is invalid
9801 ** and may not be used following a call to sqlite3_backup_finish().
9802 **
9803 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9804 ** sqlite3_backup_step() errors occurred, regardless or whether or not
9805 ** sqlite3_backup_step() completed.
9806 ** ^If an out-of-memory condition or IO error occurred during any prior
9807 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9808 ** sqlite3_backup_finish() returns the corresponding [error code].
9809 **
@@ -9901,11 +9903,11 @@
9901 ** identity of the database connection (the blocking connection) that
9902 ** has locked the required resource is stored internally. ^After an
9903 ** application receives an SQLITE_LOCKED error, it may call the
9904 ** sqlite3_unlock_notify() method with the blocked connection handle as
9905 ** the first argument to register for a callback that will be invoked
9906 ** when the blocking connections current transaction is concluded. ^The
9907 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9908 ** call that concludes the blocking connection's transaction.
9909 **
9910 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9911 ** there is a chance that the blocking connection will have already
@@ -9921,11 +9923,11 @@
9921 ** ^(There may be at most one unlock-notify callback registered by a
9922 ** blocked connection. If sqlite3_unlock_notify() is called when the
9923 ** blocked connection already has a registered unlock-notify callback,
9924 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9925 ** called with a NULL pointer as its second argument, then any existing
9926 ** unlock-notify callback is canceled. ^The blocked connections
9927 ** unlock-notify callback may also be canceled by closing the blocked
9928 ** connection using [sqlite3_close()].
9929 **
9930 ** The unlock-notify callback is not reentrant. If an application invokes
9931 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10319,11 +10321,11 @@
10319 ** where X is an integer. If X is zero, then the [virtual table] whose
10320 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
10321 ** support constraints. In this configuration (which is the default) if
10322 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
10323 ** 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
10325 ** ON CONFLICT mode specified.
10326 **
10327 ** If X is non-zero, then the virtual table implementation guarantees
10328 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
10329 ** any modifications to internal or persistent data structures have been made.
@@ -10353,11 +10355,11 @@
10353 ** </dd>
10354 **
10355 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10356 ** <dd>Calls of the form
10357 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10358 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10359 ** identify that virtual table as being safe to use from within triggers
10360 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10361 ** virtual table can do no serious harm even if it is controlled by a
10362 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10363 ** flag unless absolutely necessary.
@@ -10521,21 +10523,21 @@
10521 ** <tr><td>2<td>no<td>yes<td>yes
10522 ** <tr><td>3<td>yes<td>yes<td>yes
10523 ** </table>
10524 **
10525 ** ^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
10527 ** to be the same. In other words, the comparison operator is "IS"
10528 ** (or "IS NOT DISTINCT FROM") and not "==".
10529 **
10530 ** If a virtual table implementation is unable to meet the requirements
10531 ** specified above, then it must not set the "orderByConsumed" flag in the
10532 ** [sqlite3_index_info] object or an incorrect answer may result.
10533 **
10534 ** ^A virtual table implementation is always free to return rows in any order
10535 ** 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
10537 ** [bytecode] to ensure that the final results returned by the SQL query are
10538 ** ordered correctly. The use of the "orderByConsumed" flag and the
10539 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
10540 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
10541 ** flag might help queries against a virtual table to run faster. Being
@@ -10628,11 +10630,11 @@
10628 **
10629 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10630 ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10631 ** xFilter method which invokes these routines, and specifically
10632 ** a parameter that was previously selected for all-at-once IN constraint
10633 ** processing use the [sqlite3_vtab_in()] interface in the
10634 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10635 ** an xFilter argument that was selected for all-at-once IN constraint
10636 ** processing, then these routines return [SQLITE_ERROR].)^
10637 **
10638 ** ^(Use these routines to access all values on the right-hand side
@@ -10683,11 +10685,11 @@
10683 ** right-hand operand is not known, then *V is set to a NULL pointer.
10684 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10685 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10686 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10687 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10688 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10689 ** something goes wrong.
10690 **
10691 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10692 ** the right-hand operand of a constraint is a literal value in the original
10693 ** SQL statement. If the right-hand operand is an expression or a reference
@@ -10711,12 +10713,12 @@
10711 /*
10712 ** CAPI3REF: Conflict resolution modes
10713 ** KEYWORDS: {conflict resolution mode}
10714 **
10715 ** 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 **
10719 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
10720 ** return value from the [sqlite3_set_authorizer()] callback and that
10721 ** [SQLITE_ABORT] is also a [result code].
10722 */
@@ -10752,43 +10754,43 @@
10752 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10753 **
10754 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10755 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10756 ** 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,
10758 ** then this value will approximate the quotient NVISIT/NLOOP and the
10759 ** product of this value for all prior loops with the same SELECTID will
10760 ** be the NLOOP value for the current loop.
10761 **
10762 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10763 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10764 ** to a zero-terminated UTF-8 string containing the name of the index or table
10765 ** used for the X-th loop.
10766 **
10767 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10768 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10769 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10770 ** description for the X-th loop.
10771 **
10772 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10773 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10774 ** id for the X-th query plan element. The id value is unique within the
10775 ** statement. The select-id is the same value as is output in the first
10776 ** column of an [EXPLAIN QUERY PLAN] query.
10777 **
10778 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10779 ** <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
10781 ** 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.
10783 **
10784 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10785 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10786 ** according to the processor time-stamp counter, that elapsed while the
10787 ** query element was being processed. This value is not available for
10788 ** all query elements - if it is unavailable the output variable is
10789 ** set to -1.
10790 ** </dl>
10791 */
10792 #define SQLITE_SCANSTAT_NLOOP 0
10793 #define SQLITE_SCANSTAT_NVISIT 1
10794 #define SQLITE_SCANSTAT_EST 2
@@ -10825,12 +10827,12 @@
10825 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10826 ** sqlite3_stmt_scanstatus() is equivalent to calling
10827 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10828 **
10829 ** 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 ** - less than -1 or greater than or equal to the total number of query
10833 ** elements used to implement the statement - a non-zero value is returned and
10834 ** the variable that pOut points to is unchanged.
10835 **
10836 ** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10869,11 +10871,11 @@
10869 /*
10870 ** CAPI3REF: Flush caches to disk mid-transaction
10871 ** METHOD: sqlite3
10872 **
10873 ** ^If a write-transaction is open on [database connection] D when the
10874 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10875 ** pages in the pager-cache that are not currently in use are written out
10876 ** to disk. A dirty page may be in use if a database cursor created by an
10877 ** active SQL statement is reading from it, or if it is page 1 of a database
10878 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10879 ** interface flushes caches for all schemas - "main", "temp", and
@@ -10983,12 +10985,12 @@
10983 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10984 ** triggers; or 2 for changes resulting from triggers called by top-level
10985 ** triggers; and so forth.
10986 **
10987 ** 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 ** callback made with op==SQLITE_DELETE is actually a write using the
10991 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10992 ** the index of the column being written. In other cases, where the
10993 ** pre-update hook is being invoked for some other reason, including a
10994 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -11237,20 +11239,20 @@
11237 ** is written into *P.
11238 **
11239 ** For an ordinary on-disk database file, the serialization is just a
11240 ** copy of the disk file. For an in-memory database or a "TEMP" database,
11241 ** the serialization is the same sequence of bytes which would be written
11242 ** to disk if that database where backed up to disk.
11243 **
11244 ** The usual case is that sqlite3_serialize() copies the serialization of
11245 ** the database into memory obtained from [sqlite3_malloc64()] and returns
11246 ** a pointer to that memory. The caller is responsible for freeing the
11247 ** returned value to avoid a memory leak. However, if the F argument
11248 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
11249 ** are made, and the sqlite3_serialize() function will return a pointer
11250 ** to the contiguous memory representation of the database that SQLite
11251 ** is currently using for that database, or NULL if the no such contiguous
11252 ** memory representation of the database exists. A contiguous memory
11253 ** representation of the database will usually only exist if there has
11254 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
11255 ** values of D and S.
11256 ** The size of the database is written into *P even if the
@@ -11317,11 +11319,11 @@
11317 **
11318 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
11319 ** database is currently in a read transaction or is involved in a backup
11320 ** operation.
11321 **
11322 ** It is not possible to deserialized into the TEMP database. If the
11323 ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
11324 ** function returns SQLITE_ERROR.
11325 **
11326 ** The deserialized database should not be in [WAL mode]. If the database
11327 ** is in WAL mode, then any attempt to use the database file will result
@@ -11339,19 +11341,19 @@
11339 */
11340 SQLITE_API int sqlite3_deserialize(
11341 sqlite3 *db, /* The database connection */
11342 const char *zSchema, /* Which DB to reopen with the deserialization */
11343 unsigned char *pData, /* The serialized database content */
11344 sqlite3_int64 szDb, /* Number bytes in the deserialization */
11345 sqlite3_int64 szBuf, /* Total size of buffer pData[] */
11346 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
11347 );
11348
11349 /*
11350 ** CAPI3REF: Flags for sqlite3_deserialize()
11351 **
11352 ** The following are allowed values for 6th argument (the F argument) to
11353 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
11354 **
11355 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
11356 ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
11357 ** and that SQLite should take ownership of this memory and automatically
@@ -12084,11 +12086,11 @@
12084 ** CAPI3REF: Flags for sqlite3changeset_start_v2
12085 **
12086 ** The following flags may passed via the 4th parameter to
12087 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
12088 **
12089 ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
12090 ** Invert the changeset while iterating through it. This is equivalent to
12091 ** inverting a changeset using sqlite3changeset_invert() before applying it.
12092 ** It is an error to specify this flag with a patchset.
12093 */
12094 #define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12629,17 +12631,26 @@
12629 ** Apply a changeset or patchset to a database. These functions attempt to
12630 ** update the "main" database attached to handle db with the changes found in
12631 ** the changeset passed via the second and third arguments.
12632 **
12633 ** 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.
 
 
 
 
 
 
 
 
 
12641 **
12642 ** For each table that is not excluded by the filter callback, this function
12643 ** tests that the target database contains a compatible table. A table is
12644 ** considered compatible if all of the following are true:
12645 **
@@ -12656,15 +12667,15 @@
12656 ** changes associated with the table are applied. A warning message is issued
12657 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
12658 ** one such warning is issued for each table in the changeset.
12659 **
12660 ** 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.
12666 **
12667 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
12668 ** of passing anything other than a valid function pointer as the xConflict
12669 ** argument are undefined.
12670 **
@@ -12802,10 +12813,27 @@
12802 void *pChangeset, /* Changeset blob */
12803 int(*xFilter)(
12804 void *pCtx, /* Copy of sixth arg to _apply() */
12805 const char *zTab /* Table name */
12806 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12807 int(*xConflict)(
12808 void *pCtx, /* Copy of sixth arg to _apply() */
12809 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12810 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12811 ),
@@ -13221,10 +13249,27 @@
13221 void *pIn, /* First arg for xInput */
13222 int(*xFilter)(
13223 void *pCtx, /* Copy of sixth arg to _apply() */
13224 const char *zTab /* Table name */
13225 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13226 int(*xConflict)(
13227 void *pCtx, /* Copy of sixth arg to _apply() */
13228 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
13229 sqlite3_changeset_iter *p /* Handle describing change and conflict */
13230 ),
@@ -15174,11 +15219,11 @@
15174 /*
15175 ** GCC does not define the offsetof() macro so we'll have to do it
15176 ** ourselves.
15177 */
15178 #ifndef offsetof
15179 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
15180 #endif
15181
15182 /*
15183 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15184 ** to avoid complaints from -fsanitize=strict-bounds.
@@ -15440,12 +15485,12 @@
15440 /*
15441 ** Macro SMXV(n) return the maximum value that can be held in variable n,
15442 ** assuming n is a signed integer type. UMXV(n) is similar for unsigned
15443 ** integer types.
15444 */
15445 #define SMXV(n) ((((i64)1)<<(sizeof(n)-1))-1)
15446 #define UMXV(n) ((((i64)1)<<(sizeof(n)))-1)
15447
15448 /*
15449 ** Round up a number to the next larger multiple of 8. This is used
15450 ** to force 8-byte alignment on 64-bit architectures.
15451 **
@@ -15562,10 +15607,12 @@
15562 ** 0x00008000 After all FROM-clause analysis
15563 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15564 ** 0x00020000 Transform DISTINCT into GROUP BY
15565 ** 0x00040000 SELECT tree dump after all code has been generated
15566 ** 0x00080000 NOT NULL strength reduction
 
 
15567 */
15568
15569 /*
15570 ** Macros for "wheretrace"
15571 */
@@ -15606,10 +15653,11 @@
15606 **
15607 ** 0x00010000 Show more detail when printing WHERE terms
15608 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15609 ** 0x00040000 Solver overview messages
15610 ** 0x00080000 Star-query heuristic
 
15611 */
15612
15613
15614 /*
15615 ** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15726,11 @@
15678 ** one parameter that destructors normally want. So we have to introduce
15679 ** this magic value that the code knows to handle differently. Any
15680 ** pointer will work here as long as it is distinct from SQLITE_STATIC
15681 ** and SQLITE_TRANSIENT.
15682 */
15683 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
15684
15685 /*
15686 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
15687 ** not support Writable Static Data (WSD) such as global and static variables.
15688 ** All variables must either be on the stack or dynamically allocated from
@@ -16746,10 +16794,11 @@
16746 };
16747
16748 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
16749 int flags, int seekResult);
16750 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
 
16751 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
16752 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
16753 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
16754 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
16755 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -17079,76 +17128,76 @@
17079 #define OP_Last 32 /* jump0 */
17080 #define OP_IfSizeBetween 33 /* jump */
17081 #define OP_SorterSort 34 /* jump */
17082 #define OP_Sort 35 /* jump */
17083 #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] */
17090 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
17091 #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 */
17098 #define OP_IsNull 51 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
17099 #define OP_NotNull 52 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
17100 #define OP_Ne 53 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
17101 #define OP_Eq 54 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
17102 #define OP_Gt 55 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
17103 #define OP_Le 56 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
17104 #define OP_Lt 57 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
17105 #define OP_Ge 58 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
17106 #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 */
17150 #define OP_BitAnd 103 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
17151 #define OP_BitOr 104 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
17152 #define OP_ShiftLeft 105 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
17153 #define OP_ShiftRight 106 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
17154 #define OP_Add 107 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -17155,87 +17204,88 @@
17155 #define OP_Subtract 108 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
17156 #define OP_Multiply 109 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
17157 #define OP_Divide 110 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
17158 #define OP_Remainder 111 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
17159 #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
17162 #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 */
17165 #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
17201 #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
 
17237
17238 /* Properties such as "out2" or "jump" that are specified in
17239 ** comments following the "case" for each opcode in the vdbe.c
17240 ** are encoded into bitvectors as follows:
17241 */
@@ -17250,38 +17300,38 @@
17250 #define OPFLG_INITIALIZER {\
17251 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
17252 /* 8 */ 0x81, 0x01, 0x01, 0x81, 0x83, 0x83, 0x01, 0x01,\
17253 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0xc9, 0xc9, 0xc9,\
17254 /* 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,\
17264 /* 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,}
17275
17276 /* The resolve3P2Values() routine is able to run faster if it knows
17277 ** the value of the largest JUMP opcode. The smaller the maximum
17278 ** JUMP opcode the better, so the mkopcodeh.tcl script that
17279 ** generated this include file strives to group all JUMP opcodes
17280 ** together near the beginning of the list.
17281 */
17282 #define SQLITE_MX_JUMP_OPCODE 64 /* Maximum JUMP opcode */
17283
17284 /************** End of opcodes.h *********************************************/
17285 /************** Continuing where we left off in vdbe.h ***********************/
17286
17287 /*
@@ -17401,11 +17451,11 @@
17401 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
17402 #endif
17403 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
17404 SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
17405
17406 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
17407 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
17408 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
17409 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
17410
17411 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -17414,11 +17464,13 @@
17414 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
17415 SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe*);
17416
17417 SQLITE_PRIVATE void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val);
17418
 
17419 SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
 
17420 #ifdef SQLITE_ENABLE_BYTECODE_VTAB
17421 SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3*);
17422 #endif
17423
17424 /* Use SQLITE_ENABLE_EXPLAIN_COMMENTS to enable generation of extra
@@ -18296,10 +18348,11 @@
18296 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18297 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18298 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18299 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18300 #define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
 
18301 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
18302
18303 /*
18304 ** Macros for testing whether or not optimizations are enabled or disabled.
18305 */
@@ -18534,11 +18587,11 @@
18534 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
18535 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18536 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
18537 {nArg, SQLITE_FUNC_BUILTIN|\
18538 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
18539 pArg, 0, xFunc, 0, 0, 0, #zName, }
18540 #define LIKEFUNC(zName, nArg, arg, flags) \
18541 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
18542 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
18543 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
18544 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
@@ -18701,10 +18754,11 @@
18701 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18702 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18703 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18704 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18705 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
 
18706
18707 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
18708
18709 /*
18710 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19070,19 @@
19016 /*
19017 ** An instance of the following structure is passed as the first
19018 ** argument to sqlite3VdbeKeyCompare and is used to control the
19019 ** comparison of the two index keys.
19020 **
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.
 
 
 
 
 
 
19024 */
19025 struct KeyInfo {
19026 u32 nRef; /* Number of references to this KeyInfo object */
19027 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
19028 u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19090,21 @@
19030 sqlite3 *db; /* The database connection */
19031 u8 *aSortFlags; /* Sort order for each column. */
19032 CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
19033 };
19034
19035 /* The size (in bytes) of a KeyInfo object with up to N fields */
 
 
19036 #define SZ_KEYINFO(N) (offsetof(KeyInfo,aColl) + (N)*sizeof(CollSeq*))
 
 
 
 
 
 
 
19037
19038 /*
19039 ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
19040 */
19041 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19120,22 @@
19051 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
19052 ** OP_Column opcode.
19053 **
19054 ** An instance of this object serves as a "key" for doing a search on
19055 ** 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.
19059 **
19060 ** The r1 and r2 fields are the values to return if this key is less than
19061 ** or greater than a key in the btree, respectively. These are normally
19062 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
19063 ** is in DESC order.
19064 **
19065 ** The key comparison functions actually return default_rc when they find
19066 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
19067 ** 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
19069 ** cause the search to find the last match, or +1 to cause the search to
19070 ** find the first match.
19071 **
19072 ** The key comparison functions will set eqSeen to true if they ever
19073 ** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19143,12 @@
19075 ** before the first match or immediately after the last match. The
19076 ** eqSeen field will indicate whether or not an exact match exists in the
19077 ** b-tree.
19078 */
19079 struct UnpackedRecord {
19080 KeyInfo *pKeyInfo; /* Collation and sort-order information */
19081 Mem *aMem; /* Values */
19082 union {
19083 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
19084 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
19085 } u;
19086 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -19161,14 +19229,12 @@
19161 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
19162 unsigned isResized:1; /* True if resizeIndexObject() has been called */
19163 unsigned isCovering:1; /* True if this is a covering index */
19164 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
19165 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
19166 unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */
19167 unsigned bNoQuery:1; /* Do not use this index to optimize queries */
19168 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
19169 unsigned bIdxRowid:1; /* One or more of the index keys is the ROWID */
19170 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
19171 unsigned bHasExpr:1; /* Index contains an expression, either a literal
19172 ** expression, or a reference to a VIRTUAL column */
19173 #ifdef SQLITE_ENABLE_STAT4
19174 int nSample; /* Number of elements in aSample[] */
@@ -19252,21 +19318,21 @@
19252 struct AggInfo {
19253 u8 directMode; /* Direct rendering mode means take data directly
19254 ** from source tables rather than from accumulators */
19255 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
19256 ** than the source table */
19257 u16 nSortingColumn; /* Number of columns in the sorting index */
19258 int sortingIdx; /* Cursor number of the sorting index */
19259 int sortingIdxPTab; /* Cursor number of pseudo-table */
19260 int iFirstReg; /* First register in range for aCol[] and aFunc[] */
19261 ExprList *pGroupBy; /* The group by clause */
19262 struct AggInfo_col { /* For each column used in source tables */
19263 Table *pTab; /* Source table */
19264 Expr *pCExpr; /* The original expression */
19265 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 */
19268 } *aCol;
19269 int nColumn; /* Number of used entries in aCol[] */
19270 int nAccumulator; /* Number of columns that show through to the output.
19271 ** Additional columns are used only as parameters to
19272 ** aggregate functions */
@@ -19726,10 +19792,11 @@
19726 unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
19727 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
19728 unsigned rowidUsed :1; /* The ROWID of this table is referenced */
19729 unsigned fixedSchema :1; /* Uses u4.pSchema, not u4.zDatabase */
19730 unsigned hadSchema :1; /* Had u4.zDatabase before u4.pSchema */
 
19731 } fg;
19732 int iCursor; /* The VDBE cursor number used to access this table */
19733 Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
19734 union {
19735 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
@@ -20256,10 +20323,11 @@
20256 u8 mayAbort; /* True if statement may throw an ABORT exception */
20257 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20258 u8 disableLookaside; /* Number of times lookaside has been disabled */
20259 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20260 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
 
20261 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20262 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20263 u8 bReturning; /* Coding a RETURNING trigger */
20264 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20265 u8 disableTriggers; /* True to disable triggers */
@@ -21252,10 +21320,11 @@
21252 #endif
21253 #ifndef SQLITE_OMIT_WINDOWFUNC
21254 SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
21255 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
21256 #endif
 
21257 #endif
21258
21259 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
21260 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
21261 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -22425,10 +22494,13 @@
22425 #ifdef SQLITE_BITMASK_TYPE
22426 "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
22427 #endif
22428 #ifdef SQLITE_BUG_COMPATIBLE_20160819
22429 "BUG_COMPATIBLE_20160819",
 
 
 
22430 #endif
22431 #ifdef SQLITE_CASE_SENSITIVE_LIKE
22432 "CASE_SENSITIVE_LIKE",
22433 #endif
22434 #ifdef SQLITE_CHECK_PAGES
@@ -23861,11 +23933,11 @@
23861 ** * MEM_Blob A blob, stored in Mem.z length Mem.n.
23862 ** Incompatible with MEM_Str, MEM_Null,
23863 ** MEM_Int, MEM_Real, and MEM_IntReal.
23864 **
23865 ** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
23866 ** MEM.u.i extra 0x00 bytes at the end.
23867 **
23868 ** * MEM_Int Integer stored in Mem.u.i.
23869 **
23870 ** * MEM_Real Real stored in Mem.u.r.
23871 **
@@ -24130,11 +24202,11 @@
24130 Mem oldipk; /* Memory cell holding "old" IPK value */
24131 Mem *aNew; /* Array of new.* values */
24132 Table *pTab; /* Schema object being updated */
24133 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24134 sqlite3_value **apDflt; /* Array of default values, if required */
24135 u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */
24136 };
24137
24138 /*
24139 ** An instance of this object is used to pass an vector of values into
24140 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -32060,10 +32132,18 @@
32060 }else{
32061 longvalue = va_arg(ap,unsigned int);
32062 }
32063 prefix = 0;
32064 }
 
 
 
 
 
 
 
 
32065 if( longvalue==0 ) flag_alternateform = 0;
32066 if( flag_zeropad && precision<width-(prefix!=0) ){
32067 precision = width-(prefix!=0);
32068 }
32069 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -35011,11 +35091,11 @@
35011 }
35012
35013 /*
35014 ** Write a single UTF8 character whose value is v into the
35015 ** buffer starting at zOut. zOut must be sized to hold at
35016 ** least for bytes. Return the number of bytes needed
35017 ** to encode the new character.
35018 */
35019 SQLITE_PRIVATE int sqlite3AppendOneUtf8Character(char *zOut, u32 v){
35020 if( v<0x00080 ){
35021 zOut[0] = (u8)(v & 0xff);
@@ -37691,76 +37771,76 @@
37691 /* 32 */ "Last" OpHelp(""),
37692 /* 33 */ "IfSizeBetween" OpHelp(""),
37693 /* 34 */ "SorterSort" OpHelp(""),
37694 /* 35 */ "Sort" OpHelp(""),
37695 /* 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]"),
37702 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
37703 /* 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"),
37710 /* 51 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
37711 /* 52 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
37712 /* 53 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
37713 /* 54 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
37714 /* 55 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
37715 /* 56 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
37716 /* 57 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
37717 /* 58 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
37718 /* 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"),
37762 /* 103 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
37763 /* 104 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
37764 /* 105 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
37765 /* 106 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
37766 /* 107 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -37767,87 +37847,88 @@
37767 /* 108 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
37768 /* 109 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
37769 /* 110 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
37770 /* 111 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
37771 /* 112 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
37772 /* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
37773 /* 114 */ "OpenDup" OpHelp(""),
37774 /* 115 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
37775 /* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"),
37776 /* 117 */ "OpenEphemeral" OpHelp("nColumn=P2"),
37777 /* 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(""),
37813 /* 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(""),
 
37849 };
37850 return azName[i];
37851 }
37852 #endif
37853
@@ -43870,25 +43951,24 @@
43870 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43871
43872 /* Check that, if this to be a blocking lock, no locks that occur later
43873 ** in the following list than the lock being obtained are already held:
43874 **
43875 ** 1. Checkpointer lock (ofst==1).
43876 ** 2. Write lock (ofst==0).
43877 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
 
43878 **
43879 ** In other words, if this is a blocking lock, none of the locks that
43880 ** occur later in the above list than the lock being obtained may be
43881 ** held.
43882 **
43883 ** It is not permitted to block on the RECOVER lock.
43884 */
43885 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
43886 {
43887 u16 lockMask = (p->exclMask|p->sharedMask);
43888 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43889 (ofst!=2) /* not RECOVER */
43890 && (ofst!=1 || lockMask==0 || lockMask==2)
43891 && (ofst!=0 || lockMask<3)
43892 && (ofst<3 || lockMask<(1<<ofst))
43893 ));
43894 }
@@ -49845,11 +49925,15 @@
49845 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49846 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49847 if( res==WAIT_OBJECT_0 ){
49848 ret = TRUE;
49849 }else if( res==WAIT_TIMEOUT ){
 
49850 rc = SQLITE_BUSY_TIMEOUT;
 
 
 
49851 }else{
49852 /* Some other error has occurred */
49853 rc = SQLITE_IOERR_LOCK;
49854 }
49855
@@ -51331,17 +51415,17 @@
51331 int nChar;
51332 LPWSTR zWideFilename;
51333
51334 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51335 && winIsDirSep(zFilename[2])) ){
51336 int nByte;
51337 int convertflag = CCP_POSIX_TO_WIN_W;
51338 if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51339 nByte = (int)osCygwin_conv_path(convertflag,
51340 zFilename, 0, 0);
51341 if( nByte>0 ){
51342 zConverted = sqlite3MallocZero(nByte+12);
51343 if ( zConverted==0 ){
51344 return zConverted;
51345 }
51346 zWideFilename = zConverted;
51347 /* Filenames should be prefixed, except when converted
@@ -51656,25 +51740,24 @@
51656 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51657
51658 /* Check that, if this to be a blocking lock, no locks that occur later
51659 ** in the following list than the lock being obtained are already held:
51660 **
51661 ** 1. Checkpointer lock (ofst==1).
51662 ** 2. Write lock (ofst==0).
51663 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
 
51664 **
51665 ** In other words, if this is a blocking lock, none of the locks that
51666 ** occur later in the above list than the lock being obtained may be
51667 ** held.
51668 **
51669 ** It is not permitted to block on the RECOVER lock.
51670 */
51671 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
51672 {
51673 u16 lockMask = (p->exclMask|p->sharedMask);
51674 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51675 (ofst!=2) /* not RECOVER */
51676 && (ofst!=1 || lockMask==0 || lockMask==2)
51677 && (ofst!=0 || lockMask<3)
51678 && (ofst<3 || lockMask<(1<<ofst))
51679 ));
51680 }
@@ -52220,31 +52303,10 @@
52220 **
52221 ** This division contains the implementation of methods on the
52222 ** sqlite3_vfs object.
52223 */
52224
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
52246 /*
52247 ** This function returns non-zero if the specified UTF-8 string buffer
52248 ** ends with a directory separator character or one was successfully
52249 ** added to it.
52250 */
@@ -52380,46 +52442,10 @@
52380 sqlite3_snprintf(nMax, zBuf, "%s", zDir);
52381 sqlite3_free(zConverted);
52382 break;
52383 }
52384 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 */
52421 }
52422 }
52423 }
52424 #endif
52425
@@ -53314,38 +53340,10 @@
53314 winSimplifyName(zFull);
53315 return rc;
53316 }
53317 }
53318 #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
53347
53348 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && defined(_WIN32)
53349 SimulateIOError( return SQLITE_ERROR );
53350 /* WinCE has no concept of a relative pathname, or so I am told. */
53351 /* WinRT has no way to convert a relative path to an absolute one. */
@@ -53487,31 +53485,12 @@
53487 ** Interfaces for opening a shared library, finding entry points
53488 ** within the shared library, and closing the shared library.
53489 */
53490 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53491 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
53510 void *zConverted = winConvertFromUtf8Filename(zFilename);
53511 UNUSED_PARAMETER(pVfs);
53512 #endif
53513 if( zConverted==0 ){
53514 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53515 return 0;
53516 }
53517 if( osIsNT() ){
@@ -54953,10 +54932,11 @@
54953 BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
54954 u32 aHash[BITVEC_NINT]; /* Hash table representation */
54955 Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
54956 } u;
54957 };
 
54958
54959 /*
54960 ** Create a new bitmap object able to handle bits between 0 and iSize,
54961 ** inclusive. Return a pointer to the new object. Return NULL if
54962 ** malloc fails.
@@ -55063,11 +55043,13 @@
55063 if( aiValues==0 ){
55064 return SQLITE_NOMEM_BKPT;
55065 }else{
55066 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
55067 memset(p->u.apSub, 0, sizeof(p->u.apSub));
55068 p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
 
 
55069 rc = sqlite3BitvecSet(p, i);
55070 for(j=0; j<BITVEC_NINT; j++){
55071 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
55072 }
55073 sqlite3StackFree(0, aiValues);
@@ -55139,10 +55121,56 @@
55139 ** was created.
55140 */
55141 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
55142 return p->iSize;
55143 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55144
55145 #ifndef SQLITE_UNTESTABLE
55146 /*
55147 ** Let V[] be an array of unsigned characters sufficient to hold
55148 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55150,40 +55178,48 @@
55150 ** individual bits within V.
55151 */
55152 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
55153 #define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
55154 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
 
55155
55156 /*
55157 ** This routine runs an extensive test of the Bitvec code.
55158 **
55159 ** The input is an array of integers that acts as a program
55160 ** to test the Bitvec. The integers are opcodes followed
55161 ** by 0, 1, or 3 operands, depending on the opcode. Another
55162 ** opcode follows immediately after the last operand.
55163 **
55164 ** There are 6 opcodes numbered from 0 through 5. 0 is the
55165 ** "halt" opcode and causes the test to end.
55166 **
55167 ** 0 Halt and return the number of errors
55168 ** 1 N S X Set N bits beginning with S and incrementing by X
55169 ** 2 N S X Clear N bits beginning with S and incrementing by X
55170 ** 3 N Set N randomly chosen bits
55171 ** 4 N Clear N randomly chosen bits
55172 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
 
 
55173 **
55174 ** The opcodes 1 through 4 perform set and clear operations are performed
55175 ** on both a Bitvec object and on a linear array of bits obtained from malloc.
55176 ** Opcode 5 works on the linear array only, not on the Bitvec.
55177 ** Opcode 5 is used to deliberately induce a fault in order to
55178 ** confirm that error detection works.
 
 
55179 **
55180 ** At the conclusion of the test the linear array is compared
55181 ** against the Bitvec object. If there are any differences,
55182 ** an error is returned. If they are the same, zero is returned.
55183 **
55184 ** If a memory allocation error occurs, return -1.
 
 
 
55185 */
55186 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
55187 Bitvec *pBitvec = 0;
55188 unsigned char *pV = 0;
55189 int rc = -1;
@@ -55190,22 +55226,45 @@
55190 int i, nx, pc, op;
55191 void *pTmpSpace;
55192
55193 /* Allocate the Bitvec to be tested and a linear array of
55194 ** bits to act as the reference */
55195 pBitvec = sqlite3BitvecCreate( sz );
55196 pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
 
 
 
 
 
55197 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55198 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
55199
55200 /* NULL pBitvec tests */
55201 sqlite3BitvecSet(0, 1);
55202 sqlite3BitvecClear(0, 1, pTmpSpace);
55203
55204 /* Run the program */
55205 pc = i = 0;
55206 while( (op = aOp[pc])!=0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55207 switch( op ){
55208 case 1:
55209 case 2:
55210 case 5: {
55211 nx = 4;
@@ -55223,33 +55282,37 @@
55223 }
55224 if( (--aOp[pc+1]) > 0 ) nx = 0;
55225 pc += nx;
55226 i = (i & 0x7fffffff)%sz;
55227 if( (op & 1)!=0 ){
55228 SETBIT(pV, (i+1));
55229 if( op!=5 ){
55230 if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
55231 }
55232 }else{
55233 CLEARBIT(pV, (i+1));
55234 sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
55235 }
55236 }
55237
55238 /* Test to make sure the linear array exactly matches the
55239 ** Bitvec object. Start with the assumption that they do
55240 ** match (rc==0). Change rc to non-zero if a discrepancy
55241 ** is found.
55242 */
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 }
 
 
 
 
55251 }
55252
55253 /* Free allocated structure */
55254 bitvec_end:
55255 sqlite3_free(pTmpSpace);
@@ -58849,10 +58912,13 @@
58849 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
58850 PCache *pPCache; /* Pointer to page cache object */
58851 #ifndef SQLITE_OMIT_WAL
58852 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
58853 char *zWal; /* File name for write-ahead log */
 
 
 
58854 #endif
58855 };
58856
58857 /*
58858 ** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
@@ -65731,10 +65797,15 @@
65731 if( rc==SQLITE_OK ){
65732 rc = sqlite3WalOpen(pPager->pVfs,
65733 pPager->fd, pPager->zWal, pPager->exclusiveMode,
65734 pPager->journalSizeLimit, &pPager->pWal
65735 );
 
 
 
 
 
65736 }
65737 pagerFixMaplimit(pPager);
65738
65739 return rc;
65740 }
@@ -65850,10 +65921,11 @@
65850 /*
65851 ** Set the database handle used by the wal layer to determine if
65852 ** blocking locks are required.
65853 */
65854 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
 
65855 if( pagerUseWal(pPager) ){
65856 sqlite3WalDb(pPager->pWal, db);
65857 }
65858 }
65859 #endif
@@ -69023,11 +69095,10 @@
69023 assert( rc==SQLITE_OK );
69024 if( pWal->bShmUnreliable==0 ){
69025 rc = walIndexReadHdr(pWal, pChanged);
69026 }
69027 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
69028 walDisableBlocking(pWal);
69029 if( rc==SQLITE_BUSY_TIMEOUT ){
69030 rc = SQLITE_BUSY;
69031 *pCnt |= WAL_RETRY_BLOCKED_MASK;
69032 }
69033 #endif
@@ -69038,10 +69109,11 @@
69038 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
69039 ** would be technically correct. But the race is benign since with
69040 ** WAL_RETRY this routine will be called again and will probably be
69041 ** right on the second iteration.
69042 */
 
69043 if( pWal->apWiData[0]==0 ){
69044 /* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
69045 ** We assume this is a transient condition, so return WAL_RETRY. The
69046 ** xShmMap() implementation used by the default unix and win32 VFS
69047 ** modules may return SQLITE_BUSY due to a race condition in the
@@ -69054,10 +69126,11 @@
69054 rc = WAL_RETRY;
69055 }else if( rc==SQLITE_BUSY ){
69056 rc = SQLITE_BUSY_RECOVERY;
69057 }
69058 }
 
69059 if( rc!=SQLITE_OK ){
69060 return rc;
69061 }
69062 else if( pWal->bShmUnreliable ){
69063 return walBeginShmUnreliable(pWal, pChanged);
@@ -69741,10 +69814,11 @@
69741 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
69742 }
69743 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
69744 }
69745 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
 
69746 }
69747 return rc;
69748 }
69749
69750 /*
@@ -69788,10 +69862,13 @@
69788 pWal->hdr.aFrameCksum[1] = aWalData[2];
69789 SEH_TRY {
69790 walCleanupHash(pWal);
69791 }
69792 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
 
 
 
69793 }
69794
69795 return rc;
69796 }
69797
@@ -72503,11 +72580,11 @@
72503 if( pKey ){
72504 KeyInfo *pKeyInfo = pCur->pKeyInfo;
72505 assert( nKey==(i64)(int)nKey );
72506 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
72507 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72508 sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
72509 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72510 rc = SQLITE_CORRUPT_BKPT;
72511 }else{
72512 rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
72513 }
@@ -73560,14 +73637,14 @@
73560 u8 *pTmp; /* Temporary ptr into data[] */
73561
73562 assert( pPage->pBt!=0 );
73563 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73564 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
73565 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
73566 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73567 assert( iSize>=4 ); /* Minimum cell size is 4 */
73568 assert( CORRUPT_DB || iStart<=pPage->pBt->usableSize-4 );
73569
73570 /* The list of freeblocks must be in ascending order. Find the
73571 ** spot on the list where iStart should be inserted.
73572 */
73573 hdr = pPage->hdrOffset;
@@ -74487,10 +74564,11 @@
74487 removed = 1;
74488 }
74489 sqlite3_mutex_leave(pMainMtx);
74490 return removed;
74491 #else
 
74492 return 1;
74493 #endif
74494 }
74495
74496 /*
@@ -74704,10 +74782,14 @@
74704 BtShared *pBt = p->pBt;
74705 assert( nReserve>=0 && nReserve<=255 );
74706 sqlite3BtreeEnter(p);
74707 pBt->nReserveWanted = (u8)nReserve;
74708 x = pBt->pageSize - pBt->usableSize;
 
 
 
 
74709 if( nReserve<x ) nReserve = x;
74710 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
74711 sqlite3BtreeLeave(p);
74712 return SQLITE_READONLY;
74713 }
@@ -75328,10 +75410,17 @@
75328
75329 if( rc!=SQLITE_OK ){
75330 (void)sqlite3PagerWalWriteLock(pPager, 0);
75331 unlockBtreeIfUnused(pBt);
75332 }
 
 
 
 
 
 
 
75333 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75334 btreeInvokeBusyHandler(pBt) );
75335 sqlite3PagerWalDb(pPager, 0);
75336 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
75337 if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -77285,10 +77374,34 @@
77285 *pRes = 1;
77286 rc = SQLITE_OK;
77287 }
77288 return rc;
77289 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77290
77291 #ifdef SQLITE_DEBUG
77292 /* The cursors is CURSOR_VALID and has BTCF_AtLast set. Verify that
77293 ** this flags are true for a consistent database.
77294 **
@@ -77505,12 +77618,12 @@
77505 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77506 return rc;
77507 }
77508
77509 /*
77510 ** Compare the "idx"-th cell on the page the cursor pCur is currently
77511 ** pointing to to pIdxKey using xRecordCompare. Return negative or
77512 ** zero if the cell is less than or equal pIdxKey. Return positive
77513 ** if unknown.
77514 **
77515 ** Return value negative: Cell at pCur[idx] less than pIdxKey
77516 **
@@ -77521,16 +77634,15 @@
77521 **
77522 ** This routine is part of an optimization. It is always safe to return
77523 ** a positive value as that will cause the optimization to be skipped.
77524 */
77525 static int indexCellCompare(
77526 BtCursor *pCur,
77527 int idx,
77528 UnpackedRecord *pIdxKey,
77529 RecordCompare xRecordCompare
77530 ){
77531 MemPage *pPage = pCur->pPage;
77532 int c;
77533 int nCell; /* Size of the pCell cell in bytes */
77534 u8 *pCell = findCellPastPtr(pPage, idx);
77535
77536 nCell = pCell[0];
@@ -77635,18 +77747,18 @@
77635 && pCur->pPage->leaf
77636 && cursorOnLastPage(pCur)
77637 ){
77638 int c;
77639 if( pCur->ix==pCur->pPage->nCell-1
77640 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
77641 && pIdxKey->errCode==SQLITE_OK
77642 ){
77643 *pRes = c;
77644 return SQLITE_OK; /* Cursor already pointing at the correct spot */
77645 }
77646 if( pCur->iPage>0
77647 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
77648 && pIdxKey->errCode==SQLITE_OK
77649 ){
77650 pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
77651 if( !pCur->pPage->isInit ){
77652 return SQLITE_CORRUPT_BKPT;
@@ -77859,11 +77971,11 @@
77859 if( pCur->eState!=CURSOR_VALID ) return 0;
77860 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77861
77862 n = pCur->pPage->nCell;
77863 for(i=0; i<pCur->iPage; i++){
77864 n *= pCur->apPage[i]->nCell;
77865 }
77866 return n;
77867 }
77868
77869 /*
@@ -80316,11 +80428,16 @@
80316
80317 /* If the sibling pages are not leaves, ensure that the right-child pointer
80318 ** of the right-most new sibling page is set to the value that was
80319 ** originally in the same field of the right-most old sibling page. */
80320 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
80321 MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
 
 
 
 
 
80322 memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
80323 }
80324
80325 /* Make any required updates to pointer map entries associated with
80326 ** cells stored on sibling pages following the balance operation. Pointer
@@ -82948,10 +83065,11 @@
82948 ** btree as the argument handle holds an exclusive lock on the
82949 ** sqlite_schema table. Otherwise SQLITE_OK.
82950 */
82951 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
82952 int rc;
 
82953 assert( sqlite3_mutex_held(p->db->mutex) );
82954 sqlite3BtreeEnter(p);
82955 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
82956 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
82957 sqlite3BtreeLeave(p);
@@ -87272,10 +87390,13 @@
87272 ** into register iDest, then add the OPFLAG_TYPEOFARG flag to that
87273 ** opcode.
87274 */
87275 SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe *p, int iDest){
87276 VdbeOp *pOp = sqlite3VdbeGetLastOp(p);
 
 
 
87277 if( pOp->p3==iDest && pOp->opcode==OP_Column ){
87278 pOp->p5 |= OPFLAG_TYPEOFARG;
87279 }
87280 }
87281
@@ -90165,34 +90286,26 @@
90165 }
90166 }
90167 return;
90168 }
90169 /*
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.
90182 */
90183 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
90184 KeyInfo *pKeyInfo /* Description of the record */
90185 ){
90186 UnpackedRecord *p; /* Unpacked record to return */
90187 int nByte; /* Number of bytes required for *p */
90188 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90189 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
90190 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
90191 if( !p ) return 0;
90192 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
90193 assert( pKeyInfo->aSortFlags!=0 );
90194 p->pKeyInfo = pKeyInfo;
90195 p->nField = pKeyInfo->nKeyField + 1;
90196 return p;
90197 }
90198
@@ -90200,11 +90313,10 @@
90200 ** Given the nKey-byte encoding of a record in pKey[], populate the
90201 ** UnpackedRecord structure indicated by the fourth argument with the
90202 ** contents of the decoded record.
90203 */
90204 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
90205 KeyInfo *pKeyInfo, /* Information about the record format */
90206 int nKey, /* Size of the binary record */
90207 const void *pKey, /* The binary record */
90208 UnpackedRecord *p /* Populate this structure before returning. */
90209 ){
90210 const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90211,10 +90323,11 @@
90211 u32 d;
90212 u32 idx; /* Offset in aKey[] to read from */
90213 u16 u; /* Unsigned loop counter */
90214 u32 szHdr;
90215 Mem *pMem = p->aMem;
 
90216
90217 p->default_rc = 0;
90218 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
90219 idx = getVarint32(aKey, szHdr);
90220 d = szHdr;
@@ -90238,10 +90351,12 @@
90238 /* In a corrupt record entry, the last pMem might have been set up using
90239 ** uninitialized memory. Overwrite its value with NULL, to prevent
90240 ** warnings from MSAN. */
90241 sqlite3VdbeMemSetNull(pMem-1);
90242 }
 
 
90243 assert( u<=pKeyInfo->nKeyField + 1 );
90244 p->nField = u;
90245 }
90246
90247 #ifdef SQLITE_DEBUG
@@ -91097,10 +91212,11 @@
91097 ** is an integer.
91098 **
91099 ** The easiest way to enforce this limit is to consider only records with
91100 ** 13 fields or less. If the first field is an integer, the maximum legal
91101 ** header size is (12*5 + 1 + 1) bytes. */
 
91102 if( p->pKeyInfo->nAllField<=13 ){
91103 int flags = p->aMem[0].flags;
91104 if( p->pKeyInfo->aSortFlags[0] ){
91105 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91106 return sqlite3VdbeRecordCompare;
@@ -91346,10 +91462,11 @@
91346 }else{
91347 v->expmask |= ((u32)1 << (iVar-1));
91348 }
91349 }
91350
 
91351 /*
91352 ** Cause a function to throw an error if it was call from OP_PureFunc
91353 ** rather than OP_Function.
91354 **
91355 ** OP_PureFunc means that the function must be deterministic, and should
@@ -91379,10 +91496,11 @@
91379 sqlite3_free(zMsg);
91380 return 0;
91381 }
91382 return 1;
91383 }
 
91384
91385 #if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
91386 /*
91387 ** This Walker callback is used to help verify that calls to
91388 ** sqlite3BtreeCursorHint() with opcode BTREE_HINT_RANGE have
@@ -91455,11 +91573,10 @@
91455 ){
91456 sqlite3 *db = v->db;
91457 i64 iKey2;
91458 PreUpdate preupdate;
91459 const char *zTbl = pTab->zName;
91460 static const u8 fakeSortOrder = 0;
91461 #ifdef SQLITE_DEBUG
91462 int nRealCol;
91463 if( pTab->tabFlags & TF_WithoutRowid ){
91464 nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
91465 }else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91494,11 +91611,11 @@
91494 preupdate.iNewReg = iReg;
91495 preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91496 preupdate.pKeyinfo->db = db;
91497 preupdate.pKeyinfo->enc = ENC(db);
91498 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91499 preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder;
91500 preupdate.iKey1 = iKey1;
91501 preupdate.iKey2 = iKey2;
91502 preupdate.pTab = pTab;
91503 preupdate.iBlobWrite = iBlobWrite;
91504
@@ -93691,11 +93808,11 @@
93691 UnpackedRecord *pRet; /* Return value */
93692
93693 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
93694 if( pRet ){
93695 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93696 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
93697 }
93698 return pRet;
93699 }
93700
93701 /*
@@ -93720,10 +93837,13 @@
93720 rc = SQLITE_MISUSE_BKPT;
93721 goto preupdate_old_out;
93722 }
93723 if( p->pPk ){
93724 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
 
 
 
93725 }else{
93726 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93727 }
93728 if( iStore>=p->pCsr->nField || iStore<0 ){
93729 rc = SQLITE_RANGE;
@@ -93875,10 +93995,12 @@
93875 rc = SQLITE_MISUSE_BKPT;
93876 goto preupdate_new_out;
93877 }
93878 if( p->pPk && p->op!=SQLITE_UPDATE ){
93879 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
 
 
93880 }else{
93881 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93882 }
93883
93884 if( iStore>=p->pCsr->nField || iStore<0 ){
@@ -95200,10 +95322,40 @@
95200 }
95201 pDest->flags &= ~MEM_Ephem;
95202 return rc;
95203 }
95204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95205
95206 /*
95207 ** Return the symbolic name for the data type of a pMem
95208 */
95209 static const char *vdbeMemTypeName(Mem *pMem){
@@ -95725,12 +95877,11 @@
95725 p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
95726 }
95727 }else{
95728 sqlite3VdbeError(p, "%s", pOp->p4.z);
95729 }
95730 pcx = (int)(pOp - aOp);
95731 sqlite3_log(pOp->p1, "abort at %d: %s; [%s]", pcx, p->zErrMsg, p->zSql);
95732 }
95733 rc = sqlite3VdbeHalt(p);
95734 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
95735 if( rc==SQLITE_BUSY ){
95736 p->rc = SQLITE_BUSY;
@@ -96884,10 +97035,11 @@
96884 }
96885 n = pOp->p3;
96886 pKeyInfo = pOp->p4.pKeyInfo;
96887 assert( n>0 );
96888 assert( pKeyInfo!=0 );
 
96889 p1 = pOp->p1;
96890 p2 = pOp->p2;
96891 #ifdef SQLITE_DEBUG
96892 if( aPermute ){
96893 int k, mx = 0;
@@ -97645,10 +97797,19 @@
97645 ** Synopsis: typecheck(r[P1@P2])
97646 **
97647 ** Apply affinities to the range of P2 registers beginning with P1.
97648 ** Take the affinities from the Table object in P4. If any value
97649 ** cannot be coerced into the correct type, then raise an error.
 
 
 
 
 
 
 
 
 
97650 **
97651 ** This opcode is similar to OP_Affinity except that this opcode
97652 ** forces the register type to the Table column type. This is used
97653 ** to implement "strict affinity".
97654 **
@@ -97659,30 +97820,42 @@
97659 **
97660 ** Preconditions:
97661 **
97662 ** <ul>
97663 ** <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.
97666 ** </ul>
97667 **
97668 ** If any precondition is false, an assertion fault occurs.
97669 */
97670 case OP_TypeCheck: {
97671 Table *pTab;
97672 Column *aCol;
97673 int i;
 
97674
97675 assert( pOp->p4type==P4_TABLE );
97676 pTab = pOp->p4.pTab;
97677 assert( pTab->tabFlags & TF_Strict );
97678 assert( pTab->nNVCol==pOp->p2 );
97679 aCol = pTab->aCol;
97680 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;
 
 
 
 
 
 
 
 
 
 
 
97684 if( pOp->p3 ){ pIn1++; continue; }
97685 }
97686 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
97687 applyAffinity(pIn1, aCol[i].affinity, encoding);
97688 if( (pIn1->flags & MEM_Null)==0 ){
@@ -98119,10 +98292,11 @@
98119 }
98120 }else{
98121 zHdr += sqlite3PutVarint(zHdr, serial_type);
98122 if( pRec->n ){
98123 assert( pRec->z!=0 );
 
98124 memcpy(zPayload, pRec->z, pRec->n);
98125 zPayload += pRec->n;
98126 }
98127 }
98128 if( pRec==pLast ) break;
@@ -99756,11 +99930,11 @@
99756 rc = ExpandBlob(r.aMem);
99757 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
99758 if( rc ) goto no_mem;
99759 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
99760 if( pIdxKey==0 ) goto no_mem;
99761 sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey);
99762 pIdxKey->default_rc = 0;
99763 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
99764 sqlite3DbFreeNN(db, pIdxKey);
99765 }
99766 if( rc!=SQLITE_OK ){
@@ -100753,10 +100927,36 @@
100753 VdbeBranchTaken(res!=0,2);
100754 if( res ) goto jump_to_p2;
100755 }
100756 break;
100757 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100758
100759 /* Opcode: Next P1 P2 P3 * P5
100760 **
100761 ** Advance cursor P1 so that it points to the next key/data pair in its
100762 ** table or index. If there are no more key/value pairs then fall through
@@ -102625,11 +102825,18 @@
102625 sqlite3_vtab_cursor *pVCur;
102626 sqlite3_vtab *pVtab;
102627 const sqlite3_module *pModule;
102628
102629 assert( p->bIsReader );
102630 pCur = 0;
 
 
 
 
 
 
 
102631 pVCur = 0;
102632 pVtab = pOp->p4.pVtab->pVtab;
102633 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102634 rc = SQLITE_LOCKED;
102635 goto abort_due_to_error;
@@ -103567,12 +103774,11 @@
103567 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
103568 }
103569 p->rc = rc;
103570 sqlite3SystemError(db, rc);
103571 testcase( sqlite3GlobalConfig.xLog!=0 );
103572 sqlite3_log(rc, "statement aborts at %d: %s; [%s]",
103573 (int)(pOp - aOp), p->zErrMsg, p->zSql);
103574 if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p);
103575 if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
103576 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
103577 db->flags |= SQLITE_CorruptRdOnly;
103578 }
@@ -104029,11 +104235,11 @@
104029 void *z,
104030 int n,
104031 int iOffset,
104032 int (*xCall)(BtCursor*, u32, u32, void*)
104033 ){
104034 int rc;
104035 Incrblob *p = (Incrblob *)pBlob;
104036 Vdbe *v;
104037 sqlite3 *db;
104038
104039 if( p==0 ) return SQLITE_MISUSE_BKPT;
@@ -104069,21 +104275,36 @@
104069 ** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
104070 ** slightly more efficient). Since you cannot write to a PK column
104071 ** using the incremental-blob API, this works. For the sessions module
104072 ** anyhow.
104073 */
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
 
 
 
 
 
 
 
 
 
 
 
 
 
104084 rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
 
 
104085 sqlite3BtreeLeaveCursor(p->pCsr);
104086 if( rc==SQLITE_ABORT ){
104087 sqlite3VdbeFinalize(v);
104088 p->pStmt = 0;
104089 }else{
@@ -104932,11 +105153,11 @@
104932 const void *pKey1, int nKey1, /* Left side of comparison */
104933 const void *pKey2, int nKey2 /* Right side of comparison */
104934 ){
104935 UnpackedRecord *r2 = pTask->pUnpacked;
104936 if( *pbKey2Cached==0 ){
104937 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104938 *pbKey2Cached = 1;
104939 }
104940 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
104941 }
104942
@@ -104959,11 +105180,11 @@
104959 const void *pKey1, int nKey1, /* Left side of comparison */
104960 const void *pKey2, int nKey2 /* Right side of comparison */
104961 ){
104962 UnpackedRecord *r2 = pTask->pUnpacked;
104963 if( !*pbKey2Cached ){
104964 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104965 *pbKey2Cached = 1;
104966 }
104967 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
104968 }
104969
@@ -104999,10 +105220,11 @@
104999 res = vdbeSorterCompareTail(
105000 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105001 );
105002 }
105003 }else{
 
105004 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
105005 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
105006 res = res * -1;
105007 }
105008 }
@@ -105062,10 +105284,11 @@
105062 }else{
105063 if( *v2 & 0x80 ) res = +1;
105064 }
105065 }
105066
 
105067 if( res==0 ){
105068 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
105069 res = vdbeSorterCompareTail(
105070 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105071 );
@@ -105135,11 +105358,12 @@
105135 assert( pCsr->pKeyInfo );
105136 assert( !pCsr->isEphemeral );
105137 assert( pCsr->eCurType==CURTYPE_SORTER );
105138 assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105139 < 0x7fffffff );
105140 szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1);
 
105141 sz = SZ_VDBESORTER(nWorker+1);
105142
105143 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105144 pCsr->uc.pSorter = pSorter;
105145 if( pSorter==0 ){
@@ -105149,11 +105373,16 @@
105149 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105150 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105151 pKeyInfo->db = 0;
105152 if( nField && nWorker==0 ){
105153 pKeyInfo->nKeyField = nField;
 
105154 }
 
 
 
 
105155 sqlite3BtreeEnter(pBt);
105156 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105157 sqlite3BtreeLeave(pBt);
105158 pSorter->nTask = nWorker + 1;
105159 pSorter->iPrev = (u8)(nWorker - 1);
@@ -106929,11 +107158,11 @@
106929 r2->nField = nKeyCol;
106930 }
106931 assert( r2->nField==nKeyCol );
106932
106933 pKey = vdbeSorterRowkey(pSorter, &nKey);
106934 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
106935 for(i=0; i<nKeyCol; i++){
106936 if( r2->aMem[i].flags & MEM_Null ){
106937 *pRes = -1;
106938 return SQLITE_OK;
106939 }
@@ -109303,17 +109532,16 @@
109303 /* Clearly non-deterministic functions like random(), but also
109304 ** date/time functions that use 'now', and other functions like
109305 ** sqlite_version() that might change over time cannot be used
109306 ** in an index or generated column. Curiously, they can be used
109307 ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
109308 ** all this. */
109309 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
109310 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
109311 }else{
109312 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
109313 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
109314 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
109315 }
109316 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
109317 && pParse->nested==0
109318 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
109319 ){
@@ -109325,10 +109553,11 @@
109325 pDef = 0;
109326 }else
109327 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
109328 && !IN_RENAME_OBJECT
109329 ){
 
109330 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
109331 }
109332 }
109333
109334 if( 0==IN_RENAME_OBJECT ){
@@ -109459,22 +109688,25 @@
109459 ** type of the function
109460 */
109461 return WRC_Prune;
109462 }
109463 #ifndef SQLITE_OMIT_SUBQUERY
 
109464 case TK_SELECT:
109465 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
109466 #endif
109467 case TK_IN: {
109468 testcase( pExpr->op==TK_IN );
 
 
109469 if( ExprUseXSelect(pExpr) ){
109470 int nRef = pNC->nRef;
109471 testcase( pNC->ncFlags & NC_IsCheck );
109472 testcase( pNC->ncFlags & NC_PartIdx );
109473 testcase( pNC->ncFlags & NC_IdxExpr );
109474 testcase( pNC->ncFlags & NC_GenCol );
109475 assert( pExpr->x.pSelect );
 
109476 if( pNC->ncFlags & NC_SelfRef ){
109477 notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
109478 }else{
109479 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
109480 }
@@ -110485,11 +110717,13 @@
110485 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110486 return sqlite3ExprAffinity(
110487 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110488 );
110489 }
110490 if( op==TK_VECTOR ){
 
 
110491 assert( ExprUseXList(pExpr) );
110492 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110493 }
110494 if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110495 assert( pExpr->op==TK_COLLATE
@@ -110678,11 +110912,13 @@
110678 }
110679 if( op==TK_CAST || op==TK_UPLUS ){
110680 p = p->pLeft;
110681 continue;
110682 }
110683 if( op==TK_VECTOR ){
 
 
110684 assert( ExprUseXList(p) );
110685 p = p->x.pList->a[0].pExpr;
110686 continue;
110687 }
110688 if( op==TK_COLLATE ){
@@ -111552,11 +111788,11 @@
111552 return pRight;
111553 }else if( pRight==0 ){
111554 return pLeft;
111555 }else{
111556 u32 f = pLeft->flags | pRight->flags;
111557 if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse))==EP_IsFalse
111558 && !IN_RENAME_OBJECT
111559 ){
111560 sqlite3ExprDeferredDelete(pParse, pLeft);
111561 sqlite3ExprDeferredDelete(pParse, pRight);
111562 return sqlite3Expr(db, TK_INTEGER, "0");
@@ -112780,10 +113016,90 @@
112780 pExpr = pExpr->op==TK_AND ? pLeft : pRight;
112781 }
112782 }
112783 return pExpr;
112784 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112785
112786 /*
112787 ** pExpr is a TK_FUNCTION node. Try to determine whether or not the
112788 ** function is a constant function. A function is constant if all of
112789 ** the following are true:
@@ -114225,21 +114541,27 @@
114225 dest.eDest = SRT_Exists;
114226 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
114227 VdbeComment((v, "Init EXISTS result"));
114228 }
114229 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;
 
 
 
 
 
 
114241 }else{
114242 /* If there is no pre-existing limit add a limit of 1 */
114243 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
114244 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
114245 }
@@ -114677,11 +114999,16 @@
114677 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
114678 }else{
114679 iAddr = 0;
114680 }
114681 sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
114682 if( pCol->affinity>=SQLITE_AFF_TEXT ){
 
 
 
 
 
114683 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
114684 }
114685 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
114686 if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
114687 }
@@ -115364,15 +115691,21 @@
115364 case TK_GT:
115365 case TK_GE:
115366 case TK_NE:
115367 case TK_EQ: {
115368 Expr *pLeft = pExpr->pLeft;
 
115369 if( sqlite3ExprIsVector(pLeft) ){
115370 codeVectorCompare(pParse, pExpr, target, op, p5);
115371 }else{
115372 r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
115373 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
 
 
 
 
 
115374 sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
115375 codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
115376 sqlite3VdbeCurrentAddr(v)+2, p5,
115377 ExprHasProperty(pExpr,EP_Commuted));
115378 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
@@ -115383,13 +115716,19 @@
115383 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
115384 if( p5==SQLITE_NULLEQ ){
115385 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
115386 }else{
115387 sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2);
 
 
 
 
 
115388 }
115389 testcase( regFree1==0 );
115390 testcase( regFree2==0 );
 
115391 }
115392 break;
115393 }
115394 case TK_AND:
115395 case TK_OR:
@@ -115401,10 +115740,11 @@
115401 case TK_BITOR:
115402 case TK_SLASH:
115403 case TK_LSHIFT:
115404 case TK_RSHIFT:
115405 case TK_CONCAT: {
 
115406 assert( TK_AND==OP_And ); testcase( op==TK_AND );
115407 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115408 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
115409 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
115410 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
@@ -115412,15 +115752,27 @@
115412 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
115413 assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
115414 assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
115415 assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
115416 assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
115417 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
115418 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
 
 
 
 
 
 
115419 sqlite3VdbeAddOp3(v, op, r2, r1, target);
115420 testcase( regFree1==0 );
115421 testcase( regFree2==0 );
 
 
 
 
 
 
115422 break;
115423 }
115424 case TK_UMINUS: {
115425 Expr *pLeft = pExpr->pLeft;
115426 assert( pLeft );
@@ -116265,21 +116617,31 @@
116265 case TK_AND:
116266 case TK_OR: {
116267 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116268 if( pAlt!=pExpr ){
116269 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);
116277 }else{
116278 testcase( jumpIfNull==0 );
116279 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
116280 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116281 }
116282 break;
116283 }
116284 case TK_NOT: {
116285 testcase( jumpIfNull==0 );
@@ -116314,14 +116676,20 @@
116314 case TK_LE:
116315 case TK_GT:
116316 case TK_GE:
116317 case TK_NE:
116318 case TK_EQ: {
 
116319 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);
 
 
 
 
 
116323 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116324 r1, r2, dest, jumpIfNull, ExprHasProperty(pExpr,EP_Commuted));
116325 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116326 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116327 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116332,22 +116700,29 @@
116332 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116333 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116334 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116335 testcase( regFree1==0 );
116336 testcase( regFree2==0 );
 
 
 
 
 
 
 
116337 break;
116338 }
116339 case TK_ISNULL:
116340 case TK_NOTNULL: {
116341 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
116342 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
116343 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116344 sqlite3VdbeTypeofColumn(v, r1);
 
116345 sqlite3VdbeAddOp2(v, op, r1, dest);
116346 VdbeCoverageIf(v, op==TK_ISNULL);
116347 VdbeCoverageIf(v, op==TK_NOTNULL);
116348 testcase( regFree1==0 );
116349 break;
116350 }
116351 case TK_BETWEEN: {
116352 testcase( jumpIfNull==0 );
116353 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
@@ -116439,21 +116814,31 @@
116439 case TK_AND:
116440 case TK_OR: {
116441 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116442 if( pAlt!=pExpr ){
116443 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);
116448 }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);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116455 }
116456 break;
116457 }
116458 case TK_NOT: {
116459 testcase( jumpIfNull==0 );
@@ -116491,14 +116876,20 @@
116491 case TK_LE:
116492 case TK_GT:
116493 case TK_GE:
116494 case TK_NE:
116495 case TK_EQ: {
 
116496 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);
 
 
 
 
 
116500 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116501 r1, r2, dest, jumpIfNull,ExprHasProperty(pExpr,EP_Commuted));
116502 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116503 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116504 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116509,20 +116900,27 @@
116509 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116510 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116511 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116512 testcase( regFree1==0 );
116513 testcase( regFree2==0 );
 
 
 
 
 
 
 
116514 break;
116515 }
116516 case TK_ISNULL:
116517 case TK_NOTNULL: {
116518 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116519 sqlite3VdbeTypeofColumn(v, r1);
 
116520 sqlite3VdbeAddOp2(v, op, r1, dest);
116521 testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
116522 testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
116523 testcase( regFree1==0 );
116524 break;
116525 }
116526 case TK_BETWEEN: {
116527 testcase( jumpIfNull==0 );
116528 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfFalse, jumpIfNull);
@@ -117418,11 +117816,13 @@
117418 AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
117419 Expr *pExpr /* Expr describing the column to find or insert */
117420 ){
117421 struct AggInfo_col *pCol;
117422 int k;
 
117423
 
117424 assert( pAggInfo->iFirstReg==0 );
117425 pCol = pAggInfo->aCol;
117426 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
117427 if( pCol->pCExpr==pExpr ) return;
117428 if( pCol->iTable==pExpr->iTable
@@ -117435,10 +117835,14 @@
117435 k = addAggInfoColumn(pParse->db, pAggInfo);
117436 if( k<0 ){
117437 /* OOM on resize */
117438 assert( pParse->db->mallocFailed );
117439 return;
 
 
 
 
117440 }
117441 pCol = &pAggInfo->aCol[k];
117442 assert( ExprUseYTab(pExpr) );
117443 pCol->pTab = pExpr->y.pTab;
117444 pCol->iTable = pExpr->iTable;
@@ -117469,10 +117873,11 @@
117469 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
117470 pExpr->pAggInfo = pAggInfo;
117471 if( pExpr->op==TK_COLUMN ){
117472 pExpr->op = TK_AGG_COLUMN;
117473 }
 
117474 pExpr->iAgg = (i16)k;
117475 }
117476
117477 /*
117478 ** This is the xExprCallback for a tree walker. It is used to
@@ -117553,17 +117958,23 @@
117553 ){
117554 /* Check to see if pExpr is a duplicate of another aggregate
117555 ** function that is already in the pAggInfo structure
117556 */
117557 struct AggInfo_func *pItem = pAggInfo->aFunc;
 
 
117558 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
117559 if( NEVER(pItem->pFExpr==pExpr) ) break;
117560 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
117561 break;
117562 }
117563 }
117564 if( i>=pAggInfo->nFunc ){
 
 
 
 
117565 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
117566 */
117567 u8 enc = ENC(pParse->db);
117568 i = addAggInfoFunc(pParse->db, pAggInfo);
117569 if( i>=0 ){
@@ -117613,10 +118024,11 @@
117613 }
117614 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
117615 */
117616 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
117617 ExprSetVVAProperty(pExpr, EP_NoReduce);
 
117618 pExpr->iAgg = (i16)i;
117619 pExpr->pAggInfo = pAggInfo;
117620 return WRC_Prune;
117621 }else{
117622 return WRC_Continue;
@@ -119015,14 +119427,14 @@
119015 }else{
119016 nQuot = sqlite3Strlen30(zQuot)-1;
119017 }
119018
119019 assert( nQuot>=nNew && nSql>=0 && nNew>=0 );
119020 zOut = sqlite3DbMallocZero(db, (u64)(nSql + pRename->nList*nQuot + 1));
119021 }else{
119022 assert( nSql>0 );
119023 zOut = (char*)sqlite3DbMallocZero(db, (u64)(nSql*2+1) * 3);
119024 if( zOut ){
119025 zBuf1 = &zOut[nSql*2+1];
119026 zBuf2 = &zOut[nSql*4+2];
119027 }
119028 }
@@ -121700,20 +122112,10 @@
121700 }
121701 #endif
121702 while( z[0]!=0 && z[0]!=' ' ) z++;
121703 while( z[0]==' ' ) z++;
121704 }
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 }
121715 }
121716 }
121717
121718 /*
121719 ** This callback is invoked once for each index when reading the
@@ -127256,11 +127658,10 @@
127256 }else{
127257 j = pCExpr->iColumn;
127258 assert( j<=0x7fff );
127259 if( j<0 ){
127260 j = pTab->iPKey;
127261 pIndex->bIdxRowid = 1;
127262 }else{
127263 if( pTab->aCol[j].notNull==0 ){
127264 pIndex->uniqNotNull = 0;
127265 }
127266 if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -128175,20 +128576,26 @@
128175 ** Append the contents of SrcList p2 to SrcList p1 and return the resulting
128176 ** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
128177 ** are deleted by this function.
128178 */
128179 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
128180 assert( p1 && p1->nSrc==1 );
 
 
 
128181 if( p2 ){
128182 SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, 1);
 
128183 if( pNew==0 ){
128184 sqlite3SrcListDelete(pParse->db, p2);
128185 }else{
128186 p1 = pNew;
128187 memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
 
 
 
128188 sqlite3DbFree(pParse->db, p2);
128189 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
128190 }
128191 }
128192 return p1;
128193 }
128194
@@ -132081,11 +132488,11 @@
132081 int argc,
132082 sqlite3_value **argv,
132083 int nSep,
132084 const char *zSep
132085 ){
132086 i64 j, k, n = 0;
132087 int i;
132088 char *z;
132089 for(i=0; i<argc; i++){
132090 n += sqlite3_value_bytes(argv[i]);
132091 }
@@ -132095,12 +132502,12 @@
132095 sqlite3_result_error_nomem(context);
132096 return;
132097 }
132098 j = 0;
132099 for(i=0; i<argc; i++){
132100 k = sqlite3_value_bytes(argv[i]);
132101 if( k>0 ){
132102 const char *v = (const char*)sqlite3_value_text(argv[i]);
132103 if( v!=0 ){
132104 if( j>0 && nSep>0 ){
132105 memcpy(&z[j], zSep, nSep);
132106 j += nSep;
@@ -135034,16 +135441,19 @@
135034 if( iReg==0 ){
135035 /* Move the previous opcode (which should be OP_MakeRecord) forward
135036 ** by one slot and insert a new OP_TypeCheck where the current
135037 ** OP_MakeRecord is found */
135038 VdbeOp *pPrev;
 
135039 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135040 pPrev = sqlite3VdbeGetLastOp(v);
135041 assert( pPrev!=0 );
135042 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
135043 pPrev->opcode = OP_TypeCheck;
135044 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
 
 
135045 }else{
135046 /* Insert an isolated OP_Typecheck */
135047 sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
135048 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135049 }
@@ -138772,10 +139182,12 @@
138772 /* Version 3.43.0 and later */
138773 int (*stmt_explain)(sqlite3_stmt*,int);
138774 /* Version 3.44.0 and later */
138775 void *(*get_clientdata)(sqlite3*,const char*);
138776 int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
 
 
138777 };
138778
138779 /*
138780 ** This is the function signature used for all extension entry points. It
138781 ** is also defined in the file "loadext.c".
@@ -139105,10 +139517,12 @@
139105 /* Version 3.43.0 and later */
139106 #define sqlite3_stmt_explain sqlite3_api->stmt_explain
139107 /* Version 3.44.0 and later */
139108 #define sqlite3_get_clientdata sqlite3_api->get_clientdata
139109 #define sqlite3_set_clientdata sqlite3_api->set_clientdata
 
 
139110 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139111
139112 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139113 /* This case when the file really is being compiled as a loadable
139114 ** extension */
@@ -139626,11 +140040,13 @@
139626 sqlite3_is_interrupted,
139627 /* Version 3.43.0 and later */
139628 sqlite3_stmt_explain,
139629 /* Version 3.44.0 and later */
139630 sqlite3_get_clientdata,
139631 sqlite3_set_clientdata
 
 
139632 };
139633
139634 /* True if x is the directory separator character
139635 */
139636 #if SQLITE_OS_WIN
@@ -145252,11 +145668,11 @@
145252 SrcList *pSrc, /* Array of tables to search */
145253 int iStart, /* First member of pSrc->a[] to check */
145254 int iEnd, /* Last member of pSrc->a[] to check */
145255 const char *zCol, /* Name of the column we are looking for */
145256 int *piTab, /* Write index of pSrc->a[] here */
145257 int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
145258 int bIgnoreHidden /* Ignore hidden columns */
145259 ){
145260 int i; /* For looping over tables in pSrc */
145261 int iCol; /* Index of column matching zCol */
145262
@@ -145464,11 +145880,11 @@
145464 "not present in both tables", zName);
145465 return 1;
145466 }
145467 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145468 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145469 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
145470 /* This branch runs if the query contains one or more RIGHT or FULL
145471 ** JOINs. If only a single table on the left side of this join
145472 ** contains the zName column, then this branch is a no-op.
145473 ** But if there are two or more tables on the left side
145474 ** of the join, construct a coalesce() function that gathers all
@@ -145480,10 +145896,12 @@
145480 ** JOIN. But older versions of SQLite do not do that, so we avoid
145481 ** adding a new error so as to not break legacy applications.
145482 */
145483 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145484 static const Token tkCoalesce = { "coalesce", 8 };
 
 
145485 while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145486 pRight->fg.isSynthUsing)!=0 ){
145487 if( pSrc->a[iLeft].fg.isUsing==0
145488 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145489 ){
@@ -145496,11 +145914,17 @@
145496 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145497 }
145498 if( pFuncArgs ){
145499 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145500 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
 
 
 
145501 }
 
 
 
145502 }
145503 pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145504 sqlite3SrcItemColumnUsed(pRight, iRightCol);
145505 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145506 assert( pE2!=0 || pEq==0 );
@@ -146973,10 +147397,14 @@
146973 #else
146974 zType = columnType(&sNC, p, 0, 0, 0);
146975 #endif
146976 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
146977 }
 
 
 
 
146978 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
146979 }
146980
146981
146982 /*
@@ -147892,11 +148320,13 @@
147892 int unionTab; /* Cursor number of the temp table holding result */
147893 u8 op = 0; /* One of the SRT_ operations to apply to self */
147894 int priorOp; /* The SRT_ operation to apply to prior selects */
147895 Expr *pLimit; /* Saved values of p->nLimit */
147896 int addr;
 
147897 SelectDest uniondest;
 
147898
147899 testcase( p->op==TK_EXCEPT );
147900 testcase( p->op==TK_UNION );
147901 priorOp = SRT_Union;
147902 if( dest.eDest==priorOp ){
@@ -147931,10 +148361,12 @@
147931
147932 /* Code the current SELECT statement
147933 */
147934 if( p->op==TK_EXCEPT ){
147935 op = SRT_Except;
 
 
147936 }else{
147937 assert( p->op==TK_UNION );
147938 op = SRT_Union;
147939 }
147940 p->pPrior = 0;
@@ -147951,10 +148383,11 @@
147951 p->pPrior = pPrior;
147952 p->pOrderBy = 0;
147953 if( p->op==TK_UNION ){
147954 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
147955 }
 
147956 sqlite3ExprDelete(db, p->pLimit);
147957 p->pLimit = pLimit;
147958 p->iLimit = 0;
147959 p->iOffset = 0;
147960
@@ -147981,13 +148414,14 @@
147981 }
147982 default: assert( p->op==TK_INTERSECT ); {
147983 int tab1, tab2;
147984 int iCont, iBreak, iStart;
147985 Expr *pLimit;
147986 int addr;
147987 SelectDest intersectdest;
147988 int r1;
 
147989
147990 /* INTERSECT is different from the others since it requires
147991 ** two temporary tables. Hence it has its own case. Begin
147992 ** by allocating the tables we will need.
147993 */
@@ -148008,18 +148442,32 @@
148008 rc = sqlite3Select(pParse, pPrior, &intersectdest);
148009 if( rc ){
148010 goto multi_select_end;
148011 }
148012
 
 
 
 
 
 
148013 /* Code the current SELECT into temporary table "tab2"
148014 */
148015 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
148016 assert( p->addrOpenEphm[1] == -1 );
148017 p->addrOpenEphm[1] = addr;
148018 p->pPrior = 0;
 
 
148019 pLimit = p->pLimit;
 
 
 
148020 p->pLimit = 0;
 
 
 
148021 intersectdest.iSDParm = tab2;
148022 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
148023 sqlite3SelectOpName(p->op)));
148024 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
148025 rc = sqlite3Select(pParse, p, &intersectdest);
@@ -148028,32 +148476,35 @@
148028 p->pPrior = pPrior;
148029 if( p->nSelectRow>pPrior->nSelectRow ){
148030 p->nSelectRow = pPrior->nSelectRow;
148031 }
148032 sqlite3ExprDelete(db, p->pLimit);
 
 
148033 p->pLimit = pLimit;
 
 
148034
148035 /* Generate code to take the intersection of the two temporary
148036 ** tables.
148037 */
148038 if( rc ) break;
148039 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);
148044 r1 = sqlite3GetTempReg(pParse);
148045 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
 
148046 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
148047 VdbeCoverage(v);
148048 sqlite3ReleaseTempReg(pParse, r1);
148049 selectInnerLoop(pParse, p, tab1,
148050 0, 0, &dest, iCont, iBreak);
148051 sqlite3VdbeResolveLabel(v, iCont);
148052 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
148053 sqlite3VdbeResolveLabel(v, iBreak);
148054 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
 
148055 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
148056 break;
148057 }
148058 }
148059
@@ -148728,10 +149179,11 @@
148728 typedef struct SubstContext {
148729 Parse *pParse; /* The parsing context */
148730 int iTable; /* Replace references to this table */
148731 int iNewTable; /* New table number */
148732 int isOuterJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
 
148733 ExprList *pEList; /* Replacement expressions */
148734 ExprList *pCList; /* Collation sequences for replacement expr */
148735 } SubstContext;
148736
148737 /* Forward Declarations */
@@ -148834,10 +149286,13 @@
148834 }
148835 }
148836 }else{
148837 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
148838 pExpr->iTable = pSubst->iNewTable;
 
 
 
148839 }
148840 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
148841 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
148842 if( ExprUseXSelect(pExpr) ){
148843 substSelect(pSubst, pExpr->x.pSelect, 1);
@@ -148872,10 +149327,11 @@
148872 ){
148873 SrcList *pSrc;
148874 SrcItem *pItem;
148875 int i;
148876 if( !p ) return;
 
148877 do{
148878 substExprList(pSubst, p->pEList);
148879 substExprList(pSubst, p->pGroupBy);
148880 substExprList(pSubst, p->pOrderBy);
148881 p->pHaving = substExpr(pSubst, p->pHaving);
@@ -148889,10 +149345,11 @@
148889 if( pItem->fg.isTabFunc ){
148890 substExprList(pSubst, pItem->u1.pFuncArg);
148891 }
148892 }
148893 }while( doPrior && (p = p->pPrior)!=0 );
 
148894 }
148895 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
148896
148897 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
148898 /*
@@ -149104,13 +149561,13 @@
149104 ** other than the one FROM-clause subquery that is a candidate
149105 ** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149106 ** from 2015-02-09.)
149107 **
149108 ** (3) If the subquery is the right operand of a LEFT JOIN then
149109 ** (3a) the subquery may not be a join and
149110 ** (3b) the FROM clause of the subquery may not contain a virtual
149111 ** table and
149112 ** (**) Was: "The outer query may not have a GROUP BY." This case
149113 ** is now managed correctly
149114 ** (3d) the outer query may not be DISTINCT.
149115 ** See also (26) for restrictions on RIGHT JOIN.
149116 **
@@ -149322,11 +149779,11 @@
149322 **
149323 ** See also tickets #306, #350, and #3300.
149324 */
149325 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149326 if( pSubSrc->nSrc>1 /* (3a) */
149327 || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */
149328 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149329 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149330 ){
149331 return 0;
149332 }
@@ -149500,11 +149957,11 @@
149500 /* Defer deleting the Table object associated with the
149501 ** subquery until code generation is
149502 ** complete, since there may still exist Expr.pTab entries that
149503 ** refer to the subquery even after flattening. Ticket #3346.
149504 **
149505 ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
149506 */
149507 if( ALWAYS(pSubitem->pSTab!=0) ){
149508 Table *pTabToDel = pSubitem->pSTab;
149509 if( pTabToDel->nTabRef==1 ){
149510 Parse *pToplevel = sqlite3ParseToplevel(pParse);
@@ -149630,10 +150087,11 @@
149630 SubstContext x;
149631 x.pParse = pParse;
149632 x.iTable = iParent;
149633 x.iNewTable = iNewParent;
149634 x.isOuterJoin = isOuterJoin;
 
149635 x.pEList = pSub->pEList;
149636 x.pCList = findLeftmostExprlist(pSub);
149637 substSelect(&x, pParent, 0);
149638 }
149639
@@ -150215,10 +150673,11 @@
150215 unsetJoinExpr(pNew, -1, 1);
150216 x.pParse = pParse;
150217 x.iTable = pSrc->iCursor;
150218 x.iNewTable = pSrc->iCursor;
150219 x.isOuterJoin = 0;
 
150220 x.pEList = pSubq->pEList;
150221 x.pCList = findLeftmostExprlist(pSubq);
150222 pNew = substExpr(&x, pNew);
150223 #ifndef SQLITE_OMIT_WINDOWFUNC
150224 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -150612,11 +151071,11 @@
150612 ** a WITH clause on the stack currently maintained by the parser (on the
150613 ** pParse->pWith linked list). And if currently processing a CTE
150614 ** CTE expression, through routine checks to see if the reference is
150615 ** a recursive reference to the CTE.
150616 **
150617 ** If pFrom matches a CTE according to either of these two above, pFrom->pTab
150618 ** and other fields are populated accordingly.
150619 **
150620 ** Return 0 if no match is found.
150621 ** Return 1 if a match is found.
150622 ** Return 2 if an error condition is detected.
@@ -152238,10 +152697,87 @@
152238 pItem--;
152239 if( pItem->fg.isSubquery ) return 0; /* (1c-i) */
152240 }
152241 return 1;
152242 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152243
152244 /*
152245 ** Generate byte-code for the SELECT statement given in the p argument.
152246 **
152247 ** The results are returned according to the SelectDest structure.
@@ -152606,10 +153142,17 @@
152606 #endif
152607 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
152608 return rc;
152609 }
152610 #endif
 
 
 
 
 
 
 
152611
152612 /* Do the WHERE-clause constant propagation optimization if this is
152613 ** a join. No need to spend time on this operation for non-join queries
152614 ** as the equivalent optimization will be handled by query planner in
152615 ** sqlite3WhereBegin(). tag-select-0330
@@ -153366,10 +153909,14 @@
153366 }
153367
153368 if( iOrderByCol ){
153369 Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
153370 Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
 
 
 
 
153371 if( ALWAYS(pBase!=0)
153372 && pBase->op!=TK_AGG_COLUMN
153373 && pBase->op!=TK_REGISTER
153374 ){
153375 sqlite3ExprToRegister(pX, iAMem+j);
@@ -153389,24 +153936,24 @@
153389 ** over to a0,a1,a2. It then calls the output subroutine
153390 ** and resets the aggregate accumulator registers in preparation
153391 ** for the next GROUP BY batch.
153392 */
153393 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153394 VdbeComment((v, "output one row"));
153395 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
153396 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
153397 VdbeComment((v, "check abort flag"));
153398 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
153399 VdbeComment((v, "reset accumulator"));
153400
153401 /* Update the aggregate accumulators based on the content of
153402 ** the current row
153403 */
153404 sqlite3VdbeJumpHere(v, addr1);
153405 updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
153406 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
153407 VdbeComment((v, "indicate data in accumulator"));
153408
153409 /* End of the loop
153410 */
153411 if( groupBySort ){
153412 sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx,addrTopOfLoop);
@@ -153419,11 +153966,11 @@
153419 sqlite3ExprListDelete(db, pDistinct);
153420
153421 /* Output the final row of result
153422 */
153423 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153424 VdbeComment((v, "output final row"));
153425
153426 /* Jump over the subroutines
153427 */
153428 sqlite3VdbeGoto(v, addrEnd);
153429
@@ -153440,26 +153987,26 @@
153440 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153441 sqlite3VdbeResolveLabel(v, addrOutputRow);
153442 addrOutputRow = sqlite3VdbeCurrentAddr(v);
153443 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
153444 VdbeCoverage(v);
153445 VdbeComment((v, "Groupby result generator entry point"));
153446 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153447 finalizeAggFunctions(pParse, pAggInfo);
153448 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
153449 selectInnerLoop(pParse, p, -1, &sSort,
153450 &sDistinct, pDest,
153451 addrOutputRow+1, addrSetAbort);
153452 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153453 VdbeComment((v, "end groupby result generator"));
153454
153455 /* Generate a subroutine that will reset the group-by accumulator
153456 */
153457 sqlite3VdbeResolveLabel(v, addrReset);
153458 resetAccumulator(pParse, pAggInfo);
153459 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
153460 VdbeComment((v, "indicate accumulator empty"));
153461 sqlite3VdbeAddOp1(v, OP_Return, regReset);
153462
153463 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
153464 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
153465 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
@@ -157343,11 +157890,12 @@
157343 saved_flags = db->flags;
157344 saved_mDbFlags = db->mDbFlags;
157345 saved_nChange = db->nChange;
157346 saved_nTotalChange = db->nTotalChange;
157347 saved_mTrace = db->mTrace;
157348 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments;
 
157349 db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157350 db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157351 | SQLITE_Defensive | SQLITE_CountRows);
157352 db->mTrace = 0;
157353
@@ -159046,10 +159594,11 @@
159046 struct WhereLevel {
159047 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
159048 int iTabCur; /* The VDBE cursor used to access the table */
159049 int iIdxCur; /* The VDBE cursor used to access pIdx */
159050 int addrBrk; /* Jump here to break out of the loop */
 
159051 int addrNxt; /* Jump here to start the next IN combination */
159052 int addrSkip; /* Jump here for next iteration of skip-scan */
159053 int addrCont; /* Jump here to continue with the next loop cycle */
159054 int addrFirst; /* First instruction of interior of the loop */
159055 int addrBody; /* Beginning of the body of this loop */
@@ -159251,10 +159800,13 @@
159251 u16 eOperator; /* A WO_xx value describing <op> */
159252 u8 nChild; /* Number of children that must disable us */
159253 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159254 int iParent; /* Disable pWC->a[iParent] when this term disabled */
159255 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
 
 
 
159256 union {
159257 struct {
159258 int leftColumn; /* Column number of X in "X <op> <expr>" */
159259 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159260 } x; /* Opcode other than OP_OR or OP_AND */
@@ -159743,11 +160295,10 @@
159743 #if !defined(SQLITE_DEBUG)
159744 if( sqlite3ParseToplevel(pParse)->explain==2 || IS_STMT_SCANSTATUS(pParse->db) )
159745 #endif
159746 {
159747 VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe, addr);
159748
159749 SrcItem *pItem = &pTabList->a[pLevel->iFrom];
159750 sqlite3 *db = pParse->db; /* Database handle */
159751 int isSearch; /* True for a SEARCH. False for SCAN. */
159752 WhereLoop *pLoop; /* The controlling WhereLoop object */
159753 u32 flags; /* Flags that describe this loop */
@@ -159766,11 +160317,14 @@
159766 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
159767 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
159768
159769 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
159770 str.printfFlags = SQLITE_PRINTF_INTERNAL;
159771 sqlite3_str_appendf(&str, "%s %S", isSearch ? "SEARCH" : "SCAN", pItem);
 
 
 
159772 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
159773 const char *zFmt = 0;
159774 Index *pIdx;
159775
159776 assert( pLoop->u.btree.pIndex!=0 );
@@ -160215,11 +160769,13 @@
160215 for(i=iEq; i<pLoop->nLTerm; i++){
160216 if( pLoop->aLTerm[i]->pExpr==pX ){
160217 int iField;
160218 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
160219 iField = pLoop->aLTerm[i]->u.x.iField - 1;
160220 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
 
 
160221 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
160222 pOrigRhs->a[iField].pExpr = 0;
160223 if( pRhs ) pRhs->a[pRhs->nExpr-1].u.x.iOrderByCol = iField+1;
160224 if( pOrigLhs ){
160225 assert( pOrigLhs->a[iField].pExpr!=0 );
@@ -160312,35 +160868,26 @@
160312 if( pLoop->aLTerm[i] && pLoop->aLTerm[i]->pExpr==pX ){
160313 disableTerm(pLevel, pTerm);
160314 return;
160315 }
160316 }
160317 for(i=iEq;i<pLoop->nLTerm; i++){
160318 assert( pLoop->aLTerm[i]!=0 );
160319 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
160320 }
160321
160322 iTab = 0;
160323 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
160324 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
160325 }else{
160326 Expr *pExpr = pTerm->pExpr;
160327 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
160328 sqlite3 *db = pParse->db;
160329 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
160330 if( !db->mallocFailed ){
160331 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
160332 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
160333 pExpr->iTable = iTab;
160334 }
160335 sqlite3ExprDelete(db, pX);
160336 }else{
160337 int n = sqlite3ExprVectorSize(pX->pLeft);
160338 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*MAX(nEq,n));
160339 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
160340 }
160341 pX = pExpr;
160342 }
160343
160344 if( eType==IN_INDEX_INDEX_DESC ){
160345 testcase( bRev );
160346 bRev = !bRev;
@@ -160366,11 +160913,11 @@
160366 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
160367 pIn = pLevel->u.in.aInLoop;
160368 if( pIn ){
160369 int iMap = 0; /* Index in aiMap[] */
160370 pIn += i;
160371 for(i=iEq;i<pLoop->nLTerm; i++){
160372 if( pLoop->aLTerm[i]->pExpr==pX ){
160373 int iOut = iTarget + i - iEq;
160374 if( eType==IN_INDEX_ROWID ){
160375 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
160376 }else{
@@ -161017,19 +161564,20 @@
161017 WhereInfo *pWInfo, /* Complete information about the WHERE clause */
161018 int iLevel, /* Which level of pWInfo->a[] should be coded */
161019 int addrNxt, /* Jump here to bypass inner loops */
161020 Bitmask notReady /* Loops that are not ready */
161021 ){
 
161022 while( ++iLevel < pWInfo->nLevel ){
161023 WhereLevel *pLevel = &pWInfo->a[iLevel];
161024 WhereLoop *pLoop = pLevel->pWLoop;
161025 if( pLevel->regFilter==0 ) continue;
161026 if( pLevel->pWLoop->nSkip ) continue;
161027 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
161028 ** vvvvv--' pLevel->regFilter if this were true. */
161029 if( NEVER(pLoop->prereq & notReady) ) continue;
161030 assert( pLevel->addrBrk==0 );
161031 pLevel->addrBrk = addrNxt;
161032 if( pLoop->wsFlags & WHERE_IPK ){
161033 WhereTerm *pTerm = pLoop->aLTerm[0];
161034 int regRowid;
161035 assert( pTerm!=0 );
@@ -161055,11 +161603,11 @@
161055 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
161056 addrNxt, r1, nEq);
161057 VdbeCoverage(pParse->pVdbe);
161058 }
161059 pLevel->regFilter = 0;
161060 pLevel->addrBrk = 0;
161061 }
161062 }
161063
161064 /*
161065 ** Loop pLoop is a WHERE_INDEXED level that uses at least one IN(...)
@@ -161102,11 +161650,10 @@
161102 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
161103 WhereTerm *pTerm; /* A WHERE clause term */
161104 sqlite3 *db; /* Database connection */
161105 SrcItem *pTabItem; /* FROM clause term being coded */
161106 int addrBrk; /* Jump here to break out of the loop */
161107 int addrHalt; /* addrBrk for the outermost loop */
161108 int addrCont; /* Jump here to continue with next cycle */
161109 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
161110 int iReleaseReg = 0; /* Temp register to free before returning */
161111 Index *pIdx = 0; /* Index used by loop (if any) */
161112 int iLoop; /* Iteration of constraint generator loop */
@@ -161146,11 +161693,11 @@
161146 ** When there is an IN operator, we also have a "addrNxt" label that
161147 ** means to continue with the next IN value combination. When
161148 ** there are no IN operators in the constraints, the "addrNxt" label
161149 ** is the same as "addrBrk".
161150 */
161151 addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
161152 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
161153
161154 /* If this is the right table of a LEFT OUTER JOIN, allocate and
161155 ** initialize a memory cell that records if this table matches any
161156 ** row of the left table of the join.
@@ -161162,18 +161709,10 @@
161162 pLevel->iLeftJoin = ++pParse->nMem;
161163 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
161164 VdbeComment((v, "init LEFT JOIN match flag"));
161165 }
161166
161167 /* Compute a safe address to jump to if we discover that the table for
161168 ** this loop is empty and can never contribute content. */
161169 for(j=iLevel; j>0; j--){
161170 if( pWInfo->a[j].iLeftJoin ) break;
161171 if( pWInfo->a[j].pRJ ) break;
161172 }
161173 addrHalt = pWInfo->a[j].addrBrk;
161174
161175 /* Special case of a FROM clause subquery implemented as a co-routine */
161176 if( pTabItem->fg.viaCoroutine ){
161177 int regYield;
161178 Subquery *pSubq;
161179 assert( pTabItem->fg.isSubquery && pTabItem->u4.pSubq!=0 );
@@ -161408,11 +161947,11 @@
161408 VdbeCoverageIf(v, pX->op==TK_LE);
161409 VdbeCoverageIf(v, pX->op==TK_LT);
161410 VdbeCoverageIf(v, pX->op==TK_GE);
161411 sqlite3ReleaseTempReg(pParse, rTemp);
161412 }else{
161413 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt);
161414 VdbeCoverageIf(v, bRev==0);
161415 VdbeCoverageIf(v, bRev!=0);
161416 }
161417 if( pEnd ){
161418 Expr *pX;
@@ -161448,40 +161987,40 @@
161448 VdbeCoverageIf(v, testOp==OP_Ge);
161449 VdbeCoverageIf(v, testOp==OP_Gt);
161450 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161451 }
161452 }else if( pLoop->wsFlags & WHERE_INDEXED ){
161453 /* Case 4: A scan using an index.
161454 **
161455 ** The WHERE clause may contain zero or more equality
161456 ** terms ("==" or "IN" operators) that refer to the N
161457 ** left-most columns of the index. It may also contain
161458 ** inequality constraints (>, <, >= or <=) on the indexed
161459 ** column that immediately follows the N equalities. Only
161460 ** the right-most column can be an inequality - the rest must
161461 ** use the "==" and "IN" operators. For example, if the
161462 ** index is on (x,y,z), then the following clauses are all
161463 ** optimized:
161464 **
161465 ** x=5
161466 ** x=5 AND y=10
161467 ** x=5 AND y<10
161468 ** x=5 AND y>5 AND y<10
161469 ** x=5 AND y=5 AND z<=10
161470 **
161471 ** The z<10 term of the following cannot be used, only
161472 ** the x=5 term:
161473 **
161474 ** x=5 AND z<10
161475 **
161476 ** N may be zero if there are inequality constraints.
161477 ** If there are no inequality constraints, then N is at
161478 ** least one.
161479 **
161480 ** This case is also used when there are no WHERE clause
161481 ** constraints but an index is selected anyway, in order
161482 ** to force the output order to conform to an ORDER BY.
161483 */
161484 static const u8 aStartOp[] = {
161485 0,
161486 0,
161487 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -161818,16 +162357,17 @@
161818 }
161819
161820 if( pLevel->iLeftJoin==0 ){
161821 /* If a partial index is driving the loop, try to eliminate WHERE clause
161822 ** terms from the query that must be true due to the WHERE clause of
161823 ** the partial index.
 
161824 **
161825 ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
161826 ** for a LEFT JOIN.
161827 */
161828 if( pIdx->pPartIdxWhere ){
161829 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161830 }
161831 }else{
161832 testcase( pIdx->pPartIdxWhere );
161833 /* The following assert() is not a requirement, merely an observation:
@@ -162202,11 +162742,11 @@
162202 pLevel->op = OP_Noop;
162203 }else{
162204 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
162205 pLevel->op = aStep[bRev];
162206 pLevel->p1 = iCur;
162207 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt);
162208 VdbeCoverageIf(v, bRev==0);
162209 VdbeCoverageIf(v, bRev!=0);
162210 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
162211 }
162212 }
@@ -163496,34 +164036,46 @@
163496 ** column references. This routine checks to see if pExpr is an equivalence
163497 ** relation:
163498 ** 1. The SQLITE_Transitive optimization must be enabled
163499 ** 2. Must be either an == or an IS operator
163500 ** 3. Not originating in the ON clause of an OUTER JOIN
163501 ** 4. The affinities of A and B must be compatible
163502 ** 5a. Both operands use the same collating sequence OR
163503 ** 5b. The overall collating sequence is BINARY
 
163504 ** If this routine returns TRUE, that means that the RHS can be substituted
163505 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
163506 ** This is an optimization. No harm comes from returning 0. But if 1 is
163507 ** returned when it should not be, then incorrect answers might result.
163508 */
163509 static int termIsEquivalence(Parse *pParse, Expr *pExpr){
163510 char aff1, aff2;
163511 CollSeq *pColl;
163512 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
163513 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
163514 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
 
 
 
 
 
 
 
163515 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
163516 aff2 = sqlite3ExprAffinity(pExpr->pRight);
163517 if( aff1!=aff2
163518 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
163519 ){
163520 return 0;
163521 }
163522 pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
163523 if( sqlite3IsBinary(pColl) ) return 1;
163524 return sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight);
 
 
 
 
163525 }
163526
163527 /*
163528 ** Recursively walk the expressions of a SELECT statement and generate
163529 ** a bitmask indicating which tables are used in that expression
@@ -163677,10 +164229,13 @@
163677 if( db->mallocFailed ){
163678 return;
163679 }
163680 assert( pWC->nTerm > idxTerm );
163681 pTerm = &pWC->a[idxTerm];
 
 
 
163682 pMaskSet = &pWInfo->sMaskSet;
163683 pExpr = pTerm->pExpr;
163684 assert( pExpr!=0 ); /* Because malloc() has not failed */
163685 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
163686 pMaskSet->bVarSelect = 0;
@@ -163784,12 +164339,12 @@
163784 pNew = &pWC->a[idxNew];
163785 markTermAsChild(pWC, idxNew, idxTerm);
163786 if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
163787 pTerm = &pWC->a[idxTerm];
163788 pTerm->wtFlags |= TERM_COPIED;
163789
163790 if( termIsEquivalence(pParse, pDup) ){
163791 pTerm->eOperator |= WO_EQUIV;
163792 eExtraOp = WO_EQUIV;
163793 }
163794 }else{
163795 pDup = pExpr;
@@ -164091,11 +164646,11 @@
164091 pNewExpr->w.iJoin = pExpr->w.iJoin;
164092 }
164093 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
164094 testcase( idxNew==0 );
164095 pNewTerm = &pWC->a[idxNew];
164096 pNewTerm->prereqRight = prereqExpr;
164097 pNewTerm->leftCursor = pLeft->iTable;
164098 pNewTerm->u.x.leftColumn = pLeft->iColumn;
164099 pNewTerm->eOperator = WO_AUX;
164100 pNewTerm->eMatchOp = eOp2;
164101 markTermAsChild(pWC, idxNew, idxTerm);
@@ -164202,11 +164757,11 @@
164202 ** SELECT statement passed as the second argument. These terms are only
164203 ** added if:
164204 **
164205 ** 1. The SELECT statement has a LIMIT clause, and
164206 ** 2. The SELECT statement is not an aggregate or DISTINCT query, and
164207 ** 3. The SELECT statement has exactly one object in its from clause, and
164208 ** that object is a virtual table, and
164209 ** 4. There are no terms in the WHERE clause that will not be passed
164210 ** to the virtual table xBestIndex method.
164211 ** 5. The ORDER BY clause, if any, will be made available to the xBestIndex
164212 ** method.
@@ -164239,12 +164794,26 @@
164239 ** pWC->a[] array. So this term can be ignored, as a LIMIT clause
164240 ** will only be added if each of the child terms passes the
164241 ** (leftCursor==iCsr) test below. */
164242 continue;
164243 }
164244 if( pWC->a[ii].leftCursor!=iCsr ) return;
164245 if( pWC->a[ii].prereqRight!=0 ) return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164246 }
164247
164248 /* Check condition (5). Return early if it is not met. */
164249 if( pOrderBy ){
164250 for(ii=0; ii<pOrderBy->nExpr; ii++){
@@ -164904,15 +165473,15 @@
164904 continue;
164905 }
164906 pScan->pWC = pWC;
164907 pScan->k = k+1;
164908 #ifdef WHERETRACE_ENABLED
164909 if( sqlite3WhereTrace & 0x20000 ){
164910 int ii;
164911 sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
164912 pTerm, pScan->nEquiv);
164913 for(ii=0; ii<pScan->nEquiv; ii++){
164914 sqlite3DebugPrintf(" {%d:%d}",
164915 pScan->aiCur[ii], pScan->aiColumn[ii]);
164916 }
164917 sqlite3DebugPrintf("\n");
164918 }
@@ -165679,11 +166248,13 @@
165679 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
165680 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
165681 VdbeCoverage(v);
165682 VdbeComment((v, "next row of %s", pSrc->pSTab->zName));
165683 }else{
165684 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
 
 
165685 }
165686 if( pPartial ){
165687 iContinue = sqlite3VdbeMakeLabel(pParse);
165688 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
165689 pLoop->wsFlags |= WHERE_PARTIALIDX;
@@ -165707,15 +166278,18 @@
165707 assert( pLevel->iIdxCur>0 );
165708 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
165709 pSrc->u4.pSubq->regResult, pLevel->iIdxCur);
165710 sqlite3VdbeGoto(v, addrTop);
165711 pSrc->fg.viaCoroutine = 0;
 
165712 }else{
165713 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
165714 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
 
 
 
165715 }
165716 sqlite3VdbeJumpHere(v, addrTop);
165717 sqlite3ReleaseTempReg(pParse, regRecord);
165718
165719 /* Jump here when skipping the initialization */
165720 sqlite3VdbeJumpHere(v, addrInit);
165721 sqlite3VdbeScanStatusRange(v, addrExp, addrExp, -1);
@@ -166863,10 +167437,11 @@
166863 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
166864 pTerm->u.pOrInfo->indexable);
166865 }else{
166866 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
166867 }
 
166868 sqlite3DebugPrintf(
166869 "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
166870 iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
166871 /* The 0x10000 .wheretrace flag causes extra information to be
166872 ** shown about each Term */
@@ -167637,15 +168212,12 @@
167637 opMask = WO_LT|WO_LE;
167638 }else{
167639 assert( pNew->u.btree.nBtm==0 );
167640 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
167641 }
167642 if( pProbe->bUnordered || pProbe->bLowQual ){
167643 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
167644 if( pProbe->bLowQual && pSrc->fg.isIndexedBy==0 ){
167645 opMask &= ~(WO_EQ|WO_IN|WO_IS);
167646 }
167647 }
167648
167649 assert( pNew->u.btree.nEq<pProbe->nColumn );
167650 assert( pNew->u.btree.nEq<pProbe->nKeyCol
167651 || pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY );
@@ -167714,19 +168286,33 @@
167714 if( eOp & WO_IN ){
167715 Expr *pExpr = pTerm->pExpr;
167716 if( ExprUseXSelect(pExpr) ){
167717 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
167718 int i;
 
167719 nIn = 46; assert( 46==sqlite3LogEst(25) );
167720
167721 /* The expression may actually be of the form (x, y) IN (SELECT...).
167722 ** In this case there is a separate term for each of (x) and (y).
167723 ** However, the nIn multiplier should only be applied once, not once
167724 ** for each such term. The following loop checks that pTerm is the
167725 ** first such term in use, and sets nIn back to 0 if it is not. */
167726 for(i=0; i<pNew->nLTerm-1; i++){
167727 if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
167728 }
167729 }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
167730 /* "x IN (value, value, ...)" */
167731 nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
167732 }
@@ -167954,11 +168540,11 @@
167954 }
167955
167956 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167957 && pNew->u.btree.nEq<pProbe->nColumn
167958 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
167959 (pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY && !pProbe->bIdxRowid))
167960 ){
167961 if( pNew->u.btree.nEq>3 ){
167962 sqlite3ProgressCheck(pParse);
167963 }
167964 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -167993,10 +168579,11 @@
167993 && saved_nEq==pNew->nLTerm
167994 && pProbe->noSkipScan==0
167995 && pProbe->hasStat1!=0
167996 && OptimizationEnabled(db, SQLITE_SkipScan)
167997 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
 
167998 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
167999 ){
168000 LogEst nIter;
168001 pNew->u.btree.nEq++;
168002 pNew->nSkip++;
@@ -168083,10 +168670,11 @@
168083 Expr *pExpr;
168084 pExpr = pTerm->pExpr;
168085 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
168086 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
168087 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
 
168088 && (pTerm->wtFlags & TERM_VNULL)==0
168089 ){
168090 return 1;
168091 }
168092 }
@@ -168578,11 +169166,11 @@
168578 }
168579 }else if( m==0
168580 && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
168581 ){
168582 WHERETRACE(0x200,
168583 ("-> %s a covering index according to bitmasks\n",
168584 pProbe->zName, m==0 ? "is" : "is not"));
168585 pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
168586 }
168587 }
168588
@@ -171549,10 +172137,18 @@
171549
171550 pTabItem = &pTabList->a[pLevel->iFrom];
171551 pTab = pTabItem->pSTab;
171552 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
171553 pLoop = pLevel->pWLoop;
 
 
 
 
 
 
 
 
171554 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
171555 /* Do nothing */
171556 }else
171557 #ifndef SQLITE_OMIT_VIRTUALTABLE
171558 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -171600,10 +172196,17 @@
171600 }
171601 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
171602 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
171603 (const u8*)&pTabItem->colUsed, P4_INT64);
171604 #endif
 
 
 
 
 
 
 
171605 }else{
171606 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
171607 }
171608 if( pLoop->wsFlags & WHERE_INDEXED ){
171609 Index *pIx = pLoop->u.btree.pIndex;
@@ -171856,10 +172459,13 @@
171856 VdbeCoverageIf(v, op==OP_SeekLT);
171857 VdbeCoverageIf(v, op==OP_SeekGT);
171858 sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
171859 }
171860 #endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
 
 
 
171861 /* The common case: Advance to the next row */
171862 if( pLevel->addrCont ) sqlite3VdbeResolveLabel(v, pLevel->addrCont);
171863 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
171864 sqlite3VdbeChangeP5(v, pLevel->p5);
171865 VdbeCoverage(v);
@@ -179928,16 +180534,25 @@
179928 /* Expressions of the form
179929 **
179930 ** expr1 IN ()
179931 ** expr1 NOT IN ()
179932 **
179933 ** simplify to constants 0 (false) and 1 (true), respectively,
179934 ** regardless of the value of expr1.
 
 
 
 
179935 */
179936 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy590);
179937 yymsp[-4].minor.yy590 = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy502 ? "true" : "false");
179938 if( yymsp[-4].minor.yy590 ) sqlite3ExprIdToTrueFalse(yymsp[-4].minor.yy590);
 
 
 
 
 
179939 }else{
179940 Expr *pRHS = yymsp[-1].minor.yy402->a[0].pExpr;
179941 if( yymsp[-1].minor.yy402->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && yymsp[-4].minor.yy590->op!=TK_VECTOR ){
179942 yymsp[-1].minor.yy402->a[0].pExpr = 0;
179943 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy402);
@@ -181539,11 +182154,11 @@
181539 static int getToken(const unsigned char **pz){
181540 const unsigned char *z = *pz;
181541 int t; /* Token type to return */
181542 do {
181543 z += sqlite3GetToken(z, &t);
181544 }while( t==TK_SPACE );
181545 if( t==TK_ID
181546 || t==TK_STRING
181547 || t==TK_JOIN_KW
181548 || t==TK_WINDOW
181549 || t==TK_OVER
@@ -184489,10 +185104,11 @@
184489 #ifdef SQLITE_ENABLE_API_ARMOR
184490 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
184491 #endif
184492 if( ms<-1 ) return SQLITE_RANGE;
184493 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
 
184494 db->setlkTimeout = ms;
184495 db->setlkFlags = flags;
184496 sqlite3BtreeEnterAll(db);
184497 for(iDb=0; iDb<db->nDb; iDb++){
184498 Btree *pBt = db->aDb[iDb].pBt;
@@ -184500,10 +185116,11 @@
184500 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
184501 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
184502 }
184503 }
184504 sqlite3BtreeLeaveAll(db);
 
184505 #endif
184506 #if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
184507 UNUSED_PARAMETER(db);
184508 UNUSED_PARAMETER(flags);
184509 #endif
@@ -188886,11 +189503,11 @@
188886
188887 /*
188888 ** Macros needed to provide flexible arrays in a portable way
188889 */
188890 #ifndef offsetof
188891 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
188892 #endif
188893 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
188894 # define FLEXARRAY
188895 #else
188896 # define FLEXARRAY 1
@@ -209119,12 +209736,14 @@
209119 nExtra = 0;
209120 }else if( szType==12 ){
209121 nExtra = 1;
209122 }else if( szType==13 ){
209123 nExtra = 2;
209124 }else{
209125 nExtra = 4;
 
 
209126 }
209127 if( szPayload<=11 ){
209128 nNeeded = 0;
209129 }else if( szPayload<=0xff ){
209130 nNeeded = 1;
@@ -209590,11 +210209,16 @@
209590 c = z[++j];
209591 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
209592 || c=='n' || c=='r' || c=='t'
209593 || (c=='u' && jsonIs4Hex(&z[j+1])) ){
209594 if( opcode==JSONB_TEXT ) opcode = JSONB_TEXTJ;
209595 }else if( c=='\'' || c=='0' || c=='v' || c=='\n'
 
 
 
 
 
209596 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
209597 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
209598 || (c=='x' && jsonIs2Hex(&z[j+1])) ){
209599 opcode = JSONB_TEXT5;
209600 pParse->hasNonstd = 1;
@@ -209977,11 +210601,11 @@
209977 || pParse->aBlob[i+4]!=0
209978 ){
209979 *pSz = 0;
209980 return 0;
209981 }
209982 sz = (pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
209983 (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
209984 n = 9;
209985 }
209986 if( (i64)i+sz+n > pParse->nBlob
209987 && (i64)i+sz+n > pParse->nBlob-pParse->delta
@@ -210558,11 +211182,25 @@
210558 case 'f': { *piOut = '\f'; return 2; }
210559 case 'n': { *piOut = '\n'; return 2; }
210560 case 'r': { *piOut = '\r'; return 2; }
210561 case 't': { *piOut = '\t'; return 2; }
210562 case 'v': { *piOut = '\v'; return 2; }
210563 case '0': { *piOut = 0; return 2; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210564 case '\'':
210565 case '"':
210566 case '/':
210567 case '\\':{ *piOut = z[1]; return 2; }
210568 case 'x': {
@@ -212665,22 +213303,24 @@
212665 const char *z;
212666 u32 n;
212667 UNUSED_PARAMETER(argc);
212668 pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
212669 if( pStr ){
 
 
212670 if( pStr->zBuf==0 ){
212671 jsonStringInit(pStr, ctx);
212672 jsonAppendChar(pStr, '{');
212673 }else if( pStr->nUsed>1 ){
212674 jsonAppendChar(pStr, ',');
212675 }
212676 pStr->pCtx = ctx;
212677 z = (const char*)sqlite3_value_text(argv[0]);
212678 n = sqlite3Strlen30(z);
212679 jsonAppendString(pStr, z, n);
212680 jsonAppendChar(pStr, ':');
212681 jsonAppendSqlValue(pStr, argv[1]);
212682 }
212683 }
212684 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
212685 JsonString *pStr;
212686 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
@@ -213484,10 +214124,12 @@
213484 #else
213485 /* #include "sqlite3.h" */
213486 #endif
213487 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213488
 
 
213489 /*
213490 ** If building separately, we will need some setup that is normally
213491 ** found in sqliteInt.h
213492 */
213493 #if !defined(SQLITE_AMALGAMATION)
@@ -213515,11 +214157,11 @@
213515 #else
213516 # define ALWAYS(X) (X)
213517 # define NEVER(X) (X)
213518 #endif
213519 #ifndef offsetof
213520 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
213521 #endif
213522 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
213523 # define FLEXARRAY
213524 #else
213525 # define FLEXARRAY 1
@@ -214553,10 +215195,16 @@
214553 pStmt = pCsr->pReadAux;
214554 memset(pCsr, 0, sizeof(RtreeCursor));
214555 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
214556 pCsr->pReadAux = pStmt;
214557
 
 
 
 
 
 
214558 }
214559
214560 /*
214561 ** Rtree virtual table module xClose method.
214562 */
@@ -227832,11 +228480,12 @@
227832 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
227833 int rc;
227834 sqlite3 *db = pTab->db;
227835 Btree *pBt;
227836
227837 (void)idxStr;
 
227838
227839 /* Default setting is no rows of result */
227840 pCsr->pgno = 1;
227841 pCsr->mxPgno = 0;
227842
@@ -231494,18 +232143,19 @@
231494 /*
231495 ** If the SessionInput object passed as the only argument is a streaming
231496 ** object and the buffer is full, discard some data to free up space.
231497 */
231498 static void sessionDiscardData(SessionInput *pIn){
231499 if( pIn->xInput && pIn->iNext>=sessions_strm_chunk_size ){
231500 int nMove = pIn->buf.nBuf - pIn->iNext;
231501 assert( nMove>=0 );
231502 if( nMove>0 ){
231503 memmove(pIn->buf.aBuf, &pIn->buf.aBuf[pIn->iNext], nMove);
231504 }
231505 pIn->buf.nBuf -= pIn->iNext;
231506 pIn->iNext = 0;
 
231507 pIn->nData = pIn->buf.nBuf;
231508 }
231509 }
231510
231511 /*
@@ -231855,12 +232505,12 @@
231855 ** sufficient either for the 'T' or 'P' byte and the varint that follows
231856 ** it, or for the two single byte values otherwise. */
231857 p->rc = sessionInputBuffer(&p->in, 2);
231858 if( p->rc!=SQLITE_OK ) return p->rc;
231859
231860 sessionDiscardData(&p->in);
231861 p->in.iCurrent = p->in.iNext;
 
231862
231863 /* If the iterator is already at the end of the changeset, return DONE. */
231864 if( p->in.iNext>=p->in.nData ){
231865 return SQLITE_DONE;
231866 }
@@ -233279,10 +233929,14 @@
233279 sqlite3_changeset_iter *pIter, /* Changeset to apply */
233280 int(*xFilter)(
233281 void *pCtx, /* Copy of sixth arg to _apply() */
233282 const char *zTab /* Table name */
233283 ),
 
 
 
 
233284 int(*xConflict)(
233285 void *pCtx, /* Copy of fifth arg to _apply() */
233286 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233287 sqlite3_changeset_iter *p /* Handle describing change and conflict */
233288 ),
@@ -233418,10 +234072,13 @@
233418 }
233419
233420 /* If there is a schema mismatch on the current table, proceed to the
233421 ** next change. A log message has already been issued. */
233422 if( schemaMismatch ) continue;
 
 
 
233423
233424 rc = sessionApplyOneWithRetry(db, pIter, &sApply, xConflict, pCtx);
233425 }
233426
233427 bPatchset = pIter->bPatchset;
@@ -233485,10 +234142,91 @@
233485 db->aDb[0].pSchema->schema_cookie -= 32;
233486 }
233487 sqlite3_mutex_leave(sqlite3_db_mutex(db));
233488 return rc;
233489 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233490
233491 /*
233492 ** Apply the changeset passed via pChangeset/nChangeset to the main
233493 ** database attached to handle "db".
233494 */
@@ -233507,21 +234245,43 @@
233507 ),
233508 void *pCtx, /* First argument passed to xConflict */
233509 void **ppRebase, int *pnRebase,
233510 int flags
233511 ){
233512 sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
233513 int bInv = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
233514 int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
233515
233516 if( rc==SQLITE_OK ){
233517 rc = sessionChangesetApply(
233518 db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
233519 );
233520 }
233521
233522 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233523 }
233524
233525 /*
233526 ** Apply the changeset passed via pChangeset/nChangeset to the main database
233527 ** attached to handle "db". Invoke the supplied conflict handler callback
@@ -233540,20 +234300,45 @@
233540 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233541 sqlite3_changeset_iter *p /* Handle describing change and conflict */
233542 ),
233543 void *pCtx /* First argument passed to xConflict */
233544 ){
233545 return sqlite3changeset_apply_v2(
233546 db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
 
 
233547 );
233548 }
233549
233550 /*
233551 ** Apply the changeset passed via xInput/pIn to the main database
233552 ** attached to handle "db". Invoke the supplied conflict handler callback
233553 ** to resolve any conflicts encountered while applying the change.
233554 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233555 SQLITE_API int sqlite3changeset_apply_v2_strm(
233556 sqlite3 *db, /* Apply change to "main" db of this handle */
233557 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
233558 void *pIn, /* First arg for xInput */
233559 int(*xFilter)(
@@ -233567,19 +234352,15 @@
233567 ),
233568 void *pCtx, /* First argument passed to xConflict */
233569 void **ppRebase, int *pnRebase,
233570 int flags
233571 ){
233572 sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
233573 int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
233574 int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
233575 if( rc==SQLITE_OK ){
233576 rc = sessionChangesetApply(
233577 db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
233578 );
233579 }
233580 return rc;
233581 }
233582 SQLITE_API int sqlite3changeset_apply_strm(
233583 sqlite3 *db, /* Apply change to "main" db of this handle */
233584 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
233585 void *pIn, /* First arg for xInput */
@@ -233592,12 +234373,14 @@
233592 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233593 sqlite3_changeset_iter *p /* Handle describing change and conflict */
233594 ),
233595 void *pCtx /* First argument passed to xConflict */
233596 ){
233597 return sqlite3changeset_apply_v2_strm(
233598 db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
 
 
233599 );
233600 }
233601
233602 /*
233603 ** sqlite3_changegroup handle.
@@ -234215,18 +234998,23 @@
234215 */
234216 SQLITE_API int sqlite3changegroup_add_change(
234217 sqlite3_changegroup *pGrp,
234218 sqlite3_changeset_iter *pIter
234219 ){
 
 
234220 if( pIter->in.iCurrent==pIter->in.iNext
234221 || pIter->rc!=SQLITE_OK
234222 || pIter->bInvert
234223 ){
234224 /* Iterator does not point to any valid entry or is an INVERT iterator. */
234225 return SQLITE_ERROR;
 
 
 
234226 }
234227 return sessionOneChangeToHash(pGrp, pIter, 0);
234228 }
234229
234230 /*
234231 ** Obtain a buffer containing a changeset representing the concatenation
234232 ** of all changesets added to the group so far.
@@ -235520,10 +236308,11 @@
235520 /* #include "sqlite3ext.h" */
235521 SQLITE_EXTENSION_INIT1
235522
235523 /* #include <string.h> */
235524 /* #include <assert.h> */
 
235525
235526 #ifndef SQLITE_AMALGAMATION
235527
235528 typedef unsigned char u8;
235529 typedef unsigned int u32;
@@ -235579,11 +236368,11 @@
235579
235580 /*
235581 ** Macros needed to provide flexible arrays in a portable way
235582 */
235583 #ifndef offsetof
235584 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
235585 #endif
235586 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235587 # define FLEXARRAY
235588 #else
235589 # define FLEXARRAY 1
@@ -244763,10 +245552,40 @@
244763 Fts5Buffer term; /* Current term */
244764 i64 iRowid; /* Current rowid */
244765 int nPos; /* Number of bytes in current position list */
244766 u8 bDel; /* True if the delete flag is set */
244767 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244768
244769 /*
244770 ** Array of tombstone pages. Reference counted.
244771 */
244772 struct Fts5TombstoneArray {
@@ -245053,11 +245872,11 @@
245053 /* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245054 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245055 ** All the reasons those functions might return SQLITE_ERROR - missing
245056 ** table, missing row, non-blob/text in block column - indicate
245057 ** backing store corruption. */
245058 if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;
245059
245060 if( rc==SQLITE_OK ){
245061 u8 *aOut = 0; /* Read blob data into this buffer */
245062 int nByte = sqlite3_blob_bytes(p->pReader);
245063 int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245103,11 +245922,11 @@
245103
245104 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245105 Fts5Data *pRet = fts5DataRead(p, iRowid);
245106 if( pRet ){
245107 if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245108 p->rc = FTS5_CORRUPT;
245109 fts5DataRelease(pRet);
245110 pRet = 0;
245111 }
245112 }
245113 return pRet;
@@ -245462,12 +246281,18 @@
245462 pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
245463 if( p->rc==SQLITE_OK ){
245464 /* TODO: Do we need this if the leaf-index is appended? Probably... */
245465 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245466 p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
245467 if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245468 p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
 
 
 
 
 
 
245469 }
245470 fts5DataRelease(pData);
245471 if( p->rc!=SQLITE_OK ){
245472 fts5StructureRelease(pRet);
245473 pRet = 0;
@@ -246086,11 +246911,11 @@
246086
246087 ASSERT_SZLEAF_OK(pIter->pLeaf);
246088 while( iOff>=pIter->pLeaf->szLeaf ){
246089 fts5SegIterNextPage(p, pIter);
246090 if( pIter->pLeaf==0 ){
246091 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
246092 return;
246093 }
246094 iOff = 4;
246095 a = pIter->pLeaf->p;
246096 }
@@ -246118,11 +246943,11 @@
246118 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246119 int nNew; /* Bytes of new data */
246120
246121 iOff += fts5GetVarint32(&a[iOff], nNew);
246122 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246123 p->rc = FTS5_CORRUPT;
246124 return;
246125 }
246126 pIter->term.n = nKeep;
246127 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246128 assert( pIter->term.n<=pIter->term.nSpace );
@@ -246160,13 +246985,13 @@
246160 ** Allocate a tombstone hash page array object (pIter->pTombArray) for
246161 ** the iterator passed as the second argument. If an OOM error occurs,
246162 ** leave an error in the Fts5Index object.
246163 */
246164 static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
246165 const int nTomb = pIter->pSeg->nPgTombstone;
246166 if( nTomb>0 ){
246167 int nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
246168 Fts5TombstoneArray *pNew;
246169 pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
246170 if( pNew ){
246171 pNew->nTombstone = nTomb;
246172 pNew->nRef = 1;
@@ -246313,11 +247138,11 @@
246313 }else{
246314 int iRowidOff;
246315 iRowidOff = fts5LeafFirstRowidOff(pNew);
246316 if( iRowidOff ){
246317 if( iRowidOff>=pNew->szLeaf ){
246318 p->rc = FTS5_CORRUPT;
246319 }else{
246320 pIter->pLeaf = pNew;
246321 pIter->iLeafOffset = iRowidOff;
246322 }
246323 }
@@ -246547,11 +247372,11 @@
246547 pIter->iEndofDoclist = iOff;
246548 bNewTerm = 1;
246549 }
246550 assert_nc( iOff<pLeaf->szLeaf );
246551 if( iOff>pLeaf->szLeaf ){
246552 p->rc = FTS5_CORRUPT;
246553 return;
246554 }
246555 }
246556 }
246557
@@ -246655,22 +247480,24 @@
246655 if( pLast ){
246656 int iOff;
246657 fts5DataRelease(pIter->pLeaf);
246658 pIter->pLeaf = pLast;
246659 pIter->iLeafPgno = pgnoLast;
246660 iOff = fts5LeafFirstRowidOff(pLast);
246661 if( iOff>pLast->szLeaf ){
246662 p->rc = FTS5_CORRUPT;
246663 return;
246664 }
246665 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
246666 pIter->iLeafOffset = iOff;
246667
246668 if( fts5LeafIsTermless(pLast) ){
246669 pIter->iEndofDoclist = pLast->nn+1;
246670 }else{
246671 pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
 
 
246672 }
246673 }
246674
246675 fts5SegIterReverseInitPage(p, pIter);
246676 }
@@ -246736,11 +247563,11 @@
246736
246737 iPgidx = (u32)pIter->pLeaf->szLeaf;
246738 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
246739 iOff = iTermOff;
246740 if( iOff>n ){
246741 p->rc = FTS5_CORRUPT;
246742 return;
246743 }
246744
246745 while( 1 ){
246746
@@ -246779,11 +247606,11 @@
246779 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
246780 iTermOff += nKeep;
246781 iOff = iTermOff;
246782
246783 if( iOff>=n ){
246784 p->rc = FTS5_CORRUPT;
246785 return;
246786 }
246787
246788 /* Read the nKeep field of the next term. */
246789 fts5FastGetVarint32(a, iOff, nKeep);
@@ -246801,11 +247628,11 @@
246801 a = pIter->pLeaf->p;
246802 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246803 iPgidx = (u32)pIter->pLeaf->szLeaf;
246804 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
246805 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
246806 p->rc = FTS5_CORRUPT;
246807 return;
246808 }else{
246809 nKeep = 0;
246810 iTermOff = iOff;
246811 n = (u32)pIter->pLeaf->nn;
@@ -246816,11 +247643,11 @@
246816 }while( 1 );
246817 }
246818
246819 search_success:
246820 if( (i64)iOff+nNew>n || nNew<1 ){
246821 p->rc = FTS5_CORRUPT;
246822 return;
246823 }
246824 pIter->iLeafOffset = iOff + nNew;
246825 pIter->iTermLeafOffset = pIter->iLeafOffset;
246826 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247281,11 +248108,11 @@
247281 int iLeafPgno
247282 ){
247283 assert( iLeafPgno>pIter->iLeafPgno );
247284
247285 if( iLeafPgno>pIter->pSeg->pgnoLast ){
247286 p->rc = FTS5_CORRUPT;
247287 }else{
247288 fts5DataRelease(pIter->pNextLeaf);
247289 pIter->pNextLeaf = 0;
247290 pIter->iLeafPgno = iLeafPgno-1;
247291
@@ -247296,11 +248123,11 @@
247296 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
247297 if( iOff>0 ){
247298 u8 *a = pIter->pLeaf->p;
247299 int n = pIter->pLeaf->szLeaf;
247300 if( iOff<4 || iOff>=n ){
247301 p->rc = FTS5_CORRUPT;
247302 }else{
247303 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
247304 pIter->iLeafOffset = iOff;
247305 fts5SegIterLoadNPos(p, pIter);
247306 }
@@ -247775,11 +248602,11 @@
247775 nRem -= nChunk;
247776 fts5DataRelease(pData);
247777 if( nRem<=0 ){
247778 break;
247779 }else if( pSeg->pSeg==0 ){
247780 p->rc = FTS5_CORRUPT;
247781 return;
247782 }else{
247783 pgno++;
247784 pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
247785 if( pData==0 ) break;
@@ -248878,11 +249705,11 @@
248878 if( iOff>pData->szLeaf ){
248879 /* This can occur if the pages that the segments occupy overlap - if
248880 ** a single page has been assigned to more than one segment. In
248881 ** this case a prior iteration of this loop may have corrupted the
248882 ** segment currently being trimmed. */
248883 p->rc = FTS5_CORRUPT;
248884 }else{
248885 fts5BufferZero(&buf);
248886 fts5BufferGrow(&p->rc, &buf, pData->nn);
248887 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
248888 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249345,11 +250172,11 @@
249345 fts5DataRelease(pLeaf);
249346 pLeaf = 0;
249347 }else if( bDetailNone ){
249348 break;
249349 }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
249350 p->rc = FTS5_CORRUPT;
249351 break;
249352 }else{
249353 int nShift = iNext - 4;
249354 int nPg;
249355
@@ -249365,11 +250192,11 @@
249365 int i1 = pLeaf->szLeaf;
249366 int i2 = 0;
249367
249368 i1 += fts5GetVarint32(&aPg[i1], iFirst);
249369 if( iFirst<iNext ){
249370 p->rc = FTS5_CORRUPT;
249371 break;
249372 }
249373 aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
249374 if( aIdx==0 ) break;
249375 i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249588,18 +250415,18 @@
249588
249589 nPrefix = MIN(nPrefix, nPrefix2);
249590 nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
249591
249592 if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
249593 p->rc = FTS5_CORRUPT;
249594 }else{
249595 if( iKey!=1 ){
249596 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
249597 }
249598 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
249599 if( nPrefix2>pSeg->term.n ){
249600 p->rc = FTS5_CORRUPT;
249601 }else if( nPrefix2>nPrefix ){
249602 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
249603 iOff += (nPrefix2-nPrefix);
249604 }
249605 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250019,11 +250846,11 @@
250019 }
250020 assert( pStruct->aLevel[i].nMerge<=nThis );
250021 }
250022
250023 nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
250024 assert( nByte==SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
250025 pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
250026
250027 if( pNew ){
250028 Fts5StructureLevel *pLvl;
250029 nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -250388,11 +251215,11 @@
250388 fts5PrefixMergerInsertByPosition(&pHead, pSave);
250389 pSave = pNext;
250390 }
250391
250392 if( pHead==0 || pHead->pNext==0 ){
250393 p->rc = FTS5_CORRUPT;
250394 break;
250395 }
250396
250397 /* See the earlier comment in this function for an explanation of why
250398 ** corrupt input position lists might cause the output to consume
@@ -250425,11 +251252,11 @@
250425
250426 /* WRITEPOSLISTSIZE */
250427 assert_nc( tmp.n+nTail<=nTmp );
250428 assert( tmp.n+nTail<=nTmp+nMerge*10 );
250429 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
250430 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
250431 break;
250432 }
250433 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
250434 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
250435 if( nTail>0 ){
@@ -252458,23 +253285,31 @@
252458 }
252459
252460 /*
252461 ** This function is also purely an internal test. It does not contribute to
252462 ** FTS functionality, or even the integrity-check, in any way.
 
 
 
252463 */
252464 static void fts5TestTerm(
252465 Fts5Index *p,
252466 Fts5Buffer *pPrev, /* Previous term */
252467 const char *z, int n, /* Possibly new term to test */
252468 u64 expected,
252469 u64 *pCksum
 
252470 ){
252471 int rc = p->rc;
252472 if( pPrev->n==0 ){
252473 fts5BufferSet(&rc, pPrev, n, (const u8*)z);
252474 }else
252475 if( rc==SQLITE_OK && (pPrev->n!=n || memcmp(pPrev->p, z, n)) ){
 
 
 
 
252476 u64 cksum3 = *pCksum;
252477 const char *zTerm = (const char*)&pPrev->p[1]; /* term sans prefix-byte */
252478 int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
252479 int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
252480 int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
@@ -252520,20 +253355,20 @@
252520
252521 cksum3 ^= ck1;
252522 fts5BufferSet(&rc, pPrev, n, (const u8*)z);
252523
252524 if( rc==SQLITE_OK && cksum3!=expected ){
252525 rc = FTS5_CORRUPT;
252526 }
252527 *pCksum = cksum3;
252528 }
252529 p->rc = rc;
252530 }
252531
252532 #else
252533 # define fts5TestDlidxReverse(x,y,z)
252534 # define fts5TestTerm(u,v,w,x,y,z)
252535 #endif
252536
252537 /*
252538 ** Check that:
252539 **
@@ -252554,18 +253389,21 @@
252554 /* Now check that the iter.nEmpty leaves following the current leaf
252555 ** (a) exist and (b) contain no terms. */
252556 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
252557 Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252558 if( pLeaf ){
252559 if( !fts5LeafIsTermless(pLeaf) ) p->rc = FTS5_CORRUPT;
252560 if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
 
 
 
252561 }
252562 fts5DataRelease(pLeaf);
252563 }
252564 }
252565
252566 static void fts5IntegrityCheckPgidx(Fts5Index *p, Fts5Data *pLeaf){
252567 i64 iTermOff = 0;
252568 int ii;
252569
252570 Fts5Buffer buf1 = {0,0,0};
252571 Fts5Buffer buf2 = {0,0,0};
@@ -252579,33 +253417,33 @@
252579 ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
252580 iTermOff += nIncr;
252581 iOff = iTermOff;
252582
252583 if( iOff>=pLeaf->szLeaf ){
252584 p->rc = FTS5_CORRUPT;
252585 }else if( iTermOff==nIncr ){
252586 int nByte;
252587 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252588 if( (iOff+nByte)>pLeaf->szLeaf ){
252589 p->rc = FTS5_CORRUPT;
252590 }else{
252591 fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252592 }
252593 }else{
252594 int nKeep, nByte;
252595 iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
252596 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252597 if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
252598 p->rc = FTS5_CORRUPT;
252599 }else{
252600 buf1.n = nKeep;
252601 fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252602 }
252603
252604 if( p->rc==SQLITE_OK ){
252605 res = fts5BufferCompare(&buf1, &buf2);
252606 if( res<=0 ) p->rc = FTS5_CORRUPT;
252607 }
252608 }
252609 fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
252610 }
252611
@@ -252662,11 +253500,11 @@
252662 ){
252663 /* special case - the very first page in a segment keeps its %_idx
252664 ** entry even if all the terms are removed from it by secure-delete
252665 ** operations. */
252666 }else{
252667 p->rc = FTS5_CORRUPT;
252668 }
252669
252670 }else{
252671 int iOff; /* Offset of first term on leaf */
252672 int iRowidOff; /* Offset of first rowid on leaf */
@@ -252674,19 +253512,19 @@
252674 int res; /* Comparison of term and split-key */
252675
252676 iOff = fts5LeafFirstTermOff(pLeaf);
252677 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252678 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
252679 p->rc = FTS5_CORRUPT;
252680 }else{
252681 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
252682 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
252683 if( res==0 ) res = nTerm - nIdxTerm;
252684 if( res<0 ) p->rc = FTS5_CORRUPT;
252685 }
252686
252687 fts5IntegrityCheckPgidx(p, pLeaf);
252688 }
252689 fts5DataRelease(pLeaf);
252690 if( p->rc ) break;
252691
252692 /* Now check that the iter.nEmpty leaves following the current leaf
@@ -252712,11 +253550,11 @@
252712 /* Check any rowid-less pages that occur before the current leaf. */
252713 for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
252714 iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
252715 pLeaf = fts5DataRead(p, iKey);
252716 if( pLeaf ){
252717 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
252718 fts5DataRelease(pLeaf);
252719 }
252720 }
252721 iPrevLeaf = fts5DlidxIterPgno(pDlidx);
252722
@@ -252727,16 +253565,16 @@
252727 if( pLeaf ){
252728 i64 iRowid;
252729 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252730 ASSERT_SZLEAF_OK(pLeaf);
252731 if( iRowidOff>=pLeaf->szLeaf ){
252732 p->rc = FTS5_CORRUPT;
252733 }else if( bSecureDelete==0 || iRowidOff>0 ){
252734 i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
252735 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
252736 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252737 p->rc = FTS5_CORRUPT;
252738 }
252739 }
252740 fts5DataRelease(pLeaf);
252741 }
252742 }
@@ -252784,10 +253622,11 @@
252784
252785 #ifdef SQLITE_DEBUG
252786 /* Used by extra internal tests only run if NDEBUG is not defined */
252787 u64 cksum3 = 0; /* Checksum based on contents of indexes */
252788 Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
 
252789 #endif
252790 const int flags = FTS5INDEX_QUERY_NOOUTPUT;
252791
252792 /* Load the FTS index structure */
252793 pStruct = fts5StructureRead(p);
@@ -252826,11 +253665,11 @@
252826 int iOff = 0; /* Offset within poslist */
252827 i64 iRowid = fts5MultiIterRowid(pIter);
252828 char *z = (char*)fts5MultiIterTerm(pIter, &n);
252829
252830 /* If this is a new term, query for it. Update cksum3 with the results. */
252831 fts5TestTerm(p, &term, z, n, cksum2, &cksum3);
252832 if( p->rc ) break;
252833
252834 if( eDetail==FTS5_DETAIL_NONE ){
252835 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
252836 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
@@ -252844,19 +253683,30 @@
252844 int iTokOff = FTS5_POS2OFFSET(iPos);
252845 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, iCol, iTokOff, -1, z, n);
252846 }
252847 }
252848 }
252849 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
252850
252851 fts5MultiIterFree(pIter);
252852 if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ) p->rc = FTS5_CORRUPT;
252853
252854 fts5StructureRelease(pStruct);
 
 
 
252855 #ifdef SQLITE_DEBUG
 
 
 
 
 
 
252856 fts5BufferFree(&term);
252857 #endif
 
 
252858 fts5BufferFree(&poslist);
252859 return fts5IndexReturn(p);
252860 }
252861
252862 /*************************************************************************
@@ -257263,11 +258113,11 @@
257263 int nArg, /* Number of args */
257264 sqlite3_value **apUnused /* Function arguments */
257265 ){
257266 assert( nArg==0 );
257267 UNUSED_PARAM2(nArg, apUnused);
257268 sqlite3_result_text(pCtx, "fts5: 2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849", -1, SQLITE_TRANSIENT);
257269 }
257270
257271 /*
257272 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257273 **
@@ -257386,12 +258236,13 @@
257386 }else{
257387 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
257388 " FTS5 table %s.%s: %s",
257389 zSchema, zTabname, sqlite3_errstr(rc));
257390 }
 
 
257391 }
257392
257393 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
257394 pTab->p.pConfig->pzErrmsg = 0;
257395
257396 return rc;
257397 }
@@ -258078,10 +258929,11 @@
258078 ctx.pStorage = p;
258079 ctx.iCol = -1;
258080 for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258081 if( pConfig->abUnindexed[iCol-1]==0 ){
258082 sqlite3_value *pVal = 0;
 
258083 const char *pText = 0;
258084 int nText = 0;
258085 const char *pLoc = 0;
258086 int nLoc = 0;
258087
@@ -258094,15 +258946,26 @@
258094 }
258095
258096 if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258097 rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258098 }else{
258099 pText = (const char*)sqlite3_value_text(pVal);
258100 nText = sqlite3_value_bytes(pVal);
258101 if( pConfig->bLocale && pSeek ){
258102 pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol);
258103 nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
 
 
 
 
 
 
 
 
 
 
 
258104 }
258105 }
258106
258107 if( rc==SQLITE_OK ){
258108 sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258114,10 +258977,11 @@
258114 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258115 rc = FTS5_CORRUPT;
258116 }
258117 sqlite3Fts5ClearLocale(pConfig);
258118 }
 
258119 }
258120 }
258121 if( rc==SQLITE_OK && p->nTotalRow<1 ){
258122 rc = FTS5_CORRUPT;
258123 }else{
258124
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.51.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 9f184f8dfa5ef6d57e10376adc30e0060ced with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -485,13 +485,13 @@
485 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
486 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
487 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
488 ** </pre></blockquote>)^
489 **
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()
493 ** function is provided for use in DLLs since DLL users usually do not have
494 ** direct access to string constants within the DLL. ^The
495 ** sqlite3_libversion_number() function returns an integer equal to
496 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
497 ** a pointer to a string constant whose value is the same as the
@@ -687,11 +687,11 @@
687 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
688 ** that allows an application to run multiple statements of SQL
689 ** without having to use a lot of C code.
690 **
691 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
692 ** semicolon-separated SQL statements passed into its 2nd argument,
693 ** in the context of the [database connection] passed in as its 1st
694 ** argument. ^If the callback function of the 3rd argument to
695 ** sqlite3_exec() is not NULL, then it is invoked for each result row
696 ** coming out of the evaluated SQL statements. ^The 4th argument to
697 ** sqlite3_exec() is relayed through to the 1st argument of each
@@ -720,11 +720,11 @@
720 ** callback is an array of pointers to strings obtained as if from
721 ** [sqlite3_column_text()], one for each column. ^If an element of a
722 ** result row is NULL then the corresponding string pointer for the
723 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
724 ** sqlite3_exec() callback is an array of pointers to strings where each
725 ** entry represents the name of a corresponding result column as obtained
726 ** from [sqlite3_column_name()].
727 **
728 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
729 ** to an empty string, or a pointer that contains only whitespace and/or
730 ** SQL comments, then no SQL statements are evaluated and the database
@@ -906,11 +906,11 @@
906 ** Applications should not depend on the historical behavior.
907 **
908 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
909 ** [sqlite3_open_v2()] does *not* cause the underlying database file
910 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
911 ** [sqlite3_open_v2()] has historically been a no-op and might become an
912 ** error in future versions of SQLite.
913 */
914 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
915 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
916 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -1000,11 +1000,11 @@
1000 ** CAPI3REF: File Locking Levels
1001 **
1002 ** SQLite uses one of these integer values as the second
1003 ** argument to calls it makes to the xLock() and xUnlock() methods
1004 ** of an [sqlite3_io_methods] object. These values are ordered from
1005 ** least restrictive to most restrictive.
1006 **
1007 ** The argument to xLock() is always SHARED or higher. The argument to
1008 ** xUnlock is either SHARED or NONE.
1009 */
1010 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -1316,11 +1316,11 @@
1316 ** reason, the entire database file will be overwritten by the current
1317 ** transaction. This is used by VACUUM operations.
1318 **
1319 ** <li>[[SQLITE_FCNTL_VFSNAME]]
1320 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1321 ** all [VFSes] in the VFS stack. The names of all VFS shims and the
1322 ** final bottom-level VFS are written into memory obtained from
1323 ** [sqlite3_malloc()] and the result is stored in the char* variable
1324 ** that the fourth parameter of [sqlite3_file_control()] points to.
1325 ** The caller is responsible for freeing the memory when done. As with
1326 ** all file-control actions, there is no guarantee that this will actually
@@ -1330,11 +1330,11 @@
1330 **
1331 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1332 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1333 ** [VFSes] currently in use. ^(The argument X in
1334 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1335 ** of type "[sqlite3_vfs] **". This opcode will set *X
1336 ** to a pointer to the top-level VFS.)^
1337 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1338 ** upper-most shim only.
1339 **
1340 ** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1520,11 +1520,11 @@
1520 ** record the fact that the pages have been checkpointed.
1521 **
1522 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1523 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1524 ** 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
1526 ** (void*) argument passed with this file-control should be a pointer to a
1527 ** value of type (int). The integer value is set to 1 if the database is a wal
1528 ** mode database and there exists at least one client in another process that
1529 ** currently has an SQL transaction open on the database. It is set to 0 if
1530 ** the database is not a wal-mode db, or if there is no such connection in any
@@ -1945,11 +1945,11 @@
1945 **
1946 ** ^The sqlite3_initialize() routine is called internally by many other
1947 ** SQLite interfaces so that an application usually does not need to
1948 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1949 ** calls sqlite3_initialize() so the SQLite library will be automatically
1950 ** initialized when [sqlite3_open()] is called if it has not been initialized
1951 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1952 ** compile-time option, then the automatic calls to sqlite3_initialize()
1953 ** are omitted and the application must call sqlite3_initialize() directly
1954 ** prior to using any other SQLite interface. For maximum portability,
1955 ** it is recommended that applications always invoke sqlite3_initialize()
@@ -2202,25 +2202,25 @@
2202 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
2203 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
2204 ** The [sqlite3_mem_methods]
2205 ** structure is filled with the currently defined memory allocation routines.)^
2206 ** This option can be used to overload the default memory allocation
2207 ** routines with a wrapper that simulates memory allocation failure or
2208 ** tracks memory usage, for example. </dd>
2209 **
2210 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2211 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of
2212 ** type int, interpreted as a boolean, which if true provides a hint to
2213 ** SQLite that it should avoid large memory allocations if possible.
2214 ** SQLite will run faster if it is free to make large memory allocations,
2215 ** but some applications might prefer to run slower in exchange for
2216 ** guarantees about memory fragmentation that are possible if large
2217 ** allocations are avoided. This hint is normally off.
2218 ** </dd>
2219 **
2220 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2221 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,
2222 ** interpreted as a boolean, which enables or disables the collection of
2223 ** memory allocation statistics. ^(When memory allocation statistics are
2224 ** disabled, the following SQLite interfaces become non-operational:
2225 ** <ul>
2226 ** <li> [sqlite3_hard_heap_limit64()]
@@ -2261,11 +2261,11 @@
2261 ** a page cache line is larger than sz bytes or if all of the pMem buffer
2262 ** is exhausted.
2263 ** ^If pMem is NULL and N is non-zero, then each database connection
2264 ** does an initial bulk allocation for page cache memory
2265 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
2266 ** of -1024*N bytes if N is negative. ^If additional
2267 ** page cache memory is needed beyond what is provided by the initial
2268 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
2269 ** additional cache line. </dd>
2270 **
2271 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -2290,11 +2290,11 @@
2290 **
2291 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
2292 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
2293 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
2294 ** The argument specifies alternative low-level mutex routines to be used
2295 ** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of
2296 ** the content of the [sqlite3_mutex_methods] structure before the call to
2297 ** [sqlite3_config()] returns. ^If SQLite is compiled with
2298 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2299 ** the entire mutexing subsystem is omitted from the build and hence calls to
2300 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2332,11 +2332,11 @@
2332 ** the interface to a custom page cache implementation.)^
2333 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2334 **
2335 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2336 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2337 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off
2338 ** the current page cache implementation into that object.)^ </dd>
2339 **
2340 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2341 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2342 ** global [error log].
@@ -2349,11 +2349,11 @@
2349 ** passed through as the first parameter to the application-defined logger
2350 ** function whenever that function is invoked. ^The second parameter to
2351 ** the logger function is a copy of the first parameter to the corresponding
2352 ** [sqlite3_log()] call and is intended to be a [result code] or an
2353 ** [extended result code]. ^The third parameter passed to the logger is
2354 ** a log message after formatting via [sqlite3_snprintf()].
2355 ** The SQLite logging interface is not reentrant; the logger function
2356 ** supplied by the application must not invoke any SQLite interface.
2357 ** In a multi-threaded application, the application-defined logger
2358 ** function must be threadsafe. </dd>
2359 **
@@ -2540,11 +2540,11 @@
2540 ** CAPI3REF: Database Connection Configuration Options
2541 **
2542 ** These constants are the available integer configuration options that
2543 ** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2544 **
2545 ** The [sqlite3_db_config()] interface is a var-args function. It takes a
2546 ** variable number of parameters, though always at least two. The number of
2547 ** parameters passed into sqlite3_db_config() depends on which of these
2548 ** constants is given as the second parameter. This documentation page
2549 ** refers to parameters beyond the second as "arguments". Thus, when this
2550 ** page says "the N-th argument" it means "the N-th parameter past the
@@ -2674,12 +2674,12 @@
2674 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2675 ** There must be two additional arguments.
2676 ** When the first argument to this interface is 1, then only the C-API is
2677 ** enabled and the SQL function remains disabled. If the first argument to
2678 ** 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 the state of either
2680 ** the C-API or the SQL function.
2681 ** The second parameter is a pointer to an integer into which
2682 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2683 ** is disabled or enabled following this call. The second parameter may
2684 ** be a NULL pointer, in which case the new setting is not reported back.
2685 ** </dd>
@@ -2793,11 +2793,11 @@
2793 ** </dd>
2794 **
2795 ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2796 ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2797 ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2798 ** the legacy behavior of the [ALTER TABLE RENAME] command such that it
2799 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2800 ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2801 ** additional information. This feature can also be turned on and off
2802 ** using the [PRAGMA legacy_alter_table] statement.
2803 ** </dd>
@@ -2842,11 +2842,11 @@
2842 **
2843 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2844 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2845 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2846 ** the legacy file format flag. When activated, this flag causes all newly
2847 ** created database files to have a schema format version number (the 4-byte
2848 ** integer found at offset 44 into the database header) of 1. This in turn
2849 ** means that the resulting database file will be readable and writable by
2850 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2851 ** newly created databases are generally not understandable by SQLite versions
2852 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2869,11 +2869,11 @@
2869 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2870 ** statistics. For statistics to be collected, the flag must be set on
2871 ** the database handle both when the SQL statement is prepared and when it
2872 ** is stepped. The flag is set (collection of statistics is enabled)
2873 ** 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
2875 ** leave unchanged the statement scanstatus option. If the second argument
2876 ** is not NULL, then the value of the statement scanstatus setting after
2877 ** processing the first argument is written into the integer that the second
2878 ** argument points to.
2879 ** </dd>
@@ -2912,12 +2912,12 @@
2912 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2913 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2914 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2915 ** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2916 ** This capability is enabled by default. Applications can disable or
2917 ** reenable this capability using the current DBCONFIG option. If
2918 ** this capability is disabled, the [ATTACH] command will still work,
2919 ** but the database will be opened read-only. If this option is disabled,
2920 ** then the ability to create a new database using [ATTACH] is also disabled,
2921 ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2922 ** option.<p>
2923 ** This option takes two arguments which are an integer and a pointer
@@ -2947,11 +2947,11 @@
2947 **
2948 ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2949 **
2950 ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2951 ** overall call to [sqlite3_db_config()] has a total of four parameters.
2952 ** The first argument (the third parameter to sqlite3_db_config()) is an integer.
2953 ** The second argument is a pointer to an integer. If the first argument is 1,
2954 ** then the option becomes enabled. If the first integer argument is 0, then the
2955 ** option is disabled. If the first argument is -1, then the option setting
2956 ** is unchanged. The second argument, the pointer to an integer, may be NULL.
2957 ** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -3237,11 +3237,11 @@
3237 ** and comments that follow the final semicolon are ignored.
3238 **
3239 ** ^These routines return 0 if the statement is incomplete. ^If a
3240 ** memory allocation fails, then SQLITE_NOMEM is returned.
3241 **
3242 ** ^These routines do not parse the SQL statements and thus
3243 ** will not detect syntactically incorrect SQL.
3244 **
3245 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
3246 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
3247 ** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3354,11 +3354,11 @@
3354 ** Passing 0 to this function disables blocking locks altogether. Passing
3355 ** -1 to this function requests that the VFS blocks for a long time -
3356 ** indefinitely if possible. The results of passing any other negative value
3357 ** are undefined.
3358 **
3359 ** Internally, each SQLite database handle stores two timeout values - the
3360 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3361 ** support blocking locks) and the setlk-timeout (used for blocking locks
3362 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3363 ** values, this function sets only the setlk-timeout value. Therefore,
3364 ** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3384,11 +3384,11 @@
3384 ** METHOD: sqlite3
3385 **
3386 ** This is a legacy interface that is preserved for backwards compatibility.
3387 ** Use of this interface is not recommended.
3388 **
3389 ** Definition: A <b>result table</b> is a memory data structure created by the
3390 ** [sqlite3_get_table()] interface. A result table records the
3391 ** complete query results from one or more queries.
3392 **
3393 ** The table conceptually has a number of rows and columns. But
3394 ** these numbers are not part of the result table itself. These
@@ -3527,11 +3527,11 @@
3527 ** of a signed 32-bit integer.
3528 **
3529 ** ^Calling sqlite3_free() with a pointer previously returned
3530 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3531 ** that it might be reused. ^The sqlite3_free() routine is
3532 ** a no-op if it is called with a NULL pointer. Passing a NULL pointer
3533 ** to sqlite3_free() is harmless. After being freed, memory
3534 ** should neither be read nor written. Even reading previously freed
3535 ** memory might result in a segmentation fault or other severe error.
3536 ** Memory corruption, a segmentation fault, or other severe error
3537 ** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3545,17 +3545,17 @@
3545 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3546 ** negative then the behavior is exactly the same as calling
3547 ** sqlite3_free(X).
3548 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3549 ** 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 of the
3551 ** prior allocation are copied into the beginning of the buffer returned
3552 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
3553 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3554 ** prior allocation is not freed.
3555 **
3556 ** ^The sqlite3_realloc64(X,N) interface works the same as
3557 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3558 ** of a 32-bit signed integer.
3559 **
3560 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3561 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3601,11 +3601,11 @@
3601 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
3602 ** value of [sqlite3_memory_used()] since the high-water mark
3603 ** was last reset. ^The values returned by [sqlite3_memory_used()] and
3604 ** [sqlite3_memory_highwater()] include any overhead
3605 ** added by SQLite in its implementation of [sqlite3_malloc()],
3606 ** but not overhead added by any underlying system library
3607 ** routines that [sqlite3_malloc()] may call.
3608 **
3609 ** ^The memory high-water mark is reset to the current value of
3610 ** [sqlite3_memory_used()] if and only if the parameter to
3611 ** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -4053,19 +4053,19 @@
4053 ** attempt to use the same database connection at the same time.
4054 ** (Mutexes will block any actual concurrency, but in this mode
4055 ** there is no harm in trying.)
4056 **
4057 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
4058 ** <dd>The database is opened with [shared cache] enabled, overriding
4059 ** the default shared cache setting provided by
4060 ** [sqlite3_enable_shared_cache()].)^
4061 ** The [use of shared cache mode is discouraged] and hence shared cache
4062 ** capabilities may be omitted from many builds of SQLite. In such cases,
4063 ** this option is a no-op.
4064 **
4065 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
4066 ** <dd>The database is opened with [shared cache] disabled, overriding
4067 ** the default shared cache setting provided by
4068 ** [sqlite3_enable_shared_cache()].)^
4069 **
4070 ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
4071 ** <dd>The database connection comes up in "extended result code mode".
@@ -4396,11 +4396,11 @@
4396 ** These interfaces are provided for use by [VFS shim] implementations and
4397 ** are not useful outside of that context.
4398 **
4399 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4400 ** database filename D with corresponding journal file J and WAL file W and
4401 ** an array P of N URI Key/Value pairs. The result from
4402 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4403 ** is safe to pass to routines like:
4404 ** <ul>
4405 ** <li> [sqlite3_uri_parameter()],
4406 ** <li> [sqlite3_uri_boolean()],
@@ -4479,19 +4479,19 @@
4479 ** The application does not need to worry about freeing the result.
4480 ** However, the error string might be overwritten or deallocated by
4481 ** subsequent calls to other SQLite interface functions.)^
4482 **
4483 ** ^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 a
4485 ** result code for which a text error message is available.
4486 ** ^(Memory to hold the error message string is managed internally
4487 ** and must not be freed by the application)^.
4488 **
4489 ** ^If the most recent error references a specific token in the input
4490 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4491 ** of the start of that token. ^The byte offset returned by
4492 ** sqlite3_error_offset() assumes that the input SQL is UTF-8.
4493 ** ^If the most recent error does not reference a specific token in the input
4494 ** SQL, then the sqlite3_error_offset() function returns -1.
4495 **
4496 ** When the serialized [threading mode] is in use, it might be the
4497 ** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
4586 ** CAPI3REF: Run-Time Limit Categories
4587 ** KEYWORDS: {limit category} {*limit categories}
4588 **
4589 ** These constants define various performance limits
4590 ** that can be lowered at run-time using [sqlite3_limit()].
4591 ** A concise description of these limits follows, and additional information
4592 ** is available at [limits | Limits in SQLite].
4593 **
4594 ** <dl>
4595 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4596 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4597 **
@@ -4652,11 +4652,11 @@
4652 #define SQLITE_LIMIT_WORKER_THREADS 11
4653
4654 /*
4655 ** CAPI3REF: Prepare Flags
4656 **
4657 ** These constants define various flags that can be passed into the
4658 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4659 ** [sqlite3_prepare16_v3()] interfaces.
4660 **
4661 ** New flags may be added in future releases of SQLite.
4662 **
@@ -4739,11 +4739,11 @@
4739 ** statement is generated.
4740 ** If the caller knows that the supplied string is nul-terminated, then
4741 ** there is a small performance advantage to passing an nByte parameter that
4742 ** is the number of bytes in the input string <i>including</i>
4743 ** the nul-terminator.
4744 ** Note that nByte measures the length of the input in bytes, not
4745 ** characters, even for the UTF-16 interfaces.
4746 **
4747 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4748 ** past the end of the first SQL statement in zSql. These routines only
4749 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
4873 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4874 ** will return "SELECT 2345,NULL".)^
4875 **
4876 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4877 ** is available to hold the result, or if the result would exceed the
4878 ** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4879 **
4880 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4881 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4882 ** option causes sqlite3_expanded_sql() to always return NULL.
4883 **
@@ -5061,11 +5061,11 @@
5061 /*
5062 ** CAPI3REF: SQL Function Context Object
5063 **
5064 ** The context in which an SQL function executes is stored in an
5065 ** sqlite3_context object. ^A pointer to an sqlite3_context object
5066 ** is always the first parameter to [application-defined SQL functions].
5067 ** The application-defined SQL function implementation will pass this
5068 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
5069 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
5070 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
5071 ** and/or [sqlite3_set_auxdata()].
@@ -5077,11 +5077,11 @@
5077 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
5078 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
5079 ** METHOD: sqlite3_stmt
5080 **
5081 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
5082 ** literals may be replaced by a [parameter] that matches one of the following
5083 ** templates:
5084 **
5085 ** <ul>
5086 ** <li> ?
5087 ** <li> ?NNN
@@ -5122,11 +5122,11 @@
5122 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
5123 ** otherwise.
5124 **
5125 ** [[byte-order determination rules]] ^The byte-order of
5126 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
5127 ** found in the first character, which is removed, or in the absence of a BOM
5128 ** the byte order is the native byte order of the host
5129 ** machine for sqlite3_bind_text16() or the byte order specified in
5130 ** the 6th parameter for sqlite3_bind_text64().)^
5131 ** ^If UTF16 input text contains invalid unicode
5132 ** characters, then SQLite might change those invalid characters
@@ -5142,11 +5142,11 @@
5142 ** the behavior is undefined.
5143 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
5144 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
5145 ** that parameter must be the byte offset
5146 ** where the NUL terminator would occur assuming the string were NUL
5147 ** terminated. If any NUL characters occur at byte offsets less than
5148 ** the value of the fourth parameter then the resulting string value will
5149 ** contain embedded NULs. The result of expressions involving strings
5150 ** with embedded NULs is undefined.
5151 **
5152 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5354,11 +5354,11 @@
5354 /*
5355 ** CAPI3REF: Source Of Data In A Query Result
5356 ** METHOD: sqlite3_stmt
5357 **
5358 ** ^These routines provide a means to determine the database, table, and
5359 ** table column that is the origin of a particular result column in a
5360 ** [SELECT] statement.
5361 ** ^The name of the database or table or column can be returned as
5362 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5363 ** the database name, the _table_ routines return the table name, and
5364 ** the origin_ routines return the column name.
@@ -5798,11 +5798,11 @@
5798 ** CAPI3REF: Destroy A Prepared Statement Object
5799 ** DESTRUCTOR: sqlite3_stmt
5800 **
5801 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5802 ** ^If the most recent evaluation of the statement encountered no errors
5803 ** or if the statement has never been evaluated, then sqlite3_finalize() returns
5804 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5805 ** sqlite3_finalize(S) returns the appropriate [error code] or
5806 ** [extended error code].
5807 **
5808 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5923,12 +5923,12 @@
5923 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5924 ** index expressions, or the WHERE clause of partial indexes.
5925 **
5926 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5927 ** all application-defined SQL functions that do not need to be
5928 ** used inside of triggers, views, CHECK constraints, or other elements of
5929 ** the database schema. This flag is especially recommended for SQL
5930 ** functions that have side effects or reveal internal application state.
5931 ** Without this flag, an attacker might be able to modify the schema of
5932 ** a database file to include invocations of the function with parameters
5933 ** chosen by the attacker, which the application will then execute when
5934 ** the database file is opened and read.
@@ -5955,11 +5955,11 @@
5955 ** or aggregate window function. More details regarding the implementation
5956 ** of aggregate window functions are
5957 ** [user-defined window functions|available here].
5958 **
5959 ** ^(If the final parameter to sqlite3_create_function_v2() or
5960 ** sqlite3_create_window_function() is not NULL, then it is the destructor for
5961 ** the application data pointer. The destructor is invoked when the function
5962 ** is deleted, either by being overloaded or when the database connection
5963 ** closes.)^ ^The destructor is also invoked if the call to
5964 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5965 ** invoked, it is passed a single argument which is a copy of the application
@@ -6030,11 +6030,11 @@
6030 );
6031
6032 /*
6033 ** CAPI3REF: Text Encodings
6034 **
6035 ** These constants define integer codes that represent the various
6036 ** text encodings supported by SQLite.
6037 */
6038 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
6039 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
6040 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
6122 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
6123 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
6124 ** result.
6125 ** Every function that invokes [sqlite3_result_subtype()] should have this
6126 ** property. If it does not, then the call to [sqlite3_result_subtype()]
6127 ** might become a no-op if the function is used as a term in an
6128 ** [expression index]. On the other hand, SQL functions that never invoke
6129 ** [sqlite3_result_subtype()] should avoid setting this property, as the
6130 ** purpose of this property is to disable certain optimizations that are
6131 ** incompatible with subtypes.
6132 **
@@ -6249,11 +6249,11 @@
6249 **
6250 ** ^Within the [xUpdate] method of a [virtual table], the
6251 ** sqlite3_value_nochange(X) interface returns true if and only if
6252 ** the column corresponding to X is unchanged by the UPDATE operation
6253 ** that the xUpdate method call was invoked to implement and if
6254 ** the prior [xColumn] method call that was invoked to extract
6255 ** the value for that column returned without setting a result (probably
6256 ** because it queried [sqlite3_vtab_nochange()] and found that the column
6257 ** was unchanging). ^Within an [xUpdate] method, any value for which
6258 ** sqlite3_value_nochange(X) is true will in all other respects appear
6259 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6355,11 +6355,11 @@
6355 /*
6356 ** CAPI3REF: Copy And Free SQL Values
6357 ** METHOD: sqlite3_value
6358 **
6359 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6360 ** object V and returns a pointer to that copy. ^The [sqlite3_value] returned
6361 ** is a [protected sqlite3_value] object even if the input is not.
6362 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
6363 ** memory allocation fails. ^If V is a [pointer value], then the result
6364 ** of sqlite3_value_dup(V) is a NULL value.
6365 **
@@ -6393,11 +6393,11 @@
6393 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
6394 ** when first called if N is less than or equal to zero or if a memory
6395 ** allocation error occurs.
6396 **
6397 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6398 ** determined by the N parameter on the first successful call. Changing the
6399 ** value of N in any subsequent call to sqlite3_aggregate_context() within
6400 ** the same aggregate function instance will not resize the memory
6401 ** allocation.)^ Within the xFinal callback, it is customary to set
6402 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6403 ** pointless memory allocations occur.
@@ -6555,11 +6555,11 @@
6555 ** of as a secret key such that only code that knows the secret key is able
6556 ** to access the associated data.
6557 **
6558 ** Security Warning: These interfaces should not be exposed in scripting
6559 ** languages or in other circumstances where it might be possible for an
6560 ** attacker to invoke them. Any agent that can invoke these interfaces
6561 ** can probably also take control of the process.
6562 **
6563 ** Database connection client data is only available for SQLite
6564 ** version 3.44.0 ([dateof:3.44.0]) and later.
6565 **
@@ -6669,11 +6669,11 @@
6669 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6670 ** is non-negative, then as many bytes (not characters) of the text
6671 ** pointed to by the 2nd parameter are taken as the application-defined
6672 ** function result. If the 3rd parameter is non-negative, then it
6673 ** must be the byte offset into the string where the NUL terminator would
6674 ** appear if the string were NUL terminated. If any NUL characters occur
6675 ** in the string at a byte offset that is less than the value of the 3rd
6676 ** parameter, then the resulting string will contain embedded NULs and the
6677 ** result of expressions operating on strings with embedded NULs is undefined.
6678 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6679 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6727,11 +6727,11 @@
6727 ** for the P parameter. ^SQLite invokes D with P as its only argument
6728 ** when SQLite is finished with P. The T parameter should be a static
6729 ** string and preferably a string literal. The sqlite3_result_pointer()
6730 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6731 **
6732 ** If these routines are called from within a different thread
6733 ** than the one containing the application-defined function that received
6734 ** the [sqlite3_context] pointer, the results are undefined.
6735 */
6736 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
6737 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -7133,11 +7133,11 @@
7133 /*
7134 ** CAPI3REF: Return The Schema Name For A Database Connection
7135 ** METHOD: sqlite3
7136 **
7137 ** ^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 if N is
7139 ** out of range. An N value of 0 means the main database file. An N of 1 is
7140 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
7141 ** databases.
7142 **
7143 ** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -7228,20 +7228,20 @@
7228 **
7229 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
7230 ** <dd>The SQLITE_TXN_READ state means that the database is currently
7231 ** in a read transaction. Content has been read from the database file
7232 ** but nothing in the database file has changed. The transaction state
7233 ** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are
7234 ** no other conflicting concurrent write transactions. The transaction
7235 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
7236 ** [COMMIT].</dd>
7237 **
7238 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
7239 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
7240 ** in a write transaction. Content has been written to the database file
7241 ** but has not yet committed. The transaction state will change to
7242 ** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7243 */
7244 #define SQLITE_TXN_NONE 0
7245 #define SQLITE_TXN_READ 1
7246 #define SQLITE_TXN_WRITE 2
7247
@@ -7518,11 +7518,11 @@
7518
7519 /*
7520 ** CAPI3REF: Impose A Limit On Heap Size
7521 **
7522 ** These interfaces impose limits on the amount of heap memory that will be
7523 ** used by all database connections within a single process.
7524 **
7525 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
7526 ** soft limit on the amount of heap memory that may be allocated by SQLite.
7527 ** ^SQLite strives to keep heap memory utilization below the soft heap
7528 ** limit by reducing the number of pages held in the page cache
@@ -7576,11 +7576,11 @@
7576 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
7577 ** from the heap.
7578 ** </ul>)^
7579 **
7580 ** The circumstances under which SQLite will enforce the heap limits may
7581 ** change in future releases of SQLite.
7582 */
7583 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7584 SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
7585
7586 /*
@@ -7691,12 +7691,12 @@
7691 ** be tried also.
7692 **
7693 ** ^The entry point is zProc.
7694 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7695 ** 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
7697 ** X consists of the lower-case equivalent of all ASCII alphabetic
7698 ** characters in the filename from the last "/" to the first following
7699 ** "." and omitting any initial "lib".)^
7700 ** ^The sqlite3_load_extension() interface returns
7701 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7702 ** ^If an error occurs and pzErrMsg is not 0, then the
@@ -7763,11 +7763,11 @@
7763 ** that is to be automatically loaded into all new database connections.
7764 **
7765 ** ^(Even though the function prototype shows that xEntryPoint() takes
7766 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7767 ** arguments and expects an integer result as if the signature of the
7768 ** entry point were as follows:
7769 **
7770 ** <blockquote><pre>
7771 ** &nbsp; int xEntryPoint(
7772 ** &nbsp; sqlite3 *db,
7773 ** &nbsp; const char **pzErrMsg,
@@ -7927,11 +7927,11 @@
7927 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7928 ** is true, then the constraint is assumed to be fully handled by the
7929 ** virtual table and might not be checked again by the byte code.)^ ^(The
7930 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7931 ** is left in its default setting of false, the constraint will always be
7932 ** checked separately in byte code. If the omit flag is changed to true, then
7933 ** the constraint may or may not be checked in byte code. In other words,
7934 ** when the omit flag is true there is no guarantee that the constraint will
7935 ** not be checked again using byte code.)^
7936 **
7937 ** ^The idxNum and idxStr values are recorded and passed into the
@@ -7953,11 +7953,11 @@
7953 ** will be returned by the strategy.
7954 **
7955 ** The xBestIndex method may optionally populate the idxFlags field with a
7956 ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7957 ** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7958 ** output to show the idxNum as hex instead of as decimal. Another flag is
7959 ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7960 ** return at most one row.
7961 **
7962 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7963 ** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -8094,11 +8094,11 @@
8094 ** by the first parameter. ^The name of the module is given by the
8095 ** second parameter. ^The third parameter is a pointer to
8096 ** the implementation of the [virtual table module]. ^The fourth
8097 ** parameter is an arbitrary client data pointer that is passed through
8098 ** into the [xCreate] and [xConnect] methods of the virtual table module
8099 ** when a new virtual table is being created or reinitialized.
8100 **
8101 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
8102 ** is a pointer to a destructor for the pClientData. ^SQLite will
8103 ** invoke the destructor function (if it is not NULL) when SQLite
8104 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -8259,11 +8259,11 @@
8259 **
8260 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
8261 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
8262 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
8263 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
8264 ** on *ppBlob after this function returns.
8265 **
8266 ** This function fails with SQLITE_ERROR if any of the following are true:
8267 ** <ul>
8268 ** <li> ^(Database zDb does not exist)^,
8269 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8379,11 +8379,11 @@
8379 ** CAPI3REF: Return The Size Of An Open BLOB
8380 ** METHOD: sqlite3_blob
8381 **
8382 ** ^Returns the size in bytes of the BLOB accessible via the
8383 ** successfully opened [BLOB handle] in its only argument. ^The
8384 ** incremental blob I/O routines can only read or overwrite existing
8385 ** blob content; they cannot change the size of a blob.
8386 **
8387 ** This routine only works on a [BLOB handle] which has been created
8388 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8389 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -8529,11 +8529,11 @@
8529 ** function that calls sqlite3_initialize().
8530 **
8531 ** ^The sqlite3_mutex_alloc() routine allocates a new
8532 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8533 ** routine returns NULL if it is unable to allocate the requested
8534 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
8535 ** integer constants:
8536 **
8537 ** <ul>
8538 ** <li> SQLITE_MUTEX_FAST
8539 ** <li> SQLITE_MUTEX_RECURSIVE
@@ -8762,11 +8762,11 @@
8762
8763 /*
8764 ** CAPI3REF: Retrieve the mutex for a database connection
8765 ** METHOD: sqlite3
8766 **
8767 ** ^This interface returns a pointer to the [sqlite3_mutex] object that
8768 ** serializes access to the [database connection] given in the argument
8769 ** when the [threading mode] is Serialized.
8770 ** ^If the [threading mode] is Single-thread or Multi-thread then this
8771 ** routine returns a NULL pointer.
8772 */
@@ -8885,11 +8885,11 @@
8885
8886 /*
8887 ** CAPI3REF: SQL Keyword Checking
8888 **
8889 ** These routines provide access to the set of SQL language keywords
8890 ** recognized by SQLite. Applications can use these routines to determine
8891 ** whether or not a specific identifier needs to be escaped (for example,
8892 ** by enclosing in double-quotes) so as not to confuse the parser.
8893 **
8894 ** The sqlite3_keyword_count() interface returns the number of distinct
8895 ** keywords understood by SQLite.
@@ -9053,11 +9053,11 @@
9053 **
9054 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
9055 ** content of the dynamic string under construction in X. The value
9056 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
9057 ** and might be freed or altered by any subsequent method on the same
9058 ** [sqlite3_str] object. Applications must not use the pointer returned by
9059 ** [sqlite3_str_value(X)] after any subsequent method call on the same
9060 ** object. ^Applications may change the content of the string returned
9061 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
9062 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
9063 ** write any byte after any subsequent sqlite3_str method call.
@@ -9139,11 +9139,11 @@
9139 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
9140 ** <dd>This parameter returns the number of bytes of page cache
9141 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
9142 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
9143 ** returned value includes allocations that overflowed because they
9144 ** were too large (they were larger than the "sz" parameter to
9145 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
9146 ** no space was left in the page cache.</dd>)^
9147 **
9148 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
9149 ** <dd>This parameter records the largest memory allocation request
@@ -9223,53 +9223,55 @@
9223 ** checked out.</dd>)^
9224 **
9225 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
9226 ** <dd>This parameter returns the number of malloc attempts that were
9227 ** satisfied using lookaside memory. Only the high-water value is meaningful;
9228 ** the current value is always zero.</dd>)^
9229 **
9230 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
9231 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
9232 ** <dd>This parameter returns the number of malloc attempts that might have
9233 ** been satisfied using lookaside memory but failed due to the amount of
9234 ** memory requested being larger than the lookaside slot size.
9235 ** Only the high-water value is meaningful;
9236 ** the current value is always zero.</dd>)^
9237 **
9238 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
9239 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
9240 ** <dd>This parameter returns the number of malloc attempts that might have
9241 ** been satisfied using lookaside memory but failed due to all lookaside
9242 ** memory already being in use.
9243 ** Only the high-water value is meaningful;
9244 ** the current value is always zero.</dd>)^
9245 **
9246 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
9247 ** <dd>This parameter returns the approximate number of bytes of heap
9248 ** memory used by all pager caches associated with the database connection.)^
9249 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
9250 ** </dd>
9251 **
9252 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
9253 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
9254 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
9255 ** pager cache is shared between two or more connections the bytes of heap
9256 ** memory used by that pager cache is divided evenly between the attached
9257 ** connections.)^ In other words, if none of the pager caches associated
9258 ** with the database connection are shared, this request returns the same
9259 ** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are
9260 ** shared, the value returned by this call will be smaller than that returned
9261 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
9262 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
9263 **
9264 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
9265 ** <dd>This parameter returns the approximate number of bytes of heap
9266 ** memory used to store the schema for all databases associated
9267 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
9268 ** ^The full amount of memory used by the schemas is reported, even if the
9269 ** schema memory is shared with other database connections due to
9270 ** [shared cache mode] being enabled.
9271 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
9272 ** </dd>
9273 **
9274 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
9275 ** <dd>This parameter returns the approximate number of bytes of heap
9276 ** and lookaside memory used by all prepared statements associated with
9277 ** the database connection.)^
@@ -9302,11 +9304,11 @@
9304 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
9305 ** <dd>This parameter returns the number of dirty cache entries that have
9306 ** been written to disk in the middle of a transaction due to the page
9307 ** cache overflowing. Transactions are more efficient if they are written
9308 ** to disk all at once. When pages spill mid-transaction, that introduces
9309 ** additional overhead. This parameter can be used to help identify
9310 ** inefficiencies that can be resolved by increasing the cache size.
9311 ** </dd>
9312 **
9313 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
9314 ** <dd>This parameter returns zero for the current value if and only if
@@ -9373,48 +9375,48 @@
9375 ** careful use of indices.</dd>
9376 **
9377 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
9378 ** <dd>^This is the number of sort operations that have occurred.
9379 ** A non-zero value in this counter may indicate an opportunity to
9380 ** improve performance through careful use of indices.</dd>
9381 **
9382 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
9383 ** <dd>^This is the number of rows inserted into transient indices that
9384 ** were created automatically in order to help joins run faster.
9385 ** A non-zero value in this counter may indicate an opportunity to
9386 ** improve performance by adding permanent indices that do not
9387 ** need to be reinitialized each time the statement is run.</dd>
9388 **
9389 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
9390 ** <dd>^This is the number of virtual machine operations executed
9391 ** by the prepared statement if that number is less than or equal
9392 ** to 2147483647. The number of virtual machine operations can be
9393 ** used as a proxy for the total work done by the prepared statement.
9394 ** If the number of virtual machine operations exceeds 2147483647
9395 ** then the value returned by this statement status code is undefined.</dd>
9396 **
9397 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9398 ** <dd>^This is the number of times that the prepare statement has been
9399 ** automatically regenerated due to schema changes or changes to
9400 ** [bound parameters] that might affect the query plan.</dd>
9401 **
9402 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9403 ** <dd>^This is the number of times that the prepared statement has
9404 ** been run. A single "run" for the purposes of this counter is one
9405 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
9406 ** The counter is incremented on the first [sqlite3_step()] call of each
9407 ** cycle.</dd>
9408 **
9409 ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
9410 ** [[SQLITE_STMTSTATUS_FILTER HIT]]
9411 ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
9412 ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
9413 ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
9414 ** step was bypassed because a Bloom filter returned not-found. The
9415 ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
9416 ** times that the Bloom filter returned a find, and thus the join step
9417 ** had to be processed as normal.</dd>
9418 **
9419 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
9420 ** <dd>^This is the approximate number of bytes of heap memory
9421 ** used to store the prepared statement. ^This value is not actually
9422 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9515,31 +9517,31 @@
9517 ** [[the xCreate() page cache methods]]
9518 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
9519 ** SQLite will typically create one cache instance for each open database file,
9520 ** though this is not guaranteed. ^The
9521 ** first parameter, szPage, is the size in bytes of the pages that must
9522 ** be allocated by the cache. ^szPage will always be a power of two. ^The
9523 ** second parameter szExtra is a number of bytes of extra storage
9524 ** associated with each page cache entry. ^The szExtra parameter will be
9525 ** a number less than 250. SQLite will use the
9526 ** extra szExtra bytes on each page to store metadata about the underlying
9527 ** database page on disk. The value passed into szExtra depends
9528 ** on the SQLite version, the target platform, and how SQLite was compiled.
9529 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
9530 ** created will be used to cache database pages of a file stored on disk, or
9531 ** false if it is used for an in-memory database. The cache implementation
9532 ** does not have to do anything special based upon the value of bPurgeable;
9533 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
9534 ** never invoke xUnpin() except to deliberately delete a page.
9535 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
9536 ** false will always have the "discard" flag set to true.
9537 ** ^Hence, a cache created with bPurgeable set to false will
9538 ** never contain any unpinned pages.
9539 **
9540 ** [[the xCachesize() page cache method]]
9541 ** ^(The xCachesize() method may be called at any time by SQLite to set the
9542 ** suggested maximum cache-size (number of pages stored) for the cache
9543 ** instance passed as the first argument. This is the value configured using
9544 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
9545 ** parameter, the implementation is not required to do anything with this
9546 ** value; it is advisory only.
9547 **
@@ -9562,16 +9564,16 @@
9564 **
9565 ** If the requested page is already in the page cache, then the page cache
9566 ** implementation must return a pointer to the page buffer with its content
9567 ** intact. If the requested page is not already in the cache, then the
9568 ** cache implementation should use the value of the createFlag
9569 ** parameter to help it determine what action to take:
9570 **
9571 ** <table border=1 width=85% align=center>
9572 ** <tr><th> createFlag <th> Behavior when page is not already in cache
9573 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9574 ** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.
9575 ** Otherwise return NULL.
9576 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
9577 ** NULL if allocating a new page is effectively impossible.
9578 ** </table>
9579 **
@@ -9584,11 +9586,11 @@
9586 ** [[the xUnpin() page cache method]]
9587 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9588 ** as its second argument. If the third parameter, discard, is non-zero,
9589 ** then the page must be evicted from the cache.
9590 ** ^If the discard parameter is
9591 ** zero, then the page may be discarded or retained at the discretion of the
9592 ** page cache implementation. ^The page cache implementation
9593 ** may choose to evict unpinned pages at any time.
9594 **
9595 ** The cache must not perform any reference counting. A single
9596 ** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9602,11 +9604,11 @@
9604 ** to be pinned.
9605 **
9606 ** When SQLite calls the xTruncate() method, the cache must discard all
9607 ** existing cache entries with page numbers (keys) greater than or equal
9608 ** to the value of the iLimit parameter passed to xTruncate(). If any
9609 ** of these pages are pinned, they become implicitly unpinned, meaning that
9610 ** they can be safely discarded.
9611 **
9612 ** [[the xDestroy() page cache method]]
9613 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
9614 ** All resources associated with the specified cache should be freed. ^After
@@ -9782,11 +9784,11 @@
9784 ** sqlite3_backup_step(), the source database may be modified mid-way
9785 ** through the backup process. ^If the source database is modified by an
9786 ** external process or via a database connection other than the one being
9787 ** used by the backup operation, then the backup will be automatically
9788 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9789 ** database is modified by using the same database connection as is used
9790 ** by the backup operation, then the backup database is automatically
9791 ** updated at the same time.
9792 **
9793 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9794 **
@@ -9799,11 +9801,11 @@
9801 ** active write-transaction on the destination database is rolled back.
9802 ** The [sqlite3_backup] object is invalid
9803 ** and may not be used following a call to sqlite3_backup_finish().
9804 **
9805 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9806 ** sqlite3_backup_step() errors occurred, regardless of whether or not
9807 ** sqlite3_backup_step() completed.
9808 ** ^If an out-of-memory condition or IO error occurred during any prior
9809 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9810 ** sqlite3_backup_finish() returns the corresponding [error code].
9811 **
@@ -9901,11 +9903,11 @@
9903 ** identity of the database connection (the blocking connection) that
9904 ** has locked the required resource is stored internally. ^After an
9905 ** application receives an SQLITE_LOCKED error, it may call the
9906 ** sqlite3_unlock_notify() method with the blocked connection handle as
9907 ** the first argument to register for a callback that will be invoked
9908 ** when the blocking connection's current transaction is concluded. ^The
9909 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9910 ** call that concludes the blocking connection's transaction.
9911 **
9912 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9913 ** there is a chance that the blocking connection will have already
@@ -9921,11 +9923,11 @@
9923 ** ^(There may be at most one unlock-notify callback registered by a
9924 ** blocked connection. If sqlite3_unlock_notify() is called when the
9925 ** blocked connection already has a registered unlock-notify callback,
9926 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9927 ** called with a NULL pointer as its second argument, then any existing
9928 ** unlock-notify callback is canceled. ^The blocked connection's
9929 ** unlock-notify callback may also be canceled by closing the blocked
9930 ** connection using [sqlite3_close()].
9931 **
9932 ** The unlock-notify callback is not reentrant. If an application invokes
9933 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10319,11 +10321,11 @@
10321 ** where X is an integer. If X is zero, then the [virtual table] whose
10322 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
10323 ** support constraints. In this configuration (which is the default) if
10324 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
10325 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10326 ** specified as part of the user's SQL statement, regardless of the actual
10327 ** ON CONFLICT mode specified.
10328 **
10329 ** If X is non-zero, then the virtual table implementation guarantees
10330 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
10331 ** any modifications to internal or persistent data structures have been made.
@@ -10353,11 +10355,11 @@
10355 ** </dd>
10356 **
10357 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10358 ** <dd>Calls of the form
10359 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10360 ** [xConnect] or [xCreate] methods of a [virtual table] implementation
10361 ** identify that virtual table as being safe to use from within triggers
10362 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10363 ** virtual table can do no serious harm even if it is controlled by a
10364 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10365 ** flag unless absolutely necessary.
@@ -10521,21 +10523,21 @@
10523 ** <tr><td>2<td>no<td>yes<td>yes
10524 ** <tr><td>3<td>yes<td>yes<td>yes
10525 ** </table>
10526 **
10527 ** ^For the purposes of comparing virtual table output values to see if the
10528 ** values are the same value for sorting purposes, two NULL values are considered
10529 ** to be the same. In other words, the comparison operator is "IS"
10530 ** (or "IS NOT DISTINCT FROM") and not "==".
10531 **
10532 ** If a virtual table implementation is unable to meet the requirements
10533 ** specified above, then it must not set the "orderByConsumed" flag in the
10534 ** [sqlite3_index_info] object or an incorrect answer may result.
10535 **
10536 ** ^A virtual table implementation is always free to return rows in any order
10537 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
10538 ** "orderByConsumed" flag is unset, the query planner will add extra
10539 ** [bytecode] to ensure that the final results returned by the SQL query are
10540 ** ordered correctly. The use of the "orderByConsumed" flag and the
10541 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
10542 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
10543 ** flag might help queries against a virtual table to run faster. Being
@@ -10628,11 +10630,11 @@
10630 **
10631 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10632 ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10633 ** xFilter method which invokes these routines, and specifically
10634 ** a parameter that was previously selected for all-at-once IN constraint
10635 ** processing using the [sqlite3_vtab_in()] interface in the
10636 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10637 ** an xFilter argument that was selected for all-at-once IN constraint
10638 ** processing, then these routines return [SQLITE_ERROR].)^
10639 **
10640 ** ^(Use these routines to access all values on the right-hand side
@@ -10683,11 +10685,11 @@
10685 ** right-hand operand is not known, then *V is set to a NULL pointer.
10686 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10687 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10688 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10689 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10690 ** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if
10691 ** something goes wrong.
10692 **
10693 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10694 ** the right-hand operand of a constraint is a literal value in the original
10695 ** SQL statement. If the right-hand operand is an expression or a reference
@@ -10711,12 +10713,12 @@
10713 /*
10714 ** CAPI3REF: Conflict resolution modes
10715 ** KEYWORDS: {conflict resolution mode}
10716 **
10717 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
10718 ** inform a [virtual table] implementation of the [ON CONFLICT] mode
10719 ** for the SQL statement being evaluated.
10720 **
10721 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
10722 ** return value from the [sqlite3_set_authorizer()] callback and that
10723 ** [SQLITE_ABORT] is also a [result code].
10724 */
@@ -10752,43 +10754,43 @@
10754 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10755 **
10756 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10757 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10758 ** query planner's estimate for the average number of rows output from each
10759 ** iteration of the X-th loop. If the query planner's estimate was accurate,
10760 ** then this value will approximate the quotient NVISIT/NLOOP and the
10761 ** product of this value for all prior loops with the same SELECTID will
10762 ** be the NLOOP value for the current loop.</dd>
10763 **
10764 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10765 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10766 ** to a zero-terminated UTF-8 string containing the name of the index or table
10767 ** used for the X-th loop.</dd>
10768 **
10769 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10770 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10771 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10772 ** description for the X-th loop.</dd>
10773 **
10774 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10775 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10776 ** id for the X-th query plan element. The id value is unique within the
10777 ** statement. The select-id is the same value as is output in the first
10778 ** column of an [EXPLAIN QUERY PLAN] query.</dd>
10779 **
10780 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10781 ** <dd>The "int" variable pointed to by the V parameter will be set to the
10782 ** id of the parent of the current query element, if applicable, or
10783 ** to zero if the query element has no parent. This is the same value as
10784 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>
10785 **
10786 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10787 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10788 ** according to the processor time-stamp counter, that elapsed while the
10789 ** query element was being processed. This value is not available for
10790 ** all query elements - if it is unavailable the output variable is
10791 ** set to -1.</dd>
10792 ** </dl>
10793 */
10794 #define SQLITE_SCANSTAT_NLOOP 0
10795 #define SQLITE_SCANSTAT_NVISIT 1
10796 #define SQLITE_SCANSTAT_EST 2
@@ -10825,12 +10827,12 @@
10827 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10828 ** sqlite3_stmt_scanstatus() is equivalent to calling
10829 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10830 **
10831 ** Parameter "idx" identifies the specific query element to retrieve statistics
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
10834 ** - less than -1 or greater than or equal to the total number of query
10835 ** elements used to implement the statement - a non-zero value is returned and
10836 ** the variable that pOut points to is unchanged.
10837 **
10838 ** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10869,11 +10871,11 @@
10871 /*
10872 ** CAPI3REF: Flush caches to disk mid-transaction
10873 ** METHOD: sqlite3
10874 **
10875 ** ^If a write-transaction is open on [database connection] D when the
10876 ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
10877 ** pages in the pager-cache that are not currently in use are written out
10878 ** to disk. A dirty page may be in use if a database cursor created by an
10879 ** active SQL statement is reading from it, or if it is page 1 of a database
10880 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10881 ** interface flushes caches for all schemas - "main", "temp", and
@@ -10983,12 +10985,12 @@
10985 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10986 ** triggers; or 2 for changes resulting from triggers called by top-level
10987 ** triggers; and so forth.
10988 **
10989 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10990 ** the pre-update hook is invoked with SQLITE_DELETE, because
10991 ** the new values are not yet available. In this case, when a
10992 ** callback made with op==SQLITE_DELETE is actually a write using the
10993 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10994 ** the index of the column being written. In other cases, where the
10995 ** pre-update hook is being invoked for some other reason, including a
10996 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -11237,20 +11239,20 @@
11239 ** is written into *P.
11240 **
11241 ** For an ordinary on-disk database file, the serialization is just a
11242 ** copy of the disk file. For an in-memory database or a "TEMP" database,
11243 ** the serialization is the same sequence of bytes which would be written
11244 ** to disk if that database were backed up to disk.
11245 **
11246 ** The usual case is that sqlite3_serialize() copies the serialization of
11247 ** the database into memory obtained from [sqlite3_malloc64()] and returns
11248 ** a pointer to that memory. The caller is responsible for freeing the
11249 ** returned value to avoid a memory leak. However, if the F argument
11250 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
11251 ** are made, and the sqlite3_serialize() function will return a pointer
11252 ** to the contiguous memory representation of the database that SQLite
11253 ** is currently using for that database, or NULL if no such contiguous
11254 ** memory representation of the database exists. A contiguous memory
11255 ** representation of the database will usually only exist if there has
11256 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
11257 ** values of D and S.
11258 ** The size of the database is written into *P even if the
@@ -11317,11 +11319,11 @@
11319 **
11320 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
11321 ** database is currently in a read transaction or is involved in a backup
11322 ** operation.
11323 **
11324 ** It is not possible to deserialize into the TEMP database. If the
11325 ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
11326 ** function returns SQLITE_ERROR.
11327 **
11328 ** The deserialized database should not be in [WAL mode]. If the database
11329 ** is in WAL mode, then any attempt to use the database file will result
@@ -11339,19 +11341,19 @@
11341 */
11342 SQLITE_API int sqlite3_deserialize(
11343 sqlite3 *db, /* The database connection */
11344 const char *zSchema, /* Which DB to reopen with the deserialization */
11345 unsigned char *pData, /* The serialized database content */
11346 sqlite3_int64 szDb, /* Number of bytes in the deserialization */
11347 sqlite3_int64 szBuf, /* Total size of buffer pData[] */
11348 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
11349 );
11350
11351 /*
11352 ** CAPI3REF: Flags for sqlite3_deserialize()
11353 **
11354 ** The following are allowed values for the 6th argument (the F argument) to
11355 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
11356 **
11357 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
11358 ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
11359 ** and that SQLite should take ownership of this memory and automatically
@@ -12084,11 +12086,11 @@
12086 ** CAPI3REF: Flags for sqlite3changeset_start_v2
12087 **
12088 ** The following flags may passed via the 4th parameter to
12089 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
12090 **
12091 ** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
12092 ** Invert the changeset while iterating through it. This is equivalent to
12093 ** inverting a changeset using sqlite3changeset_invert() before applying it.
12094 ** It is an error to specify this flag with a patchset.
12095 */
12096 #define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12629,17 +12631,26 @@
12631 ** Apply a changeset or patchset to a database. These functions attempt to
12632 ** update the "main" database attached to handle db with the changes found in
12633 ** the changeset passed via the second and third arguments.
12634 **
12635 ** The fourth argument (xFilter) passed to these functions is the "filter
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.
12652 **
12653 ** For each table that is not excluded by the filter callback, this function
12654 ** tests that the target database contains a compatible table. A table is
12655 ** considered compatible if all of the following are true:
12656 **
@@ -12656,15 +12667,15 @@
12667 ** changes associated with the table are applied. A warning message is issued
12668 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
12669 ** one such warning is issued for each table in the changeset.
12670 **
12671 ** For each change for which there is a compatible table, an attempt is made
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.
12677 **
12678 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
12679 ** of passing anything other than a valid function pointer as the xConflict
12680 ** argument are undefined.
12681 **
@@ -12802,10 +12813,27 @@
12813 void *pChangeset, /* Changeset blob */
12814 int(*xFilter)(
12815 void *pCtx, /* Copy of sixth arg to _apply() */
12816 const char *zTab /* Table name */
12817 ),
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 ),
12835 int(*xConflict)(
12836 void *pCtx, /* Copy of sixth arg to _apply() */
12837 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12838 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12839 ),
@@ -13221,10 +13249,27 @@
13249 void *pIn, /* First arg for xInput */
13250 int(*xFilter)(
13251 void *pCtx, /* Copy of sixth arg to _apply() */
13252 const char *zTab /* Table name */
13253 ),
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 ),
13271 int(*xConflict)(
13272 void *pCtx, /* Copy of sixth arg to _apply() */
13273 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
13274 sqlite3_changeset_iter *p /* Handle describing change and conflict */
13275 ),
@@ -15174,11 +15219,11 @@
15219 /*
15220 ** GCC does not define the offsetof() macro so we'll have to do it
15221 ** ourselves.
15222 */
15223 #ifndef offsetof
15224 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
15225 #endif
15226
15227 /*
15228 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15229 ** to avoid complaints from -fsanitize=strict-bounds.
@@ -15440,12 +15485,12 @@
15485 /*
15486 ** Macro SMXV(n) return the maximum value that can be held in variable n,
15487 ** assuming n is a signed integer type. UMXV(n) is similar for unsigned
15488 ** integer types.
15489 */
15490 #define SMXV(n) ((((i64)1)<<(sizeof(n)*8-1))-1)
15491 #define UMXV(n) ((((i64)1)<<(sizeof(n)*8))-1)
15492
15493 /*
15494 ** Round up a number to the next larger multiple of 8. This is used
15495 ** to force 8-byte alignment on 64-bit architectures.
15496 **
@@ -15562,10 +15607,12 @@
15607 ** 0x00008000 After all FROM-clause analysis
15608 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15609 ** 0x00020000 Transform DISTINCT into GROUP BY
15610 ** 0x00040000 SELECT tree dump after all code has been generated
15611 ** 0x00080000 NOT NULL strength reduction
15612 ** 0x00100000 Pointers are all shown as zero
15613 ** 0x00200000 EXISTS-to-JOIN optimization
15614 */
15615
15616 /*
15617 ** Macros for "wheretrace"
15618 */
@@ -15606,10 +15653,11 @@
15653 **
15654 ** 0x00010000 Show more detail when printing WHERE terms
15655 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15656 ** 0x00040000 Solver overview messages
15657 ** 0x00080000 Star-query heuristic
15658 ** 0x00100000 Pointers are all shown as zero
15659 */
15660
15661
15662 /*
15663 ** An instance of the following structure is used to store the busy-handler
@@ -15678,11 +15726,11 @@
15726 ** one parameter that destructors normally want. So we have to introduce
15727 ** this magic value that the code knows to handle differently. Any
15728 ** pointer will work here as long as it is distinct from SQLITE_STATIC
15729 ** and SQLITE_TRANSIENT.
15730 */
15731 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3RowSetClear)
15732
15733 /*
15734 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
15735 ** not support Writable Static Data (WSD) such as global and static variables.
15736 ** All variables must either be on the stack or dynamically allocated from
@@ -16746,10 +16794,11 @@
16794 };
16795
16796 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
16797 int flags, int seekResult);
16798 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
16799 SQLITE_PRIVATE int sqlite3BtreeIsEmpty(BtCursor *pCur, int *pRes);
16800 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
16801 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
16802 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
16803 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
16804 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -17079,76 +17128,76 @@
17128 #define OP_Last 32 /* jump0 */
17129 #define OP_IfSizeBetween 33 /* jump */
17130 #define OP_SorterSort 34 /* jump */
17131 #define OP_Sort 35 /* jump */
17132 #define OP_Rewind 36 /* jump0 */
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] */
17139 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
17140 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[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 */
17147 #define OP_IsNull 51 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
17148 #define OP_NotNull 52 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
17149 #define OP_Ne 53 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
17150 #define OP_Eq 54 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
17151 #define OP_Gt 55 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
17152 #define OP_Le 56 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
17153 #define OP_Lt 57 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
17154 #define OP_Ge 58 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
17155 #define OP_ElseEq 59 /* jump, same as TK_ESCAPE */
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 */
17199 #define OP_BitAnd 103 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
17200 #define OP_BitOr 104 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
17201 #define OP_ShiftLeft 105 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
17202 #define OP_ShiftRight 106 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
17203 #define OP_Add 107 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -17155,87 +17204,88 @@
17204 #define OP_Subtract 108 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
17205 #define OP_Multiply 109 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
17206 #define OP_Divide 110 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
17207 #define OP_Remainder 111 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
17208 #define OP_Concat 112 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
17209 #define OP_OpenRead 113 /* synopsis: root=P2 iDb=P3 */
17210 #define OP_OpenWrite 114 /* synopsis: root=P2 iDb=P3 */
17211 #define OP_BitNot 115 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
17212 #define OP_OpenDup 116
17213 #define OP_OpenAutoindex 117 /* synopsis: nColumn=P2 */
17214 #define OP_String8 118 /* same as TK_STRING, synopsis: r[P2]='P4' */
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
17250 #define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
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
17287
17288 /* Properties such as "out2" or "jump" that are specified in
17289 ** comments following the "case" for each opcode in the vdbe.c
17290 ** are encoded into bitvectors as follows:
17291 */
@@ -17250,38 +17300,38 @@
17300 #define OPFLG_INITIALIZER {\
17301 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
17302 /* 8 */ 0x81, 0x01, 0x01, 0x81, 0x83, 0x83, 0x01, 0x01,\
17303 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0xc9, 0xc9, 0xc9,\
17304 /* 24 */ 0xc9, 0x01, 0x49, 0x49, 0x49, 0x49, 0xc9, 0x49,\
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,\
17314 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
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,}
17325
17326 /* The resolve3P2Values() routine is able to run faster if it knows
17327 ** the value of the largest JUMP opcode. The smaller the maximum
17328 ** JUMP opcode the better, so the mkopcodeh.tcl script that
17329 ** generated this include file strives to group all JUMP opcodes
17330 ** together near the beginning of the list.
17331 */
17332 #define SQLITE_MX_JUMP_OPCODE 65 /* Maximum JUMP opcode */
17333
17334 /************** End of opcodes.h *********************************************/
17335 /************** Continuing where we left off in vdbe.h ***********************/
17336
17337 /*
@@ -17401,11 +17451,11 @@
17451 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
17452 #endif
17453 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
17454 SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
17455
17456 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*);
17457 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
17458 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
17459 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
17460
17461 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -17414,11 +17464,13 @@
17464 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
17465 SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe*);
17466
17467 SQLITE_PRIVATE void sqlite3MemSetArrayInt64(sqlite3_value *aMem, int iIdx, i64 val);
17468
17469 #ifndef SQLITE_OMIT_DATETIME_FUNCS
17470 SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
17471 #endif
17472 #ifdef SQLITE_ENABLE_BYTECODE_VTAB
17473 SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3*);
17474 #endif
17475
17476 /* Use SQLITE_ENABLE_EXPLAIN_COMMENTS to enable generation of extra
@@ -18296,10 +18348,11 @@
18348 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18349 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18350 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18351 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18352 #define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
18353 #define SQLITE_ExistsToJoin 0x40000000 /* The EXISTS-to-JOIN optimization */
18354 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
18355
18356 /*
18357 ** Macros for testing whether or not optimizations are enabled or disabled.
18358 */
@@ -18534,11 +18587,11 @@
18587 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
18588 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
18589 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
18590 {nArg, SQLITE_FUNC_BUILTIN|\
18591 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
18592 pArg, 0, xFunc, 0, 0, 0, #zName, {0} }
18593 #define LIKEFUNC(zName, nArg, arg, flags) \
18594 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
18595 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
18596 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
18597 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
@@ -18701,10 +18754,11 @@
18754 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18755 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18756 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18757 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18758 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18759 #define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
18760
18761 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
18762
18763 /*
18764 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19070,19 @@
19070 /*
19071 ** An instance of the following structure is passed as the first
19072 ** argument to sqlite3VdbeKeyCompare and is used to control the
19073 ** comparison of the two index keys.
19074 **
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.
19084 */
19085 struct KeyInfo {
19086 u32 nRef; /* Number of references to this KeyInfo object */
19087 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
19088 u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19090,21 @@
19090 sqlite3 *db; /* The database connection */
19091 u8 *aSortFlags; /* Sort order for each column. */
19092 CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
19093 };
19094
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[]. */
19098 #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
19106
19107 /*
19108 ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
19109 */
19110 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19120,22 @@
19120 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
19121 ** OP_Column opcode.
19122 **
19123 ** An instance of this object serves as a "key" for doing a search on
19124 ** an index b+tree. The goal of the search is to find the entry that
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.
 
19127 **
19128 ** The r1 and r2 fields are the values to return if this key is less than
19129 ** or greater than a key in the btree, respectively. These are normally
19130 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
19131 ** is in DESC order.
19132 **
19133 ** The key comparison functions actually return default_rc when they find
19134 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
19135 ** multiple entries in the b-tree with the same key (when only looking
19136 ** at the first nField elements) then default_rc can be set to -1 to
19137 ** cause the search to find the last match, or +1 to cause the search to
19138 ** find the first match.
19139 **
19140 ** The key comparison functions will set eqSeen to true if they ever
19141 ** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19143,12 @@
19143 ** before the first match or immediately after the last match. The
19144 ** eqSeen field will indicate whether or not an exact match exists in the
19145 ** b-tree.
19146 */
19147 struct UnpackedRecord {
19148 KeyInfo *pKeyInfo; /* Comparison info for the index that is unpacked */
19149 Mem *aMem; /* Values for columns of the index */
19150 union {
19151 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
19152 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
19153 } u;
19154 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -19161,14 +19229,12 @@
19229 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
19230 unsigned isResized:1; /* True if resizeIndexObject() has been called */
19231 unsigned isCovering:1; /* True if this is a covering index */
19232 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
19233 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
 
19234 unsigned bNoQuery:1; /* Do not use this index to optimize queries */
19235 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
 
19236 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
19237 unsigned bHasExpr:1; /* Index contains an expression, either a literal
19238 ** expression, or a reference to a VIRTUAL column */
19239 #ifdef SQLITE_ENABLE_STAT4
19240 int nSample; /* Number of elements in aSample[] */
@@ -19252,21 +19318,21 @@
19318 struct AggInfo {
19319 u8 directMode; /* Direct rendering mode means take data directly
19320 ** from source tables rather than from accumulators */
19321 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
19322 ** than the source table */
19323 u32 nSortingColumn; /* Number of columns in the sorting index */
19324 int sortingIdx; /* Cursor number of the sorting index */
19325 int sortingIdxPTab; /* Cursor number of pseudo-table */
19326 int iFirstReg; /* First register in range for aCol[] and aFunc[] */
19327 ExprList *pGroupBy; /* The group by clause */
19328 struct AggInfo_col { /* For each column used in source tables */
19329 Table *pTab; /* Source table */
19330 Expr *pCExpr; /* The original expression */
19331 int iTable; /* Cursor number of the source table */
19332 int iColumn; /* Column number within the source table */
19333 int iSorterColumn; /* Column number in the sorting index */
19334 } *aCol;
19335 int nColumn; /* Number of used entries in aCol[] */
19336 int nAccumulator; /* Number of columns that show through to the output.
19337 ** Additional columns are used only as parameters to
19338 ** aggregate functions */
@@ -19726,10 +19792,11 @@
19792 unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
19793 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
19794 unsigned rowidUsed :1; /* The ROWID of this table is referenced */
19795 unsigned fixedSchema :1; /* Uses u4.pSchema, not u4.zDatabase */
19796 unsigned hadSchema :1; /* Had u4.zDatabase before u4.pSchema */
19797 unsigned fromExists :1; /* Comes from WHERE EXISTS(...) */
19798 } fg;
19799 int iCursor; /* The VDBE cursor number used to access this table */
19800 Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
19801 union {
19802 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
@@ -20256,10 +20323,11 @@
20323 u8 mayAbort; /* True if statement may throw an ABORT exception */
20324 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20325 u8 disableLookaside; /* Number of times lookaside has been disabled */
20326 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20327 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20328 u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
20329 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20330 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20331 u8 bReturning; /* Coding a RETURNING trigger */
20332 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20333 u8 disableTriggers; /* True to disable triggers */
@@ -21252,10 +21320,11 @@
21320 #endif
21321 #ifndef SQLITE_OMIT_WINDOWFUNC
21322 SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
21323 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
21324 #endif
21325 SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec*);
21326 #endif
21327
21328 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
21329 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
21330 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -22425,10 +22494,13 @@
22494 #ifdef SQLITE_BITMASK_TYPE
22495 "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
22496 #endif
22497 #ifdef SQLITE_BUG_COMPATIBLE_20160819
22498 "BUG_COMPATIBLE_20160819",
22499 #endif
22500 #ifdef SQLITE_BUG_COMPATIBLE_20250510
22501 "BUG_COMPATIBLE_20250510",
22502 #endif
22503 #ifdef SQLITE_CASE_SENSITIVE_LIKE
22504 "CASE_SENSITIVE_LIKE",
22505 #endif
22506 #ifdef SQLITE_CHECK_PAGES
@@ -23861,11 +23933,11 @@
23933 ** * MEM_Blob A blob, stored in Mem.z length Mem.n.
23934 ** Incompatible with MEM_Str, MEM_Null,
23935 ** MEM_Int, MEM_Real, and MEM_IntReal.
23936 **
23937 ** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
23938 ** Mem.u.nZero extra 0x00 bytes at the end.
23939 **
23940 ** * MEM_Int Integer stored in Mem.u.i.
23941 **
23942 ** * MEM_Real Real stored in Mem.u.r.
23943 **
@@ -24130,11 +24202,11 @@
24202 Mem oldipk; /* Memory cell holding "old" IPK value */
24203 Mem *aNew; /* Array of new.* values */
24204 Table *pTab; /* Schema object being updated */
24205 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24206 sqlite3_value **apDflt; /* Array of default values, if required */
24207 u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
24208 };
24209
24210 /*
24211 ** An instance of this object is used to pass an vector of values into
24212 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -32060,10 +32132,18 @@
32132 }else{
32133 longvalue = va_arg(ap,unsigned int);
32134 }
32135 prefix = 0;
32136 }
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
32145 if( longvalue==0 ) flag_alternateform = 0;
32146 if( flag_zeropad && precision<width-(prefix!=0) ){
32147 precision = width-(prefix!=0);
32148 }
32149 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
@@ -35011,11 +35091,11 @@
35091 }
35092
35093 /*
35094 ** Write a single UTF8 character whose value is v into the
35095 ** buffer starting at zOut. zOut must be sized to hold at
35096 ** least four bytes. Return the number of bytes needed
35097 ** to encode the new character.
35098 */
35099 SQLITE_PRIVATE int sqlite3AppendOneUtf8Character(char *zOut, u32 v){
35100 if( v<0x00080 ){
35101 zOut[0] = (u8)(v & 0xff);
@@ -37691,76 +37771,76 @@
37771 /* 32 */ "Last" OpHelp(""),
37772 /* 33 */ "IfSizeBetween" OpHelp(""),
37773 /* 34 */ "SorterSort" OpHelp(""),
37774 /* 35 */ "Sort" OpHelp(""),
37775 /* 36 */ "Rewind" OpHelp(""),
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]"),
37782 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
37783 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[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"),
37790 /* 51 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
37791 /* 52 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
37792 /* 53 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
37793 /* 54 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
37794 /* 55 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
37795 /* 56 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
37796 /* 57 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
37797 /* 58 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
37798 /* 59 */ "ElseEq" OpHelp(""),
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"),
37842 /* 103 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
37843 /* 104 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
37844 /* 105 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
37845 /* 106 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
37846 /* 107 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -37767,87 +37847,88 @@
37847 /* 108 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
37848 /* 109 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
37849 /* 110 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
37850 /* 111 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
37851 /* 112 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
37852 /* 113 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
37853 /* 114 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
37854 /* 115 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
37855 /* 116 */ "OpenDup" OpHelp(""),
37856 /* 117 */ "OpenAutoindex" OpHelp("nColumn=P2"),
37857 /* 118 */ "String8" OpHelp("r[P2]='P4'"),
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(""),
37893 /* 154 */ "Real" OpHelp("r[P2]=P4"),
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(""),
37930 };
37931 return azName[i];
37932 }
37933 #endif
37934
@@ -43870,25 +43951,24 @@
43951 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43952
43953 /* Check that, if this to be a blocking lock, no locks that occur later
43954 ** in the following list than the lock being obtained are already held:
43955 **
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).
43960 **
43961 ** In other words, if this is a blocking lock, none of the locks that
43962 ** occur later in the above list than the lock being obtained may be
43963 ** held.
 
 
43964 */
43965 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
43966 {
43967 u16 lockMask = (p->exclMask|p->sharedMask);
43968 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43969 (ofst!=2 || lockMask==0)
43970 && (ofst!=1 || lockMask==0 || lockMask==2)
43971 && (ofst!=0 || lockMask<3)
43972 && (ofst<3 || lockMask<(1<<ofst))
43973 ));
43974 }
@@ -49845,11 +49925,15 @@
49925 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49926 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49927 if( res==WAIT_OBJECT_0 ){
49928 ret = TRUE;
49929 }else if( res==WAIT_TIMEOUT ){
49930 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
49931 rc = SQLITE_BUSY_TIMEOUT;
49932 #else
49933 rc = SQLITE_BUSY;
49934 #endif
49935 }else{
49936 /* Some other error has occurred */
49937 rc = SQLITE_IOERR_LOCK;
49938 }
49939
@@ -51331,17 +51415,17 @@
51415 int nChar;
51416 LPWSTR zWideFilename;
51417
51418 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51419 && winIsDirSep(zFilename[2])) ){
51420 i64 nByte;
51421 int convertflag = CCP_POSIX_TO_WIN_W;
51422 if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51423 nByte = (i64)osCygwin_conv_path(convertflag,
51424 zFilename, 0, 0);
51425 if( nByte>0 ){
51426 zConverted = sqlite3MallocZero(12+(u64)nByte);
51427 if ( zConverted==0 ){
51428 return zConverted;
51429 }
51430 zWideFilename = zConverted;
51431 /* Filenames should be prefixed, except when converted
@@ -51656,25 +51740,24 @@
51740 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51741
51742 /* Check that, if this to be a blocking lock, no locks that occur later
51743 ** in the following list than the lock being obtained are already held:
51744 **
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).
51749 **
51750 ** In other words, if this is a blocking lock, none of the locks that
51751 ** occur later in the above list than the lock being obtained may be
51752 ** held.
 
 
51753 */
51754 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
51755 {
51756 u16 lockMask = (p->exclMask|p->sharedMask);
51757 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51758 (ofst!=2 || lockMask==0)
51759 && (ofst!=1 || lockMask==0 || lockMask==2)
51760 && (ofst!=0 || lockMask<3)
51761 && (ofst<3 || lockMask<(1<<ofst))
51762 ));
51763 }
@@ -52220,31 +52303,10 @@
52303 **
52304 ** This division contains the implementation of methods on the
52305 ** sqlite3_vfs object.
52306 */
52307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52308 /*
52309 ** This function returns non-zero if the specified UTF-8 string buffer
52310 ** ends with a directory separator character or one was successfully
52311 ** added to it.
52312 */
@@ -52380,46 +52442,10 @@
52442 sqlite3_snprintf(nMax, zBuf, "%s", zDir);
52443 sqlite3_free(zConverted);
52444 break;
52445 }
52446 sqlite3_free(zConverted);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52447 }
52448 }
52449 }
52450 #endif
52451
@@ -53314,38 +53340,10 @@
53340 winSimplifyName(zFull);
53341 return rc;
53342 }
53343 }
53344 #endif /* __CYGWIN__ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53345
53346 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && defined(_WIN32)
53347 SimulateIOError( return SQLITE_ERROR );
53348 /* WinCE has no concept of a relative pathname, or so I am told. */
53349 /* WinRT has no way to convert a relative path to an absolute one. */
@@ -53487,31 +53485,12 @@
53485 ** Interfaces for opening a shared library, finding entry points
53486 ** within the shared library, and closing the shared library.
53487 */
53488 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53489 HANDLE h;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53490 void *zConverted = winConvertFromUtf8Filename(zFilename);
53491 UNUSED_PARAMETER(pVfs);
 
53492 if( zConverted==0 ){
53493 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53494 return 0;
53495 }
53496 if( osIsNT() ){
@@ -54953,10 +54932,11 @@
54932 BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
54933 u32 aHash[BITVEC_NINT]; /* Hash table representation */
54934 Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
54935 } u;
54936 };
54937
54938
54939 /*
54940 ** Create a new bitmap object able to handle bits between 0 and iSize,
54941 ** inclusive. Return a pointer to the new object. Return NULL if
54942 ** malloc fails.
@@ -55063,11 +55043,13 @@
55043 if( aiValues==0 ){
55044 return SQLITE_NOMEM_BKPT;
55045 }else{
55046 memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
55047 memset(p->u.apSub, 0, sizeof(p->u.apSub));
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;
55051 rc = sqlite3BitvecSet(p, i);
55052 for(j=0; j<BITVEC_NINT; j++){
55053 if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
55054 }
55055 sqlite3StackFree(0, aiValues);
@@ -55139,10 +55121,56 @@
55121 ** was created.
55122 */
55123 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
55124 return p->iSize;
55125 }
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
55172
55173 #ifndef SQLITE_UNTESTABLE
55174 /*
55175 ** Let V[] be an array of unsigned characters sufficient to hold
55176 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
@@ -55150,40 +55178,48 @@
55178 ** individual bits within V.
55179 */
55180 #define SETBIT(V,I) V[I>>3] |= (1<<(I&7))
55181 #define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7))
55182 #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0
55183
55184
55185 /*
55186 ** This routine runs an extensive test of the Bitvec code.
55187 **
55188 ** The input is an array of integers that acts as a program
55189 ** to test the Bitvec. The integers are opcodes followed
55190 ** by 0, 1, or 3 operands, depending on the opcode. Another
55191 ** opcode follows immediately after the last operand.
55192 **
55193 ** There are opcodes numbered starting with 0. 0 is the
55194 ** "halt" opcode and causes the test to end.
55195 **
55196 ** 0 Halt and return the number of errors
55197 ** 1 N S X Set N bits beginning with S and incrementing by X
55198 ** 2 N S X Clear N bits beginning with S and incrementing by X
55199 ** 3 N Set N randomly chosen bits
55200 ** 4 N Clear N randomly chosen bits
55201 ** 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
55204 **
55205 ** The opcodes 1 through 4 perform set and clear operations are performed
55206 ** on both a Bitvec object and on a linear array of bits obtained from malloc.
55207 ** Opcode 5 works on the linear array only, not on the Bitvec.
55208 ** Opcode 5 is used to deliberately induce a fault in order to
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.
55212 **
55213 ** At the conclusion of the test the linear array is compared
55214 ** against the Bitvec object. If there are any differences,
55215 ** an error is returned. If they are the same, zero is returned.
55216 **
55217 ** 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.
55221 */
55222 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
55223 Bitvec *pBitvec = 0;
55224 unsigned char *pV = 0;
55225 int rc = -1;
@@ -55190,22 +55226,45 @@
55226 int i, nx, pc, op;
55227 void *pTmpSpace;
55228
55229 /* Allocate the Bitvec to be tested and a linear array of
55230 ** bits to act as the reference */
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 }
55238 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
55239 if( pBitvec==0 || pTmpSpace==0 || (pV==0 && sz>0) ) goto bitvec_end;
55240
55241 /* NULL pBitvec tests */
55242 sqlite3BitvecSet(0, 1);
55243 sqlite3BitvecClear(0, 1, pTmpSpace);
55244
55245 /* Run the program */
55246 pc = i = 0;
55247 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 }
55266 switch( op ){
55267 case 1:
55268 case 2:
55269 case 5: {
55270 nx = 4;
@@ -55223,33 +55282,37 @@
55282 }
55283 if( (--aOp[pc+1]) > 0 ) nx = 0;
55284 pc += nx;
55285 i = (i & 0x7fffffff)%sz;
55286 if( (op & 1)!=0 ){
55287 if( pV ) SETBIT(pV, (i+1));
55288 if( op!=5 ){
55289 if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
55290 }
55291 }else{
55292 if( pV ) CLEARBIT(pV, (i+1));
55293 sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
55294 }
55295 }
55296
55297 /* Test to make sure the linear array exactly matches the
55298 ** Bitvec object. Start with the assumption that they do
55299 ** match (rc==0). Change rc to non-zero if a discrepancy
55300 ** is found.
55301 */
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;
55314 }
55315
55316 /* Free allocated structure */
55317 bitvec_end:
55318 sqlite3_free(pTmpSpace);
@@ -58849,10 +58912,13 @@
58912 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
58913 PCache *pPCache; /* Pointer to page cache object */
58914 #ifndef SQLITE_OMIT_WAL
58915 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
58916 char *zWal; /* File name for write-ahead log */
58917 #endif
58918 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
58919 sqlite3 *dbWal;
58920 #endif
58921 };
58922
58923 /*
58924 ** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
@@ -65731,10 +65797,15 @@
65797 if( rc==SQLITE_OK ){
65798 rc = sqlite3WalOpen(pPager->pVfs,
65799 pPager->fd, pPager->zWal, pPager->exclusiveMode,
65800 pPager->journalSizeLimit, &pPager->pWal
65801 );
65802 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65803 if( rc==SQLITE_OK ){
65804 sqlite3WalDb(pPager->pWal, pPager->dbWal);
65805 }
65806 #endif
65807 }
65808 pagerFixMaplimit(pPager);
65809
65810 return rc;
65811 }
@@ -65850,10 +65921,11 @@
65921 /*
65922 ** Set the database handle used by the wal layer to determine if
65923 ** blocking locks are required.
65924 */
65925 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
65926 pPager->dbWal = db;
65927 if( pagerUseWal(pPager) ){
65928 sqlite3WalDb(pPager->pWal, db);
65929 }
65930 }
65931 #endif
@@ -69023,11 +69095,10 @@
69095 assert( rc==SQLITE_OK );
69096 if( pWal->bShmUnreliable==0 ){
69097 rc = walIndexReadHdr(pWal, pChanged);
69098 }
69099 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
 
69100 if( rc==SQLITE_BUSY_TIMEOUT ){
69101 rc = SQLITE_BUSY;
69102 *pCnt |= WAL_RETRY_BLOCKED_MASK;
69103 }
69104 #endif
@@ -69038,10 +69109,11 @@
69109 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
69110 ** would be technically correct. But the race is benign since with
69111 ** WAL_RETRY this routine will be called again and will probably be
69112 ** right on the second iteration.
69113 */
69114 (void)walEnableBlocking(pWal);
69115 if( pWal->apWiData[0]==0 ){
69116 /* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
69117 ** We assume this is a transient condition, so return WAL_RETRY. The
69118 ** xShmMap() implementation used by the default unix and win32 VFS
69119 ** modules may return SQLITE_BUSY due to a race condition in the
@@ -69054,10 +69126,11 @@
69126 rc = WAL_RETRY;
69127 }else if( rc==SQLITE_BUSY ){
69128 rc = SQLITE_BUSY_RECOVERY;
69129 }
69130 }
69131 walDisableBlocking(pWal);
69132 if( rc!=SQLITE_OK ){
69133 return rc;
69134 }
69135 else if( pWal->bShmUnreliable ){
69136 return walBeginShmUnreliable(pWal, pChanged);
@@ -69741,10 +69814,11 @@
69814 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
69815 }
69816 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
69817 }
69818 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69819 pWal->iReCksum = 0;
69820 }
69821 return rc;
69822 }
69823
69824 /*
@@ -69788,10 +69862,13 @@
69862 pWal->hdr.aFrameCksum[1] = aWalData[2];
69863 SEH_TRY {
69864 walCleanupHash(pWal);
69865 }
69866 SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; )
69867 if( pWal->iReCksum>pWal->hdr.mxFrame ){
69868 pWal->iReCksum = 0;
69869 }
69870 }
69871
69872 return rc;
69873 }
69874
@@ -72503,11 +72580,11 @@
72580 if( pKey ){
72581 KeyInfo *pKeyInfo = pCur->pKeyInfo;
72582 assert( nKey==(i64)(int)nKey );
72583 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
72584 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72585 sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey);
72586 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72587 rc = SQLITE_CORRUPT_BKPT;
72588 }else{
72589 rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
72590 }
@@ -73560,14 +73637,14 @@
73637 u8 *pTmp; /* Temporary ptr into data[] */
73638
73639 assert( pPage->pBt!=0 );
73640 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73641 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
73642 assert( CORRUPT_DB || iEnd <= (int)pPage->pBt->usableSize );
73643 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73644 assert( iSize>=4 ); /* Minimum cell size is 4 */
73645 assert( CORRUPT_DB || iStart<=(int)pPage->pBt->usableSize-4 );
73646
73647 /* The list of freeblocks must be in ascending order. Find the
73648 ** spot on the list where iStart should be inserted.
73649 */
73650 hdr = pPage->hdrOffset;
@@ -74487,10 +74564,11 @@
74564 removed = 1;
74565 }
74566 sqlite3_mutex_leave(pMainMtx);
74567 return removed;
74568 #else
74569 UNUSED_PARAMETER( pBt );
74570 return 1;
74571 #endif
74572 }
74573
74574 /*
@@ -74704,10 +74782,14 @@
74782 BtShared *pBt = p->pBt;
74783 assert( nReserve>=0 && nReserve<=255 );
74784 sqlite3BtreeEnter(p);
74785 pBt->nReserveWanted = (u8)nReserve;
74786 x = pBt->pageSize - pBt->usableSize;
74787 if( x==nReserve && (pageSize==0 || (u32)pageSize==pBt->pageSize) ){
74788 sqlite3BtreeLeave(p);
74789 return SQLITE_OK;
74790 }
74791 if( nReserve<x ) nReserve = x;
74792 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
74793 sqlite3BtreeLeave(p);
74794 return SQLITE_READONLY;
74795 }
@@ -75328,10 +75410,17 @@
75410
75411 if( rc!=SQLITE_OK ){
75412 (void)sqlite3PagerWalWriteLock(pPager, 0);
75413 unlockBtreeIfUnused(pBt);
75414 }
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
75422 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75423 btreeInvokeBusyHandler(pBt) );
75424 sqlite3PagerWalDb(pPager, 0);
75425 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
75426 if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -77285,10 +77374,34 @@
77374 *pRes = 1;
77375 rc = SQLITE_OK;
77376 }
77377 return rc;
77378 }
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 }
77403
77404 #ifdef SQLITE_DEBUG
77405 /* The cursors is CURSOR_VALID and has BTCF_AtLast set. Verify that
77406 ** this flags are true for a consistent database.
77407 **
@@ -77505,12 +77618,12 @@
77618 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
77619 return rc;
77620 }
77621
77622 /*
77623 ** Compare the "idx"-th cell on the page pPage against the key
77624 ** pointing to by pIdxKey using xRecordCompare. Return negative or
77625 ** zero if the cell is less than or equal pIdxKey. Return positive
77626 ** if unknown.
77627 **
77628 ** Return value negative: Cell at pCur[idx] less than pIdxKey
77629 **
@@ -77521,16 +77634,15 @@
77634 **
77635 ** This routine is part of an optimization. It is always safe to return
77636 ** a positive value as that will cause the optimization to be skipped.
77637 */
77638 static int indexCellCompare(
77639 MemPage *pPage,
77640 int idx,
77641 UnpackedRecord *pIdxKey,
77642 RecordCompare xRecordCompare
77643 ){
 
77644 int c;
77645 int nCell; /* Size of the pCell cell in bytes */
77646 u8 *pCell = findCellPastPtr(pPage, idx);
77647
77648 nCell = pCell[0];
@@ -77635,18 +77747,18 @@
77747 && pCur->pPage->leaf
77748 && cursorOnLastPage(pCur)
77749 ){
77750 int c;
77751 if( pCur->ix==pCur->pPage->nCell-1
77752 && (c = indexCellCompare(pCur->pPage,pCur->ix,pIdxKey,xRecordCompare))<=0
77753 && pIdxKey->errCode==SQLITE_OK
77754 ){
77755 *pRes = c;
77756 return SQLITE_OK; /* Cursor already pointing at the correct spot */
77757 }
77758 if( pCur->iPage>0
77759 && indexCellCompare(pCur->pPage, 0, pIdxKey, xRecordCompare)<=0
77760 && pIdxKey->errCode==SQLITE_OK
77761 ){
77762 pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
77763 if( !pCur->pPage->isInit ){
77764 return SQLITE_CORRUPT_BKPT;
@@ -77859,11 +77971,11 @@
77971 if( pCur->eState!=CURSOR_VALID ) return 0;
77972 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77973
77974 n = pCur->pPage->nCell;
77975 for(i=0; i<pCur->iPage; i++){
77976 n *= pCur->apPage[i]->nCell+1;
77977 }
77978 return n;
77979 }
77980
77981 /*
@@ -80316,11 +80428,16 @@
80428
80429 /* If the sibling pages are not leaves, ensure that the right-child pointer
80430 ** of the right-most new sibling page is set to the value that was
80431 ** originally in the same field of the right-most old sibling page. */
80432 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
80433 MemPage *pOld;
80434 if( nNew>nOld ){
80435 pOld = apNew[nOld-1];
80436 }else{
80437 pOld = apOld[nOld-1];
80438 }
80439 memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
80440 }
80441
80442 /* Make any required updates to pointer map entries associated with
80443 ** cells stored on sibling pages following the balance operation. Pointer
@@ -82948,10 +83065,11 @@
83065 ** btree as the argument handle holds an exclusive lock on the
83066 ** sqlite_schema table. Otherwise SQLITE_OK.
83067 */
83068 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
83069 int rc;
83070 UNUSED_PARAMETER(p); /* only used in DEBUG builds */
83071 assert( sqlite3_mutex_held(p->db->mutex) );
83072 sqlite3BtreeEnter(p);
83073 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
83074 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
83075 sqlite3BtreeLeave(p);
@@ -87272,10 +87390,13 @@
87390 ** into register iDest, then add the OPFLAG_TYPEOFARG flag to that
87391 ** opcode.
87392 */
87393 SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe *p, int iDest){
87394 VdbeOp *pOp = sqlite3VdbeGetLastOp(p);
87395 #ifdef SQLITE_DEBUG
87396 while( pOp->opcode==OP_ReleaseReg ) pOp--;
87397 #endif
87398 if( pOp->p3==iDest && pOp->opcode==OP_Column ){
87399 pOp->p5 |= OPFLAG_TYPEOFARG;
87400 }
87401 }
87402
@@ -90165,34 +90286,26 @@
90286 }
90287 }
90288 return;
90289 }
90290 /*
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.
 
 
 
 
 
 
 
90296 */
90297 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
90298 KeyInfo *pKeyInfo /* Description of the record */
90299 ){
90300 UnpackedRecord *p; /* Unpacked record to return */
90301 u64 nByte; /* Number of bytes required for *p */
90302 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90303 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
90304 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
90305 if( !p ) return 0;
90306 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
 
90307 p->pKeyInfo = pKeyInfo;
90308 p->nField = pKeyInfo->nKeyField + 1;
90309 return p;
90310 }
90311
@@ -90200,11 +90313,10 @@
90313 ** Given the nKey-byte encoding of a record in pKey[], populate the
90314 ** UnpackedRecord structure indicated by the fourth argument with the
90315 ** contents of the decoded record.
90316 */
90317 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
 
90318 int nKey, /* Size of the binary record */
90319 const void *pKey, /* The binary record */
90320 UnpackedRecord *p /* Populate this structure before returning. */
90321 ){
90322 const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90211,10 +90323,11 @@
90323 u32 d;
90324 u32 idx; /* Offset in aKey[] to read from */
90325 u16 u; /* Unsigned loop counter */
90326 u32 szHdr;
90327 Mem *pMem = p->aMem;
90328 KeyInfo *pKeyInfo = p->pKeyInfo;
90329
90330 p->default_rc = 0;
90331 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
90332 idx = getVarint32(aKey, szHdr);
90333 d = szHdr;
@@ -90238,10 +90351,12 @@
90351 /* In a corrupt record entry, the last pMem might have been set up using
90352 ** uninitialized memory. Overwrite its value with NULL, to prevent
90353 ** warnings from MSAN. */
90354 sqlite3VdbeMemSetNull(pMem-1);
90355 }
90356 testcase( u == pKeyInfo->nKeyField + 1 );
90357 testcase( u < pKeyInfo->nKeyField + 1 );
90358 assert( u<=pKeyInfo->nKeyField + 1 );
90359 p->nField = u;
90360 }
90361
90362 #ifdef SQLITE_DEBUG
@@ -91097,10 +91212,11 @@
91212 ** is an integer.
91213 **
91214 ** The easiest way to enforce this limit is to consider only records with
91215 ** 13 fields or less. If the first field is an integer, the maximum legal
91216 ** header size is (12*5 + 1 + 1) bytes. */
91217 assert( p->pKeyInfo->aSortFlags!=0 );
91218 if( p->pKeyInfo->nAllField<=13 ){
91219 int flags = p->aMem[0].flags;
91220 if( p->pKeyInfo->aSortFlags[0] ){
91221 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91222 return sqlite3VdbeRecordCompare;
@@ -91346,10 +91462,11 @@
91462 }else{
91463 v->expmask |= ((u32)1 << (iVar-1));
91464 }
91465 }
91466
91467 #ifndef SQLITE_OMIT_DATETIME_FUNCS
91468 /*
91469 ** Cause a function to throw an error if it was call from OP_PureFunc
91470 ** rather than OP_Function.
91471 **
91472 ** OP_PureFunc means that the function must be deterministic, and should
@@ -91379,10 +91496,11 @@
91496 sqlite3_free(zMsg);
91497 return 0;
91498 }
91499 return 1;
91500 }
91501 #endif /* SQLITE_OMIT_DATETIME_FUNCS */
91502
91503 #if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
91504 /*
91505 ** This Walker callback is used to help verify that calls to
91506 ** sqlite3BtreeCursorHint() with opcode BTREE_HINT_RANGE have
@@ -91455,11 +91573,10 @@
91573 ){
91574 sqlite3 *db = v->db;
91575 i64 iKey2;
91576 PreUpdate preupdate;
91577 const char *zTbl = pTab->zName;
 
91578 #ifdef SQLITE_DEBUG
91579 int nRealCol;
91580 if( pTab->tabFlags & TF_WithoutRowid ){
91581 nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
91582 }else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91494,11 +91611,11 @@
91611 preupdate.iNewReg = iReg;
91612 preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91613 preupdate.pKeyinfo->db = db;
91614 preupdate.pKeyinfo->enc = ENC(db);
91615 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91616 preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
91617 preupdate.iKey1 = iKey1;
91618 preupdate.iKey2 = iKey2;
91619 preupdate.pTab = pTab;
91620 preupdate.iBlobWrite = iBlobWrite;
91621
@@ -93691,11 +93808,11 @@
93808 UnpackedRecord *pRet; /* Return value */
93809
93810 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
93811 if( pRet ){
93812 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93813 sqlite3VdbeRecordUnpack(nKey, pKey, pRet);
93814 }
93815 return pRet;
93816 }
93817
93818 /*
@@ -93720,10 +93837,13 @@
93837 rc = SQLITE_MISUSE_BKPT;
93838 goto preupdate_old_out;
93839 }
93840 if( p->pPk ){
93841 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
93842 }else if( iIdx >= p->pTab->nCol ){
93843 rc = SQLITE_MISUSE_BKPT;
93844 goto preupdate_old_out;
93845 }else{
93846 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93847 }
93848 if( iStore>=p->pCsr->nField || iStore<0 ){
93849 rc = SQLITE_RANGE;
@@ -93875,10 +93995,12 @@
93995 rc = SQLITE_MISUSE_BKPT;
93996 goto preupdate_new_out;
93997 }
93998 if( p->pPk && p->op!=SQLITE_UPDATE ){
93999 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
94000 }else if( iIdx >= p->pTab->nCol ){
94001 return SQLITE_MISUSE_BKPT;
94002 }else{
94003 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
94004 }
94005
94006 if( iStore>=p->pCsr->nField || iStore<0 ){
@@ -95200,10 +95322,40 @@
95322 }
95323 pDest->flags &= ~MEM_Ephem;
95324 return rc;
95325 }
95326
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 }
95357
95358 /*
95359 ** Return the symbolic name for the data type of a pMem
95360 */
95361 static const char *vdbeMemTypeName(Mem *pMem){
@@ -95725,12 +95877,11 @@
95877 p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
95878 }
95879 }else{
95880 sqlite3VdbeError(p, "%s", pOp->p4.z);
95881 }
95882 sqlite3VdbeLogAbort(p, pOp->p1, pOp, aOp);
 
95883 }
95884 rc = sqlite3VdbeHalt(p);
95885 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
95886 if( rc==SQLITE_BUSY ){
95887 p->rc = SQLITE_BUSY;
@@ -96884,10 +97035,11 @@
97035 }
97036 n = pOp->p3;
97037 pKeyInfo = pOp->p4.pKeyInfo;
97038 assert( n>0 );
97039 assert( pKeyInfo!=0 );
97040 assert( pKeyInfo->aSortFlags!=0 );
97041 p1 = pOp->p1;
97042 p2 = pOp->p2;
97043 #ifdef SQLITE_DEBUG
97044 if( aPermute ){
97045 int k, mx = 0;
@@ -97645,10 +97797,19 @@
97797 ** Synopsis: typecheck(r[P1@P2])
97798 **
97799 ** Apply affinities to the range of P2 registers beginning with P1.
97800 ** Take the affinities from the Table object in P4. If any value
97801 ** 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.
97811 **
97812 ** This opcode is similar to OP_Affinity except that this opcode
97813 ** forces the register type to the Table column type. This is used
97814 ** to implement "strict affinity".
97815 **
@@ -97659,30 +97820,42 @@
97820 **
97821 ** Preconditions:
97822 **
97823 ** <ul>
97824 ** <li> P2 should be the number of non-virtual columns in the
97825 ** table of P4 unless P3>1, in which case P2 will be 1.
97826 ** <li> Table P4 is a STRICT table.
97827 ** </ul>
97828 **
97829 ** If any precondition is false, an assertion fault occurs.
97830 */
97831 case OP_TypeCheck: {
97832 Table *pTab;
97833 Column *aCol;
97834 int i;
97835 int nCol;
97836
97837 assert( pOp->p4type==P4_TABLE );
97838 pTab = pOp->p4.pTab;
97839 assert( pTab->tabFlags & TF_Strict );
97840 assert( pOp->p3>=0 && pOp->p3<pTab->nCol+2 );
97841 aCol = pTab->aCol;
97842 pIn1 = &aMem[pOp->p1];
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;
97857 if( pOp->p3 ){ pIn1++; continue; }
97858 }
97859 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
97860 applyAffinity(pIn1, aCol[i].affinity, encoding);
97861 if( (pIn1->flags & MEM_Null)==0 ){
@@ -98119,10 +98292,11 @@
98292 }
98293 }else{
98294 zHdr += sqlite3PutVarint(zHdr, serial_type);
98295 if( pRec->n ){
98296 assert( pRec->z!=0 );
98297 assert( pRec->z!=(const char*)sqlite3CtypeMap );
98298 memcpy(zPayload, pRec->z, pRec->n);
98299 zPayload += pRec->n;
98300 }
98301 }
98302 if( pRec==pLast ) break;
@@ -99756,11 +99930,11 @@
99930 rc = ExpandBlob(r.aMem);
99931 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
99932 if( rc ) goto no_mem;
99933 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
99934 if( pIdxKey==0 ) goto no_mem;
99935 sqlite3VdbeRecordUnpack(r.aMem->n, r.aMem->z, pIdxKey);
99936 pIdxKey->default_rc = 0;
99937 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
99938 sqlite3DbFreeNN(db, pIdxKey);
99939 }
99940 if( rc!=SQLITE_OK ){
@@ -100753,10 +100927,36 @@
100927 VdbeBranchTaken(res!=0,2);
100928 if( res ) goto jump_to_p2;
100929 }
100930 break;
100931 }
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 }
100958
100959 /* Opcode: Next P1 P2 P3 * P5
100960 **
100961 ** Advance cursor P1 so that it points to the next key/data pair in its
100962 ** table or index. If there are no more key/value pairs then fall through
@@ -102625,11 +102825,18 @@
102825 sqlite3_vtab_cursor *pVCur;
102826 sqlite3_vtab *pVtab;
102827 const sqlite3_module *pModule;
102828
102829 assert( p->bIsReader );
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 }
102838 pVCur = 0;
102839 pVtab = pOp->p4.pVtab->pVtab;
102840 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
102841 rc = SQLITE_LOCKED;
102842 goto abort_due_to_error;
@@ -103567,12 +103774,11 @@
103774 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
103775 }
103776 p->rc = rc;
103777 sqlite3SystemError(db, rc);
103778 testcase( sqlite3GlobalConfig.xLog!=0 );
103779 sqlite3VdbeLogAbort(p, rc, pOp, aOp);
 
103780 if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p);
103781 if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
103782 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
103783 db->flags |= SQLITE_CorruptRdOnly;
103784 }
@@ -104029,11 +104235,11 @@
104235 void *z,
104236 int n,
104237 int iOffset,
104238 int (*xCall)(BtCursor*, u32, u32, void*)
104239 ){
104240 int rc = SQLITE_OK;
104241 Incrblob *p = (Incrblob *)pBlob;
104242 Vdbe *v;
104243 sqlite3 *db;
104244
104245 if( p==0 ) return SQLITE_MISUSE_BKPT;
@@ -104069,21 +104275,36 @@
104275 ** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
104276 ** slightly more efficient). Since you cannot write to a PK column
104277 ** using the incremental-blob API, this works. For the sessions module
104278 ** anyhow.
104279 */
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
104303 rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
104304 #endif
104305
104306 sqlite3BtreeLeaveCursor(p->pCsr);
104307 if( rc==SQLITE_ABORT ){
104308 sqlite3VdbeFinalize(v);
104309 p->pStmt = 0;
104310 }else{
@@ -104932,11 +105153,11 @@
105153 const void *pKey1, int nKey1, /* Left side of comparison */
105154 const void *pKey2, int nKey2 /* Right side of comparison */
105155 ){
105156 UnpackedRecord *r2 = pTask->pUnpacked;
105157 if( *pbKey2Cached==0 ){
105158 sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
105159 *pbKey2Cached = 1;
105160 }
105161 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
105162 }
105163
@@ -104959,11 +105180,11 @@
105180 const void *pKey1, int nKey1, /* Left side of comparison */
105181 const void *pKey2, int nKey2 /* Right side of comparison */
105182 ){
105183 UnpackedRecord *r2 = pTask->pUnpacked;
105184 if( !*pbKey2Cached ){
105185 sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
105186 *pbKey2Cached = 1;
105187 }
105188 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
105189 }
105190
@@ -104999,10 +105220,11 @@
105220 res = vdbeSorterCompareTail(
105221 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105222 );
105223 }
105224 }else{
105225 assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
105226 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
105227 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
105228 res = res * -1;
105229 }
105230 }
@@ -105062,10 +105284,11 @@
105284 }else{
105285 if( *v2 & 0x80 ) res = +1;
105286 }
105287 }
105288
105289 assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
105290 if( res==0 ){
105291 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
105292 res = vdbeSorterCompareTail(
105293 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105294 );
@@ -105135,11 +105358,12 @@
105358 assert( pCsr->pKeyInfo );
105359 assert( !pCsr->isEphemeral );
105360 assert( pCsr->eCurType==CURTYPE_SORTER );
105361 assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105362 < 0x7fffffff );
105363 assert( pCsr->pKeyInfo->nKeyField<=pCsr->pKeyInfo->nAllField );
105364 szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nAllField);
105365 sz = SZ_VDBESORTER(nWorker+1);
105366
105367 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105368 pCsr->uc.pSorter = pSorter;
105369 if( pSorter==0 ){
@@ -105149,11 +105373,16 @@
105373 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105374 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105375 pKeyInfo->db = 0;
105376 if( nField && nWorker==0 ){
105377 pKeyInfo->nKeyField = nField;
105378 assert( nField<=pCsr->pKeyInfo->nAllField );
105379 }
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 );
105384 sqlite3BtreeEnter(pBt);
105385 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105386 sqlite3BtreeLeave(pBt);
105387 pSorter->nTask = nWorker + 1;
105388 pSorter->iPrev = (u8)(nWorker - 1);
@@ -106929,11 +107158,11 @@
107158 r2->nField = nKeyCol;
107159 }
107160 assert( r2->nField==nKeyCol );
107161
107162 pKey = vdbeSorterRowkey(pSorter, &nKey);
107163 sqlite3VdbeRecordUnpack(nKey, pKey, r2);
107164 for(i=0; i<nKeyCol; i++){
107165 if( r2->aMem[i].flags & MEM_Null ){
107166 *pRes = -1;
107167 return SQLITE_OK;
107168 }
@@ -109303,17 +109532,16 @@
109532 /* Clearly non-deterministic functions like random(), but also
109533 ** date/time functions that use 'now', and other functions like
109534 ** sqlite_version() that might change over time cannot be used
109535 ** in an index or generated column. Curiously, they can be used
109536 ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
109537 ** allow this. */
109538 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
109539 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
109540 }else{
109541 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
109542 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
 
109543 }
109544 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
109545 && pParse->nested==0
109546 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
109547 ){
@@ -109325,10 +109553,11 @@
109553 pDef = 0;
109554 }else
109555 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
109556 && !IN_RENAME_OBJECT
109557 ){
109558 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
109559 sqlite3ExprFunctionUsable(pParse, pExpr, pDef);
109560 }
109561 }
109562
109563 if( 0==IN_RENAME_OBJECT ){
@@ -109459,22 +109688,25 @@
109688 ** type of the function
109689 */
109690 return WRC_Prune;
109691 }
109692 #ifndef SQLITE_OMIT_SUBQUERY
109693 case TK_EXISTS:
109694 case TK_SELECT:
 
109695 #endif
109696 case TK_IN: {
109697 testcase( pExpr->op==TK_IN );
109698 testcase( pExpr->op==TK_EXISTS );
109699 testcase( pExpr->op==TK_SELECT );
109700 if( ExprUseXSelect(pExpr) ){
109701 int nRef = pNC->nRef;
109702 testcase( pNC->ncFlags & NC_IsCheck );
109703 testcase( pNC->ncFlags & NC_PartIdx );
109704 testcase( pNC->ncFlags & NC_IdxExpr );
109705 testcase( pNC->ncFlags & NC_GenCol );
109706 assert( pExpr->x.pSelect );
109707 if( pExpr->op==TK_EXISTS ) pParse->bHasExists = 1;
109708 if( pNC->ncFlags & NC_SelfRef ){
109709 notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
109710 }else{
109711 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
109712 }
@@ -110485,11 +110717,13 @@
110717 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110718 return sqlite3ExprAffinity(
110719 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110720 );
110721 }
110722 if( op==TK_VECTOR
110723 || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
110724 ){
110725 assert( ExprUseXList(pExpr) );
110726 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110727 }
110728 if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110729 assert( pExpr->op==TK_COLLATE
@@ -110678,11 +110912,13 @@
110912 }
110913 if( op==TK_CAST || op==TK_UPLUS ){
110914 p = p->pLeft;
110915 continue;
110916 }
110917 if( op==TK_VECTOR
110918 || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
110919 ){
110920 assert( ExprUseXList(p) );
110921 p = p->x.pList->a[0].pExpr;
110922 continue;
110923 }
110924 if( op==TK_COLLATE ){
@@ -111552,11 +111788,11 @@
111788 return pRight;
111789 }else if( pRight==0 ){
111790 return pLeft;
111791 }else{
111792 u32 f = pLeft->flags | pRight->flags;
111793 if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse|EP_HasFunc))==EP_IsFalse
111794 && !IN_RENAME_OBJECT
111795 ){
111796 sqlite3ExprDeferredDelete(pParse, pLeft);
111797 sqlite3ExprDeferredDelete(pParse, pRight);
111798 return sqlite3Expr(db, TK_INTEGER, "0");
@@ -112780,10 +113016,90 @@
113016 pExpr = pExpr->op==TK_AND ? pLeft : pRight;
113017 }
113018 }
113019 return pExpr;
113020 }
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 }
113101
113102 /*
113103 ** pExpr is a TK_FUNCTION node. Try to determine whether or not the
113104 ** function is a constant function. A function is constant if all of
113105 ** the following are true:
@@ -114225,21 +114541,27 @@
114541 dest.eDest = SRT_Exists;
114542 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
114543 VdbeComment((v, "Init EXISTS result"));
114544 }
114545 if( pSel->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 }
114563 }else{
114564 /* If there is no pre-existing limit add a limit of 1 */
114565 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
114566 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
114567 }
@@ -114677,11 +114999,16 @@
114999 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
115000 }else{
115001 iAddr = 0;
115002 }
115003 sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut);
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 ){
115010 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
115011 }
115012 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
115013 if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
115014 }
@@ -115364,15 +115691,21 @@
115691 case TK_GT:
115692 case TK_GE:
115693 case TK_NE:
115694 case TK_EQ: {
115695 Expr *pLeft = pExpr->pLeft;
115696 int addrIsNull = 0;
115697 if( sqlite3ExprIsVector(pLeft) ){
115698 codeVectorCompare(pParse, pExpr, target, op, p5);
115699 }else{
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 }
115707 sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
115708 codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
115709 sqlite3VdbeCurrentAddr(v)+2, p5,
115710 ExprHasProperty(pExpr,EP_Commuted));
115711 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
@@ -115383,13 +115716,19 @@
115716 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
115717 if( p5==SQLITE_NULLEQ ){
115718 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
115719 }else{
115720 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 }
115726 }
115727 testcase( regFree1==0 );
115728 testcase( regFree2==0 );
115729
115730 }
115731 break;
115732 }
115733 case TK_AND:
115734 case TK_OR:
@@ -115401,10 +115740,11 @@
115740 case TK_BITOR:
115741 case TK_SLASH:
115742 case TK_LSHIFT:
115743 case TK_RSHIFT:
115744 case TK_CONCAT: {
115745 int addrIsNull;
115746 assert( TK_AND==OP_And ); testcase( op==TK_AND );
115747 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115748 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
115749 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
115750 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
@@ -115412,15 +115752,27 @@
115752 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
115753 assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
115754 assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
115755 assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
115756 assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
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 }
115765 sqlite3VdbeAddOp3(v, op, r2, r1, target);
115766 testcase( regFree1==0 );
115767 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 }
115774 break;
115775 }
115776 case TK_UMINUS: {
115777 Expr *pLeft = pExpr->pLeft;
115778 assert( pLeft );
@@ -116265,21 +116617,31 @@
116617 case TK_AND:
116618 case TK_OR: {
116619 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116620 if( pAlt!=pExpr ){
116621 sqlite3ExprIfTrue(pParse, pAlt, dest, jumpIfNull);
 
 
 
 
 
 
 
116622 }else{
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 }
116643 }
116644 break;
116645 }
116646 case TK_NOT: {
116647 testcase( jumpIfNull==0 );
@@ -116314,14 +116676,20 @@
116676 case TK_LE:
116677 case TK_GT:
116678 case TK_GE:
116679 case TK_NE:
116680 case TK_EQ: {
116681 int addrIsNull;
116682 if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
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 }
116691 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116692 r1, r2, dest, jumpIfNull, ExprHasProperty(pExpr,EP_Commuted));
116693 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116694 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116695 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116332,22 +116700,29 @@
116700 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116701 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116702 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116703 testcase( regFree1==0 );
116704 testcase( regFree2==0 );
116705 if( addrIsNull ){
116706 if( jumpIfNull ){
116707 sqlite3VdbeChangeP2(v, addrIsNull, dest);
116708 }else{
116709 sqlite3VdbeJumpHere(v, addrIsNull);
116710 }
116711 }
116712 break;
116713 }
116714 case TK_ISNULL:
116715 case TK_NOTNULL: {
116716 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
116717 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
116718 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116719 assert( regFree1==0 || regFree1==r1 );
116720 if( regFree1 ) sqlite3VdbeTypeofColumn(v, r1);
116721 sqlite3VdbeAddOp2(v, op, r1, dest);
116722 VdbeCoverageIf(v, op==TK_ISNULL);
116723 VdbeCoverageIf(v, op==TK_NOTNULL);
 
116724 break;
116725 }
116726 case TK_BETWEEN: {
116727 testcase( jumpIfNull==0 );
116728 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
@@ -116439,21 +116814,31 @@
116814 case TK_AND:
116815 case TK_OR: {
116816 Expr *pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
116817 if( pAlt!=pExpr ){
116818 sqlite3ExprIfFalse(pParse, pAlt, dest, jumpIfNull);
 
 
 
 
116819 }else{
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 }
116840 }
116841 break;
116842 }
116843 case TK_NOT: {
116844 testcase( jumpIfNull==0 );
@@ -116491,14 +116876,20 @@
116876 case TK_LE:
116877 case TK_GT:
116878 case TK_GE:
116879 case TK_NE:
116880 case TK_EQ: {
116881 int addrIsNull;
116882 if( sqlite3ExprIsVector(pExpr->pLeft) ) goto default_expr;
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 }
116891 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
116892 r1, r2, dest, jumpIfNull,ExprHasProperty(pExpr,EP_Commuted));
116893 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
116894 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
116895 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
@@ -116509,20 +116900,27 @@
116900 assert(TK_NE==OP_Ne); testcase(op==OP_Ne);
116901 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull!=SQLITE_NULLEQ);
116902 VdbeCoverageIf(v, op==OP_Ne && jumpIfNull==SQLITE_NULLEQ);
116903 testcase( regFree1==0 );
116904 testcase( regFree2==0 );
116905 if( addrIsNull ){
116906 if( jumpIfNull ){
116907 sqlite3VdbeChangeP2(v, addrIsNull, dest);
116908 }else{
116909 sqlite3VdbeJumpHere(v, addrIsNull);
116910 }
116911 }
116912 break;
116913 }
116914 case TK_ISNULL:
116915 case TK_NOTNULL: {
116916 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
116917 assert( regFree1==0 || regFree1==r1 );
116918 if( regFree1 ) sqlite3VdbeTypeofColumn(v, r1);
116919 sqlite3VdbeAddOp2(v, op, r1, dest);
116920 testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
116921 testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
 
116922 break;
116923 }
116924 case TK_BETWEEN: {
116925 testcase( jumpIfNull==0 );
116926 exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfFalse, jumpIfNull);
@@ -117418,11 +117816,13 @@
117816 AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
117817 Expr *pExpr /* Expr describing the column to find or insert */
117818 ){
117819 struct AggInfo_col *pCol;
117820 int k;
117821 int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
117822
117823 assert( mxTerm <= SMXV(i16) );
117824 assert( pAggInfo->iFirstReg==0 );
117825 pCol = pAggInfo->aCol;
117826 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
117827 if( pCol->pCExpr==pExpr ) return;
117828 if( pCol->iTable==pExpr->iTable
@@ -117435,10 +117835,14 @@
117835 k = addAggInfoColumn(pParse->db, pAggInfo);
117836 if( k<0 ){
117837 /* OOM on resize */
117838 assert( pParse->db->mallocFailed );
117839 return;
117840 }
117841 if( k>mxTerm ){
117842 sqlite3ErrorMsg(pParse, "more than %d aggregate terms", mxTerm);
117843 k = mxTerm;
117844 }
117845 pCol = &pAggInfo->aCol[k];
117846 assert( ExprUseYTab(pExpr) );
117847 pCol->pTab = pExpr->y.pTab;
117848 pCol->iTable = pExpr->iTable;
@@ -117469,10 +117873,11 @@
117873 assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
117874 pExpr->pAggInfo = pAggInfo;
117875 if( pExpr->op==TK_COLUMN ){
117876 pExpr->op = TK_AGG_COLUMN;
117877 }
117878 assert( k <= SMXV(pExpr->iAgg) );
117879 pExpr->iAgg = (i16)k;
117880 }
117881
117882 /*
117883 ** This is the xExprCallback for a tree walker. It is used to
@@ -117553,17 +117958,23 @@
117958 ){
117959 /* Check to see if pExpr is a duplicate of another aggregate
117960 ** function that is already in the pAggInfo structure
117961 */
117962 struct AggInfo_func *pItem = pAggInfo->aFunc;
117963 int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
117964 assert( mxTerm <= SMXV(i16) );
117965 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
117966 if( NEVER(pItem->pFExpr==pExpr) ) break;
117967 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
117968 break;
117969 }
117970 }
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 ){
117976 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
117977 */
117978 u8 enc = ENC(pParse->db);
117979 i = addAggInfoFunc(pParse->db, pAggInfo);
117980 if( i>=0 ){
@@ -117613,10 +118024,11 @@
118024 }
118025 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
118026 */
118027 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
118028 ExprSetVVAProperty(pExpr, EP_NoReduce);
118029 assert( i <= SMXV(pExpr->iAgg) );
118030 pExpr->iAgg = (i16)i;
118031 pExpr->pAggInfo = pAggInfo;
118032 return WRC_Prune;
118033 }else{
118034 return WRC_Continue;
@@ -119015,14 +119427,14 @@
119427 }else{
119428 nQuot = sqlite3Strlen30(zQuot)-1;
119429 }
119430
119431 assert( nQuot>=nNew && nSql>=0 && nNew>=0 );
119432 zOut = sqlite3DbMallocZero(db, (u64)nSql + pRename->nList*(u64)nQuot + 1);
119433 }else{
119434 assert( nSql>0 );
119435 zOut = (char*)sqlite3DbMallocZero(db, (2*(u64)nSql + 1) * 3);
119436 if( zOut ){
119437 zBuf1 = &zOut[nSql*2+1];
119438 zBuf2 = &zOut[nSql*4+2];
119439 }
119440 }
@@ -121700,20 +122112,10 @@
122112 }
122113 #endif
122114 while( z[0]!=0 && z[0]!=' ' ) z++;
122115 while( z[0]==' ' ) z++;
122116 }
 
 
 
 
 
 
 
 
 
 
122117 }
122118 }
122119
122120 /*
122121 ** This callback is invoked once for each index when reading the
@@ -127256,11 +127658,10 @@
127658 }else{
127659 j = pCExpr->iColumn;
127660 assert( j<=0x7fff );
127661 if( j<0 ){
127662 j = pTab->iPKey;
 
127663 }else{
127664 if( pTab->aCol[j].notNull==0 ){
127665 pIndex->uniqNotNull = 0;
127666 }
127667 if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -128175,20 +128576,26 @@
128576 ** Append the contents of SrcList p2 to SrcList p1 and return the resulting
128577 ** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
128578 ** are deleted by this function.
128579 */
128580 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
128581 assert( p1 );
128582 assert( p2 || pParse->nErr );
128583 assert( p2==0 || p2->nSrc>=1 );
128584 testcase( p1->nSrc==0 );
128585 if( p2 ){
128586 int nOld = p1->nSrc;
128587 SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, nOld);
128588 if( pNew==0 ){
128589 sqlite3SrcListDelete(pParse->db, p2);
128590 }else{
128591 p1 = pNew;
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);
128596 sqlite3DbFree(pParse->db, p2);
 
128597 }
128598 }
128599 return p1;
128600 }
128601
@@ -132081,11 +132488,11 @@
132488 int argc,
132489 sqlite3_value **argv,
132490 int nSep,
132491 const char *zSep
132492 ){
132493 i64 j, n = 0;
132494 int i;
132495 char *z;
132496 for(i=0; i<argc; i++){
132497 n += sqlite3_value_bytes(argv[i]);
132498 }
@@ -132095,12 +132502,12 @@
132502 sqlite3_result_error_nomem(context);
132503 return;
132504 }
132505 j = 0;
132506 for(i=0; i<argc; i++){
132507 if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){
132508 int k = sqlite3_value_bytes(argv[i]);
132509 const char *v = (const char*)sqlite3_value_text(argv[i]);
132510 if( v!=0 ){
132511 if( j>0 && nSep>0 ){
132512 memcpy(&z[j], zSep, nSep);
132513 j += nSep;
@@ -135034,16 +135441,19 @@
135441 if( iReg==0 ){
135442 /* Move the previous opcode (which should be OP_MakeRecord) forward
135443 ** by one slot and insert a new OP_TypeCheck where the current
135444 ** OP_MakeRecord is found */
135445 VdbeOp *pPrev;
135446 int p3;
135447 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135448 pPrev = sqlite3VdbeGetLastOp(v);
135449 assert( pPrev!=0 );
135450 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
135451 pPrev->opcode = OP_TypeCheck;
135452 p3 = pPrev->p3;
135453 pPrev->p3 = 0;
135454 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, p3);
135455 }else{
135456 /* Insert an isolated OP_Typecheck */
135457 sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
135458 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
135459 }
@@ -138772,10 +139182,12 @@
139182 /* Version 3.43.0 and later */
139183 int (*stmt_explain)(sqlite3_stmt*,int);
139184 /* Version 3.44.0 and later */
139185 void *(*get_clientdata)(sqlite3*,const char*);
139186 int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
139187 /* Version 3.50.0 and later */
139188 int (*setlk_timeout)(sqlite3*,int,int);
139189 };
139190
139191 /*
139192 ** This is the function signature used for all extension entry points. It
139193 ** is also defined in the file "loadext.c".
@@ -139105,10 +139517,12 @@
139517 /* Version 3.43.0 and later */
139518 #define sqlite3_stmt_explain sqlite3_api->stmt_explain
139519 /* Version 3.44.0 and later */
139520 #define sqlite3_get_clientdata sqlite3_api->get_clientdata
139521 #define sqlite3_set_clientdata sqlite3_api->set_clientdata
139522 /* Version 3.50.0 and later */
139523 #define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
139524 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139525
139526 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139527 /* This case when the file really is being compiled as a loadable
139528 ** extension */
@@ -139626,11 +140040,13 @@
140040 sqlite3_is_interrupted,
140041 /* Version 3.43.0 and later */
140042 sqlite3_stmt_explain,
140043 /* Version 3.44.0 and later */
140044 sqlite3_get_clientdata,
140045 sqlite3_set_clientdata,
140046 /* Version 3.50.0 and later */
140047 sqlite3_setlk_timeout
140048 };
140049
140050 /* True if x is the directory separator character
140051 */
140052 #if SQLITE_OS_WIN
@@ -145252,11 +145668,11 @@
145668 SrcList *pSrc, /* Array of tables to search */
145669 int iStart, /* First member of pSrc->a[] to check */
145670 int iEnd, /* Last member of pSrc->a[] to check */
145671 const char *zCol, /* Name of the column we are looking for */
145672 int *piTab, /* Write index of pSrc->a[] here */
145673 int *piCol, /* Write index of pSrc->a[*piTab].pSTab->aCol[] here */
145674 int bIgnoreHidden /* Ignore hidden columns */
145675 ){
145676 int i; /* For looping over tables in pSrc */
145677 int iCol; /* Index of column matching zCol */
145678
@@ -145464,11 +145880,11 @@
145880 "not present in both tables", zName);
145881 return 1;
145882 }
145883 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145884 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145885 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145886 /* This branch runs if the query contains one or more RIGHT or FULL
145887 ** JOINs. If only a single table on the left side of this join
145888 ** contains the zName column, then this branch is a no-op.
145889 ** But if there are two or more tables on the left side
145890 ** of the join, construct a coalesce() function that gathers all
@@ -145480,10 +145896,12 @@
145896 ** JOIN. But older versions of SQLite do not do that, so we avoid
145897 ** adding a new error so as to not break legacy applications.
145898 */
145899 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145900 static const Token tkCoalesce = { "coalesce", 8 };
145901 assert( pE1!=0 );
145902 ExprSetProperty(pE1, EP_CanBeNull);
145903 while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145904 pRight->fg.isSynthUsing)!=0 ){
145905 if( pSrc->a[iLeft].fg.isUsing==0
145906 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145907 ){
@@ -145496,11 +145914,17 @@
145914 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145915 }
145916 if( pFuncArgs ){
145917 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145918 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145919 if( pE1 ){
145920 pE1->affExpr = SQLITE_AFF_DEFER;
145921 }
145922 }
145923 }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145924 assert( pE1!=0 );
145925 ExprSetProperty(pE1, EP_CanBeNull);
145926 }
145927 pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145928 sqlite3SrcItemColumnUsed(pRight, iRightCol);
145929 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145930 assert( pE2!=0 || pEq==0 );
@@ -146973,10 +147397,14 @@
147397 #else
147398 zType = columnType(&sNC, p, 0, 0, 0);
147399 #endif
147400 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
147401 }
147402 #else
147403 UNUSED_PARAMETER(pParse);
147404 UNUSED_PARAMETER(pTabList);
147405 UNUSED_PARAMETER(pEList);
147406 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
147407 }
147408
147409
147410 /*
@@ -147892,11 +148320,13 @@
148320 int unionTab; /* Cursor number of the temp table holding result */
148321 u8 op = 0; /* One of the SRT_ operations to apply to self */
148322 int priorOp; /* The SRT_ operation to apply to prior selects */
148323 Expr *pLimit; /* Saved values of p->nLimit */
148324 int addr;
148325 int emptyBypass = 0; /* IfEmpty opcode to bypass RHS */
148326 SelectDest uniondest;
148327
148328
148329 testcase( p->op==TK_EXCEPT );
148330 testcase( p->op==TK_UNION );
148331 priorOp = SRT_Union;
148332 if( dest.eDest==priorOp ){
@@ -147931,10 +148361,12 @@
148361
148362 /* Code the current SELECT statement
148363 */
148364 if( p->op==TK_EXCEPT ){
148365 op = SRT_Except;
148366 emptyBypass = sqlite3VdbeAddOp1(v, OP_IfEmpty, unionTab);
148367 VdbeCoverage(v);
148368 }else{
148369 assert( p->op==TK_UNION );
148370 op = SRT_Union;
148371 }
148372 p->pPrior = 0;
@@ -147951,10 +148383,11 @@
148383 p->pPrior = pPrior;
148384 p->pOrderBy = 0;
148385 if( p->op==TK_UNION ){
148386 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
148387 }
148388 if( emptyBypass ) sqlite3VdbeJumpHere(v, emptyBypass);
148389 sqlite3ExprDelete(db, p->pLimit);
148390 p->pLimit = pLimit;
148391 p->iLimit = 0;
148392 p->iOffset = 0;
148393
@@ -147981,13 +148414,14 @@
148414 }
148415 default: assert( p->op==TK_INTERSECT ); {
148416 int tab1, tab2;
148417 int iCont, iBreak, iStart;
148418 Expr *pLimit;
148419 int addr, iLimit, iOffset;
148420 SelectDest intersectdest;
148421 int r1;
148422 int emptyBypass;
148423
148424 /* INTERSECT is different from the others since it requires
148425 ** two temporary tables. Hence it has its own case. Begin
148426 ** by allocating the tables we will need.
148427 */
@@ -148008,18 +148442,32 @@
148442 rc = sqlite3Select(pParse, pPrior, &intersectdest);
148443 if( rc ){
148444 goto multi_select_end;
148445 }
148446
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
148453 /* Code the current SELECT into temporary table "tab2"
148454 */
148455 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab2, 0);
148456 assert( p->addrOpenEphm[1] == -1 );
148457 p->addrOpenEphm[1] = addr;
148458
148459 /* Disable prior SELECTs and the LIMIT counters during the computation
148460 ** of the RHS select */
148461 pLimit = p->pLimit;
148462 iLimit = p->iLimit;
148463 iOffset = p->iOffset;
148464 p->pPrior = 0;
148465 p->pLimit = 0;
148466 p->iLimit = 0;
148467 p->iOffset = 0;
148468
148469 intersectdest.iSDParm = tab2;
148470 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
148471 sqlite3SelectOpName(p->op)));
148472 TREETRACE(0x400, pParse, p, ("multiSelect INTERSECT right...\n"));
148473 rc = sqlite3Select(pParse, p, &intersectdest);
@@ -148028,32 +148476,35 @@
148476 p->pPrior = pPrior;
148477 if( p->nSelectRow>pPrior->nSelectRow ){
148478 p->nSelectRow = pPrior->nSelectRow;
148479 }
148480 sqlite3ExprDelete(db, p->pLimit);
148481
148482 /* Reinstate the LIMIT counters prior to running the final intersect */
148483 p->pLimit = pLimit;
148484 p->iLimit = iLimit;
148485 p->iOffset = iOffset;
148486
148487 /* Generate code to take the intersection of the two temporary
148488 ** tables.
148489 */
148490 if( rc ) break;
148491 assert( p->pEList );
148492 sqlite3VdbeAddOp1(v, OP_Rewind, tab1);
 
 
 
148493 r1 = sqlite3GetTempReg(pParse);
148494 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
148495 iCont = sqlite3VdbeMakeLabel(pParse);
148496 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
148497 VdbeCoverage(v);
148498 sqlite3ReleaseTempReg(pParse, r1);
148499 selectInnerLoop(pParse, p, tab1,
148500 0, 0, &dest, iCont, iBreak);
148501 sqlite3VdbeResolveLabel(v, iCont);
148502 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
148503 sqlite3VdbeResolveLabel(v, iBreak);
148504 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
148505 sqlite3VdbeJumpHere(v, emptyBypass);
148506 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
148507 break;
148508 }
148509 }
148510
@@ -148728,10 +149179,11 @@
149179 typedef struct SubstContext {
149180 Parse *pParse; /* The parsing context */
149181 int iTable; /* Replace references to this table */
149182 int iNewTable; /* New table number */
149183 int isOuterJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
149184 int nSelDepth; /* Depth of sub-query recursion. Top==1 */
149185 ExprList *pEList; /* Replacement expressions */
149186 ExprList *pCList; /* Collation sequences for replacement expr */
149187 } SubstContext;
149188
149189 /* Forward Declarations */
@@ -148834,10 +149286,13 @@
149286 }
149287 }
149288 }else{
149289 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
149290 pExpr->iTable = pSubst->iNewTable;
149291 }
149292 if( pExpr->op==TK_AGG_FUNCTION && pExpr->op2>=pSubst->nSelDepth ){
149293 pExpr->op2--;
149294 }
149295 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
149296 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
149297 if( ExprUseXSelect(pExpr) ){
149298 substSelect(pSubst, pExpr->x.pSelect, 1);
@@ -148872,10 +149327,11 @@
149327 ){
149328 SrcList *pSrc;
149329 SrcItem *pItem;
149330 int i;
149331 if( !p ) return;
149332 pSubst->nSelDepth++;
149333 do{
149334 substExprList(pSubst, p->pEList);
149335 substExprList(pSubst, p->pGroupBy);
149336 substExprList(pSubst, p->pOrderBy);
149337 p->pHaving = substExpr(pSubst, p->pHaving);
@@ -148889,10 +149345,11 @@
149345 if( pItem->fg.isTabFunc ){
149346 substExprList(pSubst, pItem->u1.pFuncArg);
149347 }
149348 }
149349 }while( doPrior && (p = p->pPrior)!=0 );
149350 pSubst->nSelDepth--;
149351 }
149352 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
149353
149354 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
149355 /*
@@ -149104,13 +149561,13 @@
149561 ** other than the one FROM-clause subquery that is a candidate
149562 ** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149563 ** from 2015-02-09.)
149564 **
149565 ** (3) If the subquery is the right operand of a LEFT JOIN then
149566 ** (3a) the subquery may not be a join
149567 ** (**) Was (3b): "the FROM clause of the subquery may not contain
149568 ** a virtual table"
149569 ** (**) Was: "The outer query may not have a GROUP BY." This case
149570 ** is now managed correctly
149571 ** (3d) the outer query may not be DISTINCT.
149572 ** See also (26) for restrictions on RIGHT JOIN.
149573 **
@@ -149322,11 +149779,11 @@
149779 **
149780 ** See also tickets #306, #350, and #3300.
149781 */
149782 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149783 if( pSubSrc->nSrc>1 /* (3a) */
149784 /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149785 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149786 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149787 ){
149788 return 0;
149789 }
@@ -149500,11 +149957,11 @@
149957 /* Defer deleting the Table object associated with the
149958 ** subquery until code generation is
149959 ** complete, since there may still exist Expr.pTab entries that
149960 ** refer to the subquery even after flattening. Ticket #3346.
149961 **
149962 ** pSubitem->pSTab is always non-NULL by test restrictions and tests above.
149963 */
149964 if( ALWAYS(pSubitem->pSTab!=0) ){
149965 Table *pTabToDel = pSubitem->pSTab;
149966 if( pTabToDel->nTabRef==1 ){
149967 Parse *pToplevel = sqlite3ParseToplevel(pParse);
@@ -149630,10 +150087,11 @@
150087 SubstContext x;
150088 x.pParse = pParse;
150089 x.iTable = iParent;
150090 x.iNewTable = iNewParent;
150091 x.isOuterJoin = isOuterJoin;
150092 x.nSelDepth = 0;
150093 x.pEList = pSub->pEList;
150094 x.pCList = findLeftmostExprlist(pSub);
150095 substSelect(&x, pParent, 0);
150096 }
150097
@@ -150215,10 +150673,11 @@
150673 unsetJoinExpr(pNew, -1, 1);
150674 x.pParse = pParse;
150675 x.iTable = pSrc->iCursor;
150676 x.iNewTable = pSrc->iCursor;
150677 x.isOuterJoin = 0;
150678 x.nSelDepth = 0;
150679 x.pEList = pSubq->pEList;
150680 x.pCList = findLeftmostExprlist(pSubq);
150681 pNew = substExpr(&x, pNew);
150682 #ifndef SQLITE_OMIT_WINDOWFUNC
150683 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -150612,11 +151071,11 @@
151071 ** a WITH clause on the stack currently maintained by the parser (on the
151072 ** pParse->pWith linked list). And if currently processing a CTE
151073 ** CTE expression, through routine checks to see if the reference is
151074 ** a recursive reference to the CTE.
151075 **
151076 ** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
151077 ** and other fields are populated accordingly.
151078 **
151079 ** Return 0 if no match is found.
151080 ** Return 1 if a match is found.
151081 ** Return 2 if an error condition is detected.
@@ -152238,10 +152697,87 @@
152697 pItem--;
152698 if( pItem->fg.isSubquery ) return 0; /* (1c-i) */
152699 }
152700 return 1;
152701 }
152702
152703 /*
152704 ** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
152705 ** function attempts to transform expressions of the form:
152706 **
152707 ** EXISTS (SELECT ...)
152708 **
152709 ** into joins. For example, given
152710 **
152711 ** CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
152712 ** CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
152713 **
152714 ** SELECT name FROM sailors AS S WHERE EXISTS (
152715 ** SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
152716 ** );
152717 **
152718 ** the SELECT statement may be transformed as follows:
152719 **
152720 ** SELECT name FROM sailors AS S, reserves AS R
152721 ** WHERE S.sid = R.sid AND R.day = '2022-10-25';
152722 **
152723 ** **Approximately**. Really, we have to ensure that the FROM-clause term
152724 ** that was formerly inside the EXISTS is only executed once. This is handled
152725 ** by setting the SrcItem.fg.fromExists flag, which then causes code in
152726 ** the where.c file to exit the corresponding loop after the first successful
152727 ** match (if any).
152728 */
152729 static SQLITE_NOINLINE void existsToJoin(
152730 Parse *pParse, /* Parsing context */
152731 Select *p, /* The SELECT statement being optimized */
152732 Expr *pWhere /* part of the WHERE clause currently being examined */
152733 ){
152734 if( pParse->nErr==0
152735 && pWhere!=0
152736 && !ExprHasProperty(pWhere, EP_OuterON|EP_InnerON)
152737 && ALWAYS(p->pSrc!=0)
152738 && p->pSrc->nSrc<BMS
152739 ){
152740 if( pWhere->op==TK_AND ){
152741 Expr *pRight = pWhere->pRight;
152742 existsToJoin(pParse, p, pWhere->pLeft);
152743 existsToJoin(pParse, p, pRight);
152744 }
152745 else if( pWhere->op==TK_EXISTS ){
152746 Select *pSub = pWhere->x.pSelect;
152747 Expr *pSubWhere = pSub->pWhere;
152748 if( pSub->pSrc->nSrc==1
152749 && (pSub->selFlags & SF_Aggregate)==0
152750 && !pSub->pSrc->a[0].fg.isSubquery
152751 ){
152752 memset(pWhere, 0, sizeof(*pWhere));
152753 pWhere->op = TK_INTEGER;
152754 pWhere->u.iValue = 1;
152755 ExprSetProperty(pWhere, EP_IntValue);
152756
152757 assert( p->pWhere!=0 );
152758 pSub->pSrc->a[0].fg.fromExists = 1;
152759 pSub->pSrc->a[0].fg.jointype |= JT_CROSS;
152760 p->pSrc = sqlite3SrcListAppendList(pParse, p->pSrc, pSub->pSrc);
152761 if( pSubWhere ){
152762 p->pWhere = sqlite3PExpr(pParse, TK_AND, p->pWhere, pSubWhere);
152763 pSub->pWhere = 0;
152764 }
152765 pSub->pSrc = 0;
152766 sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pSub);
152767 #if TREETRACE_ENABLED
152768 if( sqlite3TreeTrace & 0x100000 ){
152769 TREETRACE(0x100000,pParse,p,
152770 ("After EXISTS-to-JOIN optimization:\n"));
152771 sqlite3TreeViewSelect(0, p, 0);
152772 }
152773 #endif
152774 existsToJoin(pParse, p, pSubWhere);
152775 }
152776 }
152777 }
152778 }
152779
152780 /*
152781 ** Generate byte-code for the SELECT statement given in the p argument.
152782 **
152783 ** The results are returned according to the SelectDest structure.
@@ -152606,10 +153142,17 @@
153142 #endif
153143 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
153144 return rc;
153145 }
153146 #endif
153147
153148 /* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
153149 ** to change it into a join. */
153150 if( pParse->bHasExists && OptimizationEnabled(db,SQLITE_ExistsToJoin) ){
153151 existsToJoin(pParse, p, p->pWhere);
153152 pTabList = p->pSrc;
153153 }
153154
153155 /* Do the WHERE-clause constant propagation optimization if this is
153156 ** a join. No need to spend time on this operation for non-join queries
153157 ** as the equivalent optimization will be handled by query planner in
153158 ** sqlite3WhereBegin(). tag-select-0330
@@ -153366,10 +153909,14 @@
153909 }
153910
153911 if( iOrderByCol ){
153912 Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
153913 Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
153914 while( ALWAYS(pBase!=0) && pBase->op==TK_IF_NULL_ROW ){
153915 pX = pBase->pLeft;
153916 pBase = sqlite3ExprSkipCollateAndLikely(pX);
153917 }
153918 if( ALWAYS(pBase!=0)
153919 && pBase->op!=TK_AGG_COLUMN
153920 && pBase->op!=TK_REGISTER
153921 ){
153922 sqlite3ExprToRegister(pX, iAMem+j);
@@ -153389,24 +153936,24 @@
153936 ** over to a0,a1,a2. It then calls the output subroutine
153937 ** and resets the aggregate accumulator registers in preparation
153938 ** for the next GROUP BY batch.
153939 */
153940 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153941 VdbeComment((v, "output one row of %d", p->selId));
153942 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
153943 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
153944 VdbeComment((v, "check abort flag"));
153945 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
153946 VdbeComment((v, "reset accumulator %d", p->selId));
153947
153948 /* Update the aggregate accumulators based on the content of
153949 ** the current row
153950 */
153951 sqlite3VdbeJumpHere(v, addr1);
153952 updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
153953 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
153954 VdbeComment((v, "indicate data in accumulator %d", p->selId));
153955
153956 /* End of the loop
153957 */
153958 if( groupBySort ){
153959 sqlite3VdbeAddOp2(v, OP_SorterNext, pAggInfo->sortingIdx,addrTopOfLoop);
@@ -153419,11 +153966,11 @@
153966 sqlite3ExprListDelete(db, pDistinct);
153967
153968 /* Output the final row of result
153969 */
153970 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
153971 VdbeComment((v, "output final row of %d", p->selId));
153972
153973 /* Jump over the subroutines
153974 */
153975 sqlite3VdbeGoto(v, addrEnd);
153976
@@ -153440,26 +153987,26 @@
153987 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153988 sqlite3VdbeResolveLabel(v, addrOutputRow);
153989 addrOutputRow = sqlite3VdbeCurrentAddr(v);
153990 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
153991 VdbeCoverage(v);
153992 VdbeComment((v, "Groupby result generator entry point %d", p->selId));
153993 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
153994 finalizeAggFunctions(pParse, pAggInfo);
153995 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
153996 selectInnerLoop(pParse, p, -1, &sSort,
153997 &sDistinct, pDest,
153998 addrOutputRow+1, addrSetAbort);
153999 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
154000 VdbeComment((v, "end groupby result generator %d", p->selId));
154001
154002 /* Generate a subroutine that will reset the group-by accumulator
154003 */
154004 sqlite3VdbeResolveLabel(v, addrReset);
154005 resetAccumulator(pParse, pAggInfo);
154006 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
154007 VdbeComment((v, "indicate accumulator %d empty", p->selId));
154008 sqlite3VdbeAddOp1(v, OP_Return, regReset);
154009
154010 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
154011 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
154012 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
@@ -157343,11 +157890,12 @@
157890 saved_flags = db->flags;
157891 saved_mDbFlags = db->mDbFlags;
157892 saved_nChange = db->nChange;
157893 saved_nTotalChange = db->nTotalChange;
157894 saved_mTrace = db->mTrace;
157895 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments
157896 | SQLITE_AttachCreate | SQLITE_AttachWrite;
157897 db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157898 db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157899 | SQLITE_Defensive | SQLITE_CountRows);
157900 db->mTrace = 0;
157901
@@ -159046,10 +159594,11 @@
159594 struct WhereLevel {
159595 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
159596 int iTabCur; /* The VDBE cursor used to access the table */
159597 int iIdxCur; /* The VDBE cursor used to access pIdx */
159598 int addrBrk; /* Jump here to break out of the loop */
159599 int addrHalt; /* Abort the query due to empty table or similar */
159600 int addrNxt; /* Jump here to start the next IN combination */
159601 int addrSkip; /* Jump here for next iteration of skip-scan */
159602 int addrCont; /* Jump here to continue with the next loop cycle */
159603 int addrFirst; /* First instruction of interior of the loop */
159604 int addrBody; /* Beginning of the body of this loop */
@@ -159251,10 +159800,13 @@
159800 u16 eOperator; /* A WO_xx value describing <op> */
159801 u8 nChild; /* Number of children that must disable us */
159802 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
159803 int iParent; /* Disable pWC->a[iParent] when this term disabled */
159804 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
159805 #ifdef SQLITE_DEBUG
159806 int iTerm; /* Which WhereTerm is this, for debug purposes */
159807 #endif
159808 union {
159809 struct {
159810 int leftColumn; /* Column number of X in "X <op> <expr>" */
159811 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
159812 } x; /* Opcode other than OP_OR or OP_AND */
@@ -159743,11 +160295,10 @@
160295 #if !defined(SQLITE_DEBUG)
160296 if( sqlite3ParseToplevel(pParse)->explain==2 || IS_STMT_SCANSTATUS(pParse->db) )
160297 #endif
160298 {
160299 VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe, addr);
 
160300 SrcItem *pItem = &pTabList->a[pLevel->iFrom];
160301 sqlite3 *db = pParse->db; /* Database handle */
160302 int isSearch; /* True for a SEARCH. False for SCAN. */
160303 WhereLoop *pLoop; /* The controlling WhereLoop object */
160304 u32 flags; /* Flags that describe this loop */
@@ -159766,11 +160317,14 @@
160317 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
160318 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
160319
160320 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
160321 str.printfFlags = SQLITE_PRINTF_INTERNAL;
160322 sqlite3_str_appendf(&str, "%s %S%s",
160323 isSearch ? "SEARCH" : "SCAN",
160324 pItem,
160325 pItem->fg.fromExists ? " EXISTS" : "");
160326 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
160327 const char *zFmt = 0;
160328 Index *pIdx;
160329
160330 assert( pLoop->u.btree.pIndex!=0 );
@@ -160215,11 +160769,13 @@
160769 for(i=iEq; i<pLoop->nLTerm; i++){
160770 if( pLoop->aLTerm[i]->pExpr==pX ){
160771 int iField;
160772 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
160773 iField = pLoop->aLTerm[i]->u.x.iField - 1;
160774 if( NEVER(pOrigRhs->a[iField].pExpr==0) ){
160775 continue; /* Duplicate PK column */
160776 }
160777 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
160778 pOrigRhs->a[iField].pExpr = 0;
160779 if( pRhs ) pRhs->a[pRhs->nExpr-1].u.x.iOrderByCol = iField+1;
160780 if( pOrigLhs ){
160781 assert( pOrigLhs->a[iField].pExpr!=0 );
@@ -160312,35 +160868,26 @@
160868 if( pLoop->aLTerm[i] && pLoop->aLTerm[i]->pExpr==pX ){
160869 disableTerm(pLevel, pTerm);
160870 return;
160871 }
160872 }
160873 for(i=iEq; i<pLoop->nLTerm; i++){
160874 assert( pLoop->aLTerm[i]!=0 );
160875 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
160876 }
160877
160878 iTab = 0;
160879 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
160880 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
160881 }else{
160882 sqlite3 *db = pParse->db;
160883 Expr *pXMod = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
160884 if( !db->mallocFailed ){
160885 aiMap = (int*)sqlite3DbMallocZero(db, sizeof(int)*nEq);
160886 eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
160887 }
160888 sqlite3ExprDelete(db, pXMod);
 
 
 
 
 
 
 
 
 
160889 }
160890
160891 if( eType==IN_INDEX_INDEX_DESC ){
160892 testcase( bRev );
160893 bRev = !bRev;
@@ -160366,11 +160913,11 @@
160913 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
160914 pIn = pLevel->u.in.aInLoop;
160915 if( pIn ){
160916 int iMap = 0; /* Index in aiMap[] */
160917 pIn += i;
160918 for(i=iEq; i<pLoop->nLTerm; i++){
160919 if( pLoop->aLTerm[i]->pExpr==pX ){
160920 int iOut = iTarget + i - iEq;
160921 if( eType==IN_INDEX_ROWID ){
160922 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
160923 }else{
@@ -161017,19 +161564,20 @@
161564 WhereInfo *pWInfo, /* Complete information about the WHERE clause */
161565 int iLevel, /* Which level of pWInfo->a[] should be coded */
161566 int addrNxt, /* Jump here to bypass inner loops */
161567 Bitmask notReady /* Loops that are not ready */
161568 ){
161569 int saved_addrBrk;
161570 while( ++iLevel < pWInfo->nLevel ){
161571 WhereLevel *pLevel = &pWInfo->a[iLevel];
161572 WhereLoop *pLoop = pLevel->pWLoop;
161573 if( pLevel->regFilter==0 ) continue;
161574 if( pLevel->pWLoop->nSkip ) continue;
161575 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
161576 ** vvvvv--' pLevel->regFilter if this were true. */
161577 if( NEVER(pLoop->prereq & notReady) ) continue;
161578 saved_addrBrk = pLevel->addrBrk;
161579 pLevel->addrBrk = addrNxt;
161580 if( pLoop->wsFlags & WHERE_IPK ){
161581 WhereTerm *pTerm = pLoop->aLTerm[0];
161582 int regRowid;
161583 assert( pTerm!=0 );
@@ -161055,11 +161603,11 @@
161603 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
161604 addrNxt, r1, nEq);
161605 VdbeCoverage(pParse->pVdbe);
161606 }
161607 pLevel->regFilter = 0;
161608 pLevel->addrBrk = saved_addrBrk;
161609 }
161610 }
161611
161612 /*
161613 ** Loop pLoop is a WHERE_INDEXED level that uses at least one IN(...)
@@ -161102,11 +161650,10 @@
161650 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
161651 WhereTerm *pTerm; /* A WHERE clause term */
161652 sqlite3 *db; /* Database connection */
161653 SrcItem *pTabItem; /* FROM clause term being coded */
161654 int addrBrk; /* Jump here to break out of the loop */
 
161655 int addrCont; /* Jump here to continue with next cycle */
161656 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
161657 int iReleaseReg = 0; /* Temp register to free before returning */
161658 Index *pIdx = 0; /* Index used by loop (if any) */
161659 int iLoop; /* Iteration of constraint generator loop */
@@ -161146,11 +161693,11 @@
161693 ** When there is an IN operator, we also have a "addrNxt" label that
161694 ** means to continue with the next IN value combination. When
161695 ** there are no IN operators in the constraints, the "addrNxt" label
161696 ** is the same as "addrBrk".
161697 */
161698 addrBrk = pLevel->addrNxt = pLevel->addrBrk;
161699 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
161700
161701 /* If this is the right table of a LEFT OUTER JOIN, allocate and
161702 ** initialize a memory cell that records if this table matches any
161703 ** row of the left table of the join.
@@ -161162,18 +161709,10 @@
161709 pLevel->iLeftJoin = ++pParse->nMem;
161710 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
161711 VdbeComment((v, "init LEFT JOIN match flag"));
161712 }
161713
 
 
 
 
 
 
 
 
161714 /* Special case of a FROM clause subquery implemented as a co-routine */
161715 if( pTabItem->fg.viaCoroutine ){
161716 int regYield;
161717 Subquery *pSubq;
161718 assert( pTabItem->fg.isSubquery && pTabItem->u4.pSubq!=0 );
@@ -161408,11 +161947,11 @@
161947 VdbeCoverageIf(v, pX->op==TK_LE);
161948 VdbeCoverageIf(v, pX->op==TK_LT);
161949 VdbeCoverageIf(v, pX->op==TK_GE);
161950 sqlite3ReleaseTempReg(pParse, rTemp);
161951 }else{
161952 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, pLevel->addrHalt);
161953 VdbeCoverageIf(v, bRev==0);
161954 VdbeCoverageIf(v, bRev!=0);
161955 }
161956 if( pEnd ){
161957 Expr *pX;
@@ -161448,40 +161987,40 @@
161987 VdbeCoverageIf(v, testOp==OP_Ge);
161988 VdbeCoverageIf(v, testOp==OP_Gt);
161989 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
161990 }
161991 }else if( pLoop->wsFlags & WHERE_INDEXED ){
161992 /* Case 4: Search using an index.
161993 **
161994 ** The WHERE clause may contain zero or more equality
161995 ** terms ("==" or "IN" or "IS" operators) that refer to the N
161996 ** left-most columns of the index. It may also contain
161997 ** inequality constraints (>, <, >= or <=) on the indexed
161998 ** column that immediately follows the N equalities. Only
161999 ** the right-most column can be an inequality - the rest must
162000 ** use the "==", "IN", or "IS" operators. For example, if the
162001 ** index is on (x,y,z), then the following clauses are all
162002 ** optimized:
162003 **
162004 ** x=5
162005 ** x=5 AND y=10
162006 ** x=5 AND y<10
162007 ** x=5 AND y>5 AND y<10
162008 ** x=5 AND y=5 AND z<=10
162009 **
162010 ** The z<10 term of the following cannot be used, only
162011 ** the x=5 term:
162012 **
162013 ** x=5 AND z<10
162014 **
162015 ** N may be zero if there are inequality constraints.
162016 ** If there are no inequality constraints, then N is at
162017 ** least one.
162018 **
162019 ** This case is also used when there are no WHERE clause
162020 ** constraints but an index is selected anyway, in order
162021 ** to force the output order to conform to an ORDER BY.
162022 */
162023 static const u8 aStartOp[] = {
162024 0,
162025 0,
162026 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
@@ -161818,16 +162357,17 @@
162357 }
162358
162359 if( pLevel->iLeftJoin==0 ){
162360 /* If a partial index is driving the loop, try to eliminate WHERE clause
162361 ** terms from the query that must be true due to the WHERE clause of
162362 ** the partial index. This optimization does not work on an outer join,
162363 ** as shown by:
162364 **
162365 ** 2019-11-02 ticket 623eff57e76d45f6 (LEFT JOIN)
162366 ** 2025-05-29 forum post 7dee41d32506c4ae (RIGHT JOIN)
162367 */
162368 if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
162369 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
162370 }
162371 }else{
162372 testcase( pIdx->pPartIdxWhere );
162373 /* The following assert() is not a requirement, merely an observation:
@@ -162202,11 +162742,11 @@
162742 pLevel->op = OP_Noop;
162743 }else{
162744 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
162745 pLevel->op = aStep[bRev];
162746 pLevel->p1 = iCur;
162747 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev],iCur,pLevel->addrHalt);
162748 VdbeCoverageIf(v, bRev==0);
162749 VdbeCoverageIf(v, bRev!=0);
162750 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
162751 }
162752 }
@@ -163496,34 +164036,46 @@
164036 ** column references. This routine checks to see if pExpr is an equivalence
164037 ** relation:
164038 ** 1. The SQLITE_Transitive optimization must be enabled
164039 ** 2. Must be either an == or an IS operator
164040 ** 3. Not originating in the ON clause of an OUTER JOIN
164041 ** 4. The operator is not IS or else the query does not contain RIGHT JOIN
164042 ** 5. The affinities of A and B must be compatible
164043 ** 6a. Both operands use the same collating sequence OR
164044 ** 6b. The overall collating sequence is BINARY
164045 ** If this routine returns TRUE, that means that the RHS can be substituted
164046 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
164047 ** This is an optimization. No harm comes from returning 0. But if 1 is
164048 ** returned when it should not be, then incorrect answers might result.
164049 */
164050 static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
164051 char aff1, aff2;
164052 CollSeq *pColl;
164053 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
164054 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
164055 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
164056 assert( pSrc!=0 );
164057 if( pExpr->op==TK_IS
164058 && pSrc->nSrc>=2
164059 && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0
164060 ){
164061 return 0; /* (4) */
164062 }
164063 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
164064 aff2 = sqlite3ExprAffinity(pExpr->pRight);
164065 if( aff1!=aff2
164066 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
164067 ){
164068 return 0; /* (5) */
164069 }
164070 pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
164071 if( !sqlite3IsBinary(pColl)
164072 && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
164073 ){
164074 return 0; /* (6) */
164075 }
164076 return 1;
164077 }
164078
164079 /*
164080 ** Recursively walk the expressions of a SELECT statement and generate
164081 ** a bitmask indicating which tables are used in that expression
@@ -163677,10 +164229,13 @@
164229 if( db->mallocFailed ){
164230 return;
164231 }
164232 assert( pWC->nTerm > idxTerm );
164233 pTerm = &pWC->a[idxTerm];
164234 #ifdef SQLITE_DEBUG
164235 pTerm->iTerm = idxTerm;
164236 #endif
164237 pMaskSet = &pWInfo->sMaskSet;
164238 pExpr = pTerm->pExpr;
164239 assert( pExpr!=0 ); /* Because malloc() has not failed */
164240 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE );
164241 pMaskSet->bVarSelect = 0;
@@ -163784,12 +164339,12 @@
164339 pNew = &pWC->a[idxNew];
164340 markTermAsChild(pWC, idxNew, idxTerm);
164341 if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
164342 pTerm = &pWC->a[idxTerm];
164343 pTerm->wtFlags |= TERM_COPIED;
164344 assert( pWInfo->pTabList!=0 );
164345 if( termIsEquivalence(pParse, pDup, pWInfo->pTabList) ){
164346 pTerm->eOperator |= WO_EQUIV;
164347 eExtraOp = WO_EQUIV;
164348 }
164349 }else{
164350 pDup = pExpr;
@@ -164091,11 +164646,11 @@
164646 pNewExpr->w.iJoin = pExpr->w.iJoin;
164647 }
164648 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
164649 testcase( idxNew==0 );
164650 pNewTerm = &pWC->a[idxNew];
164651 pNewTerm->prereqRight = prereqExpr | extraRight;
164652 pNewTerm->leftCursor = pLeft->iTable;
164653 pNewTerm->u.x.leftColumn = pLeft->iColumn;
164654 pNewTerm->eOperator = WO_AUX;
164655 pNewTerm->eMatchOp = eOp2;
164656 markTermAsChild(pWC, idxNew, idxTerm);
@@ -164202,11 +164757,11 @@
164757 ** SELECT statement passed as the second argument. These terms are only
164758 ** added if:
164759 **
164760 ** 1. The SELECT statement has a LIMIT clause, and
164761 ** 2. The SELECT statement is not an aggregate or DISTINCT query, and
164762 ** 3. The SELECT statement has exactly one object in its FROM clause, and
164763 ** that object is a virtual table, and
164764 ** 4. There are no terms in the WHERE clause that will not be passed
164765 ** to the virtual table xBestIndex method.
164766 ** 5. The ORDER BY clause, if any, will be made available to the xBestIndex
164767 ** method.
@@ -164239,12 +164794,26 @@
164794 ** pWC->a[] array. So this term can be ignored, as a LIMIT clause
164795 ** will only be added if each of the child terms passes the
164796 ** (leftCursor==iCsr) test below. */
164797 continue;
164798 }
164799 if( pWC->a[ii].leftCursor==iCsr && pWC->a[ii].prereqRight==0 ) continue;
164800
164801 /* If this term has a parent with exactly one child, and the parent will
164802 ** be passed through to xBestIndex, then this term can be ignored. */
164803 if( pWC->a[ii].iParent>=0 ){
164804 WhereTerm *pParent = &pWC->a[ pWC->a[ii].iParent ];
164805 if( pParent->leftCursor==iCsr
164806 && pParent->prereqRight==0
164807 && pParent->nChild==1
164808 ){
164809 continue;
164810 }
164811 }
164812
164813 /* This term will not be passed through. Do not add a LIMIT clause. */
164814 return;
164815 }
164816
164817 /* Check condition (5). Return early if it is not met. */
164818 if( pOrderBy ){
164819 for(ii=0; ii<pOrderBy->nExpr; ii++){
@@ -164904,15 +165473,15 @@
165473 continue;
165474 }
165475 pScan->pWC = pWC;
165476 pScan->k = k+1;
165477 #ifdef WHERETRACE_ENABLED
165478 if( (sqlite3WhereTrace & 0x20000)!=0 && pScan->nEquiv>1 ){
165479 int ii;
165480 sqlite3DebugPrintf("EQUIVALENT TO {%d:%d} (due to TERM-%d):",
165481 pScan->aiCur[0], pScan->aiColumn[0], pTerm->iTerm);
165482 for(ii=1; ii<pScan->nEquiv; ii++){
165483 sqlite3DebugPrintf(" {%d:%d}",
165484 pScan->aiCur[ii], pScan->aiColumn[ii]);
165485 }
165486 sqlite3DebugPrintf("\n");
165487 }
@@ -165679,11 +166248,13 @@
166248 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pSubq->addrFillSub);
166249 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
166250 VdbeCoverage(v);
166251 VdbeComment((v, "next row of %s", pSrc->pSTab->zName));
166252 }else{
166253 assert( pLevel->addrHalt );
166254 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind,pLevel->iTabCur,pLevel->addrHalt);
166255 VdbeCoverage(v);
166256 }
166257 if( pPartial ){
166258 iContinue = sqlite3VdbeMakeLabel(pParse);
166259 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
166260 pLoop->wsFlags |= WHERE_PARTIALIDX;
@@ -165707,15 +166278,18 @@
166278 assert( pLevel->iIdxCur>0 );
166279 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
166280 pSrc->u4.pSubq->regResult, pLevel->iIdxCur);
166281 sqlite3VdbeGoto(v, addrTop);
166282 pSrc->fg.viaCoroutine = 0;
166283 sqlite3VdbeJumpHere(v, addrTop);
166284 }else{
166285 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
166286 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
166287 if( (pSrc->fg.jointype & JT_LEFT)!=0 ){
166288 sqlite3VdbeJumpHere(v, addrTop);
166289 }
166290 }
 
166291 sqlite3ReleaseTempReg(pParse, regRecord);
166292
166293 /* Jump here when skipping the initialization */
166294 sqlite3VdbeJumpHere(v, addrInit);
166295 sqlite3VdbeScanStatusRange(v, addrExp, addrExp, -1);
@@ -166863,10 +167437,11 @@
167437 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
167438 pTerm->u.pOrInfo->indexable);
167439 }else{
167440 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);
167441 }
167442 iTerm = pTerm->iTerm = MAX(iTerm,pTerm->iTerm);
167443 sqlite3DebugPrintf(
167444 "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x",
167445 iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags);
167446 /* The 0x10000 .wheretrace flag causes extra information to be
167447 ** shown about each Term */
@@ -167637,15 +168212,12 @@
168212 opMask = WO_LT|WO_LE;
168213 }else{
168214 assert( pNew->u.btree.nBtm==0 );
168215 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
168216 }
168217 if( pProbe->bUnordered ){
168218 opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
 
 
 
168219 }
168220
168221 assert( pNew->u.btree.nEq<pProbe->nColumn );
168222 assert( pNew->u.btree.nEq<pProbe->nKeyCol
168223 || pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY );
@@ -167714,19 +168286,33 @@
168286 if( eOp & WO_IN ){
168287 Expr *pExpr = pTerm->pExpr;
168288 if( ExprUseXSelect(pExpr) ){
168289 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
168290 int i;
168291 int bRedundant = 0;
168292 nIn = 46; assert( 46==sqlite3LogEst(25) );
168293
168294 /* The expression may actually be of the form (x, y) IN (SELECT...).
168295 ** In this case there is a separate term for each of (x) and (y).
168296 ** However, the nIn multiplier should only be applied once, not once
168297 ** for each such term. The following loop checks that pTerm is the
168298 ** first such term in use, and sets nIn back to 0 if it is not. */
168299 for(i=0; i<pNew->nLTerm-1; i++){
168300 if( pNew->aLTerm[i] && pNew->aLTerm[i]->pExpr==pExpr ){
168301 nIn = 0;
168302 if( pNew->aLTerm[i]->u.x.iField == pTerm->u.x.iField ){
168303 /* Detect when two or more columns of an index match the same
168304 ** column of a vector IN operater, and avoid adding the column
168305 ** to the WhereLoop more than once. See tag-20250707-01
168306 ** in test/rowvalue.test */
168307 bRedundant = 1;
168308 }
168309 }
168310 }
168311 if( bRedundant ){
168312 pNew->nLTerm--;
168313 continue;
168314 }
168315 }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
168316 /* "x IN (value, value, ...)" */
168317 nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
168318 }
@@ -167954,11 +168540,11 @@
168540 }
168541
168542 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
168543 && pNew->u.btree.nEq<pProbe->nColumn
168544 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
168545 pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
168546 ){
168547 if( pNew->u.btree.nEq>3 ){
168548 sqlite3ProgressCheck(pParse);
168549 }
168550 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -167993,10 +168579,11 @@
168579 && saved_nEq==pNew->nLTerm
168580 && pProbe->noSkipScan==0
168581 && pProbe->hasStat1!=0
168582 && OptimizationEnabled(db, SQLITE_SkipScan)
168583 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
168584 && pSrc->fg.fromExists==0
168585 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
168586 ){
168587 LogEst nIter;
168588 pNew->u.btree.nEq++;
168589 pNew->nSkip++;
@@ -168083,10 +168670,11 @@
168670 Expr *pExpr;
168671 pExpr = pTerm->pExpr;
168672 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
168673 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
168674 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
168675 && !sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, -1)
168676 && (pTerm->wtFlags & TERM_VNULL)==0
168677 ){
168678 return 1;
168679 }
168680 }
@@ -168578,11 +169166,11 @@
169166 }
169167 }else if( m==0
169168 && (HasRowid(pTab) || pWInfo->pSelect!=0 || sqlite3FaultSim(700))
169169 ){
169170 WHERETRACE(0x200,
169171 ("-> %s is a covering index according to bitmasks\n",
169172 pProbe->zName, m==0 ? "is" : "is not"));
169173 pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
169174 }
169175 }
169176
@@ -171549,10 +172137,18 @@
172137
172138 pTabItem = &pTabList->a[pLevel->iFrom];
172139 pTab = pTabItem->pSTab;
172140 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
172141 pLoop = pLevel->pWLoop;
172142 pLevel->addrBrk = sqlite3VdbeMakeLabel(pParse);
172143 if( ii==0 || (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
172144 pLevel->addrHalt = pLevel->addrBrk;
172145 }else if( pWInfo->a[ii-1].pRJ ){
172146 pLevel->addrHalt = pWInfo->a[ii-1].addrBrk;
172147 }else{
172148 pLevel->addrHalt = pWInfo->a[ii-1].addrHalt;
172149 }
172150 if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){
172151 /* Do nothing */
172152 }else
172153 #ifndef SQLITE_OMIT_VIRTUALTABLE
172154 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -171600,10 +172196,17 @@
172196 }
172197 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
172198 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
172199 (const u8*)&pTabItem->colUsed, P4_INT64);
172200 #endif
172201 if( ii>=2
172202 && (pTabItem[0].fg.jointype & (JT_LTORJ|JT_LEFT))==0
172203 && pLevel->addrHalt==pWInfo->a[0].addrHalt
172204 ){
172205 sqlite3VdbeAddOp2(v, OP_IfEmpty, pTabItem->iCursor, pWInfo->iBreak);
172206 VdbeCoverage(v);
172207 }
172208 }else{
172209 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
172210 }
172211 if( pLoop->wsFlags & WHERE_INDEXED ){
172212 Index *pIx = pLoop->u.btree.pIndex;
@@ -171856,10 +172459,13 @@
172459 VdbeCoverageIf(v, op==OP_SeekLT);
172460 VdbeCoverageIf(v, op==OP_SeekGT);
172461 sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
172462 }
172463 #endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
172464 if( pTabList->a[pLevel->iFrom].fg.fromExists ){
172465 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
172466 }
172467 /* The common case: Advance to the next row */
172468 if( pLevel->addrCont ) sqlite3VdbeResolveLabel(v, pLevel->addrCont);
172469 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
172470 sqlite3VdbeChangeP5(v, pLevel->p5);
172471 VdbeCoverage(v);
@@ -179928,16 +180534,25 @@
180534 /* Expressions of the form
180535 **
180536 ** expr1 IN ()
180537 ** expr1 NOT IN ()
180538 **
180539 ** simplify to constants 0 (false) and 1 (true), respectively.
180540 **
180541 ** Except, do not apply this optimization if expr1 contains a function
180542 ** because that function might be an aggregate (we don't know yet whether
180543 ** it is or not) and if it is an aggregate, that could change the meaning
180544 ** of the whole query.
180545 */
180546 Expr *pB = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy502 ? "true" : "false");
180547 if( pB ) sqlite3ExprIdToTrueFalse(pB);
180548 if( !ExprHasProperty(yymsp[-4].minor.yy590, EP_HasFunc) ){
180549 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy590);
180550 yymsp[-4].minor.yy590 = pB;
180551 }else{
180552 yymsp[-4].minor.yy590 = sqlite3PExpr(pParse, yymsp[-3].minor.yy502 ? TK_OR : TK_AND, pB, yymsp[-4].minor.yy590);
180553 }
180554 }else{
180555 Expr *pRHS = yymsp[-1].minor.yy402->a[0].pExpr;
180556 if( yymsp[-1].minor.yy402->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && yymsp[-4].minor.yy590->op!=TK_VECTOR ){
180557 yymsp[-1].minor.yy402->a[0].pExpr = 0;
180558 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy402);
@@ -181539,11 +182154,11 @@
182154 static int getToken(const unsigned char **pz){
182155 const unsigned char *z = *pz;
182156 int t; /* Token type to return */
182157 do {
182158 z += sqlite3GetToken(z, &t);
182159 }while( t==TK_SPACE || t==TK_COMMENT );
182160 if( t==TK_ID
182161 || t==TK_STRING
182162 || t==TK_JOIN_KW
182163 || t==TK_WINDOW
182164 || t==TK_OVER
@@ -184489,10 +185104,11 @@
185104 #ifdef SQLITE_ENABLE_API_ARMOR
185105 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
185106 #endif
185107 if( ms<-1 ) return SQLITE_RANGE;
185108 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
185109 sqlite3_mutex_enter(db->mutex);
185110 db->setlkTimeout = ms;
185111 db->setlkFlags = flags;
185112 sqlite3BtreeEnterAll(db);
185113 for(iDb=0; iDb<db->nDb; iDb++){
185114 Btree *pBt = db->aDb[iDb].pBt;
@@ -184500,10 +185116,11 @@
185116 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
185117 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
185118 }
185119 }
185120 sqlite3BtreeLeaveAll(db);
185121 sqlite3_mutex_leave(db->mutex);
185122 #endif
185123 #if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT)
185124 UNUSED_PARAMETER(db);
185125 UNUSED_PARAMETER(flags);
185126 #endif
@@ -188886,11 +189503,11 @@
189503
189504 /*
189505 ** Macros needed to provide flexible arrays in a portable way
189506 */
189507 #ifndef offsetof
189508 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
189509 #endif
189510 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
189511 # define FLEXARRAY
189512 #else
189513 # define FLEXARRAY 1
@@ -209119,12 +209736,14 @@
209736 nExtra = 0;
209737 }else if( szType==12 ){
209738 nExtra = 1;
209739 }else if( szType==13 ){
209740 nExtra = 2;
209741 }else if( szType==14 ){
209742 nExtra = 4;
209743 }else{
209744 nExtra = 8;
209745 }
209746 if( szPayload<=11 ){
209747 nNeeded = 0;
209748 }else if( szPayload<=0xff ){
209749 nNeeded = 1;
@@ -209590,11 +210209,16 @@
210209 c = z[++j];
210210 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
210211 || c=='n' || c=='r' || c=='t'
210212 || (c=='u' && jsonIs4Hex(&z[j+1])) ){
210213 if( opcode==JSONB_TEXT ) opcode = JSONB_TEXTJ;
210214 }else if( c=='\'' || c=='v' || c=='\n'
210215 #ifdef SQLITE_BUG_COMPATIBLE_20250510
210216 || (c=='0') /* Legacy bug compatible */
210217 #else
210218 || (c=='0' && !sqlite3Isdigit(z[j+1])) /* Correct implementation */
210219 #endif
210220 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
210221 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
210222 || (c=='x' && jsonIs2Hex(&z[j+1])) ){
210223 opcode = JSONB_TEXT5;
210224 pParse->hasNonstd = 1;
@@ -209977,11 +210601,11 @@
210601 || pParse->aBlob[i+4]!=0
210602 ){
210603 *pSz = 0;
210604 return 0;
210605 }
210606 sz = ((u32)pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
210607 (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
210608 n = 9;
210609 }
210610 if( (i64)i+sz+n > pParse->nBlob
210611 && (i64)i+sz+n > pParse->nBlob-pParse->delta
@@ -210558,11 +211182,25 @@
211182 case 'f': { *piOut = '\f'; return 2; }
211183 case 'n': { *piOut = '\n'; return 2; }
211184 case 'r': { *piOut = '\r'; return 2; }
211185 case 't': { *piOut = '\t'; return 2; }
211186 case 'v': { *piOut = '\v'; return 2; }
211187 case '0': {
211188 /* JSON5 requires that the \0 escape not be followed by a digit.
211189 ** But SQLite did not enforce this restriction in versions 3.42.0
211190 ** through 3.49.2. That was a bug. But some applications might have
211191 ** come to depend on that bug. Use the SQLITE_BUG_COMPATIBLE_20250510
211192 ** option to restore the old buggy behavior. */
211193 #ifdef SQLITE_BUG_COMPATIBLE_20250510
211194 /* Legacy bug-compatible behavior */
211195 *piOut = 0;
211196 #else
211197 /* Correct behavior */
211198 *piOut = (n>2 && sqlite3Isdigit(z[2])) ? JSON_INVALID_CHAR : 0;
211199 #endif
211200 return 2;
211201 }
211202 case '\'':
211203 case '"':
211204 case '/':
211205 case '\\':{ *piOut = z[1]; return 2; }
211206 case 'x': {
@@ -212665,22 +213303,24 @@
213303 const char *z;
213304 u32 n;
213305 UNUSED_PARAMETER(argc);
213306 pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
213307 if( pStr ){
213308 z = (const char*)sqlite3_value_text(argv[0]);
213309 n = sqlite3Strlen30(z);
213310 if( pStr->zBuf==0 ){
213311 jsonStringInit(pStr, ctx);
213312 jsonAppendChar(pStr, '{');
213313 }else if( pStr->nUsed>1 && z!=0 ){
213314 jsonAppendChar(pStr, ',');
213315 }
213316 pStr->pCtx = ctx;
213317 if( z!=0 ){
213318 jsonAppendString(pStr, z, n);
213319 jsonAppendChar(pStr, ':');
213320 jsonAppendSqlValue(pStr, argv[1]);
213321 }
213322 }
213323 }
213324 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
213325 JsonString *pStr;
213326 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
@@ -213484,10 +214124,12 @@
214124 #else
214125 /* #include "sqlite3.h" */
214126 #endif
214127 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
214128
214129 /* #include <stddef.h> */
214130
214131 /*
214132 ** If building separately, we will need some setup that is normally
214133 ** found in sqliteInt.h
214134 */
214135 #if !defined(SQLITE_AMALGAMATION)
@@ -213515,11 +214157,11 @@
214157 #else
214158 # define ALWAYS(X) (X)
214159 # define NEVER(X) (X)
214160 #endif
214161 #ifndef offsetof
214162 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
214163 #endif
214164 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
214165 # define FLEXARRAY
214166 #else
214167 # define FLEXARRAY 1
@@ -214553,10 +215195,16 @@
215195 pStmt = pCsr->pReadAux;
215196 memset(pCsr, 0, sizeof(RtreeCursor));
215197 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
215198 pCsr->pReadAux = pStmt;
215199
215200 /* The following will only fail if the previous sqlite3_step() call failed,
215201 ** in which case the error has already been caught. This statement never
215202 ** encounters an error within an sqlite3_column_xxx() function, as it
215203 ** calls sqlite3_column_value(), which does not use malloc(). So it is safe
215204 ** to ignore the error code here. */
215205 sqlite3_reset(pStmt);
215206 }
215207
215208 /*
215209 ** Rtree virtual table module xClose method.
215210 */
@@ -227832,11 +228480,12 @@
228480 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
228481 int rc;
228482 sqlite3 *db = pTab->db;
228483 Btree *pBt;
228484
228485 UNUSED_PARAMETER(idxStr);
228486 UNUSED_PARAMETER(argc);
228487
228488 /* Default setting is no rows of result */
228489 pCsr->pgno = 1;
228490 pCsr->mxPgno = 0;
228491
@@ -231494,18 +232143,19 @@
232143 /*
232144 ** If the SessionInput object passed as the only argument is a streaming
232145 ** object and the buffer is full, discard some data to free up space.
232146 */
232147 static void sessionDiscardData(SessionInput *pIn){
232148 if( pIn->xInput && pIn->iCurrent>=sessions_strm_chunk_size ){
232149 int nMove = pIn->buf.nBuf - pIn->iCurrent;
232150 assert( nMove>=0 );
232151 if( nMove>0 ){
232152 memmove(pIn->buf.aBuf, &pIn->buf.aBuf[pIn->iCurrent], nMove);
232153 }
232154 pIn->buf.nBuf -= pIn->iCurrent;
232155 pIn->iNext -= pIn->iCurrent;
232156 pIn->iCurrent = 0;
232157 pIn->nData = pIn->buf.nBuf;
232158 }
232159 }
232160
232161 /*
@@ -231855,12 +232505,12 @@
232505 ** sufficient either for the 'T' or 'P' byte and the varint that follows
232506 ** it, or for the two single byte values otherwise. */
232507 p->rc = sessionInputBuffer(&p->in, 2);
232508 if( p->rc!=SQLITE_OK ) return p->rc;
232509
 
232510 p->in.iCurrent = p->in.iNext;
232511 sessionDiscardData(&p->in);
232512
232513 /* If the iterator is already at the end of the changeset, return DONE. */
232514 if( p->in.iNext>=p->in.nData ){
232515 return SQLITE_DONE;
232516 }
@@ -233279,10 +233929,14 @@
233929 sqlite3_changeset_iter *pIter, /* Changeset to apply */
233930 int(*xFilter)(
233931 void *pCtx, /* Copy of sixth arg to _apply() */
233932 const char *zTab /* Table name */
233933 ),
233934 int(*xFilterIter)(
233935 void *pCtx, /* Copy of sixth arg to _apply() */
233936 sqlite3_changeset_iter *p
233937 ),
233938 int(*xConflict)(
233939 void *pCtx, /* Copy of fifth arg to _apply() */
233940 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
233941 sqlite3_changeset_iter *p /* Handle describing change and conflict */
233942 ),
@@ -233418,10 +234072,13 @@
234072 }
234073
234074 /* If there is a schema mismatch on the current table, proceed to the
234075 ** next change. A log message has already been issued. */
234076 if( schemaMismatch ) continue;
234077
234078 /* If this is a call to apply_v3(), invoke xFilterIter here. */
234079 if( xFilterIter && 0==xFilterIter(pCtx, pIter) ) continue;
234080
234081 rc = sessionApplyOneWithRetry(db, pIter, &sApply, xConflict, pCtx);
234082 }
234083
234084 bPatchset = pIter->bPatchset;
@@ -233485,10 +234142,91 @@
234142 db->aDb[0].pSchema->schema_cookie -= 32;
234143 }
234144 sqlite3_mutex_leave(sqlite3_db_mutex(db));
234145 return rc;
234146 }
234147
234148 /*
234149 ** This function is called by all six sqlite3changeset_apply() variants:
234150 **
234151 ** + sqlite3changeset_apply()
234152 ** + sqlite3changeset_apply_v2()
234153 ** + sqlite3changeset_apply_v3()
234154 ** + sqlite3changeset_apply_strm()
234155 ** + sqlite3changeset_apply_strm_v2()
234156 ** + sqlite3changeset_apply_strm_v3()
234157 **
234158 ** Arguments passed to this function are as follows:
234159 **
234160 ** db:
234161 ** Database handle to apply changeset to main database of.
234162 **
234163 ** nChangeset/pChangeset:
234164 ** These are both passed zero for the streaming variants. For the normal
234165 ** apply() functions, these are passed the size of and the buffer containing
234166 ** the changeset, respectively.
234167 **
234168 ** xInput/pIn:
234169 ** These are both passed zero for the normal variants. For the streaming
234170 ** apply() functions, these are passed the input callback and context
234171 ** pointer, respectively.
234172 **
234173 ** xFilter:
234174 ** The filter function as passed to apply() or apply_v2() (to filter by
234175 ** table name), if any. This is always NULL for apply_v3() calls.
234176 **
234177 ** xFilterIter:
234178 ** The filter function as passed to apply_v3(), if any.
234179 **
234180 ** xConflict:
234181 ** The conflict handler callback (must not be NULL).
234182 **
234183 ** pCtx:
234184 ** The context pointer passed to the xFilter and xConflict handler callbacks.
234185 **
234186 ** ppRebase, pnRebase:
234187 ** Zero for apply(). The rebase changeset output pointers, if any, for
234188 ** apply_v2() and apply_v3().
234189 **
234190 ** flags:
234191 ** Zero for apply(). The flags parameter for apply_v2() and apply_v3().
234192 */
234193 static int sessionChangesetApplyV23(
234194 sqlite3 *db, /* Apply change to "main" db of this handle */
234195 int nChangeset, /* Size of changeset in bytes */
234196 void *pChangeset, /* Changeset blob */
234197 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234198 void *pIn, /* First arg for xInput */
234199 int(*xFilter)(
234200 void *pCtx, /* Copy of sixth arg to _apply() */
234201 const char *zTab /* Table name */
234202 ),
234203 int(*xFilterIter)(
234204 void *pCtx, /* Copy of sixth arg to _apply() */
234205 sqlite3_changeset_iter *p /* Handle describing current change */
234206 ),
234207 int(*xConflict)(
234208 void *pCtx, /* Copy of sixth arg to _apply() */
234209 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234210 sqlite3_changeset_iter *p /* Handle describing change and conflict */
234211 ),
234212 void *pCtx, /* First argument passed to xConflict */
234213 void **ppRebase, int *pnRebase,
234214 int flags
234215 ){
234216 sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
234217 int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
234218 int rc = sessionChangesetStart(
234219 &pIter, xInput, pIn, nChangeset, pChangeset, bInverse, 1
234220 );
234221 if( rc==SQLITE_OK ){
234222 rc = sessionChangesetApply(db, pIter,
234223 xFilter, xFilterIter, xConflict, pCtx, ppRebase, pnRebase, flags
234224 );
234225 }
234226 return rc;
234227 }
234228
234229 /*
234230 ** Apply the changeset passed via pChangeset/nChangeset to the main
234231 ** database attached to handle "db".
234232 */
@@ -233507,21 +234245,43 @@
234245 ),
234246 void *pCtx, /* First argument passed to xConflict */
234247 void **ppRebase, int *pnRebase,
234248 int flags
234249 ){
234250 return sessionChangesetApplyV23(db,
234251 nChangeset, pChangeset, 0, 0,
234252 xFilter, 0, xConflict, pCtx,
234253 ppRebase, pnRebase, flags
234254 );
234255 }
234256
234257 /*
234258 ** Apply the changeset passed via pChangeset/nChangeset to the main
234259 ** database attached to handle "db".
234260 */
234261 SQLITE_API int sqlite3changeset_apply_v3(
234262 sqlite3 *db, /* Apply change to "main" db of this handle */
234263 int nChangeset, /* Size of changeset in bytes */
234264 void *pChangeset, /* Changeset blob */
234265 int(*xFilter)(
234266 void *pCtx, /* Copy of sixth arg to _apply() */
234267 sqlite3_changeset_iter *p /* Handle describing current change */
234268 ),
234269 int(*xConflict)(
234270 void *pCtx, /* Copy of sixth arg to _apply() */
234271 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234272 sqlite3_changeset_iter *p /* Handle describing change and conflict */
234273 ),
234274 void *pCtx, /* First argument passed to xConflict */
234275 void **ppRebase, int *pnRebase,
234276 int flags
234277 ){
234278 return sessionChangesetApplyV23(db,
234279 nChangeset, pChangeset, 0, 0,
234280 0, xFilter, xConflict, pCtx,
234281 ppRebase, pnRebase, flags
234282 );
234283 }
234284
234285 /*
234286 ** Apply the changeset passed via pChangeset/nChangeset to the main database
234287 ** attached to handle "db". Invoke the supplied conflict handler callback
@@ -233540,20 +234300,45 @@
234300 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234301 sqlite3_changeset_iter *p /* Handle describing change and conflict */
234302 ),
234303 void *pCtx /* First argument passed to xConflict */
234304 ){
234305 return sessionChangesetApplyV23(db,
234306 nChangeset, pChangeset, 0, 0,
234307 xFilter, 0, xConflict, pCtx,
234308 0, 0, 0
234309 );
234310 }
234311
234312 /*
234313 ** Apply the changeset passed via xInput/pIn to the main database
234314 ** attached to handle "db". Invoke the supplied conflict handler callback
234315 ** to resolve any conflicts encountered while applying the change.
234316 */
234317 SQLITE_API int sqlite3changeset_apply_v3_strm(
234318 sqlite3 *db, /* Apply change to "main" db of this handle */
234319 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234320 void *pIn, /* First arg for xInput */
234321 int(*xFilter)(
234322 void *pCtx, /* Copy of sixth arg to _apply() */
234323 sqlite3_changeset_iter *p
234324 ),
234325 int(*xConflict)(
234326 void *pCtx, /* Copy of sixth arg to _apply() */
234327 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234328 sqlite3_changeset_iter *p /* Handle describing change and conflict */
234329 ),
234330 void *pCtx, /* First argument passed to xConflict */
234331 void **ppRebase, int *pnRebase,
234332 int flags
234333 ){
234334 return sessionChangesetApplyV23(db,
234335 0, 0, xInput, pIn,
234336 0, xFilter, xConflict, pCtx,
234337 ppRebase, pnRebase, flags
234338 );
234339 }
234340 SQLITE_API int sqlite3changeset_apply_v2_strm(
234341 sqlite3 *db, /* Apply change to "main" db of this handle */
234342 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234343 void *pIn, /* First arg for xInput */
234344 int(*xFilter)(
@@ -233567,19 +234352,15 @@
234352 ),
234353 void *pCtx, /* First argument passed to xConflict */
234354 void **ppRebase, int *pnRebase,
234355 int flags
234356 ){
234357 return sessionChangesetApplyV23(db,
234358 0, 0, xInput, pIn,
234359 xFilter, 0, xConflict, pCtx,
234360 ppRebase, pnRebase, flags
234361 );
 
 
 
 
234362 }
234363 SQLITE_API int sqlite3changeset_apply_strm(
234364 sqlite3 *db, /* Apply change to "main" db of this handle */
234365 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
234366 void *pIn, /* First arg for xInput */
@@ -233592,12 +234373,14 @@
234373 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
234374 sqlite3_changeset_iter *p /* Handle describing change and conflict */
234375 ),
234376 void *pCtx /* First argument passed to xConflict */
234377 ){
234378 return sessionChangesetApplyV23(db,
234379 0, 0, xInput, pIn,
234380 xFilter, 0, xConflict, pCtx,
234381 0, 0, 0
234382 );
234383 }
234384
234385 /*
234386 ** sqlite3_changegroup handle.
@@ -234215,18 +234998,23 @@
234998 */
234999 SQLITE_API int sqlite3changegroup_add_change(
235000 sqlite3_changegroup *pGrp,
235001 sqlite3_changeset_iter *pIter
235002 ){
235003 int rc = SQLITE_OK;
235004
235005 if( pIter->in.iCurrent==pIter->in.iNext
235006 || pIter->rc!=SQLITE_OK
235007 || pIter->bInvert
235008 ){
235009 /* Iterator does not point to any valid entry or is an INVERT iterator. */
235010 rc = SQLITE_ERROR;
235011 }else{
235012 pIter->in.bNoDiscard = 1;
235013 rc = sessionOneChangeToHash(pGrp, pIter, 0);
235014 }
235015 return rc;
235016 }
235017
235018 /*
235019 ** Obtain a buffer containing a changeset representing the concatenation
235020 ** of all changesets added to the group so far.
@@ -235520,10 +236308,11 @@
236308 /* #include "sqlite3ext.h" */
236309 SQLITE_EXTENSION_INIT1
236310
236311 /* #include <string.h> */
236312 /* #include <assert.h> */
236313 /* #include <stddef.h> */
236314
236315 #ifndef SQLITE_AMALGAMATION
236316
236317 typedef unsigned char u8;
236318 typedef unsigned int u32;
@@ -235579,11 +236368,11 @@
236368
236369 /*
236370 ** Macros needed to provide flexible arrays in a portable way
236371 */
236372 #ifndef offsetof
236373 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
236374 #endif
236375 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
236376 # define FLEXARRAY
236377 #else
236378 # define FLEXARRAY 1
@@ -244763,10 +245552,40 @@
245552 Fts5Buffer term; /* Current term */
245553 i64 iRowid; /* Current rowid */
245554 int nPos; /* Number of bytes in current position list */
245555 u8 bDel; /* True if the delete flag is set */
245556 };
245557
245558 static int fts5IndexCorruptRowid(Fts5Index *pIdx, i64 iRowid){
245559 pIdx->rc = FTS5_CORRUPT;
245560 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245561 "fts5: corruption found reading blob %lld from table \"%s\"",
245562 iRowid, pIdx->pConfig->zName
245563 );
245564 return SQLITE_CORRUPT_VTAB;
245565 }
245566 #define FTS5_CORRUPT_ROWID(pIdx, iRowid) fts5IndexCorruptRowid(pIdx, iRowid)
245567
245568 static int fts5IndexCorruptIter(Fts5Index *pIdx, Fts5SegIter *pIter){
245569 pIdx->rc = FTS5_CORRUPT;
245570 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245571 "fts5: corruption on page %d, segment %d, table \"%s\"",
245572 pIter->iLeafPgno, pIter->pSeg->iSegid, pIdx->pConfig->zName
245573 );
245574 return SQLITE_CORRUPT_VTAB;
245575 }
245576 #define FTS5_CORRUPT_ITER(pIdx, pIter) fts5IndexCorruptIter(pIdx, pIter)
245577
245578 static int fts5IndexCorruptIdx(Fts5Index *pIdx){
245579 pIdx->rc = FTS5_CORRUPT;
245580 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
245581 "fts5: corruption in table \"%s\"", pIdx->pConfig->zName
245582 );
245583 return SQLITE_CORRUPT_VTAB;
245584 }
245585 #define FTS5_CORRUPT_IDX(pIdx) fts5IndexCorruptIdx(pIdx)
245586
245587
245588 /*
245589 ** Array of tombstone pages. Reference counted.
245590 */
245591 struct Fts5TombstoneArray {
@@ -245053,11 +245872,11 @@
245872 /* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245873 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245874 ** All the reasons those functions might return SQLITE_ERROR - missing
245875 ** table, missing row, non-blob/text in block column - indicate
245876 ** backing store corruption. */
245877 if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT_ROWID(p, iRowid);
245878
245879 if( rc==SQLITE_OK ){
245880 u8 *aOut = 0; /* Read blob data into this buffer */
245881 int nByte = sqlite3_blob_bytes(p->pReader);
245882 int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245103,11 +245922,11 @@
245922
245923 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245924 Fts5Data *pRet = fts5DataRead(p, iRowid);
245925 if( pRet ){
245926 if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245927 FTS5_CORRUPT_ROWID(p, iRowid);
245928 fts5DataRelease(pRet);
245929 pRet = 0;
245930 }
245931 }
245932 return pRet;
@@ -245462,12 +246281,18 @@
246281 pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
246282 if( p->rc==SQLITE_OK ){
246283 /* TODO: Do we need this if the leaf-index is appended? Probably... */
246284 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
246285 p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
246286 if( p->rc==SQLITE_OK ){
246287 if( (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
246288 p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
246289 }
246290 }else if( p->rc==SQLITE_CORRUPT_VTAB ){
246291 sqlite3Fts5ConfigErrmsg(p->pConfig,
246292 "fts5: corrupt structure record for table \"%s\"", p->pConfig->zName
246293 );
246294 }
246295 fts5DataRelease(pData);
246296 if( p->rc!=SQLITE_OK ){
246297 fts5StructureRelease(pRet);
246298 pRet = 0;
@@ -246086,11 +246911,11 @@
246911
246912 ASSERT_SZLEAF_OK(pIter->pLeaf);
246913 while( iOff>=pIter->pLeaf->szLeaf ){
246914 fts5SegIterNextPage(p, pIter);
246915 if( pIter->pLeaf==0 ){
246916 if( p->rc==SQLITE_OK ) FTS5_CORRUPT_ITER(p, pIter);
246917 return;
246918 }
246919 iOff = 4;
246920 a = pIter->pLeaf->p;
246921 }
@@ -246118,11 +246943,11 @@
246943 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246944 int nNew; /* Bytes of new data */
246945
246946 iOff += fts5GetVarint32(&a[iOff], nNew);
246947 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246948 FTS5_CORRUPT_ITER(p, pIter);
246949 return;
246950 }
246951 pIter->term.n = nKeep;
246952 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246953 assert( pIter->term.n<=pIter->term.nSpace );
@@ -246160,13 +246985,13 @@
246985 ** Allocate a tombstone hash page array object (pIter->pTombArray) for
246986 ** the iterator passed as the second argument. If an OOM error occurs,
246987 ** leave an error in the Fts5Index object.
246988 */
246989 static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
246990 const i64 nTomb = (i64)pIter->pSeg->nPgTombstone;
246991 if( nTomb>0 ){
246992 i64 nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
246993 Fts5TombstoneArray *pNew;
246994 pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
246995 if( pNew ){
246996 pNew->nTombstone = nTomb;
246997 pNew->nRef = 1;
@@ -246313,11 +247138,11 @@
247138 }else{
247139 int iRowidOff;
247140 iRowidOff = fts5LeafFirstRowidOff(pNew);
247141 if( iRowidOff ){
247142 if( iRowidOff>=pNew->szLeaf ){
247143 FTS5_CORRUPT_ITER(p, pIter);
247144 }else{
247145 pIter->pLeaf = pNew;
247146 pIter->iLeafOffset = iRowidOff;
247147 }
247148 }
@@ -246547,11 +247372,11 @@
247372 pIter->iEndofDoclist = iOff;
247373 bNewTerm = 1;
247374 }
247375 assert_nc( iOff<pLeaf->szLeaf );
247376 if( iOff>pLeaf->szLeaf ){
247377 FTS5_CORRUPT_ITER(p, pIter);
247378 return;
247379 }
247380 }
247381 }
247382
@@ -246655,22 +247480,24 @@
247480 if( pLast ){
247481 int iOff;
247482 fts5DataRelease(pIter->pLeaf);
247483 pIter->pLeaf = pLast;
247484 pIter->iLeafPgno = pgnoLast;
247485 if( p->rc==SQLITE_OK ){
247486 iOff = fts5LeafFirstRowidOff(pLast);
247487 if( iOff>pLast->szLeaf ){
247488 FTS5_CORRUPT_ITER(p, pIter);
247489 return;
247490 }
247491 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
247492 pIter->iLeafOffset = iOff;
247493
247494 if( fts5LeafIsTermless(pLast) ){
247495 pIter->iEndofDoclist = pLast->nn+1;
247496 }else{
247497 pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
247498 }
247499 }
247500 }
247501
247502 fts5SegIterReverseInitPage(p, pIter);
247503 }
@@ -246736,11 +247563,11 @@
247563
247564 iPgidx = (u32)pIter->pLeaf->szLeaf;
247565 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
247566 iOff = iTermOff;
247567 if( iOff>n ){
247568 FTS5_CORRUPT_ITER(p, pIter);
247569 return;
247570 }
247571
247572 while( 1 ){
247573
@@ -246779,11 +247606,11 @@
247606 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
247607 iTermOff += nKeep;
247608 iOff = iTermOff;
247609
247610 if( iOff>=n ){
247611 FTS5_CORRUPT_ITER(p, pIter);
247612 return;
247613 }
247614
247615 /* Read the nKeep field of the next term. */
247616 fts5FastGetVarint32(a, iOff, nKeep);
@@ -246801,11 +247628,11 @@
247628 a = pIter->pLeaf->p;
247629 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
247630 iPgidx = (u32)pIter->pLeaf->szLeaf;
247631 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
247632 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
247633 FTS5_CORRUPT_ITER(p, pIter);
247634 return;
247635 }else{
247636 nKeep = 0;
247637 iTermOff = iOff;
247638 n = (u32)pIter->pLeaf->nn;
@@ -246816,11 +247643,11 @@
247643 }while( 1 );
247644 }
247645
247646 search_success:
247647 if( (i64)iOff+nNew>n || nNew<1 ){
247648 FTS5_CORRUPT_ITER(p, pIter);
247649 return;
247650 }
247651 pIter->iLeafOffset = iOff + nNew;
247652 pIter->iTermLeafOffset = pIter->iLeafOffset;
247653 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247281,11 +248108,11 @@
248108 int iLeafPgno
248109 ){
248110 assert( iLeafPgno>pIter->iLeafPgno );
248111
248112 if( iLeafPgno>pIter->pSeg->pgnoLast ){
248113 FTS5_CORRUPT_IDX(p);
248114 }else{
248115 fts5DataRelease(pIter->pNextLeaf);
248116 pIter->pNextLeaf = 0;
248117 pIter->iLeafPgno = iLeafPgno-1;
248118
@@ -247296,11 +248123,11 @@
248123 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
248124 if( iOff>0 ){
248125 u8 *a = pIter->pLeaf->p;
248126 int n = pIter->pLeaf->szLeaf;
248127 if( iOff<4 || iOff>=n ){
248128 FTS5_CORRUPT_IDX(p);
248129 }else{
248130 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
248131 pIter->iLeafOffset = iOff;
248132 fts5SegIterLoadNPos(p, pIter);
248133 }
@@ -247775,11 +248602,11 @@
248602 nRem -= nChunk;
248603 fts5DataRelease(pData);
248604 if( nRem<=0 ){
248605 break;
248606 }else if( pSeg->pSeg==0 ){
248607 FTS5_CORRUPT_IDX(p);
248608 return;
248609 }else{
248610 pgno++;
248611 pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
248612 if( pData==0 ) break;
@@ -248878,11 +249705,11 @@
249705 if( iOff>pData->szLeaf ){
249706 /* This can occur if the pages that the segments occupy overlap - if
249707 ** a single page has been assigned to more than one segment. In
249708 ** this case a prior iteration of this loop may have corrupted the
249709 ** segment currently being trimmed. */
249710 FTS5_CORRUPT_ROWID(p, iLeafRowid);
249711 }else{
249712 fts5BufferZero(&buf);
249713 fts5BufferGrow(&p->rc, &buf, pData->nn);
249714 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
249715 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249345,11 +250172,11 @@
250172 fts5DataRelease(pLeaf);
250173 pLeaf = 0;
250174 }else if( bDetailNone ){
250175 break;
250176 }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
250177 FTS5_CORRUPT_ROWID(p, iRowid);
250178 break;
250179 }else{
250180 int nShift = iNext - 4;
250181 int nPg;
250182
@@ -249365,11 +250192,11 @@
250192 int i1 = pLeaf->szLeaf;
250193 int i2 = 0;
250194
250195 i1 += fts5GetVarint32(&aPg[i1], iFirst);
250196 if( iFirst<iNext ){
250197 FTS5_CORRUPT_ROWID(p, iRowid);
250198 break;
250199 }
250200 aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
250201 if( aIdx==0 ) break;
250202 i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249588,18 +250415,18 @@
250415
250416 nPrefix = MIN(nPrefix, nPrefix2);
250417 nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
250418
250419 if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
250420 FTS5_CORRUPT_IDX(p);
250421 }else{
250422 if( iKey!=1 ){
250423 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
250424 }
250425 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
250426 if( nPrefix2>pSeg->term.n ){
250427 FTS5_CORRUPT_IDX(p);
250428 }else if( nPrefix2>nPrefix ){
250429 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
250430 iOff += (nPrefix2-nPrefix);
250431 }
250432 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250019,11 +250846,11 @@
250846 }
250847 assert( pStruct->aLevel[i].nMerge<=nThis );
250848 }
250849
250850 nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
250851 assert( nByte==(i64)SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
250852 pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
250853
250854 if( pNew ){
250855 Fts5StructureLevel *pLvl;
250856 nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -250388,11 +251215,11 @@
251215 fts5PrefixMergerInsertByPosition(&pHead, pSave);
251216 pSave = pNext;
251217 }
251218
251219 if( pHead==0 || pHead->pNext==0 ){
251220 FTS5_CORRUPT_IDX(p);
251221 break;
251222 }
251223
251224 /* See the earlier comment in this function for an explanation of why
251225 ** corrupt input position lists might cause the output to consume
@@ -250425,11 +251252,11 @@
251252
251253 /* WRITEPOSLISTSIZE */
251254 assert_nc( tmp.n+nTail<=nTmp );
251255 assert( tmp.n+nTail<=nTmp+nMerge*10 );
251256 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
251257 if( p->rc==SQLITE_OK ) FTS5_CORRUPT_IDX(p);
251258 break;
251259 }
251260 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
251261 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
251262 if( nTail>0 ){
@@ -252458,23 +253285,31 @@
253285 }
253286
253287 /*
253288 ** This function is also purely an internal test. It does not contribute to
253289 ** FTS functionality, or even the integrity-check, in any way.
253290 **
253291 ** This function sets output variable (*pbFail) to true if the test fails. Or
253292 ** leaves it unchanged if the test succeeds.
253293 */
253294 static void fts5TestTerm(
253295 Fts5Index *p,
253296 Fts5Buffer *pPrev, /* Previous term */
253297 const char *z, int n, /* Possibly new term to test */
253298 u64 expected,
253299 u64 *pCksum,
253300 int *pbFail
253301 ){
253302 int rc = p->rc;
253303 if( pPrev->n==0 ){
253304 fts5BufferSet(&rc, pPrev, n, (const u8*)z);
253305 }else
253306 if( *pbFail==0
253307 && rc==SQLITE_OK
253308 && (pPrev->n!=n || memcmp(pPrev->p, z, n))
253309 && (p->pHash==0 || p->pHash->nEntry==0)
253310 ){
253311 u64 cksum3 = *pCksum;
253312 const char *zTerm = (const char*)&pPrev->p[1]; /* term sans prefix-byte */
253313 int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
253314 int iIdx = (pPrev->p[0] - FTS5_MAIN_PREFIX);
253315 int flags = (iIdx==0 ? 0 : FTS5INDEX_QUERY_PREFIX);
@@ -252520,20 +253355,20 @@
253355
253356 cksum3 ^= ck1;
253357 fts5BufferSet(&rc, pPrev, n, (const u8*)z);
253358
253359 if( rc==SQLITE_OK && cksum3!=expected ){
253360 *pbFail = 1;
253361 }
253362 *pCksum = cksum3;
253363 }
253364 p->rc = rc;
253365 }
253366
253367 #else
253368 # define fts5TestDlidxReverse(x,y,z)
253369 # define fts5TestTerm(t,u,v,w,x,y,z)
253370 #endif
253371
253372 /*
253373 ** Check that:
253374 **
@@ -252554,18 +253389,21 @@
253389 /* Now check that the iter.nEmpty leaves following the current leaf
253390 ** (a) exist and (b) contain no terms. */
253391 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
253392 Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
253393 if( pLeaf ){
253394 if( !fts5LeafIsTermless(pLeaf)
253395 || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
253396 ){
253397 FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
253398 }
253399 }
253400 fts5DataRelease(pLeaf);
253401 }
253402 }
253403
253404 static void fts5IntegrityCheckPgidx(Fts5Index *p, i64 iRowid, Fts5Data *pLeaf){
253405 i64 iTermOff = 0;
253406 int ii;
253407
253408 Fts5Buffer buf1 = {0,0,0};
253409 Fts5Buffer buf2 = {0,0,0};
@@ -252579,33 +253417,33 @@
253417 ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
253418 iTermOff += nIncr;
253419 iOff = iTermOff;
253420
253421 if( iOff>=pLeaf->szLeaf ){
253422 FTS5_CORRUPT_ROWID(p, iRowid);
253423 }else if( iTermOff==nIncr ){
253424 int nByte;
253425 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
253426 if( (iOff+nByte)>pLeaf->szLeaf ){
253427 FTS5_CORRUPT_ROWID(p, iRowid);
253428 }else{
253429 fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
253430 }
253431 }else{
253432 int nKeep, nByte;
253433 iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
253434 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
253435 if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
253436 FTS5_CORRUPT_ROWID(p, iRowid);
253437 }else{
253438 buf1.n = nKeep;
253439 fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
253440 }
253441
253442 if( p->rc==SQLITE_OK ){
253443 res = fts5BufferCompare(&buf1, &buf2);
253444 if( res<=0 ) FTS5_CORRUPT_ROWID(p, iRowid);
253445 }
253446 }
253447 fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
253448 }
253449
@@ -252662,11 +253500,11 @@
253500 ){
253501 /* special case - the very first page in a segment keeps its %_idx
253502 ** entry even if all the terms are removed from it by secure-delete
253503 ** operations. */
253504 }else{
253505 FTS5_CORRUPT_ROWID(p, iRow);
253506 }
253507
253508 }else{
253509 int iOff; /* Offset of first term on leaf */
253510 int iRowidOff; /* Offset of first rowid on leaf */
@@ -252674,19 +253512,19 @@
253512 int res; /* Comparison of term and split-key */
253513
253514 iOff = fts5LeafFirstTermOff(pLeaf);
253515 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
253516 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
253517 FTS5_CORRUPT_ROWID(p, iRow);
253518 }else{
253519 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
253520 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
253521 if( res==0 ) res = nTerm - nIdxTerm;
253522 if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
253523 }
253524
253525 fts5IntegrityCheckPgidx(p, iRow, pLeaf);
253526 }
253527 fts5DataRelease(pLeaf);
253528 if( p->rc ) break;
253529
253530 /* Now check that the iter.nEmpty leaves following the current leaf
@@ -252712,11 +253550,11 @@
253550 /* Check any rowid-less pages that occur before the current leaf. */
253551 for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
253552 iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
253553 pLeaf = fts5DataRead(p, iKey);
253554 if( pLeaf ){
253555 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey);
253556 fts5DataRelease(pLeaf);
253557 }
253558 }
253559 iPrevLeaf = fts5DlidxIterPgno(pDlidx);
253560
@@ -252727,16 +253565,16 @@
253565 if( pLeaf ){
253566 i64 iRowid;
253567 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
253568 ASSERT_SZLEAF_OK(pLeaf);
253569 if( iRowidOff>=pLeaf->szLeaf ){
253570 FTS5_CORRUPT_ROWID(p, iKey);
253571 }else if( bSecureDelete==0 || iRowidOff>0 ){
253572 i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
253573 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
253574 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
253575 FTS5_CORRUPT_ROWID(p, iKey);
253576 }
253577 }
253578 fts5DataRelease(pLeaf);
253579 }
253580 }
@@ -252784,10 +253622,11 @@
253622
253623 #ifdef SQLITE_DEBUG
253624 /* Used by extra internal tests only run if NDEBUG is not defined */
253625 u64 cksum3 = 0; /* Checksum based on contents of indexes */
253626 Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
253627 int bTestFail = 0;
253628 #endif
253629 const int flags = FTS5INDEX_QUERY_NOOUTPUT;
253630
253631 /* Load the FTS index structure */
253632 pStruct = fts5StructureRead(p);
@@ -252826,11 +253665,11 @@
253665 int iOff = 0; /* Offset within poslist */
253666 i64 iRowid = fts5MultiIterRowid(pIter);
253667 char *z = (char*)fts5MultiIterTerm(pIter, &n);
253668
253669 /* If this is a new term, query for it. Update cksum3 with the results. */
253670 fts5TestTerm(p, &term, z, n, cksum2, &cksum3, &bTestFail);
253671 if( p->rc ) break;
253672
253673 if( eDetail==FTS5_DETAIL_NONE ){
253674 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
253675 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, 0, 0, -1, z, n);
@@ -252844,19 +253683,30 @@
253683 int iTokOff = FTS5_POS2OFFSET(iPos);
253684 cksum2 ^= sqlite3Fts5IndexEntryCksum(iRowid, iCol, iTokOff, -1, z, n);
253685 }
253686 }
253687 }
253688 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3, &bTestFail);
253689
253690 fts5MultiIterFree(pIter);
253691 if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
253692 p->rc = FTS5_CORRUPT;
253693 sqlite3Fts5ConfigErrmsg(p->pConfig,
253694 "fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
253695 );
253696 }
253697 #ifdef SQLITE_DEBUG
253698 /* In SQLITE_DEBUG builds, expensive extra checks were run as part of
253699 ** the integrity-check above. If no other errors were detected, but one
253700 ** of these tests failed, set the result to SQLITE_CORRUPT_VTAB here. */
253701 if( p->rc==SQLITE_OK && bTestFail ){
253702 p->rc = FTS5_CORRUPT;
253703 }
253704 fts5BufferFree(&term);
253705 #endif
253706
253707 fts5StructureRelease(pStruct);
253708 fts5BufferFree(&poslist);
253709 return fts5IndexReturn(p);
253710 }
253711
253712 /*************************************************************************
@@ -257263,11 +258113,11 @@
258113 int nArg, /* Number of args */
258114 sqlite3_value **apUnused /* Function arguments */
258115 ){
258116 assert( nArg==0 );
258117 UNUSED_PARAM2(nArg, apUnused);
258118 sqlite3_result_text(pCtx, "fts5: 2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839", -1, SQLITE_TRANSIENT);
258119 }
258120
258121 /*
258122 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258123 **
@@ -257386,12 +258236,13 @@
258236 }else{
258237 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
258238 " FTS5 table %s.%s: %s",
258239 zSchema, zTabname, sqlite3_errstr(rc));
258240 }
258241 }else if( (rc&0xff)==SQLITE_CORRUPT ){
258242 rc = SQLITE_OK;
258243 }
 
258244 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
258245 pTab->p.pConfig->pzErrmsg = 0;
258246
258247 return rc;
258248 }
@@ -258078,10 +258929,11 @@
258929 ctx.pStorage = p;
258930 ctx.iCol = -1;
258931 for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
258932 if( pConfig->abUnindexed[iCol-1]==0 ){
258933 sqlite3_value *pVal = 0;
258934 sqlite3_value *pFree = 0;
258935 const char *pText = 0;
258936 int nText = 0;
258937 const char *pLoc = 0;
258938 int nLoc = 0;
258939
@@ -258094,15 +258946,26 @@
258946 }
258947
258948 if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
258949 rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
258950 }else{
258951 if( sqlite3_value_type(pVal)!=SQLITE_TEXT ){
258952 /* Make a copy of the value to work with. This is because the call
258953 ** to sqlite3_value_text() below forces the type of the value to
258954 ** SQLITE_TEXT, and we may need to use it again later. */
258955 pFree = pVal = sqlite3_value_dup(pVal);
258956 if( pVal==0 ){
258957 rc = SQLITE_NOMEM;
258958 }
258959 }
258960 if( rc==SQLITE_OK ){
258961 pText = (const char*)sqlite3_value_text(pVal);
258962 nText = sqlite3_value_bytes(pVal);
258963 if( pConfig->bLocale && pSeek ){
258964 pLoc = (const char*)sqlite3_column_text(pSeek, iCol+pConfig->nCol);
258965 nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
258966 }
258967 }
258968 }
258969
258970 if( rc==SQLITE_OK ){
258971 sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
@@ -258114,10 +258977,11 @@
258977 if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
258978 rc = FTS5_CORRUPT;
258979 }
258980 sqlite3Fts5ClearLocale(pConfig);
258981 }
258982 sqlite3_value_free(pFree);
258983 }
258984 }
258985 if( rc==SQLITE_OK && p->nTotalRow<1 ){
258986 rc = FTS5_CORRUPT;
258987 }else{
258988
+195 -150
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.50.0"
150
-#define SQLITE_VERSION_NUMBER 3050000
151
-#define SQLITE_SOURCE_ID "2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849"
149
+#define SQLITE_VERSION "3.51.0"
150
+#define SQLITE_VERSION_NUMBER 3051000
151
+#define SQLITE_SOURCE_ID "2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -166,13 +166,13 @@
166166
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
167167
** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
168168
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
169169
** </pre></blockquote>)^
170170
**
171
-** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
172
-** macro. ^The sqlite3_libversion() function returns a pointer to the
173
-** to the sqlite3_version[] string constant. The sqlite3_libversion()
171
+** ^The sqlite3_version[] string constant contains the text of the
172
+** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a
173
+** pointer to the sqlite3_version[] string constant. The sqlite3_libversion()
174174
** function is provided for use in DLLs since DLL users usually do not have
175175
** direct access to string constants within the DLL. ^The
176176
** sqlite3_libversion_number() function returns an integer equal to
177177
** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
178178
** a pointer to a string constant whose value is the same as the
@@ -368,11 +368,11 @@
368368
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
369369
** that allows an application to run multiple statements of SQL
370370
** without having to use a lot of C code.
371371
**
372372
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
373
-** semicolon-separate SQL statements passed into its 2nd argument,
373
+** semicolon-separated SQL statements passed into its 2nd argument,
374374
** in the context of the [database connection] passed in as its 1st
375375
** argument. ^If the callback function of the 3rd argument to
376376
** sqlite3_exec() is not NULL, then it is invoked for each result row
377377
** coming out of the evaluated SQL statements. ^The 4th argument to
378378
** sqlite3_exec() is relayed through to the 1st argument of each
@@ -401,11 +401,11 @@
401401
** callback is an array of pointers to strings obtained as if from
402402
** [sqlite3_column_text()], one for each column. ^If an element of a
403403
** result row is NULL then the corresponding string pointer for the
404404
** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
405405
** sqlite3_exec() callback is an array of pointers to strings where each
406
-** entry represents the name of corresponding result column as obtained
406
+** entry represents the name of a corresponding result column as obtained
407407
** from [sqlite3_column_name()].
408408
**
409409
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
410410
** to an empty string, or a pointer that contains only whitespace and/or
411411
** SQL comments, then no SQL statements are evaluated and the database
@@ -587,11 +587,11 @@
587587
** Applications should not depend on the historical behavior.
588588
**
589589
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
590590
** [sqlite3_open_v2()] does *not* cause the underlying database file
591591
** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
592
-** [sqlite3_open_v2()] has historically be a no-op and might become an
592
+** [sqlite3_open_v2()] has historically been a no-op and might become an
593593
** error in future versions of SQLite.
594594
*/
595595
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
596596
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
597597
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -681,11 +681,11 @@
681681
** CAPI3REF: File Locking Levels
682682
**
683683
** SQLite uses one of these integer values as the second
684684
** argument to calls it makes to the xLock() and xUnlock() methods
685685
** of an [sqlite3_io_methods] object. These values are ordered from
686
-** lest restrictive to most restrictive.
686
+** least restrictive to most restrictive.
687687
**
688688
** The argument to xLock() is always SHARED or higher. The argument to
689689
** xUnlock is either SHARED or NONE.
690690
*/
691691
#define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -997,11 +997,11 @@
997997
** reason, the entire database file will be overwritten by the current
998998
** transaction. This is used by VACUUM operations.
999999
**
10001000
** <li>[[SQLITE_FCNTL_VFSNAME]]
10011001
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1002
-** all [VFSes] in the VFS stack. The names are of all VFS shims and the
1002
+** all [VFSes] in the VFS stack. The names of all VFS shims and the
10031003
** final bottom-level VFS are written into memory obtained from
10041004
** [sqlite3_malloc()] and the result is stored in the char* variable
10051005
** that the fourth parameter of [sqlite3_file_control()] points to.
10061006
** The caller is responsible for freeing the memory when done. As with
10071007
** all file-control actions, there is no guarantee that this will actually
@@ -1011,11 +1011,11 @@
10111011
**
10121012
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
10131013
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
10141014
** [VFSes] currently in use. ^(The argument X in
10151015
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1016
-** of type "[sqlite3_vfs] **". This opcodes will set *X
1016
+** of type "[sqlite3_vfs] **". This opcode will set *X
10171017
** to a pointer to the top-level VFS.)^
10181018
** ^When there are multiple VFS shims in the stack, this opcode finds the
10191019
** upper-most shim only.
10201020
**
10211021
** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1201,11 +1201,11 @@
12011201
** record the fact that the pages have been checkpointed.
12021202
**
12031203
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
12041204
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
12051205
** whether or not there is a database client in another process with a wal-mode
1206
-** transaction open on the database or not. It is only available on unix.The
1206
+** transaction open on the database or not. It is only available on unix. The
12071207
** (void*) argument passed with this file-control should be a pointer to a
12081208
** value of type (int). The integer value is set to 1 if the database is a wal
12091209
** mode database and there exists at least one client in another process that
12101210
** currently has an SQL transaction open on the database. It is set to 0 if
12111211
** the database is not a wal-mode db, or if there is no such connection in any
@@ -1626,11 +1626,11 @@
16261626
**
16271627
** ^The sqlite3_initialize() routine is called internally by many other
16281628
** SQLite interfaces so that an application usually does not need to
16291629
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
16301630
** calls sqlite3_initialize() so the SQLite library will be automatically
1631
-** initialized when [sqlite3_open()] is called if it has not be initialized
1631
+** initialized when [sqlite3_open()] is called if it has not been initialized
16321632
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
16331633
** compile-time option, then the automatic calls to sqlite3_initialize()
16341634
** are omitted and the application must call sqlite3_initialize() directly
16351635
** prior to using any other SQLite interface. For maximum portability,
16361636
** it is recommended that applications always invoke sqlite3_initialize()
@@ -1883,25 +1883,25 @@
18831883
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
18841884
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
18851885
** The [sqlite3_mem_methods]
18861886
** structure is filled with the currently defined memory allocation routines.)^
18871887
** This option can be used to overload the default memory allocation
1888
-** routines with a wrapper that simulations memory allocation failure or
1888
+** routines with a wrapper that simulates memory allocation failure or
18891889
** tracks memory usage, for example. </dd>
18901890
**
18911891
** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1892
-** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1892
+** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of
18931893
** type int, interpreted as a boolean, which if true provides a hint to
18941894
** SQLite that it should avoid large memory allocations if possible.
18951895
** SQLite will run faster if it is free to make large memory allocations,
1896
-** but some application might prefer to run slower in exchange for
1896
+** but some applications might prefer to run slower in exchange for
18971897
** guarantees about memory fragmentation that are possible if large
18981898
** allocations are avoided. This hint is normally off.
18991899
** </dd>
19001900
**
19011901
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1902
-** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1902
+** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,
19031903
** interpreted as a boolean, which enables or disables the collection of
19041904
** memory allocation statistics. ^(When memory allocation statistics are
19051905
** disabled, the following SQLite interfaces become non-operational:
19061906
** <ul>
19071907
** <li> [sqlite3_hard_heap_limit64()]
@@ -1942,11 +1942,11 @@
19421942
** a page cache line is larger than sz bytes or if all of the pMem buffer
19431943
** is exhausted.
19441944
** ^If pMem is NULL and N is non-zero, then each database connection
19451945
** does an initial bulk allocation for page cache memory
19461946
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1947
-** of -1024*N bytes if N is negative, . ^If additional
1947
+** of -1024*N bytes if N is negative. ^If additional
19481948
** page cache memory is needed beyond what is provided by the initial
19491949
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
19501950
** additional cache line. </dd>
19511951
**
19521952
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -1971,11 +1971,11 @@
19711971
**
19721972
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
19731973
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
19741974
** pointer to an instance of the [sqlite3_mutex_methods] structure.
19751975
** The argument specifies alternative low-level mutex routines to be used
1976
-** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1976
+** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of
19771977
** the content of the [sqlite3_mutex_methods] structure before the call to
19781978
** [sqlite3_config()] returns. ^If SQLite is compiled with
19791979
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
19801980
** the entire mutexing subsystem is omitted from the build and hence calls to
19811981
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2013,11 +2013,11 @@
20132013
** the interface to a custom page cache implementation.)^
20142014
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
20152015
**
20162016
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
20172017
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2018
-** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
2018
+** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off
20192019
** the current page cache implementation into that object.)^ </dd>
20202020
**
20212021
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
20222022
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
20232023
** global [error log].
@@ -2030,11 +2030,11 @@
20302030
** passed through as the first parameter to the application-defined logger
20312031
** function whenever that function is invoked. ^The second parameter to
20322032
** the logger function is a copy of the first parameter to the corresponding
20332033
** [sqlite3_log()] call and is intended to be a [result code] or an
20342034
** [extended result code]. ^The third parameter passed to the logger is
2035
-** log message after formatting via [sqlite3_snprintf()].
2035
+** a log message after formatting via [sqlite3_snprintf()].
20362036
** The SQLite logging interface is not reentrant; the logger function
20372037
** supplied by the application must not invoke any SQLite interface.
20382038
** In a multi-threaded application, the application-defined logger
20392039
** function must be threadsafe. </dd>
20402040
**
@@ -2221,11 +2221,11 @@
22212221
** CAPI3REF: Database Connection Configuration Options
22222222
**
22232223
** These constants are the available integer configuration options that
22242224
** can be passed as the second parameter to the [sqlite3_db_config()] interface.
22252225
**
2226
-** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2226
+** The [sqlite3_db_config()] interface is a var-args function. It takes a
22272227
** variable number of parameters, though always at least two. The number of
22282228
** parameters passed into sqlite3_db_config() depends on which of these
22292229
** constants is given as the second parameter. This documentation page
22302230
** refers to parameters beyond the second as "arguments". Thus, when this
22312231
** page says "the N-th argument" it means "the N-th parameter past the
@@ -2355,12 +2355,12 @@
23552355
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
23562356
** There must be two additional arguments.
23572357
** When the first argument to this interface is 1, then only the C-API is
23582358
** enabled and the SQL function remains disabled. If the first argument to
23592359
** this interface is 0, then both the C-API and the SQL function are disabled.
2360
-** If the first argument is -1, then no changes are made to state of either the
2361
-** C-API or the SQL function.
2360
+** If the first argument is -1, then no changes are made to the state of either
2361
+** the C-API or the SQL function.
23622362
** The second parameter is a pointer to an integer into which
23632363
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
23642364
** is disabled or enabled following this call. The second parameter may
23652365
** be a NULL pointer, in which case the new setting is not reported back.
23662366
** </dd>
@@ -2474,11 +2474,11 @@
24742474
** </dd>
24752475
**
24762476
** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
24772477
** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
24782478
** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2479
-** the legacy behavior of the [ALTER TABLE RENAME] command such it
2479
+** the legacy behavior of the [ALTER TABLE RENAME] command such that it
24802480
** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
24812481
** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
24822482
** additional information. This feature can also be turned on and off
24832483
** using the [PRAGMA legacy_alter_table] statement.
24842484
** </dd>
@@ -2523,11 +2523,11 @@
25232523
**
25242524
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
25252525
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
25262526
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
25272527
** the legacy file format flag. When activated, this flag causes all newly
2528
-** created database file to have a schema format version number (the 4-byte
2528
+** created database files to have a schema format version number (the 4-byte
25292529
** integer found at offset 44 into the database header) of 1. This in turn
25302530
** means that the resulting database file will be readable and writable by
25312531
** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
25322532
** newly created databases are generally not understandable by SQLite versions
25332533
** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2550,11 +2550,11 @@
25502550
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
25512551
** statistics. For statistics to be collected, the flag must be set on
25522552
** the database handle both when the SQL statement is prepared and when it
25532553
** is stepped. The flag is set (collection of statistics is enabled)
25542554
** by default. <p>This option takes two arguments: an integer and a pointer to
2555
-** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2555
+** an integer. The first argument is 1, 0, or -1 to enable, disable, or
25562556
** leave unchanged the statement scanstatus option. If the second argument
25572557
** is not NULL, then the value of the statement scanstatus setting after
25582558
** processing the first argument is written into the integer that the second
25592559
** argument points to.
25602560
** </dd>
@@ -2593,12 +2593,12 @@
25932593
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
25942594
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
25952595
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
25962596
** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
25972597
** This capability is enabled by default. Applications can disable or
2598
-** reenable this capability using the current DBCONFIG option. If the
2599
-** the this capability is disabled, the [ATTACH] command will still work,
2598
+** reenable this capability using the current DBCONFIG option. If
2599
+** this capability is disabled, the [ATTACH] command will still work,
26002600
** but the database will be opened read-only. If this option is disabled,
26012601
** then the ability to create a new database using [ATTACH] is also disabled,
26022602
** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
26032603
** option.<p>
26042604
** This option takes two arguments which are an integer and a pointer
@@ -2628,11 +2628,11 @@
26282628
**
26292629
** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
26302630
**
26312631
** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
26322632
** overall call to [sqlite3_db_config()] has a total of four parameters.
2633
-** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2633
+** The first argument (the third parameter to sqlite3_db_config()) is an integer.
26342634
** The second argument is a pointer to an integer. If the first argument is 1,
26352635
** then the option becomes enabled. If the first integer argument is 0, then the
26362636
** option is disabled. If the first argument is -1, then the option setting
26372637
** is unchanged. The second argument, the pointer to an integer, may be NULL.
26382638
** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -2918,11 +2918,11 @@
29182918
** and comments that follow the final semicolon are ignored.
29192919
**
29202920
** ^These routines return 0 if the statement is incomplete. ^If a
29212921
** memory allocation fails, then SQLITE_NOMEM is returned.
29222922
**
2923
-** ^These routines do not parse the SQL statements thus
2923
+** ^These routines do not parse the SQL statements and thus
29242924
** will not detect syntactically incorrect SQL.
29252925
**
29262926
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
29272927
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
29282928
** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3035,11 +3035,11 @@
30353035
** Passing 0 to this function disables blocking locks altogether. Passing
30363036
** -1 to this function requests that the VFS blocks for a long time -
30373037
** indefinitely if possible. The results of passing any other negative value
30383038
** are undefined.
30393039
**
3040
-** Internally, each SQLite database handle store two timeout values - the
3040
+** Internally, each SQLite database handle stores two timeout values - the
30413041
** busy-timeout (used for rollback mode databases, or if the VFS does not
30423042
** support blocking locks) and the setlk-timeout (used for blocking locks
30433043
** on wal-mode databases). The sqlite3_busy_timeout() method sets both
30443044
** values, this function sets only the setlk-timeout value. Therefore,
30453045
** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3065,11 +3065,11 @@
30653065
** METHOD: sqlite3
30663066
**
30673067
** This is a legacy interface that is preserved for backwards compatibility.
30683068
** Use of this interface is not recommended.
30693069
**
3070
-** Definition: A <b>result table</b> is memory data structure created by the
3070
+** Definition: A <b>result table</b> is a memory data structure created by the
30713071
** [sqlite3_get_table()] interface. A result table records the
30723072
** complete query results from one or more queries.
30733073
**
30743074
** The table conceptually has a number of rows and columns. But
30753075
** these numbers are not part of the result table itself. These
@@ -3208,11 +3208,11 @@
32083208
** of a signed 32-bit integer.
32093209
**
32103210
** ^Calling sqlite3_free() with a pointer previously returned
32113211
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
32123212
** that it might be reused. ^The sqlite3_free() routine is
3213
-** a no-op if is called with a NULL pointer. Passing a NULL pointer
3213
+** a no-op if it is called with a NULL pointer. Passing a NULL pointer
32143214
** to sqlite3_free() is harmless. After being freed, memory
32153215
** should neither be read nor written. Even reading previously freed
32163216
** memory might result in a segmentation fault or other severe error.
32173217
** Memory corruption, a segmentation fault, or other severe error
32183218
** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3226,17 +3226,17 @@
32263226
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
32273227
** negative then the behavior is exactly the same as calling
32283228
** sqlite3_free(X).
32293229
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
32303230
** of at least N bytes in size or NULL if insufficient memory is available.
3231
-** ^If M is the size of the prior allocation, then min(N,M) bytes
3232
-** of the prior allocation are copied into the beginning of buffer returned
3231
+** ^If M is the size of the prior allocation, then min(N,M) bytes of the
3232
+** prior allocation are copied into the beginning of the buffer returned
32333233
** by sqlite3_realloc(X,N) and the prior allocation is freed.
32343234
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
32353235
** prior allocation is not freed.
32363236
**
3237
-** ^The sqlite3_realloc64(X,N) interfaces works the same as
3237
+** ^The sqlite3_realloc64(X,N) interface works the same as
32383238
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
32393239
** of a 32-bit signed integer.
32403240
**
32413241
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
32423242
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3282,11 +3282,11 @@
32823282
** ^The [sqlite3_memory_highwater()] routine returns the maximum
32833283
** value of [sqlite3_memory_used()] since the high-water mark
32843284
** was last reset. ^The values returned by [sqlite3_memory_used()] and
32853285
** [sqlite3_memory_highwater()] include any overhead
32863286
** added by SQLite in its implementation of [sqlite3_malloc()],
3287
-** but not overhead added by the any underlying system library
3287
+** but not overhead added by any underlying system library
32883288
** routines that [sqlite3_malloc()] may call.
32893289
**
32903290
** ^The memory high-water mark is reset to the current value of
32913291
** [sqlite3_memory_used()] if and only if the parameter to
32923292
** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -3734,19 +3734,19 @@
37343734
** attempt to use the same database connection at the same time.
37353735
** (Mutexes will block any actual concurrency, but in this mode
37363736
** there is no harm in trying.)
37373737
**
37383738
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3739
-** <dd>The database is opened [shared cache] enabled, overriding
3739
+** <dd>The database is opened with [shared cache] enabled, overriding
37403740
** the default shared cache setting provided by
37413741
** [sqlite3_enable_shared_cache()].)^
37423742
** The [use of shared cache mode is discouraged] and hence shared cache
37433743
** capabilities may be omitted from many builds of SQLite. In such cases,
37443744
** this option is a no-op.
37453745
**
37463746
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3747
-** <dd>The database is opened [shared cache] disabled, overriding
3747
+** <dd>The database is opened with [shared cache] disabled, overriding
37483748
** the default shared cache setting provided by
37493749
** [sqlite3_enable_shared_cache()].)^
37503750
**
37513751
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
37523752
** <dd>The database connection comes up in "extended result code mode".
@@ -4077,11 +4077,11 @@
40774077
** These interfaces are provided for use by [VFS shim] implementations and
40784078
** are not useful outside of that context.
40794079
**
40804080
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
40814081
** database filename D with corresponding journal file J and WAL file W and
4082
-** with N URI parameters key/values pairs in the array P. The result from
4082
+** an array P of N URI Key/Value pairs. The result from
40834083
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
40844084
** is safe to pass to routines like:
40854085
** <ul>
40864086
** <li> [sqlite3_uri_parameter()],
40874087
** <li> [sqlite3_uri_boolean()],
@@ -4160,19 +4160,19 @@
41604160
** The application does not need to worry about freeing the result.
41614161
** However, the error string might be overwritten or deallocated by
41624162
** subsequent calls to other SQLite interface functions.)^
41634163
**
41644164
** ^The sqlite3_errstr(E) interface returns the English-language text
4165
-** that describes the [result code] E, as UTF-8, or NULL if E is not an
4165
+** that describes the [result code] E, as UTF-8, or NULL if E is not a
41664166
** result code for which a text error message is available.
41674167
** ^(Memory to hold the error message string is managed internally
41684168
** and must not be freed by the application)^.
41694169
**
41704170
** ^If the most recent error references a specific token in the input
41714171
** SQL, the sqlite3_error_offset() interface returns the byte offset
41724172
** of the start of that token. ^The byte offset returned by
4173
-** sqlite3_error_offset() assumes that the input SQL is UTF8.
4173
+** sqlite3_error_offset() assumes that the input SQL is UTF-8.
41744174
** ^If the most recent error does not reference a specific token in the input
41754175
** SQL, then the sqlite3_error_offset() function returns -1.
41764176
**
41774177
** When the serialized [threading mode] is in use, it might be the
41784178
** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
42674267
** CAPI3REF: Run-Time Limit Categories
42684268
** KEYWORDS: {limit category} {*limit categories}
42694269
**
42704270
** These constants define various performance limits
42714271
** that can be lowered at run-time using [sqlite3_limit()].
4272
-** The synopsis of the meanings of the various limits is shown below.
4273
-** Additional information is available at [limits | Limits in SQLite].
4272
+** A concise description of these limits follows, and additional information
4273
+** is available at [limits | Limits in SQLite].
42744274
**
42754275
** <dl>
42764276
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
42774277
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
42784278
**
@@ -4333,11 +4333,11 @@
43334333
#define SQLITE_LIMIT_WORKER_THREADS 11
43344334
43354335
/*
43364336
** CAPI3REF: Prepare Flags
43374337
**
4338
-** These constants define various flags that can be passed into
4338
+** These constants define various flags that can be passed into the
43394339
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
43404340
** [sqlite3_prepare16_v3()] interfaces.
43414341
**
43424342
** New flags may be added in future releases of SQLite.
43434343
**
@@ -4420,11 +4420,11 @@
44204420
** statement is generated.
44214421
** If the caller knows that the supplied string is nul-terminated, then
44224422
** there is a small performance advantage to passing an nByte parameter that
44234423
** is the number of bytes in the input string <i>including</i>
44244424
** the nul-terminator.
4425
-** Note that nByte measure the length of the input in bytes, not
4425
+** Note that nByte measures the length of the input in bytes, not
44264426
** characters, even for the UTF-16 interfaces.
44274427
**
44284428
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
44294429
** past the end of the first SQL statement in zSql. These routines only
44304430
** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
45544554
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
45554555
** will return "SELECT 2345,NULL".)^
45564556
**
45574557
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
45584558
** is available to hold the result, or if the result would exceed the
4559
-** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4559
+** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
45604560
**
45614561
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
45624562
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
45634563
** option causes sqlite3_expanded_sql() to always return NULL.
45644564
**
@@ -4742,11 +4742,11 @@
47424742
/*
47434743
** CAPI3REF: SQL Function Context Object
47444744
**
47454745
** The context in which an SQL function executes is stored in an
47464746
** sqlite3_context object. ^A pointer to an sqlite3_context object
4747
-** is always first parameter to [application-defined SQL functions].
4747
+** is always the first parameter to [application-defined SQL functions].
47484748
** The application-defined SQL function implementation will pass this
47494749
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
47504750
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
47514751
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
47524752
** and/or [sqlite3_set_auxdata()].
@@ -4758,11 +4758,11 @@
47584758
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
47594759
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
47604760
** METHOD: sqlite3_stmt
47614761
**
47624762
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763
-** literals may be replaced by a [parameter] that matches one of following
4763
+** literals may be replaced by a [parameter] that matches one of the following
47644764
** templates:
47654765
**
47664766
** <ul>
47674767
** <li> ?
47684768
** <li> ?NNN
@@ -4803,11 +4803,11 @@
48034803
** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
48044804
** otherwise.
48054805
**
48064806
** [[byte-order determination rules]] ^The byte-order of
48074807
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808
-** found in first character, which is removed, or in the absence of a BOM
4808
+** found in the first character, which is removed, or in the absence of a BOM
48094809
** the byte order is the native byte order of the host
48104810
** machine for sqlite3_bind_text16() or the byte order specified in
48114811
** the 6th parameter for sqlite3_bind_text64().)^
48124812
** ^If UTF16 input text contains invalid unicode
48134813
** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
48234823
** the behavior is undefined.
48244824
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
48254825
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
48264826
** that parameter must be the byte offset
48274827
** where the NUL terminator would occur assuming the string were NUL
4828
-** terminated. If any NUL characters occurs at byte offsets less than
4828
+** terminated. If any NUL characters occur at byte offsets less than
48294829
** the value of the fourth parameter then the resulting string value will
48304830
** contain embedded NULs. The result of expressions involving strings
48314831
** with embedded NULs is undefined.
48324832
**
48334833
** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
50355035
/*
50365036
** CAPI3REF: Source Of Data In A Query Result
50375037
** METHOD: sqlite3_stmt
50385038
**
50395039
** ^These routines provide a means to determine the database, table, and
5040
-** table column that is the origin of a particular result column in
5040
+** table column that is the origin of a particular result column in a
50415041
** [SELECT] statement.
50425042
** ^The name of the database or table or column can be returned as
50435043
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
50445044
** the database name, the _table_ routines return the table name, and
50455045
** the origin_ routines return the column name.
@@ -5479,11 +5479,11 @@
54795479
** CAPI3REF: Destroy A Prepared Statement Object
54805480
** DESTRUCTOR: sqlite3_stmt
54815481
**
54825482
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
54835483
** ^If the most recent evaluation of the statement encountered no errors
5484
-** or if the statement is never been evaluated, then sqlite3_finalize() returns
5484
+** or if the statement has never been evaluated, then sqlite3_finalize() returns
54855485
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
54865486
** sqlite3_finalize(S) returns the appropriate [error code] or
54875487
** [extended error code].
54885488
**
54895489
** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5604,12 +5604,12 @@
56045604
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
56055605
** index expressions, or the WHERE clause of partial indexes.
56065606
**
56075607
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
56085608
** all application-defined SQL functions that do not need to be
5609
-** used inside of triggers, view, CHECK constraints, or other elements of
5610
-** the database schema. This flags is especially recommended for SQL
5609
+** used inside of triggers, views, CHECK constraints, or other elements of
5610
+** the database schema. This flag is especially recommended for SQL
56115611
** functions that have side effects or reveal internal application state.
56125612
** Without this flag, an attacker might be able to modify the schema of
56135613
** a database file to include invocations of the function with parameters
56145614
** chosen by the attacker, which the application will then execute when
56155615
** the database file is opened and read.
@@ -5636,11 +5636,11 @@
56365636
** or aggregate window function. More details regarding the implementation
56375637
** of aggregate window functions are
56385638
** [user-defined window functions|available here].
56395639
**
56405640
** ^(If the final parameter to sqlite3_create_function_v2() or
5641
-** sqlite3_create_window_function() is not NULL, then it is destructor for
5641
+** sqlite3_create_window_function() is not NULL, then it is the destructor for
56425642
** the application data pointer. The destructor is invoked when the function
56435643
** is deleted, either by being overloaded or when the database connection
56445644
** closes.)^ ^The destructor is also invoked if the call to
56455645
** sqlite3_create_function_v2() fails. ^When the destructor callback is
56465646
** invoked, it is passed a single argument which is a copy of the application
@@ -5711,11 +5711,11 @@
57115711
);
57125712
57135713
/*
57145714
** CAPI3REF: Text Encodings
57155715
**
5716
-** These constant define integer codes that represent the various
5716
+** These constants define integer codes that represent the various
57175717
** text encodings supported by SQLite.
57185718
*/
57195719
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
57205720
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
57215721
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
58035803
** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
58045804
** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
58055805
** result.
58065806
** Every function that invokes [sqlite3_result_subtype()] should have this
58075807
** property. If it does not, then the call to [sqlite3_result_subtype()]
5808
-** might become a no-op if the function is used as term in an
5808
+** might become a no-op if the function is used as a term in an
58095809
** [expression index]. On the other hand, SQL functions that never invoke
58105810
** [sqlite3_result_subtype()] should avoid setting this property, as the
58115811
** purpose of this property is to disable certain optimizations that are
58125812
** incompatible with subtypes.
58135813
**
@@ -5930,11 +5930,11 @@
59305930
**
59315931
** ^Within the [xUpdate] method of a [virtual table], the
59325932
** sqlite3_value_nochange(X) interface returns true if and only if
59335933
** the column corresponding to X is unchanged by the UPDATE operation
59345934
** that the xUpdate method call was invoked to implement and if
5935
-** and the prior [xColumn] method call that was invoked to extracted
5935
+** the prior [xColumn] method call that was invoked to extract
59365936
** the value for that column returned without setting a result (probably
59375937
** because it queried [sqlite3_vtab_nochange()] and found that the column
59385938
** was unchanging). ^Within an [xUpdate] method, any value for which
59395939
** sqlite3_value_nochange(X) is true will in all other respects appear
59405940
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6036,11 +6036,11 @@
60366036
/*
60376037
** CAPI3REF: Copy And Free SQL Values
60386038
** METHOD: sqlite3_value
60396039
**
60406040
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6041
-** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
6041
+** object V and returns a pointer to that copy. ^The [sqlite3_value] returned
60426042
** is a [protected sqlite3_value] object even if the input is not.
60436043
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
60446044
** memory allocation fails. ^If V is a [pointer value], then the result
60456045
** of sqlite3_value_dup(V) is a NULL value.
60466046
**
@@ -6074,11 +6074,11 @@
60746074
** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
60756075
** when first called if N is less than or equal to zero or if a memory
60766076
** allocation error occurs.
60776077
**
60786078
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6079
-** determined by the N parameter on first successful call. Changing the
6079
+** determined by the N parameter on the first successful call. Changing the
60806080
** value of N in any subsequent call to sqlite3_aggregate_context() within
60816081
** the same aggregate function instance will not resize the memory
60826082
** allocation.)^ Within the xFinal callback, it is customary to set
60836083
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
60846084
** pointless memory allocations occur.
@@ -6236,11 +6236,11 @@
62366236
** of as a secret key such that only code that knows the secret key is able
62376237
** to access the associated data.
62386238
**
62396239
** Security Warning: These interfaces should not be exposed in scripting
62406240
** languages or in other circumstances where it might be possible for an
6241
-** an attacker to invoke them. Any agent that can invoke these interfaces
6241
+** attacker to invoke them. Any agent that can invoke these interfaces
62426242
** can probably also take control of the process.
62436243
**
62446244
** Database connection client data is only available for SQLite
62456245
** version 3.44.0 ([dateof:3.44.0]) and later.
62466246
**
@@ -6350,11 +6350,11 @@
63506350
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
63516351
** is non-negative, then as many bytes (not characters) of the text
63526352
** pointed to by the 2nd parameter are taken as the application-defined
63536353
** function result. If the 3rd parameter is non-negative, then it
63546354
** must be the byte offset into the string where the NUL terminator would
6355
-** appear if the string where NUL terminated. If any NUL characters occur
6355
+** appear if the string were NUL terminated. If any NUL characters occur
63566356
** in the string at a byte offset that is less than the value of the 3rd
63576357
** parameter, then the resulting string will contain embedded NULs and the
63586358
** result of expressions operating on strings with embedded NULs is undefined.
63596359
** ^If the 4th parameter to the sqlite3_result_text* interfaces
63606360
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6408,11 +6408,11 @@
64086408
** for the P parameter. ^SQLite invokes D with P as its only argument
64096409
** when SQLite is finished with P. The T parameter should be a static
64106410
** string and preferably a string literal. The sqlite3_result_pointer()
64116411
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
64126412
**
6413
-** If these routines are called from within the different thread
6413
+** If these routines are called from within a different thread
64146414
** than the one containing the application-defined function that received
64156415
** the [sqlite3_context] pointer, the results are undefined.
64166416
*/
64176417
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
64186418
SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -6814,11 +6814,11 @@
68146814
/*
68156815
** CAPI3REF: Return The Schema Name For A Database Connection
68166816
** METHOD: sqlite3
68176817
**
68186818
** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6819
-** for the N-th database on database connection D, or a NULL pointer of N is
6819
+** for the N-th database on database connection D, or a NULL pointer if N is
68206820
** out of range. An N value of 0 means the main database file. An N of 1 is
68216821
** the "temp" schema. Larger values of N correspond to various ATTACH-ed
68226822
** databases.
68236823
**
68246824
** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -6909,20 +6909,20 @@
69096909
**
69106910
** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
69116911
** <dd>The SQLITE_TXN_READ state means that the database is currently
69126912
** in a read transaction. Content has been read from the database file
69136913
** but nothing in the database file has changed. The transaction state
6914
-** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
6914
+** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are
69156915
** no other conflicting concurrent write transactions. The transaction
69166916
** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
69176917
** [COMMIT].</dd>
69186918
**
69196919
** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
69206920
** <dd>The SQLITE_TXN_WRITE state means that the database is currently
69216921
** in a write transaction. Content has been written to the database file
69226922
** but has not yet committed. The transaction state will change to
6923
-** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6923
+** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
69246924
*/
69256925
#define SQLITE_TXN_NONE 0
69266926
#define SQLITE_TXN_READ 1
69276927
#define SQLITE_TXN_WRITE 2
69286928
@@ -7199,11 +7199,11 @@
71997199
72007200
/*
72017201
** CAPI3REF: Impose A Limit On Heap Size
72027202
**
72037203
** These interfaces impose limits on the amount of heap memory that will be
7204
-** by all database connections within a single process.
7204
+** used by all database connections within a single process.
72057205
**
72067206
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
72077207
** soft limit on the amount of heap memory that may be allocated by SQLite.
72087208
** ^SQLite strives to keep heap memory utilization below the soft heap
72097209
** limit by reducing the number of pages held in the page cache
@@ -7257,11 +7257,11 @@
72577257
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
72587258
** from the heap.
72597259
** </ul>)^
72607260
**
72617261
** The circumstances under which SQLite will enforce the heap limits may
7262
-** changes in future releases of SQLite.
7262
+** change in future releases of SQLite.
72637263
*/
72647264
SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
72657265
SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
72667266
72677267
/*
@@ -7372,12 +7372,12 @@
73727372
** be tried also.
73737373
**
73747374
** ^The entry point is zProc.
73757375
** ^(zProc may be 0, in which case SQLite will try to come up with an
73767376
** entry point name on its own. It first tries "sqlite3_extension_init".
7377
-** If that does not work, it constructs a name "sqlite3_X_init" where the
7378
-** X is consists of the lower-case equivalent of all ASCII alphabetic
7377
+** If that does not work, it constructs a name "sqlite3_X_init" where
7378
+** X consists of the lower-case equivalent of all ASCII alphabetic
73797379
** characters in the filename from the last "/" to the first following
73807380
** "." and omitting any initial "lib".)^
73817381
** ^The sqlite3_load_extension() interface returns
73827382
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
73837383
** ^If an error occurs and pzErrMsg is not 0, then the
@@ -7444,11 +7444,11 @@
74447444
** that is to be automatically loaded into all new database connections.
74457445
**
74467446
** ^(Even though the function prototype shows that xEntryPoint() takes
74477447
** no arguments and returns void, SQLite invokes xEntryPoint() with three
74487448
** arguments and expects an integer result as if the signature of the
7449
-** entry point where as follows:
7449
+** entry point were as follows:
74507450
**
74517451
** <blockquote><pre>
74527452
** &nbsp; int xEntryPoint(
74537453
** &nbsp; sqlite3 *db,
74547454
** &nbsp; const char **pzErrMsg,
@@ -7608,11 +7608,11 @@
76087608
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
76097609
** is true, then the constraint is assumed to be fully handled by the
76107610
** virtual table and might not be checked again by the byte code.)^ ^(The
76117611
** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
76127612
** is left in its default setting of false, the constraint will always be
7613
-** checked separately in byte code. If the omit flag is change to true, then
7613
+** checked separately in byte code. If the omit flag is changed to true, then
76147614
** the constraint may or may not be checked in byte code. In other words,
76157615
** when the omit flag is true there is no guarantee that the constraint will
76167616
** not be checked again using byte code.)^
76177617
**
76187618
** ^The idxNum and idxStr values are recorded and passed into the
@@ -7634,11 +7634,11 @@
76347634
** will be returned by the strategy.
76357635
**
76367636
** The xBestIndex method may optionally populate the idxFlags field with a
76377637
** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
76387638
** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7639
-** output to show the idxNum has hex instead of as decimal. Another flag is
7639
+** output to show the idxNum as hex instead of as decimal. Another flag is
76407640
** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
76417641
** return at most one row.
76427642
**
76437643
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
76447644
** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7775,11 +7775,11 @@
77757775
** by the first parameter. ^The name of the module is given by the
77767776
** second parameter. ^The third parameter is a pointer to
77777777
** the implementation of the [virtual table module]. ^The fourth
77787778
** parameter is an arbitrary client data pointer that is passed through
77797779
** into the [xCreate] and [xConnect] methods of the virtual table module
7780
-** when a new virtual table is be being created or reinitialized.
7780
+** when a new virtual table is being created or reinitialized.
77817781
**
77827782
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
77837783
** is a pointer to a destructor for the pClientData. ^SQLite will
77847784
** invoke the destructor function (if it is not NULL) when SQLite
77857785
** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
79407940
**
79417941
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
79427942
** in *ppBlob. Otherwise an [error code] is returned and, unless the error
79437943
** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
79447944
** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945
-** on *ppBlob after this function it returns.
7945
+** on *ppBlob after this function returns.
79467946
**
79477947
** This function fails with SQLITE_ERROR if any of the following are true:
79487948
** <ul>
79497949
** <li> ^(Database zDb does not exist)^,
79507950
** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
80608060
** CAPI3REF: Return The Size Of An Open BLOB
80618061
** METHOD: sqlite3_blob
80628062
**
80638063
** ^Returns the size in bytes of the BLOB accessible via the
80648064
** successfully opened [BLOB handle] in its only argument. ^The
8065
-** incremental blob I/O routines can only read or overwriting existing
8065
+** incremental blob I/O routines can only read or overwrite existing
80668066
** blob content; they cannot change the size of a blob.
80678067
**
80688068
** This routine only works on a [BLOB handle] which has been created
80698069
** by a prior successful call to [sqlite3_blob_open()] and which has not
80708070
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -8210,11 +8210,11 @@
82108210
** function that calls sqlite3_initialize().
82118211
**
82128212
** ^The sqlite3_mutex_alloc() routine allocates a new
82138213
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
82148214
** routine returns NULL if it is unable to allocate the requested
8215
-** mutex. The argument to sqlite3_mutex_alloc() must one of these
8215
+** mutex. The argument to sqlite3_mutex_alloc() must be one of these
82168216
** integer constants:
82178217
**
82188218
** <ul>
82198219
** <li> SQLITE_MUTEX_FAST
82208220
** <li> SQLITE_MUTEX_RECURSIVE
@@ -8443,11 +8443,11 @@
84438443
84448444
/*
84458445
** CAPI3REF: Retrieve the mutex for a database connection
84468446
** METHOD: sqlite3
84478447
**
8448
-** ^This interface returns a pointer the [sqlite3_mutex] object that
8448
+** ^This interface returns a pointer to the [sqlite3_mutex] object that
84498449
** serializes access to the [database connection] given in the argument
84508450
** when the [threading mode] is Serialized.
84518451
** ^If the [threading mode] is Single-thread or Multi-thread then this
84528452
** routine returns a NULL pointer.
84538453
*/
@@ -8566,11 +8566,11 @@
85668566
85678567
/*
85688568
** CAPI3REF: SQL Keyword Checking
85698569
**
85708570
** These routines provide access to the set of SQL language keywords
8571
-** recognized by SQLite. Applications can uses these routines to determine
8571
+** recognized by SQLite. Applications can use these routines to determine
85728572
** whether or not a specific identifier needs to be escaped (for example,
85738573
** by enclosing in double-quotes) so as not to confuse the parser.
85748574
**
85758575
** The sqlite3_keyword_count() interface returns the number of distinct
85768576
** keywords understood by SQLite.
@@ -8734,11 +8734,11 @@
87348734
**
87358735
** ^The [sqlite3_str_value(X)] method returns a pointer to the current
87368736
** content of the dynamic string under construction in X. The value
87378737
** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
87388738
** and might be freed or altered by any subsequent method on the same
8739
-** [sqlite3_str] object. Applications must not used the pointer returned
8739
+** [sqlite3_str] object. Applications must not use the pointer returned by
87408740
** [sqlite3_str_value(X)] after any subsequent method call on the same
87418741
** object. ^Applications may change the content of the string returned
87428742
** by [sqlite3_str_value(X)] as long as they do not write into any bytes
87438743
** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
87448744
** write any byte after any subsequent sqlite3_str method call.
@@ -8820,11 +8820,11 @@
88208820
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
88218821
** <dd>This parameter returns the number of bytes of page cache
88228822
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
88238823
** buffer and where forced to overflow to [sqlite3_malloc()]. The
88248824
** returned value includes allocations that overflowed because they
8825
-** where too large (they were larger than the "sz" parameter to
8825
+** were too large (they were larger than the "sz" parameter to
88268826
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
88278827
** no space was left in the page cache.</dd>)^
88288828
**
88298829
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
88308830
** <dd>This parameter records the largest memory allocation request
@@ -8904,53 +8904,55 @@
89048904
** checked out.</dd>)^
89058905
**
89068906
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
89078907
** <dd>This parameter returns the number of malloc attempts that were
89088908
** satisfied using lookaside memory. Only the high-water value is meaningful;
8909
-** the current value is always zero.)^
8909
+** the current value is always zero.</dd>)^
89108910
**
89118911
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
89128912
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
8913
-** <dd>This parameter returns the number malloc attempts that might have
8913
+** <dd>This parameter returns the number of malloc attempts that might have
89148914
** been satisfied using lookaside memory but failed due to the amount of
89158915
** memory requested being larger than the lookaside slot size.
89168916
** Only the high-water value is meaningful;
8917
-** the current value is always zero.)^
8917
+** the current value is always zero.</dd>)^
89188918
**
89198919
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
89208920
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
8921
-** <dd>This parameter returns the number malloc attempts that might have
8921
+** <dd>This parameter returns the number of malloc attempts that might have
89228922
** been satisfied using lookaside memory but failed due to all lookaside
89238923
** memory already being in use.
89248924
** Only the high-water value is meaningful;
8925
-** the current value is always zero.)^
8925
+** the current value is always zero.</dd>)^
89268926
**
89278927
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
89288928
** <dd>This parameter returns the approximate number of bytes of heap
89298929
** memory used by all pager caches associated with the database connection.)^
89308930
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
8931
+** </dd>
89318932
**
89328933
** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
89338934
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
89348935
** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
89358936
** pager cache is shared between two or more connections the bytes of heap
89368937
** memory used by that pager cache is divided evenly between the attached
89378938
** connections.)^ In other words, if none of the pager caches associated
89388939
** with the database connection are shared, this request returns the same
8939
-** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
8940
+** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are
89408941
** shared, the value returned by this call will be smaller than that returned
89418942
** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
8942
-** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
8943
+** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
89438944
**
89448945
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
89458946
** <dd>This parameter returns the approximate number of bytes of heap
89468947
** memory used to store the schema for all databases associated
89478948
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
89488949
** ^The full amount of memory used by the schemas is reported, even if the
89498950
** schema memory is shared with other database connections due to
89508951
** [shared cache mode] being enabled.
89518952
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
8953
+** </dd>
89528954
**
89538955
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
89548956
** <dd>This parameter returns the approximate number of bytes of heap
89558957
** and lookaside memory used by all prepared statements associated with
89568958
** the database connection.)^
@@ -8983,11 +8985,11 @@
89838985
** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
89848986
** <dd>This parameter returns the number of dirty cache entries that have
89858987
** been written to disk in the middle of a transaction due to the page
89868988
** cache overflowing. Transactions are more efficient if they are written
89878989
** to disk all at once. When pages spill mid-transaction, that introduces
8988
-** additional overhead. This parameter can be used help identify
8990
+** additional overhead. This parameter can be used to help identify
89898991
** inefficiencies that can be resolved by increasing the cache size.
89908992
** </dd>
89918993
**
89928994
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
89938995
** <dd>This parameter returns zero for the current value if and only if
@@ -9054,48 +9056,48 @@
90549056
** careful use of indices.</dd>
90559057
**
90569058
** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
90579059
** <dd>^This is the number of sort operations that have occurred.
90589060
** A non-zero value in this counter may indicate an opportunity to
9059
-** improvement performance through careful use of indices.</dd>
9061
+** improve performance through careful use of indices.</dd>
90609062
**
90619063
** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
90629064
** <dd>^This is the number of rows inserted into transient indices that
90639065
** were created automatically in order to help joins run faster.
90649066
** A non-zero value in this counter may indicate an opportunity to
9065
-** improvement performance by adding permanent indices that do not
9067
+** improve performance by adding permanent indices that do not
90669068
** need to be reinitialized each time the statement is run.</dd>
90679069
**
90689070
** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
90699071
** <dd>^This is the number of virtual machine operations executed
90709072
** by the prepared statement if that number is less than or equal
90719073
** to 2147483647. The number of virtual machine operations can be
90729074
** used as a proxy for the total work done by the prepared statement.
90739075
** If the number of virtual machine operations exceeds 2147483647
9074
-** then the value returned by this statement status code is undefined.
9076
+** then the value returned by this statement status code is undefined.</dd>
90759077
**
90769078
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
90779079
** <dd>^This is the number of times that the prepare statement has been
90789080
** automatically regenerated due to schema changes or changes to
9079
-** [bound parameters] that might affect the query plan.
9081
+** [bound parameters] that might affect the query plan.</dd>
90809082
**
90819083
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
90829084
** <dd>^This is the number of times that the prepared statement has
90839085
** been run. A single "run" for the purposes of this counter is one
90849086
** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
90859087
** The counter is incremented on the first [sqlite3_step()] call of each
9086
-** cycle.
9088
+** cycle.</dd>
90879089
**
90889090
** [[SQLITE_STMTSTATUS_FILTER_MISS]]
90899091
** [[SQLITE_STMTSTATUS_FILTER HIT]]
90909092
** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
90919093
** SQLITE_STMTSTATUS_FILTER_MISS</dt>
90929094
** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
90939095
** step was bypassed because a Bloom filter returned not-found. The
90949096
** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
90959097
** times that the Bloom filter returned a find, and thus the join step
9096
-** had to be processed as normal.
9098
+** had to be processed as normal.</dd>
90979099
**
90989100
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
90999101
** <dd>^This is the approximate number of bytes of heap memory
91009102
** used to store the prepared statement. ^This value is not actually
91019103
** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9196,31 +9198,31 @@
91969198
** [[the xCreate() page cache methods]]
91979199
** ^SQLite invokes the xCreate() method to construct a new cache instance.
91989200
** SQLite will typically create one cache instance for each open database file,
91999201
** though this is not guaranteed. ^The
92009202
** first parameter, szPage, is the size in bytes of the pages that must
9201
-** be allocated by the cache. ^szPage will always a power of two. ^The
9203
+** be allocated by the cache. ^szPage will always be a power of two. ^The
92029204
** second parameter szExtra is a number of bytes of extra storage
9203
-** associated with each page cache entry. ^The szExtra parameter will
9205
+** associated with each page cache entry. ^The szExtra parameter will be
92049206
** a number less than 250. SQLite will use the
92059207
** extra szExtra bytes on each page to store metadata about the underlying
92069208
** database page on disk. The value passed into szExtra depends
92079209
** on the SQLite version, the target platform, and how SQLite was compiled.
92089210
** ^The third argument to xCreate(), bPurgeable, is true if the cache being
92099211
** created will be used to cache database pages of a file stored on disk, or
92109212
** false if it is used for an in-memory database. The cache implementation
9211
-** does not have to do anything special based with the value of bPurgeable;
9213
+** does not have to do anything special based upon the value of bPurgeable;
92129214
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
92139215
** never invoke xUnpin() except to deliberately delete a page.
92149216
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
92159217
** false will always have the "discard" flag set to true.
9216
-** ^Hence, a cache created with bPurgeable false will
9218
+** ^Hence, a cache created with bPurgeable set to false will
92179219
** never contain any unpinned pages.
92189220
**
92199221
** [[the xCachesize() page cache method]]
92209222
** ^(The xCachesize() method may be called at any time by SQLite to set the
9221
-** suggested maximum cache-size (number of pages stored by) the cache
9223
+** suggested maximum cache-size (number of pages stored) for the cache
92229224
** instance passed as the first argument. This is the value configured using
92239225
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
92249226
** parameter, the implementation is not required to do anything with this
92259227
** value; it is advisory only.
92269228
**
@@ -9243,16 +9245,16 @@
92439245
**
92449246
** If the requested page is already in the page cache, then the page cache
92459247
** implementation must return a pointer to the page buffer with its content
92469248
** intact. If the requested page is not already in the cache, then the
92479249
** cache implementation should use the value of the createFlag
9248
-** parameter to help it determined what action to take:
9250
+** parameter to help it determine what action to take:
92499251
**
92509252
** <table border=1 width=85% align=center>
92519253
** <tr><th> createFlag <th> Behavior when page is not already in cache
92529254
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9253
-** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
9255
+** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.
92549256
** Otherwise return NULL.
92559257
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
92569258
** NULL if allocating a new page is effectively impossible.
92579259
** </table>
92589260
**
@@ -9265,11 +9267,11 @@
92659267
** [[the xUnpin() page cache method]]
92669268
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
92679269
** as its second argument. If the third parameter, discard, is non-zero,
92689270
** then the page must be evicted from the cache.
92699271
** ^If the discard parameter is
9270
-** zero, then the page may be discarded or retained at the discretion of
9272
+** zero, then the page may be discarded or retained at the discretion of the
92719273
** page cache implementation. ^The page cache implementation
92729274
** may choose to evict unpinned pages at any time.
92739275
**
92749276
** The cache must not perform any reference counting. A single
92759277
** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9283,11 +9285,11 @@
92839285
** to be pinned.
92849286
**
92859287
** When SQLite calls the xTruncate() method, the cache must discard all
92869288
** existing cache entries with page numbers (keys) greater than or equal
92879289
** to the value of the iLimit parameter passed to xTruncate(). If any
9288
-** of these pages are pinned, they are implicitly unpinned, meaning that
9290
+** of these pages are pinned, they become implicitly unpinned, meaning that
92899291
** they can be safely discarded.
92909292
**
92919293
** [[the xDestroy() page cache method]]
92929294
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
92939295
** All resources associated with the specified cache should be freed. ^After
@@ -9463,11 +9465,11 @@
94639465
** sqlite3_backup_step(), the source database may be modified mid-way
94649466
** through the backup process. ^If the source database is modified by an
94659467
** external process or via a database connection other than the one being
94669468
** used by the backup operation, then the backup will be automatically
94679469
** restarted by the next call to sqlite3_backup_step(). ^If the source
9468
-** database is modified by the using the same database connection as is used
9470
+** database is modified by using the same database connection as is used
94699471
** by the backup operation, then the backup database is automatically
94709472
** updated at the same time.
94719473
**
94729474
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
94739475
**
@@ -9480,11 +9482,11 @@
94809482
** active write-transaction on the destination database is rolled back.
94819483
** The [sqlite3_backup] object is invalid
94829484
** and may not be used following a call to sqlite3_backup_finish().
94839485
**
94849486
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9485
-** sqlite3_backup_step() errors occurred, regardless or whether or not
9487
+** sqlite3_backup_step() errors occurred, regardless of whether or not
94869488
** sqlite3_backup_step() completed.
94879489
** ^If an out-of-memory condition or IO error occurred during any prior
94889490
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
94899491
** sqlite3_backup_finish() returns the corresponding [error code].
94909492
**
@@ -9582,11 +9584,11 @@
95829584
** identity of the database connection (the blocking connection) that
95839585
** has locked the required resource is stored internally. ^After an
95849586
** application receives an SQLITE_LOCKED error, it may call the
95859587
** sqlite3_unlock_notify() method with the blocked connection handle as
95869588
** the first argument to register for a callback that will be invoked
9587
-** when the blocking connections current transaction is concluded. ^The
9589
+** when the blocking connection's current transaction is concluded. ^The
95889590
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
95899591
** call that concludes the blocking connection's transaction.
95909592
**
95919593
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
95929594
** there is a chance that the blocking connection will have already
@@ -9602,11 +9604,11 @@
96029604
** ^(There may be at most one unlock-notify callback registered by a
96039605
** blocked connection. If sqlite3_unlock_notify() is called when the
96049606
** blocked connection already has a registered unlock-notify callback,
96059607
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
96069608
** called with a NULL pointer as its second argument, then any existing
9607
-** unlock-notify callback is canceled. ^The blocked connections
9609
+** unlock-notify callback is canceled. ^The blocked connection's
96089610
** unlock-notify callback may also be canceled by closing the blocked
96099611
** connection using [sqlite3_close()].
96109612
**
96119613
** The unlock-notify callback is not reentrant. If an application invokes
96129614
** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10000,11 +10002,11 @@
1000010002
** where X is an integer. If X is zero, then the [virtual table] whose
1000110003
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
1000210004
** support constraints. In this configuration (which is the default) if
1000310005
** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
1000410006
** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10005
-** specified as part of the users SQL statement, regardless of the actual
10007
+** specified as part of the user's SQL statement, regardless of the actual
1000610008
** ON CONFLICT mode specified.
1000710009
**
1000810010
** If X is non-zero, then the virtual table implementation guarantees
1000910011
** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
1001010012
** any modifications to internal or persistent data structures have been made.
@@ -10034,11 +10036,11 @@
1003410036
** </dd>
1003510037
**
1003610038
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
1003710039
** <dd>Calls of the form
1003810040
** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10039
-** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10041
+** [xConnect] or [xCreate] methods of a [virtual table] implementation
1004010042
** identify that virtual table as being safe to use from within triggers
1004110043
** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
1004210044
** virtual table can do no serious harm even if it is controlled by a
1004310045
** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
1004410046
** flag unless absolutely necessary.
@@ -10202,21 +10204,21 @@
1020210204
** <tr><td>2<td>no<td>yes<td>yes
1020310205
** <tr><td>3<td>yes<td>yes<td>yes
1020410206
** </table>
1020510207
**
1020610208
** ^For the purposes of comparing virtual table output values to see if the
10207
-** values are same value for sorting purposes, two NULL values are considered
10209
+** values are the same value for sorting purposes, two NULL values are considered
1020810210
** to be the same. In other words, the comparison operator is "IS"
1020910211
** (or "IS NOT DISTINCT FROM") and not "==".
1021010212
**
1021110213
** If a virtual table implementation is unable to meet the requirements
1021210214
** specified above, then it must not set the "orderByConsumed" flag in the
1021310215
** [sqlite3_index_info] object or an incorrect answer may result.
1021410216
**
1021510217
** ^A virtual table implementation is always free to return rows in any order
1021610218
** it wants, as long as the "orderByConsumed" flag is not set. ^When the
10217
-** the "orderByConsumed" flag is unset, the query planner will add extra
10219
+** "orderByConsumed" flag is unset, the query planner will add extra
1021810220
** [bytecode] to ensure that the final results returned by the SQL query are
1021910221
** ordered correctly. The use of the "orderByConsumed" flag and the
1022010222
** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
1022110223
** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
1022210224
** flag might help queries against a virtual table to run faster. Being
@@ -10309,11 +10311,11 @@
1030910311
**
1031010312
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
1031110313
** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
1031210314
** xFilter method which invokes these routines, and specifically
1031310315
** a parameter that was previously selected for all-at-once IN constraint
10314
-** processing use the [sqlite3_vtab_in()] interface in the
10316
+** processing using the [sqlite3_vtab_in()] interface in the
1031510317
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
1031610318
** an xFilter argument that was selected for all-at-once IN constraint
1031710319
** processing, then these routines return [SQLITE_ERROR].)^
1031810320
**
1031910321
** ^(Use these routines to access all values on the right-hand side
@@ -10364,11 +10366,11 @@
1036410366
** right-hand operand is not known, then *V is set to a NULL pointer.
1036510367
** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
1036610368
** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
1036710369
** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
1036810370
** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10369
-** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10371
+** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if
1037010372
** something goes wrong.
1037110373
**
1037210374
** The sqlite3_vtab_rhs_value() interface is usually only successful if
1037310375
** the right-hand operand of a constraint is a literal value in the original
1037410376
** SQL statement. If the right-hand operand is an expression or a reference
@@ -10392,12 +10394,12 @@
1039210394
/*
1039310395
** CAPI3REF: Conflict resolution modes
1039410396
** KEYWORDS: {conflict resolution mode}
1039510397
**
1039610398
** These constants are returned by [sqlite3_vtab_on_conflict()] to
10397
-** inform a [virtual table] implementation what the [ON CONFLICT] mode
10398
-** is for the SQL statement being evaluated.
10399
+** inform a [virtual table] implementation of the [ON CONFLICT] mode
10400
+** for the SQL statement being evaluated.
1039910401
**
1040010402
** Note that the [SQLITE_IGNORE] constant is also used as a potential
1040110403
** return value from the [sqlite3_set_authorizer()] callback and that
1040210404
** [SQLITE_ABORT] is also a [result code].
1040310405
*/
@@ -10433,43 +10435,43 @@
1043310435
** to the total number of rows examined by all iterations of the X-th loop.</dd>
1043410436
**
1043510437
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
1043610438
** <dd>^The "double" variable pointed to by the V parameter will be set to the
1043710439
** query planner's estimate for the average number of rows output from each
10438
-** iteration of the X-th loop. If the query planner's estimates was accurate,
10440
+** iteration of the X-th loop. If the query planner's estimate was accurate,
1043910441
** then this value will approximate the quotient NVISIT/NLOOP and the
1044010442
** product of this value for all prior loops with the same SELECTID will
10441
-** be the NLOOP value for the current loop.
10443
+** be the NLOOP value for the current loop.</dd>
1044210444
**
1044310445
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
1044410446
** <dd>^The "const char *" variable pointed to by the V parameter will be set
1044510447
** to a zero-terminated UTF-8 string containing the name of the index or table
10446
-** used for the X-th loop.
10448
+** used for the X-th loop.</dd>
1044710449
**
1044810450
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
1044910451
** <dd>^The "const char *" variable pointed to by the V parameter will be set
1045010452
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10451
-** description for the X-th loop.
10453
+** description for the X-th loop.</dd>
1045210454
**
1045310455
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
1045410456
** <dd>^The "int" variable pointed to by the V parameter will be set to the
1045510457
** id for the X-th query plan element. The id value is unique within the
1045610458
** statement. The select-id is the same value as is output in the first
10457
-** column of an [EXPLAIN QUERY PLAN] query.
10459
+** column of an [EXPLAIN QUERY PLAN] query.</dd>
1045810460
**
1045910461
** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
1046010462
** <dd>The "int" variable pointed to by the V parameter will be set to the
10461
-** the id of the parent of the current query element, if applicable, or
10463
+** id of the parent of the current query element, if applicable, or
1046210464
** to zero if the query element has no parent. This is the same value as
10463
-** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10465
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>
1046410466
**
1046510467
** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
1046610468
** <dd>The sqlite3_int64 output value is set to the number of cycles,
1046710469
** according to the processor time-stamp counter, that elapsed while the
1046810470
** query element was being processed. This value is not available for
1046910471
** all query elements - if it is unavailable the output variable is
10470
-** set to -1.
10472
+** set to -1.</dd>
1047110473
** </dl>
1047210474
*/
1047310475
#define SQLITE_SCANSTAT_NLOOP 0
1047410476
#define SQLITE_SCANSTAT_NVISIT 1
1047510477
#define SQLITE_SCANSTAT_EST 2
@@ -10506,12 +10508,12 @@
1050610508
** the EXPLAIN QUERY PLAN output) are available. Invoking API
1050710509
** sqlite3_stmt_scanstatus() is equivalent to calling
1050810510
** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
1050910511
**
1051010512
** Parameter "idx" identifies the specific query element to retrieve statistics
10511
-** for. Query elements are numbered starting from zero. A value of -1 may be
10512
-** to query for statistics regarding the entire query. ^If idx is out of range
10513
+** for. Query elements are numbered starting from zero. A value of -1 may
10514
+** retrieve statistics for the entire query. ^If idx is out of range
1051310515
** - less than -1 or greater than or equal to the total number of query
1051410516
** elements used to implement the statement - a non-zero value is returned and
1051510517
** the variable that pOut points to is unchanged.
1051610518
**
1051710519
** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10550,11 +10552,11 @@
1055010552
/*
1055110553
** CAPI3REF: Flush caches to disk mid-transaction
1055210554
** METHOD: sqlite3
1055310555
**
1055410556
** ^If a write-transaction is open on [database connection] D when the
10555
-** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10557
+** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
1055610558
** pages in the pager-cache that are not currently in use are written out
1055710559
** to disk. A dirty page may be in use if a database cursor created by an
1055810560
** active SQL statement is reading from it, or if it is page 1 of a database
1055910561
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
1056010562
** interface flushes caches for all schemas - "main", "temp", and
@@ -10664,12 +10666,12 @@
1066410666
** operation; or 1 for inserts, updates, or deletes invoked by top-level
1066510667
** triggers; or 2 for changes resulting from triggers called by top-level
1066610668
** triggers; and so forth.
1066710669
**
1066810670
** When the [sqlite3_blob_write()] API is used to update a blob column,
10669
-** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10670
-** in this case the new values are not available. In this case, when a
10671
+** the pre-update hook is invoked with SQLITE_DELETE, because
10672
+** the new values are not yet available. In this case, when a
1067110673
** callback made with op==SQLITE_DELETE is actually a write using the
1067210674
** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
1067310675
** the index of the column being written. In other cases, where the
1067410676
** pre-update hook is being invoked for some other reason, including a
1067510677
** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -10918,20 +10920,20 @@
1091810920
** is written into *P.
1091910921
**
1092010922
** For an ordinary on-disk database file, the serialization is just a
1092110923
** copy of the disk file. For an in-memory database or a "TEMP" database,
1092210924
** the serialization is the same sequence of bytes which would be written
10923
-** to disk if that database where backed up to disk.
10925
+** to disk if that database were backed up to disk.
1092410926
**
1092510927
** The usual case is that sqlite3_serialize() copies the serialization of
1092610928
** the database into memory obtained from [sqlite3_malloc64()] and returns
1092710929
** a pointer to that memory. The caller is responsible for freeing the
1092810930
** returned value to avoid a memory leak. However, if the F argument
1092910931
** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
1093010932
** are made, and the sqlite3_serialize() function will return a pointer
1093110933
** to the contiguous memory representation of the database that SQLite
10932
-** is currently using for that database, or NULL if the no such contiguous
10934
+** is currently using for that database, or NULL if no such contiguous
1093310935
** memory representation of the database exists. A contiguous memory
1093410936
** representation of the database will usually only exist if there has
1093510937
** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
1093610938
** values of D and S.
1093710939
** The size of the database is written into *P even if the
@@ -10998,11 +11000,11 @@
1099811000
**
1099911001
** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
1100011002
** database is currently in a read transaction or is involved in a backup
1100111003
** operation.
1100211004
**
11003
-** It is not possible to deserialized into the TEMP database. If the
11005
+** It is not possible to deserialize into the TEMP database. If the
1100411006
** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
1100511007
** function returns SQLITE_ERROR.
1100611008
**
1100711009
** The deserialized database should not be in [WAL mode]. If the database
1100811010
** is in WAL mode, then any attempt to use the database file will result
@@ -11020,19 +11022,19 @@
1102011022
*/
1102111023
SQLITE_API int sqlite3_deserialize(
1102211024
sqlite3 *db, /* The database connection */
1102311025
const char *zSchema, /* Which DB to reopen with the deserialization */
1102411026
unsigned char *pData, /* The serialized database content */
11025
- sqlite3_int64 szDb, /* Number bytes in the deserialization */
11027
+ sqlite3_int64 szDb, /* Number of bytes in the deserialization */
1102611028
sqlite3_int64 szBuf, /* Total size of buffer pData[] */
1102711029
unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
1102811030
);
1102911031
1103011032
/*
1103111033
** CAPI3REF: Flags for sqlite3_deserialize()
1103211034
**
11033
-** The following are allowed values for 6th argument (the F argument) to
11035
+** The following are allowed values for the 6th argument (the F argument) to
1103411036
** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
1103511037
**
1103611038
** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
1103711039
** in the P argument is held in memory obtained from [sqlite3_malloc64()]
1103811040
** and that SQLite should take ownership of this memory and automatically
@@ -11765,11 +11767,11 @@
1176511767
** CAPI3REF: Flags for sqlite3changeset_start_v2
1176611768
**
1176711769
** The following flags may passed via the 4th parameter to
1176811770
** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
1176911771
**
11770
-** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
11772
+** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
1177111773
** Invert the changeset while iterating through it. This is equivalent to
1177211774
** inverting a changeset using sqlite3changeset_invert() before applying it.
1177311775
** It is an error to specify this flag with a patchset.
1177411776
*/
1177511777
#define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12310,17 +12312,26 @@
1231012312
** Apply a changeset or patchset to a database. These functions attempt to
1231112313
** update the "main" database attached to handle db with the changes found in
1231212314
** the changeset passed via the second and third arguments.
1231312315
**
1231412316
** The fourth argument (xFilter) passed to these functions is the "filter
12315
-** callback". If it is not NULL, then for each table affected by at least one
12316
-** change in the changeset, the filter callback is invoked with
12317
-** the table name as the second argument, and a copy of the context pointer
12318
-** passed as the sixth argument as the first. If the "filter callback"
12319
-** returns zero, then no attempt is made to apply any changes to the table.
12320
-** Otherwise, if the return value is non-zero or the xFilter argument to
12321
-** is NULL, all changes related to the table are attempted.
12317
+** callback". This may be passed NULL, in which case all changes in the
12318
+** changeset are applied to the database. For sqlite3changeset_apply() and
12319
+** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
12320
+** for each table affected by at least one change in the changeset. In this
12321
+** case the table name is passed as the second argument, and a copy of
12322
+** the context pointer passed as the sixth argument to apply() or apply_v2()
12323
+** as the first. If the "filter callback" returns zero, then no attempt is
12324
+** made to apply any changes to the table. Otherwise, if the return value is
12325
+** non-zero, all changes related to the table are attempted.
12326
+**
12327
+** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once
12328
+** per change. The second argument in this case is an sqlite3_changeset_iter
12329
+** that may be queried using the usual APIs for the details of the current
12330
+** change. If the "filter callback" returns zero in this case, then no attempt
12331
+** is made to apply the current change. If it returns non-zero, the change
12332
+** is applied.
1232212333
**
1232312334
** For each table that is not excluded by the filter callback, this function
1232412335
** tests that the target database contains a compatible table. A table is
1232512336
** considered compatible if all of the following are true:
1232612337
**
@@ -12337,15 +12348,15 @@
1233712348
** changes associated with the table are applied. A warning message is issued
1233812349
** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
1233912350
** one such warning is issued for each table in the changeset.
1234012351
**
1234112352
** For each change for which there is a compatible table, an attempt is made
12342
-** to modify the table contents according to the UPDATE, INSERT or DELETE
12343
-** change. If a change cannot be applied cleanly, the conflict handler
12344
-** function passed as the fifth argument to sqlite3changeset_apply() may be
12345
-** invoked. A description of exactly when the conflict handler is invoked for
12346
-** each type of change is below.
12353
+** to modify the table contents according to each UPDATE, INSERT or DELETE
12354
+** change that is not excluded by a filter callback. If a change cannot be
12355
+** applied cleanly, the conflict handler function passed as the fifth argument
12356
+** to sqlite3changeset_apply() may be invoked. A description of exactly when
12357
+** the conflict handler is invoked for each type of change is below.
1234712358
**
1234812359
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
1234912360
** of passing anything other than a valid function pointer as the xConflict
1235012361
** argument are undefined.
1235112362
**
@@ -12483,10 +12494,27 @@
1248312494
void *pChangeset, /* Changeset blob */
1248412495
int(*xFilter)(
1248512496
void *pCtx, /* Copy of sixth arg to _apply() */
1248612497
const char *zTab /* Table name */
1248712498
),
12499
+ int(*xConflict)(
12500
+ void *pCtx, /* Copy of sixth arg to _apply() */
12501
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12502
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
12503
+ ),
12504
+ void *pCtx, /* First argument passed to xConflict */
12505
+ void **ppRebase, int *pnRebase, /* OUT: Rebase data */
12506
+ int flags /* SESSION_CHANGESETAPPLY_* flags */
12507
+);
12508
+SQLITE_API int sqlite3changeset_apply_v3(
12509
+ sqlite3 *db, /* Apply change to "main" db of this handle */
12510
+ int nChangeset, /* Size of changeset in bytes */
12511
+ void *pChangeset, /* Changeset blob */
12512
+ int(*xFilter)(
12513
+ void *pCtx, /* Copy of sixth arg to _apply() */
12514
+ sqlite3_changeset_iter *p /* Handle describing change */
12515
+ ),
1248812516
int(*xConflict)(
1248912517
void *pCtx, /* Copy of sixth arg to _apply() */
1249012518
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1249112519
sqlite3_changeset_iter *p /* Handle describing change and conflict */
1249212520
),
@@ -12902,10 +12930,27 @@
1290212930
void *pIn, /* First arg for xInput */
1290312931
int(*xFilter)(
1290412932
void *pCtx, /* Copy of sixth arg to _apply() */
1290512933
const char *zTab /* Table name */
1290612934
),
12935
+ int(*xConflict)(
12936
+ void *pCtx, /* Copy of sixth arg to _apply() */
12937
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12938
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
12939
+ ),
12940
+ void *pCtx, /* First argument passed to xConflict */
12941
+ void **ppRebase, int *pnRebase,
12942
+ int flags
12943
+);
12944
+SQLITE_API int sqlite3changeset_apply_v3_strm(
12945
+ sqlite3 *db, /* Apply change to "main" db of this handle */
12946
+ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
12947
+ void *pIn, /* First arg for xInput */
12948
+ int(*xFilter)(
12949
+ void *pCtx, /* Copy of sixth arg to _apply() */
12950
+ sqlite3_changeset_iter *p
12951
+ ),
1290712952
int(*xConflict)(
1290812953
void *pCtx, /* Copy of sixth arg to _apply() */
1290912954
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1291012955
sqlite3_changeset_iter *p /* Handle describing change and conflict */
1291112956
),
1291212957
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -166,13 +166,13 @@
166 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
167 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
168 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
169 ** </pre></blockquote>)^
170 **
171 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
172 ** macro. ^The sqlite3_libversion() function returns a pointer to the
173 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
174 ** function is provided for use in DLLs since DLL users usually do not have
175 ** direct access to string constants within the DLL. ^The
176 ** sqlite3_libversion_number() function returns an integer equal to
177 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
178 ** a pointer to a string constant whose value is the same as the
@@ -368,11 +368,11 @@
368 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
369 ** that allows an application to run multiple statements of SQL
370 ** without having to use a lot of C code.
371 **
372 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
373 ** semicolon-separate SQL statements passed into its 2nd argument,
374 ** in the context of the [database connection] passed in as its 1st
375 ** argument. ^If the callback function of the 3rd argument to
376 ** sqlite3_exec() is not NULL, then it is invoked for each result row
377 ** coming out of the evaluated SQL statements. ^The 4th argument to
378 ** sqlite3_exec() is relayed through to the 1st argument of each
@@ -401,11 +401,11 @@
401 ** callback is an array of pointers to strings obtained as if from
402 ** [sqlite3_column_text()], one for each column. ^If an element of a
403 ** result row is NULL then the corresponding string pointer for the
404 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
405 ** sqlite3_exec() callback is an array of pointers to strings where each
406 ** entry represents the name of corresponding result column as obtained
407 ** from [sqlite3_column_name()].
408 **
409 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
410 ** to an empty string, or a pointer that contains only whitespace and/or
411 ** SQL comments, then no SQL statements are evaluated and the database
@@ -587,11 +587,11 @@
587 ** Applications should not depend on the historical behavior.
588 **
589 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
590 ** [sqlite3_open_v2()] does *not* cause the underlying database file
591 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
592 ** [sqlite3_open_v2()] has historically be a no-op and might become an
593 ** error in future versions of SQLite.
594 */
595 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
596 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
597 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -681,11 +681,11 @@
681 ** CAPI3REF: File Locking Levels
682 **
683 ** SQLite uses one of these integer values as the second
684 ** argument to calls it makes to the xLock() and xUnlock() methods
685 ** of an [sqlite3_io_methods] object. These values are ordered from
686 ** lest restrictive to most restrictive.
687 **
688 ** The argument to xLock() is always SHARED or higher. The argument to
689 ** xUnlock is either SHARED or NONE.
690 */
691 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -997,11 +997,11 @@
997 ** reason, the entire database file will be overwritten by the current
998 ** transaction. This is used by VACUUM operations.
999 **
1000 ** <li>[[SQLITE_FCNTL_VFSNAME]]
1001 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1002 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
1003 ** final bottom-level VFS are written into memory obtained from
1004 ** [sqlite3_malloc()] and the result is stored in the char* variable
1005 ** that the fourth parameter of [sqlite3_file_control()] points to.
1006 ** The caller is responsible for freeing the memory when done. As with
1007 ** all file-control actions, there is no guarantee that this will actually
@@ -1011,11 +1011,11 @@
1011 **
1012 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1013 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1014 ** [VFSes] currently in use. ^(The argument X in
1015 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1016 ** of type "[sqlite3_vfs] **". This opcodes will set *X
1017 ** to a pointer to the top-level VFS.)^
1018 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1019 ** upper-most shim only.
1020 **
1021 ** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1201,11 +1201,11 @@
1201 ** record the fact that the pages have been checkpointed.
1202 **
1203 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1204 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1205 ** whether or not there is a database client in another process with a wal-mode
1206 ** transaction open on the database or not. It is only available on unix.The
1207 ** (void*) argument passed with this file-control should be a pointer to a
1208 ** value of type (int). The integer value is set to 1 if the database is a wal
1209 ** mode database and there exists at least one client in another process that
1210 ** currently has an SQL transaction open on the database. It is set to 0 if
1211 ** the database is not a wal-mode db, or if there is no such connection in any
@@ -1626,11 +1626,11 @@
1626 **
1627 ** ^The sqlite3_initialize() routine is called internally by many other
1628 ** SQLite interfaces so that an application usually does not need to
1629 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1630 ** calls sqlite3_initialize() so the SQLite library will be automatically
1631 ** initialized when [sqlite3_open()] is called if it has not be initialized
1632 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1633 ** compile-time option, then the automatic calls to sqlite3_initialize()
1634 ** are omitted and the application must call sqlite3_initialize() directly
1635 ** prior to using any other SQLite interface. For maximum portability,
1636 ** it is recommended that applications always invoke sqlite3_initialize()
@@ -1883,25 +1883,25 @@
1883 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1884 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1885 ** The [sqlite3_mem_methods]
1886 ** structure is filled with the currently defined memory allocation routines.)^
1887 ** This option can be used to overload the default memory allocation
1888 ** routines with a wrapper that simulations memory allocation failure or
1889 ** tracks memory usage, for example. </dd>
1890 **
1891 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1892 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1893 ** type int, interpreted as a boolean, which if true provides a hint to
1894 ** SQLite that it should avoid large memory allocations if possible.
1895 ** SQLite will run faster if it is free to make large memory allocations,
1896 ** but some application might prefer to run slower in exchange for
1897 ** guarantees about memory fragmentation that are possible if large
1898 ** allocations are avoided. This hint is normally off.
1899 ** </dd>
1900 **
1901 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1902 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1903 ** interpreted as a boolean, which enables or disables the collection of
1904 ** memory allocation statistics. ^(When memory allocation statistics are
1905 ** disabled, the following SQLite interfaces become non-operational:
1906 ** <ul>
1907 ** <li> [sqlite3_hard_heap_limit64()]
@@ -1942,11 +1942,11 @@
1942 ** a page cache line is larger than sz bytes or if all of the pMem buffer
1943 ** is exhausted.
1944 ** ^If pMem is NULL and N is non-zero, then each database connection
1945 ** does an initial bulk allocation for page cache memory
1946 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1947 ** of -1024*N bytes if N is negative, . ^If additional
1948 ** page cache memory is needed beyond what is provided by the initial
1949 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1950 ** additional cache line. </dd>
1951 **
1952 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -1971,11 +1971,11 @@
1971 **
1972 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1973 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1974 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1975 ** The argument specifies alternative low-level mutex routines to be used
1976 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1977 ** the content of the [sqlite3_mutex_methods] structure before the call to
1978 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1979 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1980 ** the entire mutexing subsystem is omitted from the build and hence calls to
1981 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2013,11 +2013,11 @@
2013 ** the interface to a custom page cache implementation.)^
2014 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2015 **
2016 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2017 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2018 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
2019 ** the current page cache implementation into that object.)^ </dd>
2020 **
2021 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2022 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2023 ** global [error log].
@@ -2030,11 +2030,11 @@
2030 ** passed through as the first parameter to the application-defined logger
2031 ** function whenever that function is invoked. ^The second parameter to
2032 ** the logger function is a copy of the first parameter to the corresponding
2033 ** [sqlite3_log()] call and is intended to be a [result code] or an
2034 ** [extended result code]. ^The third parameter passed to the logger is
2035 ** log message after formatting via [sqlite3_snprintf()].
2036 ** The SQLite logging interface is not reentrant; the logger function
2037 ** supplied by the application must not invoke any SQLite interface.
2038 ** In a multi-threaded application, the application-defined logger
2039 ** function must be threadsafe. </dd>
2040 **
@@ -2221,11 +2221,11 @@
2221 ** CAPI3REF: Database Connection Configuration Options
2222 **
2223 ** These constants are the available integer configuration options that
2224 ** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2225 **
2226 ** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2227 ** variable number of parameters, though always at least two. The number of
2228 ** parameters passed into sqlite3_db_config() depends on which of these
2229 ** constants is given as the second parameter. This documentation page
2230 ** refers to parameters beyond the second as "arguments". Thus, when this
2231 ** page says "the N-th argument" it means "the N-th parameter past the
@@ -2355,12 +2355,12 @@
2355 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2356 ** There must be two additional arguments.
2357 ** When the first argument to this interface is 1, then only the C-API is
2358 ** enabled and the SQL function remains disabled. If the first argument to
2359 ** this interface is 0, then both the C-API and the SQL function are disabled.
2360 ** If the first argument is -1, then no changes are made to state of either the
2361 ** C-API or the SQL function.
2362 ** The second parameter is a pointer to an integer into which
2363 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2364 ** is disabled or enabled following this call. The second parameter may
2365 ** be a NULL pointer, in which case the new setting is not reported back.
2366 ** </dd>
@@ -2474,11 +2474,11 @@
2474 ** </dd>
2475 **
2476 ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2477 ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2478 ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2479 ** the legacy behavior of the [ALTER TABLE RENAME] command such it
2480 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2481 ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2482 ** additional information. This feature can also be turned on and off
2483 ** using the [PRAGMA legacy_alter_table] statement.
2484 ** </dd>
@@ -2523,11 +2523,11 @@
2523 **
2524 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2525 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2526 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2527 ** the legacy file format flag. When activated, this flag causes all newly
2528 ** created database file to have a schema format version number (the 4-byte
2529 ** integer found at offset 44 into the database header) of 1. This in turn
2530 ** means that the resulting database file will be readable and writable by
2531 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2532 ** newly created databases are generally not understandable by SQLite versions
2533 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2550,11 +2550,11 @@
2550 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2551 ** statistics. For statistics to be collected, the flag must be set on
2552 ** the database handle both when the SQL statement is prepared and when it
2553 ** is stepped. The flag is set (collection of statistics is enabled)
2554 ** by default. <p>This option takes two arguments: an integer and a pointer to
2555 ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2556 ** leave unchanged the statement scanstatus option. If the second argument
2557 ** is not NULL, then the value of the statement scanstatus setting after
2558 ** processing the first argument is written into the integer that the second
2559 ** argument points to.
2560 ** </dd>
@@ -2593,12 +2593,12 @@
2593 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2594 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2595 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2596 ** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2597 ** This capability is enabled by default. Applications can disable or
2598 ** reenable this capability using the current DBCONFIG option. If the
2599 ** the this capability is disabled, the [ATTACH] command will still work,
2600 ** but the database will be opened read-only. If this option is disabled,
2601 ** then the ability to create a new database using [ATTACH] is also disabled,
2602 ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2603 ** option.<p>
2604 ** This option takes two arguments which are an integer and a pointer
@@ -2628,11 +2628,11 @@
2628 **
2629 ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2630 **
2631 ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2632 ** overall call to [sqlite3_db_config()] has a total of four parameters.
2633 ** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2634 ** The second argument is a pointer to an integer. If the first argument is 1,
2635 ** then the option becomes enabled. If the first integer argument is 0, then the
2636 ** option is disabled. If the first argument is -1, then the option setting
2637 ** is unchanged. The second argument, the pointer to an integer, may be NULL.
2638 ** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -2918,11 +2918,11 @@
2918 ** and comments that follow the final semicolon are ignored.
2919 **
2920 ** ^These routines return 0 if the statement is incomplete. ^If a
2921 ** memory allocation fails, then SQLITE_NOMEM is returned.
2922 **
2923 ** ^These routines do not parse the SQL statements thus
2924 ** will not detect syntactically incorrect SQL.
2925 **
2926 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2927 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2928 ** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3035,11 +3035,11 @@
3035 ** Passing 0 to this function disables blocking locks altogether. Passing
3036 ** -1 to this function requests that the VFS blocks for a long time -
3037 ** indefinitely if possible. The results of passing any other negative value
3038 ** are undefined.
3039 **
3040 ** Internally, each SQLite database handle store two timeout values - the
3041 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3042 ** support blocking locks) and the setlk-timeout (used for blocking locks
3043 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3044 ** values, this function sets only the setlk-timeout value. Therefore,
3045 ** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3065,11 +3065,11 @@
3065 ** METHOD: sqlite3
3066 **
3067 ** This is a legacy interface that is preserved for backwards compatibility.
3068 ** Use of this interface is not recommended.
3069 **
3070 ** Definition: A <b>result table</b> is memory data structure created by the
3071 ** [sqlite3_get_table()] interface. A result table records the
3072 ** complete query results from one or more queries.
3073 **
3074 ** The table conceptually has a number of rows and columns. But
3075 ** these numbers are not part of the result table itself. These
@@ -3208,11 +3208,11 @@
3208 ** of a signed 32-bit integer.
3209 **
3210 ** ^Calling sqlite3_free() with a pointer previously returned
3211 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3212 ** that it might be reused. ^The sqlite3_free() routine is
3213 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
3214 ** to sqlite3_free() is harmless. After being freed, memory
3215 ** should neither be read nor written. Even reading previously freed
3216 ** memory might result in a segmentation fault or other severe error.
3217 ** Memory corruption, a segmentation fault, or other severe error
3218 ** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3226,17 +3226,17 @@
3226 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3227 ** negative then the behavior is exactly the same as calling
3228 ** sqlite3_free(X).
3229 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3230 ** of at least N bytes in size or NULL if insufficient memory is available.
3231 ** ^If M is the size of the prior allocation, then min(N,M) bytes
3232 ** of the prior allocation are copied into the beginning of buffer returned
3233 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
3234 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3235 ** prior allocation is not freed.
3236 **
3237 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
3238 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3239 ** of a 32-bit signed integer.
3240 **
3241 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3242 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3282,11 +3282,11 @@
3282 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
3283 ** value of [sqlite3_memory_used()] since the high-water mark
3284 ** was last reset. ^The values returned by [sqlite3_memory_used()] and
3285 ** [sqlite3_memory_highwater()] include any overhead
3286 ** added by SQLite in its implementation of [sqlite3_malloc()],
3287 ** but not overhead added by the any underlying system library
3288 ** routines that [sqlite3_malloc()] may call.
3289 **
3290 ** ^The memory high-water mark is reset to the current value of
3291 ** [sqlite3_memory_used()] if and only if the parameter to
3292 ** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -3734,19 +3734,19 @@
3734 ** attempt to use the same database connection at the same time.
3735 ** (Mutexes will block any actual concurrency, but in this mode
3736 ** there is no harm in trying.)
3737 **
3738 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3739 ** <dd>The database is opened [shared cache] enabled, overriding
3740 ** the default shared cache setting provided by
3741 ** [sqlite3_enable_shared_cache()].)^
3742 ** The [use of shared cache mode is discouraged] and hence shared cache
3743 ** capabilities may be omitted from many builds of SQLite. In such cases,
3744 ** this option is a no-op.
3745 **
3746 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3747 ** <dd>The database is opened [shared cache] disabled, overriding
3748 ** the default shared cache setting provided by
3749 ** [sqlite3_enable_shared_cache()].)^
3750 **
3751 ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3752 ** <dd>The database connection comes up in "extended result code mode".
@@ -4077,11 +4077,11 @@
4077 ** These interfaces are provided for use by [VFS shim] implementations and
4078 ** are not useful outside of that context.
4079 **
4080 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4081 ** database filename D with corresponding journal file J and WAL file W and
4082 ** with N URI parameters key/values pairs in the array P. The result from
4083 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4084 ** is safe to pass to routines like:
4085 ** <ul>
4086 ** <li> [sqlite3_uri_parameter()],
4087 ** <li> [sqlite3_uri_boolean()],
@@ -4160,19 +4160,19 @@
4160 ** The application does not need to worry about freeing the result.
4161 ** However, the error string might be overwritten or deallocated by
4162 ** subsequent calls to other SQLite interface functions.)^
4163 **
4164 ** ^The sqlite3_errstr(E) interface returns the English-language text
4165 ** that describes the [result code] E, as UTF-8, or NULL if E is not an
4166 ** result code for which a text error message is available.
4167 ** ^(Memory to hold the error message string is managed internally
4168 ** and must not be freed by the application)^.
4169 **
4170 ** ^If the most recent error references a specific token in the input
4171 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4172 ** of the start of that token. ^The byte offset returned by
4173 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4174 ** ^If the most recent error does not reference a specific token in the input
4175 ** SQL, then the sqlite3_error_offset() function returns -1.
4176 **
4177 ** When the serialized [threading mode] is in use, it might be the
4178 ** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
4267 ** CAPI3REF: Run-Time Limit Categories
4268 ** KEYWORDS: {limit category} {*limit categories}
4269 **
4270 ** These constants define various performance limits
4271 ** that can be lowered at run-time using [sqlite3_limit()].
4272 ** The synopsis of the meanings of the various limits is shown below.
4273 ** Additional information is available at [limits | Limits in SQLite].
4274 **
4275 ** <dl>
4276 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4277 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4278 **
@@ -4333,11 +4333,11 @@
4333 #define SQLITE_LIMIT_WORKER_THREADS 11
4334
4335 /*
4336 ** CAPI3REF: Prepare Flags
4337 **
4338 ** These constants define various flags that can be passed into
4339 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4340 ** [sqlite3_prepare16_v3()] interfaces.
4341 **
4342 ** New flags may be added in future releases of SQLite.
4343 **
@@ -4420,11 +4420,11 @@
4420 ** statement is generated.
4421 ** If the caller knows that the supplied string is nul-terminated, then
4422 ** there is a small performance advantage to passing an nByte parameter that
4423 ** is the number of bytes in the input string <i>including</i>
4424 ** the nul-terminator.
4425 ** Note that nByte measure the length of the input in bytes, not
4426 ** characters, even for the UTF-16 interfaces.
4427 **
4428 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4429 ** past the end of the first SQL statement in zSql. These routines only
4430 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
4554 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4555 ** will return "SELECT 2345,NULL".)^
4556 **
4557 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4558 ** is available to hold the result, or if the result would exceed the
4559 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4560 **
4561 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4562 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4563 ** option causes sqlite3_expanded_sql() to always return NULL.
4564 **
@@ -4742,11 +4742,11 @@
4742 /*
4743 ** CAPI3REF: SQL Function Context Object
4744 **
4745 ** The context in which an SQL function executes is stored in an
4746 ** sqlite3_context object. ^A pointer to an sqlite3_context object
4747 ** is always first parameter to [application-defined SQL functions].
4748 ** The application-defined SQL function implementation will pass this
4749 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4750 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4751 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4752 ** and/or [sqlite3_set_auxdata()].
@@ -4758,11 +4758,11 @@
4758 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4759 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4760 ** METHOD: sqlite3_stmt
4761 **
4762 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763 ** literals may be replaced by a [parameter] that matches one of following
4764 ** templates:
4765 **
4766 ** <ul>
4767 ** <li> ?
4768 ** <li> ?NNN
@@ -4803,11 +4803,11 @@
4803 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4804 ** otherwise.
4805 **
4806 ** [[byte-order determination rules]] ^The byte-order of
4807 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808 ** found in first character, which is removed, or in the absence of a BOM
4809 ** the byte order is the native byte order of the host
4810 ** machine for sqlite3_bind_text16() or the byte order specified in
4811 ** the 6th parameter for sqlite3_bind_text64().)^
4812 ** ^If UTF16 input text contains invalid unicode
4813 ** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
4823 ** the behavior is undefined.
4824 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4825 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4826 ** that parameter must be the byte offset
4827 ** where the NUL terminator would occur assuming the string were NUL
4828 ** terminated. If any NUL characters occurs at byte offsets less than
4829 ** the value of the fourth parameter then the resulting string value will
4830 ** contain embedded NULs. The result of expressions involving strings
4831 ** with embedded NULs is undefined.
4832 **
4833 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
5035 /*
5036 ** CAPI3REF: Source Of Data In A Query Result
5037 ** METHOD: sqlite3_stmt
5038 **
5039 ** ^These routines provide a means to determine the database, table, and
5040 ** table column that is the origin of a particular result column in
5041 ** [SELECT] statement.
5042 ** ^The name of the database or table or column can be returned as
5043 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5044 ** the database name, the _table_ routines return the table name, and
5045 ** the origin_ routines return the column name.
@@ -5479,11 +5479,11 @@
5479 ** CAPI3REF: Destroy A Prepared Statement Object
5480 ** DESTRUCTOR: sqlite3_stmt
5481 **
5482 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5483 ** ^If the most recent evaluation of the statement encountered no errors
5484 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
5485 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5486 ** sqlite3_finalize(S) returns the appropriate [error code] or
5487 ** [extended error code].
5488 **
5489 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5604,12 +5604,12 @@
5604 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5605 ** index expressions, or the WHERE clause of partial indexes.
5606 **
5607 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5608 ** all application-defined SQL functions that do not need to be
5609 ** used inside of triggers, view, CHECK constraints, or other elements of
5610 ** the database schema. This flags is especially recommended for SQL
5611 ** functions that have side effects or reveal internal application state.
5612 ** Without this flag, an attacker might be able to modify the schema of
5613 ** a database file to include invocations of the function with parameters
5614 ** chosen by the attacker, which the application will then execute when
5615 ** the database file is opened and read.
@@ -5636,11 +5636,11 @@
5636 ** or aggregate window function. More details regarding the implementation
5637 ** of aggregate window functions are
5638 ** [user-defined window functions|available here].
5639 **
5640 ** ^(If the final parameter to sqlite3_create_function_v2() or
5641 ** sqlite3_create_window_function() is not NULL, then it is destructor for
5642 ** the application data pointer. The destructor is invoked when the function
5643 ** is deleted, either by being overloaded or when the database connection
5644 ** closes.)^ ^The destructor is also invoked if the call to
5645 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5646 ** invoked, it is passed a single argument which is a copy of the application
@@ -5711,11 +5711,11 @@
5711 );
5712
5713 /*
5714 ** CAPI3REF: Text Encodings
5715 **
5716 ** These constant define integer codes that represent the various
5717 ** text encodings supported by SQLite.
5718 */
5719 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
5720 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
5721 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
5803 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
5804 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
5805 ** result.
5806 ** Every function that invokes [sqlite3_result_subtype()] should have this
5807 ** property. If it does not, then the call to [sqlite3_result_subtype()]
5808 ** might become a no-op if the function is used as term in an
5809 ** [expression index]. On the other hand, SQL functions that never invoke
5810 ** [sqlite3_result_subtype()] should avoid setting this property, as the
5811 ** purpose of this property is to disable certain optimizations that are
5812 ** incompatible with subtypes.
5813 **
@@ -5930,11 +5930,11 @@
5930 **
5931 ** ^Within the [xUpdate] method of a [virtual table], the
5932 ** sqlite3_value_nochange(X) interface returns true if and only if
5933 ** the column corresponding to X is unchanged by the UPDATE operation
5934 ** that the xUpdate method call was invoked to implement and if
5935 ** and the prior [xColumn] method call that was invoked to extracted
5936 ** the value for that column returned without setting a result (probably
5937 ** because it queried [sqlite3_vtab_nochange()] and found that the column
5938 ** was unchanging). ^Within an [xUpdate] method, any value for which
5939 ** sqlite3_value_nochange(X) is true will in all other respects appear
5940 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6036,11 +6036,11 @@
6036 /*
6037 ** CAPI3REF: Copy And Free SQL Values
6038 ** METHOD: sqlite3_value
6039 **
6040 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6041 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
6042 ** is a [protected sqlite3_value] object even if the input is not.
6043 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
6044 ** memory allocation fails. ^If V is a [pointer value], then the result
6045 ** of sqlite3_value_dup(V) is a NULL value.
6046 **
@@ -6074,11 +6074,11 @@
6074 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
6075 ** when first called if N is less than or equal to zero or if a memory
6076 ** allocation error occurs.
6077 **
6078 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6079 ** determined by the N parameter on first successful call. Changing the
6080 ** value of N in any subsequent call to sqlite3_aggregate_context() within
6081 ** the same aggregate function instance will not resize the memory
6082 ** allocation.)^ Within the xFinal callback, it is customary to set
6083 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6084 ** pointless memory allocations occur.
@@ -6236,11 +6236,11 @@
6236 ** of as a secret key such that only code that knows the secret key is able
6237 ** to access the associated data.
6238 **
6239 ** Security Warning: These interfaces should not be exposed in scripting
6240 ** languages or in other circumstances where it might be possible for an
6241 ** an attacker to invoke them. Any agent that can invoke these interfaces
6242 ** can probably also take control of the process.
6243 **
6244 ** Database connection client data is only available for SQLite
6245 ** version 3.44.0 ([dateof:3.44.0]) and later.
6246 **
@@ -6350,11 +6350,11 @@
6350 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6351 ** is non-negative, then as many bytes (not characters) of the text
6352 ** pointed to by the 2nd parameter are taken as the application-defined
6353 ** function result. If the 3rd parameter is non-negative, then it
6354 ** must be the byte offset into the string where the NUL terminator would
6355 ** appear if the string where NUL terminated. If any NUL characters occur
6356 ** in the string at a byte offset that is less than the value of the 3rd
6357 ** parameter, then the resulting string will contain embedded NULs and the
6358 ** result of expressions operating on strings with embedded NULs is undefined.
6359 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6360 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6408,11 +6408,11 @@
6408 ** for the P parameter. ^SQLite invokes D with P as its only argument
6409 ** when SQLite is finished with P. The T parameter should be a static
6410 ** string and preferably a string literal. The sqlite3_result_pointer()
6411 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6412 **
6413 ** If these routines are called from within the different thread
6414 ** than the one containing the application-defined function that received
6415 ** the [sqlite3_context] pointer, the results are undefined.
6416 */
6417 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
6418 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -6814,11 +6814,11 @@
6814 /*
6815 ** CAPI3REF: Return The Schema Name For A Database Connection
6816 ** METHOD: sqlite3
6817 **
6818 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6819 ** for the N-th database on database connection D, or a NULL pointer of N is
6820 ** out of range. An N value of 0 means the main database file. An N of 1 is
6821 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6822 ** databases.
6823 **
6824 ** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -6909,20 +6909,20 @@
6909 **
6910 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6911 ** <dd>The SQLITE_TXN_READ state means that the database is currently
6912 ** in a read transaction. Content has been read from the database file
6913 ** but nothing in the database file has changed. The transaction state
6914 ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
6915 ** no other conflicting concurrent write transactions. The transaction
6916 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6917 ** [COMMIT].</dd>
6918 **
6919 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6920 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6921 ** in a write transaction. Content has been written to the database file
6922 ** but has not yet committed. The transaction state will change to
6923 ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6924 */
6925 #define SQLITE_TXN_NONE 0
6926 #define SQLITE_TXN_READ 1
6927 #define SQLITE_TXN_WRITE 2
6928
@@ -7199,11 +7199,11 @@
7199
7200 /*
7201 ** CAPI3REF: Impose A Limit On Heap Size
7202 **
7203 ** These interfaces impose limits on the amount of heap memory that will be
7204 ** by all database connections within a single process.
7205 **
7206 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
7207 ** soft limit on the amount of heap memory that may be allocated by SQLite.
7208 ** ^SQLite strives to keep heap memory utilization below the soft heap
7209 ** limit by reducing the number of pages held in the page cache
@@ -7257,11 +7257,11 @@
7257 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
7258 ** from the heap.
7259 ** </ul>)^
7260 **
7261 ** The circumstances under which SQLite will enforce the heap limits may
7262 ** changes in future releases of SQLite.
7263 */
7264 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7265 SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
7266
7267 /*
@@ -7372,12 +7372,12 @@
7372 ** be tried also.
7373 **
7374 ** ^The entry point is zProc.
7375 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7376 ** entry point name on its own. It first tries "sqlite3_extension_init".
7377 ** If that does not work, it constructs a name "sqlite3_X_init" where the
7378 ** X is consists of the lower-case equivalent of all ASCII alphabetic
7379 ** characters in the filename from the last "/" to the first following
7380 ** "." and omitting any initial "lib".)^
7381 ** ^The sqlite3_load_extension() interface returns
7382 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7383 ** ^If an error occurs and pzErrMsg is not 0, then the
@@ -7444,11 +7444,11 @@
7444 ** that is to be automatically loaded into all new database connections.
7445 **
7446 ** ^(Even though the function prototype shows that xEntryPoint() takes
7447 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7448 ** arguments and expects an integer result as if the signature of the
7449 ** entry point where as follows:
7450 **
7451 ** <blockquote><pre>
7452 ** &nbsp; int xEntryPoint(
7453 ** &nbsp; sqlite3 *db,
7454 ** &nbsp; const char **pzErrMsg,
@@ -7608,11 +7608,11 @@
7608 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7609 ** is true, then the constraint is assumed to be fully handled by the
7610 ** virtual table and might not be checked again by the byte code.)^ ^(The
7611 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7612 ** is left in its default setting of false, the constraint will always be
7613 ** checked separately in byte code. If the omit flag is change to true, then
7614 ** the constraint may or may not be checked in byte code. In other words,
7615 ** when the omit flag is true there is no guarantee that the constraint will
7616 ** not be checked again using byte code.)^
7617 **
7618 ** ^The idxNum and idxStr values are recorded and passed into the
@@ -7634,11 +7634,11 @@
7634 ** will be returned by the strategy.
7635 **
7636 ** The xBestIndex method may optionally populate the idxFlags field with a
7637 ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7638 ** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7639 ** output to show the idxNum has hex instead of as decimal. Another flag is
7640 ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7641 ** return at most one row.
7642 **
7643 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7644 ** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7775,11 +7775,11 @@
7775 ** by the first parameter. ^The name of the module is given by the
7776 ** second parameter. ^The third parameter is a pointer to
7777 ** the implementation of the [virtual table module]. ^The fourth
7778 ** parameter is an arbitrary client data pointer that is passed through
7779 ** into the [xCreate] and [xConnect] methods of the virtual table module
7780 ** when a new virtual table is be being created or reinitialized.
7781 **
7782 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
7783 ** is a pointer to a destructor for the pClientData. ^SQLite will
7784 ** invoke the destructor function (if it is not NULL) when SQLite
7785 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
7940 **
7941 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
7942 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
7943 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
7944 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945 ** on *ppBlob after this function it returns.
7946 **
7947 ** This function fails with SQLITE_ERROR if any of the following are true:
7948 ** <ul>
7949 ** <li> ^(Database zDb does not exist)^,
7950 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
8060 ** CAPI3REF: Return The Size Of An Open BLOB
8061 ** METHOD: sqlite3_blob
8062 **
8063 ** ^Returns the size in bytes of the BLOB accessible via the
8064 ** successfully opened [BLOB handle] in its only argument. ^The
8065 ** incremental blob I/O routines can only read or overwriting existing
8066 ** blob content; they cannot change the size of a blob.
8067 **
8068 ** This routine only works on a [BLOB handle] which has been created
8069 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8070 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -8210,11 +8210,11 @@
8210 ** function that calls sqlite3_initialize().
8211 **
8212 ** ^The sqlite3_mutex_alloc() routine allocates a new
8213 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8214 ** routine returns NULL if it is unable to allocate the requested
8215 ** mutex. The argument to sqlite3_mutex_alloc() must one of these
8216 ** integer constants:
8217 **
8218 ** <ul>
8219 ** <li> SQLITE_MUTEX_FAST
8220 ** <li> SQLITE_MUTEX_RECURSIVE
@@ -8443,11 +8443,11 @@
8443
8444 /*
8445 ** CAPI3REF: Retrieve the mutex for a database connection
8446 ** METHOD: sqlite3
8447 **
8448 ** ^This interface returns a pointer the [sqlite3_mutex] object that
8449 ** serializes access to the [database connection] given in the argument
8450 ** when the [threading mode] is Serialized.
8451 ** ^If the [threading mode] is Single-thread or Multi-thread then this
8452 ** routine returns a NULL pointer.
8453 */
@@ -8566,11 +8566,11 @@
8566
8567 /*
8568 ** CAPI3REF: SQL Keyword Checking
8569 **
8570 ** These routines provide access to the set of SQL language keywords
8571 ** recognized by SQLite. Applications can uses these routines to determine
8572 ** whether or not a specific identifier needs to be escaped (for example,
8573 ** by enclosing in double-quotes) so as not to confuse the parser.
8574 **
8575 ** The sqlite3_keyword_count() interface returns the number of distinct
8576 ** keywords understood by SQLite.
@@ -8734,11 +8734,11 @@
8734 **
8735 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
8736 ** content of the dynamic string under construction in X. The value
8737 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
8738 ** and might be freed or altered by any subsequent method on the same
8739 ** [sqlite3_str] object. Applications must not used the pointer returned
8740 ** [sqlite3_str_value(X)] after any subsequent method call on the same
8741 ** object. ^Applications may change the content of the string returned
8742 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
8743 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8744 ** write any byte after any subsequent sqlite3_str method call.
@@ -8820,11 +8820,11 @@
8820 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
8821 ** <dd>This parameter returns the number of bytes of page cache
8822 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
8823 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
8824 ** returned value includes allocations that overflowed because they
8825 ** where too large (they were larger than the "sz" parameter to
8826 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
8827 ** no space was left in the page cache.</dd>)^
8828 **
8829 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
8830 ** <dd>This parameter records the largest memory allocation request
@@ -8904,53 +8904,55 @@
8904 ** checked out.</dd>)^
8905 **
8906 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8907 ** <dd>This parameter returns the number of malloc attempts that were
8908 ** satisfied using lookaside memory. Only the high-water value is meaningful;
8909 ** the current value is always zero.)^
8910 **
8911 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
8912 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
8913 ** <dd>This parameter returns the number malloc attempts that might have
8914 ** been satisfied using lookaside memory but failed due to the amount of
8915 ** memory requested being larger than the lookaside slot size.
8916 ** Only the high-water value is meaningful;
8917 ** the current value is always zero.)^
8918 **
8919 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
8920 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
8921 ** <dd>This parameter returns the number malloc attempts that might have
8922 ** been satisfied using lookaside memory but failed due to all lookaside
8923 ** memory already being in use.
8924 ** Only the high-water value is meaningful;
8925 ** the current value is always zero.)^
8926 **
8927 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
8928 ** <dd>This parameter returns the approximate number of bytes of heap
8929 ** memory used by all pager caches associated with the database connection.)^
8930 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 
8931 **
8932 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
8933 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
8934 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
8935 ** pager cache is shared between two or more connections the bytes of heap
8936 ** memory used by that pager cache is divided evenly between the attached
8937 ** connections.)^ In other words, if none of the pager caches associated
8938 ** with the database connection are shared, this request returns the same
8939 ** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
8940 ** shared, the value returned by this call will be smaller than that returned
8941 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
8942 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
8943 **
8944 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
8945 ** <dd>This parameter returns the approximate number of bytes of heap
8946 ** memory used to store the schema for all databases associated
8947 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
8948 ** ^The full amount of memory used by the schemas is reported, even if the
8949 ** schema memory is shared with other database connections due to
8950 ** [shared cache mode] being enabled.
8951 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
 
8952 **
8953 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
8954 ** <dd>This parameter returns the approximate number of bytes of heap
8955 ** and lookaside memory used by all prepared statements associated with
8956 ** the database connection.)^
@@ -8983,11 +8985,11 @@
8983 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
8984 ** <dd>This parameter returns the number of dirty cache entries that have
8985 ** been written to disk in the middle of a transaction due to the page
8986 ** cache overflowing. Transactions are more efficient if they are written
8987 ** to disk all at once. When pages spill mid-transaction, that introduces
8988 ** additional overhead. This parameter can be used help identify
8989 ** inefficiencies that can be resolved by increasing the cache size.
8990 ** </dd>
8991 **
8992 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
8993 ** <dd>This parameter returns zero for the current value if and only if
@@ -9054,48 +9056,48 @@
9054 ** careful use of indices.</dd>
9055 **
9056 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
9057 ** <dd>^This is the number of sort operations that have occurred.
9058 ** A non-zero value in this counter may indicate an opportunity to
9059 ** improvement performance through careful use of indices.</dd>
9060 **
9061 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
9062 ** <dd>^This is the number of rows inserted into transient indices that
9063 ** were created automatically in order to help joins run faster.
9064 ** A non-zero value in this counter may indicate an opportunity to
9065 ** improvement performance by adding permanent indices that do not
9066 ** need to be reinitialized each time the statement is run.</dd>
9067 **
9068 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
9069 ** <dd>^This is the number of virtual machine operations executed
9070 ** by the prepared statement if that number is less than or equal
9071 ** to 2147483647. The number of virtual machine operations can be
9072 ** used as a proxy for the total work done by the prepared statement.
9073 ** If the number of virtual machine operations exceeds 2147483647
9074 ** then the value returned by this statement status code is undefined.
9075 **
9076 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9077 ** <dd>^This is the number of times that the prepare statement has been
9078 ** automatically regenerated due to schema changes or changes to
9079 ** [bound parameters] that might affect the query plan.
9080 **
9081 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9082 ** <dd>^This is the number of times that the prepared statement has
9083 ** been run. A single "run" for the purposes of this counter is one
9084 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
9085 ** The counter is incremented on the first [sqlite3_step()] call of each
9086 ** cycle.
9087 **
9088 ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
9089 ** [[SQLITE_STMTSTATUS_FILTER HIT]]
9090 ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
9091 ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
9092 ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
9093 ** step was bypassed because a Bloom filter returned not-found. The
9094 ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
9095 ** times that the Bloom filter returned a find, and thus the join step
9096 ** had to be processed as normal.
9097 **
9098 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
9099 ** <dd>^This is the approximate number of bytes of heap memory
9100 ** used to store the prepared statement. ^This value is not actually
9101 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9196,31 +9198,31 @@
9196 ** [[the xCreate() page cache methods]]
9197 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
9198 ** SQLite will typically create one cache instance for each open database file,
9199 ** though this is not guaranteed. ^The
9200 ** first parameter, szPage, is the size in bytes of the pages that must
9201 ** be allocated by the cache. ^szPage will always a power of two. ^The
9202 ** second parameter szExtra is a number of bytes of extra storage
9203 ** associated with each page cache entry. ^The szExtra parameter will
9204 ** a number less than 250. SQLite will use the
9205 ** extra szExtra bytes on each page to store metadata about the underlying
9206 ** database page on disk. The value passed into szExtra depends
9207 ** on the SQLite version, the target platform, and how SQLite was compiled.
9208 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
9209 ** created will be used to cache database pages of a file stored on disk, or
9210 ** false if it is used for an in-memory database. The cache implementation
9211 ** does not have to do anything special based with the value of bPurgeable;
9212 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
9213 ** never invoke xUnpin() except to deliberately delete a page.
9214 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
9215 ** false will always have the "discard" flag set to true.
9216 ** ^Hence, a cache created with bPurgeable false will
9217 ** never contain any unpinned pages.
9218 **
9219 ** [[the xCachesize() page cache method]]
9220 ** ^(The xCachesize() method may be called at any time by SQLite to set the
9221 ** suggested maximum cache-size (number of pages stored by) the cache
9222 ** instance passed as the first argument. This is the value configured using
9223 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
9224 ** parameter, the implementation is not required to do anything with this
9225 ** value; it is advisory only.
9226 **
@@ -9243,16 +9245,16 @@
9243 **
9244 ** If the requested page is already in the page cache, then the page cache
9245 ** implementation must return a pointer to the page buffer with its content
9246 ** intact. If the requested page is not already in the cache, then the
9247 ** cache implementation should use the value of the createFlag
9248 ** parameter to help it determined what action to take:
9249 **
9250 ** <table border=1 width=85% align=center>
9251 ** <tr><th> createFlag <th> Behavior when page is not already in cache
9252 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9253 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
9254 ** Otherwise return NULL.
9255 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
9256 ** NULL if allocating a new page is effectively impossible.
9257 ** </table>
9258 **
@@ -9265,11 +9267,11 @@
9265 ** [[the xUnpin() page cache method]]
9266 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9267 ** as its second argument. If the third parameter, discard, is non-zero,
9268 ** then the page must be evicted from the cache.
9269 ** ^If the discard parameter is
9270 ** zero, then the page may be discarded or retained at the discretion of
9271 ** page cache implementation. ^The page cache implementation
9272 ** may choose to evict unpinned pages at any time.
9273 **
9274 ** The cache must not perform any reference counting. A single
9275 ** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9283,11 +9285,11 @@
9283 ** to be pinned.
9284 **
9285 ** When SQLite calls the xTruncate() method, the cache must discard all
9286 ** existing cache entries with page numbers (keys) greater than or equal
9287 ** to the value of the iLimit parameter passed to xTruncate(). If any
9288 ** of these pages are pinned, they are implicitly unpinned, meaning that
9289 ** they can be safely discarded.
9290 **
9291 ** [[the xDestroy() page cache method]]
9292 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
9293 ** All resources associated with the specified cache should be freed. ^After
@@ -9463,11 +9465,11 @@
9463 ** sqlite3_backup_step(), the source database may be modified mid-way
9464 ** through the backup process. ^If the source database is modified by an
9465 ** external process or via a database connection other than the one being
9466 ** used by the backup operation, then the backup will be automatically
9467 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9468 ** database is modified by the using the same database connection as is used
9469 ** by the backup operation, then the backup database is automatically
9470 ** updated at the same time.
9471 **
9472 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9473 **
@@ -9480,11 +9482,11 @@
9480 ** active write-transaction on the destination database is rolled back.
9481 ** The [sqlite3_backup] object is invalid
9482 ** and may not be used following a call to sqlite3_backup_finish().
9483 **
9484 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9485 ** sqlite3_backup_step() errors occurred, regardless or whether or not
9486 ** sqlite3_backup_step() completed.
9487 ** ^If an out-of-memory condition or IO error occurred during any prior
9488 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9489 ** sqlite3_backup_finish() returns the corresponding [error code].
9490 **
@@ -9582,11 +9584,11 @@
9582 ** identity of the database connection (the blocking connection) that
9583 ** has locked the required resource is stored internally. ^After an
9584 ** application receives an SQLITE_LOCKED error, it may call the
9585 ** sqlite3_unlock_notify() method with the blocked connection handle as
9586 ** the first argument to register for a callback that will be invoked
9587 ** when the blocking connections current transaction is concluded. ^The
9588 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9589 ** call that concludes the blocking connection's transaction.
9590 **
9591 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9592 ** there is a chance that the blocking connection will have already
@@ -9602,11 +9604,11 @@
9602 ** ^(There may be at most one unlock-notify callback registered by a
9603 ** blocked connection. If sqlite3_unlock_notify() is called when the
9604 ** blocked connection already has a registered unlock-notify callback,
9605 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9606 ** called with a NULL pointer as its second argument, then any existing
9607 ** unlock-notify callback is canceled. ^The blocked connections
9608 ** unlock-notify callback may also be canceled by closing the blocked
9609 ** connection using [sqlite3_close()].
9610 **
9611 ** The unlock-notify callback is not reentrant. If an application invokes
9612 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10000,11 +10002,11 @@
10000 ** where X is an integer. If X is zero, then the [virtual table] whose
10001 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
10002 ** support constraints. In this configuration (which is the default) if
10003 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
10004 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10005 ** specified as part of the users SQL statement, regardless of the actual
10006 ** ON CONFLICT mode specified.
10007 **
10008 ** If X is non-zero, then the virtual table implementation guarantees
10009 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
10010 ** any modifications to internal or persistent data structures have been made.
@@ -10034,11 +10036,11 @@
10034 ** </dd>
10035 **
10036 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10037 ** <dd>Calls of the form
10038 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10039 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10040 ** identify that virtual table as being safe to use from within triggers
10041 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10042 ** virtual table can do no serious harm even if it is controlled by a
10043 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10044 ** flag unless absolutely necessary.
@@ -10202,21 +10204,21 @@
10202 ** <tr><td>2<td>no<td>yes<td>yes
10203 ** <tr><td>3<td>yes<td>yes<td>yes
10204 ** </table>
10205 **
10206 ** ^For the purposes of comparing virtual table output values to see if the
10207 ** values are same value for sorting purposes, two NULL values are considered
10208 ** to be the same. In other words, the comparison operator is "IS"
10209 ** (or "IS NOT DISTINCT FROM") and not "==".
10210 **
10211 ** If a virtual table implementation is unable to meet the requirements
10212 ** specified above, then it must not set the "orderByConsumed" flag in the
10213 ** [sqlite3_index_info] object or an incorrect answer may result.
10214 **
10215 ** ^A virtual table implementation is always free to return rows in any order
10216 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
10217 ** the "orderByConsumed" flag is unset, the query planner will add extra
10218 ** [bytecode] to ensure that the final results returned by the SQL query are
10219 ** ordered correctly. The use of the "orderByConsumed" flag and the
10220 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
10221 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
10222 ** flag might help queries against a virtual table to run faster. Being
@@ -10309,11 +10311,11 @@
10309 **
10310 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10311 ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10312 ** xFilter method which invokes these routines, and specifically
10313 ** a parameter that was previously selected for all-at-once IN constraint
10314 ** processing use the [sqlite3_vtab_in()] interface in the
10315 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10316 ** an xFilter argument that was selected for all-at-once IN constraint
10317 ** processing, then these routines return [SQLITE_ERROR].)^
10318 **
10319 ** ^(Use these routines to access all values on the right-hand side
@@ -10364,11 +10366,11 @@
10364 ** right-hand operand is not known, then *V is set to a NULL pointer.
10365 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10366 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10367 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10368 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10369 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
10370 ** something goes wrong.
10371 **
10372 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10373 ** the right-hand operand of a constraint is a literal value in the original
10374 ** SQL statement. If the right-hand operand is an expression or a reference
@@ -10392,12 +10394,12 @@
10392 /*
10393 ** CAPI3REF: Conflict resolution modes
10394 ** KEYWORDS: {conflict resolution mode}
10395 **
10396 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
10397 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
10398 ** is for the SQL statement being evaluated.
10399 **
10400 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
10401 ** return value from the [sqlite3_set_authorizer()] callback and that
10402 ** [SQLITE_ABORT] is also a [result code].
10403 */
@@ -10433,43 +10435,43 @@
10433 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10434 **
10435 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10436 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10437 ** query planner's estimate for the average number of rows output from each
10438 ** iteration of the X-th loop. If the query planner's estimates was accurate,
10439 ** then this value will approximate the quotient NVISIT/NLOOP and the
10440 ** product of this value for all prior loops with the same SELECTID will
10441 ** be the NLOOP value for the current loop.
10442 **
10443 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10444 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10445 ** to a zero-terminated UTF-8 string containing the name of the index or table
10446 ** used for the X-th loop.
10447 **
10448 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10449 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10450 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10451 ** description for the X-th loop.
10452 **
10453 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10454 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10455 ** id for the X-th query plan element. The id value is unique within the
10456 ** statement. The select-id is the same value as is output in the first
10457 ** column of an [EXPLAIN QUERY PLAN] query.
10458 **
10459 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10460 ** <dd>The "int" variable pointed to by the V parameter will be set to the
10461 ** the id of the parent of the current query element, if applicable, or
10462 ** to zero if the query element has no parent. This is the same value as
10463 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10464 **
10465 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10466 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10467 ** according to the processor time-stamp counter, that elapsed while the
10468 ** query element was being processed. This value is not available for
10469 ** all query elements - if it is unavailable the output variable is
10470 ** set to -1.
10471 ** </dl>
10472 */
10473 #define SQLITE_SCANSTAT_NLOOP 0
10474 #define SQLITE_SCANSTAT_NVISIT 1
10475 #define SQLITE_SCANSTAT_EST 2
@@ -10506,12 +10508,12 @@
10506 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10507 ** sqlite3_stmt_scanstatus() is equivalent to calling
10508 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10509 **
10510 ** Parameter "idx" identifies the specific query element to retrieve statistics
10511 ** for. Query elements are numbered starting from zero. A value of -1 may be
10512 ** to query for statistics regarding the entire query. ^If idx is out of range
10513 ** - less than -1 or greater than or equal to the total number of query
10514 ** elements used to implement the statement - a non-zero value is returned and
10515 ** the variable that pOut points to is unchanged.
10516 **
10517 ** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10550,11 +10552,11 @@
10550 /*
10551 ** CAPI3REF: Flush caches to disk mid-transaction
10552 ** METHOD: sqlite3
10553 **
10554 ** ^If a write-transaction is open on [database connection] D when the
10555 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10556 ** pages in the pager-cache that are not currently in use are written out
10557 ** to disk. A dirty page may be in use if a database cursor created by an
10558 ** active SQL statement is reading from it, or if it is page 1 of a database
10559 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10560 ** interface flushes caches for all schemas - "main", "temp", and
@@ -10664,12 +10666,12 @@
10664 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10665 ** triggers; or 2 for changes resulting from triggers called by top-level
10666 ** triggers; and so forth.
10667 **
10668 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10669 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10670 ** in this case the new values are not available. In this case, when a
10671 ** callback made with op==SQLITE_DELETE is actually a write using the
10672 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10673 ** the index of the column being written. In other cases, where the
10674 ** pre-update hook is being invoked for some other reason, including a
10675 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -10918,20 +10920,20 @@
10918 ** is written into *P.
10919 **
10920 ** For an ordinary on-disk database file, the serialization is just a
10921 ** copy of the disk file. For an in-memory database or a "TEMP" database,
10922 ** the serialization is the same sequence of bytes which would be written
10923 ** to disk if that database where backed up to disk.
10924 **
10925 ** The usual case is that sqlite3_serialize() copies the serialization of
10926 ** the database into memory obtained from [sqlite3_malloc64()] and returns
10927 ** a pointer to that memory. The caller is responsible for freeing the
10928 ** returned value to avoid a memory leak. However, if the F argument
10929 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
10930 ** are made, and the sqlite3_serialize() function will return a pointer
10931 ** to the contiguous memory representation of the database that SQLite
10932 ** is currently using for that database, or NULL if the no such contiguous
10933 ** memory representation of the database exists. A contiguous memory
10934 ** representation of the database will usually only exist if there has
10935 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
10936 ** values of D and S.
10937 ** The size of the database is written into *P even if the
@@ -10998,11 +11000,11 @@
10998 **
10999 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
11000 ** database is currently in a read transaction or is involved in a backup
11001 ** operation.
11002 **
11003 ** It is not possible to deserialized into the TEMP database. If the
11004 ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
11005 ** function returns SQLITE_ERROR.
11006 **
11007 ** The deserialized database should not be in [WAL mode]. If the database
11008 ** is in WAL mode, then any attempt to use the database file will result
@@ -11020,19 +11022,19 @@
11020 */
11021 SQLITE_API int sqlite3_deserialize(
11022 sqlite3 *db, /* The database connection */
11023 const char *zSchema, /* Which DB to reopen with the deserialization */
11024 unsigned char *pData, /* The serialized database content */
11025 sqlite3_int64 szDb, /* Number bytes in the deserialization */
11026 sqlite3_int64 szBuf, /* Total size of buffer pData[] */
11027 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
11028 );
11029
11030 /*
11031 ** CAPI3REF: Flags for sqlite3_deserialize()
11032 **
11033 ** The following are allowed values for 6th argument (the F argument) to
11034 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
11035 **
11036 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
11037 ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
11038 ** and that SQLite should take ownership of this memory and automatically
@@ -11765,11 +11767,11 @@
11765 ** CAPI3REF: Flags for sqlite3changeset_start_v2
11766 **
11767 ** The following flags may passed via the 4th parameter to
11768 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
11769 **
11770 ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
11771 ** Invert the changeset while iterating through it. This is equivalent to
11772 ** inverting a changeset using sqlite3changeset_invert() before applying it.
11773 ** It is an error to specify this flag with a patchset.
11774 */
11775 #define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12310,17 +12312,26 @@
12310 ** Apply a changeset or patchset to a database. These functions attempt to
12311 ** update the "main" database attached to handle db with the changes found in
12312 ** the changeset passed via the second and third arguments.
12313 **
12314 ** The fourth argument (xFilter) passed to these functions is the "filter
12315 ** callback". If it is not NULL, then for each table affected by at least one
12316 ** change in the changeset, the filter callback is invoked with
12317 ** the table name as the second argument, and a copy of the context pointer
12318 ** passed as the sixth argument as the first. If the "filter callback"
12319 ** returns zero, then no attempt is made to apply any changes to the table.
12320 ** Otherwise, if the return value is non-zero or the xFilter argument to
12321 ** is NULL, all changes related to the table are attempted.
 
 
 
 
 
 
 
 
 
12322 **
12323 ** For each table that is not excluded by the filter callback, this function
12324 ** tests that the target database contains a compatible table. A table is
12325 ** considered compatible if all of the following are true:
12326 **
@@ -12337,15 +12348,15 @@
12337 ** changes associated with the table are applied. A warning message is issued
12338 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
12339 ** one such warning is issued for each table in the changeset.
12340 **
12341 ** For each change for which there is a compatible table, an attempt is made
12342 ** to modify the table contents according to the UPDATE, INSERT or DELETE
12343 ** change. If a change cannot be applied cleanly, the conflict handler
12344 ** function passed as the fifth argument to sqlite3changeset_apply() may be
12345 ** invoked. A description of exactly when the conflict handler is invoked for
12346 ** each type of change is below.
12347 **
12348 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
12349 ** of passing anything other than a valid function pointer as the xConflict
12350 ** argument are undefined.
12351 **
@@ -12483,10 +12494,27 @@
12483 void *pChangeset, /* Changeset blob */
12484 int(*xFilter)(
12485 void *pCtx, /* Copy of sixth arg to _apply() */
12486 const char *zTab /* Table name */
12487 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12488 int(*xConflict)(
12489 void *pCtx, /* Copy of sixth arg to _apply() */
12490 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12491 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12492 ),
@@ -12902,10 +12930,27 @@
12902 void *pIn, /* First arg for xInput */
12903 int(*xFilter)(
12904 void *pCtx, /* Copy of sixth arg to _apply() */
12905 const char *zTab /* Table name */
12906 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12907 int(*xConflict)(
12908 void *pCtx, /* Copy of sixth arg to _apply() */
12909 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12910 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12911 ),
12912
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-07-15 19:00:01 9f184f8dfa5ef6d57e10376adc30e0060ceda07d283c23dfdfe3dbdd6608f839"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -166,13 +166,13 @@
166 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
167 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
168 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
169 ** </pre></blockquote>)^
170 **
171 ** ^The sqlite3_version[] string constant contains the text of the
172 ** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a
173 ** pointer to the sqlite3_version[] string constant. The sqlite3_libversion()
174 ** function is provided for use in DLLs since DLL users usually do not have
175 ** direct access to string constants within the DLL. ^The
176 ** sqlite3_libversion_number() function returns an integer equal to
177 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
178 ** a pointer to a string constant whose value is the same as the
@@ -368,11 +368,11 @@
368 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
369 ** that allows an application to run multiple statements of SQL
370 ** without having to use a lot of C code.
371 **
372 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
373 ** semicolon-separated SQL statements passed into its 2nd argument,
374 ** in the context of the [database connection] passed in as its 1st
375 ** argument. ^If the callback function of the 3rd argument to
376 ** sqlite3_exec() is not NULL, then it is invoked for each result row
377 ** coming out of the evaluated SQL statements. ^The 4th argument to
378 ** sqlite3_exec() is relayed through to the 1st argument of each
@@ -401,11 +401,11 @@
401 ** callback is an array of pointers to strings obtained as if from
402 ** [sqlite3_column_text()], one for each column. ^If an element of a
403 ** result row is NULL then the corresponding string pointer for the
404 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
405 ** sqlite3_exec() callback is an array of pointers to strings where each
406 ** entry represents the name of a corresponding result column as obtained
407 ** from [sqlite3_column_name()].
408 **
409 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
410 ** to an empty string, or a pointer that contains only whitespace and/or
411 ** SQL comments, then no SQL statements are evaluated and the database
@@ -587,11 +587,11 @@
587 ** Applications should not depend on the historical behavior.
588 **
589 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
590 ** [sqlite3_open_v2()] does *not* cause the underlying database file
591 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
592 ** [sqlite3_open_v2()] has historically been a no-op and might become an
593 ** error in future versions of SQLite.
594 */
595 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
596 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
597 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
@@ -681,11 +681,11 @@
681 ** CAPI3REF: File Locking Levels
682 **
683 ** SQLite uses one of these integer values as the second
684 ** argument to calls it makes to the xLock() and xUnlock() methods
685 ** of an [sqlite3_io_methods] object. These values are ordered from
686 ** least restrictive to most restrictive.
687 **
688 ** The argument to xLock() is always SHARED or higher. The argument to
689 ** xUnlock is either SHARED or NONE.
690 */
691 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */
@@ -997,11 +997,11 @@
997 ** reason, the entire database file will be overwritten by the current
998 ** transaction. This is used by VACUUM operations.
999 **
1000 ** <li>[[SQLITE_FCNTL_VFSNAME]]
1001 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1002 ** all [VFSes] in the VFS stack. The names of all VFS shims and the
1003 ** final bottom-level VFS are written into memory obtained from
1004 ** [sqlite3_malloc()] and the result is stored in the char* variable
1005 ** that the fourth parameter of [sqlite3_file_control()] points to.
1006 ** The caller is responsible for freeing the memory when done. As with
1007 ** all file-control actions, there is no guarantee that this will actually
@@ -1011,11 +1011,11 @@
1011 **
1012 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1013 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1014 ** [VFSes] currently in use. ^(The argument X in
1015 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1016 ** of type "[sqlite3_vfs] **". This opcode will set *X
1017 ** to a pointer to the top-level VFS.)^
1018 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1019 ** upper-most shim only.
1020 **
1021 ** <li>[[SQLITE_FCNTL_PRAGMA]]
@@ -1201,11 +1201,11 @@
1201 ** record the fact that the pages have been checkpointed.
1202 **
1203 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1204 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1205 ** whether or not there is a database client in another process with a wal-mode
1206 ** transaction open on the database or not. It is only available on unix. The
1207 ** (void*) argument passed with this file-control should be a pointer to a
1208 ** value of type (int). The integer value is set to 1 if the database is a wal
1209 ** mode database and there exists at least one client in another process that
1210 ** currently has an SQL transaction open on the database. It is set to 0 if
1211 ** the database is not a wal-mode db, or if there is no such connection in any
@@ -1626,11 +1626,11 @@
1626 **
1627 ** ^The sqlite3_initialize() routine is called internally by many other
1628 ** SQLite interfaces so that an application usually does not need to
1629 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1630 ** calls sqlite3_initialize() so the SQLite library will be automatically
1631 ** initialized when [sqlite3_open()] is called if it has not been initialized
1632 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1633 ** compile-time option, then the automatic calls to sqlite3_initialize()
1634 ** are omitted and the application must call sqlite3_initialize() directly
1635 ** prior to using any other SQLite interface. For maximum portability,
1636 ** it is recommended that applications always invoke sqlite3_initialize()
@@ -1883,25 +1883,25 @@
1883 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1884 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1885 ** The [sqlite3_mem_methods]
1886 ** structure is filled with the currently defined memory allocation routines.)^
1887 ** This option can be used to overload the default memory allocation
1888 ** routines with a wrapper that simulates memory allocation failure or
1889 ** tracks memory usage, for example. </dd>
1890 **
1891 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1892 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of
1893 ** type int, interpreted as a boolean, which if true provides a hint to
1894 ** SQLite that it should avoid large memory allocations if possible.
1895 ** SQLite will run faster if it is free to make large memory allocations,
1896 ** but some applications might prefer to run slower in exchange for
1897 ** guarantees about memory fragmentation that are possible if large
1898 ** allocations are avoided. This hint is normally off.
1899 ** </dd>
1900 **
1901 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1902 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,
1903 ** interpreted as a boolean, which enables or disables the collection of
1904 ** memory allocation statistics. ^(When memory allocation statistics are
1905 ** disabled, the following SQLite interfaces become non-operational:
1906 ** <ul>
1907 ** <li> [sqlite3_hard_heap_limit64()]
@@ -1942,11 +1942,11 @@
1942 ** a page cache line is larger than sz bytes or if all of the pMem buffer
1943 ** is exhausted.
1944 ** ^If pMem is NULL and N is non-zero, then each database connection
1945 ** does an initial bulk allocation for page cache memory
1946 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1947 ** of -1024*N bytes if N is negative. ^If additional
1948 ** page cache memory is needed beyond what is provided by the initial
1949 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1950 ** additional cache line. </dd>
1951 **
1952 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
@@ -1971,11 +1971,11 @@
1971 **
1972 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1973 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1974 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1975 ** The argument specifies alternative low-level mutex routines to be used
1976 ** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1977 ** the content of the [sqlite3_mutex_methods] structure before the call to
1978 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1979 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1980 ** the entire mutexing subsystem is omitted from the build and hence calls to
1981 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
@@ -2013,11 +2013,11 @@
2013 ** the interface to a custom page cache implementation.)^
2014 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2015 **
2016 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2017 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2018 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off
2019 ** the current page cache implementation into that object.)^ </dd>
2020 **
2021 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2022 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2023 ** global [error log].
@@ -2030,11 +2030,11 @@
2030 ** passed through as the first parameter to the application-defined logger
2031 ** function whenever that function is invoked. ^The second parameter to
2032 ** the logger function is a copy of the first parameter to the corresponding
2033 ** [sqlite3_log()] call and is intended to be a [result code] or an
2034 ** [extended result code]. ^The third parameter passed to the logger is
2035 ** a log message after formatting via [sqlite3_snprintf()].
2036 ** The SQLite logging interface is not reentrant; the logger function
2037 ** supplied by the application must not invoke any SQLite interface.
2038 ** In a multi-threaded application, the application-defined logger
2039 ** function must be threadsafe. </dd>
2040 **
@@ -2221,11 +2221,11 @@
2221 ** CAPI3REF: Database Connection Configuration Options
2222 **
2223 ** These constants are the available integer configuration options that
2224 ** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2225 **
2226 ** The [sqlite3_db_config()] interface is a var-args function. It takes a
2227 ** variable number of parameters, though always at least two. The number of
2228 ** parameters passed into sqlite3_db_config() depends on which of these
2229 ** constants is given as the second parameter. This documentation page
2230 ** refers to parameters beyond the second as "arguments". Thus, when this
2231 ** page says "the N-th argument" it means "the N-th parameter past the
@@ -2355,12 +2355,12 @@
2355 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2356 ** There must be two additional arguments.
2357 ** When the first argument to this interface is 1, then only the C-API is
2358 ** enabled and the SQL function remains disabled. If the first argument to
2359 ** this interface is 0, then both the C-API and the SQL function are disabled.
2360 ** If the first argument is -1, then no changes are made to the state of either
2361 ** the C-API or the SQL function.
2362 ** The second parameter is a pointer to an integer into which
2363 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2364 ** is disabled or enabled following this call. The second parameter may
2365 ** be a NULL pointer, in which case the new setting is not reported back.
2366 ** </dd>
@@ -2474,11 +2474,11 @@
2474 ** </dd>
2475 **
2476 ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2477 ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2478 ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2479 ** the legacy behavior of the [ALTER TABLE RENAME] command such that it
2480 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2481 ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2482 ** additional information. This feature can also be turned on and off
2483 ** using the [PRAGMA legacy_alter_table] statement.
2484 ** </dd>
@@ -2523,11 +2523,11 @@
2523 **
2524 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2525 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2526 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2527 ** the legacy file format flag. When activated, this flag causes all newly
2528 ** created database files to have a schema format version number (the 4-byte
2529 ** integer found at offset 44 into the database header) of 1. This in turn
2530 ** means that the resulting database file will be readable and writable by
2531 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2532 ** newly created databases are generally not understandable by SQLite versions
2533 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
@@ -2550,11 +2550,11 @@
2550 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2551 ** statistics. For statistics to be collected, the flag must be set on
2552 ** the database handle both when the SQL statement is prepared and when it
2553 ** is stepped. The flag is set (collection of statistics is enabled)
2554 ** by default. <p>This option takes two arguments: an integer and a pointer to
2555 ** an integer. The first argument is 1, 0, or -1 to enable, disable, or
2556 ** leave unchanged the statement scanstatus option. If the second argument
2557 ** is not NULL, then the value of the statement scanstatus setting after
2558 ** processing the first argument is written into the integer that the second
2559 ** argument points to.
2560 ** </dd>
@@ -2593,12 +2593,12 @@
2593 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2594 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2595 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2596 ** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2597 ** This capability is enabled by default. Applications can disable or
2598 ** reenable this capability using the current DBCONFIG option. If
2599 ** this capability is disabled, the [ATTACH] command will still work,
2600 ** but the database will be opened read-only. If this option is disabled,
2601 ** then the ability to create a new database using [ATTACH] is also disabled,
2602 ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2603 ** option.<p>
2604 ** This option takes two arguments which are an integer and a pointer
@@ -2628,11 +2628,11 @@
2628 **
2629 ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2630 **
2631 ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2632 ** overall call to [sqlite3_db_config()] has a total of four parameters.
2633 ** The first argument (the third parameter to sqlite3_db_config()) is an integer.
2634 ** The second argument is a pointer to an integer. If the first argument is 1,
2635 ** then the option becomes enabled. If the first integer argument is 0, then the
2636 ** option is disabled. If the first argument is -1, then the option setting
2637 ** is unchanged. The second argument, the pointer to an integer, may be NULL.
2638 ** If the second argument is not NULL, then a value of 0 or 1 is written into
@@ -2918,11 +2918,11 @@
2918 ** and comments that follow the final semicolon are ignored.
2919 **
2920 ** ^These routines return 0 if the statement is incomplete. ^If a
2921 ** memory allocation fails, then SQLITE_NOMEM is returned.
2922 **
2923 ** ^These routines do not parse the SQL statements and thus
2924 ** will not detect syntactically incorrect SQL.
2925 **
2926 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2927 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2928 ** automatically by sqlite3_complete16(). If that initialization fails,
@@ -3035,11 +3035,11 @@
3035 ** Passing 0 to this function disables blocking locks altogether. Passing
3036 ** -1 to this function requests that the VFS blocks for a long time -
3037 ** indefinitely if possible. The results of passing any other negative value
3038 ** are undefined.
3039 **
3040 ** Internally, each SQLite database handle stores two timeout values - the
3041 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3042 ** support blocking locks) and the setlk-timeout (used for blocking locks
3043 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3044 ** values, this function sets only the setlk-timeout value. Therefore,
3045 ** to configure separate busy-timeout and setlk-timeout values for a single
@@ -3065,11 +3065,11 @@
3065 ** METHOD: sqlite3
3066 **
3067 ** This is a legacy interface that is preserved for backwards compatibility.
3068 ** Use of this interface is not recommended.
3069 **
3070 ** Definition: A <b>result table</b> is a memory data structure created by the
3071 ** [sqlite3_get_table()] interface. A result table records the
3072 ** complete query results from one or more queries.
3073 **
3074 ** The table conceptually has a number of rows and columns. But
3075 ** these numbers are not part of the result table itself. These
@@ -3208,11 +3208,11 @@
3208 ** of a signed 32-bit integer.
3209 **
3210 ** ^Calling sqlite3_free() with a pointer previously returned
3211 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3212 ** that it might be reused. ^The sqlite3_free() routine is
3213 ** a no-op if it is called with a NULL pointer. Passing a NULL pointer
3214 ** to sqlite3_free() is harmless. After being freed, memory
3215 ** should neither be read nor written. Even reading previously freed
3216 ** memory might result in a segmentation fault or other severe error.
3217 ** Memory corruption, a segmentation fault, or other severe error
3218 ** might result if sqlite3_free() is called with a non-NULL pointer that
@@ -3226,17 +3226,17 @@
3226 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3227 ** negative then the behavior is exactly the same as calling
3228 ** sqlite3_free(X).
3229 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3230 ** of at least N bytes in size or NULL if insufficient memory is available.
3231 ** ^If M is the size of the prior allocation, then min(N,M) bytes of the
3232 ** prior allocation are copied into the beginning of the buffer returned
3233 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
3234 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3235 ** prior allocation is not freed.
3236 **
3237 ** ^The sqlite3_realloc64(X,N) interface works the same as
3238 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3239 ** of a 32-bit signed integer.
3240 **
3241 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3242 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
@@ -3282,11 +3282,11 @@
3282 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
3283 ** value of [sqlite3_memory_used()] since the high-water mark
3284 ** was last reset. ^The values returned by [sqlite3_memory_used()] and
3285 ** [sqlite3_memory_highwater()] include any overhead
3286 ** added by SQLite in its implementation of [sqlite3_malloc()],
3287 ** but not overhead added by any underlying system library
3288 ** routines that [sqlite3_malloc()] may call.
3289 **
3290 ** ^The memory high-water mark is reset to the current value of
3291 ** [sqlite3_memory_used()] if and only if the parameter to
3292 ** [sqlite3_memory_highwater()] is true. ^The value returned
@@ -3734,19 +3734,19 @@
3734 ** attempt to use the same database connection at the same time.
3735 ** (Mutexes will block any actual concurrency, but in this mode
3736 ** there is no harm in trying.)
3737 **
3738 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3739 ** <dd>The database is opened with [shared cache] enabled, overriding
3740 ** the default shared cache setting provided by
3741 ** [sqlite3_enable_shared_cache()].)^
3742 ** The [use of shared cache mode is discouraged] and hence shared cache
3743 ** capabilities may be omitted from many builds of SQLite. In such cases,
3744 ** this option is a no-op.
3745 **
3746 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3747 ** <dd>The database is opened with [shared cache] disabled, overriding
3748 ** the default shared cache setting provided by
3749 ** [sqlite3_enable_shared_cache()].)^
3750 **
3751 ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3752 ** <dd>The database connection comes up in "extended result code mode".
@@ -4077,11 +4077,11 @@
4077 ** These interfaces are provided for use by [VFS shim] implementations and
4078 ** are not useful outside of that context.
4079 **
4080 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4081 ** database filename D with corresponding journal file J and WAL file W and
4082 ** an array P of N URI Key/Value pairs. The result from
4083 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4084 ** is safe to pass to routines like:
4085 ** <ul>
4086 ** <li> [sqlite3_uri_parameter()],
4087 ** <li> [sqlite3_uri_boolean()],
@@ -4160,19 +4160,19 @@
4160 ** The application does not need to worry about freeing the result.
4161 ** However, the error string might be overwritten or deallocated by
4162 ** subsequent calls to other SQLite interface functions.)^
4163 **
4164 ** ^The sqlite3_errstr(E) interface returns the English-language text
4165 ** that describes the [result code] E, as UTF-8, or NULL if E is not a
4166 ** result code for which a text error message is available.
4167 ** ^(Memory to hold the error message string is managed internally
4168 ** and must not be freed by the application)^.
4169 **
4170 ** ^If the most recent error references a specific token in the input
4171 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4172 ** of the start of that token. ^The byte offset returned by
4173 ** sqlite3_error_offset() assumes that the input SQL is UTF-8.
4174 ** ^If the most recent error does not reference a specific token in the input
4175 ** SQL, then the sqlite3_error_offset() function returns -1.
4176 **
4177 ** When the serialized [threading mode] is in use, it might be the
4178 ** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
4267 ** CAPI3REF: Run-Time Limit Categories
4268 ** KEYWORDS: {limit category} {*limit categories}
4269 **
4270 ** These constants define various performance limits
4271 ** that can be lowered at run-time using [sqlite3_limit()].
4272 ** A concise description of these limits follows, and additional information
4273 ** is available at [limits | Limits in SQLite].
4274 **
4275 ** <dl>
4276 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4277 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4278 **
@@ -4333,11 +4333,11 @@
4333 #define SQLITE_LIMIT_WORKER_THREADS 11
4334
4335 /*
4336 ** CAPI3REF: Prepare Flags
4337 **
4338 ** These constants define various flags that can be passed into the
4339 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4340 ** [sqlite3_prepare16_v3()] interfaces.
4341 **
4342 ** New flags may be added in future releases of SQLite.
4343 **
@@ -4420,11 +4420,11 @@
4420 ** statement is generated.
4421 ** If the caller knows that the supplied string is nul-terminated, then
4422 ** there is a small performance advantage to passing an nByte parameter that
4423 ** is the number of bytes in the input string <i>including</i>
4424 ** the nul-terminator.
4425 ** Note that nByte measures the length of the input in bytes, not
4426 ** characters, even for the UTF-16 interfaces.
4427 **
4428 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4429 ** past the end of the first SQL statement in zSql. These routines only
4430 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
4554 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4555 ** will return "SELECT 2345,NULL".)^
4556 **
4557 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4558 ** is available to hold the result, or if the result would exceed the
4559 ** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4560 **
4561 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4562 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4563 ** option causes sqlite3_expanded_sql() to always return NULL.
4564 **
@@ -4742,11 +4742,11 @@
4742 /*
4743 ** CAPI3REF: SQL Function Context Object
4744 **
4745 ** The context in which an SQL function executes is stored in an
4746 ** sqlite3_context object. ^A pointer to an sqlite3_context object
4747 ** is always the first parameter to [application-defined SQL functions].
4748 ** The application-defined SQL function implementation will pass this
4749 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4750 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4751 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4752 ** and/or [sqlite3_set_auxdata()].
@@ -4758,11 +4758,11 @@
4758 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4759 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4760 ** METHOD: sqlite3_stmt
4761 **
4762 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4763 ** literals may be replaced by a [parameter] that matches one of the following
4764 ** templates:
4765 **
4766 ** <ul>
4767 ** <li> ?
4768 ** <li> ?NNN
@@ -4803,11 +4803,11 @@
4803 ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4804 ** otherwise.
4805 **
4806 ** [[byte-order determination rules]] ^The byte-order of
4807 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4808 ** found in the first character, which is removed, or in the absence of a BOM
4809 ** the byte order is the native byte order of the host
4810 ** machine for sqlite3_bind_text16() or the byte order specified in
4811 ** the 6th parameter for sqlite3_bind_text64().)^
4812 ** ^If UTF16 input text contains invalid unicode
4813 ** characters, then SQLite might change those invalid characters
@@ -4823,11 +4823,11 @@
4823 ** the behavior is undefined.
4824 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4825 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4826 ** that parameter must be the byte offset
4827 ** where the NUL terminator would occur assuming the string were NUL
4828 ** terminated. If any NUL characters occur at byte offsets less than
4829 ** the value of the fourth parameter then the resulting string value will
4830 ** contain embedded NULs. The result of expressions involving strings
4831 ** with embedded NULs is undefined.
4832 **
4833 ** ^The fifth argument to the BLOB and string binding interfaces controls
@@ -5035,11 +5035,11 @@
5035 /*
5036 ** CAPI3REF: Source Of Data In A Query Result
5037 ** METHOD: sqlite3_stmt
5038 **
5039 ** ^These routines provide a means to determine the database, table, and
5040 ** table column that is the origin of a particular result column in a
5041 ** [SELECT] statement.
5042 ** ^The name of the database or table or column can be returned as
5043 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5044 ** the database name, the _table_ routines return the table name, and
5045 ** the origin_ routines return the column name.
@@ -5479,11 +5479,11 @@
5479 ** CAPI3REF: Destroy A Prepared Statement Object
5480 ** DESTRUCTOR: sqlite3_stmt
5481 **
5482 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5483 ** ^If the most recent evaluation of the statement encountered no errors
5484 ** or if the statement has never been evaluated, then sqlite3_finalize() returns
5485 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5486 ** sqlite3_finalize(S) returns the appropriate [error code] or
5487 ** [extended error code].
5488 **
5489 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5604,12 +5604,12 @@
5604 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5605 ** index expressions, or the WHERE clause of partial indexes.
5606 **
5607 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5608 ** all application-defined SQL functions that do not need to be
5609 ** used inside of triggers, views, CHECK constraints, or other elements of
5610 ** the database schema. This flag is especially recommended for SQL
5611 ** functions that have side effects or reveal internal application state.
5612 ** Without this flag, an attacker might be able to modify the schema of
5613 ** a database file to include invocations of the function with parameters
5614 ** chosen by the attacker, which the application will then execute when
5615 ** the database file is opened and read.
@@ -5636,11 +5636,11 @@
5636 ** or aggregate window function. More details regarding the implementation
5637 ** of aggregate window functions are
5638 ** [user-defined window functions|available here].
5639 **
5640 ** ^(If the final parameter to sqlite3_create_function_v2() or
5641 ** sqlite3_create_window_function() is not NULL, then it is the destructor for
5642 ** the application data pointer. The destructor is invoked when the function
5643 ** is deleted, either by being overloaded or when the database connection
5644 ** closes.)^ ^The destructor is also invoked if the call to
5645 ** sqlite3_create_function_v2() fails. ^When the destructor callback is
5646 ** invoked, it is passed a single argument which is a copy of the application
@@ -5711,11 +5711,11 @@
5711 );
5712
5713 /*
5714 ** CAPI3REF: Text Encodings
5715 **
5716 ** These constants define integer codes that represent the various
5717 ** text encodings supported by SQLite.
5718 */
5719 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
5720 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
5721 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
5803 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
5804 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
5805 ** result.
5806 ** Every function that invokes [sqlite3_result_subtype()] should have this
5807 ** property. If it does not, then the call to [sqlite3_result_subtype()]
5808 ** might become a no-op if the function is used as a term in an
5809 ** [expression index]. On the other hand, SQL functions that never invoke
5810 ** [sqlite3_result_subtype()] should avoid setting this property, as the
5811 ** purpose of this property is to disable certain optimizations that are
5812 ** incompatible with subtypes.
5813 **
@@ -5930,11 +5930,11 @@
5930 **
5931 ** ^Within the [xUpdate] method of a [virtual table], the
5932 ** sqlite3_value_nochange(X) interface returns true if and only if
5933 ** the column corresponding to X is unchanged by the UPDATE operation
5934 ** that the xUpdate method call was invoked to implement and if
5935 ** the prior [xColumn] method call that was invoked to extract
5936 ** the value for that column returned without setting a result (probably
5937 ** because it queried [sqlite3_vtab_nochange()] and found that the column
5938 ** was unchanging). ^Within an [xUpdate] method, any value for which
5939 ** sqlite3_value_nochange(X) is true will in all other respects appear
5940 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -6036,11 +6036,11 @@
6036 /*
6037 ** CAPI3REF: Copy And Free SQL Values
6038 ** METHOD: sqlite3_value
6039 **
6040 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6041 ** object V and returns a pointer to that copy. ^The [sqlite3_value] returned
6042 ** is a [protected sqlite3_value] object even if the input is not.
6043 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
6044 ** memory allocation fails. ^If V is a [pointer value], then the result
6045 ** of sqlite3_value_dup(V) is a NULL value.
6046 **
@@ -6074,11 +6074,11 @@
6074 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
6075 ** when first called if N is less than or equal to zero or if a memory
6076 ** allocation error occurs.
6077 **
6078 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6079 ** determined by the N parameter on the first successful call. Changing the
6080 ** value of N in any subsequent call to sqlite3_aggregate_context() within
6081 ** the same aggregate function instance will not resize the memory
6082 ** allocation.)^ Within the xFinal callback, it is customary to set
6083 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6084 ** pointless memory allocations occur.
@@ -6236,11 +6236,11 @@
6236 ** of as a secret key such that only code that knows the secret key is able
6237 ** to access the associated data.
6238 **
6239 ** Security Warning: These interfaces should not be exposed in scripting
6240 ** languages or in other circumstances where it might be possible for an
6241 ** attacker to invoke them. Any agent that can invoke these interfaces
6242 ** can probably also take control of the process.
6243 **
6244 ** Database connection client data is only available for SQLite
6245 ** version 3.44.0 ([dateof:3.44.0]) and later.
6246 **
@@ -6350,11 +6350,11 @@
6350 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6351 ** is non-negative, then as many bytes (not characters) of the text
6352 ** pointed to by the 2nd parameter are taken as the application-defined
6353 ** function result. If the 3rd parameter is non-negative, then it
6354 ** must be the byte offset into the string where the NUL terminator would
6355 ** appear if the string were NUL terminated. If any NUL characters occur
6356 ** in the string at a byte offset that is less than the value of the 3rd
6357 ** parameter, then the resulting string will contain embedded NULs and the
6358 ** result of expressions operating on strings with embedded NULs is undefined.
6359 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6360 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
@@ -6408,11 +6408,11 @@
6408 ** for the P parameter. ^SQLite invokes D with P as its only argument
6409 ** when SQLite is finished with P. The T parameter should be a static
6410 ** string and preferably a string literal. The sqlite3_result_pointer()
6411 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6412 **
6413 ** If these routines are called from within a different thread
6414 ** than the one containing the application-defined function that received
6415 ** the [sqlite3_context] pointer, the results are undefined.
6416 */
6417 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
6418 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
@@ -6814,11 +6814,11 @@
6814 /*
6815 ** CAPI3REF: Return The Schema Name For A Database Connection
6816 ** METHOD: sqlite3
6817 **
6818 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6819 ** for the N-th database on database connection D, or a NULL pointer if N is
6820 ** out of range. An N value of 0 means the main database file. An N of 1 is
6821 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6822 ** databases.
6823 **
6824 ** Space to hold the string that is returned by sqlite3_db_name() is managed
@@ -6909,20 +6909,20 @@
6909 **
6910 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6911 ** <dd>The SQLITE_TXN_READ state means that the database is currently
6912 ** in a read transaction. Content has been read from the database file
6913 ** but nothing in the database file has changed. The transaction state
6914 ** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are
6915 ** no other conflicting concurrent write transactions. The transaction
6916 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6917 ** [COMMIT].</dd>
6918 **
6919 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6920 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6921 ** in a write transaction. Content has been written to the database file
6922 ** but has not yet committed. The transaction state will change to
6923 ** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6924 */
6925 #define SQLITE_TXN_NONE 0
6926 #define SQLITE_TXN_READ 1
6927 #define SQLITE_TXN_WRITE 2
6928
@@ -7199,11 +7199,11 @@
7199
7200 /*
7201 ** CAPI3REF: Impose A Limit On Heap Size
7202 **
7203 ** These interfaces impose limits on the amount of heap memory that will be
7204 ** used by all database connections within a single process.
7205 **
7206 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
7207 ** soft limit on the amount of heap memory that may be allocated by SQLite.
7208 ** ^SQLite strives to keep heap memory utilization below the soft heap
7209 ** limit by reducing the number of pages held in the page cache
@@ -7257,11 +7257,11 @@
7257 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
7258 ** from the heap.
7259 ** </ul>)^
7260 **
7261 ** The circumstances under which SQLite will enforce the heap limits may
7262 ** change in future releases of SQLite.
7263 */
7264 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7265 SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
7266
7267 /*
@@ -7372,12 +7372,12 @@
7372 ** be tried also.
7373 **
7374 ** ^The entry point is zProc.
7375 ** ^(zProc may be 0, in which case SQLite will try to come up with an
7376 ** entry point name on its own. It first tries "sqlite3_extension_init".
7377 ** If that does not work, it constructs a name "sqlite3_X_init" where
7378 ** X consists of the lower-case equivalent of all ASCII alphabetic
7379 ** characters in the filename from the last "/" to the first following
7380 ** "." and omitting any initial "lib".)^
7381 ** ^The sqlite3_load_extension() interface returns
7382 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7383 ** ^If an error occurs and pzErrMsg is not 0, then the
@@ -7444,11 +7444,11 @@
7444 ** that is to be automatically loaded into all new database connections.
7445 **
7446 ** ^(Even though the function prototype shows that xEntryPoint() takes
7447 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7448 ** arguments and expects an integer result as if the signature of the
7449 ** entry point were as follows:
7450 **
7451 ** <blockquote><pre>
7452 ** &nbsp; int xEntryPoint(
7453 ** &nbsp; sqlite3 *db,
7454 ** &nbsp; const char **pzErrMsg,
@@ -7608,11 +7608,11 @@
7608 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7609 ** is true, then the constraint is assumed to be fully handled by the
7610 ** virtual table and might not be checked again by the byte code.)^ ^(The
7611 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7612 ** is left in its default setting of false, the constraint will always be
7613 ** checked separately in byte code. If the omit flag is changed to true, then
7614 ** the constraint may or may not be checked in byte code. In other words,
7615 ** when the omit flag is true there is no guarantee that the constraint will
7616 ** not be checked again using byte code.)^
7617 **
7618 ** ^The idxNum and idxStr values are recorded and passed into the
@@ -7634,11 +7634,11 @@
7634 ** will be returned by the strategy.
7635 **
7636 ** The xBestIndex method may optionally populate the idxFlags field with a
7637 ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7638 ** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7639 ** output to show the idxNum as hex instead of as decimal. Another flag is
7640 ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7641 ** return at most one row.
7642 **
7643 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7644 ** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7775,11 +7775,11 @@
7775 ** by the first parameter. ^The name of the module is given by the
7776 ** second parameter. ^The third parameter is a pointer to
7777 ** the implementation of the [virtual table module]. ^The fourth
7778 ** parameter is an arbitrary client data pointer that is passed through
7779 ** into the [xCreate] and [xConnect] methods of the virtual table module
7780 ** when a new virtual table is being created or reinitialized.
7781 **
7782 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
7783 ** is a pointer to a destructor for the pClientData. ^SQLite will
7784 ** invoke the destructor function (if it is not NULL) when SQLite
7785 ** no longer needs the pClientData pointer. ^The destructor will also
@@ -7940,11 +7940,11 @@
7940 **
7941 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
7942 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
7943 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
7944 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7945 ** on *ppBlob after this function returns.
7946 **
7947 ** This function fails with SQLITE_ERROR if any of the following are true:
7948 ** <ul>
7949 ** <li> ^(Database zDb does not exist)^,
7950 ** <li> ^(Table zTable does not exist within database zDb)^,
@@ -8060,11 +8060,11 @@
8060 ** CAPI3REF: Return The Size Of An Open BLOB
8061 ** METHOD: sqlite3_blob
8062 **
8063 ** ^Returns the size in bytes of the BLOB accessible via the
8064 ** successfully opened [BLOB handle] in its only argument. ^The
8065 ** incremental blob I/O routines can only read or overwrite existing
8066 ** blob content; they cannot change the size of a blob.
8067 **
8068 ** This routine only works on a [BLOB handle] which has been created
8069 ** by a prior successful call to [sqlite3_blob_open()] and which has not
8070 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
@@ -8210,11 +8210,11 @@
8210 ** function that calls sqlite3_initialize().
8211 **
8212 ** ^The sqlite3_mutex_alloc() routine allocates a new
8213 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8214 ** routine returns NULL if it is unable to allocate the requested
8215 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
8216 ** integer constants:
8217 **
8218 ** <ul>
8219 ** <li> SQLITE_MUTEX_FAST
8220 ** <li> SQLITE_MUTEX_RECURSIVE
@@ -8443,11 +8443,11 @@
8443
8444 /*
8445 ** CAPI3REF: Retrieve the mutex for a database connection
8446 ** METHOD: sqlite3
8447 **
8448 ** ^This interface returns a pointer to the [sqlite3_mutex] object that
8449 ** serializes access to the [database connection] given in the argument
8450 ** when the [threading mode] is Serialized.
8451 ** ^If the [threading mode] is Single-thread or Multi-thread then this
8452 ** routine returns a NULL pointer.
8453 */
@@ -8566,11 +8566,11 @@
8566
8567 /*
8568 ** CAPI3REF: SQL Keyword Checking
8569 **
8570 ** These routines provide access to the set of SQL language keywords
8571 ** recognized by SQLite. Applications can use these routines to determine
8572 ** whether or not a specific identifier needs to be escaped (for example,
8573 ** by enclosing in double-quotes) so as not to confuse the parser.
8574 **
8575 ** The sqlite3_keyword_count() interface returns the number of distinct
8576 ** keywords understood by SQLite.
@@ -8734,11 +8734,11 @@
8734 **
8735 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
8736 ** content of the dynamic string under construction in X. The value
8737 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
8738 ** and might be freed or altered by any subsequent method on the same
8739 ** [sqlite3_str] object. Applications must not use the pointer returned by
8740 ** [sqlite3_str_value(X)] after any subsequent method call on the same
8741 ** object. ^Applications may change the content of the string returned
8742 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
8743 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8744 ** write any byte after any subsequent sqlite3_str method call.
@@ -8820,11 +8820,11 @@
8820 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
8821 ** <dd>This parameter returns the number of bytes of page cache
8822 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
8823 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
8824 ** returned value includes allocations that overflowed because they
8825 ** were too large (they were larger than the "sz" parameter to
8826 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
8827 ** no space was left in the page cache.</dd>)^
8828 **
8829 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
8830 ** <dd>This parameter records the largest memory allocation request
@@ -8904,53 +8904,55 @@
8904 ** checked out.</dd>)^
8905 **
8906 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8907 ** <dd>This parameter returns the number of malloc attempts that were
8908 ** satisfied using lookaside memory. Only the high-water value is meaningful;
8909 ** the current value is always zero.</dd>)^
8910 **
8911 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
8912 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
8913 ** <dd>This parameter returns the number of malloc attempts that might have
8914 ** been satisfied using lookaside memory but failed due to the amount of
8915 ** memory requested being larger than the lookaside slot size.
8916 ** Only the high-water value is meaningful;
8917 ** the current value is always zero.</dd>)^
8918 **
8919 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
8920 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
8921 ** <dd>This parameter returns the number of malloc attempts that might have
8922 ** been satisfied using lookaside memory but failed due to all lookaside
8923 ** memory already being in use.
8924 ** Only the high-water value is meaningful;
8925 ** the current value is always zero.</dd>)^
8926 **
8927 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
8928 ** <dd>This parameter returns the approximate number of bytes of heap
8929 ** memory used by all pager caches associated with the database connection.)^
8930 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
8931 ** </dd>
8932 **
8933 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
8934 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
8935 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
8936 ** pager cache is shared between two or more connections the bytes of heap
8937 ** memory used by that pager cache is divided evenly between the attached
8938 ** connections.)^ In other words, if none of the pager caches associated
8939 ** with the database connection are shared, this request returns the same
8940 ** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are
8941 ** shared, the value returned by this call will be smaller than that returned
8942 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
8943 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
8944 **
8945 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
8946 ** <dd>This parameter returns the approximate number of bytes of heap
8947 ** memory used to store the schema for all databases associated
8948 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
8949 ** ^The full amount of memory used by the schemas is reported, even if the
8950 ** schema memory is shared with other database connections due to
8951 ** [shared cache mode] being enabled.
8952 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
8953 ** </dd>
8954 **
8955 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
8956 ** <dd>This parameter returns the approximate number of bytes of heap
8957 ** and lookaside memory used by all prepared statements associated with
8958 ** the database connection.)^
@@ -8983,11 +8985,11 @@
8985 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
8986 ** <dd>This parameter returns the number of dirty cache entries that have
8987 ** been written to disk in the middle of a transaction due to the page
8988 ** cache overflowing. Transactions are more efficient if they are written
8989 ** to disk all at once. When pages spill mid-transaction, that introduces
8990 ** additional overhead. This parameter can be used to help identify
8991 ** inefficiencies that can be resolved by increasing the cache size.
8992 ** </dd>
8993 **
8994 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
8995 ** <dd>This parameter returns zero for the current value if and only if
@@ -9054,48 +9056,48 @@
9056 ** careful use of indices.</dd>
9057 **
9058 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
9059 ** <dd>^This is the number of sort operations that have occurred.
9060 ** A non-zero value in this counter may indicate an opportunity to
9061 ** improve performance through careful use of indices.</dd>
9062 **
9063 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
9064 ** <dd>^This is the number of rows inserted into transient indices that
9065 ** were created automatically in order to help joins run faster.
9066 ** A non-zero value in this counter may indicate an opportunity to
9067 ** improve performance by adding permanent indices that do not
9068 ** need to be reinitialized each time the statement is run.</dd>
9069 **
9070 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
9071 ** <dd>^This is the number of virtual machine operations executed
9072 ** by the prepared statement if that number is less than or equal
9073 ** to 2147483647. The number of virtual machine operations can be
9074 ** used as a proxy for the total work done by the prepared statement.
9075 ** If the number of virtual machine operations exceeds 2147483647
9076 ** then the value returned by this statement status code is undefined.</dd>
9077 **
9078 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9079 ** <dd>^This is the number of times that the prepare statement has been
9080 ** automatically regenerated due to schema changes or changes to
9081 ** [bound parameters] that might affect the query plan.</dd>
9082 **
9083 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9084 ** <dd>^This is the number of times that the prepared statement has
9085 ** been run. A single "run" for the purposes of this counter is one
9086 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
9087 ** The counter is incremented on the first [sqlite3_step()] call of each
9088 ** cycle.</dd>
9089 **
9090 ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
9091 ** [[SQLITE_STMTSTATUS_FILTER HIT]]
9092 ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
9093 ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
9094 ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
9095 ** step was bypassed because a Bloom filter returned not-found. The
9096 ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
9097 ** times that the Bloom filter returned a find, and thus the join step
9098 ** had to be processed as normal.</dd>
9099 **
9100 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
9101 ** <dd>^This is the approximate number of bytes of heap memory
9102 ** used to store the prepared statement. ^This value is not actually
9103 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
@@ -9196,31 +9198,31 @@
9198 ** [[the xCreate() page cache methods]]
9199 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
9200 ** SQLite will typically create one cache instance for each open database file,
9201 ** though this is not guaranteed. ^The
9202 ** first parameter, szPage, is the size in bytes of the pages that must
9203 ** be allocated by the cache. ^szPage will always be a power of two. ^The
9204 ** second parameter szExtra is a number of bytes of extra storage
9205 ** associated with each page cache entry. ^The szExtra parameter will be
9206 ** a number less than 250. SQLite will use the
9207 ** extra szExtra bytes on each page to store metadata about the underlying
9208 ** database page on disk. The value passed into szExtra depends
9209 ** on the SQLite version, the target platform, and how SQLite was compiled.
9210 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
9211 ** created will be used to cache database pages of a file stored on disk, or
9212 ** false if it is used for an in-memory database. The cache implementation
9213 ** does not have to do anything special based upon the value of bPurgeable;
9214 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
9215 ** never invoke xUnpin() except to deliberately delete a page.
9216 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
9217 ** false will always have the "discard" flag set to true.
9218 ** ^Hence, a cache created with bPurgeable set to false will
9219 ** never contain any unpinned pages.
9220 **
9221 ** [[the xCachesize() page cache method]]
9222 ** ^(The xCachesize() method may be called at any time by SQLite to set the
9223 ** suggested maximum cache-size (number of pages stored) for the cache
9224 ** instance passed as the first argument. This is the value configured using
9225 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
9226 ** parameter, the implementation is not required to do anything with this
9227 ** value; it is advisory only.
9228 **
@@ -9243,16 +9245,16 @@
9245 **
9246 ** If the requested page is already in the page cache, then the page cache
9247 ** implementation must return a pointer to the page buffer with its content
9248 ** intact. If the requested page is not already in the cache, then the
9249 ** cache implementation should use the value of the createFlag
9250 ** parameter to help it determine what action to take:
9251 **
9252 ** <table border=1 width=85% align=center>
9253 ** <tr><th> createFlag <th> Behavior when page is not already in cache
9254 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
9255 ** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.
9256 ** Otherwise return NULL.
9257 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
9258 ** NULL if allocating a new page is effectively impossible.
9259 ** </table>
9260 **
@@ -9265,11 +9267,11 @@
9267 ** [[the xUnpin() page cache method]]
9268 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9269 ** as its second argument. If the third parameter, discard, is non-zero,
9270 ** then the page must be evicted from the cache.
9271 ** ^If the discard parameter is
9272 ** zero, then the page may be discarded or retained at the discretion of the
9273 ** page cache implementation. ^The page cache implementation
9274 ** may choose to evict unpinned pages at any time.
9275 **
9276 ** The cache must not perform any reference counting. A single
9277 ** call to xUnpin() unpins the page regardless of the number of prior calls
@@ -9283,11 +9285,11 @@
9285 ** to be pinned.
9286 **
9287 ** When SQLite calls the xTruncate() method, the cache must discard all
9288 ** existing cache entries with page numbers (keys) greater than or equal
9289 ** to the value of the iLimit parameter passed to xTruncate(). If any
9290 ** of these pages are pinned, they become implicitly unpinned, meaning that
9291 ** they can be safely discarded.
9292 **
9293 ** [[the xDestroy() page cache method]]
9294 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
9295 ** All resources associated with the specified cache should be freed. ^After
@@ -9463,11 +9465,11 @@
9465 ** sqlite3_backup_step(), the source database may be modified mid-way
9466 ** through the backup process. ^If the source database is modified by an
9467 ** external process or via a database connection other than the one being
9468 ** used by the backup operation, then the backup will be automatically
9469 ** restarted by the next call to sqlite3_backup_step(). ^If the source
9470 ** database is modified by using the same database connection as is used
9471 ** by the backup operation, then the backup database is automatically
9472 ** updated at the same time.
9473 **
9474 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9475 **
@@ -9480,11 +9482,11 @@
9482 ** active write-transaction on the destination database is rolled back.
9483 ** The [sqlite3_backup] object is invalid
9484 ** and may not be used following a call to sqlite3_backup_finish().
9485 **
9486 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9487 ** sqlite3_backup_step() errors occurred, regardless of whether or not
9488 ** sqlite3_backup_step() completed.
9489 ** ^If an out-of-memory condition or IO error occurred during any prior
9490 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9491 ** sqlite3_backup_finish() returns the corresponding [error code].
9492 **
@@ -9582,11 +9584,11 @@
9584 ** identity of the database connection (the blocking connection) that
9585 ** has locked the required resource is stored internally. ^After an
9586 ** application receives an SQLITE_LOCKED error, it may call the
9587 ** sqlite3_unlock_notify() method with the blocked connection handle as
9588 ** the first argument to register for a callback that will be invoked
9589 ** when the blocking connection's current transaction is concluded. ^The
9590 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9591 ** call that concludes the blocking connection's transaction.
9592 **
9593 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9594 ** there is a chance that the blocking connection will have already
@@ -9602,11 +9604,11 @@
9604 ** ^(There may be at most one unlock-notify callback registered by a
9605 ** blocked connection. If sqlite3_unlock_notify() is called when the
9606 ** blocked connection already has a registered unlock-notify callback,
9607 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9608 ** called with a NULL pointer as its second argument, then any existing
9609 ** unlock-notify callback is canceled. ^The blocked connection's
9610 ** unlock-notify callback may also be canceled by closing the blocked
9611 ** connection using [sqlite3_close()].
9612 **
9613 ** The unlock-notify callback is not reentrant. If an application invokes
9614 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
@@ -10000,11 +10002,11 @@
10002 ** where X is an integer. If X is zero, then the [virtual table] whose
10003 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
10004 ** support constraints. In this configuration (which is the default) if
10005 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
10006 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10007 ** specified as part of the user's SQL statement, regardless of the actual
10008 ** ON CONFLICT mode specified.
10009 **
10010 ** If X is non-zero, then the virtual table implementation guarantees
10011 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
10012 ** any modifications to internal or persistent data structures have been made.
@@ -10034,11 +10036,11 @@
10036 ** </dd>
10037 **
10038 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10039 ** <dd>Calls of the form
10040 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10041 ** [xConnect] or [xCreate] methods of a [virtual table] implementation
10042 ** identify that virtual table as being safe to use from within triggers
10043 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10044 ** virtual table can do no serious harm even if it is controlled by a
10045 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10046 ** flag unless absolutely necessary.
@@ -10202,21 +10204,21 @@
10204 ** <tr><td>2<td>no<td>yes<td>yes
10205 ** <tr><td>3<td>yes<td>yes<td>yes
10206 ** </table>
10207 **
10208 ** ^For the purposes of comparing virtual table output values to see if the
10209 ** values are the same value for sorting purposes, two NULL values are considered
10210 ** to be the same. In other words, the comparison operator is "IS"
10211 ** (or "IS NOT DISTINCT FROM") and not "==".
10212 **
10213 ** If a virtual table implementation is unable to meet the requirements
10214 ** specified above, then it must not set the "orderByConsumed" flag in the
10215 ** [sqlite3_index_info] object or an incorrect answer may result.
10216 **
10217 ** ^A virtual table implementation is always free to return rows in any order
10218 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
10219 ** "orderByConsumed" flag is unset, the query planner will add extra
10220 ** [bytecode] to ensure that the final results returned by the SQL query are
10221 ** ordered correctly. The use of the "orderByConsumed" flag and the
10222 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
10223 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
10224 ** flag might help queries against a virtual table to run faster. Being
@@ -10309,11 +10311,11 @@
10311 **
10312 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10313 ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10314 ** xFilter method which invokes these routines, and specifically
10315 ** a parameter that was previously selected for all-at-once IN constraint
10316 ** processing using the [sqlite3_vtab_in()] interface in the
10317 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10318 ** an xFilter argument that was selected for all-at-once IN constraint
10319 ** processing, then these routines return [SQLITE_ERROR].)^
10320 **
10321 ** ^(Use these routines to access all values on the right-hand side
@@ -10364,11 +10366,11 @@
10366 ** right-hand operand is not known, then *V is set to a NULL pointer.
10367 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10368 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
10369 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10370 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
10371 ** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if
10372 ** something goes wrong.
10373 **
10374 ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10375 ** the right-hand operand of a constraint is a literal value in the original
10376 ** SQL statement. If the right-hand operand is an expression or a reference
@@ -10392,12 +10394,12 @@
10394 /*
10395 ** CAPI3REF: Conflict resolution modes
10396 ** KEYWORDS: {conflict resolution mode}
10397 **
10398 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
10399 ** inform a [virtual table] implementation of the [ON CONFLICT] mode
10400 ** for the SQL statement being evaluated.
10401 **
10402 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
10403 ** return value from the [sqlite3_set_authorizer()] callback and that
10404 ** [SQLITE_ABORT] is also a [result code].
10405 */
@@ -10433,43 +10435,43 @@
10435 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10436 **
10437 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10438 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10439 ** query planner's estimate for the average number of rows output from each
10440 ** iteration of the X-th loop. If the query planner's estimate was accurate,
10441 ** then this value will approximate the quotient NVISIT/NLOOP and the
10442 ** product of this value for all prior loops with the same SELECTID will
10443 ** be the NLOOP value for the current loop.</dd>
10444 **
10445 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10446 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10447 ** to a zero-terminated UTF-8 string containing the name of the index or table
10448 ** used for the X-th loop.</dd>
10449 **
10450 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10451 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10452 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10453 ** description for the X-th loop.</dd>
10454 **
10455 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10456 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10457 ** id for the X-th query plan element. The id value is unique within the
10458 ** statement. The select-id is the same value as is output in the first
10459 ** column of an [EXPLAIN QUERY PLAN] query.</dd>
10460 **
10461 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10462 ** <dd>The "int" variable pointed to by the V parameter will be set to the
10463 ** id of the parent of the current query element, if applicable, or
10464 ** to zero if the query element has no parent. This is the same value as
10465 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>
10466 **
10467 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10468 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10469 ** according to the processor time-stamp counter, that elapsed while the
10470 ** query element was being processed. This value is not available for
10471 ** all query elements - if it is unavailable the output variable is
10472 ** set to -1.</dd>
10473 ** </dl>
10474 */
10475 #define SQLITE_SCANSTAT_NLOOP 0
10476 #define SQLITE_SCANSTAT_NVISIT 1
10477 #define SQLITE_SCANSTAT_EST 2
@@ -10506,12 +10508,12 @@
10508 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10509 ** sqlite3_stmt_scanstatus() is equivalent to calling
10510 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10511 **
10512 ** Parameter "idx" identifies the specific query element to retrieve statistics
10513 ** for. Query elements are numbered starting from zero. A value of -1 may
10514 ** retrieve statistics for the entire query. ^If idx is out of range
10515 ** - less than -1 or greater than or equal to the total number of query
10516 ** elements used to implement the statement - a non-zero value is returned and
10517 ** the variable that pOut points to is unchanged.
10518 **
10519 ** See also: [sqlite3_stmt_scanstatus_reset()]
@@ -10550,11 +10552,11 @@
10552 /*
10553 ** CAPI3REF: Flush caches to disk mid-transaction
10554 ** METHOD: sqlite3
10555 **
10556 ** ^If a write-transaction is open on [database connection] D when the
10557 ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
10558 ** pages in the pager-cache that are not currently in use are written out
10559 ** to disk. A dirty page may be in use if a database cursor created by an
10560 ** active SQL statement is reading from it, or if it is page 1 of a database
10561 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10562 ** interface flushes caches for all schemas - "main", "temp", and
@@ -10664,12 +10666,12 @@
10666 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10667 ** triggers; or 2 for changes resulting from triggers called by top-level
10668 ** triggers; and so forth.
10669 **
10670 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10671 ** the pre-update hook is invoked with SQLITE_DELETE, because
10672 ** the new values are not yet available. In this case, when a
10673 ** callback made with op==SQLITE_DELETE is actually a write using the
10674 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10675 ** the index of the column being written. In other cases, where the
10676 ** pre-update hook is being invoked for some other reason, including a
10677 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
@@ -10918,20 +10920,20 @@
10920 ** is written into *P.
10921 **
10922 ** For an ordinary on-disk database file, the serialization is just a
10923 ** copy of the disk file. For an in-memory database or a "TEMP" database,
10924 ** the serialization is the same sequence of bytes which would be written
10925 ** to disk if that database were backed up to disk.
10926 **
10927 ** The usual case is that sqlite3_serialize() copies the serialization of
10928 ** the database into memory obtained from [sqlite3_malloc64()] and returns
10929 ** a pointer to that memory. The caller is responsible for freeing the
10930 ** returned value to avoid a memory leak. However, if the F argument
10931 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
10932 ** are made, and the sqlite3_serialize() function will return a pointer
10933 ** to the contiguous memory representation of the database that SQLite
10934 ** is currently using for that database, or NULL if no such contiguous
10935 ** memory representation of the database exists. A contiguous memory
10936 ** representation of the database will usually only exist if there has
10937 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
10938 ** values of D and S.
10939 ** The size of the database is written into *P even if the
@@ -10998,11 +11000,11 @@
11000 **
11001 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
11002 ** database is currently in a read transaction or is involved in a backup
11003 ** operation.
11004 **
11005 ** It is not possible to deserialize into the TEMP database. If the
11006 ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
11007 ** function returns SQLITE_ERROR.
11008 **
11009 ** The deserialized database should not be in [WAL mode]. If the database
11010 ** is in WAL mode, then any attempt to use the database file will result
@@ -11020,19 +11022,19 @@
11022 */
11023 SQLITE_API int sqlite3_deserialize(
11024 sqlite3 *db, /* The database connection */
11025 const char *zSchema, /* Which DB to reopen with the deserialization */
11026 unsigned char *pData, /* The serialized database content */
11027 sqlite3_int64 szDb, /* Number of bytes in the deserialization */
11028 sqlite3_int64 szBuf, /* Total size of buffer pData[] */
11029 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
11030 );
11031
11032 /*
11033 ** CAPI3REF: Flags for sqlite3_deserialize()
11034 **
11035 ** The following are allowed values for the 6th argument (the F argument) to
11036 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
11037 **
11038 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
11039 ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
11040 ** and that SQLite should take ownership of this memory and automatically
@@ -11765,11 +11767,11 @@
11767 ** CAPI3REF: Flags for sqlite3changeset_start_v2
11768 **
11769 ** The following flags may passed via the 4th parameter to
11770 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
11771 **
11772 ** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
11773 ** Invert the changeset while iterating through it. This is equivalent to
11774 ** inverting a changeset using sqlite3changeset_invert() before applying it.
11775 ** It is an error to specify this flag with a patchset.
11776 */
11777 #define SQLITE_CHANGESETSTART_INVERT 0x0002
@@ -12310,17 +12312,26 @@
12312 ** Apply a changeset or patchset to a database. These functions attempt to
12313 ** update the "main" database attached to handle db with the changes found in
12314 ** the changeset passed via the second and third arguments.
12315 **
12316 ** The fourth argument (xFilter) passed to these functions is the "filter
12317 ** callback". This may be passed NULL, in which case all changes in the
12318 ** changeset are applied to the database. For sqlite3changeset_apply() and
12319 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
12320 ** for each table affected by at least one change in the changeset. In this
12321 ** case the table name is passed as the second argument, and a copy of
12322 ** the context pointer passed as the sixth argument to apply() or apply_v2()
12323 ** as the first. If the "filter callback" returns zero, then no attempt is
12324 ** made to apply any changes to the table. Otherwise, if the return value is
12325 ** non-zero, all changes related to the table are attempted.
12326 **
12327 ** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once
12328 ** per change. The second argument in this case is an sqlite3_changeset_iter
12329 ** that may be queried using the usual APIs for the details of the current
12330 ** change. If the "filter callback" returns zero in this case, then no attempt
12331 ** is made to apply the current change. If it returns non-zero, the change
12332 ** is applied.
12333 **
12334 ** For each table that is not excluded by the filter callback, this function
12335 ** tests that the target database contains a compatible table. A table is
12336 ** considered compatible if all of the following are true:
12337 **
@@ -12337,15 +12348,15 @@
12348 ** changes associated with the table are applied. A warning message is issued
12349 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
12350 ** one such warning is issued for each table in the changeset.
12351 **
12352 ** For each change for which there is a compatible table, an attempt is made
12353 ** to modify the table contents according to each UPDATE, INSERT or DELETE
12354 ** change that is not excluded by a filter callback. If a change cannot be
12355 ** applied cleanly, the conflict handler function passed as the fifth argument
12356 ** to sqlite3changeset_apply() may be invoked. A description of exactly when
12357 ** the conflict handler is invoked for each type of change is below.
12358 **
12359 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
12360 ** of passing anything other than a valid function pointer as the xConflict
12361 ** argument are undefined.
12362 **
@@ -12483,10 +12494,27 @@
12494 void *pChangeset, /* Changeset blob */
12495 int(*xFilter)(
12496 void *pCtx, /* Copy of sixth arg to _apply() */
12497 const char *zTab /* Table name */
12498 ),
12499 int(*xConflict)(
12500 void *pCtx, /* Copy of sixth arg to _apply() */
12501 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12502 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12503 ),
12504 void *pCtx, /* First argument passed to xConflict */
12505 void **ppRebase, int *pnRebase, /* OUT: Rebase data */
12506 int flags /* SESSION_CHANGESETAPPLY_* flags */
12507 );
12508 SQLITE_API int sqlite3changeset_apply_v3(
12509 sqlite3 *db, /* Apply change to "main" db of this handle */
12510 int nChangeset, /* Size of changeset in bytes */
12511 void *pChangeset, /* Changeset blob */
12512 int(*xFilter)(
12513 void *pCtx, /* Copy of sixth arg to _apply() */
12514 sqlite3_changeset_iter *p /* Handle describing change */
12515 ),
12516 int(*xConflict)(
12517 void *pCtx, /* Copy of sixth arg to _apply() */
12518 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12519 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12520 ),
@@ -12902,10 +12930,27 @@
12930 void *pIn, /* First arg for xInput */
12931 int(*xFilter)(
12932 void *pCtx, /* Copy of sixth arg to _apply() */
12933 const char *zTab /* Table name */
12934 ),
12935 int(*xConflict)(
12936 void *pCtx, /* Copy of sixth arg to _apply() */
12937 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12938 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12939 ),
12940 void *pCtx, /* First argument passed to xConflict */
12941 void **ppRebase, int *pnRebase,
12942 int flags
12943 );
12944 SQLITE_API int sqlite3changeset_apply_v3_strm(
12945 sqlite3 *db, /* Apply change to "main" db of this handle */
12946 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
12947 void *pIn, /* First arg for xInput */
12948 int(*xFilter)(
12949 void *pCtx, /* Copy of sixth arg to _apply() */
12950 sqlite3_changeset_iter *p
12951 ),
12952 int(*xConflict)(
12953 void *pCtx, /* Copy of sixth arg to _apply() */
12954 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
12955 sqlite3_changeset_iter *p /* Handle describing change and conflict */
12956 ),
12957
+1 -1
--- src/ajax.c
+++ src/ajax.c
@@ -307,11 +307,11 @@
307307
Blob content = empty_blob;
308308
const char * zRenderMode = 0;
309309
310310
ajax_get_fnci_args( &zFilename, 0 );
311311
312
- if(!ajax_route_bootstrap(1,1)){
312
+ if(!ajax_route_bootstrap(0,1)){
313313
return;
314314
}
315315
if(zFilename==0){
316316
/* The filename is only used for mimetype determination,
317317
** so we can default it... */
318318
--- src/ajax.c
+++ src/ajax.c
@@ -307,11 +307,11 @@
307 Blob content = empty_blob;
308 const char * zRenderMode = 0;
309
310 ajax_get_fnci_args( &zFilename, 0 );
311
312 if(!ajax_route_bootstrap(1,1)){
313 return;
314 }
315 if(zFilename==0){
316 /* The filename is only used for mimetype determination,
317 ** so we can default it... */
318
--- src/ajax.c
+++ src/ajax.c
@@ -307,11 +307,11 @@
307 Blob content = empty_blob;
308 const char * zRenderMode = 0;
309
310 ajax_get_fnci_args( &zFilename, 0 );
311
312 if(!ajax_route_bootstrap(0,1)){
313 return;
314 }
315 if(zFilename==0){
316 /* The filename is only used for mimetype determination,
317 ** so we can default it... */
318
+1 -1
--- src/bisect.c
+++ src/bisect.c
@@ -336,11 +336,11 @@
336336
}
337337
zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
338338
if( blob_size(&link)>0 ) blob_append(&link, "-", 1);
339339
blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
340340
}
341
- zResult = mprintf("%s", blob_str(&link));
341
+ zResult = fossil_strdup(blob_str(&link));
342342
blob_reset(&link);
343343
blob_reset(&log);
344344
blob_reset(&id);
345345
return zResult;
346346
}
347347
--- src/bisect.c
+++ src/bisect.c
@@ -336,11 +336,11 @@
336 }
337 zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
338 if( blob_size(&link)>0 ) blob_append(&link, "-", 1);
339 blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
340 }
341 zResult = mprintf("%s", blob_str(&link));
342 blob_reset(&link);
343 blob_reset(&log);
344 blob_reset(&id);
345 return zResult;
346 }
347
--- src/bisect.c
+++ src/bisect.c
@@ -336,11 +336,11 @@
336 }
337 zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
338 if( blob_size(&link)>0 ) blob_append(&link, "-", 1);
339 blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
340 }
341 zResult = fossil_strdup(blob_str(&link));
342 blob_reset(&link);
343 blob_reset(&log);
344 blob_reset(&id);
345 return zResult;
346 }
347
+24 -11
--- src/cgi.c
+++ src/cgi.c
@@ -505,11 +505,11 @@
505505
&& strcmp(zContentType,"text/html")!=0
506506
){
507507
/* Do not cache HTML replies as those will have been generated and
508508
** will likely, therefore, contains a nonce and we want that nonce to
509509
** be different every time. */
510
- blob_appendf(&hdr, "ETag: %s\r\n", etag_tag());
510
+ blob_appendf(&hdr, "ETag: \"%s\"\r\n", etag_tag());
511511
blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
512512
if( etag_mtime()>0 ){
513513
blob_appendf(&hdr, "Last-Modified: %s\r\n",
514514
cgi_rfc822_datestamp(etag_mtime()));
515515
}
@@ -964,11 +964,11 @@
964964
** * it is impossible for a cookie or query parameter to
965965
** override the value of an environment variable since
966966
** environment variables always have uppercase names.
967967
**
968968
** 2018-03-29: Also ignore the entry if NAME that contains any characters
969
-** other than [a-zA-Z0-9_]. There are no known exploits involving unusual
969
+** other than [-a-zA-Z0-9_]. There are no known exploits involving unusual
970970
** names that contain characters outside that set, but it never hurts to
971971
** be extra cautious when sanitizing inputs.
972972
**
973973
** Parameters are separated by the "terminator" character. Whitespace
974974
** before the NAME is ignored.
@@ -1280,36 +1280,49 @@
12801280
12811281
/* Forward declaration */
12821282
static NORETURN void malformed_request(const char *zMsg, ...);
12831283
12841284
/*
1285
-** Checks the QUERY_STRING environment variable, sets it up
1286
-** via add_param_list() and, if found, applies its "skin"
1287
-** setting. Returns 0 if no QUERY_STRING is set, 1 if it is,
1288
-** and 2 if it sets the skin (in which case the cookie may
1289
-** still need flushing by the page, via cookie_render()).
1285
+** Checks the QUERY_STRING environment variable, sets it up via
1286
+** add_param_list() and, if found, applies its "skin" setting. Returns
1287
+** 0 if no QUERY_STRING is set, else it returns a bitmask of:
1288
+**
1289
+** 0x01 = QUERY_STRING was set up
1290
+** 0x02 = "skin" URL param arg was processed
1291
+** 0x04 = "x-f-l-c" cookie arg was processed.
1292
+**
1293
+* In the case of the skin, the cookie may still need flushing
1294
+** by the page, via cookie_render().
12901295
*/
12911296
int cgi_setup_query_string(void){
12921297
int rc = 0;
12931298
char * z = (char*)P("QUERY_STRING");
12941299
if( z ){
1295
- ++rc;
1300
+ rc = 0x01;
12961301
z = fossil_strdup(z);
12971302
add_param_list(z, '&');
12981303
z = (char*)P("skin");
12991304
if( z ){
13001305
char *zErr = skin_use_alternative(z, 2, SKIN_FROM_QPARAM);
1301
- ++rc;
1306
+ rc |= 0x02;
13021307
if( !zErr && P("once")==0 ){
13031308
cookie_write_parameter("skin","skin",z);
13041309
/* Per /chat discussion, passing ?skin=... without "once"
13051310
** implies the "udc" argument, so we force that into the
13061311
** environment here. */
13071312
cgi_set_parameter_nocopy("udc", "1", 1);
13081313
}
13091314
fossil_free(zErr);
13101315
}
1316
+ }
1317
+ if( !g.syncInfo.zLoginCard && 0!=(z=(char*)P("x-f-l-c")) ){
1318
+ /* x-f-l-c (X-Fossil-Login-Card card transmitted via cookie
1319
+ ** instead of in the sync payload. */
1320
+ rc |= 0x04;
1321
+ g.syncInfo.zLoginCard = fossil_strdup(z);
1322
+ g.syncInfo.fLoginCardMode |= 0x02;
1323
+ cgi_delete_parameter("x-f-l-c");
13111324
}
13121325
return rc;
13131326
}
13141327
13151328
/*
@@ -2125,10 +2138,11 @@
21252138
int i;
21262139
const char *zScheme = "http";
21272140
char zLine[2000]; /* A single line of input. */
21282141
g.fullHttpReply = 1;
21292142
g.zReqType = "HTTP";
2143
+
21302144
if( cgi_fgets(zLine, sizeof(zLine))==0 ){
21312145
malformed_request("missing header");
21322146
}
21332147
blob_append(&g.httpHeader, zLine, -1);
21342148
cgi_trace(zLine);
@@ -2138,11 +2152,11 @@
21382152
}
21392153
if( fossil_strcmp(zToken,"GET")!=0
21402154
&& fossil_strcmp(zToken,"POST")!=0
21412155
&& fossil_strcmp(zToken,"HEAD")!=0
21422156
){
2143
- malformed_request("unsupported HTTP method: \"%s\" - Fossil only supports"
2157
+ malformed_request("unsupported HTTP method: \"%s\" - Fossil only supports "
21442158
"GET, POST, and HEAD", zToken);
21452159
}
21462160
cgi_setenv("GATEWAY_INTERFACE","CGI/1.0");
21472161
cgi_setenv("REQUEST_METHOD",zToken);
21482162
zToken = extract_token(z, &z);
@@ -2160,11 +2174,10 @@
21602174
}
21612175
if( zIpAddr ){
21622176
cgi_setenv("REMOTE_ADDR", zIpAddr);
21632177
g.zIpAddr = fossil_strdup(zIpAddr);
21642178
}
2165
-
21662179
21672180
/* Get all the optional fields that follow the first line.
21682181
*/
21692182
while( cgi_fgets(zLine,sizeof(zLine)) ){
21702183
char *zFieldName;
21712184
--- src/cgi.c
+++ src/cgi.c
@@ -505,11 +505,11 @@
505 && strcmp(zContentType,"text/html")!=0
506 ){
507 /* Do not cache HTML replies as those will have been generated and
508 ** will likely, therefore, contains a nonce and we want that nonce to
509 ** be different every time. */
510 blob_appendf(&hdr, "ETag: %s\r\n", etag_tag());
511 blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
512 if( etag_mtime()>0 ){
513 blob_appendf(&hdr, "Last-Modified: %s\r\n",
514 cgi_rfc822_datestamp(etag_mtime()));
515 }
@@ -964,11 +964,11 @@
964 ** * it is impossible for a cookie or query parameter to
965 ** override the value of an environment variable since
966 ** environment variables always have uppercase names.
967 **
968 ** 2018-03-29: Also ignore the entry if NAME that contains any characters
969 ** other than [a-zA-Z0-9_]. There are no known exploits involving unusual
970 ** names that contain characters outside that set, but it never hurts to
971 ** be extra cautious when sanitizing inputs.
972 **
973 ** Parameters are separated by the "terminator" character. Whitespace
974 ** before the NAME is ignored.
@@ -1280,36 +1280,49 @@
1280
1281 /* Forward declaration */
1282 static NORETURN void malformed_request(const char *zMsg, ...);
1283
1284 /*
1285 ** Checks the QUERY_STRING environment variable, sets it up
1286 ** via add_param_list() and, if found, applies its "skin"
1287 ** setting. Returns 0 if no QUERY_STRING is set, 1 if it is,
1288 ** and 2 if it sets the skin (in which case the cookie may
1289 ** still need flushing by the page, via cookie_render()).
 
 
 
 
 
1290 */
1291 int cgi_setup_query_string(void){
1292 int rc = 0;
1293 char * z = (char*)P("QUERY_STRING");
1294 if( z ){
1295 ++rc;
1296 z = fossil_strdup(z);
1297 add_param_list(z, '&');
1298 z = (char*)P("skin");
1299 if( z ){
1300 char *zErr = skin_use_alternative(z, 2, SKIN_FROM_QPARAM);
1301 ++rc;
1302 if( !zErr && P("once")==0 ){
1303 cookie_write_parameter("skin","skin",z);
1304 /* Per /chat discussion, passing ?skin=... without "once"
1305 ** implies the "udc" argument, so we force that into the
1306 ** environment here. */
1307 cgi_set_parameter_nocopy("udc", "1", 1);
1308 }
1309 fossil_free(zErr);
1310 }
 
 
 
 
 
 
 
 
1311 }
1312 return rc;
1313 }
1314
1315 /*
@@ -2125,10 +2138,11 @@
2125 int i;
2126 const char *zScheme = "http";
2127 char zLine[2000]; /* A single line of input. */
2128 g.fullHttpReply = 1;
2129 g.zReqType = "HTTP";
 
2130 if( cgi_fgets(zLine, sizeof(zLine))==0 ){
2131 malformed_request("missing header");
2132 }
2133 blob_append(&g.httpHeader, zLine, -1);
2134 cgi_trace(zLine);
@@ -2138,11 +2152,11 @@
2138 }
2139 if( fossil_strcmp(zToken,"GET")!=0
2140 && fossil_strcmp(zToken,"POST")!=0
2141 && fossil_strcmp(zToken,"HEAD")!=0
2142 ){
2143 malformed_request("unsupported HTTP method: \"%s\" - Fossil only supports"
2144 "GET, POST, and HEAD", zToken);
2145 }
2146 cgi_setenv("GATEWAY_INTERFACE","CGI/1.0");
2147 cgi_setenv("REQUEST_METHOD",zToken);
2148 zToken = extract_token(z, &z);
@@ -2160,11 +2174,10 @@
2160 }
2161 if( zIpAddr ){
2162 cgi_setenv("REMOTE_ADDR", zIpAddr);
2163 g.zIpAddr = fossil_strdup(zIpAddr);
2164 }
2165
2166
2167 /* Get all the optional fields that follow the first line.
2168 */
2169 while( cgi_fgets(zLine,sizeof(zLine)) ){
2170 char *zFieldName;
2171
--- src/cgi.c
+++ src/cgi.c
@@ -505,11 +505,11 @@
505 && strcmp(zContentType,"text/html")!=0
506 ){
507 /* Do not cache HTML replies as those will have been generated and
508 ** will likely, therefore, contains a nonce and we want that nonce to
509 ** be different every time. */
510 blob_appendf(&hdr, "ETag: \"%s\"\r\n", etag_tag());
511 blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
512 if( etag_mtime()>0 ){
513 blob_appendf(&hdr, "Last-Modified: %s\r\n",
514 cgi_rfc822_datestamp(etag_mtime()));
515 }
@@ -964,11 +964,11 @@
964 ** * it is impossible for a cookie or query parameter to
965 ** override the value of an environment variable since
966 ** environment variables always have uppercase names.
967 **
968 ** 2018-03-29: Also ignore the entry if NAME that contains any characters
969 ** other than [-a-zA-Z0-9_]. There are no known exploits involving unusual
970 ** names that contain characters outside that set, but it never hurts to
971 ** be extra cautious when sanitizing inputs.
972 **
973 ** Parameters are separated by the "terminator" character. Whitespace
974 ** before the NAME is ignored.
@@ -1280,36 +1280,49 @@
1280
1281 /* Forward declaration */
1282 static NORETURN void malformed_request(const char *zMsg, ...);
1283
1284 /*
1285 ** Checks the QUERY_STRING environment variable, sets it up via
1286 ** add_param_list() and, if found, applies its "skin" setting. Returns
1287 ** 0 if no QUERY_STRING is set, else it returns a bitmask of:
1288 **
1289 ** 0x01 = QUERY_STRING was set up
1290 ** 0x02 = "skin" URL param arg was processed
1291 ** 0x04 = "x-f-l-c" cookie arg was processed.
1292 **
1293 * In the case of the skin, the cookie may still need flushing
1294 ** by the page, via cookie_render().
1295 */
1296 int cgi_setup_query_string(void){
1297 int rc = 0;
1298 char * z = (char*)P("QUERY_STRING");
1299 if( z ){
1300 rc = 0x01;
1301 z = fossil_strdup(z);
1302 add_param_list(z, '&');
1303 z = (char*)P("skin");
1304 if( z ){
1305 char *zErr = skin_use_alternative(z, 2, SKIN_FROM_QPARAM);
1306 rc |= 0x02;
1307 if( !zErr && P("once")==0 ){
1308 cookie_write_parameter("skin","skin",z);
1309 /* Per /chat discussion, passing ?skin=... without "once"
1310 ** implies the "udc" argument, so we force that into the
1311 ** environment here. */
1312 cgi_set_parameter_nocopy("udc", "1", 1);
1313 }
1314 fossil_free(zErr);
1315 }
1316 }
1317 if( !g.syncInfo.zLoginCard && 0!=(z=(char*)P("x-f-l-c")) ){
1318 /* x-f-l-c (X-Fossil-Login-Card card transmitted via cookie
1319 ** instead of in the sync payload. */
1320 rc |= 0x04;
1321 g.syncInfo.zLoginCard = fossil_strdup(z);
1322 g.syncInfo.fLoginCardMode |= 0x02;
1323 cgi_delete_parameter("x-f-l-c");
1324 }
1325 return rc;
1326 }
1327
1328 /*
@@ -2125,10 +2138,11 @@
2138 int i;
2139 const char *zScheme = "http";
2140 char zLine[2000]; /* A single line of input. */
2141 g.fullHttpReply = 1;
2142 g.zReqType = "HTTP";
2143
2144 if( cgi_fgets(zLine, sizeof(zLine))==0 ){
2145 malformed_request("missing header");
2146 }
2147 blob_append(&g.httpHeader, zLine, -1);
2148 cgi_trace(zLine);
@@ -2138,11 +2152,11 @@
2152 }
2153 if( fossil_strcmp(zToken,"GET")!=0
2154 && fossil_strcmp(zToken,"POST")!=0
2155 && fossil_strcmp(zToken,"HEAD")!=0
2156 ){
2157 malformed_request("unsupported HTTP method: \"%s\" - Fossil only supports "
2158 "GET, POST, and HEAD", zToken);
2159 }
2160 cgi_setenv("GATEWAY_INTERFACE","CGI/1.0");
2161 cgi_setenv("REQUEST_METHOD",zToken);
2162 zToken = extract_token(z, &z);
@@ -2160,11 +2174,10 @@
2174 }
2175 if( zIpAddr ){
2176 cgi_setenv("REMOTE_ADDR", zIpAddr);
2177 g.zIpAddr = fossil_strdup(zIpAddr);
2178 }
 
2179
2180 /* Get all the optional fields that follow the first line.
2181 */
2182 while( cgi_fgets(zLine,sizeof(zLine)) ){
2183 char *zFieldName;
2184
+1 -1
--- src/chat.c
+++ src/chat.c
@@ -1321,11 +1321,11 @@
13211321
if( zMsg && zMsg[0] ){
13221322
blob_appendf(&up,"\r\nContent-Disposition: form-data; name=\"msg\"\r\n"
13231323
"\r\n%s\r\n%s", zMsg, zBoundary);
13241324
}
13251325
if( zFilename && blob_read_from_file(&fcontent, zFilename, ExtFILE)>0 ){
1326
- char *zFN = mprintf("%s", file_tail(zAs ? zAs : zFilename));
1326
+ char *zFN = fossil_strdup(file_tail(zAs ? zAs : zFilename));
13271327
int i;
13281328
const char *zMime = mimetype_from_name(zFN);
13291329
for(i=0; zFN[i]; i++){
13301330
char c = zFN[i];
13311331
if( fossil_isalnum(c) ) continue;
13321332
--- src/chat.c
+++ src/chat.c
@@ -1321,11 +1321,11 @@
1321 if( zMsg && zMsg[0] ){
1322 blob_appendf(&up,"\r\nContent-Disposition: form-data; name=\"msg\"\r\n"
1323 "\r\n%s\r\n%s", zMsg, zBoundary);
1324 }
1325 if( zFilename && blob_read_from_file(&fcontent, zFilename, ExtFILE)>0 ){
1326 char *zFN = mprintf("%s", file_tail(zAs ? zAs : zFilename));
1327 int i;
1328 const char *zMime = mimetype_from_name(zFN);
1329 for(i=0; zFN[i]; i++){
1330 char c = zFN[i];
1331 if( fossil_isalnum(c) ) continue;
1332
--- src/chat.c
+++ src/chat.c
@@ -1321,11 +1321,11 @@
1321 if( zMsg && zMsg[0] ){
1322 blob_appendf(&up,"\r\nContent-Disposition: form-data; name=\"msg\"\r\n"
1323 "\r\n%s\r\n%s", zMsg, zBoundary);
1324 }
1325 if( zFilename && blob_read_from_file(&fcontent, zFilename, ExtFILE)>0 ){
1326 char *zFN = fossil_strdup(file_tail(zAs ? zAs : zFilename));
1327 int i;
1328 const char *zMime = mimetype_from_name(zFN);
1329 for(i=0; zFN[i]; i++){
1330 char c = zFN[i];
1331 if( fossil_isalnum(c) ) continue;
1332
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -1386,11 +1386,11 @@
13861386
file_relative_name(g.zLocalRoot, &fname, 1);
13871387
zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
13881388
blob_str(&fname));
13891389
}else{
13901390
file_tempname(&fname, "ci-comment",0);
1391
- zFile = mprintf("%s", blob_str(&fname));
1391
+ zFile = fossil_strdup(blob_str(&fname));
13921392
}
13931393
blob_reset(&fname);
13941394
}
13951395
#if defined(_WIN32)
13961396
blob_add_cr(pPrompt);
13971397
--- src/checkin.c
+++ src/checkin.c
@@ -1386,11 +1386,11 @@
1386 file_relative_name(g.zLocalRoot, &fname, 1);
1387 zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
1388 blob_str(&fname));
1389 }else{
1390 file_tempname(&fname, "ci-comment",0);
1391 zFile = mprintf("%s", blob_str(&fname));
1392 }
1393 blob_reset(&fname);
1394 }
1395 #if defined(_WIN32)
1396 blob_add_cr(pPrompt);
1397
--- src/checkin.c
+++ src/checkin.c
@@ -1386,11 +1386,11 @@
1386 file_relative_name(g.zLocalRoot, &fname, 1);
1387 zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
1388 blob_str(&fname));
1389 }else{
1390 file_tempname(&fname, "ci-comment",0);
1391 zFile = fossil_strdup(blob_str(&fname));
1392 }
1393 blob_reset(&fname);
1394 }
1395 #if defined(_WIN32)
1396 blob_add_cr(pPrompt);
1397
+2 -2
--- src/clone.c
+++ src/clone.c
@@ -348,11 +348,11 @@
348348
const char *zHttpAuth, /* Credentials in the form "user:password" */
349349
int fRemember, /* True to remember credentials for later reuse */
350350
const char *zUrl /* URL for which these credentials apply */
351351
){
352352
if( zHttpAuth && zHttpAuth[0] ){
353
- g.zHttpAuth = mprintf("%s", zHttpAuth);
353
+ g.zHttpAuth = fossil_strdup(zHttpAuth);
354354
}
355355
if( fRemember ){
356356
if( g.zHttpAuth && g.zHttpAuth[0] ){
357357
set_httpauth(g.zHttpAuth);
358358
}else if( zUrl && zUrl[0] ){
@@ -388,11 +388,11 @@
388388
void clone_ssh_find_options(void){
389389
const char *zSshCmd; /* SSH command string */
390390
391391
zSshCmd = find_option("ssh-command","c",1);
392392
if( zSshCmd && zSshCmd[0] ){
393
- g.zSshCmd = mprintf("%s", zSshCmd);
393
+ g.zSshCmd = fossil_strdup(zSshCmd);
394394
}
395395
}
396396
397397
/*
398398
** Set SSH options discovered in global variables (set from command line
399399
--- src/clone.c
+++ src/clone.c
@@ -348,11 +348,11 @@
348 const char *zHttpAuth, /* Credentials in the form "user:password" */
349 int fRemember, /* True to remember credentials for later reuse */
350 const char *zUrl /* URL for which these credentials apply */
351 ){
352 if( zHttpAuth && zHttpAuth[0] ){
353 g.zHttpAuth = mprintf("%s", zHttpAuth);
354 }
355 if( fRemember ){
356 if( g.zHttpAuth && g.zHttpAuth[0] ){
357 set_httpauth(g.zHttpAuth);
358 }else if( zUrl && zUrl[0] ){
@@ -388,11 +388,11 @@
388 void clone_ssh_find_options(void){
389 const char *zSshCmd; /* SSH command string */
390
391 zSshCmd = find_option("ssh-command","c",1);
392 if( zSshCmd && zSshCmd[0] ){
393 g.zSshCmd = mprintf("%s", zSshCmd);
394 }
395 }
396
397 /*
398 ** Set SSH options discovered in global variables (set from command line
399
--- src/clone.c
+++ src/clone.c
@@ -348,11 +348,11 @@
348 const char *zHttpAuth, /* Credentials in the form "user:password" */
349 int fRemember, /* True to remember credentials for later reuse */
350 const char *zUrl /* URL for which these credentials apply */
351 ){
352 if( zHttpAuth && zHttpAuth[0] ){
353 g.zHttpAuth = fossil_strdup(zHttpAuth);
354 }
355 if( fRemember ){
356 if( g.zHttpAuth && g.zHttpAuth[0] ){
357 set_httpauth(g.zHttpAuth);
358 }else if( zUrl && zUrl[0] ){
@@ -388,11 +388,11 @@
388 void clone_ssh_find_options(void){
389 const char *zSshCmd; /* SSH command string */
390
391 zSshCmd = find_option("ssh-command","c",1);
392 if( zSshCmd && zSshCmd[0] ){
393 g.zSshCmd = fossil_strdup(zSshCmd);
394 }
395 }
396
397 /*
398 ** Set SSH options discovered in global variables (set from command line
399
+2 -2
--- src/comformat.c
+++ src/comformat.c
@@ -807,17 +807,17 @@
807807
verify_all_options();
808808
zPrefix = zText = zOrigText = 0;
809809
if( fromFile ){
810810
Blob fileData;
811811
blob_read_from_file(&fileData, fromFile, ExtFILE);
812
- zText = mprintf("%s", blob_str(&fileData));
812
+ zText = fossil_strdup(blob_str(&fileData));
813813
blob_reset(&fileData);
814814
}
815815
if( fromOrig ){
816816
Blob fileData;
817817
blob_read_from_file(&fileData, fromOrig, ExtFILE);
818
- zOrigText = mprintf("%s", blob_str(&fileData));
818
+ zOrigText = fossil_strdup(blob_str(&fileData));
819819
blob_reset(&fileData);
820820
}
821821
for(i=2; i<g.argc; i++){
822822
if( zText==0 ){
823823
zText = g.argv[i];
824824
--- src/comformat.c
+++ src/comformat.c
@@ -807,17 +807,17 @@
807 verify_all_options();
808 zPrefix = zText = zOrigText = 0;
809 if( fromFile ){
810 Blob fileData;
811 blob_read_from_file(&fileData, fromFile, ExtFILE);
812 zText = mprintf("%s", blob_str(&fileData));
813 blob_reset(&fileData);
814 }
815 if( fromOrig ){
816 Blob fileData;
817 blob_read_from_file(&fileData, fromOrig, ExtFILE);
818 zOrigText = mprintf("%s", blob_str(&fileData));
819 blob_reset(&fileData);
820 }
821 for(i=2; i<g.argc; i++){
822 if( zText==0 ){
823 zText = g.argv[i];
824
--- src/comformat.c
+++ src/comformat.c
@@ -807,17 +807,17 @@
807 verify_all_options();
808 zPrefix = zText = zOrigText = 0;
809 if( fromFile ){
810 Blob fileData;
811 blob_read_from_file(&fileData, fromFile, ExtFILE);
812 zText = fossil_strdup(blob_str(&fileData));
813 blob_reset(&fileData);
814 }
815 if( fromOrig ){
816 Blob fileData;
817 blob_read_from_file(&fileData, fromOrig, ExtFILE);
818 zOrigText = fossil_strdup(blob_str(&fileData));
819 blob_reset(&fileData);
820 }
821 for(i=2; i<g.argc; i++){
822 if( zText==0 ){
823 zText = g.argv[i];
824
--- src/configure.c
+++ src/configure.c
@@ -370,10 +370,14 @@
370370
** /user $MTIME $LOGIN pw $VALUE cap $VALUE info $VALUE photo $VALUE
371371
** /shun $MTIME $UUID scom $VALUE
372372
** /reportfmt $MTIME $TITLE owner $VALUE cols $VALUE sqlcode $VALUE jx $JSON
373373
** /concealed $MTIME $HASH content $VALUE
374374
** /subscriber $SMTIME $SEMAIL suname $V ...
375
+**
376
+** NAME-specific notes:
377
+**
378
+** - /reportftm's $MTIME is in Julian, not the Unix epoch.
375379
*/
376380
void configure_receive(const char *zName, Blob *pContent, int groupMask){
377381
int checkMask; /* Masks for which we must first check existance of tables */
378382
379383
checkMask = CONFIGSET_SCRIBER;
380384
--- src/configure.c
+++ src/configure.c
@@ -370,10 +370,14 @@
370 ** /user $MTIME $LOGIN pw $VALUE cap $VALUE info $VALUE photo $VALUE
371 ** /shun $MTIME $UUID scom $VALUE
372 ** /reportfmt $MTIME $TITLE owner $VALUE cols $VALUE sqlcode $VALUE jx $JSON
373 ** /concealed $MTIME $HASH content $VALUE
374 ** /subscriber $SMTIME $SEMAIL suname $V ...
 
 
 
 
375 */
376 void configure_receive(const char *zName, Blob *pContent, int groupMask){
377 int checkMask; /* Masks for which we must first check existance of tables */
378
379 checkMask = CONFIGSET_SCRIBER;
380
--- src/configure.c
+++ src/configure.c
@@ -370,10 +370,14 @@
370 ** /user $MTIME $LOGIN pw $VALUE cap $VALUE info $VALUE photo $VALUE
371 ** /shun $MTIME $UUID scom $VALUE
372 ** /reportfmt $MTIME $TITLE owner $VALUE cols $VALUE sqlcode $VALUE jx $JSON
373 ** /concealed $MTIME $HASH content $VALUE
374 ** /subscriber $SMTIME $SEMAIL suname $V ...
375 **
376 ** NAME-specific notes:
377 **
378 ** - /reportftm's $MTIME is in Julian, not the Unix epoch.
379 */
380 void configure_receive(const char *zName, Blob *pContent, int groupMask){
381 int checkMask; /* Masks for which we must first check existance of tables */
382
383 checkMask = CONFIGSET_SCRIBER;
384
+1 -1
--- src/cookies.c
+++ src/cookies.c
@@ -86,11 +86,11 @@
8686
void cookie_parse(void){
8787
char *z;
8888
if( cookies.bIsInit ) return;
8989
z = (char*)P(DISPLAY_SETTINGS_COOKIE);
9090
if( z==0 ) z = "";
91
- cookies.zCookieValue = z = mprintf("%s", z);
91
+ cookies.zCookieValue = z = fossil_strdup(z);
9292
cookies.bIsInit = 1;
9393
while( cookies.nParam<COOKIE_NPARAM ){
9494
while( fossil_isspace(z[0]) ) z++;
9595
if( z[0]==0 ) break;
9696
cookies.aParam[cookies.nParam].zPName = z;
9797
--- src/cookies.c
+++ src/cookies.c
@@ -86,11 +86,11 @@
86 void cookie_parse(void){
87 char *z;
88 if( cookies.bIsInit ) return;
89 z = (char*)P(DISPLAY_SETTINGS_COOKIE);
90 if( z==0 ) z = "";
91 cookies.zCookieValue = z = mprintf("%s", z);
92 cookies.bIsInit = 1;
93 while( cookies.nParam<COOKIE_NPARAM ){
94 while( fossil_isspace(z[0]) ) z++;
95 if( z[0]==0 ) break;
96 cookies.aParam[cookies.nParam].zPName = z;
97
--- src/cookies.c
+++ src/cookies.c
@@ -86,11 +86,11 @@
86 void cookie_parse(void){
87 char *z;
88 if( cookies.bIsInit ) return;
89 z = (char*)P(DISPLAY_SETTINGS_COOKIE);
90 if( z==0 ) z = "";
91 cookies.zCookieValue = z = fossil_strdup(z);
92 cookies.bIsInit = 1;
93 while( cookies.nParam<COOKIE_NPARAM ){
94 while( fossil_isspace(z[0]) ) z++;
95 if( z[0]==0 ) break;
96 cookies.aParam[cookies.nParam].zPName = z;
97
+1 -1
--- src/diff.c
+++ src/diff.c
@@ -3781,11 +3781,11 @@
37813781
unsigned clr1, clr2, clr;
37823782
int bBlame = g.zPath[0]!='a';/* True for BLAME output. False for ANNOTATE. */
37833783
37843784
/* Gather query parameters */
37853785
login_check_credentials();
3786
- if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
3786
+ if( !g.perm.Read || g.zLogin==0 ){ login_needed(g.anon.Read); return; }
37873787
if( exclude_spiders(0) ) return;
37883788
fossil_nice_default();
37893789
zFilename = P("filename");
37903790
zRevision = PD("checkin",0);
37913791
zOrigin = P("origin");
37923792
--- src/diff.c
+++ src/diff.c
@@ -3781,11 +3781,11 @@
3781 unsigned clr1, clr2, clr;
3782 int bBlame = g.zPath[0]!='a';/* True for BLAME output. False for ANNOTATE. */
3783
3784 /* Gather query parameters */
3785 login_check_credentials();
3786 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
3787 if( exclude_spiders(0) ) return;
3788 fossil_nice_default();
3789 zFilename = P("filename");
3790 zRevision = PD("checkin",0);
3791 zOrigin = P("origin");
3792
--- src/diff.c
+++ src/diff.c
@@ -3781,11 +3781,11 @@
3781 unsigned clr1, clr2, clr;
3782 int bBlame = g.zPath[0]!='a';/* True for BLAME output. False for ANNOTATE. */
3783
3784 /* Gather query parameters */
3785 login_check_credentials();
3786 if( !g.perm.Read || g.zLogin==0 ){ login_needed(g.anon.Read); return; }
3787 if( exclude_spiders(0) ) return;
3788 fossil_nice_default();
3789 zFilename = P("filename");
3790 zRevision = PD("checkin",0);
3791 zOrigin = P("origin");
3792
+7 -1
--- src/diff.tcl
+++ src/diff.tcl
@@ -500,10 +500,12 @@
500500
if {$fn==""} return
501501
set out [open $fn wb]
502502
puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
503503
puts $out "# to see the graphical diff.\n#"
504504
puts $out "set fossilcmd {}"
505
+ puts $out "set darkmode $::darkmode"
506
+ puts $out "set debug $::debug"
505507
puts $out "set prog [list $::prog]"
506508
puts $out "set difftxt \173"
507509
foreach e $::difftxt {puts $out [list $e]}
508510
puts $out "\175"
509511
puts $out "eval \$prog"
@@ -606,11 +608,15 @@
606608
::ttk::button .bb.quit -text {Quit} -command exit
607609
::ttk::button .bb.reload -text {Reload} -command reloadDiff
608610
::ttk::button .bb.invert -text {Invert} -command invertDiff
609611
::ttk::button .bb.save -text {Save As...} -command saveDiff
610612
::ttk::button .bb.search -text {Search} -command searchOnOff
611
-pack .bb.quit .bb.reload .bb.invert -side left
613
+pack .bb.quit -side left
614
+if {$fossilcmd ne ""} {
615
+ pack .bb.reload -side left
616
+}
617
+pack .bb.invert -side left
612618
if {$fossilcmd!=""} {pack .bb.save -side left}
613619
pack .bb.files .bb.search -side left
614620
grid rowconfigure . 1 -weight 1
615621
grid columnconfigure . 1 -weight 1
616622
grid columnconfigure . 4 -weight 1
617623
--- src/diff.tcl
+++ src/diff.tcl
@@ -500,10 +500,12 @@
500 if {$fn==""} return
501 set out [open $fn wb]
502 puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
503 puts $out "# to see the graphical diff.\n#"
504 puts $out "set fossilcmd {}"
 
 
505 puts $out "set prog [list $::prog]"
506 puts $out "set difftxt \173"
507 foreach e $::difftxt {puts $out [list $e]}
508 puts $out "\175"
509 puts $out "eval \$prog"
@@ -606,11 +608,15 @@
606 ::ttk::button .bb.quit -text {Quit} -command exit
607 ::ttk::button .bb.reload -text {Reload} -command reloadDiff
608 ::ttk::button .bb.invert -text {Invert} -command invertDiff
609 ::ttk::button .bb.save -text {Save As...} -command saveDiff
610 ::ttk::button .bb.search -text {Search} -command searchOnOff
611 pack .bb.quit .bb.reload .bb.invert -side left
 
 
 
 
612 if {$fossilcmd!=""} {pack .bb.save -side left}
613 pack .bb.files .bb.search -side left
614 grid rowconfigure . 1 -weight 1
615 grid columnconfigure . 1 -weight 1
616 grid columnconfigure . 4 -weight 1
617
--- src/diff.tcl
+++ src/diff.tcl
@@ -500,10 +500,12 @@
500 if {$fn==""} return
501 set out [open $fn wb]
502 puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
503 puts $out "# to see the graphical diff.\n#"
504 puts $out "set fossilcmd {}"
505 puts $out "set darkmode $::darkmode"
506 puts $out "set debug $::debug"
507 puts $out "set prog [list $::prog]"
508 puts $out "set difftxt \173"
509 foreach e $::difftxt {puts $out [list $e]}
510 puts $out "\175"
511 puts $out "eval \$prog"
@@ -606,11 +608,15 @@
608 ::ttk::button .bb.quit -text {Quit} -command exit
609 ::ttk::button .bb.reload -text {Reload} -command reloadDiff
610 ::ttk::button .bb.invert -text {Invert} -command invertDiff
611 ::ttk::button .bb.save -text {Save As...} -command saveDiff
612 ::ttk::button .bb.search -text {Search} -command searchOnOff
613 pack .bb.quit -side left
614 if {$fossilcmd ne ""} {
615 pack .bb.reload -side left
616 }
617 pack .bb.invert -side left
618 if {$fossilcmd!=""} {pack .bb.save -side left}
619 pack .bb.files .bb.search -side left
620 grid rowconfigure . 1 -weight 1
621 grid columnconfigure . 1 -weight 1
622 grid columnconfigure . 4 -weight 1
623
+2 -7
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -667,16 +667,11 @@
667667
blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1);
668668
blob_append_escaped_arg(&cmd, zFile2, 1);
669669
}
670670
671671
/* Run the external diff command */
672
- if( fossil_system(blob_str(&cmd)) ){
673
-#if !defined(_WIN32)
674
- /* On Windows, exit codes are unreliable. */
675
- fossil_warning("External diff command failed: %b\n", &cmd);
676
-#endif
677
- }
672
+ fossil_system(blob_str(&cmd));
678673
679674
/* Delete the temporary file and clean up memory used */
680675
if( useTempfile ) file_delete(blob_str(&nameFile1));
681676
blob_reset(&nameFile1);
682677
blob_reset(&cmd);
@@ -1295,11 +1290,11 @@
12951290
**
12961291
** Show the difference between the current version of each of the FILEs
12971292
** specified (as they exist on disk) and that same file as it was checked-
12981293
** out. Or if the FILE arguments are omitted, show all unsaved changes
12991294
** currently in the working check-out. The "gdiff" variant means to
1300
-** to use a GUI diff.
1295
+** use a GUI diff.
13011296
**
13021297
** The default output format is a "unified patch" (the same as the
13031298
** output of "diff -u" on most unix systems). Many alternative formats
13041299
** are available. A few of the more useful alternatives:
13051300
**
13061301
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -667,16 +667,11 @@
667 blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1);
668 blob_append_escaped_arg(&cmd, zFile2, 1);
669 }
670
671 /* Run the external diff command */
672 if( fossil_system(blob_str(&cmd)) ){
673 #if !defined(_WIN32)
674 /* On Windows, exit codes are unreliable. */
675 fossil_warning("External diff command failed: %b\n", &cmd);
676 #endif
677 }
678
679 /* Delete the temporary file and clean up memory used */
680 if( useTempfile ) file_delete(blob_str(&nameFile1));
681 blob_reset(&nameFile1);
682 blob_reset(&cmd);
@@ -1295,11 +1290,11 @@
1295 **
1296 ** Show the difference between the current version of each of the FILEs
1297 ** specified (as they exist on disk) and that same file as it was checked-
1298 ** out. Or if the FILE arguments are omitted, show all unsaved changes
1299 ** currently in the working check-out. The "gdiff" variant means to
1300 ** to use a GUI diff.
1301 **
1302 ** The default output format is a "unified patch" (the same as the
1303 ** output of "diff -u" on most unix systems). Many alternative formats
1304 ** are available. A few of the more useful alternatives:
1305 **
1306
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -667,16 +667,11 @@
667 blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1);
668 blob_append_escaped_arg(&cmd, zFile2, 1);
669 }
670
671 /* Run the external diff command */
672 fossil_system(blob_str(&cmd));
 
 
 
 
 
673
674 /* Delete the temporary file and clean up memory used */
675 if( useTempfile ) file_delete(blob_str(&nameFile1));
676 blob_reset(&nameFile1);
677 blob_reset(&cmd);
@@ -1295,11 +1290,11 @@
1290 **
1291 ** Show the difference between the current version of each of the FILEs
1292 ** specified (as they exist on disk) and that same file as it was checked-
1293 ** out. Or if the FILE arguments are omitted, show all unsaved changes
1294 ** currently in the working check-out. The "gdiff" variant means to
1295 ** use a GUI diff.
1296 **
1297 ** The default output format is a "unified patch" (the same as the
1298 ** output of "diff -u" on most unix systems). Many alternative formats
1299 ** are available. A few of the more useful alternatives:
1300 **
1301
+11 -3
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
9494
** Generate an ETag
9595
*/
9696
void etag_check(unsigned eFlags, const char *zHash){
9797
const char *zIfNoneMatch;
9898
char zBuf[50];
99
+ const int cchETag = 32; /* Not including NULL terminator. */
100
+ int cch; /* Length of zIfNoneMatch header. */
99101
assert( zETag[0]==0 ); /* Only call this routine once! */
100102
101103
if( etagCancelled ) return;
102104
103105
/* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
157159
md5sum_step_text("\n", 1);
158160
}
159161
}
160162
161163
/* Generate the ETag */
162
- memcpy(zETag, md5sum_finish(0), 33);
164
+ memcpy(zETag, md5sum_finish(0), cchETag+1);
163165
164166
/* Check to see if the generated ETag matches If-None-Match and
165
- ** generate a 304 reply if it does. */
167
+ ** generate a 304 reply if it does. Test both with and without
168
+ ** double quotes. */
166169
zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
167170
if( zIfNoneMatch==0 ) return;
168
- if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
171
+ cch = strlen(zIfNoneMatch);
172
+ if( cch==cchETag+2 && zIfNoneMatch[0]=='"' && zIfNoneMatch[cch-1]=='"' ){
173
+ if( memcmp(&zIfNoneMatch[1],zETag,cchETag)!=0 ) return;
174
+ }else{
175
+ if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
176
+ }
169177
170178
/* If we get this far, it means that the content has
171179
** not changed and we can do a 304 reply */
172180
cgi_reset_content();
173181
cgi_set_status(304, "Not Modified");
174182
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
94 ** Generate an ETag
95 */
96 void etag_check(unsigned eFlags, const char *zHash){
97 const char *zIfNoneMatch;
98 char zBuf[50];
 
 
99 assert( zETag[0]==0 ); /* Only call this routine once! */
100
101 if( etagCancelled ) return;
102
103 /* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
157 md5sum_step_text("\n", 1);
158 }
159 }
160
161 /* Generate the ETag */
162 memcpy(zETag, md5sum_finish(0), 33);
163
164 /* Check to see if the generated ETag matches If-None-Match and
165 ** generate a 304 reply if it does. */
 
166 zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
167 if( zIfNoneMatch==0 ) return;
168 if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
 
 
 
 
 
169
170 /* If we get this far, it means that the content has
171 ** not changed and we can do a 304 reply */
172 cgi_reset_content();
173 cgi_set_status(304, "Not Modified");
174
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
94 ** Generate an ETag
95 */
96 void etag_check(unsigned eFlags, const char *zHash){
97 const char *zIfNoneMatch;
98 char zBuf[50];
99 const int cchETag = 32; /* Not including NULL terminator. */
100 int cch; /* Length of zIfNoneMatch header. */
101 assert( zETag[0]==0 ); /* Only call this routine once! */
102
103 if( etagCancelled ) return;
104
105 /* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
159 md5sum_step_text("\n", 1);
160 }
161 }
162
163 /* Generate the ETag */
164 memcpy(zETag, md5sum_finish(0), cchETag+1);
165
166 /* Check to see if the generated ETag matches If-None-Match and
167 ** generate a 304 reply if it does. Test both with and without
168 ** double quotes. */
169 zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
170 if( zIfNoneMatch==0 ) return;
171 cch = strlen(zIfNoneMatch);
172 if( cch==cchETag+2 && zIfNoneMatch[0]=='"' && zIfNoneMatch[cch-1]=='"' ){
173 if( memcmp(&zIfNoneMatch[1],zETag,cchETag)!=0 ) return;
174 }else{
175 if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
176 }
177
178 /* If we get this far, it means that the content has
179 ** not changed and we can do a 304 reply */
180 cgi_reset_content();
181 cgi_set_status(304, "Not Modified");
182
+1 -1
--- src/event.c
+++ src/event.c
@@ -382,11 +382,11 @@
382382
const char *zClr; /* Name of the background color */
383383
const char *zMimetype = P("mimetype"); /* Mimetype of zBody */
384384
int isNew = 0;
385385
386386
if( zBody ){
387
- zBody = mprintf("%s", zBody);
387
+ zBody = fossil_strdup(zBody);
388388
}
389389
login_check_credentials();
390390
zId = P("name");
391391
if( zId==0 ){
392392
zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
393393
--- src/event.c
+++ src/event.c
@@ -382,11 +382,11 @@
382 const char *zClr; /* Name of the background color */
383 const char *zMimetype = P("mimetype"); /* Mimetype of zBody */
384 int isNew = 0;
385
386 if( zBody ){
387 zBody = mprintf("%s", zBody);
388 }
389 login_check_credentials();
390 zId = P("name");
391 if( zId==0 ){
392 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
393
--- src/event.c
+++ src/event.c
@@ -382,11 +382,11 @@
382 const char *zClr; /* Name of the background color */
383 const char *zMimetype = P("mimetype"); /* Mimetype of zBody */
384 int isNew = 0;
385
386 if( zBody ){
387 zBody = fossil_strdup(zBody);
388 }
389 login_check_credentials();
390 zId = P("name");
391 if( zId==0 ){
392 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
393
+5 -5
--- src/export.c
+++ src/export.c
@@ -58,11 +58,11 @@
5858
}
5959
db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
6060
db_bind_text(&q, ":user", zUser);
6161
if( db_step(&q)!=SQLITE_ROW ){
6262
db_reset(&q);
63
- zName = mprintf("%s", zUser);
63
+ zName = fossil_strdup(zUser);
6464
for(i=j=0; zName[i]; i++){
6565
if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
6666
zName[j++] = zName[i];
6767
}
6868
}
@@ -102,11 +102,11 @@
102102
atEmailFirst = i+1;
103103
}
104104
}
105105
if( zContact[i]==0 ){
106106
/* No email address found. Take as user info if not empty */
107
- zName = mprintf("%s", zContact[0] ? zContact : zUser);
107
+ zName = fossil_strdup(zContact[0] ? zContact : zUser);
108108
for(i=j=0; zName[i]; i++){
109109
if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
110110
zName[j++] = zName[i];
111111
}
112112
}
@@ -149,11 +149,11 @@
149149
for(j=0; j<i && zContact[j] && zContact[j]==' '; j++){}
150150
zName = mprintf("%.*s", i-j+1, &zContact[j]);
151151
}
152152
}
153153
154
- if( zName==NULL ) zName = mprintf("%s", zUser);
154
+ if( zName==NULL ) zName = fossil_strdup(zUser);
155155
for(i=j=0; zName[i]; i++){
156156
if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
157157
zName[j++] = zName[i];
158158
}
159159
}
@@ -172,11 +172,11 @@
172172
** https://git-scm.com/docs/git-check-ref-format
173173
** This implementation assumes we are only printing
174174
** the branch or tag part of the reference.
175175
*/
176176
static void print_ref(const char *zRef){
177
- char *zEncoded = mprintf("%s", zRef);
177
+ char *zEncoded = fossil_strdup(zRef);
178178
int i, w;
179179
if (zEncoded[0]=='@' && zEncoded[1]=='\0'){
180180
putchar(REFREPLACEMENT);
181181
return;
182182
}
@@ -1152,11 +1152,11 @@
11521152
TAG_BRANCH, rid
11531153
);
11541154
if( fossil_strcmp(zBranch,"trunk")==0 ){
11551155
assert( gitmirror_mainbranch!=0 );
11561156
fossil_free(zBranch);
1157
- zBranch = mprintf("%s",gitmirror_mainbranch);
1157
+ zBranch = fossil_strdup(gitmirror_mainbranch);
11581158
}else if( zBranch==0 ){
11591159
zBranch = mprintf("unknown");
11601160
}else{
11611161
gitmirror_sanitize_name(zBranch);
11621162
}
11631163
--- src/export.c
+++ src/export.c
@@ -58,11 +58,11 @@
58 }
59 db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
60 db_bind_text(&q, ":user", zUser);
61 if( db_step(&q)!=SQLITE_ROW ){
62 db_reset(&q);
63 zName = mprintf("%s", zUser);
64 for(i=j=0; zName[i]; i++){
65 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
66 zName[j++] = zName[i];
67 }
68 }
@@ -102,11 +102,11 @@
102 atEmailFirst = i+1;
103 }
104 }
105 if( zContact[i]==0 ){
106 /* No email address found. Take as user info if not empty */
107 zName = mprintf("%s", zContact[0] ? zContact : zUser);
108 for(i=j=0; zName[i]; i++){
109 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
110 zName[j++] = zName[i];
111 }
112 }
@@ -149,11 +149,11 @@
149 for(j=0; j<i && zContact[j] && zContact[j]==' '; j++){}
150 zName = mprintf("%.*s", i-j+1, &zContact[j]);
151 }
152 }
153
154 if( zName==NULL ) zName = mprintf("%s", zUser);
155 for(i=j=0; zName[i]; i++){
156 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
157 zName[j++] = zName[i];
158 }
159 }
@@ -172,11 +172,11 @@
172 ** https://git-scm.com/docs/git-check-ref-format
173 ** This implementation assumes we are only printing
174 ** the branch or tag part of the reference.
175 */
176 static void print_ref(const char *zRef){
177 char *zEncoded = mprintf("%s", zRef);
178 int i, w;
179 if (zEncoded[0]=='@' && zEncoded[1]=='\0'){
180 putchar(REFREPLACEMENT);
181 return;
182 }
@@ -1152,11 +1152,11 @@
1152 TAG_BRANCH, rid
1153 );
1154 if( fossil_strcmp(zBranch,"trunk")==0 ){
1155 assert( gitmirror_mainbranch!=0 );
1156 fossil_free(zBranch);
1157 zBranch = mprintf("%s",gitmirror_mainbranch);
1158 }else if( zBranch==0 ){
1159 zBranch = mprintf("unknown");
1160 }else{
1161 gitmirror_sanitize_name(zBranch);
1162 }
1163
--- src/export.c
+++ src/export.c
@@ -58,11 +58,11 @@
58 }
59 db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
60 db_bind_text(&q, ":user", zUser);
61 if( db_step(&q)!=SQLITE_ROW ){
62 db_reset(&q);
63 zName = fossil_strdup(zUser);
64 for(i=j=0; zName[i]; i++){
65 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
66 zName[j++] = zName[i];
67 }
68 }
@@ -102,11 +102,11 @@
102 atEmailFirst = i+1;
103 }
104 }
105 if( zContact[i]==0 ){
106 /* No email address found. Take as user info if not empty */
107 zName = fossil_strdup(zContact[0] ? zContact : zUser);
108 for(i=j=0; zName[i]; i++){
109 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
110 zName[j++] = zName[i];
111 }
112 }
@@ -149,11 +149,11 @@
149 for(j=0; j<i && zContact[j] && zContact[j]==' '; j++){}
150 zName = mprintf("%.*s", i-j+1, &zContact[j]);
151 }
152 }
153
154 if( zName==NULL ) zName = fossil_strdup(zUser);
155 for(i=j=0; zName[i]; i++){
156 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
157 zName[j++] = zName[i];
158 }
159 }
@@ -172,11 +172,11 @@
172 ** https://git-scm.com/docs/git-check-ref-format
173 ** This implementation assumes we are only printing
174 ** the branch or tag part of the reference.
175 */
176 static void print_ref(const char *zRef){
177 char *zEncoded = fossil_strdup(zRef);
178 int i, w;
179 if (zEncoded[0]=='@' && zEncoded[1]=='\0'){
180 putchar(REFREPLACEMENT);
181 return;
182 }
@@ -1152,11 +1152,11 @@
1152 TAG_BRANCH, rid
1153 );
1154 if( fossil_strcmp(zBranch,"trunk")==0 ){
1155 assert( gitmirror_mainbranch!=0 );
1156 fossil_free(zBranch);
1157 zBranch = fossil_strdup(gitmirror_mainbranch);
1158 }else if( zBranch==0 ){
1159 zBranch = mprintf("unknown");
1160 }else{
1161 gitmirror_sanitize_name(zBranch);
1162 }
1163
+5 -5
--- src/file.c
+++ src/file.c
@@ -260,11 +260,11 @@
260260
int i, nName;
261261
char *zName, zBuf[1000];
262262
263263
nName = strlen(zLinkFile);
264264
if( nName>=(int)sizeof(zBuf) ){
265
- zName = mprintf("%s", zLinkFile);
265
+ zName = fossil_strdup(zLinkFile);
266266
}else{
267267
zName = zBuf;
268268
memcpy(zName, zLinkFile, nName+1);
269269
}
270270
nName = file_simplify_name(zName, nName, 0);
@@ -425,11 +425,11 @@
425425
*/
426426
int file_isdir(const char *zFilename, int eFType){
427427
int rc;
428428
char *zFN;
429429
430
- zFN = mprintf("%s", zFilename);
430
+ zFN = fossil_strdup(zFilename);
431431
file_simplify_name(zFN, -1, 0);
432432
rc = getStat(zFN, eFType);
433433
if( rc ){
434434
rc = 0; /* It does not exist at all. */
435435
}else if( S_ISDIR(fx.fileStat.st_mode) ){
@@ -904,11 +904,11 @@
904904
){
905905
int nName, rc = 0;
906906
char *zName;
907907
908908
nName = strlen(zFilename);
909
- zName = mprintf("%s", zFilename);
909
+ zName = fossil_strdup(zFilename);
910910
nName = file_simplify_name(zName, nName, 0);
911911
while( nName>0 && zName[nName-1]!='/' ){ nName--; }
912912
if( nName>1 ){
913913
zName[nName-1] = 0;
914914
if( file_isdir(zName, eFType)!=1 ){
@@ -1277,13 +1277,13 @@
12771277
const char *zTail;
12781278
for(i=2; i<g.argc; i++){
12791279
zTail = file_skip_userhost(g.argv[i]);
12801280
if( zTail ){
12811281
fossil_print("... ON REMOTE: %.*s\n", (int)(zTail-g.argv[i]), g.argv[i]);
1282
- z = mprintf("%s", zTail);
1282
+ z = fossil_strdup(zTail);
12831283
}else{
1284
- z = mprintf("%s", g.argv[i]);
1284
+ z = fossil_strdup(g.argv[i]);
12851285
}
12861286
fossil_print("[%s] -> ", z);
12871287
file_simplify_name(z, -1, 0);
12881288
fossil_print("[%s]\n", z);
12891289
fossil_free(z);
12901290
--- src/file.c
+++ src/file.c
@@ -260,11 +260,11 @@
260 int i, nName;
261 char *zName, zBuf[1000];
262
263 nName = strlen(zLinkFile);
264 if( nName>=(int)sizeof(zBuf) ){
265 zName = mprintf("%s", zLinkFile);
266 }else{
267 zName = zBuf;
268 memcpy(zName, zLinkFile, nName+1);
269 }
270 nName = file_simplify_name(zName, nName, 0);
@@ -425,11 +425,11 @@
425 */
426 int file_isdir(const char *zFilename, int eFType){
427 int rc;
428 char *zFN;
429
430 zFN = mprintf("%s", zFilename);
431 file_simplify_name(zFN, -1, 0);
432 rc = getStat(zFN, eFType);
433 if( rc ){
434 rc = 0; /* It does not exist at all. */
435 }else if( S_ISDIR(fx.fileStat.st_mode) ){
@@ -904,11 +904,11 @@
904 ){
905 int nName, rc = 0;
906 char *zName;
907
908 nName = strlen(zFilename);
909 zName = mprintf("%s", zFilename);
910 nName = file_simplify_name(zName, nName, 0);
911 while( nName>0 && zName[nName-1]!='/' ){ nName--; }
912 if( nName>1 ){
913 zName[nName-1] = 0;
914 if( file_isdir(zName, eFType)!=1 ){
@@ -1277,13 +1277,13 @@
1277 const char *zTail;
1278 for(i=2; i<g.argc; i++){
1279 zTail = file_skip_userhost(g.argv[i]);
1280 if( zTail ){
1281 fossil_print("... ON REMOTE: %.*s\n", (int)(zTail-g.argv[i]), g.argv[i]);
1282 z = mprintf("%s", zTail);
1283 }else{
1284 z = mprintf("%s", g.argv[i]);
1285 }
1286 fossil_print("[%s] -> ", z);
1287 file_simplify_name(z, -1, 0);
1288 fossil_print("[%s]\n", z);
1289 fossil_free(z);
1290
--- src/file.c
+++ src/file.c
@@ -260,11 +260,11 @@
260 int i, nName;
261 char *zName, zBuf[1000];
262
263 nName = strlen(zLinkFile);
264 if( nName>=(int)sizeof(zBuf) ){
265 zName = fossil_strdup(zLinkFile);
266 }else{
267 zName = zBuf;
268 memcpy(zName, zLinkFile, nName+1);
269 }
270 nName = file_simplify_name(zName, nName, 0);
@@ -425,11 +425,11 @@
425 */
426 int file_isdir(const char *zFilename, int eFType){
427 int rc;
428 char *zFN;
429
430 zFN = fossil_strdup(zFilename);
431 file_simplify_name(zFN, -1, 0);
432 rc = getStat(zFN, eFType);
433 if( rc ){
434 rc = 0; /* It does not exist at all. */
435 }else if( S_ISDIR(fx.fileStat.st_mode) ){
@@ -904,11 +904,11 @@
904 ){
905 int nName, rc = 0;
906 char *zName;
907
908 nName = strlen(zFilename);
909 zName = fossil_strdup(zFilename);
910 nName = file_simplify_name(zName, nName, 0);
911 while( nName>0 && zName[nName-1]!='/' ){ nName--; }
912 if( nName>1 ){
913 zName[nName-1] = 0;
914 if( file_isdir(zName, eFType)!=1 ){
@@ -1277,13 +1277,13 @@
1277 const char *zTail;
1278 for(i=2; i<g.argc; i++){
1279 zTail = file_skip_userhost(g.argv[i]);
1280 if( zTail ){
1281 fossil_print("... ON REMOTE: %.*s\n", (int)(zTail-g.argv[i]), g.argv[i]);
1282 z = fossil_strdup(zTail);
1283 }else{
1284 z = fossil_strdup(g.argv[i]);
1285 }
1286 fossil_print("[%s] -> ", z);
1287 file_simplify_name(z, -1, 0);
1288 fossil_print("[%s]\n", z);
1289 fossil_free(z);
1290
+6 -6
--- src/fileedit.c
+++ src/fileedit.c
@@ -825,13 +825,13 @@
825825
}
826826
db_begin_transaction();
827827
zFilename = g.argv[2];
828828
cimi.zFilename = mprintf("%/", zAsFilename ? zAsFilename : zFilename);
829829
cimi.filePerm = file_perm(zFilename, ExtFILE);
830
- cimi.zUser = mprintf("%s", zUser ? zUser : login_name());
830
+ cimi.zUser = fossil_strdup(zUser ? zUser : login_name());
831831
if(zDate){
832
- cimi.zDate = mprintf("%s", zDate);
832
+ cimi.zDate = fossil_strdup(zDate);
833833
}
834834
if(zRevision==0 || zRevision[0]==0){
835835
if(g.localOpen/*check-out*/){
836836
zRevision = db_lget("checkout-hash", 0)/*leak*/;
837837
}else{
@@ -928,11 +928,11 @@
928928
char * zFileUuid = 0;
929929
db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
930930
"WHERE filename=%Q %s AND checkinID=%d",
931931
zFilename, filename_collation(), vid);
932932
if(SQLITE_ROW==db_step(&stmt)){
933
- zFileUuid = mprintf("%s",db_column_text(&stmt, 0));
933
+ zFileUuid = fossil_strdup(db_column_text(&stmt, 0));
934934
if(pFilePerm){
935935
*pFilePerm = mfile_permstr_int(db_column_text(&stmt, 1));
936936
}
937937
}
938938
db_finalize(&stmt);
@@ -1187,11 +1187,11 @@
11871187
if(bIsMissingArg){
11881188
*bIsMissingArg = 1;
11891189
}
11901190
fail((pErr,"Missing required 'filename' parameter."));
11911191
}
1192
- p->zFilename = mprintf("%s",zFlag);
1192
+ p->zFilename = fossil_strdup(zFlag);
11931193
11941194
if(0==fileedit_is_editable(p->zFilename)){
11951195
rc = 403;
11961196
fail((pErr,"Filename [%h] is disallowed "
11971197
"by the [fileedit-glob] repository "
@@ -1248,11 +1248,11 @@
12481248
if(zFlag!=0 && *zFlag!=0){
12491249
blob_append(&p->comment, zFlag, -1);
12501250
}
12511251
zFlag = P("comment_mimetype");
12521252
if(zFlag){
1253
- p->zCommentMimetype = mprintf("%s",zFlag);
1253
+ p->zCommentMimetype = fossil_strdup(zFlag);
12541254
zFlag = 0;
12551255
}
12561256
#define p_int(K) atoi(PD(K,"0"))
12571257
if(p_int("dry_run")!=0){
12581258
p->flags |= CIMINI_DRY_RUN;
@@ -1284,11 +1284,11 @@
12841284
#undef p_int
12851285
/*
12861286
** TODO?: date-override date selection field. Maybe use
12871287
** an input[type=datetime-local].
12881288
*/
1289
- p->zUser = mprintf("%s",g.zLogin);
1289
+ p->zUser = fossil_strdup(g.zLogin);
12901290
return 0;
12911291
end_fail:
12921292
#undef fail
12931293
fossil_free(zFileUuid);
12941294
return rc ? rc : 500;
12951295
--- src/fileedit.c
+++ src/fileedit.c
@@ -825,13 +825,13 @@
825 }
826 db_begin_transaction();
827 zFilename = g.argv[2];
828 cimi.zFilename = mprintf("%/", zAsFilename ? zAsFilename : zFilename);
829 cimi.filePerm = file_perm(zFilename, ExtFILE);
830 cimi.zUser = mprintf("%s", zUser ? zUser : login_name());
831 if(zDate){
832 cimi.zDate = mprintf("%s", zDate);
833 }
834 if(zRevision==0 || zRevision[0]==0){
835 if(g.localOpen/*check-out*/){
836 zRevision = db_lget("checkout-hash", 0)/*leak*/;
837 }else{
@@ -928,11 +928,11 @@
928 char * zFileUuid = 0;
929 db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
930 "WHERE filename=%Q %s AND checkinID=%d",
931 zFilename, filename_collation(), vid);
932 if(SQLITE_ROW==db_step(&stmt)){
933 zFileUuid = mprintf("%s",db_column_text(&stmt, 0));
934 if(pFilePerm){
935 *pFilePerm = mfile_permstr_int(db_column_text(&stmt, 1));
936 }
937 }
938 db_finalize(&stmt);
@@ -1187,11 +1187,11 @@
1187 if(bIsMissingArg){
1188 *bIsMissingArg = 1;
1189 }
1190 fail((pErr,"Missing required 'filename' parameter."));
1191 }
1192 p->zFilename = mprintf("%s",zFlag);
1193
1194 if(0==fileedit_is_editable(p->zFilename)){
1195 rc = 403;
1196 fail((pErr,"Filename [%h] is disallowed "
1197 "by the [fileedit-glob] repository "
@@ -1248,11 +1248,11 @@
1248 if(zFlag!=0 && *zFlag!=0){
1249 blob_append(&p->comment, zFlag, -1);
1250 }
1251 zFlag = P("comment_mimetype");
1252 if(zFlag){
1253 p->zCommentMimetype = mprintf("%s",zFlag);
1254 zFlag = 0;
1255 }
1256 #define p_int(K) atoi(PD(K,"0"))
1257 if(p_int("dry_run")!=0){
1258 p->flags |= CIMINI_DRY_RUN;
@@ -1284,11 +1284,11 @@
1284 #undef p_int
1285 /*
1286 ** TODO?: date-override date selection field. Maybe use
1287 ** an input[type=datetime-local].
1288 */
1289 p->zUser = mprintf("%s",g.zLogin);
1290 return 0;
1291 end_fail:
1292 #undef fail
1293 fossil_free(zFileUuid);
1294 return rc ? rc : 500;
1295
--- src/fileedit.c
+++ src/fileedit.c
@@ -825,13 +825,13 @@
825 }
826 db_begin_transaction();
827 zFilename = g.argv[2];
828 cimi.zFilename = mprintf("%/", zAsFilename ? zAsFilename : zFilename);
829 cimi.filePerm = file_perm(zFilename, ExtFILE);
830 cimi.zUser = fossil_strdup(zUser ? zUser : login_name());
831 if(zDate){
832 cimi.zDate = fossil_strdup(zDate);
833 }
834 if(zRevision==0 || zRevision[0]==0){
835 if(g.localOpen/*check-out*/){
836 zRevision = db_lget("checkout-hash", 0)/*leak*/;
837 }else{
@@ -928,11 +928,11 @@
928 char * zFileUuid = 0;
929 db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
930 "WHERE filename=%Q %s AND checkinID=%d",
931 zFilename, filename_collation(), vid);
932 if(SQLITE_ROW==db_step(&stmt)){
933 zFileUuid = fossil_strdup(db_column_text(&stmt, 0));
934 if(pFilePerm){
935 *pFilePerm = mfile_permstr_int(db_column_text(&stmt, 1));
936 }
937 }
938 db_finalize(&stmt);
@@ -1187,11 +1187,11 @@
1187 if(bIsMissingArg){
1188 *bIsMissingArg = 1;
1189 }
1190 fail((pErr,"Missing required 'filename' parameter."));
1191 }
1192 p->zFilename = fossil_strdup(zFlag);
1193
1194 if(0==fileedit_is_editable(p->zFilename)){
1195 rc = 403;
1196 fail((pErr,"Filename [%h] is disallowed "
1197 "by the [fileedit-glob] repository "
@@ -1248,11 +1248,11 @@
1248 if(zFlag!=0 && *zFlag!=0){
1249 blob_append(&p->comment, zFlag, -1);
1250 }
1251 zFlag = P("comment_mimetype");
1252 if(zFlag){
1253 p->zCommentMimetype = fossil_strdup(zFlag);
1254 zFlag = 0;
1255 }
1256 #define p_int(K) atoi(PD(K,"0"))
1257 if(p_int("dry_run")!=0){
1258 p->flags |= CIMINI_DRY_RUN;
@@ -1284,11 +1284,11 @@
1284 #undef p_int
1285 /*
1286 ** TODO?: date-override date selection field. Maybe use
1287 ** an input[type=datetime-local].
1288 */
1289 p->zUser = fossil_strdup(g.zLogin);
1290 return 0;
1291 end_fail:
1292 #undef fail
1293 fossil_free(zFileUuid);
1294 return rc ? rc : 500;
1295
+4 -2
--- src/forum.c
+++ src/forum.c
@@ -933,11 +933,12 @@
933933
@ <form method="post" \
934934
@ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
935935
login_insert_csrf_secret();
936936
@ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" />
937937
if( moderation_pending(p->fpid)==0 ){
938
- @ <input type="submit" value='%s(iClosed ? "Re-open" : "Close")' />
938
+ @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
939
+ @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
939940
}
940941
@ </form>
941942
}
942943
@ </div>
943944
}
@@ -1114,11 +1115,12 @@
11141115
** Emit Forum Javascript which applies (or optionally can apply)
11151116
** to all forum-related pages. It does not include page-specific
11161117
** code (e.g. "forum.js").
11171118
*/
11181119
static void forum_emit_js(void){
1119
- builtin_fossil_js_bundle_or("copybutton", "pikchr", NULL);
1120
+ builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer",
1121
+ NULL);
11201122
builtin_request_js("fossil.page.forumpost.js");
11211123
}
11221124
11231125
/*
11241126
** WEBPAGE: forumpost
11251127
--- src/forum.c
+++ src/forum.c
@@ -933,11 +933,12 @@
933 @ <form method="post" \
934 @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
935 login_insert_csrf_secret();
936 @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" />
937 if( moderation_pending(p->fpid)==0 ){
938 @ <input type="submit" value='%s(iClosed ? "Re-open" : "Close")' />
 
939 }
940 @ </form>
941 }
942 @ </div>
943 }
@@ -1114,11 +1115,12 @@
1114 ** Emit Forum Javascript which applies (or optionally can apply)
1115 ** to all forum-related pages. It does not include page-specific
1116 ** code (e.g. "forum.js").
1117 */
1118 static void forum_emit_js(void){
1119 builtin_fossil_js_bundle_or("copybutton", "pikchr", NULL);
 
1120 builtin_request_js("fossil.page.forumpost.js");
1121 }
1122
1123 /*
1124 ** WEBPAGE: forumpost
1125
--- src/forum.c
+++ src/forum.c
@@ -933,11 +933,12 @@
933 @ <form method="post" \
934 @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'>
935 login_insert_csrf_secret();
936 @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" />
937 if( moderation_pending(p->fpid)==0 ){
938 @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \
939 @ class='%s(iClosed ? "action-reopen" : "action-close")'/>
940 }
941 @ </form>
942 }
943 @ </div>
944 }
@@ -1114,11 +1115,12 @@
1115 ** Emit Forum Javascript which applies (or optionally can apply)
1116 ** to all forum-related pages. It does not include page-specific
1117 ** code (e.g. "forum.js").
1118 */
1119 static void forum_emit_js(void){
1120 builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer",
1121 NULL);
1122 builtin_request_js("fossil.page.forumpost.js");
1123 }
1124
1125 /*
1126 ** WEBPAGE: forumpost
1127
--- src/fossil.numbered-lines.js
+++ src/fossil.numbered-lines.js
@@ -21,14 +21,11 @@
2121
const tdLn = tbl.querySelector('td.line-numbers');
2222
const urlArgsRaw = (window.location.search||'?')
2323
.replace(/&?\budc=[^&]*/,'') /* "update display prefs cookie" */
2424
.replace(/&?\bln=[^&]*/,'') /* inbound line number/range */
2525
.replace('?&','?');
26
- var urlArgsDecoded = urlArgsRaw;
27
- try{urlArgsDecoded = decodeURIComponent(urlArgsRaw);}
28
- catch{}
29
- const lineState = { urlArgs: urlArgsDecoded, start: 0, end: 0 };
26
+ const lineState = { urlArgs: urlArgsRaw, start: 0, end: 0 };
3027
const lineTip = new F.PopupWidget({
3128
style: {
3229
cursor: 'pointer'
3330
},
3431
refresh: function(){
3532
--- src/fossil.numbered-lines.js
+++ src/fossil.numbered-lines.js
@@ -21,14 +21,11 @@
21 const tdLn = tbl.querySelector('td.line-numbers');
22 const urlArgsRaw = (window.location.search||'?')
23 .replace(/&?\budc=[^&]*/,'') /* "update display prefs cookie" */
24 .replace(/&?\bln=[^&]*/,'') /* inbound line number/range */
25 .replace('?&','?');
26 var urlArgsDecoded = urlArgsRaw;
27 try{urlArgsDecoded = decodeURIComponent(urlArgsRaw);}
28 catch{}
29 const lineState = { urlArgs: urlArgsDecoded, start: 0, end: 0 };
30 const lineTip = new F.PopupWidget({
31 style: {
32 cursor: 'pointer'
33 },
34 refresh: function(){
35
--- src/fossil.numbered-lines.js
+++ src/fossil.numbered-lines.js
@@ -21,14 +21,11 @@
21 const tdLn = tbl.querySelector('td.line-numbers');
22 const urlArgsRaw = (window.location.search||'?')
23 .replace(/&?\budc=[^&]*/,'') /* "update display prefs cookie" */
24 .replace(/&?\bln=[^&]*/,'') /* inbound line number/range */
25 .replace('?&','?');
26 const lineState = { urlArgs: urlArgsRaw, start: 0, end: 0 };
 
 
 
27 const lineTip = new F.PopupWidget({
28 style: {
29 cursor: 'pointer'
30 },
31 refresh: function(){
32
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -117,8 +117,19 @@
117117
setTimeout(()=>{delete form.dataset.submitted}, 7000);
118118
return;
119119
};
120120
document.querySelectorAll("form").forEach(function(form){
121121
form.addEventListener('submit',formSubmitted);
122
+ form
123
+ .querySelectorAll("input.action-close, input.action-reopen")
124
+ .forEach(function(e){
125
+ F.confirmer(e, {
126
+ confirmText: (e.classList.contains('action-reopen')
127
+ ? "Confirm re-open"
128
+ : "Confirm close"),
129
+ onconfirm: ()=>form.submit()
130
+ });
131
+ });
122132
});
133
+
123134
})/*F.onPageLoad callback*/;
124135
})(window.fossil);
125136
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -117,8 +117,19 @@
117 setTimeout(()=>{delete form.dataset.submitted}, 7000);
118 return;
119 };
120 document.querySelectorAll("form").forEach(function(form){
121 form.addEventListener('submit',formSubmitted);
 
 
 
 
 
 
 
 
 
 
122 });
 
123 })/*F.onPageLoad callback*/;
124 })(window.fossil);
125
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -117,8 +117,19 @@
117 setTimeout(()=>{delete form.dataset.submitted}, 7000);
118 return;
119 };
120 document.querySelectorAll("form").forEach(function(form){
121 form.addEventListener('submit',formSubmitted);
122 form
123 .querySelectorAll("input.action-close, input.action-reopen")
124 .forEach(function(e){
125 F.confirmer(e, {
126 confirmText: (e.classList.contains('action-reopen')
127 ? "Confirm re-open"
128 : "Confirm close"),
129 onconfirm: ()=>form.submit()
130 });
131 });
132 });
133
134 })/*F.onPageLoad callback*/;
135 })(window.fossil);
136
+1 -1
--- src/graph.c
+++ src/graph.c
@@ -226,11 +226,11 @@
226226
for(i=0; i<p->nBranch; i++){
227227
if( fossil_strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
228228
}
229229
p->nBranch++;
230230
p->azBranch = fossil_realloc(p->azBranch, sizeof(char*)*p->nBranch);
231
- p->azBranch[p->nBranch-1] = mprintf("%s", zBranch);
231
+ p->azBranch[p->nBranch-1] = fossil_strdup(zBranch);
232232
return p->azBranch[p->nBranch-1];
233233
}
234234
235235
/*
236236
** Add a new row to the graph context. Rows are added from top to bottom.
237237
--- src/graph.c
+++ src/graph.c
@@ -226,11 +226,11 @@
226 for(i=0; i<p->nBranch; i++){
227 if( fossil_strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
228 }
229 p->nBranch++;
230 p->azBranch = fossil_realloc(p->azBranch, sizeof(char*)*p->nBranch);
231 p->azBranch[p->nBranch-1] = mprintf("%s", zBranch);
232 return p->azBranch[p->nBranch-1];
233 }
234
235 /*
236 ** Add a new row to the graph context. Rows are added from top to bottom.
237
--- src/graph.c
+++ src/graph.c
@@ -226,11 +226,11 @@
226 for(i=0; i<p->nBranch; i++){
227 if( fossil_strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
228 }
229 p->nBranch++;
230 p->azBranch = fossil_realloc(p->azBranch, sizeof(char*)*p->nBranch);
231 p->azBranch[p->nBranch-1] = fossil_strdup(zBranch);
232 return p->azBranch[p->nBranch-1];
233 }
234
235 /*
236 ** Add a new row to the graph context. Rows are added from top to bottom.
237
+52 -22
--- src/http.c
+++ src/http.c
@@ -52,29 +52,33 @@
5252
** Construct the "login" card with the client credentials.
5353
**
5454
** login LOGIN NONCE SIGNATURE
5555
**
5656
** The LOGIN is the user id of the client. NONCE is the sha1 checksum
57
-** of all payload that follows the login card. SIGNATURE is the sha1
58
-** checksum of the nonce followed by the user password.
57
+** of all payload that follows the login card. Randomness for the
58
+** NONCE must be provided in the payload (in xfer.c) (e.g. by
59
+** appending a timestamp or random bytes as a comment line to the
60
+** payload). SIGNATURE is the sha1 checksum of the nonce followed by
61
+** the fossil-hashed version of the user's password.
5962
**
60
-** Write the constructed login card into pLogin. pLogin is initialized
61
-** by this routine.
63
+** Write the constructed login card into pLogin. The result does not
64
+** have an EOL added to it because which type of EOL it needs has to
65
+** be determined later. pLogin is initialized by this routine.
6266
*/
63
-static void http_build_login_card(Blob *pPayload, Blob *pLogin){
67
+static void http_build_login_card(Blob * const pPayload, Blob * const pLogin){
6468
Blob nonce; /* The nonce */
6569
const char *zLogin; /* The user login name */
6670
const char *zPw; /* The user password */
6771
Blob pw; /* The nonce with user password appended */
6872
Blob sig; /* The signature field */
6973
7074
blob_zero(pLogin);
7175
if( g.url.user==0 || fossil_strcmp(g.url.user, "anonymous")==0 ){
72
- return; /* If no login card for users "nobody" and "anonymous" */
76
+ return; /* No login card for users "nobody" and "anonymous" */
7377
}
7478
if( g.url.isSsh ){
75
- return; /* If no login card for SSH: */
79
+ return; /* No login card for SSH: */
7680
}
7781
blob_zero(&nonce);
7882
blob_zero(&pw);
7983
sha1sum_blob(pPayload, &nonce);
8084
blob_copy(&pw, &nonce);
@@ -118,32 +122,34 @@
118122
g.url.passwd = fossil_strdup(zPw);
119123
}
120124
121125
blob_append(&pw, zPw, -1);
122126
sha1sum_blob(&pw, &sig);
123
- blob_appendf(pLogin, "login %F %b %b\n", zLogin, &nonce, &sig);
127
+ blob_appendf(pLogin, "login %F %b %b", zLogin, &nonce, &sig);
124128
blob_reset(&pw);
125129
blob_reset(&sig);
126130
blob_reset(&nonce);
127131
}
128132
129133
/*
130134
** Construct an appropriate HTTP request header. Write the header
131135
** into pHdr. This routine initializes the pHdr blob. pPayload is
132
-** the complete payload (including the login card) already compressed.
136
+** the complete payload (including the login card if pLogin is NULL or
137
+** empty) already compressed.
133138
*/
134139
static void http_build_header(
135140
Blob *pPayload, /* the payload that will be sent */
136141
Blob *pHdr, /* construct the header here */
142
+ Blob *pLogin, /* Login card header value or NULL */
137143
const char *zAltMimetype /* Alternative mimetype */
138144
){
139145
int nPayload = pPayload ? blob_size(pPayload) : 0;
140146
141147
blob_zero(pHdr);
142
- blob_appendf(pHdr, "%s %s%s HTTP/1.0\r\n",
143
- nPayload>0 ? "POST" : "GET", g.url.path,
144
- g.url.path[0]==0 ? "/" : "");
148
+ blob_appendf(pHdr, "%s %s HTTP/1.0\r\n",
149
+ nPayload>0 ? "POST" : "GET",
150
+ (g.url.path && g.url.path[0]) ? g.url.path : "/");
145151
if( g.url.proxyAuth ){
146152
blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.url.proxyAuth);
147153
}
148154
if( g.zHttpAuth && g.zHttpAuth[0] ){
149155
const char *zCredentials = g.zHttpAuth;
@@ -152,10 +158,16 @@
152158
fossil_free(zEncoded);
153159
}
154160
blob_appendf(pHdr, "Host: %s\r\n", g.url.hostname);
155161
blob_appendf(pHdr, "User-Agent: %s\r\n", get_user_agent());
156162
if( g.url.isSsh ) blob_appendf(pHdr, "X-Fossil-Transport: SSH\r\n");
163
+ if( g.syncInfo.fLoginCardMode>0
164
+ && nPayload>0 && pLogin && blob_size(pLogin) ){
165
+ /* Add sync login card via a transient cookie. We can only do this
166
+ if we know the remote supports it. */
167
+ blob_appendf(pHdr, "Cookie: x-f-l-c=%T\r\n", blob_str(pLogin));
168
+ }
157169
if( nPayload ){
158170
if( zAltMimetype ){
159171
blob_appendf(pHdr, "Content-Type: %s\r\n", zAltMimetype);
160172
}else if( g.fHttpTrace ){
161173
blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
@@ -385,11 +397,11 @@
385397
** * The test-ssh-needs-path command that shows the settings
386398
** that cache whether or not a PATH= is needed for a particular
387399
** HOSTNAME.
388400
*/
389401
void ssh_add_path_argument(Blob *pCmd){
390
- blob_append_escaped_arg(pCmd,
402
+ blob_append_escaped_arg(pCmd,
391403
"PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
392404
}
393405
394406
/*
395407
** Return the complete text of the last HTTP reply as saved in the
@@ -456,28 +468,46 @@
456468
457469
if( transport_open(&g.url) ){
458470
fossil_warning("%s", transport_errmsg(&g.url));
459471
return 1;
460472
}
461
-
462473
/* Construct the login card and prepare the complete payload */
474
+ blob_zero(&login);
463475
if( blob_size(pSend)==0 ){
464476
blob_zero(&payload);
465477
}else{
466
- blob_zero(&login);
467478
if( mHttpFlags & HTTP_USE_LOGIN ) http_build_login_card(pSend, &login);
468
- if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
469
- payload = login;
470
- blob_append(&payload, blob_buffer(pSend), blob_size(pSend));
479
+ if( g.syncInfo.fLoginCardMode ){
480
+ /* The login card will be sent via an HTTP header and/or URL flag. */
481
+ if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
482
+ /* Maintenance note: we cannot blob_swap(pSend,&payload) here
483
+ ** because the HTTP 401 and redirect response handling below
484
+ ** needs pSend unmodified. payload won't be modified after
485
+ ** this point, so we can make it a proxy for pSend for
486
+ ** zero heap memory. */
487
+ blob_init(&payload, blob_buffer(pSend), blob_size(pSend));
488
+ }else{
489
+ blob_compress(pSend, &payload);
490
+ }
471491
}else{
472
- blob_compress2(&login, pSend, &payload);
473
- blob_reset(&login);
492
+ /* Prepend the login card (if set) to the payload */
493
+ if( blob_size(&login) ){
494
+ blob_append_char(&login, '\n');
495
+ }
496
+ if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
497
+ payload = login;
498
+ login = empty_blob/*transfer ownership*/;
499
+ blob_append(&payload, blob_buffer(pSend), blob_size(pSend));
500
+ }else{
501
+ blob_compress2(&login, pSend, &payload);
502
+ blob_reset(&login);
503
+ }
474504
}
475505
}
476506
477507
/* Construct the HTTP request header */
478
- http_build_header(&payload, &hdr, zAltMimetype);
508
+ http_build_header(&payload, &hdr, &login, zAltMimetype);
479509
480510
/* When tracing, write the transmitted HTTP message both to standard
481511
** output and into a file. The file can then be used to drive the
482512
** server-side like this:
483513
**
@@ -764,11 +794,11 @@
764794
** COMMAND: test-httpmsg
765795
**
766796
** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT?
767797
**
768798
** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing
769
-** the payload, or "-" to read payload from standard input. a POST message
799
+** the payload, or "-" to read payload from standard input. A POST message
770800
** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted
771801
** or is an empty file, then a GET message is sent.
772802
**
773803
** If a second filename (OUTPUT) is given after PAYLOAD, then the reply
774804
** is written into that second file instead of being written on standard
775805
--- src/http.c
+++ src/http.c
@@ -52,29 +52,33 @@
52 ** Construct the "login" card with the client credentials.
53 **
54 ** login LOGIN NONCE SIGNATURE
55 **
56 ** The LOGIN is the user id of the client. NONCE is the sha1 checksum
57 ** of all payload that follows the login card. SIGNATURE is the sha1
58 ** checksum of the nonce followed by the user password.
 
 
 
59 **
60 ** Write the constructed login card into pLogin. pLogin is initialized
61 ** by this routine.
 
62 */
63 static void http_build_login_card(Blob *pPayload, Blob *pLogin){
64 Blob nonce; /* The nonce */
65 const char *zLogin; /* The user login name */
66 const char *zPw; /* The user password */
67 Blob pw; /* The nonce with user password appended */
68 Blob sig; /* The signature field */
69
70 blob_zero(pLogin);
71 if( g.url.user==0 || fossil_strcmp(g.url.user, "anonymous")==0 ){
72 return; /* If no login card for users "nobody" and "anonymous" */
73 }
74 if( g.url.isSsh ){
75 return; /* If no login card for SSH: */
76 }
77 blob_zero(&nonce);
78 blob_zero(&pw);
79 sha1sum_blob(pPayload, &nonce);
80 blob_copy(&pw, &nonce);
@@ -118,32 +122,34 @@
118 g.url.passwd = fossil_strdup(zPw);
119 }
120
121 blob_append(&pw, zPw, -1);
122 sha1sum_blob(&pw, &sig);
123 blob_appendf(pLogin, "login %F %b %b\n", zLogin, &nonce, &sig);
124 blob_reset(&pw);
125 blob_reset(&sig);
126 blob_reset(&nonce);
127 }
128
129 /*
130 ** Construct an appropriate HTTP request header. Write the header
131 ** into pHdr. This routine initializes the pHdr blob. pPayload is
132 ** the complete payload (including the login card) already compressed.
 
133 */
134 static void http_build_header(
135 Blob *pPayload, /* the payload that will be sent */
136 Blob *pHdr, /* construct the header here */
 
137 const char *zAltMimetype /* Alternative mimetype */
138 ){
139 int nPayload = pPayload ? blob_size(pPayload) : 0;
140
141 blob_zero(pHdr);
142 blob_appendf(pHdr, "%s %s%s HTTP/1.0\r\n",
143 nPayload>0 ? "POST" : "GET", g.url.path,
144 g.url.path[0]==0 ? "/" : "");
145 if( g.url.proxyAuth ){
146 blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.url.proxyAuth);
147 }
148 if( g.zHttpAuth && g.zHttpAuth[0] ){
149 const char *zCredentials = g.zHttpAuth;
@@ -152,10 +158,16 @@
152 fossil_free(zEncoded);
153 }
154 blob_appendf(pHdr, "Host: %s\r\n", g.url.hostname);
155 blob_appendf(pHdr, "User-Agent: %s\r\n", get_user_agent());
156 if( g.url.isSsh ) blob_appendf(pHdr, "X-Fossil-Transport: SSH\r\n");
 
 
 
 
 
 
157 if( nPayload ){
158 if( zAltMimetype ){
159 blob_appendf(pHdr, "Content-Type: %s\r\n", zAltMimetype);
160 }else if( g.fHttpTrace ){
161 blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
@@ -385,11 +397,11 @@
385 ** * The test-ssh-needs-path command that shows the settings
386 ** that cache whether or not a PATH= is needed for a particular
387 ** HOSTNAME.
388 */
389 void ssh_add_path_argument(Blob *pCmd){
390 blob_append_escaped_arg(pCmd,
391 "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
392 }
393
394 /*
395 ** Return the complete text of the last HTTP reply as saved in the
@@ -456,28 +468,46 @@
456
457 if( transport_open(&g.url) ){
458 fossil_warning("%s", transport_errmsg(&g.url));
459 return 1;
460 }
461
462 /* Construct the login card and prepare the complete payload */
 
463 if( blob_size(pSend)==0 ){
464 blob_zero(&payload);
465 }else{
466 blob_zero(&login);
467 if( mHttpFlags & HTTP_USE_LOGIN ) http_build_login_card(pSend, &login);
468 if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
469 payload = login;
470 blob_append(&payload, blob_buffer(pSend), blob_size(pSend));
 
 
 
 
 
 
 
 
 
471 }else{
472 blob_compress2(&login, pSend, &payload);
473 blob_reset(&login);
 
 
 
 
 
 
 
 
 
 
474 }
475 }
476
477 /* Construct the HTTP request header */
478 http_build_header(&payload, &hdr, zAltMimetype);
479
480 /* When tracing, write the transmitted HTTP message both to standard
481 ** output and into a file. The file can then be used to drive the
482 ** server-side like this:
483 **
@@ -764,11 +794,11 @@
764 ** COMMAND: test-httpmsg
765 **
766 ** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT?
767 **
768 ** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing
769 ** the payload, or "-" to read payload from standard input. a POST message
770 ** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted
771 ** or is an empty file, then a GET message is sent.
772 **
773 ** If a second filename (OUTPUT) is given after PAYLOAD, then the reply
774 ** is written into that second file instead of being written on standard
775
--- src/http.c
+++ src/http.c
@@ -52,29 +52,33 @@
52 ** Construct the "login" card with the client credentials.
53 **
54 ** login LOGIN NONCE SIGNATURE
55 **
56 ** The LOGIN is the user id of the client. NONCE is the sha1 checksum
57 ** of all payload that follows the login card. Randomness for the
58 ** NONCE must be provided in the payload (in xfer.c) (e.g. by
59 ** appending a timestamp or random bytes as a comment line to the
60 ** payload). SIGNATURE is the sha1 checksum of the nonce followed by
61 ** the fossil-hashed version of the user's password.
62 **
63 ** Write the constructed login card into pLogin. The result does not
64 ** have an EOL added to it because which type of EOL it needs has to
65 ** be determined later. pLogin is initialized by this routine.
66 */
67 static void http_build_login_card(Blob * const pPayload, Blob * const pLogin){
68 Blob nonce; /* The nonce */
69 const char *zLogin; /* The user login name */
70 const char *zPw; /* The user password */
71 Blob pw; /* The nonce with user password appended */
72 Blob sig; /* The signature field */
73
74 blob_zero(pLogin);
75 if( g.url.user==0 || fossil_strcmp(g.url.user, "anonymous")==0 ){
76 return; /* No login card for users "nobody" and "anonymous" */
77 }
78 if( g.url.isSsh ){
79 return; /* No login card for SSH: */
80 }
81 blob_zero(&nonce);
82 blob_zero(&pw);
83 sha1sum_blob(pPayload, &nonce);
84 blob_copy(&pw, &nonce);
@@ -118,32 +122,34 @@
122 g.url.passwd = fossil_strdup(zPw);
123 }
124
125 blob_append(&pw, zPw, -1);
126 sha1sum_blob(&pw, &sig);
127 blob_appendf(pLogin, "login %F %b %b", zLogin, &nonce, &sig);
128 blob_reset(&pw);
129 blob_reset(&sig);
130 blob_reset(&nonce);
131 }
132
133 /*
134 ** Construct an appropriate HTTP request header. Write the header
135 ** into pHdr. This routine initializes the pHdr blob. pPayload is
136 ** the complete payload (including the login card if pLogin is NULL or
137 ** empty) already compressed.
138 */
139 static void http_build_header(
140 Blob *pPayload, /* the payload that will be sent */
141 Blob *pHdr, /* construct the header here */
142 Blob *pLogin, /* Login card header value or NULL */
143 const char *zAltMimetype /* Alternative mimetype */
144 ){
145 int nPayload = pPayload ? blob_size(pPayload) : 0;
146
147 blob_zero(pHdr);
148 blob_appendf(pHdr, "%s %s HTTP/1.0\r\n",
149 nPayload>0 ? "POST" : "GET",
150 (g.url.path && g.url.path[0]) ? g.url.path : "/");
151 if( g.url.proxyAuth ){
152 blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.url.proxyAuth);
153 }
154 if( g.zHttpAuth && g.zHttpAuth[0] ){
155 const char *zCredentials = g.zHttpAuth;
@@ -152,10 +158,16 @@
158 fossil_free(zEncoded);
159 }
160 blob_appendf(pHdr, "Host: %s\r\n", g.url.hostname);
161 blob_appendf(pHdr, "User-Agent: %s\r\n", get_user_agent());
162 if( g.url.isSsh ) blob_appendf(pHdr, "X-Fossil-Transport: SSH\r\n");
163 if( g.syncInfo.fLoginCardMode>0
164 && nPayload>0 && pLogin && blob_size(pLogin) ){
165 /* Add sync login card via a transient cookie. We can only do this
166 if we know the remote supports it. */
167 blob_appendf(pHdr, "Cookie: x-f-l-c=%T\r\n", blob_str(pLogin));
168 }
169 if( nPayload ){
170 if( zAltMimetype ){
171 blob_appendf(pHdr, "Content-Type: %s\r\n", zAltMimetype);
172 }else if( g.fHttpTrace ){
173 blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
@@ -385,11 +397,11 @@
397 ** * The test-ssh-needs-path command that shows the settings
398 ** that cache whether or not a PATH= is needed for a particular
399 ** HOSTNAME.
400 */
401 void ssh_add_path_argument(Blob *pCmd){
402 blob_append_escaped_arg(pCmd,
403 "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
404 }
405
406 /*
407 ** Return the complete text of the last HTTP reply as saved in the
@@ -456,28 +468,46 @@
468
469 if( transport_open(&g.url) ){
470 fossil_warning("%s", transport_errmsg(&g.url));
471 return 1;
472 }
 
473 /* Construct the login card and prepare the complete payload */
474 blob_zero(&login);
475 if( blob_size(pSend)==0 ){
476 blob_zero(&payload);
477 }else{
 
478 if( mHttpFlags & HTTP_USE_LOGIN ) http_build_login_card(pSend, &login);
479 if( g.syncInfo.fLoginCardMode ){
480 /* The login card will be sent via an HTTP header and/or URL flag. */
481 if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
482 /* Maintenance note: we cannot blob_swap(pSend,&payload) here
483 ** because the HTTP 401 and redirect response handling below
484 ** needs pSend unmodified. payload won't be modified after
485 ** this point, so we can make it a proxy for pSend for
486 ** zero heap memory. */
487 blob_init(&payload, blob_buffer(pSend), blob_size(pSend));
488 }else{
489 blob_compress(pSend, &payload);
490 }
491 }else{
492 /* Prepend the login card (if set) to the payload */
493 if( blob_size(&login) ){
494 blob_append_char(&login, '\n');
495 }
496 if( g.fHttpTrace || (mHttpFlags & HTTP_NOCOMPRESS)!=0 ){
497 payload = login;
498 login = empty_blob/*transfer ownership*/;
499 blob_append(&payload, blob_buffer(pSend), blob_size(pSend));
500 }else{
501 blob_compress2(&login, pSend, &payload);
502 blob_reset(&login);
503 }
504 }
505 }
506
507 /* Construct the HTTP request header */
508 http_build_header(&payload, &hdr, &login, zAltMimetype);
509
510 /* When tracing, write the transmitted HTTP message both to standard
511 ** output and into a file. The file can then be used to drive the
512 ** server-side like this:
513 **
@@ -764,11 +794,11 @@
794 ** COMMAND: test-httpmsg
795 **
796 ** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT?
797 **
798 ** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing
799 ** the payload, or "-" to read payload from standard input. A POST message
800 ** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted
801 ** or is an empty file, then a GET message is sent.
802 **
803 ** If a second filename (OUTPUT) is given after PAYLOAD, then the reply
804 ** is written into that second file instead of being written on standard
805
--- src/http_socket.c
+++ src/http_socket.c
@@ -175,11 +175,11 @@
175175
0, 0, NI_NUMERICHOST);
176176
if( rc ){
177177
socket_set_errmsg("getnameinfo() failed: %s", gai_strerror(rc));
178178
goto end_socket_open;
179179
}
180
- g.zIpAddr = mprintf("%s", zRemote);
180
+ g.zIpAddr = fossil_strdup(zRemote);
181181
break;
182182
}
183183
if( p==0 ){
184184
socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
185185
pUrlData->port);
186186
--- src/http_socket.c
+++ src/http_socket.c
@@ -175,11 +175,11 @@
175 0, 0, NI_NUMERICHOST);
176 if( rc ){
177 socket_set_errmsg("getnameinfo() failed: %s", gai_strerror(rc));
178 goto end_socket_open;
179 }
180 g.zIpAddr = mprintf("%s", zRemote);
181 break;
182 }
183 if( p==0 ){
184 socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
185 pUrlData->port);
186
--- src/http_socket.c
+++ src/http_socket.c
@@ -175,11 +175,11 @@
175 0, 0, NI_NUMERICHOST);
176 if( rc ){
177 socket_set_errmsg("getnameinfo() failed: %s", gai_strerror(rc));
178 goto end_socket_open;
179 }
180 g.zIpAddr = fossil_strdup(zRemote);
181 break;
182 }
183 if( p==0 ){
184 socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
185 pUrlData->port);
186
+1 -1
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -638,11 +638,11 @@
638638
** check here for the correct LIBRESSL_VERSION_NUMBER too. For now: disable
639639
*/
640640
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L \
641641
&& !defined(LIBRESSL_VERSION_NUMBER)
642642
char *ip = BIO_ADDR_hostname_string(BIO_get_conn_address(iBio),1);
643
- g.zIpAddr = mprintf("%s", ip);
643
+ g.zIpAddr = fossil_strdup(ip);
644644
OPENSSL_free(ip);
645645
#else
646646
/* IPv4 only code */
647647
const unsigned char *ip;
648648
ip = (const unsigned char*)BIO_ptr_ctrl(iBio,BIO_C_GET_CONNECT,2);
649649
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -638,11 +638,11 @@
638 ** check here for the correct LIBRESSL_VERSION_NUMBER too. For now: disable
639 */
640 #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L \
641 && !defined(LIBRESSL_VERSION_NUMBER)
642 char *ip = BIO_ADDR_hostname_string(BIO_get_conn_address(iBio),1);
643 g.zIpAddr = mprintf("%s", ip);
644 OPENSSL_free(ip);
645 #else
646 /* IPv4 only code */
647 const unsigned char *ip;
648 ip = (const unsigned char*)BIO_ptr_ctrl(iBio,BIO_C_GET_CONNECT,2);
649
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -638,11 +638,11 @@
638 ** check here for the correct LIBRESSL_VERSION_NUMBER too. For now: disable
639 */
640 #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L \
641 && !defined(LIBRESSL_VERSION_NUMBER)
642 char *ip = BIO_ADDR_hostname_string(BIO_get_conn_address(iBio),1);
643 g.zIpAddr = fossil_strdup(ip);
644 OPENSSL_free(ip);
645 #else
646 /* IPv4 only code */
647 const unsigned char *ip;
648 ip = (const unsigned char*)BIO_ptr_ctrl(iBio,BIO_C_GET_CONNECT,2);
649
--- src/http_transport.c
+++ src/http_transport.c
@@ -121,11 +121,11 @@
121121
*/
122122
Blob zCmd; /* The SSH command */
123123
char *zHost; /* The host name to contact */
124124
125125
fossil_free(g.zIpAddr);
126
- g.zIpAddr = mprintf("%s", pUrlData->name);
126
+ g.zIpAddr = fossil_strdup(pUrlData->name);
127127
transport_ssh_command(&zCmd);
128128
if( pUrlData->port!=pUrlData->dfltPort && pUrlData->port ){
129129
blob_appendf(&zCmd, " -p %d", pUrlData->port);
130130
}
131131
blob_appendf(&zCmd, " -T --"); /* End of switches */
@@ -141,11 +141,11 @@
141141
){
142142
fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
143143
"the server.", pUrlData->fossil);
144144
}
145145
if( (pUrlData->flags & URL_SSH_EXE)==0
146
- && (pUrlData->flags & URL_SSH_PATH)!=0
146
+ && (pUrlData->flags & URL_SSH_PATH)!=0
147147
){
148148
ssh_add_path_argument(&zCmd);
149149
}
150150
blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
151151
blob_append(&zCmd, " test-http", 10);
@@ -245,11 +245,11 @@
245245
}
246246
247247
/*
248248
** Send content over the wire.
249249
*/
250
-void transport_send(UrlData *pUrlData, Blob *toSend){
250
+void transport_send(UrlData const *pUrlData, const Blob *toSend){
251251
char *z = blob_buffer(toSend);
252252
int n = blob_size(toSend);
253253
transport.nSent += n;
254254
if( pUrlData->isSsh ){
255255
fwrite(z, 1, n, sshOut);
256256
--- src/http_transport.c
+++ src/http_transport.c
@@ -121,11 +121,11 @@
121 */
122 Blob zCmd; /* The SSH command */
123 char *zHost; /* The host name to contact */
124
125 fossil_free(g.zIpAddr);
126 g.zIpAddr = mprintf("%s", pUrlData->name);
127 transport_ssh_command(&zCmd);
128 if( pUrlData->port!=pUrlData->dfltPort && pUrlData->port ){
129 blob_appendf(&zCmd, " -p %d", pUrlData->port);
130 }
131 blob_appendf(&zCmd, " -T --"); /* End of switches */
@@ -141,11 +141,11 @@
141 ){
142 fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
143 "the server.", pUrlData->fossil);
144 }
145 if( (pUrlData->flags & URL_SSH_EXE)==0
146 && (pUrlData->flags & URL_SSH_PATH)!=0
147 ){
148 ssh_add_path_argument(&zCmd);
149 }
150 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
151 blob_append(&zCmd, " test-http", 10);
@@ -245,11 +245,11 @@
245 }
246
247 /*
248 ** Send content over the wire.
249 */
250 void transport_send(UrlData *pUrlData, Blob *toSend){
251 char *z = blob_buffer(toSend);
252 int n = blob_size(toSend);
253 transport.nSent += n;
254 if( pUrlData->isSsh ){
255 fwrite(z, 1, n, sshOut);
256
--- src/http_transport.c
+++ src/http_transport.c
@@ -121,11 +121,11 @@
121 */
122 Blob zCmd; /* The SSH command */
123 char *zHost; /* The host name to contact */
124
125 fossil_free(g.zIpAddr);
126 g.zIpAddr = fossil_strdup(pUrlData->name);
127 transport_ssh_command(&zCmd);
128 if( pUrlData->port!=pUrlData->dfltPort && pUrlData->port ){
129 blob_appendf(&zCmd, " -p %d", pUrlData->port);
130 }
131 blob_appendf(&zCmd, " -T --"); /* End of switches */
@@ -141,11 +141,11 @@
141 ){
142 fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
143 "the server.", pUrlData->fossil);
144 }
145 if( (pUrlData->flags & URL_SSH_EXE)==0
146 && (pUrlData->flags & URL_SSH_PATH)!=0
147 ){
148 ssh_add_path_argument(&zCmd);
149 }
150 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
151 blob_append(&zCmd, " test-http", 10);
@@ -245,11 +245,11 @@
245 }
246
247 /*
248 ** Send content over the wire.
249 */
250 void transport_send(UrlData const *pUrlData, const Blob *toSend){
251 char *z = blob_buffer(toSend);
252 int n = blob_size(toSend);
253 transport.nSent += n;
254 if( pUrlData->isSsh ){
255 fwrite(z, 1, n, sshOut);
256
+3 -3
--- src/import.c
+++ src/import.c
@@ -895,11 +895,11 @@
895895
char *sep;
896896
if( zLine[0]=='\n' ) break;
897897
rec->nHeaders += 1;
898898
rec->aHeaders = fossil_realloc(rec->aHeaders,
899899
sizeof(rec->aHeaders[0])*rec->nHeaders);
900
- rec->aHeaders[rec->nHeaders-1].zKey = mprintf("%s", zLine);
900
+ rec->aHeaders[rec->nHeaders-1].zKey = fossil_strdup(zLine);
901901
sep = strchr(rec->aHeaders[rec->nHeaders-1].zKey, ':');
902902
if( !sep ){
903903
trim_newline(zLine);
904904
fossil_fatal("bad header line: [%s]", zLine);
905905
}
@@ -1426,12 +1426,12 @@
14261426
fossil_free(gsvn.zDate);
14271427
bag_clear(&gsvn.newBranches);
14281428
}
14291429
/* start new revision */
14301430
gsvn.rev = atoi(zTemp);
1431
- gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author"));
1432
- gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log"));
1431
+ gsvn.zUser = fossil_strdup(svn_find_prop(rec, "svn:author"));
1432
+ gsvn.zComment = fossil_strdup(svn_find_prop(rec, "svn:log"));
14331433
zDate = svn_find_prop(rec, "svn:date");
14341434
if( zDate ){
14351435
gsvn.zDate = date_in_standard_format(zDate);
14361436
}else{
14371437
gsvn.zDate = date_in_standard_format("now");
14381438
--- src/import.c
+++ src/import.c
@@ -895,11 +895,11 @@
895 char *sep;
896 if( zLine[0]=='\n' ) break;
897 rec->nHeaders += 1;
898 rec->aHeaders = fossil_realloc(rec->aHeaders,
899 sizeof(rec->aHeaders[0])*rec->nHeaders);
900 rec->aHeaders[rec->nHeaders-1].zKey = mprintf("%s", zLine);
901 sep = strchr(rec->aHeaders[rec->nHeaders-1].zKey, ':');
902 if( !sep ){
903 trim_newline(zLine);
904 fossil_fatal("bad header line: [%s]", zLine);
905 }
@@ -1426,12 +1426,12 @@
1426 fossil_free(gsvn.zDate);
1427 bag_clear(&gsvn.newBranches);
1428 }
1429 /* start new revision */
1430 gsvn.rev = atoi(zTemp);
1431 gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author"));
1432 gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log"));
1433 zDate = svn_find_prop(rec, "svn:date");
1434 if( zDate ){
1435 gsvn.zDate = date_in_standard_format(zDate);
1436 }else{
1437 gsvn.zDate = date_in_standard_format("now");
1438
--- src/import.c
+++ src/import.c
@@ -895,11 +895,11 @@
895 char *sep;
896 if( zLine[0]=='\n' ) break;
897 rec->nHeaders += 1;
898 rec->aHeaders = fossil_realloc(rec->aHeaders,
899 sizeof(rec->aHeaders[0])*rec->nHeaders);
900 rec->aHeaders[rec->nHeaders-1].zKey = fossil_strdup(zLine);
901 sep = strchr(rec->aHeaders[rec->nHeaders-1].zKey, ':');
902 if( !sep ){
903 trim_newline(zLine);
904 fossil_fatal("bad header line: [%s]", zLine);
905 }
@@ -1426,12 +1426,12 @@
1426 fossil_free(gsvn.zDate);
1427 bag_clear(&gsvn.newBranches);
1428 }
1429 /* start new revision */
1430 gsvn.rev = atoi(zTemp);
1431 gsvn.zUser = fossil_strdup(svn_find_prop(rec, "svn:author"));
1432 gsvn.zComment = fossil_strdup(svn_find_prop(rec, "svn:log"));
1433 zDate = svn_find_prop(rec, "svn:date");
1434 if( zDate ){
1435 gsvn.zDate = date_in_standard_format(zDate);
1436 }else{
1437 gsvn.zDate = date_in_standard_format("now");
1438
+5 -3
--- src/info.c
+++ src/info.c
@@ -2886,11 +2886,11 @@
28862886
style_set_current_page("doc/%t/%T", zCI, zName);
28872887
}else if( zCIUuid && zCIUuid[0] ){
28882888
zHeader = mprintf("%s at [%S]", file_tail(zName), zCIUuid);
28892889
style_set_current_page("doc/%S/%T", zCIUuid, zName);
28902890
}else{
2891
- zHeader = mprintf("%s", file_tail(zName));
2891
+ zHeader = fossil_strdup(file_tail(zName));
28922892
style_set_current_page("doc/tip/%T", zName);
28932893
}
28942894
}else if( descOnly ){
28952895
zHeader = mprintf("Artifact Description [%S]", zUuid);
28962896
}else{
@@ -3932,10 +3932,11 @@
39323932
** --cancel TAG Cancel TAG from this check-in
39333933
** --close Mark this "leaf" as closed
39343934
** --date DATETIME Make DATETIME the check-in time
39353935
** --date-override DATETIME Set the change time on the control artifact
39363936
** -e|--edit-comment Launch editor to revise comment
3937
+** --editor NAME Text editor to use for check-in comment
39373938
** --hide Hide branch starting from this check-in
39383939
** -m|--comment COMMENT Make COMMENT the check-in comment
39393940
** -M|--message-file FILE Read the amended comment from FILE
39403941
** -n|--dry-run Print control artifact, but make no changes
39413942
** --no-verify-comment Do not validate the check-in comment
@@ -4005,10 +4006,11 @@
40054006
if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
40064007
zUserOvrd = find_option("user-override",0,1);
40074008
noVerifyCom = find_option("no-verify-comment",0,0)!=0;
40084009
db_find_and_open_repository(0,0);
40094010
user_select();
4011
+ (void)fossil_text_editor();
40104012
verify_all_options();
40114013
if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
40124014
rid = name_to_typed_rid(g.argv[2], "ci");
40134015
if( rid==0 && !is_a_version(rid) ) fossil_fatal("no such check-in");
40144016
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -4238,11 +4240,11 @@
42384240
descr->isDirty = -1;
42394241
return (rid-1);
42404242
}
42414243
42424244
zUuid = rid_to_uuid(rid);
4243
- descr->zCommitHash = mprintf("%s", zUuid);
4245
+ descr->zCommitHash = fossil_strdup(zUuid);
42444246
descr->isDirty = unsaved_changes(0);
42454247
42464248
db_multi_exec(
42474249
"DROP TABLE IF EXISTS temp.singletonTag;"
42484250
"CREATE TEMP TABLE singletonTag("
@@ -4287,11 +4289,11 @@
42874289
rid, rid
42884290
);
42894291
42904292
if( db_step(&q)==SQLITE_ROW ){
42914293
const char *lastTag = db_column_text(&q, 0);
4292
- descr->zRelTagname = mprintf("%s", lastTag);
4294
+ descr->zRelTagname = fossil_strdup(lastTag);
42934295
descr->nCommitsSince = db_column_int(&q, 1);
42944296
nRet = 0;
42954297
}else{
42964298
/* no ancestor commit with a fitting singleton tag found */
42974299
descr->zRelTagname = mprintf("");
42984300
--- src/info.c
+++ src/info.c
@@ -2886,11 +2886,11 @@
2886 style_set_current_page("doc/%t/%T", zCI, zName);
2887 }else if( zCIUuid && zCIUuid[0] ){
2888 zHeader = mprintf("%s at [%S]", file_tail(zName), zCIUuid);
2889 style_set_current_page("doc/%S/%T", zCIUuid, zName);
2890 }else{
2891 zHeader = mprintf("%s", file_tail(zName));
2892 style_set_current_page("doc/tip/%T", zName);
2893 }
2894 }else if( descOnly ){
2895 zHeader = mprintf("Artifact Description [%S]", zUuid);
2896 }else{
@@ -3932,10 +3932,11 @@
3932 ** --cancel TAG Cancel TAG from this check-in
3933 ** --close Mark this "leaf" as closed
3934 ** --date DATETIME Make DATETIME the check-in time
3935 ** --date-override DATETIME Set the change time on the control artifact
3936 ** -e|--edit-comment Launch editor to revise comment
 
3937 ** --hide Hide branch starting from this check-in
3938 ** -m|--comment COMMENT Make COMMENT the check-in comment
3939 ** -M|--message-file FILE Read the amended comment from FILE
3940 ** -n|--dry-run Print control artifact, but make no changes
3941 ** --no-verify-comment Do not validate the check-in comment
@@ -4005,10 +4006,11 @@
4005 if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
4006 zUserOvrd = find_option("user-override",0,1);
4007 noVerifyCom = find_option("no-verify-comment",0,0)!=0;
4008 db_find_and_open_repository(0,0);
4009 user_select();
 
4010 verify_all_options();
4011 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
4012 rid = name_to_typed_rid(g.argv[2], "ci");
4013 if( rid==0 && !is_a_version(rid) ) fossil_fatal("no such check-in");
4014 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -4238,11 +4240,11 @@
4238 descr->isDirty = -1;
4239 return (rid-1);
4240 }
4241
4242 zUuid = rid_to_uuid(rid);
4243 descr->zCommitHash = mprintf("%s", zUuid);
4244 descr->isDirty = unsaved_changes(0);
4245
4246 db_multi_exec(
4247 "DROP TABLE IF EXISTS temp.singletonTag;"
4248 "CREATE TEMP TABLE singletonTag("
@@ -4287,11 +4289,11 @@
4287 rid, rid
4288 );
4289
4290 if( db_step(&q)==SQLITE_ROW ){
4291 const char *lastTag = db_column_text(&q, 0);
4292 descr->zRelTagname = mprintf("%s", lastTag);
4293 descr->nCommitsSince = db_column_int(&q, 1);
4294 nRet = 0;
4295 }else{
4296 /* no ancestor commit with a fitting singleton tag found */
4297 descr->zRelTagname = mprintf("");
4298
--- src/info.c
+++ src/info.c
@@ -2886,11 +2886,11 @@
2886 style_set_current_page("doc/%t/%T", zCI, zName);
2887 }else if( zCIUuid && zCIUuid[0] ){
2888 zHeader = mprintf("%s at [%S]", file_tail(zName), zCIUuid);
2889 style_set_current_page("doc/%S/%T", zCIUuid, zName);
2890 }else{
2891 zHeader = fossil_strdup(file_tail(zName));
2892 style_set_current_page("doc/tip/%T", zName);
2893 }
2894 }else if( descOnly ){
2895 zHeader = mprintf("Artifact Description [%S]", zUuid);
2896 }else{
@@ -3932,10 +3932,11 @@
3932 ** --cancel TAG Cancel TAG from this check-in
3933 ** --close Mark this "leaf" as closed
3934 ** --date DATETIME Make DATETIME the check-in time
3935 ** --date-override DATETIME Set the change time on the control artifact
3936 ** -e|--edit-comment Launch editor to revise comment
3937 ** --editor NAME Text editor to use for check-in comment
3938 ** --hide Hide branch starting from this check-in
3939 ** -m|--comment COMMENT Make COMMENT the check-in comment
3940 ** -M|--message-file FILE Read the amended comment from FILE
3941 ** -n|--dry-run Print control artifact, but make no changes
3942 ** --no-verify-comment Do not validate the check-in comment
@@ -4005,10 +4006,11 @@
4006 if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
4007 zUserOvrd = find_option("user-override",0,1);
4008 noVerifyCom = find_option("no-verify-comment",0,0)!=0;
4009 db_find_and_open_repository(0,0);
4010 user_select();
4011 (void)fossil_text_editor();
4012 verify_all_options();
4013 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
4014 rid = name_to_typed_rid(g.argv[2], "ci");
4015 if( rid==0 && !is_a_version(rid) ) fossil_fatal("no such check-in");
4016 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -4238,11 +4240,11 @@
4240 descr->isDirty = -1;
4241 return (rid-1);
4242 }
4243
4244 zUuid = rid_to_uuid(rid);
4245 descr->zCommitHash = fossil_strdup(zUuid);
4246 descr->isDirty = unsaved_changes(0);
4247
4248 db_multi_exec(
4249 "DROP TABLE IF EXISTS temp.singletonTag;"
4250 "CREATE TEMP TABLE singletonTag("
@@ -4287,11 +4289,11 @@
4289 rid, rid
4290 );
4291
4292 if( db_step(&q)==SQLITE_ROW ){
4293 const char *lastTag = db_column_text(&q, 0);
4294 descr->zRelTagname = fossil_strdup(lastTag);
4295 descr->nCommitsSince = db_column_int(&q, 1);
4296 nRet = 0;
4297 }else{
4298 /* no ancestor commit with a fitting singleton tag found */
4299 descr->zRelTagname = mprintf("");
4300
+1 -2
--- src/json.c
+++ src/json.c
@@ -1643,11 +1643,11 @@
16431643
int json_set_err( int code, char const * fmt, ... ){
16441644
assert( (code>=1000) && (code<=9999) );
16451645
fossil_free(g.zErrMsg);
16461646
g.json.resultCode = code;
16471647
if(!fmt || !*fmt){
1648
- g.zErrMsg = mprintf("%s", json_err_cstr(code));
1648
+ g.zErrMsg = fossil_strdup(json_err_cstr(code));
16491649
}else{
16501650
va_list vargs;
16511651
char * msg;
16521652
va_start(vargs,fmt);
16531653
msg = vmprintf(fmt, vargs);
@@ -1961,11 +1961,10 @@
19611961
19621962
#define ADD(X,K) cson_object_set(obj, K, cson_value_new_bool(g.perm.X))
19631963
ADD(Setup,"setup");
19641964
ADD(Admin,"admin");
19651965
ADD(Password,"password");
1966
- ADD(Query,"query"); /* don't think this one is actually used */
19671966
ADD(Write,"checkin");
19681967
ADD(Read,"checkout");
19691968
ADD(Hyperlink,"history");
19701969
ADD(Clone,"clone");
19711970
ADD(RdWiki,"readWiki");
19721971
--- src/json.c
+++ src/json.c
@@ -1643,11 +1643,11 @@
1643 int json_set_err( int code, char const * fmt, ... ){
1644 assert( (code>=1000) && (code<=9999) );
1645 fossil_free(g.zErrMsg);
1646 g.json.resultCode = code;
1647 if(!fmt || !*fmt){
1648 g.zErrMsg = mprintf("%s", json_err_cstr(code));
1649 }else{
1650 va_list vargs;
1651 char * msg;
1652 va_start(vargs,fmt);
1653 msg = vmprintf(fmt, vargs);
@@ -1961,11 +1961,10 @@
1961
1962 #define ADD(X,K) cson_object_set(obj, K, cson_value_new_bool(g.perm.X))
1963 ADD(Setup,"setup");
1964 ADD(Admin,"admin");
1965 ADD(Password,"password");
1966 ADD(Query,"query"); /* don't think this one is actually used */
1967 ADD(Write,"checkin");
1968 ADD(Read,"checkout");
1969 ADD(Hyperlink,"history");
1970 ADD(Clone,"clone");
1971 ADD(RdWiki,"readWiki");
1972
--- src/json.c
+++ src/json.c
@@ -1643,11 +1643,11 @@
1643 int json_set_err( int code, char const * fmt, ... ){
1644 assert( (code>=1000) && (code<=9999) );
1645 fossil_free(g.zErrMsg);
1646 g.json.resultCode = code;
1647 if(!fmt || !*fmt){
1648 g.zErrMsg = fossil_strdup(json_err_cstr(code));
1649 }else{
1650 va_list vargs;
1651 char * msg;
1652 va_start(vargs,fmt);
1653 msg = vmprintf(fmt, vargs);
@@ -1961,11 +1961,10 @@
1961
1962 #define ADD(X,K) cson_object_set(obj, K, cson_value_new_bool(g.perm.X))
1963 ADD(Setup,"setup");
1964 ADD(Admin,"admin");
1965 ADD(Password,"password");
 
1966 ADD(Write,"checkin");
1967 ADD(Read,"checkout");
1968 ADD(Hyperlink,"history");
1969 ADD(Clone,"clone");
1970 ADD(RdWiki,"readWiki");
1971
--- src/json_report.c
+++ src/json_report.c
@@ -202,11 +202,11 @@
202202
limit = json_find_option_int("limit",NULL,"n",-1);
203203
204204
205205
/* Copy over report's SQL...*/
206206
blob_append(&sql, db_column_text(&q,0), -1);
207
- zTitle = mprintf("%s", db_column_text(&q,1));
207
+ zTitle = fossil_strdup(db_column_text(&q,1));
208208
db_finalize(&q);
209209
db_prepare(&q, "%s", blob_sql_text(&sql));
210210
211211
/** Build the response... */
212212
pay = cson_new_object();
213213
--- src/json_report.c
+++ src/json_report.c
@@ -202,11 +202,11 @@
202 limit = json_find_option_int("limit",NULL,"n",-1);
203
204
205 /* Copy over report's SQL...*/
206 blob_append(&sql, db_column_text(&q,0), -1);
207 zTitle = mprintf("%s", db_column_text(&q,1));
208 db_finalize(&q);
209 db_prepare(&q, "%s", blob_sql_text(&sql));
210
211 /** Build the response... */
212 pay = cson_new_object();
213
--- src/json_report.c
+++ src/json_report.c
@@ -202,11 +202,11 @@
202 limit = json_find_option_int("limit",NULL,"n",-1);
203
204
205 /* Copy over report's SQL...*/
206 blob_append(&sql, db_column_text(&q,0), -1);
207 zTitle = fossil_strdup(db_column_text(&q,1));
208 db_finalize(&q);
209 db_prepare(&q, "%s", blob_sql_text(&sql));
210
211 /** Build the response... */
212 pay = cson_new_object();
213
+45 -22
--- src/main.c
+++ src/main.c
@@ -83,11 +83,10 @@
8383
*/
8484
struct FossilUserPerms {
8585
char Setup; /* s: use Setup screens on web interface */
8686
char Admin; /* a: administrative permission */
8787
char Password; /* p: change password */
88
- char Query; /* q: create new reports */
8988
char Write; /* i: xfer inbound. check-in */
9089
char Read; /* o: xfer outbound. check-out */
9190
char Hyperlink; /* h: enable the display of hyperlinks */
9291
char Clone; /* g: clone */
9392
char RdWiki; /* j: view wiki via web */
@@ -289,10 +288,27 @@
289288
int allowSymlinks; /* Cached "allow-symlinks" option */
290289
int mainTimerId; /* Set to fossil_timer_start() */
291290
int nPendingRequest; /* # of HTTP requests in "fossil server" */
292291
int nRequest; /* Total # of HTTP request */
293292
int bAvoidDeltaManifests; /* Avoid using delta manifests if true */
293
+
294
+ /* State for communicating specific details between the inbound HTTP
295
+ ** header parser (cgi.c), xfer.c, and http.c. */
296
+ struct {
297
+ char *zLoginCard; /* Inbound "x-f-l-c" Cookie header. */
298
+ int fLoginCardMode; /* If non-0, emit login cards in outbound
299
+ ** requests as a HTTP cookie instead of as
300
+ ** part of the payload. Gets activated
301
+ ** on-demand based on xfer traffic
302
+ ** contents. Values, for
303
+ ** diagnostic/debugging purposes: 0x01=CLI
304
+ ** --flag, 0x02=cgi_setup_query_string(),
305
+ ** 0x04=page_xfer(),
306
+ ** 0x08=client_sync(). */
307
+ int remoteVersion; /* Remote fossil version. Used for negotiating
308
+ ** how to handle the login card. */
309
+ } syncInfo;
294310
#ifdef FOSSIL_ENABLE_JSON
295311
struct FossilJsonBits {
296312
int isJsonMode; /* True if running in JSON mode, else
297313
false. This changes how errors are
298314
reported. In JSON mode we try to
@@ -759,10 +775,17 @@
759775
g.tcl.argc = g.argc;
760776
g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
761777
#endif
762778
g.mainTimerId = fossil_timer_start();
763779
capture_case_sensitive_option();
780
+ g.syncInfo.fLoginCardMode =
781
+ /* The undocumented/unsupported --login-card-header provides a way
782
+ ** to force use of the feature added by the xfer-login-card branch
783
+ ** in 2025-07, intended for assisting in debugging any related
784
+ ** issues. It can be removed once we reach the level of "implicit
785
+ ** trust" in that feature. */
786
+ find_option("login-card-header",0,0) ? 0x01 : 0;
764787
g.zVfsName = find_option("vfs",0,1);
765788
if( g.zVfsName==0 ){
766789
g.zVfsName = fossil_getenv("FOSSIL_VFS");
767790
}
768791
if( g.zVfsName ){
@@ -1140,11 +1163,11 @@
11401163
*/
11411164
const char *find_repository_option(){
11421165
const char *zRepository = find_option("repository", "R", 1);
11431166
if( zRepository ){
11441167
if( g.zRepositoryOption ) fossil_free(g.zRepositoryOption);
1145
- g.zRepositoryOption = mprintf("%s", zRepository);
1168
+ g.zRepositoryOption = fossil_strdup(zRepository);
11461169
}
11471170
return g.zRepositoryOption;
11481171
}
11491172
11501173
/*
@@ -1386,20 +1409,20 @@
13861409
const char *zCur;
13871410
13881411
if( g.zBaseURL!=0 ) return;
13891412
if( zAltBase ){
13901413
int i, n, c;
1391
- g.zTop = g.zBaseURL = mprintf("%s", zAltBase);
1414
+ g.zTop = g.zBaseURL = fossil_strdup(zAltBase);
13921415
i = (int)strlen(g.zBaseURL);
13931416
while( i>3 && g.zBaseURL[i-1]=='/' ){ i--; }
13941417
g.zBaseURL[i] = 0;
13951418
if( strncmp(g.zTop, "http://", 7)==0 ){
13961419
/* it is HTTP, replace prefix with HTTPS. */
13971420
g.zHttpsURL = mprintf("https://%s", &g.zTop[7]);
13981421
}else if( strncmp(g.zTop, "https://", 8)==0 ){
13991422
/* it is already HTTPS, use it. */
1400
- g.zHttpsURL = mprintf("%s", g.zTop);
1423
+ g.zHttpsURL = fossil_strdup(g.zTop);
14011424
}else{
14021425
fossil_fatal("argument to --baseurl should be 'http://host/path'"
14031426
" or 'https://host/path'");
14041427
}
14051428
for(i=n=0; (c = g.zTop[i])!=0; i++){
@@ -1491,11 +1514,11 @@
14911514
/* In order for ?skin=... to work when visiting the site from
14921515
** a typical external link, we have to process it here, as
14931516
** that parameter gets lost during the redirect. We "could"
14941517
** pass the whole query string along instead, but that seems
14951518
** unnecessary. */
1496
- if(cgi_setup_query_string()>1){
1519
+ if(cgi_setup_query_string() & 0x02){
14971520
cookie_render();
14981521
}
14991522
cgi_redirectf("%R%s", db_get("index-page", "/index"));
15001523
}
15011524
@@ -1795,22 +1818,22 @@
17951818
}
17961819
17971820
17981821
/* Restrictions on the URI for security:
17991822
**
1800
- ** 1. Reject characters that are not ASCII alphanumerics,
1823
+ ** 1. Reject characters that are not ASCII alphanumerics,
18011824
** "-", "_", ".", "/", or unicode (above ASCII).
18021825
** In other words: No ASCII punctuation or control characters
18031826
** other than "-", "_", "." and "/".
1804
- ** 2. Exception to rule 1: Allow /X:/ where X is any ASCII
1827
+ ** 2. Exception to rule 1: Allow /X:/ where X is any ASCII
18051828
** alphabetic character at the beginning of the name on windows.
18061829
** 3. "-" may not occur immediately after "/"
18071830
** 4. "." may not be adjacent to another "." or to "/"
18081831
**
18091832
** Any character does not satisfy these constraints a Not Found
18101833
** error is returned.
1811
- */
1834
+ */
18121835
szFile = 0;
18131836
for(j=nBase+1, k=0; zRepo[j] && k<i-1; j++, k++){
18141837
char c = zRepo[j];
18151838
if( c>='a' && c<='z' ) continue;
18161839
if( c>='A' && c<='Z' ) continue;
@@ -2072,11 +2095,11 @@
20722095
cgi_redirectf("%R/ckout");
20732096
}else{
20742097
fossil_redirect_home() /*does not return*/;
20752098
}
20762099
}else{
2077
- zPath = mprintf("%s", zPathInfo);
2100
+ zPath = fossil_strdup(zPathInfo);
20782101
}
20792102
20802103
/* Make g.zPath point to the first element of the path. Make
20812104
** g.zExtra point to everything past that point.
20822105
*/
@@ -2483,21 +2506,21 @@
24832506
** If repository: is omitted, then terms of the PATH_INFO cgi parameter
24842507
** are appended to DIRECTORY looking for a repository (whose name ends
24852508
** in ".fossil") or a file in "files:".
24862509
*/
24872510
db_close(1);
2488
- g.zRepositoryName = mprintf("%s", blob_str(&value));
2511
+ g.zRepositoryName = fossil_strdup(blob_str(&value));
24892512
blob_reset(&value);
24902513
continue;
24912514
}
24922515
if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){
24932516
/* notfound: URL
24942517
**
24952518
** If using directory: and no suitable repository or file is found,
24962519
** then redirect to URL.
24972520
*/
2498
- zNotFound = mprintf("%s", blob_str(&value));
2521
+ zNotFound = fossil_strdup(blob_str(&value));
24992522
blob_reset(&value);
25002523
continue;
25012524
}
25022525
if( blob_eq(&key, "localauth") ){
25032526
/* localauth
@@ -2537,12 +2560,12 @@
25372560
&& blob_token(&line, &value2) ){
25382561
/* See the header comment on the redirect_web_page() function
25392562
** above for details. */
25402563
nRedirect++;
25412564
azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*));
2542
- azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value));
2543
- azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2));
2565
+ azRedirect[nRedirect*2-2] = fossil_strdup(blob_str(&value));
2566
+ azRedirect[nRedirect*2-1] = fossil_strdup(blob_str(&value2));
25442567
blob_reset(&value);
25452568
blob_reset(&value2);
25462569
continue;
25472570
}
25482571
if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
@@ -2581,20 +2604,20 @@
25812604
/* errorlog: FILENAME
25822605
**
25832606
** Causes messages from warnings, errors, and panics to be appended
25842607
** to FILENAME.
25852608
*/
2586
- g.zErrlog = mprintf("%s", blob_str(&value));
2609
+ g.zErrlog = fossil_strdup(blob_str(&value));
25872610
blob_reset(&value);
25882611
continue;
25892612
}
25902613
if( blob_eq(&key, "extroot:") && blob_token(&line, &value) ){
25912614
/* extroot: DIRECTORY
25922615
**
25932616
** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
25942617
*/
2595
- g.zExtRoot = mprintf("%s", blob_str(&value));
2618
+ g.zExtRoot = fossil_strdup(blob_str(&value));
25962619
blob_reset(&value);
25972620
continue;
25982621
}
25992622
if( blob_eq(&key, "timeout:") && blob_token(&line, &value) ){
26002623
/* timeout: SECONDS
@@ -2651,11 +2674,11 @@
26512674
**
26522675
** Use the contents of FILENAME as the value of the site's
26532676
** "mainmenu" setting, overriding the contents (for this
26542677
** request) of the db-side setting or the hard-coded default.
26552678
*/
2656
- g.zMainMenuFile = mprintf("%s", blob_str(&value));
2679
+ g.zMainMenuFile = fossil_strdup(blob_str(&value));
26572680
blob_reset(&value);
26582681
continue;
26592682
}
26602683
if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
26612684
/* cgi-debug: FILENAME
@@ -2708,11 +2731,11 @@
27082731
db_must_be_within_tree();
27092732
}else{
27102733
const char *zRepo = g.argv[arg];
27112734
int isDir = file_isdir(zRepo, ExtFILE);
27122735
if( isDir==1 ){
2713
- g.zRepositoryName = mprintf("%s", zRepo);
2736
+ g.zRepositoryName = fossil_strdup(zRepo);
27142737
file_simplify_name(g.zRepositoryName, -1, 0);
27152738
}else{
27162739
if( isDir==0 && fCreate ){
27172740
const char *zPassword;
27182741
db_create_repository(zRepo);
@@ -2920,11 +2943,11 @@
29202943
** the argument being URL encoded, to avoid wildcard expansion in the
29212944
** shell. This option is for internal use and is undocumented.
29222945
*/
29232946
zFileGlob = find_option("files-urlenc",0,1);
29242947
if( zFileGlob ){
2925
- char *z = mprintf("%s", zFileGlob);
2948
+ char *z = fossil_strdup(zFileGlob);
29262949
dehttpize(z);
29272950
zFileGlob = z;
29282951
}else{
29292952
zFileGlob = find_option("files",0,1);
29302953
}
@@ -3064,11 +3087,11 @@
30643087
**
30653088
** echo 'GET /timeline' >request.txt
30663089
**
30673090
** Then run (in a debugger) a command like this:
30683091
**
3069
-** fossil test-http --debug <request.txt
3092
+** fossil test-http <request.txt
30703093
**
30713094
** This command is also used internally by the "ssh" sync protocol. Some
30723095
** special processing to support sync happens when this command is run
30733096
** and the SSH_CONNECTION environment variable is set. Use the --test
30743097
** option on interactive sessions to avoid that special processing when
@@ -3330,11 +3353,11 @@
33303353
g.zExtRoot = find_option("extroot",0,1);
33313354
zJsMode = find_option("jsmode",0,1);
33323355
builtin_set_js_delivery_mode(zJsMode,0);
33333356
zFileGlob = find_option("files-urlenc",0,1);
33343357
if( zFileGlob ){
3335
- char *z = mprintf("%s", zFileGlob);
3358
+ char *z = fossil_strdup(zFileGlob);
33363359
dehttpize(z);
33373360
zFileGlob = z;
33383361
}else{
33393362
zFileGlob = find_option("files",0,1);
33403363
}
@@ -3511,11 +3534,11 @@
35113534
** "fossil ui --nobrowser" on the remote system and to set up a
35123535
** tunnel from the local machine to the remote. */
35133536
FILE *sshIn;
35143537
Blob ssh;
35153538
int bRunning = 0; /* True when fossil starts up on the remote */
3516
- int isRetry; /* True if on the second attempt */
3539
+ int isRetry; /* True if on the second attempt */
35173540
char zLine[1000];
35183541
35193542
blob_init(&ssh, 0, 0);
35203543
for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
35213544
blob_reset(&ssh);
@@ -3550,11 +3573,11 @@
35503573
if( fCreate ) blob_appendf(&ssh, " --create");
35513574
blob_appendf(&ssh, " %$", g.argv[2]);
35523575
if( isRetry ){
35533576
fossil_print("First attempt to run \"fossil\" on %s failed\n"
35543577
"Retry: ", zRemote);
3555
- }
3578
+ }
35563579
fossil_print("%s\n", blob_str(&ssh));
35573580
sshIn = popen(blob_str(&ssh), "r");
35583581
if( sshIn==0 ){
35593582
fossil_fatal("unable to %s", blob_str(&ssh));
35603583
}
35613584
--- src/main.c
+++ src/main.c
@@ -83,11 +83,10 @@
83 */
84 struct FossilUserPerms {
85 char Setup; /* s: use Setup screens on web interface */
86 char Admin; /* a: administrative permission */
87 char Password; /* p: change password */
88 char Query; /* q: create new reports */
89 char Write; /* i: xfer inbound. check-in */
90 char Read; /* o: xfer outbound. check-out */
91 char Hyperlink; /* h: enable the display of hyperlinks */
92 char Clone; /* g: clone */
93 char RdWiki; /* j: view wiki via web */
@@ -289,10 +288,27 @@
289 int allowSymlinks; /* Cached "allow-symlinks" option */
290 int mainTimerId; /* Set to fossil_timer_start() */
291 int nPendingRequest; /* # of HTTP requests in "fossil server" */
292 int nRequest; /* Total # of HTTP request */
293 int bAvoidDeltaManifests; /* Avoid using delta manifests if true */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294 #ifdef FOSSIL_ENABLE_JSON
295 struct FossilJsonBits {
296 int isJsonMode; /* True if running in JSON mode, else
297 false. This changes how errors are
298 reported. In JSON mode we try to
@@ -759,10 +775,17 @@
759 g.tcl.argc = g.argc;
760 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
761 #endif
762 g.mainTimerId = fossil_timer_start();
763 capture_case_sensitive_option();
 
 
 
 
 
 
 
764 g.zVfsName = find_option("vfs",0,1);
765 if( g.zVfsName==0 ){
766 g.zVfsName = fossil_getenv("FOSSIL_VFS");
767 }
768 if( g.zVfsName ){
@@ -1140,11 +1163,11 @@
1140 */
1141 const char *find_repository_option(){
1142 const char *zRepository = find_option("repository", "R", 1);
1143 if( zRepository ){
1144 if( g.zRepositoryOption ) fossil_free(g.zRepositoryOption);
1145 g.zRepositoryOption = mprintf("%s", zRepository);
1146 }
1147 return g.zRepositoryOption;
1148 }
1149
1150 /*
@@ -1386,20 +1409,20 @@
1386 const char *zCur;
1387
1388 if( g.zBaseURL!=0 ) return;
1389 if( zAltBase ){
1390 int i, n, c;
1391 g.zTop = g.zBaseURL = mprintf("%s", zAltBase);
1392 i = (int)strlen(g.zBaseURL);
1393 while( i>3 && g.zBaseURL[i-1]=='/' ){ i--; }
1394 g.zBaseURL[i] = 0;
1395 if( strncmp(g.zTop, "http://", 7)==0 ){
1396 /* it is HTTP, replace prefix with HTTPS. */
1397 g.zHttpsURL = mprintf("https://%s", &g.zTop[7]);
1398 }else if( strncmp(g.zTop, "https://", 8)==0 ){
1399 /* it is already HTTPS, use it. */
1400 g.zHttpsURL = mprintf("%s", g.zTop);
1401 }else{
1402 fossil_fatal("argument to --baseurl should be 'http://host/path'"
1403 " or 'https://host/path'");
1404 }
1405 for(i=n=0; (c = g.zTop[i])!=0; i++){
@@ -1491,11 +1514,11 @@
1491 /* In order for ?skin=... to work when visiting the site from
1492 ** a typical external link, we have to process it here, as
1493 ** that parameter gets lost during the redirect. We "could"
1494 ** pass the whole query string along instead, but that seems
1495 ** unnecessary. */
1496 if(cgi_setup_query_string()>1){
1497 cookie_render();
1498 }
1499 cgi_redirectf("%R%s", db_get("index-page", "/index"));
1500 }
1501
@@ -1795,22 +1818,22 @@
1795 }
1796
1797
1798 /* Restrictions on the URI for security:
1799 **
1800 ** 1. Reject characters that are not ASCII alphanumerics,
1801 ** "-", "_", ".", "/", or unicode (above ASCII).
1802 ** In other words: No ASCII punctuation or control characters
1803 ** other than "-", "_", "." and "/".
1804 ** 2. Exception to rule 1: Allow /X:/ where X is any ASCII
1805 ** alphabetic character at the beginning of the name on windows.
1806 ** 3. "-" may not occur immediately after "/"
1807 ** 4. "." may not be adjacent to another "." or to "/"
1808 **
1809 ** Any character does not satisfy these constraints a Not Found
1810 ** error is returned.
1811 */
1812 szFile = 0;
1813 for(j=nBase+1, k=0; zRepo[j] && k<i-1; j++, k++){
1814 char c = zRepo[j];
1815 if( c>='a' && c<='z' ) continue;
1816 if( c>='A' && c<='Z' ) continue;
@@ -2072,11 +2095,11 @@
2072 cgi_redirectf("%R/ckout");
2073 }else{
2074 fossil_redirect_home() /*does not return*/;
2075 }
2076 }else{
2077 zPath = mprintf("%s", zPathInfo);
2078 }
2079
2080 /* Make g.zPath point to the first element of the path. Make
2081 ** g.zExtra point to everything past that point.
2082 */
@@ -2483,21 +2506,21 @@
2483 ** If repository: is omitted, then terms of the PATH_INFO cgi parameter
2484 ** are appended to DIRECTORY looking for a repository (whose name ends
2485 ** in ".fossil") or a file in "files:".
2486 */
2487 db_close(1);
2488 g.zRepositoryName = mprintf("%s", blob_str(&value));
2489 blob_reset(&value);
2490 continue;
2491 }
2492 if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){
2493 /* notfound: URL
2494 **
2495 ** If using directory: and no suitable repository or file is found,
2496 ** then redirect to URL.
2497 */
2498 zNotFound = mprintf("%s", blob_str(&value));
2499 blob_reset(&value);
2500 continue;
2501 }
2502 if( blob_eq(&key, "localauth") ){
2503 /* localauth
@@ -2537,12 +2560,12 @@
2537 && blob_token(&line, &value2) ){
2538 /* See the header comment on the redirect_web_page() function
2539 ** above for details. */
2540 nRedirect++;
2541 azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*));
2542 azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value));
2543 azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2));
2544 blob_reset(&value);
2545 blob_reset(&value2);
2546 continue;
2547 }
2548 if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
@@ -2581,20 +2604,20 @@
2581 /* errorlog: FILENAME
2582 **
2583 ** Causes messages from warnings, errors, and panics to be appended
2584 ** to FILENAME.
2585 */
2586 g.zErrlog = mprintf("%s", blob_str(&value));
2587 blob_reset(&value);
2588 continue;
2589 }
2590 if( blob_eq(&key, "extroot:") && blob_token(&line, &value) ){
2591 /* extroot: DIRECTORY
2592 **
2593 ** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
2594 */
2595 g.zExtRoot = mprintf("%s", blob_str(&value));
2596 blob_reset(&value);
2597 continue;
2598 }
2599 if( blob_eq(&key, "timeout:") && blob_token(&line, &value) ){
2600 /* timeout: SECONDS
@@ -2651,11 +2674,11 @@
2651 **
2652 ** Use the contents of FILENAME as the value of the site's
2653 ** "mainmenu" setting, overriding the contents (for this
2654 ** request) of the db-side setting or the hard-coded default.
2655 */
2656 g.zMainMenuFile = mprintf("%s", blob_str(&value));
2657 blob_reset(&value);
2658 continue;
2659 }
2660 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2661 /* cgi-debug: FILENAME
@@ -2708,11 +2731,11 @@
2708 db_must_be_within_tree();
2709 }else{
2710 const char *zRepo = g.argv[arg];
2711 int isDir = file_isdir(zRepo, ExtFILE);
2712 if( isDir==1 ){
2713 g.zRepositoryName = mprintf("%s", zRepo);
2714 file_simplify_name(g.zRepositoryName, -1, 0);
2715 }else{
2716 if( isDir==0 && fCreate ){
2717 const char *zPassword;
2718 db_create_repository(zRepo);
@@ -2920,11 +2943,11 @@
2920 ** the argument being URL encoded, to avoid wildcard expansion in the
2921 ** shell. This option is for internal use and is undocumented.
2922 */
2923 zFileGlob = find_option("files-urlenc",0,1);
2924 if( zFileGlob ){
2925 char *z = mprintf("%s", zFileGlob);
2926 dehttpize(z);
2927 zFileGlob = z;
2928 }else{
2929 zFileGlob = find_option("files",0,1);
2930 }
@@ -3064,11 +3087,11 @@
3064 **
3065 ** echo 'GET /timeline' >request.txt
3066 **
3067 ** Then run (in a debugger) a command like this:
3068 **
3069 ** fossil test-http --debug <request.txt
3070 **
3071 ** This command is also used internally by the "ssh" sync protocol. Some
3072 ** special processing to support sync happens when this command is run
3073 ** and the SSH_CONNECTION environment variable is set. Use the --test
3074 ** option on interactive sessions to avoid that special processing when
@@ -3330,11 +3353,11 @@
3330 g.zExtRoot = find_option("extroot",0,1);
3331 zJsMode = find_option("jsmode",0,1);
3332 builtin_set_js_delivery_mode(zJsMode,0);
3333 zFileGlob = find_option("files-urlenc",0,1);
3334 if( zFileGlob ){
3335 char *z = mprintf("%s", zFileGlob);
3336 dehttpize(z);
3337 zFileGlob = z;
3338 }else{
3339 zFileGlob = find_option("files",0,1);
3340 }
@@ -3511,11 +3534,11 @@
3511 ** "fossil ui --nobrowser" on the remote system and to set up a
3512 ** tunnel from the local machine to the remote. */
3513 FILE *sshIn;
3514 Blob ssh;
3515 int bRunning = 0; /* True when fossil starts up on the remote */
3516 int isRetry; /* True if on the second attempt */
3517 char zLine[1000];
3518
3519 blob_init(&ssh, 0, 0);
3520 for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
3521 blob_reset(&ssh);
@@ -3550,11 +3573,11 @@
3550 if( fCreate ) blob_appendf(&ssh, " --create");
3551 blob_appendf(&ssh, " %$", g.argv[2]);
3552 if( isRetry ){
3553 fossil_print("First attempt to run \"fossil\" on %s failed\n"
3554 "Retry: ", zRemote);
3555 }
3556 fossil_print("%s\n", blob_str(&ssh));
3557 sshIn = popen(blob_str(&ssh), "r");
3558 if( sshIn==0 ){
3559 fossil_fatal("unable to %s", blob_str(&ssh));
3560 }
3561
--- src/main.c
+++ src/main.c
@@ -83,11 +83,10 @@
83 */
84 struct FossilUserPerms {
85 char Setup; /* s: use Setup screens on web interface */
86 char Admin; /* a: administrative permission */
87 char Password; /* p: change password */
 
88 char Write; /* i: xfer inbound. check-in */
89 char Read; /* o: xfer outbound. check-out */
90 char Hyperlink; /* h: enable the display of hyperlinks */
91 char Clone; /* g: clone */
92 char RdWiki; /* j: view wiki via web */
@@ -289,10 +288,27 @@
288 int allowSymlinks; /* Cached "allow-symlinks" option */
289 int mainTimerId; /* Set to fossil_timer_start() */
290 int nPendingRequest; /* # of HTTP requests in "fossil server" */
291 int nRequest; /* Total # of HTTP request */
292 int bAvoidDeltaManifests; /* Avoid using delta manifests if true */
293
294 /* State for communicating specific details between the inbound HTTP
295 ** header parser (cgi.c), xfer.c, and http.c. */
296 struct {
297 char *zLoginCard; /* Inbound "x-f-l-c" Cookie header. */
298 int fLoginCardMode; /* If non-0, emit login cards in outbound
299 ** requests as a HTTP cookie instead of as
300 ** part of the payload. Gets activated
301 ** on-demand based on xfer traffic
302 ** contents. Values, for
303 ** diagnostic/debugging purposes: 0x01=CLI
304 ** --flag, 0x02=cgi_setup_query_string(),
305 ** 0x04=page_xfer(),
306 ** 0x08=client_sync(). */
307 int remoteVersion; /* Remote fossil version. Used for negotiating
308 ** how to handle the login card. */
309 } syncInfo;
310 #ifdef FOSSIL_ENABLE_JSON
311 struct FossilJsonBits {
312 int isJsonMode; /* True if running in JSON mode, else
313 false. This changes how errors are
314 reported. In JSON mode we try to
@@ -759,10 +775,17 @@
775 g.tcl.argc = g.argc;
776 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
777 #endif
778 g.mainTimerId = fossil_timer_start();
779 capture_case_sensitive_option();
780 g.syncInfo.fLoginCardMode =
781 /* The undocumented/unsupported --login-card-header provides a way
782 ** to force use of the feature added by the xfer-login-card branch
783 ** in 2025-07, intended for assisting in debugging any related
784 ** issues. It can be removed once we reach the level of "implicit
785 ** trust" in that feature. */
786 find_option("login-card-header",0,0) ? 0x01 : 0;
787 g.zVfsName = find_option("vfs",0,1);
788 if( g.zVfsName==0 ){
789 g.zVfsName = fossil_getenv("FOSSIL_VFS");
790 }
791 if( g.zVfsName ){
@@ -1140,11 +1163,11 @@
1163 */
1164 const char *find_repository_option(){
1165 const char *zRepository = find_option("repository", "R", 1);
1166 if( zRepository ){
1167 if( g.zRepositoryOption ) fossil_free(g.zRepositoryOption);
1168 g.zRepositoryOption = fossil_strdup(zRepository);
1169 }
1170 return g.zRepositoryOption;
1171 }
1172
1173 /*
@@ -1386,20 +1409,20 @@
1409 const char *zCur;
1410
1411 if( g.zBaseURL!=0 ) return;
1412 if( zAltBase ){
1413 int i, n, c;
1414 g.zTop = g.zBaseURL = fossil_strdup(zAltBase);
1415 i = (int)strlen(g.zBaseURL);
1416 while( i>3 && g.zBaseURL[i-1]=='/' ){ i--; }
1417 g.zBaseURL[i] = 0;
1418 if( strncmp(g.zTop, "http://", 7)==0 ){
1419 /* it is HTTP, replace prefix with HTTPS. */
1420 g.zHttpsURL = mprintf("https://%s", &g.zTop[7]);
1421 }else if( strncmp(g.zTop, "https://", 8)==0 ){
1422 /* it is already HTTPS, use it. */
1423 g.zHttpsURL = fossil_strdup(g.zTop);
1424 }else{
1425 fossil_fatal("argument to --baseurl should be 'http://host/path'"
1426 " or 'https://host/path'");
1427 }
1428 for(i=n=0; (c = g.zTop[i])!=0; i++){
@@ -1491,11 +1514,11 @@
1514 /* In order for ?skin=... to work when visiting the site from
1515 ** a typical external link, we have to process it here, as
1516 ** that parameter gets lost during the redirect. We "could"
1517 ** pass the whole query string along instead, but that seems
1518 ** unnecessary. */
1519 if(cgi_setup_query_string() & 0x02){
1520 cookie_render();
1521 }
1522 cgi_redirectf("%R%s", db_get("index-page", "/index"));
1523 }
1524
@@ -1795,22 +1818,22 @@
1818 }
1819
1820
1821 /* Restrictions on the URI for security:
1822 **
1823 ** 1. Reject characters that are not ASCII alphanumerics,
1824 ** "-", "_", ".", "/", or unicode (above ASCII).
1825 ** In other words: No ASCII punctuation or control characters
1826 ** other than "-", "_", "." and "/".
1827 ** 2. Exception to rule 1: Allow /X:/ where X is any ASCII
1828 ** alphabetic character at the beginning of the name on windows.
1829 ** 3. "-" may not occur immediately after "/"
1830 ** 4. "." may not be adjacent to another "." or to "/"
1831 **
1832 ** Any character does not satisfy these constraints a Not Found
1833 ** error is returned.
1834 */
1835 szFile = 0;
1836 for(j=nBase+1, k=0; zRepo[j] && k<i-1; j++, k++){
1837 char c = zRepo[j];
1838 if( c>='a' && c<='z' ) continue;
1839 if( c>='A' && c<='Z' ) continue;
@@ -2072,11 +2095,11 @@
2095 cgi_redirectf("%R/ckout");
2096 }else{
2097 fossil_redirect_home() /*does not return*/;
2098 }
2099 }else{
2100 zPath = fossil_strdup(zPathInfo);
2101 }
2102
2103 /* Make g.zPath point to the first element of the path. Make
2104 ** g.zExtra point to everything past that point.
2105 */
@@ -2483,21 +2506,21 @@
2506 ** If repository: is omitted, then terms of the PATH_INFO cgi parameter
2507 ** are appended to DIRECTORY looking for a repository (whose name ends
2508 ** in ".fossil") or a file in "files:".
2509 */
2510 db_close(1);
2511 g.zRepositoryName = fossil_strdup(blob_str(&value));
2512 blob_reset(&value);
2513 continue;
2514 }
2515 if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){
2516 /* notfound: URL
2517 **
2518 ** If using directory: and no suitable repository or file is found,
2519 ** then redirect to URL.
2520 */
2521 zNotFound = fossil_strdup(blob_str(&value));
2522 blob_reset(&value);
2523 continue;
2524 }
2525 if( blob_eq(&key, "localauth") ){
2526 /* localauth
@@ -2537,12 +2560,12 @@
2560 && blob_token(&line, &value2) ){
2561 /* See the header comment on the redirect_web_page() function
2562 ** above for details. */
2563 nRedirect++;
2564 azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*));
2565 azRedirect[nRedirect*2-2] = fossil_strdup(blob_str(&value));
2566 azRedirect[nRedirect*2-1] = fossil_strdup(blob_str(&value2));
2567 blob_reset(&value);
2568 blob_reset(&value2);
2569 continue;
2570 }
2571 if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
@@ -2581,20 +2604,20 @@
2604 /* errorlog: FILENAME
2605 **
2606 ** Causes messages from warnings, errors, and panics to be appended
2607 ** to FILENAME.
2608 */
2609 g.zErrlog = fossil_strdup(blob_str(&value));
2610 blob_reset(&value);
2611 continue;
2612 }
2613 if( blob_eq(&key, "extroot:") && blob_token(&line, &value) ){
2614 /* extroot: DIRECTORY
2615 **
2616 ** Enables the /ext webpage to use sub-cgi rooted at DIRECTORY
2617 */
2618 g.zExtRoot = fossil_strdup(blob_str(&value));
2619 blob_reset(&value);
2620 continue;
2621 }
2622 if( blob_eq(&key, "timeout:") && blob_token(&line, &value) ){
2623 /* timeout: SECONDS
@@ -2651,11 +2674,11 @@
2674 **
2675 ** Use the contents of FILENAME as the value of the site's
2676 ** "mainmenu" setting, overriding the contents (for this
2677 ** request) of the db-side setting or the hard-coded default.
2678 */
2679 g.zMainMenuFile = fossil_strdup(blob_str(&value));
2680 blob_reset(&value);
2681 continue;
2682 }
2683 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2684 /* cgi-debug: FILENAME
@@ -2708,11 +2731,11 @@
2731 db_must_be_within_tree();
2732 }else{
2733 const char *zRepo = g.argv[arg];
2734 int isDir = file_isdir(zRepo, ExtFILE);
2735 if( isDir==1 ){
2736 g.zRepositoryName = fossil_strdup(zRepo);
2737 file_simplify_name(g.zRepositoryName, -1, 0);
2738 }else{
2739 if( isDir==0 && fCreate ){
2740 const char *zPassword;
2741 db_create_repository(zRepo);
@@ -2920,11 +2943,11 @@
2943 ** the argument being URL encoded, to avoid wildcard expansion in the
2944 ** shell. This option is for internal use and is undocumented.
2945 */
2946 zFileGlob = find_option("files-urlenc",0,1);
2947 if( zFileGlob ){
2948 char *z = fossil_strdup(zFileGlob);
2949 dehttpize(z);
2950 zFileGlob = z;
2951 }else{
2952 zFileGlob = find_option("files",0,1);
2953 }
@@ -3064,11 +3087,11 @@
3087 **
3088 ** echo 'GET /timeline' >request.txt
3089 **
3090 ** Then run (in a debugger) a command like this:
3091 **
3092 ** fossil test-http <request.txt
3093 **
3094 ** This command is also used internally by the "ssh" sync protocol. Some
3095 ** special processing to support sync happens when this command is run
3096 ** and the SSH_CONNECTION environment variable is set. Use the --test
3097 ** option on interactive sessions to avoid that special processing when
@@ -3330,11 +3353,11 @@
3353 g.zExtRoot = find_option("extroot",0,1);
3354 zJsMode = find_option("jsmode",0,1);
3355 builtin_set_js_delivery_mode(zJsMode,0);
3356 zFileGlob = find_option("files-urlenc",0,1);
3357 if( zFileGlob ){
3358 char *z = fossil_strdup(zFileGlob);
3359 dehttpize(z);
3360 zFileGlob = z;
3361 }else{
3362 zFileGlob = find_option("files",0,1);
3363 }
@@ -3511,11 +3534,11 @@
3534 ** "fossil ui --nobrowser" on the remote system and to set up a
3535 ** tunnel from the local machine to the remote. */
3536 FILE *sshIn;
3537 Blob ssh;
3538 int bRunning = 0; /* True when fossil starts up on the remote */
3539 int isRetry; /* True if on the second attempt */
3540 char zLine[1000];
3541
3542 blob_init(&ssh, 0, 0);
3543 for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
3544 blob_reset(&ssh);
@@ -3550,11 +3573,11 @@
3573 if( fCreate ) blob_appendf(&ssh, " --create");
3574 blob_appendf(&ssh, " %$", g.argv[2]);
3575 if( isRetry ){
3576 fossil_print("First attempt to run \"fossil\" on %s failed\n"
3577 "Retry: ", zRemote);
3578 }
3579 fossil_print("%s\n", blob_str(&ssh));
3580 sshIn = popen(blob_str(&ssh), "r");
3581 if( sshIn==0 ){
3582 fossil_fatal("unable to %s", blob_str(&ssh));
3583 }
3584
+17 -7
--- src/main.mk
+++ src/main.mk
@@ -578,39 +578,41 @@
578578
$(OBJDIR)/winfile.o \
579579
$(OBJDIR)/winhttp.o \
580580
$(OBJDIR)/xfer.o \
581581
$(OBJDIR)/xfersetup.o \
582582
$(OBJDIR)/zip.o
583
-all: $(OBJDIR) $(APPNAME)
583
+all: $(APPNAME)
584584
585585
install: all
586586
mkdir -p $(INSTALLDIR)
587587
cp $(APPNAME) $(INSTALLDIR)
588588
589589
codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
590590
$(OBJDIR)/codecheck1 $(TRANS_SRC)
591591
592
-$(OBJDIR):
593
- -mkdir $(OBJDIR)
594
-
595592
$(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
596593
-mkdir -p $(OBJDIR)
597594
$(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
598595
599596
$(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
597
+ -mkdir -p $(OBJDIR)
600598
$(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
601599
602600
$(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
601
+ -mkdir -p $(OBJDIR)
603602
$(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
604603
605604
$(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
605
+ -mkdir -p $(OBJDIR)
606606
$(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
607607
608608
$(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
609
+ -mkdir -p $(OBJDIR)
609610
$(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
610611
611612
$(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
613
+ -mkdir -p $(OBJDIR)
612614
$(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
613615
614616
# Run the test suite.
615617
# Other flags that can be included in TESTFLAGS are:
616618
#
@@ -622,11 +624,11 @@
622624
# -strict Treat known bugs as failures
623625
#
624626
# TESTFLAGS can also include names of specific test files to limit
625627
# the run to just those test cases.
626628
#
627
-test: $(OBJDIR) $(APPNAME)
629
+test: $(APPNAME)
628630
$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
629631
630632
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
631633
$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
632634
$(SRCDIR)/../manifest \
@@ -653,10 +655,11 @@
653655
-DSQLITE_ENABLE_DBSTAT_VTAB \
654656
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
655657
-DSQLITE_ENABLE_FTS4 \
656658
-DSQLITE_ENABLE_FTS5 \
657659
-DSQLITE_ENABLE_MATH_FUNCTIONS \
660
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
658661
-DSQLITE_ENABLE_STMTVTAB \
659662
-DSQLITE_HAVE_ZLIB \
660663
-DSQLITE_ENABLE_DBPAGE_VTAB \
661664
-DSQLITE_TRUSTED_SCHEMA=0 \
662665
-DHAVE_USLEEP
@@ -679,10 +682,11 @@
679682
-DSQLITE_ENABLE_DBSTAT_VTAB \
680683
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
681684
-DSQLITE_ENABLE_FTS4 \
682685
-DSQLITE_ENABLE_FTS5 \
683686
-DSQLITE_ENABLE_MATH_FUNCTIONS \
687
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
684688
-DSQLITE_ENABLE_STMTVTAB \
685689
-DSQLITE_HAVE_ZLIB \
686690
-DSQLITE_ENABLE_DBPAGE_VTAB \
687691
-DSQLITE_TRUSTED_SCHEMA=0 \
688692
-DHAVE_USLEEP \
@@ -2119,23 +2123,29 @@
21192123
21202124
$(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h
21212125
$(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@
21222126
21232127
$(OBJDIR)/th.o: $(SRCDIR)/th.c
2128
+ -mkdir -p $(OBJDIR)
2129
+
21242130
$(XTCC) -c $(SRCDIR)/th.c -o $@
21252131
21262132
$(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
2133
+ -mkdir -p $(OBJDIR)
2134
+
21272135
$(XTCC) -c $(SRCDIR)/th_lang.c -o $@
21282136
21292137
$(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2138
+ -mkdir -p $(OBJDIR)
2139
+
21302140
$(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
21312141
21322142
2133
-$(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
2143
+$(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c $(OBJDIR)/mkversion
21342144
$(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
21352145
2136
-$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2146
+$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c $(OBJDIR)/mkversion
21372147
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
21382148
21392149
$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
21402150
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
21412151
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore \
21422152
--- src/main.mk
+++ src/main.mk
@@ -578,39 +578,41 @@
578 $(OBJDIR)/winfile.o \
579 $(OBJDIR)/winhttp.o \
580 $(OBJDIR)/xfer.o \
581 $(OBJDIR)/xfersetup.o \
582 $(OBJDIR)/zip.o
583 all: $(OBJDIR) $(APPNAME)
584
585 install: all
586 mkdir -p $(INSTALLDIR)
587 cp $(APPNAME) $(INSTALLDIR)
588
589 codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
590 $(OBJDIR)/codecheck1 $(TRANS_SRC)
591
592 $(OBJDIR):
593 -mkdir $(OBJDIR)
594
595 $(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
596 -mkdir -p $(OBJDIR)
597 $(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
598
599 $(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
 
600 $(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
601
602 $(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
 
603 $(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
604
605 $(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
 
606 $(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
607
608 $(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
 
609 $(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
610
611 $(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
 
612 $(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
613
614 # Run the test suite.
615 # Other flags that can be included in TESTFLAGS are:
616 #
@@ -622,11 +624,11 @@
622 # -strict Treat known bugs as failures
623 #
624 # TESTFLAGS can also include names of specific test files to limit
625 # the run to just those test cases.
626 #
627 test: $(OBJDIR) $(APPNAME)
628 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
629
630 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
631 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
632 $(SRCDIR)/../manifest \
@@ -653,10 +655,11 @@
653 -DSQLITE_ENABLE_DBSTAT_VTAB \
654 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
655 -DSQLITE_ENABLE_FTS4 \
656 -DSQLITE_ENABLE_FTS5 \
657 -DSQLITE_ENABLE_MATH_FUNCTIONS \
 
658 -DSQLITE_ENABLE_STMTVTAB \
659 -DSQLITE_HAVE_ZLIB \
660 -DSQLITE_ENABLE_DBPAGE_VTAB \
661 -DSQLITE_TRUSTED_SCHEMA=0 \
662 -DHAVE_USLEEP
@@ -679,10 +682,11 @@
679 -DSQLITE_ENABLE_DBSTAT_VTAB \
680 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
681 -DSQLITE_ENABLE_FTS4 \
682 -DSQLITE_ENABLE_FTS5 \
683 -DSQLITE_ENABLE_MATH_FUNCTIONS \
 
684 -DSQLITE_ENABLE_STMTVTAB \
685 -DSQLITE_HAVE_ZLIB \
686 -DSQLITE_ENABLE_DBPAGE_VTAB \
687 -DSQLITE_TRUSTED_SCHEMA=0 \
688 -DHAVE_USLEEP \
@@ -2119,23 +2123,29 @@
2119
2120 $(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h
2121 $(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@
2122
2123 $(OBJDIR)/th.o: $(SRCDIR)/th.c
 
 
2124 $(XTCC) -c $(SRCDIR)/th.c -o $@
2125
2126 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
 
 
2127 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2128
2129 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
 
 
2130 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2131
2132
2133 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
2134 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
2135
2136 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2137 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2138
2139 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
2140 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore \
2142
--- src/main.mk
+++ src/main.mk
@@ -578,39 +578,41 @@
578 $(OBJDIR)/winfile.o \
579 $(OBJDIR)/winhttp.o \
580 $(OBJDIR)/xfer.o \
581 $(OBJDIR)/xfersetup.o \
582 $(OBJDIR)/zip.o
583 all: $(APPNAME)
584
585 install: all
586 mkdir -p $(INSTALLDIR)
587 cp $(APPNAME) $(INSTALLDIR)
588
589 codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
590 $(OBJDIR)/codecheck1 $(TRANS_SRC)
591
 
 
 
592 $(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
593 -mkdir -p $(OBJDIR)
594 $(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
595
596 $(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
597 -mkdir -p $(OBJDIR)
598 $(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
599
600 $(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
601 -mkdir -p $(OBJDIR)
602 $(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
603
604 $(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
605 -mkdir -p $(OBJDIR)
606 $(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
607
608 $(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
609 -mkdir -p $(OBJDIR)
610 $(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
611
612 $(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
613 -mkdir -p $(OBJDIR)
614 $(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
615
616 # Run the test suite.
617 # Other flags that can be included in TESTFLAGS are:
618 #
@@ -622,11 +624,11 @@
624 # -strict Treat known bugs as failures
625 #
626 # TESTFLAGS can also include names of specific test files to limit
627 # the run to just those test cases.
628 #
629 test: $(APPNAME)
630 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
631
632 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
633 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
634 $(SRCDIR)/../manifest \
@@ -653,10 +655,11 @@
655 -DSQLITE_ENABLE_DBSTAT_VTAB \
656 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
657 -DSQLITE_ENABLE_FTS4 \
658 -DSQLITE_ENABLE_FTS5 \
659 -DSQLITE_ENABLE_MATH_FUNCTIONS \
660 -DSQLITE_ENABLE_SETLK_TIMEOUT \
661 -DSQLITE_ENABLE_STMTVTAB \
662 -DSQLITE_HAVE_ZLIB \
663 -DSQLITE_ENABLE_DBPAGE_VTAB \
664 -DSQLITE_TRUSTED_SCHEMA=0 \
665 -DHAVE_USLEEP
@@ -679,10 +682,11 @@
682 -DSQLITE_ENABLE_DBSTAT_VTAB \
683 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
684 -DSQLITE_ENABLE_FTS4 \
685 -DSQLITE_ENABLE_FTS5 \
686 -DSQLITE_ENABLE_MATH_FUNCTIONS \
687 -DSQLITE_ENABLE_SETLK_TIMEOUT \
688 -DSQLITE_ENABLE_STMTVTAB \
689 -DSQLITE_HAVE_ZLIB \
690 -DSQLITE_ENABLE_DBPAGE_VTAB \
691 -DSQLITE_TRUSTED_SCHEMA=0 \
692 -DHAVE_USLEEP \
@@ -2119,23 +2123,29 @@
2123
2124 $(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h
2125 $(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@
2126
2127 $(OBJDIR)/th.o: $(SRCDIR)/th.c
2128 -mkdir -p $(OBJDIR)
2129
2130 $(XTCC) -c $(SRCDIR)/th.c -o $@
2131
2132 $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c
2133 -mkdir -p $(OBJDIR)
2134
2135 $(XTCC) -c $(SRCDIR)/th_lang.c -o $@
2136
2137 $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c
2138 -mkdir -p $(OBJDIR)
2139
2140 $(XTCC) -c $(SRCDIR)/th_tcl.c -o $@
2141
2142
2143 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c $(OBJDIR)/mkversion
2144 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
2145
2146 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c $(OBJDIR)/mkversion
2147 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2148
2149 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
2150 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2151 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore \
2152
+1 -1
--- src/merge.c
+++ src/merge.c
@@ -481,11 +481,11 @@
481481
const char *zTagList = db_column_text(&q, 4);
482482
char *zCom;
483483
if( zTagList && zTagList[0] ){
484484
zCom = mprintf("%s (%s)", db_column_text(&q, 2), zTagList);
485485
}else{
486
- zCom = mprintf("%s", db_column_text(&q,2));
486
+ zCom = fossil_strdup(db_column_text(&q,2));
487487
}
488488
fossil_print("%-*s [%S] by %s on %s\n%*s",
489489
indent-1, zLabel,
490490
db_column_text(&q, 3),
491491
db_column_text(&q, 1),
492492
--- src/merge.c
+++ src/merge.c
@@ -481,11 +481,11 @@
481 const char *zTagList = db_column_text(&q, 4);
482 char *zCom;
483 if( zTagList && zTagList[0] ){
484 zCom = mprintf("%s (%s)", db_column_text(&q, 2), zTagList);
485 }else{
486 zCom = mprintf("%s", db_column_text(&q,2));
487 }
488 fossil_print("%-*s [%S] by %s on %s\n%*s",
489 indent-1, zLabel,
490 db_column_text(&q, 3),
491 db_column_text(&q, 1),
492
--- src/merge.c
+++ src/merge.c
@@ -481,11 +481,11 @@
481 const char *zTagList = db_column_text(&q, 4);
482 char *zCom;
483 if( zTagList && zTagList[0] ){
484 zCom = mprintf("%s (%s)", db_column_text(&q, 2), zTagList);
485 }else{
486 zCom = fossil_strdup(db_column_text(&q,2));
487 }
488 fossil_print("%-*s [%S] by %s on %s\n%*s",
489 indent-1, zLabel,
490 db_column_text(&q, 3),
491 db_column_text(&q, 1),
492
+8 -5
--- src/name.c
+++ src/name.c
@@ -581,11 +581,11 @@
581581
nTag = strlen(zTag);
582582
for(i=0; i<nTag-8 && zTag[i]!=':'; i++){}
583583
if( zTag[i]==':'
584584
&& (fossil_isdate(&zTag[i+1]) || fossil_expand_datetime(&zTag[i+1],0,0)!=0)
585585
){
586
- char *zDate = mprintf("%s", &zTag[i+1]);
586
+ char *zDate = fossil_strdup(&zTag[i+1]);
587587
char *zTagBase = mprintf("%.*s", i, zTag);
588588
char *zXDate;
589589
int nDate = strlen(zDate);
590590
if( sqlite3_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
591591
zDate[nDate-3] = 'z';
@@ -986,11 +986,11 @@
986986
}
987987
style_header("Ambiguous Artifact ID");
988988
@ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might
989989
@ mean any of the following:
990990
@ <ol>
991
- z = mprintf("%s", zName);
991
+ z = fossil_strdup(zName);
992992
canonical16(z, strlen(z));
993993
db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
994994
while( db_step(&q)==SQLITE_ROW ){
995995
const char *zUuid = db_column_text(&q, 0);
996996
int rid = db_column_int(&q, 1);
@@ -1223,26 +1223,29 @@
12231223
db_finalize(&q);
12241224
12251225
/* Check to see if this object is used as a file in a check-in */
12261226
db_prepare(&q,
12271227
"SELECT filename.name, blob.uuid, datetime(event.mtime,toLocal()),"
1228
- " coalesce(euser,user), coalesce(ecomment,comment)"
1228
+ " coalesce(euser,user), coalesce(ecomment,comment),"
1229
+ " coalesce((SELECT value FROM tagxref"
1230
+ " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')"
12291231
" FROM mlink, filename, blob, event"
12301232
" WHERE mlink.fid=%d"
12311233
" AND filename.fnid=mlink.fnid"
12321234
" AND event.objid=mlink.mid"
12331235
" AND blob.rid=mlink.mid"
12341236
" ORDER BY event.mtime %s /*sort*/",
1235
- rid,
1237
+ TAG_BRANCH, rid,
12361238
(flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC");
12371239
while( db_step(&q)==SQLITE_ROW ){
12381240
if( flags & WHATIS_BRIEF ){
12391241
fossil_print("mtime: %s\n", db_column_text(&q,2));
12401242
}
12411243
fossil_print("file: %s\n", db_column_text(&q,0));
1242
- fossil_print(" part of [%S] by %s on %s\n",
1244
+ fossil_print(" part of [%S] on branch %s by %s on %s\n",
12431245
db_column_text(&q, 1),
1246
+ db_column_text(&q, 5),
12441247
db_column_text(&q, 3),
12451248
db_column_text(&q, 2));
12461249
fossil_print(" ");
12471250
comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format());
12481251
cnt++;
12491252
--- src/name.c
+++ src/name.c
@@ -581,11 +581,11 @@
581 nTag = strlen(zTag);
582 for(i=0; i<nTag-8 && zTag[i]!=':'; i++){}
583 if( zTag[i]==':'
584 && (fossil_isdate(&zTag[i+1]) || fossil_expand_datetime(&zTag[i+1],0,0)!=0)
585 ){
586 char *zDate = mprintf("%s", &zTag[i+1]);
587 char *zTagBase = mprintf("%.*s", i, zTag);
588 char *zXDate;
589 int nDate = strlen(zDate);
590 if( sqlite3_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
591 zDate[nDate-3] = 'z';
@@ -986,11 +986,11 @@
986 }
987 style_header("Ambiguous Artifact ID");
988 @ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might
989 @ mean any of the following:
990 @ <ol>
991 z = mprintf("%s", zName);
992 canonical16(z, strlen(z));
993 db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
994 while( db_step(&q)==SQLITE_ROW ){
995 const char *zUuid = db_column_text(&q, 0);
996 int rid = db_column_int(&q, 1);
@@ -1223,26 +1223,29 @@
1223 db_finalize(&q);
1224
1225 /* Check to see if this object is used as a file in a check-in */
1226 db_prepare(&q,
1227 "SELECT filename.name, blob.uuid, datetime(event.mtime,toLocal()),"
1228 " coalesce(euser,user), coalesce(ecomment,comment)"
 
 
1229 " FROM mlink, filename, blob, event"
1230 " WHERE mlink.fid=%d"
1231 " AND filename.fnid=mlink.fnid"
1232 " AND event.objid=mlink.mid"
1233 " AND blob.rid=mlink.mid"
1234 " ORDER BY event.mtime %s /*sort*/",
1235 rid,
1236 (flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC");
1237 while( db_step(&q)==SQLITE_ROW ){
1238 if( flags & WHATIS_BRIEF ){
1239 fossil_print("mtime: %s\n", db_column_text(&q,2));
1240 }
1241 fossil_print("file: %s\n", db_column_text(&q,0));
1242 fossil_print(" part of [%S] by %s on %s\n",
1243 db_column_text(&q, 1),
 
1244 db_column_text(&q, 3),
1245 db_column_text(&q, 2));
1246 fossil_print(" ");
1247 comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format());
1248 cnt++;
1249
--- src/name.c
+++ src/name.c
@@ -581,11 +581,11 @@
581 nTag = strlen(zTag);
582 for(i=0; i<nTag-8 && zTag[i]!=':'; i++){}
583 if( zTag[i]==':'
584 && (fossil_isdate(&zTag[i+1]) || fossil_expand_datetime(&zTag[i+1],0,0)!=0)
585 ){
586 char *zDate = fossil_strdup(&zTag[i+1]);
587 char *zTagBase = mprintf("%.*s", i, zTag);
588 char *zXDate;
589 int nDate = strlen(zDate);
590 if( sqlite3_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
591 zDate[nDate-3] = 'z';
@@ -986,11 +986,11 @@
986 }
987 style_header("Ambiguous Artifact ID");
988 @ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might
989 @ mean any of the following:
990 @ <ol>
991 z = fossil_strdup(zName);
992 canonical16(z, strlen(z));
993 db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
994 while( db_step(&q)==SQLITE_ROW ){
995 const char *zUuid = db_column_text(&q, 0);
996 int rid = db_column_int(&q, 1);
@@ -1223,26 +1223,29 @@
1223 db_finalize(&q);
1224
1225 /* Check to see if this object is used as a file in a check-in */
1226 db_prepare(&q,
1227 "SELECT filename.name, blob.uuid, datetime(event.mtime,toLocal()),"
1228 " coalesce(euser,user), coalesce(ecomment,comment),"
1229 " coalesce((SELECT value FROM tagxref"
1230 " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')"
1231 " FROM mlink, filename, blob, event"
1232 " WHERE mlink.fid=%d"
1233 " AND filename.fnid=mlink.fnid"
1234 " AND event.objid=mlink.mid"
1235 " AND blob.rid=mlink.mid"
1236 " ORDER BY event.mtime %s /*sort*/",
1237 TAG_BRANCH, rid,
1238 (flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC");
1239 while( db_step(&q)==SQLITE_ROW ){
1240 if( flags & WHATIS_BRIEF ){
1241 fossil_print("mtime: %s\n", db_column_text(&q,2));
1242 }
1243 fossil_print("file: %s\n", db_column_text(&q,0));
1244 fossil_print(" part of [%S] on branch %s by %s on %s\n",
1245 db_column_text(&q, 1),
1246 db_column_text(&q, 5),
1247 db_column_text(&q, 3),
1248 db_column_text(&q, 2));
1249 fossil_print(" ");
1250 comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format());
1251 cnt++;
1252
+12 -4
--- src/printf.c
+++ src/printf.c
@@ -774,10 +774,11 @@
774774
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */
775775
char *escarg = va_arg(ap,char*);
776776
isnull = escarg==0;
777777
if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
778778
if( limit<0 ) limit = strlen(escarg);
779
+ if( precision>=0 && precision<limit ) limit = precision;
779780
for(i=n=0; i<limit; i++){
780781
if( escarg[i]==q ) n++;
781782
}
782783
needQuote = !isnull && xtype==etSQLESCAPE2;
783784
n += i + 1 + needQuote*2;
@@ -793,11 +794,10 @@
793794
if( ch==q ) bufpt[j++] = ch;
794795
}
795796
if( needQuote ) bufpt[j++] = q;
796797
bufpt[j] = 0;
797798
length = j;
798
- if( precision>=0 && precision<length ) length = precision;
799799
break;
800800
}
801801
case etHTMLIZE: {
802802
int limit = flag_alternateform ? va_arg(ap,int) : -1;
803803
char *zMem = va_arg(ap,char*);
@@ -1158,15 +1158,23 @@
11581158
#endif
11591159
if( g.cgiOutput==1 && g.db ){
11601160
g.cgiOutput = 2;
11611161
cgi_reset_content();
11621162
cgi_set_content_type("text/html");
1163
- style_set_current_feature("error");
1163
+ if( g.zLogin!=0 ){
1164
+ style_set_current_feature("error");
1165
+ }
11641166
style_header("Bad Request");
11651167
etag_cancel();
1166
- @ <p class="generalError">%h(z)</p>
1167
- cgi_set_status(400, "Bad Request");
1168
+ if( g.zLogin==0 ){
1169
+ /* Do not give unnecessary clues about a malfunction to robots */
1170
+ @ <p>Something did not work right.</p>
1171
+ @ <p>%h(z)</p>
1172
+ }else{
1173
+ @ <p class="generalError">%h(z)</p>
1174
+ cgi_set_status(400, "Bad Request");
1175
+ }
11681176
style_finish_page();
11691177
cgi_reply();
11701178
}else if( !g.fQuiet ){
11711179
fossil_force_newline();
11721180
fossil_trace("%s\n", z);
11731181
--- src/printf.c
+++ src/printf.c
@@ -774,10 +774,11 @@
774 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */
775 char *escarg = va_arg(ap,char*);
776 isnull = escarg==0;
777 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
778 if( limit<0 ) limit = strlen(escarg);
 
779 for(i=n=0; i<limit; i++){
780 if( escarg[i]==q ) n++;
781 }
782 needQuote = !isnull && xtype==etSQLESCAPE2;
783 n += i + 1 + needQuote*2;
@@ -793,11 +794,10 @@
793 if( ch==q ) bufpt[j++] = ch;
794 }
795 if( needQuote ) bufpt[j++] = q;
796 bufpt[j] = 0;
797 length = j;
798 if( precision>=0 && precision<length ) length = precision;
799 break;
800 }
801 case etHTMLIZE: {
802 int limit = flag_alternateform ? va_arg(ap,int) : -1;
803 char *zMem = va_arg(ap,char*);
@@ -1158,15 +1158,23 @@
1158 #endif
1159 if( g.cgiOutput==1 && g.db ){
1160 g.cgiOutput = 2;
1161 cgi_reset_content();
1162 cgi_set_content_type("text/html");
1163 style_set_current_feature("error");
 
 
1164 style_header("Bad Request");
1165 etag_cancel();
1166 @ <p class="generalError">%h(z)</p>
1167 cgi_set_status(400, "Bad Request");
 
 
 
 
 
 
1168 style_finish_page();
1169 cgi_reply();
1170 }else if( !g.fQuiet ){
1171 fossil_force_newline();
1172 fossil_trace("%s\n", z);
1173
--- src/printf.c
+++ src/printf.c
@@ -774,10 +774,11 @@
774 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote characters */
775 char *escarg = va_arg(ap,char*);
776 isnull = escarg==0;
777 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
778 if( limit<0 ) limit = strlen(escarg);
779 if( precision>=0 && precision<limit ) limit = precision;
780 for(i=n=0; i<limit; i++){
781 if( escarg[i]==q ) n++;
782 }
783 needQuote = !isnull && xtype==etSQLESCAPE2;
784 n += i + 1 + needQuote*2;
@@ -793,11 +794,10 @@
794 if( ch==q ) bufpt[j++] = ch;
795 }
796 if( needQuote ) bufpt[j++] = q;
797 bufpt[j] = 0;
798 length = j;
 
799 break;
800 }
801 case etHTMLIZE: {
802 int limit = flag_alternateform ? va_arg(ap,int) : -1;
803 char *zMem = va_arg(ap,char*);
@@ -1158,15 +1158,23 @@
1158 #endif
1159 if( g.cgiOutput==1 && g.db ){
1160 g.cgiOutput = 2;
1161 cgi_reset_content();
1162 cgi_set_content_type("text/html");
1163 if( g.zLogin!=0 ){
1164 style_set_current_feature("error");
1165 }
1166 style_header("Bad Request");
1167 etag_cancel();
1168 if( g.zLogin==0 ){
1169 /* Do not give unnecessary clues about a malfunction to robots */
1170 @ <p>Something did not work right.</p>
1171 @ <p>%h(z)</p>
1172 }else{
1173 @ <p class="generalError">%h(z)</p>
1174 cgi_set_status(400, "Bad Request");
1175 }
1176 style_finish_page();
1177 cgi_reply();
1178 }else if( !g.fQuiet ){
1179 fossil_force_newline();
1180 fossil_trace("%s\n", z);
1181
+7 -4
--- src/repolist.c
+++ src/repolist.c
@@ -157,17 +157,20 @@
157157
allRepo = 1;
158158
}else{
159159
/* The default case: All repositories under the g.zRepositoryName
160160
** directory.
161161
*/
162
+ Glob *pExclude;
162163
blob_init(&base, g.zRepositoryName, -1);
163164
db_close(0);
164165
assert( g.db==0 );
165166
sqlite3_open(":memory:", &g.db);
166167
db_multi_exec("CREATE TABLE sfile(pathname TEXT);");
167168
db_multi_exec("CREATE TABLE vfile(pathname);");
168
- vfile_scan(&base, blob_size(&base), 0, 0, 0, ExtFILE);
169
+ pExclude = glob_create("*/proc,proc");
170
+ vfile_scan(&base, blob_size(&base), 0, pExclude, 0, ExtFILE);
171
+ glob_free(pExclude);
169172
db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'"
170173
#if USE_SEE
171174
" AND pathname NOT GLOB '*[^/].efossil'"
172175
#endif
173176
);
@@ -244,22 +247,22 @@
244247
if( zName[0]=='/'
245248
#ifdef _WIN32
246249
|| sqlite3_strglob("[a-zA-Z]:/*", zName)==0
247250
#endif
248251
){
249
- zFull = mprintf("%s", zName);
252
+ zFull = fossil_strdup(zName);
250253
}else if ( allRepo ){
251254
zFull = mprintf("/%s", zName);
252255
}else{
253256
zFull = mprintf("%s/%s", g.zRepositoryName, zName);
254257
}
255258
x.zRepoName = zFull;
256259
remote_repo_info(&x);
257260
if( x.isRepolistSkin ){
258261
if( zSkinRepo==0 ){
259
- zSkinRepo = mprintf("%s", x.zRepoName);
260
- zSkinUrl = mprintf("%s", zUrl);
262
+ zSkinRepo = fossil_strdup(x.zRepoName);
263
+ zSkinUrl = fossil_strdup(zUrl);
261264
}
262265
}
263266
fossil_free(zFull);
264267
if( !x.isValid
265268
#if USE_SEE
266269
--- src/repolist.c
+++ src/repolist.c
@@ -157,17 +157,20 @@
157 allRepo = 1;
158 }else{
159 /* The default case: All repositories under the g.zRepositoryName
160 ** directory.
161 */
 
162 blob_init(&base, g.zRepositoryName, -1);
163 db_close(0);
164 assert( g.db==0 );
165 sqlite3_open(":memory:", &g.db);
166 db_multi_exec("CREATE TABLE sfile(pathname TEXT);");
167 db_multi_exec("CREATE TABLE vfile(pathname);");
168 vfile_scan(&base, blob_size(&base), 0, 0, 0, ExtFILE);
 
 
169 db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'"
170 #if USE_SEE
171 " AND pathname NOT GLOB '*[^/].efossil'"
172 #endif
173 );
@@ -244,22 +247,22 @@
244 if( zName[0]=='/'
245 #ifdef _WIN32
246 || sqlite3_strglob("[a-zA-Z]:/*", zName)==0
247 #endif
248 ){
249 zFull = mprintf("%s", zName);
250 }else if ( allRepo ){
251 zFull = mprintf("/%s", zName);
252 }else{
253 zFull = mprintf("%s/%s", g.zRepositoryName, zName);
254 }
255 x.zRepoName = zFull;
256 remote_repo_info(&x);
257 if( x.isRepolistSkin ){
258 if( zSkinRepo==0 ){
259 zSkinRepo = mprintf("%s", x.zRepoName);
260 zSkinUrl = mprintf("%s", zUrl);
261 }
262 }
263 fossil_free(zFull);
264 if( !x.isValid
265 #if USE_SEE
266
--- src/repolist.c
+++ src/repolist.c
@@ -157,17 +157,20 @@
157 allRepo = 1;
158 }else{
159 /* The default case: All repositories under the g.zRepositoryName
160 ** directory.
161 */
162 Glob *pExclude;
163 blob_init(&base, g.zRepositoryName, -1);
164 db_close(0);
165 assert( g.db==0 );
166 sqlite3_open(":memory:", &g.db);
167 db_multi_exec("CREATE TABLE sfile(pathname TEXT);");
168 db_multi_exec("CREATE TABLE vfile(pathname);");
169 pExclude = glob_create("*/proc,proc");
170 vfile_scan(&base, blob_size(&base), 0, pExclude, 0, ExtFILE);
171 glob_free(pExclude);
172 db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'"
173 #if USE_SEE
174 " AND pathname NOT GLOB '*[^/].efossil'"
175 #endif
176 );
@@ -244,22 +247,22 @@
247 if( zName[0]=='/'
248 #ifdef _WIN32
249 || sqlite3_strglob("[a-zA-Z]:/*", zName)==0
250 #endif
251 ){
252 zFull = fossil_strdup(zName);
253 }else if ( allRepo ){
254 zFull = mprintf("/%s", zName);
255 }else{
256 zFull = mprintf("%s/%s", g.zRepositoryName, zName);
257 }
258 x.zRepoName = zFull;
259 remote_repo_info(&x);
260 if( x.isRepolistSkin ){
261 if( zSkinRepo==0 ){
262 zSkinRepo = fossil_strdup(x.zRepoName);
263 zSkinUrl = fossil_strdup(zUrl);
264 }
265 }
266 fossil_free(zFull);
267 if( !x.isValid
268 #if USE_SEE
269
+5 -5
--- src/search.c
+++ src/search.c
@@ -130,14 +130,14 @@
130130
search_end(p);
131131
}else{
132132
p = fossil_malloc(sizeof(*p));
133133
memset(p, 0, sizeof(*p));
134134
}
135
- p->zPattern = z = mprintf("%s", zPattern);
136
- p->zMarkBegin = mprintf("%s", zMarkBegin);
137
- p->zMarkEnd = mprintf("%s", zMarkEnd);
138
- p->zMarkGap = mprintf("%s", zMarkGap);
135
+ p->zPattern = z = fossil_strdup(zPattern);
136
+ p->zMarkBegin = fossil_strdup(zMarkBegin);
137
+ p->zMarkEnd = fossil_strdup(zMarkEnd);
138
+ p->zMarkGap = fossil_strdup(zMarkGap);
139139
p->fSrchFlg = fSrchFlg;
140140
blob_init(&p->snip, 0, 0);
141141
while( *z && p->nTerm<SEARCH_MAX_TERM ){
142142
while( *z && !ISALNUM(*z) ){ z++; }
143143
if( *z==0 ) break;
@@ -1076,11 +1076,11 @@
10761076
** causing errors in FTS5 searches with inputs which contain AND, OR,
10771077
** and symbols like #. The caller is responsible for passing the
10781078
** result to fossil_free().
10791079
*/
10801080
char *search_simplify_pattern(const char * zPattern){
1081
- char *zPat = mprintf("%s",zPattern);
1081
+ char *zPat = fossil_strdup(zPattern);
10821082
int i;
10831083
for(i=0; zPat[i]; i++){
10841084
if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
10851085
if( fossil_isupper(zPat[i]) ) zPat[i] = fossil_tolower(zPat[i]);
10861086
}
10871087
--- src/search.c
+++ src/search.c
@@ -130,14 +130,14 @@
130 search_end(p);
131 }else{
132 p = fossil_malloc(sizeof(*p));
133 memset(p, 0, sizeof(*p));
134 }
135 p->zPattern = z = mprintf("%s", zPattern);
136 p->zMarkBegin = mprintf("%s", zMarkBegin);
137 p->zMarkEnd = mprintf("%s", zMarkEnd);
138 p->zMarkGap = mprintf("%s", zMarkGap);
139 p->fSrchFlg = fSrchFlg;
140 blob_init(&p->snip, 0, 0);
141 while( *z && p->nTerm<SEARCH_MAX_TERM ){
142 while( *z && !ISALNUM(*z) ){ z++; }
143 if( *z==0 ) break;
@@ -1076,11 +1076,11 @@
1076 ** causing errors in FTS5 searches with inputs which contain AND, OR,
1077 ** and symbols like #. The caller is responsible for passing the
1078 ** result to fossil_free().
1079 */
1080 char *search_simplify_pattern(const char * zPattern){
1081 char *zPat = mprintf("%s",zPattern);
1082 int i;
1083 for(i=0; zPat[i]; i++){
1084 if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
1085 if( fossil_isupper(zPat[i]) ) zPat[i] = fossil_tolower(zPat[i]);
1086 }
1087
--- src/search.c
+++ src/search.c
@@ -130,14 +130,14 @@
130 search_end(p);
131 }else{
132 p = fossil_malloc(sizeof(*p));
133 memset(p, 0, sizeof(*p));
134 }
135 p->zPattern = z = fossil_strdup(zPattern);
136 p->zMarkBegin = fossil_strdup(zMarkBegin);
137 p->zMarkEnd = fossil_strdup(zMarkEnd);
138 p->zMarkGap = fossil_strdup(zMarkGap);
139 p->fSrchFlg = fSrchFlg;
140 blob_init(&p->snip, 0, 0);
141 while( *z && p->nTerm<SEARCH_MAX_TERM ){
142 while( *z && !ISALNUM(*z) ){ z++; }
143 if( *z==0 ) break;
@@ -1076,11 +1076,11 @@
1076 ** causing errors in FTS5 searches with inputs which contain AND, OR,
1077 ** and symbols like #. The caller is responsible for passing the
1078 ** result to fossil_free().
1079 */
1080 char *search_simplify_pattern(const char * zPattern){
1081 char *zPat = fossil_strdup(zPattern);
1082 int i;
1083 for(i=0; zPat[i]; i++){
1084 if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
1085 if( fossil_isupper(zPat[i]) ) zPat[i] = fossil_tolower(zPat[i]);
1086 }
1087
--- src/security_audit.c
+++ src/security_audit.c
@@ -830,10 +830,11 @@
830830
** y=0x004 Show hung backoffice processes
831831
** y=0x008 Show POST requests from a different origin
832832
** y=0x010 Show SQLITE_AUTH and similar
833833
** y=0x020 Show SMTP error reports
834834
** y=0x040 Show TH1 vulnerability reports
835
+** y=0x080 Show SQL errors
835836
** y=0x800 Show other uncategorized messages
836837
**
837838
** If y is omitted or is zero, a count of the various message types is
838839
** shown.
839840
*/
@@ -840,11 +841,11 @@
840841
void errorlog_page(void){
841842
i64 szFile;
842843
FILE *in;
843844
char *zLog;
844845
const char *zType = P("y");
845
- static const int eAllTypes = 0x87f;
846
+ static const int eAllTypes = 0x8ff;
846847
long eType = 0;
847848
int bOutput = 0;
848849
int prevWasTime = 0;
849850
int nHack = 0;
850851
int nPanic = 0;
@@ -852,10 +853,11 @@
852853
int nHang = 0;
853854
int nXPost = 0;
854855
int nAuth = 0;
855856
int nSmtp = 0;
856857
int nVuln = 0;
858
+ int nSqlErr = 0;
857859
char z[10000];
858860
char zTime[10000];
859861
860862
login_check_credentials();
861863
if( !g.perm.Admin ){
@@ -933,10 +935,13 @@
933935
if( eType & 0x20 ){
934936
@ <li>SMTP malfunctions
935937
}
936938
if( eType & 0x40 ){
937939
@ <li>TH1 vulnerabilities
940
+ }
941
+ if( eType & 0x80 ){
942
+ @ <li>SQL errors
938943
}
939944
if( eType & 0x800 ){
940945
@ <li>Other uncategorized messages
941946
}
942947
@ </ul>
@@ -975,10 +980,14 @@
975980
}else
976981
if( strncmp(z,"possible", 8)==0 && strstr(z,"tainted")!=0 ){
977982
bOutput = (eType & 0x40)!=0;
978983
nVuln++;
979984
}else
985
+ if( strstr(z,"statement aborts at ") ){
986
+ bOutput = (eType & 0x80)!=0;
987
+ nSqlErr++;
988
+ }else
980989
{
981990
bOutput = (eType & 0x800)!=0;
982991
nOther++;
983992
}
984993
if( bOutput ){
@@ -1000,11 +1009,11 @@
10001009
fclose(in);
10011010
if( eType ){
10021011
@ </pre>
10031012
}
10041013
if( eType==0 ){
1005
- int nNonHack = nPanic + nHang + nAuth + nSmtp + nVuln + nOther;
1014
+ int nNonHack = nPanic + nHang + nAuth + nSmtp + nVuln + nOther + nSqlErr;
10061015
int nTotal = nNonHack + nHack + nXPost;
10071016
@ <p><table border="a" cellspacing="0" cellpadding="5">
10081017
if( nPanic>0 ){
10091018
@ <tr><td align="right">%d(nPanic)</td>
10101019
@ <td><a href="./errorlog?y=2">Panics</a></td>
@@ -1015,10 +1024,14 @@
10151024
}
10161025
if( nHack>0 ){
10171026
@ <tr><td align="right">%d(nHack)</td>
10181027
@ <td><a href="./errorlog?y=1">Hack Attempts</a></td>
10191028
}
1029
+ if( nSqlErr>0 ){
1030
+ @ <tr><td align="right">%d(nSqlErr)</td>
1031
+ @ <td><a href="./errorlog?y=128">SQL Errors</a></td>
1032
+ }
10201033
if( nHang>0 ){
10211034
@ <tr><td align="right">%d(nHang)</td>
10221035
@ <td><a href="./errorlog?y=4">Hung Backoffice</a></td>
10231036
}
10241037
if( nXPost>0 ){
10251038
--- src/security_audit.c
+++ src/security_audit.c
@@ -830,10 +830,11 @@
830 ** y=0x004 Show hung backoffice processes
831 ** y=0x008 Show POST requests from a different origin
832 ** y=0x010 Show SQLITE_AUTH and similar
833 ** y=0x020 Show SMTP error reports
834 ** y=0x040 Show TH1 vulnerability reports
 
835 ** y=0x800 Show other uncategorized messages
836 **
837 ** If y is omitted or is zero, a count of the various message types is
838 ** shown.
839 */
@@ -840,11 +841,11 @@
840 void errorlog_page(void){
841 i64 szFile;
842 FILE *in;
843 char *zLog;
844 const char *zType = P("y");
845 static const int eAllTypes = 0x87f;
846 long eType = 0;
847 int bOutput = 0;
848 int prevWasTime = 0;
849 int nHack = 0;
850 int nPanic = 0;
@@ -852,10 +853,11 @@
852 int nHang = 0;
853 int nXPost = 0;
854 int nAuth = 0;
855 int nSmtp = 0;
856 int nVuln = 0;
 
857 char z[10000];
858 char zTime[10000];
859
860 login_check_credentials();
861 if( !g.perm.Admin ){
@@ -933,10 +935,13 @@
933 if( eType & 0x20 ){
934 @ <li>SMTP malfunctions
935 }
936 if( eType & 0x40 ){
937 @ <li>TH1 vulnerabilities
 
 
 
938 }
939 if( eType & 0x800 ){
940 @ <li>Other uncategorized messages
941 }
942 @ </ul>
@@ -975,10 +980,14 @@
975 }else
976 if( strncmp(z,"possible", 8)==0 && strstr(z,"tainted")!=0 ){
977 bOutput = (eType & 0x40)!=0;
978 nVuln++;
979 }else
 
 
 
 
980 {
981 bOutput = (eType & 0x800)!=0;
982 nOther++;
983 }
984 if( bOutput ){
@@ -1000,11 +1009,11 @@
1000 fclose(in);
1001 if( eType ){
1002 @ </pre>
1003 }
1004 if( eType==0 ){
1005 int nNonHack = nPanic + nHang + nAuth + nSmtp + nVuln + nOther;
1006 int nTotal = nNonHack + nHack + nXPost;
1007 @ <p><table border="a" cellspacing="0" cellpadding="5">
1008 if( nPanic>0 ){
1009 @ <tr><td align="right">%d(nPanic)</td>
1010 @ <td><a href="./errorlog?y=2">Panics</a></td>
@@ -1015,10 +1024,14 @@
1015 }
1016 if( nHack>0 ){
1017 @ <tr><td align="right">%d(nHack)</td>
1018 @ <td><a href="./errorlog?y=1">Hack Attempts</a></td>
1019 }
 
 
 
 
1020 if( nHang>0 ){
1021 @ <tr><td align="right">%d(nHang)</td>
1022 @ <td><a href="./errorlog?y=4">Hung Backoffice</a></td>
1023 }
1024 if( nXPost>0 ){
1025
--- src/security_audit.c
+++ src/security_audit.c
@@ -830,10 +830,11 @@
830 ** y=0x004 Show hung backoffice processes
831 ** y=0x008 Show POST requests from a different origin
832 ** y=0x010 Show SQLITE_AUTH and similar
833 ** y=0x020 Show SMTP error reports
834 ** y=0x040 Show TH1 vulnerability reports
835 ** y=0x080 Show SQL errors
836 ** y=0x800 Show other uncategorized messages
837 **
838 ** If y is omitted or is zero, a count of the various message types is
839 ** shown.
840 */
@@ -840,11 +841,11 @@
841 void errorlog_page(void){
842 i64 szFile;
843 FILE *in;
844 char *zLog;
845 const char *zType = P("y");
846 static const int eAllTypes = 0x8ff;
847 long eType = 0;
848 int bOutput = 0;
849 int prevWasTime = 0;
850 int nHack = 0;
851 int nPanic = 0;
@@ -852,10 +853,11 @@
853 int nHang = 0;
854 int nXPost = 0;
855 int nAuth = 0;
856 int nSmtp = 0;
857 int nVuln = 0;
858 int nSqlErr = 0;
859 char z[10000];
860 char zTime[10000];
861
862 login_check_credentials();
863 if( !g.perm.Admin ){
@@ -933,10 +935,13 @@
935 if( eType & 0x20 ){
936 @ <li>SMTP malfunctions
937 }
938 if( eType & 0x40 ){
939 @ <li>TH1 vulnerabilities
940 }
941 if( eType & 0x80 ){
942 @ <li>SQL errors
943 }
944 if( eType & 0x800 ){
945 @ <li>Other uncategorized messages
946 }
947 @ </ul>
@@ -975,10 +980,14 @@
980 }else
981 if( strncmp(z,"possible", 8)==0 && strstr(z,"tainted")!=0 ){
982 bOutput = (eType & 0x40)!=0;
983 nVuln++;
984 }else
985 if( strstr(z,"statement aborts at ") ){
986 bOutput = (eType & 0x80)!=0;
987 nSqlErr++;
988 }else
989 {
990 bOutput = (eType & 0x800)!=0;
991 nOther++;
992 }
993 if( bOutput ){
@@ -1000,11 +1009,11 @@
1009 fclose(in);
1010 if( eType ){
1011 @ </pre>
1012 }
1013 if( eType==0 ){
1014 int nNonHack = nPanic + nHang + nAuth + nSmtp + nVuln + nOther + nSqlErr;
1015 int nTotal = nNonHack + nHack + nXPost;
1016 @ <p><table border="a" cellspacing="0" cellpadding="5">
1017 if( nPanic>0 ){
1018 @ <tr><td align="right">%d(nPanic)</td>
1019 @ <td><a href="./errorlog?y=2">Panics</a></td>
@@ -1015,10 +1024,14 @@
1024 }
1025 if( nHack>0 ){
1026 @ <tr><td align="right">%d(nHack)</td>
1027 @ <td><a href="./errorlog?y=1">Hack Attempts</a></td>
1028 }
1029 if( nSqlErr>0 ){
1030 @ <tr><td align="right">%d(nSqlErr)</td>
1031 @ <td><a href="./errorlog?y=128">SQL Errors</a></td>
1032 }
1033 if( nHang>0 ){
1034 @ <tr><td align="right">%d(nHang)</td>
1035 @ <td><a href="./errorlog?y=4">Hung Backoffice</a></td>
1036 }
1037 if( nXPost>0 ){
1038
+1 -1
--- src/setupuser.c
+++ src/setupuser.c
@@ -408,11 +408,11 @@
408408
blob_appendf(&body, "Permissions for user [%q] where changed "
409409
"from [%q] to [%q] by user [%q].\n",
410410
zLogin, zOrigCaps, zNewCaps, g.zLogin);
411411
}
412412
if( zURL ){
413
- blob_appendf(&body, "\nUser editor: %s/setup_uedit?uid=%d\n", zURL, uid);
413
+ blob_appendf(&body, "\nUser editor: %s/setup_uedit?id=%d\n", zURL, uid);
414414
}
415415
nBody = blob_size(&body);
416416
pSender = alert_sender_new(0, 0);
417417
db_prepare(&q,
418418
"SELECT semail, hex(subscriberCode)"
419419
--- src/setupuser.c
+++ src/setupuser.c
@@ -408,11 +408,11 @@
408 blob_appendf(&body, "Permissions for user [%q] where changed "
409 "from [%q] to [%q] by user [%q].\n",
410 zLogin, zOrigCaps, zNewCaps, g.zLogin);
411 }
412 if( zURL ){
413 blob_appendf(&body, "\nUser editor: %s/setup_uedit?uid=%d\n", zURL, uid);
414 }
415 nBody = blob_size(&body);
416 pSender = alert_sender_new(0, 0);
417 db_prepare(&q,
418 "SELECT semail, hex(subscriberCode)"
419
--- src/setupuser.c
+++ src/setupuser.c
@@ -408,11 +408,11 @@
408 blob_appendf(&body, "Permissions for user [%q] where changed "
409 "from [%q] to [%q] by user [%q].\n",
410 zLogin, zOrigCaps, zNewCaps, g.zLogin);
411 }
412 if( zURL ){
413 blob_appendf(&body, "\nUser editor: %s/setup_uedit?id=%d\n", zURL, uid);
414 }
415 nBody = blob_size(&body);
416 pSender = alert_sender_new(0, 0);
417 db_prepare(&q,
418 "SELECT semail, hex(subscriberCode)"
419
+3 -3
--- src/sha1.c
+++ src/sha1.c
@@ -420,11 +420,11 @@
420420
421421
SHA1Init(&ctx);
422422
SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
423423
SHA1Final(zResult, &ctx);
424424
DigestToBase16(zResult, zDigest);
425
- return mprintf("%s", zDigest);
425
+ return fossil_strdup(zDigest);
426426
}
427427
428428
/*
429429
** Convert a cleartext password for a specific user into a SHA1 hash.
430430
**
@@ -459,11 +459,11 @@
459459
460460
/* On the first xfer request of a clone, the project-code is not yet
461461
** known. Use the cleartext password, since that is all we have.
462462
*/
463463
if( zProjectId==0 ){
464
- return mprintf("%s", zPw);
464
+ return fossil_strdup(zPw);
465465
}
466466
}
467467
zProjCode = zProjectId;
468468
}
469469
SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
@@ -471,11 +471,11 @@
471471
SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
472472
SHA1Update(&ctx, (unsigned char*)"/", 1);
473473
SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
474474
SHA1Final(zResult, &ctx);
475475
DigestToBase16(zResult, zDigest);
476
- return mprintf("%s", zDigest);
476
+ return fossil_strdup(zDigest);
477477
}
478478
479479
/*
480480
** Implement the shared_secret() SQL function. shared_secret() takes two or
481481
** three arguments; the third argument is optional.
482482
--- src/sha1.c
+++ src/sha1.c
@@ -420,11 +420,11 @@
420
421 SHA1Init(&ctx);
422 SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
423 SHA1Final(zResult, &ctx);
424 DigestToBase16(zResult, zDigest);
425 return mprintf("%s", zDigest);
426 }
427
428 /*
429 ** Convert a cleartext password for a specific user into a SHA1 hash.
430 **
@@ -459,11 +459,11 @@
459
460 /* On the first xfer request of a clone, the project-code is not yet
461 ** known. Use the cleartext password, since that is all we have.
462 */
463 if( zProjectId==0 ){
464 return mprintf("%s", zPw);
465 }
466 }
467 zProjCode = zProjectId;
468 }
469 SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
@@ -471,11 +471,11 @@
471 SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
472 SHA1Update(&ctx, (unsigned char*)"/", 1);
473 SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
474 SHA1Final(zResult, &ctx);
475 DigestToBase16(zResult, zDigest);
476 return mprintf("%s", zDigest);
477 }
478
479 /*
480 ** Implement the shared_secret() SQL function. shared_secret() takes two or
481 ** three arguments; the third argument is optional.
482
--- src/sha1.c
+++ src/sha1.c
@@ -420,11 +420,11 @@
420
421 SHA1Init(&ctx);
422 SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
423 SHA1Final(zResult, &ctx);
424 DigestToBase16(zResult, zDigest);
425 return fossil_strdup(zDigest);
426 }
427
428 /*
429 ** Convert a cleartext password for a specific user into a SHA1 hash.
430 **
@@ -459,11 +459,11 @@
459
460 /* On the first xfer request of a clone, the project-code is not yet
461 ** known. Use the cleartext password, since that is all we have.
462 */
463 if( zProjectId==0 ){
464 return fossil_strdup(zPw);
465 }
466 }
467 zProjCode = zProjectId;
468 }
469 SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
@@ -471,11 +471,11 @@
471 SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
472 SHA1Update(&ctx, (unsigned char*)"/", 1);
473 SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
474 SHA1Final(zResult, &ctx);
475 DigestToBase16(zResult, zDigest);
476 return fossil_strdup(zDigest);
477 }
478
479 /*
480 ** Implement the shared_secret() SQL function. shared_secret() takes two or
481 ** three arguments; the third argument is optional.
482
+1 -1
--- src/sha3.c
+++ src/sha3.c
@@ -612,11 +612,11 @@
612612
char zDigest[132];
613613
614614
SHA3Init(&ctx, iSize);
615615
SHA3Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
616616
DigestToBase16(SHA3Final(&ctx), zDigest, iSize/8);
617
- return mprintf("%s", zDigest);
617
+ return fossil_strdup(zDigest);
618618
}
619619
#endif
620620
621621
/*
622622
** COMMAND: sha3sum*
623623
--- src/sha3.c
+++ src/sha3.c
@@ -612,11 +612,11 @@
612 char zDigest[132];
613
614 SHA3Init(&ctx, iSize);
615 SHA3Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
616 DigestToBase16(SHA3Final(&ctx), zDigest, iSize/8);
617 return mprintf("%s", zDigest);
618 }
619 #endif
620
621 /*
622 ** COMMAND: sha3sum*
623
--- src/sha3.c
+++ src/sha3.c
@@ -612,11 +612,11 @@
612 char zDigest[132];
613
614 SHA3Init(&ctx, iSize);
615 SHA3Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
616 DigestToBase16(SHA3Final(&ctx), zDigest, iSize/8);
617 return fossil_strdup(zDigest);
618 }
619 #endif
620
621 /*
622 ** COMMAND: sha3sum*
623
+5 -3
--- src/stat.c
+++ src/stat.c
@@ -268,16 +268,18 @@
268268
}
269269
@ <tr><th>Project&nbsp;Age:</th><td>
270270
z = db_text(0, "SELECT timediff('now',(SELECT min(mtime) FROM event));");
271271
sscanf(z, "+%d-%d-%d", &Y, &M, &D);
272272
if( Y>0 ){
273
- @ %d(Y) years, \
273
+ @ %d(Y) year%s(Y==1?"":"s") \
274274
}
275275
if( M>0 ){
276
- @ %d(M) months, \
276
+ @ %d(M) month%s(M==1?"":"s") \
277277
}
278
- @ %d(D) days
278
+ if( D>0 || (Y==0 && M==0) ){
279
+ @ %d(D) day%s(D==1?"":"s")
280
+ }
279281
@ </td></tr>
280282
p = db_get("project-code", 0);
281283
if( p ){
282284
@ <tr><th>Project&nbsp;ID:</th>
283285
@ <td>%h(p) %h(db_get("project-name",""))</td></tr>
284286
--- src/stat.c
+++ src/stat.c
@@ -268,16 +268,18 @@
268 }
269 @ <tr><th>Project&nbsp;Age:</th><td>
270 z = db_text(0, "SELECT timediff('now',(SELECT min(mtime) FROM event));");
271 sscanf(z, "+%d-%d-%d", &Y, &M, &D);
272 if( Y>0 ){
273 @ %d(Y) years, \
274 }
275 if( M>0 ){
276 @ %d(M) months, \
277 }
278 @ %d(D) days
 
 
279 @ </td></tr>
280 p = db_get("project-code", 0);
281 if( p ){
282 @ <tr><th>Project&nbsp;ID:</th>
283 @ <td>%h(p) %h(db_get("project-name",""))</td></tr>
284
--- src/stat.c
+++ src/stat.c
@@ -268,16 +268,18 @@
268 }
269 @ <tr><th>Project&nbsp;Age:</th><td>
270 z = db_text(0, "SELECT timediff('now',(SELECT min(mtime) FROM event));");
271 sscanf(z, "+%d-%d-%d", &Y, &M, &D);
272 if( Y>0 ){
273 @ %d(Y) year%s(Y==1?"":"s") \
274 }
275 if( M>0 ){
276 @ %d(M) month%s(M==1?"":"s") \
277 }
278 if( D>0 || (Y==0 && M==0) ){
279 @ %d(D) day%s(D==1?"":"s")
280 }
281 @ </td></tr>
282 p = db_get("project-code", 0);
283 if( p ){
284 @ <tr><th>Project&nbsp;ID:</th>
285 @ <td>%h(p) %h(db_get("project-name",""))</td></tr>
286
+2 -2
--- src/tag.c
+++ src/tag.c
@@ -219,11 +219,11 @@
219219
}
220220
if( zCol ){
221221
db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222222
zCol, zValue, rid);
223223
if( tagid==TAG_COMMENT ){
224
- char *zCopy = mprintf("%s", zValue);
224
+ char *zCopy = fossil_strdup(zValue);
225225
backlink_extract(zCopy, MT_NONE, rid, BKLNK_COMMENT, mtime, 1);
226226
free(zCopy);
227227
}
228228
}
229229
if( tagid==TAG_DATE ){
@@ -412,11 +412,11 @@
412412
** non-CHECK-IN artifacts.
413413
** --user-override USER Name USER when adding the tag
414414
**
415415
** The --date-override and --user-override options support
416416
** importing history from other SCM systems. DATETIME has
417
-** the form 'YYYY-MMM-DD HH:MM:SS'.
417
+** the form 'YYYY-MM-DD HH:MM:SS'.
418418
**
419419
** Note that fossil uses some tag prefixes internally and this
420420
** command will reject tags with these prefixes to avoid
421421
** causing problems or confusion: "wiki-", "tkt-", "event-".
422422
**
423423
--- src/tag.c
+++ src/tag.c
@@ -219,11 +219,11 @@
219 }
220 if( zCol ){
221 db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222 zCol, zValue, rid);
223 if( tagid==TAG_COMMENT ){
224 char *zCopy = mprintf("%s", zValue);
225 backlink_extract(zCopy, MT_NONE, rid, BKLNK_COMMENT, mtime, 1);
226 free(zCopy);
227 }
228 }
229 if( tagid==TAG_DATE ){
@@ -412,11 +412,11 @@
412 ** non-CHECK-IN artifacts.
413 ** --user-override USER Name USER when adding the tag
414 **
415 ** The --date-override and --user-override options support
416 ** importing history from other SCM systems. DATETIME has
417 ** the form 'YYYY-MMM-DD HH:MM:SS'.
418 **
419 ** Note that fossil uses some tag prefixes internally and this
420 ** command will reject tags with these prefixes to avoid
421 ** causing problems or confusion: "wiki-", "tkt-", "event-".
422 **
423
--- src/tag.c
+++ src/tag.c
@@ -219,11 +219,11 @@
219 }
220 if( zCol ){
221 db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222 zCol, zValue, rid);
223 if( tagid==TAG_COMMENT ){
224 char *zCopy = fossil_strdup(zValue);
225 backlink_extract(zCopy, MT_NONE, rid, BKLNK_COMMENT, mtime, 1);
226 free(zCopy);
227 }
228 }
229 if( tagid==TAG_DATE ){
@@ -412,11 +412,11 @@
412 ** non-CHECK-IN artifacts.
413 ** --user-override USER Name USER when adding the tag
414 **
415 ** The --date-override and --user-override options support
416 ** importing history from other SCM systems. DATETIME has
417 ** the form 'YYYY-MM-DD HH:MM:SS'.
418 **
419 ** Note that fossil uses some tag prefixes internally and this
420 ** command will reject tags with these prefixes to avoid
421 ** causing problems or confusion: "wiki-", "tkt-", "event-".
422 **
423
+1 -1
--- src/th_main.c
+++ src/th_main.c
@@ -1432,11 +1432,11 @@
14321432
int *argl
14331433
){
14341434
if( argc!=3 ){
14351435
return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
14361436
}
1437
- cgi_replace_parameter(mprintf("%s", argv[1]), mprintf("%s", argv[2]));
1437
+ cgi_replace_parameter(fossil_strdup(argv[1]), fossil_strdup(argv[2]));
14381438
return TH_OK;
14391439
}
14401440
14411441
/*
14421442
** TH1 command: reinitialize ?FLAGS?
14431443
--- src/th_main.c
+++ src/th_main.c
@@ -1432,11 +1432,11 @@
1432 int *argl
1433 ){
1434 if( argc!=3 ){
1435 return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
1436 }
1437 cgi_replace_parameter(mprintf("%s", argv[1]), mprintf("%s", argv[2]));
1438 return TH_OK;
1439 }
1440
1441 /*
1442 ** TH1 command: reinitialize ?FLAGS?
1443
--- src/th_main.c
+++ src/th_main.c
@@ -1432,11 +1432,11 @@
1432 int *argl
1433 ){
1434 if( argc!=3 ){
1435 return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
1436 }
1437 cgi_replace_parameter(fossil_strdup(argv[1]), fossil_strdup(argv[2]));
1438 return TH_OK;
1439 }
1440
1441 /*
1442 ** TH1 command: reinitialize ?FLAGS?
1443
+54 -12
--- src/timeline.c
+++ src/timeline.c
@@ -1273,11 +1273,11 @@
12731273
*/
12741274
static void addFileGlobExclusion(
12751275
const char *zChng, /* The filename GLOB list */
12761276
Blob *pSql /* The SELECT statement under construction */
12771277
){
1278
- if( zChng==0 || zChng[0]==0 ) return;
1278
+ if( zChng==0 ) return;
12791279
blob_append_sql(pSql," AND event.objid IN ("
12801280
"SELECT mlink.mid FROM mlink, filename\n"
12811281
" WHERE mlink.fnid=filename.fnid\n"
12821282
" AND %s)",
12831283
glob_expr("filename.name", mprintf("\"%s\"", zChng)));
@@ -1284,14 +1284,33 @@
12841284
}
12851285
static void addFileGlobDescription(
12861286
const char *zChng, /* The filename GLOB list */
12871287
Blob *pDescription /* Result description */
12881288
){
1289
- if( zChng==0 || zChng[0]==0 ) return;
1289
+ if( zChng==0 ) return;
12901290
blob_appendf(pDescription, " that include changes to files matching '%h'",
12911291
zChng);
12921292
}
1293
+
1294
+/*
1295
+** If zChng is not NULL, then use it as a comma-separated list of
1296
+** glob patterns for filenames, and remove from the "ok" table any
1297
+** check-ins that do not modify one or more of the files identified
1298
+** by zChng.
1299
+*/
1300
+static void removeFileGlobFromOk(
1301
+ const char *zChng /* The filename GLOB list */
1302
+){
1303
+ if( zChng==0 ) return;
1304
+ db_multi_exec(
1305
+ "DELETE FROM ok WHERE rid NOT IN (\n"
1306
+ " SELECT mlink.mid FROM mlink, filename\n"
1307
+ " WHERE mlink.fnid=filename.fnid\n"
1308
+ " AND %z);\n",
1309
+ glob_expr("filename.name", zChng)
1310
+ );
1311
+}
12931312
12941313
/*
12951314
** Similar to fossil_expand_datetime()
12961315
**
12971316
** Add missing "-" characters into a date/time. Examples:
@@ -1777,10 +1796,11 @@
17771796
nEntry = 0;
17781797
useDividers = 0;
17791798
cgi_replace_query_parameter("d",fossil_strdup(z));
17801799
zDPNameD = zDPNameP = z;
17811800
}
1801
+ if( zChng && zChng[0]==0 ) zChng = 0;
17821802
17831803
/* Undocumented query parameter to set JS mode */
17841804
builtin_set_js_delivery_mode(P("jsmode"),1);
17851805
17861806
secondaryRid = name_to_typed_rid(P("sel2"),"ci");
@@ -2174,12 +2194,14 @@
21742194
);
21752195
}
21762196
db_multi_exec("INSERT OR IGNORE INTO pathnode SELECT x FROM related");
21772197
}
21782198
add_extra_rids("pathnode",P("x"));
2199
+ add_extra_rids("pathnode",P("sel1"));
2200
+ add_extra_rids("pathnode",P("sel2"));
21792201
blob_append_sql(&sql, " AND event.objid IN pathnode");
2180
- if( zChng && zChng[0] ){
2202
+ if( zChng ){
21812203
db_multi_exec(
21822204
"DELETE FROM pathnode\n"
21832205
" WHERE NOT EXISTS(SELECT 1 FROM mlink, filename\n"
21842206
" WHERE mlink.mid=x\n"
21852207
" AND mlink.fnid=filename.fnid\n"
@@ -2248,10 +2270,12 @@
22482270
}
22492271
db_multi_exec(
22502272
"CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)"
22512273
);
22522274
add_extra_rids("ok", P("x"));
2275
+ add_extra_rids("ok", P("sel1"));
2276
+ add_extra_rids("ok", P("sel2"));
22532277
blob_append_sql(&sql, " AND event.objid IN ok");
22542278
nd = 0;
22552279
if( d_rid ){
22562280
double rStopTime = 9e99;
22572281
zFwdTo = P("ft");
@@ -2299,14 +2323,16 @@
22992323
db_multi_exec(
23002324
"INSERT INTO ok_d SELECT rid FROM ok;"
23012325
"DELETE FROM ok;"
23022326
);
23032327
}else{
2328
+ removeFileGlobFromOk(zChng);
23042329
nd = db_int(0, "SELECT count(*)-1 FROM ok");
23052330
if( nd>=0 ) db_multi_exec("%s", blob_sql_text(&sql));
23062331
if( nd>0 || p_rid==0 ){
2307
- blob_appendf(&desc, "%d descendant%s", nd,(1==nd)?"":"s");
2332
+ blob_appendf(&desc, "%d descendant%s",
2333
+ nd>=0 ? nd : 0,(1==nd)?"":"s");
23082334
}
23092335
if( useDividers && !selectedRid ) selectedRid = d_rid;
23102336
db_multi_exec("DELETE FROM ok");
23112337
}
23122338
}
@@ -2335,30 +2361,34 @@
23352361
db_multi_exec("INSERT OR IGNORE INTO ok VALUES(%d)", ridBackTo);
23362362
bBackAdded = 1;
23372363
}
23382364
if( bSeparateDandP ){
23392365
db_multi_exec("DELETE FROM ok WHERE rid NOT IN ok_d;");
2366
+ removeFileGlobFromOk(zChng);
23402367
db_multi_exec("%s", blob_sql_text(&sql));
23412368
}else{
2369
+ removeFileGlobFromOk(zChng);
23422370
np = db_int(0, "SELECT count(*)-1 FROM ok");
23432371
if( np>0 || nd==0 ){
23442372
if( nd>0 ) blob_appendf(&desc, " and ");
2345
- blob_appendf(&desc, "%d ancestor%s", np, (1==np)?"":"s");
2373
+ blob_appendf(&desc, "%d ancestor%s",
2374
+ np>=0 ? np : 0, (1==np)?"":"s");
23462375
db_multi_exec("%s", blob_sql_text(&sql));
23472376
}
23482377
if( useDividers && !selectedRid ) selectedRid = p_rid;
23492378
}
23502379
}
2380
+
23512381
if( bSeparateDandP ){
23522382
int n = db_int(0, "SELECT count(*) FROM ok");
23532383
blob_reset(&desc);
23542384
blob_appendf(&desc,
2355
- "%d check-ins that are both ancestors of %z%h</a>"
2356
- " and descendants of %z%h</a>",
2385
+ "%d check-ins that are derived from %z%h</a>"
2386
+ " and contribute to %z%h</a>",
23572387
n,
2358
- href("%R/info?name=%h",zDPNameP),zDPNameP,
2359
- href("%R/info?name=%h",zDPNameD),zDPNameD
2388
+ href("%R/info?name=%h",zDPNameD),zDPNameD,
2389
+ href("%R/info?name=%h",zDPNameP),zDPNameP
23602390
);
23612391
ridBackTo = 0;
23622392
ridFwdTo = 0;
23632393
}else{
23642394
blob_appendf(&desc, " of %z%h</a>",
@@ -2392,10 +2422,14 @@
23922422
blob_appendf(&desc, " up to %z%h</a>%s",
23932423
href("%R/info?name=%h",zFwdTo), zFwdTo,
23942424
bFwdAdded ? " (not a direct descendant)":"");
23952425
}
23962426
}
2427
+ if( zChng ){
2428
+ if( strstr(blob_str(&desc)," that ") ) blob_appendf(&desc, " and");
2429
+ blob_appendf(&desc, " that make changes to files matching \"%h\"", zChng);
2430
+ }
23972431
if( advancedMenu ){
23982432
style_submenu_checkbox("v", "Files", (zType[0]!='a' && zType[0]!='c'),0);
23992433
}
24002434
style_submenu_entry("n","Max:",4,0);
24012435
timeline_y_submenu(1);
@@ -2730,10 +2764,12 @@
27302764
int ridMark = name_to_rid(zMark);
27312765
db_multi_exec(
27322766
"INSERT OR IGNORE INTO selected_nodes(rid) VALUES(%d)", ridMark);
27332767
}
27342768
add_extra_rids("selected_nodes",P("x"));
2769
+ add_extra_rids("selected_nodes",P("sel1"));
2770
+ add_extra_rids("selected_nodes",P("sel2"));
27352771
if( related==0 ){
27362772
blob_append_sql(&cond, " AND blob.rid IN selected_nodes");
27372773
}else{
27382774
db_multi_exec(
27392775
"CREATE TEMP TABLE related_nodes(rid INTEGER PRIMARY KEY);"
@@ -3003,11 +3039,11 @@
30033039
"brlist", "List"
30043040
};
30053041
double rDate;
30063042
zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
30073043
if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3008
- zDate = mprintf("%s", (zAfter ? zAfter : zBefore));
3044
+ zDate = fossil_strdup((zAfter ? zAfter : zBefore));
30093045
}
30103046
if( zDate ){
30113047
rDate = symbolic_name_to_mtime(zDate, 0, 0);
30123048
if( db_int(0,
30133049
"SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3019,11 +3055,11 @@
30193055
}
30203056
free(zDate);
30213057
}
30223058
zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
30233059
if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3024
- zDate = mprintf("%s", (zBefore ? zBefore : zAfter));
3060
+ zDate = fossil_strdup((zBefore ? zBefore : zAfter));
30253061
}
30263062
if( zDate ){
30273063
rDate = symbolic_name_to_mtime(zDate, 0, 0);
30283064
if( db_int(0,
30293065
"SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3816,13 +3852,19 @@
38163852
" AND (tagxref.value IS NULL OR tagxref.value='%q')",
38173853
zBr, zBr, zBr, TAG_BRANCH, zBr, zBr);
38183854
}
38193855
38203856
if( mode==TIMELINE_MODE_AFTER ){
3857
+ int lim = n;
3858
+ if( n == 0 ){
3859
+ lim = -1; /* 0 means no limit */
3860
+ }else if( n < 0 ){
3861
+ lim = -n;
3862
+ }
38213863
/* Complete the above outer select. */
38223864
blob_append_sql(&sql,
3823
- "\nORDER BY event.mtime LIMIT abs(%d)) t ORDER BY t.mDateTime DESC;", n);
3865
+ "\nORDER BY event.mtime LIMIT %d) t ORDER BY t.mDateTime DESC;", lim);
38243866
}else{
38253867
blob_append_sql(&sql, "\nORDER BY event.mtime DESC");
38263868
}
38273869
if( iOffset>0 ){
38283870
/* Don't handle LIMIT here, otherwise print_timeline()
38293871
--- src/timeline.c
+++ src/timeline.c
@@ -1273,11 +1273,11 @@
1273 */
1274 static void addFileGlobExclusion(
1275 const char *zChng, /* The filename GLOB list */
1276 Blob *pSql /* The SELECT statement under construction */
1277 ){
1278 if( zChng==0 || zChng[0]==0 ) return;
1279 blob_append_sql(pSql," AND event.objid IN ("
1280 "SELECT mlink.mid FROM mlink, filename\n"
1281 " WHERE mlink.fnid=filename.fnid\n"
1282 " AND %s)",
1283 glob_expr("filename.name", mprintf("\"%s\"", zChng)));
@@ -1284,14 +1284,33 @@
1284 }
1285 static void addFileGlobDescription(
1286 const char *zChng, /* The filename GLOB list */
1287 Blob *pDescription /* Result description */
1288 ){
1289 if( zChng==0 || zChng[0]==0 ) return;
1290 blob_appendf(pDescription, " that include changes to files matching '%h'",
1291 zChng);
1292 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1293
1294 /*
1295 ** Similar to fossil_expand_datetime()
1296 **
1297 ** Add missing "-" characters into a date/time. Examples:
@@ -1777,10 +1796,11 @@
1777 nEntry = 0;
1778 useDividers = 0;
1779 cgi_replace_query_parameter("d",fossil_strdup(z));
1780 zDPNameD = zDPNameP = z;
1781 }
 
1782
1783 /* Undocumented query parameter to set JS mode */
1784 builtin_set_js_delivery_mode(P("jsmode"),1);
1785
1786 secondaryRid = name_to_typed_rid(P("sel2"),"ci");
@@ -2174,12 +2194,14 @@
2174 );
2175 }
2176 db_multi_exec("INSERT OR IGNORE INTO pathnode SELECT x FROM related");
2177 }
2178 add_extra_rids("pathnode",P("x"));
 
 
2179 blob_append_sql(&sql, " AND event.objid IN pathnode");
2180 if( zChng && zChng[0] ){
2181 db_multi_exec(
2182 "DELETE FROM pathnode\n"
2183 " WHERE NOT EXISTS(SELECT 1 FROM mlink, filename\n"
2184 " WHERE mlink.mid=x\n"
2185 " AND mlink.fnid=filename.fnid\n"
@@ -2248,10 +2270,12 @@
2248 }
2249 db_multi_exec(
2250 "CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)"
2251 );
2252 add_extra_rids("ok", P("x"));
 
 
2253 blob_append_sql(&sql, " AND event.objid IN ok");
2254 nd = 0;
2255 if( d_rid ){
2256 double rStopTime = 9e99;
2257 zFwdTo = P("ft");
@@ -2299,14 +2323,16 @@
2299 db_multi_exec(
2300 "INSERT INTO ok_d SELECT rid FROM ok;"
2301 "DELETE FROM ok;"
2302 );
2303 }else{
 
2304 nd = db_int(0, "SELECT count(*)-1 FROM ok");
2305 if( nd>=0 ) db_multi_exec("%s", blob_sql_text(&sql));
2306 if( nd>0 || p_rid==0 ){
2307 blob_appendf(&desc, "%d descendant%s", nd,(1==nd)?"":"s");
 
2308 }
2309 if( useDividers && !selectedRid ) selectedRid = d_rid;
2310 db_multi_exec("DELETE FROM ok");
2311 }
2312 }
@@ -2335,30 +2361,34 @@
2335 db_multi_exec("INSERT OR IGNORE INTO ok VALUES(%d)", ridBackTo);
2336 bBackAdded = 1;
2337 }
2338 if( bSeparateDandP ){
2339 db_multi_exec("DELETE FROM ok WHERE rid NOT IN ok_d;");
 
2340 db_multi_exec("%s", blob_sql_text(&sql));
2341 }else{
 
2342 np = db_int(0, "SELECT count(*)-1 FROM ok");
2343 if( np>0 || nd==0 ){
2344 if( nd>0 ) blob_appendf(&desc, " and ");
2345 blob_appendf(&desc, "%d ancestor%s", np, (1==np)?"":"s");
 
2346 db_multi_exec("%s", blob_sql_text(&sql));
2347 }
2348 if( useDividers && !selectedRid ) selectedRid = p_rid;
2349 }
2350 }
 
2351 if( bSeparateDandP ){
2352 int n = db_int(0, "SELECT count(*) FROM ok");
2353 blob_reset(&desc);
2354 blob_appendf(&desc,
2355 "%d check-ins that are both ancestors of %z%h</a>"
2356 " and descendants of %z%h</a>",
2357 n,
2358 href("%R/info?name=%h",zDPNameP),zDPNameP,
2359 href("%R/info?name=%h",zDPNameD),zDPNameD
2360 );
2361 ridBackTo = 0;
2362 ridFwdTo = 0;
2363 }else{
2364 blob_appendf(&desc, " of %z%h</a>",
@@ -2392,10 +2422,14 @@
2392 blob_appendf(&desc, " up to %z%h</a>%s",
2393 href("%R/info?name=%h",zFwdTo), zFwdTo,
2394 bFwdAdded ? " (not a direct descendant)":"");
2395 }
2396 }
 
 
 
 
2397 if( advancedMenu ){
2398 style_submenu_checkbox("v", "Files", (zType[0]!='a' && zType[0]!='c'),0);
2399 }
2400 style_submenu_entry("n","Max:",4,0);
2401 timeline_y_submenu(1);
@@ -2730,10 +2764,12 @@
2730 int ridMark = name_to_rid(zMark);
2731 db_multi_exec(
2732 "INSERT OR IGNORE INTO selected_nodes(rid) VALUES(%d)", ridMark);
2733 }
2734 add_extra_rids("selected_nodes",P("x"));
 
 
2735 if( related==0 ){
2736 blob_append_sql(&cond, " AND blob.rid IN selected_nodes");
2737 }else{
2738 db_multi_exec(
2739 "CREATE TEMP TABLE related_nodes(rid INTEGER PRIMARY KEY);"
@@ -3003,11 +3039,11 @@
3003 "brlist", "List"
3004 };
3005 double rDate;
3006 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
3007 if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3008 zDate = mprintf("%s", (zAfter ? zAfter : zBefore));
3009 }
3010 if( zDate ){
3011 rDate = symbolic_name_to_mtime(zDate, 0, 0);
3012 if( db_int(0,
3013 "SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3019,11 +3055,11 @@
3019 }
3020 free(zDate);
3021 }
3022 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
3023 if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3024 zDate = mprintf("%s", (zBefore ? zBefore : zAfter));
3025 }
3026 if( zDate ){
3027 rDate = symbolic_name_to_mtime(zDate, 0, 0);
3028 if( db_int(0,
3029 "SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3816,13 +3852,19 @@
3816 " AND (tagxref.value IS NULL OR tagxref.value='%q')",
3817 zBr, zBr, zBr, TAG_BRANCH, zBr, zBr);
3818 }
3819
3820 if( mode==TIMELINE_MODE_AFTER ){
 
 
 
 
 
 
3821 /* Complete the above outer select. */
3822 blob_append_sql(&sql,
3823 "\nORDER BY event.mtime LIMIT abs(%d)) t ORDER BY t.mDateTime DESC;", n);
3824 }else{
3825 blob_append_sql(&sql, "\nORDER BY event.mtime DESC");
3826 }
3827 if( iOffset>0 ){
3828 /* Don't handle LIMIT here, otherwise print_timeline()
3829
--- src/timeline.c
+++ src/timeline.c
@@ -1273,11 +1273,11 @@
1273 */
1274 static void addFileGlobExclusion(
1275 const char *zChng, /* The filename GLOB list */
1276 Blob *pSql /* The SELECT statement under construction */
1277 ){
1278 if( zChng==0 ) return;
1279 blob_append_sql(pSql," AND event.objid IN ("
1280 "SELECT mlink.mid FROM mlink, filename\n"
1281 " WHERE mlink.fnid=filename.fnid\n"
1282 " AND %s)",
1283 glob_expr("filename.name", mprintf("\"%s\"", zChng)));
@@ -1284,14 +1284,33 @@
1284 }
1285 static void addFileGlobDescription(
1286 const char *zChng, /* The filename GLOB list */
1287 Blob *pDescription /* Result description */
1288 ){
1289 if( zChng==0 ) return;
1290 blob_appendf(pDescription, " that include changes to files matching '%h'",
1291 zChng);
1292 }
1293
1294 /*
1295 ** If zChng is not NULL, then use it as a comma-separated list of
1296 ** glob patterns for filenames, and remove from the "ok" table any
1297 ** check-ins that do not modify one or more of the files identified
1298 ** by zChng.
1299 */
1300 static void removeFileGlobFromOk(
1301 const char *zChng /* The filename GLOB list */
1302 ){
1303 if( zChng==0 ) return;
1304 db_multi_exec(
1305 "DELETE FROM ok WHERE rid NOT IN (\n"
1306 " SELECT mlink.mid FROM mlink, filename\n"
1307 " WHERE mlink.fnid=filename.fnid\n"
1308 " AND %z);\n",
1309 glob_expr("filename.name", zChng)
1310 );
1311 }
1312
1313 /*
1314 ** Similar to fossil_expand_datetime()
1315 **
1316 ** Add missing "-" characters into a date/time. Examples:
@@ -1777,10 +1796,11 @@
1796 nEntry = 0;
1797 useDividers = 0;
1798 cgi_replace_query_parameter("d",fossil_strdup(z));
1799 zDPNameD = zDPNameP = z;
1800 }
1801 if( zChng && zChng[0]==0 ) zChng = 0;
1802
1803 /* Undocumented query parameter to set JS mode */
1804 builtin_set_js_delivery_mode(P("jsmode"),1);
1805
1806 secondaryRid = name_to_typed_rid(P("sel2"),"ci");
@@ -2174,12 +2194,14 @@
2194 );
2195 }
2196 db_multi_exec("INSERT OR IGNORE INTO pathnode SELECT x FROM related");
2197 }
2198 add_extra_rids("pathnode",P("x"));
2199 add_extra_rids("pathnode",P("sel1"));
2200 add_extra_rids("pathnode",P("sel2"));
2201 blob_append_sql(&sql, " AND event.objid IN pathnode");
2202 if( zChng ){
2203 db_multi_exec(
2204 "DELETE FROM pathnode\n"
2205 " WHERE NOT EXISTS(SELECT 1 FROM mlink, filename\n"
2206 " WHERE mlink.mid=x\n"
2207 " AND mlink.fnid=filename.fnid\n"
@@ -2248,10 +2270,12 @@
2270 }
2271 db_multi_exec(
2272 "CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)"
2273 );
2274 add_extra_rids("ok", P("x"));
2275 add_extra_rids("ok", P("sel1"));
2276 add_extra_rids("ok", P("sel2"));
2277 blob_append_sql(&sql, " AND event.objid IN ok");
2278 nd = 0;
2279 if( d_rid ){
2280 double rStopTime = 9e99;
2281 zFwdTo = P("ft");
@@ -2299,14 +2323,16 @@
2323 db_multi_exec(
2324 "INSERT INTO ok_d SELECT rid FROM ok;"
2325 "DELETE FROM ok;"
2326 );
2327 }else{
2328 removeFileGlobFromOk(zChng);
2329 nd = db_int(0, "SELECT count(*)-1 FROM ok");
2330 if( nd>=0 ) db_multi_exec("%s", blob_sql_text(&sql));
2331 if( nd>0 || p_rid==0 ){
2332 blob_appendf(&desc, "%d descendant%s",
2333 nd>=0 ? nd : 0,(1==nd)?"":"s");
2334 }
2335 if( useDividers && !selectedRid ) selectedRid = d_rid;
2336 db_multi_exec("DELETE FROM ok");
2337 }
2338 }
@@ -2335,30 +2361,34 @@
2361 db_multi_exec("INSERT OR IGNORE INTO ok VALUES(%d)", ridBackTo);
2362 bBackAdded = 1;
2363 }
2364 if( bSeparateDandP ){
2365 db_multi_exec("DELETE FROM ok WHERE rid NOT IN ok_d;");
2366 removeFileGlobFromOk(zChng);
2367 db_multi_exec("%s", blob_sql_text(&sql));
2368 }else{
2369 removeFileGlobFromOk(zChng);
2370 np = db_int(0, "SELECT count(*)-1 FROM ok");
2371 if( np>0 || nd==0 ){
2372 if( nd>0 ) blob_appendf(&desc, " and ");
2373 blob_appendf(&desc, "%d ancestor%s",
2374 np>=0 ? np : 0, (1==np)?"":"s");
2375 db_multi_exec("%s", blob_sql_text(&sql));
2376 }
2377 if( useDividers && !selectedRid ) selectedRid = p_rid;
2378 }
2379 }
2380
2381 if( bSeparateDandP ){
2382 int n = db_int(0, "SELECT count(*) FROM ok");
2383 blob_reset(&desc);
2384 blob_appendf(&desc,
2385 "%d check-ins that are derived from %z%h</a>"
2386 " and contribute to %z%h</a>",
2387 n,
2388 href("%R/info?name=%h",zDPNameD),zDPNameD,
2389 href("%R/info?name=%h",zDPNameP),zDPNameP
2390 );
2391 ridBackTo = 0;
2392 ridFwdTo = 0;
2393 }else{
2394 blob_appendf(&desc, " of %z%h</a>",
@@ -2392,10 +2422,14 @@
2422 blob_appendf(&desc, " up to %z%h</a>%s",
2423 href("%R/info?name=%h",zFwdTo), zFwdTo,
2424 bFwdAdded ? " (not a direct descendant)":"");
2425 }
2426 }
2427 if( zChng ){
2428 if( strstr(blob_str(&desc)," that ") ) blob_appendf(&desc, " and");
2429 blob_appendf(&desc, " that make changes to files matching \"%h\"", zChng);
2430 }
2431 if( advancedMenu ){
2432 style_submenu_checkbox("v", "Files", (zType[0]!='a' && zType[0]!='c'),0);
2433 }
2434 style_submenu_entry("n","Max:",4,0);
2435 timeline_y_submenu(1);
@@ -2730,10 +2764,12 @@
2764 int ridMark = name_to_rid(zMark);
2765 db_multi_exec(
2766 "INSERT OR IGNORE INTO selected_nodes(rid) VALUES(%d)", ridMark);
2767 }
2768 add_extra_rids("selected_nodes",P("x"));
2769 add_extra_rids("selected_nodes",P("sel1"));
2770 add_extra_rids("selected_nodes",P("sel2"));
2771 if( related==0 ){
2772 blob_append_sql(&cond, " AND blob.rid IN selected_nodes");
2773 }else{
2774 db_multi_exec(
2775 "CREATE TEMP TABLE related_nodes(rid INTEGER PRIMARY KEY);"
@@ -3003,11 +3039,11 @@
3039 "brlist", "List"
3040 };
3041 double rDate;
3042 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
3043 if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3044 zDate = fossil_strdup((zAfter ? zAfter : zBefore));
3045 }
3046 if( zDate ){
3047 rDate = symbolic_name_to_mtime(zDate, 0, 0);
3048 if( db_int(0,
3049 "SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3019,11 +3055,11 @@
3055 }
3056 free(zDate);
3057 }
3058 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
3059 if( (!zDate || !zDate[0]) && ( zAfter || zBefore ) ){
3060 zDate = fossil_strdup((zBefore ? zBefore : zAfter));
3061 }
3062 if( zDate ){
3063 rDate = symbolic_name_to_mtime(zDate, 0, 0);
3064 if( db_int(0,
3065 "SELECT EXISTS (SELECT 1 FROM event CROSS JOIN blob"
@@ -3816,13 +3852,19 @@
3852 " AND (tagxref.value IS NULL OR tagxref.value='%q')",
3853 zBr, zBr, zBr, TAG_BRANCH, zBr, zBr);
3854 }
3855
3856 if( mode==TIMELINE_MODE_AFTER ){
3857 int lim = n;
3858 if( n == 0 ){
3859 lim = -1; /* 0 means no limit */
3860 }else if( n < 0 ){
3861 lim = -n;
3862 }
3863 /* Complete the above outer select. */
3864 blob_append_sql(&sql,
3865 "\nORDER BY event.mtime LIMIT %d) t ORDER BY t.mDateTime DESC;", lim);
3866 }else{
3867 blob_append_sql(&sql, "\nORDER BY event.mtime DESC");
3868 }
3869 if( iOffset>0 ){
3870 /* Don't handle LIMIT here, otherwise print_timeline()
3871
+4 -4
--- src/tkt.c
+++ src/tkt.c
@@ -102,11 +102,11 @@
102102
if( strchr(zFieldName,' ')!=0 ) continue;
103103
if( nField%10==0 ){
104104
aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
105105
}
106106
aField[nField].zBsln = 0;
107
- aField[nField].zName = mprintf("%s", zFieldName);
107
+ aField[nField].zName = fossil_strdup(zFieldName);
108108
aField[nField].mUsed = USEDBY_TICKET;
109109
nField++;
110110
}
111111
db_finalize(&q);
112112
if( nBaselines ){
@@ -145,11 +145,11 @@
145145
}
146146
if( nField%10==0 ){
147147
aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
148148
}
149149
aField[nField].zBsln = 0;
150
- aField[nField].zName = mprintf("%s", zFieldName);
150
+ aField[nField].zName = fossil_strdup(zFieldName);
151151
aField[nField].mUsed = USEDBY_TICKETCHNG;
152152
nField++;
153153
}
154154
db_finalize(&q);
155155
qsort(aField, nField, sizeof(aField[0]), nameCmpr);
@@ -210,11 +210,11 @@
210210
zVal = "";
211211
}else if( strncmp(zName, "private_", 8)==0 ){
212212
zVal = zRevealed = db_reveal(zVal);
213213
}
214214
if( (j = fieldId(zName))>=0 ){
215
- aField[j].zValue = mprintf("%s", zVal);
215
+ aField[j].zValue = fossil_strdup(zVal);
216216
}else if( memcmp(zName, "tkt_", 4)==0 && Th_Fetch(zName, &size)==0 ){
217217
/* TICKET table columns that begin with "tkt_" are always safe */
218218
Th_Store(zName, zVal);
219219
}
220220
free(zRevealed);
@@ -1787,11 +1787,11 @@
17871787
if( i==g.argc ){
17881788
fossil_fatal("missing value for '%s'!",zFName);
17891789
}
17901790
zFValue = g.argv[i++];
17911791
if( tktEncoding == tktFossilize ){
1792
- zFValue=mprintf("%s",zFValue);
1792
+ zFValue=fossil_strdup(zFValue);
17931793
defossilize(zFValue);
17941794
}
17951795
append = (zFName[0] == '+');
17961796
if( append ){
17971797
zFName++;
17981798
--- src/tkt.c
+++ src/tkt.c
@@ -102,11 +102,11 @@
102 if( strchr(zFieldName,' ')!=0 ) continue;
103 if( nField%10==0 ){
104 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
105 }
106 aField[nField].zBsln = 0;
107 aField[nField].zName = mprintf("%s", zFieldName);
108 aField[nField].mUsed = USEDBY_TICKET;
109 nField++;
110 }
111 db_finalize(&q);
112 if( nBaselines ){
@@ -145,11 +145,11 @@
145 }
146 if( nField%10==0 ){
147 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
148 }
149 aField[nField].zBsln = 0;
150 aField[nField].zName = mprintf("%s", zFieldName);
151 aField[nField].mUsed = USEDBY_TICKETCHNG;
152 nField++;
153 }
154 db_finalize(&q);
155 qsort(aField, nField, sizeof(aField[0]), nameCmpr);
@@ -210,11 +210,11 @@
210 zVal = "";
211 }else if( strncmp(zName, "private_", 8)==0 ){
212 zVal = zRevealed = db_reveal(zVal);
213 }
214 if( (j = fieldId(zName))>=0 ){
215 aField[j].zValue = mprintf("%s", zVal);
216 }else if( memcmp(zName, "tkt_", 4)==0 && Th_Fetch(zName, &size)==0 ){
217 /* TICKET table columns that begin with "tkt_" are always safe */
218 Th_Store(zName, zVal);
219 }
220 free(zRevealed);
@@ -1787,11 +1787,11 @@
1787 if( i==g.argc ){
1788 fossil_fatal("missing value for '%s'!",zFName);
1789 }
1790 zFValue = g.argv[i++];
1791 if( tktEncoding == tktFossilize ){
1792 zFValue=mprintf("%s",zFValue);
1793 defossilize(zFValue);
1794 }
1795 append = (zFName[0] == '+');
1796 if( append ){
1797 zFName++;
1798
--- src/tkt.c
+++ src/tkt.c
@@ -102,11 +102,11 @@
102 if( strchr(zFieldName,' ')!=0 ) continue;
103 if( nField%10==0 ){
104 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
105 }
106 aField[nField].zBsln = 0;
107 aField[nField].zName = fossil_strdup(zFieldName);
108 aField[nField].mUsed = USEDBY_TICKET;
109 nField++;
110 }
111 db_finalize(&q);
112 if( nBaselines ){
@@ -145,11 +145,11 @@
145 }
146 if( nField%10==0 ){
147 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
148 }
149 aField[nField].zBsln = 0;
150 aField[nField].zName = fossil_strdup(zFieldName);
151 aField[nField].mUsed = USEDBY_TICKETCHNG;
152 nField++;
153 }
154 db_finalize(&q);
155 qsort(aField, nField, sizeof(aField[0]), nameCmpr);
@@ -210,11 +210,11 @@
210 zVal = "";
211 }else if( strncmp(zName, "private_", 8)==0 ){
212 zVal = zRevealed = db_reveal(zVal);
213 }
214 if( (j = fieldId(zName))>=0 ){
215 aField[j].zValue = fossil_strdup(zVal);
216 }else if( memcmp(zName, "tkt_", 4)==0 && Th_Fetch(zName, &size)==0 ){
217 /* TICKET table columns that begin with "tkt_" are always safe */
218 Th_Store(zName, zVal);
219 }
220 free(zRevealed);
@@ -1787,11 +1787,11 @@
1787 if( i==g.argc ){
1788 fossil_fatal("missing value for '%s'!",zFName);
1789 }
1790 zFValue = g.argv[i++];
1791 if( tktEncoding == tktFossilize ){
1792 zFValue=fossil_strdup(zFValue);
1793 defossilize(zFValue);
1794 }
1795 append = (zFName[0] == '+');
1796 if( append ){
1797 zFName++;
1798
--- src/unversioned.c
+++ src/unversioned.c
@@ -147,10 +147,12 @@
147147
}else{
148148
db_bind_int(&ins, ":encoding", 0);
149149
db_bind_blob(&ins, ":content", pContent);
150150
}
151151
db_step(&ins);
152
+ admin_log("Wrote unversioned file \"%w\" with hash %!S",
153
+ zUVFile, blob_str(&hash));
152154
blob_reset(&compressed);
153155
blob_reset(&hash);
154156
db_finalize(&ins);
155157
db_unset("uv-hash", 0);
156158
}
157159
--- src/unversioned.c
+++ src/unversioned.c
@@ -147,10 +147,12 @@
147 }else{
148 db_bind_int(&ins, ":encoding", 0);
149 db_bind_blob(&ins, ":content", pContent);
150 }
151 db_step(&ins);
 
 
152 blob_reset(&compressed);
153 blob_reset(&hash);
154 db_finalize(&ins);
155 db_unset("uv-hash", 0);
156 }
157
--- src/unversioned.c
+++ src/unversioned.c
@@ -147,10 +147,12 @@
147 }else{
148 db_bind_int(&ins, ":encoding", 0);
149 db_bind_blob(&ins, ":content", pContent);
150 }
151 db_step(&ins);
152 admin_log("Wrote unversioned file \"%w\" with hash %!S",
153 zUVFile, blob_str(&hash));
154 blob_reset(&compressed);
155 blob_reset(&hash);
156 db_finalize(&ins);
157 db_unset("uv-hash", 0);
158 }
159
+5 -5
--- src/url.c
+++ src/url.c
@@ -227,17 +227,17 @@
227227
}else{
228228
pUrlData->port = pUrlData->dfltPort;
229229
pUrlData->hostname = pUrlData->name;
230230
}
231231
dehttpize(pUrlData->name);
232
- pUrlData->path = mprintf("%s", &zUrl[i]);
232
+ pUrlData->path = fossil_strdup(&zUrl[i]);
233233
for(i=0; pUrlData->path[i] && pUrlData->path[i]!='?'; i++){}
234234
if( pUrlData->path[i] ){
235235
pUrlData->path[i] = 0;
236236
i++;
237237
}
238
- zExe = mprintf("");
238
+ zExe = fossil_strdup("");
239239
while( pUrlData->path[i]!=0 ){
240240
char *zName, *zValue;
241241
zName = &pUrlData->path[i];
242242
zValue = zName;
243243
while( pUrlData->path[i] && pUrlData->path[i]!='=' ){ i++; }
@@ -275,11 +275,11 @@
275275
pUrlData->path, zExe
276276
);
277277
}
278278
if( pUrlData->isSsh && pUrlData->path[1] ){
279279
char *zOld = pUrlData->path;
280
- pUrlData->path = mprintf("%s", zOld+1);
280
+ pUrlData->path = fossil_strdup(zOld+1);
281281
fossil_free(zOld);
282282
}
283283
free(zLogin);
284284
}else if( strncmp(zUrl, "file:", 5)==0 ){
285285
pUrlData->isFile = 1;
@@ -286,14 +286,14 @@
286286
if( zUrl[5]=='/' && zUrl[6]=='/' ){
287287
i = 7;
288288
}else{
289289
i = 5;
290290
}
291
- zFile = mprintf("%s", &zUrl[i]);
291
+ zFile = fossil_strdup(&zUrl[i]);
292292
}else if( file_isfile(zUrl, ExtFILE) ){
293293
pUrlData->isFile = 1;
294
- zFile = mprintf("%s", zUrl);
294
+ zFile = fossil_strdup(zUrl);
295295
}else if( file_isdir(zUrl, ExtFILE)==1 ){
296296
zFile = mprintf("%s/FOSSIL", zUrl);
297297
if( file_isfile(zFile, ExtFILE) ){
298298
pUrlData->isFile = 1;
299299
}else{
300300
--- src/url.c
+++ src/url.c
@@ -227,17 +227,17 @@
227 }else{
228 pUrlData->port = pUrlData->dfltPort;
229 pUrlData->hostname = pUrlData->name;
230 }
231 dehttpize(pUrlData->name);
232 pUrlData->path = mprintf("%s", &zUrl[i]);
233 for(i=0; pUrlData->path[i] && pUrlData->path[i]!='?'; i++){}
234 if( pUrlData->path[i] ){
235 pUrlData->path[i] = 0;
236 i++;
237 }
238 zExe = mprintf("");
239 while( pUrlData->path[i]!=0 ){
240 char *zName, *zValue;
241 zName = &pUrlData->path[i];
242 zValue = zName;
243 while( pUrlData->path[i] && pUrlData->path[i]!='=' ){ i++; }
@@ -275,11 +275,11 @@
275 pUrlData->path, zExe
276 );
277 }
278 if( pUrlData->isSsh && pUrlData->path[1] ){
279 char *zOld = pUrlData->path;
280 pUrlData->path = mprintf("%s", zOld+1);
281 fossil_free(zOld);
282 }
283 free(zLogin);
284 }else if( strncmp(zUrl, "file:", 5)==0 ){
285 pUrlData->isFile = 1;
@@ -286,14 +286,14 @@
286 if( zUrl[5]=='/' && zUrl[6]=='/' ){
287 i = 7;
288 }else{
289 i = 5;
290 }
291 zFile = mprintf("%s", &zUrl[i]);
292 }else if( file_isfile(zUrl, ExtFILE) ){
293 pUrlData->isFile = 1;
294 zFile = mprintf("%s", zUrl);
295 }else if( file_isdir(zUrl, ExtFILE)==1 ){
296 zFile = mprintf("%s/FOSSIL", zUrl);
297 if( file_isfile(zFile, ExtFILE) ){
298 pUrlData->isFile = 1;
299 }else{
300
--- src/url.c
+++ src/url.c
@@ -227,17 +227,17 @@
227 }else{
228 pUrlData->port = pUrlData->dfltPort;
229 pUrlData->hostname = pUrlData->name;
230 }
231 dehttpize(pUrlData->name);
232 pUrlData->path = fossil_strdup(&zUrl[i]);
233 for(i=0; pUrlData->path[i] && pUrlData->path[i]!='?'; i++){}
234 if( pUrlData->path[i] ){
235 pUrlData->path[i] = 0;
236 i++;
237 }
238 zExe = fossil_strdup("");
239 while( pUrlData->path[i]!=0 ){
240 char *zName, *zValue;
241 zName = &pUrlData->path[i];
242 zValue = zName;
243 while( pUrlData->path[i] && pUrlData->path[i]!='=' ){ i++; }
@@ -275,11 +275,11 @@
275 pUrlData->path, zExe
276 );
277 }
278 if( pUrlData->isSsh && pUrlData->path[1] ){
279 char *zOld = pUrlData->path;
280 pUrlData->path = fossil_strdup(zOld+1);
281 fossil_free(zOld);
282 }
283 free(zLogin);
284 }else if( strncmp(zUrl, "file:", 5)==0 ){
285 pUrlData->isFile = 1;
@@ -286,14 +286,14 @@
286 if( zUrl[5]=='/' && zUrl[6]=='/' ){
287 i = 7;
288 }else{
289 i = 5;
290 }
291 zFile = fossil_strdup(&zUrl[i]);
292 }else if( file_isfile(zUrl, ExtFILE) ){
293 pUrlData->isFile = 1;
294 zFile = fossil_strdup(zUrl);
295 }else if( file_isdir(zUrl, ExtFILE)==1 ){
296 zFile = mprintf("%s/FOSSIL", zUrl);
297 if( file_isfile(zFile, ExtFILE) ){
298 pUrlData->isFile = 1;
299 }else{
300
+2 -2
--- src/user.c
+++ src/user.c
@@ -465,11 +465,11 @@
465465
char *zSecret = sha1_shared_secret(blob_str(&pw), g.argv[3], 0);
466466
db_unprotect(PROTECT_USER);
467467
db_multi_exec("UPDATE user SET pw=%Q, mtime=now() WHERE uid=%d",
468468
zSecret, uid);
469469
db_protect_pop();
470
- free(zSecret);
470
+ fossil_free(zSecret);
471471
}
472472
}else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
473473
int uid;
474474
if( g.argc!=4 && g.argc!=5 ){
475475
usage("capabilities USERNAME ?PERMISSIONS?");
@@ -521,11 +521,11 @@
521521
return 0;
522522
}
523523
uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zLogin);
524524
if( uid ){
525525
g.userUid = uid;
526
- g.zLogin = mprintf("%s", zLogin);
526
+ g.zLogin = fossil_strdup(zLogin);
527527
return 1;
528528
}
529529
return 0;
530530
}
531531
532532
--- src/user.c
+++ src/user.c
@@ -465,11 +465,11 @@
465 char *zSecret = sha1_shared_secret(blob_str(&pw), g.argv[3], 0);
466 db_unprotect(PROTECT_USER);
467 db_multi_exec("UPDATE user SET pw=%Q, mtime=now() WHERE uid=%d",
468 zSecret, uid);
469 db_protect_pop();
470 free(zSecret);
471 }
472 }else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
473 int uid;
474 if( g.argc!=4 && g.argc!=5 ){
475 usage("capabilities USERNAME ?PERMISSIONS?");
@@ -521,11 +521,11 @@
521 return 0;
522 }
523 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zLogin);
524 if( uid ){
525 g.userUid = uid;
526 g.zLogin = mprintf("%s", zLogin);
527 return 1;
528 }
529 return 0;
530 }
531
532
--- src/user.c
+++ src/user.c
@@ -465,11 +465,11 @@
465 char *zSecret = sha1_shared_secret(blob_str(&pw), g.argv[3], 0);
466 db_unprotect(PROTECT_USER);
467 db_multi_exec("UPDATE user SET pw=%Q, mtime=now() WHERE uid=%d",
468 zSecret, uid);
469 db_protect_pop();
470 fossil_free(zSecret);
471 }
472 }else if( n>=2 && strncmp(g.argv[2],"capabilities",2)==0 ){
473 int uid;
474 if( g.argc!=4 && g.argc!=5 ){
475 usage("capabilities USERNAME ?PERMISSIONS?");
@@ -521,11 +521,11 @@
521 return 0;
522 }
523 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zLogin);
524 if( uid ){
525 g.userUid = uid;
526 g.zLogin = fossil_strdup(zLogin);
527 return 1;
528 }
529 return 0;
530 }
531
532
+2 -2
--- src/vfile.c
+++ src/vfile.c
@@ -643,11 +643,11 @@
643643
if( pEntry->d_name[0]=='.' ){
644644
if( (scanFlags & SCAN_ALL)==0 ) continue;
645645
if( pEntry->d_name[1]==0 ) continue;
646646
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
647647
}
648
- zOrigPath = mprintf("%s", blob_str(pPath));
648
+ zOrigPath = fossil_strdup(blob_str(pPath));
649649
zUtf8 = fossil_path_to_utf8(pEntry->d_name);
650650
blob_appendf(pPath, "/%s", zUtf8);
651651
zPath = blob_str(pPath);
652652
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
653653
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
@@ -657,11 +657,11 @@
657657
? (file_isdir(zPath, eFType)==1) : (pEntry->d_type==DT_DIR) ){
658658
#else
659659
}else if( file_isdir(zPath, eFType)==1 ){
660660
#endif
661661
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
662
- char *zSavePath = mprintf("%s", zPath);
662
+ char *zSavePath = fossil_strdup(zPath);
663663
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
664664
pIgnore2, eFType);
665665
db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
666666
db_bind_int(&ins, ":count", count);
667667
db_step(&ins);
668668
--- src/vfile.c
+++ src/vfile.c
@@ -643,11 +643,11 @@
643 if( pEntry->d_name[0]=='.' ){
644 if( (scanFlags & SCAN_ALL)==0 ) continue;
645 if( pEntry->d_name[1]==0 ) continue;
646 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
647 }
648 zOrigPath = mprintf("%s", blob_str(pPath));
649 zUtf8 = fossil_path_to_utf8(pEntry->d_name);
650 blob_appendf(pPath, "/%s", zUtf8);
651 zPath = blob_str(pPath);
652 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
653 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
@@ -657,11 +657,11 @@
657 ? (file_isdir(zPath, eFType)==1) : (pEntry->d_type==DT_DIR) ){
658 #else
659 }else if( file_isdir(zPath, eFType)==1 ){
660 #endif
661 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
662 char *zSavePath = mprintf("%s", zPath);
663 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
664 pIgnore2, eFType);
665 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
666 db_bind_int(&ins, ":count", count);
667 db_step(&ins);
668
--- src/vfile.c
+++ src/vfile.c
@@ -643,11 +643,11 @@
643 if( pEntry->d_name[0]=='.' ){
644 if( (scanFlags & SCAN_ALL)==0 ) continue;
645 if( pEntry->d_name[1]==0 ) continue;
646 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
647 }
648 zOrigPath = fossil_strdup(blob_str(pPath));
649 zUtf8 = fossil_path_to_utf8(pEntry->d_name);
650 blob_appendf(pPath, "/%s", zUtf8);
651 zPath = blob_str(pPath);
652 if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
653 glob_match(pIgnore2, &zPath[nPrefix+1]) ){
@@ -657,11 +657,11 @@
657 ? (file_isdir(zPath, eFType)==1) : (pEntry->d_type==DT_DIR) ){
658 #else
659 }else if( file_isdir(zPath, eFType)==1 ){
660 #endif
661 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
662 char *zSavePath = fossil_strdup(zPath);
663 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
664 pIgnore2, eFType);
665 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
666 db_bind_int(&ins, ":count", count);
667 db_step(&ins);
668
+5 -2
--- src/wiki.c
+++ src/wiki.c
@@ -574,11 +574,11 @@
574574
Blob wiki;
575575
Manifest *pWiki = 0;
576576
const char *zPageName;
577577
const char *zMimetype = 0;
578578
int isPopup = P("popup")!=0;
579
- char *zBody = mprintf("%s","<i>Empty Page</i>");
579
+ char *zBody = fossil_strdup("<i>Empty Page</i>");
580580
int noSubmenu = P("nsm")!=0 || g.isHome;
581581
582582
login_check_credentials();
583583
if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
584584
zPageName = P("name");
@@ -2583,11 +2583,14 @@
25832583
static void wiki_submenu_to_read_wiki(
25842584
const char *zPrefix, /* "branch", "tag", or "checkin" */
25852585
const char *zName, /* Name of the object */
25862586
unsigned int mFlags /* Zero or more WIKIASSOC_* flags */
25872587
){
2588
- if( g.perm.RdWiki && (mFlags & WIKIASSOC_MENU_READ)!=0 ){
2588
+ if( g.perm.RdWiki && (mFlags & WIKIASSOC_MENU_READ)!=0
2589
+ && 0!=fossil_strcmp("branch", zPrefix)
2590
+ /* ^^^ https://fossil-scm.org/forum/forumpost/ff453de2f30791dd */
2591
+ ){
25892592
style_submenu_element("Wiki", "%R/wiki?name=%s/%t", zPrefix, zName);
25902593
}
25912594
}
25922595
25932596
/*
25942597
--- src/wiki.c
+++ src/wiki.c
@@ -574,11 +574,11 @@
574 Blob wiki;
575 Manifest *pWiki = 0;
576 const char *zPageName;
577 const char *zMimetype = 0;
578 int isPopup = P("popup")!=0;
579 char *zBody = mprintf("%s","<i>Empty Page</i>");
580 int noSubmenu = P("nsm")!=0 || g.isHome;
581
582 login_check_credentials();
583 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
584 zPageName = P("name");
@@ -2583,11 +2583,14 @@
2583 static void wiki_submenu_to_read_wiki(
2584 const char *zPrefix, /* "branch", "tag", or "checkin" */
2585 const char *zName, /* Name of the object */
2586 unsigned int mFlags /* Zero or more WIKIASSOC_* flags */
2587 ){
2588 if( g.perm.RdWiki && (mFlags & WIKIASSOC_MENU_READ)!=0 ){
 
 
 
2589 style_submenu_element("Wiki", "%R/wiki?name=%s/%t", zPrefix, zName);
2590 }
2591 }
2592
2593 /*
2594
--- src/wiki.c
+++ src/wiki.c
@@ -574,11 +574,11 @@
574 Blob wiki;
575 Manifest *pWiki = 0;
576 const char *zPageName;
577 const char *zMimetype = 0;
578 int isPopup = P("popup")!=0;
579 char *zBody = fossil_strdup("<i>Empty Page</i>");
580 int noSubmenu = P("nsm")!=0 || g.isHome;
581
582 login_check_credentials();
583 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
584 zPageName = P("name");
@@ -2583,11 +2583,14 @@
2583 static void wiki_submenu_to_read_wiki(
2584 const char *zPrefix, /* "branch", "tag", or "checkin" */
2585 const char *zName, /* Name of the object */
2586 unsigned int mFlags /* Zero or more WIKIASSOC_* flags */
2587 ){
2588 if( g.perm.RdWiki && (mFlags & WIKIASSOC_MENU_READ)!=0
2589 && 0!=fossil_strcmp("branch", zPrefix)
2590 /* ^^^ https://fossil-scm.org/forum/forumpost/ff453de2f30791dd */
2591 ){
2592 style_submenu_element("Wiki", "%R/wiki?name=%s/%t", zPrefix, zName);
2593 }
2594 }
2595
2596 /*
2597
+1 -1
--- src/winhttp.c
+++ src/winhttp.c
@@ -1154,11 +1154,11 @@
11541154
"port number must be in the range 1 - 65535.");
11551155
}
11561156
if( !zRepository ){
11571157
db_must_be_within_tree();
11581158
}else if( file_isdir(zRepository, ExtFILE)==1 ){
1159
- g.zRepositoryName = mprintf("%s", zRepository);
1159
+ g.zRepositoryName = fossil_strdup(zRepository);
11601160
file_simplify_name(g.zRepositoryName, -1, 0);
11611161
}else{
11621162
db_open_repository(zRepository);
11631163
}
11641164
db_close(0);
11651165
--- src/winhttp.c
+++ src/winhttp.c
@@ -1154,11 +1154,11 @@
1154 "port number must be in the range 1 - 65535.");
1155 }
1156 if( !zRepository ){
1157 db_must_be_within_tree();
1158 }else if( file_isdir(zRepository, ExtFILE)==1 ){
1159 g.zRepositoryName = mprintf("%s", zRepository);
1160 file_simplify_name(g.zRepositoryName, -1, 0);
1161 }else{
1162 db_open_repository(zRepository);
1163 }
1164 db_close(0);
1165
--- src/winhttp.c
+++ src/winhttp.c
@@ -1154,11 +1154,11 @@
1154 "port number must be in the range 1 - 65535.");
1155 }
1156 if( !zRepository ){
1157 db_must_be_within_tree();
1158 }else if( file_isdir(zRepository, ExtFILE)==1 ){
1159 g.zRepositoryName = fossil_strdup(zRepository);
1160 file_simplify_name(g.zRepositoryName, -1, 0);
1161 }else{
1162 db_open_repository(zRepository);
1163 }
1164 db_close(0);
1165
+59 -15
--- src/xfer.c
+++ src/xfer.c
@@ -827,11 +827,11 @@
827827
int rc = -1;
828828
char *zLogin = blob_terminate(pLogin);
829829
defossilize(zLogin);
830830
831831
if( fossil_strcmp(zLogin, "nobody")==0
832
- || fossil_strcmp(zLogin,"anonymous")==0
832
+ || fossil_strcmp(zLogin, "anonymous")==0
833833
){
834834
return 0; /* Anybody is allowed to sync as "nobody" or "anonymous" */
835835
}
836836
if( fossil_strcmp(P("REMOTE_USER"), zLogin)==0
837837
&& db_get_boolean("remote_user_ok",0) ){
@@ -866,11 +866,11 @@
866866
const char *zPw = db_column_text(&q, 0);
867867
char *zSecret = sha1_shared_secret(zPw, blob_str(pLogin), 0);
868868
blob_zero(&combined);
869869
blob_copy(&combined, pNonce);
870870
blob_append(&combined, zSecret, -1);
871
- free(zSecret);
871
+ fossil_free(zSecret);
872872
sha1sum_blob(&combined, &hash);
873873
rc = blob_constant_time_cmp(&hash, pSig);
874874
blob_reset(&hash);
875875
blob_reset(&combined);
876876
}
@@ -1241,10 +1241,25 @@
12411241
/*
12421242
** If this variable is set, disable login checks. Used for debugging
12431243
** only.
12441244
*/
12451245
static int disableLogin = 0;
1246
+
1247
+/*
1248
+** Must be passed the version info from pragmas
1249
+** client-version/server-version cards. If the version info is "new
1250
+** enough" then the loginCardMode is ORd into the X-Fossil-Xfer-Login
1251
+** card flag, else this is a no-op.
1252
+*/
1253
+static void xfer_xflc_check(int iRemoteVersion, int iDate, int iTime,
1254
+ int fLoginCardMode){
1255
+ if( iRemoteVersion>=22700
1256
+ && (iDate > 20250727
1257
+ || (iDate == 20250727 && iTime >= 110500)) ){
1258
+ g.syncInfo.fLoginCardMode |= fLoginCardMode;
1259
+ }
1260
+}
12461261
12471262
/*
12481263
** The CGI/HTTP preprocessor always redirects requests with a content-type
12491264
** of application/x-fossil or application/x-fossil-debug to this page,
12501265
** regardless of what path was specified in the HTTP header. This allows
@@ -1273,10 +1288,11 @@
12731288
int nUuidList = 0;
12741289
char **pzUuidList = 0;
12751290
int *pnUuidList = 0;
12761291
int uvCatalogSent = 0;
12771292
int bSendLinks = 0;
1293
+ int nLogin = 0;
12781294
12791295
if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
12801296
fossil_redirect_home();
12811297
}
12821298
g.zLogin = "anonymous";
@@ -1314,10 +1330,24 @@
13141330
}
13151331
zScript = xfer_push_code();
13161332
if( zScript ){ /* NOTE: Are TH1 transfer hooks enabled? */
13171333
pzUuidList = &zUuidList;
13181334
pnUuidList = &nUuidList;
1335
+ }
1336
+ if( g.syncInfo.zLoginCard ){
1337
+ /* Login card received via HTTP Cookie header */
1338
+ assert( g.syncInfo.fLoginCardMode && "Set via HTTP cookie" );
1339
+ blob_zero(&xfer.line);
1340
+ blob_append(&xfer.line, g.syncInfo.zLoginCard, -1);
1341
+ xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken,
1342
+ count(xfer.aToken));
1343
+ fossil_free( g.syncInfo.zLoginCard );
1344
+ g.syncInfo.zLoginCard = 0;
1345
+ if( xfer.nToken==4
1346
+ && blob_eq(&xfer.aToken[0], "login") ){
1347
+ goto handle_login_card;
1348
+ }
13191349
}
13201350
while( blob_line(xfer.pIn, &xfer.line) ){
13211351
if( blob_buffer(&xfer.line)[0]=='#' ) continue;
13221352
if( blob_size(&xfer.line)==0 ) continue;
13231353
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
@@ -1523,10 +1553,11 @@
15231553
cgi_set_content_type("application/x-fossil-uncompressed");
15241554
}
15251555
blob_is_int(&xfer.aToken[2], &seqno);
15261556
if( seqno<=0 ){
15271557
xfer_fatal_error("invalid clone sequence number");
1558
+ db_rollback_transaction();
15281559
return;
15291560
}
15301561
max = db_int(0, "SELECT max(rid) FROM blob");
15311562
while( xfer.mxSend>(int)blob_size(xfer.pOut) && seqno<=max){
15321563
if( time(NULL) >= xfer.maxTime ) break;
@@ -1549,17 +1580,28 @@
15491580
15501581
/* login USER NONCE SIGNATURE
15511582
**
15521583
** The client has sent login credentials to the server.
15531584
** Validate the login. This has to happen before anything else.
1554
- ** The client can send multiple logins. Permissions are cumulative.
1585
+ **
1586
+ ** For many years, Fossil would accept multiple login cards with
1587
+ ** cumulative permissions. But that feature was never used. Hence
1588
+ ** it is now prohibited. Any login card after the first generates
1589
+ ** a fatal error.
15551590
*/
15561591
if( blob_eq(&xfer.aToken[0], "login")
15571592
&& xfer.nToken==4
15581593
){
1594
+ handle_login_card:
1595
+ nLogin++;
15591596
if( disableLogin ){
15601597
g.perm.Read = g.perm.Write = g.perm.Private = g.perm.Admin = 1;
1598
+ }else if( nLogin > 1 ){
1599
+ cgi_reset_content();
1600
+ @ error multiple\slogin\cards
1601
+ nErr++;
1602
+ break;
15611603
}else{
15621604
if( check_tail_hash(&xfer.aToken[2], xfer.pIn)
15631605
|| check_login(&xfer.aToken[1], &xfer.aToken[2], &xfer.aToken[3])
15641606
){
15651607
cgi_reset_content();
@@ -1598,10 +1640,11 @@
15981640
&& blob_is_int(&xfer.aToken[2], &size) ){
15991641
const char *zName = blob_str(&xfer.aToken[1]);
16001642
Blob content;
16011643
if( size<0 ){
16021644
xfer_fatal_error("invalid config record");
1645
+ db_rollback_transaction();
16031646
return;
16041647
}
16051648
blob_zero(&content);
16061649
blob_extract(xfer.pIn, size, &content);
16071650
if( !g.perm.Admin ){
@@ -1649,11 +1692,10 @@
16491692
}else{
16501693
xfer.nextIsPrivate = 1;
16511694
}
16521695
}else
16531696
1654
-
16551697
/* pragma NAME VALUE...
16561698
**
16571699
** The client issues pragmas to try to influence the behavior of the
16581700
** server. These are requests only. Unknown pragmas are silently
16591701
** ignored.
@@ -1692,17 +1734,20 @@
16921734
** The client announces to the server what version of Fossil it
16931735
** is running. The DATE and TIME are a pure numeric ISO8601 time
16941736
** for the specific check-in of the client.
16951737
*/
16961738
if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "client-version") ){
1697
- xfer.remoteVersion = atoi(blob_str(&xfer.aToken[2]));
1739
+ xfer.remoteVersion = g.syncInfo.remoteVersion =
1740
+ atoi(blob_str(&xfer.aToken[2]));
16981741
if( xfer.nToken>=5 ){
16991742
xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
17001743
xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
17011744
@ pragma server-version %d(RELEASE_VERSION_NUMBER) \
17021745
@ %d(MANIFEST_NUMERIC_DATE) %d(MANIFEST_NUMERIC_TIME)
17031746
}
1747
+ xfer_xflc_check( xfer.remoteVersion, xfer.remoteDate,
1748
+ xfer.remoteTime, 0x04 );
17041749
}else
17051750
17061751
/* pragma uv-hash HASH
17071752
**
17081753
** The client wants to make sure that unversioned files are all synced.
@@ -2339,18 +2384,17 @@
23392384
blob_appendf(&send, "pragma ci-lock %s %s\n", zCkinLock, zClientId);
23402385
zCkinLock = 0;
23412386
}else if( zClientId ){
23422387
blob_appendf(&send, "pragma ci-unlock %s\n", zClientId);
23432388
}
2344
-
23452389
/* Append randomness to the end of the uplink message. This makes all
23462390
** messages unique so that that the login-card nonce will always
23472391
** be unique.
23482392
*/
23492393
zRandomness = db_text(0, "SELECT hex(randomblob(20))");
23502394
blob_appendf(&send, "# %s\n", zRandomness);
2351
- free(zRandomness);
2395
+ fossil_free(zRandomness);
23522396
23532397
if( (syncFlags & SYNC_VERBOSE)!=0
23542398
&& (syncFlags & SYNC_XVERBOSE)==0
23552399
){
23562400
fossil_print("waiting for server...");
@@ -2382,17 +2426,17 @@
23822426
if( nCycle==0 && db_is_writeable("repository") ){
23832427
xfer_syncwith(g.url.canonical, 0);
23842428
}
23852429
23862430
/* Output current stats */
2431
+ nRoundtrip++;
2432
+ nArtifactSent += xfer.nFileSent + xfer.nDeltaSent;
23872433
if( syncFlags & SYNC_VERBOSE ){
23882434
fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
23892435
blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
23902436
xfer.nFileSent, xfer.nDeltaSent);
23912437
}else{
2392
- nRoundtrip++;
2393
- nArtifactSent += xfer.nFileSent + xfer.nDeltaSent;
23942438
if( bOutIsTty!=0 ){
23952439
fossil_print(zBriefFormat /*works-like:"%d%d%d"*/,
23962440
nRoundtrip, nArtifactSent, nArtifactRcvd);
23972441
}
23982442
}
@@ -2723,13 +2767,10 @@
27232767
27242768
/* message MESSAGE
27252769
**
27262770
** A message is received from the server. Print it.
27272771
** Similar to "error" but does not stop processing.
2728
- **
2729
- ** If the "login failed" message is seen, clear the sync password prior
2730
- ** to the next cycle.
27312772
*/
27322773
if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
27332774
char *zMsg = blob_terminate(&xfer.aToken[1]);
27342775
defossilize(zMsg);
27352776
if( (syncFlags & SYNC_PUSH) && zMsg
@@ -2755,15 +2796,18 @@
27552796
** The server announces to the server what version of Fossil it
27562797
** is running. The DATE and TIME are a pure numeric ISO8601 time
27572798
** for the specific check-in of the client.
27582799
*/
27592800
if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "server-version") ){
2760
- xfer.remoteVersion = atoi(blob_str(&xfer.aToken[2]));
2801
+ xfer.remoteVersion = g.syncInfo.remoteVersion =
2802
+ atoi(blob_str(&xfer.aToken[2]));
27612803
if( xfer.nToken>=5 ){
27622804
xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
27632805
xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
27642806
}
2807
+ xfer_xflc_check( xfer.remoteVersion, xfer.remoteDate,
2808
+ xfer.remoteTime, 0x08 );
27652809
}
27662810
27672811
/* pragma uv-pull-only
27682812
** pragma uv-push-ok
27692813
**
@@ -2894,11 +2938,11 @@
28942938
&recv
28952939
);
28962940
nErr++;
28972941
break;
28982942
}
2899
- blob_appendf(&xfer.err, "unknown command: [%b]\n", &xfer.aToken[0]);
2943
+ blob_appendf(&xfer.err, "unknown command: [%b]\n", &xfer.line);
29002944
}
29012945
29022946
if( blob_size(&xfer.err) ){
29032947
fossil_force_newline();
29042948
fossil_warning("%b", &xfer.err);
@@ -2961,11 +3005,11 @@
29613005
}else{
29623006
manifest_crosslink_end(MC_PERMIT_HOOKS);
29633007
content_enable_dephantomize(1);
29643008
}
29653009
db_end_transaction(0);
2966
- };
3010
+ }; /* while(go) */
29673011
transport_stats(&nSent, &nRcvd, 1);
29683012
if( pnRcvd ) *pnRcvd = nArtifactRcvd;
29693013
if( (rSkew*24.0*3600.0) > 10.0 ){
29703014
fossil_warning("*** time skew *** server is fast by %s",
29713015
db_timespan_name(rSkew));
29723016
--- src/xfer.c
+++ src/xfer.c
@@ -827,11 +827,11 @@
827 int rc = -1;
828 char *zLogin = blob_terminate(pLogin);
829 defossilize(zLogin);
830
831 if( fossil_strcmp(zLogin, "nobody")==0
832 || fossil_strcmp(zLogin,"anonymous")==0
833 ){
834 return 0; /* Anybody is allowed to sync as "nobody" or "anonymous" */
835 }
836 if( fossil_strcmp(P("REMOTE_USER"), zLogin)==0
837 && db_get_boolean("remote_user_ok",0) ){
@@ -866,11 +866,11 @@
866 const char *zPw = db_column_text(&q, 0);
867 char *zSecret = sha1_shared_secret(zPw, blob_str(pLogin), 0);
868 blob_zero(&combined);
869 blob_copy(&combined, pNonce);
870 blob_append(&combined, zSecret, -1);
871 free(zSecret);
872 sha1sum_blob(&combined, &hash);
873 rc = blob_constant_time_cmp(&hash, pSig);
874 blob_reset(&hash);
875 blob_reset(&combined);
876 }
@@ -1241,10 +1241,25 @@
1241 /*
1242 ** If this variable is set, disable login checks. Used for debugging
1243 ** only.
1244 */
1245 static int disableLogin = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1246
1247 /*
1248 ** The CGI/HTTP preprocessor always redirects requests with a content-type
1249 ** of application/x-fossil or application/x-fossil-debug to this page,
1250 ** regardless of what path was specified in the HTTP header. This allows
@@ -1273,10 +1288,11 @@
1273 int nUuidList = 0;
1274 char **pzUuidList = 0;
1275 int *pnUuidList = 0;
1276 int uvCatalogSent = 0;
1277 int bSendLinks = 0;
 
1278
1279 if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
1280 fossil_redirect_home();
1281 }
1282 g.zLogin = "anonymous";
@@ -1314,10 +1330,24 @@
1314 }
1315 zScript = xfer_push_code();
1316 if( zScript ){ /* NOTE: Are TH1 transfer hooks enabled? */
1317 pzUuidList = &zUuidList;
1318 pnUuidList = &nUuidList;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1319 }
1320 while( blob_line(xfer.pIn, &xfer.line) ){
1321 if( blob_buffer(&xfer.line)[0]=='#' ) continue;
1322 if( blob_size(&xfer.line)==0 ) continue;
1323 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
@@ -1523,10 +1553,11 @@
1523 cgi_set_content_type("application/x-fossil-uncompressed");
1524 }
1525 blob_is_int(&xfer.aToken[2], &seqno);
1526 if( seqno<=0 ){
1527 xfer_fatal_error("invalid clone sequence number");
 
1528 return;
1529 }
1530 max = db_int(0, "SELECT max(rid) FROM blob");
1531 while( xfer.mxSend>(int)blob_size(xfer.pOut) && seqno<=max){
1532 if( time(NULL) >= xfer.maxTime ) break;
@@ -1549,17 +1580,28 @@
1549
1550 /* login USER NONCE SIGNATURE
1551 **
1552 ** The client has sent login credentials to the server.
1553 ** Validate the login. This has to happen before anything else.
1554 ** The client can send multiple logins. Permissions are cumulative.
 
 
 
 
1555 */
1556 if( blob_eq(&xfer.aToken[0], "login")
1557 && xfer.nToken==4
1558 ){
 
 
1559 if( disableLogin ){
1560 g.perm.Read = g.perm.Write = g.perm.Private = g.perm.Admin = 1;
 
 
 
 
 
1561 }else{
1562 if( check_tail_hash(&xfer.aToken[2], xfer.pIn)
1563 || check_login(&xfer.aToken[1], &xfer.aToken[2], &xfer.aToken[3])
1564 ){
1565 cgi_reset_content();
@@ -1598,10 +1640,11 @@
1598 && blob_is_int(&xfer.aToken[2], &size) ){
1599 const char *zName = blob_str(&xfer.aToken[1]);
1600 Blob content;
1601 if( size<0 ){
1602 xfer_fatal_error("invalid config record");
 
1603 return;
1604 }
1605 blob_zero(&content);
1606 blob_extract(xfer.pIn, size, &content);
1607 if( !g.perm.Admin ){
@@ -1649,11 +1692,10 @@
1649 }else{
1650 xfer.nextIsPrivate = 1;
1651 }
1652 }else
1653
1654
1655 /* pragma NAME VALUE...
1656 **
1657 ** The client issues pragmas to try to influence the behavior of the
1658 ** server. These are requests only. Unknown pragmas are silently
1659 ** ignored.
@@ -1692,17 +1734,20 @@
1692 ** The client announces to the server what version of Fossil it
1693 ** is running. The DATE and TIME are a pure numeric ISO8601 time
1694 ** for the specific check-in of the client.
1695 */
1696 if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "client-version") ){
1697 xfer.remoteVersion = atoi(blob_str(&xfer.aToken[2]));
 
1698 if( xfer.nToken>=5 ){
1699 xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
1700 xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
1701 @ pragma server-version %d(RELEASE_VERSION_NUMBER) \
1702 @ %d(MANIFEST_NUMERIC_DATE) %d(MANIFEST_NUMERIC_TIME)
1703 }
 
 
1704 }else
1705
1706 /* pragma uv-hash HASH
1707 **
1708 ** The client wants to make sure that unversioned files are all synced.
@@ -2339,18 +2384,17 @@
2339 blob_appendf(&send, "pragma ci-lock %s %s\n", zCkinLock, zClientId);
2340 zCkinLock = 0;
2341 }else if( zClientId ){
2342 blob_appendf(&send, "pragma ci-unlock %s\n", zClientId);
2343 }
2344
2345 /* Append randomness to the end of the uplink message. This makes all
2346 ** messages unique so that that the login-card nonce will always
2347 ** be unique.
2348 */
2349 zRandomness = db_text(0, "SELECT hex(randomblob(20))");
2350 blob_appendf(&send, "# %s\n", zRandomness);
2351 free(zRandomness);
2352
2353 if( (syncFlags & SYNC_VERBOSE)!=0
2354 && (syncFlags & SYNC_XVERBOSE)==0
2355 ){
2356 fossil_print("waiting for server...");
@@ -2382,17 +2426,17 @@
2382 if( nCycle==0 && db_is_writeable("repository") ){
2383 xfer_syncwith(g.url.canonical, 0);
2384 }
2385
2386 /* Output current stats */
 
 
2387 if( syncFlags & SYNC_VERBOSE ){
2388 fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
2389 blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
2390 xfer.nFileSent, xfer.nDeltaSent);
2391 }else{
2392 nRoundtrip++;
2393 nArtifactSent += xfer.nFileSent + xfer.nDeltaSent;
2394 if( bOutIsTty!=0 ){
2395 fossil_print(zBriefFormat /*works-like:"%d%d%d"*/,
2396 nRoundtrip, nArtifactSent, nArtifactRcvd);
2397 }
2398 }
@@ -2723,13 +2767,10 @@
2723
2724 /* message MESSAGE
2725 **
2726 ** A message is received from the server. Print it.
2727 ** Similar to "error" but does not stop processing.
2728 **
2729 ** If the "login failed" message is seen, clear the sync password prior
2730 ** to the next cycle.
2731 */
2732 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
2733 char *zMsg = blob_terminate(&xfer.aToken[1]);
2734 defossilize(zMsg);
2735 if( (syncFlags & SYNC_PUSH) && zMsg
@@ -2755,15 +2796,18 @@
2755 ** The server announces to the server what version of Fossil it
2756 ** is running. The DATE and TIME are a pure numeric ISO8601 time
2757 ** for the specific check-in of the client.
2758 */
2759 if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "server-version") ){
2760 xfer.remoteVersion = atoi(blob_str(&xfer.aToken[2]));
 
2761 if( xfer.nToken>=5 ){
2762 xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
2763 xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
2764 }
 
 
2765 }
2766
2767 /* pragma uv-pull-only
2768 ** pragma uv-push-ok
2769 **
@@ -2894,11 +2938,11 @@
2894 &recv
2895 );
2896 nErr++;
2897 break;
2898 }
2899 blob_appendf(&xfer.err, "unknown command: [%b]\n", &xfer.aToken[0]);
2900 }
2901
2902 if( blob_size(&xfer.err) ){
2903 fossil_force_newline();
2904 fossil_warning("%b", &xfer.err);
@@ -2961,11 +3005,11 @@
2961 }else{
2962 manifest_crosslink_end(MC_PERMIT_HOOKS);
2963 content_enable_dephantomize(1);
2964 }
2965 db_end_transaction(0);
2966 };
2967 transport_stats(&nSent, &nRcvd, 1);
2968 if( pnRcvd ) *pnRcvd = nArtifactRcvd;
2969 if( (rSkew*24.0*3600.0) > 10.0 ){
2970 fossil_warning("*** time skew *** server is fast by %s",
2971 db_timespan_name(rSkew));
2972
--- src/xfer.c
+++ src/xfer.c
@@ -827,11 +827,11 @@
827 int rc = -1;
828 char *zLogin = blob_terminate(pLogin);
829 defossilize(zLogin);
830
831 if( fossil_strcmp(zLogin, "nobody")==0
832 || fossil_strcmp(zLogin, "anonymous")==0
833 ){
834 return 0; /* Anybody is allowed to sync as "nobody" or "anonymous" */
835 }
836 if( fossil_strcmp(P("REMOTE_USER"), zLogin)==0
837 && db_get_boolean("remote_user_ok",0) ){
@@ -866,11 +866,11 @@
866 const char *zPw = db_column_text(&q, 0);
867 char *zSecret = sha1_shared_secret(zPw, blob_str(pLogin), 0);
868 blob_zero(&combined);
869 blob_copy(&combined, pNonce);
870 blob_append(&combined, zSecret, -1);
871 fossil_free(zSecret);
872 sha1sum_blob(&combined, &hash);
873 rc = blob_constant_time_cmp(&hash, pSig);
874 blob_reset(&hash);
875 blob_reset(&combined);
876 }
@@ -1241,10 +1241,25 @@
1241 /*
1242 ** If this variable is set, disable login checks. Used for debugging
1243 ** only.
1244 */
1245 static int disableLogin = 0;
1246
1247 /*
1248 ** Must be passed the version info from pragmas
1249 ** client-version/server-version cards. If the version info is "new
1250 ** enough" then the loginCardMode is ORd into the X-Fossil-Xfer-Login
1251 ** card flag, else this is a no-op.
1252 */
1253 static void xfer_xflc_check(int iRemoteVersion, int iDate, int iTime,
1254 int fLoginCardMode){
1255 if( iRemoteVersion>=22700
1256 && (iDate > 20250727
1257 || (iDate == 20250727 && iTime >= 110500)) ){
1258 g.syncInfo.fLoginCardMode |= fLoginCardMode;
1259 }
1260 }
1261
1262 /*
1263 ** The CGI/HTTP preprocessor always redirects requests with a content-type
1264 ** of application/x-fossil or application/x-fossil-debug to this page,
1265 ** regardless of what path was specified in the HTTP header. This allows
@@ -1273,10 +1288,11 @@
1288 int nUuidList = 0;
1289 char **pzUuidList = 0;
1290 int *pnUuidList = 0;
1291 int uvCatalogSent = 0;
1292 int bSendLinks = 0;
1293 int nLogin = 0;
1294
1295 if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
1296 fossil_redirect_home();
1297 }
1298 g.zLogin = "anonymous";
@@ -1314,10 +1330,24 @@
1330 }
1331 zScript = xfer_push_code();
1332 if( zScript ){ /* NOTE: Are TH1 transfer hooks enabled? */
1333 pzUuidList = &zUuidList;
1334 pnUuidList = &nUuidList;
1335 }
1336 if( g.syncInfo.zLoginCard ){
1337 /* Login card received via HTTP Cookie header */
1338 assert( g.syncInfo.fLoginCardMode && "Set via HTTP cookie" );
1339 blob_zero(&xfer.line);
1340 blob_append(&xfer.line, g.syncInfo.zLoginCard, -1);
1341 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken,
1342 count(xfer.aToken));
1343 fossil_free( g.syncInfo.zLoginCard );
1344 g.syncInfo.zLoginCard = 0;
1345 if( xfer.nToken==4
1346 && blob_eq(&xfer.aToken[0], "login") ){
1347 goto handle_login_card;
1348 }
1349 }
1350 while( blob_line(xfer.pIn, &xfer.line) ){
1351 if( blob_buffer(&xfer.line)[0]=='#' ) continue;
1352 if( blob_size(&xfer.line)==0 ) continue;
1353 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
@@ -1523,10 +1553,11 @@
1553 cgi_set_content_type("application/x-fossil-uncompressed");
1554 }
1555 blob_is_int(&xfer.aToken[2], &seqno);
1556 if( seqno<=0 ){
1557 xfer_fatal_error("invalid clone sequence number");
1558 db_rollback_transaction();
1559 return;
1560 }
1561 max = db_int(0, "SELECT max(rid) FROM blob");
1562 while( xfer.mxSend>(int)blob_size(xfer.pOut) && seqno<=max){
1563 if( time(NULL) >= xfer.maxTime ) break;
@@ -1549,17 +1580,28 @@
1580
1581 /* login USER NONCE SIGNATURE
1582 **
1583 ** The client has sent login credentials to the server.
1584 ** Validate the login. This has to happen before anything else.
1585 **
1586 ** For many years, Fossil would accept multiple login cards with
1587 ** cumulative permissions. But that feature was never used. Hence
1588 ** it is now prohibited. Any login card after the first generates
1589 ** a fatal error.
1590 */
1591 if( blob_eq(&xfer.aToken[0], "login")
1592 && xfer.nToken==4
1593 ){
1594 handle_login_card:
1595 nLogin++;
1596 if( disableLogin ){
1597 g.perm.Read = g.perm.Write = g.perm.Private = g.perm.Admin = 1;
1598 }else if( nLogin > 1 ){
1599 cgi_reset_content();
1600 @ error multiple\slogin\cards
1601 nErr++;
1602 break;
1603 }else{
1604 if( check_tail_hash(&xfer.aToken[2], xfer.pIn)
1605 || check_login(&xfer.aToken[1], &xfer.aToken[2], &xfer.aToken[3])
1606 ){
1607 cgi_reset_content();
@@ -1598,10 +1640,11 @@
1640 && blob_is_int(&xfer.aToken[2], &size) ){
1641 const char *zName = blob_str(&xfer.aToken[1]);
1642 Blob content;
1643 if( size<0 ){
1644 xfer_fatal_error("invalid config record");
1645 db_rollback_transaction();
1646 return;
1647 }
1648 blob_zero(&content);
1649 blob_extract(xfer.pIn, size, &content);
1650 if( !g.perm.Admin ){
@@ -1649,11 +1692,10 @@
1692 }else{
1693 xfer.nextIsPrivate = 1;
1694 }
1695 }else
1696
 
1697 /* pragma NAME VALUE...
1698 **
1699 ** The client issues pragmas to try to influence the behavior of the
1700 ** server. These are requests only. Unknown pragmas are silently
1701 ** ignored.
@@ -1692,17 +1734,20 @@
1734 ** The client announces to the server what version of Fossil it
1735 ** is running. The DATE and TIME are a pure numeric ISO8601 time
1736 ** for the specific check-in of the client.
1737 */
1738 if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "client-version") ){
1739 xfer.remoteVersion = g.syncInfo.remoteVersion =
1740 atoi(blob_str(&xfer.aToken[2]));
1741 if( xfer.nToken>=5 ){
1742 xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
1743 xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
1744 @ pragma server-version %d(RELEASE_VERSION_NUMBER) \
1745 @ %d(MANIFEST_NUMERIC_DATE) %d(MANIFEST_NUMERIC_TIME)
1746 }
1747 xfer_xflc_check( xfer.remoteVersion, xfer.remoteDate,
1748 xfer.remoteTime, 0x04 );
1749 }else
1750
1751 /* pragma uv-hash HASH
1752 **
1753 ** The client wants to make sure that unversioned files are all synced.
@@ -2339,18 +2384,17 @@
2384 blob_appendf(&send, "pragma ci-lock %s %s\n", zCkinLock, zClientId);
2385 zCkinLock = 0;
2386 }else if( zClientId ){
2387 blob_appendf(&send, "pragma ci-unlock %s\n", zClientId);
2388 }
 
2389 /* Append randomness to the end of the uplink message. This makes all
2390 ** messages unique so that that the login-card nonce will always
2391 ** be unique.
2392 */
2393 zRandomness = db_text(0, "SELECT hex(randomblob(20))");
2394 blob_appendf(&send, "# %s\n", zRandomness);
2395 fossil_free(zRandomness);
2396
2397 if( (syncFlags & SYNC_VERBOSE)!=0
2398 && (syncFlags & SYNC_XVERBOSE)==0
2399 ){
2400 fossil_print("waiting for server...");
@@ -2382,17 +2426,17 @@
2426 if( nCycle==0 && db_is_writeable("repository") ){
2427 xfer_syncwith(g.url.canonical, 0);
2428 }
2429
2430 /* Output current stats */
2431 nRoundtrip++;
2432 nArtifactSent += xfer.nFileSent + xfer.nDeltaSent;
2433 if( syncFlags & SYNC_VERBOSE ){
2434 fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
2435 blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
2436 xfer.nFileSent, xfer.nDeltaSent);
2437 }else{
 
 
2438 if( bOutIsTty!=0 ){
2439 fossil_print(zBriefFormat /*works-like:"%d%d%d"*/,
2440 nRoundtrip, nArtifactSent, nArtifactRcvd);
2441 }
2442 }
@@ -2723,13 +2767,10 @@
2767
2768 /* message MESSAGE
2769 **
2770 ** A message is received from the server. Print it.
2771 ** Similar to "error" but does not stop processing.
 
 
 
2772 */
2773 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
2774 char *zMsg = blob_terminate(&xfer.aToken[1]);
2775 defossilize(zMsg);
2776 if( (syncFlags & SYNC_PUSH) && zMsg
@@ -2755,15 +2796,18 @@
2796 ** The server announces to the server what version of Fossil it
2797 ** is running. The DATE and TIME are a pure numeric ISO8601 time
2798 ** for the specific check-in of the client.
2799 */
2800 if( xfer.nToken>=3 && blob_eq(&xfer.aToken[1], "server-version") ){
2801 xfer.remoteVersion = g.syncInfo.remoteVersion =
2802 atoi(blob_str(&xfer.aToken[2]));
2803 if( xfer.nToken>=5 ){
2804 xfer.remoteDate = atoi(blob_str(&xfer.aToken[3]));
2805 xfer.remoteTime = atoi(blob_str(&xfer.aToken[4]));
2806 }
2807 xfer_xflc_check( xfer.remoteVersion, xfer.remoteDate,
2808 xfer.remoteTime, 0x08 );
2809 }
2810
2811 /* pragma uv-pull-only
2812 ** pragma uv-push-ok
2813 **
@@ -2894,11 +2938,11 @@
2938 &recv
2939 );
2940 nErr++;
2941 break;
2942 }
2943 blob_appendf(&xfer.err, "unknown command: [%b]\n", &xfer.line);
2944 }
2945
2946 if( blob_size(&xfer.err) ){
2947 fossil_force_newline();
2948 fossil_warning("%b", &xfer.err);
@@ -2961,11 +3005,11 @@
3005 }else{
3006 manifest_crosslink_end(MC_PERMIT_HOOKS);
3007 content_enable_dephantomize(1);
3008 }
3009 db_end_transaction(0);
3010 }; /* while(go) */
3011 transport_stats(&nSent, &nRcvd, 1);
3012 if( pnRcvd ) *pnRcvd = nArtifactRcvd;
3013 if( (rSkew*24.0*3600.0) > 10.0 ){
3014 fossil_warning("*** time skew *** server is fast by %s",
3015 db_timespan_name(rSkew));
3016
+110 -22
--- src/zip.c
+++ src/zip.c
@@ -496,11 +496,11 @@
496496
if( fossil_strcmp(zName, azDir[j])==0 ) break;
497497
}
498498
if( j>=nDir ){
499499
nDir++;
500500
azDir = fossil_realloc(azDir, sizeof(azDir[0])*nDir);
501
- azDir[j] = mprintf("%s", zName);
501
+ azDir[j] = fossil_strdup(zName);
502502
zip_add_file(p, zName, 0, 0);
503503
}
504504
zName[i+1] = c;
505505
}
506506
}
@@ -562,40 +562,128 @@
562562
fossil_free(azDir);
563563
nDir = 0;
564564
azDir = 0;
565565
}
566566
567
+/* Functions found in shell.c */
568
+extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*);
569
+extern int sqlite3_zipfile_init(sqlite3*,char**,const sqlite3_api_routines*);
570
+
567571
/*
568572
** COMMAND: test-filezip
569573
**
570
-** Generate a ZIP archive specified by the first argument that
571
-** contains files given in the second and subsequent arguments.
574
+** Usage: %fossil test-filezip [OPTIONS] ZIPFILE [FILENAME...]
575
+**
576
+** This command uses Fossil infrastructure or read or create a ZIP
577
+** archive named by the ZIPFILE argument. With no options, a new
578
+** ZIP archive is created and there must be at least one FILENAME
579
+** argument. If the -l option is used, the contents of the named ZIP
580
+** archive are listed on standard output. With the -x argument, the
581
+** contents of the ZIP archive are extracted.
582
+**
583
+** There are two purposes for this command: (1) To server as a test
584
+** platform for the Fossil ZIP archive generator, and (2) to provide
585
+** rudimentary ZIP archive creation capabilities on platforms that do
586
+** not have the "zip" command installed.
587
+**
588
+** Options:
589
+**
590
+** -h|--dereference Follow symlinks
591
+** -l|--list List the contents of the ZIP archive
592
+** -x|--extract Extract files from a ZIP archive
572593
*/
573594
void filezip_cmd(void){
574
- int i;
575
- Blob zip;
576
- Blob file;
577595
int eFType = SymFILE;
578
- Archive sArchive;
579
- memset(&sArchive, 0, sizeof(Archive));
580
- sArchive.eType = ARCHIVE_ZIP;
581
- sArchive.pBlob = &zip;
582
- if( g.argc<3 ){
583
- usage("ARCHIVE FILE....");
584
- }
596
+ int doList = 0;
597
+ int doExtract = 0;
598
+ char *zArchiveName;
585599
if( find_option("dereference","h",0)!=0 ){
586600
eFType = ExtFILE;
587601
}
588
- zip_open();
589
- for(i=3; i<g.argc; i++){
590
- blob_zero(&file);
591
- blob_read_from_file(&file, g.argv[i], eFType);
592
- zip_add_file(&sArchive, g.argv[i], &file, file_perm(0,eFType));
593
- blob_reset(&file);
594
- }
595
- zip_close(&sArchive);
596
- blob_write_to_file(&zip, g.argv[2]);
602
+ if( find_option("list","l",0)!=0 ){
603
+ doList = 1;
604
+ }
605
+ if( find_option("extract","x",0)!=0 ){
606
+ if( doList ){
607
+ fossil_fatal("incompatible options: -l and -x");
608
+ }
609
+ doExtract = 1;
610
+ }
611
+ if( g.argc<3 ){
612
+ usage("ARCHIVE FILES...");
613
+ }
614
+ zArchiveName = g.argv[2];
615
+ sqlite3_open(":memory:", &g.db);
616
+ if( doList ){
617
+ /* Do a content listing of a ZIP archive */
618
+ Stmt q;
619
+ int nRow = 0;
620
+ i64 szTotal = 0;
621
+ if( file_size(zArchiveName, eFType)<0 ){
622
+ fossil_fatal("No such ZIP archive: %s", zArchiveName);
623
+ }
624
+ if( g.argc>3 ){
625
+ fossil_fatal("extra arguments after \"fossil test-filezip -l ARCHIVE\"");
626
+ }
627
+ sqlite3_zipfile_init(g.db, 0, 0);
628
+ db_multi_exec("CREATE VIRTUAL TABLE z1 USING zipfile(%Q)", zArchiveName);
629
+ db_prepare(&q, "SELECT sz, datetime(mtime,'unixepoch'), name FROM z1");
630
+ while( db_step(&q)==SQLITE_ROW ){
631
+ int sz = db_column_int(&q, 0);
632
+ szTotal += sz;
633
+ if( nRow==0 ){
634
+ fossil_print(" Length Date Time Name\n");
635
+ fossil_print("--------- ---------- ----- ----\n");
636
+ }
637
+ nRow++;
638
+ fossil_print("%9d %.16s %s\n", sz, db_column_text(&q,1),
639
+ db_column_text(&q,2));
640
+ }
641
+ if( nRow ){
642
+ fossil_print("--------- --------\n");
643
+ fossil_print("%9lld %16s %d files\n", szTotal, "", nRow);
644
+ }
645
+ db_finalize(&q);
646
+ }else if( doExtract ){
647
+ /* Extract files from an existing ZIP archive */
648
+ if( file_size(zArchiveName, eFType)<0 ){
649
+ fossil_fatal("No such ZIP archive: %s", zArchiveName);
650
+ }
651
+ if( g.argc>3 ){
652
+ fossil_fatal("extra arguments after \"fossil test-filezip -x ARCHIVE\"");
653
+ }
654
+ sqlite3_zipfile_init(g.db, 0, 0);
655
+ sqlite3_fileio_init(g.db, 0, 0);
656
+ db_multi_exec("CREATE VIRTUAL TABLE z1 USING zipfile(%Q)", zArchiveName);
657
+ db_multi_exec("SELECT writefile(name,data) FROM z1");
658
+ }else{
659
+ /* Without the -x or -l options, construct a new ZIP archive */
660
+ int i;
661
+ Blob zip;
662
+ Blob file;
663
+ Archive sArchive;
664
+ memset(&sArchive, 0, sizeof(Archive));
665
+ sArchive.eType = ARCHIVE_ZIP;
666
+ sArchive.pBlob = &zip;
667
+ if( file_size(zArchiveName, eFType)>0 ){
668
+ fossil_fatal("ZIP archive %s already exists", zArchiveName);
669
+ }
670
+ zip_open();
671
+ for(i=3; i<g.argc; i++){
672
+ double rDate;
673
+ i64 iDate;
674
+ blob_zero(&file);
675
+ blob_read_from_file(&file, g.argv[i], eFType);
676
+ iDate = file_mtime(g.argv[i], eFType);
677
+ rDate = ((double)iDate)/86400.0 + 2440587.5;
678
+ zip_set_timedate(rDate);
679
+ zip_add_file(&sArchive, g.argv[i], &file, file_perm(0,eFType));
680
+ blob_reset(&file);
681
+ }
682
+ zip_close(&sArchive);
683
+ blob_write_to_file(&zip, g.argv[2]);
684
+ }
597685
}
598686
599687
/*
600688
** Given the RID for a manifest, construct a ZIP archive containing
601689
** all files in the corresponding baseline.
602690
603691
ADDED test/link-tester.html
604692
ADDED test/link-tester.js
605693
ADDED test/link-tester.json
--- src/zip.c
+++ src/zip.c
@@ -496,11 +496,11 @@
496 if( fossil_strcmp(zName, azDir[j])==0 ) break;
497 }
498 if( j>=nDir ){
499 nDir++;
500 azDir = fossil_realloc(azDir, sizeof(azDir[0])*nDir);
501 azDir[j] = mprintf("%s", zName);
502 zip_add_file(p, zName, 0, 0);
503 }
504 zName[i+1] = c;
505 }
506 }
@@ -562,40 +562,128 @@
562 fossil_free(azDir);
563 nDir = 0;
564 azDir = 0;
565 }
566
 
 
 
 
567 /*
568 ** COMMAND: test-filezip
569 **
570 ** Generate a ZIP archive specified by the first argument that
571 ** contains files given in the second and subsequent arguments.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572 */
573 void filezip_cmd(void){
574 int i;
575 Blob zip;
576 Blob file;
577 int eFType = SymFILE;
578 Archive sArchive;
579 memset(&sArchive, 0, sizeof(Archive));
580 sArchive.eType = ARCHIVE_ZIP;
581 sArchive.pBlob = &zip;
582 if( g.argc<3 ){
583 usage("ARCHIVE FILE....");
584 }
585 if( find_option("dereference","h",0)!=0 ){
586 eFType = ExtFILE;
587 }
588 zip_open();
589 for(i=3; i<g.argc; i++){
590 blob_zero(&file);
591 blob_read_from_file(&file, g.argv[i], eFType);
592 zip_add_file(&sArchive, g.argv[i], &file, file_perm(0,eFType));
593 blob_reset(&file);
594 }
595 zip_close(&sArchive);
596 blob_write_to_file(&zip, g.argv[2]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597 }
598
599 /*
600 ** Given the RID for a manifest, construct a ZIP archive containing
601 ** all files in the corresponding baseline.
602
603 DDED test/link-tester.html
604 DDED test/link-tester.js
605 DDED test/link-tester.json
--- src/zip.c
+++ src/zip.c
@@ -496,11 +496,11 @@
496 if( fossil_strcmp(zName, azDir[j])==0 ) break;
497 }
498 if( j>=nDir ){
499 nDir++;
500 azDir = fossil_realloc(azDir, sizeof(azDir[0])*nDir);
501 azDir[j] = fossil_strdup(zName);
502 zip_add_file(p, zName, 0, 0);
503 }
504 zName[i+1] = c;
505 }
506 }
@@ -562,40 +562,128 @@
562 fossil_free(azDir);
563 nDir = 0;
564 azDir = 0;
565 }
566
567 /* Functions found in shell.c */
568 extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*);
569 extern int sqlite3_zipfile_init(sqlite3*,char**,const sqlite3_api_routines*);
570
571 /*
572 ** COMMAND: test-filezip
573 **
574 ** Usage: %fossil test-filezip [OPTIONS] ZIPFILE [FILENAME...]
575 **
576 ** This command uses Fossil infrastructure or read or create a ZIP
577 ** archive named by the ZIPFILE argument. With no options, a new
578 ** ZIP archive is created and there must be at least one FILENAME
579 ** argument. If the -l option is used, the contents of the named ZIP
580 ** archive are listed on standard output. With the -x argument, the
581 ** contents of the ZIP archive are extracted.
582 **
583 ** There are two purposes for this command: (1) To server as a test
584 ** platform for the Fossil ZIP archive generator, and (2) to provide
585 ** rudimentary ZIP archive creation capabilities on platforms that do
586 ** not have the "zip" command installed.
587 **
588 ** Options:
589 **
590 ** -h|--dereference Follow symlinks
591 ** -l|--list List the contents of the ZIP archive
592 ** -x|--extract Extract files from a ZIP archive
593 */
594 void filezip_cmd(void){
 
 
 
595 int eFType = SymFILE;
596 int doList = 0;
597 int doExtract = 0;
598 char *zArchiveName;
 
 
 
 
599 if( find_option("dereference","h",0)!=0 ){
600 eFType = ExtFILE;
601 }
602 if( find_option("list","l",0)!=0 ){
603 doList = 1;
604 }
605 if( find_option("extract","x",0)!=0 ){
606 if( doList ){
607 fossil_fatal("incompatible options: -l and -x");
608 }
609 doExtract = 1;
610 }
611 if( g.argc<3 ){
612 usage("ARCHIVE FILES...");
613 }
614 zArchiveName = g.argv[2];
615 sqlite3_open(":memory:", &g.db);
616 if( doList ){
617 /* Do a content listing of a ZIP archive */
618 Stmt q;
619 int nRow = 0;
620 i64 szTotal = 0;
621 if( file_size(zArchiveName, eFType)<0 ){
622 fossil_fatal("No such ZIP archive: %s", zArchiveName);
623 }
624 if( g.argc>3 ){
625 fossil_fatal("extra arguments after \"fossil test-filezip -l ARCHIVE\"");
626 }
627 sqlite3_zipfile_init(g.db, 0, 0);
628 db_multi_exec("CREATE VIRTUAL TABLE z1 USING zipfile(%Q)", zArchiveName);
629 db_prepare(&q, "SELECT sz, datetime(mtime,'unixepoch'), name FROM z1");
630 while( db_step(&q)==SQLITE_ROW ){
631 int sz = db_column_int(&q, 0);
632 szTotal += sz;
633 if( nRow==0 ){
634 fossil_print(" Length Date Time Name\n");
635 fossil_print("--------- ---------- ----- ----\n");
636 }
637 nRow++;
638 fossil_print("%9d %.16s %s\n", sz, db_column_text(&q,1),
639 db_column_text(&q,2));
640 }
641 if( nRow ){
642 fossil_print("--------- --------\n");
643 fossil_print("%9lld %16s %d files\n", szTotal, "", nRow);
644 }
645 db_finalize(&q);
646 }else if( doExtract ){
647 /* Extract files from an existing ZIP archive */
648 if( file_size(zArchiveName, eFType)<0 ){
649 fossil_fatal("No such ZIP archive: %s", zArchiveName);
650 }
651 if( g.argc>3 ){
652 fossil_fatal("extra arguments after \"fossil test-filezip -x ARCHIVE\"");
653 }
654 sqlite3_zipfile_init(g.db, 0, 0);
655 sqlite3_fileio_init(g.db, 0, 0);
656 db_multi_exec("CREATE VIRTUAL TABLE z1 USING zipfile(%Q)", zArchiveName);
657 db_multi_exec("SELECT writefile(name,data) FROM z1");
658 }else{
659 /* Without the -x or -l options, construct a new ZIP archive */
660 int i;
661 Blob zip;
662 Blob file;
663 Archive sArchive;
664 memset(&sArchive, 0, sizeof(Archive));
665 sArchive.eType = ARCHIVE_ZIP;
666 sArchive.pBlob = &zip;
667 if( file_size(zArchiveName, eFType)>0 ){
668 fossil_fatal("ZIP archive %s already exists", zArchiveName);
669 }
670 zip_open();
671 for(i=3; i<g.argc; i++){
672 double rDate;
673 i64 iDate;
674 blob_zero(&file);
675 blob_read_from_file(&file, g.argv[i], eFType);
676 iDate = file_mtime(g.argv[i], eFType);
677 rDate = ((double)iDate)/86400.0 + 2440587.5;
678 zip_set_timedate(rDate);
679 zip_add_file(&sArchive, g.argv[i], &file, file_perm(0,eFType));
680 blob_reset(&file);
681 }
682 zip_close(&sArchive);
683 blob_write_to_file(&zip, g.argv[2]);
684 }
685 }
686
687 /*
688 ** Given the RID for a manifest, construct a ZIP archive containing
689 ** all files in the corresponding baseline.
690
691 DDED test/link-tester.html
692 DDED test/link-tester.js
693 DDED test/link-tester.json
--- a/test/link-tester.html
+++ b/test/link-tester.html
@@ -0,0 +1,82 @@
1
+<!DOCTYPE html>
2
+<head><!--
3
+ This file is intended to be loaded from a fossil
4
+ repository, either using:
5
+
6
+ fossil ui --extpage test/link-tester.html
7
+
8
+ or by adding test/link-tester.* to uv and then:
9
+
10
+ fossil ui -page uv/link-tester.html
11
+--></head>
12
+<style>
13
+ body {
14
+ width: 100%;
15
+ height: 100%;
16
+ margin: 0;
17
+ padding: 0;
18
+ display: flex;
19
+ flex-direction: column;
20
+ }
21
+ header {
22
+ margin: 0.5em 0 0 0;
23
+ padding: 0 1em 0 1em;
24
+ z-index: 1;
25
+ }
26
+ #controlWrapper {
27
+ display: flex;
28
+ flex-direction: row;
29
+ border-bottom: 2px dotted;
30
+ padding-bottom: 0.5em;
31
+ }
32
+ #controlWrapper > button {
33
+ flex-grow: 1;
34
+ margin: 0.5em;
35
+ }
36
+ #selectWrapper {
37
+ display: flex;
38
+ flex-direction: column;
39
+ flex-grow: 8;
40
+ }
41
+ #selectPage {
42
+ flex-grow: 1;
43
+ margin: 1em;
44
+ padding: 1em;
45
+ }
46
+ #currentUrl {
47
+ font-family: monospace;
48
+ text-align: center;
49
+ }
50
+ #iframe {
51
+ flex-grow: 1; border: none; margin: 0; padding: 0;
52
+ display: block;
53
+ /* Absolute positioning is apparently the only way to get
54
+ the iframe to stretch to fill the page, but we have to
55
+ set its Y coordinate to something a bit below #controls. */
56
+ width: 100%;
57
+ height: calc(100% - 5em);
58
+ position: absolute;
59
+ top: 4em;
60
+ }
61
+</style>
62
+<body>
63
+ <header>
64
+ Fossil link test app. Select links from the list below to load
65
+ them. Use the arrow keys to cycle through the list. The links are
66
+ loaded within an iframe, so navigation within it will stay within
67
+ that frame.
68
+ </header>
69
+ <header id='controlWrapper'>
70
+ <button id='btn-prev'>&larr;</button>
71
+ <div id='selectWrapper'>
72
+ <select id='selectPage'>
73
+ <option>/timeline</option>
74
+ <option>/dir</option>
75
+ </select>
76
+ <a target='_blank' id='currentUrl'></a>
77
+ </div>
78
+ <button id='btn-next'>&rarr;</button>
79
+ </header>
80
+ <iframe id='iframe'><!--populated via the UI--></iframe>
81
+ <script src='link-tester.js'></script>
82
+<body>
--- a/test/link-tester.html
+++ b/test/link-tester.html
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/link-tester.html
+++ b/test/link-tester.html
@@ -0,0 +1,82 @@
1 <!DOCTYPE html>
2 <head><!--
3 This file is intended to be loaded from a fossil
4 repository, either using:
5
6 fossil ui --extpage test/link-tester.html
7
8 or by adding test/link-tester.* to uv and then:
9
10 fossil ui -page uv/link-tester.html
11 --></head>
12 <style>
13 body {
14 width: 100%;
15 height: 100%;
16 margin: 0;
17 padding: 0;
18 display: flex;
19 flex-direction: column;
20 }
21 header {
22 margin: 0.5em 0 0 0;
23 padding: 0 1em 0 1em;
24 z-index: 1;
25 }
26 #controlWrapper {
27 display: flex;
28 flex-direction: row;
29 border-bottom: 2px dotted;
30 padding-bottom: 0.5em;
31 }
32 #controlWrapper > button {
33 flex-grow: 1;
34 margin: 0.5em;
35 }
36 #selectWrapper {
37 display: flex;
38 flex-direction: column;
39 flex-grow: 8;
40 }
41 #selectPage {
42 flex-grow: 1;
43 margin: 1em;
44 padding: 1em;
45 }
46 #currentUrl {
47 font-family: monospace;
48 text-align: center;
49 }
50 #iframe {
51 flex-grow: 1; border: none; margin: 0; padding: 0;
52 display: block;
53 /* Absolute positioning is apparently the only way to get
54 the iframe to stretch to fill the page, but we have to
55 set its Y coordinate to something a bit below #controls. */
56 width: 100%;
57 height: calc(100% - 5em);
58 position: absolute;
59 top: 4em;
60 }
61 </style>
62 <body>
63 <header>
64 Fossil link test app. Select links from the list below to load
65 them. Use the arrow keys to cycle through the list. The links are
66 loaded within an iframe, so navigation within it will stay within
67 that frame.
68 </header>
69 <header id='controlWrapper'>
70 <button id='btn-prev'>&larr;</button>
71 <div id='selectWrapper'>
72 <select id='selectPage'>
73 <option>/timeline</option>
74 <option>/dir</option>
75 </select>
76 <a target='_blank' id='currentUrl'></a>
77 </div>
78 <button id='btn-next'>&rarr;</button>
79 </header>
80 <iframe id='iframe'><!--populated via the UI--></iframe>
81 <script src='link-tester.js'></script>
82 <body>
--- a/test/link-tester.js
+++ b/test/link-tester.js
@@ -0,0 +1,224 @@
1
+/**
2
+ JS code for link-tester.html. We cannot host this JS inline in that
3
+ file because fossil's default Content Security Policy won't let it
4
+ run that way.
5
+*/
6
+window.addEventListener("DOMContentLoaded", function(){
7
+ const E = function(s){
8
+ const e = document.querySelector(s);
9
+ if( !e ) throw new Error("Missing element: "+s);
10
+ return e;
11
+ };
12
+ const EAll = function(s){
13
+ const e = document.querySelectorAll(s);
14
+ if( !e || !e.length ) throw new Error("Missing elements: "+s);
15
+ return e;
16
+ };
17
+ const eIframe = E('#iframe');
18
+ const eSelect = E('#selectPage');
19
+ const eCurrentUrl = E('#currentUrl');
20
+
21
+ /*
22
+ Prepend the fossil instance's URL to each link. We have to guess
23
+ which part of the URL is the fossil CGI/server instance. The
24
+ following works when run (A) from under /uv or /ext and (B) from
25
+ /doc/branchname/test/link-tester.html.
26
+ */
27
+ let urlTop;
28
+ let loc = (''+window.location);
29
+ let aLoc = loc.split('/')
30
+ aLoc.pop(); /* file name */
31
+ const thisDir = aLoc.join('/');
32
+ const rxDoc = /.*\/doc\/[^/]+\/.*/;
33
+ //console.log(rxDoc, loc, aLoc);
34
+ if( loc.match(rxDoc) ){
35
+ /* We're hopefully now at the top-most fossil-served
36
+ URL. */
37
+ aLoc.pop(); aLoc.pop(); /* /doc/foo */
38
+ aLoc.pop(); /* current dir name */
39
+ }else{
40
+ aLoc.pop(); /* current dir name */
41
+ }
42
+ urlTop = aLoc.join('/');
43
+ //console.log(urlTop, aLoc);
44
+ for( const o of eSelect.options ){
45
+ o.value = urlTop + (o.value || o.innerText);
46
+ }
47
+
48
+ const updateUrl = function(opt){
49
+ if( opt ){
50
+ let url = (opt.value || opt.innerText);
51
+ eCurrentUrl.innerText = url.replace(urlTop,'');
52
+ eCurrentUrl.setAttribute('href', url);
53
+ }else{
54
+ eCurrentUrl.innerText = '';
55
+ }
56
+ };
57
+
58
+ eSelect.addEventListener('change',function(ev){
59
+ const so = ev.target.options[ev.target.selectedIndex];
60
+ if( so ){
61
+ eIframe.setAttribute('src', so.value || so.innerText);
62
+ updateUrl(so);
63
+ }
64
+ });
65
+
66
+ /** Select the entry at the given ndx and fire a change event. */
67
+ const selectEntry = function(ndx){
68
+ if( ndx>=0 ){
69
+ eSelect.selectedIndex = ndx;
70
+ eSelect.dispatchEvent(new Event('change',{target:eSelect}));
71
+ }
72
+ };
73
+
74
+ /* Cycle to the next link in the list, accounting for separators and
75
+ wrapping around at either end. */
76
+ const cycleLink = function(dir/*<0 = prev, >0 = next*/){
77
+ let n = eSelect.selectedIndex + dir;
78
+ if( n < 0 ) n = eSelect.options.length-1;
79
+ else if( n>=eSelect.options.length ){
80
+ n = 0;
81
+ }
82
+ const opt = eSelect.options[n];
83
+ if( opt && opt.disabled ){
84
+ /* If that OPTION element is disabled, skip over it. */
85
+ eSelect.selectedIndex = n;
86
+ cycleLink(dir);
87
+ }else{
88
+ selectEntry(n);
89
+ }
90
+ };
91
+
92
+ E('#btn-prev').addEventListener('click', ()=>cycleLink(-1), false);
93
+ E('#btn-next').addEventListener('click', ()=>cycleLink(1), false);
94
+
95
+ /**
96
+ We have to adjust the iframe's size dynamically to account for
97
+ other widgets around it. iframes don't simply like to fill up all
98
+ available space without some help. If #controlWrapper only
99
+ contained the one SELECT element, CSS would be sufficient, but
100
+ once we add text around it, #controlWrapper's size becomes
101
+ unpredictable and we need JS to calculate it. We do this every
102
+ time the window size changes.
103
+ */
104
+ const effectiveHeight = function f(e){
105
+ // Copied from fossil.dom.js
106
+ if(!e) return 0;
107
+ if(!f.measure){
108
+ f.measure = function callee(e, depth){
109
+ if(!e) return;
110
+ const m = e.getBoundingClientRect();
111
+ if(0===depth){
112
+ callee.top = m.top;
113
+ callee.bottom = m.bottom;
114
+ }else{
115
+ callee.top = m.top ? Math.min(callee.top, m.top) : callee.top;
116
+ callee.bottom = Math.max(callee.bottom, m.bottom);
117
+ }
118
+ Array.prototype.forEach.call(e.children,(e)=>callee(e,depth+1));
119
+ if(0===depth){
120
+ //console.debug("measure() height:",e.className, callee.top, callee.bottom, (callee.bottom - callee.top));
121
+ f.extra += callee.bottom - callee.top;
122
+ }
123
+ return f.extra;
124
+ };
125
+ }
126
+ f.extra = 0;
127
+ f.measure(e,0);
128
+ return f.extra;
129
+ };
130
+
131
+ /* Helper for the window-resized event handler below, to avoid
132
+ handling the resize until after it's finished. */
133
+ const debounce = function f(func, waitMs, immediate) {
134
+ // Copied from fossil.bootstrap.js
135
+ var timeoutId;
136
+ if(!waitMs) waitMs = f.$defaultDelay;
137
+ return function() {
138
+ const context = this, args = Array.prototype.slice.call(arguments);
139
+ const later = function() {
140
+ timeoutId = undefined;
141
+ if(!immediate) func.apply(context, args);
142
+ };
143
+ const callNow = immediate && !timeoutId;
144
+ clearTimeout(timeoutId);
145
+ timeoutId = setTimeout(later, waitMs);
146
+ if(callNow) func.apply(context, args);
147
+ };
148
+ };
149
+
150
+ /**
151
+ Resize eConstrained (the ifame element) so that it fits within
152
+ the page space not occupied by the list of elements eToAvoid.
153
+ */
154
+ const ForceResizeKludge = (function(eToAvoid, eConstrained){
155
+ const resized = function f(){
156
+ if( f.$disabled ) return;
157
+ const wh = window.innerHeight;
158
+ let ht;
159
+ let extra = 0;
160
+ eToAvoid.forEach((e)=>e ? extra += effectiveHeight(e) : false);
161
+ ht = wh - extra;
162
+ if( ht < 100 ) ht = 100;
163
+ eConstrained.style.top = 'calc('+extra+'px + 2em)';
164
+ eConstrained.style.height =
165
+ eConstrained.style.maxHeight = "calc("+ ht+ "px - 2em)";
166
+ };
167
+ resized.$disabled = true/* gets deleted later */;
168
+ window.addEventListener('resize', debounce(resized, 250), false);
169
+ return resized;
170
+ })(
171
+ EAll('body > *:not(iframe)'),
172
+ eIframe
173
+ );
174
+
175
+ delete ForceResizeKludge.$disabled;
176
+ ForceResizeKludge();
177
+
178
+ selectEntry(0);
179
+
180
+ /**
181
+ Read link-tester.json, which should live in the same directory
182
+ as this file. It's expected to be an array with entries
183
+ in one of the following forms:
184
+
185
+ - "string" = Separator label (disabled)
186
+ - ["/path"] = path with itself as a label
187
+ - ["label", "/path"] = path with the given label
188
+
189
+ All paths are expected to have a "/" prefix and this script
190
+ accounts for mapping that to the fossil part of this script's
191
+ URL.
192
+ */
193
+ window.fetch(thisDir+'/link-tester.json').then((r)=>r.json()).then(j=>{
194
+ //console.log("fetched",j);
195
+ eSelect.innerHTML = '';
196
+ const opt = function(arg){
197
+ const o = document.createElement('option');
198
+ //console.warn(arguments);
199
+ let rc = true;
200
+ if( 'string' === typeof arg ){
201
+ /* Grouping separator */
202
+ o.innerText = "--- " + arg + " ---";
203
+ o.setAttribute('disabled','');
204
+ rc = false;
205
+ }else if( 1===arg.length ){
206
+ o.innerText = arg[0];
207
+ o.value = urlTop + arg[0];
208
+ }else if( 2==arg.length ){
209
+ o.innerText = arg[0];
210
+ o.value = urlTop + arg[1];
211
+ }
212
+ eSelect.appendChild(o);
213
+ return rc;
214
+ };
215
+ let ndx = -1/*index of first non-disabled entry*/, i = 0;
216
+ for(const e of j){
217
+ if( opt(e) && ndx<0 ){
218
+ ndx = i;
219
+ }
220
+ ++i;
221
+ }
222
+ selectEntry(ndx);
223
+ });
224
+});
--- a/test/link-tester.js
+++ b/test/link-tester.js
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/link-tester.js
+++ b/test/link-tester.js
@@ -0,0 +1,224 @@
1 /**
2 JS code for link-tester.html. We cannot host this JS inline in that
3 file because fossil's default Content Security Policy won't let it
4 run that way.
5 */
6 window.addEventListener("DOMContentLoaded", function(){
7 const E = function(s){
8 const e = document.querySelector(s);
9 if( !e ) throw new Error("Missing element: "+s);
10 return e;
11 };
12 const EAll = function(s){
13 const e = document.querySelectorAll(s);
14 if( !e || !e.length ) throw new Error("Missing elements: "+s);
15 return e;
16 };
17 const eIframe = E('#iframe');
18 const eSelect = E('#selectPage');
19 const eCurrentUrl = E('#currentUrl');
20
21 /*
22 Prepend the fossil instance's URL to each link. We have to guess
23 which part of the URL is the fossil CGI/server instance. The
24 following works when run (A) from under /uv or /ext and (B) from
25 /doc/branchname/test/link-tester.html.
26 */
27 let urlTop;
28 let loc = (''+window.location);
29 let aLoc = loc.split('/')
30 aLoc.pop(); /* file name */
31 const thisDir = aLoc.join('/');
32 const rxDoc = /.*\/doc\/[^/]+\/.*/;
33 //console.log(rxDoc, loc, aLoc);
34 if( loc.match(rxDoc) ){
35 /* We're hopefully now at the top-most fossil-served
36 URL. */
37 aLoc.pop(); aLoc.pop(); /* /doc/foo */
38 aLoc.pop(); /* current dir name */
39 }else{
40 aLoc.pop(); /* current dir name */
41 }
42 urlTop = aLoc.join('/');
43 //console.log(urlTop, aLoc);
44 for( const o of eSelect.options ){
45 o.value = urlTop + (o.value || o.innerText);
46 }
47
48 const updateUrl = function(opt){
49 if( opt ){
50 let url = (opt.value || opt.innerText);
51 eCurrentUrl.innerText = url.replace(urlTop,'');
52 eCurrentUrl.setAttribute('href', url);
53 }else{
54 eCurrentUrl.innerText = '';
55 }
56 };
57
58 eSelect.addEventListener('change',function(ev){
59 const so = ev.target.options[ev.target.selectedIndex];
60 if( so ){
61 eIframe.setAttribute('src', so.value || so.innerText);
62 updateUrl(so);
63 }
64 });
65
66 /** Select the entry at the given ndx and fire a change event. */
67 const selectEntry = function(ndx){
68 if( ndx>=0 ){
69 eSelect.selectedIndex = ndx;
70 eSelect.dispatchEvent(new Event('change',{target:eSelect}));
71 }
72 };
73
74 /* Cycle to the next link in the list, accounting for separators and
75 wrapping around at either end. */
76 const cycleLink = function(dir/*<0 = prev, >0 = next*/){
77 let n = eSelect.selectedIndex + dir;
78 if( n < 0 ) n = eSelect.options.length-1;
79 else if( n>=eSelect.options.length ){
80 n = 0;
81 }
82 const opt = eSelect.options[n];
83 if( opt && opt.disabled ){
84 /* If that OPTION element is disabled, skip over it. */
85 eSelect.selectedIndex = n;
86 cycleLink(dir);
87 }else{
88 selectEntry(n);
89 }
90 };
91
92 E('#btn-prev').addEventListener('click', ()=>cycleLink(-1), false);
93 E('#btn-next').addEventListener('click', ()=>cycleLink(1), false);
94
95 /**
96 We have to adjust the iframe's size dynamically to account for
97 other widgets around it. iframes don't simply like to fill up all
98 available space without some help. If #controlWrapper only
99 contained the one SELECT element, CSS would be sufficient, but
100 once we add text around it, #controlWrapper's size becomes
101 unpredictable and we need JS to calculate it. We do this every
102 time the window size changes.
103 */
104 const effectiveHeight = function f(e){
105 // Copied from fossil.dom.js
106 if(!e) return 0;
107 if(!f.measure){
108 f.measure = function callee(e, depth){
109 if(!e) return;
110 const m = e.getBoundingClientRect();
111 if(0===depth){
112 callee.top = m.top;
113 callee.bottom = m.bottom;
114 }else{
115 callee.top = m.top ? Math.min(callee.top, m.top) : callee.top;
116 callee.bottom = Math.max(callee.bottom, m.bottom);
117 }
118 Array.prototype.forEach.call(e.children,(e)=>callee(e,depth+1));
119 if(0===depth){
120 //console.debug("measure() height:",e.className, callee.top, callee.bottom, (callee.bottom - callee.top));
121 f.extra += callee.bottom - callee.top;
122 }
123 return f.extra;
124 };
125 }
126 f.extra = 0;
127 f.measure(e,0);
128 return f.extra;
129 };
130
131 /* Helper for the window-resized event handler below, to avoid
132 handling the resize until after it's finished. */
133 const debounce = function f(func, waitMs, immediate) {
134 // Copied from fossil.bootstrap.js
135 var timeoutId;
136 if(!waitMs) waitMs = f.$defaultDelay;
137 return function() {
138 const context = this, args = Array.prototype.slice.call(arguments);
139 const later = function() {
140 timeoutId = undefined;
141 if(!immediate) func.apply(context, args);
142 };
143 const callNow = immediate && !timeoutId;
144 clearTimeout(timeoutId);
145 timeoutId = setTimeout(later, waitMs);
146 if(callNow) func.apply(context, args);
147 };
148 };
149
150 /**
151 Resize eConstrained (the ifame element) so that it fits within
152 the page space not occupied by the list of elements eToAvoid.
153 */
154 const ForceResizeKludge = (function(eToAvoid, eConstrained){
155 const resized = function f(){
156 if( f.$disabled ) return;
157 const wh = window.innerHeight;
158 let ht;
159 let extra = 0;
160 eToAvoid.forEach((e)=>e ? extra += effectiveHeight(e) : false);
161 ht = wh - extra;
162 if( ht < 100 ) ht = 100;
163 eConstrained.style.top = 'calc('+extra+'px + 2em)';
164 eConstrained.style.height =
165 eConstrained.style.maxHeight = "calc("+ ht+ "px - 2em)";
166 };
167 resized.$disabled = true/* gets deleted later */;
168 window.addEventListener('resize', debounce(resized, 250), false);
169 return resized;
170 })(
171 EAll('body > *:not(iframe)'),
172 eIframe
173 );
174
175 delete ForceResizeKludge.$disabled;
176 ForceResizeKludge();
177
178 selectEntry(0);
179
180 /**
181 Read link-tester.json, which should live in the same directory
182 as this file. It's expected to be an array with entries
183 in one of the following forms:
184
185 - "string" = Separator label (disabled)
186 - ["/path"] = path with itself as a label
187 - ["label", "/path"] = path with the given label
188
189 All paths are expected to have a "/" prefix and this script
190 accounts for mapping that to the fossil part of this script's
191 URL.
192 */
193 window.fetch(thisDir+'/link-tester.json').then((r)=>r.json()).then(j=>{
194 //console.log("fetched",j);
195 eSelect.innerHTML = '';
196 const opt = function(arg){
197 const o = document.createElement('option');
198 //console.warn(arguments);
199 let rc = true;
200 if( 'string' === typeof arg ){
201 /* Grouping separator */
202 o.innerText = "--- " + arg + " ---";
203 o.setAttribute('disabled','');
204 rc = false;
205 }else if( 1===arg.length ){
206 o.innerText = arg[0];
207 o.value = urlTop + arg[0];
208 }else if( 2==arg.length ){
209 o.innerText = arg[0];
210 o.value = urlTop + arg[1];
211 }
212 eSelect.appendChild(o);
213 return rc;
214 };
215 let ndx = -1/*index of first non-disabled entry*/, i = 0;
216 for(const e of j){
217 if( opt(e) && ndx<0 ){
218 ndx = i;
219 }
220 ++i;
221 }
222 selectEntry(ndx);
223 });
224 });
--- a/test/link-tester.json
+++ b/test/link-tester.json
@@ -0,0 +1,68 @@
1
+[
2
+ "Timelines",
3
+ ["Default", "/timeline"],
4
+ ["anonymous", "/timeline?u=anonymous&y=a"],
5
+ ["after date/time", "/timeline?n=12&y=ci&a=2024-12-31T20:29Z"],
6
+ ["after hash", "/timeline?n=12&y=ci&a=3cb092c0e2f0ff26"],
7
+ ["before date/time", "/timeline?n=12&y=ci&b=2024-12-31T20:30Z"],
8
+ ["before hash", "/timeline?n=12&y=ci&b=3cb092c0e2f0ff26"],
9
+ ["circa date/time", "/timeline?n=12&y=ci&c=2024-12-31T20:29Z"],
10
+ ["circa hash", "/timeline?n=12&y=ci&c=3cb092c0e2f0ff26"],
11
+ ["d=,p=", "/timeline?d=version-2.25&p=version-2.26"],
12
+ ["from=,ft=", "/timeline?from=2765f04694d36e68&ft=release"],
13
+ ["from=,ft=,min", "/timeline?from=2765f04694d36e68&ft=release&min"],
14
+ ["from=,to=", "/timeline?from=version-2.25&to=version-2.26"],
15
+ ["from=,to=,min", "/timeline?from=version-2.25&to=version-2.26&min"],
16
+ ["omit-cr branch", "/timeline?r=omit-cr&m&c=7e97f4999b16ab75"],
17
+ ["diff-eolws branch", "/timeline?r=diff-eolws&n=50"],
18
+ ["Shortest path (from=,to=)",
19
+ "/timeline?from=e663bac6f7&to=a298a0e2f9&shortest"],
20
+ ["Common Ancestor (me=,you=)",
21
+ "/timeline?me=e663bac6f7&you=a298a0e2f9"],
22
+
23
+ "Diff",
24
+ ["Multiple edits on a single line", "/info/030035345c#chunk73"],
25
+ ["Tricky alignment, multiple edits per line",
26
+ "/fdiff?v1=6da016415dc52d61&v2=af6df3466e3c4a88"],
27
+ ["Column alignment with multibyte characters",
28
+ "/fdiff?v1=d1c60722e0b9d775&v2=58d1a8991bacb113"],
29
+ ["Large diff of sqlite3.c - was once very slow",
30
+ "/fdiff?v1=57b0d8183cab0e3d&v2=37b3ef49d73cdfe6"],
31
+ ["A difficult indentation change", "/info/bda00cbada#chunk49"],
32
+ ["Inverse of the previous",
33
+ "/fdiff?v1=bc8100c9ee01b8c2&v2=1d2acc1a2a65c2bf#chunk42"],
34
+ ["Another tricky indentation",
35
+ "/fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk13"],
36
+ ["Inverse of the previous",
37
+ "/fdiff?v2=955cc67ace8fb622&v1=e2e1c87b86664b45#chunk13"],
38
+ ["A tricky alignment",
39
+ "/fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk24"],
40
+ ["sqlite3.c changes that are difficult to align",
41
+ "/fdiff?v1=21f9a00fe2fa4a17&v2=d5c4ff0532bd89c3#chunk5"],
42
+ ["Lorem Ipsum in Greek", "/fdiff?v1=4f70c682e44f&v2=55659c6e062994f"],
43
+ ["Inverted Greek Lorem Ipsum", "/fdiff?v2=4f70c682e44f&v1=55659c6e062994f"],
44
+
45
+ "Infos",
46
+ ["Merge riser coalescing #1", "/info/eed3946bd92a499?diff=0"],
47
+ ["Merge riser coalescing #2", "/info/ef6979eac9abded?diff=0"],
48
+ ["Merge riser coalescing #3", "/info/9e1fa626e47f147?diff=0"],
49
+ ["Merge riser coalescing #4", "/info/68bd2e7bedb8d05?diff=0"],
50
+ ["Merge riser coalescing #5", "/info/7766e689926c703?diff=0"],
51
+ ["Merge riser coalescing #6", "/info/3ea66260b5555d2?diff=0"],
52
+ ["Merge riser coalescing #7", "/info/66ae70a54b20656?diff=0"],
53
+ ["Context graph #1", "/info/b0f2a0ac53926c9?diff=0"],
54
+ ["Context graph #2", "/info/303e7af7c31866c?diff=0"],
55
+ ["Context graph #3", "/info/b31afcc2cab1dc4?diff=0"],
56
+ ["Context graph #4", "/info/1a164e5fb76a46b?diff=0"],
57
+ ["Context graph #5", "/info/2d75e87b760c0a9?diff=0"],
58
+ ["Context graph #6", "/info/76442af7e13267bd?diff=0"],
59
+ ["Info about the tip", "/info/tip"],
60
+ ["/info/tip"],
61
+
62
+ "Admin",
63
+ ["Users", "/setup_ulist"],
64
+
65
+ "Misc.",
66
+ ["/skins"],
67
+ ["/chat"]
68
+]
--- a/test/link-tester.json
+++ b/test/link-tester.json
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/link-tester.json
+++ b/test/link-tester.json
@@ -0,0 +1,68 @@
1 [
2 "Timelines",
3 ["Default", "/timeline"],
4 ["anonymous", "/timeline?u=anonymous&y=a"],
5 ["after date/time", "/timeline?n=12&y=ci&a=2024-12-31T20:29Z"],
6 ["after hash", "/timeline?n=12&y=ci&a=3cb092c0e2f0ff26"],
7 ["before date/time", "/timeline?n=12&y=ci&b=2024-12-31T20:30Z"],
8 ["before hash", "/timeline?n=12&y=ci&b=3cb092c0e2f0ff26"],
9 ["circa date/time", "/timeline?n=12&y=ci&c=2024-12-31T20:29Z"],
10 ["circa hash", "/timeline?n=12&y=ci&c=3cb092c0e2f0ff26"],
11 ["d=,p=", "/timeline?d=version-2.25&p=version-2.26"],
12 ["from=,ft=", "/timeline?from=2765f04694d36e68&ft=release"],
13 ["from=,ft=,min", "/timeline?from=2765f04694d36e68&ft=release&min"],
14 ["from=,to=", "/timeline?from=version-2.25&to=version-2.26"],
15 ["from=,to=,min", "/timeline?from=version-2.25&to=version-2.26&min"],
16 ["omit-cr branch", "/timeline?r=omit-cr&m&c=7e97f4999b16ab75"],
17 ["diff-eolws branch", "/timeline?r=diff-eolws&n=50"],
18 ["Shortest path (from=,to=)",
19 "/timeline?from=e663bac6f7&to=a298a0e2f9&shortest"],
20 ["Common Ancestor (me=,you=)",
21 "/timeline?me=e663bac6f7&you=a298a0e2f9"],
22
23 "Diff",
24 ["Multiple edits on a single line", "/info/030035345c#chunk73"],
25 ["Tricky alignment, multiple edits per line",
26 "/fdiff?v1=6da016415dc52d61&v2=af6df3466e3c4a88"],
27 ["Column alignment with multibyte characters",
28 "/fdiff?v1=d1c60722e0b9d775&v2=58d1a8991bacb113"],
29 ["Large diff of sqlite3.c - was once very slow",
30 "/fdiff?v1=57b0d8183cab0e3d&v2=37b3ef49d73cdfe6"],
31 ["A difficult indentation change", "/info/bda00cbada#chunk49"],
32 ["Inverse of the previous",
33 "/fdiff?v1=bc8100c9ee01b8c2&v2=1d2acc1a2a65c2bf#chunk42"],
34 ["Another tricky indentation",
35 "/fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk13"],
36 ["Inverse of the previous",
37 "/fdiff?v2=955cc67ace8fb622&v1=e2e1c87b86664b45#chunk13"],
38 ["A tricky alignment",
39 "/fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk24"],
40 ["sqlite3.c changes that are difficult to align",
41 "/fdiff?v1=21f9a00fe2fa4a17&v2=d5c4ff0532bd89c3#chunk5"],
42 ["Lorem Ipsum in Greek", "/fdiff?v1=4f70c682e44f&v2=55659c6e062994f"],
43 ["Inverted Greek Lorem Ipsum", "/fdiff?v2=4f70c682e44f&v1=55659c6e062994f"],
44
45 "Infos",
46 ["Merge riser coalescing #1", "/info/eed3946bd92a499?diff=0"],
47 ["Merge riser coalescing #2", "/info/ef6979eac9abded?diff=0"],
48 ["Merge riser coalescing #3", "/info/9e1fa626e47f147?diff=0"],
49 ["Merge riser coalescing #4", "/info/68bd2e7bedb8d05?diff=0"],
50 ["Merge riser coalescing #5", "/info/7766e689926c703?diff=0"],
51 ["Merge riser coalescing #6", "/info/3ea66260b5555d2?diff=0"],
52 ["Merge riser coalescing #7", "/info/66ae70a54b20656?diff=0"],
53 ["Context graph #1", "/info/b0f2a0ac53926c9?diff=0"],
54 ["Context graph #2", "/info/303e7af7c31866c?diff=0"],
55 ["Context graph #3", "/info/b31afcc2cab1dc4?diff=0"],
56 ["Context graph #4", "/info/1a164e5fb76a46b?diff=0"],
57 ["Context graph #5", "/info/2d75e87b760c0a9?diff=0"],
58 ["Context graph #6", "/info/76442af7e13267bd?diff=0"],
59 ["Info about the tip", "/info/tip"],
60 ["/info/tip"],
61
62 "Admin",
63 ["Users", "/setup_ulist"],
64
65 "Misc.",
66 ["/skins"],
67 ["/chat"]
68 ]
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -245,10 +245,11 @@
245245
-DSQLITE_ENABLE_DBSTAT_VTAB
246246
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
247247
-DSQLITE_ENABLE_FTS4
248248
-DSQLITE_ENABLE_FTS5
249249
-DSQLITE_ENABLE_MATH_FUNCTIONS
250
+ -DSQLITE_ENABLE_SETLK_TIMEOUT
250251
-DSQLITE_ENABLE_STMTVTAB
251252
-DSQLITE_HAVE_ZLIB
252253
-DSQLITE_ENABLE_DBPAGE_VTAB
253254
-DSQLITE_TRUSTED_SCHEMA=0
254255
-DHAVE_USLEEP
@@ -368,39 +369,41 @@
368369
writeln [string map [list \
369370
<<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
370371
<<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
371372
<<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
372373
<<<NEXT_LINE>>> \\] {
373
-all: $(OBJDIR) $(APPNAME)
374
+all: $(APPNAME)
374375
375376
install: all
376377
mkdir -p $(INSTALLDIR)
377378
cp $(APPNAME) $(INSTALLDIR)
378379
379380
codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
380381
$(OBJDIR)/codecheck1 $(TRANS_SRC)
381382
382
-$(OBJDIR):
383
- -mkdir $(OBJDIR)
384
-
385383
$(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
386384
-mkdir -p $(OBJDIR)
387385
$(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
388386
389387
$(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
388
+ -mkdir -p $(OBJDIR)
390389
$(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
391390
392391
$(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
392
+ -mkdir -p $(OBJDIR)
393393
$(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
394394
395395
$(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
396
+ -mkdir -p $(OBJDIR)
396397
$(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
397398
398399
$(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
400
+ -mkdir -p $(OBJDIR)
399401
$(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
400402
401403
$(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
404
+ -mkdir -p $(OBJDIR)
402405
$(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
403406
404407
# Run the test suite.
405408
# Other flags that can be included in TESTFLAGS are:
406409
#
@@ -412,11 +415,11 @@
412415
# -strict Treat known bugs as failures
413416
#
414417
# TESTFLAGS can also include names of specific test files to limit
415418
# the run to just those test cases.
416419
#
417
-test: $(OBJDIR) $(APPNAME)
420
+test: $(APPNAME)
418421
$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
419422
420423
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
421424
$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid <<<NEXT_LINE>>>
422425
$(SRCDIR)/../manifest <<<NEXT_LINE>>>
@@ -552,23 +555,26 @@
552555
553556
writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h"
554557
writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n"
555558
556559
writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
560
+writeln "\t-mkdir -p \$(OBJDIR)\n"
557561
writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n"
558562
559563
writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
564
+writeln "\t-mkdir -p \$(OBJDIR)\n"
560565
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
561566
562567
writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
568
+writeln "\t-mkdir -p \$(OBJDIR)\n"
563569
writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
564570
565571
writeln [string map [list <<<NEXT_LINE>>> \\] {
566
-$(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
572
+$(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c $(OBJDIR)/mkversion
567573
$(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
568574
569
-$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
575
+$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c $(OBJDIR)/mkversion
570576
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
571577
572578
$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
573579
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
574580
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575581
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -245,10 +245,11 @@
245 -DSQLITE_ENABLE_DBSTAT_VTAB
246 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
247 -DSQLITE_ENABLE_FTS4
248 -DSQLITE_ENABLE_FTS5
249 -DSQLITE_ENABLE_MATH_FUNCTIONS
 
250 -DSQLITE_ENABLE_STMTVTAB
251 -DSQLITE_HAVE_ZLIB
252 -DSQLITE_ENABLE_DBPAGE_VTAB
253 -DSQLITE_TRUSTED_SCHEMA=0
254 -DHAVE_USLEEP
@@ -368,39 +369,41 @@
368 writeln [string map [list \
369 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
370 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
371 <<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
372 <<<NEXT_LINE>>> \\] {
373 all: $(OBJDIR) $(APPNAME)
374
375 install: all
376 mkdir -p $(INSTALLDIR)
377 cp $(APPNAME) $(INSTALLDIR)
378
379 codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
380 $(OBJDIR)/codecheck1 $(TRANS_SRC)
381
382 $(OBJDIR):
383 -mkdir $(OBJDIR)
384
385 $(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
386 -mkdir -p $(OBJDIR)
387 $(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
388
389 $(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
 
390 $(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
391
392 $(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
 
393 $(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
394
395 $(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
 
396 $(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
397
398 $(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
 
399 $(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
400
401 $(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
 
402 $(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
403
404 # Run the test suite.
405 # Other flags that can be included in TESTFLAGS are:
406 #
@@ -412,11 +415,11 @@
412 # -strict Treat known bugs as failures
413 #
414 # TESTFLAGS can also include names of specific test files to limit
415 # the run to just those test cases.
416 #
417 test: $(OBJDIR) $(APPNAME)
418 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
419
420 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
421 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid <<<NEXT_LINE>>>
422 $(SRCDIR)/../manifest <<<NEXT_LINE>>>
@@ -552,23 +555,26 @@
552
553 writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h"
554 writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n"
555
556 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
 
557 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n"
558
559 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
 
560 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
561
562 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
 
563 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
564
565 writeln [string map [list <<<NEXT_LINE>>> \\] {
566 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
567 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
568
569 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
570 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
571
572 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
573 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
574 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -245,10 +245,11 @@
245 -DSQLITE_ENABLE_DBSTAT_VTAB
246 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
247 -DSQLITE_ENABLE_FTS4
248 -DSQLITE_ENABLE_FTS5
249 -DSQLITE_ENABLE_MATH_FUNCTIONS
250 -DSQLITE_ENABLE_SETLK_TIMEOUT
251 -DSQLITE_ENABLE_STMTVTAB
252 -DSQLITE_HAVE_ZLIB
253 -DSQLITE_ENABLE_DBPAGE_VTAB
254 -DSQLITE_TRUSTED_SCHEMA=0
255 -DHAVE_USLEEP
@@ -368,39 +369,41 @@
369 writeln [string map [list \
370 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
371 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
372 <<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
373 <<<NEXT_LINE>>> \\] {
374 all: $(APPNAME)
375
376 install: all
377 mkdir -p $(INSTALLDIR)
378 cp $(APPNAME) $(INSTALLDIR)
379
380 codecheck: $(TRANS_SRC) $(OBJDIR)/codecheck1
381 $(OBJDIR)/codecheck1 $(TRANS_SRC)
382
 
 
 
383 $(OBJDIR)/translate: $(SRCDIR_tools)/translate.c
384 -mkdir -p $(OBJDIR)
385 $(XBCC) -o $(OBJDIR)/translate $(SRCDIR_tools)/translate.c
386
387 $(OBJDIR)/makeheaders: $(SRCDIR_tools)/makeheaders.c
388 -mkdir -p $(OBJDIR)
389 $(XBCC) -o $(OBJDIR)/makeheaders $(SRCDIR_tools)/makeheaders.c
390
391 $(OBJDIR)/mkindex: $(SRCDIR_tools)/mkindex.c
392 -mkdir -p $(OBJDIR)
393 $(XBCC) -o $(OBJDIR)/mkindex $(SRCDIR_tools)/mkindex.c
394
395 $(OBJDIR)/mkbuiltin: $(SRCDIR_tools)/mkbuiltin.c
396 -mkdir -p $(OBJDIR)
397 $(XBCC) -o $(OBJDIR)/mkbuiltin $(SRCDIR_tools)/mkbuiltin.c
398
399 $(OBJDIR)/mkversion: $(SRCDIR_tools)/mkversion.c
400 -mkdir -p $(OBJDIR)
401 $(XBCC) -o $(OBJDIR)/mkversion $(SRCDIR_tools)/mkversion.c
402
403 $(OBJDIR)/codecheck1: $(SRCDIR_tools)/codecheck1.c
404 -mkdir -p $(OBJDIR)
405 $(XBCC) -o $(OBJDIR)/codecheck1 $(SRCDIR_tools)/codecheck1.c
406
407 # Run the test suite.
408 # Other flags that can be included in TESTFLAGS are:
409 #
@@ -412,11 +415,11 @@
415 # -strict Treat known bugs as failures
416 #
417 # TESTFLAGS can also include names of specific test files to limit
418 # the run to just those test cases.
419 #
420 test: $(APPNAME)
421 $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(TESTFLAGS)
422
423 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/phony.h
424 $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid <<<NEXT_LINE>>>
425 $(SRCDIR)/../manifest <<<NEXT_LINE>>>
@@ -552,23 +555,26 @@
555
556 writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h"
557 writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n"
558
559 writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
560 writeln "\t-mkdir -p \$(OBJDIR)\n"
561 writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n"
562
563 writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
564 writeln "\t-mkdir -p \$(OBJDIR)\n"
565 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_lang.c -o \$@\n"
566
567 writeln "\$(OBJDIR)/th_tcl.o:\t\$(SRCDIR)/th_tcl.c"
568 writeln "\t-mkdir -p \$(OBJDIR)\n"
569 writeln "\t\$(XTCC) -c \$(SRCDIR)/th_tcl.c -o \$@\n"
570
571 writeln [string map [list <<<NEXT_LINE>>> \\] {
572 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c $(OBJDIR)/mkversion
573 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
574
575 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c $(OBJDIR)/mkversion
576 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
577
578 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
579 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
580 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
581
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
2626
CFLAGS = -o
2727
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2828
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2929
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
3030
31
-SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
31
+SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_SETLK_TIMEOUT -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
3232
33
-SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
33
+SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_SETLK_TIMEOUT -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3434
3535
PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
3636
3737
SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
3838
3939
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_SETLK_TIMEOUT -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_SETLK_TIMEOUT -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2533,10 +2533,11 @@
25332533
-DSQLITE_ENABLE_DBSTAT_VTAB \
25342534
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
25352535
-DSQLITE_ENABLE_FTS4 \
25362536
-DSQLITE_ENABLE_FTS5 \
25372537
-DSQLITE_ENABLE_MATH_FUNCTIONS \
2538
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
25382539
-DSQLITE_ENABLE_STMTVTAB \
25392540
-DSQLITE_HAVE_ZLIB \
25402541
-DSQLITE_ENABLE_DBPAGE_VTAB \
25412542
-DSQLITE_TRUSTED_SCHEMA=0 \
25422543
-DHAVE_USLEEP \
@@ -2562,10 +2563,11 @@
25622563
-DSQLITE_ENABLE_DBSTAT_VTAB \
25632564
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
25642565
-DSQLITE_ENABLE_FTS4 \
25652566
-DSQLITE_ENABLE_FTS5 \
25662567
-DSQLITE_ENABLE_MATH_FUNCTIONS \
2568
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
25672569
-DSQLITE_ENABLE_STMTVTAB \
25682570
-DSQLITE_HAVE_ZLIB \
25692571
-DSQLITE_ENABLE_DBPAGE_VTAB \
25702572
-DSQLITE_TRUSTED_SCHEMA=0 \
25712573
-DHAVE_USLEEP \
25722574
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2533,10 +2533,11 @@
2533 -DSQLITE_ENABLE_DBSTAT_VTAB \
2534 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2535 -DSQLITE_ENABLE_FTS4 \
2536 -DSQLITE_ENABLE_FTS5 \
2537 -DSQLITE_ENABLE_MATH_FUNCTIONS \
 
2538 -DSQLITE_ENABLE_STMTVTAB \
2539 -DSQLITE_HAVE_ZLIB \
2540 -DSQLITE_ENABLE_DBPAGE_VTAB \
2541 -DSQLITE_TRUSTED_SCHEMA=0 \
2542 -DHAVE_USLEEP \
@@ -2562,10 +2563,11 @@
2562 -DSQLITE_ENABLE_DBSTAT_VTAB \
2563 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2564 -DSQLITE_ENABLE_FTS4 \
2565 -DSQLITE_ENABLE_FTS5 \
2566 -DSQLITE_ENABLE_MATH_FUNCTIONS \
 
2567 -DSQLITE_ENABLE_STMTVTAB \
2568 -DSQLITE_HAVE_ZLIB \
2569 -DSQLITE_ENABLE_DBPAGE_VTAB \
2570 -DSQLITE_TRUSTED_SCHEMA=0 \
2571 -DHAVE_USLEEP \
2572
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2533,10 +2533,11 @@
2533 -DSQLITE_ENABLE_DBSTAT_VTAB \
2534 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2535 -DSQLITE_ENABLE_FTS4 \
2536 -DSQLITE_ENABLE_FTS5 \
2537 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2538 -DSQLITE_ENABLE_SETLK_TIMEOUT \
2539 -DSQLITE_ENABLE_STMTVTAB \
2540 -DSQLITE_HAVE_ZLIB \
2541 -DSQLITE_ENABLE_DBPAGE_VTAB \
2542 -DSQLITE_TRUSTED_SCHEMA=0 \
2543 -DHAVE_USLEEP \
@@ -2562,10 +2563,11 @@
2563 -DSQLITE_ENABLE_DBSTAT_VTAB \
2564 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2565 -DSQLITE_ENABLE_FTS4 \
2566 -DSQLITE_ENABLE_FTS5 \
2567 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2568 -DSQLITE_ENABLE_SETLK_TIMEOUT \
2569 -DSQLITE_ENABLE_STMTVTAB \
2570 -DSQLITE_HAVE_ZLIB \
2571 -DSQLITE_ENABLE_DBPAGE_VTAB \
2572 -DSQLITE_TRUSTED_SCHEMA=0 \
2573 -DHAVE_USLEEP \
2574
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -316,10 +316,11 @@
316316
/DSQLITE_ENABLE_DBSTAT_VTAB \
317317
/DSQLITE_ENABLE_EXPLAIN_COMMENTS \
318318
/DSQLITE_ENABLE_FTS4 \
319319
/DSQLITE_ENABLE_FTS5 \
320320
/DSQLITE_ENABLE_MATH_FUNCTIONS \
321
+ /DSQLITE_ENABLE_SETLK_TIMEOUT \
321322
/DSQLITE_ENABLE_STMTVTAB \
322323
/DSQLITE_HAVE_ZLIB \
323324
/DSQLITE_ENABLE_DBPAGE_VTAB \
324325
/DSQLITE_TRUSTED_SCHEMA=0 \
325326
/DHAVE_USLEEP \
@@ -342,10 +343,11 @@
342343
/DSQLITE_ENABLE_DBSTAT_VTAB \
343344
/DSQLITE_ENABLE_EXPLAIN_COMMENTS \
344345
/DSQLITE_ENABLE_FTS4 \
345346
/DSQLITE_ENABLE_FTS5 \
346347
/DSQLITE_ENABLE_MATH_FUNCTIONS \
348
+ /DSQLITE_ENABLE_SETLK_TIMEOUT \
347349
/DSQLITE_ENABLE_STMTVTAB \
348350
/DSQLITE_HAVE_ZLIB \
349351
/DSQLITE_ENABLE_DBPAGE_VTAB \
350352
/DSQLITE_TRUSTED_SCHEMA=0 \
351353
/DHAVE_USLEEP \
352354
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -316,10 +316,11 @@
316 /DSQLITE_ENABLE_DBSTAT_VTAB \
317 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
318 /DSQLITE_ENABLE_FTS4 \
319 /DSQLITE_ENABLE_FTS5 \
320 /DSQLITE_ENABLE_MATH_FUNCTIONS \
 
321 /DSQLITE_ENABLE_STMTVTAB \
322 /DSQLITE_HAVE_ZLIB \
323 /DSQLITE_ENABLE_DBPAGE_VTAB \
324 /DSQLITE_TRUSTED_SCHEMA=0 \
325 /DHAVE_USLEEP \
@@ -342,10 +343,11 @@
342 /DSQLITE_ENABLE_DBSTAT_VTAB \
343 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
344 /DSQLITE_ENABLE_FTS4 \
345 /DSQLITE_ENABLE_FTS5 \
346 /DSQLITE_ENABLE_MATH_FUNCTIONS \
 
347 /DSQLITE_ENABLE_STMTVTAB \
348 /DSQLITE_HAVE_ZLIB \
349 /DSQLITE_ENABLE_DBPAGE_VTAB \
350 /DSQLITE_TRUSTED_SCHEMA=0 \
351 /DHAVE_USLEEP \
352
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -316,10 +316,11 @@
316 /DSQLITE_ENABLE_DBSTAT_VTAB \
317 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
318 /DSQLITE_ENABLE_FTS4 \
319 /DSQLITE_ENABLE_FTS5 \
320 /DSQLITE_ENABLE_MATH_FUNCTIONS \
321 /DSQLITE_ENABLE_SETLK_TIMEOUT \
322 /DSQLITE_ENABLE_STMTVTAB \
323 /DSQLITE_HAVE_ZLIB \
324 /DSQLITE_ENABLE_DBPAGE_VTAB \
325 /DSQLITE_TRUSTED_SCHEMA=0 \
326 /DHAVE_USLEEP \
@@ -342,10 +343,11 @@
343 /DSQLITE_ENABLE_DBSTAT_VTAB \
344 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
345 /DSQLITE_ENABLE_FTS4 \
346 /DSQLITE_ENABLE_FTS5 \
347 /DSQLITE_ENABLE_MATH_FUNCTIONS \
348 /DSQLITE_ENABLE_SETLK_TIMEOUT \
349 /DSQLITE_ENABLE_STMTVTAB \
350 /DSQLITE_HAVE_ZLIB \
351 /DSQLITE_ENABLE_DBPAGE_VTAB \
352 /DSQLITE_TRUSTED_SCHEMA=0 \
353 /DHAVE_USLEEP \
354
+22 -6
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,10 +1,25 @@
11
<title>Change Log</title>
22
3
-<h2 id='v2_27'>Changes for version 2.27 (pending)</h2>
4
-
5
- * <i>(pending)</i>
3
+<h2 id='v2_27'>Changes for version 2.27 (pending)</h2><ol>
4
+ <li> Fix a SQL injection on the [/help?cmd=/file|/file page]. Thanks to
5
+ additional defenses built into Fossil, as well as good luck, this injection
6
+ is not exploitable for either data exfiltration or privilege escalation. The
7
+ only possible result of invoking the injection is a harmless SQL syntax error.
8
+ (The [https://en.wikipedia.org/wiki/Swiss_cheese_model|holes in the Swiss cheese]
9
+ did not line up!)
10
+ <li> Enhance the chng= query parameter on the [/help?cmd=/timeline|timeline page]
11
+ so that it works with other query parameters like p=, d=, from=, and to=.
12
+ <li> Always include nodes identify by sel1= and sel2= in the /timeline display.
13
+ <li> Enable the --editor option on the [/help?cmd=amend|fossil amend] command.
14
+ <li> Require at least an anonymous login to access the /blame page and similar,
15
+ to help prevent robots from soaking up excess CPU time on such pages.
16
+ <li> When walking the filesystem looking for Fossil repositories, avoid descending
17
+ into directories named "/proc".
18
+ <ll> Reduce memory requirements for sending authenticated sync protocol
19
+ messages.
20
+ </ol>
621
722
<h2 id='v2_26'>Changes for version 2.26 (2025-04-30)</h2><ol>
823
<li>Enhancements to [/help?cmd=diff|fossil diff] and similar:
924
<ol type="a">
1025
<li> The argument to the --from option can be a directory name, causing
@@ -48,11 +63,13 @@
4863
him or her the opportunity to edit the comment before continuing.
4964
This feature is controllable by the
5065
[/help?cmd=verify-comments|verify-comments setting].
5166
<li> The new "--if-changes" option causes the commit to become
5267
a quiet no-op if there are no pending changes.
53
- <li> Added the ability to sign check-ins with SSH keys.
68
+ <li> Added the ability to sign check-ins with SSH keys. Artifacts signed
69
+ this way are ignored by all previous fossil versions, as if they
70
+ were plain-text file content instead of Fossil artifacts.
5471
<li> Issue a warning if a user tries to commit on a check-in where the
5572
branch has been changed.
5673
<li> The interactive checkin comment prompt shows the formatting rules
5774
set for that repository.
5875
<li> Add the "--editor" option.
@@ -1188,12 +1205,11 @@
11881205
of rows in a timeline) are held in a cookie and thus persist
11891206
across multiple pages.
11901207
* Rework the skin editing process so that changes are implemented
11911208
on one of nine /draft pages, evaluated, then merged back to the
11921209
default.
1193
- * Added the [https://fossil-scm.org/skins/ardoise/timeline|Ardoise]
1194
- skin.
1210
+ * Added the [/timeline?skin=ardoise&once|Ardoise] skin.
11951211
* Fix the "fossil server" command on Unix to be much more responsive
11961212
to multiple simultaneous web requests.
11971213
* Use the IPv6 stack for the "fossil ui" and "fossil server"
11981214
commands on Windows.
11991215
* Support for [https://sqlite.org/sqlar|SQL Archives] as a download
12001216
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,10 +1,25 @@
1 <title>Change Log</title>
2
3 <h2 id='v2_27'>Changes for version 2.27 (pending)</h2>
4
5 * <i>(pending)</i>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7 <h2 id='v2_26'>Changes for version 2.26 (2025-04-30)</h2><ol>
8 <li>Enhancements to [/help?cmd=diff|fossil diff] and similar:
9 <ol type="a">
10 <li> The argument to the --from option can be a directory name, causing
@@ -48,11 +63,13 @@
48 him or her the opportunity to edit the comment before continuing.
49 This feature is controllable by the
50 [/help?cmd=verify-comments|verify-comments setting].
51 <li> The new "--if-changes" option causes the commit to become
52 a quiet no-op if there are no pending changes.
53 <li> Added the ability to sign check-ins with SSH keys.
 
 
54 <li> Issue a warning if a user tries to commit on a check-in where the
55 branch has been changed.
56 <li> The interactive checkin comment prompt shows the formatting rules
57 set for that repository.
58 <li> Add the "--editor" option.
@@ -1188,12 +1205,11 @@
1188 of rows in a timeline) are held in a cookie and thus persist
1189 across multiple pages.
1190 * Rework the skin editing process so that changes are implemented
1191 on one of nine /draft pages, evaluated, then merged back to the
1192 default.
1193 * Added the [https://fossil-scm.org/skins/ardoise/timeline|Ardoise]
1194 skin.
1195 * Fix the "fossil server" command on Unix to be much more responsive
1196 to multiple simultaneous web requests.
1197 * Use the IPv6 stack for the "fossil ui" and "fossil server"
1198 commands on Windows.
1199 * Support for [https://sqlite.org/sqlar|SQL Archives] as a download
1200
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,10 +1,25 @@
1 <title>Change Log</title>
2
3 <h2 id='v2_27'>Changes for version 2.27 (pending)</h2><ol>
4 <li> Fix a SQL injection on the [/help?cmd=/file|/file page]. Thanks to
5 additional defenses built into Fossil, as well as good luck, this injection
6 is not exploitable for either data exfiltration or privilege escalation. The
7 only possible result of invoking the injection is a harmless SQL syntax error.
8 (The [https://en.wikipedia.org/wiki/Swiss_cheese_model|holes in the Swiss cheese]
9 did not line up!)
10 <li> Enhance the chng= query parameter on the [/help?cmd=/timeline|timeline page]
11 so that it works with other query parameters like p=, d=, from=, and to=.
12 <li> Always include nodes identify by sel1= and sel2= in the /timeline display.
13 <li> Enable the --editor option on the [/help?cmd=amend|fossil amend] command.
14 <li> Require at least an anonymous login to access the /blame page and similar,
15 to help prevent robots from soaking up excess CPU time on such pages.
16 <li> When walking the filesystem looking for Fossil repositories, avoid descending
17 into directories named "/proc".
18 <ll> Reduce memory requirements for sending authenticated sync protocol
19 messages.
20 </ol>
21
22 <h2 id='v2_26'>Changes for version 2.26 (2025-04-30)</h2><ol>
23 <li>Enhancements to [/help?cmd=diff|fossil diff] and similar:
24 <ol type="a">
25 <li> The argument to the --from option can be a directory name, causing
@@ -48,11 +63,13 @@
63 him or her the opportunity to edit the comment before continuing.
64 This feature is controllable by the
65 [/help?cmd=verify-comments|verify-comments setting].
66 <li> The new "--if-changes" option causes the commit to become
67 a quiet no-op if there are no pending changes.
68 <li> Added the ability to sign check-ins with SSH keys. Artifacts signed
69 this way are ignored by all previous fossil versions, as if they
70 were plain-text file content instead of Fossil artifacts.
71 <li> Issue a warning if a user tries to commit on a check-in where the
72 branch has been changed.
73 <li> The interactive checkin comment prompt shows the formatting rules
74 set for that repository.
75 <li> Add the "--editor" option.
@@ -1188,12 +1205,11 @@
1205 of rows in a timeline) are held in a cookie and thus persist
1206 across multiple pages.
1207 * Rework the skin editing process so that changes are implemented
1208 on one of nine /draft pages, evaluated, then merged back to the
1209 default.
1210 * Added the [/timeline?skin=ardoise&once|Ardoise] skin.
 
1211 * Fix the "fossil server" command on Unix to be much more responsive
1212 to multiple simultaneous web requests.
1213 * Use the IPv6 stack for the "fossil ui" and "fossil server"
1214 commands on Windows.
1215 * Support for [https://sqlite.org/sqlar|SQL Archives] as a download
1216
--- www/containers.md
+++ www/containers.md
@@ -670,11 +670,11 @@
670670
671671
[pmmac]: https://podman.io/getting-started/installation.html#macos
672672
[pmwin]: https://github.com/containers/podman/blob/main/docs/tutorials/podman-for-windows.md
673673
[Podman]: https://podman.io/
674674
[rl]: https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md
675
-[whatis]: https://podman.io/whatis.html
675
+[whatis]: https://docs.podman.io/en/latest/index.html
676676
677677
678678
### 6.3 <a id="nspawn"></a>`systemd-container`
679679
680680
If even the Podman stack is too big for you, the next-best option I’m
681681
--- www/containers.md
+++ www/containers.md
@@ -670,11 +670,11 @@
670
671 [pmmac]: https://podman.io/getting-started/installation.html#macos
672 [pmwin]: https://github.com/containers/podman/blob/main/docs/tutorials/podman-for-windows.md
673 [Podman]: https://podman.io/
674 [rl]: https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md
675 [whatis]: https://podman.io/whatis.html
676
677
678 ### 6.3 <a id="nspawn"></a>`systemd-container`
679
680 If even the Podman stack is too big for you, the next-best option I’m
681
--- www/containers.md
+++ www/containers.md
@@ -670,11 +670,11 @@
670
671 [pmmac]: https://podman.io/getting-started/installation.html#macos
672 [pmwin]: https://github.com/containers/podman/blob/main/docs/tutorials/podman-for-windows.md
673 [Podman]: https://podman.io/
674 [rl]: https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md
675 [whatis]: https://docs.podman.io/en/latest/index.html
676
677
678 ### 6.3 <a id="nspawn"></a>`systemd-container`
679
680 If even the Podman stack is too big for you, the next-best option I’m
681
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -274,11 +274,11 @@
274274
Git lets you see "what came before". Fossil makes it just as
275275
easy to also see "what came after".
276276
277277
Leaf check-ins in Git that lack a "ref" become "detached," making them
278278
difficult to locate and subject to garbage collection. This
279
-[http://gitfaq.org/1/01/what-is-a-detached-head/|detached head
279
+[https://stackoverflow.com/q/3965676 | detached head
280280
state] problem has caused grief for
281281
[https://www.google.com/search?q=git+detached+head+state | many
282282
Git users]. With
283283
Fossil, detached heads are simply impossible because we can always find
284284
our way back into the Merkle tree using one or more of the relations
@@ -342,11 +342,11 @@
342342
Fossil isn't entirely C and SQL code. Its web UI [./javascript.md |
343343
uses JavaScript where
344344
necessary]. The server-side
345345
UI scripting uses a custom minimal
346346
[https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called
347
-[https://fossil-scm.org/xfer/doc/trunk/www/th1.md|TH1], which is
347
+[./th1.md|TH1], which is
348348
embedded into Fossil itself. Fossil's build system and test suite are
349349
largely based on Tcl.⁵ All of this is quite portable.
350350
351351
About half of Git's code is POSIX C, and about a third is POSIX shell
352352
code. This is largely why the so-called "Git for Windows" distributions
353353
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -274,11 +274,11 @@
274 Git lets you see "what came before". Fossil makes it just as
275 easy to also see "what came after".
276
277 Leaf check-ins in Git that lack a "ref" become "detached," making them
278 difficult to locate and subject to garbage collection. This
279 [http://gitfaq.org/1/01/what-is-a-detached-head/|detached head
280 state] problem has caused grief for
281 [https://www.google.com/search?q=git+detached+head+state | many
282 Git users]. With
283 Fossil, detached heads are simply impossible because we can always find
284 our way back into the Merkle tree using one or more of the relations
@@ -342,11 +342,11 @@
342 Fossil isn't entirely C and SQL code. Its web UI [./javascript.md |
343 uses JavaScript where
344 necessary]. The server-side
345 UI scripting uses a custom minimal
346 [https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called
347 [https://fossil-scm.org/xfer/doc/trunk/www/th1.md|TH1], which is
348 embedded into Fossil itself. Fossil's build system and test suite are
349 largely based on Tcl.⁵ All of this is quite portable.
350
351 About half of Git's code is POSIX C, and about a third is POSIX shell
352 code. This is largely why the so-called "Git for Windows" distributions
353
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -274,11 +274,11 @@
274 Git lets you see "what came before". Fossil makes it just as
275 easy to also see "what came after".
276
277 Leaf check-ins in Git that lack a "ref" become "detached," making them
278 difficult to locate and subject to garbage collection. This
279 [https://stackoverflow.com/q/3965676 | detached head
280 state] problem has caused grief for
281 [https://www.google.com/search?q=git+detached+head+state | many
282 Git users]. With
283 Fossil, detached heads are simply impossible because we can always find
284 our way back into the Merkle tree using one or more of the relations
@@ -342,11 +342,11 @@
342 Fossil isn't entirely C and SQL code. Its web UI [./javascript.md |
343 uses JavaScript where
344 necessary]. The server-side
345 UI scripting uses a custom minimal
346 [https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called
347 [./th1.md|TH1], which is
348 embedded into Fossil itself. Fossil's build system and test suite are
349 largely based on Tcl.⁵ All of this is quite portable.
350
351 About half of Git's code is POSIX C, and about a third is POSIX shell
352 code. This is largely why the so-called "Git for Windows" distributions
353
--- www/gsoc-ideas.md
+++ www/gsoc-ideas.md
@@ -24,11 +24,11 @@
2424
# UI, Look and Feel
2525
2626
Tasks for those interested in graphic/web design:
2727
2828
* Add a quote button to the Forum, such as [discussed in this thread](https://fossil-scm.org/forum/forumpost/7ad03cd73d)
29
-* Improve the documentation history-browsing page to enable selection of 2 arbitrary versions to diff, similar to the [Mediawiki history feature enabled on Wikipedia](https://en.wikipedia.org/w/index.php?title=Fossil_(software)&action=history)
29
+* Improve the documentation history-browsing page to enable selection of 2 arbitrary versions to diff, similar to the [Mediawiki history feature enabled on Wikipedia](https://en.wikipedia.org/w/index.php?title=Fossil_\(software\)&action=history)
3030
* Allow diffing of Forum posts
3131
* General touch-ups in the existing skins. This may, depending on how deep one
3232
cares to dig, require digging into C code to find, and potentially modify, how
3333
the HTML is generated.
3434
* Creation of one or more new skins. This does not specifically require any C
3535
--- www/gsoc-ideas.md
+++ www/gsoc-ideas.md
@@ -24,11 +24,11 @@
24 # UI, Look and Feel
25
26 Tasks for those interested in graphic/web design:
27
28 * Add a quote button to the Forum, such as [discussed in this thread](https://fossil-scm.org/forum/forumpost/7ad03cd73d)
29 * Improve the documentation history-browsing page to enable selection of 2 arbitrary versions to diff, similar to the [Mediawiki history feature enabled on Wikipedia](https://en.wikipedia.org/w/index.php?title=Fossil_(software)&action=history)
30 * Allow diffing of Forum posts
31 * General touch-ups in the existing skins. This may, depending on how deep one
32 cares to dig, require digging into C code to find, and potentially modify, how
33 the HTML is generated.
34 * Creation of one or more new skins. This does not specifically require any C
35
--- www/gsoc-ideas.md
+++ www/gsoc-ideas.md
@@ -24,11 +24,11 @@
24 # UI, Look and Feel
25
26 Tasks for those interested in graphic/web design:
27
28 * Add a quote button to the Forum, such as [discussed in this thread](https://fossil-scm.org/forum/forumpost/7ad03cd73d)
29 * Improve the documentation history-browsing page to enable selection of 2 arbitrary versions to diff, similar to the [Mediawiki history feature enabled on Wikipedia](https://en.wikipedia.org/w/index.php?title=Fossil_\(software\)&action=history)
30 * Allow diffing of Forum posts
31 * General touch-ups in the existing skins. This may, depending on how deep one
32 cares to dig, require digging into C code to find, and potentially modify, how
33 the HTML is generated.
34 * Creation of one or more new skins. This does not specifically require any C
35
+1 -1
--- www/index.wiki
+++ www/index.wiki
@@ -88,11 +88,11 @@
8888
<hr>
8989
<h3>Latest Release: 2.26 ([/timeline?c=version-2.26|2025-04-30])</h3>
9090
9191
* [/uv/download.html|Download]
9292
* [./changes.wiki#v2_26|Change Summary]
93
- * [/timeline?p=version-2.26&bt=version-2.25&y=ci|Check-ins in version 2.26]
93
+ * [/timeline?p=version-2.26&d=version-2.25&y=ci|Check-ins in version 2.26]
9494
* [/timeline?df=version-2.26&y=ci|Check-ins derived from the 2.26 release]
9595
* [/timeline?t=release|Timeline of all past releases]
9696
9797
<hr>
9898
<h3>Quick Start</h3>
9999
--- www/index.wiki
+++ www/index.wiki
@@ -88,11 +88,11 @@
88 <hr>
89 <h3>Latest Release: 2.26 ([/timeline?c=version-2.26|2025-04-30])</h3>
90
91 * [/uv/download.html|Download]
92 * [./changes.wiki#v2_26|Change Summary]
93 * [/timeline?p=version-2.26&bt=version-2.25&y=ci|Check-ins in version 2.26]
94 * [/timeline?df=version-2.26&y=ci|Check-ins derived from the 2.26 release]
95 * [/timeline?t=release|Timeline of all past releases]
96
97 <hr>
98 <h3>Quick Start</h3>
99
--- www/index.wiki
+++ www/index.wiki
@@ -88,11 +88,11 @@
88 <hr>
89 <h3>Latest Release: 2.26 ([/timeline?c=version-2.26|2025-04-30])</h3>
90
91 * [/uv/download.html|Download]
92 * [./changes.wiki#v2_26|Change Summary]
93 * [/timeline?p=version-2.26&d=version-2.25&y=ci|Check-ins in version 2.26]
94 * [/timeline?df=version-2.26&y=ci|Check-ins derived from the 2.26 release]
95 * [/timeline?t=release|Timeline of all past releases]
96
97 <hr>
98 <h3>Quick Start</h3>
99
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -196,11 +196,11 @@
196196
separate directories from the same repository. This enables you,
197197
for example, to do builds from multiple branches or versions at
198198
the same time without having to generate extra clones.
199199
200200
To switch a checkout between different versions and branches,
201
-use:<
201
+use:
202202
203203
<pre>
204204
<b>[/help/update | fossil update]</b>
205205
<b>[/help/checkout | fossil checkout]</b>
206206
</pre>
207207
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -196,11 +196,11 @@
196 separate directories from the same repository. This enables you,
197 for example, to do builds from multiple branches or versions at
198 the same time without having to generate extra clones.
199
200 To switch a checkout between different versions and branches,
201 use:<
202
203 <pre>
204 <b>[/help/update | fossil update]</b>
205 <b>[/help/checkout | fossil checkout]</b>
206 </pre>
207
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -196,11 +196,11 @@
196 separate directories from the same repository. This enables you,
197 for example, to do builds from multiple branches or versions at
198 the same time without having to generate extra clones.
199
200 To switch a checkout between different versions and branches,
201 use:
202
203 <pre>
204 <b>[/help/update | fossil update]</b>
205 <b>[/help/checkout | fossil checkout]</b>
206 </pre>
207
+16 -18
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -35,33 +35,31 @@
3535
</div>
3636
3737
<b>Stephan Beal writes on 2009-01-11:</b>
3838
3939
<div class="indent">
40
-Sometime in late 2007 I came across a link to fossil on
41
-<a href="http://www.sqlite.org/">sqlite.org</a>. It
42
-was a good thing I bookmarked it, because I was never able to find the
43
-link again (it might have been in a bug report or something). The
44
-reasons I first took a close look at it were (A) it stemmed from the
45
-sqlite project, which I've held in high regards for years (e.g. I
46
-wrote JavaScript bindings for it:
47
-<a href="http://spiderape.sourceforge.net/plugins/sqlite/">
48
-http://spiderape.sourceforge.net/plugins/sqlite/</a>), and (B) it could
49
-run as a CGI. That second point might seem a bit archaic, but in
50
-practice CGI is the only way most hosted sites can set up a shared
51
-source repository with multiple user IDs. (i'm not about to give out
52
-my only account password or SSH key for my hosted sites, no matter how
53
-much I trust the other developers, and none of my hosters allow me to
54
-run standalone servers or add Apache modules.)
40
+Sometime in late 2007 I came across a link to fossil on <a
41
+href="https://sqlite.org/">sqlite.org</a>. It was a good thing I
42
+bookmarked it, because I was never able to find the link again (it
43
+might have been in a bug report or something). The reasons I first
44
+took a close look at it were (A) it stemmed from the sqlite project,
45
+which I've held in high regards for years (e.g. I wrote bindings for
46
+it for Mozilla's SpiderMonkey JavaScript engine), and (B) it could run
47
+as a CGI. That second point might seem a bit archaic, but in practice
48
+CGI is the only way most hosted sites can set up a shared source
49
+repository with multiple user IDs. (i'm not about to give out my only
50
+account password or SSH key for my hosted sites, no matter how much I
51
+trust the other developers, and none of my hosters allow me to run
52
+standalone servers or add Apache modules.)
5553
5654
So I tried it out. The thing which bugged me most about it was having
5755
to type "commit" or "com" instead of "ci" for checking in (as is
5856
custom in all other systems I've used), despite the fact that fossil
5957
uses "ci" as a filter in things like the timeline view. Looking back
6058
now, I have used fossil for about about 95% of my work in the past
61
-year (<a href="http://blog.s11n.net/?p=71"><i>dead link</i></a>), in
62
-over 15 source trees, and I now get tripped up when I have to use svn or cvs.
59
+year, in over 15 source trees, and I now get tripped up when I have to
60
+use svn or cvs.
6361
6462
So, having got over typing "fossil com -m ...", here's why I love it so much...
6563
6664
Point #1: CGI
6765
@@ -70,11 +68,11 @@
7068
(they don't belong to those projects), which I cannot host in google
7169
code (because google code doesn't allow/recognize Public Domain as a
7270
license, and I refuse to relicense just to accommodate them), and for
7371
which SourceForge is overkill (and way too slow). With fossil I can
7472
create a new repo, have it installed on my hoster
75
-(http://fossil.wanderinghorse.net), and be commiting code to it within
73
+(https://fossil.wanderinghorse.net), and be commiting code to it within
7674
5 minutes.
7775
7876
Point #2: Wiki
7977
8078
I hate wikis. I really do. Always have. They all have a different
8179
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -35,33 +35,31 @@
35 </div>
36
37 <b>Stephan Beal writes on 2009-01-11:</b>
38
39 <div class="indent">
40 Sometime in late 2007 I came across a link to fossil on
41 <a href="http://www.sqlite.org/">sqlite.org</a>. It
42 was a good thing I bookmarked it, because I was never able to find the
43 link again (it might have been in a bug report or something). The
44 reasons I first took a close look at it were (A) it stemmed from the
45 sqlite project, which I've held in high regards for years (e.g. I
46 wrote JavaScript bindings for it:
47 <a href="http://spiderape.sourceforge.net/plugins/sqlite/">
48 http://spiderape.sourceforge.net/plugins/sqlite/</a>), and (B) it could
49 run as a CGI. That second point might seem a bit archaic, but in
50 practice CGI is the only way most hosted sites can set up a shared
51 source repository with multiple user IDs. (i'm not about to give out
52 my only account password or SSH key for my hosted sites, no matter how
53 much I trust the other developers, and none of my hosters allow me to
54 run standalone servers or add Apache modules.)
55
56 So I tried it out. The thing which bugged me most about it was having
57 to type "commit" or "com" instead of "ci" for checking in (as is
58 custom in all other systems I've used), despite the fact that fossil
59 uses "ci" as a filter in things like the timeline view. Looking back
60 now, I have used fossil for about about 95% of my work in the past
61 year (<a href="http://blog.s11n.net/?p=71"><i>dead link</i></a>), in
62 over 15 source trees, and I now get tripped up when I have to use svn or cvs.
63
64 So, having got over typing "fossil com -m ...", here's why I love it so much...
65
66 Point #1: CGI
67
@@ -70,11 +68,11 @@
70 (they don't belong to those projects), which I cannot host in google
71 code (because google code doesn't allow/recognize Public Domain as a
72 license, and I refuse to relicense just to accommodate them), and for
73 which SourceForge is overkill (and way too slow). With fossil I can
74 create a new repo, have it installed on my hoster
75 (http://fossil.wanderinghorse.net), and be commiting code to it within
76 5 minutes.
77
78 Point #2: Wiki
79
80 I hate wikis. I really do. Always have. They all have a different
81
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -35,33 +35,31 @@
35 </div>
36
37 <b>Stephan Beal writes on 2009-01-11:</b>
38
39 <div class="indent">
40 Sometime in late 2007 I came across a link to fossil on <a
41 href="https://sqlite.org/">sqlite.org</a>. It was a good thing I
42 bookmarked it, because I was never able to find the link again (it
43 might have been in a bug report or something). The reasons I first
44 took a close look at it were (A) it stemmed from the sqlite project,
45 which I've held in high regards for years (e.g. I wrote bindings for
46 it for Mozilla's SpiderMonkey JavaScript engine), and (B) it could run
47 as a CGI. That second point might seem a bit archaic, but in practice
48 CGI is the only way most hosted sites can set up a shared source
49 repository with multiple user IDs. (i'm not about to give out my only
50 account password or SSH key for my hosted sites, no matter how much I
51 trust the other developers, and none of my hosters allow me to run
52 standalone servers or add Apache modules.)
 
 
53
54 So I tried it out. The thing which bugged me most about it was having
55 to type "commit" or "com" instead of "ci" for checking in (as is
56 custom in all other systems I've used), despite the fact that fossil
57 uses "ci" as a filter in things like the timeline view. Looking back
58 now, I have used fossil for about about 95% of my work in the past
59 year, in over 15 source trees, and I now get tripped up when I have to
60 use svn or cvs.
61
62 So, having got over typing "fossil com -m ...", here's why I love it so much...
63
64 Point #1: CGI
65
@@ -70,11 +68,11 @@
68 (they don't belong to those projects), which I cannot host in google
69 code (because google code doesn't allow/recognize Public Domain as a
70 license, and I refuse to relicense just to accommodate them), and for
71 which SourceForge is overkill (and way too slow). With fossil I can
72 create a new repo, have it installed on my hoster
73 (https://fossil.wanderinghorse.net), and be commiting code to it within
74 5 minutes.
75
76 Point #2: Wiki
77
78 I hate wikis. I really do. Always have. They all have a different
79
+5 -1
--- www/signing.md
+++ www/signing.md
@@ -51,15 +51,19 @@
5151
used.
5252
5353
The value for `-n` (the _namespace_) can be changed at will, but care has to be
5454
taken to use the same value when verifying the signature.
5555
56
+Fossil versions prior to 2.26 do not understand SSH signatures and
57
+will treat artifacts signed this way as opaque blobs, not Fossil
58
+artifacts.
59
+
5660
5761
## Verifying a signature
5862
5963
Fossil does not provide an internal method for verifying signatures and
60
-relies – like it does for signing – on external tools.
64
+relies – like it does for signing – on external tools.
6165
6266
### GnuPG
6367
6468
Assuming you used the
6569
default GPG command for signing, one can verify the signature using
6670
--- www/signing.md
+++ www/signing.md
@@ -51,15 +51,19 @@
51 used.
52
53 The value for `-n` (the _namespace_) can be changed at will, but care has to be
54 taken to use the same value when verifying the signature.
55
 
 
 
 
56
57 ## Verifying a signature
58
59 Fossil does not provide an internal method for verifying signatures and
60 relies – like it does for signing – on external tools.
61
62 ### GnuPG
63
64 Assuming you used the
65 default GPG command for signing, one can verify the signature using
66
--- www/signing.md
+++ www/signing.md
@@ -51,15 +51,19 @@
51 used.
52
53 The value for `-n` (the _namespace_) can be changed at will, but care has to be
54 taken to use the same value when verifying the signature.
55
56 Fossil versions prior to 2.26 do not understand SSH signatures and
57 will treat artifacts signed this way as opaque blobs, not Fossil
58 artifacts.
59
60
61 ## Verifying a signature
62
63 Fossil does not provide an internal method for verifying signatures and
64 relies – like it does for signing – on external tools.
65
66 ### GnuPG
67
68 Assuming you used the
69 default GPG command for signing, one can verify the signature using
70
+43 -27
--- www/sync.wiki
+++ www/sync.wiki
@@ -58,20 +58,20 @@
5858
request.
5959
6060
The server might be running as an independent server
6161
using the [/help?cmd=server|"fossil server" command], or it
6262
might be launched from inetd or xinetd using the
63
-["fossil http" command|/help?cmd=http]. Or the server might
63
+[/help?cmd=http|"fossil http" command]. Or the server might
6464
be [./server/any/cgi.md|launched from CGI] or from
6565
[./server/any/scgi.md|SCGI].
6666
(See "[./server/|How To Configure A Fossil Server]" for details.)
6767
The specifics of how the server listens
6868
for incoming HTTP requests is immaterial to this protocol.
6969
The important point is that the server is listening for requests and
7070
the client is the issuer of the requests.
7171
72
-A single [/help?cmd=push|push],
72
+A single [/help?cmd=push|push],
7373
[/help?cmd=pull|pull], or [/help?cmd=sync|sync]
7474
might involve multiple HTTP requests.
7575
The client maintains state between all requests. But on the server
7676
side, each request is independent. The server does not preserve
7777
any information about the client from one request to the next.
@@ -150,24 +150,24 @@
150150
151151
The client modifies the URL by appending the method name "<b>/xfer</b>"
152152
to the end. For example, if the URL specified on the client command
153153
line is
154154
155
-<pre>https://fossil-scm.org/fossil</pre>
155
+<pre>https://fossil-scm.org/home</pre>
156156
157157
Then the URL that is really used to do the synchronization will
158158
be:
159159
160
-<pre>https://fossil-scm.org/fossil/xfer</pre>
160
+<pre>https://fossil-scm.org/home/xfer</pre>
161161
162162
<h3 id="req-format">2.2 HTTP Request Format</h3>
163163
164164
The client always sends a POST request to the server. The
165165
general format of the POST request is as follows:
166166
167167
<pre>
168
-POST /fossil/xfer HTTP/1.0
168
+POST /home/xfer HTTP/1.0
169169
Host: fossil-scm.hwaci.com:80
170170
Content-Type: application/x-fossil
171171
Content-Length: 4216
172172
</pre>
173173
@@ -220,26 +220,38 @@
220220
Every message from client to server begins with one or more login
221221
cards. Each login card has the following format:
222222
223223
<pre><b>login</b> <i>userid nonce signature</i></pre>
224224
225
-The userid is the name of the user that is requesting service
226
-from the server. The nonce is the SHA1 hash of the remainder of
227
-the message - all text that follows the newline character that
228
-terminates the login card. The signature is the SHA1 hash of
229
-the concatenation of the nonce and the users password.
230
-
231
-For each login card, the server looks up the user and verifies
232
-that the nonce matches the SHA1 hash of the remainder of the
233
-message. It then checks the signature hash to make sure the
234
-signature matches. If everything
235
-checks out, then the client is granted all privileges of the
236
-specified user.
237
-
238
-Privileges are cumulative. There can be multiple successful
239
-login cards. The session privilege is the union of all
240
-privileges from all login cards.
225
+The userid is the name of the user that is requesting service from the
226
+server, encoded in "fossilized" form (exactly as described for <a
227
+href="#error">the error card</a>). The nonce is the SHA1 hash of the
228
+remainder of the message - all text that follows the newline character
229
+that terminates the login card. The signature is the SHA1 hash of the
230
+concatenation of the nonce and the users password.
231
+
232
+When receving a login card, the server looks up the user and verifies
233
+that the nonce matches the SHA1 hash of the remainder of the message.
234
+It then checks the signature hash to make sure the signature matches.
235
+If everything checks out, then the client is granted all privileges of
236
+the specified user.
237
+
238
+Only one login card is permitted. A second login card will trigger
239
+a sync error. (Prior to 2025-07-21, the protocol permitted multiple
240
+logins, treating the login as the union of all privileges from all
241
+login cards. That capability was never used and has been removed.)
242
+
243
+As of version 2.27, Fossil supports transfering of the login card
244
+externally to the request payload via a Cookie HTTP header:
245
+
246
+<verbatim>
247
+ Cookie: x-f-x-l=...
248
+</verbatim>
249
+
250
+Where "..." is the URL-encoded login cookie. <code>x-f-x-l</code> is
251
+short for X-Fossil-Xfer-Login.
252
+
241253
242254
<h3 id="file">3.3 File Cards</h3>
243255
244256
Artifacts are transferred using either "file" cards, or "cfile"
245257
or "uvfile" cards.
@@ -250,11 +262,11 @@
250262
251263
<h4 id="ordinary-fc">3.3.1 Ordinary File Cards</h4>
252264
253265
For sync protocols, artifacts are transferred using "file"
254266
cards. File cards come in two different formats depending
255
-on whether the artifact is sent directly or as a
267
+on whether the artifact is sent directly or as a
256268
[./delta_format.wiki|delta] from some
257269
other artifact.
258270
259271
<pre>
260272
<b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
@@ -273,11 +285,11 @@
273285
representation of the name hash for the artifact.
274286
The last argument of the file card is the number of bytes of
275287
payload that immediately follow the file card. If the file
276288
card has only two arguments, that means the payload is the
277289
complete content of the artifact. If the file card has three
278
-arguments, then the payload is a
290
+arguments, then the payload is a
279291
[./delta_format.wiki|delta] and the second argument is
280292
the ID of another artifact that is the source of the delta.
281293
282294
File cards are sent in both directions: client to server and
283295
server to client. A delta might be sent before the source of
@@ -286,12 +298,16 @@
286298
287299
<h4 id="compressed-fc">3.3.2 Compressed File Cards</h4>
288300
289301
A client that sends a clone protocol version "3" or greater will
290302
receive artifacts as "cfile" cards while cloning. This card was
291
-introduced to improve the speed of the transfer of content by sending the
292
-compressed artifact directly from the server database to the client.
303
+introduced to improve the speed of the transfer of content by sending
304
+the compressed artifact directly from the server database to the
305
+client. In this case, the containing response body is <em>not</em>
306
+compressed separately because the vast majority of the response is
307
+already compressed in cfile cards. In practice, version "3" is
308
+significantly faster than version "2".
293309
294310
Compressed File cards are similar to File cards, sharing the same
295311
in-line "payload" data characteristics and also the same treatment of
296312
direct content or delta content. Cfile cards come in two different formats
297313
depending on whether the artifact is sent directly or as a delta from
@@ -411,11 +427,11 @@
411427
412428
<h4>3.5.2 Protocol 2</h4>
413429
414430
The sequence-number sent is the number
415431
of artifacts received so far. For the first clone message, the
416
-sequence number is 0. The server will respond by sending file
432
+sequence number is 1. The server will respond by sending file
417433
cards for some number of artifacts up to the maximum message size.
418434
419435
The server will also send a single "clone_seqno" card to the client
420436
so that the client can know where the server left off.
421437
@@ -1038,11 +1054,11 @@
10381054
<ul>
10391055
<li> <b>login</b> <i>userid nonce signature</i>
10401056
<li> <b>push</b> <i>servercode projectcode</i>
10411057
<li> <b>pull</b> <i>servercode projectcode</i>
10421058
<li> <b>clone</b>
1043
- <li> <b>clone_seqno</b> <i>sequence-number</i>
1059
+ <li> <b>clone</b> <i>protocol-version sequence-number</i>
10441060
<li> <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
10451061
<li> <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
10461062
<li> <b>cfile</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
10471063
<li> <b>cfile</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
10481064
<li> <b>uvfile</b> <i>name mtime hash size flags</i> <b>\n</b> <i>content</i>
10491065
--- www/sync.wiki
+++ www/sync.wiki
@@ -58,20 +58,20 @@
58 request.
59
60 The server might be running as an independent server
61 using the [/help?cmd=server|"fossil server" command], or it
62 might be launched from inetd or xinetd using the
63 ["fossil http" command|/help?cmd=http]. Or the server might
64 be [./server/any/cgi.md|launched from CGI] or from
65 [./server/any/scgi.md|SCGI].
66 (See "[./server/|How To Configure A Fossil Server]" for details.)
67 The specifics of how the server listens
68 for incoming HTTP requests is immaterial to this protocol.
69 The important point is that the server is listening for requests and
70 the client is the issuer of the requests.
71
72 A single [/help?cmd=push|push],
73 [/help?cmd=pull|pull], or [/help?cmd=sync|sync]
74 might involve multiple HTTP requests.
75 The client maintains state between all requests. But on the server
76 side, each request is independent. The server does not preserve
77 any information about the client from one request to the next.
@@ -150,24 +150,24 @@
150
151 The client modifies the URL by appending the method name "<b>/xfer</b>"
152 to the end. For example, if the URL specified on the client command
153 line is
154
155 <pre>https://fossil-scm.org/fossil</pre>
156
157 Then the URL that is really used to do the synchronization will
158 be:
159
160 <pre>https://fossil-scm.org/fossil/xfer</pre>
161
162 <h3 id="req-format">2.2 HTTP Request Format</h3>
163
164 The client always sends a POST request to the server. The
165 general format of the POST request is as follows:
166
167 <pre>
168 POST /fossil/xfer HTTP/1.0
169 Host: fossil-scm.hwaci.com:80
170 Content-Type: application/x-fossil
171 Content-Length: 4216
172 </pre>
173
@@ -220,26 +220,38 @@
220 Every message from client to server begins with one or more login
221 cards. Each login card has the following format:
222
223 <pre><b>login</b> <i>userid nonce signature</i></pre>
224
225 The userid is the name of the user that is requesting service
226 from the server. The nonce is the SHA1 hash of the remainder of
227 the message - all text that follows the newline character that
228 terminates the login card. The signature is the SHA1 hash of
229 the concatenation of the nonce and the users password.
230
231 For each login card, the server looks up the user and verifies
232 that the nonce matches the SHA1 hash of the remainder of the
233 message. It then checks the signature hash to make sure the
234 signature matches. If everything
235 checks out, then the client is granted all privileges of the
236 specified user.
237
238 Privileges are cumulative. There can be multiple successful
239 login cards. The session privilege is the union of all
240 privileges from all login cards.
 
 
 
 
 
 
 
 
 
 
 
 
241
242 <h3 id="file">3.3 File Cards</h3>
243
244 Artifacts are transferred using either "file" cards, or "cfile"
245 or "uvfile" cards.
@@ -250,11 +262,11 @@
250
251 <h4 id="ordinary-fc">3.3.1 Ordinary File Cards</h4>
252
253 For sync protocols, artifacts are transferred using "file"
254 cards. File cards come in two different formats depending
255 on whether the artifact is sent directly or as a
256 [./delta_format.wiki|delta] from some
257 other artifact.
258
259 <pre>
260 <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
@@ -273,11 +285,11 @@
273 representation of the name hash for the artifact.
274 The last argument of the file card is the number of bytes of
275 payload that immediately follow the file card. If the file
276 card has only two arguments, that means the payload is the
277 complete content of the artifact. If the file card has three
278 arguments, then the payload is a
279 [./delta_format.wiki|delta] and the second argument is
280 the ID of another artifact that is the source of the delta.
281
282 File cards are sent in both directions: client to server and
283 server to client. A delta might be sent before the source of
@@ -286,12 +298,16 @@
286
287 <h4 id="compressed-fc">3.3.2 Compressed File Cards</h4>
288
289 A client that sends a clone protocol version "3" or greater will
290 receive artifacts as "cfile" cards while cloning. This card was
291 introduced to improve the speed of the transfer of content by sending the
292 compressed artifact directly from the server database to the client.
 
 
 
 
293
294 Compressed File cards are similar to File cards, sharing the same
295 in-line "payload" data characteristics and also the same treatment of
296 direct content or delta content. Cfile cards come in two different formats
297 depending on whether the artifact is sent directly or as a delta from
@@ -411,11 +427,11 @@
411
412 <h4>3.5.2 Protocol 2</h4>
413
414 The sequence-number sent is the number
415 of artifacts received so far. For the first clone message, the
416 sequence number is 0. The server will respond by sending file
417 cards for some number of artifacts up to the maximum message size.
418
419 The server will also send a single "clone_seqno" card to the client
420 so that the client can know where the server left off.
421
@@ -1038,11 +1054,11 @@
1038 <ul>
1039 <li> <b>login</b> <i>userid nonce signature</i>
1040 <li> <b>push</b> <i>servercode projectcode</i>
1041 <li> <b>pull</b> <i>servercode projectcode</i>
1042 <li> <b>clone</b>
1043 <li> <b>clone_seqno</b> <i>sequence-number</i>
1044 <li> <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
1045 <li> <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
1046 <li> <b>cfile</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
1047 <li> <b>cfile</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
1048 <li> <b>uvfile</b> <i>name mtime hash size flags</i> <b>\n</b> <i>content</i>
1049
--- www/sync.wiki
+++ www/sync.wiki
@@ -58,20 +58,20 @@
58 request.
59
60 The server might be running as an independent server
61 using the [/help?cmd=server|"fossil server" command], or it
62 might be launched from inetd or xinetd using the
63 [/help?cmd=http|"fossil http" command]. Or the server might
64 be [./server/any/cgi.md|launched from CGI] or from
65 [./server/any/scgi.md|SCGI].
66 (See "[./server/|How To Configure A Fossil Server]" for details.)
67 The specifics of how the server listens
68 for incoming HTTP requests is immaterial to this protocol.
69 The important point is that the server is listening for requests and
70 the client is the issuer of the requests.
71
72 A single [/help?cmd=push|push],
73 [/help?cmd=pull|pull], or [/help?cmd=sync|sync]
74 might involve multiple HTTP requests.
75 The client maintains state between all requests. But on the server
76 side, each request is independent. The server does not preserve
77 any information about the client from one request to the next.
@@ -150,24 +150,24 @@
150
151 The client modifies the URL by appending the method name "<b>/xfer</b>"
152 to the end. For example, if the URL specified on the client command
153 line is
154
155 <pre>https://fossil-scm.org/home</pre>
156
157 Then the URL that is really used to do the synchronization will
158 be:
159
160 <pre>https://fossil-scm.org/home/xfer</pre>
161
162 <h3 id="req-format">2.2 HTTP Request Format</h3>
163
164 The client always sends a POST request to the server. The
165 general format of the POST request is as follows:
166
167 <pre>
168 POST /home/xfer HTTP/1.0
169 Host: fossil-scm.hwaci.com:80
170 Content-Type: application/x-fossil
171 Content-Length: 4216
172 </pre>
173
@@ -220,26 +220,38 @@
220 Every message from client to server begins with one or more login
221 cards. Each login card has the following format:
222
223 <pre><b>login</b> <i>userid nonce signature</i></pre>
224
225 The userid is the name of the user that is requesting service from the
226 server, encoded in "fossilized" form (exactly as described for <a
227 href="#error">the error card</a>). The nonce is the SHA1 hash of the
228 remainder of the message - all text that follows the newline character
229 that terminates the login card. The signature is the SHA1 hash of the
230 concatenation of the nonce and the users password.
231
232 When receving a login card, the server looks up the user and verifies
233 that the nonce matches the SHA1 hash of the remainder of the message.
234 It then checks the signature hash to make sure the signature matches.
235 If everything checks out, then the client is granted all privileges of
236 the specified user.
237
238 Only one login card is permitted. A second login card will trigger
239 a sync error. (Prior to 2025-07-21, the protocol permitted multiple
240 logins, treating the login as the union of all privileges from all
241 login cards. That capability was never used and has been removed.)
242
243 As of version 2.27, Fossil supports transfering of the login card
244 externally to the request payload via a Cookie HTTP header:
245
246 <verbatim>
247 Cookie: x-f-x-l=...
248 </verbatim>
249
250 Where "..." is the URL-encoded login cookie. <code>x-f-x-l</code> is
251 short for X-Fossil-Xfer-Login.
252
253
254 <h3 id="file">3.3 File Cards</h3>
255
256 Artifacts are transferred using either "file" cards, or "cfile"
257 or "uvfile" cards.
@@ -250,11 +262,11 @@
262
263 <h4 id="ordinary-fc">3.3.1 Ordinary File Cards</h4>
264
265 For sync protocols, artifacts are transferred using "file"
266 cards. File cards come in two different formats depending
267 on whether the artifact is sent directly or as a
268 [./delta_format.wiki|delta] from some
269 other artifact.
270
271 <pre>
272 <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
@@ -273,11 +285,11 @@
285 representation of the name hash for the artifact.
286 The last argument of the file card is the number of bytes of
287 payload that immediately follow the file card. If the file
288 card has only two arguments, that means the payload is the
289 complete content of the artifact. If the file card has three
290 arguments, then the payload is a
291 [./delta_format.wiki|delta] and the second argument is
292 the ID of another artifact that is the source of the delta.
293
294 File cards are sent in both directions: client to server and
295 server to client. A delta might be sent before the source of
@@ -286,12 +298,16 @@
298
299 <h4 id="compressed-fc">3.3.2 Compressed File Cards</h4>
300
301 A client that sends a clone protocol version "3" or greater will
302 receive artifacts as "cfile" cards while cloning. This card was
303 introduced to improve the speed of the transfer of content by sending
304 the compressed artifact directly from the server database to the
305 client. In this case, the containing response body is <em>not</em>
306 compressed separately because the vast majority of the response is
307 already compressed in cfile cards. In practice, version "3" is
308 significantly faster than version "2".
309
310 Compressed File cards are similar to File cards, sharing the same
311 in-line "payload" data characteristics and also the same treatment of
312 direct content or delta content. Cfile cards come in two different formats
313 depending on whether the artifact is sent directly or as a delta from
@@ -411,11 +427,11 @@
427
428 <h4>3.5.2 Protocol 2</h4>
429
430 The sequence-number sent is the number
431 of artifacts received so far. For the first clone message, the
432 sequence number is 1. The server will respond by sending file
433 cards for some number of artifacts up to the maximum message size.
434
435 The server will also send a single "clone_seqno" card to the client
436 so that the client can know where the server left off.
437
@@ -1038,11 +1054,11 @@
1054 <ul>
1055 <li> <b>login</b> <i>userid nonce signature</i>
1056 <li> <b>push</b> <i>servercode projectcode</i>
1057 <li> <b>pull</b> <i>servercode projectcode</i>
1058 <li> <b>clone</b>
1059 <li> <b>clone</b> <i>protocol-version sequence-number</i>
1060 <li> <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
1061 <li> <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
1062 <li> <b>cfile</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
1063 <li> <b>cfile</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
1064 <li> <b>uvfile</b> <i>name mtime hash size flags</i> <b>\n</b> <i>content</i>
1065
+1 -1
--- www/th1.md
+++ www/th1.md
@@ -140,11 +140,11 @@
140140
custom TH1 scripts for headers or footers or tickets are added to a
141141
repository. Note that the tainted/untainted distinction in strings does
142142
not make it impossible to introduce XSS and SQL-injections vulnerabilities
143143
using poorly-written TH1 scripts; it just makes it more difficult and
144144
less likely to happen by accident. Developers must still consider the
145
-security implications TH1 customizations they add to Fossil, and take
145
+security implications of TH1 customizations they add to Fossil, and take
146146
appropriate precautions when writing custom TH1. Peer review of TH1
147147
script changes is encouraged.
148148
149149
In Fossil version 2.26, if the vuln-report setting is set to "block"
150150
or "fatal", the [html](#html) and [query](#query) TH1 commands will
151151
--- www/th1.md
+++ www/th1.md
@@ -140,11 +140,11 @@
140 custom TH1 scripts for headers or footers or tickets are added to a
141 repository. Note that the tainted/untainted distinction in strings does
142 not make it impossible to introduce XSS and SQL-injections vulnerabilities
143 using poorly-written TH1 scripts; it just makes it more difficult and
144 less likely to happen by accident. Developers must still consider the
145 security implications TH1 customizations they add to Fossil, and take
146 appropriate precautions when writing custom TH1. Peer review of TH1
147 script changes is encouraged.
148
149 In Fossil version 2.26, if the vuln-report setting is set to "block"
150 or "fatal", the [html](#html) and [query](#query) TH1 commands will
151
--- www/th1.md
+++ www/th1.md
@@ -140,11 +140,11 @@
140 custom TH1 scripts for headers or footers or tickets are added to a
141 repository. Note that the tainted/untainted distinction in strings does
142 not make it impossible to introduce XSS and SQL-injections vulnerabilities
143 using poorly-written TH1 scripts; it just makes it more difficult and
144 less likely to happen by accident. Developers must still consider the
145 security implications of TH1 customizations they add to Fossil, and take
146 appropriate precautions when writing custom TH1. Peer review of TH1
147 script changes is encouraged.
148
149 In Fossil version 2.26, if the vuln-report setting is set to "block"
150 or "fatal", the [html](#html) and [query](#query) TH1 commands will
151

Keyboard Shortcuts

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