Fossil SCM

Update the built-in SQLite to the 3.34.0 first beta, for testing.

drh 2020-11-24 00:10 trunk
Commit 39b114c19f69d2fb86471b53cca7f2da9dfd1d163ee7da56858c8d35008857d9
3 files changed +13 -7 +175 -51 +2 -1
+13 -7
--- src/shell.c
+++ src/shell.c
@@ -21278,24 +21278,29 @@
2127821278
** the database filename.
2127921279
*/
2128021280
for(i=0; i<nCmd; i++){
2128121281
if( azCmd[i][0]=='.' ){
2128221282
rc = do_meta_command(azCmd[i], &data);
21283
- if( rc ) return rc==2 ? 0 : rc;
21283
+ if( rc ){
21284
+ free(azCmd);
21285
+ return rc==2 ? 0 : rc;
21286
+ }
2128421287
}else{
2128521288
open_db(&data, 0);
2128621289
rc = shell_exec(&data, azCmd[i], &zErrMsg);
21287
- if( zErrMsg!=0 ){
21288
- utf8_printf(stderr,"Error: %s\n", zErrMsg);
21290
+ if( zErrMsg || rc ){
21291
+ if( zErrMsg!=0 ){
21292
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
21293
+ }else{
21294
+ utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
21295
+ }
21296
+ sqlite3_free(zErrMsg);
21297
+ free(azCmd);
2128921298
return rc!=0 ? rc : 1;
21290
- }else if( rc!=0 ){
21291
- utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
21292
- return rc;
2129321299
}
2129421300
}
2129521301
}
21296
- free(azCmd);
2129721302
}else{
2129821303
/* Run commands received from standard input
2129921304
*/
2130021305
if( stdin_is_interactive ){
2130121306
char *zHome;
@@ -21337,10 +21342,11 @@
2133721342
}else{
2133821343
data.in = stdin;
2133921344
rc = process_input(&data);
2134021345
}
2134121346
}
21347
+ free(azCmd);
2134221348
set_table_name(&data, 0);
2134321349
if( data.db ){
2134421350
session_close_all(&data);
2134521351
close_db(data.db);
2134621352
}
2134721353
--- src/shell.c
+++ src/shell.c
@@ -21278,24 +21278,29 @@
21278 ** the database filename.
21279 */
21280 for(i=0; i<nCmd; i++){
21281 if( azCmd[i][0]=='.' ){
21282 rc = do_meta_command(azCmd[i], &data);
21283 if( rc ) return rc==2 ? 0 : rc;
 
 
 
21284 }else{
21285 open_db(&data, 0);
21286 rc = shell_exec(&data, azCmd[i], &zErrMsg);
21287 if( zErrMsg!=0 ){
21288 utf8_printf(stderr,"Error: %s\n", zErrMsg);
 
 
 
 
 
 
21289 return rc!=0 ? rc : 1;
21290 }else if( rc!=0 ){
21291 utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
21292 return rc;
21293 }
21294 }
21295 }
21296 free(azCmd);
21297 }else{
21298 /* Run commands received from standard input
21299 */
21300 if( stdin_is_interactive ){
21301 char *zHome;
@@ -21337,10 +21342,11 @@
21337 }else{
21338 data.in = stdin;
21339 rc = process_input(&data);
21340 }
21341 }
 
21342 set_table_name(&data, 0);
21343 if( data.db ){
21344 session_close_all(&data);
21345 close_db(data.db);
21346 }
21347
--- src/shell.c
+++ src/shell.c
@@ -21278,24 +21278,29 @@
21278 ** the database filename.
21279 */
21280 for(i=0; i<nCmd; i++){
21281 if( azCmd[i][0]=='.' ){
21282 rc = do_meta_command(azCmd[i], &data);
21283 if( rc ){
21284 free(azCmd);
21285 return rc==2 ? 0 : rc;
21286 }
21287 }else{
21288 open_db(&data, 0);
21289 rc = shell_exec(&data, azCmd[i], &zErrMsg);
21290 if( zErrMsg || rc ){
21291 if( zErrMsg!=0 ){
21292 utf8_printf(stderr,"Error: %s\n", zErrMsg);
21293 }else{
21294 utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
21295 }
21296 sqlite3_free(zErrMsg);
21297 free(azCmd);
21298 return rc!=0 ? rc : 1;
 
 
 
21299 }
21300 }
21301 }
 
