Fossil SCM

Update the built-in SQLite to the latest 3.37.0 alpha.

drh 2021-09-22 13:54 trunk
Commit 606dcf08c94e4a142fe21bdcbf813bfe48eaf71db45e9b9a1785ed5c9d3d79a2
3 files changed +229 -77 +257 -137 +1 -1
+229 -77
--- src/shell.c
+++ src/shell.c
@@ -651,23 +651,42 @@
651651
}
652652
return n;
653653
}
654654
655655
/*
656
-** Return true if zFile does not exist or if it is not an ordinary file.
656
+** Return open FILE * if zFile exists, can be opened for read
657
+** and is an ordinary file or a character stream source.
658
+** Otherwise return 0.
657659
*/
660
+static FILE * openChrSource(const char *zFile){
658661
#ifdef _WIN32
659
-# define notNormalFile(X) 0
662
+ struct _stat x = {0};
663
+# define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
664
+ /* On Windows, open first, then check the stream nature. This order
665
+ ** is necessary because _stat() and sibs, when checking a named pipe,
666
+ ** effectively break the pipe as its supplier sees it. */
667
+ FILE *rv = fopen(zFile, "rb");
668
+ if( rv==0 ) return 0;
669
+ if( _fstat(_fileno(rv), &x) != 0
670
+ || !STAT_CHR_SRC(x.st_mode)){
671
+ fclose(rv);
672
+ rv = 0;
673
+ }
674
+ return rv;
660675
#else
661
-static int notNormalFile(const char *zFile){
662
- struct stat x;
663
- int rc;
664
- memset(&x, 0, sizeof(x));
665
- rc = stat(zFile, &x);
666
- return rc || !S_ISREG(x.st_mode);
667
-}
668
-#endif
676
+ struct stat x = {0};
677
+ int rc = stat(zFile, &x);
678
+# define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
679
+ if( rc!=0 ) return 0;
680
+ if( STAT_CHR_SRC(x.st_mode) ){
681
+ return fopen(zFile, "rb");
682
+ }else{
683
+ return 0;
684
+ }
685
+#endif
686
+#undef STAT_CHR_SRC
687
+}
669688
670689
/*
671690
** This routine reads a line of text from FILE in, stores
672691
** the text in memory obtained from malloc() and returns a pointer
673692
** to the text. NULL is returned at end of file, or if malloc()
@@ -2202,10 +2221,15 @@
22022221
**
22032222
** If a non-NULL value is specified for the optional $dir parameter and
22042223
** $path is a relative path, then $path is interpreted relative to $dir.
22052224
** And the paths returned in the "name" column of the table are also
22062225
** relative to directory $dir.
2226
+**
2227
+** Notes on building this extension for Windows:
2228
+** Unless linked statically with the SQLite library, a preprocessor
2229
+** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
2230
+** DLL form of this extension for WIN32. See its use below for details.
22072231
*/
22082232
/* #include "sqlite3ext.h" */
22092233
SQLITE_EXTENSION_INIT1
22102234
#include <stdio.h>
22112235
#include <string.h>
@@ -2355,10 +2379,26 @@
23552379
fileIntervals.HighPart = pFileTime->dwHighDateTime;
23562380
23572381
return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
23582382
}
23592383
2384
+
2385
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
2386
+# /* To allow a standalone DLL, use this next replacement function: */
2387
+# undef sqlite3_win32_utf8_to_unicode
2388
+# define sqlite3_win32_utf8_to_unicode utf8_to_utf16
2389
+#
2390
+LPWSTR utf8_to_utf16(const char *z){
2391
+ int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
2392
+ LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
2393
+ if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
2394
+ return rv;
2395
+ sqlite3_free(rv);
2396
+ return 0;
2397
+}
2398
+#endif
2399
+
23602400
/*
23612401
** This function attempts to normalize the time values found in the stat()
23622402
** buffer to UTC. This is necessary on Win32, where the runtime library
23632403
** appears to return these values as local times.
23642404
*/
@@ -3128,10 +3168,18 @@
31283168
if( rc==SQLITE_OK ){
31293169
rc = fsdirRegister(db);
31303170
}
31313171
return rc;
31323172
}
3173
+
3174
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
3175
+/* To allow a standalone DLL, make test_windirent.c use the same
3176
+ * redefined SQLite API calls as the above extension code does.
3177
+ * Just pull in this .c to accomplish this. As a beneficial side
3178
+ * effect, this extension becomes a single translation unit. */
3179
+# include "test_windirent.c"
3180
+#endif
31333181
31343182
/************************* End ../ext/misc/fileio.c ********************/
31353183
/************************* Begin ../ext/misc/completion.c ******************/
31363184
/*
31373185
** 2017-07-10
@@ -10099,10 +10147,22 @@
1009910147
idxFinalize(&rc, pIdxList);
1010010148
1010110149
*pRc = rc;
1010210150
return 0;
1010310151
}
10152
+
10153
+/* Callback for sqlite3_exec() with query with leading count(*) column.
10154
+ * The first argument is expected to be an int*, referent to be incremented
10155
+ * if that leading column is not exactly '0'.
10156
+ */
10157
+static int countNonzeros(void* pCount, int nc,
10158
+ char* azResults[], char* azColumns[]){
10159
+ if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){
10160
+ *((int *)pCount) += 1;
10161
+ }
10162
+ return 0;
10163
+}
1010410164
1010510165
static int idxCreateFromCons(
1010610166
sqlite3expert *p,
1010710167
IdxScan *pScan,
1010810168
IdxConstraint *pEq,
@@ -10126,30 +10186,57 @@
1012610186
}
1012710187
1012810188
if( rc==SQLITE_OK ){
1012910189
/* Hash the list of columns to come up with a name for the index */
1013010190
const char *zTable = pScan->pTab->zName;
10131
- char *zName; /* Index name */
10132
- int i;
10133
- for(i=0; zCols[i]; i++){
10134
- h += ((h<<3) + zCols[i]);
10135
- }
10136
- zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
10137
- if( zName==0 ){
10191
+ int quoteTable = idxIdentifierRequiresQuotes(zTable);
10192
+ char *zName = 0; /* Index name */
10193
+ int collisions = 0;
10194
+ do{
10195
+ int i;
10196
+ char *zFind;
10197
+ for(i=0; zCols[i]; i++){
10198
+ h += ((h<<3) + zCols[i]);
10199
+ }
10200
+ sqlite3_free(zName);
10201
+ zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
10202
+ if( zName==0 ) break;
10203
+ /* Is is unique among table, view and index names? */
10204
+ zFmt = "SELECT count(*) FROM sqlite_schema WHERE name=%Q"
10205
+ " AND type in ('index','table','view')";
10206
+ zFind = sqlite3_mprintf(zFmt, zName);
10207
+ i = 0;
10208
+ rc = sqlite3_exec(dbm, zFind, countNonzeros, &i, 0);
10209
+ assert(rc==SQLITE_OK);
10210
+ sqlite3_free(zFind);
10211
+ if( i==0 ){
10212
+ collisions = 0;
10213
+ break;
10214
+ }
10215
+ ++collisions;
10216
+ }while( collisions<50 && zName!=0 );
10217
+ if( collisions ){
10218
+ /* This return means "Gave up trying to find a unique index name." */
10219
+ rc = SQLITE_BUSY_TIMEOUT;
10220
+ }else if( zName==0 ){
1013810221
rc = SQLITE_NOMEM;
1013910222
}else{
10140
- if( idxIdentifierRequiresQuotes(zTable) ){
10141
- zFmt = "CREATE INDEX '%q' ON %Q(%s)";
10223
+ if( quoteTable ){
10224
+ zFmt = "CREATE INDEX \"%w\" ON \"%w\"(%s)";
1014210225
}else{
1014310226
zFmt = "CREATE INDEX %s ON %s(%s)";
1014410227
}
1014510228
zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
1014610229
if( !zIdx ){
1014710230
rc = SQLITE_NOMEM;
1014810231
}else{
1014910232
rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
10150
- idxHashAdd(&rc, &p->hIdx, zName, zIdx);
10233
+ if( rc!=SQLITE_OK ){
10234
+ rc = SQLITE_BUSY_TIMEOUT;
10235
+ }else{
10236
+ idxHashAdd(&rc, &p->hIdx, zName, zIdx);
10237
+ }
1015110238
}
1015210239
sqlite3_free(zName);
1015310240
sqlite3_free(zIdx);
1015410241
}
1015510242
}
@@ -11069,10 +11156,14 @@
1106911156
rc = idxProcessTriggers(p, pzErr);
1107011157
1107111158
/* Create candidate indexes within the in-memory database file */
1107211159
if( rc==SQLITE_OK ){
1107311160
rc = idxCreateCandidates(p);
11161
+ }else if ( rc==SQLITE_BUSY_TIMEOUT ){
11162
+ if( pzErr )
11163
+ *pzErr = sqlite3_mprintf("Cannot find a unique index name to propose.");
11164
+ return rc;
1107411165
}
1107511166
1107611167
/* Generate the stat1 data */
1107711168
if( rc==SQLITE_OK ){
1107811169
rc = idxPopulateStat1(p, pzErr);
@@ -12161,11 +12252,11 @@
1216112252
#define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
1216212253
#define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
1216312254
#define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
1216412255
#define SHFLG_CountChanges 0x00000020 /* .changes setting */
1216512256
#define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
12166
-#define SHFLG_HeaderSet 0x00000080 /* .header has been used */
12257
+#define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
1216712258
#define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
1216812259
#define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
1216912260
1217012261
/*
1217112262
** Macros for testing and setting shellFlgs
@@ -20197,11 +20288,11 @@
2019720288
}else{
2019820289
rc = process_input(p);
2019920290
pclose(p->in);
2020020291
}
2020120292
#endif
20202
- }else if( notNormalFile(azArg[1]) || (p->in = fopen(azArg[1], "rb"))==0 ){
20293
+ }else if( (p->in = openChrSource(azArg[1]))==0 ){
2020320294
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
2020420295
rc = 1;
2020520296
}else{
2020620297
rc = process_input(p);
2020720298
fclose(p->in);
@@ -21556,59 +21647,111 @@
2155621647
}
2155721648
p->bSafeMode = p->bSafeModePersist;
2155821649
return rc;
2155921650
}
2156021651
21561
-/*
21562
-** Return TRUE if a semicolon occurs anywhere in the first N characters
21563
-** of string z[].
21564
-*/
21565
-static int line_contains_semicolon(const char *z, int N){
21566
- int i;
21567
- for(i=0; i<N; i++){ if( z[i]==';' ) return 1; }
21568
- return 0;
21569
-}
21570
-
21571
-/*
21572
-** Test to see if a line consists entirely of whitespace.
21573
-*/
21574
-static int _all_whitespace(const char *z){
21575
- for(; *z; z++){
21576
- if( IsSpace(z[0]) ) continue;
21577
- if( *z=='/' && z[1]=='*' ){
21578
- z += 2;
21579
- while( *z && (*z!='*' || z[1]!='/') ){ z++; }
21580
- if( *z==0 ) return 0;
21581
- z++;
21582
- continue;
21583
- }
21584
- if( *z=='-' && z[1]=='-' ){
21585
- z += 2;
21586
- while( *z && *z!='\n' ){ z++; }
21587
- if( *z==0 ) return 1;
21588
- continue;
21589
- }
21590
- return 0;
21591
- }
21592
- return 1;
21652
+/* Line scan result and intermediate states (supporting scan resumption)
21653
+*/
21654
+typedef enum {
21655
+ QSS_HasDark = 1<<CHAR_BIT, QSS_EndingSemi = 2<<CHAR_BIT,
21656
+ QSS_CharMask = (1<<CHAR_BIT)-1, QSS_ScanMask = 3<<CHAR_BIT,
21657
+ QSS_Start = 0
21658
+} QuickScanState;
21659
+#define QSS_SETV(qss, newst) ((newst) | ((qss) & QSS_ScanMask))
21660
+#define QSS_INPLAIN(qss) (((qss)&QSS_CharMask)==QSS_Start)
21661
+#define QSS_PLAINWHITE(qss) (((qss)&~QSS_EndingSemi)==QSS_Start)
21662
+#define QSS_PLAINDARK(qss) (((qss)&~QSS_EndingSemi)==QSS_HasDark)
21663
+#define QSS_SEMITERM(qss) (((qss)&~QSS_HasDark)==QSS_EndingSemi)
21664
+
21665
+/*
21666
+** Scan line for classification to guide shell's handling.
21667
+** The scan is resumable for subsequent lines when prior
21668
+** return values are passed as the 2nd argument.
21669
+*/
21670
+static QuickScanState quickscan(char *zLine, QuickScanState qss){
21671
+ char cin;
21672
+ char cWait = (char)qss; /* intentional narrowing loss */
21673
+ if( cWait==0 ){
21674
+ PlainScan:
21675
+ while( (cin = *zLine++)!=0 ){
21676
+ if( IsSpace(cin) )
21677
+ continue;
21678
+ switch (cin){
21679
+ case '-':
21680
+ if( *zLine!='-' )
21681
+ break;
21682
+ while((cin = *++zLine)!=0 )
21683
+ if( cin=='\n')
21684
+ goto PlainScan;
21685
+ return qss;
21686
+ case ';':
21687
+ qss |= QSS_EndingSemi;
21688
+ continue;
21689
+ case '/':
21690
+ if( *zLine=='*' ){
21691
+ ++zLine;
21692
+ cWait = '*';
21693
+ qss = QSS_SETV(qss, cWait);
21694
+ goto TermScan;
21695
+ }
21696
+ break;
21697
+ case '[':
21698
+ cin = ']';
21699
+ /* fall thru */
21700
+ case '`': case '\'': case '"':
21701
+ cWait = cin;
21702
+ qss = QSS_HasDark | cWait;
21703
+ goto TermScan;
21704
+ default:
21705
+ break;
21706
+ }
21707
+ qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
21708
+ }
21709
+ }else{
21710
+ TermScan:
21711
+ while( (cin = *zLine++)!=0 ){
21712
+ if( cin==cWait ){
21713
+ switch( cWait ){
21714
+ case '*':
21715
+ if( *zLine != '/' )
21716
+ continue;
21717
+ ++zLine;
21718
+ cWait = 0;
21719
+ qss = QSS_SETV(qss, 0);
21720
+ goto PlainScan;
21721
+ case '`': case '\'': case '"':
21722
+ if(*zLine==cWait){
21723
+ ++zLine;
21724
+ continue;
21725
+ }
21726
+ /* fall thru */
21727
+ case ']':
21728
+ cWait = 0;
21729
+ qss = QSS_SETV(qss, 0);
21730
+ goto PlainScan;
21731
+ default: assert(0);
21732
+ }
21733
+ }
21734
+ }
21735
+ }
21736
+ return qss;
2159321737
}
2159421738
2159521739
/*
2159621740
** Return TRUE if the line typed in is an SQL command terminator other
2159721741
** than a semi-colon. The SQL Server style "go" command is understood
2159821742
** as is the Oracle "/".
2159921743
*/
21600
-static int line_is_command_terminator(const char *zLine){
21744
+static int line_is_command_terminator(char *zLine){
2160121745
while( IsSpace(zLine[0]) ){ zLine++; };
21602
- if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
21603
- return 1; /* Oracle */
21604
- }
21605
- if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
21606
- && _all_whitespace(&zLine[2]) ){
21607
- return 1; /* SQL Server */
21608
- }
21609
- return 0;
21746
+ if( zLine[0]=='/' )
21747
+ zLine += 1; /* Oracle */
21748
+ else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
21749
+ zLine += 2; /* SQL Server */
21750
+ else
21751
+ return 0;
21752
+ return quickscan(zLine,QSS_Start)==QSS_Start;
2161021753
}
2161121754
2161221755
/*
2161321756
** We need a default sqlite3_complete() implementation to use in case
2161421757
** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -21661,12 +21804,15 @@
2166121804
}else{
2166221805
utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
2166321806
}
2166421807
return 1;
2166521808
}else if( ShellHasFlag(p, SHFLG_CountChanges) ){
21666
- raw_printf(p->out, "changes: %3lld total_changes: %lld\n",
21809
+ char zLineBuf[2000];
21810
+ sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
21811
+ "changes: %lld total_changes: %lld",
2166721812
sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
21813
+ raw_printf(p->out, "%s\n", zLineBuf);
2166821814
}
2166921815
return 0;
2167021816
}
2167121817
2167221818
@@ -21683,14 +21829,14 @@
2168321829
char *zLine = 0; /* A single input line */
2168421830
char *zSql = 0; /* Accumulated SQL text */
2168521831
int nLine; /* Length of current line */
2168621832
int nSql = 0; /* Bytes of zSql[] used */
2168721833
int nAlloc = 0; /* Allocated zSql[] space */
21688
- int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
2168921834
int rc; /* Error code */
2169021835
int errCnt = 0; /* Number of errors seen */
2169121836
int startline = 0; /* Line number for start of current input */
21837
+ QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
2169221838
2169321839
p->lineno = 0;
2169421840
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
2169521841
fflush(p->out);
2169621842
zLine = one_input_line(p->in, zLine, nSql>0);
@@ -21702,12 +21848,20 @@
2170221848
if( seenInterrupt ){
2170321849
if( p->in!=0 ) break;
2170421850
seenInterrupt = 0;
2170521851
}
2170621852
p->lineno++;
21707
- if( nSql==0 && _all_whitespace(zLine) ){
21708
- if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
21853
+ if( QSS_INPLAIN(qss)
21854
+ && line_is_command_terminator(zLine)
21855
+ && line_is_complete(zSql, nSql) ){
21856
+ memcpy(zLine,";",2);
21857
+ }
21858
+ qss = quickscan(zLine, qss);
21859
+ if( QSS_PLAINWHITE(qss) && nSql==0 ){
21860
+ if( ShellHasFlag(p, SHFLG_Echo) )
21861
+ printf("%s\n", zLine);
21862
+ /* Just swallow leading whitespace */
2170921863
continue;
2171021864
}
2171121865
if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
2171221866
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
2171321867
if( zLine[0]=='.' ){
@@ -21718,20 +21872,17 @@
2171821872
errCnt++;
2171921873
}
2172021874
}
2172121875
continue;
2172221876
}
21723
- if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
21724
- memcpy(zLine,";",2);
21725
- }
2172621877
nLine = strlen30(zLine);
2172721878
if( nSql+nLine+2>=nAlloc ){
21728
- nAlloc = nSql+nLine+100;
21879
+ /* Grow buffer by half-again increments when big. */
21880
+ nAlloc = nSql+(nSql>>1)+nLine+100;
2172921881
zSql = realloc(zSql, nAlloc);
2173021882
if( zSql==0 ) shell_out_of_memory();
2173121883
}
21732
- nSqlPrior = nSql;
2173321884
if( nSql==0 ){
2173421885
int i;
2173521886
for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
2173621887
assert( nAlloc>0 && zSql!=0 );
2173721888
memcpy(zSql, zLine+i, nLine+1-i);
@@ -21740,27 +21891,26 @@
2174021891
}else{
2174121892
zSql[nSql++] = '\n';
2174221893
memcpy(zSql+nSql, zLine, nLine+1);
2174321894
nSql += nLine;
2174421895
}
21745
- if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
21746
- && sqlite3_complete(zSql) ){
21896
+ if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
2174721897
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2174821898
nSql = 0;
2174921899
if( p->outCount ){
2175021900
output_reset(p);
2175121901
p->outCount = 0;
2175221902
}else{
2175321903
clearTempFile(p);
2175421904
}
2175521905
p->bSafeMode = p->bSafeModePersist;
21756
- }else if( nSql && _all_whitespace(zSql) ){
21906
+ }else if( nSql && QSS_PLAINWHITE(qss) ){
2175721907
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
2175821908
nSql = 0;
2175921909
}
2176021910
}
21761
- if( nSql && !_all_whitespace(zSql) ){
21911
+ if( nSql && QSS_PLAINDARK(qss) ){
2176221912
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2176321913
}
2176421914
free(zSql);
2176521915
free(zLine);
2176621916
return errCnt>0;
@@ -22399,12 +22549,14 @@
2239922549
}else if( strcmp(z,"-nullvalue")==0 ){
2240022550
sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
2240122551
"%s",cmdline_option_value(argc,argv,++i));
2240222552
}else if( strcmp(z,"-header")==0 ){
2240322553
data.showHeader = 1;
22404
- }else if( strcmp(z,"-noheader")==0 ){
22554
+ ShellSetFlag(&data, SHFLG_HeaderSet);
22555
+ }else if( strcmp(z,"-noheader")==0 ){
2240522556
data.showHeader = 0;
22557
+ ShellSetFlag(&data, SHFLG_HeaderSet);
2240622558
}else if( strcmp(z,"-echo")==0 ){
2240722559
ShellSetFlag(&data, SHFLG_Echo);
2240822560
}else if( strcmp(z,"-eqp")==0 ){
2240922561
data.autoEQP = AUTOEQP_on;
2241022562
}else if( strcmp(z,"-eqpfull")==0 ){
2241122563
--- src/shell.c
+++ src/shell.c
@@ -651,23 +651,42 @@
651 }
652 return n;
653 }
654
655 /*
656 ** Return true if zFile does not exist or if it is not an ordinary file.
 
 
657 */
 
