Fossil SCM

Update the built-in SQLite to the latest 3.38.0 beta that includes the performance enhancements on the datetime() function.

drh 2022-02-10 15:50 trunk
Commit 740d655e553f0ef184c78a96ed8dd62a3b4f22da683da773ab0dcb0c87358c90
+35 -17
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -13714,21 +13714,28 @@
1371413714
/*
1371513715
** Allocate space and save off string indicating current error.
1371613716
*/
1371713717
static char *save_err_msg(
1371813718
sqlite3 *db, /* Database to query */
13719
- const char *zWhen, /* Qualifier (format) wrapper */
13719
+ const char *zPhase, /* When the error occcurs */
1372013720
int rc, /* Error code returned from API */
1372113721
const char *zSql /* SQL string, or NULL */
1372213722
){
1372313723
char *zErr;
1372413724
char *zContext;
13725
- if( zWhen==0 ) zWhen = "%s (%d)%s";
13725
+ sqlite3_str *pStr = sqlite3_str_new(0);
13726
+ sqlite3_str_appendf(pStr, "%s, %s", zPhase, sqlite3_errmsg(db));
13727
+ if( rc>1 ){
13728
+ sqlite3_str_appendf(pStr, " (%d)", rc);
13729
+ }
1372613730
zContext = shell_error_context(zSql, db);
13727
- zErr = sqlite3_mprintf(zWhen, sqlite3_errmsg(db), rc, zContext);
13731
+ if( zContext ){
13732
+ sqlite3_str_appendall(pStr, zContext);
13733
+ sqlite3_free(zContext);
13734
+ }
13735
+ zErr = sqlite3_str_finish(pStr);
1372813736
shell_check_oom(zErr);
13729
- sqlite3_free(zContext);
1373013737
return zErr;
1373113738
}
1373213739
1373313740
#ifdef __linux__
1373413741
/*
@@ -14855,11 +14862,11 @@
1485514862
while( zSql[0] && (SQLITE_OK == rc) ){
1485614863
static const char *zStmtSql;
1485714864
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1485814865
if( SQLITE_OK != rc ){
1485914866
if( pzErrMsg ){
14860
- *pzErrMsg = save_err_msg(db, "in prepare, %s (%d)%s", rc, zSql);
14867
+ *pzErrMsg = save_err_msg(db, "in prepare", rc, zSql);
1486114868
}
1486214869
}else{
1486314870
if( !pStmt ){
1486414871
/* this happens for a comment or white-space */
1486514872
zSql = zLeftover;
@@ -14971,11 +14978,11 @@
1497114978
if( rc!=SQLITE_NOMEM ) rc = rc2;
1497214979
if( rc==SQLITE_OK ){
1497314980
zSql = zLeftover;
1497414981
while( IsSpace(zSql[0]) ) zSql++;
1497514982
}else if( pzErrMsg ){
14976
- *pzErrMsg = save_err_msg(db, "stepping, %s (%d)", rc, 0);
14983
+ *pzErrMsg = save_err_msg(db, "stepping", rc, 0);
1497714984
}
1497814985
1497914986
/* clear saved stmt handle */
1498014987
if( pArg ){
1498114988
pArg->pStmt = NULL;
@@ -22256,23 +22263,34 @@
2225622263
BEGIN_TIMER;
2225722264
rc = shell_exec(p, zSql, &zErrMsg);
2225822265
END_TIMER;
2225922266
if( rc || zErrMsg ){
2226022267
char zPrefix[100];
22268
+ const char *zErrorTail;
22269
+ const char *zErrorType;
22270
+ if( zErrMsg==0 ){
22271
+ zErrorType = "Error";
22272
+ zErrorTail = sqlite3_errmsg(p->db);
22273
+ }else if( strncmp(zErrMsg, "in prepare, ",12)==0 ){
22274
+ zErrorType = "Parse error";
22275
+ zErrorTail = &zErrMsg[12];
22276
+ }else if( strncmp(zErrMsg, "stepping, ", 10)==0 ){
22277
+ zErrorType = "Runtime error";
22278
+ zErrorTail = &zErrMsg[10];
22279
+ }else{
22280
+ zErrorType = "Error";
22281
+ zErrorTail = zErrMsg;
22282
+ }
2226122283
if( in!=0 || !stdin_is_interactive ){
2226222284
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
22263
- "Error: near line %d:", startline);
22264
- }else{
22265
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
22266
- }
22267
- if( zErrMsg!=0 ){
22268
- utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
22269
- sqlite3_free(zErrMsg);
22270
- zErrMsg = 0;
22271
- }else{
22272
- utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
22273
- }
22285
+ "%s near line %d:", zErrorType, startline);
22286
+ }else{
22287
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
22288
+ }
22289
+ utf8_printf(stderr, "%s %s\n", zPrefix, zErrorTail);
22290
+ sqlite3_free(zErrMsg);
22291
+ zErrMsg = 0;
2227422292
return 1;
2227522293
}else if( ShellHasFlag(p, SHFLG_CountChanges) ){
2227622294
char zLineBuf[2000];
2227722295
sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
2227822296
"changes: %lld total_changes: %lld",
2227922297
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -13714,21 +13714,28 @@
13714 /*
13715 ** Allocate space and save off string indicating current error.
13716 */
13717 static char *save_err_msg(
13718 sqlite3 *db, /* Database to query */
13719 const char *zWhen, /* Qualifier (format) wrapper */
13720 int rc, /* Error code returned from API */
13721 const char *zSql /* SQL string, or NULL */
13722 ){
13723 char *zErr;
13724 char *zContext;
13725 if( zWhen==0 ) zWhen = "%s (%d)%s";
 
 
 
 
13726 zContext = shell_error_context(zSql, db);
13727 zErr = sqlite3_mprintf(zWhen, sqlite3_errmsg(db), rc, zContext);
 
 
 
 
13728 shell_check_oom(zErr);
13729 sqlite3_free(zContext);
13730 return zErr;
13731 }
13732
13733 #ifdef __linux__
13734 /*
@@ -14855,11 +14862,11 @@
14855 while( zSql[0] && (SQLITE_OK == rc) ){
14856 static const char *zStmtSql;
14857 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
14858 if( SQLITE_OK != rc ){
14859 if( pzErrMsg ){
14860 *pzErrMsg = save_err_msg(db, "in prepare, %s (%d)%s", rc, zSql);
14861 }
14862 }else{
14863 if( !pStmt ){
14864 /* this happens for a comment or white-space */
14865 zSql = zLeftover;
@@ -14971,11 +14978,11 @@
14971 if( rc!=SQLITE_NOMEM ) rc = rc2;
14972 if( rc==SQLITE_OK ){
14973 zSql = zLeftover;
14974 while( IsSpace(zSql[0]) ) zSql++;
14975 }else if( pzErrMsg ){
14976 *pzErrMsg = save_err_msg(db, "stepping, %s (%d)", rc, 0);
14977 }
14978
14979 /* clear saved stmt handle */
14980 if( pArg ){
14981 pArg->pStmt = NULL;
@@ -22256,23 +22263,34 @@
22256 BEGIN_TIMER;
22257 rc = shell_exec(p, zSql, &zErrMsg);
22258 END_TIMER;
22259 if( rc || zErrMsg ){
22260 char zPrefix[100];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22261 if( in!=0 || !stdin_is_interactive ){
22262 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
22263 "Error: near line %d:", startline);
22264 }else{
22265 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
22266 }
22267 if( zErrMsg!=0 ){
22268 utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
22269 sqlite3_free(zErrMsg);
22270 zErrMsg = 0;
22271 }else{
22272 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
22273 }
22274 return 1;
22275 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
22276 char zLineBuf[2000];
22277 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
22278 "changes: %lld total_changes: %lld",
22279
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -13714,21 +13714,28 @@
13714 /*
13715 ** Allocate space and save off string indicating current error.
13716 */
13717 static char *save_err_msg(
13718 sqlite3 *db, /* Database to query */
13719 const char *zPhase, /* When the error occcurs */
13720 int rc, /* Error code returned from API */
13721 const char *zSql /* SQL string, or NULL */
13722 ){
13723 char *zErr;
13724 char *zContext;
13725 sqlite3_str *pStr = sqlite3_str_new(0);
13726 sqlite3_str_appendf(pStr, "%s, %s", zPhase, sqlite3_errmsg(db));
13727 if( rc>1 ){
13728 sqlite3_str_appendf(pStr, " (%d)", rc);
13729 }
13730 zContext = shell_error_context(zSql, db);
13731 if( zContext ){
13732 sqlite3_str_appendall(pStr, zContext);
13733 sqlite3_free(zContext);
13734 }
13735 zErr = sqlite3_str_finish(pStr);
13736 shell_check_oom(zErr);
 
13737 return zErr;
13738 }
13739
13740 #ifdef __linux__
13741 /*
@@ -14855,11 +14862,11 @@
14862 while( zSql[0] && (SQLITE_OK == rc) ){
14863 static const char *zStmtSql;
14864 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
14865 if( SQLITE_OK != rc ){
14866 if( pzErrMsg ){
14867 *pzErrMsg = save_err_msg(db, "in prepare", rc, zSql);
14868 }
14869 }else{
14870 if( !pStmt ){
14871 /* this happens for a comment or white-space */
14872 zSql = zLeftover;
@@ -14971,11 +14978,11 @@
14978 if( rc!=SQLITE_NOMEM ) rc = rc2;
14979 if( rc==SQLITE_OK ){
14980 zSql = zLeftover;
14981 while( IsSpace(zSql[0]) ) zSql++;
14982 }else if( pzErrMsg ){
14983 *pzErrMsg = save_err_msg(db, "stepping", rc, 0);
14984 }
14985
14986 /* clear saved stmt handle */
14987 if( pArg ){
14988 pArg->pStmt = NULL;
@@ -22256,23 +22263,34 @@
22263 BEGIN_TIMER;
22264 rc = shell_exec(p, zSql, &zErrMsg);
22265 END_TIMER;
22266 if( rc || zErrMsg ){
22267 char zPrefix[100];
22268 const char *zErrorTail;
22269 const char *zErrorType;
22270 if( zErrMsg==0 ){
22271 zErrorType = "Error";
22272 zErrorTail = sqlite3_errmsg(p->db);
22273 }else if( strncmp(zErrMsg, "in prepare, ",12)==0 ){
22274 zErrorType = "Parse error";
22275 zErrorTail = &zErrMsg[12];
22276 }else if( strncmp(zErrMsg, "stepping, ", 10)==0 ){
22277 zErrorType = "Runtime error";
22278 zErrorTail = &zErrMsg[10];
22279 }else{
22280 zErrorType = "Error";
22281 zErrorTail = zErrMsg;
22282 }
22283 if( in!=0 || !stdin_is_interactive ){
22284 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
22285 "%s near line %d:", zErrorType, startline);
22286 }else{
22287 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
22288 }
22289 utf8_printf(stderr, "%s %s\n", zPrefix, zErrorTail);
22290 sqlite3_free(zErrMsg);
22291 zErrMsg = 0;
 
 
 
 
22292 return 1;
22293 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
22294 char zLineBuf[2000];
22295 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
22296 "changes: %lld total_changes: %lld",
22297
+303 -177
--- extsrc/sqlite3.c
+++ extsrc/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.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
457
+#define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -870,11 +870,11 @@
870870
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871871
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
872872
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
873873
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
874874
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
875
-#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
875
+#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
876876
877877
/*
878878
** CAPI3REF: Flags For File Open Operations
879879
**
880880
** These bit values are intended for use in the
@@ -4154,11 +4154,11 @@
41544154
**
41554155
** ^If the most recent error references a specific token in the input
41564156
** SQL, the sqlite3_error_offset() interface returns the byte offset
41574157
** of the start of that token. ^The byte offset returned by
41584158
** sqlite3_error_offset() assumes that the input SQL is UTF8.
4159
-** ^If the most error does not reference a specific token in the input
4159
+** ^If the most recent error does not reference a specific token in the input
41604160
** SQL, then the sqlite3_error_offset() function returns -1.
41614161
**
41624162
** When the serialized [threading mode] is in use, it might be the
41634163
** case that a second error occurs on a separate thread in between
41644164
** the time of the first error and the call to these interfaces.
@@ -7515,11 +7515,11 @@
75157515
** ^The sqlite3_create_module()
75167516
** interface is equivalent to sqlite3_create_module_v2() with a NULL
75177517
** destructor.
75187518
**
75197519
** ^If the third parameter (the pointer to the sqlite3_module object) is
7520
-** NULL then no new module is create and any existing modules with the
7520
+** NULL then no new module is created and any existing modules with the
75217521
** same name are dropped.
75227522
**
75237523
** See also: [sqlite3_drop_modules()]
75247524
*/
75257525
SQLITE_API int sqlite3_create_module(
@@ -18081,11 +18081,14 @@
1808118081
** TK_SELECT: 1st register of result vector */
1808218082
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1808318083
** TK_VARIABLE: variable number (always >= 1).
1808418084
** TK_SELECT_COLUMN: column of the result vector */
1808518085
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18086
- int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18086
+ union {
18087
+ int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18088
+ int iOfst; /* else: start of token from start of statement */
18089
+ } w;
1808718090
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1808818091
union {
1808918092
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
1809018093
** for a column of an index on an expression */
1809118094
Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
@@ -20249,10 +20252,11 @@
2024920252
SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
2025020253
SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
2025120254
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
2025220255
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
2025320256
SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
20257
+SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
2025420258
2025520259
SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
2025620260
SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
2025720261
2025820262
#ifndef SQLITE_OMIT_SUBQUERY
@@ -23584,71 +23588,60 @@
2358423588
#endif /* SQLITE_OMIT_LOCALTIME */
2358523589
2358623590
2358723591
#ifndef SQLITE_OMIT_LOCALTIME
2358823592
/*
23589
-** Compute the difference (in milliseconds) between localtime and UTC
23590
-** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
23591
-** return this value and set *pRc to SQLITE_OK.
23592
-**
23593
-** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
23594
-** is undefined in this case.
23593
+** Assuming the input DateTime is UTC, move it to its localtime equivalent.
2359523594
*/
23596
-static sqlite3_int64 localtimeOffset(
23597
- DateTime *p, /* Date at which to calculate offset */
23598
- sqlite3_context *pCtx, /* Write error here if one occurs */
23599
- int *pRc /* OUT: Error code. SQLITE_OK or ERROR */
23595
+static int toLocaltime(
23596
+ DateTime *p, /* Date at which to calculate offset */
23597
+ sqlite3_context *pCtx /* Write error here if one occurs */
2360023598
){
23601
- DateTime x, y;
2360223599
time_t t;
2360323600
struct tm sLocal;
23601
+ int iYearDiff;
2360423602
2360523603
/* Initialize the contents of sLocal to avoid a compiler warning. */
2360623604
memset(&sLocal, 0, sizeof(sLocal));
2360723605
23608
- x = *p;
23609
- computeYMD_HMS(&x);
23610
- if( x.Y<1971 || x.Y>=2038 ){
23606
+ computeJD(p);
23607
+ if( p->iJD<21086676000*(i64)10000 /* 1970-01-01 */
23608
+ || p->iJD>21301414560*(i64)10000 /* 2038-01-18 */
23609
+ ){
2361123610
/* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
2361223611
** works for years between 1970 and 2037. For dates outside this range,
2361323612
** SQLite attempts to map the year into an equivalent year within this
2361423613
** range, do the calculation, then map the year back.
2361523614
*/
23616
- x.Y = 2000;
23617
- x.M = 1;
23618
- x.D = 1;
23619
- x.h = 0;
23620
- x.m = 0;
23621
- x.s = 0.0;
23622
- } else {
23623
- int s = (int)(x.s + 0.5);
23624
- x.s = s;
23625
- }
23626
- x.tz = 0;
23627
- x.validJD = 0;
23628
- computeJD(&x);
23629
- t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
23615
+ DateTime x = *p;
23616
+ computeYMD_HMS(&x);
23617
+ iYearDiff = (2000 + x.Y%4) - x.Y;
23618
+ x.Y += iYearDiff;
23619
+ x.validJD = 0;
23620
+ computeJD(&x);
23621
+ t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
23622
+ }else{
23623
+ iYearDiff = 0;
23624
+ t = (time_t)(p->iJD/1000 - 21086676*(i64)10000);
23625
+ }
2363023626
if( osLocaltime(&t, &sLocal) ){
2363123627
sqlite3_result_error(pCtx, "local time unavailable", -1);
23632
- *pRc = SQLITE_ERROR;
23633
- return 0;
23634
- }
23635
- y.Y = sLocal.tm_year + 1900;
23636
- y.M = sLocal.tm_mon + 1;
23637
- y.D = sLocal.tm_mday;
23638
- y.h = sLocal.tm_hour;
23639
- y.m = sLocal.tm_min;
23640
- y.s = sLocal.tm_sec;
23641
- y.validYMD = 1;
23642
- y.validHMS = 1;
23643
- y.validJD = 0;
23644
- y.rawS = 0;
23645
- y.validTZ = 0;
23646
- y.isError = 0;
23647
- computeJD(&y);
23648
- *pRc = SQLITE_OK;
23649
- return y.iJD - x.iJD;
23628
+ return SQLITE_ERROR;
23629
+ }
23630
+ p->Y = sLocal.tm_year + 1900 - iYearDiff;
23631
+ p->M = sLocal.tm_mon + 1;
23632
+ p->D = sLocal.tm_mday;
23633
+ p->h = sLocal.tm_hour;
23634
+ p->m = sLocal.tm_min;
23635
+ p->s = sLocal.tm_sec;
23636
+ p->validYMD = 1;
23637
+ p->validHMS = 1;
23638
+ p->validJD = 0;
23639
+ p->rawS = 0;
23640
+ p->validTZ = 0;
23641
+ p->isError = 0;
23642
+ return SQLITE_OK;
2365023643
}
2365123644
#endif /* SQLITE_OMIT_LOCALTIME */
2365223645
2365323646
/*
2365423647
** The following table defines various date transformations of the form
@@ -23753,13 +23746,11 @@
2375323746
**
2375423747
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
2375523748
** show local time.
2375623749
*/
2375723750
if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
23758
- computeJD(p);
23759
- p->iJD += localtimeOffset(p, pCtx, &rc);
23760
- clearYMD_HMS_TZ(p);
23751
+ rc = toLocaltime(p, pCtx);
2376123752
}
2376223753
break;
2376323754
}
2376423755
#endif
2376523756
case 'u': {
@@ -23781,22 +23772,35 @@
2378123772
}
2378223773
}
2378323774
#ifndef SQLITE_OMIT_LOCALTIME
2378423775
else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
2378523776
if( p->tzSet==0 ){
23786
- sqlite3_int64 c1;
23777
+ i64 iOrigJD; /* Original localtime */
23778
+ i64 iGuess; /* Guess at the corresponding utc time */
23779
+ int cnt = 0; /* Safety to prevent infinite loop */
23780
+ int iErr; /* Guess is off by this much */
23781
+
2378723782
computeJD(p);
23788
- c1 = localtimeOffset(p, pCtx, &rc);
23789
- if( rc==SQLITE_OK ){
23790
- p->iJD -= c1;
23791
- clearYMD_HMS_TZ(p);
23792
- p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
23793
- }
23783
+ iGuess = iOrigJD = p->iJD;
23784
+ iErr = 0;
23785
+ do{
23786
+ DateTime new;
23787
+ memset(&new, 0, sizeof(new));
23788
+ iGuess -= iErr;
23789
+ new.iJD = iGuess;
23790
+ new.validJD = 1;
23791
+ rc = toLocaltime(&new, pCtx);
23792
+ if( rc ) return rc;
23793
+ computeJD(&new);
23794
+ iErr = new.iJD - iOrigJD;
23795
+ }while( iErr && cnt++<3 );
23796
+ memset(p, 0, sizeof(*p));
23797
+ p->iJD = iGuess;
23798
+ p->validJD = 1;
2379423799
p->tzSet = 1;
23795
- }else{
23796
- rc = SQLITE_OK;
2379723800
}
23801
+ rc = SQLITE_OK;
2379823802
}
2379923803
#endif
2380023804
break;
2380123805
}
2380223806
case 'w': {
@@ -24042,15 +24046,42 @@
2404224046
int argc,
2404324047
sqlite3_value **argv
2404424048
){
2404524049
DateTime x;
2404624050
if( isDate(context, argc, argv, &x)==0 ){
24047
- char zBuf[100];
24051
+ int Y, s;
24052
+ char zBuf[24];
2404824053
computeYMD_HMS(&x);
24049
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d",
24050
- x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
24051
- sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
24054
+ Y = x.Y;
24055
+ if( Y<0 ) Y = -Y;
24056
+ zBuf[1] = '0' + (Y/1000)%10;
24057
+ zBuf[2] = '0' + (Y/100)%10;
24058
+ zBuf[3] = '0' + (Y/10)%10;
24059
+ zBuf[4] = '0' + (Y)%10;
24060
+ zBuf[5] = '-';
24061
+ zBuf[6] = '0' + (x.M/10)%10;
24062
+ zBuf[7] = '0' + (x.M)%10;
24063
+ zBuf[8] = '-';
24064
+ zBuf[9] = '0' + (x.D/10)%10;
24065
+ zBuf[10] = '0' + (x.D)%10;
24066
+ zBuf[11] = ' ';
24067
+ zBuf[12] = '0' + (x.h/10)%10;
24068
+ zBuf[13] = '0' + (x.h)%10;
24069
+ zBuf[14] = ':';
24070
+ zBuf[15] = '0' + (x.m/10)%10;
24071
+ zBuf[16] = '0' + (x.m)%10;
24072
+ zBuf[17] = ':';
24073
+ s = (int)x.s;
24074
+ zBuf[18] = '0' + (s/10)%10;
24075
+ zBuf[19] = '0' + (s)%10;
24076
+ zBuf[20] = 0;
24077
+ if( x.Y<0 ){
24078
+ zBuf[0] = '-';
24079
+ sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT);
24080
+ }else{
24081
+ sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT);
24082
+ }
2405224083
}
2405324084
}
2405424085
2405524086
/*
2405624087
** time( TIMESTRING, MOD, MOD, ...)
@@ -24062,14 +24093,24 @@
2406224093
int argc,
2406324094
sqlite3_value **argv
2406424095
){
2406524096
DateTime x;
2406624097
if( isDate(context, argc, argv, &x)==0 ){
24067
- char zBuf[100];
24098
+ int s;
24099
+ char zBuf[16];
2406824100
computeHMS(&x);
24069
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
24070
- sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
24101
+ zBuf[0] = '0' + (x.h/10)%10;
24102
+ zBuf[1] = '0' + (x.h)%10;
24103
+ zBuf[2] = ':';
24104
+ zBuf[3] = '0' + (x.m/10)%10;
24105
+ zBuf[4] = '0' + (x.m)%10;
24106
+ zBuf[5] = ':';
24107
+ s = (int)x.s;
24108
+ zBuf[6] = '0' + (s/10)%10;
24109
+ zBuf[7] = '0' + (s)%10;
24110
+ zBuf[8] = 0;
24111
+ sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT);
2407124112
}
2407224113
}
2407324114
2407424115
/*
2407524116
** date( TIMESTRING, MOD, MOD, ...)
@@ -24081,14 +24122,32 @@
2408124122
int argc,
2408224123
sqlite3_value **argv
2408324124
){
2408424125
DateTime x;
2408524126
if( isDate(context, argc, argv, &x)==0 ){
24086
- char zBuf[100];
24127
+ int Y;
24128
+ char zBuf[16];
2408724129
computeYMD(&x);
24088
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
24089
- sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
24130
+ Y = x.Y;
24131
+ if( Y<0 ) Y = -Y;
24132
+ zBuf[1] = '0' + (Y/1000)%10;
24133
+ zBuf[2] = '0' + (Y/100)%10;
24134
+ zBuf[3] = '0' + (Y/10)%10;
24135
+ zBuf[4] = '0' + (Y)%10;
24136
+ zBuf[5] = '-';
24137
+ zBuf[6] = '0' + (x.M/10)%10;
24138
+ zBuf[7] = '0' + (x.M)%10;
24139
+ zBuf[8] = '-';
24140
+ zBuf[9] = '0' + (x.D/10)%10;
24141
+ zBuf[10] = '0' + (x.D)%10;
24142
+ zBuf[11] = 0;
24143
+ if( x.Y<0 ){
24144
+ zBuf[0] = '-';
24145
+ sqlite3_result_text(context, zBuf, 11, SQLITE_TRANSIENT);
24146
+ }else{
24147
+ sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
24148
+ }
2409024149
}
2409124150
}
2409224151
2409324152
/*
2409424153
** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
@@ -30181,17 +30240,26 @@
3018130240
bufpt[j] = 0;
3018230241
length = j;
3018330242
goto adjust_width_for_utf8;
3018430243
}
3018530244
case etTOKEN: {
30186
- Token *pToken;
3018730245
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
30188
- pToken = va_arg(ap, Token*);
30189
- assert( bArgList==0 );
30190
- if( pToken && pToken->n ){
30191
- sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
30192
- sqlite3RecordErrorByteOffset(pAccum->db, pToken->z);
30246
+ if( flag_alternateform ){
30247
+ /* %#T means an Expr pointer that uses Expr.u.zToken */
30248
+ Expr *pExpr = va_arg(ap,Expr*);
30249
+ if( ALWAYS(pExpr) && ALWAYS(!ExprHasProperty(pExpr,EP_IntValue)) ){
30250
+ sqlite3_str_appendall(pAccum, (const char*)pExpr->u.zToken);
30251
+ sqlite3RecordErrorOffsetOfExpr(pAccum->db, pExpr);
30252
+ }
30253
+ }else{
30254
+ /* %T means a Token pointer */
30255
+ Token *pToken = va_arg(ap, Token*);
30256
+ assert( bArgList==0 );
30257
+ if( pToken && pToken->n ){
30258
+ sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
30259
+ sqlite3RecordErrorByteOffset(pAccum->db, pToken->z);
30260
+ }
3019330261
}
3019430262
length = width = 0;
3019530263
break;
3019630264
}
3019730265
case etSRCITEM: {
@@ -30265,10 +30333,22 @@
3026530333
zEnd = &zText[strlen(zText)];
3026630334
if( SQLITE_WITHIN(z,zText,zEnd) ){
3026730335
db->errByteOffset = (int)(z-zText);
3026830336
}
3026930337
}
30338
+
30339
+/*
30340
+** If pExpr has a byte offset for the start of a token, record that as
30341
+** as the error offset.
30342
+*/
30343
+SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30344
+ while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
30345
+ pExpr = pExpr->pLeft;
30346
+ }
30347
+ if( pExpr==0 ) return;
30348
+ db->errByteOffset = pExpr->w.iOfst;
30349
+}
3027030350
3027130351
/*
3027230352
** Enlarge the memory allocation on a StrAccum object so that it is
3027330353
** able to accept at least N more bytes of text.
3027430354
**
@@ -31107,11 +31187,11 @@
3110731187
StrAccum x;
3110831188
sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
3110931189
sqlite3_str_appendf(&x, " fg.af=%x.%c",
3111031190
pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
3111131191
if( ExprHasProperty(pExpr, EP_FromJoin) ){
31112
- sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
31192
+ sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable);
3111331193
}
3111431194
if( ExprHasProperty(pExpr, EP_FromDDL) ){
3111531195
sqlite3_str_appendf(&x, " DDL");
3111631196
}
3111731197
if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -57586,10 +57666,16 @@
5758657666
PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
5758757667
rc = write32bits(pPager->sjfd, offset, pPg->pgno);
5758857668
if( rc==SQLITE_OK ){
5758957669
rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
5759057670
}
57671
+ if( rc!=SQLITE_OK ){
57672
+ /* Subjournal writes should be "atomic" in the sense that we should
57673
+ ** never allow a partial write. If anything goes wrong, make sure
57674
+ ** to roll back any partial writes that may have occurred */
57675
+ (void)sqlite3OsTruncate(pPager->sjfd, offset);
57676
+ }
5759157677
}
5759257678
}
5759357679
if( rc==SQLITE_OK ){
5759457680
pPager->nSubRec++;
5759557681
assert( pPager->nSavepoint>0 );
@@ -60514,10 +60600,22 @@
6051460600
int eMode, /* Type of checkpoint */
6051560601
int *pnLog, /* OUT: Final number of frames in log */
6051660602
int *pnCkpt /* OUT: Final number of checkpointed frames */
6051760603
){
6051860604
int rc = SQLITE_OK;
60605
+ if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
60606
+ /* This only happens when a database file is zero bytes in size opened and
60607
+ ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint()
60608
+ ** is invoked without any intervening transactions. We need to start
60609
+ ** a transaction to initialize pWal. The PRAGMA table_list statement is
60610
+ ** used for this since it starts transactions on every database file,
60611
+ ** including all ATTACHed databases. This seems expensive for a single
60612
+ ** sqlite3_wal_checkpoint() call, but it happens very rarely.
60613
+ ** https://sqlite.org/forum/forumpost/fd0f19d229156939
60614
+ */
60615
+ sqlite3_exec(db, "PRAGMA table_list",0,0,0);
60616
+ }
6051960617
if( pPager->pWal ){
6052060618
rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
6052160619
(eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
6052260620
pPager->pBusyHandlerArg,
6052360621
pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
@@ -82890,10 +82988,11 @@
8289082988
db->bBenignMalloc--;
8289182989
}else if( db->pErr ){
8289282990
sqlite3ValueSetNull(db->pErr);
8289382991
}
8289482992
db->errCode = rc;
82993
+ db->errByteOffset = -1;
8289582994
return rc;
8289682995
}
8289782996
8289882997
#ifdef SQLITE_ENABLE_SQLLOG
8289982998
/*
@@ -86496,11 +86595,11 @@
8649686595
case SQLITE_INTEGER: {
8649786596
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
8649886597
break;
8649986598
}
8650086599
case SQLITE_FLOAT: {
86501
- rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
86600
+ rc = sqlite3_bind_double(pStmt, i, sqlite3VdbeRealValue((Mem*)pValue));
8650286601
break;
8650386602
}
8650486603
case SQLITE_BLOB: {
8650586604
if( pValue->flags & MEM_Zero ){
8650686605
rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -100865,10 +100964,11 @@
100865100964
}else if( zTab ){
100866100965
sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
100867100966
}else{
100868100967
sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
100869100968
}
100969
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
100870100970
pParse->checkSchema = 1;
100871100971
pTopNC->nNcErr++;
100872100972
}
100873100973
100874100974
/* If a column from a table in pSrcList is referenced, then record
@@ -100973,11 +101073,12 @@
100973101073
*/
100974101074
static void notValidImpl(
100975101075
Parse *pParse, /* Leave error message here */
100976101076
NameContext *pNC, /* The name context */
100977101077
const char *zMsg, /* Type of error */
100978
- Expr *pExpr /* Invalidate this expression on error */
101078
+ Expr *pExpr, /* Invalidate this expression on error */
101079
+ Expr *pError /* Associate error with this expression */
100979101080
){
100980101081
const char *zIn = "partial index WHERE clauses";
100981101082
if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
100982101083
#ifndef SQLITE_OMIT_CHECK
100983101084
else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
@@ -100985,14 +101086,15 @@
100985101086
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
100986101087
else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
100987101088
#endif
100988101089
sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
100989101090
if( pExpr ) pExpr->op = TK_NULL;
101091
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
100990101092
}
100991
-#define sqlite3ResolveNotValid(P,N,M,X,E) \
101093
+#define sqlite3ResolveNotValid(P,N,M,X,E,R) \
100992101094
assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
100993
- if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
101095
+ if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
100994101096
100995101097
/*
100996101098
** Expression p should encode a floating point value between 1.0 and 0.0.
100997101099
** Return 1024 times this value. Or return -1 if p is not a floating point
100998101100
** value between 1.0 and 0.0.
@@ -101123,11 +101225,11 @@
101123101225
}else{
101124101226
Expr *pLeft = pExpr->pLeft;
101125101227
testcase( pNC->ncFlags & NC_IdxExpr );
101126101228
testcase( pNC->ncFlags & NC_GenCol );
101127101229
sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
101128
- NC_IdxExpr|NC_GenCol, 0);
101230
+ NC_IdxExpr|NC_GenCol, 0, pExpr);
101129101231
pRight = pExpr->pRight;
101130101232
if( pRight->op==TK_ID ){
101131101233
zDb = 0;
101132101234
}else{
101133101235
assert( pRight->op==TK_DOT );
@@ -101154,21 +101256,19 @@
101154101256
ExprList *pList = pExpr->x.pList; /* The argument list */
101155101257
int n = pList ? pList->nExpr : 0; /* Number of arguments */
101156101258
int no_such_func = 0; /* True if no such function exists */
101157101259
int wrong_num_args = 0; /* True if wrong number of arguments */
101158101260
int is_agg = 0; /* True if is an aggregate function */
101159
- int nId; /* Number of characters in function name */
101160101261
const char *zId; /* The function name. */
101161101262
FuncDef *pDef; /* Information about the function */
101162101263
u8 enc = ENC(pParse->db); /* The database encoding */
101163101264
int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
101164101265
#ifndef SQLITE_OMIT_WINDOWFUNC
101165101266
Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
101166101267
#endif
101167101268
assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
101168101269
zId = pExpr->u.zToken;
101169
- nId = sqlite3Strlen30(zId);
101170101270
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
101171101271
if( pDef==0 ){
101172101272
pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
101173101273
if( pDef==0 ){
101174101274
no_such_func = 1;
@@ -101181,12 +101281,12 @@
101181101281
ExprSetProperty(pExpr, EP_Unlikely);
101182101282
if( n==2 ){
101183101283
pExpr->iTable = exprProbability(pList->a[1].pExpr);
101184101284
if( pExpr->iTable<0 ){
101185101285
sqlite3ErrorMsg(pParse,
101186
- "second argument to likelihood() must be a "
101187
- "constant between 0.0 and 1.0");
101286
+ "second argument to %#T() must be a "
101287
+ "constant between 0.0 and 1.0", pExpr);
101188101288
pNC->nNcErr++;
101189101289
}
101190101290
}else{
101191101291
/* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
101192101292
** equivalent to likelihood(X, 0.0625).
@@ -101203,12 +101303,12 @@
101203101303
#ifndef SQLITE_OMIT_AUTHORIZATION
101204101304
{
101205101305
int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
101206101306
if( auth!=SQLITE_OK ){
101207101307
if( auth==SQLITE_DENY ){
101208
- sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
101209
- pDef->zName);
101308
+ sqlite3ErrorMsg(pParse, "not authorized to use function: %#T",
101309
+ pExpr);
101210101310
pNC->nNcErr++;
101211101311
}
101212101312
pExpr->op = TK_NULL;
101213101313
return WRC_Prune;
101214101314
}
@@ -101227,11 +101327,11 @@
101227101327
** sqlite_version() that might change over time cannot be used
101228101328
** in an index or generated column. Curiously, they can be used
101229101329
** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
101230101330
** all this. */
101231101331
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
101232
- NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
101332
+ NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
101233101333
}else{
101234101334
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
101235101335
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
101236101336
if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
101237101337
}
@@ -101259,11 +101359,11 @@
101259101359
|| (pDef->xValue==0 && pDef->xInverse==0)
101260101360
|| (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
101261101361
);
101262101362
if( pDef && pDef->xValue==0 && pWin ){
101263101363
sqlite3ErrorMsg(pParse,
101264
- "%.*s() may not be used as a window function", nId, zId
101364
+ "%#T() may not be used as a window function", pExpr
101265101365
);
101266101366
pNC->nNcErr++;
101267101367
}else if(
101268101368
(is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
101269101369
|| (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
@@ -101273,38 +101373,38 @@
101273101373
if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){
101274101374
zType = "window";
101275101375
}else{
101276101376
zType = "aggregate";
101277101377
}
101278
- sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
101378
+ sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr);
101279101379
pNC->nNcErr++;
101280101380
is_agg = 0;
101281101381
}
101282101382
#else
101283101383
if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
101284
- sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
101384
+ sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
101285101385
pNC->nNcErr++;
101286101386
is_agg = 0;
101287101387
}
101288101388
#endif
101289101389
else if( no_such_func && pParse->db->init.busy==0
101290101390
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
101291101391
&& pParse->explain==0
101292101392
#endif
101293101393
){
101294
- sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
101394
+ sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
101295101395
pNC->nNcErr++;
101296101396
}else if( wrong_num_args ){
101297
- sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
101298
- nId, zId);
101397
+ sqlite3ErrorMsg(pParse,"wrong number of arguments to function %#T()",
101398
+ pExpr);
101299101399
pNC->nNcErr++;
101300101400
}
101301101401
#ifndef SQLITE_OMIT_WINDOWFUNC
101302101402
else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
101303101403
sqlite3ErrorMsg(pParse,
101304
- "FILTER may not be used with non-aggregate %.*s()",
101305
- nId, zId
101404
+ "FILTER may not be used with non-aggregate %#T()",
101405
+ pExpr
101306101406
);
101307101407
pNC->nNcErr++;
101308101408
}
101309101409
#endif
101310101410
if( is_agg ){
@@ -101385,11 +101485,11 @@
101385101485
testcase( pNC->ncFlags & NC_IsCheck );
101386101486
testcase( pNC->ncFlags & NC_PartIdx );
101387101487
testcase( pNC->ncFlags & NC_IdxExpr );
101388101488
testcase( pNC->ncFlags & NC_GenCol );
101389101489
if( pNC->ncFlags & NC_SelfRef ){
101390
- notValidImpl(pParse, pNC, "subqueries", pExpr);
101490
+ notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
101391101491
}else{
101392101492
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
101393101493
}
101394101494
assert( pNC->nRef>=nRef );
101395101495
if( nRef!=pNC->nRef ){
@@ -101403,11 +101503,11 @@
101403101503
testcase( pNC->ncFlags & NC_IsCheck );
101404101504
testcase( pNC->ncFlags & NC_PartIdx );
101405101505
testcase( pNC->ncFlags & NC_IdxExpr );
101406101506
testcase( pNC->ncFlags & NC_GenCol );
101407101507
sqlite3ResolveNotValid(pParse, pNC, "parameters",
101408
- NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
101508
+ NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr, pExpr);
101409101509
break;
101410101510
}
101411101511
case TK_IS:
101412101512
case TK_ISNOT: {
101413101513
Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -101455,10 +101555,11 @@
101455101555
testcase( pExpr->op==TK_GE );
101456101556
testcase( pExpr->op==TK_IS );
101457101557
testcase( pExpr->op==TK_ISNOT );
101458101558
testcase( pExpr->op==TK_BETWEEN );
101459101559
sqlite3ErrorMsg(pParse, "row value misused");
101560
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
101460101561
}
101461101562
break;
101462101563
}
101463101564
}
101464101565
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
@@ -101568,15 +101669,17 @@
101568101669
*/
101569101670
static void resolveOutOfRangeError(
101570101671
Parse *pParse, /* The error context into which to write the error */
101571101672
const char *zType, /* "ORDER" or "GROUP" */
101572101673
int i, /* The index (1-based) of the term out of range */
101573
- int mx /* Largest permissible value of i */
101674
+ int mx, /* Largest permissible value of i */
101675
+ Expr *pError /* Associate the error with the expression */
101574101676
){
101575101677
sqlite3ErrorMsg(pParse,
101576101678
"%r %s BY term out of range - should be "
101577101679
"between 1 and %d", i, zType, mx);
101680
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
101578101681
}
101579101682
101580101683
/*
101581101684
** Analyze the ORDER BY clause in a compound SELECT statement. Modify
101582101685
** each term of the ORDER BY clause is a constant integer between 1
@@ -101628,11 +101731,11 @@
101628101731
if( pItem->done ) continue;
101629101732
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
101630101733
if( NEVER(pE==0) ) continue;
101631101734
if( sqlite3ExprIsInteger(pE, &iCol) ){
101632101735
if( iCol<=0 || iCol>pEList->nExpr ){
101633
- resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
101736
+ resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
101634101737
return 1;
101635101738
}
101636101739
}else{
101637101740
iCol = resolveAsName(pParse, pEList, pE);
101638101741
if( iCol==0 ){
@@ -101724,11 +101827,11 @@
101724101827
pEList = pSelect->pEList;
101725101828
assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
101726101829
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
101727101830
if( pItem->u.x.iOrderByCol ){
101728101831
if( pItem->u.x.iOrderByCol>pEList->nExpr ){
101729
- resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
101832
+ resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
101730101833
return 1;
101731101834
}
101732101835
resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
101733101836
}
101734101837
}
@@ -101816,11 +101919,11 @@
101816101919
if( sqlite3ExprIsInteger(pE2, &iCol) ){
101817101920
/* The ORDER BY term is an integer constant. Again, set the column
101818101921
** number so that sqlite3ResolveOrderGroupBy() will convert the
101819101922
** order-by term to a copy of the result-set expression */
101820101923
if( iCol<1 || iCol>0xffff ){
101821
- resolveOutOfRangeError(pParse, zType, i+1, nResult);
101924
+ resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2);
101822101925
return 1;
101823101926
}
101824101927
pItem->u.x.iOrderByCol = (u16)iCol;
101825101928
continue;
101826101929
}
@@ -103069,13 +103172,12 @@
103069103172
**
103070103173
** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
103071103174
** if appropriate.
103072103175
*/
103073103176
static void exprSetHeight(Expr *p){
103074
- int nHeight = 0;
103075
- heightOfExpr(p->pLeft, &nHeight);
103076
- heightOfExpr(p->pRight, &nHeight);
103177
+ int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
103178
+ if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
103077103179
if( ExprUseXSelect(p) ){
103078103180
heightOfSelect(p->x.pSelect, &nHeight);
103079103181
}else if( p->x.pList ){
103080103182
heightOfExprList(p->x.pList, &nHeight);
103081103183
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -103370,10 +103472,11 @@
103370103472
pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
103371103473
if( pNew==0 ){
103372103474
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
103373103475
return 0;
103374103476
}
103477
+ pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
103375103478
if( pList
103376103479
&& pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
103377103480
&& !pParse->nested
103378103481
){
103379103482
sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
@@ -103413,11 +103516,11 @@
103413103516
** (2) not tagged with SQLITE_INNOCUOUS (which means it
103414103517
** is tagged with SQLITE_FUNC_UNSAFE) and
103415103518
** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
103416103519
** that the schema is possibly tainted).
103417103520
*/
103418
- sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName);
103521
+ sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr);
103419103522
}
103420103523
}
103421103524
}
103422103525
103423103526
/*
@@ -103469,10 +103572,11 @@
103469103572
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
103470103573
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
103471103574
if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103472103575
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
103473103576
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
103577
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
103474103578
return;
103475103579
}
103476103580
x = (ynVar)i;
103477103581
if( x>pParse->nVar ){
103478103582
pParse->nVar = (int)x;
@@ -103496,10 +103600,11 @@
103496103600
}
103497103601
}
103498103602
pExpr->iColumn = x;
103499103603
if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103500103604
sqlite3ErrorMsg(pParse, "too many SQL variables");
103605
+ sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
103501103606
}
103502103607
}
103503103608
103504103609
/*
103505103610
** Recursively delete an expression tree.
@@ -105937,15 +106042,16 @@
105937106042
const char *z = pExpr->u.zToken;
105938106043
assert( z!=0 );
105939106044
c = sqlite3DecOrHexToI64(z, &value);
105940106045
if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
105941106046
#ifdef SQLITE_OMIT_FLOATING_POINT
105942
- sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
106047
+ sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr);
105943106048
#else
105944106049
#ifndef SQLITE_OMIT_HEX_INTEGER
105945106050
if( sqlite3_strnicmp(z,"0x",2)==0 ){
105946
- sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
106051
+ sqlite3ErrorMsg(pParse, "hex literal too big: %s%#T",
106052
+ negFlag?"-":"",pExpr);
105947106053
}else
105948106054
#endif
105949106055
{
105950106056
codeReal(v, z, negFlag, iMem);
105951106057
}
@@ -106617,11 +106723,11 @@
106617106723
if( pInfo==0
106618106724
|| NEVER(pExpr->iAgg<0)
106619106725
|| NEVER(pExpr->iAgg>=pInfo->nFunc)
106620106726
){
106621106727
assert( !ExprHasProperty(pExpr, EP_IntValue) );
106622
- sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
106728
+ sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr);
106623106729
}else{
106624106730
return pInfo->aFunc[pExpr->iAgg].iMem;
106625106731
}
106626106732
break;
106627106733
}
@@ -106658,11 +106764,11 @@
106658106764
if( pDef==0 && pParse->explain ){
106659106765
pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
106660106766
}
106661106767
#endif
106662106768
if( pDef==0 || pDef->xFinalize!=0 ){
106663
- sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
106769
+ sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
106664106770
break;
106665106771
}
106666106772
if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
106667106773
assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
106668106774
assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
@@ -109281,11 +109387,11 @@
109281109387
if( !zOld ) goto exit_rename_column;
109282109388
for(iCol=0; iCol<pTab->nCol; iCol++){
109283109389
if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
109284109390
}
109285109391
if( iCol==pTab->nCol ){
109286
- sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
109392
+ sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
109287109393
goto exit_rename_column;
109288109394
}
109289109395
109290109396
/* Ensure the schema contains no double-quoted strings */
109291109397
renameTestSchema(pParse, zDb, iSchema==1, "", 0);
@@ -109711,16 +109817,16 @@
109711109817
){
109712109818
const char *zT = (const char*)sqlite3_value_text(pType);
109713109819
const char *zN = (const char*)sqlite3_value_text(pObject);
109714109820
char *zErr;
109715109821
109716
- zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
109822
+ zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s",
109717109823
zT, zN, (zWhen[0] ? " " : ""), zWhen,
109718109824
pParse->zErrMsg
109719109825
);
109720109826
sqlite3_result_error(pCtx, zErr, -1);
109721
- sqlite3_free(zErr);
109827
+ sqlite3DbFree(pParse->db, zErr);
109722109828
}
109723109829
109724109830
/*
109725109831
** For each name in the the expression-list pEList (i.e. each
109726109832
** pEList->a[i].zName) that matches the string in zOld, extract the
@@ -110077,11 +110183,11 @@
110077110183
}
110078110184
110079110185
/*
110080110186
** SQL function:
110081110187
**
110082
-** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld)
110188
+** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
110083110189
**
110084110190
** 0. zSql: SQL statement to rewrite
110085110191
** 1. type: Type of object ("table", "view" etc.)
110086110192
** 2. object: Name of object
110087110193
** 3. Database: Database name (e.g. "main")
@@ -110095,11 +110201,12 @@
110095110201
** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
110096110202
** into zNew. The name should be quoted if bQuote is true.
110097110203
**
110098110204
** This function is used internally by the ALTER TABLE RENAME COLUMN command.
110099110205
** It is only accessible to SQL created using sqlite3NestedParse(). It is
110100
-** not reachable from ordinary SQL passed into sqlite3_prepare().
110206
+** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
110207
+** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
110101110208
*/
110102110209
static void renameColumnFunc(
110103110210
sqlite3_context *context,
110104110211
int NotUsed,
110105110212
sqlite3_value **argv
@@ -110244,11 +110351,13 @@
110244110351
assert( rc==SQLITE_OK );
110245110352
rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote);
110246110353
110247110354
renameColumnFunc_done:
110248110355
if( rc!=SQLITE_OK ){
110249
- if( sParse.zErrMsg ){
110356
+ if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
110357
+ sqlite3_result_value(context, argv[0]);
110358
+ }else if( sParse.zErrMsg ){
110250110359
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110251110360
}else{
110252110361
sqlite3_result_error_code(context, rc);
110253110362
}
110254110363
}
@@ -110443,11 +110552,13 @@
110443110552
110444110553
if( rc==SQLITE_OK ){
110445110554
rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
110446110555
}
110447110556
if( rc!=SQLITE_OK ){
110448
- if( sParse.zErrMsg ){
110557
+ if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
110558
+ sqlite3_result_value(context, argv[3]);
110559
+ }else if( sParse.zErrMsg ){
110449110560
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110450110561
}else{
110451110562
sqlite3_result_error_code(context, rc);
110452110563
}
110453110564
}
@@ -110468,14 +110579,14 @@
110468110579
renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr);
110469110580
}
110470110581
return WRC_Continue;
110471110582
}
110472110583
110473
-/*
110474
-** The implementation of an SQL scalar function that rewrites DDL statements
110475
-** so that any string literals that use double-quotes are modified so that
110476
-** they use single quotes.
110584
+/* SQL function: sqlite_rename_quotefix(DB,SQL)
110585
+**
110586
+** Rewrite the DDL statement "SQL" so that any string literals that use
110587
+** double-quotes use single quotes instead.
110477110588
**
110478110589
** Two arguments must be passed:
110479110590
**
110480110591
** 0: Database name ("main", "temp" etc.).
110481110592
** 1: SQL statement to edit.
@@ -110490,10 +110601,14 @@
110490110601
** );
110491110602
**
110492110603
** returns the string:
110493110604
**
110494110605
** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
110606
+**
110607
+** If there is a error in the input SQL, then raise an error, except
110608
+** if PRAGMA writable_schema=ON, then just return the input string
110609
+** unmodified following an error.
110495110610
*/
110496110611
static void renameQuotefixFunc(
110497110612
sqlite3_context *context,
110498110613
int NotUsed,
110499110614
sqlite3_value **argv
@@ -110564,11 +110679,15 @@
110564110679
rc = renameEditSql(context, &sCtx, zInput, 0, 0);
110565110680
}
110566110681
renameTokenFree(db, sCtx.pList);
110567110682
}
110568110683
if( rc!=SQLITE_OK ){
110569
- sqlite3_result_error_code(context, rc);
110684
+ if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){
110685
+ sqlite3_result_value(context, argv[1]);
110686
+ }else{
110687
+ sqlite3_result_error_code(context, rc);
110688
+ }
110570110689
}
110571110690
renameParseCleanup(&sParse);
110572110691
}
110573110692
110574110693
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -110576,11 +110695,12 @@
110576110695
#endif
110577110696
110578110697
sqlite3BtreeLeaveAll(db);
110579110698
}
110580110699
110581
-/*
110700
+/* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS)
110701
+**
110582110702
** An SQL user function that checks that there are no parse or symbol
110583110703
** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
110584110704
** After an ALTER TABLE .. RENAME operation is performed and the schema
110585110705
** reloaded, this function is called on each SQL statement in the schema
110586110706
** to ensure that it is still usable.
@@ -110591,15 +110711,17 @@
110591110711
** 3: Object name.
110592110712
** 4: True if object is from temp schema.
110593110713
** 5: "when" part of error message.
110594110714
** 6: True to disable the DQS quirk when parsing SQL.
110595110715
**
110596
-** Unless it finds an error, this function normally returns NULL. However, it
110597
-** returns integer value 1 if:
110716
+** The return value is computed as follows:
110598110717
**
110599
-** * the SQL argument creates a trigger, and
110600
-** * the table that the trigger is attached to is in database zDb.
110718
+** A. If an error is seen and not in PRAGMA writable_schema=ON mode,
110719
+** then raise the error.
110720
+** B. Else if a trigger is created and the the table that the trigger is
110721
+** attached to is in database zDb, then return 1.
110722
+** C. Otherwise return NULL.
110601110723
*/
110602110724
static void renameTableTest(
110603110725
sqlite3_context *context,
110604110726
int NotUsed,
110605110727
sqlite3_value **argv
@@ -110640,16 +110762,20 @@
110640110762
rc = renameResolveTrigger(&sParse);
110641110763
}
110642110764
if( rc==SQLITE_OK ){
110643110765
int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
110644110766
int i2 = sqlite3FindDbName(db, zDb);
110645
- if( i1==i2 ) sqlite3_result_int(context, 1);
110767
+ if( i1==i2 ){
110768
+ /* Handle output case B */
110769
+ sqlite3_result_int(context, 1);
110770
+ }
110646110771
}
110647110772
}
110648110773
}
110649110774
110650
- if( rc!=SQLITE_OK && zWhen ){
110775
+ if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){
110776
+ /* Output case A */
110651110777
renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse);
110652110778
}
110653110779
renameParseCleanup(&sParse);
110654110780
}
110655110781
@@ -110761,11 +110887,11 @@
110761110887
assert( db->mallocFailed );
110762110888
goto exit_drop_column;
110763110889
}
110764110890
iCol = sqlite3ColumnIndex(pTab, zCol);
110765110891
if( iCol<0 ){
110766
- sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol);
110892
+ sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName);
110767110893
goto exit_drop_column;
110768110894
}
110769110895
110770110896
/* Do not allow the user to drop a PRIMARY KEY column or a column
110771110897
** constrained by a UNIQUE constraint. */
@@ -114989,11 +115115,12 @@
114989115115
goto begin_table_error;
114990115116
}
114991115117
pTable = sqlite3FindTable(db, zName, zDb);
114992115118
if( pTable ){
114993115119
if( !noErr ){
114994
- sqlite3ErrorMsg(pParse, "table %T already exists", pName);
115120
+ sqlite3ErrorMsg(pParse, "%s %T already exists",
115121
+ (IsView(pTable)? "view" : "table"), pName);
114995115122
}else{
114996115123
assert( !db->init.busy || CORRUPT_DB );
114997115124
sqlite3CodeVerifySchema(pParse, iDb);
114998115125
sqlite3ForceNotReadOnly(pParse);
114999115126
}
@@ -134366,29 +134493,29 @@
134366134493
** sqlite3PExpr(). */
134367134494
if( pEq && isOuterJoin ){
134368134495
ExprSetProperty(pEq, EP_FromJoin);
134369134496
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
134370134497
ExprSetVVAProperty(pEq, EP_NoReduce);
134371
- pEq->iRightJoinTable = pE2->iTable;
134498
+ pEq->w.iRightJoinTable = pE2->iTable;
134372134499
}
134373134500
*ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
134374134501
}
134375134502
134376134503
/*
134377134504
** Set the EP_FromJoin property on all terms of the given expression.
134378
-** And set the Expr.iRightJoinTable to iTable for every term in the
134505
+** And set the Expr.w.iRightJoinTable to iTable for every term in the
134379134506
** expression.
134380134507
**
134381134508
** The EP_FromJoin property is used on terms of an expression to tell
134382134509
** the LEFT OUTER JOIN processing logic that this term is part of the
134383134510
** join restriction specified in the ON or USING clause and not a part
134384134511
** of the more general WHERE clause. These terms are moved over to the
134385134512
** WHERE clause during join processing but we need to remember that they
134386134513
** originated in the ON or USING clause.
134387134514
**
134388
-** The Expr.iRightJoinTable tells the WHERE clause processing that the
134389
-** expression depends on table iRightJoinTable even if that table is not
134515
+** The Expr.w.iRightJoinTable tells the WHERE clause processing that the
134516
+** expression depends on table w.iRightJoinTable even if that table is not
134390134517
** explicitly mentioned in the expression. That information is needed
134391134518
** for cases like this:
134392134519
**
134393134520
** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
134394134521
**
@@ -134402,11 +134529,11 @@
134402134529
SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){
134403134530
while( p ){
134404134531
ExprSetProperty(p, EP_FromJoin);
134405134532
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
134406134533
ExprSetVVAProperty(p, EP_NoReduce);
134407
- p->iRightJoinTable = iTable;
134534
+ p->w.iRightJoinTable = iTable;
134408134535
if( p->op==TK_FUNCTION ){
134409134536
assert( ExprUseXList(p) );
134410134537
if( p->x.pList ){
134411134538
int i;
134412134539
for(i=0; i<p->x.pList->nExpr; i++){
@@ -134418,19 +134545,19 @@
134418134545
p = p->pRight;
134419134546
}
134420134547
}
134421134548
134422134549
/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
134423
-** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
134550
+** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into
134424134551
** an ordinary term that omits the EP_FromJoin mark.
134425134552
**
134426134553
** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
134427134554
*/
134428134555
static void unsetJoinExpr(Expr *p, int iTable){
134429134556
while( p ){
134430134557
if( ExprHasProperty(p, EP_FromJoin)
134431
- && (iTable<0 || p->iRightJoinTable==iTable) ){
134558
+ && (iTable<0 || p->w.iRightJoinTable==iTable) ){
134432134559
ExprClearProperty(p, EP_FromJoin);
134433134560
}
134434134561
if( p->op==TK_COLUMN && p->iTable==iTable ){
134435134562
ExprClearProperty(p, EP_CanBeNull);
134436134563
}
@@ -137660,13 +137787,13 @@
137660137787
SubstContext *pSubst, /* Description of the substitution */
137661137788
Expr *pExpr /* Expr in which substitution occurs */
137662137789
){
137663137790
if( pExpr==0 ) return 0;
137664137791
if( ExprHasProperty(pExpr, EP_FromJoin)
137665
- && pExpr->iRightJoinTable==pSubst->iTable
137792
+ && pExpr->w.iRightJoinTable==pSubst->iTable
137666137793
){
137667
- pExpr->iRightJoinTable = pSubst->iNewTable;
137794
+ pExpr->w.iRightJoinTable = pSubst->iNewTable;
137668137795
}
137669137796
if( pExpr->op==TK_COLUMN
137670137797
&& pExpr->iTable==pSubst->iTable
137671137798
&& !ExprHasProperty(pExpr, EP_FixedCol)
137672137799
){
@@ -137701,11 +137828,11 @@
137701137828
}
137702137829
if( pSubst->isLeftJoin ){
137703137830
ExprSetProperty(pNew, EP_CanBeNull);
137704137831
}
137705137832
if( ExprHasProperty(pExpr,EP_FromJoin) ){
137706
- sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
137833
+ sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable);
137707137834
}
137708137835
sqlite3ExprDelete(db, pExpr);
137709137836
pExpr = pNew;
137710137837
137711137838
/* Ensure that the expression now has an implicit collation sequence,
@@ -137866,11 +137993,11 @@
137866137993
int op = pExpr->op;
137867137994
if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
137868137995
renumberCursorDoMapping(pWalker, &pExpr->iTable);
137869137996
}
137870137997
if( ExprHasProperty(pExpr, EP_FromJoin) ){
137871
- renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable);
137998
+ renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable);
137872137999
}
137873138000
return WRC_Continue;
137874138001
}
137875138002
137876138003
/*
@@ -138876,15 +139003,17 @@
138876139003
iCursor, isLeftJoin);
138877139004
pWhere = pWhere->pLeft;
138878139005
}
138879139006
if( isLeftJoin
138880139007
&& (ExprHasProperty(pWhere,EP_FromJoin)==0
138881
- || pWhere->iRightJoinTable!=iCursor)
139008
+ || pWhere->w.iRightJoinTable!=iCursor)
138882139009
){
138883139010
return 0; /* restriction (4) */
138884139011
}
138885
- if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
139012
+ if( ExprHasProperty(pWhere,EP_FromJoin)
139013
+ && pWhere->w.iRightJoinTable!=iCursor
139014
+ ){
138886139015
return 0; /* restriction (5) */
138887139016
}
138888139017
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
138889139018
nChng++;
138890139019
pSubq->selFlags |= SF_PushDown;
@@ -142999,10 +143128,11 @@
142999143128
);
143000143129
143001143130
/* If an existing TriggerPrg could not be located, create a new one. */
143002143131
if( !pPrg ){
143003143132
pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf);
143133
+ pParse->db->errByteOffset = -1;
143004143134
}
143005143135
143006143136
return pPrg;
143007143137
}
143008143138
@@ -148291,11 +148421,11 @@
148291148421
** are also excluded. See codeCursorHintIsOrFunction() for details.
148292148422
*/
148293148423
if( pTabItem->fg.jointype & JT_LEFT ){
148294148424
Expr *pExpr = pTerm->pExpr;
148295148425
if( !ExprHasProperty(pExpr, EP_FromJoin)
148296
- || pExpr->iRightJoinTable!=pTabItem->iCursor
148426
+ || pExpr->w.iRightJoinTable!=pTabItem->iCursor
148297148427
){
148298148428
sWalker.eCode = 0;
148299148429
sWalker.xExprCallback = codeCursorHintIsOrFunction;
148300148430
sqlite3WalkExpr(&sWalker, pTerm->pExpr);
148301148431
if( sWalker.eCode ) continue;
@@ -150402,11 +150532,11 @@
150402150532
** a join, then transfer the appropriate markings over to derived.
150403150533
*/
150404150534
static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
150405150535
if( pDerived ){
150406150536
pDerived->flags |= pBase->flags & EP_FromJoin;
150407
- pDerived->iRightJoinTable = pBase->iRightJoinTable;
150537
+ pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable;
150408150538
}
150409150539
}
150410150540
150411150541
/*
150412150542
** Mark term iChild as being a child of term iParent
@@ -151047,11 +151177,11 @@
151047151177
abort();
151048151178
}
151049151179
#endif
151050151180
151051151181
if( ExprHasProperty(pExpr, EP_FromJoin) ){
151052
- Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
151182
+ Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable);
151053151183
prereqAll |= x;
151054151184
extraRight = x-1; /* ON clause terms may not be used with an index
151055151185
** on left table of a LEFT JOIN. Ticket #3015 */
151056151186
if( (prereqAll>>1)>=x ){
151057151187
sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
@@ -151365,11 +151495,11 @@
151365151495
&& pWC->op==TK_AND
151366151496
){
151367151497
int i;
151368151498
for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
151369151499
int idxNew;
151370
- idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
151500
+ idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE);
151371151501
pWC->a[idxNew].u.x.iField = i+1;
151372151502
exprAnalyze(pSrc, pWC, idxNew);
151373151503
markTermAsChild(pWC, idxNew, idxTerm);
151374151504
}
151375151505
}
@@ -151398,11 +151528,11 @@
151398151528
Expr *pNewExpr;
151399151529
pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
151400151530
0, sqlite3ExprDup(db, pRight, 0));
151401151531
if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
151402151532
ExprSetProperty(pNewExpr, EP_FromJoin);
151403
- pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
151533
+ pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable;
151404151534
}
151405151535
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
151406151536
testcase( idxNew==0 );
151407151537
pNewTerm = &pWC->a[idxNew];
151408151538
pNewTerm->prereqRight = prereqExpr;
@@ -151472,11 +151602,11 @@
151472151602
** In the common case where the value is a simple integer
151473151603
** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
151474151604
** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
151475151605
** If not, then it codes as a TK_REGISTER expression.
151476151606
*/
151477
-void whereAddLimitExpr(
151607
+static void whereAddLimitExpr(
151478151608
WhereClause *pWC, /* Add the constraint to this WHERE clause */
151479151609
int iReg, /* Register that will hold value of the limit/offset */
151480151610
Expr *pExpr, /* Expression that defines the limit/offset */
151481151611
int iCsr, /* Cursor to which the constraint applies */
151482151612
int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */
@@ -153019,11 +153149,13 @@
153019153149
if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
153020153150
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
153021153151
pIdxCons[j].iTermOffset = i;
153022153152
op = pTerm->eOperator & WO_ALL;
153023153153
if( op==WO_IN ){
153024
- pHidden->mIn |= SMASKBIT32(j);
153154
+ if( (pTerm->wtFlags & TERM_SLICE)==0 ){
153155
+ pHidden->mIn |= SMASKBIT32(j);
153156
+ }
153025153157
op = WO_EQ;
153026153158
}
153027153159
if( op==WO_AUX ){
153028153160
pIdxCons[j].op = pTerm->eMatchOp;
153029153161
}else if( op & (WO_ISNULL|WO_IS) ){
@@ -154942,11 +155074,11 @@
154942155074
}
154943155075
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
154944155076
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
154945155077
Expr *pExpr;
154946155078
pExpr = pTerm->pExpr;
154947
- if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
155079
+ if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab)
154948155080
&& (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
154949155081
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
154950155082
&& (pTerm->wtFlags & TERM_VNULL)==0
154951155083
){
154952155084
return 1;
@@ -156922,11 +157054,11 @@
156922157054
if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
156923157055
pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
156924157056
for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
156925157057
if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
156926157058
if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156927
- || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
157059
+ || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor
156928157060
){
156929157061
break;
156930157062
}
156931157063
}
156932157064
}
@@ -161202,14 +161334,11 @@
161202161334
}
161203161335
return pSelect;
161204161336
}
161205161337
161206161338
161207
- /* Construct a new Expr object from a single identifier. Use the
161208
- ** new Expr to populate pOut. Set the span of pOut to be the identifier
161209
- ** that created the expression.
161210
- */
161339
+ /* Construct a new Expr object from a single token */
161211161340
static Expr *tokenExpr(Parse *pParse, int op, Token t){
161212161341
Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
161213161342
if( p ){
161214161343
/* memset(p, 0, sizeof(Expr)); */
161215161344
p->op = (u8)op;
@@ -161225,10 +161354,11 @@
161225161354
p->iTable = 0;
161226161355
p->iColumn = 0;
161227161356
p->u.zToken = (char*)&p[1];
161228161357
memcpy(p->u.zToken, t.z, t.n);
161229161358
p->u.zToken[t.n] = 0;
161359
+ p->w.iOfst = (int)(t.z - pParse->zTail);
161230161360
if( sqlite3Isquote(p->u.zToken[0]) ){
161231161361
sqlite3DequoteExpr(p);
161232161362
}
161233161363
#if SQLITE_MAX_EXPR_DEPTH>0
161234161364
p->nHeight = 1;
@@ -165036,11 +165166,11 @@
165036165166
}
165037165167
break;
165038165168
case 102: /* selcollist ::= sclp scanpt nm DOT STAR */
165039165169
{
165040165170
Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
165041
- Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165171
+ Expr *pLeft = tokenExpr(pParse, TK_ID, yymsp[-2].minor.yy0);
165042165172
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
165043165173
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
165044165174
}
165045165175
break;
165046165176
case 103: /* as ::= AS nm */
@@ -165321,30 +165451,22 @@
165321165451
case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179);
165322165452
{yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165323165453
break;
165324165454
case 180: /* expr ::= nm DOT nm */
165325165455
{
165326
- Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165327
- Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
165328
- if( IN_RENAME_OBJECT ){
165329
- sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
165330
- sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
165331
- }
165456
+ Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165457
+ Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165332165458
yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
165333165459
}
165334165460
yymsp[-2].minor.yy528 = yylhsminor.yy528;
165335165461
break;
165336165462
case 181: /* expr ::= nm DOT nm DOT nm */
165337165463
{
165338
- Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
165339
- Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165340
- Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
165464
+ Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0);
165465
+ Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165466
+ Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165341165467
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
165342
- if( IN_RENAME_OBJECT ){
165343
- sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
165344
- sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
165345
- }
165346165468
yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165347165469
}
165348165470
yymsp[-4].minor.yy528 = yylhsminor.yy528;
165349165471
break;
165350165472
case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -165352,10 +165474,11 @@
165352165474
{yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165353165475
break;
165354165476
case 184: /* term ::= INTEGER */
165355165477
{
165356165478
yylhsminor.yy528 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
165479
+ if( yylhsminor.yy528 ) yylhsminor.yy528->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail);
165357165480
}
165358165481
yymsp[0].minor.yy528 = yylhsminor.yy528;
165359165482
break;
165360165483
case 185: /* expr ::= VARIABLE */
165361165484
{
@@ -167596,11 +167719,14 @@
167596167719
}else if( tokenType==TK_FILTER ){
167597167720
assert( n==6 );
167598167721
tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed);
167599167722
#endif /* SQLITE_OMIT_WINDOWFUNC */
167600167723
}else{
167601
- sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
167724
+ Token x;
167725
+ x.z = zSql;
167726
+ x.n = n;
167727
+ sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &x);
167602167728
break;
167603167729
}
167604167730
}
167605167731
pParse->sLastToken.z = zSql;
167606167732
pParse->sLastToken.n = n;
@@ -234119,11 +234245,11 @@
234119234245
int nArg, /* Number of args */
234120234246
sqlite3_value **apUnused /* Function arguments */
234121234247
){
234122234248
assert( nArg==0 );
234123234249
UNUSED_PARAM2(nArg, apUnused);
234124
- sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
234250
+ sqlite3_result_text(pCtx, "fts5: 2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e", -1, SQLITE_TRANSIENT);
234125234251
}
234126234252
234127234253
/*
234128234254
** Return true if zName is the extension on one of the shadow tables used
234129234255
** by this module.
234130234256
--- extsrc/sqlite3.c
+++ extsrc/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.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -870,11 +870,11 @@
870 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
872 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
873 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
874 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
875 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
876
877 /*
878 ** CAPI3REF: Flags For File Open Operations
879 **
880 ** These bit values are intended for use in the
@@ -4154,11 +4154,11 @@
4154 **
4155 ** ^If the most recent error references a specific token in the input
4156 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4157 ** of the start of that token. ^The byte offset returned by
4158 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4159 ** ^If the most error does not reference a specific token in the input
4160 ** SQL, then the sqlite3_error_offset() function returns -1.
4161 **
4162 ** When the serialized [threading mode] is in use, it might be the
4163 ** case that a second error occurs on a separate thread in between
4164 ** the time of the first error and the call to these interfaces.
@@ -7515,11 +7515,11 @@
7515 ** ^The sqlite3_create_module()
7516 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
7517 ** destructor.
7518 **
7519 ** ^If the third parameter (the pointer to the sqlite3_module object) is
7520 ** NULL then no new module is create and any existing modules with the
7521 ** same name are dropped.
7522 **
7523 ** See also: [sqlite3_drop_modules()]
7524 */
7525 SQLITE_API int sqlite3_create_module(
@@ -18081,11 +18081,14 @@
18081 ** TK_SELECT: 1st register of result vector */
18082 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18083 ** TK_VARIABLE: variable number (always >= 1).
18084 ** TK_SELECT_COLUMN: column of the result vector */
18085 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18086 int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
 
 
 
18087 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
18088 union {
18089 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
18090 ** for a column of an index on an expression */
18091 Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
@@ -20249,10 +20252,11 @@
20249 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
20250 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
20251 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
20252 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
20253 SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
 
20254
20255 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
20256 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
20257
20258 #ifndef SQLITE_OMIT_SUBQUERY
@@ -23584,71 +23588,60 @@
23584 #endif /* SQLITE_OMIT_LOCALTIME */
23585
23586
23587 #ifndef SQLITE_OMIT_LOCALTIME
23588 /*
23589 ** Compute the difference (in milliseconds) between localtime and UTC
23590 ** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
23591 ** return this value and set *pRc to SQLITE_OK.
23592 **
23593 ** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
23594 ** is undefined in this case.
23595 */
23596 static sqlite3_int64 localtimeOffset(
23597 DateTime *p, /* Date at which to calculate offset */
23598 sqlite3_context *pCtx, /* Write error here if one occurs */
23599 int *pRc /* OUT: Error code. SQLITE_OK or ERROR */
23600 ){
23601 DateTime x, y;
23602 time_t t;
23603 struct tm sLocal;
 
23604
23605 /* Initialize the contents of sLocal to avoid a compiler warning. */
23606 memset(&sLocal, 0, sizeof(sLocal));
23607
23608 x = *p;
23609 computeYMD_HMS(&x);
23610 if( x.Y<1971 || x.Y>=2038 ){
 
23611 /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
23612 ** works for years between 1970 and 2037. For dates outside this range,
23613 ** SQLite attempts to map the year into an equivalent year within this
23614 ** range, do the calculation, then map the year back.
23615 */
23616 x.Y = 2000;
23617 x.M = 1;
23618 x.D = 1;
23619 x.h = 0;
23620 x.m = 0;
23621 x.s = 0.0;
23622 } else {
23623 int s = (int)(x.s + 0.5);
23624 x.s = s;
23625 }
23626 x.tz = 0;
23627 x.validJD = 0;
23628 computeJD(&x);
23629 t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
23630 if( osLocaltime(&t, &sLocal) ){
23631 sqlite3_result_error(pCtx, "local time unavailable", -1);
23632 *pRc = SQLITE_ERROR;
23633 return 0;
23634 }
23635 y.Y = sLocal.tm_year + 1900;
23636 y.M = sLocal.tm_mon + 1;
23637 y.D = sLocal.tm_mday;
23638 y.h = sLocal.tm_hour;
23639 y.m = sLocal.tm_min;
23640 y.s = sLocal.tm_sec;
23641 y.validYMD = 1;
23642 y.validHMS = 1;
23643 y.validJD = 0;
23644 y.rawS = 0;
23645 y.validTZ = 0;
23646 y.isError = 0;
23647 computeJD(&y);
23648 *pRc = SQLITE_OK;
23649 return y.iJD - x.iJD;
23650 }
23651 #endif /* SQLITE_OMIT_LOCALTIME */
23652
23653 /*
23654 ** The following table defines various date transformations of the form
@@ -23753,13 +23746,11 @@
23753 **
23754 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
23755 ** show local time.
23756 */
23757 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
23758 computeJD(p);
23759 p->iJD += localtimeOffset(p, pCtx, &rc);
23760 clearYMD_HMS_TZ(p);
23761 }
23762 break;
23763 }
23764 #endif
23765 case 'u': {
@@ -23781,22 +23772,35 @@
23781 }
23782 }
23783 #ifndef SQLITE_OMIT_LOCALTIME
23784 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
23785 if( p->tzSet==0 ){
23786 sqlite3_int64 c1;
 
 
 
 
23787 computeJD(p);
23788 c1 = localtimeOffset(p, pCtx, &rc);
23789 if( rc==SQLITE_OK ){
23790 p->iJD -= c1;
23791 clearYMD_HMS_TZ(p);
23792 p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
23793 }
 
 
 
 
 
 
 
 
 
 
23794 p->tzSet = 1;
23795 }else{
23796 rc = SQLITE_OK;
23797 }
 