21302 }else{
21303 /* Run commands received from standard input
21304 */
21305 if( stdin_is_interactive ){
21306 char *zHome;
@@ -21337,10 +21342,11 @@
21342 }else{
21343 data.in = stdin;
21344 rc = process_input(&data);
21345 }
21346 }
21347 free(azCmd);
21348 set_table_name(&data, 0);
21349 if( data.db ){
21350 session_close_all(&data);
21351 close_db(data.db);
21352 }
21353
+175 -51
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1171,11 +1171,11 @@
11711171
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11721172
** [sqlite_version()] and [sqlite_source_id()].
11731173
*/
11741174
#define SQLITE_VERSION "3.34.0"
11751175
#define SQLITE_VERSION_NUMBER 3034000
1176
-#define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692392d"
1176
+#define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0b020"
11771177
11781178
/*
11791179
** CAPI3REF: Run-Time Library Version Numbers
11801180
** KEYWORDS: sqlite3_version sqlite3_sourceid
11811181
**
@@ -1550,10 +1550,11 @@
15501550
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
15511551
#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
15521552
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
15531553
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
15541554
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
1555
+#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
15551556
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
15561557
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
15571558
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
15581559
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
15591560
#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
@@ -28182,16 +28183,19 @@
2818228183
EnableLookaside;
2818328184
}
2818428185
}
2818528186
2818628187
/*
28187
-** Take actions at the end of an API call to indicate an OOM error
28188
+** Take actions at the end of an API call to deal with error codes.
2818828189
*/
28189
-static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
28190
- sqlite3OomClear(db);
28191
- sqlite3Error(db, SQLITE_NOMEM);
28192
- return SQLITE_NOMEM_BKPT;
28190
+static SQLITE_NOINLINE int apiHandleError(sqlite3 *db, int rc){
28191
+ if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28192
+ sqlite3OomClear(db);
28193
+ sqlite3Error(db, SQLITE_NOMEM);
28194
+ return SQLITE_NOMEM_BKPT;
28195
+ }
28196
+ return rc & db->errMask;
2819328197
}
2819428198
2819528199
/*
2819628200
** This function must be called before exiting any API function (i.e.
2819728201
** returning control to the user) that has called sqlite3_malloc or
@@ -28209,12 +28213,12 @@
2820928213
** Otherwise the read (and possible write) of db->mallocFailed
2821028214
** is unsafe, as is the call to sqlite3Error().
2821128215
*/
2821228216
assert( db!=0 );
2821328217
assert( sqlite3_mutex_held(db->mutex) );
28214
- if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28215
- return apiOomError(db);
28218
+ if( db->mallocFailed || rc ){
28219
+ return apiHandleError(db, rc);
2821628220
}
2821728221
return rc & db->errMask;
2821828222
}
2821928223
2822028224
/************** End of malloc.c **********************************************/
@@ -37003,11 +37007,28 @@
3700337007
3700437008
got = seekAndRead(pFile, offset, pBuf, amt);
3700537009
if( got==amt ){
3700637010
return SQLITE_OK;
3700737011
}else if( got<0 ){
37008
- /* lastErrno set by seekAndRead */
37012
+ /* pFile->lastErrno has been set by seekAndRead().
37013
+ ** Usually we return SQLITE_IOERR_READ here, though for some
37014
+ ** kinds of errors we return SQLITE_IOERR_CORRUPTFS. The
37015
+ ** SQLITE_IOERR_CORRUPTFS will be converted into SQLITE_CORRUPT
37016
+ ** prior to returning to the application by the sqlite3ApiExit()
37017
+ ** routine.
37018
+ */
37019
+ switch( pFile->lastErrno ){
37020
+ case ERANGE:
37021
+ case EIO:
37022
+#ifdef ENXIO
37023
+ case ENXIO:
37024
+#endif
37025
+#ifdef EDEVERR
37026
+ case EDEVERR:
37027
+#endif
37028
+ return SQLITE_IOERR_CORRUPTFS;
37029
+ }
3700937030
return SQLITE_IOERR_READ;
3701037031
}else{
3701137032
storeLastErrno(pFile, 0); /* not a system error */
3701237033
/* Unread parts of the buffer must be zero-filled */
3701337034
memset(&((char*)pBuf)[got], 0, amt-got);
@@ -38535,11 +38556,11 @@
3853538556
if( bUnlock ){
3853638557
rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
3853738558
if( rc==SQLITE_OK ){
3853838559
memset(&aLock[ofst], 0, sizeof(int)*n);
3853938560
}
38540
- }else if( p->sharedMask & (1<<ofst) ){
38561
+ }else if( ALWAYS(p->sharedMask & (1<<ofst)) ){
3854138562
assert( n==1 && aLock[ofst]>1 );
3854238563
aLock[ofst]--;
3854338564
}
3854438565
3854538566
/* Undo the local locks */
@@ -38568,11 +38589,11 @@
3856838589
/* Make sure no sibling connections hold locks that will block this
3856938590
** lock. If any do, return SQLITE_BUSY right away. */
3857038591
int ii;
3857138592
for(ii=ofst; ii<ofst+n; ii++){
3857238593
assert( (p->sharedMask & mask)==0 );
38573
- if( (p->exclMask & (1<<ii))==0 && aLock[ii] ){
38594
+ if( ALWAYS((p->exclMask & (1<<ii))==0) && aLock[ii] ){
3857438595
rc = SQLITE_BUSY;
3857538596
break;
3857638597
}
3857738598
}
3857838599
@@ -39964,19 +39985,39 @@
3996439985
}
3996539986
return SQLITE_OK;
3996639987
}
3996739988
3996839989
/*
39990
+** If the last component of the pathname in z[0]..z[j-1] is something
39991
+** other than ".." then back it out and return true. If the last
39992
+** component is empty or if it is ".." then return false.
39993
+*/
39994
+static int unixBackupDir(const char *z, int *pJ){
39995
+ int j = *pJ;
39996
+ int i;
39997
+ if( j<=0 ) return 0;
39998
+ for(i=j-1; ALWAYS(i>0) && z[i-1]!='/'; i--){}
39999
+ if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
40000
+ *pJ = i-1;
40001
+ return 1;
40002
+}
40003
+
40004
+/*
40005
+** Convert a relative pathname into a full pathname. Also
40006
+** simplify the pathname as follows:
3996940007
**
40008
+** Remove all instances of /./
40009
+** Remove all isntances of /X/../ for any X
3997040010
*/
3997140011
static int mkFullPathname(
3997240012
const char *zPath, /* Input path */
3997340013
char *zOut, /* Output buffer */
3997440014
int nOut /* Allocated size of buffer zOut */
3997540015
){
3997640016
int nPath = sqlite3Strlen30(zPath);
3997740017
int iOff = 0;
40018
+ int i, j;
3997840019
if( zPath[0]!='/' ){
3997940020
if( osGetcwd(zOut, nOut-2)==0 ){
3998040021
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
3998140022
}
3998240023
iOff = sqlite3Strlen30(zOut);
@@ -39987,10 +40028,45 @@
3998740028
** even if it returns an error. */
3998840029
zOut[iOff] = '\0';
3998940030
return SQLITE_CANTOPEN_BKPT;
3999040031
}
3999140032
sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
40033
+
40034
+ /* Remove duplicate '/' characters. Except, two // at the beginning
40035
+ ** of a pathname is allowed since this is important on windows. */
40036
+ for(i=j=1; zOut[i]; i++){
40037
+ zOut[j++] = zOut[i];
40038
+ while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
40039
+ }
40040
+ zOut[j] = 0;
40041
+
40042
+ assert( zOut[0]=='/' );
40043
+ for(i=j=0; zOut[i]; i++){
40044
+ if( zOut[i]=='/' ){
40045
+ /* Skip over internal "/." directory components */
40046
+ if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
40047
+ i += 1;
40048
+ continue;
40049
+ }
40050
+
40051
+ /* If this is a "/.." directory component then back out the
40052
+ ** previous term of the directory if it is something other than "..".
40053
+ */
40054
+ if( zOut[i+1]=='.'
40055
+ && zOut[i+2]=='.'
40056
+ && zOut[i+3]=='/'
40057
+ && unixBackupDir(zOut, &j)
40058
+ ){
40059
+ i += 2;
40060
+ continue;
40061
+ }
40062
+ }
40063
+ if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
40064
+ j++;
40065
+ }
40066
+ if( NEVER(j==0) ) zOut[j++] = '/';
40067
+ zOut[j] = 0;
3999240068
return SQLITE_OK;
3999340069
}
3999440070
3999540071
/*
3999640072
** Turn a relative pathname into a full pathname. The relative path
@@ -82192,13 +82268,16 @@
8219282268
** equal to, or greater than the second (double).
8219382269
*/
8219482270
static int sqlite3IntFloatCompare(i64 i, double r){
8219582271
if( sizeof(LONGDOUBLE_TYPE)>8 ){
8219682272
LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
82273
+ testcase( x<r );
82274
+ testcase( x>r );
82275
+ testcase( x==r );
8219782276
if( x<r ) return -1;
82198
- if( x>r ) return +1;
82199
- return 0;
82277
+ if( x>r ) return +1; /*NO_TEST*/ /* work around bugs in gcov */
82278
+ return 0; /*NO_TEST*/ /* work around bugs in gcov */
8220082279
}else{
8220182280
i64 y;
8220282281
double s;
8220382282
if( r<-9223372036854775808.0 ) return +1;
8220482283
if( r>=9223372036854775808.0 ) return -1;
@@ -89388,11 +89467,11 @@
8938889467
assert( rc==SQLITE_OK );
8938989468
break;
8939089469
}
8939189470
8939289471
89393
-/* Opcode: OpenEphemeral P1 P2 * P4 P5
89472
+/* Opcode: OpenEphemeral P1 P2 P3 P4 P5
8939489473
** Synopsis: nColumn=P2
8939589474
**
8939689475
** Open a new cursor P1 to a transient table.
8939789476
** The cursor is always opened read/write even if
8939889477
** the main database is read-only. The ephemeral
@@ -89408,10 +89487,14 @@
8940889487
**
8940989488
** The P5 parameter can be a mask of the BTREE_* flags defined
8941089489
** in btree.h. These flags control aspects of the operation of
8941189490
** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
8941289491
** added automatically.
89492
+**
89493
+** If P3 is positive, then reg[P3] is modified slightly so that it
89494
+** can be used as zero-length data for OP_Insert. This is an optimization
89495
+** that avoids an extra OP_Blob opcode to initialize that register.
8941389496
*/
8941489497
/* Opcode: OpenAutoindex P1 P2 * P4 *
8941589498
** Synopsis: nColumn=P2
8941689499
**
8941789500
** This opcode works the same as OP_OpenEphemeral. It has a
@@ -89430,10 +89513,19 @@
8943089513
SQLITE_OPEN_EXCLUSIVE |
8943189514
SQLITE_OPEN_DELETEONCLOSE |
8943289515
SQLITE_OPEN_TRANSIENT_DB;
8943389516
assert( pOp->p1>=0 );
8943489517
assert( pOp->p2>=0 );
89518
+ if( pOp->p3>0 ){
89519
+ /* Make register reg[P3] into a value that can be used as the data
89520
+ ** form sqlite3BtreeInsert() where the length of the data is zero. */
89521
+ assert( pOp->p2==0 ); /* Only used when number of columns is zero */
89522
+ assert( pOp->opcode==OP_OpenEphemeral );
89523
+ assert( aMem[pOp->p3].flags & MEM_Null );
89524
+ aMem[pOp->p3].n = 0;
89525
+ aMem[pOp->p3].z = "";
89526
+ }
8943589527
pCx = p->apCsr[pOp->p1];
8943689528
if( pCx && pCx->pBtx ){
8943789529
/* If the ephermeral table is already open, erase all existing content
8943889530
** so that the table is empty again, rather than creating a new table. */
8943989531
assert( pCx->isEphemeral );
@@ -90589,11 +90681,11 @@
9058990681
if( pOp->p5 & OPFLAG_ISNOOP ) break;
9059090682
#endif
9059190683
9059290684
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
9059390685
if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
90594
- assert( pData->flags & (MEM_Blob|MEM_Str) );
90686
+ assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
9059590687
x.pData = pData->z;
9059690688
x.nData = pData->n;
9059790689
seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
9059890690
if( pData->flags & MEM_Zero ){
9059990691
x.nZero = pData->u.nZero;
@@ -93644,11 +93736,15 @@
9364493736
9364593737
/* If we reach this point, it means that execution is finished with
9364693738
** an error of some kind.
9364793739
*/
9364893740
abort_due_to_error:
93649
- if( db->mallocFailed ) rc = SQLITE_NOMEM_BKPT;
93741
+ if( db->mallocFailed ){
93742
+ rc = SQLITE_NOMEM_BKPT;
93743
+ }else if( rc==SQLITE_IOERR_CORRUPTFS ){
93744
+ rc = SQLITE_CORRUPT_BKPT;
93745
+ }
9365093746
assert( rc );
9365193747
if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
9365293748
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
9365393749
}
9365493750
p->rc = rc;
@@ -99381,10 +99477,11 @@
9938199477
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
9938299478
int iCol = -1;
9938399479
Expr *pE, *pDup;
9938499480
if( pItem->done ) continue;
9938599481
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
99482
+ if( NEVER(pE==0) ) continue;
9938699483
if( sqlite3ExprIsInteger(pE, &iCol) ){
9938799484
if( iCol<=0 || iCol>pEList->nExpr ){
9938899485
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
9938999486
return 1;
9939099487
}
@@ -99560,10 +99657,11 @@
9956099657
nResult = pSelect->pEList->nExpr;
9956199658
pParse = pNC->pParse;
9956299659
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
9956399660
Expr *pE = pItem->pExpr;
9956499661
Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
99662
+ if( NEVER(pE2==0) ) continue;
9956599663
if( zType[0]!='G' ){
9956699664
iCol = resolveAsName(pParse, pSelect->pEList, pE2);
9956799665
if( iCol>0 ){
9956899666
/* If an AS-name match is found, mark this ORDER BY column as being
9956999667
** a copy of the iCol-th result-set column. The subsequent call to
@@ -103679,10 +103777,11 @@
103679103777
** register iReg. The caller must ensure that iReg already contains
103680103778
** the correct value for the expression.
103681103779
*/
103682103780
static void exprToRegister(Expr *pExpr, int iReg){
103683103781
Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
103782
+ if( NEVER(p==0) ) return;
103684103783
p->op2 = p->op;
103685103784
p->op = TK_REGISTER;
103686103785
p->iTable = iReg;
103687103786
ExprClearProperty(p, EP_Skip);
103688103787
}
@@ -104666,10 +104765,11 @@
104666104765
*/
104667104766
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
104668104767
int r2;
104669104768
pExpr = sqlite3ExprSkipCollateAndLikely(pExpr);
104670104769
if( ConstFactorOk(pParse)
104770
+ && ALWAYS(pExpr!=0)
104671104771
&& pExpr->op!=TK_REGISTER
104672104772
&& sqlite3ExprIsConstantNotJoin(pExpr)
104673104773
){
104674104774
*pReg = 0;
104675104775
r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
@@ -119424,10 +119524,12 @@
119424119524
VFUNCTION(total_changes, 0, 0, 0, total_changes ),
119425119525
FUNCTION(replace, 3, 0, 0, replaceFunc ),
119426119526
FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
119427119527
FUNCTION(substr, 2, 0, 0, substrFunc ),
119428119528
FUNCTION(substr, 3, 0, 0, substrFunc ),
119529
+ FUNCTION(substring, 2, 0, 0, substrFunc ),
119530
+ FUNCTION(substring, 3, 0, 0, substrFunc ),
119429119531
WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
119430119532
WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
119431119533
WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
119432119534
WAGGREGATE(count, 0,0,0, countStep,
119433119535
countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ),
@@ -131654,10 +131756,11 @@
131654131756
Column *aCol, *pCol; /* For looping over result columns */
131655131757
int nCol; /* Number of columns in the result set */
131656131758
char *zName; /* Column name */
131657131759
int nName; /* Size of name in zName[] */
131658131760
Hash ht; /* Hash table of column names */
131761
+ Table *pTab;
131659131762
131660131763
sqlite3HashInit(&ht);
131661131764
if( pEList ){
131662131765
nCol = pEList->nExpr;
131663131766
aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
@@ -131676,19 +131779,17 @@
131676131779
*/
131677131780
if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
131678131781
/* If the column contains an "AS <name>" phrase, use <name> as the name */
131679131782
}else{
131680131783
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
131681
- while( pColExpr->op==TK_DOT ){
131784
+ while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
131682131785
pColExpr = pColExpr->pRight;
131683131786
assert( pColExpr!=0 );
131684131787
}
131685
- if( pColExpr->op==TK_COLUMN ){
131788
+ if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
131686131789
/* For columns use the column name name */
131687131790
int iCol = pColExpr->iColumn;
131688
- Table *pTab = pColExpr->y.pTab;
131689
- assert( pTab!=0 );
131690131791
if( iCol<0 ) iCol = pTab->iPKey;
131691131792
zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
131692131793
}else if( pColExpr->op==TK_ID ){
131693131794
assert( !ExprHasProperty(pColExpr, EP_IntValue) );
131694131795
zName = pColExpr->u.zToken;
@@ -136959,26 +137060,15 @@
136959137060
goto trigger_cleanup;
136960137061
}
136961137062
pTab = sqlite3SrcListLookup(pParse, pTableName);
136962137063
if( !pTab ){
136963137064
/* The table does not exist. */
136964
- if( db->init.iDb==1 ){
136965
- /* Ticket #3810.
136966
- ** Normally, whenever a table is dropped, all associated triggers are
136967
- ** dropped too. But if a TEMP trigger is created on a non-TEMP table
136968
- ** and the table is dropped by a different database connection, the
136969
- ** trigger is not visible to the database connection that does the
136970
- ** drop so the trigger cannot be dropped. This results in an
136971
- ** "orphaned trigger" - a trigger whose associated table is missing.
136972
- */
136973
- db->init.orphanTrigger = 1;
136974
- }
136975
- goto trigger_cleanup;
137065
+ goto trigger_orphan_error;
136976137066
}
136977137067
if( IsVirtual(pTab) ){
136978137068
sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");
136979
- goto trigger_cleanup;
137069
+ goto trigger_orphan_error;
136980137070
}
136981137071
136982137072
/* Check that the trigger name is not reserved and that no trigger of the
136983137073
** specified name exists */
136984137074
zName = sqlite3NameFromToken(db, pName);
@@ -137012,16 +137102,16 @@
137012137102
** of triggers.
137013137103
*/
137014137104
if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
137015137105
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
137016137106
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
137017
- goto trigger_cleanup;
137107
+ goto trigger_orphan_error;
137018137108
}
137019137109
if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
137020137110
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
137021137111
" trigger on table: %S", pTableName, 0);
137022
- goto trigger_cleanup;
137112
+ goto trigger_orphan_error;
137023137113
}
137024137114
137025137115
#ifndef SQLITE_OMIT_AUTHORIZATION
137026137116
if( !IN_RENAME_OBJECT ){
137027137117
int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -137077,10 +137167,27 @@
137077137167
if( !pParse->pNewTrigger ){
137078137168
sqlite3DeleteTrigger(db, pTrigger);
137079137169
}else{
137080137170
assert( pParse->pNewTrigger==pTrigger );
137081137171
}
137172
+ return;
137173
+
137174
+trigger_orphan_error:
137175
+ if( db->init.iDb==1 ){
137176
+ /* Ticket #3810.
137177
+ ** Normally, whenever a table is dropped, all associated triggers are
137178
+ ** dropped too. But if a TEMP trigger is created on a non-TEMP table
137179
+ ** and the table is dropped by a different database connection, the
137180
+ ** trigger is not visible to the database connection that does the
137181
+ ** drop so the trigger cannot be dropped. This results in an
137182
+ ** "orphaned trigger" - a trigger whose associated table is missing.
137183
+ **
137184
+ ** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
137185
+ */
137186
+ db->init.orphanTrigger = 1;
137187
+ }
137188
+ goto trigger_cleanup;
137082137189
}
137083137190
137084137191
/*
137085137192
** This routine is called after all of the trigger actions have been parsed
137086137193
** in order to complete the process of building the trigger.
@@ -138664,10 +138771,12 @@
138664138771
sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
138665138772
}
138666138773
138667138774
if( nChangeFrom==0 && HasRowid(pTab) ){
138668138775
sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
138776
+ iEph = pParse->nTab++;
138777
+ addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet);
138669138778
}else{
138670138779
assert( pPk!=0 || HasRowid(pTab) );
138671138780
nPk = pPk ? pPk->nKeyCol : 0;
138672138781
iPk = pParse->nMem+1;
138673138782
pParse->nMem += nPk;
@@ -138755,13 +138864,14 @@
138755138864
/* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
138756138865
** mode, write the rowid into the FIFO. In either of the one-pass modes,
138757138866
** leave it in register regOldRowid. */
138758138867
sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
138759138868
if( eOnePass==ONEPASS_OFF ){
138760
- /* We need to use regRowSet, so reallocate aRegIdx[nAllIdx] */
138761138869
aRegIdx[nAllIdx] = ++pParse->nMem;
138762
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
138870
+ sqlite3VdbeAddOp3(v, OP_Insert, iEph, regRowSet, regOldRowid);
138871
+ }else{
138872
+ if( ALWAYS(addrOpen) ) sqlite3VdbeChangeToNoop(v, addrOpen);
138763138873
}
138764138874
}else{
138765138875
/* Read the PK of the current row into an array of registers. In
138766138876
** ONEPASS_OFF mode, serialize the array into a record and store it in
138767138877
** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
@@ -138845,12 +138955,13 @@
138845138955
sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
138846138956
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
138847138957
VdbeCoverage(v);
138848138958
}
138849138959
}else{
138850
- labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
138851
- regOldRowid);
138960
+ sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
138961
+ labelContinue = sqlite3VdbeMakeLabel(pParse);
138962
+ addrTop = sqlite3VdbeAddOp2(v, OP_Rowid, iEph, regOldRowid);
138852138963
VdbeCoverage(v);
138853138964
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
138854138965
VdbeCoverage(v);
138855138966
}
138856138967
}
@@ -139096,15 +139207,13 @@
139096139207
if( eOnePass==ONEPASS_SINGLE ){
139097139208
/* Nothing to do at end-of-loop for a single-pass */
139098139209
}else if( eOnePass==ONEPASS_MULTI ){
139099139210
sqlite3VdbeResolveLabel(v, labelContinue);
139100139211
sqlite3WhereEnd(pWInfo);
139101
- }else if( pPk || nChangeFrom ){
139212
+ }else{
139102139213
sqlite3VdbeResolveLabel(v, labelContinue);
139103139214
sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
139104
- }else{
139105
- sqlite3VdbeGoto(v, labelContinue);
139106139215
}
139107139216
sqlite3VdbeResolveLabel(v, labelBreak);
139108139217
139109139218
/* Update the sqlite_sequence table by storing the content of the
139110139219
** maximum rowid counter values recorded while inserting into
@@ -145894,10 +146003,11 @@
145894146003
** all terms of the WHERE clause.
145895146004
*/
145896146005
SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
145897146006
Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pExpr);
145898146007
pWC->op = op;
146008
+ assert( pE2!=0 || pExpr==0 );
145899146009
if( pE2==0 ) return;
145900146010
if( pE2->op!=op ){
145901146011
whereClauseInsert(pWC, pExpr, 0);
145902146012
}else{
145903146013
sqlite3WhereSplit(pWC, pE2->pLeft, op);
@@ -146292,10 +146402,20 @@
146292146402
*/
146293146403
static void createMask(WhereMaskSet *pMaskSet, int iCursor){
146294146404
assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
146295146405
pMaskSet->ix[pMaskSet->n++] = iCursor;
146296146406
}
146407
+
146408
+/*
146409
+** If the right-hand branch of the expression is a TK_COLUMN, then return
146410
+** a pointer to the right-hand branch. Otherwise, return NULL.
146411
+*/
146412
+static Expr *whereRightSubexprIsColumn(Expr *p){
146413
+ p = sqlite3ExprSkipCollateAndLikely(p->pRight);
146414
+ if( ALWAYS(p!=0) && p->op==TK_COLUMN ) return p;
146415
+ return 0;
146416
+}
146297146417
146298146418
/*
146299146419
** Advance to the next WhereTerm that matches according to the criteria
146300146420
** established when the pScan object was initialized by whereScanInit().
146301146421
** Return NULL if there are no more matching WhereTerms.
@@ -146323,12 +146443,11 @@
146323146443
pScan->pIdxExpr,iCur)==0)
146324146444
&& (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
146325146445
){
146326146446
if( (pTerm->eOperator & WO_EQUIV)!=0
146327146447
&& pScan->nEquiv<ArraySize(pScan->aiCur)
146328
- && (pX = sqlite3ExprSkipCollateAndLikely(pTerm->pExpr->pRight))->op
146329
- ==TK_COLUMN
146448
+ && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
146330146449
){
146331146450
int j;
146332146451
for(j=0; j<pScan->nEquiv; j++){
146333146452
if( pScan->aiCur[j]==pX->iTable
146334146453
&& pScan->aiColumn[j]==pX->iColumn ){
@@ -146520,11 +146639,12 @@
146520146639
int i;
146521146640
const char *zColl = pIdx->azColl[iCol];
146522146641
146523146642
for(i=0; i<pList->nExpr; i++){
146524146643
Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
146525
- if( p->op==TK_COLUMN
146644
+ if( ALWAYS(p!=0)
146645
+ && p->op==TK_COLUMN
146526146646
&& p->iColumn==pIdx->aiColumn[iCol]
146527146647
&& p->iTable==iBase
146528146648
){
146529146649
CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
146530146650
if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -146584,10 +146704,11 @@
146584146704
** true. Note: The (p->iTable==iBase) part of this test may be false if the
146585146705
** current SELECT is a correlated sub-query.
146586146706
*/
146587146707
for(i=0; i<pDistinct->nExpr; i++){
146588146708
Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
146709
+ if( NEVER(p==0) ) continue;
146589146710
if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
146590146711
}
146591146712
146592146713
/* Loop through all indices on the table, checking each to see if it makes
146593146714
** the DISTINCT qualifier redundant. It does so if:
@@ -148498,13 +148619,13 @@
148498148619
LogEst rLogSize; /* Logarithm of table size */
148499148620
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
148500148621
148501148622
pNew = pBuilder->pNew;
148502148623
if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
148503
- WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n",
148624
+ WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
148504148625
pProbe->pTable->zName,pProbe->zName,
148505
- pNew->u.btree.nEq, pNew->nSkip));
148626
+ pNew->u.btree.nEq, pNew->nSkip, pNew->rRun));
148506148627
148507148628
assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
148508148629
assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
148509148630
if( pNew->wsFlags & WHERE_BTM_LIMIT ){
148510148631
opMask = WO_LT|WO_LE;
@@ -148869,10 +148990,11 @@
148869148990
148870148991
if( pIndex->bUnordered ) return 0;
148871148992
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
148872148993
for(ii=0; ii<pOB->nExpr; ii++){
148873148994
Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
148995
+ if( NEVER(pExpr==0) ) continue;
148874148996
if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
148875148997
if( pExpr->iColumn<0 ) return 1;
148876148998
for(jj=0; jj<pIndex->nKeyCol; jj++){
148877148999
if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
148878149000
}
@@ -149847,10 +149969,11 @@
149847149969
** loops.
149848149970
*/
149849149971
for(i=0; i<nOrderBy; i++){
149850149972
if( MASKBIT(i) & obSat ) continue;
149851149973
pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149974
+ if( NEVER(pOBExpr==0) ) continue;
149852149975
if( pOBExpr->op!=TK_COLUMN ) continue;
149853149976
if( pOBExpr->iTable!=iCur ) continue;
149854149977
pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
149855149978
~ready, eqOpMask, 0);
149856149979
if( pTerm==0 ) continue;
@@ -149973,10 +150096,11 @@
149973150096
for(i=0; bOnce && i<nOrderBy; i++){
149974150097
if( MASKBIT(i) & obSat ) continue;
149975150098
pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149976150099
testcase( wctrlFlags & WHERE_GROUPBY );
149977150100
testcase( wctrlFlags & WHERE_DISTINCTBY );
150101
+ if( NEVER(pOBExpr==0) ) continue;
149978150102
if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
149979150103
if( iColumn>=XN_ROWID ){
149980150104
if( pOBExpr->op!=TK_COLUMN ) continue;
149981150105
if( pOBExpr->iTable!=iCur ) continue;
149982150106
if( pOBExpr->iColumn!=iColumn ) continue;
@@ -150136,11 +150260,11 @@
150136150260
rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
150137150261
rSortCost = nRow + rScale + 16;
150138150262
150139150263
/* Multiple by log(M) where M is the number of output rows.
150140150264
** Use the LIMIT for M if it is smaller. Or if this sort is for
150141
- ** a DISTINT operator, M will be the number of distinct output
150265
+ ** a DISTINCT operator, M will be the number of distinct output
150142150266
** rows, so fudge it downwards a bit.
150143150267
*/
150144150268
if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
150145150269
nRow = pWInfo->iLimit;
150146150270
}else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
@@ -226679,11 +226803,11 @@
226679226803
int nArg, /* Number of args */
226680226804
sqlite3_value **apUnused /* Function arguments */
226681226805
){
226682226806
assert( nArg==0 );
226683226807
UNUSED_PARAM2(nArg, apUnused);
226684
- sqlite3_result_text(pCtx, "fts5: 2020-10-26 16:22:31 80eba105d6d1b49ba8ca2ad4e14ddec2de0bdc2f6686c2f8a1c1d24fc1fe846f", -1, SQLITE_TRANSIENT);
226808
+ sqlite3_result_text(pCtx, "fts5: 2020-11-19 21:12:08 c38dec6f52c01614c1bee8356daf0fcd9f708d029116e9bff51e06719a730dde", -1, SQLITE_TRANSIENT);
226685226809
}
226686226810
226687226811
/*
226688226812
** Return true if zName is the extension on one of the shadow tables used
226689226813
** by this module.
@@ -231602,12 +231726,12 @@
231602231726
}
231603231727
#endif /* SQLITE_CORE */
231604231728
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
231605231729
231606231730
/************** End of stmt.c ************************************************/
231607
-#if __LINE__!=231607
231731
+#if __LINE__!=231731
231608231732
#undef SQLITE_SOURCE_ID
231609
-#define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692alt2"
231733
+#define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0alt2"
231610231734
#endif
231611231735
/* Return the source-id for this library */
231612231736
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
231613231737
/************************** End of sqlite3.c ******************************/
231614231738
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1171,11 +1171,11 @@
1171 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1172 ** [sqlite_version()] and [sqlite_source_id()].
1173 */
1174 #define SQLITE_VERSION "3.34.0"
1175 #define SQLITE_VERSION_NUMBER 3034000
1176 #define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692392d"
1177
1178 /*
1179 ** CAPI3REF: Run-Time Library Version Numbers
1180 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1181 **
@@ -1550,10 +1550,11 @@
1550 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
1551 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
1552 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
1553 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
1554 #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
 
1555 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1556 #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
1557 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1558 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1559 #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
@@ -28182,16 +28183,19 @@
28182 EnableLookaside;
28183 }
28184 }
28185
28186 /*
28187 ** Take actions at the end of an API call to indicate an OOM error
28188 */
28189 static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
28190 sqlite3OomClear(db);
28191 sqlite3Error(db, SQLITE_NOMEM);
28192 return SQLITE_NOMEM_BKPT;
 
 
 
28193 }
28194
28195 /*
28196 ** This function must be called before exiting any API function (i.e.
28197 ** returning control to the user) that has called sqlite3_malloc or
@@ -28209,12 +28213,12 @@
28209 ** Otherwise the read (and possible write) of db->mallocFailed
28210 ** is unsafe, as is the call to sqlite3Error().
28211 */
28212 assert( db!=0 );
28213 assert( sqlite3_mutex_held(db->mutex) );
28214 if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28215 return apiOomError(db);
28216 }
28217 return rc & db->errMask;
28218 }
28219
28220 /************** End of malloc.c **********************************************/
@@ -37003,11 +37007,28 @@
37003
37004 got = seekAndRead(pFile, offset, pBuf, amt);
37005 if( got==amt ){
37006 return SQLITE_OK;
37007 }else if( got<0 ){
37008 /* lastErrno set by seekAndRead */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37009 return SQLITE_IOERR_READ;
37010 }else{
37011 storeLastErrno(pFile, 0); /* not a system error */
37012 /* Unread parts of the buffer must be zero-filled */
37013 memset(&((char*)pBuf)[got], 0, amt-got);
@@ -38535,11 +38556,11 @@
38535 if( bUnlock ){
38536 rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
38537 if( rc==SQLITE_OK ){
38538 memset(&aLock[ofst], 0, sizeof(int)*n);
38539 }
38540 }else if( p->sharedMask & (1<<ofst) ){
38541 assert( n==1 && aLock[ofst]>1 );
38542 aLock[ofst]--;
38543 }
38544
38545 /* Undo the local locks */
@@ -38568,11 +38589,11 @@
38568 /* Make sure no sibling connections hold locks that will block this
38569 ** lock. If any do, return SQLITE_BUSY right away. */
38570 int ii;
38571 for(ii=ofst; ii<ofst+n; ii++){
38572 assert( (p->sharedMask & mask)==0 );
38573 if( (p->exclMask & (1<<ii))==0 && aLock[ii] ){
38574 rc = SQLITE_BUSY;
38575 break;
38576 }
38577 }
38578
@@ -39964,19 +39985,39 @@
39964 }
39965 return SQLITE_OK;
39966 }
39967
39968 /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39969 **
 
 
39970 */
39971 static int mkFullPathname(
39972 const char *zPath, /* Input path */
39973 char *zOut, /* Output buffer */
39974 int nOut /* Allocated size of buffer zOut */
39975 ){
39976 int nPath = sqlite3Strlen30(zPath);
39977 int iOff = 0;
 
39978 if( zPath[0]!='/' ){
39979 if( osGetcwd(zOut, nOut-2)==0 ){
39980 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
39981 }
39982 iOff = sqlite3Strlen30(zOut);
@@ -39987,10 +40028,45 @@
39987 ** even if it returns an error. */
39988 zOut[iOff] = '\0';
39989 return SQLITE_CANTOPEN_BKPT;
39990 }
39991 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39992 return SQLITE_OK;
39993 }
39994
39995 /*
39996 ** Turn a relative pathname into a full pathname. The relative path
@@ -82192,13 +82268,16 @@
82192 ** equal to, or greater than the second (double).
82193 */
82194 static int sqlite3IntFloatCompare(i64 i, double r){
82195 if( sizeof(LONGDOUBLE_TYPE)>8 ){
82196 LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
 
 
 
82197 if( x<r ) return -1;
82198 if( x>r ) return +1;
82199 return 0;
82200 }else{
82201 i64 y;
82202 double s;
82203 if( r<-9223372036854775808.0 ) return +1;
82204 if( r>=9223372036854775808.0 ) return -1;
@@ -89388,11 +89467,11 @@
89388 assert( rc==SQLITE_OK );
89389 break;
89390 }
89391
89392
89393 /* Opcode: OpenEphemeral P1 P2 * P4 P5
89394 ** Synopsis: nColumn=P2
89395 **
89396 ** Open a new cursor P1 to a transient table.
89397 ** The cursor is always opened read/write even if
89398 ** the main database is read-only. The ephemeral
@@ -89408,10 +89487,14 @@
89408 **
89409 ** The P5 parameter can be a mask of the BTREE_* flags defined
89410 ** in btree.h. These flags control aspects of the operation of
89411 ** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
89412 ** added automatically.
 
 
 
 
89413 */
89414 /* Opcode: OpenAutoindex P1 P2 * P4 *
89415 ** Synopsis: nColumn=P2
89416 **
89417 ** This opcode works the same as OP_OpenEphemeral. It has a
@@ -89430,10 +89513,19 @@
89430 SQLITE_OPEN_EXCLUSIVE |
89431 SQLITE_OPEN_DELETEONCLOSE |
89432 SQLITE_OPEN_TRANSIENT_DB;
89433 assert( pOp->p1>=0 );
89434 assert( pOp->p2>=0 );
 
 
 
 
 
 
 
 
 
89435 pCx = p->apCsr[pOp->p1];
89436 if( pCx && pCx->pBtx ){
89437 /* If the ephermeral table is already open, erase all existing content
89438 ** so that the table is empty again, rather than creating a new table. */
89439 assert( pCx->isEphemeral );
@@ -90589,11 +90681,11 @@
90589 if( pOp->p5 & OPFLAG_ISNOOP ) break;
90590 #endif
90591
90592 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
90593 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
90594 assert( pData->flags & (MEM_Blob|MEM_Str) );
90595 x.pData = pData->z;
90596 x.nData = pData->n;
90597 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
90598 if( pData->flags & MEM_Zero ){
90599 x.nZero = pData->u.nZero;
@@ -93644,11 +93736,15 @@
93644
93645 /* If we reach this point, it means that execution is finished with
93646 ** an error of some kind.
93647 */
93648 abort_due_to_error:
93649 if( db->mallocFailed ) rc = SQLITE_NOMEM_BKPT;
 
 
 
 
93650 assert( rc );
93651 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
93652 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
93653 }
93654 p->rc = rc;
@@ -99381,10 +99477,11 @@
99381 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99382 int iCol = -1;
99383 Expr *pE, *pDup;
99384 if( pItem->done ) continue;
99385 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
 
99386 if( sqlite3ExprIsInteger(pE, &iCol) ){
99387 if( iCol<=0 || iCol>pEList->nExpr ){
99388 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
99389 return 1;
99390 }
@@ -99560,10 +99657,11 @@
99560 nResult = pSelect->pEList->nExpr;
99561 pParse = pNC->pParse;
99562 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99563 Expr *pE = pItem->pExpr;
99564 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
 
99565 if( zType[0]!='G' ){
99566 iCol = resolveAsName(pParse, pSelect->pEList, pE2);
99567 if( iCol>0 ){
99568 /* If an AS-name match is found, mark this ORDER BY column as being
99569 ** a copy of the iCol-th result-set column. The subsequent call to
@@ -103679,10 +103777,11 @@
103679 ** register iReg. The caller must ensure that iReg already contains
103680 ** the correct value for the expression.
103681 */
103682 static void exprToRegister(Expr *pExpr, int iReg){
103683 Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
 
103684 p->op2 = p->op;
103685 p->op = TK_REGISTER;
103686 p->iTable = iReg;
103687 ExprClearProperty(p, EP_Skip);
103688 }
@@ -104666,10 +104765,11 @@
104666 */
104667 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
104668 int r2;
104669 pExpr = sqlite3ExprSkipCollateAndLikely(pExpr);
104670 if( ConstFactorOk(pParse)
 
104671 && pExpr->op!=TK_REGISTER
104672 && sqlite3ExprIsConstantNotJoin(pExpr)
104673 ){
104674 *pReg = 0;
104675 r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
@@ -119424,10 +119524,12 @@
119424 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
119425 FUNCTION(replace, 3, 0, 0, replaceFunc ),
119426 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
119427 FUNCTION(substr, 2, 0, 0, substrFunc ),
119428 FUNCTION(substr, 3, 0, 0, substrFunc ),
 
 
119429 WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
119430 WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
119431 WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
119432 WAGGREGATE(count, 0,0,0, countStep,
119433 countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ),
@@ -131654,10 +131756,11 @@
131654 Column *aCol, *pCol; /* For looping over result columns */
131655 int nCol; /* Number of columns in the result set */
131656 char *zName; /* Column name */
131657 int nName; /* Size of name in zName[] */
131658 Hash ht; /* Hash table of column names */
 
131659
131660 sqlite3HashInit(&ht);
131661 if( pEList ){
131662 nCol = pEList->nExpr;
131663 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
@@ -131676,19 +131779,17 @@
131676 */
131677 if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
131678 /* If the column contains an "AS <name>" phrase, use <name> as the name */
131679 }else{
131680 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
131681 while( pColExpr->op==TK_DOT ){
131682 pColExpr = pColExpr->pRight;
131683 assert( pColExpr!=0 );
131684 }
131685 if( pColExpr->op==TK_COLUMN ){
131686 /* For columns use the column name name */
131687 int iCol = pColExpr->iColumn;
131688 Table *pTab = pColExpr->y.pTab;
131689 assert( pTab!=0 );
131690 if( iCol<0 ) iCol = pTab->iPKey;
131691 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
131692 }else if( pColExpr->op==TK_ID ){
131693 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
131694 zName = pColExpr->u.zToken;
@@ -136959,26 +137060,15 @@
136959 goto trigger_cleanup;
136960 }
136961 pTab = sqlite3SrcListLookup(pParse, pTableName);
136962 if( !pTab ){
136963 /* The table does not exist. */
136964 if( db->init.iDb==1 ){
136965 /* Ticket #3810.
136966 ** Normally, whenever a table is dropped, all associated triggers are
136967 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
136968 ** and the table is dropped by a different database connection, the
136969 ** trigger is not visible to the database connection that does the
136970 ** drop so the trigger cannot be dropped. This results in an
136971 ** "orphaned trigger" - a trigger whose associated table is missing.
136972 */
136973 db->init.orphanTrigger = 1;
136974 }
136975 goto trigger_cleanup;
136976 }
136977 if( IsVirtual(pTab) ){
136978 sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");
136979 goto trigger_cleanup;
136980 }
136981
136982 /* Check that the trigger name is not reserved and that no trigger of the
136983 ** specified name exists */
136984 zName = sqlite3NameFromToken(db, pName);
@@ -137012,16 +137102,16 @@
137012 ** of triggers.
137013 */
137014 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
137015 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
137016 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
137017 goto trigger_cleanup;
137018 }
137019 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
137020 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
137021 " trigger on table: %S", pTableName, 0);
137022 goto trigger_cleanup;
137023 }
137024
137025 #ifndef SQLITE_OMIT_AUTHORIZATION
137026 if( !IN_RENAME_OBJECT ){
137027 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -137077,10 +137167,27 @@
137077 if( !pParse->pNewTrigger ){
137078 sqlite3DeleteTrigger(db, pTrigger);
137079 }else{
137080 assert( pParse->pNewTrigger==pTrigger );
137081 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137082 }
137083
137084 /*
137085 ** This routine is called after all of the trigger actions have been parsed
137086 ** in order to complete the process of building the trigger.
@@ -138664,10 +138771,12 @@
138664 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
138665 }
138666
138667 if( nChangeFrom==0 && HasRowid(pTab) ){
138668 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
 
 
138669 }else{
138670 assert( pPk!=0 || HasRowid(pTab) );
138671 nPk = pPk ? pPk->nKeyCol : 0;
138672 iPk = pParse->nMem+1;
138673 pParse->nMem += nPk;
@@ -138755,13 +138864,14 @@
138755 /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
138756 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
138757 ** leave it in register regOldRowid. */
138758 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
138759 if( eOnePass==ONEPASS_OFF ){
138760 /* We need to use regRowSet, so reallocate aRegIdx[nAllIdx] */
138761 aRegIdx[nAllIdx] = ++pParse->nMem;
138762 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
 
 
138763 }
138764 }else{
138765 /* Read the PK of the current row into an array of registers. In
138766 ** ONEPASS_OFF mode, serialize the array into a record and store it in
138767 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
@@ -138845,12 +138955,13 @@
138845 sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
138846 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
138847 VdbeCoverage(v);
138848 }
138849 }else{
138850 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
138851 regOldRowid);
 
138852 VdbeCoverage(v);
138853 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
138854 VdbeCoverage(v);
138855 }
138856 }
@@ -139096,15 +139207,13 @@
139096 if( eOnePass==ONEPASS_SINGLE ){
139097 /* Nothing to do at end-of-loop for a single-pass */
139098 }else if( eOnePass==ONEPASS_MULTI ){
139099 sqlite3VdbeResolveLabel(v, labelContinue);
139100 sqlite3WhereEnd(pWInfo);
139101 }else if( pPk || nChangeFrom ){
139102 sqlite3VdbeResolveLabel(v, labelContinue);
139103 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
139104 }else{
139105 sqlite3VdbeGoto(v, labelContinue);
139106 }
139107 sqlite3VdbeResolveLabel(v, labelBreak);
139108
139109 /* Update the sqlite_sequence table by storing the content of the
139110 ** maximum rowid counter values recorded while inserting into
@@ -145894,10 +146003,11 @@
145894 ** all terms of the WHERE clause.
145895 */
145896 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
145897 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pExpr);
145898 pWC->op = op;
 
145899 if( pE2==0 ) return;
145900 if( pE2->op!=op ){
145901 whereClauseInsert(pWC, pExpr, 0);
145902 }else{
145903 sqlite3WhereSplit(pWC, pE2->pLeft, op);
@@ -146292,10 +146402,20 @@
146292 */
146293 static void createMask(WhereMaskSet *pMaskSet, int iCursor){
146294 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
146295 pMaskSet->ix[pMaskSet->n++] = iCursor;
146296 }
 
 
 
 
 
 
 
 
 
 
146297
146298 /*
146299 ** Advance to the next WhereTerm that matches according to the criteria
146300 ** established when the pScan object was initialized by whereScanInit().
146301 ** Return NULL if there are no more matching WhereTerms.
@@ -146323,12 +146443,11 @@
146323 pScan->pIdxExpr,iCur)==0)
146324 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
146325 ){
146326 if( (pTerm->eOperator & WO_EQUIV)!=0
146327 && pScan->nEquiv<ArraySize(pScan->aiCur)
146328 && (pX = sqlite3ExprSkipCollateAndLikely(pTerm->pExpr->pRight))->op
146329 ==TK_COLUMN
146330 ){
146331 int j;
146332 for(j=0; j<pScan->nEquiv; j++){
146333 if( pScan->aiCur[j]==pX->iTable
146334 && pScan->aiColumn[j]==pX->iColumn ){
@@ -146520,11 +146639,12 @@
146520 int i;
146521 const char *zColl = pIdx->azColl[iCol];
146522
146523 for(i=0; i<pList->nExpr; i++){
146524 Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
146525 if( p->op==TK_COLUMN
 
146526 && p->iColumn==pIdx->aiColumn[iCol]
146527 && p->iTable==iBase
146528 ){
146529 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
146530 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -146584,10 +146704,11 @@
146584 ** true. Note: The (p->iTable==iBase) part of this test may be false if the
146585 ** current SELECT is a correlated sub-query.
146586 */
146587 for(i=0; i<pDistinct->nExpr; i++){
146588 Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
 
146589 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
146590 }
146591
146592 /* Loop through all indices on the table, checking each to see if it makes
146593 ** the DISTINCT qualifier redundant. It does so if:
@@ -148498,13 +148619,13 @@
148498 LogEst rLogSize; /* Logarithm of table size */
148499 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
148500
148501 pNew = pBuilder->pNew;
148502 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
148503 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n",
148504 pProbe->pTable->zName,pProbe->zName,
148505 pNew->u.btree.nEq, pNew->nSkip));
148506
148507 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
148508 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
148509 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
148510 opMask = WO_LT|WO_LE;
@@ -148869,10 +148990,11 @@
148869
148870 if( pIndex->bUnordered ) return 0;
148871 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
148872 for(ii=0; ii<pOB->nExpr; ii++){
148873 Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
 
148874 if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
148875 if( pExpr->iColumn<0 ) return 1;
148876 for(jj=0; jj<pIndex->nKeyCol; jj++){
148877 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
148878 }
@@ -149847,10 +149969,11 @@
149847 ** loops.
149848 */
149849 for(i=0; i<nOrderBy; i++){
149850 if( MASKBIT(i) & obSat ) continue;
149851 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
 
149852 if( pOBExpr->op!=TK_COLUMN ) continue;
149853 if( pOBExpr->iTable!=iCur ) continue;
149854 pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
149855 ~ready, eqOpMask, 0);
149856 if( pTerm==0 ) continue;
@@ -149973,10 +150096,11 @@
149973 for(i=0; bOnce && i<nOrderBy; i++){
149974 if( MASKBIT(i) & obSat ) continue;
149975 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149976 testcase( wctrlFlags & WHERE_GROUPBY );
149977 testcase( wctrlFlags & WHERE_DISTINCTBY );
 
149978 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
149979 if( iColumn>=XN_ROWID ){
149980 if( pOBExpr->op!=TK_COLUMN ) continue;
149981 if( pOBExpr->iTable!=iCur ) continue;
149982 if( pOBExpr->iColumn!=iColumn ) continue;
@@ -150136,11 +150260,11 @@
150136 rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
150137 rSortCost = nRow + rScale + 16;
150138
150139 /* Multiple by log(M) where M is the number of output rows.
150140 ** Use the LIMIT for M if it is smaller. Or if this sort is for
150141 ** a DISTINT operator, M will be the number of distinct output
150142 ** rows, so fudge it downwards a bit.
150143 */
150144 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
150145 nRow = pWInfo->iLimit;
150146 }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
@@ -226679,11 +226803,11 @@
226679 int nArg, /* Number of args */
226680 sqlite3_value **apUnused /* Function arguments */
226681 ){
226682 assert( nArg==0 );
226683 UNUSED_PARAM2(nArg, apUnused);
226684 sqlite3_result_text(pCtx, "fts5: 2020-10-26 16:22:31 80eba105d6d1b49ba8ca2ad4e14ddec2de0bdc2f6686c2f8a1c1d24fc1fe846f", -1, SQLITE_TRANSIENT);
226685 }
226686
226687 /*
226688 ** Return true if zName is the extension on one of the shadow tables used
226689 ** by this module.
@@ -231602,12 +231726,12 @@
231602 }
231603 #endif /* SQLITE_CORE */
231604 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
231605
231606 /************** End of stmt.c ************************************************/
231607 #if __LINE__!=231607
231608 #undef SQLITE_SOURCE_ID
231609 #define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692alt2"
231610 #endif
231611 /* Return the source-id for this library */
231612 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
231613 /************************** End of sqlite3.c ******************************/
231614
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1171,11 +1171,11 @@
1171 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1172 ** [sqlite_version()] and [sqlite_source_id()].
1173 */
1174 #define SQLITE_VERSION "3.34.0"
1175 #define SQLITE_VERSION_NUMBER 3034000
1176 #define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0b020"
1177
1178 /*
1179 ** CAPI3REF: Run-Time Library Version Numbers
1180 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1181 **
@@ -1550,10 +1550,11 @@
1550 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
1551 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
1552 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
1553 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
1554 #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
1555 #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
1556 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1557 #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
1558 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1559 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1560 #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
@@ -28182,16 +28183,19 @@
28183 EnableLookaside;
28184 }
28185 }
28186
28187 /*
28188 ** Take actions at the end of an API call to deal with error codes.
28189 */
28190 static SQLITE_NOINLINE int apiHandleError(sqlite3 *db, int rc){
28191 if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28192 sqlite3OomClear(db);
28193 sqlite3Error(db, SQLITE_NOMEM);
28194 return SQLITE_NOMEM_BKPT;
28195 }
28196 return rc & db->errMask;
28197 }
28198
28199 /*
28200 ** This function must be called before exiting any API function (i.e.
28201 ** returning control to the user) that has called sqlite3_malloc or
@@ -28209,12 +28213,12 @@
28213 ** Otherwise the read (and possible write) of db->mallocFailed
28214 ** is unsafe, as is the call to sqlite3Error().
28215 */
28216 assert( db!=0 );
28217 assert( sqlite3_mutex_held(db->mutex) );
28218 if( db->mallocFailed || rc ){
28219 return apiHandleError(db, rc);
28220 }
28221 return rc & db->errMask;
28222 }
28223
28224 /************** End of malloc.c **********************************************/
@@ -37003,11 +37007,28 @@
37007
37008 got = seekAndRead(pFile, offset, pBuf, amt);
37009 if( got==amt ){
37010 return SQLITE_OK;
37011 }else if( got<0 ){
37012 /* pFile->lastErrno has been set by seekAndRead().
37013 ** Usually we return SQLITE_IOERR_READ here, though for some
37014 ** kinds of errors we return SQLITE_IOERR_CORRUPTFS. The
37015 ** SQLITE_IOERR_CORRUPTFS will be converted into SQLITE_CORRUPT
37016 ** prior to returning to the application by the sqlite3ApiExit()
37017 ** routine.
37018 */
37019 switch( pFile->lastErrno ){
37020 case ERANGE:
37021 case EIO:
37022 #ifdef ENXIO
37023 case ENXIO:
37024 #endif
37025 #ifdef EDEVERR
37026 case EDEVERR:
37027 #endif
37028 return SQLITE_IOERR_CORRUPTFS;
37029 }
37030 return SQLITE_IOERR_READ;
37031 }else{
37032 storeLastErrno(pFile, 0); /* not a system error */
37033 /* Unread parts of the buffer must be zero-filled */
37034 memset(&((char*)pBuf)[got], 0, amt-got);
@@ -38535,11 +38556,11 @@
38556 if( bUnlock ){
38557 rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
38558 if( rc==SQLITE_OK ){
38559 memset(&aLock[ofst], 0, sizeof(int)*n);
38560 }
38561 }else if( ALWAYS(p->sharedMask & (1<<ofst)) ){
38562 assert( n==1 && aLock[ofst]>1 );
38563 aLock[ofst]--;
38564 }
38565
38566 /* Undo the local locks */
@@ -38568,11 +38589,11 @@
38589 /* Make sure no sibling connections hold locks that will block this
38590 ** lock. If any do, return SQLITE_BUSY right away. */
38591 int ii;
38592 for(ii=ofst; ii<ofst+n; ii++){
38593 assert( (p->sharedMask & mask)==0 );
38594 if( ALWAYS((p->exclMask & (1<<ii))==0) && aLock[ii] ){
38595 rc = SQLITE_BUSY;
38596 break;
38597 }
38598 }
38599
@@ -39964,19 +39985,39 @@
39985 }
39986 return SQLITE_OK;
39987 }
39988
39989 /*
39990 ** If the last component of the pathname in z[0]..z[j-1] is something
39991 ** other than ".." then back it out and return true. If the last
39992 ** component is empty or if it is ".." then return false.
39993 */
39994 static int unixBackupDir(const char *z, int *pJ){
39995 int j = *pJ;
39996 int i;
39997 if( j<=0 ) return 0;
39998 for(i=j-1; ALWAYS(i>0) && z[i-1]!='/'; i--){}
39999 if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
40000 *pJ = i-1;
40001 return 1;
40002 }
40003
40004 /*
40005 ** Convert a relative pathname into a full pathname. Also
40006 ** simplify the pathname as follows:
40007 **
40008 ** Remove all instances of /./
40009 ** Remove all isntances of /X/../ for any X
40010 */
40011 static int mkFullPathname(
40012 const char *zPath, /* Input path */
40013 char *zOut, /* Output buffer */
40014 int nOut /* Allocated size of buffer zOut */
40015 ){
40016 int nPath = sqlite3Strlen30(zPath);
40017 int iOff = 0;
40018 int i, j;
40019 if( zPath[0]!='/' ){
40020 if( osGetcwd(zOut, nOut-2)==0 ){
40021 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
40022 }
40023 iOff = sqlite3Strlen30(zOut);
@@ -39987,10 +40028,45 @@
40028 ** even if it returns an error. */
40029 zOut[iOff] = '\0';
40030 return SQLITE_CANTOPEN_BKPT;
40031 }
40032 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
40033
40034 /* Remove duplicate '/' characters. Except, two // at the beginning
40035 ** of a pathname is allowed since this is important on windows. */
40036 for(i=j=1; zOut[i]; i++){
40037 zOut[j++] = zOut[i];
40038 while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
40039 }
40040 zOut[j] = 0;
40041
40042 assert( zOut[0]=='/' );
40043 for(i=j=0; zOut[i]; i++){
40044 if( zOut[i]=='/' ){
40045 /* Skip over internal "/." directory components */
40046 if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
40047 i += 1;
40048 continue;
40049 }
40050
40051 /* If this is a "/.." directory component then back out the
40052 ** previous term of the directory if it is something other than "..".
40053 */
40054 if( zOut[i+1]=='.'
40055 && zOut[i+2]=='.'
40056 && zOut[i+3]=='/'
40057 && unixBackupDir(zOut, &j)
40058 ){
40059 i += 2;
40060 continue;
40061 }
40062 }
40063 if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
40064 j++;
40065 }
40066 if( NEVER(j==0) ) zOut[j++] = '/';
40067 zOut[j] = 0;
40068 return SQLITE_OK;
40069 }
40070
40071 /*
40072 ** Turn a relative pathname into a full pathname. The relative path
@@ -82192,13 +82268,16 @@
82268 ** equal to, or greater than the second (double).
82269 */
82270 static int sqlite3IntFloatCompare(i64 i, double r){
82271 if( sizeof(LONGDOUBLE_TYPE)>8 ){
82272 LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
82273 testcase( x<r );
82274 testcase( x>r );
82275 testcase( x==r );
82276 if( x<r ) return -1;
82277 if( x>r ) return +1; /*NO_TEST*/ /* work around bugs in gcov */
82278 return 0; /*NO_TEST*/ /* work around bugs in gcov */
82279 }else{
82280 i64 y;
82281 double s;
82282 if( r<-9223372036854775808.0 ) return +1;
82283 if( r>=9223372036854775808.0 ) return -1;
@@ -89388,11 +89467,11 @@
89467 assert( rc==SQLITE_OK );
89468 break;
89469 }
89470
89471
89472 /* Opcode: OpenEphemeral P1 P2 P3 P4 P5
89473 ** Synopsis: nColumn=P2
89474 **
89475 ** Open a new cursor P1 to a transient table.
89476 ** The cursor is always opened read/write even if
89477 ** the main database is read-only. The ephemeral
@@ -89408,10 +89487,14 @@
89487 **
89488 ** The P5 parameter can be a mask of the BTREE_* flags defined
89489 ** in btree.h. These flags control aspects of the operation of
89490 ** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
89491 ** added automatically.
89492 **
89493 ** If P3 is positive, then reg[P3] is modified slightly so that it
89494 ** can be used as zero-length data for OP_Insert. This is an optimization
89495 ** that avoids an extra OP_Blob opcode to initialize that register.
89496 */
89497 /* Opcode: OpenAutoindex P1 P2 * P4 *
89498 ** Synopsis: nColumn=P2
89499 **
89500 ** This opcode works the same as OP_OpenEphemeral. It has a
@@ -89430,10 +89513,19 @@
89513 SQLITE_OPEN_EXCLUSIVE |
89514 SQLITE_OPEN_DELETEONCLOSE |
89515 SQLITE_OPEN_TRANSIENT_DB;
89516 assert( pOp->p1>=0 );
89517 assert( pOp->p2>=0 );
89518 if( pOp->p3>0 ){
89519 /* Make register reg[P3] into a value that can be used as the data
89520 ** form sqlite3BtreeInsert() where the length of the data is zero. */
89521 assert( pOp->p2==0 ); /* Only used when number of columns is zero */
89522 assert( pOp->opcode==OP_OpenEphemeral );
89523 assert( aMem[pOp->p3].flags & MEM_Null );
89524 aMem[pOp->p3].n = 0;
89525 aMem[pOp->p3].z = "";
89526 }
89527 pCx = p->apCsr[pOp->p1];
89528 if( pCx && pCx->pBtx ){
89529 /* If the ephermeral table is already open, erase all existing content
89530 ** so that the table is empty again, rather than creating a new table. */
89531 assert( pCx->isEphemeral );
@@ -90589,11 +90681,11 @@
90681 if( pOp->p5 & OPFLAG_ISNOOP ) break;
90682 #endif
90683
90684 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
90685 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
90686 assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
90687 x.pData = pData->z;
90688 x.nData = pData->n;
90689 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
90690 if( pData->flags & MEM_Zero ){
90691 x.nZero = pData->u.nZero;
@@ -93644,11 +93736,15 @@
93736
93737 /* If we reach this point, it means that execution is finished with
93738 ** an error of some kind.
93739 */
93740 abort_due_to_error:
93741 if( db->mallocFailed ){
93742 rc = SQLITE_NOMEM_BKPT;
93743 }else if( rc==SQLITE_IOERR_CORRUPTFS ){
93744 rc = SQLITE_CORRUPT_BKPT;
93745 }
93746 assert( rc );
93747 if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
93748 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
93749 }
93750 p->rc = rc;
@@ -99381,10 +99477,11 @@
99477 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99478 int iCol = -1;
99479 Expr *pE, *pDup;
99480 if( pItem->done ) continue;
99481 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
99482 if( NEVER(pE==0) ) continue;
99483 if( sqlite3ExprIsInteger(pE, &iCol) ){
99484 if( iCol<=0 || iCol>pEList->nExpr ){
99485 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
99486 return 1;
99487 }
@@ -99560,10 +99657,11 @@
99657 nResult = pSelect->pEList->nExpr;
99658 pParse = pNC->pParse;
99659 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
99660 Expr *pE = pItem->pExpr;
99661 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
99662 if( NEVER(pE2==0) ) continue;
99663 if( zType[0]!='G' ){
99664 iCol = resolveAsName(pParse, pSelect->pEList, pE2);
99665 if( iCol>0 ){
99666 /* If an AS-name match is found, mark this ORDER BY column as being
99667 ** a copy of the iCol-th result-set column. The subsequent call to
@@ -103679,10 +103777,11 @@
103777 ** register iReg. The caller must ensure that iReg already contains
103778 ** the correct value for the expression.
103779 */
103780 static void exprToRegister(Expr *pExpr, int iReg){
103781 Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
103782 if( NEVER(p==0) ) return;
103783 p->op2 = p->op;
103784 p->op = TK_REGISTER;
103785 p->iTable = iReg;
103786 ExprClearProperty(p, EP_Skip);
103787 }
@@ -104666,10 +104765,11 @@
104765 */
104766 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
104767 int r2;
104768 pExpr = sqlite3ExprSkipCollateAndLikely(pExpr);
104769 if( ConstFactorOk(pParse)
104770 && ALWAYS(pExpr!=0)
104771 && pExpr->op!=TK_REGISTER
104772 && sqlite3ExprIsConstantNotJoin(pExpr)
104773 ){
104774 *pReg = 0;
104775 r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
@@ -119424,10 +119524,12 @@
119524 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
119525 FUNCTION(replace, 3, 0, 0, replaceFunc ),
119526 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
119527 FUNCTION(substr, 2, 0, 0, substrFunc ),
119528 FUNCTION(substr, 3, 0, 0, substrFunc ),
119529 FUNCTION(substring, 2, 0, 0, substrFunc ),
119530 FUNCTION(substring, 3, 0, 0, substrFunc ),
119531 WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
119532 WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
119533 WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
119534 WAGGREGATE(count, 0,0,0, countStep,
119535 countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ),
@@ -131654,10 +131756,11 @@
131756 Column *aCol, *pCol; /* For looping over result columns */
131757 int nCol; /* Number of columns in the result set */
131758 char *zName; /* Column name */
131759 int nName; /* Size of name in zName[] */
131760 Hash ht; /* Hash table of column names */
131761 Table *pTab;
131762
131763 sqlite3HashInit(&ht);
131764 if( pEList ){
131765 nCol = pEList->nExpr;
131766 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
@@ -131676,19 +131779,17 @@
131779 */
131780 if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){
131781 /* If the column contains an "AS <name>" phrase, use <name> as the name */
131782 }else{
131783 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
131784 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
131785 pColExpr = pColExpr->pRight;
131786 assert( pColExpr!=0 );
131787 }
131788 if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
131789 /* For columns use the column name name */
131790 int iCol = pColExpr->iColumn;
 
 
131791 if( iCol<0 ) iCol = pTab->iPKey;
131792 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
131793 }else if( pColExpr->op==TK_ID ){
131794 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
131795 zName = pColExpr->u.zToken;
@@ -136959,26 +137060,15 @@
137060 goto trigger_cleanup;
137061 }
137062 pTab = sqlite3SrcListLookup(pParse, pTableName);
137063 if( !pTab ){
137064 /* The table does not exist. */
137065 goto trigger_orphan_error;
 
 
 
 
 
 
 
 
 
 
 
137066 }
137067 if( IsVirtual(pTab) ){
137068 sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");
137069 goto trigger_orphan_error;
137070 }
137071
137072 /* Check that the trigger name is not reserved and that no trigger of the
137073 ** specified name exists */
137074 zName = sqlite3NameFromToken(db, pName);
@@ -137012,16 +137102,16 @@
137102 ** of triggers.
137103 */
137104 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
137105 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
137106 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
137107 goto trigger_orphan_error;
137108 }
137109 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
137110 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
137111 " trigger on table: %S", pTableName, 0);
137112 goto trigger_orphan_error;
137113 }
137114
137115 #ifndef SQLITE_OMIT_AUTHORIZATION
137116 if( !IN_RENAME_OBJECT ){
137117 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -137077,10 +137167,27 @@
137167 if( !pParse->pNewTrigger ){
137168 sqlite3DeleteTrigger(db, pTrigger);
137169 }else{
137170 assert( pParse->pNewTrigger==pTrigger );
137171 }
137172 return;
137173
137174 trigger_orphan_error:
137175 if( db->init.iDb==1 ){
137176 /* Ticket #3810.
137177 ** Normally, whenever a table is dropped, all associated triggers are
137178 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
137179 ** and the table is dropped by a different database connection, the
137180 ** trigger is not visible to the database connection that does the
137181 ** drop so the trigger cannot be dropped. This results in an
137182 ** "orphaned trigger" - a trigger whose associated table is missing.
137183 **
137184 ** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
137185 */
137186 db->init.orphanTrigger = 1;
137187 }
137188 goto trigger_cleanup;
137189 }
137190
137191 /*
137192 ** This routine is called after all of the trigger actions have been parsed
137193 ** in order to complete the process of building the trigger.
@@ -138664,10 +138771,12 @@
138771 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
138772 }
138773
138774 if( nChangeFrom==0 && HasRowid(pTab) ){
138775 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
138776 iEph = pParse->nTab++;
138777 addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet);
138778 }else{
138779 assert( pPk!=0 || HasRowid(pTab) );
138780 nPk = pPk ? pPk->nKeyCol : 0;
138781 iPk = pParse->nMem+1;
138782 pParse->nMem += nPk;
@@ -138755,13 +138864,14 @@
138864 /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
138865 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
138866 ** leave it in register regOldRowid. */
138867 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
138868 if( eOnePass==ONEPASS_OFF ){
 
138869 aRegIdx[nAllIdx] = ++pParse->nMem;
138870 sqlite3VdbeAddOp3(v, OP_Insert, iEph, regRowSet, regOldRowid);
138871 }else{
138872 if( ALWAYS(addrOpen) ) sqlite3VdbeChangeToNoop(v, addrOpen);
138873 }
138874 }else{
138875 /* Read the PK of the current row into an array of registers. In
138876 ** ONEPASS_OFF mode, serialize the array into a record and store it in
138877 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
@@ -138845,12 +138955,13 @@
138955 sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
138956 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey,0);
138957 VdbeCoverage(v);
138958 }
138959 }else{
138960 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
138961 labelContinue = sqlite3VdbeMakeLabel(pParse);
138962 addrTop = sqlite3VdbeAddOp2(v, OP_Rowid, iEph, regOldRowid);
138963 VdbeCoverage(v);
138964 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
138965 VdbeCoverage(v);
138966 }
138967 }
@@ -139096,15 +139207,13 @@
139207 if( eOnePass==ONEPASS_SINGLE ){
139208 /* Nothing to do at end-of-loop for a single-pass */
139209 }else if( eOnePass==ONEPASS_MULTI ){
139210 sqlite3VdbeResolveLabel(v, labelContinue);
139211 sqlite3WhereEnd(pWInfo);
139212 }else{
139213 sqlite3VdbeResolveLabel(v, labelContinue);
139214 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
 
 
139215 }
139216 sqlite3VdbeResolveLabel(v, labelBreak);
139217
139218 /* Update the sqlite_sequence table by storing the content of the
139219 ** maximum rowid counter values recorded while inserting into
@@ -145894,10 +146003,11 @@
146003 ** all terms of the WHERE clause.
146004 */
146005 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
146006 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pExpr);
146007 pWC->op = op;
146008 assert( pE2!=0 || pExpr==0 );
146009 if( pE2==0 ) return;
146010 if( pE2->op!=op ){
146011 whereClauseInsert(pWC, pExpr, 0);
146012 }else{
146013 sqlite3WhereSplit(pWC, pE2->pLeft, op);
@@ -146292,10 +146402,20 @@
146402 */
146403 static void createMask(WhereMaskSet *pMaskSet, int iCursor){
146404 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
146405 pMaskSet->ix[pMaskSet->n++] = iCursor;
146406 }
146407
146408 /*
146409 ** If the right-hand branch of the expression is a TK_COLUMN, then return
146410 ** a pointer to the right-hand branch. Otherwise, return NULL.
146411 */
146412 static Expr *whereRightSubexprIsColumn(Expr *p){
146413 p = sqlite3ExprSkipCollateAndLikely(p->pRight);
146414 if( ALWAYS(p!=0) && p->op==TK_COLUMN ) return p;
146415 return 0;
146416 }
146417
146418 /*
146419 ** Advance to the next WhereTerm that matches according to the criteria
146420 ** established when the pScan object was initialized by whereScanInit().
146421 ** Return NULL if there are no more matching WhereTerms.
@@ -146323,12 +146443,11 @@
146443 pScan->pIdxExpr,iCur)==0)
146444 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
146445 ){
146446 if( (pTerm->eOperator & WO_EQUIV)!=0
146447 && pScan->nEquiv<ArraySize(pScan->aiCur)
146448 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
 
146449 ){
146450 int j;
146451 for(j=0; j<pScan->nEquiv; j++){
146452 if( pScan->aiCur[j]==pX->iTable
146453 && pScan->aiColumn[j]==pX->iColumn ){
@@ -146520,11 +146639,12 @@
146639 int i;
146640 const char *zColl = pIdx->azColl[iCol];
146641
146642 for(i=0; i<pList->nExpr; i++){
146643 Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
146644 if( ALWAYS(p!=0)
146645 && p->op==TK_COLUMN
146646 && p->iColumn==pIdx->aiColumn[iCol]
146647 && p->iTable==iBase
146648 ){
146649 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
146650 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -146584,10 +146704,11 @@
146704 ** true. Note: The (p->iTable==iBase) part of this test may be false if the
146705 ** current SELECT is a correlated sub-query.
146706 */
146707 for(i=0; i<pDistinct->nExpr; i++){
146708 Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
146709 if( NEVER(p==0) ) continue;
146710 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
146711 }
146712
146713 /* Loop through all indices on the table, checking each to see if it makes
146714 ** the DISTINCT qualifier redundant. It does so if:
@@ -148498,13 +148619,13 @@
148619 LogEst rLogSize; /* Logarithm of table size */
148620 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
148621
148622 pNew = pBuilder->pNew;
148623 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
148624 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
148625 pProbe->pTable->zName,pProbe->zName,
148626 pNew->u.btree.nEq, pNew->nSkip, pNew->rRun));
148627
148628 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
148629 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
148630 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
148631 opMask = WO_LT|WO_LE;
@@ -148869,10 +148990,11 @@
148990
148991 if( pIndex->bUnordered ) return 0;
148992 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
148993 for(ii=0; ii<pOB->nExpr; ii++){
148994 Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
148995 if( NEVER(pExpr==0) ) continue;
148996 if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
148997 if( pExpr->iColumn<0 ) return 1;
148998 for(jj=0; jj<pIndex->nKeyCol; jj++){
148999 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
149000 }
@@ -149847,10 +149969,11 @@
149969 ** loops.
149970 */
149971 for(i=0; i<nOrderBy; i++){
149972 if( MASKBIT(i) & obSat ) continue;
149973 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
149974 if( NEVER(pOBExpr==0) ) continue;
149975 if( pOBExpr->op!=TK_COLUMN ) continue;
149976 if( pOBExpr->iTable!=iCur ) continue;
149977 pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
149978 ~ready, eqOpMask, 0);
149979 if( pTerm==0 ) continue;
@@ -149973,10 +150096,11 @@
150096 for(i=0; bOnce && i<nOrderBy; i++){
150097 if( MASKBIT(i) & obSat ) continue;
150098 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
150099 testcase( wctrlFlags & WHERE_GROUPBY );
150100 testcase( wctrlFlags & WHERE_DISTINCTBY );
150101 if( NEVER(pOBExpr==0) ) continue;
150102 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
150103 if( iColumn>=XN_ROWID ){
150104 if( pOBExpr->op!=TK_COLUMN ) continue;
150105 if( pOBExpr->iTable!=iCur ) continue;
150106 if( pOBExpr->iColumn!=iColumn ) continue;
@@ -150136,11 +150260,11 @@
150260 rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
150261 rSortCost = nRow + rScale + 16;
150262
150263 /* Multiple by log(M) where M is the number of output rows.
150264 ** Use the LIMIT for M if it is smaller. Or if this sort is for
150265 ** a DISTINCT operator, M will be the number of distinct output
150266 ** rows, so fudge it downwards a bit.
150267 */
150268 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
150269 nRow = pWInfo->iLimit;
150270 }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
@@ -226679,11 +226803,11 @@
226803 int nArg, /* Number of args */
226804 sqlite3_value **apUnused /* Function arguments */
226805 ){
226806 assert( nArg==0 );
226807 UNUSED_PARAM2(nArg, apUnused);
226808 sqlite3_result_text(pCtx, "fts5: 2020-11-19 21:12:08 c38dec6f52c01614c1bee8356daf0fcd9f708d029116e9bff51e06719a730dde", -1, SQLITE_TRANSIENT);
226809 }
226810
226811 /*
226812 ** Return true if zName is the extension on one of the shadow tables used
226813 ** by this module.
@@ -231602,12 +231726,12 @@
231726 }
231727 #endif /* SQLITE_CORE */
231728 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
231729
231730 /************** End of stmt.c ************************************************/
231731 #if __LINE__!=231731
231732 #undef SQLITE_SOURCE_ID
231733 #define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0alt2"
231734 #endif
231735 /* Return the source-id for this library */
231736 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
231737 /************************** End of sqlite3.c ******************************/
231738
+2 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.34.0"
127127
#define SQLITE_VERSION_NUMBER 3034000
128
-#define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692392d"
128
+#define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0b020"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -502,10 +502,11 @@
502502
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
503503
#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
504504
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
505505
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
506506
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
507
+#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
507508
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
508509
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
509510
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
510511
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
511512
#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
512513
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.34.0"
127 #define SQLITE_VERSION_NUMBER 3034000
128 #define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692392d"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -502,10 +502,11 @@
502 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
503 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
504 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
505 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
506 #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
 
507 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
508 #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
509 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
510 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
511 #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
512
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.34.0"
127 #define SQLITE_VERSION_NUMBER 3034000
128 #define SQLITE_SOURCE_ID "2020-11-23 21:05:29 4f1573b146193e5d552981a9d1d11e50da4da4a843f790e4af1cf0cc19a0b020"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -502,10 +502,11 @@
502 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
503 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
504 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
505 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
506 #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
507 #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
508 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
509 #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
510 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
511 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
512 #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
513

Keyboard Shortcuts

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