Fossil SCM

Update the built-in SQLite to version 3.35.2.

drh 2021-03-17 19:34 trunk
Commit 4c561266129d6b0453c05244da22cd9f0ccad5a0a8cf57cc434656e3eb705321
3 files changed +101 -91 +48 -27 +3 -3
+101 -91
--- src/shell.c
+++ src/shell.c
@@ -3662,12 +3662,12 @@
36623662
** set, then a new database is appended to the already existing file.
36633663
**
36643664
** (5) Otherwise, SQLITE_CANTOPEN is returned.
36653665
**
36663666
** 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
3667
+** the file containing the database is limited to 1GiB. (1073741824 bytes)
3668
+** This VFS will not read or write past the 1GiB mark. This restriction
36693669
** might be lifted in future versions. For now, if you need a larger
36703670
** database, then keep it in a separate file.
36713671
**
36723672
** If the file being opened is a plain database (not an appended one), then
36733673
** this shim is a pass-through into the default underlying VFS. (rule 3)
@@ -3692,18 +3692,20 @@
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
*/
3697
-#define APND_MAX_SIZE (65536*15259)
3697
+#define APND_MAX_SIZE (0x40000000)
36983698
36993699
/*
3700
-** Size of storage page upon which to align appendvfs portion.
3700
+** Try to align the database to an even multiple of APND_ROUNDUP bytes.
37013701
*/
3702
-#ifndef APND_ROUNDUP_BITS
3703
-#define APND_ROUNDUP_BITS 12
3702
+#ifndef APND_ROUNDUP
3703
+#define APND_ROUNDUP 4096
37043704
#endif
3705
+#define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
3706
+#define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
37053707
37063708
/*
37073709
** Forward declaration of objects used by this utility
37083710
*/
37093711
typedef struct sqlite3_vfs ApndVfs;
@@ -3713,43 +3715,49 @@
37133715
** access to randomness, etc.
37143716
*/
37153717
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
37163718
#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
37173719
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
- */
3720
+/* An open appendvfs file
3721
+**
3722
+** An instance of this structure describes the appended database file.
3723
+** A separate sqlite3_file object is always appended. The appended
3724
+** sqlite3_file object (which can be accessed using ORIGFILE()) describes
3725
+** the entire file, including the prefix, the database, and the
3726
+** append-mark.
3727
+**
3728
+** The structure of an AppendVFS database is like this:
3729
+**
3730
+** +-------------+---------+----------+-------------+
3731
+** | prefix-file | padding | database | append-mark |
3732
+** +-------------+---------+----------+-------------+
3733
+** ^ ^
3734
+** | |
3735
+** iPgOne iMark
3736
+**
3737
+**
3738
+** "prefix file" - file onto which the database has been appended.
3739
+** "padding" - zero or more bytes inserted so that "database"
3740
+** starts on an APND_ROUNDUP boundary
3741
+** "database" - The SQLite database file
3742
+** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
3743
+** the offset from the start of prefix-file to the start
3744
+** of "database".
3745
+**
3746
+** The size of the database is iMark - iPgOne.
3747
+**
3748
+** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
3749
+** of iPgOne stored as a big-ending 64-bit integer.
3750
+**
3751
+** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
3752
+** Or, iMark is -1 to indicate that it has not yet been written.
3753
+*/
37443754
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;
3755
+ sqlite3_file base; /* Subclass. MUST BE FIRST! */
3756
+ sqlite3_int64 iPgOne; /* Offset to the start of the database */
3757
+ sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
3758
+ /* Always followed by another sqlite3_file that describes the whole file */
37513759
};
37523760
37533761
/*
37543762
** Methods for ApndFile
37553763
*/
@@ -3875,11 +3883,11 @@
38753883
unsigned char a[APND_MARK_SIZE];
38763884
int i = APND_MARK_FOS_SZ;
38773885
int rc;
38783886
assert(pFile == ORIGFILE(paf));
38793887
memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3880
- while (--i >= 0) {
3888
+ while( --i >= 0 ){
38813889
a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
38823890
iPgOne >>= 8;
38833891
}
38843892
iWriteEnd += paf->iPgOne;
38853893
if( SQLITE_OK==(rc = pFile->pMethods->xWrite
@@ -3903,12 +3911,11 @@
39033911
if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
39043912
pFile = ORIGFILE(pFile);
39053913
/* If append-mark is absent or will be overwritten, write it. */
39063914
if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
39073915
int rc = apndWriteMark(paf, pFile, iWriteEnd);
3908
- if( SQLITE_OK!=rc )
3909
- return rc;
3916
+ if( SQLITE_OK!=rc ) return rc;
39103917
}
39113918
return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
39123919
}
39133920
39143921
/*
@@ -3916,12 +3923,11 @@
39163923
*/
39173924
static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
39183925
ApndFile *paf = (ApndFile *)pFile;
39193926
pFile = ORIGFILE(pFile);
39203927
/* 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;
3928
+ if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
39233929
/* Truncate underlying file just past append mark */
39243930
return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
39253931
}
39263932
39273933
/*
@@ -4033,12 +4039,13 @@
40334039
sqlite3_int64 iOfst,
40344040
int iAmt,
40354041
void **pp
40364042
){
40374043
ApndFile *p = (ApndFile *)pFile;
4038
- if( p->iMark < 0 || iOfst+iAmt > p->iMark)
4044
+ if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
40394045
return SQLITE_IOERR; /* Cannot read what is not yet there. */
4046
+ }
40404047
pFile = ORIGFILE(pFile);
40414048
return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
40424049
}
40434050
40444051
/* Release a memory-mapped page */
@@ -4085,18 +4092,22 @@
40854092
static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
40864093
int rc;
40874094
char zHdr[16];
40884095
sqlite3_int64 iMark = apndReadMark(sz, pFile);
40894096
if( iMark>=0 ){
4090
- /* If file has right end-marker, the expected odd size, and the
4091
- * SQLite DB type marker where the end-marker puts it, then it
4092
- * is an appendvfs database (to be treated as such.)
4093
- */
4097
+ /* If file has the correct end-marker, the expected odd size, and the
4098
+ ** SQLite DB type marker where the end-marker puts it, then it
4099
+ ** is an appendvfs database.
4100
+ */
40944101
rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4095
- if( SQLITE_OK==rc && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4096
- && (sz & 0x1ff)== APND_MARK_SIZE && sz>=512+APND_MARK_SIZE )
4102
+ if( SQLITE_OK==rc
4103
+ && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4104
+ && (sz & 0x1ff) == APND_MARK_SIZE
4105
+ && sz>=512+APND_MARK_SIZE
4106
+ ){
40974107
return 1; /* It's an appendvfs database */
4108
+ }
40984109
}
40994110
return 0;
41004111
}
41014112
41024113
/*
@@ -4114,70 +4125,69 @@
41144125
}else{
41154126
return 1;
41164127
}
41174128
}
41184129
4119
-/* Round-up used to get appendvfs portion to begin at a page boundary. */
4120
-#define APND_ALIGN_MASK(nbits) ((1<<nbits)-1)
4121
-#define APND_START_ROUNDUP(fsz, nbits) \
4122
- ( ((fsz)+APND_ALIGN_MASK(nbits)) & ~(sqlite3_int64)APND_ALIGN_MASK(nbits) )
4123
-
41244130
/*
41254131
** Open an apnd file handle.
41264132
*/
41274133
static int apndOpen(
4128
- sqlite3_vfs *pVfs,
4134
+ sqlite3_vfs *pApndVfs,
41294135
const char *zName,
41304136
sqlite3_file *pFile,
41314137
int flags,
41324138
int *pOutFlags
41334139
){
4134
- ApndFile *p;
4135
- sqlite3_file *pSubFile;
4136
- sqlite3_vfs *pSubVfs;
4140
+ ApndFile *pApndFile = (ApndFile*)pFile;
4141
+ sqlite3_file *pBaseFile = ORIGFILE(pFile);
4142
+ sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
41374143
int rc;
4138
- sqlite3_int64 sz;
4139
- pSubVfs = ORIGVFS(pVfs);
4144
+ sqlite3_int64 sz = 0;
41404145
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4141
- /* The appendvfs is not to be used for transient or temporary databases. */
4142
- return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
4146
+ /* The appendvfs is not to be used for transient or temporary databases.
4147
+ ** Just use the base VFS open to initialize the given file object and
4148
+ ** open the underlying file. (Appendvfs is then unused for this file.)
4149
+ */
4150
+ return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
41434151
}
4144
- p = (ApndFile*)pFile;
4145
- memset(p, 0, sizeof(*p));
4146
- pSubFile = ORIGFILE(pFile);
4152
+ memset(pApndFile, 0, sizeof(ApndFile));
41474153
pFile->pMethods = &apnd_io_methods;
4148
- rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
4149
- if( rc ) goto apnd_open_done;
4150
- rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
4154
+ pApndFile->iMark = -1; /* Append mark not yet written */
4155
+
4156
+ rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4157
+ if( rc==SQLITE_OK ){
4158
+ rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4159
+ }
41514160
if( rc ){
4152
- pSubFile->pMethods->xClose(pSubFile);
4153
- goto apnd_open_done;
4161
+ pBaseFile->pMethods->xClose(pBaseFile);
4162
+ pFile->pMethods = 0;
4163
+ return rc;
41544164
}
4155
- if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
4156
- memmove(pFile, pSubFile, pSubVfs->szOsFile);
4165
+ if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4166
+ /* The file being opened appears to be just an ordinary DB. Copy
4167
+ ** the base dispatch-table so this instance mimics the base VFS.
4168
+ */
4169
+ memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
41574170
return SQLITE_OK;
41584171
}
4159
- /* Record that append mark has not been written until seen otherwise. */
4160
- p->iMark = -1;
4161
- p->iPgOne = apndReadMark(sz, pFile);
4162
- if( p->iPgOne>=0 ){
4163
- /* Append mark was found, infer its offset */
4164
- p->iMark = sz - p->iPgOne - APND_MARK_SIZE;
4172
+ pApndFile->iPgOne = apndReadMark(sz, pFile);
4173
+ if( pApndFile->iPgOne>=0 ){
4174
+ pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
41654175
return SQLITE_OK;
41664176
}
41674177
if( (flags & SQLITE_OPEN_CREATE)==0 ){
4168
- pSubFile->pMethods->xClose(pSubFile);
4178
+ pBaseFile->pMethods->xClose(pBaseFile);
41694179
rc = SQLITE_CANTOPEN;
4170
- }
4171
- /* Round newly added appendvfs location to #define'd page boundary.
4172
- * Note that nothing has yet been written to the underlying file.
4173
- * The append mark will be written along with first content write.
4174
- * Until then, the p->iMark value indicates it is not yet written.
4175
- */
4176
- p->iPgOne = APND_START_ROUNDUP(sz, APND_ROUNDUP_BITS);
4177
-apnd_open_done:
4178
- if( rc ) pFile->pMethods = 0;
4180
+ pFile->pMethods = 0;
4181
+ }else{
4182
+ /* Round newly added appendvfs location to #define'd page boundary.
4183
+ ** Note that nothing has yet been written to the underlying file.
4184
+ ** The append mark will be written along with first content write.
4185
+ ** Until then, paf->iMark value indicates it is not yet written.
4186
+ */
4187
+ pApndFile->iPgOne = APND_START_ROUNDUP(sz);
4188
+ }
41794189
return rc;
41804190
}
41814191
41824192
/*
41834193
** Delete an apnd file.
@@ -14035,17 +14045,17 @@
1403514045
".check GLOB Fail if output since .testcase does not match",
1403614046
".clone NEWDB Clone data into NEWDB from the existing database",
1403714047
".databases List names and files of attached databases",
1403814048
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
1403914049
".dbinfo ?DB? Show status information about the database",
14040
- ".dump ?TABLE? Render database content as SQL",
14050
+ ".dump ?OBJECTS? Render database content as SQL",
1404114051
" Options:",
1404214052
" --data-only Output only INSERT statements",
1404314053
" --newlines Allow unescaped newline characters in output",
1404414054
" --nosys Omit system tables (ex: \"sqlite_stat1\")",
1404514055
" --preserve-rowids Include ROWID values in the output",
14046
- " TABLE is a LIKE pattern for the tables to dump",
14056
+ " OBJECTS is a LIKE pattern for tables, indexes, triggers or views to dump",
1404714057
" Additional LIKE patterns can be given in subsequent arguments",
1404814058
".echo on|off Turn command echo on or off",
1404914059
".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
1405014060
" Other Modes:",
1405114061
#ifdef SQLITE_DEBUG
1405214062
--- src/shell.c
+++ src/shell.c
@@ -3662,12 +3662,12 @@
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)
@@ -3692,18 +3692,20 @@
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;
@@ -3713,43 +3715,49 @@
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 */
@@ -3875,11 +3883,11 @@
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
@@ -3903,12 +3911,11 @@
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 /*
@@ -3916,12 +3923,11 @@
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 /*
@@ -4033,12 +4039,13 @@
4033 sqlite3_int64 iOfst,
4034 int iAmt,
4035 void **pp
4036 ){
4037 ApndFile *p = (ApndFile *)pFile;
4038 if( p->iMark < 0 || iOfst+iAmt > p->iMark)
4039 return SQLITE_IOERR; /* Cannot read what is not yet there. */
 