23798 }
23799 #endif
23800 break;
23801 }
23802 case 'w': {
@@ -24042,15 +24046,42 @@
24042 int argc,
24043 sqlite3_value **argv
24044 ){
24045 DateTime x;
24046 if( isDate(context, argc, argv, &x)==0 ){
24047 char zBuf[100];
 
24048 computeYMD_HMS(&x);
24049 sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d",
24050 x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
24051 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24052 }
24053 }
24054
24055 /*
24056 ** time( TIMESTRING, MOD, MOD, ...)
@@ -24062,14 +24093,24 @@
24062 int argc,
24063 sqlite3_value **argv
24064 ){
24065 DateTime x;
24066 if( isDate(context, argc, argv, &x)==0 ){
24067 char zBuf[100];
 
24068 computeHMS(&x);
24069 sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
24070 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
 
 
 
 
 
 
 
 
 
24071 }
24072 }
24073
24074 /*
24075 ** date( TIMESTRING, MOD, MOD, ...)
@@ -24081,14 +24122,32 @@
24081 int argc,
24082 sqlite3_value **argv
24083 ){
24084 DateTime x;
24085 if( isDate(context, argc, argv, &x)==0 ){
24086 char zBuf[100];
 
24087 computeYMD(&x);
24088 sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
24089 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24090 }
24091 }
24092
24093 /*
24094 ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
@@ -30181,17 +30240,26 @@
30181 bufpt[j] = 0;
30182 length = j;
30183 goto adjust_width_for_utf8;
30184 }
30185 case etTOKEN: {
30186 Token *pToken;
30187 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
30188 pToken = va_arg(ap, Token*);
30189 assert( bArgList==0 );
30190 if( pToken && pToken->n ){
30191 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
30192 sqlite3RecordErrorByteOffset(pAccum->db, pToken->z);
 
 
 
 
 
 
 
 
 
 
30193 }
30194 length = width = 0;
30195 break;
30196 }
30197 case etSRCITEM: {
@@ -30265,10 +30333,22 @@
30265 zEnd = &zText[strlen(zText)];
30266 if( SQLITE_WITHIN(z,zText,zEnd) ){
30267 db->errByteOffset = (int)(z-zText);
30268 }
30269 }
 
 
 
 
 
 
 
 
 
 
 
 
30270
30271 /*
30272 ** Enlarge the memory allocation on a StrAccum object so that it is
30273 ** able to accept at least N more bytes of text.
30274 **
@@ -31107,11 +31187,11 @@
31107 StrAccum x;
31108 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31109 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31110 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31111 if( ExprHasProperty(pExpr, EP_FromJoin) ){
31112 sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
31113 }
31114 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31115 sqlite3_str_appendf(&x, " DDL");
31116 }
31117 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -57586,10 +57666,16 @@
57586 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
57587 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
57588 if( rc==SQLITE_OK ){
57589 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
57590 }
 
 
 
 
 
 
57591 }
57592 }
57593 if( rc==SQLITE_OK ){
57594 pPager->nSubRec++;
57595 assert( pPager->nSavepoint>0 );
@@ -60514,10 +60600,22 @@
60514 int eMode, /* Type of checkpoint */
60515 int *pnLog, /* OUT: Final number of frames in log */
60516 int *pnCkpt /* OUT: Final number of checkpointed frames */
60517 ){
60518 int rc = SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
60519 if( pPager->pWal ){
60520 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
60521 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
60522 pPager->pBusyHandlerArg,
60523 pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
@@ -82890,10 +82988,11 @@
82890 db->bBenignMalloc--;
82891 }else if( db->pErr ){
82892 sqlite3ValueSetNull(db->pErr);
82893 }
82894 db->errCode = rc;
 
82895 return rc;
82896 }
82897
82898 #ifdef SQLITE_ENABLE_SQLLOG
82899 /*
@@ -86496,11 +86595,11 @@
86496 case SQLITE_INTEGER: {
86497 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
86498 break;
86499 }
86500 case SQLITE_FLOAT: {
86501 rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
86502 break;
86503 }
86504 case SQLITE_BLOB: {
86505 if( pValue->flags & MEM_Zero ){
86506 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -100865,10 +100964,11 @@
100865 }else if( zTab ){
100866 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
100867 }else{
100868 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
100869 }
 
100870 pParse->checkSchema = 1;
100871 pTopNC->nNcErr++;
100872 }
100873
100874 /* If a column from a table in pSrcList is referenced, then record
@@ -100973,11 +101073,12 @@
100973 */
100974 static void notValidImpl(
100975 Parse *pParse, /* Leave error message here */
100976 NameContext *pNC, /* The name context */
100977 const char *zMsg, /* Type of error */
100978 Expr *pExpr /* Invalidate this expression on error */
 
100979 ){
100980 const char *zIn = "partial index WHERE clauses";
100981 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
100982 #ifndef SQLITE_OMIT_CHECK
100983 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
@@ -100985,14 +101086,15 @@
100985 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
100986 else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
100987 #endif
100988 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
100989 if( pExpr ) pExpr->op = TK_NULL;
 
100990 }
100991 #define sqlite3ResolveNotValid(P,N,M,X,E) \
100992 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
100993 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
100994
100995 /*
100996 ** Expression p should encode a floating point value between 1.0 and 0.0.
100997 ** Return 1024 times this value. Or return -1 if p is not a floating point
100998 ** value between 1.0 and 0.0.
@@ -101123,11 +101225,11 @@
101123 }else{
101124 Expr *pLeft = pExpr->pLeft;
101125 testcase( pNC->ncFlags & NC_IdxExpr );
101126 testcase( pNC->ncFlags & NC_GenCol );
101127 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
101128 NC_IdxExpr|NC_GenCol, 0);
101129 pRight = pExpr->pRight;
101130 if( pRight->op==TK_ID ){
101131 zDb = 0;
101132 }else{
101133 assert( pRight->op==TK_DOT );
@@ -101154,21 +101256,19 @@
101154 ExprList *pList = pExpr->x.pList; /* The argument list */
101155 int n = pList ? pList->nExpr : 0; /* Number of arguments */
101156 int no_such_func = 0; /* True if no such function exists */
101157 int wrong_num_args = 0; /* True if wrong number of arguments */
101158 int is_agg = 0; /* True if is an aggregate function */
101159 int nId; /* Number of characters in function name */
101160 const char *zId; /* The function name. */
101161 FuncDef *pDef; /* Information about the function */
101162 u8 enc = ENC(pParse->db); /* The database encoding */
101163 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
101164 #ifndef SQLITE_OMIT_WINDOWFUNC
101165 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
101166 #endif
101167 assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
101168 zId = pExpr->u.zToken;
101169 nId = sqlite3Strlen30(zId);
101170 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
101171 if( pDef==0 ){
101172 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
101173 if( pDef==0 ){
101174 no_such_func = 1;
@@ -101181,12 +101281,12 @@
101181 ExprSetProperty(pExpr, EP_Unlikely);
101182 if( n==2 ){
101183 pExpr->iTable = exprProbability(pList->a[1].pExpr);
101184 if( pExpr->iTable<0 ){
101185 sqlite3ErrorMsg(pParse,
101186 "second argument to likelihood() must be a "
101187 "constant between 0.0 and 1.0");
101188 pNC->nNcErr++;
101189 }
101190 }else{
101191 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
101192 ** equivalent to likelihood(X, 0.0625).
@@ -101203,12 +101303,12 @@
101203 #ifndef SQLITE_OMIT_AUTHORIZATION
101204 {
101205 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
101206 if( auth!=SQLITE_OK ){
101207 if( auth==SQLITE_DENY ){
101208 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
101209 pDef->zName);
101210 pNC->nNcErr++;
101211 }
101212 pExpr->op = TK_NULL;
101213 return WRC_Prune;
101214 }
@@ -101227,11 +101327,11 @@
101227 ** sqlite_version() that might change over time cannot be used
101228 ** in an index or generated column. Curiously, they can be used
101229 ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
101230 ** all this. */
101231 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
101232 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
101233 }else{
101234 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
101235 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
101236 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
101237 }
@@ -101259,11 +101359,11 @@
101259 || (pDef->xValue==0 && pDef->xInverse==0)
101260 || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
101261 );
101262 if( pDef && pDef->xValue==0 && pWin ){
101263 sqlite3ErrorMsg(pParse,
101264 "%.*s() may not be used as a window function", nId, zId
101265 );
101266 pNC->nNcErr++;
101267 }else if(
101268 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
101269 || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
@@ -101273,38 +101373,38 @@
101273 if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){
101274 zType = "window";
101275 }else{
101276 zType = "aggregate";
101277 }
101278 sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
101279 pNC->nNcErr++;
101280 is_agg = 0;
101281 }
101282 #else
101283 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
101284 sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
101285 pNC->nNcErr++;
101286 is_agg = 0;
101287 }
101288 #endif
101289 else if( no_such_func && pParse->db->init.busy==0
101290 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
101291 && pParse->explain==0
101292 #endif
101293 ){
101294 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
101295 pNC->nNcErr++;
101296 }else if( wrong_num_args ){
101297 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
101298 nId, zId);
101299 pNC->nNcErr++;
101300 }
101301 #ifndef SQLITE_OMIT_WINDOWFUNC
101302 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
101303 sqlite3ErrorMsg(pParse,
101304 "FILTER may not be used with non-aggregate %.*s()",
101305 nId, zId
101306 );
101307 pNC->nNcErr++;
101308 }
101309 #endif
101310 if( is_agg ){
@@ -101385,11 +101485,11 @@
101385 testcase( pNC->ncFlags & NC_IsCheck );
101386 testcase( pNC->ncFlags & NC_PartIdx );
101387 testcase( pNC->ncFlags & NC_IdxExpr );
101388 testcase( pNC->ncFlags & NC_GenCol );
101389 if( pNC->ncFlags & NC_SelfRef ){
101390 notValidImpl(pParse, pNC, "subqueries", pExpr);
101391 }else{
101392 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
101393 }
101394 assert( pNC->nRef>=nRef );
101395 if( nRef!=pNC->nRef ){
@@ -101403,11 +101503,11 @@
101403 testcase( pNC->ncFlags & NC_IsCheck );
101404 testcase( pNC->ncFlags & NC_PartIdx );
101405 testcase( pNC->ncFlags & NC_IdxExpr );
101406 testcase( pNC->ncFlags & NC_GenCol );
101407 sqlite3ResolveNotValid(pParse, pNC, "parameters",
101408 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
101409 break;
101410 }
101411 case TK_IS:
101412 case TK_ISNOT: {
101413 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -101455,10 +101555,11 @@
101455 testcase( pExpr->op==TK_GE );
101456 testcase( pExpr->op==TK_IS );
101457 testcase( pExpr->op==TK_ISNOT );
101458 testcase( pExpr->op==TK_BETWEEN );
101459 sqlite3ErrorMsg(pParse, "row value misused");
 
101460 }
101461 break;
101462 }
101463 }
101464 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
@@ -101568,15 +101669,17 @@
101568 */
101569 static void resolveOutOfRangeError(
101570 Parse *pParse, /* The error context into which to write the error */
101571 const char *zType, /* "ORDER" or "GROUP" */
101572 int i, /* The index (1-based) of the term out of range */
101573 int mx /* Largest permissible value of i */
 
101574 ){
101575 sqlite3ErrorMsg(pParse,
101576 "%r %s BY term out of range - should be "
101577 "between 1 and %d", i, zType, mx);
 
101578 }
101579
101580 /*
101581 ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
101582 ** each term of the ORDER BY clause is a constant integer between 1
@@ -101628,11 +101731,11 @@
101628 if( pItem->done ) continue;
101629 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
101630 if( NEVER(pE==0) ) continue;
101631 if( sqlite3ExprIsInteger(pE, &iCol) ){
101632 if( iCol<=0 || iCol>pEList->nExpr ){
101633 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
101634 return 1;
101635 }
101636 }else{
101637 iCol = resolveAsName(pParse, pEList, pE);
101638 if( iCol==0 ){
@@ -101724,11 +101827,11 @@
101724 pEList = pSelect->pEList;
101725 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
101726 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
101727 if( pItem->u.x.iOrderByCol ){
101728 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
101729 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
101730 return 1;
101731 }
101732 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
101733 }
101734 }
@@ -101816,11 +101919,11 @@
101816 if( sqlite3ExprIsInteger(pE2, &iCol) ){
101817 /* The ORDER BY term is an integer constant. Again, set the column
101818 ** number so that sqlite3ResolveOrderGroupBy() will convert the
101819 ** order-by term to a copy of the result-set expression */
101820 if( iCol<1 || iCol>0xffff ){
101821 resolveOutOfRangeError(pParse, zType, i+1, nResult);
101822 return 1;
101823 }
101824 pItem->u.x.iOrderByCol = (u16)iCol;
101825 continue;
101826 }
@@ -103069,13 +103172,12 @@
103069 **
103070 ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
103071 ** if appropriate.
103072 */
103073 static void exprSetHeight(Expr *p){
103074 int nHeight = 0;
103075 heightOfExpr(p->pLeft, &nHeight);
103076 heightOfExpr(p->pRight, &nHeight);
103077 if( ExprUseXSelect(p) ){
103078 heightOfSelect(p->x.pSelect, &nHeight);
103079 }else if( p->x.pList ){
103080 heightOfExprList(p->x.pList, &nHeight);
103081 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -103370,10 +103472,11 @@
103370 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
103371 if( pNew==0 ){
103372 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
103373 return 0;
103374 }
 
103375 if( pList
103376 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
103377 && !pParse->nested
103378 ){
103379 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
@@ -103413,11 +103516,11 @@
103413 ** (2) not tagged with SQLITE_INNOCUOUS (which means it
103414 ** is tagged with SQLITE_FUNC_UNSAFE) and
103415 ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
103416 ** that the schema is possibly tainted).
103417 */
103418 sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName);
103419 }
103420 }
103421 }
103422
103423 /*
@@ -103469,10 +103572,11 @@
103469 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
103470 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
103471 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103472 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
103473 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
 
103474 return;
103475 }
103476 x = (ynVar)i;
103477 if( x>pParse->nVar ){
103478 pParse->nVar = (int)x;
@@ -103496,10 +103600,11 @@
103496 }
103497 }
103498 pExpr->iColumn = x;
103499 if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103500 sqlite3ErrorMsg(pParse, "too many SQL variables");
 
103501 }
103502 }
103503
103504 /*
103505 ** Recursively delete an expression tree.
@@ -105937,15 +106042,16 @@
105937 const char *z = pExpr->u.zToken;
105938 assert( z!=0 );
105939 c = sqlite3DecOrHexToI64(z, &value);
105940 if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
105941 #ifdef SQLITE_OMIT_FLOATING_POINT
105942 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
105943 #else
105944 #ifndef SQLITE_OMIT_HEX_INTEGER
105945 if( sqlite3_strnicmp(z,"0x",2)==0 ){
105946 sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
 
105947 }else
105948 #endif
105949 {
105950 codeReal(v, z, negFlag, iMem);
105951 }
@@ -106617,11 +106723,11 @@
106617 if( pInfo==0
106618 || NEVER(pExpr->iAgg<0)
106619 || NEVER(pExpr->iAgg>=pInfo->nFunc)
106620 ){
106621 assert( !ExprHasProperty(pExpr, EP_IntValue) );
106622 sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
106623 }else{
106624 return pInfo->aFunc[pExpr->iAgg].iMem;
106625 }
106626 break;
106627 }
@@ -106658,11 +106764,11 @@
106658 if( pDef==0 && pParse->explain ){
106659 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
106660 }
106661 #endif
106662 if( pDef==0 || pDef->xFinalize!=0 ){
106663 sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
106664 break;
106665 }
106666 if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
106667 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
106668 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
@@ -109281,11 +109387,11 @@
109281 if( !zOld ) goto exit_rename_column;
109282 for(iCol=0; iCol<pTab->nCol; iCol++){
109283 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
109284 }
109285 if( iCol==pTab->nCol ){
109286 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
109287 goto exit_rename_column;
109288 }
109289
109290 /* Ensure the schema contains no double-quoted strings */
109291 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
@@ -109711,16 +109817,16 @@
109711 ){
109712 const char *zT = (const char*)sqlite3_value_text(pType);
109713 const char *zN = (const char*)sqlite3_value_text(pObject);
109714 char *zErr;
109715
109716 zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
109717 zT, zN, (zWhen[0] ? " " : ""), zWhen,
109718 pParse->zErrMsg
109719 );
109720 sqlite3_result_error(pCtx, zErr, -1);
109721 sqlite3_free(zErr);
109722 }
109723
109724 /*
109725 ** For each name in the the expression-list pEList (i.e. each
109726 ** pEList->a[i].zName) that matches the string in zOld, extract the
@@ -110077,11 +110183,11 @@
110077 }
110078
110079 /*
110080 ** SQL function:
110081 **
110082 ** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld)
110083 **
110084 ** 0. zSql: SQL statement to rewrite
110085 ** 1. type: Type of object ("table", "view" etc.)
110086 ** 2. object: Name of object
110087 ** 3. Database: Database name (e.g. "main")
@@ -110095,11 +110201,12 @@
110095 ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
110096 ** into zNew. The name should be quoted if bQuote is true.
110097 **
110098 ** This function is used internally by the ALTER TABLE RENAME COLUMN command.
110099 ** It is only accessible to SQL created using sqlite3NestedParse(). It is
110100 ** not reachable from ordinary SQL passed into sqlite3_prepare().
 
110101 */
110102 static void renameColumnFunc(
110103 sqlite3_context *context,
110104 int NotUsed,
110105 sqlite3_value **argv
@@ -110244,11 +110351,13 @@
110244 assert( rc==SQLITE_OK );
110245 rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote);
110246
110247 renameColumnFunc_done:
110248 if( rc!=SQLITE_OK ){
110249 if( sParse.zErrMsg ){
 
 
110250 renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110251 }else{
110252 sqlite3_result_error_code(context, rc);
110253 }
110254 }
@@ -110443,11 +110552,13 @@
110443
110444 if( rc==SQLITE_OK ){
110445 rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
110446 }
110447 if( rc!=SQLITE_OK ){
110448 if( sParse.zErrMsg ){
 
 
110449 renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110450 }else{
110451 sqlite3_result_error_code(context, rc);
110452 }
110453 }
@@ -110468,14 +110579,14 @@
110468 renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr);
110469 }
110470 return WRC_Continue;
110471 }
110472
110473 /*
110474 ** The implementation of an SQL scalar function that rewrites DDL statements
110475 ** so that any string literals that use double-quotes are modified so that
110476 ** they use single quotes.
110477 **
110478 ** Two arguments must be passed:
110479 **
110480 ** 0: Database name ("main", "temp" etc.).
110481 ** 1: SQL statement to edit.
@@ -110490,10 +110601,14 @@
110490 ** );
110491 **
110492 ** returns the string:
110493 **
110494 ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
 
 
 
 
110495 */
110496 static void renameQuotefixFunc(
110497 sqlite3_context *context,
110498 int NotUsed,
110499 sqlite3_value **argv
@@ -110564,11 +110679,15 @@
110564 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
110565 }
110566 renameTokenFree(db, sCtx.pList);
110567 }
110568 if( rc!=SQLITE_OK ){
110569 sqlite3_result_error_code(context, rc);
 
 
 
 
110570 }
110571 renameParseCleanup(&sParse);
110572 }
110573
110574 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -110576,11 +110695,12 @@
110576 #endif
110577
110578 sqlite3BtreeLeaveAll(db);
110579 }
110580
110581 /*
 
110582 ** An SQL user function that checks that there are no parse or symbol
110583 ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
110584 ** After an ALTER TABLE .. RENAME operation is performed and the schema
110585 ** reloaded, this function is called on each SQL statement in the schema
110586 ** to ensure that it is still usable.
@@ -110591,15 +110711,17 @@
110591 ** 3: Object name.
110592 ** 4: True if object is from temp schema.
110593 ** 5: "when" part of error message.
110594 ** 6: True to disable the DQS quirk when parsing SQL.
110595 **
110596 ** Unless it finds an error, this function normally returns NULL. However, it
110597 ** returns integer value 1 if:
110598 **
110599 ** * the SQL argument creates a trigger, and
110600 ** * the table that the trigger is attached to is in database zDb.
 
 
 
110601 */
110602 static void renameTableTest(
110603 sqlite3_context *context,
110604 int NotUsed,
110605 sqlite3_value **argv
@@ -110640,16 +110762,20 @@
110640 rc = renameResolveTrigger(&sParse);
110641 }
110642 if( rc==SQLITE_OK ){
110643 int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
110644 int i2 = sqlite3FindDbName(db, zDb);
110645 if( i1==i2 ) sqlite3_result_int(context, 1);
 
 
 
110646 }
110647 }
110648 }
110649
110650 if( rc!=SQLITE_OK && zWhen ){
 
110651 renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse);
110652 }
110653 renameParseCleanup(&sParse);
110654 }
110655
@@ -110761,11 +110887,11 @@
110761 assert( db->mallocFailed );
110762 goto exit_drop_column;
110763 }
110764 iCol = sqlite3ColumnIndex(pTab, zCol);
110765 if( iCol<0 ){
110766 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol);
110767 goto exit_drop_column;
110768 }
110769
110770 /* Do not allow the user to drop a PRIMARY KEY column or a column
110771 ** constrained by a UNIQUE constraint. */
@@ -114989,11 +115115,12 @@
114989 goto begin_table_error;
114990 }
114991 pTable = sqlite3FindTable(db, zName, zDb);
114992 if( pTable ){
114993 if( !noErr ){
114994 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
 
114995 }else{
114996 assert( !db->init.busy || CORRUPT_DB );
114997 sqlite3CodeVerifySchema(pParse, iDb);
114998 sqlite3ForceNotReadOnly(pParse);
114999 }
@@ -134366,29 +134493,29 @@
134366 ** sqlite3PExpr(). */
134367 if( pEq && isOuterJoin ){
134368 ExprSetProperty(pEq, EP_FromJoin);
134369 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
134370 ExprSetVVAProperty(pEq, EP_NoReduce);
134371 pEq->iRightJoinTable = pE2->iTable;
134372 }
134373 *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
134374 }
134375
134376 /*
134377 ** Set the EP_FromJoin property on all terms of the given expression.
134378 ** And set the Expr.iRightJoinTable to iTable for every term in the
134379 ** expression.
134380 **
134381 ** The EP_FromJoin property is used on terms of an expression to tell
134382 ** the LEFT OUTER JOIN processing logic that this term is part of the
134383 ** join restriction specified in the ON or USING clause and not a part
134384 ** of the more general WHERE clause. These terms are moved over to the
134385 ** WHERE clause during join processing but we need to remember that they
134386 ** originated in the ON or USING clause.
134387 **
134388 ** The Expr.iRightJoinTable tells the WHERE clause processing that the
134389 ** expression depends on table iRightJoinTable even if that table is not
134390 ** explicitly mentioned in the expression. That information is needed
134391 ** for cases like this:
134392 **
134393 ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
134394 **
@@ -134402,11 +134529,11 @@
134402 SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){
134403 while( p ){
134404 ExprSetProperty(p, EP_FromJoin);
134405 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
134406 ExprSetVVAProperty(p, EP_NoReduce);
134407 p->iRightJoinTable = iTable;
134408 if( p->op==TK_FUNCTION ){
134409 assert( ExprUseXList(p) );
134410 if( p->x.pList ){
134411 int i;
134412 for(i=0; i<p->x.pList->nExpr; i++){
@@ -134418,19 +134545,19 @@
134418 p = p->pRight;
134419 }
134420 }
134421
134422 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
134423 ** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
134424 ** an ordinary term that omits the EP_FromJoin mark.
134425 **
134426 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
134427 */
134428 static void unsetJoinExpr(Expr *p, int iTable){
134429 while( p ){
134430 if( ExprHasProperty(p, EP_FromJoin)
134431 && (iTable<0 || p->iRightJoinTable==iTable) ){
134432 ExprClearProperty(p, EP_FromJoin);
134433 }
134434 if( p->op==TK_COLUMN && p->iTable==iTable ){
134435 ExprClearProperty(p, EP_CanBeNull);
134436 }
@@ -137660,13 +137787,13 @@
137660 SubstContext *pSubst, /* Description of the substitution */
137661 Expr *pExpr /* Expr in which substitution occurs */
137662 ){
137663 if( pExpr==0 ) return 0;
137664 if( ExprHasProperty(pExpr, EP_FromJoin)
137665 && pExpr->iRightJoinTable==pSubst->iTable
137666 ){
137667 pExpr->iRightJoinTable = pSubst->iNewTable;
137668 }
137669 if( pExpr->op==TK_COLUMN
137670 && pExpr->iTable==pSubst->iTable
137671 && !ExprHasProperty(pExpr, EP_FixedCol)
137672 ){
@@ -137701,11 +137828,11 @@
137701 }
137702 if( pSubst->isLeftJoin ){
137703 ExprSetProperty(pNew, EP_CanBeNull);
137704 }
137705 if( ExprHasProperty(pExpr,EP_FromJoin) ){
137706 sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
137707 }
137708 sqlite3ExprDelete(db, pExpr);
137709 pExpr = pNew;
137710
137711 /* Ensure that the expression now has an implicit collation sequence,
@@ -137866,11 +137993,11 @@
137866 int op = pExpr->op;
137867 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
137868 renumberCursorDoMapping(pWalker, &pExpr->iTable);
137869 }
137870 if( ExprHasProperty(pExpr, EP_FromJoin) ){
137871 renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable);
137872 }
137873 return WRC_Continue;
137874 }
137875
137876 /*
@@ -138876,15 +139003,17 @@
138876 iCursor, isLeftJoin);
138877 pWhere = pWhere->pLeft;
138878 }
138879 if( isLeftJoin
138880 && (ExprHasProperty(pWhere,EP_FromJoin)==0
138881 || pWhere->iRightJoinTable!=iCursor)
138882 ){
138883 return 0; /* restriction (4) */
138884 }
138885 if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
 
 
138886 return 0; /* restriction (5) */
138887 }
138888 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
138889 nChng++;
138890 pSubq->selFlags |= SF_PushDown;
@@ -142999,10 +143128,11 @@
142999 );
143000
143001 /* If an existing TriggerPrg could not be located, create a new one. */
143002 if( !pPrg ){
143003 pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf);
 
