Fossil SCM

Update the built-in SQLite to the second 3.35.0 beta, for testing.

drh 2021-03-09 21:24 trunk
Commit b46872985550604f02225faf66f6ec8ffe1275bd233165b0edadfa288acef1da
3 files changed +198 -96 +134 -74 +8 -2
+198 -96
--- src/shell.c
+++ src/shell.c
@@ -3638,42 +3638,41 @@
36383638
**
36393639
** This file implements a VFS shim that allows an SQLite database to be
36403640
** appended onto the end of some other file, such as an executable.
36413641
**
36423642
** A special record must appear at the end of the file that identifies the
3643
-** file as an appended database and provides an offset to page 1. For
3644
-** best performance page 1 should be located at a disk page boundary, though
3645
-** that is not required.
3643
+** file as an appended database and provides the offset to the first page
3644
+** of the exposed content. (Or, it is the length of the content prefix.)
3645
+** For best performance page 1 should be located at a disk page boundary,
3646
+** though that is not required.
36463647
**
36473648
** When opening a database using this VFS, the connection might treat
3648
-** the file as an ordinary SQLite database, or it might treat is as a
3649
-** database appended onto some other file. Here are the rules:
3650
-**
3651
-** (1) When opening a new empty file, that file is treated as an ordinary
3652
-** database.
3653
-**
3654
-** (2) When opening a file that begins with the standard SQLite prefix
3655
-** string "SQLite format 3", that file is treated as an ordinary
3656
-** database.
3657
-**
3658
-** (3) When opening a file that ends with the appendvfs trailer string
3659
-** "Start-Of-SQLite3-NNNNNNNN" that file is treated as an appended
3660
-** database.
3649
+** the file as an ordinary SQLite database, or it might treat it as a
3650
+** database appended onto some other file. The decision is made by
3651
+** applying the following rules in order:
3652
+**
3653
+** (1) An empty file is an ordinary database.
3654
+**
3655
+** (2) If the file ends with the appendvfs trailer string
3656
+** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
3657
+**
3658
+** (3) If the file begins with the standard SQLite prefix string
3659
+** "SQLite format 3", that file is an ordinary database.
36613660
**
36623661
** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
36633662
** set, then a new database is appended to the already existing file.
36643663
**
36653664
** (5) Otherwise, SQLITE_CANTOPEN is returned.
36663665
**
36673666
** To avoid unnecessary complications with the PENDING_BYTE, the size of
3668
-** the file containing the database is limited to 1GB. This VFS will refuse
3669
-** to read or write past the 1GB mark. This restriction might be lifted in
3670
-** future versions. For now, if you need a large database, then keep the
3671
-** database in a separate file.
3667
+** the file containing the database is limited to 1GB. (1000013824 bytes)
3668
+** This VFS will not read or write past the 1GB mark. This restriction
3669
+** might be lifted in future versions. For now, if you need a larger
3670
+** database, then keep it in a separate file.
36723671
**
3673
-** If the file being opened is not an appended database, then this shim is
3674
-** a pass-through into the default underlying VFS.
3672
+** If the file being opened is a plain database (not an appended one), then
3673
+** this shim is a pass-through into the default underlying VFS. (rule 3)
36753674
**/
36763675
/* #include "sqlite3ext.h" */
36773676
SQLITE_EXTENSION_INIT1
36783677
#include <string.h>
36793678
#include <assert.h>
@@ -3682,22 +3681,30 @@
36823681
**
36833682
** Start-Of-SQLite3-NNNNNNNN
36843683
** 123456789 123456789 12345
36853684
**
36863685
** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3687
-** the offset to page 1.
3686
+** the offset to page 1, and also the length of the prefix content.
36883687
*/
36893688
#define APND_MARK_PREFIX "Start-Of-SQLite3-"
36903689
#define APND_MARK_PREFIX_SZ 17
3691
-#define APND_MARK_SIZE 25
3690
+#define APND_MARK_FOS_SZ 8
3691
+#define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
36923692
36933693
/*
36943694
** Maximum size of the combined prefix + database + append-mark. This
36953695
** must be less than 0x40000000 to avoid locking issues on Windows.
36963696
*/
36973697
#define APND_MAX_SIZE (65536*15259)
36983698
3699
+/*
3700
+** Size of storage page upon which to align appendvfs portion.
3701
+*/
3702
+#ifndef APND_ROUNDUP_BITS
3703
+#define APND_ROUNDUP_BITS 12
3704
+#endif
3705
+
36993706
/*
37003707
** Forward declaration of objects used by this utility
37013708
*/
37023709
typedef struct sqlite3_vfs ApndVfs;
37033710
typedef struct ApndFile ApndFile;
@@ -3706,15 +3713,43 @@
37063713
** access to randomness, etc.
37073714
*/
37083715
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
37093716
#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
37103717
3711
-/* An open file */
3718
+/* Invariants for an open appendvfs file:
3719
+ * Once an appendvfs file is opened, it will be in one of three states:
3720
+ * State 0: Never written. Underlying file (if any) is unaltered.
3721
+ * State 1: Append mark is persisted, content write is in progress.
3722
+ * State 2: Append mark is persisted, content writes are complete.
3723
+ *
3724
+ * State 0 is persistent in the sense that nothing will have been done
3725
+ * to the underlying file, including any attempt to convert it to an
3726
+ * appendvfs file.
3727
+ *
3728
+ * State 1 is normally transitory. However, if a write operation ends
3729
+ * abnormally (disk full, power loss, process kill, etc.), then State 1
3730
+ * may be persistent on disk with an incomplete content write-out. This
3731
+ * is logically equivalent to an interrupted write to an ordinary file,
3732
+ * where some unknown portion of to-be-written data is persisted while
3733
+ * the remainder is not. Database integrity in such cases is maintained
3734
+ * (or not) by the same measures available for ordinary file access.
3735
+ *
3736
+ * State 2 is persistent under normal circumstances (when there is no
3737
+ * abnormal termination of a write operation such that data provided
3738
+ * to the underlying VFS write method has not yet reached storage.)
3739
+ *
3740
+ * In order to maintain the state invariant, the append mark is written
3741
+ * in advance of content writes where any part of such content would
3742
+ * overwrite an existing (or yet to be written) append mark.
3743
+ */
37123744
struct ApndFile {
3713
- sqlite3_file base; /* IO methods */
3714
- sqlite3_int64 iPgOne; /* File offset to page 1 */
3715
- sqlite3_int64 iMark; /* Start of the append-mark */
3745
+ /* Access to IO methods of the underlying file */
3746
+ sqlite3_file base;
3747
+ /* File offset to beginning of appended content (unchanging) */
3748
+ sqlite3_int64 iPgOne;
3749
+ /* File offset of written append-mark, or -1 if unwritten */
3750
+ sqlite3_int64 iMark;
37163751
};
37173752
37183753
/*
37193754
** Methods for ApndFile
37203755
*/
@@ -3802,12 +3837,10 @@
38023837
apndShmUnmap, /* xShmUnmap */
38033838
apndFetch, /* xFetch */
38043839
apndUnfetch /* xUnfetch */
38053840
};
38063841
3807
-
3808
-
38093842
/*
38103843
** Close an apnd-file.
38113844
*/
38123845
static int apndClose(sqlite3_file *pFile){
38133846
pFile = ORIGFILE(pFile);
@@ -3821,26 +3854,41 @@
38213854
sqlite3_file *pFile,
38223855
void *zBuf,
38233856
int iAmt,
38243857
sqlite_int64 iOfst
38253858
){
3826
- ApndFile *p = (ApndFile *)pFile;
3859
+ ApndFile *paf = (ApndFile *)pFile;
38273860
pFile = ORIGFILE(pFile);
3828
- return pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3861
+ return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
38293862
}
38303863
38313864
/*
3832
-** Add the append-mark onto the end of the file.
3865
+** Add the append-mark onto what should become the end of the file.
3866
+* If and only if this succeeds, internal ApndFile.iMark is updated.
3867
+* Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
38333868
*/
3834
-static int apndWriteMark(ApndFile *p, sqlite3_file *pFile){
3835
- int i;
3869
+static int apndWriteMark(
3870
+ ApndFile *paf,
3871
+ sqlite3_file *pFile,
3872
+ sqlite_int64 iWriteEnd
3873
+){
3874
+ sqlite_int64 iPgOne = paf->iPgOne;
38363875
unsigned char a[APND_MARK_SIZE];
3876
+ int i = APND_MARK_FOS_SZ;
3877
+ int rc;
3878
+ assert(pFile == ORIGFILE(paf));
38373879
memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3838
- for(i=0; i<8; i++){
3839
- a[APND_MARK_PREFIX_SZ+i] = (p->iPgOne >> (56 - i*8)) & 0xff;
3880
+ while (--i >= 0) {
3881
+ a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
3882
+ iPgOne >>= 8;
38403883
}
3841
- return pFile->pMethods->xWrite(pFile, a, APND_MARK_SIZE, p->iMark);
3884
+ iWriteEnd += paf->iPgOne;
3885
+ if( SQLITE_OK==(rc = pFile->pMethods->xWrite
3886
+ (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
3887
+ paf->iMark = iWriteEnd;
3888
+ }
3889
+ return rc;
38423890
}
38433891
38443892
/*
38453893
** Write data to an apnd-file.
38463894
*/
@@ -3848,42 +3896,34 @@
38483896
sqlite3_file *pFile,
38493897
const void *zBuf,
38503898
int iAmt,
38513899
sqlite_int64 iOfst
38523900
){
3853
- int rc;
3854
- ApndFile *p = (ApndFile *)pFile;
3901
+ ApndFile *paf = (ApndFile *)pFile;
3902
+ sqlite_int64 iWriteEnd = iOfst + iAmt;
3903
+ if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
38553904
pFile = ORIGFILE(pFile);
3856
- if( iOfst+iAmt>=APND_MAX_SIZE ) return SQLITE_FULL;
3857
- rc = pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3858
- if( rc==SQLITE_OK && iOfst + iAmt + p->iPgOne > p->iMark ){
3859
- sqlite3_int64 sz = 0;
3860
- rc = pFile->pMethods->xFileSize(pFile, &sz);
3861
- if( rc==SQLITE_OK ){
3862
- p->iMark = sz - APND_MARK_SIZE;
3863
- if( iOfst + iAmt + p->iPgOne > p->iMark ){
3864
- p->iMark = p->iPgOne + iOfst + iAmt;
3865
- rc = apndWriteMark(p, pFile);
3866
- }
3867
- }
3868
- }
3869
- return rc;
3905
+ /* If append-mark is absent or will be overwritten, write it. */
3906
+ if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
3907
+ int rc = apndWriteMark(paf, pFile, iWriteEnd);
3908
+ if( SQLITE_OK!=rc )
3909
+ return rc;
3910
+ }
3911
+ return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
38703912
}
38713913
38723914
/*
38733915
** Truncate an apnd-file.
38743916
*/
38753917
static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3876
- int rc;
3877
- ApndFile *p = (ApndFile *)pFile;
3918
+ ApndFile *paf = (ApndFile *)pFile;
38783919
pFile = ORIGFILE(pFile);
3879
- rc = pFile->pMethods->xTruncate(pFile, size+p->iPgOne+APND_MARK_SIZE);
3880
- if( rc==SQLITE_OK ){
3881
- p->iMark = p->iPgOne+size;
3882
- rc = apndWriteMark(p, pFile);
3883
- }
3884
- return rc;
3920
+ /* The append mark goes out first so truncate failure does not lose it. */
3921
+ if( SQLITE_OK!=apndWriteMark(paf, pFile, size) )
3922
+ return SQLITE_IOERR;
3923
+ /* Truncate underlying file just past append mark */
3924
+ return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
38853925
}
38863926
38873927
/*
38883928
** Sync an apnd-file.
38893929
*/
@@ -3892,20 +3932,16 @@
38923932
return pFile->pMethods->xSync(pFile, flags);
38933933
}
38943934
38953935
/*
38963936
** Return the current file-size of an apnd-file.
3937
+** If the append mark is not yet there, the file-size is 0.
38973938
*/
38983939
static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3899
- ApndFile *p = (ApndFile *)pFile;
3900
- int rc;
3901
- pFile = ORIGFILE(p);
3902
- rc = pFile->pMethods->xFileSize(pFile, pSize);
3903
- if( rc==SQLITE_OK && p->iPgOne ){
3904
- *pSize -= p->iPgOne + APND_MARK_SIZE;
3905
- }
3906
- return rc;
3940
+ ApndFile *paf = (ApndFile *)pFile;
3941
+ *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
3942
+ return SQLITE_OK;
39073943
}
39083944
39093945
/*
39103946
** Lock an apnd-file.
39113947
*/
@@ -3932,16 +3968,16 @@
39323968
39333969
/*
39343970
** File control method. For custom operations on an apnd-file.
39353971
*/
39363972
static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
3937
- ApndFile *p = (ApndFile *)pFile;
3973
+ ApndFile *paf = (ApndFile *)pFile;
39383974
int rc;
39393975
pFile = ORIGFILE(pFile);
39403976
rc = pFile->pMethods->xFileControl(pFile, op, pArg);
39413977
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
3942
- *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", p->iPgOne, *(char**)pArg);
3978
+ *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
39433979
}
39443980
return rc;
39453981
}
39463982
39473983
/*
@@ -3996,10 +4032,12 @@
39964032
sqlite3_int64 iOfst,
39974033
int iAmt,
39984034
void **pp
39994035
){
40004036
ApndFile *p = (ApndFile *)pFile;
4037
+ if( p->iMark < 0 || iOfst+iAmt > p->iMark)
4038
+ return SQLITE_IOERR; /* Cannot read what is not yet there. */
40014039
pFile = ORIGFILE(pFile);
40024040
return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
40034041
}
40044042
40054043
/* Release a memory-mapped page */
@@ -4007,44 +4045,83 @@
40074045
ApndFile *p = (ApndFile *)pFile;
40084046
pFile = ORIGFILE(pFile);
40094047
return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
40104048
}
40114049
4012
-/*
4013
-** Check to see if the file is an ordinary SQLite database file.
4014
-*/
4015
-static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4016
- int rc;
4017
- char zHdr[16];
4018
- static const char aSqliteHdr[] = "SQLite format 3";
4019
- if( sz<512 ) return 0;
4020
- rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0);
4021
- if( rc ) return 0;
4022
- return memcmp(zHdr, aSqliteHdr, sizeof(zHdr))==0;
4023
-}
4024
-
40254050
/*
40264051
** Try to read the append-mark off the end of a file. Return the
4027
-** start of the appended database if the append-mark is present. If
4028
-** there is no append-mark, return -1;
4052
+** start of the appended database if the append-mark is present.
4053
+** If there is no valid append-mark, return -1;
4054
+**
4055
+** An append-mark is only valid if the NNNNNNNN start-of-database offset
4056
+** indicates that the appended database contains at least one page. The
4057
+** start-of-database value must be a multiple of 512.
40294058
*/
40304059
static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
40314060
int rc, i;
40324061
sqlite3_int64 iMark;
4062
+ int msbs = 8 * (APND_MARK_FOS_SZ-1);
40334063
unsigned char a[APND_MARK_SIZE];
40344064
4035
- if( sz<=APND_MARK_SIZE ) return -1;
4065
+ if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
40364066
rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
40374067
if( rc ) return -1;
40384068
if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
4039
- iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ]&0x7f))<<56;
4040
- for(i=1; i<8; i++){
4041
- iMark += (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<(56-8*i);
4069
+ iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
4070
+ for(i=1; i<8; i++){
4071
+ msbs -= 8;
4072
+ iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
40424073
}
4074
+ if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
4075
+ if( iMark & 0x1ff ) return -1;
40434076
return iMark;
40444077
}
40454078
4079
+static const char apvfsSqliteHdr[] = "SQLite format 3";
4080
+/*
4081
+** Check to see if the file is an appendvfs SQLite database file.
4082
+** Return true iff it is such. Parameter sz is the file's size.
4083
+*/
4084
+static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4085
+ int rc;
4086
+ char zHdr[16];
4087
+ sqlite3_int64 iMark = apndReadMark(sz, pFile);
4088
+ if( iMark>=0 ){
4089
+ /* If file has right end-marker, the expected odd size, and the
4090
+ * SQLite DB type marker where the end-marker puts it, then it
4091
+ * is an appendvfs database (to be treated as such.)
4092
+ */
4093
+ rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4094
+ if( SQLITE_OK==rc && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4095
+ && (sz & 0x1ff)== APND_MARK_SIZE && sz>=512+APND_MARK_SIZE )
4096
+ return 1; /* It's an appendvfs database */
4097
+ }
4098
+ return 0;
4099
+}
4100
+
4101
+/*
4102
+** Check to see if the file is an ordinary SQLite database file.
4103
+** Return true iff so. Parameter sz is the file's size.
4104
+*/
4105
+static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4106
+ char zHdr[16];
4107
+ if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
4108
+ || (sz & 0x1ff) != 0
4109
+ || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
4110
+ || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
4111
+ ){
4112
+ return 0;
4113
+ }else{
4114
+ return 1;
4115
+ }
4116
+}
4117
+
4118
+/* Round-up used to get appendvfs portion to begin at a page boundary. */
4119
+#define APND_ALIGN_MASK(nbits) ((1<<nbits)-1)
4120
+#define APND_START_ROUNDUP(fsz, nbits) \
4121
+ ( ((fsz)+APND_ALIGN_MASK(nbits)) & ~(sqlite3_int64)APND_ALIGN_MASK(nbits) )
4122
+
40464123
/*
40474124
** Open an apnd file handle.
40484125
*/
40494126
static int apndOpen(
40504127
sqlite3_vfs *pVfs,
@@ -4058,10 +4135,11 @@
40584135
sqlite3_vfs *pSubVfs;
40594136
int rc;
40604137
sqlite3_int64 sz;
40614138
pSubVfs = ORIGVFS(pVfs);
40624139
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4140
+ /* The appendvfs is not to be used for transient or temporary databases. */
40634141
return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
40644142
}
40654143
p = (ApndFile*)pFile;
40664144
memset(p, 0, sizeof(*p));
40674145
pSubFile = ORIGFILE(pFile);
@@ -4075,31 +4153,46 @@
40754153
}
40764154
if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
40774155
memmove(pFile, pSubFile, pSubVfs->szOsFile);
40784156
return SQLITE_OK;
40794157
}
4080
- p->iMark = 0;
4158
+ /* Record that append mark has not been written until seen otherwise. */
4159
+ p->iMark = -1;
40814160
p->iPgOne = apndReadMark(sz, pFile);
4082
- if( p->iPgOne>0 ){
4161
+ if( p->iPgOne>=0 ){
4162
+ /* Append mark was found, infer its offset */
4163
+ p->iMark = sz - p->iPgOne - APND_MARK_SIZE;
40834164
return SQLITE_OK;
40844165
}
40854166
if( (flags & SQLITE_OPEN_CREATE)==0 ){
40864167
pSubFile->pMethods->xClose(pSubFile);
40874168
rc = SQLITE_CANTOPEN;
40884169
}
4089
- p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
4170
+ /* Round newly added appendvfs location to #define'd page boundary.
4171
+ * Note that nothing has yet been written to the underlying file.
4172
+ * The append mark will be written along with first content write.
4173
+ * Until then, the p->iMark value indicates it is not yet written.
4174
+ */
4175
+ p->iPgOne = APND_START_ROUNDUP(sz, APND_ROUNDUP_BITS);
40904176
apnd_open_done:
40914177
if( rc ) pFile->pMethods = 0;
40924178
return rc;
40934179
}
40944180
40954181
/*
4096
-** All other VFS methods are pass-thrus.
4182
+** Delete an apnd file.
4183
+** For an appendvfs, this could mean delete the appendvfs portion,
4184
+** leaving the appendee as it was before it gained an appendvfs.
4185
+** For now, this code deletes the underlying file too.
40974186
*/
40984187
static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
40994188
return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
41004189
}
4190
+
4191
+/*
4192
+** All other VFS methods are pass-thrus.
4193
+*/
41014194
static int apndAccess(
41024195
sqlite3_vfs *pVfs,
41034196
const char *zPath,
41044197
int flags,
41054198
int *pResOut
@@ -5202,10 +5295,18 @@
52025295
sqlite3_int64 m, e, a;
52035296
double r;
52045297
int isNeg = 0;
52055298
m = sqlite3_value_int64(argv[0]);
52065299
e = sqlite3_value_int64(argv[1]);
5300
+
5301
+ /* Limit the range of e. Ticket 22dea1cfdb9151e4 2021-03-02 */
5302
+ if( e>10000 ){
5303
+ e = 10000;
5304
+ }else if( e<-10000 ){
5305
+ e = -10000;
5306
+ }
5307
+
52075308
if( m<0 ){
52085309
isNeg = 1;
52095310
m = -m;
52105311
if( m<0 ) return;
52115312
}else if( m==0 && e>-1000 && e<1000 ){
@@ -20865,11 +20966,12 @@
2086520966
}
2086620967
return argv[i];
2086720968
}
2086820969
2086920970
#ifndef SQLITE_SHELL_IS_UTF8
20870
-# if (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
20971
+# if (defined(_WIN32) || defined(WIN32)) \
20972
+ && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
2087120973
# define SQLITE_SHELL_IS_UTF8 (0)
2087220974
# else
2087320975
# define SQLITE_SHELL_IS_UTF8 (1)
2087420976
# endif
2087520977
#endif
2087620978
--- src/shell.c
+++ src/shell.c
@@ -3638,42 +3638,41 @@
3638 **
3639 ** This file implements a VFS shim that allows an SQLite database to be
3640 ** appended onto the end of some other file, such as an executable.
3641 **
3642 ** A special record must appear at the end of the file that identifies the
3643 ** file as an appended database and provides an offset to page 1. For
3644 ** best performance page 1 should be located at a disk page boundary, though
3645 ** that is not required.
 