658 #ifdef _WIN32
659 # define notNormalFile(X) 0
 
 
 
 
 
 
 
 
 
 
 
 
660 #else
661 static int notNormalFile(const char *zFile){
662 struct stat x;
663 int rc;
664 memset(&x, 0, sizeof(x));
665 rc = stat(zFile, &x);
666 return rc || !S_ISREG(x.st_mode);
667 }
668 #endif
 
 
 
 
669
670 /*
671 ** This routine reads a line of text from FILE in, stores
672 ** the text in memory obtained from malloc() and returns a pointer
673 ** to the text. NULL is returned at end of file, or if malloc()
@@ -2202,10 +2221,15 @@
2202 **
2203 ** If a non-NULL value is specified for the optional $dir parameter and
2204 ** $path is a relative path, then $path is interpreted relative to $dir.
2205 ** And the paths returned in the "name" column of the table are also
2206 ** relative to directory $dir.
 
 
 
 
 
2207 */
2208 /* #include "sqlite3ext.h" */
2209 SQLITE_EXTENSION_INIT1
2210 #include <stdio.h>
2211 #include <string.h>
@@ -2355,10 +2379,26 @@
2355 fileIntervals.HighPart = pFileTime->dwHighDateTime;
2356
2357 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2358 }
2359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2360 /*
2361 ** This function attempts to normalize the time values found in the stat()
2362 ** buffer to UTC. This is necessary on Win32, where the runtime library
2363 ** appears to return these values as local times.
2364 */
@@ -3128,10 +3168,18 @@
3128 if( rc==SQLITE_OK ){
3129 rc = fsdirRegister(db);
3130 }
3131 return rc;
3132 }
 
 
 
 
 
 
 
 
3133
3134 /************************* End ../ext/misc/fileio.c ********************/
3135 /************************* Begin ../ext/misc/completion.c ******************/
3136 /*
3137 ** 2017-07-10
@@ -10099,10 +10147,22 @@
10099 idxFinalize(&rc, pIdxList);
10100
10101 *pRc = rc;
10102 return 0;
10103 }
 
 
 
 
 
 
 
 
 
 
 
 
10104
10105 static int idxCreateFromCons(
10106 sqlite3expert *p,
10107 IdxScan *pScan,
10108 IdxConstraint *pEq,
@@ -10126,30 +10186,57 @@
10126 }
10127
10128 if( rc==SQLITE_OK ){
10129 /* Hash the list of columns to come up with a name for the index */
10130 const char *zTable = pScan->pTab->zName;
10131 char *zName; /* Index name */
10132 int i;
10133 for(i=0; zCols[i]; i++){
10134 h += ((h<<3) + zCols[i]);
10135 }
10136 zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
10137 if( zName==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10138 rc = SQLITE_NOMEM;
10139 }else{
10140 if( idxIdentifierRequiresQuotes(zTable) ){
10141 zFmt = "CREATE INDEX '%q' ON %Q(%s)";
10142 }else{
10143 zFmt = "CREATE INDEX %s ON %s(%s)";
10144 }
10145 zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
10146 if( !zIdx ){
10147 rc = SQLITE_NOMEM;
10148 }else{
10149 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
10150 idxHashAdd(&rc, &p->hIdx, zName, zIdx);
 
 
 
 
10151 }
10152 sqlite3_free(zName);
10153 sqlite3_free(zIdx);
10154 }
10155 }
@@ -11069,10 +11156,14 @@
11069 rc = idxProcessTriggers(p, pzErr);
11070
11071 /* Create candidate indexes within the in-memory database file */
11072 if( rc==SQLITE_OK ){
11073 rc = idxCreateCandidates(p);
 
 
 
 
11074 }
11075
11076 /* Generate the stat1 data */
11077 if( rc==SQLITE_OK ){
11078 rc = idxPopulateStat1(p, pzErr);
@@ -12161,11 +12252,11 @@
12161 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
12162 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
12163 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
12164 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
12165 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
12166 #define SHFLG_HeaderSet 0x00000080 /* .header has been used */
12167 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
12168 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
12169
12170 /*
12171 ** Macros for testing and setting shellFlgs
@@ -20197,11 +20288,11 @@
20197 }else{
20198 rc = process_input(p);
20199 pclose(p->in);
20200 }
20201 #endif
20202 }else if( notNormalFile(azArg[1]) || (p->in = fopen(azArg[1], "rb"))==0 ){
20203 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
20204 rc = 1;
20205 }else{
20206 rc = process_input(p);
20207 fclose(p->in);
@@ -21556,59 +21647,111 @@
21556 }
21557 p->bSafeMode = p->bSafeModePersist;
21558 return rc;
21559 }
21560
21561 /*
21562 ** Return TRUE if a semicolon occurs anywhere in the first N characters
21563 ** of string z[].
21564 */
21565 static int line_contains_semicolon(const char *z, int N){
21566 int i;
21567 for(i=0; i<N; i++){ if( z[i]==';' ) return 1; }
21568 return 0;
21569 }
21570
21571 /*
21572 ** Test to see if a line consists entirely of whitespace.
21573 */
21574 static int _all_whitespace(const char *z){
21575 for(; *z; z++){
21576 if( IsSpace(z[0]) ) continue;
21577 if( *z=='/' && z[1]=='*' ){
21578 z += 2;
21579 while( *z && (*z!='*' || z[1]!='/') ){ z++; }
21580 if( *z==0 ) return 0;
21581 z++;
21582 continue;
21583 }
21584 if( *z=='-' && z[1]=='-' ){
21585 z += 2;
21586 while( *z && *z!='\n' ){ z++; }
21587 if( *z==0 ) return 1;
21588 continue;
21589 }
21590 return 0;
21591 }
21592 return 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21593 }
21594
21595 /*
21596 ** Return TRUE if the line typed in is an SQL command terminator other
21597 ** than a semi-colon. The SQL Server style "go" command is understood
21598 ** as is the Oracle "/".
21599 */
21600 static int line_is_command_terminator(const char *zLine){
21601 while( IsSpace(zLine[0]) ){ zLine++; };
21602 if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
21603 return 1; /* Oracle */
21604 }
21605 if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
21606 && _all_whitespace(&zLine[2]) ){
21607 return 1; /* SQL Server */
21608 }
21609 return 0;
21610 }
21611
21612 /*
21613 ** We need a default sqlite3_complete() implementation to use in case
21614 ** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -21661,12 +21804,15 @@
21661 }else{
21662 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
21663 }
21664 return 1;
21665 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
21666 raw_printf(p->out, "changes: %3lld total_changes: %lld\n",
 
 
21667 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
 
21668 }
21669 return 0;
21670 }
21671
21672
@@ -21683,14 +21829,14 @@
21683 char *zLine = 0; /* A single input line */
21684 char *zSql = 0; /* Accumulated SQL text */
21685 int nLine; /* Length of current line */
21686 int nSql = 0; /* Bytes of zSql[] used */
21687 int nAlloc = 0; /* Allocated zSql[] space */
21688 int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
21689 int rc; /* Error code */
21690 int errCnt = 0; /* Number of errors seen */
21691 int startline = 0; /* Line number for start of current input */
 
21692
21693 p->lineno = 0;
21694 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
21695 fflush(p->out);
21696 zLine = one_input_line(p->in, zLine, nSql>0);
@@ -21702,12 +21848,20 @@
21702 if( seenInterrupt ){
21703 if( p->in!=0 ) break;
21704 seenInterrupt = 0;
21705 }
21706 p->lineno++;
21707 if( nSql==0 && _all_whitespace(zLine) ){
21708 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
 
 
 
 
 
 
 
 
21709 continue;
21710 }
21711 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
21712 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
21713 if( zLine[0]=='.' ){
@@ -21718,20 +21872,17 @@
21718 errCnt++;
21719 }
21720 }
21721 continue;
21722 }
21723 if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
21724 memcpy(zLine,";",2);
21725 }
21726 nLine = strlen30(zLine);
21727 if( nSql+nLine+2>=nAlloc ){
21728 nAlloc = nSql+nLine+100;
 
21729 zSql = realloc(zSql, nAlloc);
21730 if( zSql==0 ) shell_out_of_memory();
21731 }
21732 nSqlPrior = nSql;
21733 if( nSql==0 ){
21734 int i;
21735 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
21736 assert( nAlloc>0 && zSql!=0 );
21737 memcpy(zSql, zLine+i, nLine+1-i);
@@ -21740,27 +21891,26 @@
21740 }else{
21741 zSql[nSql++] = '\n';
21742 memcpy(zSql+nSql, zLine, nLine+1);
21743 nSql += nLine;
21744 }
21745 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
21746 && sqlite3_complete(zSql) ){
21747 errCnt += runOneSqlLine(p, zSql, p->in, startline);
21748 nSql = 0;
21749 if( p->outCount ){
21750 output_reset(p);
21751 p->outCount = 0;
21752 }else{
21753 clearTempFile(p);
21754 }
21755 p->bSafeMode = p->bSafeModePersist;
21756 }else if( nSql && _all_whitespace(zSql) ){
21757 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
21758 nSql = 0;
21759 }
21760 }
21761 if( nSql && !_all_whitespace(zSql) ){
21762 errCnt += runOneSqlLine(p, zSql, p->in, startline);
21763 }
21764 free(zSql);
21765 free(zLine);
21766 return errCnt>0;
@@ -22399,12 +22549,14 @@
22399 }else if( strcmp(z,"-nullvalue")==0 ){
22400 sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
22401 "%s",cmdline_option_value(argc,argv,++i));
22402 }else if( strcmp(z,"-header")==0 ){
22403 data.showHeader = 1;
22404 }else if( strcmp(z,"-noheader")==0 ){
 
22405 data.showHeader = 0;
 
22406 }else if( strcmp(z,"-echo")==0 ){
22407 ShellSetFlag(&data, SHFLG_Echo);
22408 }else if( strcmp(z,"-eqp")==0 ){
22409 data.autoEQP = AUTOEQP_on;
22410 }else if( strcmp(z,"-eqpfull")==0 ){
22411
--- src/shell.c
+++ src/shell.c
@@ -651,23 +651,42 @@
651 }
652 return n;
653 }
654
655 /*
656 ** Return open FILE * if zFile exists, can be opened for read
657 ** and is an ordinary file or a character stream source.
658 ** Otherwise return 0.
659 */
660 static FILE * openChrSource(const char *zFile){
661 #ifdef _WIN32
662 struct _stat x = {0};
663 # define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
664 /* On Windows, open first, then check the stream nature. This order
665 ** is necessary because _stat() and sibs, when checking a named pipe,
666 ** effectively break the pipe as its supplier sees it. */
667 FILE *rv = fopen(zFile, "rb");
668 if( rv==0 ) return 0;
669 if( _fstat(_fileno(rv), &x) != 0
670 || !STAT_CHR_SRC(x.st_mode)){
671 fclose(rv);
672 rv = 0;
673 }
674 return rv;
675 #else
676 struct stat x = {0};
677 int rc = stat(zFile, &x);
678 # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
679 if( rc!=0 ) return 0;
680 if( STAT_CHR_SRC(x.st_mode) ){
681 return fopen(zFile, "rb");
682 }else{
683 return 0;
684 }
685 #endif
686 #undef STAT_CHR_SRC
687 }
688
689 /*
690 ** This routine reads a line of text from FILE in, stores
691 ** the text in memory obtained from malloc() and returns a pointer
692 ** to the text. NULL is returned at end of file, or if malloc()
@@ -2202,10 +2221,15 @@
2221 **
2222 ** If a non-NULL value is specified for the optional $dir parameter and
2223 ** $path is a relative path, then $path is interpreted relative to $dir.
2224 ** And the paths returned in the "name" column of the table are also
2225 ** relative to directory $dir.
2226 **
2227 ** Notes on building this extension for Windows:
2228 ** Unless linked statically with the SQLite library, a preprocessor
2229 ** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
2230 ** DLL form of this extension for WIN32. See its use below for details.
2231 */
2232 /* #include "sqlite3ext.h" */
2233 SQLITE_EXTENSION_INIT1
2234 #include <stdio.h>
2235 #include <string.h>
@@ -2355,10 +2379,26 @@
2379 fileIntervals.HighPart = pFileTime->dwHighDateTime;
2380
2381 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2382 }
2383
2384
2385 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
2386 # /* To allow a standalone DLL, use this next replacement function: */
2387 # undef sqlite3_win32_utf8_to_unicode
2388 # define sqlite3_win32_utf8_to_unicode utf8_to_utf16
2389 #
2390 LPWSTR utf8_to_utf16(const char *z){
2391 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
2392 LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
2393 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
2394 return rv;
2395 sqlite3_free(rv);
2396 return 0;
2397 }
2398 #endif
2399
2400 /*
2401 ** This function attempts to normalize the time values found in the stat()
2402 ** buffer to UTC. This is necessary on Win32, where the runtime library
2403 ** appears to return these values as local times.
2404 */
@@ -3128,10 +3168,18 @@
3168 if( rc==SQLITE_OK ){
3169 rc = fsdirRegister(db);
3170 }
3171 return rc;
3172 }
3173
3174 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
3175 /* To allow a standalone DLL, make test_windirent.c use the same
3176 * redefined SQLite API calls as the above extension code does.
3177 * Just pull in this .c to accomplish this. As a beneficial side
3178 * effect, this extension becomes a single translation unit. */
3179 # include "test_windirent.c"
3180 #endif
3181
3182 /************************* End ../ext/misc/fileio.c ********************/
3183 /************************* Begin ../ext/misc/completion.c ******************/
3184 /*
3185 ** 2017-07-10
@@ -10099,10 +10147,22 @@
10147 idxFinalize(&rc, pIdxList);
10148
10149 *pRc = rc;
10150 return 0;
10151 }
10152
10153 /* Callback for sqlite3_exec() with query with leading count(*) column.
10154 * The first argument is expected to be an int*, referent to be incremented
10155 * if that leading column is not exactly '0'.
10156 */
10157 static int countNonzeros(void* pCount, int nc,
10158 char* azResults[], char* azColumns[]){
10159 if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){
10160 *((int *)pCount) += 1;
10161 }
10162 return 0;
10163 }
10164
10165 static int idxCreateFromCons(
10166 sqlite3expert *p,
10167 IdxScan *pScan,
10168 IdxConstraint *pEq,
@@ -10126,30 +10186,57 @@
10186 }
10187
10188 if( rc==SQLITE_OK ){
10189 /* Hash the list of columns to come up with a name for the index */
10190 const char *zTable = pScan->pTab->zName;
10191 int quoteTable = idxIdentifierRequiresQuotes(zTable);
10192 char *zName = 0; /* Index name */
10193 int collisions = 0;
10194 do{
10195 int i;
10196 char *zFind;
10197 for(i=0; zCols[i]; i++){
10198 h += ((h<<3) + zCols[i]);
10199 }
10200 sqlite3_free(zName);
10201 zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
10202 if( zName==0 ) break;
10203 /* Is is unique among table, view and index names? */
10204 zFmt = "SELECT count(*) FROM sqlite_schema WHERE name=%Q"
10205 " AND type in ('index','table','view')";
10206 zFind = sqlite3_mprintf(zFmt, zName);
10207 i = 0;
10208 rc = sqlite3_exec(dbm, zFind, countNonzeros, &i, 0);
10209 assert(rc==SQLITE_OK);
10210 sqlite3_free(zFind);
10211 if( i==0 ){
10212 collisions = 0;
10213 break;
10214 }
10215 ++collisions;
10216 }while( collisions<50 && zName!=0 );
10217 if( collisions ){
10218 /* This return means "Gave up trying to find a unique index name." */
10219 rc = SQLITE_BUSY_TIMEOUT;
10220 }else if( zName==0 ){
10221 rc = SQLITE_NOMEM;
10222 }else{
10223 if( quoteTable ){
10224 zFmt = "CREATE INDEX \"%w\" ON \"%w\"(%s)";
10225 }else{
10226 zFmt = "CREATE INDEX %s ON %s(%s)";
10227 }
10228 zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
10229 if( !zIdx ){
10230 rc = SQLITE_NOMEM;
10231 }else{
10232 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
10233 if( rc!=SQLITE_OK ){
10234 rc = SQLITE_BUSY_TIMEOUT;
10235 }else{
10236 idxHashAdd(&rc, &p->hIdx, zName, zIdx);
10237 }
10238 }
10239 sqlite3_free(zName);
10240 sqlite3_free(zIdx);
10241 }
10242 }
@@ -11069,10 +11156,14 @@
11156 rc = idxProcessTriggers(p, pzErr);
11157
11158 /* Create candidate indexes within the in-memory database file */
11159 if( rc==SQLITE_OK ){
11160 rc = idxCreateCandidates(p);
11161 }else if ( rc==SQLITE_BUSY_TIMEOUT ){
11162 if( pzErr )
11163 *pzErr = sqlite3_mprintf("Cannot find a unique index name to propose.");
11164 return rc;
11165 }
11166
11167 /* Generate the stat1 data */
11168 if( rc==SQLITE_OK ){
11169 rc = idxPopulateStat1(p, pzErr);
@@ -12161,11 +12252,11 @@
12252 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
12253 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
12254 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
12255 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
12256 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
12257 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
12258 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
12259 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
12260
12261 /*
12262 ** Macros for testing and setting shellFlgs
@@ -20197,11 +20288,11 @@
20288 }else{
20289 rc = process_input(p);
20290 pclose(p->in);
20291 }
20292 #endif
20293 }else if( (p->in = openChrSource(azArg[1]))==0 ){
20294 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
20295 rc = 1;
20296 }else{
20297 rc = process_input(p);
20298 fclose(p->in);
@@ -21556,59 +21647,111 @@
21647 }
21648 p->bSafeMode = p->bSafeModePersist;
21649 return rc;
21650 }
21651
21652 /* Line scan result and intermediate states (supporting scan resumption)
21653 */
21654 typedef enum {
21655 QSS_HasDark = 1<<CHAR_BIT, QSS_EndingSemi = 2<<CHAR_BIT,
21656 QSS_CharMask = (1<<CHAR_BIT)-1, QSS_ScanMask = 3<<CHAR_BIT,
21657 QSS_Start = 0
21658 } QuickScanState;
21659 #define QSS_SETV(qss, newst) ((newst) | ((qss) & QSS_ScanMask))
21660 #define QSS_INPLAIN(qss) (((qss)&QSS_CharMask)==QSS_Start)
21661 #define QSS_PLAINWHITE(qss) (((qss)&~QSS_EndingSemi)==QSS_Start)
21662 #define QSS_PLAINDARK(qss) (((qss)&~QSS_EndingSemi)==QSS_HasDark)
21663 #define QSS_SEMITERM(qss) (((qss)&~QSS_HasDark)==QSS_EndingSemi)
21664
21665 /*
21666 ** Scan line for classification to guide shell's handling.
21667 ** The scan is resumable for subsequent lines when prior
21668 ** return values are passed as the 2nd argument.
21669 */
21670 static QuickScanState quickscan(char *zLine, QuickScanState qss){
21671 char cin;
21672 char cWait = (char)qss; /* intentional narrowing loss */
21673 if( cWait==0 ){
21674 PlainScan:
21675 while( (cin = *zLine++)!=0 ){
21676 if( IsSpace(cin) )
21677 continue;
21678 switch (cin){
21679 case '-':
21680 if( *zLine!='-' )
21681 break;
21682 while((cin = *++zLine)!=0 )
21683 if( cin=='\n')
21684 goto PlainScan;
21685 return qss;
21686 case ';':
21687 qss |= QSS_EndingSemi;
21688 continue;
21689 case '/':
21690 if( *zLine=='*' ){
21691 ++zLine;
21692 cWait = '*';
21693 qss = QSS_SETV(qss, cWait);
21694 goto TermScan;
21695 }
21696 break;
21697 case '[':
21698 cin = ']';
21699 /* fall thru */
21700 case '`': case '\'': case '"':
21701 cWait = cin;
21702 qss = QSS_HasDark | cWait;
21703 goto TermScan;
21704 default:
21705 break;
21706 }
21707 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
21708 }
21709 }else{
21710 TermScan:
21711 while( (cin = *zLine++)!=0 ){
21712 if( cin==cWait ){
21713 switch( cWait ){
21714 case '*':
21715 if( *zLine != '/' )
21716 continue;
21717 ++zLine;
21718 cWait = 0;
21719 qss = QSS_SETV(qss, 0);
21720 goto PlainScan;
21721 case '`': case '\'': case '"':
21722 if(*zLine==cWait){
21723 ++zLine;
21724 continue;
21725 }
21726 /* fall thru */
21727 case ']':
21728 cWait = 0;
21729 qss = QSS_SETV(qss, 0);
21730 goto PlainScan;
21731 default: assert(0);
21732 }
21733 }
21734 }
21735 }
21736 return qss;
21737 }
21738
21739 /*
21740 ** Return TRUE if the line typed in is an SQL command terminator other
21741 ** than a semi-colon. The SQL Server style "go" command is understood
21742 ** as is the Oracle "/".
21743 */
21744 static int line_is_command_terminator(char *zLine){
21745 while( IsSpace(zLine[0]) ){ zLine++; };
21746 if( zLine[0]=='/' )
21747 zLine += 1; /* Oracle */
21748 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
21749 zLine += 2; /* SQL Server */
21750 else
21751 return 0;
21752 return quickscan(zLine,QSS_Start)==QSS_Start;
 
21753 }
21754
21755 /*
21756 ** We need a default sqlite3_complete() implementation to use in case
21757 ** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -21661,12 +21804,15 @@
21804 }else{
21805 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
21806 }
21807 return 1;
21808 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
21809 char zLineBuf[2000];
21810 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
21811 "changes: %lld total_changes: %lld",
21812 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
21813 raw_printf(p->out, "%s\n", zLineBuf);
21814 }
21815 return 0;
21816 }
21817
21818
@@ -21683,14 +21829,14 @@
21829 char *zLine = 0; /* A single input line */
21830 char *zSql = 0; /* Accumulated SQL text */
21831 int nLine; /* Length of current line */
21832 int nSql = 0; /* Bytes of zSql[] used */
21833 int nAlloc = 0; /* Allocated zSql[] space */
 
21834 int rc; /* Error code */
21835 int errCnt = 0; /* Number of errors seen */
21836 int startline = 0; /* Line number for start of current input */
21837 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
21838
21839 p->lineno = 0;
21840 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
21841 fflush(p->out);
21842 zLine = one_input_line(p->in, zLine, nSql>0);
@@ -21702,12 +21848,20 @@
21848 if( seenInterrupt ){
21849 if( p->in!=0 ) break;
21850 seenInterrupt = 0;
21851 }
21852 p->lineno++;
21853 if( QSS_INPLAIN(qss)
21854 && line_is_command_terminator(zLine)
21855 && line_is_complete(zSql, nSql) ){
21856 memcpy(zLine,";",2);
21857 }
21858 qss = quickscan(zLine, qss);
21859 if( QSS_PLAINWHITE(qss) && nSql==0 ){
21860 if( ShellHasFlag(p, SHFLG_Echo) )
21861 printf("%s\n", zLine);
21862 /* Just swallow leading whitespace */
21863 continue;
21864 }
21865 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
21866 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
21867 if( zLine[0]=='.' ){
@@ -21718,20 +21872,17 @@
21872 errCnt++;
21873 }
21874 }
21875 continue;
21876 }
 
 
 