143004 }
143005
143006 return pPrg;
143007 }
143008
@@ -148291,11 +148421,11 @@
148291 ** are also excluded. See codeCursorHintIsOrFunction() for details.
148292 */
148293 if( pTabItem->fg.jointype & JT_LEFT ){
148294 Expr *pExpr = pTerm->pExpr;
148295 if( !ExprHasProperty(pExpr, EP_FromJoin)
148296 || pExpr->iRightJoinTable!=pTabItem->iCursor
148297 ){
148298 sWalker.eCode = 0;
148299 sWalker.xExprCallback = codeCursorHintIsOrFunction;
148300 sqlite3WalkExpr(&sWalker, pTerm->pExpr);
148301 if( sWalker.eCode ) continue;
@@ -150402,11 +150532,11 @@
150402 ** a join, then transfer the appropriate markings over to derived.
150403 */
150404 static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
150405 if( pDerived ){
150406 pDerived->flags |= pBase->flags & EP_FromJoin;
150407 pDerived->iRightJoinTable = pBase->iRightJoinTable;
150408 }
150409 }
150410
150411 /*
150412 ** Mark term iChild as being a child of term iParent
@@ -151047,11 +151177,11 @@
151047 abort();
151048 }
151049 #endif
151050
151051 if( ExprHasProperty(pExpr, EP_FromJoin) ){
151052 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
151053 prereqAll |= x;
151054 extraRight = x-1; /* ON clause terms may not be used with an index
151055 ** on left table of a LEFT JOIN. Ticket #3015 */
151056 if( (prereqAll>>1)>=x ){
151057 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
@@ -151365,11 +151495,11 @@
151365 && pWC->op==TK_AND
151366 ){
151367 int i;
151368 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
151369 int idxNew;
151370 idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
151371 pWC->a[idxNew].u.x.iField = i+1;
151372 exprAnalyze(pSrc, pWC, idxNew);
151373 markTermAsChild(pWC, idxNew, idxTerm);
151374 }
151375 }
@@ -151398,11 +151528,11 @@
151398 Expr *pNewExpr;
151399 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
151400 0, sqlite3ExprDup(db, pRight, 0));
151401 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
151402 ExprSetProperty(pNewExpr, EP_FromJoin);
151403 pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
151404 }
151405 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
151406 testcase( idxNew==0 );
151407 pNewTerm = &pWC->a[idxNew];
151408 pNewTerm->prereqRight = prereqExpr;
@@ -151472,11 +151602,11 @@
151472 ** In the common case where the value is a simple integer
151473 ** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
151474 ** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
151475 ** If not, then it codes as a TK_REGISTER expression.
151476 */
151477 void whereAddLimitExpr(
151478 WhereClause *pWC, /* Add the constraint to this WHERE clause */
151479 int iReg, /* Register that will hold value of the limit/offset */
151480 Expr *pExpr, /* Expression that defines the limit/offset */
151481 int iCsr, /* Cursor to which the constraint applies */
151482 int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */
@@ -153019,11 +153149,13 @@
153019 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
153020 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
153021 pIdxCons[j].iTermOffset = i;
153022 op = pTerm->eOperator & WO_ALL;
153023 if( op==WO_IN ){
153024 pHidden->mIn |= SMASKBIT32(j);
 
 
153025 op = WO_EQ;
153026 }
153027 if( op==WO_AUX ){
153028 pIdxCons[j].op = pTerm->eMatchOp;
153029 }else if( op & (WO_ISNULL|WO_IS) ){
@@ -154942,11 +155074,11 @@
154942 }
154943 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
154944 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
154945 Expr *pExpr;
154946 pExpr = pTerm->pExpr;
154947 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
154948 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
154949 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
154950 && (pTerm->wtFlags & TERM_VNULL)==0
154951 ){
154952 return 1;
@@ -156922,11 +157054,11 @@
156922 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
156923 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
156924 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
156925 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
156926 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156927 || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
156928 ){
156929 break;
156930 }
156931 }
156932 }
@@ -161202,14 +161334,11 @@
161202 }
161203 return pSelect;
161204 }
161205
161206
161207 /* Construct a new Expr object from a single identifier. Use the
161208 ** new Expr to populate pOut. Set the span of pOut to be the identifier
161209 ** that created the expression.
161210 */
161211 static Expr *tokenExpr(Parse *pParse, int op, Token t){
161212 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
161213 if( p ){
161214 /* memset(p, 0, sizeof(Expr)); */
161215 p->op = (u8)op;
@@ -161225,10 +161354,11 @@
161225 p->iTable = 0;
161226 p->iColumn = 0;
161227 p->u.zToken = (char*)&p[1];
161228 memcpy(p->u.zToken, t.z, t.n);
161229 p->u.zToken[t.n] = 0;
 
161230 if( sqlite3Isquote(p->u.zToken[0]) ){
161231 sqlite3DequoteExpr(p);
161232 }
161233 #if SQLITE_MAX_EXPR_DEPTH>0
161234 p->nHeight = 1;
@@ -165036,11 +165166,11 @@
165036 }
165037 break;
165038 case 102: /* selcollist ::= sclp scanpt nm DOT STAR */
165039 {
165040 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
165041 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165042 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
165043 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
165044 }
165045 break;
165046 case 103: /* as ::= AS nm */
@@ -165321,30 +165451,22 @@
165321 case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179);
165322 {yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165323 break;
165324 case 180: /* expr ::= nm DOT nm */
165325 {
165326 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165327 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
165328 if( IN_RENAME_OBJECT ){
165329 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
165330 sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
165331 }
165332 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
165333 }
165334 yymsp[-2].minor.yy528 = yylhsminor.yy528;
165335 break;
165336 case 181: /* expr ::= nm DOT nm DOT nm */
165337 {
165338 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
165339 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
165340 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
165341 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
165342 if( IN_RENAME_OBJECT ){
165343 sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
165344 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
165345 }
165346 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165347 }
165348 yymsp[-4].minor.yy528 = yylhsminor.yy528;
165349 break;
165350 case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -165352,10 +165474,11 @@
165352 {yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165353 break;
165354 case 184: /* term ::= INTEGER */
165355 {
165356 yylhsminor.yy528 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
 
165357 }
165358 yymsp[0].minor.yy528 = yylhsminor.yy528;
165359 break;
165360 case 185: /* expr ::= VARIABLE */
165361 {
@@ -167596,11 +167719,14 @@
167596 }else if( tokenType==TK_FILTER ){
167597 assert( n==6 );
167598 tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed);
167599 #endif /* SQLITE_OMIT_WINDOWFUNC */
167600 }else{
167601 sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
 
 
 
167602 break;
167603 }
167604 }
167605 pParse->sLastToken.z = zSql;
167606 pParse->sLastToken.n = n;
@@ -234119,11 +234245,11 @@
234119 int nArg, /* Number of args */
234120 sqlite3_value **apUnused /* Function arguments */
234121 ){
234122 assert( nArg==0 );
234123 UNUSED_PARAM2(nArg, apUnused);
234124 sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
234125 }
234126
234127 /*
234128 ** Return true if zName is the extension on one of the shadow tables used
234129 ** by this module.
234130
--- extsrc/sqlite3.c
+++ extsrc/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.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -870,11 +870,11 @@
870 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
872 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
873 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
874 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
875 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
876
877 /*
878 ** CAPI3REF: Flags For File Open Operations
879 **
880 ** These bit values are intended for use in the
@@ -4154,11 +4154,11 @@
4154 **
4155 ** ^If the most recent error references a specific token in the input
4156 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4157 ** of the start of that token. ^The byte offset returned by
4158 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4159 ** ^If the most recent error does not reference a specific token in the input
4160 ** SQL, then the sqlite3_error_offset() function returns -1.
4161 **
4162 ** When the serialized [threading mode] is in use, it might be the
4163 ** case that a second error occurs on a separate thread in between
4164 ** the time of the first error and the call to these interfaces.
@@ -7515,11 +7515,11 @@
7515 ** ^The sqlite3_create_module()
7516 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
7517 ** destructor.
7518 **
7519 ** ^If the third parameter (the pointer to the sqlite3_module object) is
7520 ** NULL then no new module is created and any existing modules with the
7521 ** same name are dropped.
7522 **
7523 ** See also: [sqlite3_drop_modules()]
7524 */
7525 SQLITE_API int sqlite3_create_module(
@@ -18081,11 +18081,14 @@
18081 ** TK_SELECT: 1st register of result vector */
18082 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18083 ** TK_VARIABLE: variable number (always >= 1).
18084 ** TK_SELECT_COLUMN: column of the result vector */
18085 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18086 union {
18087 int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18088 int iOfst; /* else: start of token from start of statement */
18089 } w;
18090 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
18091 union {
18092 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
18093 ** for a column of an index on an expression */
18094 Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
@@ -20249,10 +20252,11 @@
20252 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
20253 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
20254 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
20255 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
20256 SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
20257 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
20258
20259 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
20260 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
20261
20262 #ifndef SQLITE_OMIT_SUBQUERY
@@ -23584,71 +23588,60 @@
23588 #endif /* SQLITE_OMIT_LOCALTIME */
23589
23590
23591 #ifndef SQLITE_OMIT_LOCALTIME
23592 /*
23593 ** Assuming the input DateTime is UTC, move it to its localtime equivalent.
 
 
 
 
 
23594 */
23595 static int toLocaltime(
23596 DateTime *p, /* Date at which to calculate offset */
23597 sqlite3_context *pCtx /* Write error here if one occurs */
 
23598 ){
 
23599 time_t t;
23600 struct tm sLocal;
23601 int iYearDiff;
23602
23603 /* Initialize the contents of sLocal to avoid a compiler warning. */
23604 memset(&sLocal, 0, sizeof(sLocal));
23605
23606 computeJD(p);
23607 if( p->iJD<21086676000*(i64)10000 /* 1970-01-01 */
23608 || p->iJD>21301414560*(i64)10000 /* 2038-01-18 */
23609 ){
23610 /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
23611 ** works for years between 1970 and 2037. For dates outside this range,
23612 ** SQLite attempts to map the year into an equivalent year within this
23613 ** range, do the calculation, then map the year back.
23614 */
23615 DateTime x = *p;
23616 computeYMD_HMS(&x);
23617 iYearDiff = (2000 + x.Y%4) - x.Y;
23618 x.Y += iYearDiff;
23619 x.validJD = 0;
23620 computeJD(&x);
23621 t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
23622 }else{
23623 iYearDiff = 0;
23624 t = (time_t)(p->iJD/1000 - 21086676*(i64)10000);
23625 }
 
 
 
23626 if( osLocaltime(&t, &sLocal) ){
23627 sqlite3_result_error(pCtx, "local time unavailable", -1);
23628 return SQLITE_ERROR;
23629 }
23630 p->Y = sLocal.tm_year + 1900 - iYearDiff;
23631 p->M = sLocal.tm_mon + 1;
23632 p->D = sLocal.tm_mday;
23633 p->h = sLocal.tm_hour;
23634 p->m = sLocal.tm_min;
23635 p->s = sLocal.tm_sec;
23636 p->validYMD = 1;
23637 p->validHMS = 1;
23638 p->validJD = 0;
23639 p->rawS = 0;
23640 p->validTZ = 0;
23641 p->isError = 0;
23642 return SQLITE_OK;
 
 
 
23643 }
23644 #endif /* SQLITE_OMIT_LOCALTIME */
23645
23646 /*
23647 ** The following table defines various date transformations of the form
@@ -23753,13 +23746,11 @@
23746 **
23747 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
23748 ** show local time.
23749 */
23750 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
23751 rc = toLocaltime(p, pCtx);
 
 
23752 }
23753 break;
23754 }
23755 #endif
23756 case 'u': {
@@ -23781,22 +23772,35 @@
23772 }
23773 }
23774 #ifndef SQLITE_OMIT_LOCALTIME
23775 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
23776 if( p->tzSet==0 ){
23777 i64 iOrigJD; /* Original localtime */
23778 i64 iGuess; /* Guess at the corresponding utc time */
23779 int cnt = 0; /* Safety to prevent infinite loop */
23780 int iErr; /* Guess is off by this much */
23781
23782 computeJD(p);
23783 iGuess = iOrigJD = p->iJD;
23784 iErr = 0;
23785 do{
23786 DateTime new;
23787 memset(&new, 0, sizeof(new));
23788 iGuess -= iErr;
23789 new.iJD = iGuess;
23790 new.validJD = 1;
23791 rc = toLocaltime(&new, pCtx);
23792 if( rc ) return rc;
23793 computeJD(&new);
23794 iErr = new.iJD - iOrigJD;
23795 }while( iErr && cnt++<3 );
23796 memset(p, 0, sizeof(*p));
23797 p->iJD = iGuess;
23798 p->validJD = 1;
23799 p->tzSet = 1;
 
 
23800 }
23801 rc = SQLITE_OK;
23802 }
23803 #endif
23804 break;
23805 }
23806 case 'w': {
@@ -24042,15 +24046,42 @@
24046 int argc,
24047 sqlite3_value **argv
24048 ){
24049 DateTime x;
24050 if( isDate(context, argc, argv, &x)==0 ){
24051 int Y, s;
24052 char zBuf[24];
24053 computeYMD_HMS(&x);
24054 Y = x.Y;
24055 if( Y<0 ) Y = -Y;
24056 zBuf[1] = '0' + (Y/1000)%10;
24057 zBuf[2] = '0' + (Y/100)%10;
24058 zBuf[3] = '0' + (Y/10)%10;
24059 zBuf[4] = '0' + (Y)%10;
24060 zBuf[5] = '-';
24061 zBuf[6] = '0' + (x.M/10)%10;
24062 zBuf[7] = '0' + (x.M)%10;
24063 zBuf[8] = '-';
24064 zBuf[9] = '0' + (x.D/10)%10;
24065 zBuf[10] = '0' + (x.D)%10;
24066 zBuf[11] = ' ';
24067 zBuf[12] = '0' + (x.h/10)%10;
24068 zBuf[13] = '0' + (x.h)%10;
24069 zBuf[14] = ':';
24070 zBuf[15] = '0' + (x.m/10)%10;
24071 zBuf[16] = '0' + (x.m)%10;
24072 zBuf[17] = ':';
24073 s = (int)x.s;
24074 zBuf[18] = '0' + (s/10)%10;
24075 zBuf[19] = '0' + (s)%10;
24076 zBuf[20] = 0;
24077 if( x.Y<0 ){
24078 zBuf[0] = '-';
24079 sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT);
24080 }else{
24081 sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT);
24082 }
24083 }
24084 }
24085
24086 /*
24087 ** time( TIMESTRING, MOD, MOD, ...)
@@ -24062,14 +24093,24 @@
24093 int argc,
24094 sqlite3_value **argv
24095 ){
24096 DateTime x;
24097 if( isDate(context, argc, argv, &x)==0 ){
24098 int s;
24099 char zBuf[16];
24100 computeHMS(&x);
24101 zBuf[0] = '0' + (x.h/10)%10;
24102 zBuf[1] = '0' + (x.h)%10;
24103 zBuf[2] = ':';
24104 zBuf[3] = '0' + (x.m/10)%10;
24105 zBuf[4] = '0' + (x.m)%10;
24106 zBuf[5] = ':';
24107 s = (int)x.s;
24108 zBuf[6] = '0' + (s/10)%10;
24109 zBuf[7] = '0' + (s)%10;
24110 zBuf[8] = 0;
24111 sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT);
24112 }
24113 }
24114
24115 /*
24116 ** date( TIMESTRING, MOD, MOD, ...)
@@ -24081,14 +24122,32 @@
24122 int argc,
24123 sqlite3_value **argv
24124 ){
24125 DateTime x;
24126 if( isDate(context, argc, argv, &x)==0 ){
24127 int Y;
24128 char zBuf[16];
24129 computeYMD(&x);
24130 Y = x.Y;
24131 if( Y<0 ) Y = -Y;
24132 zBuf[1] = '0' + (Y/1000)%10;
24133 zBuf[2] = '0' + (Y/100)%10;
24134 zBuf[3] = '0' + (Y/10)%10;
24135 zBuf[4] = '0' + (Y)%10;
24136 zBuf[5] = '-';
24137 zBuf[6] = '0' + (x.M/10)%10;
24138 zBuf[7] = '0' + (x.M)%10;
24139 zBuf[8] = '-';
24140 zBuf[9] = '0' + (x.D/10)%10;
24141 zBuf[10] = '0' + (x.D)%10;
24142 zBuf[11] = 0;
24143 if( x.Y<0 ){
24144 zBuf[0] = '-';
24145 sqlite3_result_text(context, zBuf, 11, SQLITE_TRANSIENT);
24146 }else{
24147 sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
24148 }
24149 }
24150 }
24151
24152 /*
24153 ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
@@ -30181,17 +30240,26 @@
30240 bufpt[j] = 0;
30241 length = j;
30242 goto adjust_width_for_utf8;
30243 }
30244 case etTOKEN: {
 
30245 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
30246 if( flag_alternateform ){
30247 /* %#T means an Expr pointer that uses Expr.u.zToken */
30248 Expr *pExpr = va_arg(ap,Expr*);
30249 if( ALWAYS(pExpr) && ALWAYS(!ExprHasProperty(pExpr,EP_IntValue)) ){
30250 sqlite3_str_appendall(pAccum, (const char*)pExpr->u.zToken);
30251 sqlite3RecordErrorOffsetOfExpr(pAccum->db, pExpr);
30252 }
30253 }else{
30254 /* %T means a Token pointer */
30255 Token *pToken = va_arg(ap, Token*);
30256 assert( bArgList==0 );
30257 if( pToken && pToken->n ){
30258 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
30259 sqlite3RecordErrorByteOffset(pAccum->db, pToken->z);
30260 }
30261 }
30262 length = width = 0;
30263 break;
30264 }
30265 case etSRCITEM: {
@@ -30265,10 +30333,22 @@
30333 zEnd = &zText[strlen(zText)];
30334 if( SQLITE_WITHIN(z,zText,zEnd) ){
30335 db->errByteOffset = (int)(z-zText);
30336 }
30337 }
30338
30339 /*
30340 ** If pExpr has a byte offset for the start of a token, record that as
30341 ** as the error offset.
30342 */
30343 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30344 while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
30345 pExpr = pExpr->pLeft;
30346 }
30347 if( pExpr==0 ) return;
30348 db->errByteOffset = pExpr->w.iOfst;
30349 }
30350
30351 /*
30352 ** Enlarge the memory allocation on a StrAccum object so that it is
30353 ** able to accept at least N more bytes of text.
30354 **
@@ -31107,11 +31187,11 @@
31187 StrAccum x;
31188 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31189 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31190 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31191 if( ExprHasProperty(pExpr, EP_FromJoin) ){
31192 sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable);
31193 }
31194 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31195 sqlite3_str_appendf(&x, " DDL");
31196 }
31197 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -57586,10 +57666,16 @@
57666 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
57667 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
57668 if( rc==SQLITE_OK ){
57669 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
57670 }
57671 if( rc!=SQLITE_OK ){
57672 /* Subjournal writes should be "atomic" in the sense that we should
57673 ** never allow a partial write. If anything goes wrong, make sure
57674 ** to roll back any partial writes that may have occurred */
57675 (void)sqlite3OsTruncate(pPager->sjfd, offset);
57676 }
57677 }
57678 }
57679 if( rc==SQLITE_OK ){
57680 pPager->nSubRec++;
57681 assert( pPager->nSavepoint>0 );
@@ -60514,10 +60600,22 @@
60600 int eMode, /* Type of checkpoint */
60601 int *pnLog, /* OUT: Final number of frames in log */
60602 int *pnCkpt /* OUT: Final number of checkpointed frames */
60603 ){
60604 int rc = SQLITE_OK;
60605 if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
60606 /* This only happens when a database file is zero bytes in size opened and
60607 ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint()
60608 ** is invoked without any intervening transactions. We need to start
60609 ** a transaction to initialize pWal. The PRAGMA table_list statement is
60610 ** used for this since it starts transactions on every database file,
60611 ** including all ATTACHed databases. This seems expensive for a single
60612 ** sqlite3_wal_checkpoint() call, but it happens very rarely.
60613 ** https://sqlite.org/forum/forumpost/fd0f19d229156939
60614 */
60615 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
60616 }
60617 if( pPager->pWal ){
60618 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
60619 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
60620 pPager->pBusyHandlerArg,
60621 pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
@@ -82890,10 +82988,11 @@
82988 db->bBenignMalloc--;
82989 }else if( db->pErr ){
82990 sqlite3ValueSetNull(db->pErr);
82991 }
82992 db->errCode = rc;
82993 db->errByteOffset = -1;
82994 return rc;
82995 }
82996
82997 #ifdef SQLITE_ENABLE_SQLLOG
82998 /*
@@ -86496,11 +86595,11 @@
86595 case SQLITE_INTEGER: {
86596 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
86597 break;
86598 }
86599 case SQLITE_FLOAT: {
86600 rc = sqlite3_bind_double(pStmt, i, sqlite3VdbeRealValue((Mem*)pValue));
86601 break;
86602 }
86603 case SQLITE_BLOB: {
86604 if( pValue->flags & MEM_Zero ){
86605 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -100865,10 +100964,11 @@
100964 }else if( zTab ){
100965 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
100966 }else{
100967 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
100968 }
100969 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
100970 pParse->checkSchema = 1;
100971 pTopNC->nNcErr++;
100972 }
100973
100974 /* If a column from a table in pSrcList is referenced, then record
@@ -100973,11 +101073,12 @@
101073 */
101074 static void notValidImpl(
101075 Parse *pParse, /* Leave error message here */
101076 NameContext *pNC, /* The name context */
101077 const char *zMsg, /* Type of error */
101078 Expr *pExpr, /* Invalidate this expression on error */
101079 Expr *pError /* Associate error with this expression */
101080 ){
101081 const char *zIn = "partial index WHERE clauses";
101082 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
101083 #ifndef SQLITE_OMIT_CHECK
101084 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
@@ -100985,14 +101086,15 @@
101086 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
101087 else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
101088 #endif
101089 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
101090 if( pExpr ) pExpr->op = TK_NULL;
101091 sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
101092 }
101093 #define sqlite3ResolveNotValid(P,N,M,X,E,R) \
101094 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
101095 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
101096
101097 /*
101098 ** Expression p should encode a floating point value between 1.0 and 0.0.
101099 ** Return 1024 times this value. Or return -1 if p is not a floating point
101100 ** value between 1.0 and 0.0.
@@ -101123,11 +101225,11 @@
101225 }else{
101226 Expr *pLeft = pExpr->pLeft;
101227 testcase( pNC->ncFlags & NC_IdxExpr );
101228 testcase( pNC->ncFlags & NC_GenCol );
101229 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
101230 NC_IdxExpr|NC_GenCol, 0, pExpr);
101231 pRight = pExpr->pRight;
101232 if( pRight->op==TK_ID ){
101233 zDb = 0;
101234 }else{
101235 assert( pRight->op==TK_DOT );
@@ -101154,21 +101256,19 @@
101256 ExprList *pList = pExpr->x.pList; /* The argument list */
101257 int n = pList ? pList->nExpr : 0; /* Number of arguments */
101258 int no_such_func = 0; /* True if no such function exists */
101259 int wrong_num_args = 0; /* True if wrong number of arguments */
101260 int is_agg = 0; /* True if is an aggregate function */
 