4040 pFile = ORIGFILE(pFile);
4041 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4042 }
4043
4044 /* Release a memory-mapped page */
@@ -4085,18 +4092,22 @@
4085 static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4086 int rc;
4087 char zHdr[16];
4088 sqlite3_int64 iMark = apndReadMark(sz, pFile);
4089 if( iMark>=0 ){
4090 /* If file has right end-marker, the expected odd size, and the
4091 * SQLite DB type marker where the end-marker puts it, then it
4092 * is an appendvfs database (to be treated as such.)
4093 */
4094 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4095 if( SQLITE_OK==rc && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4096 && (sz & 0x1ff)== APND_MARK_SIZE && sz>=512+APND_MARK_SIZE )
 
 
 
4097 return 1; /* It's an appendvfs database */
 
4098 }
4099 return 0;
4100 }
4101
4102 /*
@@ -4114,70 +4125,69 @@
4114 }else{
4115 return 1;
4116 }
4117 }
4118
4119 /* Round-up used to get appendvfs portion to begin at a page boundary. */
4120 #define APND_ALIGN_MASK(nbits) ((1<<nbits)-1)
4121 #define APND_START_ROUNDUP(fsz, nbits) \
4122 ( ((fsz)+APND_ALIGN_MASK(nbits)) & ~(sqlite3_int64)APND_ALIGN_MASK(nbits) )
4123
4124 /*
4125 ** Open an apnd file handle.
4126 */
4127 static int apndOpen(
4128 sqlite3_vfs *pVfs,
4129 const char *zName,
4130 sqlite3_file *pFile,
4131 int flags,
4132 int *pOutFlags
4133 ){
4134 ApndFile *p;
4135 sqlite3_file *pSubFile;
4136 sqlite3_vfs *pSubVfs;
4137 int rc;
4138 sqlite3_int64 sz;
4139 pSubVfs = ORIGVFS(pVfs);
4140 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4141 /* The appendvfs is not to be used for transient or temporary databases. */
4142 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
 
 
 
4143 }
4144 p = (ApndFile*)pFile;
4145 memset(p, 0, sizeof(*p));
4146 pSubFile = ORIGFILE(pFile);
4147 pFile->pMethods = &apnd_io_methods;
4148 rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
4149 if( rc ) goto apnd_open_done;
4150 rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
 
 
 
4151 if( rc ){
4152 pSubFile->pMethods->xClose(pSubFile);
4153 goto apnd_open_done;
 
4154 }
4155 if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
4156 memmove(pFile, pSubFile, pSubVfs->szOsFile);
 
 
 
