| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" |
| 1167 | +#define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469f8ece" |
| 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. |
| | @@ -20064,12 +20065,14 @@ |
| 20064 | 20065 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 20065 | 20066 | #endif |
| 20066 | 20067 | SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db); |
| 20067 | 20068 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 20068 | 20069 | SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName); |
| 20070 | +SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); |
| 20069 | 20071 | #else |
| 20070 | 20072 | # define sqlite3ShadowTableName(A,B) 0 |
| 20073 | +# define sqlite3IsShadowTableOf(A,B,C) 0 |
| 20071 | 20074 | #endif |
| 20072 | 20075 | SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*); |
| 20073 | 20076 | SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*); |
| 20074 | 20077 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 20075 | 20078 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); |
| | @@ -27924,11 +27927,11 @@ |
| 27924 | 27927 | } |
| 27925 | 27928 | }else{ |
| 27926 | 27929 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27927 | 27930 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27928 | 27931 | sqlite3MemdebugSetType(p, MEMTYPE_HEAP); |
| 27929 | | - pNew = sqlite3_realloc64(p, n); |
| 27932 | + pNew = sqlite3Realloc(p, n); |
| 27930 | 27933 | if( !pNew ){ |
| 27931 | 27934 | sqlite3OomFault(db); |
| 27932 | 27935 | } |
| 27933 | 27936 | sqlite3MemdebugSetType(pNew, |
| 27934 | 27937 | (db->lookaside.bDisable==0 ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); |
| | @@ -29001,11 +29004,11 @@ |
| 29001 | 29004 | p->nAlloc = (int)szNew; |
| 29002 | 29005 | } |
| 29003 | 29006 | if( p->db ){ |
| 29004 | 29007 | zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); |
| 29005 | 29008 | }else{ |
| 29006 | | - zNew = sqlite3_realloc64(zOld, p->nAlloc); |
| 29009 | + zNew = sqlite3Realloc(zOld, p->nAlloc); |
| 29007 | 29010 | } |
| 29008 | 29011 | if( zNew ){ |
| 29009 | 29012 | assert( p->zText!=0 || p->nChar==0 ); |
| 29010 | 29013 | if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 29011 | 29014 | p->zText = zNew; |
| | @@ -29343,11 +29346,11 @@ |
| 29343 | 29346 | ** and segfaults if you give it a long long int. |
| 29344 | 29347 | */ |
| 29345 | 29348 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ |
| 29346 | 29349 | va_list ap; |
| 29347 | 29350 | StrAccum acc; |
| 29348 | | - char zBuf[500]; |
| 29351 | + char zBuf[SQLITE_PRINT_BUF_SIZE*10]; |
| 29349 | 29352 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 29350 | 29353 | va_start(ap,zFormat); |
| 29351 | 29354 | sqlite3_str_vappendf(&acc, zFormat, ap); |
| 29352 | 29355 | va_end(ap); |
| 29353 | 29356 | sqlite3StrAccumFinish(&acc); |
| | @@ -45048,10 +45051,11 @@ |
| 45048 | 45051 | } |
| 45049 | 45052 | |
| 45050 | 45053 | /* Forward references to VFS helper methods used for temporary files */ |
| 45051 | 45054 | static int winGetTempname(sqlite3_vfs *, char **); |
| 45052 | 45055 | static int winIsDir(const void *); |
| 45056 | +static BOOL winIsLongPathPrefix(const char *); |
| 45053 | 45057 | static BOOL winIsDriveLetterAndColon(const char *); |
| 45054 | 45058 | |
| 45055 | 45059 | /* |
| 45056 | 45060 | ** Control and query of the open file handle. |
| 45057 | 45061 | */ |
| | @@ -47026,10 +47030,21 @@ |
| 47026 | 47030 | *pResOut = rc; |
| 47027 | 47031 | OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n", |
| 47028 | 47032 | zFilename, pResOut, *pResOut)); |
| 47029 | 47033 | return SQLITE_OK; |
| 47030 | 47034 | } |
| 47035 | + |
| 47036 | +/* |
| 47037 | +** Returns non-zero if the specified path name starts with the "long path" |
| 47038 | +** prefix. |
| 47039 | +*/ |
| 47040 | +static BOOL winIsLongPathPrefix( |
| 47041 | + const char *zPathname |
| 47042 | +){ |
| 47043 | + return ( zPathname[0]=='\\' && zPathname[1]=='\\' |
| 47044 | + && zPathname[2]=='?' && zPathname[3]=='\\' ); |
| 47045 | +} |
| 47031 | 47046 | |
| 47032 | 47047 | /* |
| 47033 | 47048 | ** Returns non-zero if the specified path name starts with a drive letter |
| 47034 | 47049 | ** followed by a colon character. |
| 47035 | 47050 | */ |
| | @@ -47091,14 +47106,15 @@ |
| 47091 | 47106 | DWORD nByte; |
| 47092 | 47107 | void *zConverted; |
| 47093 | 47108 | char *zOut; |
| 47094 | 47109 | #endif |
| 47095 | 47110 | |
| 47096 | | - /* If this path name begins with "/X:", where "X" is any alphabetic |
| 47097 | | - ** character, discard the initial "/" from the pathname. |
| 47111 | + /* If this path name begins with "/X:" or "\\?\", where "X" is any |
| 47112 | + ** alphabetic character, discard the initial "/" from the pathname. |
| 47098 | 47113 | */ |
| 47099 | | - if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){ |
| 47114 | + if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1) |
| 47115 | + || winIsLongPathPrefix(zRelative+1)) ){ |
| 47100 | 47116 | zRelative++; |
| 47101 | 47117 | } |
| 47102 | 47118 | |
| 47103 | 47119 | #if defined(__CYGWIN__) |
| 47104 | 47120 | SimulateIOError( return SQLITE_ERROR ); |
| | @@ -47850,11 +47866,11 @@ |
| 47850 | 47866 | if( newSz>p->szMax ){ |
| 47851 | 47867 | return SQLITE_FULL; |
| 47852 | 47868 | } |
| 47853 | 47869 | newSz *= 2; |
| 47854 | 47870 | if( newSz>p->szMax ) newSz = p->szMax; |
| 47855 | | - pNew = sqlite3_realloc64(p->aData, newSz); |
| 47871 | + pNew = sqlite3Realloc(p->aData, newSz); |
| 47856 | 47872 | if( pNew==0 ) return SQLITE_NOMEM; |
| 47857 | 47873 | p->aData = pNew; |
| 47858 | 47874 | p->szAlloc = newSz; |
| 47859 | 47875 | return SQLITE_OK; |
| 47860 | 47876 | } |
| | @@ -59820,11 +59836,11 @@ |
| 59820 | 59836 | |
| 59821 | 59837 | /* Enlarge the pWal->apWiData[] array if required */ |
| 59822 | 59838 | if( pWal->nWiData<=iPage ){ |
| 59823 | 59839 | sqlite3_int64 nByte = sizeof(u32*)*(iPage+1); |
| 59824 | 59840 | volatile u32 **apNew; |
| 59825 | | - apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 59841 | + apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte); |
| 59826 | 59842 | if( !apNew ){ |
| 59827 | 59843 | *ppPage = 0; |
| 59828 | 59844 | return SQLITE_NOMEM_BKPT; |
| 59829 | 59845 | } |
| 59830 | 59846 | memset((void*)&apNew[pWal->nWiData], 0, |
| | @@ -61074,11 +61090,11 @@ |
| 61074 | 61090 | pWal->nCkpt++; |
| 61075 | 61091 | pWal->hdr.mxFrame = 0; |
| 61076 | 61092 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 61077 | 61093 | memcpy(&pWal->hdr.aSalt[1], &salt1, 4); |
| 61078 | 61094 | walIndexWriteHdr(pWal); |
| 61079 | | - pInfo->nBackfill = 0; |
| 61095 | + AtomicStore(&pInfo->nBackfill, 0); |
| 61080 | 61096 | pInfo->nBackfillAttempted = 0; |
| 61081 | 61097 | pInfo->aReadMark[1] = 0; |
| 61082 | 61098 | for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; |
| 61083 | 61099 | assert( pInfo->aReadMark[0]==0 ); |
| 61084 | 61100 | } |
| | @@ -61248,11 +61264,11 @@ |
| 61248 | 61264 | if( rc==SQLITE_OK ){ |
| 61249 | 61265 | rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 61250 | 61266 | } |
| 61251 | 61267 | } |
| 61252 | 61268 | if( rc==SQLITE_OK ){ |
| 61253 | | - pInfo->nBackfill = mxSafeFrame; |
| 61269 | + AtomicStore(&pInfo->nBackfill, mxSafeFrame); |
| 61254 | 61270 | } |
| 61255 | 61271 | } |
| 61256 | 61272 | |
| 61257 | 61273 | /* Release the reader lock held while backfilling */ |
| 61258 | 61274 | walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1); |
| | @@ -61871,11 +61887,11 @@ |
| 61871 | 61887 | } |
| 61872 | 61888 | |
| 61873 | 61889 | assert( pWal->nWiData>0 ); |
| 61874 | 61890 | assert( pWal->apWiData[0]!=0 ); |
| 61875 | 61891 | pInfo = walCkptInfo(pWal); |
| 61876 | | - if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame |
| 61892 | + if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame |
| 61877 | 61893 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61878 | 61894 | && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0) |
| 61879 | 61895 | #endif |
| 61880 | 61896 | ){ |
| 61881 | 61897 | /* The WAL has been completely backfilled (or it is empty). |
| | @@ -62038,11 +62054,11 @@ |
| 62038 | 62054 | void *pBuf2 = sqlite3_malloc(szPage); |
| 62039 | 62055 | if( pBuf1==0 || pBuf2==0 ){ |
| 62040 | 62056 | rc = SQLITE_NOMEM; |
| 62041 | 62057 | }else{ |
| 62042 | 62058 | u32 i = pInfo->nBackfillAttempted; |
| 62043 | | - for(i=pInfo->nBackfillAttempted; i>pInfo->nBackfill; i--){ |
| 62059 | + for(i=pInfo->nBackfillAttempted; i>AtomicLoad(&pInfo->nBackfill); i--){ |
| 62044 | 62060 | WalHashLoc sLoc; /* Hash table location */ |
| 62045 | 62061 | u32 pgno; /* Page number in db file */ |
| 62046 | 62062 | i64 iDbOff; /* Offset of db file entry */ |
| 62047 | 62063 | i64 iWalOff; /* Offset of wal file entry */ |
| 62048 | 62064 | |
| | @@ -79307,10 +79323,11 @@ |
| 79307 | 79323 | char *zP4; |
| 79308 | 79324 | char *zCom; |
| 79309 | 79325 | sqlite3 dummyDb; |
| 79310 | 79326 | static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n"; |
| 79311 | 79327 | if( pOut==0 ) pOut = stdout; |
| 79328 | + sqlite3BeginBenignMalloc(); |
| 79312 | 79329 | dummyDb.mallocFailed = 1; |
| 79313 | 79330 | zP4 = sqlite3VdbeDisplayP4(&dummyDb, pOp); |
| 79314 | 79331 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 79315 | 79332 | zCom = sqlite3VdbeDisplayComment(0, pOp, zP4); |
| 79316 | 79333 | #else |
| | @@ -79325,10 +79342,11 @@ |
| 79325 | 79342 | zCom ? zCom : "" |
| 79326 | 79343 | ); |
| 79327 | 79344 | fflush(pOut); |
| 79328 | 79345 | sqlite3_free(zP4); |
| 79329 | 79346 | sqlite3_free(zCom); |
| 79347 | + sqlite3EndBenignMalloc(); |
| 79330 | 79348 | } |
| 79331 | 79349 | #endif |
| 79332 | 79350 | |
| 79333 | 79351 | /* |
| 79334 | 79352 | ** Initialize an array of N Mem element. |
| | @@ -84066,11 +84084,11 @@ |
| 84066 | 84084 | p->db->errCode = SQLITE_OK; |
| 84067 | 84085 | |
| 84068 | 84086 | /* If the bit corresponding to this variable in Vdbe.expmask is set, then |
| 84069 | 84087 | ** binding a new value to this variable invalidates the current query plan. |
| 84070 | 84088 | ** |
| 84071 | | - ** IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host |
| 84089 | + ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host |
| 84072 | 84090 | ** parameter in the WHERE clause might influence the choice of query plan |
| 84073 | 84091 | ** for a statement, then the statement will be automatically recompiled, |
| 84074 | 84092 | ** as if there had been a schema change, on the first sqlite3_step() call |
| 84075 | 84093 | ** following any change to the bindings of that parameter. |
| 84076 | 84094 | */ |
| | @@ -96365,12 +96383,12 @@ |
| 96365 | 96383 | ************************************************************************* |
| 96366 | 96384 | ** |
| 96367 | 96385 | ** This file implements virtual-tables for examining the bytecode content |
| 96368 | 96386 | ** of a prepared statement. |
| 96369 | 96387 | */ |
| 96370 | | -#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 96371 | 96388 | /* #include "sqliteInt.h" */ |
| 96389 | +#if defined(SQLITE_ENABLE_BYTECODE_VTAB) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 96372 | 96390 | /* #include "vdbeInt.h" */ |
| 96373 | 96391 | |
| 96374 | 96392 | /* An instance of the bytecode() table-valued function. |
| 96375 | 96393 | */ |
| 96376 | 96394 | typedef struct bytecodevtab bytecodevtab; |
| | @@ -96771,10 +96789,12 @@ |
| 96771 | 96789 | if( rc==SQLITE_OK ){ |
| 96772 | 96790 | rc = sqlite3_create_module(db, "tables_used", &bytecodevtabModule, &db); |
| 96773 | 96791 | } |
| 96774 | 96792 | return rc; |
| 96775 | 96793 | } |
| 96794 | +#elif defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 96795 | +SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3 *db){ return SQLITE_OK; } |
| 96776 | 96796 | #endif /* SQLITE_ENABLE_BYTECODE_VTAB */ |
| 96777 | 96797 | |
| 96778 | 96798 | /************** End of vdbevtab.c ********************************************/ |
| 96779 | 96799 | /************** Begin file memjournal.c **************************************/ |
| 96780 | 96800 | /* |
| | @@ -103075,10 +103095,17 @@ |
| 103075 | 103095 | } |
| 103076 | 103096 | setDoNotMergeFlagOnCopy(v); |
| 103077 | 103097 | sqlite3VdbeResolveLabel(v, endCoalesce); |
| 103078 | 103098 | break; |
| 103079 | 103099 | } |
| 103100 | + case INLINEFUNC_iif: { |
| 103101 | + Expr caseExpr; |
| 103102 | + memset(&caseExpr, 0, sizeof(caseExpr)); |
| 103103 | + caseExpr.op = TK_CASE; |
| 103104 | + caseExpr.x.pList = pFarg; |
| 103105 | + return sqlite3ExprCodeTarget(pParse, &caseExpr, target); |
| 103106 | + } |
| 103080 | 103107 | |
| 103081 | 103108 | default: { |
| 103082 | 103109 | /* The UNLIKELY() function is a no-op. The result is the value |
| 103083 | 103110 | ** of the first argument. |
| 103084 | 103111 | */ |
| | @@ -105497,11 +105524,14 @@ |
| 105497 | 105524 | if( !zName ) goto exit_rename_table; |
| 105498 | 105525 | |
| 105499 | 105526 | /* Check that a table or index named 'zName' does not already exist |
| 105500 | 105527 | ** in database iDb. If so, this is an error. |
| 105501 | 105528 | */ |
| 105502 | | - if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){ |
| 105529 | + if( sqlite3FindTable(db, zName, zDb) |
| 105530 | + || sqlite3FindIndex(db, zName, zDb) |
| 105531 | + || sqlite3IsShadowTableOf(db, pTab, zName) |
| 105532 | + ){ |
| 105503 | 105533 | sqlite3ErrorMsg(pParse, |
| 105504 | 105534 | "there is already another table or index with this name: %s", zName); |
| 105505 | 105535 | goto exit_rename_table; |
| 105506 | 105536 | } |
| 105507 | 105537 | |
| | @@ -110244,26 +110274,43 @@ |
| 110244 | 110274 | ** exists */ |
| 110245 | 110275 | if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){ |
| 110246 | 110276 | return 0; |
| 110247 | 110277 | } |
| 110248 | 110278 | #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; |
| 110279 | + if( zDatabase ){ |
| 110280 | + for(i=0; i<db->nDb; i++){ |
| 110281 | + if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break; |
| 110282 | + } |
| 110283 | + if( i>=db->nDb ){ |
| 110284 | + /* No match against the official names. But always match "main" |
| 110285 | + ** to schema 0 as a legacy fallback. */ |
| 110286 | + if( sqlite3StrICmp(zDatabase,"main")==0 ){ |
| 110287 | + i = 0; |
| 110288 | + }else{ |
| 110289 | + return 0; |
| 110290 | + } |
| 110291 | + } |
| 110292 | + p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110293 | + if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){ |
| 110294 | + /* All temp.sqlite_master to be an alias for sqlite_temp_master */ |
| 110295 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME); |
| 110296 | + } |
| 110297 | + }else{ |
| 110298 | + /* Match against TEMP first */ |
| 110299 | + p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName); |
| 110300 | + if( p ) return p; |
| 110301 | + /* The main database is second */ |
| 110302 | + p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName); |
| 110303 | + if( p ) return p; |
| 110304 | + /* Attached databases are in order of attachment */ |
| 110305 | + for(i=2; i<db->nDb; i++){ |
| 110306 | + assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
| 110307 | + p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 110308 | + if( p ) break; |
| 110309 | + } |
| 110310 | + } |
| 110311 | + return p; |
| 110265 | 110312 | } |
| 110266 | 110313 | |
| 110267 | 110314 | /* |
| 110268 | 110315 | ** Locate the in-memory structure that describes a particular database |
| 110269 | 110316 | ** table given the name of that table and (optionally) the name of the |
| | @@ -112063,10 +112110,32 @@ |
| 112063 | 112110 | assert( pPk->nColumn==j ); |
| 112064 | 112111 | assert( pTab->nNVCol<=j ); |
| 112065 | 112112 | recomputeColumnsNotIndexed(pPk); |
| 112066 | 112113 | } |
| 112067 | 112114 | |
| 112115 | + |
| 112116 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 112117 | +/* |
| 112118 | +** Return true if pTab is a virtual table and zName is a shadow table name |
| 112119 | +** for that virtual table. |
| 112120 | +*/ |
| 112121 | +SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3 *db, Table *pTab, const char *zName){ |
| 112122 | + int nName; /* Length of zName */ |
| 112123 | + Module *pMod; /* Module for the virtual table */ |
| 112124 | + |
| 112125 | + if( !IsVirtual(pTab) ) return 0; |
| 112126 | + nName = sqlite3Strlen30(pTab->zName); |
| 112127 | + if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0; |
| 112128 | + if( zName[nName]!='_' ) return 0; |
| 112129 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 112130 | + if( pMod==0 ) return 0; |
| 112131 | + if( pMod->pModule->iVersion<3 ) return 0; |
| 112132 | + if( pMod->pModule->xShadowName==0 ) return 0; |
| 112133 | + return pMod->pModule->xShadowName(zName+nName+1); |
| 112134 | +} |
| 112135 | +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 112136 | + |
| 112068 | 112137 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 112069 | 112138 | /* |
| 112070 | 112139 | ** Return true if zName is a shadow table name in the current database |
| 112071 | 112140 | ** connection. |
| 112072 | 112141 | ** |
| | @@ -112074,26 +112143,21 @@ |
| 112074 | 112143 | ** restored to its original value prior to this routine returning. |
| 112075 | 112144 | */ |
| 112076 | 112145 | SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){ |
| 112077 | 112146 | char *zTail; /* Pointer to the last "_" in zName */ |
| 112078 | 112147 | Table *pTab; /* Table that zName is a shadow of */ |
| 112079 | | - Module *pMod; /* Module for the virtual table */ |
| 112080 | | - |
| 112081 | 112148 | zTail = strrchr(zName, '_'); |
| 112082 | 112149 | if( zTail==0 ) return 0; |
| 112083 | 112150 | *zTail = 0; |
| 112084 | 112151 | pTab = sqlite3FindTable(db, zName, 0); |
| 112085 | 112152 | *zTail = '_'; |
| 112086 | 112153 | if( pTab==0 ) return 0; |
| 112087 | 112154 | 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); |
| 112155 | + return sqlite3IsShadowTableOf(db, pTab, zName); |
| 112093 | 112156 | } |
| 112094 | 112157 | #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 112158 | + |
| 112095 | 112159 | |
| 112096 | 112160 | #ifdef SQLITE_DEBUG |
| 112097 | 112161 | /* |
| 112098 | 112162 | ** Mark all nodes of an expression as EP_Immutable, indicating that |
| 112099 | 112163 | ** they should not be changed. Expressions attached to a table or |
| | @@ -117780,11 +117844,11 @@ |
| 117780 | 117844 | if( (cntExpand&(cntExpand-1))==0 ){ |
| 117781 | 117845 | /* Grow the size of the output buffer only on substitutions |
| 117782 | 117846 | ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */ |
| 117783 | 117847 | u8 *zOld; |
| 117784 | 117848 | zOld = zOut; |
| 117785 | | - zOut = sqlite3_realloc64(zOut, (int)nOut + (nOut - nStr - 1)); |
| 117849 | + zOut = sqlite3Realloc(zOut, (int)nOut + (nOut - nStr - 1)); |
| 117786 | 117850 | if( zOut==0 ){ |
| 117787 | 117851 | sqlite3_result_error_nomem(context); |
| 117788 | 117852 | sqlite3_free(zOld); |
| 117789 | 117853 | return; |
| 117790 | 117854 | } |
| | @@ -118477,11 +118541,11 @@ |
| 118477 | 118541 | FUNCTION(round, 2, 0, 0, roundFunc ), |
| 118478 | 118542 | #endif |
| 118479 | 118543 | FUNCTION(upper, 1, 0, 0, upperFunc ), |
| 118480 | 118544 | FUNCTION(lower, 1, 0, 0, lowerFunc ), |
| 118481 | 118545 | FUNCTION(hex, 1, 0, 0, hexFunc ), |
| 118482 | | - INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 118546 | + INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ), |
| 118483 | 118547 | VFUNCTION(random, 0, 0, 0, randomFunc ), |
| 118484 | 118548 | VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 118485 | 118549 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 118486 | 118550 | DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 118487 | 118551 | DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| | @@ -118517,11 +118581,12 @@ |
| 118517 | 118581 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 118518 | 118582 | FUNCTION(unknown, -1, 0, 0, unknownFunc ), |
| 118519 | 118583 | #endif |
| 118520 | 118584 | FUNCTION(coalesce, 1, 0, 0, 0 ), |
| 118521 | 118585 | FUNCTION(coalesce, 0, 0, 0, 0 ), |
| 118522 | | - INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 118586 | + INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ), |
| 118587 | + INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ), |
| 118523 | 118588 | }; |
| 118524 | 118589 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 118525 | 118590 | sqlite3AlterFunctions(); |
| 118526 | 118591 | #endif |
| 118527 | 118592 | sqlite3WindowFunctions(); |
| | @@ -135570,11 +135635,11 @@ |
| 135570 | 135635 | need = nCol; |
| 135571 | 135636 | } |
| 135572 | 135637 | if( p->nData + need > p->nAlloc ){ |
| 135573 | 135638 | char **azNew; |
| 135574 | 135639 | p->nAlloc = p->nAlloc*2 + need; |
| 135575 | | - azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc ); |
| 135640 | + azNew = sqlite3Realloc( p->azResult, sizeof(char*)*p->nAlloc ); |
| 135576 | 135641 | if( azNew==0 ) goto malloc_failed; |
| 135577 | 135642 | p->azResult = azNew; |
| 135578 | 135643 | } |
| 135579 | 135644 | |
| 135580 | 135645 | /* If this is the first row, then generate an extra row containing |
| | @@ -135679,11 +135744,11 @@ |
| 135679 | 135744 | sqlite3_free_table(&res.azResult[1]); |
| 135680 | 135745 | return rc; |
| 135681 | 135746 | } |
| 135682 | 135747 | if( res.nAlloc>res.nData ){ |
| 135683 | 135748 | char **azNew; |
| 135684 | | - azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); |
| 135749 | + azNew = sqlite3Realloc( res.azResult, sizeof(char*)*res.nData ); |
| 135685 | 135750 | if( azNew==0 ){ |
| 135686 | 135751 | sqlite3_free_table(&res.azResult[1]); |
| 135687 | 135752 | db->errCode = SQLITE_NOMEM; |
| 135688 | 135753 | return SQLITE_NOMEM_BKPT; |
| 135689 | 135754 | } |
| | @@ -136969,14 +137034,14 @@ |
| 136969 | 137034 | ** Therefore, the P4 parameter is only required if the default value for |
| 136970 | 137035 | ** the column is a literal number, string or null. The sqlite3ValueFromExpr() |
| 136971 | 137036 | ** function is capable of transforming these types of expressions into |
| 136972 | 137037 | ** sqlite3_value objects. |
| 136973 | 137038 | ** |
| 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. |
| 137039 | +** If column as REAL affinity and the table is an ordinary b-tree table |
| 137040 | +** (not a virtual table) then the value might have been stored as an |
| 137041 | +** integer. In that case, add an OP_RealAffinity opcode to make sure |
| 137042 | +** it has been converted into REAL. |
| 136978 | 137043 | */ |
| 136979 | 137044 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ |
| 136980 | 137045 | assert( pTab!=0 ); |
| 136981 | 137046 | if( !pTab->pSelect ){ |
| 136982 | 137047 | sqlite3_value *pValue = 0; |
| | @@ -136989,11 +137054,11 @@ |
| 136989 | 137054 | if( pValue ){ |
| 136990 | 137055 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 136991 | 137056 | } |
| 136992 | 137057 | } |
| 136993 | 137058 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 136994 | | - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 137059 | + if( pTab->aCol[i].affinity==SQLITE_AFF_REAL && !IsVirtual(pTab) ){ |
| 136995 | 137060 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 136996 | 137061 | } |
| 136997 | 137062 | #endif |
| 136998 | 137063 | } |
| 136999 | 137064 | |
| | @@ -139838,11 +139903,11 @@ |
| 139838 | 139903 | assert( IsVirtual(pTab) ); |
| 139839 | 139904 | for(i=0; i<pToplevel->nVtabLock; i++){ |
| 139840 | 139905 | if( pTab==pToplevel->apVtabLock[i] ) return; |
| 139841 | 139906 | } |
| 139842 | 139907 | n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]); |
| 139843 | | - apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n); |
| 139908 | + apVtabLock = sqlite3Realloc(pToplevel->apVtabLock, n); |
| 139844 | 139909 | if( apVtabLock ){ |
| 139845 | 139910 | pToplevel->apVtabLock = apVtabLock; |
| 139846 | 139911 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 139847 | 139912 | }else{ |
| 139848 | 139913 | sqlite3OomFault(pToplevel->db); |
| | @@ -151130,17 +151195,23 @@ |
| 151130 | 151195 | ){ |
| 151131 | 151196 | if( pAppend ){ |
| 151132 | 151197 | int i; |
| 151133 | 151198 | int nInit = pList ? pList->nExpr : 0; |
| 151134 | 151199 | for(i=0; i<pAppend->nExpr; i++){ |
| 151135 | | - int iDummy; |
| 151136 | 151200 | Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0); |
| 151137 | 151201 | 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; |
| 151202 | + if( bIntToNull && pDup ){ |
| 151203 | + int iDummy; |
| 151204 | + Expr *pSub; |
| 151205 | + for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){ |
| 151206 | + assert( pSub ); |
| 151207 | + } |
| 151208 | + if( sqlite3ExprIsInteger(pSub, &iDummy) ){ |
| 151209 | + pSub->op = TK_NULL; |
| 151210 | + pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 151211 | + pSub->u.zToken = 0; |
| 151212 | + } |
| 151142 | 151213 | } |
| 151143 | 151214 | pList = sqlite3ExprListAppend(pParse, pList, pDup); |
| 151144 | 151215 | if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags; |
| 151145 | 151216 | } |
| 151146 | 151217 | } |
| | @@ -160322,10 +160393,11 @@ |
| 160322 | 160393 | } |
| 160323 | 160394 | #endif |
| 160324 | 160395 | if( rc==SQLITE_OK ){ |
| 160325 | 160396 | sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, |
| 160326 | 160397 | sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); |
| 160398 | + sqlite3MemoryBarrier(); |
| 160327 | 160399 | sqlite3GlobalConfig.isInit = 1; |
| 160328 | 160400 | #ifdef SQLITE_EXTRA_INIT |
| 160329 | 160401 | bRunExtraInit = 1; |
| 160330 | 160402 | #endif |
| 160331 | 160403 | } |
| | @@ -163270,11 +163342,11 @@ |
| 163270 | 163342 | assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 163271 | 163343 | testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 163272 | 163344 | testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 163273 | 163345 | testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 163274 | 163346 | if( ((1<<(flags&7)) & 0x46)==0 ){ |
| 163275 | | - rc = SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */ |
| 163347 | + rc = SQLITE_MISUSE_BKPT; /* IMP: R-18321-05872 */ |
| 163276 | 163348 | }else{ |
| 163277 | 163349 | rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); |
| 163278 | 163350 | } |
| 163279 | 163351 | if( rc!=SQLITE_OK ){ |
| 163280 | 163352 | if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
| | @@ -171194,10 +171266,11 @@ |
| 171194 | 171266 | while( *pRc==SQLITE_OK && pLeft->bEof==0 ){ |
| 171195 | 171267 | memset(pDl->pList, 0, pDl->nList); |
| 171196 | 171268 | fts3EvalNextRow(pCsr, pLeft, pRc); |
| 171197 | 171269 | } |
| 171198 | 171270 | } |
| 171271 | + pRight->bEof = pLeft->bEof = 1; |
| 171199 | 171272 | } |
| 171200 | 171273 | } |
| 171201 | 171274 | break; |
| 171202 | 171275 | } |
| 171203 | 171276 | |
| | @@ -182739,11 +182812,11 @@ |
| 182739 | 182812 | iStart = pExpr->iPhrase * p->nCol; |
| 182740 | 182813 | }else{ |
| 182741 | 182814 | iStart = pExpr->iPhrase * ((p->nCol + 31) / 32); |
| 182742 | 182815 | } |
| 182743 | 182816 | |
| 182744 | | - while( 1 ){ |
| 182817 | + if( pIter ) while( 1 ){ |
| 182745 | 182818 | int nHit = fts3ColumnlistCount(&pIter); |
| 182746 | 182819 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 182747 | 182820 | if( p->flag==FTS3_MATCHINFO_LHITS ){ |
| 182748 | 182821 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 182749 | 182822 | }else if( nHit ){ |
| | @@ -184653,10 +184726,11 @@ |
| 184653 | 184726 | } |
| 184654 | 184727 | |
| 184655 | 184728 | /* Append N bytes from zIn onto the end of the JsonString string. |
| 184656 | 184729 | */ |
| 184657 | 184730 | static void jsonAppendRaw(JsonString *p, const char *zIn, u32 N){ |
| 184731 | + if( N==0 ) return; |
| 184658 | 184732 | if( (N+p->nUsed >= p->nAlloc) && jsonGrow(p,N)!=0 ) return; |
| 184659 | 184733 | memcpy(p->zBuf+p->nUsed, zIn, N); |
| 184660 | 184734 | p->nUsed += N; |
| 184661 | 184735 | } |
| 184662 | 184736 | |
| | @@ -224664,11 +224738,11 @@ |
| 224664 | 224738 | int nArg, /* Number of args */ |
| 224665 | 224739 | sqlite3_value **apUnused /* Function arguments */ |
| 224666 | 224740 | ){ |
| 224667 | 224741 | assert( nArg==0 ); |
| 224668 | 224742 | UNUSED_PARAM2(nArg, apUnused); |
| 224669 | | - sqlite3_result_text(pCtx, "fts5: 2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff", -1, SQLITE_TRANSIENT); |
| 224743 | + sqlite3_result_text(pCtx, "fts5: 2020-05-17 00:26:44 1313557b512297e7b75ed748894379b2022aecf696d5a58318e46a668321c1ff", -1, SQLITE_TRANSIENT); |
| 224670 | 224744 | } |
| 224671 | 224745 | |
| 224672 | 224746 | /* |
| 224673 | 224747 | ** Return true if zName is the extension on one of the shadow tables used |
| 224674 | 224748 | ** by this module. |
| | @@ -229447,12 +229521,12 @@ |
| 229447 | 229521 | } |
| 229448 | 229522 | #endif /* SQLITE_CORE */ |
| 229449 | 229523 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229450 | 229524 | |
| 229451 | 229525 | /************** End of stmt.c ************************************************/ |
| 229452 | | -#if __LINE__!=229452 |
| 229526 | +#if __LINE__!=229526 |
| 229453 | 229527 | #undef SQLITE_SOURCE_ID |
| 229454 | | -#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f96alt2" |
| 229528 | +#define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469falt2" |
| 229455 | 229529 | #endif |
| 229456 | 229530 | /* Return the source-id for this library */ |
| 229457 | 229531 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229458 | 229532 | /************************** End of sqlite3.c ******************************/ |
| 229459 | 229533 | |