3646 **
3647 ** When opening a database using this VFS, the connection might treat
3648 ** the file as an ordinary SQLite database, or it might treat is as a
3649 ** database appended onto some other file. Here are the rules:
3650 **
3651 ** (1) When opening a new empty file, that file is treated as an ordinary
3652 ** database.
3653 **
3654 ** (2) When opening a file that begins with the standard SQLite prefix
3655 ** string "SQLite format 3", that file is treated as an ordinary
3656 ** database.
3657 **
3658 ** (3) When opening a file that ends with the appendvfs trailer string
3659 ** "Start-Of-SQLite3-NNNNNNNN" that file is treated as an appended
3660 ** database.
3661 **
3662 ** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3663 ** set, then a new database is appended to the already existing file.
3664 **
3665 ** (5) Otherwise, SQLITE_CANTOPEN is returned.
3666 **
3667 ** To avoid unnecessary complications with the PENDING_BYTE, the size of
3668 ** the file containing the database is limited to 1GB. This VFS will refuse
3669 ** to read or write past the 1GB mark. This restriction might be lifted in
3670 ** future versions. For now, if you need a large database, then keep the
3671 ** database in a separate file.
3672 **
3673 ** If the file being opened is not an appended database, then this shim is
3674 ** a pass-through into the default underlying VFS.
3675 **/
3676 /* #include "sqlite3ext.h" */
3677 SQLITE_EXTENSION_INIT1
3678 #include <string.h>
3679 #include <assert.h>
@@ -3682,22 +3681,30 @@
3682 **
3683 ** Start-Of-SQLite3-NNNNNNNN
3684 ** 123456789 123456789 12345
3685 **
3686 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3687 ** the offset to page 1.
3688 */
3689 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
3690 #define APND_MARK_PREFIX_SZ 17
3691 #define APND_MARK_SIZE 25
 
3692
3693 /*
3694 ** Maximum size of the combined prefix + database + append-mark. This
3695 ** must be less than 0x40000000 to avoid locking issues on Windows.
3696 */
3697 #define APND_MAX_SIZE (65536*15259)
3698
 
 
 
 
 
 
 
3699 /*
3700 ** Forward declaration of objects used by this utility
3701 */
3702 typedef struct sqlite3_vfs ApndVfs;
3703 typedef struct ApndFile ApndFile;
@@ -3706,15 +3713,43 @@
3706 ** access to randomness, etc.
3707 */
3708 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3709 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3710
3711 /* An open file */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3712 struct ApndFile {
3713 sqlite3_file base; /* IO methods */
3714 sqlite3_int64 iPgOne; /* File offset to page 1 */
3715 sqlite3_int64 iMark; /* Start of the append-mark */
 
 
 
3716 };
3717
3718 /*
3719 ** Methods for ApndFile
3720 */
@@ -3802,12 +3837,10 @@
3802 apndShmUnmap, /* xShmUnmap */
3803 apndFetch, /* xFetch */
3804 apndUnfetch /* xUnfetch */
3805 };
3806
3807
3808
3809 /*
3810 ** Close an apnd-file.
3811 */
3812 static int apndClose(sqlite3_file *pFile){
3813 pFile = ORIGFILE(pFile);
@@ -3821,26 +3854,41 @@
3821 sqlite3_file *pFile,
3822 void *zBuf,
3823 int iAmt,
3824 sqlite_int64 iOfst
3825 ){
3826 ApndFile *p = (ApndFile *)pFile;
3827 pFile = ORIGFILE(pFile);
3828 return pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3829 }
3830
3831 /*
3832 ** Add the append-mark onto the end of the file.
 
 
3833 */
3834 static int apndWriteMark(ApndFile *p, sqlite3_file *pFile){
3835 int i;
 
 
 
 
3836 unsigned char a[APND_MARK_SIZE];
 
 
 
3837 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3838 for(i=0; i<8; i++){
3839 a[APND_MARK_PREFIX_SZ+i] = (p->iPgOne >> (56 - i*8)) & 0xff;
 
3840 }
3841 return pFile->pMethods->xWrite(pFile, a, APND_MARK_SIZE, p->iMark);
 
 
 
 
 
3842 }
3843
3844 /*
3845 ** Write data to an apnd-file.
3846 */
@@ -3848,42 +3896,34 @@
3848 sqlite3_file *pFile,
3849 const void *zBuf,
3850 int iAmt,
3851 sqlite_int64 iOfst
3852 ){
3853 int rc;
3854 ApndFile *p = (ApndFile *)pFile;
 
3855 pFile = ORIGFILE(pFile);
3856 if( iOfst+iAmt>=APND_MAX_SIZE ) return SQLITE_FULL;
3857 rc = pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3858 if( rc==SQLITE_OK && iOfst + iAmt + p->iPgOne > p->iMark ){
3859 sqlite3_int64 sz = 0;
3860 rc = pFile->pMethods->xFileSize(pFile, &sz);
3861 if( rc==SQLITE_OK ){
3862 p->iMark = sz - APND_MARK_SIZE;
3863 if( iOfst + iAmt + p->iPgOne > p->iMark ){
3864 p->iMark = p->iPgOne + iOfst + iAmt;
3865 rc = apndWriteMark(p, pFile);
3866 }
3867 }
3868 }
3869 return rc;
3870 }
3871
3872 /*
3873 ** Truncate an apnd-file.
3874 */
3875 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3876 int rc;
3877 ApndFile *p = (ApndFile *)pFile;
3878 pFile = ORIGFILE(pFile);
3879 rc = pFile->pMethods->xTruncate(pFile, size+p->iPgOne+APND_MARK_SIZE);
3880 if( rc==SQLITE_OK ){
3881 p->iMark = p->iPgOne+size;
3882 rc = apndWriteMark(p, pFile);
3883 }
3884 return rc;
3885 }
3886
3887 /*
3888 ** Sync an apnd-file.
3889 */
@@ -3892,20 +3932,16 @@
3892 return pFile->pMethods->xSync(pFile, flags);
3893 }
3894
3895 /*
3896 ** Return the current file-size of an apnd-file.
 
3897 */
3898 static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3899 ApndFile *p = (ApndFile *)pFile;
3900 int rc;
3901 pFile = ORIGFILE(p);
3902 rc = pFile->pMethods->xFileSize(pFile, pSize);
3903 if( rc==SQLITE_OK && p->iPgOne ){
3904 *pSize -= p->iPgOne + APND_MARK_SIZE;
3905 }
3906 return rc;
3907 }
3908
3909 /*
3910 ** Lock an apnd-file.
3911 */
@@ -3932,16 +3968,16 @@
3932
3933 /*
3934 ** File control method. For custom operations on an apnd-file.
3935 */
3936 static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
3937 ApndFile *p = (ApndFile *)pFile;
3938 int rc;
3939 pFile = ORIGFILE(pFile);
3940 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
3941 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
3942 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", p->iPgOne, *(char**)pArg);
3943 }
3944 return rc;
3945 }
3946
3947 /*
@@ -3996,10 +4032,12 @@
3996 sqlite3_int64 iOfst,
3997 int iAmt,
3998 void **pp
3999 ){
4000 ApndFile *p = (ApndFile *)pFile;
 
 
4001 pFile = ORIGFILE(pFile);
4002 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4003 }
4004
4005 /* Release a memory-mapped page */
@@ -4007,44 +4045,83 @@
4007 ApndFile *p = (ApndFile *)pFile;
4008 pFile = ORIGFILE(pFile);
4009 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
4010 }
4011
4012 /*
4013 ** Check to see if the file is an ordinary SQLite database file.
4014 */
4015 static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4016 int rc;
4017 char zHdr[16];
4018 static const char aSqliteHdr[] = "SQLite format 3";
4019 if( sz<512 ) return 0;
4020 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0);
4021 if( rc ) return 0;
4022 return memcmp(zHdr, aSqliteHdr, sizeof(zHdr))==0;
4023 }
4024
4025 /*
4026 ** Try to read the append-mark off the end of a file. Return the
4027 ** start of the appended database if the append-mark is present. If
4028 ** there is no append-mark, return -1;
 
 
 
 
4029 */
4030 static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
4031 int rc, i;
4032 sqlite3_int64 iMark;
 
4033 unsigned char a[APND_MARK_SIZE];
4034
4035 if( sz<=APND_MARK_SIZE ) return -1;
4036 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
4037 if( rc ) return -1;
4038 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
4039 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ]&0x7f))<<56;
4040 for(i=1; i<8; i++){
4041 iMark += (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<(56-8*i);
 
4042 }
 
 
4043 return iMark;
4044 }
4045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4046 /*
4047 ** Open an apnd file handle.
4048 */
4049 static int apndOpen(
4050 sqlite3_vfs *pVfs,
@@ -4058,10 +4135,11 @@
4058 sqlite3_vfs *pSubVfs;
4059 int rc;
4060 sqlite3_int64 sz;
4061 pSubVfs = ORIGVFS(pVfs);
4062 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
 
4063 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
4064 }
4065 p = (ApndFile*)pFile;
4066 memset(p, 0, sizeof(*p));
4067 pSubFile = ORIGFILE(pFile);
@@ -4075,31 +4153,46 @@
4075 }
4076 if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
4077 memmove(pFile, pSubFile, pSubVfs->szOsFile);
4078 return SQLITE_OK;
4079 }
4080 p->iMark = 0;
 