4157 return SQLITE_OK;
4158 }
4159 /* Record that append mark has not been written until seen otherwise. */
4160 p->iMark = -1;
4161 p->iPgOne = apndReadMark(sz, pFile);
4162 if( p->iPgOne>=0 ){
4163 /* Append mark was found, infer its offset */
4164 p->iMark = sz - p->iPgOne - APND_MARK_SIZE;
4165 return SQLITE_OK;
4166 }
4167 if( (flags & SQLITE_OPEN_CREATE)==0 ){
4168 pSubFile->pMethods->xClose(pSubFile);
4169 rc = SQLITE_CANTOPEN;
4170 }
4171 /* Round newly added appendvfs location to #define'd page boundary.
4172 * Note that nothing has yet been written to the underlying file.
4173 * The append mark will be written along with first content write.
4174 * Until then, the p->iMark value indicates it is not yet written.
4175 */
4176 p->iPgOne = APND_START_ROUNDUP(sz, APND_ROUNDUP_BITS);
4177 apnd_open_done:
4178 if( rc ) pFile->pMethods = 0;
4179 return rc;
4180 }
4181
4182 /*
4183 ** Delete an apnd file.
@@ -14035,17 +14045,17 @@
14035 ".check GLOB Fail if output since .testcase does not match",
14036 ".clone NEWDB Clone data into NEWDB from the existing database",
14037 ".databases List names and files of attached databases",
14038 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
14039 ".dbinfo ?DB? Show status information about the database",
14040 ".dump ?TABLE? Render database content as SQL",
14041 " Options:",
14042 " --data-only Output only INSERT statements",
14043 " --newlines Allow unescaped newline characters in output",
14044 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
14045 " --preserve-rowids Include ROWID values in the output",
14046 " TABLE is a LIKE pattern for the tables to dump",
14047 " Additional LIKE patterns can be given in subsequent arguments",
14048 ".echo on|off Turn command echo on or off",
14049 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
14050 " Other Modes:",
14051 #ifdef SQLITE_DEBUG
14052
--- src/shell.c
+++ src/shell.c
@@ -3662,12 +3662,12 @@
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 1GiB. (1073741824 bytes)
3668 ** This VFS will not read or write past the 1GiB 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)
@@ -3692,18 +3692,20 @@
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 (0x40000000)
3698
3699 /*
3700 ** Try to align the database to an even multiple of APND_ROUNDUP bytes.
3701 */
3702 #ifndef APND_ROUNDUP
3703 #define APND_ROUNDUP 4096
3704 #endif
3705 #define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
3706 #define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
3707
3708 /*
3709 ** Forward declaration of objects used by this utility
3710 */
3711 typedef struct sqlite3_vfs ApndVfs;
@@ -3713,43 +3715,49 @@
3715 ** access to randomness, etc.
3716 */
3717 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3718 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3719
3720 /* An open appendvfs file
3721 **
3722 ** An instance of this structure describes the appended database file.
3723 ** A separate sqlite3_file object is always appended. The appended
3724 ** sqlite3_file object (which can be accessed using ORIGFILE()) describes
3725 ** the entire file, including the prefix, the database, and the
3726 ** append-mark.
3727 **
3728 ** The structure of an AppendVFS database is like this:
3729 **
3730 ** +-------------+---------+----------+-------------+
3731 ** | prefix-file | padding | database | append-mark |
3732 ** +-------------+---------+----------+-------------+
3733 ** ^ ^
3734 ** | |
3735 ** iPgOne iMark
3736 **
3737 **
3738 ** "prefix file" - file onto which the database has been appended.
3739 ** "padding" - zero or more bytes inserted so that "database"
3740 ** starts on an APND_ROUNDUP boundary
3741 ** "database" - The SQLite database file
3742 ** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
3743 ** the offset from the start of prefix-file to the start
3744 ** of "database".
3745 **
3746 ** The size of the database is iMark - iPgOne.
3747 **
3748 ** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
3749 ** of iPgOne stored as a big-ending 64-bit integer.
3750 **
3751 ** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
3752 ** Or, iMark is -1 to indicate that it has not yet been written.
3753 */
3754 struct ApndFile {
3755 sqlite3_file base; /* Subclass. MUST BE FIRST! */
3756 sqlite3_int64 iPgOne; /* Offset to the start of the database */
3757 sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
3758 /* Always followed by another sqlite3_file that describes the whole file */
 
 
3759 };
3760
3761 /*
3762 ** Methods for ApndFile
3763 */
@@ -3875,11 +3883,11 @@
3883 unsigned char a[APND_MARK_SIZE];
3884 int i = APND_MARK_FOS_SZ;
3885 int rc;
3886 assert(pFile == ORIGFILE(paf));
3887 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3888 while( --i >= 0 ){
3889 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
3890 iPgOne >>= 8;
3891 }
3892 iWriteEnd += paf->iPgOne;
3893 if( SQLITE_OK==(rc = pFile->pMethods->xWrite
@@ -3903,12 +3911,11 @@
3911 if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
3912 pFile = ORIGFILE(pFile);
3913 /* If append-mark is absent or will be overwritten, write it. */
3914 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
3915 int rc = apndWriteMark(paf, pFile, iWriteEnd);
3916 if( SQLITE_OK!=rc ) return rc;
 
3917 }
3918 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3919 }
3920
3921 /*
@@ -3916,12 +3923,11 @@
3923 */
3924 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3925 ApndFile *paf = (ApndFile *)pFile;
3926 pFile = ORIGFILE(pFile);
3927 /* The append mark goes out first so truncate failure does not lose it. */
3928 if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
 
