| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.32.0. By combining all the individual C code files into this |
| 3 | +** version 3.32.1. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -1160,13 +1160,13 @@ |
| 1160 | 1160 | ** |
| 1161 | 1161 | ** See also: [sqlite3_libversion()], |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | | -#define SQLITE_VERSION "3.32.0" |
| 1166 | | -#define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" |
| 1165 | +#define SQLITE_VERSION "3.32.1" |
| 1166 | +#define SQLITE_VERSION_NUMBER 3032001 |
| 1167 | +#define SQLITE_SOURCE_ID "2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba83350" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -6532,11 +6532,11 @@ |
| 6532 | 6532 | ** when first called if N is less than or equal to zero or if a memory |
| 6533 | 6533 | ** allocate error occurs. |
| 6534 | 6534 | ** |
| 6535 | 6535 | ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is |
| 6536 | 6536 | ** determined by the N parameter on first successful call. Changing the |
| 6537 | | -** value of N in any subsequents call to sqlite3_aggregate_context() within |
| 6537 | +** value of N in any subsequent call to sqlite3_aggregate_context() within |
| 6538 | 6538 | ** the same aggregate function instance will not resize the memory |
| 6539 | 6539 | ** allocation.)^ Within the xFinal callback, it is customary to set |
| 6540 | 6540 | ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no |
| 6541 | 6541 | ** pointless memory allocations occur. |
| 6542 | 6542 | ** |
| | @@ -17119,11 +17119,11 @@ |
| 17119 | 17119 | #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ |
| 17120 | 17120 | #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/ |
| 17121 | 17121 | #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */ |
| 17122 | 17122 | #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ |
| 17123 | 17123 | #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ |
| 17124 | | -#define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */ |
| 17124 | +/* 0x0200 -- available for reuse */ |
| 17125 | 17125 | #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 17126 | 17126 | #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 17127 | 17127 | #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 17128 | 17128 | #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 17129 | 17129 | ** single query - might change over time */ |
| | @@ -17140,10 +17140,11 @@ |
| 17140 | 17140 | #define INLINEFUNC_coalesce 0 |
| 17141 | 17141 | #define INLINEFUNC_implies_nonnull_row 1 |
| 17142 | 17142 | #define INLINEFUNC_expr_implies_expr 2 |
| 17143 | 17143 | #define INLINEFUNC_expr_compare 3 |
| 17144 | 17144 | #define INLINEFUNC_affinity 4 |
| 17145 | +#define INLINEFUNC_iif 5 |
| 17145 | 17146 | #define INLINEFUNC_unlikely 99 /* Default case */ |
| 17146 | 17147 | |
| 17147 | 17148 | /* |
| 17148 | 17149 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 17149 | 17150 | ** used to create the initializers for the FuncDef structures. |
| | @@ -17840,11 +17841,11 @@ |
| 17840 | 17841 | /* |
| 17841 | 17842 | ** An instance of this structure contains information needed to generate |
| 17842 | 17843 | ** code for a SELECT that contains aggregate functions. |
| 17843 | 17844 | ** |
| 17844 | 17845 | ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a |
| 17845 | | -** pointer to this structure. The Expr.iColumn field is the index in |
| 17846 | +** pointer to this structure. The Expr.iAgg field is the index in |
| 17846 | 17847 | ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate |
| 17847 | 17848 | ** code for that node. |
| 17848 | 17849 | ** |
| 17849 | 17850 | ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the |
| 17850 | 17851 | ** original Select structure that describes the SELECT statement. These |
| | @@ -19079,10 +19080,13 @@ |
| 19079 | 19080 | SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*); |
| 19080 | 19081 | SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*); |
| 19081 | 19082 | SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*); |
| 19082 | 19083 | SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*); |
| 19083 | 19084 | SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*); |
| 19085 | +SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*); |
| 19086 | +SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*); |
| 19087 | + |
| 19084 | 19088 | #ifdef SQLITE_DEBUG |
| 19085 | 19089 | SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*); |
| 19086 | 19090 | #endif |
| 19087 | 19091 | |
| 19088 | 19092 | /* |
| | @@ -20064,12 +20068,14 @@ |
| 20064 | 20068 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 20065 | 20069 | #endif |
| 20066 | 20070 | SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db); |
| 20067 | 20071 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 20068 | 20072 | SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName); |
| 20073 | +SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); |
| 20069 | 20074 | #else |
| 20070 | 20075 | # define sqlite3ShadowTableName(A,B) 0 |
| 20076 | +# define sqlite3IsShadowTableOf(A,B,C) 0 |
| 20071 | 20077 | #endif |
| 20072 | 20078 | SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*); |
| 20073 | 20079 | SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*); |
| 20074 | 20080 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 20075 | 20081 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); |
| | @@ -27924,11 +27930,11 @@ |
| 27924 | 27930 | } |
| 27925 | 27931 | }else{ |
| 27926 | 27932 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27927 | 27933 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27928 | 27934 | sqlite3MemdebugSetType(p, MEMTYPE_HEAP); |
| 27929 | | - pNew = sqlite3_realloc64(p, n); |
| 27935 | + pNew = sqlite3Realloc(p, n); |
| 27930 | 27936 | if( !pNew ){ |
| 27931 | 27937 | sqlite3OomFault(db); |
| 27932 | 27938 | } |
| 27933 | 27939 | sqlite3MemdebugSetType(pNew, |
| 27934 | 27940 | (db->lookaside.bDisable==0 ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); |
| | @@ -28271,10 +28277,17 @@ |
| 28271 | 28277 | #ifndef SQLITE_PRINT_BUF_SIZE |
| 28272 | 28278 | # define SQLITE_PRINT_BUF_SIZE 70 |
| 28273 | 28279 | #endif |
| 28274 | 28280 | #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ |
| 28275 | 28281 | |
| 28282 | +/* |
| 28283 | +** Hard limit on the precision of floating-point conversions. |
| 28284 | +*/ |
| 28285 | +#ifndef SQLITE_PRINTF_PRECISION_LIMIT |
| 28286 | +# define SQLITE_FP_PRECISION_LIMIT 100000000 |
| 28287 | +#endif |
| 28288 | + |
| 28276 | 28289 | /* |
| 28277 | 28290 | ** Render a string given by "fmt" into the StrAccum object. |
| 28278 | 28291 | */ |
| 28279 | 28292 | SQLITE_API void sqlite3_str_vappendf( |
| 28280 | 28293 | sqlite3_str *pAccum, /* Accumulate results here */ |
| | @@ -28471,10 +28484,12 @@ |
| 28471 | 28484 | ** precision The specified precision. The default |
| 28472 | 28485 | ** is -1. |
| 28473 | 28486 | ** xtype The class of the conversion. |
| 28474 | 28487 | ** infop Pointer to the appropriate info struct. |
| 28475 | 28488 | */ |
| 28489 | + assert( width>=0 ); |
| 28490 | + assert( precision>=(-1) ); |
| 28476 | 28491 | switch( xtype ){ |
| 28477 | 28492 | case etPOINTER: |
| 28478 | 28493 | flag_long = sizeof(char*)==sizeof(i64) ? 2 : |
| 28479 | 28494 | sizeof(char*)==sizeof(long int) ? 1 : 0; |
| 28480 | 28495 | /* Fall through into the next case */ |
| | @@ -28592,10 +28607,15 @@ |
| 28592 | 28607 | } |
| 28593 | 28608 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 28594 | 28609 | length = 0; |
| 28595 | 28610 | #else |
| 28596 | 28611 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 28612 | +#ifdef SQLITE_FP_PRECISION_LIMIT |
| 28613 | + if( precision>SQLITE_FP_PRECISION_LIMIT ){ |
| 28614 | + precision = SQLITE_FP_PRECISION_LIMIT; |
| 28615 | + } |
| 28616 | +#endif |
| 28597 | 28617 | if( realvalue<0.0 ){ |
| 28598 | 28618 | realvalue = -realvalue; |
| 28599 | 28619 | prefix = '-'; |
| 28600 | 28620 | }else{ |
| 28601 | 28621 | prefix = flag_prefix; |
| | @@ -28874,11 +28894,11 @@ |
| 28874 | 28894 | }else{ |
| 28875 | 28895 | escarg = va_arg(ap,char*); |
| 28876 | 28896 | } |
| 28877 | 28897 | isnull = escarg==0; |
| 28878 | 28898 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 28879 | | - /* For %q, %Q, and %w, the precision is the number of byte (or |
| 28899 | + /* For %q, %Q, and %w, the precision is the number of bytes (or |
| 28880 | 28900 | ** characters if the ! flags is present) to use from the input. |
| 28881 | 28901 | ** Because of the extra quoting characters inserted, the number |
| 28882 | 28902 | ** of output characters may be larger than the precision. |
| 28883 | 28903 | */ |
| 28884 | 28904 | k = precision; |
| | @@ -29001,11 +29021,11 @@ |
| 29001 | 29021 | p->nAlloc = (int)szNew; |
| 29002 | 29022 | } |
| 29003 | 29023 | if( p->db ){ |
| 29004 | 29024 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 29005 | 29025 | }else{ |
| 29006 | | - zNew = sqlite3_realloc64(zOld, p->nAlloc); |
| 29026 | + zNew = sqlite3Realloc(zOld, p->nAlloc); |
| 29007 | 29027 | } |
| 29008 | 29028 | if( zNew ){ |
| 29009 | 29029 | assert( p->zText!=0 || p->nChar==0 ); |
| 29010 | 29030 | if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 29011 | 29031 | p->zText = zNew; |
| | @@ -29343,11 +29363,11 @@ |
| 29343 | 29363 | ** and segfaults if you give it a long long int. |
| 29344 | 29364 | */ |
| 29345 | 29365 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 29346 | 29366 | va_list ap; |
| 29347 | 29367 | StrAccum acc; |
| 29348 | | - char zBuf[500]; |
| 29368 | + char zBuf[SQLITE_PRINT_BUF_SIZE*10]; |
| 29349 | 29369 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 29350 | 29370 | va_start(ap,zFormat); |
| 29351 | 29371 | sqlite3_str_vappendf(&acc, zFormat, ap); |
| 29352 | 29372 | va_end(ap); |
| 29353 | 29373 | sqlite3StrAccumFinish(&acc); |
| | @@ -29959,12 +29979,13 @@ |
| 29959 | 29979 | #else |
| 29960 | 29980 | pWin = 0; |
| 29961 | 29981 | #endif |
| 29962 | 29982 | } |
| 29963 | 29983 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| 29964 | | - sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s", |
| 29965 | | - pExpr->op2, pExpr->u.zToken, zFlgs); |
| 29984 | + sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p", |
| 29985 | + pExpr->op2, pExpr->u.zToken, zFlgs, |
| 29986 | + pExpr->iAgg, pExpr->pAggInfo); |
| 29966 | 29987 | }else if( pExpr->op2!=0 ){ |
| 29967 | 29988 | const char *zOp2; |
| 29968 | 29989 | char zBuf[8]; |
| 29969 | 29990 | sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); |
| 29970 | 29991 | zOp2 = zBuf; |
| | @@ -30853,10 +30874,11 @@ |
| 30853 | 30874 | /* UTF-16 Little-endian -> UTF-8 */ |
| 30854 | 30875 | while( zIn<zTerm ){ |
| 30855 | 30876 | c = *(zIn++); |
| 30856 | 30877 | c += (*(zIn++))<<8; |
| 30857 | 30878 | if( c>=0xd800 && c<0xe000 ){ |
| 30879 | +#ifdef SQLITE_REPLACE_INVALID_UTF |
| 30858 | 30880 | if( c>=0xdc00 || zIn>=zTerm ){ |
| 30859 | 30881 | c = 0xfffd; |
| 30860 | 30882 | }else{ |
| 30861 | 30883 | int c2 = *(zIn++); |
| 30862 | 30884 | c2 += (*(zIn++))<<8; |
| | @@ -30865,19 +30887,27 @@ |
| 30865 | 30887 | c = 0xfffd; |
| 30866 | 30888 | }else{ |
| 30867 | 30889 | c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; |
| 30868 | 30890 | } |
| 30869 | 30891 | } |
| 30892 | +#else |
| 30893 | + if( zIn<zTerm ){ |
| 30894 | + int c2 = (*zIn++); |
| 30895 | + c2 += ((*zIn++)<<8); |
| 30896 | + c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); |
| 30897 | + } |
| 30898 | +#endif |
| 30870 | 30899 | } |
| 30871 | 30900 | WRITE_UTF8(z, c); |
| 30872 | 30901 | } |
| 30873 | 30902 | }else{ |
| 30874 | 30903 | /* UTF-16 Big-endian -> UTF-8 */ |
| 30875 | 30904 | while( zIn<zTerm ){ |
| 30876 | 30905 | c = (*(zIn++))<<8; |
| 30877 | 30906 | c += *(zIn++); |
| 30878 | 30907 | if( c>=0xd800 && c<0xe000 ){ |
| 30908 | +#ifdef SQLITE_REPLACE_INVALID_UTF |
| 30879 | 30909 | if( c>=0xdc00 || zIn>=zTerm ){ |
| 30880 | 30910 | c = 0xfffd; |
| 30881 | 30911 | }else{ |
| 30882 | 30912 | int c2 = (*(zIn++))<<8; |
| 30883 | 30913 | c2 += *(zIn++); |
| | @@ -30886,10 +30916,17 @@ |
| 30886 | 30916 | c = 0xfffd; |
| 30887 | 30917 | }else{ |
| 30888 | 30918 | c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; |
| 30889 | 30919 | } |
| 30890 | 30920 | } |
| 30921 | +#else |
| 30922 | + if( zIn<zTerm ){ |
| 30923 | + int c2 = ((*zIn++)<<8); |
| 30924 | + c2 += (*zIn++); |
| 30925 | + c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); |
| 30926 | + } |
| 30927 | +#endif |
| 30891 | 30928 | } |
| 30892 | 30929 | WRITE_UTF8(z, c); |
| 30893 | 30930 | } |
| 30894 | 30931 | } |
| 30895 | 30932 | pMem->n = (int)(z - zOut); |
| | @@ -45048,10 +45085,11 @@ |
| 45048 | 45085 | } |
| 45049 | 45086 | |
| 45050 | 45087 | /* Forward references to VFS helper methods used for temporary files */ |
| 45051 | 45088 | static int winGetTempname(sqlite3_vfs *, char **); |
| 45052 | 45089 | static int winIsDir(const void *); |
| 45090 | +static BOOL winIsLongPathPrefix(const char *); |
| 45053 | 45091 | static BOOL winIsDriveLetterAndColon(const char *); |
| 45054 | 45092 | |
| 45055 | 45093 | /* |
| 45056 | 45094 | ** Control and query of the open file handle. |
| 45057 | 45095 | */ |
| | @@ -46817,11 +46855,13 @@ |
| 46817 | 46855 | pFile->pVfs = pVfs; |
| 46818 | 46856 | pFile->h = h; |
| 46819 | 46857 | if( isReadonly ){ |
| 46820 | 46858 | pFile->ctrlFlags |= WINFILE_RDONLY; |
| 46821 | 46859 | } |
| 46822 | | - if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
| 46860 | + if( (flags & SQLITE_OPEN_MAIN_DB) |
| 46861 | + && sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) |
| 46862 | + ){ |
| 46823 | 46863 | pFile->ctrlFlags |= WINFILE_PSOW; |
| 46824 | 46864 | } |
| 46825 | 46865 | pFile->lastErrno = NO_ERROR; |
| 46826 | 46866 | pFile->zPath = zName; |
| 46827 | 46867 | #if SQLITE_MAX_MMAP_SIZE>0 |
| | @@ -47026,10 +47066,21 @@ |
| 47026 | 47066 | *pResOut = rc; |
| 47027 | 47067 | OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n", |
| 47028 | 47068 | zFilename, pResOut, *pResOut)); |
| 47029 | 47069 | return SQLITE_OK; |
| 47030 | 47070 | } |
| 47071 | + |
| 47072 | +/* |
| 47073 | +** Returns non-zero if the specified path name starts with the "long path" |
| 47074 | +** prefix. |
| 47075 | +*/ |
| 47076 | +static BOOL winIsLongPathPrefix( |
| 47077 | + const char *zPathname |
| 47078 | +){ |
| 47079 | + return ( zPathname[0]=='\\' && zPathname[1]=='\\' |
| 47080 | + && zPathname[2]=='?' && zPathname[3]=='\\' ); |
| 47081 | +} |
| 47031 | 47082 | |
| 47032 | 47083 | /* |
| 47033 | 47084 | ** Returns non-zero if the specified path name starts with a drive letter |
| 47034 | 47085 | ** followed by a colon character. |
| 47035 | 47086 | */ |
| | @@ -47091,14 +47142,15 @@ |
| 47091 | 47142 | DWORD nByte; |
| 47092 | 47143 | void *zConverted; |
| 47093 | 47144 | char *zOut; |
| 47094 | 47145 | #endif |
| 47095 | 47146 | |
| 47096 | | - /* If this path name begins with "/X:", where "X" is any alphabetic |
| 47097 | | - ** character, discard the initial "/" from the pathname. |
| 47147 | + /* If this path name begins with "/X:" or "\\?\", where "X" is any |
| 47148 | + ** alphabetic character, discard the initial "/" from the pathname. |
| 47098 | 47149 | */ |
| 47099 | | - if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){ |
| 47150 | + if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1) |
| 47151 | + || winIsLongPathPrefix(zRelative+1)) ){ |
| 47100 | 47152 | zRelative++; |
| 47101 | 47153 | } |
| 47102 | 47154 | |
| 47103 | 47155 | #if defined(__CYGWIN__) |
| 47104 | 47156 | SimulateIOError( return SQLITE_ERROR ); |
| | @@ -47850,11 +47902,11 @@ |
| 47850 | 47902 | if( newSz>p->szMax ){ |
| 47851 | 47903 | return SQLITE_FULL; |
| 47852 | 47904 | } |
| 47853 | 47905 | newSz *= 2; |
| 47854 | 47906 | if( newSz>p->szMax ) newSz = p->szMax; |
| 47855 | | - pNew = sqlite3_realloc64(p->aData, newSz); |
| 47907 | + pNew = sqlite3Realloc(p->aData, newSz); |
| 47856 | 47908 | if( pNew==0 ) return SQLITE_NOMEM; |
| 47857 | 47909 | p->aData = pNew; |
| 47858 | 47910 | p->szAlloc = newSz; |
| 47859 | 47911 | return SQLITE_OK; |
| 47860 | 47912 | } |
| | @@ -48297,14 +48349,15 @@ |
| 48297 | 48349 | */ |
| 48298 | 48350 | SQLITE_PRIVATE int sqlite3MemdbInit(void){ |
| 48299 | 48351 | sqlite3_vfs *pLower = sqlite3_vfs_find(0); |
| 48300 | 48352 | int sz = pLower->szOsFile; |
| 48301 | 48353 | memdb_vfs.pAppData = pLower; |
| 48302 | | - /* In all known configurations of SQLite, the size of a default |
| 48303 | | - ** sqlite3_file is greater than the size of a memdb sqlite3_file. |
| 48304 | | - ** Should that ever change, remove the following NEVER() */ |
| 48305 | | - if( NEVER(sz<sizeof(MemFile)) ) sz = sizeof(MemFile); |
| 48354 | + /* The following conditional can only be true when compiled for |
| 48355 | + ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave |
| 48356 | + ** it in, to be safe, but it is marked as NO_TEST since there |
| 48357 | + ** is no way to reach it under most builds. */ |
| 48358 | + if( sz<sizeof(MemFile) ) sz = sizeof(MemFile); /*NO_TEST*/ |
| 48306 | 48359 | memdb_vfs.szOsFile = sz; |
| 48307 | 48360 | return sqlite3_vfs_register(&memdb_vfs, 0); |
| 48308 | 48361 | } |
| 48309 | 48362 | #endif /* SQLITE_ENABLE_DESERIALIZE */ |
| 48310 | 48363 | |
| | @@ -59820,11 +59873,11 @@ |
| 59820 | 59873 | |
| 59821 | 59874 | /* Enlarge the pWal->apWiData[] array if required */ |
| 59822 | 59875 | if( pWal->nWiData<=iPage ){ |
| 59823 | 59876 | sqlite3_int64 nByte = sizeof(u32*)*(iPage+1); |
| 59824 | 59877 | volatile u32 **apNew; |
| 59825 | | - apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 59878 | + apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte); |
| 59826 | 59879 | if( !apNew ){ |
| 59827 | 59880 | *ppPage = 0; |
| 59828 | 59881 | return SQLITE_NOMEM_BKPT; |
| 59829 | 59882 | } |
| 59830 | 59883 | memset((void*)&apNew[pWal->nWiData], 0, |
| | @@ -59941,29 +59994,47 @@ |
| 59941 | 59994 | |
| 59942 | 59995 | aOut[0] = s1; |
| 59943 | 59996 | aOut[1] = s2; |
| 59944 | 59997 | } |
| 59945 | 59998 | |
| 59999 | +/* |
| 60000 | +** If there is the possibility of concurrent access to the SHM file |
| 60001 | +** from multiple threads and/or processes, then do a memory barrier. |
| 60002 | +*/ |
| 59946 | 60003 | static void walShmBarrier(Wal *pWal){ |
| 59947 | 60004 | if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){ |
| 59948 | 60005 | sqlite3OsShmBarrier(pWal->pDbFd); |
| 59949 | 60006 | } |
| 59950 | 60007 | } |
| 59951 | 60008 | |
| 60009 | +/* |
| 60010 | +** Add the SQLITE_NO_TSAN as part of the return-type of a function |
| 60011 | +** definition as a hint that the function contains constructs that |
| 60012 | +** might give false-positive TSAN warnings. |
| 60013 | +** |
| 60014 | +** See tag-20200519-1. |
| 60015 | +*/ |
| 60016 | +#if defined(__clang__) && !defined(SQLITE_NO_TSAN) |
| 60017 | +# define SQLITE_NO_TSAN __attribute__((no_sanitize_thread)) |
| 60018 | +#else |
| 60019 | +# define SQLITE_NO_TSAN |
| 60020 | +#endif |
| 60021 | + |
| 59952 | 60022 | /* |
| 59953 | 60023 | ** Write the header information in pWal->hdr into the wal-index. |
| 59954 | 60024 | ** |
| 59955 | 60025 | ** The checksum on pWal->hdr is updated before it is written. |
| 59956 | 60026 | */ |
| 59957 | | -static void walIndexWriteHdr(Wal *pWal){ |
| 60027 | +static SQLITE_NO_TSAN void walIndexWriteHdr(Wal *pWal){ |
| 59958 | 60028 | volatile WalIndexHdr *aHdr = walIndexHdr(pWal); |
| 59959 | 60029 | const int nCksum = offsetof(WalIndexHdr, aCksum); |
| 59960 | 60030 | |
| 59961 | 60031 | assert( pWal->writeLock ); |
| 59962 | 60032 | pWal->hdr.isInit = 1; |
| 59963 | 60033 | pWal->hdr.iVersion = WALINDEX_MAX_VERSION; |
| 59964 | 60034 | walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); |
| 60035 | + /* Possible TSAN false-positive. See tag-20200519-1 */ |
| 59965 | 60036 | memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); |
| 59966 | 60037 | walShmBarrier(pWal); |
| 59967 | 60038 | memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr)); |
| 59968 | 60039 | } |
| 59969 | 60040 | |
| | @@ -61074,11 +61145,11 @@ |
| 61074 | 61145 | pWal->nCkpt++; |
| 61075 | 61146 | pWal->hdr.mxFrame = 0; |
| 61076 | 61147 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 61077 | 61148 | memcpy(&pWal->hdr.aSalt[1], &salt1, 4); |
| 61078 | 61149 | walIndexWriteHdr(pWal); |
| 61079 | | - pInfo->nBackfill = 0; |
| 61150 | + AtomicStore(&pInfo->nBackfill, 0); |
| 61080 | 61151 | pInfo->nBackfillAttempted = 0; |
| 61081 | 61152 | pInfo->aReadMark[1] = 0; |
| 61082 | 61153 | for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; |
| 61083 | 61154 | assert( pInfo->aReadMark[0]==0 ); |
| 61084 | 61155 | } |
| | @@ -61149,36 +61220,17 @@ |
| 61149 | 61220 | ** cannot be backfilled from the WAL. |
| 61150 | 61221 | */ |
| 61151 | 61222 | mxSafeFrame = pWal->hdr.mxFrame; |
| 61152 | 61223 | mxPage = pWal->hdr.nPage; |
| 61153 | 61224 | for(i=1; i<WAL_NREADER; i++){ |
| 61154 | | - /* Thread-sanitizer reports that the following is an unsafe read, |
| 61155 | | - ** as some other thread may be in the process of updating the value |
| 61156 | | - ** of the aReadMark[] slot. The assumption here is that if that is |
| 61157 | | - ** happening, the other client may only be increasing the value, |
| 61158 | | - ** not decreasing it. So assuming either that either the "old" or |
| 61159 | | - ** "new" version of the value is read, and not some arbitrary value |
| 61160 | | - ** that would never be written by a real client, things are still |
| 61161 | | - ** safe. |
| 61162 | | - ** |
| 61163 | | - ** Astute readers have pointed out that the assumption stated in the |
| 61164 | | - ** last sentence of the previous paragraph is not guaranteed to be |
| 61165 | | - ** true for all conforming systems. However, the assumption is true |
| 61166 | | - ** for all compilers and architectures in common use today (circa |
| 61167 | | - ** 2019-11-27) and the alternatives are both slow and complex, and |
| 61168 | | - ** so we will continue to go with the current design for now. If this |
| 61169 | | - ** bothers you, or if you really are running on a system where aligned |
| 61170 | | - ** 32-bit reads and writes are not atomic, then you can simply avoid |
| 61171 | | - ** the use of WAL mode, or only use WAL mode together with |
| 61172 | | - ** PRAGMA locking_mode=EXCLUSIVE and all will be well. |
| 61173 | | - */ |
| 61174 | | - u32 y = pInfo->aReadMark[i]; |
| 61225 | + u32 y = AtomicLoad(pInfo->aReadMark+i); |
| 61175 | 61226 | if( mxSafeFrame>y ){ |
| 61176 | 61227 | assert( y<=pWal->hdr.mxFrame ); |
| 61177 | 61228 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); |
| 61178 | 61229 | if( rc==SQLITE_OK ){ |
| 61179 | | - pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED); |
| 61230 | + u32 iMark = (i==1 ? mxSafeFrame : READMARK_NOT_USED); |
| 61231 | + AtomicStore(pInfo->aReadMark+i, iMark); |
| 61180 | 61232 | walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); |
| 61181 | 61233 | }else if( rc==SQLITE_BUSY ){ |
| 61182 | 61234 | mxSafeFrame = y; |
| 61183 | 61235 | xBusy = 0; |
| 61184 | 61236 | }else{ |
| | @@ -61192,11 +61244,11 @@ |
| 61192 | 61244 | rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter); |
| 61193 | 61245 | assert( rc==SQLITE_OK || pIter==0 ); |
| 61194 | 61246 | } |
| 61195 | 61247 | |
| 61196 | 61248 | if( pIter |
| 61197 | | - && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK |
| 61249 | + && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK |
| 61198 | 61250 | ){ |
| 61199 | 61251 | u32 nBackfill = pInfo->nBackfill; |
| 61200 | 61252 | |
| 61201 | 61253 | pInfo->nBackfillAttempted = mxSafeFrame; |
| 61202 | 61254 | |
| | @@ -61248,11 +61300,11 @@ |
| 61248 | 61300 | if( rc==SQLITE_OK ){ |
| 61249 | 61301 | rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 61250 | 61302 | } |
| 61251 | 61303 | } |
| 61252 | 61304 | if( rc==SQLITE_OK ){ |
| 61253 | | - pInfo->nBackfill = mxSafeFrame; |
| 61305 | + AtomicStore(&pInfo->nBackfill, mxSafeFrame); |
| 61254 | 61306 | } |
| 61255 | 61307 | } |
| 61256 | 61308 | |
| 61257 | 61309 | /* Release the reader lock held while backfilling */ |
| 61258 | 61310 | walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1); |
| | @@ -61407,11 +61459,11 @@ |
| 61407 | 61459 | ** and *pChanged is set to 1. |
| 61408 | 61460 | ** |
| 61409 | 61461 | ** If the checksum cannot be verified return non-zero. If the header |
| 61410 | 61462 | ** is read successfully and the checksum verified, return zero. |
| 61411 | 61463 | */ |
| 61412 | | -static int walIndexTryHdr(Wal *pWal, int *pChanged){ |
| 61464 | +static SQLITE_NO_TSAN int walIndexTryHdr(Wal *pWal, int *pChanged){ |
| 61413 | 61465 | u32 aCksum[2]; /* Checksum on the header content */ |
| 61414 | 61466 | WalIndexHdr h1, h2; /* Two copies of the header content */ |
| 61415 | 61467 | WalIndexHdr volatile *aHdr; /* Header in shared memory */ |
| 61416 | 61468 | |
| 61417 | 61469 | /* The first page of the wal-index must be mapped at this point. */ |
| | @@ -61420,17 +61472,23 @@ |
| 61420 | 61472 | /* Read the header. This might happen concurrently with a write to the |
| 61421 | 61473 | ** same area of shared memory on a different CPU in a SMP, |
| 61422 | 61474 | ** meaning it is possible that an inconsistent snapshot is read |
| 61423 | 61475 | ** from the file. If this happens, return non-zero. |
| 61424 | 61476 | ** |
| 61477 | + ** tag-20200519-1: |
| 61425 | 61478 | ** There are two copies of the header at the beginning of the wal-index. |
| 61426 | 61479 | ** When reading, read [0] first then [1]. Writes are in the reverse order. |
| 61427 | 61480 | ** Memory barriers are used to prevent the compiler or the hardware from |
| 61428 | | - ** reordering the reads and writes. |
| 61481 | + ** reordering the reads and writes. TSAN and similar tools can sometimes |
| 61482 | + ** give false-positive warnings about these accesses because the tools do not |
| 61483 | + ** account for the double-read and the memory barrier. The use of mutexes |
| 61484 | + ** here would be problematic as the memory being accessed is potentially |
| 61485 | + ** shared among multiple processes and not all mutex implementions work |
| 61486 | + ** reliably in that environment. |
| 61429 | 61487 | */ |
| 61430 | 61488 | aHdr = walIndexHdr(pWal); |
| 61431 | | - memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); |
| 61489 | + memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */ |
| 61432 | 61490 | walShmBarrier(pWal); |
| 61433 | 61491 | memcpy(&h2, (void *)&aHdr[1], sizeof(h2)); |
| 61434 | 61492 | |
| 61435 | 61493 | if( memcmp(&h1, &h2, sizeof(h1))!=0 ){ |
| 61436 | 61494 | return 1; /* Dirty read */ |
| | @@ -61871,11 +61929,11 @@ |
| 61871 | 61929 | } |
| 61872 | 61930 | |
| 61873 | 61931 | assert( pWal->nWiData>0 ); |
| 61874 | 61932 | assert( pWal->apWiData[0]!=0 ); |
| 61875 | 61933 | pInfo = walCkptInfo(pWal); |
| 61876 | | - if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame |
| 61934 | + if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame |
| 61877 | 61935 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61878 | 61936 | && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0) |
| 61879 | 61937 | #endif |
| 61880 | 61938 | ){ |
| 61881 | 61939 | /* The WAL has been completely backfilled (or it is empty). |
| | @@ -62038,11 +62096,11 @@ |
| 62038 | 62096 | void *pBuf2 = sqlite3_malloc(szPage); |
| 62039 | 62097 | if( pBuf1==0 || pBuf2==0 ){ |
| 62040 | 62098 | rc = SQLITE_NOMEM; |
| 62041 | 62099 | }else{ |
| 62042 | 62100 | u32 i = pInfo->nBackfillAttempted; |
| 62043 | | - for(i=pInfo->nBackfillAttempted; i>pInfo->nBackfill; i--){ |
| 62101 | + for(i=pInfo->nBackfillAttempted; i>AtomicLoad(&pInfo->nBackfill); i--){ |
| 62044 | 62102 | WalHashLoc sLoc; /* Hash table location */ |
| 62045 | 62103 | u32 pgno; /* Page number in db file */ |
| 62046 | 62104 | i64 iDbOff; /* Offset of db file entry */ |
| 62047 | 62105 | i64 iWalOff; /* Offset of wal file entry */ |
| 62048 | 62106 | |
| | @@ -62093,16 +62151,18 @@ |
| 62093 | 62151 | ** needs to be flushed. |
| 62094 | 62152 | */ |
| 62095 | 62153 | SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ |
| 62096 | 62154 | int rc; /* Return code */ |
| 62097 | 62155 | int cnt = 0; /* Number of TryBeginRead attempts */ |
| 62156 | +#ifdef SQLITE_ENABLE_SNAPSHOT |
| 62157 | + int bChanged = 0; |
| 62158 | + WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 62159 | +#endif |
| 62098 | 62160 | |
| 62099 | 62161 | assert( pWal->ckptLock==0 ); |
| 62100 | 62162 | |
| 62101 | 62163 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 62102 | | - int bChanged = 0; |
| 62103 | | - WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 62104 | 62164 | if( pSnapshot ){ |
| 62105 | 62165 | if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 62106 | 62166 | bChanged = 1; |
| 62107 | 62167 | } |
| 62108 | 62168 | |
| | @@ -62267,26 +62327,28 @@ |
| 62267 | 62327 | for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){ |
| 62268 | 62328 | WalHashLoc sLoc; /* Hash table location */ |
| 62269 | 62329 | int iKey; /* Hash slot index */ |
| 62270 | 62330 | int nCollide; /* Number of hash collisions remaining */ |
| 62271 | 62331 | int rc; /* Error code */ |
| 62332 | + u32 iH; |
| 62272 | 62333 | |
| 62273 | 62334 | rc = walHashGet(pWal, iHash, &sLoc); |
| 62274 | 62335 | if( rc!=SQLITE_OK ){ |
| 62275 | 62336 | return rc; |
| 62276 | 62337 | } |
| 62277 | 62338 | nCollide = HASHTABLE_NSLOT; |
| 62278 | | - for(iKey=walHash(pgno); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){ |
| 62279 | | - u32 iH = sLoc.aHash[iKey]; |
| 62339 | + iKey = walHash(pgno); |
| 62340 | + while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){ |
| 62280 | 62341 | u32 iFrame = iH + sLoc.iZero; |
| 62281 | 62342 | if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){ |
| 62282 | 62343 | assert( iFrame>iRead || CORRUPT_DB ); |
| 62283 | 62344 | iRead = iFrame; |
| 62284 | 62345 | } |
| 62285 | 62346 | if( (nCollide--)==0 ){ |
| 62286 | 62347 | return SQLITE_CORRUPT_BKPT; |
| 62287 | 62348 | } |
| 62349 | + iKey = walNextHash(iKey); |
| 62288 | 62350 | } |
| 62289 | 62351 | if( iRead ) break; |
| 62290 | 62352 | } |
| 62291 | 62353 | |
| 62292 | 62354 | #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| | @@ -79307,10 +79369,11 @@ |
| 79307 | 79369 | char *zP4; |
| 79308 | 79370 | char *zCom; |
| 79309 | 79371 | sqlite3 dummyDb; |
| 79310 | 79372 | static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n"; |
| 79311 | 79373 | if( pOut==0 ) pOut = stdout; |
| 79374 | + sqlite3BeginBenignMalloc(); |
| 79312 | 79375 | dummyDb.mallocFailed = 1; |
| 79313 | 79376 | zP4 = sqlite3VdbeDisplayP4(&dummyDb, pOp); |
| 79314 | 79377 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 79315 | 79378 | zCom = sqlite3VdbeDisplayComment(0, pOp, zP4); |
| 79316 | 79379 | #else |
| | @@ -79325,10 +79388,11 @@ |
| 79325 | 79388 | zCom ? zCom : "" |
| 79326 | 79389 | ); |
| 79327 | 79390 | fflush(pOut); |
| 79328 | 79391 | sqlite3_free(zP4); |
| 79329 | 79392 | sqlite3_free(zCom); |
| 79393 | + sqlite3EndBenignMalloc(); |
| 79330 | 79394 | } |
| 79331 | 79395 | #endif |
| 79332 | 79396 | |
| 79333 | 79397 | /* |
| 79334 | 79398 | ** Initialize an array of N Mem element. |
| | @@ -84066,11 +84130,11 @@ |
| 84066 | 84130 | p->db->errCode = SQLITE_OK; |
| 84067 | 84131 | |
| 84068 | 84132 | /* If the bit corresponding to this variable in Vdbe.expmask is set, then |
| 84069 | 84133 | ** binding a new value to this variable invalidates the current query plan. |
| 84070 | 84134 | ** |
| 84071 | | - ** IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host |
| 84135 | + ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host |
| 84072 | 84136 | ** parameter in the WHERE clause might influence the choice of query plan |
| 84073 | 84137 | ** for a statement, then the statement will be automatically recompiled, |
| 84074 | 84138 | ** as if there had been a schema change, on the first sqlite3_step() call |
| 84075 | 84139 | ** following any change to the bindings of that parameter. |
| 84076 | 84140 | */ |
| | @@ -96365,12 +96429,12 @@ |
| 96365 | 96429 | ************************************************************************* |
| 96366 | 96430 | ** |
| 96367 | 96431 | ** This file implements virtual-tables for examining the bytecode content |
| 96368 | 96432 | ** of a prepared statement. |
| 96369 | 96433 | */ |
| 96370 | | -#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 96371 | 96434 | /* #include "sqliteInt.h" */ |
| 96435 | +#if defined(SQLITE_ENABLE_BYTECODE_VTAB) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 96372 | 96436 | /* #include "vdbeInt.h" */ |
| 96373 | 96437 | |
| 96374 | 96438 | /* An instance of the bytecode() table-valued function. |
| 96375 | 96439 | */ |
| 96376 | 96440 | typedef struct bytecodevtab bytecodevtab; |
| | @@ -96771,10 +96835,12 @@ |
| 96771 | 96835 | if( rc==SQLITE_OK ){ |
| 96772 | 96836 | rc = sqlite3_create_module(db, "tables_used", &bytecodevtabModule, &db); |
| 96773 | 96837 | } |
| 96774 | 96838 | return rc; |
| 96775 | 96839 | } |
| 96840 | +#elif defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 96841 | +SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3 *db){ return SQLITE_OK; } |
| 96776 | 96842 | #endif /* SQLITE_ENABLE_BYTECODE_VTAB */ |
| 96777 | 96843 | |
| 96778 | 96844 | /************** End of vdbevtab.c ********************************************/ |
| 96779 | 96845 | /************** Begin file memjournal.c **************************************/ |
| 96780 | 96846 | /* |
| | @@ -97416,10 +97482,47 @@ |
| 97416 | 97482 | } |
| 97417 | 97483 | p = p->pPrior; |
| 97418 | 97484 | }while( p!=0 ); |
| 97419 | 97485 | return WRC_Continue; |
| 97420 | 97486 | } |
| 97487 | + |
| 97488 | +/* Increase the walkerDepth when entering a subquery, and |
| 97489 | +** descrease when leaving the subquery. |
| 97490 | +*/ |
| 97491 | +SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){ |
| 97492 | + UNUSED_PARAMETER(pSelect); |
| 97493 | + pWalker->walkerDepth++; |
| 97494 | + return WRC_Continue; |
| 97495 | +} |
| 97496 | +SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker *pWalker, Select *pSelect){ |
| 97497 | + UNUSED_PARAMETER(pSelect); |
| 97498 | + pWalker->walkerDepth--; |
| 97499 | +} |
| 97500 | + |
| 97501 | + |
| 97502 | +/* |
| 97503 | +** No-op routine for the parse-tree walker. |
| 97504 | +** |
| 97505 | +** When this routine is the Walker.xExprCallback then expression trees |
| 97506 | +** are walked without any actions being taken at each node. Presumably, |
| 97507 | +** when this routine is used for Walker.xExprCallback then |
| 97508 | +** Walker.xSelectCallback is set to do something useful for every |
| 97509 | +** subquery in the parser tree. |
| 97510 | +*/ |
| 97511 | +SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker *NotUsed, Expr *NotUsed2){ |
| 97512 | + UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 97513 | + return WRC_Continue; |
| 97514 | +} |
| 97515 | + |
| 97516 | +/* |
| 97517 | +** No-op routine for the parse-tree walker for SELECT statements. |
| 97518 | +** subquery in the parser tree. |
| 97519 | +*/ |
| 97520 | +SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker *NotUsed, Select *NotUsed2){ |
| 97521 | + UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 97522 | + return WRC_Continue; |
| 97523 | +} |
| 97421 | 97524 | |
| 97422 | 97525 | /************** End of walker.c **********************************************/ |
| 97423 | 97526 | /************** Begin file resolve.c *****************************************/ |
| 97424 | 97527 | /* |
| 97425 | 97528 | ** 2008 August 18 |
| | @@ -97445,10 +97548,12 @@ |
| 97445 | 97548 | ** This needs to occur when copying a TK_AGG_FUNCTION node from an |
| 97446 | 97549 | ** outer query into an inner subquery. |
| 97447 | 97550 | ** |
| 97448 | 97551 | ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 97449 | 97552 | ** is a helper function - a callback for the tree walker. |
| 97553 | +** |
| 97554 | +** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c |
| 97450 | 97555 | */ |
| 97451 | 97556 | static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 97452 | 97557 | if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; |
| 97453 | 97558 | return WRC_Continue; |
| 97454 | 97559 | } |
| | @@ -103075,10 +103180,17 @@ |
| 103075 | 103180 | } |
| 103076 | 103181 | setDoNotMergeFlagOnCopy(v); |
| 103077 | 103182 | sqlite3VdbeResolveLabel(v, endCoalesce); |
| 103078 | 103183 | break; |
| 103079 | 103184 | } |
| 103185 | + case INLINEFUNC_iif: { |
| 103186 | + Expr caseExpr; |
| 103187 | + memset(&caseExpr, 0, sizeof(caseExpr)); |
| 103188 | + caseExpr.op = TK_CASE; |
| 103189 | + caseExpr.x.pList = pFarg; |
| 103190 | + return sqlite3ExprCodeTarget(pParse, &caseExpr, target); |
| 103191 | + } |
| 103080 | 103192 | |
| 103081 | 103193 | default: { |
| 103082 | 103194 | /* The UNLIKELY() function is a no-op. The result is the value |
| 103083 | 103195 | ** of the first argument. |
| 103084 | 103196 | */ |
| | @@ -103179,11 +103291,14 @@ |
| 103179 | 103291 | op = pExpr->op; |
| 103180 | 103292 | } |
| 103181 | 103293 | switch( op ){ |
| 103182 | 103294 | case TK_AGG_COLUMN: { |
| 103183 | 103295 | AggInfo *pAggInfo = pExpr->pAggInfo; |
| 103184 | | - struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 103296 | + struct AggInfo_col *pCol; |
| 103297 | + assert( pAggInfo!=0 ); |
| 103298 | + assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn ); |
| 103299 | + pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 103185 | 103300 | if( !pAggInfo->directMode ){ |
| 103186 | 103301 | assert( pCol->iMem>0 ); |
| 103187 | 103302 | return pCol->iMem; |
| 103188 | 103303 | }else if( pAggInfo->useSortingIdx ){ |
| 103189 | 103304 | Table *pTab = pCol->pTab; |
| | @@ -103479,11 +103594,14 @@ |
| 103479 | 103594 | sqlite3VdbeJumpHere(v, addr); |
| 103480 | 103595 | break; |
| 103481 | 103596 | } |
| 103482 | 103597 | case TK_AGG_FUNCTION: { |
| 103483 | 103598 | AggInfo *pInfo = pExpr->pAggInfo; |
| 103484 | | - if( pInfo==0 ){ |
| 103599 | + if( pInfo==0 |
| 103600 | + || NEVER(pExpr->iAgg<0) |
| 103601 | + || NEVER(pExpr->iAgg>=pInfo->nFunc) |
| 103602 | + ){ |
| 103485 | 103603 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 103486 | 103604 | sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken); |
| 103487 | 103605 | }else{ |
| 103488 | 103606 | return pInfo->aFunc[pExpr->iAgg].iMem; |
| 103489 | 103607 | } |
| | @@ -105235,19 +105353,10 @@ |
| 105235 | 105353 | } |
| 105236 | 105354 | } |
| 105237 | 105355 | } |
| 105238 | 105356 | return WRC_Continue; |
| 105239 | 105357 | } |
| 105240 | | -static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ |
| 105241 | | - UNUSED_PARAMETER(pSelect); |
| 105242 | | - pWalker->walkerDepth++; |
| 105243 | | - return WRC_Continue; |
| 105244 | | -} |
| 105245 | | -static void analyzeAggregatesInSelectEnd(Walker *pWalker, Select *pSelect){ |
| 105246 | | - UNUSED_PARAMETER(pSelect); |
| 105247 | | - pWalker->walkerDepth--; |
| 105248 | | -} |
| 105249 | 105358 | |
| 105250 | 105359 | /* |
| 105251 | 105360 | ** Analyze the pExpr expression looking for aggregate functions and |
| 105252 | 105361 | ** for variables that need to be added to AggInfo object that pNC->pAggInfo |
| 105253 | 105362 | ** points to. Additional entries are made on the AggInfo object as |
| | @@ -105257,12 +105366,12 @@ |
| 105257 | 105366 | ** analyzed by sqlite3ResolveExprNames(). |
| 105258 | 105367 | */ |
| 105259 | 105368 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ |
| 105260 | 105369 | Walker w; |
| 105261 | 105370 | w.xExprCallback = analyzeAggregate; |
| 105262 | | - w.xSelectCallback = analyzeAggregatesInSelect; |
| 105263 | | - w.xSelectCallback2 = analyzeAggregatesInSelectEnd; |
| 105371 | + w.xSelectCallback = sqlite3WalkerDepthIncrease; |
| 105372 | + w.xSelectCallback2 = sqlite3WalkerDepthDecrease; |
| 105264 | 105373 | w.walkerDepth = 0; |
| 105265 | 105374 | w.u.pNC = pNC; |
| 105266 | 105375 | w.pParse = 0; |
| 105267 | 105376 | assert( pNC->pSrcList!=0 ); |
| 105268 | 105377 | sqlite3WalkExpr(&w, pExpr); |
| | @@ -105497,11 +105606,14 @@ |
| 105497 | 105606 | if( !zName ) goto exit_rename_table; |
| 105498 | 105607 | |
| 105499 | 105608 | /* Check that a table or index named 'zName' does not already exist |
| 105500 | 105609 | ** in database iDb. If so, this is an error. |
| 105501 | 105610 | */ |
| 105502 | | - if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){ |
| 105611 | + if( sqlite3FindTable(db, zName, zDb) |
| 105612 | + || sqlite3FindIndex(db, zName, zDb) |
| 105613 | + || sqlite3IsShadowTableOf(db, pTab, zName) |
| 105614 | + ){ |
| 105503 | 105615 | sqlite3ErrorMsg(pParse, |
| 105504 | 105616 | "there is already another table or index with this name: %s", zName); |
| 105505 | 105617 | goto exit_rename_table; |
| 105506 | 105618 | } |
| 105507 | 105619 | |
| | @@ -110244,26 +110356,43 @@ |
| 110244 | 110356 | ** exists */ |
| 110245 | 110357 | if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){ |
| 110246 | 110358 | return 0; |
| 110247 | 110359 | } |
| 110248 | 110360 | #endif |
| 110249 | | - while(1){ |
| 110250 | | - for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 110251 | | - int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 110252 | | - if( zDatabase==0 || sqlite3DbIsNamed(db, j, zDatabase) ){ |
| 110253 | | - assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 110254 | | - p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName); |
| 110255 | | - if( p ) return p; |
| 110256 | | - } |
| 110257 | | - } |
| 110258 | | - /* Not found. If the name we were looking for was temp.sqlite_master |
| 110259 | | - ** then change the name to sqlite_temp_master and try again. */ |
| 110260 | | - if( sqlite3StrICmp(zName, MASTER_NAME)!=0 ) break; |
| 110261 | | - if( sqlite3_stricmp(zDatabase, db->aDb[1].zDbSName)!=0 ) break; |
| 110262 | | - zName = TEMP_MASTER_NAME; |
| 110263 | | - } |
| 110264 | | - return 0; |
| 110361 | + if( zDatabase ){ |
| 110362 | + for(i=0; i<db->nDb; i++){ |
| 110363 | + if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break; |
| 110364 | + } |
| 110365 | + if( i>=db->nDb ){ |
| 110366 | + /* No match against the official names. But always match "main" |
| 110367 | + ** to schema 0 as a legacy fallback. */ |
| 110368 | + if( sqlite3StrICmp(zDatabase,"main")==0 ){ |
| 110369 | + i = 0; |
| 110370 | + }else{ |
| 110371 | + return 0; |
| 110372 | + } |
| 110373 | + } |
| 110374 | + p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110375 | + if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){ |
| 110376 | + /* All temp.sqlite_master to be an alias for sqlite_temp_master */ |
| 110377 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME); |
| 110378 | + } |
| 110379 | + }else{ |
| 110380 | + /* Match against TEMP first */ |
| 110381 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName); |
| 110382 | + if( p ) return p; |
| 110383 | + /* The main database is second */ |
| 110384 | + p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName); |
| 110385 | + if( p ) return p; |
| 110386 | + /* Attached databases are in order of attachment */ |
| 110387 | + for(i=2; i<db->nDb; i++){ |
| 110388 | + assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
| 110389 | + p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110390 | + if( p ) break; |
| 110391 | + } |
| 110392 | + } |
| 110393 | + return p; |
| 110265 | 110394 | } |
| 110266 | 110395 | |
| 110267 | 110396 | /* |
| 110268 | 110397 | ** Locate the in-memory structure that describes a particular database |
| 110269 | 110398 | ** table given the name of that table and (optionally) the name of the |
| | @@ -112063,10 +112192,32 @@ |
| 112063 | 112192 | assert( pPk->nColumn==j ); |
| 112064 | 112193 | assert( pTab->nNVCol<=j ); |
| 112065 | 112194 | recomputeColumnsNotIndexed(pPk); |
| 112066 | 112195 | } |
| 112067 | 112196 | |
| 112197 | + |
| 112198 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 112199 | +/* |
| 112200 | +** Return true if pTab is a virtual table and zName is a shadow table name |
| 112201 | +** for that virtual table. |
| 112202 | +*/ |
| 112203 | +SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3 *db, Table *pTab, const char *zName){ |
| 112204 | + int nName; /* Length of zName */ |
| 112205 | + Module *pMod; /* Module for the virtual table */ |
| 112206 | + |
| 112207 | + if( !IsVirtual(pTab) ) return 0; |
| 112208 | + nName = sqlite3Strlen30(pTab->zName); |
| 112209 | + if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0; |
| 112210 | + if( zName[nName]!='_' ) return 0; |
| 112211 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 112212 | + if( pMod==0 ) return 0; |
| 112213 | + if( pMod->pModule->iVersion<3 ) return 0; |
| 112214 | + if( pMod->pModule->xShadowName==0 ) return 0; |
| 112215 | + return pMod->pModule->xShadowName(zName+nName+1); |
| 112216 | +} |
| 112217 | +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 112218 | + |
| 112068 | 112219 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 112069 | 112220 | /* |
| 112070 | 112221 | ** Return true if zName is a shadow table name in the current database |
| 112071 | 112222 | ** connection. |
| 112072 | 112223 | ** |
| | @@ -112074,26 +112225,21 @@ |
| 112074 | 112225 | ** restored to its original value prior to this routine returning. |
| 112075 | 112226 | */ |
| 112076 | 112227 | SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){ |
| 112077 | 112228 | char *zTail; /* Pointer to the last "_" in zName */ |
| 112078 | 112229 | Table *pTab; /* Table that zName is a shadow of */ |
| 112079 | | - Module *pMod; /* Module for the virtual table */ |
| 112080 | | - |
| 112081 | 112230 | zTail = strrchr(zName, '_'); |
| 112082 | 112231 | if( zTail==0 ) return 0; |
| 112083 | 112232 | *zTail = 0; |
| 112084 | 112233 | pTab = sqlite3FindTable(db, zName, 0); |
| 112085 | 112234 | *zTail = '_'; |
| 112086 | 112235 | if( pTab==0 ) return 0; |
| 112087 | 112236 | if( !IsVirtual(pTab) ) return 0; |
| 112088 | | - pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 112089 | | - if( pMod==0 ) return 0; |
| 112090 | | - if( pMod->pModule->iVersion<3 ) return 0; |
| 112091 | | - if( pMod->pModule->xShadowName==0 ) return 0; |
| 112092 | | - return pMod->pModule->xShadowName(zTail+1); |
| 112237 | + return sqlite3IsShadowTableOf(db, pTab, zName); |
| 112093 | 112238 | } |
| 112094 | 112239 | #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 112240 | + |
| 112095 | 112241 | |
| 112096 | 112242 | #ifdef SQLITE_DEBUG |
| 112097 | 112243 | /* |
| 112098 | 112244 | ** Mark all nodes of an expression as EP_Immutable, indicating that |
| 112099 | 112245 | ** they should not be changed. Expressions attached to a table or |
| | @@ -117780,11 +117926,11 @@ |
| 117780 | 117926 | if( (cntExpand&(cntExpand-1))==0 ){ |
| 117781 | 117927 | /* Grow the size of the output buffer only on substitutions |
| 117782 | 117928 | ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */ |
| 117783 | 117929 | u8 *zOld; |
| 117784 | 117930 | zOld = zOut; |
| 117785 | | - zOut = sqlite3_realloc64(zOut, (int)nOut + (nOut - nStr - 1)); |
| 117931 | + zOut = sqlite3Realloc(zOut, (int)nOut + (nOut - nStr - 1)); |
| 117786 | 117932 | if( zOut==0 ){ |
| 117787 | 117933 | sqlite3_result_error_nomem(context); |
| 117788 | 117934 | sqlite3_free(zOld); |
| 117789 | 117935 | return; |
| 117790 | 117936 | } |
| | @@ -118477,11 +118623,11 @@ |
| 118477 | 118623 | FUNCTION(round, 2, 0, 0, roundFunc ), |
| 118478 | 118624 | #endif |
| 118479 | 118625 | FUNCTION(upper, 1, 0, 0, upperFunc ), |
| 118480 | 118626 | FUNCTION(lower, 1, 0, 0, lowerFunc ), |
| 118481 | 118627 | FUNCTION(hex, 1, 0, 0, hexFunc ), |
| 118482 | | - INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 118628 | + INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ), |
| 118483 | 118629 | VFUNCTION(random, 0, 0, 0, randomFunc ), |
| 118484 | 118630 | VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 118485 | 118631 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 118486 | 118632 | DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 118487 | 118633 | DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| | @@ -118517,11 +118663,12 @@ |
| 118517 | 118663 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 118518 | 118664 | FUNCTION(unknown, -1, 0, 0, unknownFunc ), |
| 118519 | 118665 | #endif |
| 118520 | 118666 | FUNCTION(coalesce, 1, 0, 0, 0 ), |
| 118521 | 118667 | FUNCTION(coalesce, 0, 0, 0, 0 ), |
| 118522 | | - INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 118668 | + INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ), |
| 118669 | + INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ), |
| 118523 | 118670 | }; |
| 118524 | 118671 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 118525 | 118672 | sqlite3AlterFunctions(); |
| 118526 | 118673 | #endif |
| 118527 | 118674 | sqlite3WindowFunctions(); |
| | @@ -121942,11 +122089,11 @@ |
| 121942 | 122089 | } |
| 121943 | 122090 | if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){ |
| 121944 | 122091 | sqlite3TableAffinity(v, pTab, regNewData+1); |
| 121945 | 122092 | bAffinityDone = 1; |
| 121946 | 122093 | } |
| 121947 | | - VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName)); |
| 122094 | + VdbeNoopComment((v, "prep index %s", pIdx->zName)); |
| 121948 | 122095 | iThisCur = iIdxCur+ix; |
| 121949 | 122096 | |
| 121950 | 122097 | |
| 121951 | 122098 | /* Skip partial indices for which the WHERE clause is not true */ |
| 121952 | 122099 | if( pIdx->pPartIdxWhere ){ |
| | @@ -133914,33 +134061,10 @@ |
| 133914 | 134061 | } |
| 133915 | 134062 | } |
| 133916 | 134063 | return WRC_Continue; |
| 133917 | 134064 | } |
| 133918 | 134065 | |
| 133919 | | -/* |
| 133920 | | -** No-op routine for the parse-tree walker. |
| 133921 | | -** |
| 133922 | | -** When this routine is the Walker.xExprCallback then expression trees |
| 133923 | | -** are walked without any actions being taken at each node. Presumably, |
| 133924 | | -** when this routine is used for Walker.xExprCallback then |
| 133925 | | -** Walker.xSelectCallback is set to do something useful for every |
| 133926 | | -** subquery in the parser tree. |
| 133927 | | -*/ |
| 133928 | | -SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker *NotUsed, Expr *NotUsed2){ |
| 133929 | | - UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 133930 | | - return WRC_Continue; |
| 133931 | | -} |
| 133932 | | - |
| 133933 | | -/* |
| 133934 | | -** No-op routine for the parse-tree walker for SELECT statements. |
| 133935 | | -** subquery in the parser tree. |
| 133936 | | -*/ |
| 133937 | | -SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker *NotUsed, Select *NotUsed2){ |
| 133938 | | - UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 133939 | | - return WRC_Continue; |
| 133940 | | -} |
| 133941 | | - |
| 133942 | 134066 | #if SQLITE_DEBUG |
| 133943 | 134067 | /* |
| 133944 | 134068 | ** Always assert. This xSelectCallback2 implementation proves that the |
| 133945 | 134069 | ** xSelectCallback2 is never invoked. |
| 133946 | 134070 | */ |
| | @@ -135107,11 +135231,11 @@ |
| 135107 | 135231 | sAggInfo.mxReg = pParse->nMem; |
| 135108 | 135232 | if( db->mallocFailed ) goto select_end; |
| 135109 | 135233 | #if SELECTTRACE_ENABLED |
| 135110 | 135234 | if( sqlite3SelectTrace & 0x400 ){ |
| 135111 | 135235 | int ii; |
| 135112 | | - SELECTTRACE(0x400,pParse,p,("After aggregate analysis:\n")); |
| 135236 | + SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", &sAggInfo)); |
| 135113 | 135237 | sqlite3TreeViewSelect(0, p, 0); |
| 135114 | 135238 | for(ii=0; ii<sAggInfo.nColumn; ii++){ |
| 135115 | 135239 | sqlite3DebugPrintf("agg-column[%d] iMem=%d\n", |
| 135116 | 135240 | ii, sAggInfo.aCol[ii].iMem); |
| 135117 | 135241 | sqlite3TreeViewExpr(0, sAggInfo.aCol[ii].pExpr, 0); |
| | @@ -135570,11 +135694,11 @@ |
| 135570 | 135694 | need = nCol; |
| 135571 | 135695 | } |
| 135572 | 135696 | if( p->nData + need > p->nAlloc ){ |
| 135573 | 135697 | char **azNew; |
| 135574 | 135698 | p->nAlloc = p->nAlloc*2 + need; |
| 135575 | | - azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc ); |
| 135699 | + azNew = sqlite3Realloc( p->azResult, sizeof(char*)*p->nAlloc ); |
| 135576 | 135700 | if( azNew==0 ) goto malloc_failed; |
| 135577 | 135701 | p->azResult = azNew; |
| 135578 | 135702 | } |
| 135579 | 135703 | |
| 135580 | 135704 | /* If this is the first row, then generate an extra row containing |
| | @@ -135679,11 +135803,11 @@ |
| 135679 | 135803 | sqlite3_free_table(&res.azResult[1]); |
| 135680 | 135804 | return rc; |
| 135681 | 135805 | } |
| 135682 | 135806 | if( res.nAlloc>res.nData ){ |
| 135683 | 135807 | char **azNew; |
| 135684 | | - azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); |
| 135808 | + azNew = sqlite3Realloc( res.azResult, sizeof(char*)*res.nData ); |
| 135685 | 135809 | if( azNew==0 ){ |
| 135686 | 135810 | sqlite3_free_table(&res.azResult[1]); |
| 135687 | 135811 | db->errCode = SQLITE_NOMEM; |
| 135688 | 135812 | return SQLITE_NOMEM_BKPT; |
| 135689 | 135813 | } |
| | @@ -136969,14 +137093,14 @@ |
| 136969 | 137093 | ** Therefore, the P4 parameter is only required if the default value for |
| 136970 | 137094 | ** the column is a literal number, string or null. The sqlite3ValueFromExpr() |
| 136971 | 137095 | ** function is capable of transforming these types of expressions into |
| 136972 | 137096 | ** sqlite3_value objects. |
| 136973 | 137097 | ** |
| 136974 | | -** If parameter iReg is not negative, code an OP_RealAffinity instruction |
| 136975 | | -** on register iReg. This is used when an equivalent integer value is |
| 136976 | | -** stored in place of an 8-byte floating point value in order to save |
| 136977 | | -** space. |
| 137098 | +** If column as REAL affinity and the table is an ordinary b-tree table |
| 137099 | +** (not a virtual table) then the value might have been stored as an |
| 137100 | +** integer. In that case, add an OP_RealAffinity opcode to make sure |
| 137101 | +** it has been converted into REAL. |
| 136978 | 137102 | */ |
| 136979 | 137103 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ |
| 136980 | 137104 | assert( pTab!=0 ); |
| 136981 | 137105 | if( !pTab->pSelect ){ |
| 136982 | 137106 | sqlite3_value *pValue = 0; |
| | @@ -136989,11 +137113,11 @@ |
| 136989 | 137113 | if( pValue ){ |
| 136990 | 137114 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 136991 | 137115 | } |
| 136992 | 137116 | } |
| 136993 | 137117 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 136994 | | - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 137118 | + if( pTab->aCol[i].affinity==SQLITE_AFF_REAL && !IsVirtual(pTab) ){ |
| 136995 | 137119 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 136996 | 137120 | } |
| 136997 | 137121 | #endif |
| 136998 | 137122 | } |
| 136999 | 137123 | |
| | @@ -139838,11 +139962,11 @@ |
| 139838 | 139962 | assert( IsVirtual(pTab) ); |
| 139839 | 139963 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 139840 | 139964 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 139841 | 139965 | } |
| 139842 | 139966 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 139843 | | - apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n); |
| 139967 | + apVtabLock = sqlite3Realloc(pToplevel->apVtabLock, n); |
| 139844 | 139968 | if( apVtabLock ){ |
| 139845 | 139969 | pToplevel->apVtabLock = apVtabLock; |
| 139846 | 139970 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 139847 | 139971 | }else{ |
| 139848 | 139972 | sqlite3OomFault(pToplevel->db); |
| | @@ -151130,24 +151254,47 @@ |
| 151130 | 151254 | ){ |
| 151131 | 151255 | if( pAppend ){ |
| 151132 | 151256 | int i; |
| 151133 | 151257 | int nInit = pList ? pList->nExpr : 0; |
| 151134 | 151258 | for(i=0; i<pAppend->nExpr; i++){ |
| 151135 | | - int iDummy; |
| 151136 | 151259 | Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0); |
| 151137 | 151260 | assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) ); |
| 151138 | | - if( bIntToNull && pDup && sqlite3ExprIsInteger(pDup, &iDummy) ){ |
| 151139 | | - pDup->op = TK_NULL; |
| 151140 | | - pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 151141 | | - pDup->u.zToken = 0; |
| 151261 | + if( bIntToNull && pDup ){ |
| 151262 | + int iDummy; |
| 151263 | + Expr *pSub; |
| 151264 | + for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){ |
| 151265 | + assert( pSub ); |
| 151266 | + } |
| 151267 | + if( sqlite3ExprIsInteger(pSub, &iDummy) ){ |
| 151268 | + pSub->op = TK_NULL; |
| 151269 | + pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 151270 | + pSub->u.zToken = 0; |
| 151271 | + } |
| 151142 | 151272 | } |
| 151143 | 151273 | pList = sqlite3ExprListAppend(pParse, pList, pDup); |
| 151144 | 151274 | if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags; |
| 151145 | 151275 | } |
| 151146 | 151276 | } |
| 151147 | 151277 | return pList; |
| 151148 | 151278 | } |
| 151279 | + |
| 151280 | +/* |
| 151281 | +** When rewriting a query, if the new subquery in the FROM clause |
| 151282 | +** contains TK_AGG_FUNCTION nodes that refer to an outer query, |
| 151283 | +** then we have to increase the Expr->op2 values of those nodes |
| 151284 | +** due to the extra subquery layer that was added. |
| 151285 | +** |
| 151286 | +** See also the incrAggDepth() routine in resolve.c |
| 151287 | +*/ |
| 151288 | +static int sqlite3WindowExtraAggFuncDepth(Walker *pWalker, Expr *pExpr){ |
| 151289 | + if( pExpr->op==TK_AGG_FUNCTION |
| 151290 | + && pExpr->op2>=pWalker->walkerDepth |
| 151291 | + ){ |
| 151292 | + pExpr->op2++; |
| 151293 | + } |
| 151294 | + return WRC_Continue; |
| 151295 | +} |
| 151149 | 151296 | |
| 151150 | 151297 | /* |
| 151151 | 151298 | ** If the SELECT statement passed as the second argument does not invoke |
| 151152 | 151299 | ** any SQL window functions, this function is a no-op. Otherwise, it |
| 151153 | 151300 | ** rewrites the SELECT statement so that window function xStep functions |
| | @@ -151254,10 +151401,11 @@ |
| 151254 | 151401 | pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0 |
| 151255 | 151402 | ); |
| 151256 | 151403 | p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0); |
| 151257 | 151404 | if( p->pSrc ){ |
| 151258 | 151405 | Table *pTab2; |
| 151406 | + Walker w; |
| 151259 | 151407 | p->pSrc->a[0].pSelect = pSub; |
| 151260 | 151408 | sqlite3SrcListAssignCursors(pParse, p->pSrc); |
| 151261 | 151409 | pSub->selFlags |= SF_Expanded; |
| 151262 | 151410 | pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE); |
| 151263 | 151411 | pSub->selFlags |= (selFlags & SF_Aggregate); |
| | @@ -151269,10 +151417,15 @@ |
| 151269 | 151417 | }else{ |
| 151270 | 151418 | memcpy(pTab, pTab2, sizeof(Table)); |
| 151271 | 151419 | pTab->tabFlags |= TF_Ephemeral; |
| 151272 | 151420 | p->pSrc->a[0].pTab = pTab; |
| 151273 | 151421 | pTab = pTab2; |
| 151422 | + memset(&w, 0, sizeof(w)); |
| 151423 | + w.xExprCallback = sqlite3WindowExtraAggFuncDepth; |
| 151424 | + w.xSelectCallback = sqlite3WalkerDepthIncrease; |
| 151425 | + w.xSelectCallback2 = sqlite3WalkerDepthDecrease; |
| 151426 | + sqlite3WalkSelect(&w, pSub); |
| 151274 | 151427 | } |
| 151275 | 151428 | }else{ |
| 151276 | 151429 | sqlite3SelectDelete(db, pSub); |
| 151277 | 151430 | } |
| 151278 | 151431 | if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| | @@ -160322,10 +160475,11 @@ |
| 160322 | 160475 | } |
| 160323 | 160476 | #endif |
| 160324 | 160477 | if( rc==SQLITE_OK ){ |
| 160325 | 160478 | sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, |
| 160326 | 160479 | sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); |
| 160480 | + sqlite3MemoryBarrier(); |
| 160327 | 160481 | sqlite3GlobalConfig.isInit = 1; |
| 160328 | 160482 | #ifdef SQLITE_EXTRA_INIT |
| 160329 | 160483 | bRunExtraInit = 1; |
| 160330 | 160484 | #endif |
| 160331 | 160485 | } |
| | @@ -163270,11 +163424,11 @@ |
| 163270 | 163424 | assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 163271 | 163425 | testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 163272 | 163426 | testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 163273 | 163427 | testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 163274 | 163428 | if( ((1<<(flags&7)) & 0x46)==0 ){ |
| 163275 | | - rc = SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */ |
| 163429 | + rc = SQLITE_MISUSE_BKPT; /* IMP: R-18321-05872 */ |
| 163276 | 163430 | }else{ |
| 163277 | 163431 | rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); |
| 163278 | 163432 | } |
| 163279 | 163433 | if( rc!=SQLITE_OK ){ |
| 163280 | 163434 | if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
| | @@ -171194,10 +171348,11 @@ |
| 171194 | 171348 | while( *pRc==SQLITE_OK && pLeft->bEof==0 ){ |
| 171195 | 171349 | memset(pDl->pList, 0, pDl->nList); |
| 171196 | 171350 | fts3EvalNextRow(pCsr, pLeft, pRc); |
| 171197 | 171351 | } |
| 171198 | 171352 | } |
| 171353 | + pRight->bEof = pLeft->bEof = 1; |
| 171199 | 171354 | } |
| 171200 | 171355 | } |
| 171201 | 171356 | break; |
| 171202 | 171357 | } |
| 171203 | 171358 | |
| | @@ -182739,11 +182894,11 @@ |
| 182739 | 182894 | iStart = pExpr->iPhrase * p->nCol; |
| 182740 | 182895 | }else{ |
| 182741 | 182896 | iStart = pExpr->iPhrase * ((p->nCol + 31) / 32); |
| 182742 | 182897 | } |
| 182743 | 182898 | |
| 182744 | | - while( 1 ){ |
| 182899 | + if( pIter ) while( 1 ){ |
| 182745 | 182900 | int nHit = fts3ColumnlistCount(&pIter); |
| 182746 | 182901 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 182747 | 182902 | if( p->flag==FTS3_MATCHINFO_LHITS ){ |
| 182748 | 182903 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 182749 | 182904 | }else if( nHit ){ |
| | @@ -184653,10 +184808,11 @@ |
| 184653 | 184808 | } |
| 184654 | 184809 | |
| 184655 | 184810 | /* Append N bytes from zIn onto the end of the JsonString string. |
| 184656 | 184811 | */ |
| 184657 | 184812 | static void jsonAppendRaw(JsonString *p, const char *zIn, u32 N){ |
| 184813 | + if( N==0 ) return; |
| 184658 | 184814 | if( (N+p->nUsed >= p->nAlloc) && jsonGrow(p,N)!=0 ) return; |
| 184659 | 184815 | memcpy(p->zBuf+p->nUsed, zIn, N); |
| 184660 | 184816 | p->nUsed += N; |
| 184661 | 184817 | } |
| 184662 | 184818 | |
| | @@ -224664,11 +224820,11 @@ |
| 224664 | 224820 | int nArg, /* Number of args */ |
| 224665 | 224821 | sqlite3_value **apUnused /* Function arguments */ |
| 224666 | 224822 | ){ |
| 224667 | 224823 | assert( nArg==0 ); |
| 224668 | 224824 | UNUSED_PARAM2(nArg, apUnused); |
| 224669 | | - sqlite3_result_text(pCtx, "fts5: 2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff", -1, SQLITE_TRANSIENT); |
| 224825 | + sqlite3_result_text(pCtx, "fts5: 2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba83350", -1, SQLITE_TRANSIENT); |
| 224670 | 224826 | } |
| 224671 | 224827 | |
| 224672 | 224828 | /* |
| 224673 | 224829 | ** Return true if zName is the extension on one of the shadow tables used |
| 224674 | 224830 | ** by this module. |
| | @@ -229447,12 +229603,12 @@ |
| 229447 | 229603 | } |
| 229448 | 229604 | #endif /* SQLITE_CORE */ |
| 229449 | 229605 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229450 | 229606 | |
| 229451 | 229607 | /************** End of stmt.c ************************************************/ |
| 229452 | | -#if __LINE__!=229452 |
| 229608 | +#if __LINE__!=229608 |
| 229453 | 229609 | #undef SQLITE_SOURCE_ID |
| 229454 | | -#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f96alt2" |
| 229610 | +#define SQLITE_SOURCE_ID "2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba8alt2" |
| 229455 | 229611 | #endif |
| 229456 | 229612 | /* Return the source-id for this library */ |
| 229457 | 229613 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229458 | 229614 | /************************** End of sqlite3.c ******************************/ |
| 229459 | 229615 | |