101261 const char *zId; /* The function name. */
101262 FuncDef *pDef; /* Information about the function */
101263 u8 enc = ENC(pParse->db); /* The database encoding */
101264 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
101265 #ifndef SQLITE_OMIT_WINDOWFUNC
101266 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
101267 #endif
101268 assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
101269 zId = pExpr->u.zToken;
 
101270 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
101271 if( pDef==0 ){
101272 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
101273 if( pDef==0 ){
101274 no_such_func = 1;
@@ -101181,12 +101281,12 @@
101281 ExprSetProperty(pExpr, EP_Unlikely);
101282 if( n==2 ){
101283 pExpr->iTable = exprProbability(pList->a[1].pExpr);
101284 if( pExpr->iTable<0 ){
101285 sqlite3ErrorMsg(pParse,
101286 "second argument to %#T() must be a "
101287 "constant between 0.0 and 1.0", pExpr);
101288 pNC->nNcErr++;
101289 }
101290 }else{
101291 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
101292 ** equivalent to likelihood(X, 0.0625).
@@ -101203,12 +101303,12 @@
101303 #ifndef SQLITE_OMIT_AUTHORIZATION
101304 {
101305 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
101306 if( auth!=SQLITE_OK ){
101307 if( auth==SQLITE_DENY ){
101308 sqlite3ErrorMsg(pParse, "not authorized to use function: %#T",
101309 pExpr);
101310 pNC->nNcErr++;
101311 }
101312 pExpr->op = TK_NULL;
101313 return WRC_Prune;
101314 }
@@ -101227,11 +101327,11 @@
101327 ** sqlite_version() that might change over time cannot be used
101328 ** in an index or generated column. Curiously, they can be used
101329 ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
101330 ** all this. */
101331 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
101332 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
101333 }else{
101334 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
101335 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
101336 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
101337 }
@@ -101259,11 +101359,11 @@
101359 || (pDef->xValue==0 && pDef->xInverse==0)
101360 || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
101361 );
101362 if( pDef && pDef->xValue==0 && pWin ){
101363 sqlite3ErrorMsg(pParse,
101364 "%#T() may not be used as a window function", pExpr
101365 );
101366 pNC->nNcErr++;
101367 }else if(
101368 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
101369 || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
@@ -101273,38 +101373,38 @@
101373 if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){
101374 zType = "window";
101375 }else{
101376 zType = "aggregate";
101377 }
101378 sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr);
101379 pNC->nNcErr++;
101380 is_agg = 0;
101381 }
101382 #else
101383 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
101384 sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
101385 pNC->nNcErr++;
101386 is_agg = 0;
101387 }
101388 #endif
101389 else if( no_such_func && pParse->db->init.busy==0
101390 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
101391 && pParse->explain==0
101392 #endif
101393 ){
101394 sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
101395 pNC->nNcErr++;
101396 }else if( wrong_num_args ){
101397 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %#T()",
101398 pExpr);
101399 pNC->nNcErr++;
101400 }
101401 #ifndef SQLITE_OMIT_WINDOWFUNC
101402 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
101403 sqlite3ErrorMsg(pParse,
101404 "FILTER may not be used with non-aggregate %#T()",
101405 pExpr
101406 );
101407 pNC->nNcErr++;
101408 }
101409 #endif
101410 if( is_agg ){
@@ -101385,11 +101485,11 @@
101485 testcase( pNC->ncFlags & NC_IsCheck );
101486 testcase( pNC->ncFlags & NC_PartIdx );
101487 testcase( pNC->ncFlags & NC_IdxExpr );
101488 testcase( pNC->ncFlags & NC_GenCol );
101489 if( pNC->ncFlags & NC_SelfRef ){
101490 notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
101491 }else{
101492 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
101493 }
101494 assert( pNC->nRef>=nRef );
101495 if( nRef!=pNC->nRef ){
@@ -101403,11 +101503,11 @@
101503 testcase( pNC->ncFlags & NC_IsCheck );
101504 testcase( pNC->ncFlags & NC_PartIdx );
101505 testcase( pNC->ncFlags & NC_IdxExpr );
101506 testcase( pNC->ncFlags & NC_GenCol );
101507 sqlite3ResolveNotValid(pParse, pNC, "parameters",
101508 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr, pExpr);
101509 break;
101510 }
101511 case TK_IS:
101512 case TK_ISNOT: {
101513 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -101455,10 +101555,11 @@
101555 testcase( pExpr->op==TK_GE );
101556 testcase( pExpr->op==TK_IS );
101557 testcase( pExpr->op==TK_ISNOT );
101558 testcase( pExpr->op==TK_BETWEEN );
101559 sqlite3ErrorMsg(pParse, "row value misused");
101560 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
101561 }
101562 break;
101563 }
101564 }
101565 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
@@ -101568,15 +101669,17 @@
101669 */
101670 static void resolveOutOfRangeError(
101671 Parse *pParse, /* The error context into which to write the error */
101672 const char *zType, /* "ORDER" or "GROUP" */
101673 int i, /* The index (1-based) of the term out of range */
101674 int mx, /* Largest permissible value of i */
101675 Expr *pError /* Associate the error with the expression */
101676 ){
101677 sqlite3ErrorMsg(pParse,
101678 "%r %s BY term out of range - should be "
101679 "between 1 and %d", i, zType, mx);
101680 sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
101681 }
101682
101683 /*
101684 ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
101685 ** each term of the ORDER BY clause is a constant integer between 1
@@ -101628,11 +101731,11 @@
101731 if( pItem->done ) continue;
101732 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
101733 if( NEVER(pE==0) ) continue;
101734 if( sqlite3ExprIsInteger(pE, &iCol) ){
101735 if( iCol<=0 || iCol>pEList->nExpr ){
101736 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
101737 return 1;
101738 }
101739 }else{
101740 iCol = resolveAsName(pParse, pEList, pE);
101741 if( iCol==0 ){
@@ -101724,11 +101827,11 @@
101827 pEList = pSelect->pEList;
101828 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
101829 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
101830 if( pItem->u.x.iOrderByCol ){
101831 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
101832 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
101833 return 1;
101834 }
101835 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
101836 }
101837 }
@@ -101816,11 +101919,11 @@
101919 if( sqlite3ExprIsInteger(pE2, &iCol) ){
101920 /* The ORDER BY term is an integer constant. Again, set the column
101921 ** number so that sqlite3ResolveOrderGroupBy() will convert the
101922 ** order-by term to a copy of the result-set expression */
101923 if( iCol<1 || iCol>0xffff ){
101924 resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2);
101925 return 1;
101926 }
101927 pItem->u.x.iOrderByCol = (u16)iCol;
101928 continue;
101929 }
@@ -103069,13 +103172,12 @@
103172 **
103173 ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
103174 ** if appropriate.
103175 */
103176 static void exprSetHeight(Expr *p){
103177 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
103178 if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
 
103179 if( ExprUseXSelect(p) ){
103180 heightOfSelect(p->x.pSelect, &nHeight);
103181 }else if( p->x.pList ){
103182 heightOfExprList(p->x.pList, &nHeight);
103183 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -103370,10 +103472,11 @@
103472 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
103473 if( pNew==0 ){
103474 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
103475 return 0;
103476 }
103477 pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
103478 if( pList
103479 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
103480 && !pParse->nested
103481 ){
103482 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
@@ -103413,11 +103516,11 @@
103516 ** (2) not tagged with SQLITE_INNOCUOUS (which means it
103517 ** is tagged with SQLITE_FUNC_UNSAFE) and
103518 ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
103519 ** that the schema is possibly tainted).
103520 */
103521 sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr);
103522 }
103523 }
103524 }
103525
103526 /*
@@ -103469,10 +103572,11 @@
103572 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
103573 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
103574 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103575 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
103576 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
103577 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
103578 return;
103579 }
103580 x = (ynVar)i;
103581 if( x>pParse->nVar ){
103582 pParse->nVar = (int)x;
@@ -103496,10 +103600,11 @@
103600 }
103601 }
103602 pExpr->iColumn = x;
103603 if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
103604 sqlite3ErrorMsg(pParse, "too many SQL variables");
103605 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
103606 }
103607 }
103608
103609 /*
103610 ** Recursively delete an expression tree.
@@ -105937,15 +106042,16 @@
106042 const char *z = pExpr->u.zToken;
106043 assert( z!=0 );
106044 c = sqlite3DecOrHexToI64(z, &value);
106045 if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
106046 #ifdef SQLITE_OMIT_FLOATING_POINT
106047 sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr);
106048 #else
106049 #ifndef SQLITE_OMIT_HEX_INTEGER
106050 if( sqlite3_strnicmp(z,"0x",2)==0 ){
106051 sqlite3ErrorMsg(pParse, "hex literal too big: %s%#T",
106052 negFlag?"-":"",pExpr);
106053 }else
106054 #endif
106055 {
106056 codeReal(v, z, negFlag, iMem);
106057 }
@@ -106617,11 +106723,11 @@
106723 if( pInfo==0
106724 || NEVER(pExpr->iAgg<0)
106725 || NEVER(pExpr->iAgg>=pInfo->nFunc)
106726 ){
106727 assert( !ExprHasProperty(pExpr, EP_IntValue) );
106728 sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr);
106729 }else{
106730 return pInfo->aFunc[pExpr->iAgg].iMem;
106731 }
106732 break;
106733 }
@@ -106658,11 +106764,11 @@
106764 if( pDef==0 && pParse->explain ){
106765 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
106766 }
106767 #endif
106768 if( pDef==0 || pDef->xFinalize!=0 ){
106769 sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
106770 break;
106771 }
106772 if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
106773 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
106774 assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 );
@@ -109281,11 +109387,11 @@
109387 if( !zOld ) goto exit_rename_column;
109388 for(iCol=0; iCol<pTab->nCol; iCol++){
109389 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
109390 }
109391 if( iCol==pTab->nCol ){
109392 sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
109393 goto exit_rename_column;
109394 }
109395
109396 /* Ensure the schema contains no double-quoted strings */
109397 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
@@ -109711,16 +109817,16 @@
109817 ){
109818 const char *zT = (const char*)sqlite3_value_text(pType);
109819 const char *zN = (const char*)sqlite3_value_text(pObject);
109820 char *zErr;
109821
109822 zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s",
109823 zT, zN, (zWhen[0] ? " " : ""), zWhen,
109824 pParse->zErrMsg
109825 );
109826 sqlite3_result_error(pCtx, zErr, -1);
109827 sqlite3DbFree(pParse->db, zErr);
109828 }
109829
109830 /*
109831 ** For each name in the the expression-list pEList (i.e. each
109832 ** pEList->a[i].zName) that matches the string in zOld, extract the
@@ -110077,11 +110183,11 @@
110183 }
110184
110185 /*
110186 ** SQL function:
110187 **
110188 ** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
110189 **
110190 ** 0. zSql: SQL statement to rewrite
110191 ** 1. type: Type of object ("table", "view" etc.)
110192 ** 2. object: Name of object
110193 ** 3. Database: Database name (e.g. "main")
@@ -110095,11 +110201,12 @@
110201 ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
110202 ** into zNew. The name should be quoted if bQuote is true.
110203 **
110204 ** This function is used internally by the ALTER TABLE RENAME COLUMN command.
110205 ** It is only accessible to SQL created using sqlite3NestedParse(). It is
110206 ** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
110207 ** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
110208 */
110209 static void renameColumnFunc(
110210 sqlite3_context *context,
110211 int NotUsed,
110212 sqlite3_value **argv
@@ -110244,11 +110351,13 @@
110351 assert( rc==SQLITE_OK );
110352 rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote);
110353
110354 renameColumnFunc_done:
110355 if( rc!=SQLITE_OK ){
110356 if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
110357 sqlite3_result_value(context, argv[0]);
110358 }else if( sParse.zErrMsg ){
110359 renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110360 }else{
110361 sqlite3_result_error_code(context, rc);
110362 }
110363 }
@@ -110443,11 +110552,13 @@
110552
110553 if( rc==SQLITE_OK ){
110554 rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
110555 }
110556 if( rc!=SQLITE_OK ){
110557 if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
110558 sqlite3_result_value(context, argv[3]);
110559 }else if( sParse.zErrMsg ){
110560 renameColumnParseError(context, "", argv[1], argv[2], &sParse);
110561 }else{
110562 sqlite3_result_error_code(context, rc);
110563 }
110564 }
@@ -110468,14 +110579,14 @@
110579 renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr);
110580 }
110581 return WRC_Continue;
110582 }
110583
110584 /* SQL function: sqlite_rename_quotefix(DB,SQL)
110585 **
110586 ** Rewrite the DDL statement "SQL" so that any string literals that use
110587 ** double-quotes use single quotes instead.
110588 **
110589 ** Two arguments must be passed:
110590 **
110591 ** 0: Database name ("main", "temp" etc.).
110592 ** 1: SQL statement to edit.
@@ -110490,10 +110601,14 @@
110601 ** );
110602 **
110603 ** returns the string:
110604 **
110605 ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
110606 **
110607 ** If there is a error in the input SQL, then raise an error, except
110608 ** if PRAGMA writable_schema=ON, then just return the input string
110609 ** unmodified following an error.
110610 */
110611 static void renameQuotefixFunc(
110612 sqlite3_context *context,
110613 int NotUsed,
110614 sqlite3_value **argv
@@ -110564,11 +110679,15 @@
110679 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
110680 }
110681 renameTokenFree(db, sCtx.pList);
110682 }
110683 if( rc!=SQLITE_OK ){
110684 if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){
110685 sqlite3_result_value(context, argv[1]);
110686 }else{
110687 sqlite3_result_error_code(context, rc);
110688 }
110689 }
110690 renameParseCleanup(&sParse);
110691 }
110692
110693 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -110576,11 +110695,12 @@
110695 #endif
110696
110697 sqlite3BtreeLeaveAll(db);
110698 }
110699
110700 /* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS)
110701 **
110702 ** An SQL user function that checks that there are no parse or symbol
110703 ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
110704 ** After an ALTER TABLE .. RENAME operation is performed and the schema
110705 ** reloaded, this function is called on each SQL statement in the schema
110706 ** to ensure that it is still usable.
@@ -110591,15 +110711,17 @@
110711 ** 3: Object name.
110712 ** 4: True if object is from temp schema.
110713 ** 5: "when" part of error message.
110714 ** 6: True to disable the DQS quirk when parsing SQL.
110715 **
110716 ** The return value is computed as follows:
 
110717 **
110718 ** A. If an error is seen and not in PRAGMA writable_schema=ON mode,
110719 ** then raise the error.
110720 ** B. Else if a trigger is created and the the table that the trigger is
110721 ** attached to is in database zDb, then return 1.
110722 ** C. Otherwise return NULL.
110723 */
110724 static void renameTableTest(
110725 sqlite3_context *context,
110726 int NotUsed,
110727 sqlite3_value **argv
@@ -110640,16 +110762,20 @@
110762 rc = renameResolveTrigger(&sParse);
110763 }
110764 if( rc==SQLITE_OK ){
110765 int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
110766 int i2 = sqlite3FindDbName(db, zDb);
110767 if( i1==i2 ){
110768 /* Handle output case B */
110769 sqlite3_result_int(context, 1);
110770 }
110771 }
110772 }
110773 }
110774
110775 if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){
110776 /* Output case A */
110777 renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse);
110778 }
110779 renameParseCleanup(&sParse);
110780 }
110781
@@ -110761,11 +110887,11 @@
110887 assert( db->mallocFailed );
110888 goto exit_drop_column;
110889 }
110890 iCol = sqlite3ColumnIndex(pTab, zCol);
110891 if( iCol<0 ){
110892 sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName);
110893 goto exit_drop_column;
110894 }
110895
110896 /* Do not allow the user to drop a PRIMARY KEY column or a column
110897 ** constrained by a UNIQUE constraint. */
@@ -114989,11 +115115,12 @@
115115 goto begin_table_error;
115116 }
115117 pTable = sqlite3FindTable(db, zName, zDb);
115118 if( pTable ){
115119 if( !noErr ){
115120 sqlite3ErrorMsg(pParse, "%s %T already exists",
115121 (IsView(pTable)? "view" : "table"), pName);
115122 }else{
115123 assert( !db->init.busy || CORRUPT_DB );
115124 sqlite3CodeVerifySchema(pParse, iDb);
115125 sqlite3ForceNotReadOnly(pParse);
115126 }
@@ -134366,29 +134493,29 @@
134493 ** sqlite3PExpr(). */
134494 if( pEq && isOuterJoin ){
134495 ExprSetProperty(pEq, EP_FromJoin);
134496 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
134497 ExprSetVVAProperty(pEq, EP_NoReduce);
134498 pEq->w.iRightJoinTable = pE2->iTable;
134499 }
134500 *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
134501 }
134502
134503 /*
134504 ** Set the EP_FromJoin property on all terms of the given expression.
134505 ** And set the Expr.w.iRightJoinTable to iTable for every term in the
134506 ** expression.
134507 **
134508 ** The EP_FromJoin property is used on terms of an expression to tell
134509 ** the LEFT OUTER JOIN processing logic that this term is part of the
134510 ** join restriction specified in the ON or USING clause and not a part
134511 ** of the more general WHERE clause. These terms are moved over to the
134512 ** WHERE clause during join processing but we need to remember that they
134513 ** originated in the ON or USING clause.
134514 **
134515 ** The Expr.w.iRightJoinTable tells the WHERE clause processing that the
134516 ** expression depends on table w.iRightJoinTable even if that table is not
134517 ** explicitly mentioned in the expression. That information is needed
134518 ** for cases like this:
134519 **
134520 ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
134521 **
@@ -134402,11 +134529,11 @@
134529 SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){
134530 while( p ){
134531 ExprSetProperty(p, EP_FromJoin);
134532 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
134533 ExprSetVVAProperty(p, EP_NoReduce);
134534 p->w.iRightJoinTable = iTable;
134535 if( p->op==TK_FUNCTION ){
134536 assert( ExprUseXList(p) );
134537 if( p->x.pList ){
134538 int i;
134539 for(i=0; i<p->x.pList->nExpr; i++){
@@ -134418,19 +134545,19 @@
134545 p = p->pRight;
134546 }
134547 }
134548
134549 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
134550 ** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into
134551 ** an ordinary term that omits the EP_FromJoin mark.
134552 **
134553 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
134554 */
134555 static void unsetJoinExpr(Expr *p, int iTable){
134556 while( p ){
134557 if( ExprHasProperty(p, EP_FromJoin)
134558 && (iTable<0 || p->w.iRightJoinTable==iTable) ){
134559 ExprClearProperty(p, EP_FromJoin);
134560 }
134561 if( p->op==TK_COLUMN && p->iTable==iTable ){
134562 ExprClearProperty(p, EP_CanBeNull);
134563 }
@@ -137660,13 +137787,13 @@
137787 SubstContext *pSubst, /* Description of the substitution */
137788 Expr *pExpr /* Expr in which substitution occurs */
137789 ){
137790 if( pExpr==0 ) return 0;
137791 if( ExprHasProperty(pExpr, EP_FromJoin)
137792 && pExpr->w.iRightJoinTable==pSubst->iTable
137793 ){
137794 pExpr->w.iRightJoinTable = pSubst->iNewTable;
137795 }
137796 if( pExpr->op==TK_COLUMN
137797 && pExpr->iTable==pSubst->iTable
137798 && !ExprHasProperty(pExpr, EP_FixedCol)
137799 ){
@@ -137701,11 +137828,11 @@
137828 }
137829 if( pSubst->isLeftJoin ){
137830 ExprSetProperty(pNew, EP_CanBeNull);
137831 }
137832 if( ExprHasProperty(pExpr,EP_FromJoin) ){
137833 sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable);
137834 }
137835 sqlite3ExprDelete(db, pExpr);
137836 pExpr = pNew;
137837
137838 /* Ensure that the expression now has an implicit collation sequence,
@@ -137866,11 +137993,11 @@
137993 int op = pExpr->op;
137994 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
137995 renumberCursorDoMapping(pWalker, &pExpr->iTable);
137996 }
137997 if( ExprHasProperty(pExpr, EP_FromJoin) ){
137998 renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable);
137999 }
138000 return WRC_Continue;
138001 }
138002
138003 /*
@@ -138876,15 +139003,17 @@
139003 iCursor, isLeftJoin);
139004 pWhere = pWhere->pLeft;
139005 }
139006 if( isLeftJoin
139007 && (ExprHasProperty(pWhere,EP_FromJoin)==0
139008 || pWhere->w.iRightJoinTable!=iCursor)
139009 ){
139010 return 0; /* restriction (4) */
139011 }
139012 if( ExprHasProperty(pWhere,EP_FromJoin)
139013 && pWhere->w.iRightJoinTable!=iCursor
139014 ){
139015 return 0; /* restriction (5) */
139016 }
139017 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
139018 nChng++;
139019 pSubq->selFlags |= SF_PushDown;
@@ -142999,10 +143128,11 @@
143128 );
143129
143130 /* If an existing TriggerPrg could not be located, create a new one. */
143131 if( !pPrg ){
143132 pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf);
143133 pParse->db->errByteOffset = -1;
143134 }
143135
143136 return pPrg;
143137 }
143138
@@ -148291,11 +148421,11 @@
148421 ** are also excluded. See codeCursorHintIsOrFunction() for details.
148422 */
148423 if( pTabItem->fg.jointype & JT_LEFT ){
148424 Expr *pExpr = pTerm->pExpr;
148425 if( !ExprHasProperty(pExpr, EP_FromJoin)
148426 || pExpr->w.iRightJoinTable!=pTabItem->iCursor
148427 ){
148428 sWalker.eCode = 0;
148429 sWalker.xExprCallback = codeCursorHintIsOrFunction;
148430 sqlite3WalkExpr(&sWalker, pTerm->pExpr);
148431 if( sWalker.eCode ) continue;
@@ -150402,11 +150532,11 @@
150532 ** a join, then transfer the appropriate markings over to derived.
150533 */
150534 static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
150535 if( pDerived ){
150536 pDerived->flags |= pBase->flags & EP_FromJoin;
150537 pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable;
150538 }
150539 }
150540
150541 /*
150542 ** Mark term iChild as being a child of term iParent
@@ -151047,11 +151177,11 @@
151177 abort();
151178 }
151179 #endif
151180
151181 if( ExprHasProperty(pExpr, EP_FromJoin) ){
151182 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable);
151183 prereqAll |= x;
151184 extraRight = x-1; /* ON clause terms may not be used with an index
151185 ** on left table of a LEFT JOIN. Ticket #3015 */
151186 if( (prereqAll>>1)>=x ){
151187 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
@@ -151365,11 +151495,11 @@
151495 && pWC->op==TK_AND
151496 ){
151497 int i;
151498 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
151499 int idxNew;
151500 idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE);
151501 pWC->a[idxNew].u.x.iField = i+1;
151502 exprAnalyze(pSrc, pWC, idxNew);
151503 markTermAsChild(pWC, idxNew, idxTerm);
151504 }
151505 }
@@ -151398,11 +151528,11 @@
151528 Expr *pNewExpr;
151529 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
151530 0, sqlite3ExprDup(db, pRight, 0));
151531 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
151532 ExprSetProperty(pNewExpr, EP_FromJoin);
151533 pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable;
151534 }
151535 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
151536 testcase( idxNew==0 );
151537 pNewTerm = &pWC->a[idxNew];
151538 pNewTerm->prereqRight = prereqExpr;
@@ -151472,11 +151602,11 @@
151602 ** In the common case where the value is a simple integer
151603 ** (example: "LIMIT 5 OFFSET 10") then the expression codes as a
151604 ** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value().
151605 ** If not, then it codes as a TK_REGISTER expression.
151606 */
151607 static void whereAddLimitExpr(
151608 WhereClause *pWC, /* Add the constraint to this WHERE clause */
151609 int iReg, /* Register that will hold value of the limit/offset */
151610 Expr *pExpr, /* Expression that defines the limit/offset */
151611 int iCsr, /* Cursor to which the constraint applies */
151612 int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */
@@ -153019,11 +153149,13 @@
153149 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
153150 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
153151 pIdxCons[j].iTermOffset = i;
153152 op = pTerm->eOperator & WO_ALL;
153153 if( op==WO_IN ){
153154 if( (pTerm->wtFlags & TERM_SLICE)==0 ){
153155 pHidden->mIn |= SMASKBIT32(j);
153156 }
153157 op = WO_EQ;
153158 }
153159 if( op==WO_AUX ){
153160 pIdxCons[j].op = pTerm->eMatchOp;
153161 }else if( op & (WO_ISNULL|WO_IS) ){
@@ -154942,11 +155074,11 @@
155074 }
155075 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
155076 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
155077 Expr *pExpr;
155078 pExpr = pTerm->pExpr;
155079 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab)
155080 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
155081 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
155082 && (pTerm->wtFlags & TERM_VNULL)==0
155083 ){
155084 return 1;
@@ -156922,11 +157054,11 @@
157054 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
157055 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
157056 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
157057 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
157058 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
157059 || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor
157060 ){
157061 break;
157062 }
157063 }
157064 }
@@ -161202,14 +161334,11 @@
161334 }
161335 return pSelect;
161336 }
161337
161338
161339 /* Construct a new Expr object from a single token */
 
 
 