3929 /* Truncate underlying file just past append mark */
3930 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
3931 }
3932
3933 /*
@@ -4033,12 +4039,13 @@
4039 sqlite3_int64 iOfst,
4040 int iAmt,
4041 void **pp
4042 ){
4043 ApndFile *p = (ApndFile *)pFile;
4044 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
4045 return SQLITE_IOERR; /* Cannot read what is not yet there. */
4046 }
4047 pFile = ORIGFILE(pFile);
4048 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4049 }
4050
4051 /* Release a memory-mapped page */
@@ -4085,18 +4092,22 @@
4092 static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4093 int rc;
4094 char zHdr[16];
4095 sqlite3_int64 iMark = apndReadMark(sz, pFile);
4096 if( iMark>=0 ){
4097 /* If file has the correct end-marker, the expected odd size, and the
4098 ** SQLite DB type marker where the end-marker puts it, then it
4099 ** is an appendvfs database.
4100 */
4101 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4102 if( SQLITE_OK==rc
4103 && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4104 && (sz & 0x1ff) == APND_MARK_SIZE
4105 && sz>=512+APND_MARK_SIZE
4106 ){
4107 return 1; /* It's an appendvfs database */
4108 }
4109 }
4110 return 0;
4111 }
4112
4113 /*
@@ -4114,70 +4125,69 @@
4125 }else{
4126 return 1;
4127 }
4128 }
4129
 
 
 
 
 
4130 /*
4131 ** Open an apnd file handle.
4132 */
4133 static int apndOpen(
4134 sqlite3_vfs *pApndVfs,
4135 const char *zName,
4136 sqlite3_file *pFile,
4137 int flags,
4138 int *pOutFlags
4139 ){
4140 ApndFile *pApndFile = (ApndFile*)pFile;
4141 sqlite3_file *pBaseFile = ORIGFILE(pFile);
4142 sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
4143 int rc;
4144 sqlite3_int64 sz = 0;
 
4145 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4146 /* The appendvfs is not to be used for transient or temporary databases.
4147 ** Just use the base VFS open to initialize the given file object and
4148 ** open the underlying file. (Appendvfs is then unused for this file.)
4149 */
4150 return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
4151 }
4152 memset(pApndFile, 0, sizeof(ApndFile));
 
 
4153 pFile->pMethods = &apnd_io_methods;
4154 pApndFile->iMark = -1; /* Append mark not yet written */
4155
4156 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4157 if( rc==SQLITE_OK ){
4158 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4159 }
4160 if( rc ){
4161 pBaseFile->pMethods->xClose(pBaseFile);
4162 pFile->pMethods = 0;
4163 return rc;
4164 }
4165 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4166 /* The file being opened appears to be just an ordinary DB. Copy
4167 ** the base dispatch-table so this instance mimics the base VFS.
4168 */
4169 memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
4170 return SQLITE_OK;
4171 }
4172 pApndFile->iPgOne = apndReadMark(sz, pFile);
4173 if( pApndFile->iPgOne>=0 ){
4174 pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
 
 
 
4175 return SQLITE_OK;
4176 }
4177 if( (flags & SQLITE_OPEN_CREATE)==0 ){
4178 pBaseFile->pMethods->xClose(pBaseFile);
4179 rc = SQLITE_CANTOPEN;
4180 pFile->pMethods = 0;
4181 }else{
4182 /* Round newly added appendvfs location to #define'd page boundary.
4183 ** Note that nothing has yet been written to the underlying file.
4184 ** The append mark will be written along with first content write.
4185 ** Until then, paf->iMark value indicates it is not yet written.
4186 */
4187 pApndFile->iPgOne = APND_START_ROUNDUP(sz);
4188 }
4189 return rc;
4190 }
4191
4192 /*
4193 ** Delete an apnd file.
@@ -14035,17 +14045,17 @@
14045 ".check GLOB Fail if output since .testcase does not match",
14046 ".clone NEWDB Clone data into NEWDB from the existing database",
14047 ".databases List names and files of attached databases",
14048 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
14049 ".dbinfo ?DB? Show status information about the database",
14050 ".dump ?OBJECTS? Render database content as SQL",
14051 " Options:",
14052 " --data-only Output only INSERT statements",
14053 " --newlines Allow unescaped newline characters in output",
14054 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
14055 " --preserve-rowids Include ROWID values in the output",
14056 " OBJECTS is a LIKE pattern for tables, indexes, triggers or views to dump",
14057 " Additional LIKE patterns can be given in subsequent arguments",
14058 ".echo on|off Turn command echo on or off",
14059 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
14060 " Other Modes:",
14061 #ifdef SQLITE_DEBUG
14062
+48 -27
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.35.0. By combining all the individual C code files into this
3
+** version 3.35.2. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -1184,13 +1184,13 @@
11841184
**
11851185
** See also: [sqlite3_libversion()],
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
1189
-#define SQLITE_VERSION "3.35.0"
1190
-#define SQLITE_VERSION_NUMBER 3035000
1191
-#define SQLITE_SOURCE_ID "2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b"
1189
+#define SQLITE_VERSION "3.35.2"
1190
+#define SQLITE_VERSION_NUMBER 3035002
1191
+#define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -17005,11 +17005,14 @@
1700517005
u8 iDb; /* Which db file is being initialized */
1700617006
u8 busy; /* TRUE if currently initializing */
1700717007
unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
1700817008
unsigned imposterTable : 1; /* Building an imposter table */
1700917009
unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
17010
+ unsigned bDropColumn : 1; /* Doing schema check after DROP COLUMN */
1701017011
char **azInit; /* "type", "name", and "tbl_name" columns */
17012
+ /* or if bDropColumn, then azInit[0] is the */
17013
+ /* name of the column being dropped */
1701117014
} init;
1701217015
int nVdbeActive; /* Number of VDBEs currently running */
1701317016
int nVdbeRead; /* Number of active VDBEs that read or write */
1701417017
int nVdbeWrite; /* Number of active VDBEs that read and write */
1701517018
int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -22866,10 +22869,11 @@
2286622869
int i, n;
2286722870
const unsigned char *z;
2286822871
int eType;
2286922872
memset(p, 0, sizeof(*p));
2287022873
if( argc==0 ){
22874
+ if( !sqlite3NotPureFunc(context) ) return 1;
2287122875
return setDateTimeToCurrent(context, p);
2287222876
}
2287322877
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
2287422878
|| eType==SQLITE_INTEGER ){
2287522879
setRawDateNumber(p, sqlite3_value_double(argv[0]));
@@ -99165,10 +99169,11 @@
9916599169
*/
9916699170
if( cnt==0 && zTab==0 ){
9916799171
assert( pExpr->op==TK_ID );
9916899172
if( ExprHasProperty(pExpr,EP_DblQuoted)
9916999173
&& areDoubleQuotedStringsEnabled(db, pTopNC)
99174
+ && (db->init.bDropColumn==0 || sqlite3StrICmp(zCol, db->init.azInit[0])!=0)
9917099175
){
9917199176
/* If a double-quoted identifier does not match any known column name,
9917299177
** then treat it as a string.
9917399178
**
9917499179
** This hack was added in the early days of SQLite in a misguided attempt
@@ -99179,10 +99184,15 @@
9917999184
** programmers. To all those frustrated programmers, my apologies.
9918099185
**
9918199186
** Someday, I hope to get rid of this hack. Unfortunately there is
9918299187
** a huge amount of legacy SQL that uses it. So for now, we just
9918399188
** issue a warning.
99189
+ **
99190
+ ** 2021-03-15: ticket 1c24a659e6d7f3a1
99191
+ ** Do not do the ID-to-STRING conversion when doing the schema
99192
+ ** sanity check following a DROP COLUMN if the identifer name matches
99193
+ ** the name of the column being dropped.
9918499194
*/
9918599195
sqlite3_log(SQLITE_WARNING,
9918699196
"double-quoted string literal: \"%w\"", zCol);
9918799197
#ifdef SQLITE_ENABLE_NORMALIZE
9918899198
sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -106778,31 +106788,32 @@
106778106788
*/
106779106789
static void renameTestSchema(
106780106790
Parse *pParse, /* Parse context */
106781106791
const char *zDb, /* Name of db to verify schema of */
106782106792
int bTemp, /* True if this is the temp db */
106783
- const char *zWhen /* "when" part of error message */
106793
+ const char *zWhen, /* "when" part of error message */
106794
+ const char *zDropColumn /* Name of column being dropped */
106784106795
){
106785106796
pParse->colNamesSet = 1;
106786106797
sqlite3NestedParse(pParse,
106787106798
"SELECT 1 "
106788106799
"FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106789106800
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106790106801
" AND sql NOT LIKE 'create virtual%%'"
106791
- " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q)=NULL ",
106802
+ " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %Q)=NULL ",
106792106803
zDb,
106793
- zDb, bTemp, zWhen
106804
+ zDb, bTemp, zWhen, zDropColumn
106794106805
);
106795106806
106796106807
if( bTemp==0 ){
106797106808
sqlite3NestedParse(pParse,
106798106809
"SELECT 1 "
106799106810
"FROM temp." DFLT_SCHEMA_TABLE " "
106800106811
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106801106812
" AND sql NOT LIKE 'create virtual%%'"
106802
- " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q)=NULL ",
106803
- zDb, zWhen
106813
+ " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %Q)=NULL ",
106814
+ zDb, zWhen, zDropColumn
106804106815
);
106805106816
}
106806106817
}
106807106818
106808106819
/*
@@ -106961,11 +106972,11 @@
106961106972
sqlite3NestedParse(pParse,
106962106973
"UPDATE sqlite_temp_schema SET "
106963106974
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
106964106975
"tbl_name = "
106965106976
"CASE WHEN tbl_name=%Q COLLATE nocase AND "
106966
- " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename') "
106977
+ " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename',0) "
106967106978
"THEN %Q ELSE tbl_name END "
106968106979
"WHERE type IN ('view', 'trigger')"
106969106980
, zDb, zTabName, zName, zTabName, zDb, zName);
106970106981
}
106971106982
@@ -106981,11 +106992,11 @@
106981106992
sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
106982106993
}
106983106994
#endif
106984106995
106985106996
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
106986
- renameTestSchema(pParse, zDb, iDb==1, "after rename");
106997
+ renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
106987106998
106988106999
exit_rename_table:
106989107000
sqlite3SrcListDelete(db, pSrc);
106990107001
sqlite3DbFree(db, zName);
106991107002
db->mDbFlags = savedDbFlags;
@@ -107349,11 +107360,11 @@
107349107360
zDb, pTab->zName, iCol, zNew, bQuote
107350107361
);
107351107362
107352107363
/* Drop and reload the database schema. */
107353107364
renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107354
- renameTestSchema(pParse, zDb, iSchema==1, "after rename");
107365
+ renameTestSchema(pParse, zDb, iSchema==1, "after rename", 0);
107355107366
107356107367
exit_rename_column:
107357107368
sqlite3SrcListDelete(db, pSrc);
107358107369
sqlite3DbFree(db, zOld);
107359107370
sqlite3DbFree(db, zNew);
@@ -107773,16 +107784,21 @@
107773107784
static int renameParseSql(
107774107785
Parse *p, /* Memory to use for Parse object */
107775107786
const char *zDb, /* Name of schema SQL belongs to */
107776107787
sqlite3 *db, /* Database handle */
107777107788
const char *zSql, /* SQL to parse */
107778
- int bTemp /* True if SQL is from temp schema */
107789
+ int bTemp, /* True if SQL is from temp schema */
107790
+ const char *zDropColumn /* Name of column being dropped */
107779107791
){
107780107792
int rc;
107781107793
char *zErr = 0;
107782107794
107783107795
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
107796
+ if( zDropColumn ){
107797
+ db->init.bDropColumn = 1;
107798
+ db->init.azInit = (char**)&zDropColumn;
107799
+ }
107784107800
107785107801
/* Parse the SQL statement passed as the first argument. If no error
107786107802
** occurs and the parse does not result in a new table, index or
107787107803
** trigger object, the database must be corrupt. */
107788107804
memset(p, 0, sizeof(Parse));
@@ -107811,10 +107827,11 @@
107811107827
}
107812107828
}
107813107829
#endif
107814107830
107815107831
db->init.iDb = 0;
107832
+ db->init.bDropColumn = 0;
107816107833
return rc;
107817107834
}
107818107835
107819107836
/*
107820107837
** This function edits SQL statement zSql, replacing each token identified
@@ -108112,11 +108129,11 @@
108112108129
sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108113108130
108114108131
#ifndef SQLITE_OMIT_AUTHORIZATION
108115108132
db->xAuth = 0;
108116108133
#endif
108117
- rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
108134
+ rc = renameParseSql(&sParse, zDb, db, zSql, bTemp, 0);
108118108135
108119108136
/* Find tokens that need to be replaced. */
108120108137
memset(&sWalker, 0, sizeof(Walker));
108121108138
sWalker.pParse = &sParse;
108122108139
sWalker.xExprCallback = renameColumnExprCb;
@@ -108154,16 +108171,16 @@
108154108171
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108155108172
}
108156108173
for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
108157108174
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108158108175
}
108159
- }
108160108176
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
108161
- for(i=0; i<sParse.pNewTable->nCol; i++){
108162
- sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108177
+ for(i=0; i<sParse.pNewTable->nCol; i++){
108178
+ sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108179
+ }
108180
+#endif
108163108181
}
108164
-#endif
108165108182
108166108183
for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
108167108184
for(i=0; i<pFKey->nCol; i++){
108168108185
if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
108169108186
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
@@ -108316,11 +108333,11 @@
108316108333
sWalker.pParse = &sParse;
108317108334
sWalker.xExprCallback = renameTableExprCb;
108318108335
sWalker.xSelectCallback = renameTableSelectCb;
108319108336
sWalker.u.pRename = &sCtx;
108320108337
108321
- rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108338
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, 0);
108322108339
108323108340
if( rc==SQLITE_OK ){
108324108341
int isLegacy = (db->flags & SQLITE_LegacyAlter);
108325108342
if( sParse.pNewTable ){
108326108343
Table *pTab = sParse.pNewTable;
@@ -108432,10 +108449,11 @@
108432108449
** 1: SQL statement.
108433108450
** 2: Object type ("view", "table", "trigger" or "index").
108434108451
** 3: Object name.
108435108452
** 4: True if object is from temp schema.
108436108453
** 5: "when" part of error message.
108454
+** 6: Name of column being dropped, or NULL.
108437108455
**
108438108456
** Unless it finds an error, this function normally returns NULL. However, it
108439108457
** returns integer value 1 if:
108440108458
**
108441108459
** * the SQL argument creates a trigger, and
@@ -108450,10 +108468,11 @@
108450108468
char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108451108469
char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108452108470
int bTemp = sqlite3_value_int(argv[4]);
108453108471
int isLegacy = (db->flags & SQLITE_LegacyAlter);
108454108472
char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
108473
+ char const *zDropColumn = (const char*)sqlite3_value_text(argv[6]);
108455108474
108456108475
#ifndef SQLITE_OMIT_AUTHORIZATION
108457108476
sqlite3_xauth xAuth = db->xAuth;
108458108477
db->xAuth = 0;
108459108478
#endif
@@ -108460,11 +108479,11 @@
108460108479
108461108480
UNUSED_PARAMETER(NotUsed);
108462108481
if( zDb && zInput ){
108463108482
int rc;
108464108483
Parse sParse;
108465
- rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108484
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, zDropColumn);
108466108485
if( rc==SQLITE_OK ){
108467108486
if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108468108487
NameContext sNC;
108469108488
memset(&sNC, 0, sizeof(sNC));
108470108489
sNC.pParse = &sParse;
@@ -108528,11 +108547,11 @@
108528108547
sqlite3_xauth xAuth = db->xAuth;
108529108548
db->xAuth = 0;
108530108549
#endif
108531108550
108532108551
UNUSED_PARAMETER(NotUsed);
108533
- rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108552
+ rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0);
108534108553
if( rc!=SQLITE_OK ) goto drop_column_done;
108535108554
pTab = sParse.pNewTable;
108536108555
if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108537108556
/* This can happen if the sqlite_schema table is corrupt */
108538108557
rc = SQLITE_CORRUPT_BKPT;
@@ -108621,21 +108640,21 @@
108621108640
108622108641
/* Edit the sqlite_schema table */
108623108642
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108624108643
assert( iDb>=0 );
108625108644
zDb = db->aDb[iDb].zDbSName;
108626
- renameTestSchema(pParse, zDb, iDb==1, "");
108645
+ renameTestSchema(pParse, zDb, iDb==1, "", 0);
108627108646
sqlite3NestedParse(pParse,
108628108647
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108629108648
"sql = sqlite_drop_column(%d, sql, %d) "
108630108649
"WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108631108650
, zDb, iDb, iCol, pTab->zName
108632108651
);
108633108652
108634108653
/* Drop and reload the database schema. */
108635108654
renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108636
- renameTestSchema(pParse, zDb, iDb==1, "after drop column");
108655
+ renameTestSchema(pParse, zDb, iDb==1, "after drop column", zCol);
108637108656
108638108657
/* Edit rows of table on disk */
108639108658
if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108640108659
int i;
108641108660
int addr;
@@ -108691,11 +108710,11 @@
108691108710
*/
108692108711
SQLITE_PRIVATE void sqlite3AlterFunctions(void){
108693108712
static FuncDef aAlterTableFuncs[] = {
108694108713
INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
108695108714
INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
108696
- INTERNAL_FUNCTION(sqlite_rename_test, 6, renameTableTest),
108715
+ INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
108697108716
INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
108698108717
};
108699108718
sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
108700108719
}
108701108720
#endif /* SQLITE_ALTER_TABLE */
@@ -135116,10 +135135,11 @@
135116135135
135117135136
/* Restriction (23) */
135118135137
if( (p->selFlags & SF_Recursive) ) return 0;
135119135138
135120135139
if( pSrc->nSrc>1 ){
135140
+ if( pParse->nSelect>500 ) return 0;
135121135141
aCsrMap = sqlite3DbMallocZero(db, pParse->nTab*sizeof(int));
135122135142
}
135123135143
}
135124135144
135125135145
/***** If we reach this point, flattening is permitted. *****/
@@ -135192,10 +135212,11 @@
135192135212
p->op = TK_ALL;
135193135213
pSubitem->pTab = pItemTab;
135194135214
if( pNew==0 ){
135195135215
p->pPrior = pPrior;
135196135216
}else{
135217
+ pNew->selId = ++pParse->nSelect;
135197135218
if( aCsrMap && db->mallocFailed==0 ){
135198135219
renumberCursors(pParse, pNew, iFrom, aCsrMap);
135199135220
}
135200135221
pNew->pPrior = pPrior;
135201135222
if( pPrior ) pPrior->pNext = pNew;
@@ -229190,11 +229211,11 @@
229190229211
int nArg, /* Number of args */
229191229212
sqlite3_value **apUnused /* Function arguments */
229192229213
){
229193229214
assert( nArg==0 );
229194229215
UNUSED_PARAM2(nArg, apUnused);
229195
- sqlite3_result_text(pCtx, "fts5: 2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b", -1, SQLITE_TRANSIENT);
229216
+ sqlite3_result_text(pCtx, "fts5: 2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827", -1, SQLITE_TRANSIENT);
229196229217
}
229197229218
229198229219
/*
229199229220
** Return true if zName is the extension on one of the shadow tables used
229200229221
** by this module.
@@ -234116,12 +234137,12 @@
234116234137
}
234117234138
#endif /* SQLITE_CORE */
234118234139
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234119234140
234120234141
/************** End of stmt.c ************************************************/
234121
-#if __LINE__!=234121
234142
+#if __LINE__!=234142
234122234143
#undef SQLITE_SOURCE_ID
234123
-#define SQLITE_SOURCE_ID "2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115alt2"
234144
+#define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50calt2"
234124234145
#endif
234125234146
/* Return the source-id for this library */
234126234147
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234127234148
/************************** End of sqlite3.c ******************************/
234128234149
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.35.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1184,13 +1184,13 @@
1184 **
1185 ** See also: [sqlite3_libversion()],
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-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -17005,11 +17005,14 @@
17005 u8 iDb; /* Which db file is being initialized */
17006 u8 busy; /* TRUE if currently initializing */
17007 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
17008 unsigned imposterTable : 1; /* Building an imposter table */
17009 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
 
17010 char **azInit; /* "type", "name", and "tbl_name" columns */
 
 
17011 } init;
17012 int nVdbeActive; /* Number of VDBEs currently running */
17013 int nVdbeRead; /* Number of active VDBEs that read or write */
17014 int nVdbeWrite; /* Number of active VDBEs that read and write */
17015 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -22866,10 +22869,11 @@
22866 int i, n;
22867 const unsigned char *z;
22868 int eType;
22869 memset(p, 0, sizeof(*p));
22870 if( argc==0 ){
 
22871 return setDateTimeToCurrent(context, p);
22872 }
22873 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
22874 || eType==SQLITE_INTEGER ){
22875 setRawDateNumber(p, sqlite3_value_double(argv[0]));
@@ -99165,10 +99169,11 @@
99165 */
99166 if( cnt==0 && zTab==0 ){
99167 assert( pExpr->op==TK_ID );
99168 if( ExprHasProperty(pExpr,EP_DblQuoted)
99169 && areDoubleQuotedStringsEnabled(db, pTopNC)
 
99170 ){
99171 /* If a double-quoted identifier does not match any known column name,
99172 ** then treat it as a string.
99173 **
99174 ** This hack was added in the early days of SQLite in a misguided attempt
@@ -99179,10 +99184,15 @@
99179 ** programmers. To all those frustrated programmers, my apologies.
99180 **
99181 ** Someday, I hope to get rid of this hack. Unfortunately there is
99182 ** a huge amount of legacy SQL that uses it. So for now, we just
99183 ** issue a warning.
 
 
 
 
 
99184 */
99185 sqlite3_log(SQLITE_WARNING,
99186 "double-quoted string literal: \"%w\"", zCol);
99187 #ifdef SQLITE_ENABLE_NORMALIZE
99188 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -106778,31 +106788,32 @@
106778 */
106779 static void renameTestSchema(
106780 Parse *pParse, /* Parse context */
106781 const char *zDb, /* Name of db to verify schema of */
106782 int bTemp, /* True if this is the temp db */
106783 const char *zWhen /* "when" part of error message */
 
106784 ){
106785 pParse->colNamesSet = 1;
106786 sqlite3NestedParse(pParse,
106787 "SELECT 1 "
106788 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106789 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106790 " AND sql NOT LIKE 'create virtual%%'"
106791 " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q)=NULL ",
106792 zDb,
106793 zDb, bTemp, zWhen
106794 );
106795
106796 if( bTemp==0 ){
106797 sqlite3NestedParse(pParse,
106798 "SELECT 1 "
106799 "FROM temp." DFLT_SCHEMA_TABLE " "
106800 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106801 " AND sql NOT LIKE 'create virtual%%'"
106802 " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q)=NULL ",
106803 zDb, zWhen
106804 );
106805 }
106806 }
106807
106808 /*
@@ -106961,11 +106972,11 @@
106961 sqlite3NestedParse(pParse,
106962 "UPDATE sqlite_temp_schema SET "
106963 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
106964 "tbl_name = "
106965 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
106966 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename') "
106967 "THEN %Q ELSE tbl_name END "
106968 "WHERE type IN ('view', 'trigger')"
106969 , zDb, zTabName, zName, zTabName, zDb, zName);
106970 }
106971
@@ -106981,11 +106992,11 @@
106981 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
106982 }
106983 #endif
106984
106985 renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
106986 renameTestSchema(pParse, zDb, iDb==1, "after rename");
106987
106988 exit_rename_table:
106989 sqlite3SrcListDelete(db, pSrc);
106990 sqlite3DbFree(db, zName);
106991 db->mDbFlags = savedDbFlags;
@@ -107349,11 +107360,11 @@
107349 zDb, pTab->zName, iCol, zNew, bQuote
107350 );
107351
107352 /* Drop and reload the database schema. */
107353 renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107354 renameTestSchema(pParse, zDb, iSchema==1, "after rename");
107355
107356 exit_rename_column:
107357 sqlite3SrcListDelete(db, pSrc);
107358 sqlite3DbFree(db, zOld);
107359 sqlite3DbFree(db, zNew);
@@ -107773,16 +107784,21 @@
107773 static int renameParseSql(
107774 Parse *p, /* Memory to use for Parse object */
107775 const char *zDb, /* Name of schema SQL belongs to */
107776 sqlite3 *db, /* Database handle */
107777 const char *zSql, /* SQL to parse */
107778 int bTemp /* True if SQL is from temp schema */
 
107779 ){
107780 int rc;
107781 char *zErr = 0;
107782
107783 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
 
 
 
 
107784
107785 /* Parse the SQL statement passed as the first argument. If no error
107786 ** occurs and the parse does not result in a new table, index or
107787 ** trigger object, the database must be corrupt. */
107788 memset(p, 0, sizeof(Parse));
@@ -107811,10 +107827,11 @@
107811 }
107812 }
107813 #endif
107814
107815 db->init.iDb = 0;
 
107816 return rc;
107817 }
107818
107819 /*
107820 ** This function edits SQL statement zSql, replacing each token identified
@@ -108112,11 +108129,11 @@
108112 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108113
108114 #ifndef SQLITE_OMIT_AUTHORIZATION
108115 db->xAuth = 0;
108116 #endif
108117 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
108118
108119 /* Find tokens that need to be replaced. */
108120 memset(&sWalker, 0, sizeof(Walker));
108121 sWalker.pParse = &sParse;
108122 sWalker.xExprCallback = renameColumnExprCb;
@@ -108154,16 +108171,16 @@
108154 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108155 }
108156 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
108157 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108158 }
108159 }
108160 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
108161 for(i=0; i<sParse.pNewTable->nCol; i++){
108162 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
 
 
108163 }
108164 #endif
108165
108166 for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
108167 for(i=0; i<pFKey->nCol; i++){
108168 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
108169 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
@@ -108316,11 +108333,11 @@
108316 sWalker.pParse = &sParse;
108317 sWalker.xExprCallback = renameTableExprCb;
108318 sWalker.xSelectCallback = renameTableSelectCb;
108319 sWalker.u.pRename = &sCtx;
108320
108321 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108322
108323 if( rc==SQLITE_OK ){
108324 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108325 if( sParse.pNewTable ){
108326 Table *pTab = sParse.pNewTable;
@@ -108432,10 +108449,11 @@
108432 ** 1: SQL statement.
108433 ** 2: Object type ("view", "table", "trigger" or "index").
108434 ** 3: Object name.
108435 ** 4: True if object is from temp schema.
108436 ** 5: "when" part of error message.
 
108437 **
108438 ** Unless it finds an error, this function normally returns NULL. However, it
108439 ** returns integer value 1 if:
108440 **
108441 ** * the SQL argument creates a trigger, and
@@ -108450,10 +108468,11 @@
108450 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108451 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108452 int bTemp = sqlite3_value_int(argv[4]);
108453 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108454 char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
 
108455
108456 #ifndef SQLITE_OMIT_AUTHORIZATION
108457 sqlite3_xauth xAuth = db->xAuth;
108458 db->xAuth = 0;
108459 #endif
@@ -108460,11 +108479,11 @@
108460
108461 UNUSED_PARAMETER(NotUsed);
108462 if( zDb && zInput ){
108463 int rc;
108464 Parse sParse;
108465 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108466 if( rc==SQLITE_OK ){
108467 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108468 NameContext sNC;
108469 memset(&sNC, 0, sizeof(sNC));
108470 sNC.pParse = &sParse;
@@ -108528,11 +108547,11 @@
108528 sqlite3_xauth xAuth = db->xAuth;
108529 db->xAuth = 0;
108530 #endif
108531
108532 UNUSED_PARAMETER(NotUsed);
108533 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108534 if( rc!=SQLITE_OK ) goto drop_column_done;
108535 pTab = sParse.pNewTable;
108536 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108537 /* This can happen if the sqlite_schema table is corrupt */
108538 rc = SQLITE_CORRUPT_BKPT;
@@ -108621,21 +108640,21 @@
108621
108622 /* Edit the sqlite_schema table */
108623 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108624 assert( iDb>=0 );
108625 zDb = db->aDb[iDb].zDbSName;
108626 renameTestSchema(pParse, zDb, iDb==1, "");
108627 sqlite3NestedParse(pParse,
108628 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108629 "sql = sqlite_drop_column(%d, sql, %d) "
108630 "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108631 , zDb, iDb, iCol, pTab->zName
108632 );
108633
108634 /* Drop and reload the database schema. */
108635 renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108636 renameTestSchema(pParse, zDb, iDb==1, "after drop column");
108637
108638 /* Edit rows of table on disk */
108639 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108640 int i;
108641 int addr;
@@ -108691,11 +108710,11 @@
108691 */
108692 SQLITE_PRIVATE void sqlite3AlterFunctions(void){
108693 static FuncDef aAlterTableFuncs[] = {
108694 INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
108695 INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
108696 INTERNAL_FUNCTION(sqlite_rename_test, 6, renameTableTest),
108697 INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
108698 };
108699 sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
108700 }
108701 #endif /* SQLITE_ALTER_TABLE */
@@ -135116,10 +135135,11 @@
135116
135117 /* Restriction (23) */
135118 if( (p->selFlags & SF_Recursive) ) return 0;
135119
135120 if( pSrc->nSrc>1 ){
 
135121 aCsrMap = sqlite3DbMallocZero(db, pParse->nTab*sizeof(int));
135122 }
135123 }
135124
135125 /***** If we reach this point, flattening is permitted. *****/
@@ -135192,10 +135212,11 @@
135192 p->op = TK_ALL;
135193 pSubitem->pTab = pItemTab;
135194 if( pNew==0 ){
135195 p->pPrior = pPrior;
135196 }else{
 
135197 if( aCsrMap && db->mallocFailed==0 ){
135198 renumberCursors(pParse, pNew, iFrom, aCsrMap);
135199 }
135200 pNew->pPrior = pPrior;
135201 if( pPrior ) pPrior->pNext = pNew;
@@ -229190,11 +229211,11 @@
229190 int nArg, /* Number of args */
229191 sqlite3_value **apUnused /* Function arguments */
229192 ){
229193 assert( nArg==0 );
229194 UNUSED_PARAM2(nArg, apUnused);
229195 sqlite3_result_text(pCtx, "fts5: 2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b", -1, SQLITE_TRANSIENT);
229196 }
229197
229198 /*
229199 ** Return true if zName is the extension on one of the shadow tables used
229200 ** by this module.
@@ -234116,12 +234137,12 @@
234116 }
234117 #endif /* SQLITE_CORE */
234118 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234119
234120 /************** End of stmt.c ************************************************/
234121 #if __LINE__!=234121
234122 #undef SQLITE_SOURCE_ID
234123 #define SQLITE_SOURCE_ID "2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115alt2"
234124 #endif
234125 /* Return the source-id for this library */
234126 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234127 /************************** End of sqlite3.c ******************************/
234128
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.35.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1184,13 +1184,13 @@
1184 **
1185 ** See also: [sqlite3_libversion()],
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.35.2"
1190 #define SQLITE_VERSION_NUMBER 3035002
1191 #define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -17005,11 +17005,14 @@
17005 u8 iDb; /* Which db file is being initialized */
17006 u8 busy; /* TRUE if currently initializing */
17007 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
17008 unsigned imposterTable : 1; /* Building an imposter table */
17009 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
17010 unsigned bDropColumn : 1; /* Doing schema check after DROP COLUMN */
17011 char **azInit; /* "type", "name", and "tbl_name" columns */
17012 /* or if bDropColumn, then azInit[0] is the */
17013 /* name of the column being dropped */
17014 } init;
17015 int nVdbeActive; /* Number of VDBEs currently running */
17016 int nVdbeRead; /* Number of active VDBEs that read or write */
17017 int nVdbeWrite; /* Number of active VDBEs that read and write */
17018 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -22866,10 +22869,11 @@
22869 int i, n;
22870 const unsigned char *z;
22871 int eType;
22872 memset(p, 0, sizeof(*p));
22873 if( argc==0 ){
22874 if( !sqlite3NotPureFunc(context) ) return 1;
22875 return setDateTimeToCurrent(context, p);
22876 }
22877 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
22878 || eType==SQLITE_INTEGER ){
22879 setRawDateNumber(p, sqlite3_value_double(argv[0]));
@@ -99165,10 +99169,11 @@
99169 */
99170 if( cnt==0 && zTab==0 ){
99171 assert( pExpr->op==TK_ID );
99172 if( ExprHasProperty(pExpr,EP_DblQuoted)
99173 && areDoubleQuotedStringsEnabled(db, pTopNC)
99174 && (db->init.bDropColumn==0 || sqlite3StrICmp(zCol, db->init.azInit[0])!=0)
99175 ){
99176 /* If a double-quoted identifier does not match any known column name,
99177 ** then treat it as a string.
99178 **
99179 ** This hack was added in the early days of SQLite in a misguided attempt
@@ -99179,10 +99184,15 @@
99184 ** programmers. To all those frustrated programmers, my apologies.
99185 **
99186 ** Someday, I hope to get rid of this hack. Unfortunately there is
99187 ** a huge amount of legacy SQL that uses it. So for now, we just
99188 ** issue a warning.
99189 **
99190 ** 2021-03-15: ticket 1c24a659e6d7f3a1
99191 ** Do not do the ID-to-STRING conversion when doing the schema
99192 ** sanity check following a DROP COLUMN if the identifer name matches
99193 ** the name of the column being dropped.
99194 */
99195 sqlite3_log(SQLITE_WARNING,
99196 "double-quoted string literal: \"%w\"", zCol);
99197 #ifdef SQLITE_ENABLE_NORMALIZE
99198 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -106778,31 +106788,32 @@
106788 */
106789 static void renameTestSchema(
106790 Parse *pParse, /* Parse context */
106791 const char *zDb, /* Name of db to verify schema of */
106792 int bTemp, /* True if this is the temp db */
106793 const char *zWhen, /* "when" part of error message */
106794 const char *zDropColumn /* Name of column being dropped */
106795 ){
106796 pParse->colNamesSet = 1;
106797 sqlite3NestedParse(pParse,
106798 "SELECT 1 "
106799 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106800 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106801 " AND sql NOT LIKE 'create virtual%%'"
106802 " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %Q)=NULL ",
106803 zDb,
106804 zDb, bTemp, zWhen, zDropColumn
106805 );
106806
106807 if( bTemp==0 ){
106808 sqlite3NestedParse(pParse,
106809 "SELECT 1 "
106810 "FROM temp." DFLT_SCHEMA_TABLE " "
106811 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106812 " AND sql NOT LIKE 'create virtual%%'"
106813 " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %Q)=NULL ",
106814 zDb, zWhen, zDropColumn
106815 );
106816 }
106817 }
106818
106819 /*
@@ -106961,11 +106972,11 @@
106972 sqlite3NestedParse(pParse,
106973 "UPDATE sqlite_temp_schema SET "
106974 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
106975 "tbl_name = "
106976 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
106977 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename',0) "
106978 "THEN %Q ELSE tbl_name END "
106979 "WHERE type IN ('view', 'trigger')"
106980 , zDb, zTabName, zName, zTabName, zDb, zName);
106981 }
106982
@@ -106981,11 +106992,11 @@
106992 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
106993 }
106994 #endif
106995
106996 renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
106997 renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
106998
106999 exit_rename_table:
107000 sqlite3SrcListDelete(db, pSrc);
107001 sqlite3DbFree(db, zName);
107002 db->mDbFlags = savedDbFlags;
@@ -107349,11 +107360,11 @@
107360 zDb, pTab->zName, iCol, zNew, bQuote
107361 );
107362
107363 /* Drop and reload the database schema. */
107364 renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107365 renameTestSchema(pParse, zDb, iSchema==1, "after rename", 0);
107366
107367 exit_rename_column:
107368 sqlite3SrcListDelete(db, pSrc);
107369 sqlite3DbFree(db, zOld);
107370 sqlite3DbFree(db, zNew);
@@ -107773,16 +107784,21 @@
107784 static int renameParseSql(
107785 Parse *p, /* Memory to use for Parse object */
107786 const char *zDb, /* Name of schema SQL belongs to */
107787 sqlite3 *db, /* Database handle */
107788 const char *zSql, /* SQL to parse */
107789 int bTemp, /* True if SQL is from temp schema */
107790 const char *zDropColumn /* Name of column being dropped */
107791 ){
107792 int rc;
107793 char *zErr = 0;
107794
107795 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
107796 if( zDropColumn ){
107797 db->init.bDropColumn = 1;
107798 db->init.azInit = (char**)&zDropColumn;
107799 }
107800
107801 /* Parse the SQL statement passed as the first argument. If no error
107802 ** occurs and the parse does not result in a new table, index or
107803 ** trigger object, the database must be corrupt. */
107804 memset(p, 0, sizeof(Parse));
@@ -107811,10 +107827,11 @@
107827 }
107828 }
107829 #endif
107830
107831 db->init.iDb = 0;
107832 db->init.bDropColumn = 0;
107833 return rc;
107834 }
107835
107836 /*
107837 ** This function edits SQL statement zSql, replacing each token identified
@@ -108112,11 +108129,11 @@
108129 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108130
108131 #ifndef SQLITE_OMIT_AUTHORIZATION
108132 db->xAuth = 0;
108133 #endif
108134 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp, 0);
108135
108136 /* Find tokens that need to be replaced. */
108137 memset(&sWalker, 0, sizeof(Walker));
108138 sWalker.pParse = &sParse;
108139 sWalker.xExprCallback = renameColumnExprCb;
@@ -108154,16 +108171,16 @@
108171 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108172 }
108173 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
108174 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
108175 }
 
108176 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
108177 for(i=0; i<sParse.pNewTable->nCol; i++){
108178 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108179 }
108180 #endif
108181 }
 
