| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.38.0" |
| 456 | 456 | #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" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -870,11 +870,11 @@ |
| 870 | 870 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 871 | 871 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 872 | 872 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 873 | 873 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 874 | 874 | #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 */ |
| 876 | 876 | |
| 877 | 877 | /* |
| 878 | 878 | ** CAPI3REF: Flags For File Open Operations |
| 879 | 879 | ** |
| 880 | 880 | ** These bit values are intended for use in the |
| | @@ -4154,11 +4154,11 @@ |
| 4154 | 4154 | ** |
| 4155 | 4155 | ** ^If the most recent error references a specific token in the input |
| 4156 | 4156 | ** SQL, the sqlite3_error_offset() interface returns the byte offset |
| 4157 | 4157 | ** of the start of that token. ^The byte offset returned by |
| 4158 | 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 |
| 4159 | +** ^If the most recent error does not reference a specific token in the input |
| 4160 | 4160 | ** SQL, then the sqlite3_error_offset() function returns -1. |
| 4161 | 4161 | ** |
| 4162 | 4162 | ** When the serialized [threading mode] is in use, it might be the |
| 4163 | 4163 | ** case that a second error occurs on a separate thread in between |
| 4164 | 4164 | ** the time of the first error and the call to these interfaces. |
| | @@ -7515,11 +7515,11 @@ |
| 7515 | 7515 | ** ^The sqlite3_create_module() |
| 7516 | 7516 | ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
| 7517 | 7517 | ** destructor. |
| 7518 | 7518 | ** |
| 7519 | 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 |
| 7520 | +** NULL then no new module is created and any existing modules with the |
| 7521 | 7521 | ** same name are dropped. |
| 7522 | 7522 | ** |
| 7523 | 7523 | ** See also: [sqlite3_drop_modules()] |
| 7524 | 7524 | */ |
| 7525 | 7525 | SQLITE_API int sqlite3_create_module( |
| | @@ -18081,11 +18081,14 @@ |
| 18081 | 18081 | ** TK_SELECT: 1st register of result vector */ |
| 18082 | 18082 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 18083 | 18083 | ** TK_VARIABLE: variable number (always >= 1). |
| 18084 | 18084 | ** TK_SELECT_COLUMN: column of the result vector */ |
| 18085 | 18085 | 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; |
| 18087 | 18090 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 18088 | 18091 | union { |
| 18089 | 18092 | Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL |
| 18090 | 18093 | ** for a column of an index on an expression */ |
| 18091 | 18094 | Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */ |
| | @@ -20249,10 +20252,11 @@ |
| 20249 | 20252 | SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 20250 | 20253 | SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 20251 | 20254 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 20252 | 20255 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| 20253 | 20256 | SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*); |
| 20257 | +SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*); |
| 20254 | 20258 | |
| 20255 | 20259 | SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); |
| 20256 | 20260 | SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); |
| 20257 | 20261 | |
| 20258 | 20262 | #ifndef SQLITE_OMIT_SUBQUERY |
| | @@ -23584,71 +23588,60 @@ |
| 23584 | 23588 | #endif /* SQLITE_OMIT_LOCALTIME */ |
| 23585 | 23589 | |
| 23586 | 23590 | |
| 23587 | 23591 | #ifndef SQLITE_OMIT_LOCALTIME |
| 23588 | 23592 | /* |
| 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. |
| 23595 | 23594 | */ |
| 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 */ |
| 23600 | 23598 | ){ |
| 23601 | | - DateTime x, y; |
| 23602 | 23599 | time_t t; |
| 23603 | 23600 | struct tm sLocal; |
| 23601 | + int iYearDiff; |
| 23604 | 23602 | |
| 23605 | 23603 | /* Initialize the contents of sLocal to avoid a compiler warning. */ |
| 23606 | 23604 | memset(&sLocal, 0, sizeof(sLocal)); |
| 23607 | 23605 | |
| 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 | + ){ |
| 23611 | 23610 | /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only |
| 23612 | 23611 | ** works for years between 1970 and 2037. For dates outside this range, |
| 23613 | 23612 | ** SQLite attempts to map the year into an equivalent year within this |
| 23614 | 23613 | ** range, do the calculation, then map the year back. |
| 23615 | 23614 | */ |
| 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 | + } |
| 23630 | 23626 | if( osLocaltime(&t, &sLocal) ){ |
| 23631 | 23627 | 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; |
| 23650 | 23643 | } |
| 23651 | 23644 | #endif /* SQLITE_OMIT_LOCALTIME */ |
| 23652 | 23645 | |
| 23653 | 23646 | /* |
| 23654 | 23647 | ** The following table defines various date transformations of the form |
| | @@ -23753,13 +23746,11 @@ |
| 23753 | 23746 | ** |
| 23754 | 23747 | ** Assuming the current time value is UTC (a.k.a. GMT), shift it to |
| 23755 | 23748 | ** show local time. |
| 23756 | 23749 | */ |
| 23757 | 23750 | 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); |
| 23761 | 23752 | } |
| 23762 | 23753 | break; |
| 23763 | 23754 | } |
| 23764 | 23755 | #endif |
| 23765 | 23756 | case 'u': { |
| | @@ -23781,22 +23772,35 @@ |
| 23781 | 23772 | } |
| 23782 | 23773 | } |
| 23783 | 23774 | #ifndef SQLITE_OMIT_LOCALTIME |
| 23784 | 23775 | else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ |
| 23785 | 23776 | 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 | + |
| 23787 | 23782 | 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; |
| 23794 | 23799 | p->tzSet = 1; |
| 23795 | | - }else{ |
| 23796 | | - rc = SQLITE_OK; |
| 23797 | 23800 | } |
| 23801 | + rc = SQLITE_OK; |
| 23798 | 23802 | } |
| 23799 | 23803 | #endif |
| 23800 | 23804 | break; |
| 23801 | 23805 | } |
| 23802 | 23806 | case 'w': { |
| | @@ -24042,15 +24046,42 @@ |
| 24042 | 24046 | int argc, |
| 24043 | 24047 | sqlite3_value **argv |
| 24044 | 24048 | ){ |
| 24045 | 24049 | DateTime x; |
| 24046 | 24050 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24047 | | - char zBuf[100]; |
| 24051 | + int Y, s; |
| 24052 | + char zBuf[24]; |
| 24048 | 24053 | 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 | + } |
| 24052 | 24083 | } |
| 24053 | 24084 | } |
| 24054 | 24085 | |
| 24055 | 24086 | /* |
| 24056 | 24087 | ** time( TIMESTRING, MOD, MOD, ...) |
| | @@ -24062,14 +24093,24 @@ |
| 24062 | 24093 | int argc, |
| 24063 | 24094 | sqlite3_value **argv |
| 24064 | 24095 | ){ |
| 24065 | 24096 | DateTime x; |
| 24066 | 24097 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24067 | | - char zBuf[100]; |
| 24098 | + int s; |
| 24099 | + char zBuf[16]; |
| 24068 | 24100 | 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); |
| 24071 | 24112 | } |
| 24072 | 24113 | } |
| 24073 | 24114 | |
| 24074 | 24115 | /* |
| 24075 | 24116 | ** date( TIMESTRING, MOD, MOD, ...) |
| | @@ -24081,14 +24122,32 @@ |
| 24081 | 24122 | int argc, |
| 24082 | 24123 | sqlite3_value **argv |
| 24083 | 24124 | ){ |
| 24084 | 24125 | DateTime x; |
| 24085 | 24126 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24086 | | - char zBuf[100]; |
| 24127 | + int Y; |
| 24128 | + char zBuf[16]; |
| 24087 | 24129 | 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 | + } |
| 24090 | 24149 | } |
| 24091 | 24150 | } |
| 24092 | 24151 | |
| 24093 | 24152 | /* |
| 24094 | 24153 | ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...) |
| | @@ -30181,17 +30240,26 @@ |
| 30181 | 30240 | bufpt[j] = 0; |
| 30182 | 30241 | length = j; |
| 30183 | 30242 | goto adjust_width_for_utf8; |
| 30184 | 30243 | } |
| 30185 | 30244 | case etTOKEN: { |
| 30186 | | - Token *pToken; |
| 30187 | 30245 | 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 | + } |
| 30193 | 30261 | } |
| 30194 | 30262 | length = width = 0; |
| 30195 | 30263 | break; |
| 30196 | 30264 | } |
| 30197 | 30265 | case etSRCITEM: { |
| | @@ -30265,10 +30333,22 @@ |
| 30265 | 30333 | zEnd = &zText[strlen(zText)]; |
| 30266 | 30334 | if( SQLITE_WITHIN(z,zText,zEnd) ){ |
| 30267 | 30335 | db->errByteOffset = (int)(z-zText); |
| 30268 | 30336 | } |
| 30269 | 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 | +} |
| 30270 | 30350 | |
| 30271 | 30351 | /* |
| 30272 | 30352 | ** Enlarge the memory allocation on a StrAccum object so that it is |
| 30273 | 30353 | ** able to accept at least N more bytes of text. |
| 30274 | 30354 | ** |
| | @@ -31107,11 +31187,11 @@ |
| 31107 | 31187 | StrAccum x; |
| 31108 | 31188 | sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 31109 | 31189 | sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 31110 | 31190 | pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
| 31111 | 31191 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 31112 | | - sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); |
| 31192 | + sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable); |
| 31113 | 31193 | } |
| 31114 | 31194 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 31115 | 31195 | sqlite3_str_appendf(&x, " DDL"); |
| 31116 | 31196 | } |
| 31117 | 31197 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| | @@ -57586,10 +57666,16 @@ |
| 57586 | 57666 | PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno)); |
| 57587 | 57667 | rc = write32bits(pPager->sjfd, offset, pPg->pgno); |
| 57588 | 57668 | if( rc==SQLITE_OK ){ |
| 57589 | 57669 | rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4); |
| 57590 | 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 | + } |
| 57591 | 57677 | } |
| 57592 | 57678 | } |
| 57593 | 57679 | if( rc==SQLITE_OK ){ |
| 57594 | 57680 | pPager->nSubRec++; |
| 57595 | 57681 | assert( pPager->nSavepoint>0 ); |
| | @@ -60514,10 +60600,22 @@ |
| 60514 | 60600 | int eMode, /* Type of checkpoint */ |
| 60515 | 60601 | int *pnLog, /* OUT: Final number of frames in log */ |
| 60516 | 60602 | int *pnCkpt /* OUT: Final number of checkpointed frames */ |
| 60517 | 60603 | ){ |
| 60518 | 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 | + } |
| 60519 | 60617 | if( pPager->pWal ){ |
| 60520 | 60618 | rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, |
| 60521 | 60619 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 60522 | 60620 | pPager->pBusyHandlerArg, |
| 60523 | 60621 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| | @@ -82890,10 +82988,11 @@ |
| 82890 | 82988 | db->bBenignMalloc--; |
| 82891 | 82989 | }else if( db->pErr ){ |
| 82892 | 82990 | sqlite3ValueSetNull(db->pErr); |
| 82893 | 82991 | } |
| 82894 | 82992 | db->errCode = rc; |
| 82993 | + db->errByteOffset = -1; |
| 82895 | 82994 | return rc; |
| 82896 | 82995 | } |
| 82897 | 82996 | |
| 82898 | 82997 | #ifdef SQLITE_ENABLE_SQLLOG |
| 82899 | 82998 | /* |
| | @@ -86496,11 +86595,11 @@ |
| 86496 | 86595 | case SQLITE_INTEGER: { |
| 86497 | 86596 | rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); |
| 86498 | 86597 | break; |
| 86499 | 86598 | } |
| 86500 | 86599 | case SQLITE_FLOAT: { |
| 86501 | | - rc = sqlite3_bind_double(pStmt, i, pValue->u.r); |
| 86600 | + rc = sqlite3_bind_double(pStmt, i, sqlite3VdbeRealValue((Mem*)pValue)); |
| 86502 | 86601 | break; |
| 86503 | 86602 | } |
| 86504 | 86603 | case SQLITE_BLOB: { |
| 86505 | 86604 | if( pValue->flags & MEM_Zero ){ |
| 86506 | 86605 | rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero); |
| | @@ -100865,10 +100964,11 @@ |
| 100865 | 100964 | }else if( zTab ){ |
| 100866 | 100965 | sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); |
| 100867 | 100966 | }else{ |
| 100868 | 100967 | sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); |
| 100869 | 100968 | } |
| 100969 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 100870 | 100970 | pParse->checkSchema = 1; |
| 100871 | 100971 | pTopNC->nNcErr++; |
| 100872 | 100972 | } |
| 100873 | 100973 | |
| 100874 | 100974 | /* If a column from a table in pSrcList is referenced, then record |
| | @@ -100973,11 +101073,12 @@ |
| 100973 | 101073 | */ |
| 100974 | 101074 | static void notValidImpl( |
| 100975 | 101075 | Parse *pParse, /* Leave error message here */ |
| 100976 | 101076 | NameContext *pNC, /* The name context */ |
| 100977 | 101077 | 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 */ |
| 100979 | 101080 | ){ |
| 100980 | 101081 | const char *zIn = "partial index WHERE clauses"; |
| 100981 | 101082 | if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions"; |
| 100982 | 101083 | #ifndef SQLITE_OMIT_CHECK |
| 100983 | 101084 | else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints"; |
| | @@ -100985,14 +101086,15 @@ |
| 100985 | 101086 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 100986 | 101087 | else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns"; |
| 100987 | 101088 | #endif |
| 100988 | 101089 | sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn); |
| 100989 | 101090 | if( pExpr ) pExpr->op = TK_NULL; |
| 101091 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); |
| 100990 | 101092 | } |
| 100991 | | -#define sqlite3ResolveNotValid(P,N,M,X,E) \ |
| 101093 | +#define sqlite3ResolveNotValid(P,N,M,X,E,R) \ |
| 100992 | 101094 | 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); |
| 100994 | 101096 | |
| 100995 | 101097 | /* |
| 100996 | 101098 | ** Expression p should encode a floating point value between 1.0 and 0.0. |
| 100997 | 101099 | ** Return 1024 times this value. Or return -1 if p is not a floating point |
| 100998 | 101100 | ** value between 1.0 and 0.0. |
| | @@ -101123,11 +101225,11 @@ |
| 101123 | 101225 | }else{ |
| 101124 | 101226 | Expr *pLeft = pExpr->pLeft; |
| 101125 | 101227 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 101126 | 101228 | testcase( pNC->ncFlags & NC_GenCol ); |
| 101127 | 101229 | sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator", |
| 101128 | | - NC_IdxExpr|NC_GenCol, 0); |
| 101230 | + NC_IdxExpr|NC_GenCol, 0, pExpr); |
| 101129 | 101231 | pRight = pExpr->pRight; |
| 101130 | 101232 | if( pRight->op==TK_ID ){ |
| 101131 | 101233 | zDb = 0; |
| 101132 | 101234 | }else{ |
| 101133 | 101235 | assert( pRight->op==TK_DOT ); |
| | @@ -101154,21 +101256,19 @@ |
| 101154 | 101256 | ExprList *pList = pExpr->x.pList; /* The argument list */ |
| 101155 | 101257 | int n = pList ? pList->nExpr : 0; /* Number of arguments */ |
| 101156 | 101258 | int no_such_func = 0; /* True if no such function exists */ |
| 101157 | 101259 | int wrong_num_args = 0; /* True if wrong number of arguments */ |
| 101158 | 101260 | int is_agg = 0; /* True if is an aggregate function */ |
| 101159 | | - int nId; /* Number of characters in function name */ |
| 101160 | 101261 | const char *zId; /* The function name. */ |
| 101161 | 101262 | FuncDef *pDef; /* Information about the function */ |
| 101162 | 101263 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 101163 | 101264 | int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin)); |
| 101164 | 101265 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 101165 | 101266 | Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0); |
| 101166 | 101267 | #endif |
| 101167 | 101268 | assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 101168 | 101269 | zId = pExpr->u.zToken; |
| 101169 | | - nId = sqlite3Strlen30(zId); |
| 101170 | 101270 | pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); |
| 101171 | 101271 | if( pDef==0 ){ |
| 101172 | 101272 | pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); |
| 101173 | 101273 | if( pDef==0 ){ |
| 101174 | 101274 | no_such_func = 1; |
| | @@ -101181,12 +101281,12 @@ |
| 101181 | 101281 | ExprSetProperty(pExpr, EP_Unlikely); |
| 101182 | 101282 | if( n==2 ){ |
| 101183 | 101283 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 101184 | 101284 | if( pExpr->iTable<0 ){ |
| 101185 | 101285 | 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); |
| 101188 | 101288 | pNC->nNcErr++; |
| 101189 | 101289 | } |
| 101190 | 101290 | }else{ |
| 101191 | 101291 | /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is |
| 101192 | 101292 | ** equivalent to likelihood(X, 0.0625). |
| | @@ -101203,12 +101303,12 @@ |
| 101203 | 101303 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 101204 | 101304 | { |
| 101205 | 101305 | int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0); |
| 101206 | 101306 | if( auth!=SQLITE_OK ){ |
| 101207 | 101307 | 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); |
| 101210 | 101310 | pNC->nNcErr++; |
| 101211 | 101311 | } |
| 101212 | 101312 | pExpr->op = TK_NULL; |
| 101213 | 101313 | return WRC_Prune; |
| 101214 | 101314 | } |
| | @@ -101227,11 +101327,11 @@ |
| 101227 | 101327 | ** sqlite_version() that might change over time cannot be used |
| 101228 | 101328 | ** in an index or generated column. Curiously, they can be used |
| 101229 | 101329 | ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all |
| 101230 | 101330 | ** all this. */ |
| 101231 | 101331 | sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions", |
| 101232 | | - NC_IdxExpr|NC_PartIdx|NC_GenCol, 0); |
| 101332 | + NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr); |
| 101233 | 101333 | }else{ |
| 101234 | 101334 | assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */ |
| 101235 | 101335 | pExpr->op2 = pNC->ncFlags & NC_SelfRef; |
| 101236 | 101336 | if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL); |
| 101237 | 101337 | } |
| | @@ -101259,11 +101359,11 @@ |
| 101259 | 101359 | || (pDef->xValue==0 && pDef->xInverse==0) |
| 101260 | 101360 | || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize) |
| 101261 | 101361 | ); |
| 101262 | 101362 | if( pDef && pDef->xValue==0 && pWin ){ |
| 101263 | 101363 | 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 |
| 101265 | 101365 | ); |
| 101266 | 101366 | pNC->nNcErr++; |
| 101267 | 101367 | }else if( |
| 101268 | 101368 | (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) |
| 101269 | 101369 | || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin) |
| | @@ -101273,38 +101373,38 @@ |
| 101273 | 101373 | if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){ |
| 101274 | 101374 | zType = "window"; |
| 101275 | 101375 | }else{ |
| 101276 | 101376 | zType = "aggregate"; |
| 101277 | 101377 | } |
| 101278 | | - sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId); |
| 101378 | + sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr); |
| 101279 | 101379 | pNC->nNcErr++; |
| 101280 | 101380 | is_agg = 0; |
| 101281 | 101381 | } |
| 101282 | 101382 | #else |
| 101283 | 101383 | 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); |
| 101285 | 101385 | pNC->nNcErr++; |
| 101286 | 101386 | is_agg = 0; |
| 101287 | 101387 | } |
| 101288 | 101388 | #endif |
| 101289 | 101389 | else if( no_such_func && pParse->db->init.busy==0 |
| 101290 | 101390 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 101291 | 101391 | && pParse->explain==0 |
| 101292 | 101392 | #endif |
| 101293 | 101393 | ){ |
| 101294 | | - sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); |
| 101394 | + sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); |
| 101295 | 101395 | pNC->nNcErr++; |
| 101296 | 101396 | }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); |
| 101299 | 101399 | pNC->nNcErr++; |
| 101300 | 101400 | } |
| 101301 | 101401 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 101302 | 101402 | else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 101303 | 101403 | 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 |
| 101306 | 101406 | ); |
| 101307 | 101407 | pNC->nNcErr++; |
| 101308 | 101408 | } |
| 101309 | 101409 | #endif |
| 101310 | 101410 | if( is_agg ){ |
| | @@ -101385,11 +101485,11 @@ |
| 101385 | 101485 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 101386 | 101486 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 101387 | 101487 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 101388 | 101488 | testcase( pNC->ncFlags & NC_GenCol ); |
| 101389 | 101489 | if( pNC->ncFlags & NC_SelfRef ){ |
| 101390 | | - notValidImpl(pParse, pNC, "subqueries", pExpr); |
| 101490 | + notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); |
| 101391 | 101491 | }else{ |
| 101392 | 101492 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 101393 | 101493 | } |
| 101394 | 101494 | assert( pNC->nRef>=nRef ); |
| 101395 | 101495 | if( nRef!=pNC->nRef ){ |
| | @@ -101403,11 +101503,11 @@ |
| 101403 | 101503 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 101404 | 101504 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 101405 | 101505 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 101406 | 101506 | testcase( pNC->ncFlags & NC_GenCol ); |
| 101407 | 101507 | 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); |
| 101409 | 101509 | break; |
| 101410 | 101510 | } |
| 101411 | 101511 | case TK_IS: |
| 101412 | 101512 | case TK_ISNOT: { |
| 101413 | 101513 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| | @@ -101455,10 +101555,11 @@ |
| 101455 | 101555 | testcase( pExpr->op==TK_GE ); |
| 101456 | 101556 | testcase( pExpr->op==TK_IS ); |
| 101457 | 101557 | testcase( pExpr->op==TK_ISNOT ); |
| 101458 | 101558 | testcase( pExpr->op==TK_BETWEEN ); |
| 101459 | 101559 | sqlite3ErrorMsg(pParse, "row value misused"); |
| 101560 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 101460 | 101561 | } |
| 101461 | 101562 | break; |
| 101462 | 101563 | } |
| 101463 | 101564 | } |
| 101464 | 101565 | assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); |
| | @@ -101568,15 +101669,17 @@ |
| 101568 | 101669 | */ |
| 101569 | 101670 | static void resolveOutOfRangeError( |
| 101570 | 101671 | Parse *pParse, /* The error context into which to write the error */ |
| 101571 | 101672 | const char *zType, /* "ORDER" or "GROUP" */ |
| 101572 | 101673 | 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 */ |
| 101574 | 101676 | ){ |
| 101575 | 101677 | sqlite3ErrorMsg(pParse, |
| 101576 | 101678 | "%r %s BY term out of range - should be " |
| 101577 | 101679 | "between 1 and %d", i, zType, mx); |
| 101680 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); |
| 101578 | 101681 | } |
| 101579 | 101682 | |
| 101580 | 101683 | /* |
| 101581 | 101684 | ** Analyze the ORDER BY clause in a compound SELECT statement. Modify |
| 101582 | 101685 | ** each term of the ORDER BY clause is a constant integer between 1 |
| | @@ -101628,11 +101731,11 @@ |
| 101628 | 101731 | if( pItem->done ) continue; |
| 101629 | 101732 | pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr); |
| 101630 | 101733 | if( NEVER(pE==0) ) continue; |
| 101631 | 101734 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 101632 | 101735 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 101633 | | - resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); |
| 101736 | + resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE); |
| 101634 | 101737 | return 1; |
| 101635 | 101738 | } |
| 101636 | 101739 | }else{ |
| 101637 | 101740 | iCol = resolveAsName(pParse, pEList, pE); |
| 101638 | 101741 | if( iCol==0 ){ |
| | @@ -101724,11 +101827,11 @@ |
| 101724 | 101827 | pEList = pSelect->pEList; |
| 101725 | 101828 | assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */ |
| 101726 | 101829 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 101727 | 101830 | if( pItem->u.x.iOrderByCol ){ |
| 101728 | 101831 | if( pItem->u.x.iOrderByCol>pEList->nExpr ){ |
| 101729 | | - resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr); |
| 101832 | + resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0); |
| 101730 | 101833 | return 1; |
| 101731 | 101834 | } |
| 101732 | 101835 | resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0); |
| 101733 | 101836 | } |
| 101734 | 101837 | } |
| | @@ -101816,11 +101919,11 @@ |
| 101816 | 101919 | if( sqlite3ExprIsInteger(pE2, &iCol) ){ |
| 101817 | 101920 | /* The ORDER BY term is an integer constant. Again, set the column |
| 101818 | 101921 | ** number so that sqlite3ResolveOrderGroupBy() will convert the |
| 101819 | 101922 | ** order-by term to a copy of the result-set expression */ |
| 101820 | 101923 | if( iCol<1 || iCol>0xffff ){ |
| 101821 | | - resolveOutOfRangeError(pParse, zType, i+1, nResult); |
| 101924 | + resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2); |
| 101822 | 101925 | return 1; |
| 101823 | 101926 | } |
| 101824 | 101927 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 101825 | 101928 | continue; |
| 101826 | 101929 | } |
| | @@ -103069,13 +103172,12 @@ |
| 103069 | 103172 | ** |
| 103070 | 103173 | ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags, |
| 103071 | 103174 | ** if appropriate. |
| 103072 | 103175 | */ |
| 103073 | 103176 | 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; |
| 103077 | 103179 | if( ExprUseXSelect(p) ){ |
| 103078 | 103180 | heightOfSelect(p->x.pSelect, &nHeight); |
| 103079 | 103181 | }else if( p->x.pList ){ |
| 103080 | 103182 | heightOfExprList(p->x.pList, &nHeight); |
| 103081 | 103183 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| | @@ -103370,10 +103472,11 @@ |
| 103370 | 103472 | pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1); |
| 103371 | 103473 | if( pNew==0 ){ |
| 103372 | 103474 | sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */ |
| 103373 | 103475 | return 0; |
| 103374 | 103476 | } |
| 103477 | + pNew->w.iOfst = (int)(pToken->z - pParse->zTail); |
| 103375 | 103478 | if( pList |
| 103376 | 103479 | && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] |
| 103377 | 103480 | && !pParse->nested |
| 103378 | 103481 | ){ |
| 103379 | 103482 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); |
| | @@ -103413,11 +103516,11 @@ |
| 103413 | 103516 | ** (2) not tagged with SQLITE_INNOCUOUS (which means it |
| 103414 | 103517 | ** is tagged with SQLITE_FUNC_UNSAFE) and |
| 103415 | 103518 | ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning |
| 103416 | 103519 | ** that the schema is possibly tainted). |
| 103417 | 103520 | */ |
| 103418 | | - sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName); |
| 103521 | + sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr); |
| 103419 | 103522 | } |
| 103420 | 103523 | } |
| 103421 | 103524 | } |
| 103422 | 103525 | |
| 103423 | 103526 | /* |
| | @@ -103469,10 +103572,11 @@ |
| 103469 | 103572 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 103470 | 103573 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 103471 | 103574 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 103472 | 103575 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 103473 | 103576 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 103577 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 103474 | 103578 | return; |
| 103475 | 103579 | } |
| 103476 | 103580 | x = (ynVar)i; |
| 103477 | 103581 | if( x>pParse->nVar ){ |
| 103478 | 103582 | pParse->nVar = (int)x; |
| | @@ -103496,10 +103600,11 @@ |
| 103496 | 103600 | } |
| 103497 | 103601 | } |
| 103498 | 103602 | pExpr->iColumn = x; |
| 103499 | 103603 | if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 103500 | 103604 | sqlite3ErrorMsg(pParse, "too many SQL variables"); |
| 103605 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 103501 | 103606 | } |
| 103502 | 103607 | } |
| 103503 | 103608 | |
| 103504 | 103609 | /* |
| 103505 | 103610 | ** Recursively delete an expression tree. |
| | @@ -105937,15 +106042,16 @@ |
| 105937 | 106042 | const char *z = pExpr->u.zToken; |
| 105938 | 106043 | assert( z!=0 ); |
| 105939 | 106044 | c = sqlite3DecOrHexToI64(z, &value); |
| 105940 | 106045 | if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){ |
| 105941 | 106046 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 105942 | | - sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| 106047 | + sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr); |
| 105943 | 106048 | #else |
| 105944 | 106049 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 105945 | 106050 | 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); |
| 105947 | 106053 | }else |
| 105948 | 106054 | #endif |
| 105949 | 106055 | { |
| 105950 | 106056 | codeReal(v, z, negFlag, iMem); |
| 105951 | 106057 | } |
| | @@ -106617,11 +106723,11 @@ |
| 106617 | 106723 | if( pInfo==0 |
| 106618 | 106724 | || NEVER(pExpr->iAgg<0) |
| 106619 | 106725 | || NEVER(pExpr->iAgg>=pInfo->nFunc) |
| 106620 | 106726 | ){ |
| 106621 | 106727 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 106622 | | - sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken); |
| 106728 | + sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr); |
| 106623 | 106729 | }else{ |
| 106624 | 106730 | return pInfo->aFunc[pExpr->iAgg].iMem; |
| 106625 | 106731 | } |
| 106626 | 106732 | break; |
| 106627 | 106733 | } |
| | @@ -106658,11 +106764,11 @@ |
| 106658 | 106764 | if( pDef==0 && pParse->explain ){ |
| 106659 | 106765 | pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0); |
| 106660 | 106766 | } |
| 106661 | 106767 | #endif |
| 106662 | 106768 | if( pDef==0 || pDef->xFinalize!=0 ){ |
| 106663 | | - sqlite3ErrorMsg(pParse, "unknown function: %s()", zId); |
| 106769 | + sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr); |
| 106664 | 106770 | break; |
| 106665 | 106771 | } |
| 106666 | 106772 | if( pDef->funcFlags & SQLITE_FUNC_INLINE ){ |
| 106667 | 106773 | assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 ); |
| 106668 | 106774 | assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 ); |
| | @@ -109281,11 +109387,11 @@ |
| 109281 | 109387 | if( !zOld ) goto exit_rename_column; |
| 109282 | 109388 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 109283 | 109389 | if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break; |
| 109284 | 109390 | } |
| 109285 | 109391 | if( iCol==pTab->nCol ){ |
| 109286 | | - sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); |
| 109392 | + sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld); |
| 109287 | 109393 | goto exit_rename_column; |
| 109288 | 109394 | } |
| 109289 | 109395 | |
| 109290 | 109396 | /* Ensure the schema contains no double-quoted strings */ |
| 109291 | 109397 | renameTestSchema(pParse, zDb, iSchema==1, "", 0); |
| | @@ -109711,16 +109817,16 @@ |
| 109711 | 109817 | ){ |
| 109712 | 109818 | const char *zT = (const char*)sqlite3_value_text(pType); |
| 109713 | 109819 | const char *zN = (const char*)sqlite3_value_text(pObject); |
| 109714 | 109820 | char *zErr; |
| 109715 | 109821 | |
| 109716 | | - zErr = sqlite3_mprintf("error in %s %s%s%s: %s", |
| 109822 | + zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s", |
| 109717 | 109823 | zT, zN, (zWhen[0] ? " " : ""), zWhen, |
| 109718 | 109824 | pParse->zErrMsg |
| 109719 | 109825 | ); |
| 109720 | 109826 | sqlite3_result_error(pCtx, zErr, -1); |
| 109721 | | - sqlite3_free(zErr); |
| 109827 | + sqlite3DbFree(pParse->db, zErr); |
| 109722 | 109828 | } |
| 109723 | 109829 | |
| 109724 | 109830 | /* |
| 109725 | 109831 | ** For each name in the the expression-list pEList (i.e. each |
| 109726 | 109832 | ** pEList->a[i].zName) that matches the string in zOld, extract the |
| | @@ -110077,11 +110183,11 @@ |
| 110077 | 110183 | } |
| 110078 | 110184 | |
| 110079 | 110185 | /* |
| 110080 | 110186 | ** SQL function: |
| 110081 | 110187 | ** |
| 110082 | | -** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld) |
| 110188 | +** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP) |
| 110083 | 110189 | ** |
| 110084 | 110190 | ** 0. zSql: SQL statement to rewrite |
| 110085 | 110191 | ** 1. type: Type of object ("table", "view" etc.) |
| 110086 | 110192 | ** 2. object: Name of object |
| 110087 | 110193 | ** 3. Database: Database name (e.g. "main") |
| | @@ -110095,11 +110201,12 @@ |
| 110095 | 110201 | ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol |
| 110096 | 110202 | ** into zNew. The name should be quoted if bQuote is true. |
| 110097 | 110203 | ** |
| 110098 | 110204 | ** This function is used internally by the ALTER TABLE RENAME COLUMN command. |
| 110099 | 110205 | ** 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. |
| 110101 | 110208 | */ |
| 110102 | 110209 | static void renameColumnFunc( |
| 110103 | 110210 | sqlite3_context *context, |
| 110104 | 110211 | int NotUsed, |
| 110105 | 110212 | sqlite3_value **argv |
| | @@ -110244,11 +110351,13 @@ |
| 110244 | 110351 | assert( rc==SQLITE_OK ); |
| 110245 | 110352 | rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote); |
| 110246 | 110353 | |
| 110247 | 110354 | renameColumnFunc_done: |
| 110248 | 110355 | 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 ){ |
| 110250 | 110359 | renameColumnParseError(context, "", argv[1], argv[2], &sParse); |
| 110251 | 110360 | }else{ |
| 110252 | 110361 | sqlite3_result_error_code(context, rc); |
| 110253 | 110362 | } |
| 110254 | 110363 | } |
| | @@ -110443,11 +110552,13 @@ |
| 110443 | 110552 | |
| 110444 | 110553 | if( rc==SQLITE_OK ){ |
| 110445 | 110554 | rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote); |
| 110446 | 110555 | } |
| 110447 | 110556 | 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 ){ |
| 110449 | 110560 | renameColumnParseError(context, "", argv[1], argv[2], &sParse); |
| 110450 | 110561 | }else{ |
| 110451 | 110562 | sqlite3_result_error_code(context, rc); |
| 110452 | 110563 | } |
| 110453 | 110564 | } |
| | @@ -110468,14 +110579,14 @@ |
| 110468 | 110579 | renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr); |
| 110469 | 110580 | } |
| 110470 | 110581 | return WRC_Continue; |
| 110471 | 110582 | } |
| 110472 | 110583 | |
| 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. |
| 110477 | 110588 | ** |
| 110478 | 110589 | ** Two arguments must be passed: |
| 110479 | 110590 | ** |
| 110480 | 110591 | ** 0: Database name ("main", "temp" etc.). |
| 110481 | 110592 | ** 1: SQL statement to edit. |
| | @@ -110490,10 +110601,14 @@ |
| 110490 | 110601 | ** ); |
| 110491 | 110602 | ** |
| 110492 | 110603 | ** returns the string: |
| 110493 | 110604 | ** |
| 110494 | 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. |
| 110495 | 110610 | */ |
| 110496 | 110611 | static void renameQuotefixFunc( |
| 110497 | 110612 | sqlite3_context *context, |
| 110498 | 110613 | int NotUsed, |
| 110499 | 110614 | sqlite3_value **argv |
| | @@ -110564,11 +110679,15 @@ |
| 110564 | 110679 | rc = renameEditSql(context, &sCtx, zInput, 0, 0); |
| 110565 | 110680 | } |
| 110566 | 110681 | renameTokenFree(db, sCtx.pList); |
| 110567 | 110682 | } |
| 110568 | 110683 | 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 | + } |
| 110570 | 110689 | } |
| 110571 | 110690 | renameParseCleanup(&sParse); |
| 110572 | 110691 | } |
| 110573 | 110692 | |
| 110574 | 110693 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -110576,11 +110695,12 @@ |
| 110576 | 110695 | #endif |
| 110577 | 110696 | |
| 110578 | 110697 | sqlite3BtreeLeaveAll(db); |
| 110579 | 110698 | } |
| 110580 | 110699 | |
| 110581 | | -/* |
| 110700 | +/* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS) |
| 110701 | +** |
| 110582 | 110702 | ** An SQL user function that checks that there are no parse or symbol |
| 110583 | 110703 | ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement. |
| 110584 | 110704 | ** After an ALTER TABLE .. RENAME operation is performed and the schema |
| 110585 | 110705 | ** reloaded, this function is called on each SQL statement in the schema |
| 110586 | 110706 | ** to ensure that it is still usable. |
| | @@ -110591,15 +110711,17 @@ |
| 110591 | 110711 | ** 3: Object name. |
| 110592 | 110712 | ** 4: True if object is from temp schema. |
| 110593 | 110713 | ** 5: "when" part of error message. |
| 110594 | 110714 | ** 6: True to disable the DQS quirk when parsing SQL. |
| 110595 | 110715 | ** |
| 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: |
| 110598 | 110717 | ** |
| 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. |
| 110601 | 110723 | */ |
| 110602 | 110724 | static void renameTableTest( |
| 110603 | 110725 | sqlite3_context *context, |
| 110604 | 110726 | int NotUsed, |
| 110605 | 110727 | sqlite3_value **argv |
| | @@ -110640,16 +110762,20 @@ |
| 110640 | 110762 | rc = renameResolveTrigger(&sParse); |
| 110641 | 110763 | } |
| 110642 | 110764 | if( rc==SQLITE_OK ){ |
| 110643 | 110765 | int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema); |
| 110644 | 110766 | 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 | + } |
| 110646 | 110771 | } |
| 110647 | 110772 | } |
| 110648 | 110773 | } |
| 110649 | 110774 | |
| 110650 | | - if( rc!=SQLITE_OK && zWhen ){ |
| 110775 | + if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){ |
| 110776 | + /* Output case A */ |
| 110651 | 110777 | renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse); |
| 110652 | 110778 | } |
| 110653 | 110779 | renameParseCleanup(&sParse); |
| 110654 | 110780 | } |
| 110655 | 110781 | |
| | @@ -110761,11 +110887,11 @@ |
| 110761 | 110887 | assert( db->mallocFailed ); |
| 110762 | 110888 | goto exit_drop_column; |
| 110763 | 110889 | } |
| 110764 | 110890 | iCol = sqlite3ColumnIndex(pTab, zCol); |
| 110765 | 110891 | if( iCol<0 ){ |
| 110766 | | - sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol); |
| 110892 | + sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName); |
| 110767 | 110893 | goto exit_drop_column; |
| 110768 | 110894 | } |
| 110769 | 110895 | |
| 110770 | 110896 | /* Do not allow the user to drop a PRIMARY KEY column or a column |
| 110771 | 110897 | ** constrained by a UNIQUE constraint. */ |
| | @@ -114989,11 +115115,12 @@ |
| 114989 | 115115 | goto begin_table_error; |
| 114990 | 115116 | } |
| 114991 | 115117 | pTable = sqlite3FindTable(db, zName, zDb); |
| 114992 | 115118 | if( pTable ){ |
| 114993 | 115119 | if( !noErr ){ |
| 114994 | | - sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 115120 | + sqlite3ErrorMsg(pParse, "%s %T already exists", |
| 115121 | + (IsView(pTable)? "view" : "table"), pName); |
| 114995 | 115122 | }else{ |
| 114996 | 115123 | assert( !db->init.busy || CORRUPT_DB ); |
| 114997 | 115124 | sqlite3CodeVerifySchema(pParse, iDb); |
| 114998 | 115125 | sqlite3ForceNotReadOnly(pParse); |
| 114999 | 115126 | } |
| | @@ -134366,29 +134493,29 @@ |
| 134366 | 134493 | ** sqlite3PExpr(). */ |
| 134367 | 134494 | if( pEq && isOuterJoin ){ |
| 134368 | 134495 | ExprSetProperty(pEq, EP_FromJoin); |
| 134369 | 134496 | assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) ); |
| 134370 | 134497 | ExprSetVVAProperty(pEq, EP_NoReduce); |
| 134371 | | - pEq->iRightJoinTable = pE2->iTable; |
| 134498 | + pEq->w.iRightJoinTable = pE2->iTable; |
| 134372 | 134499 | } |
| 134373 | 134500 | *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq); |
| 134374 | 134501 | } |
| 134375 | 134502 | |
| 134376 | 134503 | /* |
| 134377 | 134504 | ** 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 |
| 134379 | 134506 | ** expression. |
| 134380 | 134507 | ** |
| 134381 | 134508 | ** The EP_FromJoin property is used on terms of an expression to tell |
| 134382 | 134509 | ** the LEFT OUTER JOIN processing logic that this term is part of the |
| 134383 | 134510 | ** join restriction specified in the ON or USING clause and not a part |
| 134384 | 134511 | ** of the more general WHERE clause. These terms are moved over to the |
| 134385 | 134512 | ** WHERE clause during join processing but we need to remember that they |
| 134386 | 134513 | ** originated in the ON or USING clause. |
| 134387 | 134514 | ** |
| 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 |
| 134390 | 134517 | ** explicitly mentioned in the expression. That information is needed |
| 134391 | 134518 | ** for cases like this: |
| 134392 | 134519 | ** |
| 134393 | 134520 | ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5 |
| 134394 | 134521 | ** |
| | @@ -134402,11 +134529,11 @@ |
| 134402 | 134529 | SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){ |
| 134403 | 134530 | while( p ){ |
| 134404 | 134531 | ExprSetProperty(p, EP_FromJoin); |
| 134405 | 134532 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 134406 | 134533 | ExprSetVVAProperty(p, EP_NoReduce); |
| 134407 | | - p->iRightJoinTable = iTable; |
| 134534 | + p->w.iRightJoinTable = iTable; |
| 134408 | 134535 | if( p->op==TK_FUNCTION ){ |
| 134409 | 134536 | assert( ExprUseXList(p) ); |
| 134410 | 134537 | if( p->x.pList ){ |
| 134411 | 134538 | int i; |
| 134412 | 134539 | for(i=0; i<p->x.pList->nExpr; i++){ |
| | @@ -134418,19 +134545,19 @@ |
| 134418 | 134545 | p = p->pRight; |
| 134419 | 134546 | } |
| 134420 | 134547 | } |
| 134421 | 134548 | |
| 134422 | 134549 | /* 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 |
| 134424 | 134551 | ** an ordinary term that omits the EP_FromJoin mark. |
| 134425 | 134552 | ** |
| 134426 | 134553 | ** This happens when a LEFT JOIN is simplified into an ordinary JOIN. |
| 134427 | 134554 | */ |
| 134428 | 134555 | static void unsetJoinExpr(Expr *p, int iTable){ |
| 134429 | 134556 | while( p ){ |
| 134430 | 134557 | if( ExprHasProperty(p, EP_FromJoin) |
| 134431 | | - && (iTable<0 || p->iRightJoinTable==iTable) ){ |
| 134558 | + && (iTable<0 || p->w.iRightJoinTable==iTable) ){ |
| 134432 | 134559 | ExprClearProperty(p, EP_FromJoin); |
| 134433 | 134560 | } |
| 134434 | 134561 | if( p->op==TK_COLUMN && p->iTable==iTable ){ |
| 134435 | 134562 | ExprClearProperty(p, EP_CanBeNull); |
| 134436 | 134563 | } |
| | @@ -137660,13 +137787,13 @@ |
| 137660 | 137787 | SubstContext *pSubst, /* Description of the substitution */ |
| 137661 | 137788 | Expr *pExpr /* Expr in which substitution occurs */ |
| 137662 | 137789 | ){ |
| 137663 | 137790 | if( pExpr==0 ) return 0; |
| 137664 | 137791 | if( ExprHasProperty(pExpr, EP_FromJoin) |
| 137665 | | - && pExpr->iRightJoinTable==pSubst->iTable |
| 137792 | + && pExpr->w.iRightJoinTable==pSubst->iTable |
| 137666 | 137793 | ){ |
| 137667 | | - pExpr->iRightJoinTable = pSubst->iNewTable; |
| 137794 | + pExpr->w.iRightJoinTable = pSubst->iNewTable; |
| 137668 | 137795 | } |
| 137669 | 137796 | if( pExpr->op==TK_COLUMN |
| 137670 | 137797 | && pExpr->iTable==pSubst->iTable |
| 137671 | 137798 | && !ExprHasProperty(pExpr, EP_FixedCol) |
| 137672 | 137799 | ){ |
| | @@ -137701,11 +137828,11 @@ |
| 137701 | 137828 | } |
| 137702 | 137829 | if( pSubst->isLeftJoin ){ |
| 137703 | 137830 | ExprSetProperty(pNew, EP_CanBeNull); |
| 137704 | 137831 | } |
| 137705 | 137832 | if( ExprHasProperty(pExpr,EP_FromJoin) ){ |
| 137706 | | - sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable); |
| 137833 | + sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable); |
| 137707 | 137834 | } |
| 137708 | 137835 | sqlite3ExprDelete(db, pExpr); |
| 137709 | 137836 | pExpr = pNew; |
| 137710 | 137837 | |
| 137711 | 137838 | /* Ensure that the expression now has an implicit collation sequence, |
| | @@ -137866,11 +137993,11 @@ |
| 137866 | 137993 | int op = pExpr->op; |
| 137867 | 137994 | if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){ |
| 137868 | 137995 | renumberCursorDoMapping(pWalker, &pExpr->iTable); |
| 137869 | 137996 | } |
| 137870 | 137997 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 137871 | | - renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable); |
| 137998 | + renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable); |
| 137872 | 137999 | } |
| 137873 | 138000 | return WRC_Continue; |
| 137874 | 138001 | } |
| 137875 | 138002 | |
| 137876 | 138003 | /* |
| | @@ -138876,15 +139003,17 @@ |
| 138876 | 139003 | iCursor, isLeftJoin); |
| 138877 | 139004 | pWhere = pWhere->pLeft; |
| 138878 | 139005 | } |
| 138879 | 139006 | if( isLeftJoin |
| 138880 | 139007 | && (ExprHasProperty(pWhere,EP_FromJoin)==0 |
| 138881 | | - || pWhere->iRightJoinTable!=iCursor) |
| 139008 | + || pWhere->w.iRightJoinTable!=iCursor) |
| 138882 | 139009 | ){ |
| 138883 | 139010 | return 0; /* restriction (4) */ |
| 138884 | 139011 | } |
| 138885 | | - if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){ |
| 139012 | + if( ExprHasProperty(pWhere,EP_FromJoin) |
| 139013 | + && pWhere->w.iRightJoinTable!=iCursor |
| 139014 | + ){ |
| 138886 | 139015 | return 0; /* restriction (5) */ |
| 138887 | 139016 | } |
| 138888 | 139017 | if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ |
| 138889 | 139018 | nChng++; |
| 138890 | 139019 | pSubq->selFlags |= SF_PushDown; |
| | @@ -142999,10 +143128,11 @@ |
| 142999 | 143128 | ); |
| 143000 | 143129 | |
| 143001 | 143130 | /* If an existing TriggerPrg could not be located, create a new one. */ |
| 143002 | 143131 | if( !pPrg ){ |
| 143003 | 143132 | pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf); |
| 143133 | + pParse->db->errByteOffset = -1; |
| 143004 | 143134 | } |
| 143005 | 143135 | |
| 143006 | 143136 | return pPrg; |
| 143007 | 143137 | } |
| 143008 | 143138 | |
| | @@ -148291,11 +148421,11 @@ |
| 148291 | 148421 | ** are also excluded. See codeCursorHintIsOrFunction() for details. |
| 148292 | 148422 | */ |
| 148293 | 148423 | if( pTabItem->fg.jointype & JT_LEFT ){ |
| 148294 | 148424 | Expr *pExpr = pTerm->pExpr; |
| 148295 | 148425 | if( !ExprHasProperty(pExpr, EP_FromJoin) |
| 148296 | | - || pExpr->iRightJoinTable!=pTabItem->iCursor |
| 148426 | + || pExpr->w.iRightJoinTable!=pTabItem->iCursor |
| 148297 | 148427 | ){ |
| 148298 | 148428 | sWalker.eCode = 0; |
| 148299 | 148429 | sWalker.xExprCallback = codeCursorHintIsOrFunction; |
| 148300 | 148430 | sqlite3WalkExpr(&sWalker, pTerm->pExpr); |
| 148301 | 148431 | if( sWalker.eCode ) continue; |
| | @@ -150402,11 +150532,11 @@ |
| 150402 | 150532 | ** a join, then transfer the appropriate markings over to derived. |
| 150403 | 150533 | */ |
| 150404 | 150534 | static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ |
| 150405 | 150535 | if( pDerived ){ |
| 150406 | 150536 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 150407 | | - pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 150537 | + pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable; |
| 150408 | 150538 | } |
| 150409 | 150539 | } |
| 150410 | 150540 | |
| 150411 | 150541 | /* |
| 150412 | 150542 | ** Mark term iChild as being a child of term iParent |
| | @@ -151047,11 +151177,11 @@ |
| 151047 | 151177 | abort(); |
| 151048 | 151178 | } |
| 151049 | 151179 | #endif |
| 151050 | 151180 | |
| 151051 | 151181 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 151052 | | - Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 151182 | + Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable); |
| 151053 | 151183 | prereqAll |= x; |
| 151054 | 151184 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 151055 | 151185 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 151056 | 151186 | if( (prereqAll>>1)>=x ){ |
| 151057 | 151187 | sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); |
| | @@ -151365,11 +151495,11 @@ |
| 151365 | 151495 | && pWC->op==TK_AND |
| 151366 | 151496 | ){ |
| 151367 | 151497 | int i; |
| 151368 | 151498 | for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){ |
| 151369 | 151499 | int idxNew; |
| 151370 | | - idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL); |
| 151500 | + idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); |
| 151371 | 151501 | pWC->a[idxNew].u.x.iField = i+1; |
| 151372 | 151502 | exprAnalyze(pSrc, pWC, idxNew); |
| 151373 | 151503 | markTermAsChild(pWC, idxNew, idxTerm); |
| 151374 | 151504 | } |
| 151375 | 151505 | } |
| | @@ -151398,11 +151528,11 @@ |
| 151398 | 151528 | Expr *pNewExpr; |
| 151399 | 151529 | pNewExpr = sqlite3PExpr(pParse, TK_MATCH, |
| 151400 | 151530 | 0, sqlite3ExprDup(db, pRight, 0)); |
| 151401 | 151531 | if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ |
| 151402 | 151532 | ExprSetProperty(pNewExpr, EP_FromJoin); |
| 151403 | | - pNewExpr->iRightJoinTable = pExpr->iRightJoinTable; |
| 151533 | + pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable; |
| 151404 | 151534 | } |
| 151405 | 151535 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 151406 | 151536 | testcase( idxNew==0 ); |
| 151407 | 151537 | pNewTerm = &pWC->a[idxNew]; |
| 151408 | 151538 | pNewTerm->prereqRight = prereqExpr; |
| | @@ -151472,11 +151602,11 @@ |
| 151472 | 151602 | ** In the common case where the value is a simple integer |
| 151473 | 151603 | ** (example: "LIMIT 5 OFFSET 10") then the expression codes as a |
| 151474 | 151604 | ** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value(). |
| 151475 | 151605 | ** If not, then it codes as a TK_REGISTER expression. |
| 151476 | 151606 | */ |
| 151477 | | -void whereAddLimitExpr( |
| 151607 | +static void whereAddLimitExpr( |
| 151478 | 151608 | WhereClause *pWC, /* Add the constraint to this WHERE clause */ |
| 151479 | 151609 | int iReg, /* Register that will hold value of the limit/offset */ |
| 151480 | 151610 | Expr *pExpr, /* Expression that defines the limit/offset */ |
| 151481 | 151611 | int iCsr, /* Cursor to which the constraint applies */ |
| 151482 | 151612 | int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */ |
| | @@ -153019,11 +153149,13 @@ |
| 153019 | 153149 | if( (pTerm->wtFlags & TERM_OK)==0 ) continue; |
| 153020 | 153150 | pIdxCons[j].iColumn = pTerm->u.x.leftColumn; |
| 153021 | 153151 | pIdxCons[j].iTermOffset = i; |
| 153022 | 153152 | op = pTerm->eOperator & WO_ALL; |
| 153023 | 153153 | if( op==WO_IN ){ |
| 153024 | | - pHidden->mIn |= SMASKBIT32(j); |
| 153154 | + if( (pTerm->wtFlags & TERM_SLICE)==0 ){ |
| 153155 | + pHidden->mIn |= SMASKBIT32(j); |
| 153156 | + } |
| 153025 | 153157 | op = WO_EQ; |
| 153026 | 153158 | } |
| 153027 | 153159 | if( op==WO_AUX ){ |
| 153028 | 153160 | pIdxCons[j].op = pTerm->eMatchOp; |
| 153029 | 153161 | }else if( op & (WO_ISNULL|WO_IS) ){ |
| | @@ -154942,11 +155074,11 @@ |
| 154942 | 155074 | } |
| 154943 | 155075 | if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0; |
| 154944 | 155076 | for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 154945 | 155077 | Expr *pExpr; |
| 154946 | 155078 | pExpr = pTerm->pExpr; |
| 154947 | | - if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab) |
| 155079 | + if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab) |
| 154948 | 155080 | && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin)) |
| 154949 | 155081 | && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab) |
| 154950 | 155082 | && (pTerm->wtFlags & TERM_VNULL)==0 |
| 154951 | 155083 | ){ |
| 154952 | 155084 | return 1; |
| | @@ -156922,11 +157054,11 @@ |
| 156922 | 157054 | if( (tabUsed & pLoop->maskSelf)!=0 ) continue; |
| 156923 | 157055 | pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm; |
| 156924 | 157056 | for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ |
| 156925 | 157057 | if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 156926 | 157058 | if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 156927 | | - || pTerm->pExpr->iRightJoinTable!=pItem->iCursor |
| 157059 | + || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor |
| 156928 | 157060 | ){ |
| 156929 | 157061 | break; |
| 156930 | 157062 | } |
| 156931 | 157063 | } |
| 156932 | 157064 | } |
| | @@ -161202,14 +161334,11 @@ |
| 161202 | 161334 | } |
| 161203 | 161335 | return pSelect; |
| 161204 | 161336 | } |
| 161205 | 161337 | |
| 161206 | 161338 | |
| 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 */ |
| 161211 | 161340 | static Expr *tokenExpr(Parse *pParse, int op, Token t){ |
| 161212 | 161341 | Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1); |
| 161213 | 161342 | if( p ){ |
| 161214 | 161343 | /* memset(p, 0, sizeof(Expr)); */ |
| 161215 | 161344 | p->op = (u8)op; |
| | @@ -161225,10 +161354,11 @@ |
| 161225 | 161354 | p->iTable = 0; |
| 161226 | 161355 | p->iColumn = 0; |
| 161227 | 161356 | p->u.zToken = (char*)&p[1]; |
| 161228 | 161357 | memcpy(p->u.zToken, t.z, t.n); |
| 161229 | 161358 | p->u.zToken[t.n] = 0; |
| 161359 | + p->w.iOfst = (int)(t.z - pParse->zTail); |
| 161230 | 161360 | if( sqlite3Isquote(p->u.zToken[0]) ){ |
| 161231 | 161361 | sqlite3DequoteExpr(p); |
| 161232 | 161362 | } |
| 161233 | 161363 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 161234 | 161364 | p->nHeight = 1; |
| | @@ -165036,11 +165166,11 @@ |
| 165036 | 165166 | } |
| 165037 | 165167 | break; |
| 165038 | 165168 | case 102: /* selcollist ::= sclp scanpt nm DOT STAR */ |
| 165039 | 165169 | { |
| 165040 | 165170 | 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); |
| 165042 | 165172 | Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); |
| 165043 | 165173 | yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot); |
| 165044 | 165174 | } |
| 165045 | 165175 | break; |
| 165046 | 165176 | case 103: /* as ::= AS nm */ |
| | @@ -165321,30 +165451,22 @@ |
| 165321 | 165451 | case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179); |
| 165322 | 165452 | {yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} |
| 165323 | 165453 | break; |
| 165324 | 165454 | case 180: /* expr ::= nm DOT nm */ |
| 165325 | 165455 | { |
| 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); |
| 165332 | 165458 | yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); |
| 165333 | 165459 | } |
| 165334 | 165460 | yymsp[-2].minor.yy528 = yylhsminor.yy528; |
| 165335 | 165461 | break; |
| 165336 | 165462 | case 181: /* expr ::= nm DOT nm DOT nm */ |
| 165337 | 165463 | { |
| 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); |
| 165341 | 165467 | 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 | 165468 | yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); |
| 165347 | 165469 | } |
| 165348 | 165470 | yymsp[-4].minor.yy528 = yylhsminor.yy528; |
| 165349 | 165471 | break; |
| 165350 | 165472 | case 182: /* term ::= NULL|FLOAT|BLOB */ |
| | @@ -165352,10 +165474,11 @@ |
| 165352 | 165474 | {yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} |
| 165353 | 165475 | break; |
| 165354 | 165476 | case 184: /* term ::= INTEGER */ |
| 165355 | 165477 | { |
| 165356 | 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); |
| 165357 | 165480 | } |
| 165358 | 165481 | yymsp[0].minor.yy528 = yylhsminor.yy528; |
| 165359 | 165482 | break; |
| 165360 | 165483 | case 185: /* expr ::= VARIABLE */ |
| 165361 | 165484 | { |
| | @@ -167596,11 +167719,14 @@ |
| 167596 | 167719 | }else if( tokenType==TK_FILTER ){ |
| 167597 | 167720 | assert( n==6 ); |
| 167598 | 167721 | tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed); |
| 167599 | 167722 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 167600 | 167723 | }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); |
| 167602 | 167728 | break; |
| 167603 | 167729 | } |
| 167604 | 167730 | } |
| 167605 | 167731 | pParse->sLastToken.z = zSql; |
| 167606 | 167732 | pParse->sLastToken.n = n; |
| | @@ -234119,11 +234245,11 @@ |
| 234119 | 234245 | int nArg, /* Number of args */ |
| 234120 | 234246 | sqlite3_value **apUnused /* Function arguments */ |
| 234121 | 234247 | ){ |
| 234122 | 234248 | assert( nArg==0 ); |
| 234123 | 234249 | 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); |
| 234125 | 234251 | } |
| 234126 | 234252 | |
| 234127 | 234253 | /* |
| 234128 | 234254 | ** Return true if zName is the extension on one of the shadow tables used |
| 234129 | 234255 | ** by this module. |
| 234130 | 234256 | |