4081 p->iPgOne = apndReadMark(sz, pFile);
4082 if( p->iPgOne>0 ){
 
 
4083 return SQLITE_OK;
4084 }
4085 if( (flags & SQLITE_OPEN_CREATE)==0 ){
4086 pSubFile->pMethods->xClose(pSubFile);
4087 rc = SQLITE_CANTOPEN;
4088 }
4089 p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
 
 
 
 
 
4090 apnd_open_done:
4091 if( rc ) pFile->pMethods = 0;
4092 return rc;
4093 }
4094
4095 /*
4096 ** All other VFS methods are pass-thrus.
 
 
 
4097 */
4098 static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
4099 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
4100 }
 
 
 
 
4101 static int apndAccess(
4102 sqlite3_vfs *pVfs,
4103 const char *zPath,
4104 int flags,
4105 int *pResOut
@@ -5202,10 +5295,18 @@
5202 sqlite3_int64 m, e, a;
5203 double r;
5204 int isNeg = 0;
5205 m = sqlite3_value_int64(argv[0]);
5206 e = sqlite3_value_int64(argv[1]);
 
 
 
 
 
 
 
 
5207 if( m<0 ){
5208 isNeg = 1;
5209 m = -m;
5210 if( m<0 ) return;
5211 }else if( m==0 && e>-1000 && e<1000 ){
@@ -20865,11 +20966,12 @@
20865 }
20866 return argv[i];
20867 }
20868
20869 #ifndef SQLITE_SHELL_IS_UTF8
20870 # if (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
 
20871 # define SQLITE_SHELL_IS_UTF8 (0)
20872 # else
20873 # define SQLITE_SHELL_IS_UTF8 (1)
20874 # endif
20875 #endif
20876
--- src/shell.c
+++ src/shell.c
@@ -3638,42 +3638,41 @@
3638 **
3639 ** This file implements a VFS shim that allows an SQLite database to be
3640 ** appended onto the end of some other file, such as an executable.
3641 **
3642 ** A special record must appear at the end of the file that identifies the
3643 ** file as an appended database and provides the offset to the first page
3644 ** of the exposed content. (Or, it is the length of the content prefix.)
3645 ** For best performance page 1 should be located at a disk page boundary,
3646 ** though that is not required.
3647 **
3648 ** When opening a database using this VFS, the connection might treat
3649 ** the file as an ordinary SQLite database, or it might treat it as a
3650 ** database appended onto some other file. The decision is made by
3651 ** applying the following rules in order:
3652 **
3653 ** (1) An empty file is an ordinary database.
3654 **
3655 ** (2) If the file ends with the appendvfs trailer string
3656 ** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
3657 **
3658 ** (3) If the file begins with the standard SQLite prefix string
3659 ** "SQLite format 3", that file is an ordinary database.
 
 
3660 **
3661 ** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3662 ** set, then a new database is appended to the already existing file.
3663 **
3664 ** (5) Otherwise, SQLITE_CANTOPEN is returned.
3665 **
3666 ** To avoid unnecessary complications with the PENDING_BYTE, the size of
3667 ** the file containing the database is limited to 1GB. (1000013824 bytes)
3668 ** This VFS will not read or write past the 1GB mark. This restriction
3669 ** might be lifted in future versions. For now, if you need a larger
3670 ** database, then keep it in a separate file.
3671 **
3672 ** If the file being opened is a plain database (not an appended one), then
3673 ** this shim is a pass-through into the default underlying VFS. (rule 3)
3674 **/
3675 /* #include "sqlite3ext.h" */
3676 SQLITE_EXTENSION_INIT1
3677 #include <string.h>
3678 #include <assert.h>
@@ -3682,22 +3681,30 @@
3681 **
3682 ** Start-Of-SQLite3-NNNNNNNN
3683 ** 123456789 123456789 12345
3684 **
3685 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3686 ** the offset to page 1, and also the length of the prefix content.
3687 */
3688 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
3689 #define APND_MARK_PREFIX_SZ 17
3690 #define APND_MARK_FOS_SZ 8
3691 #define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
3692
3693 /*
3694 ** Maximum size of the combined prefix + database + append-mark. This
3695 ** must be less than 0x40000000 to avoid locking issues on Windows.
3696 */
3697 #define APND_MAX_SIZE (65536*15259)
3698
3699 /*
3700 ** Size of storage page upon which to align appendvfs portion.
3701 */
3702 #ifndef APND_ROUNDUP_BITS
3703 #define APND_ROUNDUP_BITS 12
3704 #endif
3705
3706 /*
3707 ** Forward declaration of objects used by this utility
3708 */
3709 typedef struct sqlite3_vfs ApndVfs;
3710 typedef struct ApndFile ApndFile;
@@ -3706,15 +3713,43 @@
3713 ** access to randomness, etc.
3714 */
3715 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3716 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3717
3718 /* Invariants for an open appendvfs file:
3719 * Once an appendvfs file is opened, it will be in one of three states:
3720 * State 0: Never written. Underlying file (if any) is unaltered.
3721 * State 1: Append mark is persisted, content write is in progress.
3722 * State 2: Append mark is persisted, content writes are complete.
3723 *
3724 * State 0 is persistent in the sense that nothing will have been done
3725 * to the underlying file, including any attempt to convert it to an
3726 * appendvfs file.
3727 *
3728 * State 1 is normally transitory. However, if a write operation ends
3729 * abnormally (disk full, power loss, process kill, etc.), then State 1
3730 * may be persistent on disk with an incomplete content write-out. This
3731 * is logically equivalent to an interrupted write to an ordinary file,
3732 * where some unknown portion of to-be-written data is persisted while
3733 * the remainder is not. Database integrity in such cases is maintained
3734 * (or not) by the same measures available for ordinary file access.
3735 *
3736 * State 2 is persistent under normal circumstances (when there is no
3737 * abnormal termination of a write operation such that data provided
3738 * to the underlying VFS write method has not yet reached storage.)
3739 *
3740 * In order to maintain the state invariant, the append mark is written
3741 * in advance of content writes where any part of such content would
3742 * overwrite an existing (or yet to be written) append mark.
3743 */
3744 struct ApndFile {
3745 /* Access to IO methods of the underlying file */
3746 sqlite3_file base;
3747 /* File offset to beginning of appended content (unchanging) */
3748 sqlite3_int64 iPgOne;
3749 /* File offset of written append-mark, or -1 if unwritten */
3750 sqlite3_int64 iMark;
3751 };
3752
3753 /*
3754 ** Methods for ApndFile
3755 */
@@ -3802,12 +3837,10 @@
3837 apndShmUnmap, /* xShmUnmap */
3838 apndFetch, /* xFetch */
3839 apndUnfetch /* xUnfetch */
3840 };
3841
 
 
3842 /*
3843 ** Close an apnd-file.
3844 */
3845 static int apndClose(sqlite3_file *pFile){
3846 pFile = ORIGFILE(pFile);
@@ -3821,26 +3854,41 @@
3854 sqlite3_file *pFile,
3855 void *zBuf,
3856 int iAmt,
3857 sqlite_int64 iOfst
3858 ){
3859 ApndFile *paf = (ApndFile *)pFile;
3860 pFile = ORIGFILE(pFile);
3861 return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3862 }
3863
3864 /*
3865 ** Add the append-mark onto what should become the end of the file.
3866 * If and only if this succeeds, internal ApndFile.iMark is updated.
3867 * Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
3868 */
3869 static int apndWriteMark(
3870 ApndFile *paf,
3871 sqlite3_file *pFile,
3872 sqlite_int64 iWriteEnd
3873 ){
3874 sqlite_int64 iPgOne = paf->iPgOne;
3875 unsigned char a[APND_MARK_SIZE];
3876 int i = APND_MARK_FOS_SZ;
3877 int rc;
3878 assert(pFile == ORIGFILE(paf));
3879 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3880 while (--i >= 0) {
3881 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
3882 iPgOne >>= 8;
3883 }
3884 iWriteEnd += paf->iPgOne;
3885 if( SQLITE_OK==(rc = pFile->pMethods->xWrite
3886 (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
3887 paf->iMark = iWriteEnd;
3888 }
3889 return rc;
3890 }
3891
3892 /*
3893 ** Write data to an apnd-file.
3894 */
@@ -3848,42 +3896,34 @@
3896 sqlite3_file *pFile,
3897 const void *zBuf,
3898 int iAmt,
3899 sqlite_int64 iOfst
3900 ){
3901 ApndFile *paf = (ApndFile *)pFile;
3902 sqlite_int64 iWriteEnd = iOfst + iAmt;
3903 if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
3904 pFile = ORIGFILE(pFile);
3905 /* If append-mark is absent or will be overwritten, write it. */
3906 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
3907 int rc = apndWriteMark(paf, pFile, iWriteEnd);
3908 if( SQLITE_OK!=rc )
3909 return rc;
3910 }
3911 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
 
 
 
 
 
 
 
3912 }
3913
3914 /*
3915 ** Truncate an apnd-file.
3916 */
3917 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3918 ApndFile *paf = (ApndFile *)pFile;
 
3919 pFile = ORIGFILE(pFile);
3920 /* The append mark goes out first so truncate failure does not lose it. */
3921 if( SQLITE_OK!=apndWriteMark(paf, pFile, size) )
3922 return SQLITE_IOERR;
3923 /* Truncate underlying file just past append mark */
3924 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
 
3925 }
3926
3927 /*
3928 ** Sync an apnd-file.
3929 */
@@ -3892,20 +3932,16 @@
3932 return pFile->pMethods->xSync(pFile, flags);
3933 }
3934
3935 /*
3936 ** Return the current file-size of an apnd-file.
3937 ** If the append mark is not yet there, the file-size is 0.
3938 */
3939 static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3940 ApndFile *paf = (ApndFile *)pFile;
3941 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
3942 return SQLITE_OK;
 
 
 
 
 
3943 }
3944
3945 /*
3946 ** Lock an apnd-file.
3947 */
@@ -3932,16 +3968,16 @@
3968
3969 /*
3970 ** File control method. For custom operations on an apnd-file.
3971 */
3972 static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
3973 ApndFile *paf = (ApndFile *)pFile;
3974 int rc;
3975 pFile = ORIGFILE(pFile);
3976 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
3977 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
3978 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
3979 }
3980 return rc;
3981 }
3982
3983 /*
@@ -3996,10 +4032,12 @@
4032 sqlite3_int64 iOfst,
4033 int iAmt,
4034 void **pp
4035 ){
4036 ApndFile *p = (ApndFile *)pFile;
4037 if( p->iMark < 0 || iOfst+iAmt > p->iMark)
4038 return SQLITE_IOERR; /* Cannot read what is not yet there. */
4039 pFile = ORIGFILE(pFile);
4040 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4041 }
4042
4043 /* Release a memory-mapped page */
@@ -4007,44 +4045,83 @@
4045 ApndFile *p = (ApndFile *)pFile;
4046 pFile = ORIGFILE(pFile);
4047 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
4048 }
4049
 
 
 
 
 
 
 
 
 
 
 
 
 