108182
108183 for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
108184 for(i=0; i<pFKey->nCol; i++){
108185 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
108186 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
@@ -108316,11 +108333,11 @@
108333 sWalker.pParse = &sParse;
108334 sWalker.xExprCallback = renameTableExprCb;
108335 sWalker.xSelectCallback = renameTableSelectCb;
108336 sWalker.u.pRename = &sCtx;
108337
108338 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, 0);
108339
108340 if( rc==SQLITE_OK ){
108341 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108342 if( sParse.pNewTable ){
108343 Table *pTab = sParse.pNewTable;
@@ -108432,10 +108449,11 @@
108449 ** 1: SQL statement.
108450 ** 2: Object type ("view", "table", "trigger" or "index").
108451 ** 3: Object name.
108452 ** 4: True if object is from temp schema.
108453 ** 5: "when" part of error message.
108454 ** 6: Name of column being dropped, or NULL.
108455 **
108456 ** Unless it finds an error, this function normally returns NULL. However, it
108457 ** returns integer value 1 if:
108458 **
108459 ** * the SQL argument creates a trigger, and
@@ -108450,10 +108468,11 @@
108468 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108469 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108470 int bTemp = sqlite3_value_int(argv[4]);
108471 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108472 char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
108473 char const *zDropColumn = (const char*)sqlite3_value_text(argv[6]);
108474
108475 #ifndef SQLITE_OMIT_AUTHORIZATION
108476 sqlite3_xauth xAuth = db->xAuth;
108477 db->xAuth = 0;
108478 #endif
@@ -108460,11 +108479,11 @@
108479
108480 UNUSED_PARAMETER(NotUsed);
108481 if( zDb && zInput ){
108482 int rc;
108483 Parse sParse;
108484 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, zDropColumn);
108485 if( rc==SQLITE_OK ){
108486 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108487 NameContext sNC;
108488 memset(&sNC, 0, sizeof(sNC));
108489 sNC.pParse = &sParse;
@@ -108528,11 +108547,11 @@
108547 sqlite3_xauth xAuth = db->xAuth;
108548 db->xAuth = 0;
108549 #endif
108550
108551 UNUSED_PARAMETER(NotUsed);
108552 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0);
108553 if( rc!=SQLITE_OK ) goto drop_column_done;
108554 pTab = sParse.pNewTable;
108555 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108556 /* This can happen if the sqlite_schema table is corrupt */
108557 rc = SQLITE_CORRUPT_BKPT;
@@ -108621,21 +108640,21 @@
108640
108641 /* Edit the sqlite_schema table */
108642 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108643 assert( iDb>=0 );
108644 zDb = db->aDb[iDb].zDbSName;
108645 renameTestSchema(pParse, zDb, iDb==1, "", 0);
108646 sqlite3NestedParse(pParse,
108647 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108648 "sql = sqlite_drop_column(%d, sql, %d) "
108649 "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108650 , zDb, iDb, iCol, pTab->zName
108651 );
108652
108653 /* Drop and reload the database schema. */
108654 renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108655 renameTestSchema(pParse, zDb, iDb==1, "after drop column", zCol);
108656
108657 /* Edit rows of table on disk */
108658 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108659 int i;
108660 int addr;
@@ -108691,11 +108710,11 @@
108710 */
108711 SQLITE_PRIVATE void sqlite3AlterFunctions(void){
108712 static FuncDef aAlterTableFuncs[] = {
108713 INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
108714 INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
108715 INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
108716 INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
108717 };
108718 sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
108719 }
108720 #endif /* SQLITE_ALTER_TABLE */
@@ -135116,10 +135135,11 @@
135135
135136 /* Restriction (23) */
135137 if( (p->selFlags & SF_Recursive) ) return 0;
135138
135139 if( pSrc->nSrc>1 ){
135140 if( pParse->nSelect>500 ) return 0;
135141 aCsrMap = sqlite3DbMallocZero(db, pParse->nTab*sizeof(int));
135142 }
135143 }
135144
135145 /***** If we reach this point, flattening is permitted. *****/
@@ -135192,10 +135212,11 @@
135212 p->op = TK_ALL;
135213 pSubitem->pTab = pItemTab;
135214 if( pNew==0 ){
135215 p->pPrior = pPrior;
135216 }else{
135217 pNew->selId = ++pParse->nSelect;
135218 if( aCsrMap && db->mallocFailed==0 ){
135219 renumberCursors(pParse, pNew, iFrom, aCsrMap);
135220 }
135221 pNew->pPrior = pPrior;
135222 if( pPrior ) pPrior->pNext = pNew;
@@ -229190,11 +229211,11 @@
229211 int nArg, /* Number of args */
229212 sqlite3_value **apUnused /* Function arguments */
229213 ){
229214 assert( nArg==0 );
229215 UNUSED_PARAM2(nArg, apUnused);
229216 sqlite3_result_text(pCtx, "fts5: 2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827", -1, SQLITE_TRANSIENT);
229217 }
229218
229219 /*
229220 ** Return true if zName is the extension on one of the shadow tables used
229221 ** by this module.
@@ -234116,12 +234137,12 @@
234137 }
234138 #endif /* SQLITE_CORE */
234139 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234140
234141 /************** End of stmt.c ************************************************/
234142 #if __LINE__!=234142
234143 #undef SQLITE_SOURCE_ID
234144 #define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50calt2"
234145 #endif
234146 /* Return the source-id for this library */
234147 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234148 /************************** End of sqlite3.c ******************************/
234149
+3 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121121
**
122122
** See also: [sqlite3_libversion()],
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126
-#define SQLITE_VERSION "3.35.0"
127
-#define SQLITE_VERSION_NUMBER 3035000
128
-#define SQLITE_SOURCE_ID "2021-03-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b"
126
+#define SQLITE_VERSION "3.35.2"
127
+#define SQLITE_VERSION_NUMBER 3035002
128
+#define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
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-12 15:10:09 acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.35.2"
127 #define SQLITE_VERSION_NUMBER 3035002
128 #define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

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