21877 nLine = strlen30(zLine);
21878 if( nSql+nLine+2>=nAlloc ){
21879 /* Grow buffer by half-again increments when big. */
21880 nAlloc = nSql+(nSql>>1)+nLine+100;
21881 zSql = realloc(zSql, nAlloc);
21882 if( zSql==0 ) shell_out_of_memory();
21883 }
 
21884 if( nSql==0 ){
21885 int i;
21886 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
21887 assert( nAlloc>0 && zSql!=0 );
21888 memcpy(zSql, zLine+i, nLine+1-i);
@@ -21740,27 +21891,26 @@
21891 }else{
21892 zSql[nSql++] = '\n';
21893 memcpy(zSql+nSql, zLine, nLine+1);
21894 nSql += nLine;
21895 }
21896 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
 
21897 errCnt += runOneSqlLine(p, zSql, p->in, startline);
21898 nSql = 0;
21899 if( p->outCount ){
21900 output_reset(p);
21901 p->outCount = 0;
21902 }else{
21903 clearTempFile(p);
21904 }
21905 p->bSafeMode = p->bSafeModePersist;
21906 }else if( nSql && QSS_PLAINWHITE(qss) ){
21907 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
21908 nSql = 0;
21909 }
21910 }
21911 if( nSql && QSS_PLAINDARK(qss) ){
21912 errCnt += runOneSqlLine(p, zSql, p->in, startline);
21913 }
21914 free(zSql);
21915 free(zLine);
21916 return errCnt>0;
@@ -22399,12 +22549,14 @@
22549 }else if( strcmp(z,"-nullvalue")==0 ){
22550 sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
22551 "%s",cmdline_option_value(argc,argv,++i));
22552 }else if( strcmp(z,"-header")==0 ){
22553 data.showHeader = 1;
22554 ShellSetFlag(&data, SHFLG_HeaderSet);
22555 }else if( strcmp(z,"-noheader")==0 ){
22556 data.showHeader = 0;
22557 ShellSetFlag(&data, SHFLG_HeaderSet);
22558 }else if( strcmp(z,"-echo")==0 ){
22559 ShellSetFlag(&data, SHFLG_Echo);
22560 }else if( strcmp(z,"-eqp")==0 ){
22561 data.autoEQP = AUTOEQP_on;
22562 }else if( strcmp(z,"-eqpfull")==0 ){
22563
+257 -137
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.37.0"
456456
#define SQLITE_VERSION_NUMBER 3037000
457
-#define SQLITE_SOURCE_ID "2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1"
457
+#define SQLITE_SOURCE_ID "2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -19842,11 +19842,11 @@
1984219842
#ifdef SQLITE_TEST
1984319843
SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char*);
1984419844
#endif
1984519845
1984619846
#ifdef SQLITE_OMIT_VIRTUALTABLE
19847
-# define sqlite3VtabClear(Y)
19847
+# define sqlite3VtabClear(D,T)
1984819848
# define sqlite3VtabSync(X,Y) SQLITE_OK
1984919849
# define sqlite3VtabRollback(X)
1985019850
# define sqlite3VtabCommit(X)
1985119851
# define sqlite3VtabInSync(db) 0
1985219852
# define sqlite3VtabLock(X)
@@ -48856,11 +48856,11 @@
4885648856
MemStore *p = 0;
4885748857
int szName;
4885848858
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4885948859
return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
4886048860
}
48861
- memset(pFile, 0, sizeof(*p));
48861
+ memset(pFile, 0, sizeof(*pFile));
4886248862
szName = sqlite3Strlen30(zName);
4886348863
if( szName>1 && zName[0]=='/' ){
4886448864
int i;
4886548865
#ifndef SQLITE_MUTEX_OMIT
4886648866
sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
@@ -53160,12 +53160,12 @@
5316053160
5316153161
u16 nExtra; /* Add this many bytes to each in-memory page */
5316253162
i16 nReserve; /* Number of unused bytes at end of each page */
5316353163
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
5316453164
u32 sectorSize; /* Assumed sector size during rollback */
53165
- int pageSize; /* Number of bytes in a page */
5316653165
Pgno mxPgno; /* Maximum allowed size of the database */
53166
+ i64 pageSize; /* Number of bytes in a page */
5316753167
i64 journalSizeLimit; /* Size limit for persistent journal files */
5316853168
char *zFilename; /* Name of the database file */
5316953169
char *zJournal; /* Name of the journal file */
5317053170
int (*xBusyHandler)(void*); /* Function to call when busy */
5317153171
void *pBusyHandlerArg; /* Context argument for xBusyHandler */
@@ -59218,12 +59218,12 @@
5921859218
/*
5921959219
** Return the approximate number of bytes of memory currently
5922059220
** used by the pager and its associated cache.
5922159221
*/
5922259222
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
59223
- int perPageSize = pPager->pageSize + pPager->nExtra + sizeof(PgHdr)
59224
- + 5*sizeof(void*);
59223
+ int perPageSize = pPager->pageSize + pPager->nExtra
59224
+ + (int)(sizeof(PgHdr) + 5*sizeof(void*));
5922559225
return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
5922659226
+ sqlite3MallocSize(pPager)
5922759227
+ pPager->pageSize;
5922859228
}
5922959229
@@ -59413,18 +59413,18 @@
5941359413
for(ii=nNew; ii<pPager->nSavepoint; ii++){
5941459414
sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
5941559415
}
5941659416
pPager->nSavepoint = nNew;
5941759417
59418
- /* If this is a release of the outermost savepoint, truncate
59419
- ** the sub-journal to zero bytes in size. */
59418
+ /* Truncate the sub-journal so that it only includes the parts
59419
+ ** that are still in use. */
5942059420
if( op==SAVEPOINT_RELEASE ){
5942159421
PagerSavepoint *pRel = &pPager->aSavepoint[nNew];
5942259422
if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){
5942359423
/* Only truncate if it is an in-memory sub-journal. */
5942459424
if( sqlite3JournalIsInMemory(pPager->sjfd) ){
59425
- i64 sz = (pPager->pageSize+4)*pRel->iSubRec;
59425
+ i64 sz = (pPager->pageSize+4)*(i64)pRel->iSubRec;
5942659426
rc = sqlite3OsTruncate(pPager->sjfd, sz);
5942759427
assert( rc==SQLITE_OK );
5942859428
}
5942959429
pPager->nSubRec = pRel->iSubRec;
5943059430
}
@@ -72713,10 +72713,11 @@
7271372713
nCell -= nTail;
7271472714
}
7271572715
7271672716
pData = &aData[get2byteNotZero(&aData[hdr+5])];
7271772717
if( pData<pBegin ) goto editpage_fail;
72718
+ if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
7271872719
7271972720
/* Add cells to the start of the page */
7272072721
if( iNew<iOld ){
7272172722
int nAdd = MIN(nNew,iOld-iNew);
7272272723
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74118,11 +74119,11 @@
7411874119
pBt = pPage->pBt;
7411974120
ovflPageSize = pBt->usableSize - 4;
7412074121
do{
7412174122
rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
7412274123
if( rc ) return rc;
74123
- if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
74124
+ if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
7412474125
rc = SQLITE_CORRUPT_BKPT;
7412574126
}else{
7412674127
if( iOffset+ovflPageSize<(u32)nTotal ){
7412774128
ovflPgno = get4byte(pPage->aData);
7412874129
}else{
@@ -94795,10 +94796,15 @@
9479594796
rc = SQLITE_NOMEM_BKPT;
9479694797
}else if( rc==SQLITE_IOERR_CORRUPTFS ){
9479794798
rc = SQLITE_CORRUPT_BKPT;
9479894799
}
9479994800
assert( rc );
94801
+#ifdef SQLITE_DEBUG
94802
+ if( db->flags & SQLITE_VdbeTrace ){
94803
+ printf("ABORT-due-to-error. rc=%d\n", rc);
94804
+ }
94805
+#endif
9480094806
if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
9480194807
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
9480294808
}
9480394809
p->rc = rc;
9480494810
sqlite3SystemError(db, rc);
@@ -105161,10 +105167,11 @@
105161105167
105162105168
/***********************************************************************
105163105169
** Test-only SQL functions that are only usable if enabled
105164105170
** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
105165105171
*/
105172
+#if !defined(SQLITE_UNTESTABLE)
105166105173
case INLINEFUNC_expr_compare: {
105167105174
/* Compare two expressions using sqlite3ExprCompare() */
105168105175
assert( nFarg==2 );
105169105176
sqlite3VdbeAddOp2(v, OP_Integer,
105170105177
sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
@@ -105194,11 +105201,10 @@
105194105201
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
105195105202
}
105196105203
break;
105197105204
}
105198105205
105199
-#ifdef SQLITE_DEBUG
105200105206
case INLINEFUNC_affinity: {
105201105207
/* The AFFINITY() function evaluates to a string that describes
105202105208
** the type affinity of the argument. This is used for testing of
105203105209
** the SQLite type logic.
105204105210
*/
@@ -105208,11 +105214,11 @@
105208105214
aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
105209105215
sqlite3VdbeLoadString(v, target,
105210105216
(aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
105211105217
break;
105212105218
}
105213
-#endif
105219
+#endif /* !defined(SQLITE_UNTESTABLE) */
105214105220
}
105215105221
return target;
105216105222
}
105217105223
105218105224
@@ -108172,12 +108178,11 @@
108172108178
bQuote = sqlite3Isquote(pNew->z[0]);
108173108179
sqlite3NestedParse(pParse,
108174108180
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108175108181
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
108176108182
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
108177
- " AND (type != 'index' OR tbl_name = %Q)"
108178
- " AND sql NOT LIKE 'create virtual%%'",
108183
+ " AND (type != 'index' OR tbl_name = %Q)",
108179108184
zDb,
108180108185
zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
108181108186
pTab->zName
108182108187
);
108183108188
@@ -109023,11 +109028,11 @@
109023109028
rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109024109029
if( rc==SQLITE_OK ){
109025109030
sqlite3WalkSelect(&sWalker, pSelect);
109026109031
}
109027109032
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109028
- }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){
109033
+ }else if( IsOrdinaryTable(sParse.pNewTable) ){
109029109034
/* A regular table */
109030109035
int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
109031109036
FKey *pFKey;
109032109037
sCtx.pTab = sParse.pNewTable;
109033109038
if( bFKOnly==0 ){
@@ -120209,13 +120214,13 @@
120209120214
}
120210120215
120211120216
/*
120212120217
** Implementation of the changes() SQL function.
120213120218
**
120214
-** IMP: R-62073-11209 The changes() SQL function is a wrapper
120215
-** around the sqlite3_changes64() C/C++ function and hence follows the same
120216
-** rules for counting changes.
120219
+** IMP: R-32760-32347 The changes() SQL function is a wrapper
120220
+** around the sqlite3_changes64() C/C++ function and hence follows the
120221
+** same rules for counting changes.
120217120222
*/
120218120223
static void changes(
120219120224
sqlite3_context *context,
120220120225
int NotUsed,
120221120226
sqlite3_value **NotUsed2
@@ -120234,12 +120239,12 @@
120234120239
int NotUsed,
120235120240
sqlite3_value **NotUsed2
120236120241
){
120237120242
sqlite3 *db = sqlite3_context_db_handle(context);
120238120243
UNUSED_PARAMETER2(NotUsed, NotUsed2);
120239
- /* IMP: R-52756-41993 This function was a wrapper around the
120240
- ** sqlite3_total_changes() C/C++ interface. */
120244
+ /* IMP: R-11217-42568 This function is a wrapper around the
120245
+ ** sqlite3_total_changes64() C/C++ interface. */
120241120246
sqlite3_result_int64(context, sqlite3_total_changes64(db));
120242120247
}
120243120248
120244120249
/*
120245120250
** A structure defining how to do GLOB-style comparisons.
@@ -121761,16 +121766,16 @@
121761121766
**
121762121767
** For peak efficiency, put the most frequently used function last.
121763121768
*/
121764121769
static FuncDef aBuiltinFunc[] = {
121765121770
/***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
121771
+#if !defined(SQLITE_UNTESTABLE)
121766121772
TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
121767121773
TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
121768121774
TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
121769
-#ifdef SQLITE_DEBUG
121770
- TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
121771
-#endif
121775
+ TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
121776
+#endif /* !defined(SQLITE_UNTESTABLE) */
121772121777
/***** Regular functions *****/
121773121778
#ifdef SQLITE_SOUNDEX
121774121779
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
121775121780
#endif
121776121781
#ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -128264,17 +128269,18 @@
128264128269
#define PragTyp_SECURE_DELETE 33
128265128270
#define PragTyp_SHRINK_MEMORY 34
128266128271
#define PragTyp_SOFT_HEAP_LIMIT 35
128267128272
#define PragTyp_SYNCHRONOUS 36
128268128273
#define PragTyp_TABLE_INFO 37
128269
-#define PragTyp_TEMP_STORE 38
128270
-#define PragTyp_TEMP_STORE_DIRECTORY 39
128271
-#define PragTyp_THREADS 40
128272
-#define PragTyp_WAL_AUTOCHECKPOINT 41
128273
-#define PragTyp_WAL_CHECKPOINT 42
128274
-#define PragTyp_LOCK_STATUS 43
128275
-#define PragTyp_STATS 44
128274
+#define PragTyp_TABLE_LIST 38
128275
+#define PragTyp_TEMP_STORE 39
128276
+#define PragTyp_TEMP_STORE_DIRECTORY 40
128277
+#define PragTyp_THREADS 41
128278
+#define PragTyp_WAL_AUTOCHECKPOINT 42
128279
+#define PragTyp_WAL_CHECKPOINT 43
128280
+#define PragTyp_LOCK_STATUS 44
128281
+#define PragTyp_STATS 45
128276128282
128277128283
/* Property flags associated with various pragma. */
128278128284
#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
128279128285
#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
128280128286
#define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -128303,49 +128309,55 @@
128303128309
/* 11 */ "notnull",
128304128310
/* 12 */ "dflt_value",
128305128311
/* 13 */ "pk",
128306128312
/* 14 */ "hidden",
128307128313
/* table_info reuses 8 */
128308
- /* 15 */ "seqno", /* Used by: index_xinfo */
128309
- /* 16 */ "cid",
128310
- /* 17 */ "name",
128311
- /* 18 */ "desc",
128312
- /* 19 */ "coll",
128313
- /* 20 */ "key",
128314
- /* 21 */ "name", /* Used by: function_list */
128315
- /* 22 */ "builtin",
128316
- /* 23 */ "type",
128317
- /* 24 */ "enc",
128318
- /* 25 */ "narg",
128319
- /* 26 */ "flags",
128320
- /* 27 */ "tbl", /* Used by: stats */
128321
- /* 28 */ "idx",
128322
- /* 29 */ "wdth",
128323
- /* 30 */ "hght",
128324
- /* 31 */ "flgs",
128325
- /* 32 */ "seq", /* Used by: index_list */
128326
- /* 33 */ "name",
128327
- /* 34 */ "unique",
128328
- /* 35 */ "origin",
128329
- /* 36 */ "partial",
128330
- /* 37 */ "table", /* Used by: foreign_key_check */
128331
- /* 38 */ "rowid",
128332
- /* 39 */ "parent",
128333
- /* 40 */ "fkid",
128334
- /* index_info reuses 15 */
128335
- /* 41 */ "seq", /* Used by: database_list */
128336
- /* 42 */ "name",
128337
- /* 43 */ "file",
128338
- /* 44 */ "busy", /* Used by: wal_checkpoint */
128339
- /* 45 */ "log",
128340
- /* 46 */ "checkpointed",
128341
- /* collation_list reuses 32 */
128342
- /* 47 */ "database", /* Used by: lock_status */
128343
- /* 48 */ "status",
128344
- /* 49 */ "cache_size", /* Used by: default_cache_size */
128314
+ /* 15 */ "schema", /* Used by: table_list */
128315
+ /* 16 */ "name",
128316
+ /* 17 */ "type",
128317
+ /* 18 */ "ncol",
128318
+ /* 19 */ "wr",
128319
+ /* 20 */ "strict",
128320
+ /* 21 */ "seqno", /* Used by: index_xinfo */
128321
+ /* 22 */ "cid",
128322
+ /* 23 */ "name",
128323
+ /* 24 */ "desc",
128324
+ /* 25 */ "coll",
128325
+ /* 26 */ "key",
128326
+ /* 27 */ "name", /* Used by: function_list */
128327
+ /* 28 */ "builtin",
128328
+ /* 29 */ "type",
128329
+ /* 30 */ "enc",
128330
+ /* 31 */ "narg",
128331
+ /* 32 */ "flags",
128332
+ /* 33 */ "tbl", /* Used by: stats */
128333
+ /* 34 */ "idx",
128334
+ /* 35 */ "wdth",
128335
+ /* 36 */ "hght",
128336
+ /* 37 */ "flgs",
128337
+ /* 38 */ "seq", /* Used by: index_list */
128338
+ /* 39 */ "name",
128339
+ /* 40 */ "unique",
128340
+ /* 41 */ "origin",
128341
+ /* 42 */ "partial",
128342
+ /* 43 */ "table", /* Used by: foreign_key_check */
128343
+ /* 44 */ "rowid",
128344
+ /* 45 */ "parent",
128345
+ /* 46 */ "fkid",
128346
+ /* index_info reuses 21 */
128347
+ /* 47 */ "seq", /* Used by: database_list */
128348
+ /* 48 */ "name",
128349
+ /* 49 */ "file",
128350
+ /* 50 */ "busy", /* Used by: wal_checkpoint */
128351
+ /* 51 */ "log",
128352
+ /* 52 */ "checkpointed",
128353
+ /* collation_list reuses 38 */
128354
+ /* 53 */ "database", /* Used by: lock_status */
128355
+ /* 54 */ "status",
128356
+ /* 55 */ "cache_size", /* Used by: default_cache_size */
128345128357
/* module_list pragma_list reuses 9 */
128346
- /* 50 */ "timeout", /* Used by: busy_timeout */
128358
+ /* 56 */ "timeout", /* Used by: busy_timeout */
128347128359
};
128348128360
128349128361
/* Definitions of all built-in pragmas */
128350128362
typedef struct PragmaName {
128351128363
const char *const zName; /* Name of pragma */
@@ -128392,11 +128404,11 @@
128392128404
#endif
128393128405
#endif
128394128406
{/* zName: */ "busy_timeout",
128395128407
/* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
128396128408
/* ePragFlg: */ PragFlg_Result0,
128397
- /* ColNames: */ 50, 1,
128409
+ /* ColNames: */ 56, 1,
128398128410
/* iArg: */ 0 },
128399128411
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128400128412
{/* zName: */ "cache_size",
128401128413
/* ePragTyp: */ PragTyp_CACHE_SIZE,
128402128414
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -128431,11 +128443,11 @@
128431128443
#endif
128432128444
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128433128445
{/* zName: */ "collation_list",
128434128446
/* ePragTyp: */ PragTyp_COLLATION_LIST,
128435128447
/* ePragFlg: */ PragFlg_Result0,
128436
- /* ColNames: */ 32, 2,
128448
+ /* ColNames: */ 38, 2,
128437128449
/* iArg: */ 0 },
128438128450
#endif
128439128451
#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
128440128452
{/* zName: */ "compile_options",
128441128453
/* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -128466,18 +128478,18 @@
128466128478
#endif
128467128479
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128468128480
{/* zName: */ "database_list",
128469128481
/* ePragTyp: */ PragTyp_DATABASE_LIST,
128470128482
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
128471
- /* ColNames: */ 41, 3,
128483
+ /* ColNames: */ 47, 3,
128472128484
/* iArg: */ 0 },
128473128485
#endif
128474128486
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
128475128487
{/* zName: */ "default_cache_size",
128476128488
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
128477128489
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
128478
- /* ColNames: */ 49, 1,
128490
+ /* ColNames: */ 55, 1,
128479128491
/* iArg: */ 0 },
128480128492
#endif
128481128493
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128482128494
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128483128495
{/* zName: */ "defer_foreign_keys",
@@ -128503,11 +128515,11 @@
128503128515
#endif
128504128516
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128505128517
{/* zName: */ "foreign_key_check",
128506128518
/* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
128507128519
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt,
128508
- /* ColNames: */ 37, 4,
128520
+ /* ColNames: */ 43, 4,
128509128521
/* iArg: */ 0 },
128510128522
#endif
128511128523
#if !defined(SQLITE_OMIT_FOREIGN_KEY)
128512128524
{/* zName: */ "foreign_key_list",
128513128525
/* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -128546,11 +128558,11 @@
128546128558
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128547128559
#if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
128548128560
{/* zName: */ "function_list",
128549128561
/* ePragTyp: */ PragTyp_FUNCTION_LIST,
128550128562
/* ePragFlg: */ PragFlg_Result0,
128551
- /* ColNames: */ 21, 6,
128563
+ /* ColNames: */ 27, 6,
128552128564
/* iArg: */ 0 },
128553128565
#endif
128554128566
#endif
128555128567
{/* zName: */ "hard_heap_limit",
128556128568
/* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -128575,21 +128587,21 @@
128575128587
#endif
128576128588
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128577128589
{/* zName: */ "index_info",
128578128590
/* ePragTyp: */ PragTyp_INDEX_INFO,
128579128591
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128580
- /* ColNames: */ 15, 3,
128592
+ /* ColNames: */ 21, 3,
128581128593
/* iArg: */ 0 },
128582128594
{/* zName: */ "index_list",
128583128595
/* ePragTyp: */ PragTyp_INDEX_LIST,
128584128596
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128585
- /* ColNames: */ 32, 5,
128597
+ /* ColNames: */ 38, 5,
128586128598
/* iArg: */ 0 },
128587128599
{/* zName: */ "index_xinfo",
128588128600
/* ePragTyp: */ PragTyp_INDEX_INFO,
128589128601
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128590
- /* ColNames: */ 15, 6,
128602
+ /* ColNames: */ 21, 6,
128591128603
/* iArg: */ 1 },
128592128604
#endif
128593128605
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
128594128606
{/* zName: */ "integrity_check",
128595128607
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -128625,11 +128637,11 @@
128625128637
#endif
128626128638
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
128627128639
{/* zName: */ "lock_status",
128628128640
/* ePragTyp: */ PragTyp_LOCK_STATUS,
128629128641
/* ePragFlg: */ PragFlg_Result0,
128630
- /* ColNames: */ 47, 2,
128642
+ /* ColNames: */ 53, 2,
128631128643
/* iArg: */ 0 },
128632128644
#endif
128633128645
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128634128646
{/* zName: */ "locking_mode",
128635128647
/* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -128764,11 +128776,11 @@
128764128776
#endif
128765128777
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
128766128778
{/* zName: */ "stats",
128767128779
/* ePragTyp: */ PragTyp_STATS,
128768128780
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
128769
- /* ColNames: */ 27, 5,
128781
+ /* ColNames: */ 33, 5,
128770128782
/* iArg: */ 0 },
128771128783
#endif
128772128784
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128773128785
{/* zName: */ "synchronous",
128774128786
/* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -128780,10 +128792,15 @@
128780128792
{/* zName: */ "table_info",
128781128793
/* ePragTyp: */ PragTyp_TABLE_INFO,
128782128794
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128783128795
/* ColNames: */ 8, 6,
128784128796
/* iArg: */ 0 },
128797
+ {/* zName: */ "table_list",
128798
+ /* ePragTyp: */ PragTyp_TABLE_LIST,
128799
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1,
128800
+ /* ColNames: */ 15, 6,
128801
+ /* iArg: */ 1 },
128785128802
{/* zName: */ "table_xinfo",
128786128803
/* ePragTyp: */ PragTyp_TABLE_INFO,
128787128804
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128788128805
/* ColNames: */ 8, 7,
128789128806
/* iArg: */ 1 },
@@ -128855,11 +128872,11 @@
128855128872
/* ColNames: */ 0, 0,
128856128873
/* iArg: */ 0 },
128857128874
{/* zName: */ "wal_checkpoint",
128858128875
/* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
128859128876
/* ePragFlg: */ PragFlg_NeedSchema,
128860
- /* ColNames: */ 44, 3,
128877
+ /* ColNames: */ 50, 3,
128861128878
/* iArg: */ 0 },
128862128879
#endif
128863128880
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128864128881
{/* zName: */ "writable_schema",
128865128882
/* ePragTyp: */ PragTyp_FLAG,
@@ -128866,11 +128883,11 @@
128866128883
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
128867128884
/* ColNames: */ 0, 0,
128868128885
/* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
128869128886
#endif
128870128887
};
128871
-/* Number of pragmas: 67 on by default, 77 total. */
128888
+/* Number of pragmas: 68 on by default, 78 total. */
128872128889
128873128890
/************** End of pragma.h **********************************************/
128874128891
/************** Continuing where we left off in pragma.c *********************/
128875128892
128876128893
/*
@@ -130035,10 +130052,58 @@
130035130052
}
130036130053
}
130037130054
}
130038130055
break;
130039130056
130057
+ /*
130058
+ ** PRAGMA table_list
130059
+ **
130060
+ ** Return a single row for each table, virtual table, or view in the
130061
+ ** entire schema.
130062
+ **
130063
+ ** schema: Name of attached database hold this table
130064
+ ** name: Name of the table itself
130065
+ ** type: "table", "view", "virtual", "shadow"
130066
+ ** ncol: Number of columns
130067
+ ** wr: True for a WITHOUT ROWID table
130068
+ ** strict: True for a STRICT table
130069
+ */
130070
+ case PragTyp_TABLE_LIST: {
130071
+ int ii;
130072
+ pParse->nMem = 6;
130073
+ sqlite3CodeVerifyNamedSchema(pParse, zDb);
130074
+ for(ii=0; ii<db->nDb; ii++){
130075
+ HashElem *k;
130076
+ Hash *pHash;
130077
+ if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130078
+ pHash = &db->aDb[ii].pSchema->tblHash;
130079
+ for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130080
+ Table *pTab = sqliteHashData(k);
130081
+ const char *zType;
130082
+ if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130083
+ if( IsView(pTab) ){
130084
+ zType = "view";
130085
+ }else if( IsVirtual(pTab) ){
130086
+ zType = "virtual";
130087
+ }else if( pTab->tabFlags & TF_Shadow ){
130088
+ zType = "shadow";
130089
+ }else{
130090
+ zType = "table";
130091
+ }
130092
+ sqlite3VdbeMultiLoad(v, 1, "sssiii",
130093
+ db->aDb[ii].zDbSName,
130094
+ pTab->zName,
130095
+ zType,
130096
+ pTab->nCol,
130097
+ (pTab->tabFlags & TF_WithoutRowid)!=0,
130098
+ (pTab->tabFlags & TF_Strict)!=0
130099
+ );
130100
+ }
130101
+ }
130102
+ }
130103
+ break;
130104
+
130040130105
#ifdef SQLITE_DEBUG
130041130106
case PragTyp_STATS: {
130042130107
Index *pIdx;
130043130108
HashElem *i;
130044130109
pParse->nMem = 5;
@@ -130544,11 +130609,13 @@
130544130609
}else{
130545130610
integrityCheckResultRow(v);
130546130611
}
130547130612
sqlite3VdbeJumpHere(v, jmp2);
130548130613
}
130549
- if( pTab->tabFlags & TF_Strict ){
130614
+ if( (pTab->tabFlags & TF_Strict)!=0
130615
+ && pCol->eCType!=COLTYPE_ANY
130616
+ ){
130550130617
jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
130551130618
sqlite3StdTypeMap[pCol->eCType-1]);
130552130619
VdbeCoverage(v);
130553130620
zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
130554130621
sqlite3StdType[pCol->eCType-1],
@@ -132836,10 +132903,13 @@
132836132903
132837132904
pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
132838132905
pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
132839132906
132840132907
pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
132908
+ assert( pE2!=0 || pEq==0 ); /* Due to db->mallocFailed test
132909
+ ** in sqlite3DbMallocRawNN() called from
132910
+ ** sqlite3PExpr(). */
132841132911
if( pEq && isOuterJoin ){
132842132912
ExprSetProperty(pEq, EP_FromJoin);
132843132913
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
132844132914
ExprSetVVAProperty(pEq, EP_NoReduce);
132845132915
pEq->iRightJoinTable = pE2->iTable;
@@ -148365,11 +148435,11 @@
148365148435
** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148366148436
** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148367148437
*/
148368148438
if( pLeft->op!=TK_COLUMN
148369148439
|| sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148370
- || IsVirtual(pLeft->y.pTab) /* Value might be numeric */
148440
+ || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148371148441
){
148372148442
int isNum;
148373148443
double rDummy;
148374148444
isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148375148445
if( isNum<=0 ){
@@ -156490,10 +156560,13 @@
156490156560
);
156491156561
SELECTTRACE(1,pParse,pSub,
156492156562
("New window-function subquery in FROM clause of (%u/%p)\n",
156493156563
p->selId, p));
156494156564
p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
156565
+ assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
156566
+ ** of sqlite3DbMallocRawNN() called from
156567
+ ** sqlite3SrcListAppend() */
156495156568
if( p->pSrc ){
156496156569
Table *pTab2;
156497156570
p->pSrc->a[0].pSelect = pSub;
156498156571
sqlite3SrcListAssignCursors(pParse, p->pSrc);
156499156572
pSub->selFlags |= SF_Expanded|SF_OrderByReqd;
@@ -192908,11 +192981,15 @@
192908192981
#else
192909192982
/* #include "sqlite3.h" */
192910192983
#endif
192911192984
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
192912192985
192913
-#ifndef SQLITE_AMALGAMATION
192986
+/*
192987
+** If building separately, we will need some setup that is normally
192988
+** found in sqliteInt.h
192989
+*/
192990
+#if !defined(SQLITE_AMALGAMATION)
192914192991
#include "sqlite3rtree.h"
192915192992
typedef sqlite3_int64 i64;
192916192993
typedef sqlite3_uint64 u64;
192917192994
typedef unsigned char u8;
192918192995
typedef unsigned short u16;
@@ -192921,11 +192998,21 @@
192921192998
# define NDEBUG 1
192922192999
#endif
192923193000
#if defined(NDEBUG) && defined(SQLITE_DEBUG)
192924193001
# undef NDEBUG
192925193002
#endif
193003
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
193004
+# define ALWAYS(X) (1)
193005
+# define NEVER(X) (0)
193006
+#elif !defined(NDEBUG)
193007
+# define ALWAYS(X) ((X)?1:(assert(0),0))
193008
+# define NEVER(X) ((X)?(assert(0),1):0)
193009
+#else
193010
+# define ALWAYS(X) (X)
193011
+# define NEVER(X) (X)
192926193012
#endif
193013
+#endif /* !defined(SQLITE_AMALGAMATION) */
192927193014
192928193015
/* #include <string.h> */
192929193016
/* #include <stdio.h> */
192930193017
/* #include <assert.h> */
192931193018
/* #include <stdlib.h> */
@@ -192979,11 +193066,13 @@
192979193066
u8 nDim2; /* Twice the number of dimensions */
192980193067
u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
192981193068
u8 nBytesPerCell; /* Bytes consumed per cell */
192982193069
u8 inWrTrans; /* True if inside write transaction */
192983193070
u8 nAux; /* # of auxiliary columns in %_rowid */
193071
+#ifdef SQLITE_ENABLE_GEOPOLY
192984193072
u8 nAuxNotNull; /* Number of initial not-null aux columns */
193073
+#endif
192985193074
#ifdef SQLITE_DEBUG
192986193075
u8 bCorrupt; /* Shadow table corruption detected */
192987193076
#endif
192988193077
int iDepth; /* Current depth of the r-tree structure */
192989193078
char *zDb; /* Name of database containing r-tree table */
@@ -193510,22 +193599,10 @@
193510193599
pRtree->pNodeBlob = 0;
193511193600
sqlite3_blob_close(pBlob);
193512193601
}
193513193602
}
193514193603
193515
-/*
193516
-** Check to see if pNode is the same as pParent or any of the parents
193517
-** of pParent.
193518
-*/
193519
-static int nodeInParentChain(const RtreeNode *pNode, const RtreeNode *pParent){
193520
- do{
193521
- if( pNode==pParent ) return 1;
193522
- pParent = pParent->pParent;
193523
- }while( pParent );
193524
- return 0;
193525
-}
193526
-
193527193604
/*
193528193605
** Obtain a reference to an r-tree node.
193529193606
*/
193530193607
static int nodeAcquire(
193531193608
Rtree *pRtree, /* R-tree structure */
@@ -193538,18 +193615,11 @@
193538193615
193539193616
/* Check if the requested node is already in the hash table. If so,
193540193617
** increase its reference count and return it.
193541193618
*/
193542193619
if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
193543
- if( pParent && !pNode->pParent ){
193544
- if( nodeInParentChain(pNode, pParent) ){
193545
- RTREE_IS_CORRUPT(pRtree);
193546
- return SQLITE_CORRUPT_VTAB;
193547
- }
193548
- pParent->nRef++;
193549
- pNode->pParent = pParent;
193550
- }else if( pParent && pNode->pParent && pParent!=pNode->pParent ){
193620
+ if( pParent && pParent!=pNode->pParent ){
193551193621
RTREE_IS_CORRUPT(pRtree);
193552193622
return SQLITE_CORRUPT_VTAB;
193553193623
}
193554193624
pNode->nRef++;
193555193625
*ppNode = pNode;
@@ -193603,11 +193673,11 @@
193603193673
** of the r-tree structure. A height of zero means all data is stored on
193604193674
** the root node. A height of one means the children of the root node
193605193675
** are the leaves, and so on. If the depth as specified on the root node
193606193676
** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
193607193677
*/
193608
- if( pNode && rc==SQLITE_OK && iNode==1 ){
193678
+ if( rc==SQLITE_OK && pNode && iNode==1 ){
193609193679
pRtree->iDepth = readInt16(pNode->zData);
193610193680
if( pRtree->iDepth>RTREE_MAX_DEPTH ){
193611193681
rc = SQLITE_CORRUPT_VTAB;
193612193682
RTREE_IS_CORRUPT(pRtree);
193613193683
}
@@ -194209,15 +194279,16 @@
194209194279
** Return the index of the cell containing a pointer to node pNode
194210194280
** in its parent. If pNode is the root node, return -1.
194211194281
*/
194212194282
static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
194213194283
RtreeNode *pParent = pNode->pParent;
194214
- if( pParent ){
194284
+ if( ALWAYS(pParent) ){
194215194285
return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
194286
+ }else{
194287
+ *piIndex = -1;
194288
+ return SQLITE_OK;
194216194289
}
194217
- *piIndex = -1;
194218
- return SQLITE_OK;
194219194290
}
194220194291
194221194292
/*
194222194293
** Compare two search points. Return negative, zero, or positive if the first
194223194294
** is less than, equal to, or greater than the second.
@@ -194336,11 +194407,12 @@
194336194407
if( pCur->bPoint ){
194337194408
int ii;
194338194409
pNew = rtreeEnqueue(pCur, rScore, iLevel);
194339194410
if( pNew==0 ) return 0;
194340194411
ii = (int)(pNew - pCur->aPoint) + 1;
194341
- if( ii<RTREE_CACHE_SZ ){
194412
+ assert( ii==1 );
194413
+ if( ALWAYS(ii<RTREE_CACHE_SZ) ){
194342194414
assert( pCur->aNode[ii]==0 );
194343194415
pCur->aNode[ii] = pCur->aNode[0];
194344194416
}else{
194345194417
nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
194346194418
}
@@ -194397,11 +194469,11 @@
194397194469
p->aNode[i] = 0;
194398194470
}
194399194471
if( p->bPoint ){
194400194472
p->anQueue[p->sPoint.iLevel]--;
194401194473
p->bPoint = 0;
194402
- }else if( p->nPoint ){
194474
+ }else if( ALWAYS(p->nPoint) ){
194403194475
p->anQueue[p->aPoint[0].iLevel]--;
194404194476
n = --p->nPoint;
194405194477
p->aPoint[0] = p->aPoint[n];
194406194478
if( n<RTREE_CACHE_SZ-1 ){
194407194479
p->aNode[1] = p->aNode[n+1];
@@ -194538,11 +194610,11 @@
194538194610
static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
194539194611
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
194540194612
RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
194541194613
int rc = SQLITE_OK;
194542194614
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194543
- if( rc==SQLITE_OK && p ){
194615
+ if( rc==SQLITE_OK && ALWAYS(p) ){
194544194616
*pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
194545194617
}
194546194618
return rc;
194547194619
}
194548194620
@@ -194556,11 +194628,11 @@
194556194628
RtreeCoord c;
194557194629
int rc = SQLITE_OK;
194558194630
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194559194631
194560194632
if( rc ) return rc;
194561
- if( p==0 ) return SQLITE_OK;
194633
+ if( NEVER(p==0) ) return SQLITE_OK;
194562194634
if( i==0 ){
194563194635
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
194564194636
}else if( i<=pRtree->nDim2 ){
194565194637
nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
194566194638
#ifndef SQLITE_RTREE_INT_ONLY
@@ -194755,12 +194827,15 @@
194755194827
}
194756194828
}
194757194829
}
194758194830
if( rc==SQLITE_OK ){
194759194831
RtreeSearchPoint *pNew;
194832
+ assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
194760194833
pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
194761
- if( pNew==0 ) return SQLITE_NOMEM;
194834
+ if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
194835
+ return SQLITE_NOMEM;
194836
+ }
194762194837
pNew->id = 1;
194763194838
pNew->iCell = 0;
194764194839
pNew->eWithin = PARTLY_WITHIN;
194765194840
assert( pCsr->bPoint==1 );
194766194841
pCsr->aNode[0] = pRoot;
@@ -194833,11 +194908,11 @@
194833194908
assert( pIdxInfo->idxStr==0 );
194834194909
for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
194835194910
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
194836194911
194837194912
if( bMatch==0 && p->usable
194838
- && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
194913
+ && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
194839194914
){
194840194915
/* We have an equality constraint on the rowid. Use strategy 1. */
194841194916
int jj;
194842194917
for(jj=0; jj<ii; jj++){
194843194918
pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
@@ -195086,16 +195161,23 @@
195086195161
RtreeNode *pNode, /* Adjust ancestry of this node. */
195087195162
RtreeCell *pCell /* This cell was just inserted */
195088195163
){
195089195164
RtreeNode *p = pNode;
195090195165
int cnt = 0;
195166
+ int rc;
195091195167
while( p->pParent ){
195092195168
RtreeNode *pParent = p->pParent;
195093195169
RtreeCell cell;
195094195170
int iCell;
195095195171
195096
- if( (++cnt)>1000 || nodeParentIndex(pRtree, p, &iCell) ){
195172
+ cnt++;
195173
+ if( NEVER(cnt>100) ){
195174
+ RTREE_IS_CORRUPT(pRtree);
195175
+ return SQLITE_CORRUPT_VTAB;
195176
+ }
195177
+ rc = nodeParentIndex(pRtree, p, &iCell);
195178
+ if( NEVER(rc!=SQLITE_OK) ){
195097195179
RTREE_IS_CORRUPT(pRtree);
195098195180
return SQLITE_CORRUPT_VTAB;
195099195181
}
195100195182
195101195183
nodeGetCell(pRtree, pParent, iCell, &cell);
@@ -195475,15 +195557,16 @@
195475195557
}
195476195558
}else{
195477195559
RtreeNode *pParent = pLeft->pParent;
195478195560
int iCell;
195479195561
rc = nodeParentIndex(pRtree, pLeft, &iCell);
195480
- if( rc==SQLITE_OK ){
195562
+ if( ALWAYS(rc==SQLITE_OK) ){
195481195563
nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
195482195564
rc = AdjustTree(pRtree, pParent, &leftbbox);
195565
+ assert( rc==SQLITE_OK );
195483195566
}
195484
- if( rc!=SQLITE_OK ){
195567
+ if( NEVER(rc!=SQLITE_OK) ){
195485195568
goto splitnode_out;
195486195569
}
195487195570
}
195488195571
if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
195489195572
goto splitnode_out;
@@ -195554,11 +195637,11 @@
195554195637
** want to do this as it leads to a memory leak when trying to delete
195555195638
** the referenced counted node structures.
195556195639
*/
195557195640
iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
195558195641
for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
195559
- if( !pTest ){
195642
+ if( pTest==0 ){
195560195643
rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
195561195644
}
195562195645
}
195563195646
rc = sqlite3_reset(pRtree->pReadParent);
195564195647
if( rc==SQLITE_OK ) rc = rc2;
@@ -195585,10 +195668,11 @@
195585195668
rc = nodeParentIndex(pRtree, pNode, &iCell);
195586195669
if( rc==SQLITE_OK ){
195587195670
pParent = pNode->pParent;
195588195671
pNode->pParent = 0;
195589195672
rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
195673
+ testcase( rc!=SQLITE_OK );
195590195674
}
195591195675
rc2 = nodeRelease(pRtree, pParent);
195592195676
if( rc==SQLITE_OK ){
195593195677
rc = rc2;
195594195678
}
@@ -195807,11 +195891,11 @@
195807195891
pRtree->iReinsertHeight = iHeight;
195808195892
rc = Reinsert(pRtree, pNode, pCell, iHeight);
195809195893
}
195810195894
}else{
195811195895
rc = AdjustTree(pRtree, pNode, pCell);
195812
- if( rc==SQLITE_OK ){
195896
+ if( ALWAYS(rc==SQLITE_OK) ){
195813195897
if( iHeight==0 ){
195814195898
rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
195815195899
}else{
195816195900
rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
195817195901
}
@@ -195913,11 +195997,11 @@
195913195997
*/
195914195998
if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
195915195999
int rc2;
195916196000
RtreeNode *pChild = 0;
195917196001
i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
195918
- rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
196002
+ rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); /* tag-20210916a */
195919196003
if( rc==SQLITE_OK ){
195920196004
rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
195921196005
}
195922196006
rc2 = nodeRelease(pRtree, pChild);
195923196007
if( rc==SQLITE_OK ) rc = rc2;
@@ -196248,11 +196332,11 @@
196248196332
static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
196249196333
const char *zFmt = "SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'";
196250196334
char *zSql;
196251196335
sqlite3_stmt *p;
196252196336
int rc;
196253
- i64 nRow = 0;
196337
+ i64 nRow = RTREE_MIN_ROWEST;
196254196338
196255196339
rc = sqlite3_table_column_metadata(
196256196340
db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
196257196341
);
196258196342
if( rc!=SQLITE_OK ){
@@ -196265,24 +196349,14 @@
196265196349
}else{
196266196350
rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
196267196351
if( rc==SQLITE_OK ){
196268196352
if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
196269196353
rc = sqlite3_finalize(p);
196270
- }else if( rc!=SQLITE_NOMEM ){
196271
- rc = SQLITE_OK;
196272
- }
196273
-
196274
- if( rc==SQLITE_OK ){
196275
- if( nRow==0 ){
196276
- pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
196277
- }else{
196278
- pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
196279
- }
196280196354
}
196281196355
sqlite3_free(zSql);
196282196356
}
196283
-
196357
+ pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
196284196358
return rc;
196285196359
}
196286196360
196287196361
196288196362
/*
@@ -196428,13 +196502,16 @@
196428196502
int ii;
196429196503
char *zSql;
196430196504
sqlite3_str_appendf(p, "UPDATE \"%w\".\"%w_rowid\"SET ", zDb, zPrefix);
196431196505
for(ii=0; ii<pRtree->nAux; ii++){
196432196506
if( ii ) sqlite3_str_append(p, ",", 1);
196507
+#ifdef SQLITE_ENABLE_GEOPOLY
196433196508
if( ii<pRtree->nAuxNotNull ){
196434196509
sqlite3_str_appendf(p,"a%d=coalesce(?%d,a%d)",ii,ii+2,ii);
196435
- }else{
196510
+ }else
196511
+#endif
196512
+ {
196436196513
sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
196437196514
}
196438196515
}
196439196516
sqlite3_str_appendf(p, " WHERE rowid=?1");
196440196517
zSql = sqlite3_str_finish(p);
@@ -197109,12 +197186,14 @@
197109197186
if( check.rc==SQLITE_OK ){
197110197187
pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.'%q_rowid'", zDb, zTab);
197111197188
if( pStmt ){
197112197189
nAux = sqlite3_column_count(pStmt) - 2;
197113197190
sqlite3_finalize(pStmt);
197191
+ }else
197192
+ if( check.rc!=SQLITE_NOMEM ){
197193
+ check.rc = SQLITE_OK;
197114197194
}
197115
- check.rc = SQLITE_OK;
197116197195
}
197117197196
197118197197
/* Find number of dimensions in the rtree table. */
197119197198
pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.%Q", zDb, zTab);
197120197199
if( pStmt ){
@@ -199185,11 +199264,14 @@
199185199264
){
199186199265
RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */
199187199266
199188199267
/* Allocate and populate the context object. */
199189199268
pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
199190
- if( !pGeomCtx ) return SQLITE_NOMEM;
199269
+ if( !pGeomCtx ){
199270
+ if( xDestructor ) xDestructor(pContext);
199271
+ return SQLITE_NOMEM;
199272
+ }
199191199273
pGeomCtx->xGeom = 0;
199192199274
pGeomCtx->xQueryFunc = xQueryFunc;
199193199275
pGeomCtx->xDestructor = xDestructor;
199194199276
pGeomCtx->pContext = pContext;
199195199277
return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
@@ -222468,10 +222550,46 @@
222468222550
if( p->pStruct!=(Fts5Structure*)pStruct ){
222469222551
return SQLITE_ABORT;
222470222552
}
222471222553
return SQLITE_OK;
222472222554
}
222555
+
222556
+/*
222557
+** Ensure that structure object (*pp) is writable.
222558
+**
222559
+** This function is a no-op if (*pRc) is not SQLITE_OK when it is called. If
222560
+** an error occurs, (*pRc) is set to an SQLite error code before returning.
222561
+*/
222562
+static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){
222563
+ Fts5Structure *p = *pp;
222564
+ if( *pRc==SQLITE_OK && p->nRef>1 ){
222565
+ int nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel);
222566
+ Fts5Structure *pNew;
222567
+ pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte);
222568
+ if( pNew ){
222569
+ int i;
222570
+ memcpy(pNew, p, nByte);
222571
+ for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
222572
+ for(i=0; i<p->nLevel; i++){
222573
+ Fts5StructureLevel *pLvl = &pNew->aLevel[i];
222574
+ int nByte = sizeof(Fts5StructureSegment) * pNew->aLevel[i].nSeg;
222575
+ pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(pRc, nByte);
222576
+ if( pLvl->aSeg==0 ){
222577
+ for(i=0; i<p->nLevel; i++){
222578
+ sqlite3_free(pNew->aLevel[i].aSeg);
222579
+ }
222580
+ sqlite3_free(pNew);
222581
+ return;
222582
+ }
222583
+ memcpy(pLvl->aSeg, p->aLevel[i].aSeg, nByte);
222584
+ }
222585
+ p->nRef--;
222586
+ pNew->nRef = 1;
222587
+ }
222588
+ *pp = pNew;
222589
+ }
222590
+}
222473222591
222474222592
/*
222475222593
** Deserialize and return the structure record currently stored in serialized
222476222594
** form within buffer pData/nData.
222477222595
**
@@ -222570,13 +222688,15 @@
222570222688
*ppOut = pRet;
222571222689
return rc;
222572222690
}
222573222691
222574222692
/*
222575
-**
222693
+** Add a level to the Fts5Structure.aLevel[] array of structure object
222694
+** (*ppStruct).
222576222695
*/
222577222696
static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
222697
+ fts5StructureMakeWritable(pRc, ppStruct);
222578222698
if( *pRc==SQLITE_OK ){
222579222699
Fts5Structure *pStruct = *ppStruct;
222580222700
int nLevel = pStruct->nLevel;
222581222701
sqlite3_int64 nByte = (
222582222702
sizeof(Fts5Structure) + /* Main structure */
@@ -231175,11 +231295,11 @@
231175231295
int nArg, /* Number of args */
231176231296
sqlite3_value **apUnused /* Function arguments */
231177231297
){
231178231298
assert( nArg==0 );
231179231299
UNUSED_PARAM2(nArg, apUnused);
231180
- sqlite3_result_text(pCtx, "fts5: 2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1", -1, SQLITE_TRANSIENT);
231300
+ sqlite3_result_text(pCtx, "fts5: 2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3", -1, SQLITE_TRANSIENT);
231181231301
}
231182231302
231183231303
/*
231184231304
** Return true if zName is the extension on one of the shadow tables used
231185231305
** by this module.
231186231306
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19842,11 +19842,11 @@
19842 #ifdef SQLITE_TEST
19843 SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char*);
19844 #endif
19845
19846 #ifdef SQLITE_OMIT_VIRTUALTABLE
19847 # define sqlite3VtabClear(Y)
19848 # define sqlite3VtabSync(X,Y) SQLITE_OK
19849 # define sqlite3VtabRollback(X)
19850 # define sqlite3VtabCommit(X)
19851 # define sqlite3VtabInSync(db) 0
19852 # define sqlite3VtabLock(X)
@@ -48856,11 +48856,11 @@
48856 MemStore *p = 0;
48857 int szName;
48858 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48859 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
48860 }
48861 memset(pFile, 0, sizeof(*p));
48862 szName = sqlite3Strlen30(zName);
48863 if( szName>1 && zName[0]=='/' ){
48864 int i;
48865 #ifndef SQLITE_MUTEX_OMIT
48866 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
@@ -53160,12 +53160,12 @@
53160
53161 u16 nExtra; /* Add this many bytes to each in-memory page */
53162 i16 nReserve; /* Number of unused bytes at end of each page */
53163 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
53164 u32 sectorSize; /* Assumed sector size during rollback */
53165 int pageSize; /* Number of bytes in a page */
53166 Pgno mxPgno; /* Maximum allowed size of the database */
 
53167 i64 journalSizeLimit; /* Size limit for persistent journal files */
53168 char *zFilename; /* Name of the database file */
53169 char *zJournal; /* Name of the journal file */
53170 int (*xBusyHandler)(void*); /* Function to call when busy */
53171 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
@@ -59218,12 +59218,12 @@
59218 /*
59219 ** Return the approximate number of bytes of memory currently
59220 ** used by the pager and its associated cache.
59221 */
59222 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
59223 int perPageSize = pPager->pageSize + pPager->nExtra + sizeof(PgHdr)
59224 + 5*sizeof(void*);
59225 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
59226 + sqlite3MallocSize(pPager)
59227 + pPager->pageSize;
59228 }
59229
@@ -59413,18 +59413,18 @@
59413 for(ii=nNew; ii<pPager->nSavepoint; ii++){
59414 sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
59415 }
59416 pPager->nSavepoint = nNew;
59417
59418 /* If this is a release of the outermost savepoint, truncate
59419 ** the sub-journal to zero bytes in size. */
59420 if( op==SAVEPOINT_RELEASE ){
59421 PagerSavepoint *pRel = &pPager->aSavepoint[nNew];
59422 if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){
59423 /* Only truncate if it is an in-memory sub-journal. */
59424 if( sqlite3JournalIsInMemory(pPager->sjfd) ){
59425 i64 sz = (pPager->pageSize+4)*pRel->iSubRec;
59426 rc = sqlite3OsTruncate(pPager->sjfd, sz);
59427 assert( rc==SQLITE_OK );
59428 }
59429 pPager->nSubRec = pRel->iSubRec;
59430 }
@@ -72713,10 +72713,11 @@
72713 nCell -= nTail;
72714 }
72715
72716 pData = &aData[get2byteNotZero(&aData[hdr+5])];
72717 if( pData<pBegin ) goto editpage_fail;
 
72718
72719 /* Add cells to the start of the page */
72720 if( iNew<iOld ){
72721 int nAdd = MIN(nNew,iOld-iNew);
72722 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74118,11 +74119,11 @@
74118 pBt = pPage->pBt;
74119 ovflPageSize = pBt->usableSize - 4;
74120 do{
74121 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
74122 if( rc ) return rc;
74123 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
74124 rc = SQLITE_CORRUPT_BKPT;
74125 }else{
74126 if( iOffset+ovflPageSize<(u32)nTotal ){
74127 ovflPgno = get4byte(pPage->aData);
74128 }else{
@@ -94795,10 +94796,15 @@
94795 rc = SQLITE_NOMEM_BKPT;
94796 }else if( rc==SQLITE_IOERR_CORRUPTFS ){
94797 rc = SQLITE_CORRUPT_BKPT;
94798 }
94799 assert( rc );
 
 
 
 
 
94800 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
94801 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
94802 }
94803 p->rc = rc;
94804 sqlite3SystemError(db, rc);
@@ -105161,10 +105167,11 @@
105161
105162 /***********************************************************************
105163 ** Test-only SQL functions that are only usable if enabled
105164 ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
105165 */
 
105166 case INLINEFUNC_expr_compare: {
105167 /* Compare two expressions using sqlite3ExprCompare() */
105168 assert( nFarg==2 );
105169 sqlite3VdbeAddOp2(v, OP_Integer,
105170 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
@@ -105194,11 +105201,10 @@
105194 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
105195 }
105196 break;
105197 }
105198
105199 #ifdef SQLITE_DEBUG
105200 case INLINEFUNC_affinity: {
105201 /* The AFFINITY() function evaluates to a string that describes
105202 ** the type affinity of the argument. This is used for testing of
105203 ** the SQLite type logic.
105204 */
@@ -105208,11 +105214,11 @@
105208 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
105209 sqlite3VdbeLoadString(v, target,
105210 (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
105211 break;
105212 }
105213 #endif
105214 }
105215 return target;
105216 }
105217
105218
@@ -108172,12 +108178,11 @@
108172 bQuote = sqlite3Isquote(pNew->z[0]);
108173 sqlite3NestedParse(pParse,
108174 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108175 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
108176 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
108177 " AND (type != 'index' OR tbl_name = %Q)"
108178 " AND sql NOT LIKE 'create virtual%%'",
108179 zDb,
108180 zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
108181 pTab->zName
108182 );
108183
@@ -109023,11 +109028,11 @@
109023 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109024 if( rc==SQLITE_OK ){
109025 sqlite3WalkSelect(&sWalker, pSelect);
109026 }
109027 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109028 }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){
109029 /* A regular table */
109030 int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
109031 FKey *pFKey;
109032 sCtx.pTab = sParse.pNewTable;
109033 if( bFKOnly==0 ){
@@ -120209,13 +120214,13 @@
120209 }
120210
120211 /*
120212 ** Implementation of the changes() SQL function.
120213 **
120214 ** IMP: R-62073-11209 The changes() SQL function is a wrapper
120215 ** around the sqlite3_changes64() C/C++ function and hence follows the same
120216 ** rules for counting changes.
120217 */
120218 static void changes(
120219 sqlite3_context *context,
120220 int NotUsed,
120221 sqlite3_value **NotUsed2
@@ -120234,12 +120239,12 @@
120234 int NotUsed,
120235 sqlite3_value **NotUsed2
120236 ){
120237 sqlite3 *db = sqlite3_context_db_handle(context);
120238 UNUSED_PARAMETER2(NotUsed, NotUsed2);
120239 /* IMP: R-52756-41993 This function was a wrapper around the
120240 ** sqlite3_total_changes() C/C++ interface. */
120241 sqlite3_result_int64(context, sqlite3_total_changes64(db));
120242 }
120243
120244 /*
120245 ** A structure defining how to do GLOB-style comparisons.
@@ -121761,16 +121766,16 @@
121761 **
121762 ** For peak efficiency, put the most frequently used function last.
121763 */
121764 static FuncDef aBuiltinFunc[] = {
121765 /***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
 
121766 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
121767 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
121768 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
121769 #ifdef SQLITE_DEBUG
121770 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
121771 #endif
121772 /***** Regular functions *****/
121773 #ifdef SQLITE_SOUNDEX
121774 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
121775 #endif
121776 #ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -128264,17 +128269,18 @@
128264 #define PragTyp_SECURE_DELETE 33
128265 #define PragTyp_SHRINK_MEMORY 34
128266 #define PragTyp_SOFT_HEAP_LIMIT 35
128267 #define PragTyp_SYNCHRONOUS 36
128268 #define PragTyp_TABLE_INFO 37
128269 #define PragTyp_TEMP_STORE 38
128270 #define PragTyp_TEMP_STORE_DIRECTORY 39
128271 #define PragTyp_THREADS 40
128272 #define PragTyp_WAL_AUTOCHECKPOINT 41
128273 #define PragTyp_WAL_CHECKPOINT 42
128274 #define PragTyp_LOCK_STATUS 43
128275 #define PragTyp_STATS 44
 
128276
128277 /* Property flags associated with various pragma. */
128278 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
128279 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
128280 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -128303,49 +128309,55 @@
128303 /* 11 */ "notnull",
128304 /* 12 */ "dflt_value",
128305 /* 13 */ "pk",
128306 /* 14 */ "hidden",
128307 /* table_info reuses 8 */
128308 /* 15 */ "seqno", /* Used by: index_xinfo */
128309 /* 16 */ "cid",
128310 /* 17 */ "name",
128311 /* 18 */ "desc",
128312 /* 19 */ "coll",
128313 /* 20 */ "key",
128314 /* 21 */ "name", /* Used by: function_list */
128315 /* 22 */ "builtin",
128316 /* 23 */ "type",
128317 /* 24 */ "enc",
128318 /* 25 */ "narg",
128319 /* 26 */ "flags",
128320 /* 27 */ "tbl", /* Used by: stats */
128321 /* 28 */ "idx",
128322 /* 29 */ "wdth",
128323 /* 30 */ "hght",
128324 /* 31 */ "flgs",
128325 /* 32 */ "seq", /* Used by: index_list */
128326 /* 33 */ "name",
128327 /* 34 */ "unique",
128328 /* 35 */ "origin",
128329 /* 36 */ "partial",
128330 /* 37 */ "table", /* Used by: foreign_key_check */
128331 /* 38 */ "rowid",
128332 /* 39 */ "parent",
128333 /* 40 */ "fkid",
128334 /* index_info reuses 15 */
128335 /* 41 */ "seq", /* Used by: database_list */
128336 /* 42 */ "name",
128337 /* 43 */ "file",
128338 /* 44 */ "busy", /* Used by: wal_checkpoint */
128339 /* 45 */ "log",
128340 /* 46 */ "checkpointed",
128341 /* collation_list reuses 32 */
128342 /* 47 */ "database", /* Used by: lock_status */
128343 /* 48 */ "status",
128344 /* 49 */ "cache_size", /* Used by: default_cache_size */
 
 
 
 
 
 
128345 /* module_list pragma_list reuses 9 */
128346 /* 50 */ "timeout", /* Used by: busy_timeout */
128347 };
128348
128349 /* Definitions of all built-in pragmas */
128350 typedef struct PragmaName {
128351 const char *const zName; /* Name of pragma */
@@ -128392,11 +128404,11 @@
128392 #endif
128393 #endif
128394 {/* zName: */ "busy_timeout",
128395 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
128396 /* ePragFlg: */ PragFlg_Result0,
128397 /* ColNames: */ 50, 1,
128398 /* iArg: */ 0 },
128399 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128400 {/* zName: */ "cache_size",
128401 /* ePragTyp: */ PragTyp_CACHE_SIZE,
128402 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -128431,11 +128443,11 @@
128431 #endif
128432 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128433 {/* zName: */ "collation_list",
128434 /* ePragTyp: */ PragTyp_COLLATION_LIST,
128435 /* ePragFlg: */ PragFlg_Result0,
128436 /* ColNames: */ 32, 2,
128437 /* iArg: */ 0 },
128438 #endif
128439 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
128440 {/* zName: */ "compile_options",
128441 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -128466,18 +128478,18 @@
128466 #endif
128467 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128468 {/* zName: */ "database_list",
128469 /* ePragTyp: */ PragTyp_DATABASE_LIST,
128470 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
128471 /* ColNames: */ 41, 3,
128472 /* iArg: */ 0 },
128473 #endif
128474 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
128475 {/* zName: */ "default_cache_size",
128476 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
128477 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
128478 /* ColNames: */ 49, 1,
128479 /* iArg: */ 0 },
128480 #endif
128481 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128482 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128483 {/* zName: */ "defer_foreign_keys",
@@ -128503,11 +128515,11 @@
128503 #endif
128504 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128505 {/* zName: */ "foreign_key_check",
128506 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
128507 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt,
128508 /* ColNames: */ 37, 4,
128509 /* iArg: */ 0 },
128510 #endif
128511 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
128512 {/* zName: */ "foreign_key_list",
128513 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -128546,11 +128558,11 @@
128546 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128547 #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
128548 {/* zName: */ "function_list",
128549 /* ePragTyp: */ PragTyp_FUNCTION_LIST,
128550 /* ePragFlg: */ PragFlg_Result0,
128551 /* ColNames: */ 21, 6,
128552 /* iArg: */ 0 },
128553 #endif
128554 #endif
128555 {/* zName: */ "hard_heap_limit",
128556 /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -128575,21 +128587,21 @@
128575 #endif
128576 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128577 {/* zName: */ "index_info",
128578 /* ePragTyp: */ PragTyp_INDEX_INFO,
128579 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128580 /* ColNames: */ 15, 3,
128581 /* iArg: */ 0 },
128582 {/* zName: */ "index_list",
128583 /* ePragTyp: */ PragTyp_INDEX_LIST,
128584 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128585 /* ColNames: */ 32, 5,
128586 /* iArg: */ 0 },
128587 {/* zName: */ "index_xinfo",
128588 /* ePragTyp: */ PragTyp_INDEX_INFO,
128589 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128590 /* ColNames: */ 15, 6,
128591 /* iArg: */ 1 },
128592 #endif
128593 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
128594 {/* zName: */ "integrity_check",
128595 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -128625,11 +128637,11 @@
128625 #endif
128626 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
128627 {/* zName: */ "lock_status",
128628 /* ePragTyp: */ PragTyp_LOCK_STATUS,
128629 /* ePragFlg: */ PragFlg_Result0,
128630 /* ColNames: */ 47, 2,
128631 /* iArg: */ 0 },
128632 #endif
128633 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128634 {/* zName: */ "locking_mode",
128635 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -128764,11 +128776,11 @@
128764 #endif
128765 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
128766 {/* zName: */ "stats",
128767 /* ePragTyp: */ PragTyp_STATS,
128768 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
128769 /* ColNames: */ 27, 5,
128770 /* iArg: */ 0 },
128771 #endif
128772 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128773 {/* zName: */ "synchronous",
128774 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -128780,10 +128792,15 @@
128780 {/* zName: */ "table_info",
128781 /* ePragTyp: */ PragTyp_TABLE_INFO,
128782 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128783 /* ColNames: */ 8, 6,
128784 /* iArg: */ 0 },
 
 
 
 
 
128785 {/* zName: */ "table_xinfo",
128786 /* ePragTyp: */ PragTyp_TABLE_INFO,
128787 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128788 /* ColNames: */ 8, 7,
128789 /* iArg: */ 1 },
@@ -128855,11 +128872,11 @@
128855 /* ColNames: */ 0, 0,
128856 /* iArg: */ 0 },
128857 {/* zName: */ "wal_checkpoint",
128858 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
128859 /* ePragFlg: */ PragFlg_NeedSchema,
128860 /* ColNames: */ 44, 3,
128861 /* iArg: */ 0 },
128862 #endif
128863 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128864 {/* zName: */ "writable_schema",
128865 /* ePragTyp: */ PragTyp_FLAG,
@@ -128866,11 +128883,11 @@
128866 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
128867 /* ColNames: */ 0, 0,
128868 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
128869 #endif
128870 };
128871 /* Number of pragmas: 67 on by default, 77 total. */
128872
128873 /************** End of pragma.h **********************************************/
128874 /************** Continuing where we left off in pragma.c *********************/
128875
128876 /*
@@ -130035,10 +130052,58 @@
130035 }
130036 }
130037 }
130038 break;
130039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130040 #ifdef SQLITE_DEBUG
130041 case PragTyp_STATS: {
130042 Index *pIdx;
130043 HashElem *i;
130044 pParse->nMem = 5;
@@ -130544,11 +130609,13 @@
130544 }else{
130545 integrityCheckResultRow(v);
130546 }
130547 sqlite3VdbeJumpHere(v, jmp2);
130548 }
130549 if( pTab->tabFlags & TF_Strict ){
 
 
130550 jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
130551 sqlite3StdTypeMap[pCol->eCType-1]);
130552 VdbeCoverage(v);
130553 zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
130554 sqlite3StdType[pCol->eCType-1],
@@ -132836,10 +132903,13 @@
132836
132837 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
132838 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
132839
132840 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
 
 
 
132841 if( pEq && isOuterJoin ){
132842 ExprSetProperty(pEq, EP_FromJoin);
132843 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
132844 ExprSetVVAProperty(pEq, EP_NoReduce);
132845 pEq->iRightJoinTable = pE2->iTable;
@@ -148365,11 +148435,11 @@
148365 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148366 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148367 */
148368 if( pLeft->op!=TK_COLUMN
148369 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148370 || IsVirtual(pLeft->y.pTab) /* Value might be numeric */
148371 ){
148372 int isNum;
148373 double rDummy;
148374 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148375 if( isNum<=0 ){
@@ -156490,10 +156560,13 @@
156490 );
156491 SELECTTRACE(1,pParse,pSub,
156492 ("New window-function subquery in FROM clause of (%u/%p)\n",
156493 p->selId, p));
156494 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
 
 
 
156495 if( p->pSrc ){
156496 Table *pTab2;
156497 p->pSrc->a[0].pSelect = pSub;
156498 sqlite3SrcListAssignCursors(pParse, p->pSrc);
156499 pSub->selFlags |= SF_Expanded|SF_OrderByReqd;
@@ -192908,11 +192981,15 @@
192908 #else
192909 /* #include "sqlite3.h" */
192910 #endif
192911 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
192912
192913 #ifndef SQLITE_AMALGAMATION
 
 
 
 
192914 #include "sqlite3rtree.h"
192915 typedef sqlite3_int64 i64;
192916 typedef sqlite3_uint64 u64;
192917 typedef unsigned char u8;
192918 typedef unsigned short u16;
@@ -192921,11 +192998,21 @@
192921 # define NDEBUG 1
192922 #endif
192923 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
192924 # undef NDEBUG
192925 #endif
 
 
 
 
 
 
 
 
 
192926 #endif
 
192927
192928 /* #include <string.h> */
192929 /* #include <stdio.h> */
192930 /* #include <assert.h> */
192931 /* #include <stdlib.h> */
@@ -192979,11 +193066,13 @@
192979 u8 nDim2; /* Twice the number of dimensions */
192980 u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
192981 u8 nBytesPerCell; /* Bytes consumed per cell */
192982 u8 inWrTrans; /* True if inside write transaction */
192983 u8 nAux; /* # of auxiliary columns in %_rowid */
 
192984 u8 nAuxNotNull; /* Number of initial not-null aux columns */
 
192985 #ifdef SQLITE_DEBUG
192986 u8 bCorrupt; /* Shadow table corruption detected */
192987 #endif
192988 int iDepth; /* Current depth of the r-tree structure */
192989 char *zDb; /* Name of database containing r-tree table */
@@ -193510,22 +193599,10 @@
193510 pRtree->pNodeBlob = 0;
193511 sqlite3_blob_close(pBlob);
193512 }
193513 }
193514
193515 /*
193516 ** Check to see if pNode is the same as pParent or any of the parents
193517 ** of pParent.
193518 */
193519 static int nodeInParentChain(const RtreeNode *pNode, const RtreeNode *pParent){
193520 do{
193521 if( pNode==pParent ) return 1;
193522 pParent = pParent->pParent;
193523 }while( pParent );
193524 return 0;
193525 }
193526
193527 /*
193528 ** Obtain a reference to an r-tree node.
193529 */
193530 static int nodeAcquire(
193531 Rtree *pRtree, /* R-tree structure */
@@ -193538,18 +193615,11 @@
193538
193539 /* Check if the requested node is already in the hash table. If so,
193540 ** increase its reference count and return it.
193541 */
193542 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
193543 if( pParent && !pNode->pParent ){
193544 if( nodeInParentChain(pNode, pParent) ){
193545 RTREE_IS_CORRUPT(pRtree);
193546 return SQLITE_CORRUPT_VTAB;
193547 }
193548 pParent->nRef++;
193549 pNode->pParent = pParent;
193550 }else if( pParent && pNode->pParent && pParent!=pNode->pParent ){
193551 RTREE_IS_CORRUPT(pRtree);
193552 return SQLITE_CORRUPT_VTAB;
193553 }
193554 pNode->nRef++;
193555 *ppNode = pNode;
@@ -193603,11 +193673,11 @@
193603 ** of the r-tree structure. A height of zero means all data is stored on
193604 ** the root node. A height of one means the children of the root node
193605 ** are the leaves, and so on. If the depth as specified on the root node
193606 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
193607 */
193608 if( pNode && rc==SQLITE_OK && iNode==1 ){
193609 pRtree->iDepth = readInt16(pNode->zData);
193610 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
193611 rc = SQLITE_CORRUPT_VTAB;
193612 RTREE_IS_CORRUPT(pRtree);
193613 }
@@ -194209,15 +194279,16 @@
194209 ** Return the index of the cell containing a pointer to node pNode
194210 ** in its parent. If pNode is the root node, return -1.
194211 */
194212 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
194213 RtreeNode *pParent = pNode->pParent;
194214 if( pParent ){
194215 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
 
 
 
194216 }
194217 *piIndex = -1;
194218 return SQLITE_OK;
194219 }
194220
194221 /*
194222 ** Compare two search points. Return negative, zero, or positive if the first
194223 ** is less than, equal to, or greater than the second.
@@ -194336,11 +194407,12 @@
194336 if( pCur->bPoint ){
194337 int ii;
194338 pNew = rtreeEnqueue(pCur, rScore, iLevel);
194339 if( pNew==0 ) return 0;
194340 ii = (int)(pNew - pCur->aPoint) + 1;
194341 if( ii<RTREE_CACHE_SZ ){
 
194342 assert( pCur->aNode[ii]==0 );
194343 pCur->aNode[ii] = pCur->aNode[0];
194344 }else{
194345 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
194346 }
@@ -194397,11 +194469,11 @@
194397 p->aNode[i] = 0;
194398 }
194399 if( p->bPoint ){
194400 p->anQueue[p->sPoint.iLevel]--;
194401 p->bPoint = 0;
194402 }else if( p->nPoint ){
194403 p->anQueue[p->aPoint[0].iLevel]--;
194404 n = --p->nPoint;
194405 p->aPoint[0] = p->aPoint[n];
194406 if( n<RTREE_CACHE_SZ-1 ){
194407 p->aNode[1] = p->aNode[n+1];
@@ -194538,11 +194610,11 @@
194538 static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
194539 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
194540 RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
194541 int rc = SQLITE_OK;
194542 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194543 if( rc==SQLITE_OK && p ){
194544 *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
194545 }
194546 return rc;
194547 }
194548
@@ -194556,11 +194628,11 @@
194556 RtreeCoord c;
194557 int rc = SQLITE_OK;
194558 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194559
194560 if( rc ) return rc;
194561 if( p==0 ) return SQLITE_OK;
194562 if( i==0 ){
194563 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
194564 }else if( i<=pRtree->nDim2 ){
194565 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
194566 #ifndef SQLITE_RTREE_INT_ONLY
@@ -194755,12 +194827,15 @@
194755 }
194756 }
194757 }
194758 if( rc==SQLITE_OK ){
194759 RtreeSearchPoint *pNew;
 
194760 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
194761 if( pNew==0 ) return SQLITE_NOMEM;
 
 
194762 pNew->id = 1;
194763 pNew->iCell = 0;
194764 pNew->eWithin = PARTLY_WITHIN;
194765 assert( pCsr->bPoint==1 );
194766 pCsr->aNode[0] = pRoot;
@@ -194833,11 +194908,11 @@
194833 assert( pIdxInfo->idxStr==0 );
194834 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
194835 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
194836
194837 if( bMatch==0 && p->usable
194838 && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
194839 ){
194840 /* We have an equality constraint on the rowid. Use strategy 1. */
194841 int jj;
194842 for(jj=0; jj<ii; jj++){
194843 pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
@@ -195086,16 +195161,23 @@
195086 RtreeNode *pNode, /* Adjust ancestry of this node. */
195087 RtreeCell *pCell /* This cell was just inserted */
195088 ){
195089 RtreeNode *p = pNode;
195090 int cnt = 0;
 
195091 while( p->pParent ){
195092 RtreeNode *pParent = p->pParent;
195093 RtreeCell cell;
195094 int iCell;
195095
195096 if( (++cnt)>1000 || nodeParentIndex(pRtree, p, &iCell) ){
 
 
 
 
 
 
195097 RTREE_IS_CORRUPT(pRtree);
195098 return SQLITE_CORRUPT_VTAB;
195099 }
195100
195101 nodeGetCell(pRtree, pParent, iCell, &cell);
@@ -195475,15 +195557,16 @@
195475 }
195476 }else{
195477 RtreeNode *pParent = pLeft->pParent;
195478 int iCell;
195479 rc = nodeParentIndex(pRtree, pLeft, &iCell);
195480 if( rc==SQLITE_OK ){
195481 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
195482 rc = AdjustTree(pRtree, pParent, &leftbbox);
 
195483 }
195484 if( rc!=SQLITE_OK ){
195485 goto splitnode_out;
195486 }
195487 }
195488 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
195489 goto splitnode_out;
@@ -195554,11 +195637,11 @@
195554 ** want to do this as it leads to a memory leak when trying to delete
195555 ** the referenced counted node structures.
195556 */
195557 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
195558 for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
195559 if( !pTest ){
195560 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
195561 }
195562 }
195563 rc = sqlite3_reset(pRtree->pReadParent);
195564 if( rc==SQLITE_OK ) rc = rc2;
@@ -195585,10 +195668,11 @@
195585 rc = nodeParentIndex(pRtree, pNode, &iCell);
195586 if( rc==SQLITE_OK ){
195587 pParent = pNode->pParent;
195588 pNode->pParent = 0;
195589 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
 
195590 }
195591 rc2 = nodeRelease(pRtree, pParent);
195592 if( rc==SQLITE_OK ){
195593 rc = rc2;
195594 }
@@ -195807,11 +195891,11 @@
195807 pRtree->iReinsertHeight = iHeight;
195808 rc = Reinsert(pRtree, pNode, pCell, iHeight);
195809 }
195810 }else{
195811 rc = AdjustTree(pRtree, pNode, pCell);
195812 if( rc==SQLITE_OK ){
195813 if( iHeight==0 ){
195814 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
195815 }else{
195816 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
195817 }
@@ -195913,11 +195997,11 @@
195913 */
195914 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
195915 int rc2;
195916 RtreeNode *pChild = 0;
195917 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
195918 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
195919 if( rc==SQLITE_OK ){
195920 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
195921 }
195922 rc2 = nodeRelease(pRtree, pChild);
195923 if( rc==SQLITE_OK ) rc = rc2;
@@ -196248,11 +196332,11 @@
196248 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
196249 const char *zFmt = "SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'";
196250 char *zSql;
196251 sqlite3_stmt *p;
196252 int rc;
196253 i64 nRow = 0;
196254
196255 rc = sqlite3_table_column_metadata(
196256 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
196257 );
196258 if( rc!=SQLITE_OK ){
@@ -196265,24 +196349,14 @@
196265 }else{
196266 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
196267 if( rc==SQLITE_OK ){
196268 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
196269 rc = sqlite3_finalize(p);
196270 }else if( rc!=SQLITE_NOMEM ){
196271 rc = SQLITE_OK;
196272 }
196273
196274 if( rc==SQLITE_OK ){
196275 if( nRow==0 ){
196276 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
196277 }else{
196278 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
196279 }
196280 }
196281 sqlite3_free(zSql);
196282 }
196283
196284 return rc;
196285 }
196286
196287
196288 /*
@@ -196428,13 +196502,16 @@
196428 int ii;
196429 char *zSql;
196430 sqlite3_str_appendf(p, "UPDATE \"%w\".\"%w_rowid\"SET ", zDb, zPrefix);
196431 for(ii=0; ii<pRtree->nAux; ii++){
196432 if( ii ) sqlite3_str_append(p, ",", 1);
 
196433 if( ii<pRtree->nAuxNotNull ){
196434 sqlite3_str_appendf(p,"a%d=coalesce(?%d,a%d)",ii,ii+2,ii);
196435 }else{
 
 
196436 sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
196437 }
196438 }
196439 sqlite3_str_appendf(p, " WHERE rowid=?1");
196440 zSql = sqlite3_str_finish(p);
@@ -197109,12 +197186,14 @@
197109 if( check.rc==SQLITE_OK ){
197110 pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.'%q_rowid'", zDb, zTab);
197111 if( pStmt ){
197112 nAux = sqlite3_column_count(pStmt) - 2;
197113 sqlite3_finalize(pStmt);
 
 
 
197114 }
197115 check.rc = SQLITE_OK;
197116 }
197117
197118 /* Find number of dimensions in the rtree table. */
197119 pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.%Q", zDb, zTab);
197120 if( pStmt ){
@@ -199185,11 +199264,14 @@
199185 ){
199186 RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */
199187
199188 /* Allocate and populate the context object. */
199189 pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
199190 if( !pGeomCtx ) return SQLITE_NOMEM;
 
 
 
199191 pGeomCtx->xGeom = 0;
199192 pGeomCtx->xQueryFunc = xQueryFunc;
199193 pGeomCtx->xDestructor = xDestructor;
199194 pGeomCtx->pContext = pContext;
199195 return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
@@ -222468,10 +222550,46 @@
222468 if( p->pStruct!=(Fts5Structure*)pStruct ){
222469 return SQLITE_ABORT;
222470 }
222471 return SQLITE_OK;
222472 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222473
222474 /*
222475 ** Deserialize and return the structure record currently stored in serialized
222476 ** form within buffer pData/nData.
222477 **
@@ -222570,13 +222688,15 @@
222570 *ppOut = pRet;
222571 return rc;
222572 }
222573
222574 /*
222575 **
 
222576 */
222577 static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
 
222578 if( *pRc==SQLITE_OK ){
222579 Fts5Structure *pStruct = *ppStruct;
222580 int nLevel = pStruct->nLevel;
222581 sqlite3_int64 nByte = (
222582 sizeof(Fts5Structure) + /* Main structure */
@@ -231175,11 +231295,11 @@
231175 int nArg, /* Number of args */
231176 sqlite3_value **apUnused /* Function arguments */
231177 ){
231178 assert( nArg==0 );
231179 UNUSED_PARAM2(nArg, apUnused);
231180 sqlite3_result_text(pCtx, "fts5: 2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1", -1, SQLITE_TRANSIENT);
231181 }
231182
231183 /*
231184 ** Return true if zName is the extension on one of the shadow tables used
231185 ** by this module.
231186
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19842,11 +19842,11 @@
19842 #ifdef SQLITE_TEST
19843 SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char*);
19844 #endif
19845
19846 #ifdef SQLITE_OMIT_VIRTUALTABLE
19847 # define sqlite3VtabClear(D,T)
19848 # define sqlite3VtabSync(X,Y) SQLITE_OK
19849 # define sqlite3VtabRollback(X)
19850 # define sqlite3VtabCommit(X)
19851 # define sqlite3VtabInSync(db) 0
19852 # define sqlite3VtabLock(X)
@@ -48856,11 +48856,11 @@
48856 MemStore *p = 0;
48857 int szName;
48858 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48859 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
48860 }
48861 memset(pFile, 0, sizeof(*pFile));
48862 szName = sqlite3Strlen30(zName);
48863 if( szName>1 && zName[0]=='/' ){
48864 int i;
48865 #ifndef SQLITE_MUTEX_OMIT
48866 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
@@ -53160,12 +53160,12 @@
53160
53161 u16 nExtra; /* Add this many bytes to each in-memory page */
53162 i16 nReserve; /* Number of unused bytes at end of each page */
53163 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
53164 u32 sectorSize; /* Assumed sector size during rollback */
 
53165 Pgno mxPgno; /* Maximum allowed size of the database */
53166 i64 pageSize; /* Number of bytes in a page */
53167 i64 journalSizeLimit; /* Size limit for persistent journal files */
53168 char *zFilename; /* Name of the database file */
53169 char *zJournal; /* Name of the journal file */
53170 int (*xBusyHandler)(void*); /* Function to call when busy */
53171 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
@@ -59218,12 +59218,12 @@
59218 /*
59219 ** Return the approximate number of bytes of memory currently
59220 ** used by the pager and its associated cache.
59221 */
59222 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
59223 int perPageSize = pPager->pageSize + pPager->nExtra
59224 + (int)(sizeof(PgHdr) + 5*sizeof(void*));
59225 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
59226 + sqlite3MallocSize(pPager)
59227 + pPager->pageSize;
59228 }
59229
@@ -59413,18 +59413,18 @@
59413 for(ii=nNew; ii<pPager->nSavepoint; ii++){
59414 sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
59415 }
59416 pPager->nSavepoint = nNew;
59417
59418 /* Truncate the sub-journal so that it only includes the parts
59419 ** that are still in use. */
59420 if( op==SAVEPOINT_RELEASE ){
59421 PagerSavepoint *pRel = &pPager->aSavepoint[nNew];
59422 if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){
59423 /* Only truncate if it is an in-memory sub-journal. */
59424 if( sqlite3JournalIsInMemory(pPager->sjfd) ){
59425 i64 sz = (pPager->pageSize+4)*(i64)pRel->iSubRec;
59426 rc = sqlite3OsTruncate(pPager->sjfd, sz);
59427 assert( rc==SQLITE_OK );
59428 }
59429 pPager->nSubRec = pRel->iSubRec;
59430 }
@@ -72713,10 +72713,11 @@
72713 nCell -= nTail;
72714 }
72715
72716 pData = &aData[get2byteNotZero(&aData[hdr+5])];
72717 if( pData<pBegin ) goto editpage_fail;
72718 if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
72719
72720 /* Add cells to the start of the page */
72721 if( iNew<iOld ){
72722 int nAdd = MIN(nNew,iOld-iNew);
72723 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74118,11 +74119,11 @@
74119 pBt = pPage->pBt;
74120 ovflPageSize = pBt->usableSize - 4;
74121 do{
74122 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
74123 if( rc ) return rc;
74124 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
74125 rc = SQLITE_CORRUPT_BKPT;
74126 }else{
74127 if( iOffset+ovflPageSize<(u32)nTotal ){
74128 ovflPgno = get4byte(pPage->aData);
74129 }else{
@@ -94795,10 +94796,15 @@
94796 rc = SQLITE_NOMEM_BKPT;
94797 }else if( rc==SQLITE_IOERR_CORRUPTFS ){
94798 rc = SQLITE_CORRUPT_BKPT;
94799 }
94800 assert( rc );
94801 #ifdef SQLITE_DEBUG
94802 if( db->flags & SQLITE_VdbeTrace ){
94803 printf("ABORT-due-to-error. rc=%d\n", rc);
94804 }
94805 #endif
94806 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
94807 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
94808 }
94809 p->rc = rc;
94810 sqlite3SystemError(db, rc);
@@ -105161,10 +105167,11 @@
105167
105168 /***********************************************************************
105169 ** Test-only SQL functions that are only usable if enabled
105170 ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
105171 */
105172 #if !defined(SQLITE_UNTESTABLE)
105173 case INLINEFUNC_expr_compare: {
105174 /* Compare two expressions using sqlite3ExprCompare() */
105175 assert( nFarg==2 );
105176 sqlite3VdbeAddOp2(v, OP_Integer,
105177 sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
@@ -105194,11 +105201,10 @@
105201 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
105202 }
105203 break;
105204 }
105205
 
105206 case INLINEFUNC_affinity: {
105207 /* The AFFINITY() function evaluates to a string that describes
105208 ** the type affinity of the argument. This is used for testing of
105209 ** the SQLite type logic.
105210 */
@@ -105208,11 +105214,11 @@
105214 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
105215 sqlite3VdbeLoadString(v, target,
105216 (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
105217 break;
105218 }
105219 #endif /* !defined(SQLITE_UNTESTABLE) */
105220 }
105221 return target;
105222 }
105223
105224
@@ -108172,12 +108178,11 @@
108178 bQuote = sqlite3Isquote(pNew->z[0]);
108179 sqlite3NestedParse(pParse,
108180 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108181 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
108182 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
108183 " AND (type != 'index' OR tbl_name = %Q)",
 
108184 zDb,
108185 zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
108186 pTab->zName
108187 );
108188
@@ -109023,11 +109028,11 @@
109028 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
109029 if( rc==SQLITE_OK ){
109030 sqlite3WalkSelect(&sWalker, pSelect);
109031 }
109032 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
109033 }else if( IsOrdinaryTable(sParse.pNewTable) ){
109034 /* A regular table */
109035 int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
109036 FKey *pFKey;
109037 sCtx.pTab = sParse.pNewTable;
109038 if( bFKOnly==0 ){
@@ -120209,13 +120214,13 @@
120214 }
120215
120216 /*
120217 ** Implementation of the changes() SQL function.
120218 **
120219 ** IMP: R-32760-32347 The changes() SQL function is a wrapper
120220 ** around the sqlite3_changes64() C/C++ function and hence follows the
120221 ** same rules for counting changes.
120222 */
120223 static void changes(
120224 sqlite3_context *context,
120225 int NotUsed,
120226 sqlite3_value **NotUsed2
@@ -120234,12 +120239,12 @@
120239 int NotUsed,
120240 sqlite3_value **NotUsed2
120241 ){
120242 sqlite3 *db = sqlite3_context_db_handle(context);
120243 UNUSED_PARAMETER2(NotUsed, NotUsed2);
120244 /* IMP: R-11217-42568 This function is a wrapper around the
120245 ** sqlite3_total_changes64() C/C++ interface. */
120246 sqlite3_result_int64(context, sqlite3_total_changes64(db));
120247 }
120248
120249 /*
120250 ** A structure defining how to do GLOB-style comparisons.
@@ -121761,16 +121766,16 @@
121766 **
121767 ** For peak efficiency, put the most frequently used function last.
121768 */
121769 static FuncDef aBuiltinFunc[] = {
121770 /***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
121771 #if !defined(SQLITE_UNTESTABLE)
121772 TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
121773 TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
121774 TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
121775 TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
121776 #endif /* !defined(SQLITE_UNTESTABLE) */
 
121777 /***** Regular functions *****/
121778 #ifdef SQLITE_SOUNDEX
121779 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
121780 #endif
121781 #ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -128264,17 +128269,18 @@
128269 #define PragTyp_SECURE_DELETE 33
128270 #define PragTyp_SHRINK_MEMORY 34
128271 #define PragTyp_SOFT_HEAP_LIMIT 35
128272 #define PragTyp_SYNCHRONOUS 36
128273 #define PragTyp_TABLE_INFO 37
128274 #define PragTyp_TABLE_LIST 38
128275 #define PragTyp_TEMP_STORE 39
128276 #define PragTyp_TEMP_STORE_DIRECTORY 40
128277 #define PragTyp_THREADS 41
128278 #define PragTyp_WAL_AUTOCHECKPOINT 42
128279 #define PragTyp_WAL_CHECKPOINT 43
128280 #define PragTyp_LOCK_STATUS 44
128281 #define PragTyp_STATS 45
128282
128283 /* Property flags associated with various pragma. */
128284 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
128285 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
128286 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -128303,49 +128309,55 @@
128309 /* 11 */ "notnull",
128310 /* 12 */ "dflt_value",
128311 /* 13 */ "pk",
128312 /* 14 */ "hidden",
128313 /* table_info reuses 8 */
128314 /* 15 */ "schema", /* Used by: table_list */
128315 /* 16 */ "name",
128316 /* 17 */ "type",
128317 /* 18 */ "ncol",
128318 /* 19 */ "wr",
128319 /* 20 */ "strict",
128320 /* 21 */ "seqno", /* Used by: index_xinfo */
128321 /* 22 */ "cid",
128322 /* 23 */ "name",
128323 /* 24 */ "desc",
128324 /* 25 */ "coll",
128325 /* 26 */ "key",
128326 /* 27 */ "name", /* Used by: function_list */
128327 /* 28 */ "builtin",
128328 /* 29 */ "type",
128329 /* 30 */ "enc",
128330 /* 31 */ "narg",
128331 /* 32 */ "flags",
128332 /* 33 */ "tbl", /* Used by: stats */
128333 /* 34 */ "idx",
128334 /* 35 */ "wdth",
128335 /* 36 */ "hght",
128336 /* 37 */ "flgs",
128337 /* 38 */ "seq", /* Used by: index_list */
128338 /* 39 */ "name",
128339 /* 40 */ "unique",
128340 /* 41 */ "origin",
128341 /* 42 */ "partial",
128342 /* 43 */ "table", /* Used by: foreign_key_check */
128343 /* 44 */ "rowid",
128344 /* 45 */ "parent",
128345 /* 46 */ "fkid",
128346 /* index_info reuses 21 */
128347 /* 47 */ "seq", /* Used by: database_list */
128348 /* 48 */ "name",
128349 /* 49 */ "file",
128350 /* 50 */ "busy", /* Used by: wal_checkpoint */
128351 /* 51 */ "log",
128352 /* 52 */ "checkpointed",
128353 /* collation_list reuses 38 */
128354 /* 53 */ "database", /* Used by: lock_status */
128355 /* 54 */ "status",
128356 /* 55 */ "cache_size", /* Used by: default_cache_size */
128357 /* module_list pragma_list reuses 9 */
128358 /* 56 */ "timeout", /* Used by: busy_timeout */
128359 };
128360
128361 /* Definitions of all built-in pragmas */
128362 typedef struct PragmaName {
128363 const char *const zName; /* Name of pragma */
@@ -128392,11 +128404,11 @@
128404 #endif
128405 #endif
128406 {/* zName: */ "busy_timeout",
128407 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
128408 /* ePragFlg: */ PragFlg_Result0,
128409 /* ColNames: */ 56, 1,
128410 /* iArg: */ 0 },
128411 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128412 {/* zName: */ "cache_size",
128413 /* ePragTyp: */ PragTyp_CACHE_SIZE,
128414 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -128431,11 +128443,11 @@
128443 #endif
128444 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128445 {/* zName: */ "collation_list",
128446 /* ePragTyp: */ PragTyp_COLLATION_LIST,
128447 /* ePragFlg: */ PragFlg_Result0,
128448 /* ColNames: */ 38, 2,
128449 /* iArg: */ 0 },
128450 #endif
128451 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
128452 {/* zName: */ "compile_options",
128453 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -128466,18 +128478,18 @@
128478 #endif
128479 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128480 {/* zName: */ "database_list",
128481 /* ePragTyp: */ PragTyp_DATABASE_LIST,
128482 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
128483 /* ColNames: */ 47, 3,
128484 /* iArg: */ 0 },
128485 #endif
128486 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
128487 {/* zName: */ "default_cache_size",
128488 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
128489 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
128490 /* ColNames: */ 55, 1,
128491 /* iArg: */ 0 },
128492 #endif
128493 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128494 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128495 {/* zName: */ "defer_foreign_keys",
@@ -128503,11 +128515,11 @@
128515 #endif
128516 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
128517 {/* zName: */ "foreign_key_check",
128518 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
128519 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt,
128520 /* ColNames: */ 43, 4,
128521 /* iArg: */ 0 },
128522 #endif
128523 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
128524 {/* zName: */ "foreign_key_list",
128525 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
@@ -128546,11 +128558,11 @@
128558 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128559 #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
128560 {/* zName: */ "function_list",
128561 /* ePragTyp: */ PragTyp_FUNCTION_LIST,
128562 /* ePragFlg: */ PragFlg_Result0,
128563 /* ColNames: */ 27, 6,
128564 /* iArg: */ 0 },
128565 #endif
128566 #endif
128567 {/* zName: */ "hard_heap_limit",
128568 /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT,
@@ -128575,21 +128587,21 @@
128587 #endif
128588 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
128589 {/* zName: */ "index_info",
128590 /* ePragTyp: */ PragTyp_INDEX_INFO,
128591 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128592 /* ColNames: */ 21, 3,
128593 /* iArg: */ 0 },
128594 {/* zName: */ "index_list",
128595 /* ePragTyp: */ PragTyp_INDEX_LIST,
128596 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128597 /* ColNames: */ 38, 5,
128598 /* iArg: */ 0 },
128599 {/* zName: */ "index_xinfo",
128600 /* ePragTyp: */ PragTyp_INDEX_INFO,
128601 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128602 /* ColNames: */ 21, 6,
128603 /* iArg: */ 1 },
128604 #endif
128605 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
128606 {/* zName: */ "integrity_check",
128607 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -128625,11 +128637,11 @@
128637 #endif
128638 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
128639 {/* zName: */ "lock_status",
128640 /* ePragTyp: */ PragTyp_LOCK_STATUS,
128641 /* ePragFlg: */ PragFlg_Result0,
128642 /* ColNames: */ 53, 2,
128643 /* iArg: */ 0 },
128644 #endif
128645 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128646 {/* zName: */ "locking_mode",
128647 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -128764,11 +128776,11 @@
128776 #endif
128777 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
128778 {/* zName: */ "stats",
128779 /* ePragTyp: */ PragTyp_STATS,
128780 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
128781 /* ColNames: */ 33, 5,
128782 /* iArg: */ 0 },
128783 #endif
128784 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
128785 {/* zName: */ "synchronous",
128786 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -128780,10 +128792,15 @@
128792 {/* zName: */ "table_info",
128793 /* ePragTyp: */ PragTyp_TABLE_INFO,
128794 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128795 /* ColNames: */ 8, 6,
128796 /* iArg: */ 0 },
128797 {/* zName: */ "table_list",
128798 /* ePragTyp: */ PragTyp_TABLE_LIST,
128799 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1,
128800 /* ColNames: */ 15, 6,
128801 /* iArg: */ 1 },
128802 {/* zName: */ "table_xinfo",
128803 /* ePragTyp: */ PragTyp_TABLE_INFO,
128804 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
128805 /* ColNames: */ 8, 7,
128806 /* iArg: */ 1 },
@@ -128855,11 +128872,11 @@
128872 /* ColNames: */ 0, 0,
128873 /* iArg: */ 0 },
128874 {/* zName: */ "wal_checkpoint",
128875 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
128876 /* ePragFlg: */ PragFlg_NeedSchema,
128877 /* ColNames: */ 50, 3,
128878 /* iArg: */ 0 },
128879 #endif
128880 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
128881 {/* zName: */ "writable_schema",
128882 /* ePragTyp: */ PragTyp_FLAG,
@@ -128866,11 +128883,11 @@
128883 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
128884 /* ColNames: */ 0, 0,
128885 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
128886 #endif
128887 };
128888 /* Number of pragmas: 68 on by default, 78 total. */
128889
128890 /************** End of pragma.h **********************************************/
128891 /************** Continuing where we left off in pragma.c *********************/
128892
128893 /*
@@ -130035,10 +130052,58 @@
130052 }
130053 }
130054 }
130055 break;
130056
130057 /*
130058 ** PRAGMA table_list
130059 **
130060 ** Return a single row for each table, virtual table, or view in the
130061 ** entire schema.
130062 **
130063 ** schema: Name of attached database hold this table
130064 ** name: Name of the table itself
130065 ** type: "table", "view", "virtual", "shadow"
130066 ** ncol: Number of columns
130067 ** wr: True for a WITHOUT ROWID table
130068 ** strict: True for a STRICT table
130069 */
130070 case PragTyp_TABLE_LIST: {
130071 int ii;
130072 pParse->nMem = 6;
130073 sqlite3CodeVerifyNamedSchema(pParse, zDb);
130074 for(ii=0; ii<db->nDb; ii++){
130075 HashElem *k;
130076 Hash *pHash;
130077 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130078 pHash = &db->aDb[ii].pSchema->tblHash;
130079 for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130080 Table *pTab = sqliteHashData(k);
130081 const char *zType;
130082 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130083 if( IsView(pTab) ){
130084 zType = "view";
130085 }else if( IsVirtual(pTab) ){
130086 zType = "virtual";
130087 }else if( pTab->tabFlags & TF_Shadow ){
130088 zType = "shadow";
130089 }else{
130090 zType = "table";
130091 }
130092 sqlite3VdbeMultiLoad(v, 1, "sssiii",
130093 db->aDb[ii].zDbSName,
130094 pTab->zName,
130095 zType,
130096 pTab->nCol,
130097 (pTab->tabFlags & TF_WithoutRowid)!=0,
130098 (pTab->tabFlags & TF_Strict)!=0
130099 );
130100 }
130101 }
130102 }
130103 break;
130104
130105 #ifdef SQLITE_DEBUG
130106 case PragTyp_STATS: {
130107 Index *pIdx;
130108 HashElem *i;
130109 pParse->nMem = 5;
@@ -130544,11 +130609,13 @@
130609 }else{
130610 integrityCheckResultRow(v);
130611 }
130612 sqlite3VdbeJumpHere(v, jmp2);
130613 }
130614 if( (pTab->tabFlags & TF_Strict)!=0
130615 && pCol->eCType!=COLTYPE_ANY
130616 ){
130617 jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
130618 sqlite3StdTypeMap[pCol->eCType-1]);
130619 VdbeCoverage(v);
130620 zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
130621 sqlite3StdType[pCol->eCType-1],
@@ -132836,10 +132903,13 @@
132903
132904 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
132905 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
132906
132907 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
132908 assert( pE2!=0 || pEq==0 ); /* Due to db->mallocFailed test
132909 ** in sqlite3DbMallocRawNN() called from
132910 ** sqlite3PExpr(). */
132911 if( pEq && isOuterJoin ){
132912 ExprSetProperty(pEq, EP_FromJoin);
132913 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
132914 ExprSetVVAProperty(pEq, EP_NoReduce);
132915 pEq->iRightJoinTable = pE2->iTable;
@@ -148365,11 +148435,11 @@
148435 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148436 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148437 */
148438 if( pLeft->op!=TK_COLUMN
148439 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148440 || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148441 ){
148442 int isNum;
148443 double rDummy;
148444 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148445 if( isNum<=0 ){
@@ -156490,10 +156560,13 @@
156560 );
156561 SELECTTRACE(1,pParse,pSub,
156562 ("New window-function subquery in FROM clause of (%u/%p)\n",
156563 p->selId, p));
156564 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
156565 assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
156566 ** of sqlite3DbMallocRawNN() called from
156567 ** sqlite3SrcListAppend() */
156568 if( p->pSrc ){
156569 Table *pTab2;
156570 p->pSrc->a[0].pSelect = pSub;
156571 sqlite3SrcListAssignCursors(pParse, p->pSrc);
156572 pSub->selFlags |= SF_Expanded|SF_OrderByReqd;
@@ -192908,11 +192981,15 @@
192981 #else
192982 /* #include "sqlite3.h" */
192983 #endif
192984 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
192985
192986 /*
192987 ** If building separately, we will need some setup that is normally
192988 ** found in sqliteInt.h
192989 */
192990 #if !defined(SQLITE_AMALGAMATION)
192991 #include "sqlite3rtree.h"
192992 typedef sqlite3_int64 i64;
192993 typedef sqlite3_uint64 u64;
192994 typedef unsigned char u8;
192995 typedef unsigned short u16;
@@ -192921,11 +192998,21 @@
192998 # define NDEBUG 1
192999 #endif
193000 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
193001 # undef NDEBUG
193002 #endif
193003 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
193004 # define ALWAYS(X) (1)
193005 # define NEVER(X) (0)
193006 #elif !defined(NDEBUG)
193007 # define ALWAYS(X) ((X)?1:(assert(0),0))
193008 # define NEVER(X) ((X)?(assert(0),1):0)
193009 #else
193010 # define ALWAYS(X) (X)
193011 # define NEVER(X) (X)
193012 #endif
193013 #endif /* !defined(SQLITE_AMALGAMATION) */
193014
193015 /* #include <string.h> */
193016 /* #include <stdio.h> */
193017 /* #include <assert.h> */
193018 /* #include <stdlib.h> */
@@ -192979,11 +193066,13 @@
193066 u8 nDim2; /* Twice the number of dimensions */
193067 u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
193068 u8 nBytesPerCell; /* Bytes consumed per cell */
193069 u8 inWrTrans; /* True if inside write transaction */
193070 u8 nAux; /* # of auxiliary columns in %_rowid */
193071 #ifdef SQLITE_ENABLE_GEOPOLY
193072 u8 nAuxNotNull; /* Number of initial not-null aux columns */
193073 #endif
193074 #ifdef SQLITE_DEBUG
193075 u8 bCorrupt; /* Shadow table corruption detected */
193076 #endif
193077 int iDepth; /* Current depth of the r-tree structure */
193078 char *zDb; /* Name of database containing r-tree table */
@@ -193510,22 +193599,10 @@
193599 pRtree->pNodeBlob = 0;
193600 sqlite3_blob_close(pBlob);
193601 }
193602 }
193603
 
 
 
 
 
 
 
 
 
 
 
 
193604 /*
193605 ** Obtain a reference to an r-tree node.
193606 */
193607 static int nodeAcquire(
193608 Rtree *pRtree, /* R-tree structure */
@@ -193538,18 +193615,11 @@
193615
193616 /* Check if the requested node is already in the hash table. If so,
193617 ** increase its reference count and return it.
193618 */
193619 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
193620 if( pParent && pParent!=pNode->pParent ){
 
 
 
 
 
 
 
193621 RTREE_IS_CORRUPT(pRtree);
193622 return SQLITE_CORRUPT_VTAB;
193623 }
193624 pNode->nRef++;
193625 *ppNode = pNode;
@@ -193603,11 +193673,11 @@
193673 ** of the r-tree structure. A height of zero means all data is stored on
193674 ** the root node. A height of one means the children of the root node
193675 ** are the leaves, and so on. If the depth as specified on the root node
193676 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
193677 */
193678 if( rc==SQLITE_OK && pNode && iNode==1 ){
193679 pRtree->iDepth = readInt16(pNode->zData);
193680 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
193681 rc = SQLITE_CORRUPT_VTAB;
193682 RTREE_IS_CORRUPT(pRtree);
193683 }
@@ -194209,15 +194279,16 @@
194279 ** Return the index of the cell containing a pointer to node pNode
194280 ** in its parent. If pNode is the root node, return -1.
194281 */
194282 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
194283 RtreeNode *pParent = pNode->pParent;
194284 if( ALWAYS(pParent) ){
194285 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
194286 }else{
194287 *piIndex = -1;
194288 return SQLITE_OK;
194289 }
 
 
194290 }
194291
194292 /*
194293 ** Compare two search points. Return negative, zero, or positive if the first
194294 ** is less than, equal to, or greater than the second.
@@ -194336,11 +194407,12 @@
194407 if( pCur->bPoint ){
194408 int ii;
194409 pNew = rtreeEnqueue(pCur, rScore, iLevel);
194410 if( pNew==0 ) return 0;
194411 ii = (int)(pNew - pCur->aPoint) + 1;
194412 assert( ii==1 );
194413 if( ALWAYS(ii<RTREE_CACHE_SZ) ){
194414 assert( pCur->aNode[ii]==0 );
194415 pCur->aNode[ii] = pCur->aNode[0];
194416 }else{
194417 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
194418 }
@@ -194397,11 +194469,11 @@
194469 p->aNode[i] = 0;
194470 }
194471 if( p->bPoint ){
194472 p->anQueue[p->sPoint.iLevel]--;
194473 p->bPoint = 0;
194474 }else if( ALWAYS(p->nPoint) ){
194475 p->anQueue[p->aPoint[0].iLevel]--;
194476 n = --p->nPoint;
194477 p->aPoint[0] = p->aPoint[n];
194478 if( n<RTREE_CACHE_SZ-1 ){
194479 p->aNode[1] = p->aNode[n+1];
@@ -194538,11 +194610,11 @@
194610 static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
194611 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
194612 RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
194613 int rc = SQLITE_OK;
194614 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194615 if( rc==SQLITE_OK && ALWAYS(p) ){
194616 *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
194617 }
194618 return rc;
194619 }
194620
@@ -194556,11 +194628,11 @@
194628 RtreeCoord c;
194629 int rc = SQLITE_OK;
194630 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
194631
194632 if( rc ) return rc;
194633 if( NEVER(p==0) ) return SQLITE_OK;
194634 if( i==0 ){
194635 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
194636 }else if( i<=pRtree->nDim2 ){
194637 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
194638 #ifndef SQLITE_RTREE_INT_ONLY
@@ -194755,12 +194827,15 @@
194827 }
194828 }
194829 }
194830 if( rc==SQLITE_OK ){
194831 RtreeSearchPoint *pNew;
194832 assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
194833 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
194834 if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
194835 return SQLITE_NOMEM;
194836 }
194837 pNew->id = 1;
194838 pNew->iCell = 0;
194839 pNew->eWithin = PARTLY_WITHIN;
194840 assert( pCsr->bPoint==1 );
194841 pCsr->aNode[0] = pRoot;
@@ -194833,11 +194908,11 @@
194908 assert( pIdxInfo->idxStr==0 );
194909 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
194910 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
194911
194912 if( bMatch==0 && p->usable
194913 && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
194914 ){
194915 /* We have an equality constraint on the rowid. Use strategy 1. */
194916 int jj;
194917 for(jj=0; jj<ii; jj++){
194918 pIdxInfo->aConstraintUsage[jj].argvIndex = 0;
@@ -195086,16 +195161,23 @@
195161 RtreeNode *pNode, /* Adjust ancestry of this node. */
195162 RtreeCell *pCell /* This cell was just inserted */
195163 ){
195164 RtreeNode *p = pNode;
195165 int cnt = 0;
195166 int rc;
195167 while( p->pParent ){
195168 RtreeNode *pParent = p->pParent;
195169 RtreeCell cell;
195170 int iCell;
195171
195172 cnt++;
195173 if( NEVER(cnt>100) ){
195174 RTREE_IS_CORRUPT(pRtree);
195175 return SQLITE_CORRUPT_VTAB;
195176 }
195177 rc = nodeParentIndex(pRtree, p, &iCell);
195178 if( NEVER(rc!=SQLITE_OK) ){
195179 RTREE_IS_CORRUPT(pRtree);
195180 return SQLITE_CORRUPT_VTAB;
195181 }
195182
195183 nodeGetCell(pRtree, pParent, iCell, &cell);
@@ -195475,15 +195557,16 @@
195557 }
195558 }else{
195559 RtreeNode *pParent = pLeft->pParent;
195560 int iCell;
195561 rc = nodeParentIndex(pRtree, pLeft, &iCell);
195562 if( ALWAYS(rc==SQLITE_OK) ){
195563 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
195564 rc = AdjustTree(pRtree, pParent, &leftbbox);
195565 assert( rc==SQLITE_OK );
195566 }
195567 if( NEVER(rc!=SQLITE_OK) ){
195568 goto splitnode_out;
195569 }
195570 }
195571 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
195572 goto splitnode_out;
@@ -195554,11 +195637,11 @@
195637 ** want to do this as it leads to a memory leak when trying to delete
195638 ** the referenced counted node structures.
195639 */
195640 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
195641 for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
195642 if( pTest==0 ){
195643 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
195644 }
195645 }
195646 rc = sqlite3_reset(pRtree->pReadParent);
195647 if( rc==SQLITE_OK ) rc = rc2;
@@ -195585,10 +195668,11 @@
195668 rc = nodeParentIndex(pRtree, pNode, &iCell);
195669 if( rc==SQLITE_OK ){
195670 pParent = pNode->pParent;
195671 pNode->pParent = 0;
195672 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
195673 testcase( rc!=SQLITE_OK );
195674 }
195675 rc2 = nodeRelease(pRtree, pParent);
195676 if( rc==SQLITE_OK ){
195677 rc = rc2;
195678 }
@@ -195807,11 +195891,11 @@
195891 pRtree->iReinsertHeight = iHeight;
195892 rc = Reinsert(pRtree, pNode, pCell, iHeight);
195893 }
195894 }else{
195895 rc = AdjustTree(pRtree, pNode, pCell);
195896 if( ALWAYS(rc==SQLITE_OK) ){
195897 if( iHeight==0 ){
195898 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
195899 }else{
195900 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
195901 }
@@ -195913,11 +195997,11 @@
195997 */
195998 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
195999 int rc2;
196000 RtreeNode *pChild = 0;
196001 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
196002 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); /* tag-20210916a */
196003 if( rc==SQLITE_OK ){
196004 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
196005 }
196006 rc2 = nodeRelease(pRtree, pChild);
196007 if( rc==SQLITE_OK ) rc = rc2;
@@ -196248,11 +196332,11 @@
196332 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
196333 const char *zFmt = "SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'";
196334 char *zSql;
196335 sqlite3_stmt *p;
196336 int rc;
196337 i64 nRow = RTREE_MIN_ROWEST;
196338
196339 rc = sqlite3_table_column_metadata(
196340 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
196341 );
196342 if( rc!=SQLITE_OK ){
@@ -196265,24 +196349,14 @@
196349 }else{
196350 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
196351 if( rc==SQLITE_OK ){
196352 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
196353 rc = sqlite3_finalize(p);
 
 
 
 
 
 
 
 
 
 
196354 }
196355 sqlite3_free(zSql);
196356 }
196357 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
196358 return rc;
196359 }
196360
196361
196362 /*
@@ -196428,13 +196502,16 @@
196502 int ii;
196503 char *zSql;
196504 sqlite3_str_appendf(p, "UPDATE \"%w\".\"%w_rowid\"SET ", zDb, zPrefix);
196505 for(ii=0; ii<pRtree->nAux; ii++){
196506 if( ii ) sqlite3_str_append(p, ",", 1);
196507 #ifdef SQLITE_ENABLE_GEOPOLY
196508 if( ii<pRtree->nAuxNotNull ){
196509 sqlite3_str_appendf(p,"a%d=coalesce(?%d,a%d)",ii,ii+2,ii);
196510 }else
196511 #endif
196512 {
196513 sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
196514 }
196515 }
196516 sqlite3_str_appendf(p, " WHERE rowid=?1");
196517 zSql = sqlite3_str_finish(p);
@@ -197109,12 +197186,14 @@
197186 if( check.rc==SQLITE_OK ){
197187 pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.'%q_rowid'", zDb, zTab);
197188 if( pStmt ){
197189 nAux = sqlite3_column_count(pStmt) - 2;
197190 sqlite3_finalize(pStmt);
197191 }else
197192 if( check.rc!=SQLITE_NOMEM ){
197193 check.rc = SQLITE_OK;
197194 }
 
197195 }
197196
197197 /* Find number of dimensions in the rtree table. */
197198 pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.%Q", zDb, zTab);
197199 if( pStmt ){
@@ -199185,11 +199264,14 @@
199264 ){
199265 RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */
199266
199267 /* Allocate and populate the context object. */
199268 pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
199269 if( !pGeomCtx ){
199270 if( xDestructor ) xDestructor(pContext);
199271 return SQLITE_NOMEM;
199272 }
199273 pGeomCtx->xGeom = 0;
199274 pGeomCtx->xQueryFunc = xQueryFunc;
199275 pGeomCtx->xDestructor = xDestructor;
199276 pGeomCtx->pContext = pContext;
199277 return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
@@ -222468,10 +222550,46 @@
222550 if( p->pStruct!=(Fts5Structure*)pStruct ){
222551 return SQLITE_ABORT;
222552 }
222553 return SQLITE_OK;
222554 }
222555
222556 /*
222557 ** Ensure that structure object (*pp) is writable.
222558 **
222559 ** This function is a no-op if (*pRc) is not SQLITE_OK when it is called. If
222560 ** an error occurs, (*pRc) is set to an SQLite error code before returning.
222561 */
222562 static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){
222563 Fts5Structure *p = *pp;
222564 if( *pRc==SQLITE_OK && p->nRef>1 ){
222565 int nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel);
222566 Fts5Structure *pNew;
222567 pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte);
222568 if( pNew ){
222569 int i;
222570 memcpy(pNew, p, nByte);
222571 for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
222572 for(i=0; i<p->nLevel; i++){
222573 Fts5StructureLevel *pLvl = &pNew->aLevel[i];
222574 int nByte = sizeof(Fts5StructureSegment) * pNew->aLevel[i].nSeg;
222575 pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(pRc, nByte);
222576 if( pLvl->aSeg==0 ){
222577 for(i=0; i<p->nLevel; i++){
222578 sqlite3_free(pNew->aLevel[i].aSeg);
222579 }
222580 sqlite3_free(pNew);
222581 return;
222582 }
222583 memcpy(pLvl->aSeg, p->aLevel[i].aSeg, nByte);
222584 }
222585 p->nRef--;
222586 pNew->nRef = 1;
222587 }
222588 *pp = pNew;
222589 }
222590 }
222591
222592 /*
222593 ** Deserialize and return the structure record currently stored in serialized
222594 ** form within buffer pData/nData.
222595 **
@@ -222570,13 +222688,15 @@
222688 *ppOut = pRet;
222689 return rc;
222690 }
222691
222692 /*
222693 ** Add a level to the Fts5Structure.aLevel[] array of structure object
222694 ** (*ppStruct).
222695 */
222696 static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
222697 fts5StructureMakeWritable(pRc, ppStruct);
222698 if( *pRc==SQLITE_OK ){
222699 Fts5Structure *pStruct = *ppStruct;
222700 int nLevel = pStruct->nLevel;
222701 sqlite3_int64 nByte = (
222702 sizeof(Fts5Structure) + /* Main structure */
@@ -231175,11 +231295,11 @@
231295 int nArg, /* Number of args */
231296 sqlite3_value **apUnused /* Function arguments */
231297 ){
231298 assert( nArg==0 );
231299 UNUSED_PARAM2(nArg, apUnused);
231300 sqlite3_result_text(pCtx, "fts5: 2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3", -1, SQLITE_TRANSIENT);
231301 }
231302
231303 /*
231304 ** Return true if zName is the extension on one of the shadow tables used
231305 ** by this module.
231306
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.37.0"
150150
#define SQLITE_VERSION_NUMBER 3037000
151
-#define SQLITE_SOURCE_ID "2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1"
151
+#define SQLITE_SOURCE_ID "2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-09-06 11:44:19 b3cfe23bec0b95ca673802526704200e2396df715fdded72aa71addd7f47e0e1"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-09-22 13:43:16 56da0e9c0321d1fd3c360722cd6284296f9ba459f6b37ab35c81ecabd18f12e3"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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