161340 static Expr *tokenExpr(Parse *pParse, int op, Token t){
161341 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
161342 if( p ){
161343 /* memset(p, 0, sizeof(Expr)); */
161344 p->op = (u8)op;
@@ -161225,10 +161354,11 @@
161354 p->iTable = 0;
161355 p->iColumn = 0;
161356 p->u.zToken = (char*)&p[1];
161357 memcpy(p->u.zToken, t.z, t.n);
161358 p->u.zToken[t.n] = 0;
161359 p->w.iOfst = (int)(t.z - pParse->zTail);
161360 if( sqlite3Isquote(p->u.zToken[0]) ){
161361 sqlite3DequoteExpr(p);
161362 }
161363 #if SQLITE_MAX_EXPR_DEPTH>0
161364 p->nHeight = 1;
@@ -165036,11 +165166,11 @@
165166 }
165167 break;
165168 case 102: /* selcollist ::= sclp scanpt nm DOT STAR */
165169 {
165170 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
165171 Expr *pLeft = tokenExpr(pParse, TK_ID, yymsp[-2].minor.yy0);
165172 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
165173 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
165174 }
165175 break;
165176 case 103: /* as ::= AS nm */
@@ -165321,30 +165451,22 @@
165451 case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179);
165452 {yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165453 break;
165454 case 180: /* expr ::= nm DOT nm */
165455 {
165456 Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165457 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
 
 
 
 
165458 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
165459 }
165460 yymsp[-2].minor.yy528 = yylhsminor.yy528;
165461 break;
165462 case 181: /* expr ::= nm DOT nm DOT nm */
165463 {
165464 Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0);
165465 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165466 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165467 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
 
 
 
 
165468 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165469 }
165470 yymsp[-4].minor.yy528 = yylhsminor.yy528;
165471 break;
165472 case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -165352,10 +165474,11 @@
165474 {yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
165475 break;
165476 case 184: /* term ::= INTEGER */
165477 {
165478 yylhsminor.yy528 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
165479 if( yylhsminor.yy528 ) yylhsminor.yy528->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail);
165480 }
165481 yymsp[0].minor.yy528 = yylhsminor.yy528;
165482 break;
165483 case 185: /* expr ::= VARIABLE */
165484 {
@@ -167596,11 +167719,14 @@
167719 }else if( tokenType==TK_FILTER ){
167720 assert( n==6 );
167721 tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed);
167722 #endif /* SQLITE_OMIT_WINDOWFUNC */
167723 }else{
167724 Token x;
167725 x.z = zSql;
167726 x.n = n;
167727 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &x);
167728 break;
167729 }
167730 }
167731 pParse->sLastToken.z = zSql;
167732 pParse->sLastToken.n = n;
@@ -234119,11 +234245,11 @@
234245 int nArg, /* Number of args */
234246 sqlite3_value **apUnused /* Function arguments */
234247 ){
234248 assert( nArg==0 );
234249 UNUSED_PARAM2(nArg, apUnused);
234250 sqlite3_result_text(pCtx, "fts5: 2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e", -1, SQLITE_TRANSIENT);
234251 }
234252
234253 /*
234254 ** Return true if zName is the extension on one of the shadow tables used
234255 ** by this module.
234256
--- extsrc/sqlite3.h
+++ extsrc/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.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
151
+#define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -564,11 +564,11 @@
564564
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565565
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566566
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
567567
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
568568
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
569
-#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
569
+#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
570570
571571
/*
572572
** CAPI3REF: Flags For File Open Operations
573573
**
574574
** These bit values are intended for use in the
@@ -3848,11 +3848,11 @@
38483848
**
38493849
** ^If the most recent error references a specific token in the input
38503850
** SQL, the sqlite3_error_offset() interface returns the byte offset
38513851
** of the start of that token. ^The byte offset returned by
38523852
** sqlite3_error_offset() assumes that the input SQL is UTF8.
3853
-** ^If the most error does not reference a specific token in the input
3853
+** ^If the most recent error does not reference a specific token in the input
38543854
** SQL, then the sqlite3_error_offset() function returns -1.
38553855
**
38563856
** When the serialized [threading mode] is in use, it might be the
38573857
** case that a second error occurs on a separate thread in between
38583858
** the time of the first error and the call to these interfaces.
@@ -7209,11 +7209,11 @@
72097209
** ^The sqlite3_create_module()
72107210
** interface is equivalent to sqlite3_create_module_v2() with a NULL
72117211
** destructor.
72127212
**
72137213
** ^If the third parameter (the pointer to the sqlite3_module object) is
7214
-** NULL then no new module is create and any existing modules with the
7214
+** NULL then no new module is created and any existing modules with the
72157215
** same name are dropped.
72167216
**
72177217
** See also: [sqlite3_drop_modules()]
72187218
*/
72197219
SQLITE_API int sqlite3_create_module(
72207220
--- extsrc/sqlite3.h
+++ extsrc/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.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -564,11 +564,11 @@
564 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
567 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
568 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
569 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
570
571 /*
572 ** CAPI3REF: Flags For File Open Operations
573 **
574 ** These bit values are intended for use in the
@@ -3848,11 +3848,11 @@
3848 **
3849 ** ^If the most recent error references a specific token in the input
3850 ** SQL, the sqlite3_error_offset() interface returns the byte offset
3851 ** of the start of that token. ^The byte offset returned by
3852 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
3853 ** ^If the most error does not reference a specific token in the input
3854 ** SQL, then the sqlite3_error_offset() function returns -1.
3855 **
3856 ** When the serialized [threading mode] is in use, it might be the
3857 ** case that a second error occurs on a separate thread in between
3858 ** the time of the first error and the call to these interfaces.
@@ -7209,11 +7209,11 @@
7209 ** ^The sqlite3_create_module()
7210 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
7211 ** destructor.
7212 **
7213 ** ^If the third parameter (the pointer to the sqlite3_module object) is
7214 ** NULL then no new module is create and any existing modules with the
7215 ** same name are dropped.
7216 **
7217 ** See also: [sqlite3_drop_modules()]
7218 */
7219 SQLITE_API int sqlite3_create_module(
7220
--- extsrc/sqlite3.h
+++ extsrc/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.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -564,11 +564,11 @@
564 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
567 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
568 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
569 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
570
571 /*
572 ** CAPI3REF: Flags For File Open Operations
573 **
574 ** These bit values are intended for use in the
@@ -3848,11 +3848,11 @@
3848 **
3849 ** ^If the most recent error references a specific token in the input
3850 ** SQL, the sqlite3_error_offset() interface returns the byte offset
3851 ** of the start of that token. ^The byte offset returned by
3852 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
3853 ** ^If the most recent error does not reference a specific token in the input
3854 ** SQL, then the sqlite3_error_offset() function returns -1.
3855 **
3856 ** When the serialized [threading mode] is in use, it might be the
3857 ** case that a second error occurs on a separate thread in between
3858 ** the time of the first error and the call to these interfaces.
@@ -7209,11 +7209,11 @@
7209 ** ^The sqlite3_create_module()
7210 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
7211 ** destructor.
7212 **
7213 ** ^If the third parameter (the pointer to the sqlite3_module object) is
7214 ** NULL then no new module is created and any existing modules with the
7215 ** same name are dropped.
7216 **
7217 ** See also: [sqlite3_drop_modules()]
7218 */
7219 SQLITE_API int sqlite3_create_module(
7220

Keyboard Shortcuts

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