4050 /*
4051 ** Try to read the append-mark off the end of a file. Return the
4052 ** start of the appended database if the append-mark is present.
4053 ** If there is no valid append-mark, return -1;
4054 **
4055 ** An append-mark is only valid if the NNNNNNNN start-of-database offset
4056 ** indicates that the appended database contains at least one page. The
4057 ** start-of-database value must be a multiple of 512.
4058 */
4059 static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
4060 int rc, i;
4061 sqlite3_int64 iMark;
4062 int msbs = 8 * (APND_MARK_FOS_SZ-1);
4063 unsigned char a[APND_MARK_SIZE];
4064
4065 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
4066 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
4067 if( rc ) return -1;
4068 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
4069 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
4070 for(i=1; i<8; i++){
4071 msbs -= 8;
4072 iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
4073 }
4074 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
4075 if( iMark & 0x1ff ) return -1;
4076 return iMark;
4077 }
4078
4079 static const char apvfsSqliteHdr[] = "SQLite format 3";
4080 /*
4081 ** Check to see if the file is an appendvfs SQLite database file.
4082 ** Return true iff it is such. Parameter sz is the file's size.
4083 */
4084 static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4085 int rc;
4086 char zHdr[16];
4087 sqlite3_int64 iMark = apndReadMark(sz, pFile);
4088 if( iMark>=0 ){
4089 /* If file has right end-marker, the expected odd size, and the
4090 * SQLite DB type marker where the end-marker puts it, then it
4091 * is an appendvfs database (to be treated as such.)
4092 */
4093 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4094 if( SQLITE_OK==rc && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4095 && (sz & 0x1ff)== APND_MARK_SIZE && sz>=512+APND_MARK_SIZE )
4096 return 1; /* It's an appendvfs database */
4097 }
4098 return 0;
4099 }
4100
4101 /*
4102 ** Check to see if the file is an ordinary SQLite database file.
4103 ** Return true iff so. Parameter sz is the file's size.
4104 */
4105 static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4106 char zHdr[16];
4107 if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
4108 || (sz & 0x1ff) != 0
4109 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
4110 || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
4111 ){
4112 return 0;
4113 }else{
4114 return 1;
4115 }
4116 }
4117
4118 /* Round-up used to get appendvfs portion to begin at a page boundary. */
4119 #define APND_ALIGN_MASK(nbits) ((1<<nbits)-1)
4120 #define APND_START_ROUNDUP(fsz, nbits) \
4121 ( ((fsz)+APND_ALIGN_MASK(nbits)) & ~(sqlite3_int64)APND_ALIGN_MASK(nbits) )
4122
4123 /*
4124 ** Open an apnd file handle.
4125 */
4126 static int apndOpen(
4127 sqlite3_vfs *pVfs,
@@ -4058,10 +4135,11 @@
4135 sqlite3_vfs *pSubVfs;
4136 int rc;
4137 sqlite3_int64 sz;
4138 pSubVfs = ORIGVFS(pVfs);
4139 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4140 /* The appendvfs is not to be used for transient or temporary databases. */
4141 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
4142 }
4143 p = (ApndFile*)pFile;
4144 memset(p, 0, sizeof(*p));
4145 pSubFile = ORIGFILE(pFile);
@@ -4075,31 +4153,46 @@
4153 }
4154 if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
4155 memmove(pFile, pSubFile, pSubVfs->szOsFile);
4156 return SQLITE_OK;
4157 }
4158 /* Record that append mark has not been written until seen otherwise. */
4159 p->iMark = -1;
4160 p->iPgOne = apndReadMark(sz, pFile);
4161 if( p->iPgOne>=0 ){
4162 /* Append mark was found, infer its offset */
4163 p->iMark = sz - p->iPgOne - APND_MARK_SIZE;
4164 return SQLITE_OK;
4165 }
4166 if( (flags & SQLITE_OPEN_CREATE)==0 ){
4167 pSubFile->pMethods->xClose(pSubFile);
4168 rc = SQLITE_CANTOPEN;
4169 }
4170 /* Round newly added appendvfs location to #define'd page boundary.
4171 * Note that nothing has yet been written to the underlying file.
4172 * The append mark will be written along with first content write.
4173 * Until then, the p->iMark value indicates it is not yet written.
4174 */
4175 p->iPgOne = APND_START_ROUNDUP(sz, APND_ROUNDUP_BITS);
4176 apnd_open_done:
4177 if( rc ) pFile->pMethods = 0;
4178 return rc;
4179 }
4180
4181 /*
4182 ** Delete an apnd file.
4183 ** For an appendvfs, this could mean delete the appendvfs portion,
4184 ** leaving the appendee as it was before it gained an appendvfs.
4185 ** For now, this code deletes the underlying file too.
4186 */
4187 static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
4188 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
4189 }
4190
4191 /*
4192 ** All other VFS methods are pass-thrus.
4193 */
4194 static int apndAccess(
4195 sqlite3_vfs *pVfs,
4196 const char *zPath,
4197 int flags,
4198 int *pResOut
@@ -5202,10 +5295,18 @@
5295 sqlite3_int64 m, e, a;
5296 double r;
5297 int isNeg = 0;
5298 m = sqlite3_value_int64(argv[0]);
5299 e = sqlite3_value_int64(argv[1]);
5300
5301 /* Limit the range of e. Ticket 22dea1cfdb9151e4 2021-03-02 */
5302 if( e>10000 ){
5303 e = 10000;
5304 }else if( e<-10000 ){
5305 e = -10000;
5306 }
5307
5308 if( m<0 ){
5309 isNeg = 1;
5310 m = -m;
5311 if( m<0 ) return;
5312 }else if( m==0 && e>-1000 && e<1000 ){
@@ -20865,11 +20966,12 @@
20966 }
20967 return argv[i];
20968 }
20969
20970 #ifndef SQLITE_SHELL_IS_UTF8
20971 # if (defined(_WIN32) || defined(WIN32)) \
20972 && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
20973 # define SQLITE_SHELL_IS_UTF8 (0)
20974 # else
20975 # define SQLITE_SHELL_IS_UTF8 (1)
20976 # endif
20977 #endif
20978
+134 -74
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
11891189
#define SQLITE_VERSION "3.35.0"
11901190
#define SQLITE_VERSION_NUMBER 3035000
1191
-#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092"
1191
+#define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -3193,11 +3193,17 @@
31933193
** The first argument is an integer which is 0 to disable views,
31943194
** positive to enable views or negative to leave the setting unchanged.
31953195
** The second parameter is a pointer to an integer into which
31963196
** is written 0 or 1 to indicate whether views are disabled or enabled
31973197
** following this call. The second parameter may be a NULL pointer, in
3198
-** which case the view setting is not reported back. </dd>
3198
+** which case the view setting is not reported back.
3199
+**
3200
+** <p>Originally this option disabled all views. ^(However, since
3201
+** SQLite version 3.35.0, TEMP views are still allowed even if
3202
+** this option is off. So, in other words, this option now only disables
3203
+** views in the main database schema or in the schemas of ATTACH-ed
3204
+** databases.)^ </dd>
31993205
**
32003206
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
32013207
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
32023208
** <dd> ^This option is used to enable or disable the
32033209
** [fts3_tokenizer()] function which is part of the
@@ -15368,11 +15374,11 @@
1536815374
1536915375
/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
1537015376
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
1537115377
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
1537215378
#define BTREE_APPEND 0x08 /* Insert is likely an append */
15373
-#define BTREE_PREFORMAT 0x80 /* Insert is likely an append */
15379
+#define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
1537415380
1537515381
/* An instance of the BtreePayload object describes the content of a single
1537615382
** entry in either an index or table btree.
1537715383
**
1537815384
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -20256,10 +20262,11 @@
2025620262
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
2025720263
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
2025820264
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
2025920265
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
2026020266
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
20267
+SQLITE_PRIVATE const char *sqlite3SelectOpName(int);
2026120268
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse*, ExprList*);
2026220269
2026320270
#ifdef SQLITE_DEBUG
2026420271
SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
2026520272
#endif
@@ -29330,11 +29337,11 @@
2933029337
setStrAccumError(p, SQLITE_TOOBIG);
2933129338
return p->nAlloc - p->nChar - 1;
2933229339
}else{
2933329340
char *zOld = isMalloced(p) ? p->zText : 0;
2933429341
i64 szNew = p->nChar;
29335
- szNew += N + 1;
29342
+ szNew += (sqlite3_int64)N + 1;
2933629343
if( szNew+p->nChar<=p->mxAlloc ){
2933729344
/* Force exponential buffer size growth as long as it does not overflow,
2933829345
** to avoid having to call this routine too often */
2933929346
szNew += p->nChar;
2934029347
}
@@ -87395,11 +87402,11 @@
8739587402
case OP_ChngCntRow: {
8739687403
assert( pOp->p2==1 );
8739787404
if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
8739887405
goto abort_due_to_error;
8739987406
}
87400
- /* Fall through to the next case, OP_String */
87407
+ /* Fall through to the next case, OP_ResultRow */
8740187408
/* no break */ deliberate_fall_through
8740287409
}
8740387410
8740487411
/* Opcode: ResultRow P1 P2 * * *
8740587412
** Synopsis: output=r[P1@P2]
@@ -98169,11 +98176,11 @@
9816998176
}else{
9817098177
i64 iOff = p->nChunkSize;
9817198178
for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
9817298179
iOff += p->nChunkSize;
9817398180
}
98174
- if( pIter ){
98181
+ if( ALWAYS(pIter) ){
9817598182
memjrnlFreeChunks(pIter->pNext);
9817698183
pIter->pNext = 0;
9817798184
}
9817898185
}
9817998186
@@ -99006,10 +99013,11 @@
9900699013
/* IMP: R-51414-32910 */
9900799014
iCol = -1;
9900899015
}
9900999016
if( iCol<pTab->nCol ){
9901099017
cnt++;
99018
+ pMatch = 0;
9901199019
#ifndef SQLITE_OMIT_UPSERT
9901299020
if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
9901399021
testcase( iCol==(-1) );
9901499022
if( IN_RENAME_OBJECT ){
9901599023
pExpr->iColumn = iCol;
@@ -99024,12 +99032,12 @@
9902499032
#endif /* SQLITE_OMIT_UPSERT */
9902599033
{
9902699034
pExpr->y.pTab = pTab;
9902799035
if( pParse->bReturning ){
9902899036
eNewExprOp = TK_REGISTER;
99029
- pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable
99030
- + iCol + 1;
99037
+ pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
99038
+ sqlite3TableColumnToStorage(pTab, iCol) + 1;
9903199039
}else{
9903299040
pExpr->iColumn = (i16)iCol;
9903399041
eNewExprOp = TK_TRIGGER;
9903499042
#ifndef SQLITE_OMIT_TRIGGER
9903599043
if( iCol<0 ){
@@ -99225,15 +99233,17 @@
9922599233
pExpr->op = eNewExprOp;
9922699234
ExprSetProperty(pExpr, EP_Leaf);
9922799235
lookupname_end:
9922899236
if( cnt==1 ){
9922999237
assert( pNC!=0 );
99238
+#ifndef SQLITE_OMIT_AUTHORIZATION
9923099239
if( pParse->db->xAuth
9923199240
&& (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER)
9923299241
){
9923399242
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
9923499243
}
99244
+#endif
9923599245
/* Increment the nRef value on all name contexts from TopNC up to
9923699246
** the point where the name matched. */
9923799247
for(;;){
9923899248
assert( pTopNC!=0 );
9923999249
pTopNC->nRef++;
@@ -99374,20 +99384,23 @@
9937499384
pExpr->iColumn--;
9937599385
pExpr->affExpr = SQLITE_AFF_INTEGER;
9937699386
break;
9937799387
}
9937899388
99379
- /* An "<expr> IS NOT NULL" or "<expr> IS NULL". After resolving the
99380
- ** LHS, check if there is a NOT NULL constraint in the schema that
99381
- ** means the value of the expression can be determined immediately.
99382
- ** If that is the case, replace the current expression node with
99383
- ** a TK_TRUEFALSE node.
99389
+ /* An optimization: Attempt to convert
9938499390
**
99385
- ** If the node is replaced with a TK_TRUEFALSE node, then also restore
99386
- ** the NameContext ref-counts to the state they where in before the
99387
- ** LHS expression was resolved. This prevents the current select
99388
- ** from being erroneously marked as correlated in some cases.
99391
+ ** "expr IS NOT NULL" --> "TRUE"
99392
+ ** "expr IS NULL" --> "FALSE"
99393
+ **
99394
+ ** if we can prove that "expr" is never NULL. Call this the
99395
+ ** "NOT NULL strength reduction optimization".
99396
+ **
99397
+ ** If this optimization occurs, also restore the NameContext ref-counts
99398
+ ** to the state they where in before the "column" LHS expression was
99399
+ ** resolved. This prevents "column" from being counted as having been
99400
+ ** referenced, which might prevent a SELECT from being erroneously
99401
+ ** marked as correlated.
9938999402
*/
9939099403
case TK_NOTNULL:
9939199404
case TK_ISNULL: {
9939299405
int anRef[8];
9939399406
NameContext *p;
@@ -99394,11 +99407,11 @@
9939499407
int i;
9939599408
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
9939699409
anRef[i] = p->nRef;
9939799410
}
9939899411
sqlite3WalkExpr(pWalker, pExpr->pLeft);
99399
- if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){
99412
+ if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
9940099413
if( pExpr->op==TK_NOTNULL ){
9940199414
pExpr->u.zToken = "true";
9940299415
ExprSetProperty(pExpr, EP_IsTrue);
9940399416
}else{
9940499417
pExpr->u.zToken = "false";
@@ -99639,10 +99652,11 @@
9963999652
if( pWin ){
9964099653
Select *pSel = pNC->pWinSelect;
9964199654
assert( pWin==pExpr->y.pWin );
9964299655
if( IN_RENAME_OBJECT==0 ){
9964399656
sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
99657
+ if( pParse->db->mallocFailed ) break;
9964499658
}
9964599659
sqlite3WalkExprList(pWalker, pWin->pPartition);
9964699660
sqlite3WalkExprList(pWalker, pWin->pOrderBy);
9964799661
sqlite3WalkExpr(pWalker, pWin->pFilter);
9964899662
sqlite3WindowLink(pSel, pWin);
@@ -99713,11 +99727,11 @@
9971399727
case TK_ISNOT: {
9971499728
Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
9971599729
assert( !ExprHasProperty(pExpr, EP_Reduced) );
9971699730
/* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
9971799731
** and "x IS NOT FALSE". */
99718
- if( pRight && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
99732
+ if( ALWAYS(pRight) && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
9971999733
int rc = resolveExprStep(pWalker, pRight);
9972099734
if( rc==WRC_Abort ) return WRC_Abort;
9972199735
if( pRight->op==TK_TRUEFALSE ){
9972299736
pExpr->op2 = pExpr->op;
9972399737
pExpr->op = TK_TRUTH;
@@ -107942,13 +107956,12 @@
107942107956
}
107943107957
if( rc==SQLITE_OK ){
107944107958
rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList);
107945107959
}
107946107960
assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) );
107947
- if( pStep->pUpsert ){
107961
+ if( pStep->pUpsert && rc==SQLITE_OK ){
107948107962
Upsert *pUpsert = pStep->pUpsert;
107949
- assert( rc==SQLITE_OK );
107950107963
pUpsert->pUpsertSrc = pSrc;
107951107964
sNC.uNC.pUpsert = pUpsert;
107952107965
sNC.ncFlags = NC_UUpsert;
107953107966
rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
107954107967
if( rc==SQLITE_OK ){
@@ -108504,14 +108517,15 @@
108504108517
#ifndef SQLITE_OMIT_AUTHORIZATION
108505108518
sqlite3_xauth xAuth = db->xAuth;
108506108519
db->xAuth = 0;
108507108520
#endif
108508108521
108522
+ UNUSED_PARAMETER(NotUsed);
108509108523
rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108510108524
if( rc!=SQLITE_OK ) goto drop_column_done;
108511108525
pTab = sParse.pNewTable;
108512
- if( pTab->nCol==1 || iCol>=pTab->nCol ){
108526
+ if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108513108527
/* This can happen if the sqlite_schema table is corrupt */
108514108528
rc = SQLITE_CORRUPT_BKPT;
108515108529
goto drop_column_done;
108516108530
}
108517108531
@@ -112815,10 +112829,11 @@
112815112829
pParse->u1.pReturning = pRet;
112816112830
pRet->pParse = pParse;
112817112831
pRet->pReturnEL = pList;
112818112832
sqlite3ParserAddCleanup(pParse,
112819112833
(void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
112834
+ testcase( pParse->earlyCleanup );
112820112835
if( db->mallocFailed ) return;
112821112836
pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
112822112837
pRet->retTrig.op = TK_RETURNING;
112823112838
pRet->retTrig.tr_tm = TRIGGER_AFTER;
112824112839
pRet->retTrig.bReturning = 1;
@@ -130625,17 +130640,25 @@
130625130640
** for common cleanups that happen on most calls. But for less
130626130641
** common cleanups, we save a single NULL-pointer comparison in
130627130642
** sqlite3ParserReset(), which reduces the total CPU cycle count.
130628130643
**
130629130644
** If a memory allocation error occurs, then the cleanup happens immediately.
130630
-** When eithr SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
130645
+** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
130631130646
** pParse->earlyCleanup flag is set in that case. Calling code show verify
130632130647
** that test cases exist for which this happens, to guard against possible
130633130648
** use-after-free errors following an OOM. The preferred way to do this is
130634130649
** to immediately follow the call to this routine with:
130635130650
**
130636130651
** testcase( pParse->earlyCleanup );
130652
+**
130653
+** This routine returns a copy of its pPtr input (the third parameter)
130654
+** except if an early cleanup occurs, in which case it returns NULL. So
130655
+** another way to check for early cleanup is to check the return value.
130656
+** Or, stop using the pPtr parameter with this call and use only its
130657
+** return value thereafter. Something like this:
130658
+**
130659
+** pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj);
130637130660
*/
130638130661
SQLITE_PRIVATE void *sqlite3ParserAddCleanup(
130639130662
Parse *pParse, /* Destroy when this Parser finishes */
130640130663
void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */
130641130664
void *pPtr /* Pointer to object to be cleaned up */
@@ -131129,16 +131152,20 @@
131129131152
sqlite3ExprDelete(db, p->pWhere);
131130131153
sqlite3ExprListDelete(db, p->pGroupBy);
131131131154
sqlite3ExprDelete(db, p->pHaving);
131132131155
sqlite3ExprListDelete(db, p->pOrderBy);
131133131156
sqlite3ExprDelete(db, p->pLimit);
131157
+ if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
131134131158
#ifndef SQLITE_OMIT_WINDOWFUNC
131135131159
if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
131136131160
sqlite3WindowListDelete(db, p->pWinDefn);
131137131161
}
131162
+ while( p->pWin ){
131163
+ assert( p->pWin->ppThis==&p->pWin );
131164
+ sqlite3WindowUnlinkFromSelect(p->pWin);
131165
+ }
131138131166
#endif
131139
- if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
131140131167
if( bFree ) sqlite3DbFreeNN(db, p);
131141131168
p = pPrior;
131142131169
bFree = 1;
131143131170
}
131144131171
}
@@ -132430,11 +132457,11 @@
132430132457
}
132431132458
132432132459
/*
132433132460
** Name of the connection operator, used for error messages.
132434132461
*/
132435
-static const char *selectOpName(int id){
132462
+SQLITE_PRIVATE const char *sqlite3SelectOpName(int id){
132436132463
char *z;
132437132464
switch( id ){
132438132465
case TK_ALL: z = "UNION ALL"; break;
132439132466
case TK_INTERSECT: z = "INTERSECT"; break;
132440132467
case TK_EXCEPT: z = "EXCEPT"; break;
@@ -133649,16 +133676,12 @@
133649133676
assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
133650133677
assert( p->selFlags & SF_Compound );
133651133678
db = pParse->db;
133652133679
pPrior = p->pPrior;
133653133680
dest = *pDest;
133654
- if( pPrior->pOrderBy || pPrior->pLimit ){
133655
- sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
133656
- pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op));
133657
- rc = 1;
133658
- goto multi_select_end;
133659
- }
133681
+ assert( pPrior->pOrderBy==0 );
133682
+ assert( pPrior->pLimit==0 );
133660133683
133661133684
v = sqlite3GetVdbe(pParse);
133662133685
assert( v!=0 ); /* The VDBE already created by calling function */
133663133686
133664133687
/* Create the destination temporary table if necessary
@@ -133711,11 +133734,11 @@
133711133734
assert( !pPrior->pLimit );
133712133735
pPrior->iLimit = p->iLimit;
133713133736
pPrior->iOffset = p->iOffset;
133714133737
pPrior->pLimit = p->pLimit;
133715133738
rc = sqlite3Select(pParse, pPrior, &dest);
133716
- p->pLimit = 0;
133739
+ pPrior->pLimit = 0;
133717133740
if( rc ){
133718133741
goto multi_select_end;
133719133742
}
133720133743
p->pPrior = 0;
133721133744
p->iLimit = pPrior->iLimit;
@@ -133732,12 +133755,12 @@
133732133755
rc = sqlite3Select(pParse, p, &dest);
133733133756
testcase( rc!=SQLITE_OK );
133734133757
pDelete = p->pPrior;
133735133758
p->pPrior = pPrior;
133736133759
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
133737
- if( pPrior->pLimit
133738
- && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit)
133760
+ if( p->pLimit
133761
+ && sqlite3ExprIsInteger(p->pLimit->pLeft, &nLimit)
133739133762
&& nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
133740133763
){
133741133764
p->nSelectRow = sqlite3LogEst((u64)nLimit);
133742133765
}
133743133766
if( addr ){
@@ -133797,11 +133820,11 @@
133797133820
p->pPrior = 0;
133798133821
pLimit = p->pLimit;
133799133822
p->pLimit = 0;
133800133823
uniondest.eDest = op;
133801133824
ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133802
- selectOpName(p->op)));
133825
+ sqlite3SelectOpName(p->op)));
133803133826
rc = sqlite3Select(pParse, p, &uniondest);
133804133827
testcase( rc!=SQLITE_OK );
133805133828
assert( p->pOrderBy==0 );
133806133829
pDelete = p->pPrior;
133807133830
p->pPrior = pPrior;
@@ -133873,11 +133896,11 @@
133873133896
p->pPrior = 0;
133874133897
pLimit = p->pLimit;
133875133898
p->pLimit = 0;
133876133899
intersectdest.iSDParm = tab2;
133877133900
ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133878
- selectOpName(p->op)));
133901
+ sqlite3SelectOpName(p->op)));
133879133902
rc = sqlite3Select(pParse, p, &intersectdest);
133880133903
testcase( rc!=SQLITE_OK );
133881133904
pDelete = p->pPrior;
133882133905
p->pPrior = pPrior;
133883133906
if( p->nSelectRow>pPrior->nSelectRow ){
@@ -133982,11 +134005,12 @@
133982134005
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
133983134006
if( p->selFlags & SF_Values ){
133984134007
sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
133985134008
}else{
133986134009
sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
133987
- " do not have the same number of result columns", selectOpName(p->op));
134010
+ " do not have the same number of result columns",
134011
+ sqlite3SelectOpName(p->op));
133988134012
}
133989134013
}
133990134014
133991134015
/*
133992134016
** Code an output subroutine for a coroutine implementation of a
@@ -134079,14 +134103,12 @@
134079134103
** store the results in the appropriate memory cell and break out
134080134104
** of the scan loop. Note that the select might return multiple columns
134081134105
** if it is the RHS of a row-value IN operator.
134082134106
*/
134083134107
case SRT_Mem: {
134084
- if( pParse->nErr==0 ){
134085
- testcase( pIn->nSdst>1 );
134086
- sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
134087
- }
134108
+ testcase( pIn->nSdst>1 );
134109
+ sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
134088134110
/* The LIMIT clause will jump out of the loop for us */
134089134111
break;
134090134112
}
134091134113
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
134092134114
@@ -134374,11 +134396,11 @@
134374134396
regOutA = ++pParse->nMem;
134375134397
regOutB = ++pParse->nMem;
134376134398
sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
134377134399
sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
134378134400
134379
- ExplainQueryPlan((pParse, 1, "MERGE (%s)", selectOpName(p->op)));
134401
+ ExplainQueryPlan((pParse, 1, "MERGE (%s)", sqlite3SelectOpName(p->op)));
134380134402
134381134403
/* Generate a coroutine to evaluate the SELECT statement to the
134382134404
** left of the compound operator - the "A" select.
134383134405
*/
134384134406
addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
@@ -136299,11 +136321,14 @@
136299136321
if( IsVirtual(pTab) || pTab->pSelect ){
136300136322
i16 nCol;
136301136323
u8 eCodeOrig = pWalker->eCode;
136302136324
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
136303136325
assert( pFrom->pSelect==0 );
136304
- if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
136326
+ if( pTab->pSelect
136327
+ && (db->flags & SQLITE_EnableView)==0
136328
+ && pTab->pSchema!=db->aDb[1].pSchema
136329
+ ){
136305136330
sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
136306136331
pTab->zName);
136307136332
}
136308136333
#ifndef SQLITE_OMIT_VIRTUALTABLE
136309136334
if( IsVirtual(pTab)
@@ -137078,12 +137103,23 @@
137078137103
if( IgnorableDistinct(pDest) ){
137079137104
assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union ||
137080137105
pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard ||
137081137106
pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo );
137082137107
/* All of these destinations are also able to ignore the ORDER BY clause */
137083
- sqlite3ExprListDelete(db, p->pOrderBy);
137084
- p->pOrderBy = 0;
137108
+ if( p->pOrderBy ){
137109
+#if SELECTTRACE_ENABLED
137110
+ SELECTTRACE(1,pParse,p, ("dropping superfluous ORDER BY:\n"));
137111
+ if( sqlite3SelectTrace & 0x100 ){
137112
+ sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
137113
+ }
137114
+#endif
137115
+ sqlite3ParserAddCleanup(pParse,
137116
+ (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
137117
+ p->pOrderBy);
137118
+ testcase( pParse->earlyCleanup );
137119
+ p->pOrderBy = 0;
137120
+ }
137085137121
p->selFlags &= ~SF_Distinct;
137086137122
p->selFlags |= SF_NoopOrderBy;
137087137123
}
137088137124
sqlite3SelectPrep(pParse, p, 0);
137089137125
if( pParse->nErr || db->mallocFailed ){
@@ -137698,10 +137734,11 @@
137698137734
*/
137699137735
pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
137700137736
if( pAggInfo ){
137701137737
sqlite3ParserAddCleanup(pParse,
137702137738
(void(*)(sqlite3*,void*))agginfoFree, pAggInfo);
137739
+ testcase( pParse->earlyCleanup );
137703137740
}
137704137741
if( db->mallocFailed ){
137705137742
goto select_end;
137706137743
}
137707137744
pAggInfo->selId = p->selId;
@@ -147454,11 +147491,14 @@
147454147491
sqlite3 *db = pParse->db;
147455147492
147456147493
assert( pExpr->op==TK_EXISTS );
147457147494
assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) );
147458147495
147459
- if( (pSel->selFlags & SF_Aggregate) || pSel->pWin ) return;
147496
+ if( pSel->selFlags & SF_Aggregate ) return;
147497
+#ifndef SQLITE_OMIT_WINDOWFUNC
147498
+ if( pSel->pWin ) return;
147499
+#endif
147460147500
if( pSel->pPrior ) return;
147461147501
if( pSel->pWhere==0 ) return;
147462147502
if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return;
147463147503
147464147504
pDup = sqlite3ExprDup(db, pExpr, 0);
@@ -155837,10 +155877,11 @@
155837155877
int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
155838155878
int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
155839155879
int regString = ++pParse->nMem; /* Reg. for constant value '' */
155840155880
int arith = OP_Add; /* OP_Add or OP_Subtract */
155841155881
int addrGe; /* Jump destination */
155882
+ CollSeq *pColl;
155842155883
155843155884
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
155844155885
assert( pOrderBy && pOrderBy->nExpr==1 );
155845155886
if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
155846155887
switch( op ){
@@ -155927,10 +155968,12 @@
155927155968
155928155969
/* Compare registers reg2 and reg1, taking the jump if required. Note that
155929155970
** control skips over this test if the BIGNULL flag is set and either
155930155971
** reg1 or reg2 contain a NULL value. */
155931155972
sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
155973
+ pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
155974
+ sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ);
155932155975
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
155933155976
155934155977
assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
155935155978
testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
155936155979
testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
@@ -156933,15 +156976,25 @@
156933156976
** SQLITE_LIMIT_COMPOUND_SELECT.
156934156977
*/
156935156978
static void parserDoubleLinkSelect(Parse *pParse, Select *p){
156936156979
assert( p!=0 );
156937156980
if( p->pPrior ){
156938
- Select *pNext = 0, *pLoop;
156939
- int mxSelect, cnt = 0;
156940
- for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
156981
+ Select *pNext = 0, *pLoop = p;
156982
+ int mxSelect, cnt = 1;
156983
+ while(1){
156941156984
pLoop->pNext = pNext;
156942156985
pLoop->selFlags |= SF_Compound;
156986
+ pNext = pLoop;
156987
+ pLoop = pLoop->pPrior;
156988
+ if( pLoop==0 ) break;
156989
+ cnt++;
156990
+ if( pLoop->pOrderBy || pLoop->pLimit ){
156991
+ sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
156992
+ pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
156993
+ sqlite3SelectOpName(pNext->op));
156994
+ break;
156995
+ }
156943156996
}
156944156997
if( (p->selFlags & SF_MultiValue)==0 &&
156945156998
(mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
156946156999
cnt>mxSelect
156947157000
){
@@ -175033,13 +175086,13 @@
175033175086
res = fts3PoslistNearMerge(
175034175087
&pOut, aTmp, nParam1, nParam2, paPoslist, &p2
175035175088
);
175036175089
if( res ){
175037175090
nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
175038
- if( nNew>=0 ){
175091
+ assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
175092
+ if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
175039175093
assert( pPhrase->doclist.pList[nNew]=='\0' );
175040
- assert( nNew<=pPhrase->doclist.nList && nNew>0 );
175041175094
memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
175042175095
pPhrase->doclist.nList = nNew;
175043175096
}
175044175097
*paPoslist = pPhrase->doclist.pList;
175045175098
*pnToken = pPhrase->nToken;
@@ -176969,10 +177022,15 @@
176969177022
176970177023
if( sqlite3_fts3_enable_parentheses ){
176971177024
if( *zInput=='(' ){
176972177025
int nConsumed = 0;
176973177026
pParse->nNest++;
177027
+#if !defined(SQLITE_MAX_EXPR_DEPTH)
177028
+ if( pParse->nNest>1000 ) return SQLITE_ERROR;
177029
+#elif SQLITE_MAX_EXPR_DEPTH>0
177030
+ if( pParse->nNest>SQLITE_MAX_EXPR_DEPTH ) return SQLITE_ERROR;
177031
+#endif
176974177032
rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
176975177033
*pnConsumed = (int)(zInput - z) + 1 + nConsumed;
176976177034
return rc;
176977177035
}else if( *zInput==')' ){
176978177036
pParse->nNest--;
@@ -184372,31 +184430,30 @@
184372184430
if( pNode->block.a){
184373184431
rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
184374184432
while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
184375184433
blobGrowBuffer(&pNode->key, reader.term.n, &rc);
184376184434
if( rc==SQLITE_OK ){
184377
- if( reader.term.n<=0 ){
184378
- rc = FTS_CORRUPT_VTAB;
184379
- }else{
184435
+ assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
184436
+ if( reader.term.n>0 ){
184380184437
memcpy(pNode->key.a, reader.term.a, reader.term.n);
184381
- pNode->key.n = reader.term.n;
184382
- if( i>0 ){
184383
- char *aBlock = 0;
184384
- int nBlock = 0;
184385
- pNode = &pWriter->aNodeWriter[i-1];
184386
- pNode->iBlock = reader.iChild;
184387
- rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
184388
- blobGrowBuffer(&pNode->block,
184389
- MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc
184390
- );
184391
- if( rc==SQLITE_OK ){
184392
- memcpy(pNode->block.a, aBlock, nBlock);
184393
- pNode->block.n = nBlock;
184394
- memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
184395
- }
184396
- sqlite3_free(aBlock);
184397
- }
184438
+ }
184439
+ pNode->key.n = reader.term.n;
184440
+ if( i>0 ){
184441
+ char *aBlock = 0;
184442
+ int nBlock = 0;
184443
+ pNode = &pWriter->aNodeWriter[i-1];
184444
+ pNode->iBlock = reader.iChild;
184445
+ rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
184446
+ blobGrowBuffer(&pNode->block,
184447
+ MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc
184448
+ );
184449
+ if( rc==SQLITE_OK ){
184450
+ memcpy(pNode->block.a, aBlock, nBlock);
184451
+ pNode->block.n = nBlock;
184452
+ memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
184453
+ }
184454
+ sqlite3_free(aBlock);
184398184455
}
184399184456
}
184400184457
}
184401184458
nodeReaderRelease(&reader);
184402184459
}
@@ -224442,10 +224499,13 @@
224442224499
pIter->nPoslist = ((int)(p[0])) >> 1;
224443224500
pIter->nSize = 1;
224444224501
}
224445224502
224446224503
pIter->aPoslist = p;
224504
+ if( &pIter->aPoslist[pIter->nPoslist]>pIter->aEof ){
224505
+ pIter->aPoslist = 0;
224506
+ }
224447224507
}
224448224508
}
224449224509
224450224510
static void fts5DoclistIterInit(
224451224511
Fts5Buffer *pBuf,
@@ -229109,11 +229169,11 @@
229109229169
int nArg, /* Number of args */
229110229170
sqlite3_value **apUnused /* Function arguments */
229111229171
){
229112229172
assert( nArg==0 );
229113229173
UNUSED_PARAM2(nArg, apUnused);
229114
- sqlite3_result_text(pCtx, "fts5: 2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092", -1, SQLITE_TRANSIENT);
229174
+ sqlite3_result_text(pCtx, "fts5: 2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b", -1, SQLITE_TRANSIENT);
229115229175
}
229116229176
229117229177
/*
229118229178
** Return true if zName is the extension on one of the shadow tables used
229119229179
** by this module.
@@ -234035,12 +234095,12 @@
234035234095
}
234036234096
#endif /* SQLITE_CORE */
234037234097
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234038234098
234039234099
/************** End of stmt.c ************************************************/
234040
-#if __LINE__!=234040
234100
+#if __LINE__!=234100
234041234101
#undef SQLITE_SOURCE_ID
234042
-#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9alt2"
234102
+#define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303alt2"
234043234103
#endif
234044234104
/* Return the source-id for this library */
234045234105
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234046234106
/************************** End of sqlite3.c ******************************/
234047234107
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.35.0"
1190 #define SQLITE_VERSION_NUMBER 3035000
1191 #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -3193,11 +3193,17 @@
3193 ** The first argument is an integer which is 0 to disable views,
3194 ** positive to enable views or negative to leave the setting unchanged.
3195 ** The second parameter is a pointer to an integer into which
3196 ** is written 0 or 1 to indicate whether views are disabled or enabled
3197 ** following this call. The second parameter may be a NULL pointer, in
3198 ** which case the view setting is not reported back. </dd>
 
 
 
 
 
 
3199 **
3200 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3201 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3202 ** <dd> ^This option is used to enable or disable the
3203 ** [fts3_tokenizer()] function which is part of the
@@ -15368,11 +15374,11 @@
15368
15369 /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
15370 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
15371 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
15372 #define BTREE_APPEND 0x08 /* Insert is likely an append */
15373 #define BTREE_PREFORMAT 0x80 /* Insert is likely an append */
15374
15375 /* An instance of the BtreePayload object describes the content of a single
15376 ** entry in either an index or table btree.
15377 **
15378 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -20256,10 +20262,11 @@
20256 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
20257 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
20258 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
20259 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
20260 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
 
20261 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse*, ExprList*);
20262
20263 #ifdef SQLITE_DEBUG
20264 SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
20265 #endif
@@ -29330,11 +29337,11 @@
29330 setStrAccumError(p, SQLITE_TOOBIG);
29331 return p->nAlloc - p->nChar - 1;
29332 }else{
29333 char *zOld = isMalloced(p) ? p->zText : 0;
29334 i64 szNew = p->nChar;
29335 szNew += N + 1;
29336 if( szNew+p->nChar<=p->mxAlloc ){
29337 /* Force exponential buffer size growth as long as it does not overflow,
29338 ** to avoid having to call this routine too often */
29339 szNew += p->nChar;
29340 }
@@ -87395,11 +87402,11 @@
87395 case OP_ChngCntRow: {
87396 assert( pOp->p2==1 );
87397 if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
87398 goto abort_due_to_error;
87399 }
87400 /* Fall through to the next case, OP_String */
87401 /* no break */ deliberate_fall_through
87402 }
87403
87404 /* Opcode: ResultRow P1 P2 * * *
87405 ** Synopsis: output=r[P1@P2]
@@ -98169,11 +98176,11 @@
98169 }else{
98170 i64 iOff = p->nChunkSize;
98171 for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
98172 iOff += p->nChunkSize;
98173 }
98174 if( pIter ){
98175 memjrnlFreeChunks(pIter->pNext);
98176 pIter->pNext = 0;
98177 }
98178 }
98179
@@ -99006,10 +99013,11 @@
99006 /* IMP: R-51414-32910 */
99007 iCol = -1;
99008 }
99009 if( iCol<pTab->nCol ){
99010 cnt++;
 
99011 #ifndef SQLITE_OMIT_UPSERT
99012 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
99013 testcase( iCol==(-1) );
99014 if( IN_RENAME_OBJECT ){
99015 pExpr->iColumn = iCol;
@@ -99024,12 +99032,12 @@
99024 #endif /* SQLITE_OMIT_UPSERT */
99025 {
99026 pExpr->y.pTab = pTab;
99027 if( pParse->bReturning ){
99028 eNewExprOp = TK_REGISTER;
99029 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable
99030 + iCol + 1;
99031 }else{
99032 pExpr->iColumn = (i16)iCol;
99033 eNewExprOp = TK_TRIGGER;
99034 #ifndef SQLITE_OMIT_TRIGGER
99035 if( iCol<0 ){
@@ -99225,15 +99233,17 @@
99225 pExpr->op = eNewExprOp;
99226 ExprSetProperty(pExpr, EP_Leaf);
99227 lookupname_end:
99228 if( cnt==1 ){
99229 assert( pNC!=0 );
 
99230 if( pParse->db->xAuth
99231 && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER)
99232 ){
99233 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
99234 }
 
99235 /* Increment the nRef value on all name contexts from TopNC up to
99236 ** the point where the name matched. */
99237 for(;;){
99238 assert( pTopNC!=0 );
99239 pTopNC->nRef++;
@@ -99374,20 +99384,23 @@
99374 pExpr->iColumn--;
99375 pExpr->affExpr = SQLITE_AFF_INTEGER;
99376 break;
99377 }
99378
99379 /* An "<expr> IS NOT NULL" or "<expr> IS NULL". After resolving the
99380 ** LHS, check if there is a NOT NULL constraint in the schema that
99381 ** means the value of the expression can be determined immediately.
99382 ** If that is the case, replace the current expression node with
99383 ** a TK_TRUEFALSE node.
99384 **
99385 ** If the node is replaced with a TK_TRUEFALSE node, then also restore
99386 ** the NameContext ref-counts to the state they where in before the
99387 ** LHS expression was resolved. This prevents the current select
99388 ** from being erroneously marked as correlated in some cases.
 
 
 
 
 
 
 
99389 */
99390 case TK_NOTNULL:
99391 case TK_ISNULL: {
99392 int anRef[8];
99393 NameContext *p;
@@ -99394,11 +99407,11 @@
99394 int i;
99395 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
99396 anRef[i] = p->nRef;
99397 }
99398 sqlite3WalkExpr(pWalker, pExpr->pLeft);
99399 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){
99400 if( pExpr->op==TK_NOTNULL ){
99401 pExpr->u.zToken = "true";
99402 ExprSetProperty(pExpr, EP_IsTrue);
99403 }else{
99404 pExpr->u.zToken = "false";
@@ -99639,10 +99652,11 @@
99639 if( pWin ){
99640 Select *pSel = pNC->pWinSelect;
99641 assert( pWin==pExpr->y.pWin );
99642 if( IN_RENAME_OBJECT==0 ){
99643 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
 
99644 }
99645 sqlite3WalkExprList(pWalker, pWin->pPartition);
99646 sqlite3WalkExprList(pWalker, pWin->pOrderBy);
99647 sqlite3WalkExpr(pWalker, pWin->pFilter);
99648 sqlite3WindowLink(pSel, pWin);
@@ -99713,11 +99727,11 @@
99713 case TK_ISNOT: {
99714 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
99715 assert( !ExprHasProperty(pExpr, EP_Reduced) );
99716 /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
99717 ** and "x IS NOT FALSE". */
99718 if( pRight && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
99719 int rc = resolveExprStep(pWalker, pRight);
99720 if( rc==WRC_Abort ) return WRC_Abort;
99721 if( pRight->op==TK_TRUEFALSE ){
99722 pExpr->op2 = pExpr->op;
99723 pExpr->op = TK_TRUTH;
@@ -107942,13 +107956,12 @@
107942 }
107943 if( rc==SQLITE_OK ){
107944 rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList);
107945 }
107946 assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) );
107947 if( pStep->pUpsert ){
107948 Upsert *pUpsert = pStep->pUpsert;
107949 assert( rc==SQLITE_OK );
107950 pUpsert->pUpsertSrc = pSrc;
107951 sNC.uNC.pUpsert = pUpsert;
107952 sNC.ncFlags = NC_UUpsert;
107953 rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
107954 if( rc==SQLITE_OK ){
@@ -108504,14 +108517,15 @@
108504 #ifndef SQLITE_OMIT_AUTHORIZATION
108505 sqlite3_xauth xAuth = db->xAuth;
108506 db->xAuth = 0;
108507 #endif
108508
 
108509 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108510 if( rc!=SQLITE_OK ) goto drop_column_done;
108511 pTab = sParse.pNewTable;
108512 if( pTab->nCol==1 || iCol>=pTab->nCol ){
108513 /* This can happen if the sqlite_schema table is corrupt */
108514 rc = SQLITE_CORRUPT_BKPT;
108515 goto drop_column_done;
108516 }
108517
@@ -112815,10 +112829,11 @@
112815 pParse->u1.pReturning = pRet;
112816 pRet->pParse = pParse;
112817 pRet->pReturnEL = pList;
112818 sqlite3ParserAddCleanup(pParse,
112819 (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
 
112820 if( db->mallocFailed ) return;
112821 pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
112822 pRet->retTrig.op = TK_RETURNING;
112823 pRet->retTrig.tr_tm = TRIGGER_AFTER;
112824 pRet->retTrig.bReturning = 1;
@@ -130625,17 +130640,25 @@
130625 ** for common cleanups that happen on most calls. But for less
130626 ** common cleanups, we save a single NULL-pointer comparison in
130627 ** sqlite3ParserReset(), which reduces the total CPU cycle count.
130628 **
130629 ** If a memory allocation error occurs, then the cleanup happens immediately.
130630 ** When eithr SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
130631 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
130632 ** that test cases exist for which this happens, to guard against possible
130633 ** use-after-free errors following an OOM. The preferred way to do this is
130634 ** to immediately follow the call to this routine with:
130635 **
130636 ** testcase( pParse->earlyCleanup );
 
 
 
 
 
 
 
 
130637 */
130638 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(
130639 Parse *pParse, /* Destroy when this Parser finishes */
130640 void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */
130641 void *pPtr /* Pointer to object to be cleaned up */
@@ -131129,16 +131152,20 @@
131129 sqlite3ExprDelete(db, p->pWhere);
131130 sqlite3ExprListDelete(db, p->pGroupBy);
131131 sqlite3ExprDelete(db, p->pHaving);
131132 sqlite3ExprListDelete(db, p->pOrderBy);
131133 sqlite3ExprDelete(db, p->pLimit);
 
131134 #ifndef SQLITE_OMIT_WINDOWFUNC
131135 if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
131136 sqlite3WindowListDelete(db, p->pWinDefn);
131137 }
 
 
 
 
131138 #endif
131139 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
131140 if( bFree ) sqlite3DbFreeNN(db, p);
131141 p = pPrior;
131142 bFree = 1;
131143 }
131144 }
@@ -132430,11 +132457,11 @@
132430 }
132431
132432 /*
132433 ** Name of the connection operator, used for error messages.
132434 */
132435 static const char *selectOpName(int id){
132436 char *z;
132437 switch( id ){
132438 case TK_ALL: z = "UNION ALL"; break;
132439 case TK_INTERSECT: z = "INTERSECT"; break;
132440 case TK_EXCEPT: z = "EXCEPT"; break;
@@ -133649,16 +133676,12 @@
133649 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
133650 assert( p->selFlags & SF_Compound );
133651 db = pParse->db;
133652 pPrior = p->pPrior;
133653 dest = *pDest;
133654 if( pPrior->pOrderBy || pPrior->pLimit ){
133655 sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
133656 pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op));
133657 rc = 1;
133658 goto multi_select_end;
133659 }
133660
133661 v = sqlite3GetVdbe(pParse);
133662 assert( v!=0 ); /* The VDBE already created by calling function */
133663
133664 /* Create the destination temporary table if necessary
@@ -133711,11 +133734,11 @@
133711 assert( !pPrior->pLimit );
133712 pPrior->iLimit = p->iLimit;
133713 pPrior->iOffset = p->iOffset;
133714 pPrior->pLimit = p->pLimit;
133715 rc = sqlite3Select(pParse, pPrior, &dest);
133716 p->pLimit = 0;
133717 if( rc ){
133718 goto multi_select_end;
133719 }
133720 p->pPrior = 0;
133721 p->iLimit = pPrior->iLimit;
@@ -133732,12 +133755,12 @@
133732 rc = sqlite3Select(pParse, p, &dest);
133733 testcase( rc!=SQLITE_OK );
133734 pDelete = p->pPrior;
133735 p->pPrior = pPrior;
133736 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
133737 if( pPrior->pLimit
133738 && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit)
133739 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
133740 ){
133741 p->nSelectRow = sqlite3LogEst((u64)nLimit);
133742 }
133743 if( addr ){
@@ -133797,11 +133820,11 @@
133797 p->pPrior = 0;
133798 pLimit = p->pLimit;
133799 p->pLimit = 0;
133800 uniondest.eDest = op;
133801 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133802 selectOpName(p->op)));
133803 rc = sqlite3Select(pParse, p, &uniondest);
133804 testcase( rc!=SQLITE_OK );
133805 assert( p->pOrderBy==0 );
133806 pDelete = p->pPrior;
133807 p->pPrior = pPrior;
@@ -133873,11 +133896,11 @@
133873 p->pPrior = 0;
133874 pLimit = p->pLimit;
133875 p->pLimit = 0;
133876 intersectdest.iSDParm = tab2;
133877 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133878 selectOpName(p->op)));
133879 rc = sqlite3Select(pParse, p, &intersectdest);
133880 testcase( rc!=SQLITE_OK );
133881 pDelete = p->pPrior;
133882 p->pPrior = pPrior;
133883 if( p->nSelectRow>pPrior->nSelectRow ){
@@ -133982,11 +134005,12 @@
133982 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
133983 if( p->selFlags & SF_Values ){
133984 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
133985 }else{
133986 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
133987 " do not have the same number of result columns", selectOpName(p->op));
 
133988 }
133989 }
133990
133991 /*
133992 ** Code an output subroutine for a coroutine implementation of a
@@ -134079,14 +134103,12 @@
134079 ** store the results in the appropriate memory cell and break out
134080 ** of the scan loop. Note that the select might return multiple columns
134081 ** if it is the RHS of a row-value IN operator.
134082 */
134083 case SRT_Mem: {
134084 if( pParse->nErr==0 ){
134085 testcase( pIn->nSdst>1 );
134086 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
134087 }
134088 /* The LIMIT clause will jump out of the loop for us */
134089 break;
134090 }
134091 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
134092
@@ -134374,11 +134396,11 @@
134374 regOutA = ++pParse->nMem;
134375 regOutB = ++pParse->nMem;
134376 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
134377 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
134378
134379 ExplainQueryPlan((pParse, 1, "MERGE (%s)", selectOpName(p->op)));
134380
134381 /* Generate a coroutine to evaluate the SELECT statement to the
134382 ** left of the compound operator - the "A" select.
134383 */
134384 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
@@ -136299,11 +136321,14 @@
136299 if( IsVirtual(pTab) || pTab->pSelect ){
136300 i16 nCol;
136301 u8 eCodeOrig = pWalker->eCode;
136302 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
136303 assert( pFrom->pSelect==0 );
136304 if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){
 
 
 
136305 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
136306 pTab->zName);
136307 }
136308 #ifndef SQLITE_OMIT_VIRTUALTABLE
136309 if( IsVirtual(pTab)
@@ -137078,12 +137103,23 @@
137078 if( IgnorableDistinct(pDest) ){
137079 assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union ||
137080 pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard ||
137081 pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo );
137082 /* All of these destinations are also able to ignore the ORDER BY clause */
137083 sqlite3ExprListDelete(db, p->pOrderBy);
137084 p->pOrderBy = 0;
 
 
 
 
 
 
 
 
 
 
 
137085 p->selFlags &= ~SF_Distinct;
137086 p->selFlags |= SF_NoopOrderBy;
137087 }
137088 sqlite3SelectPrep(pParse, p, 0);
137089 if( pParse->nErr || db->mallocFailed ){
@@ -137698,10 +137734,11 @@
137698 */
137699 pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
137700 if( pAggInfo ){
137701 sqlite3ParserAddCleanup(pParse,
137702 (void(*)(sqlite3*,void*))agginfoFree, pAggInfo);
 
137703 }
137704 if( db->mallocFailed ){
137705 goto select_end;
137706 }
137707 pAggInfo->selId = p->selId;
@@ -147454,11 +147491,14 @@
147454 sqlite3 *db = pParse->db;
147455
147456 assert( pExpr->op==TK_EXISTS );
147457 assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) );
147458
147459 if( (pSel->selFlags & SF_Aggregate) || pSel->pWin ) return;
 
 
 
147460 if( pSel->pPrior ) return;
147461 if( pSel->pWhere==0 ) return;
147462 if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return;
147463
147464 pDup = sqlite3ExprDup(db, pExpr, 0);
@@ -155837,10 +155877,11 @@
155837 int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
155838 int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
155839 int regString = ++pParse->nMem; /* Reg. for constant value '' */
155840 int arith = OP_Add; /* OP_Add or OP_Subtract */
155841 int addrGe; /* Jump destination */
 
155842
155843 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
155844 assert( pOrderBy && pOrderBy->nExpr==1 );
155845 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
155846 switch( op ){
@@ -155927,10 +155968,12 @@
155927
155928 /* Compare registers reg2 and reg1, taking the jump if required. Note that
155929 ** control skips over this test if the BIGNULL flag is set and either
155930 ** reg1 or reg2 contain a NULL value. */
155931 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
 
 
155932 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
155933
155934 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
155935 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
155936 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
@@ -156933,15 +156976,25 @@
156933 ** SQLITE_LIMIT_COMPOUND_SELECT.
156934 */
156935 static void parserDoubleLinkSelect(Parse *pParse, Select *p){
156936 assert( p!=0 );
156937 if( p->pPrior ){
156938 Select *pNext = 0, *pLoop;
156939 int mxSelect, cnt = 0;
156940 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
156941 pLoop->pNext = pNext;
156942 pLoop->selFlags |= SF_Compound;
 
 
 
 
 
 
 
 
 
 
156943 }
156944 if( (p->selFlags & SF_MultiValue)==0 &&
156945 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
156946 cnt>mxSelect
156947 ){
@@ -175033,13 +175086,13 @@
175033 res = fts3PoslistNearMerge(
175034 &pOut, aTmp, nParam1, nParam2, paPoslist, &p2
175035 );
175036 if( res ){
175037 nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
175038 if( nNew>=0 ){
 
175039 assert( pPhrase->doclist.pList[nNew]=='\0' );
175040 assert( nNew<=pPhrase->doclist.nList && nNew>0 );
175041 memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
175042 pPhrase->doclist.nList = nNew;
175043 }
175044 *paPoslist = pPhrase->doclist.pList;
175045 *pnToken = pPhrase->nToken;
@@ -176969,10 +177022,15 @@
176969
176970 if( sqlite3_fts3_enable_parentheses ){
176971 if( *zInput=='(' ){
176972 int nConsumed = 0;
176973 pParse->nNest++;
 
 
 
 
 
176974 rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
176975 *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
176976 return rc;
176977 }else if( *zInput==')' ){
176978 pParse->nNest--;
@@ -184372,31 +184430,30 @@
184372 if( pNode->block.a){
184373 rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
184374 while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
184375 blobGrowBuffer(&pNode->key, reader.term.n, &rc);
184376 if( rc==SQLITE_OK ){
184377 if( reader.term.n<=0 ){
184378 rc = FTS_CORRUPT_VTAB;
184379 }else{
184380 memcpy(pNode->key.a, reader.term.a, reader.term.n);
184381 pNode->key.n = reader.term.n;
184382 if( i>0 ){
184383 char *aBlock = 0;
184384 int nBlock = 0;
184385 pNode = &pWriter->aNodeWriter[i-1];
184386 pNode->iBlock = reader.iChild;
184387 rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
184388 blobGrowBuffer(&pNode->block,
184389 MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc
184390 );
184391 if( rc==SQLITE_OK ){
184392 memcpy(pNode->block.a, aBlock, nBlock);
184393 pNode->block.n = nBlock;
184394 memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
184395 }
184396 sqlite3_free(aBlock);
184397 }
184398 }
184399 }
184400 }
184401 nodeReaderRelease(&reader);
184402 }
@@ -224442,10 +224499,13 @@
224442 pIter->nPoslist = ((int)(p[0])) >> 1;
224443 pIter->nSize = 1;
224444 }
224445
224446 pIter->aPoslist = p;
 
 
 
224447 }
224448 }
224449
224450 static void fts5DoclistIterInit(
224451 Fts5Buffer *pBuf,
@@ -229109,11 +229169,11 @@
229109 int nArg, /* Number of args */
229110 sqlite3_value **apUnused /* Function arguments */
229111 ){
229112 assert( nArg==0 );
229113 UNUSED_PARAM2(nArg, apUnused);
229114 sqlite3_result_text(pCtx, "fts5: 2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092", -1, SQLITE_TRANSIENT);
229115 }
229116
229117 /*
229118 ** Return true if zName is the extension on one of the shadow tables used
229119 ** by this module.
@@ -234035,12 +234095,12 @@
234035 }
234036 #endif /* SQLITE_CORE */
234037 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234038
234039 /************** End of stmt.c ************************************************/
234040 #if __LINE__!=234040
234041 #undef SQLITE_SOURCE_ID
234042 #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9alt2"
234043 #endif
234044 /* Return the source-id for this library */
234045 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234046 /************************** End of sqlite3.c ******************************/
234047
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.35.0"
1190 #define SQLITE_VERSION_NUMBER 3035000
1191 #define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -3193,11 +3193,17 @@
3193 ** The first argument is an integer which is 0 to disable views,
3194 ** positive to enable views or negative to leave the setting unchanged.
3195 ** The second parameter is a pointer to an integer into which
3196 ** is written 0 or 1 to indicate whether views are disabled or enabled
3197 ** following this call. The second parameter may be a NULL pointer, in
3198 ** which case the view setting is not reported back.
3199 **
3200 ** <p>Originally this option disabled all views. ^(However, since
3201 ** SQLite version 3.35.0, TEMP views are still allowed even if
3202 ** this option is off. So, in other words, this option now only disables
3203 ** views in the main database schema or in the schemas of ATTACH-ed
3204 ** databases.)^ </dd>
3205 **
3206 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3207 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3208 ** <dd> ^This option is used to enable or disable the
3209 ** [fts3_tokenizer()] function which is part of the
@@ -15368,11 +15374,11 @@
15374
15375 /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
15376 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
15377 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
15378 #define BTREE_APPEND 0x08 /* Insert is likely an append */
15379 #define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
15380
15381 /* An instance of the BtreePayload object describes the content of a single
15382 ** entry in either an index or table btree.
15383 **
15384 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -20256,10 +20262,11 @@
20262 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
20263 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
20264 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
20265 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
20266 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
20267 SQLITE_PRIVATE const char *sqlite3SelectOpName(int);
20268 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse*, ExprList*);
20269
20270 #ifdef SQLITE_DEBUG
20271 SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
20272 #endif
@@ -29330,11 +29337,11 @@
29337 setStrAccumError(p, SQLITE_TOOBIG);
29338 return p->nAlloc - p->nChar - 1;
29339 }else{
29340 char *zOld = isMalloced(p) ? p->zText : 0;
29341 i64 szNew = p->nChar;
29342 szNew += (sqlite3_int64)N + 1;
29343 if( szNew+p->nChar<=p->mxAlloc ){
29344 /* Force exponential buffer size growth as long as it does not overflow,
29345 ** to avoid having to call this routine too often */
29346 szNew += p->nChar;
29347 }
@@ -87395,11 +87402,11 @@
87402 case OP_ChngCntRow: {
87403 assert( pOp->p2==1 );
87404 if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
87405 goto abort_due_to_error;
87406 }
87407 /* Fall through to the next case, OP_ResultRow */
87408 /* no break */ deliberate_fall_through
87409 }
87410
87411 /* Opcode: ResultRow P1 P2 * * *
87412 ** Synopsis: output=r[P1@P2]
@@ -98169,11 +98176,11 @@
98176 }else{
98177 i64 iOff = p->nChunkSize;
98178 for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
98179 iOff += p->nChunkSize;
98180 }
98181 if( ALWAYS(pIter) ){
98182 memjrnlFreeChunks(pIter->pNext);
98183 pIter->pNext = 0;
98184 }
98185 }
98186
@@ -99006,10 +99013,11 @@
99013 /* IMP: R-51414-32910 */
99014 iCol = -1;
99015 }
99016 if( iCol<pTab->nCol ){
99017 cnt++;
99018 pMatch = 0;
99019 #ifndef SQLITE_OMIT_UPSERT
99020 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
99021 testcase( iCol==(-1) );
99022 if( IN_RENAME_OBJECT ){
99023 pExpr->iColumn = iCol;
@@ -99024,12 +99032,12 @@
99032 #endif /* SQLITE_OMIT_UPSERT */
99033 {
99034 pExpr->y.pTab = pTab;
99035 if( pParse->bReturning ){
99036 eNewExprOp = TK_REGISTER;
99037 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
99038 sqlite3TableColumnToStorage(pTab, iCol) + 1;
99039 }else{
99040 pExpr->iColumn = (i16)iCol;
99041 eNewExprOp = TK_TRIGGER;
99042 #ifndef SQLITE_OMIT_TRIGGER
99043 if( iCol<0 ){
@@ -99225,15 +99233,17 @@
99233 pExpr->op = eNewExprOp;
99234 ExprSetProperty(pExpr, EP_Leaf);
99235 lookupname_end:
99236 if( cnt==1 ){
99237 assert( pNC!=0 );
99238 #ifndef SQLITE_OMIT_AUTHORIZATION
99239 if( pParse->db->xAuth
99240 && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER)
99241 ){
99242 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
99243 }
99244 #endif
99245 /* Increment the nRef value on all name contexts from TopNC up to
99246 ** the point where the name matched. */
99247 for(;;){
99248 assert( pTopNC!=0 );
99249 pTopNC->nRef++;
@@ -99374,20 +99384,23 @@
99384 pExpr->iColumn--;
99385 pExpr->affExpr = SQLITE_AFF_INTEGER;
99386 break;
99387 }
99388
99389 /* An optimization: Attempt to convert
 
 
 
 
99390 **
99391 ** "expr IS NOT NULL" --> "TRUE"
99392 ** "expr IS NULL" --> "FALSE"
99393 **
99394 ** if we can prove that "expr" is never NULL. Call this the
99395 ** "NOT NULL strength reduction optimization".
99396 **
99397 ** If this optimization occurs, also restore the NameContext ref-counts
99398 ** to the state they where in before the "column" LHS expression was
99399 ** resolved. This prevents "column" from being counted as having been
99400 ** referenced, which might prevent a SELECT from being erroneously
99401 ** marked as correlated.
99402 */
99403 case TK_NOTNULL:
99404 case TK_ISNULL: {
99405 int anRef[8];
99406 NameContext *p;
@@ -99394,11 +99407,11 @@
99407 int i;
99408 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
99409 anRef[i] = p->nRef;
99410 }
99411 sqlite3WalkExpr(pWalker, pExpr->pLeft);
99412 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
99413 if( pExpr->op==TK_NOTNULL ){
99414 pExpr->u.zToken = "true";
99415 ExprSetProperty(pExpr, EP_IsTrue);
99416 }else{
99417 pExpr->u.zToken = "false";
@@ -99639,10 +99652,11 @@
99652 if( pWin ){
99653 Select *pSel = pNC->pWinSelect;
99654 assert( pWin==pExpr->y.pWin );
99655 if( IN_RENAME_OBJECT==0 ){
99656 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
99657 if( pParse->db->mallocFailed ) break;
99658 }
99659 sqlite3WalkExprList(pWalker, pWin->pPartition);
99660 sqlite3WalkExprList(pWalker, pWin->pOrderBy);
99661 sqlite3WalkExpr(pWalker, pWin->pFilter);
99662 sqlite3WindowLink(pSel, pWin);
@@ -99713,11 +99727,11 @@
99727 case TK_ISNOT: {
99728 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
99729 assert( !ExprHasProperty(pExpr, EP_Reduced) );
99730 /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
99731 ** and "x IS NOT FALSE". */
99732 if( ALWAYS(pRight) && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
99733 int rc = resolveExprStep(pWalker, pRight);
99734 if( rc==WRC_Abort ) return WRC_Abort;
99735 if( pRight->op==TK_TRUEFALSE ){
99736 pExpr->op2 = pExpr->op;
99737 pExpr->op = TK_TRUTH;
@@ -107942,13 +107956,12 @@
107956 }
107957 if( rc==SQLITE_OK ){
107958 rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList);
107959 }
107960 assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) );
107961 if( pStep->pUpsert && rc==SQLITE_OK ){
107962 Upsert *pUpsert = pStep->pUpsert;
 
107963 pUpsert->pUpsertSrc = pSrc;
107964 sNC.uNC.pUpsert = pUpsert;
107965 sNC.ncFlags = NC_UUpsert;
107966 rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
107967 if( rc==SQLITE_OK ){
@@ -108504,14 +108517,15 @@
108517 #ifndef SQLITE_OMIT_AUTHORIZATION
108518 sqlite3_xauth xAuth = db->xAuth;
108519 db->xAuth = 0;
108520 #endif
108521
108522 UNUSED_PARAMETER(NotUsed);
108523 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108524 if( rc!=SQLITE_OK ) goto drop_column_done;
108525 pTab = sParse.pNewTable;
108526 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108527 /* This can happen if the sqlite_schema table is corrupt */
108528 rc = SQLITE_CORRUPT_BKPT;
108529 goto drop_column_done;
108530 }
108531
@@ -112815,10 +112829,11 @@
112829 pParse->u1.pReturning = pRet;
112830 pRet->pParse = pParse;
112831 pRet->pReturnEL = pList;
112832 sqlite3ParserAddCleanup(pParse,
112833 (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
112834 testcase( pParse->earlyCleanup );
112835 if( db->mallocFailed ) return;
112836 pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
112837 pRet->retTrig.op = TK_RETURNING;
112838 pRet->retTrig.tr_tm = TRIGGER_AFTER;
112839 pRet->retTrig.bReturning = 1;
@@ -130625,17 +130640,25 @@
130640 ** for common cleanups that happen on most calls. But for less
130641 ** common cleanups, we save a single NULL-pointer comparison in
130642 ** sqlite3ParserReset(), which reduces the total CPU cycle count.
130643 **
130644 ** If a memory allocation error occurs, then the cleanup happens immediately.
130645 ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
130646 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
130647 ** that test cases exist for which this happens, to guard against possible
130648 ** use-after-free errors following an OOM. The preferred way to do this is
130649 ** to immediately follow the call to this routine with:
130650 **
130651 ** testcase( pParse->earlyCleanup );
130652 **
130653 ** This routine returns a copy of its pPtr input (the third parameter)
130654 ** except if an early cleanup occurs, in which case it returns NULL. So
130655 ** another way to check for early cleanup is to check the return value.
130656 ** Or, stop using the pPtr parameter with this call and use only its
130657 ** return value thereafter. Something like this:
130658 **
130659 ** pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj);
130660 */
130661 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(
130662 Parse *pParse, /* Destroy when this Parser finishes */
130663 void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */
130664 void *pPtr /* Pointer to object to be cleaned up */
@@ -131129,16 +131152,20 @@
131152 sqlite3ExprDelete(db, p->pWhere);
131153 sqlite3ExprListDelete(db, p->pGroupBy);
131154 sqlite3ExprDelete(db, p->pHaving);
131155 sqlite3ExprListDelete(db, p->pOrderBy);
131156 sqlite3ExprDelete(db, p->pLimit);
131157 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
131158 #ifndef SQLITE_OMIT_WINDOWFUNC
131159 if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
131160 sqlite3WindowListDelete(db, p->pWinDefn);
131161 }
131162 while( p->pWin ){
131163 assert( p->pWin->ppThis==&p->pWin );
131164 sqlite3WindowUnlinkFromSelect(p->pWin);
131165 }
131166 #endif
 
131167 if( bFree ) sqlite3DbFreeNN(db, p);
131168 p = pPrior;
131169 bFree = 1;
131170 }
131171 }
@@ -132430,11 +132457,11 @@
132457 }
132458
132459 /*
132460 ** Name of the connection operator, used for error messages.
132461 */
132462 SQLITE_PRIVATE const char *sqlite3SelectOpName(int id){
132463 char *z;
132464 switch( id ){
132465 case TK_ALL: z = "UNION ALL"; break;
132466 case TK_INTERSECT: z = "INTERSECT"; break;
132467 case TK_EXCEPT: z = "EXCEPT"; break;
@@ -133649,16 +133676,12 @@
133676 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
133677 assert( p->selFlags & SF_Compound );
133678 db = pParse->db;
133679 pPrior = p->pPrior;
133680 dest = *pDest;
133681 assert( pPrior->pOrderBy==0 );
133682 assert( pPrior->pLimit==0 );
 
 
 
 
133683
133684 v = sqlite3GetVdbe(pParse);
133685 assert( v!=0 ); /* The VDBE already created by calling function */
133686
133687 /* Create the destination temporary table if necessary
@@ -133711,11 +133734,11 @@
133734 assert( !pPrior->pLimit );
133735 pPrior->iLimit = p->iLimit;
133736 pPrior->iOffset = p->iOffset;
133737 pPrior->pLimit = p->pLimit;
133738 rc = sqlite3Select(pParse, pPrior, &dest);
133739 pPrior->pLimit = 0;
133740 if( rc ){
133741 goto multi_select_end;
133742 }
133743 p->pPrior = 0;
133744 p->iLimit = pPrior->iLimit;
@@ -133732,12 +133755,12 @@
133755 rc = sqlite3Select(pParse, p, &dest);
133756 testcase( rc!=SQLITE_OK );
133757 pDelete = p->pPrior;
133758 p->pPrior = pPrior;
133759 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
133760 if( p->pLimit
133761 && sqlite3ExprIsInteger(p->pLimit->pLeft, &nLimit)
133762 && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit)
133763 ){
133764 p->nSelectRow = sqlite3LogEst((u64)nLimit);
133765 }
133766 if( addr ){
@@ -133797,11 +133820,11 @@
133820 p->pPrior = 0;
133821 pLimit = p->pLimit;
133822 p->pLimit = 0;
133823 uniondest.eDest = op;
133824 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133825 sqlite3SelectOpName(p->op)));
133826 rc = sqlite3Select(pParse, p, &uniondest);
133827 testcase( rc!=SQLITE_OK );
133828 assert( p->pOrderBy==0 );
133829 pDelete = p->pPrior;
133830 p->pPrior = pPrior;
@@ -133873,11 +133896,11 @@
133896 p->pPrior = 0;
133897 pLimit = p->pLimit;
133898 p->pLimit = 0;
133899 intersectdest.iSDParm = tab2;
133900 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
133901 sqlite3SelectOpName(p->op)));
133902 rc = sqlite3Select(pParse, p, &intersectdest);
133903 testcase( rc!=SQLITE_OK );
133904 pDelete = p->pPrior;
133905 p->pPrior = pPrior;
133906 if( p->nSelectRow>pPrior->nSelectRow ){
@@ -133982,11 +134005,12 @@
134005 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){
134006 if( p->selFlags & SF_Values ){
134007 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
134008 }else{
134009 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
134010 " do not have the same number of result columns",
134011 sqlite3SelectOpName(p->op));
134012 }
134013 }
134014
134015 /*
134016 ** Code an output subroutine for a coroutine implementation of a
@@ -134079,14 +134103,12 @@
134103 ** store the results in the appropriate memory cell and break out
134104 ** of the scan loop. Note that the select might return multiple columns
134105 ** if it is the RHS of a row-value IN operator.
134106 */
134107 case SRT_Mem: {
134108 testcase( pIn->nSdst>1 );
134109 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
 
 
134110 /* The LIMIT clause will jump out of the loop for us */
134111 break;
134112 }
134113 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
134114
@@ -134374,11 +134396,11 @@
134396 regOutA = ++pParse->nMem;
134397 regOutB = ++pParse->nMem;
134398 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
134399 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
134400
134401 ExplainQueryPlan((pParse, 1, "MERGE (%s)", sqlite3SelectOpName(p->op)));
134402
134403 /* Generate a coroutine to evaluate the SELECT statement to the
134404 ** left of the compound operator - the "A" select.
134405 */
134406 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
@@ -136299,11 +136321,14 @@
136321 if( IsVirtual(pTab) || pTab->pSelect ){
136322 i16 nCol;
136323 u8 eCodeOrig = pWalker->eCode;
136324 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
136325 assert( pFrom->pSelect==0 );
136326 if( pTab->pSelect
136327 && (db->flags & SQLITE_EnableView)==0
136328 && pTab->pSchema!=db->aDb[1].pSchema
136329 ){
136330 sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited",
136331 pTab->zName);
136332 }
136333 #ifndef SQLITE_OMIT_VIRTUALTABLE
136334 if( IsVirtual(pTab)
@@ -137078,12 +137103,23 @@
137103 if( IgnorableDistinct(pDest) ){
137104 assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union ||
137105 pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard ||
137106 pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo );
137107 /* All of these destinations are also able to ignore the ORDER BY clause */
137108 if( p->pOrderBy ){
137109 #if SELECTTRACE_ENABLED
137110 SELECTTRACE(1,pParse,p, ("dropping superfluous ORDER BY:\n"));
137111 if( sqlite3SelectTrace & 0x100 ){
137112 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
137113 }
137114 #endif
137115 sqlite3ParserAddCleanup(pParse,
137116 (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
137117 p->pOrderBy);
137118 testcase( pParse->earlyCleanup );
137119 p->pOrderBy = 0;
137120 }
137121 p->selFlags &= ~SF_Distinct;
137122 p->selFlags |= SF_NoopOrderBy;
137123 }
137124 sqlite3SelectPrep(pParse, p, 0);
137125 if( pParse->nErr || db->mallocFailed ){
@@ -137698,10 +137734,11 @@
137734 */
137735 pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) );
137736 if( pAggInfo ){
137737 sqlite3ParserAddCleanup(pParse,
137738 (void(*)(sqlite3*,void*))agginfoFree, pAggInfo);
137739 testcase( pParse->earlyCleanup );
137740 }
137741 if( db->mallocFailed ){
137742 goto select_end;
137743 }
137744 pAggInfo->selId = p->selId;
@@ -147454,11 +147491,14 @@
147491 sqlite3 *db = pParse->db;
147492
147493 assert( pExpr->op==TK_EXISTS );
147494 assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) );
147495
147496 if( pSel->selFlags & SF_Aggregate ) return;
147497 #ifndef SQLITE_OMIT_WINDOWFUNC
147498 if( pSel->pWin ) return;
147499 #endif
147500 if( pSel->pPrior ) return;
147501 if( pSel->pWhere==0 ) return;
147502 if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return;
147503
147504 pDup = sqlite3ExprDup(db, pExpr, 0);
@@ -155837,10 +155877,11 @@
155877 int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
155878 int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
155879 int regString = ++pParse->nMem; /* Reg. for constant value '' */
155880 int arith = OP_Add; /* OP_Add or OP_Subtract */
155881 int addrGe; /* Jump destination */
155882 CollSeq *pColl;
155883
155884 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
155885 assert( pOrderBy && pOrderBy->nExpr==1 );
155886 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
155887 switch( op ){
@@ -155927,10 +155968,12 @@
155968
155969 /* Compare registers reg2 and reg1, taking the jump if required. Note that
155970 ** control skips over this test if the BIGNULL flag is set and either
155971 ** reg1 or reg2 contain a NULL value. */
155972 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
155973 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
155974 sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ);
155975 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
155976
155977 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
155978 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
155979 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
@@ -156933,15 +156976,25 @@
156976 ** SQLITE_LIMIT_COMPOUND_SELECT.
156977 */
156978 static void parserDoubleLinkSelect(Parse *pParse, Select *p){
156979 assert( p!=0 );
156980 if( p->pPrior ){
156981 Select *pNext = 0, *pLoop = p;
156982 int mxSelect, cnt = 1;
156983 while(1){
156984 pLoop->pNext = pNext;
156985 pLoop->selFlags |= SF_Compound;
156986 pNext = pLoop;
156987 pLoop = pLoop->pPrior;
156988 if( pLoop==0 ) break;
156989 cnt++;
156990 if( pLoop->pOrderBy || pLoop->pLimit ){
156991 sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
156992 pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
156993 sqlite3SelectOpName(pNext->op));
156994 break;
156995 }
156996 }
156997 if( (p->selFlags & SF_MultiValue)==0 &&
156998 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
156999 cnt>mxSelect
157000 ){
@@ -175033,13 +175086,13 @@
175086 res = fts3PoslistNearMerge(
175087 &pOut, aTmp, nParam1, nParam2, paPoslist, &p2
175088 );
175089 if( res ){
175090 nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
175091 assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
175092 if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
175093 assert( pPhrase->doclist.pList[nNew]=='\0' );
 
175094 memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
175095 pPhrase->doclist.nList = nNew;
175096 }
175097 *paPoslist = pPhrase->doclist.pList;
175098 *pnToken = pPhrase->nToken;
@@ -176969,10 +177022,15 @@
177022
177023 if( sqlite3_fts3_enable_parentheses ){
177024 if( *zInput=='(' ){
177025 int nConsumed = 0;
177026 pParse->nNest++;
177027 #if !defined(SQLITE_MAX_EXPR_DEPTH)
177028 if( pParse->nNest>1000 ) return SQLITE_ERROR;
177029 #elif SQLITE_MAX_EXPR_DEPTH>0
177030 if( pParse->nNest>SQLITE_MAX_EXPR_DEPTH ) return SQLITE_ERROR;
177031 #endif
177032 rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
177033 *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
177034 return rc;
177035 }else if( *zInput==')' ){
177036 pParse->nNest--;
@@ -184372,31 +184430,30 @@
184430 if( pNode->block.a){
184431 rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
184432 while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
184433 blobGrowBuffer(&pNode->key, reader.term.n, &rc);
184434 if( rc==SQLITE_OK ){
184435 assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
184436 if( reader.term.n>0 ){
 
184437 memcpy(pNode->key.a, reader.term.a, reader.term.n);
184438 }
184439 pNode->key.n = reader.term.n;
184440 if( i>0 ){
184441 char *aBlock = 0;
184442 int nBlock = 0;
184443 pNode = &pWriter->aNodeWriter[i-1];
184444 pNode->iBlock = reader.iChild;
184445 rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
184446 blobGrowBuffer(&pNode->block,
184447 MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc
184448 );
184449 if( rc==SQLITE_OK ){
184450 memcpy(pNode->block.a, aBlock, nBlock);
184451 pNode->block.n = nBlock;
184452 memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING);
184453 }
184454 sqlite3_free(aBlock);
184455 }
184456 }
184457 }
184458 nodeReaderRelease(&reader);
184459 }
@@ -224442,10 +224499,13 @@
224499 pIter->nPoslist = ((int)(p[0])) >> 1;
224500 pIter->nSize = 1;
224501 }
224502
224503 pIter->aPoslist = p;
224504 if( &pIter->aPoslist[pIter->nPoslist]>pIter->aEof ){
224505 pIter->aPoslist = 0;
224506 }
224507 }
224508 }
224509
224510 static void fts5DoclistIterInit(
224511 Fts5Buffer *pBuf,
@@ -229109,11 +229169,11 @@
229169 int nArg, /* Number of args */
229170 sqlite3_value **apUnused /* Function arguments */
229171 ){
229172 assert( nArg==0 );
229173 UNUSED_PARAM2(nArg, apUnused);
229174 sqlite3_result_text(pCtx, "fts5: 2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b", -1, SQLITE_TRANSIENT);
229175 }
229176
229177 /*
229178 ** Return true if zName is the extension on one of the shadow tables used
229179 ** by this module.
@@ -234035,12 +234095,12 @@
234095 }
234096 #endif /* SQLITE_CORE */
234097 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234098
234099 /************** End of stmt.c ************************************************/
234100 #if __LINE__!=234100
234101 #undef SQLITE_SOURCE_ID
234102 #define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303alt2"
234103 #endif
234104 /* Return the source-id for this library */
234105 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234106 /************************** End of sqlite3.c ******************************/
234107
+8 -2
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.35.0"
127127
#define SQLITE_VERSION_NUMBER 3035000
128
-#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092"
128
+#define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -2130,11 +2130,17 @@
21302130
** The first argument is an integer which is 0 to disable views,
21312131
** positive to enable views or negative to leave the setting unchanged.
21322132
** The second parameter is a pointer to an integer into which
21332133
** is written 0 or 1 to indicate whether views are disabled or enabled
21342134
** following this call. The second parameter may be a NULL pointer, in
2135
-** which case the view setting is not reported back. </dd>
2135
+** which case the view setting is not reported back.
2136
+**
2137
+** <p>Originally this option disabled all views. ^(However, since
2138
+** SQLite version 3.35.0, TEMP views are still allowed even if
2139
+** this option is off. So, in other words, this option now only disables
2140
+** views in the main database schema or in the schemas of ATTACH-ed
2141
+** databases.)^ </dd>
21362142
**
21372143
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
21382144
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
21392145
** <dd> ^This option is used to enable or disable the
21402146
** [fts3_tokenizer()] function which is part of the
21412147
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.35.0"
127 #define SQLITE_VERSION_NUMBER 3035000
128 #define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2130,11 +2130,17 @@
2130 ** The first argument is an integer which is 0 to disable views,
2131 ** positive to enable views or negative to leave the setting unchanged.
2132 ** The second parameter is a pointer to an integer into which
2133 ** is written 0 or 1 to indicate whether views are disabled or enabled
2134 ** following this call. The second parameter may be a NULL pointer, in
2135 ** which case the view setting is not reported back. </dd>
 
 
 
 
 
 
2136 **
2137 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2138 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2139 ** <dd> ^This option is used to enable or disable the
2140 ** [fts3_tokenizer()] function which is part of the
2141
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.35.0"
127 #define SQLITE_VERSION_NUMBER 3035000
128 #define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2130,11 +2130,17 @@
2130 ** The first argument is an integer which is 0 to disable views,
2131 ** positive to enable views or negative to leave the setting unchanged.
2132 ** The second parameter is a pointer to an integer into which
2133 ** is written 0 or 1 to indicate whether views are disabled or enabled
2134 ** following this call. The second parameter may be a NULL pointer, in
2135 ** which case the view setting is not reported back.
2136 **
2137 ** <p>Originally this option disabled all views. ^(However, since
2138 ** SQLite version 3.35.0, TEMP views are still allowed even if
2139 ** this option is off. So, in other words, this option now only disables
2140 ** views in the main database schema or in the schemas of ATTACH-ed
2141 ** databases.)^ </dd>
2142 **
2143 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2144 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2145 ** <dd> ^This option is used to enable or disable the
2146 ** [fts3_tokenizer()] function which is part of the
2147

Keyboard Shortcuts

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