| | @@ -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-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525" |
| 1167 | +#define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -2124,14 +2124,16 @@ |
| 2124 | 2124 | ** so that all subsequent write operations are independent. |
| 2125 | 2125 | ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without |
| 2126 | 2126 | ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
| 2127 | 2127 | ** |
| 2128 | 2128 | ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]] |
| 2129 | | -** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain |
| 2130 | | -** a file lock using the xLock or xShmLock methods of the VFS to wait |
| 2131 | | -** for up to M milliseconds before failing, where M is the single |
| 2132 | | -** unsigned integer parameter. |
| 2129 | +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS |
| 2130 | +** to block for up to M milliseconds before failing when attempting to |
| 2131 | +** obtain a file lock using the xLock or xShmLock methods of the VFS. |
| 2132 | +** The parameter is a pointer to a 32-bit signed integer that contains |
| 2133 | +** the value that M is to be set to. Before returning, the 32-bit signed |
| 2134 | +** integer is overwritten with the previous value of M. |
| 2133 | 2135 | ** |
| 2134 | 2136 | ** <li>[[SQLITE_FCNTL_DATA_VERSION]] |
| 2135 | 2137 | ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to |
| 2136 | 2138 | ** a database file. The argument is a pointer to a 32-bit unsigned integer. |
| 2137 | 2139 | ** The "data version" for the pager is written into the pointer. The |
| | @@ -5295,10 +5297,28 @@ |
| 5295 | 5297 | ** |
| 5296 | 5298 | ** ^The third argument is the value to bind to the parameter. |
| 5297 | 5299 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 5298 | 5300 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 5299 | 5301 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
| 5302 | +** ^If the third parameter to sqlite3_bind_text() is not NULL, then |
| 5303 | +** it should be a pointer to well-formed UTF8 text. |
| 5304 | +** ^If the third parameter to sqlite3_bind_text16() is not NULL, then |
| 5305 | +** it should be a pointer to well-formed UTF16 text. |
| 5306 | +** ^If the third parameter to sqlite3_bind_text64() is not NULL, then |
| 5307 | +** it should be a pointer to a well-formed unicode string that is |
| 5308 | +** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16 |
| 5309 | +** otherwise. |
| 5310 | +** |
| 5311 | +** [[byte-order determination rules]] ^The byte-order of |
| 5312 | +** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF) |
| 5313 | +** found in first character, which is removed, or in the absence of a BOM |
| 5314 | +** the byte order is the native byte order of the host |
| 5315 | +** machine for sqlite3_bind_text16() or the byte order specified in |
| 5316 | +** the 6th parameter for sqlite3_bind_text64().)^ |
| 5317 | +** ^If UTF16 input text contains invalid unicode |
| 5318 | +** characters, then SQLite might change those invalid characters |
| 5319 | +** into the unicode replacement character: U+FFFD. |
| 5300 | 5320 | ** |
| 5301 | 5321 | ** ^(In those routines that have a fourth argument, its value is the |
| 5302 | 5322 | ** number of bytes in the parameter. To be clear: the value is the |
| 5303 | 5323 | ** number of <u>bytes</u> in the value, not the number of characters.)^ |
| 5304 | 5324 | ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| | @@ -5308,11 +5328,11 @@ |
| 5308 | 5328 | ** the behavior is undefined. |
| 5309 | 5329 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 5310 | 5330 | ** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
| 5311 | 5331 | ** that parameter must be the byte offset |
| 5312 | 5332 | ** where the NUL terminator would occur assuming the string were NUL |
| 5313 | | -** terminated. If any NUL characters occur at byte offsets less than |
| 5333 | +** terminated. If any NUL characters occurs at byte offsets less than |
| 5314 | 5334 | ** the value of the fourth parameter then the resulting string value will |
| 5315 | 5335 | ** contain embedded NULs. The result of expressions involving strings |
| 5316 | 5336 | ** with embedded NULs is undefined. |
| 5317 | 5337 | ** |
| 5318 | 5338 | ** ^The fifth argument to the BLOB and string binding interfaces |
| | @@ -6633,12 +6653,13 @@ |
| 6633 | 6653 | ** cause the implemented SQL function to throw an exception. |
| 6634 | 6654 | ** ^SQLite uses the string pointed to by the |
| 6635 | 6655 | ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() |
| 6636 | 6656 | ** as the text of an error message. ^SQLite interprets the error |
| 6637 | 6657 | ** message string from sqlite3_result_error() as UTF-8. ^SQLite |
| 6638 | | -** interprets the string from sqlite3_result_error16() as UTF-16 in native |
| 6639 | | -** byte order. ^If the third parameter to sqlite3_result_error() |
| 6658 | +** interprets the string from sqlite3_result_error16() as UTF-16 using |
| 6659 | +** the same [byte-order determination rules] as [sqlite3_bind_text16()]. |
| 6660 | +** ^If the third parameter to sqlite3_result_error() |
| 6640 | 6661 | ** or sqlite3_result_error16() is negative then SQLite takes as the error |
| 6641 | 6662 | ** message all text up through the first zero character. |
| 6642 | 6663 | ** ^If the third parameter to sqlite3_result_error() or |
| 6643 | 6664 | ** sqlite3_result_error16() is non-negative then SQLite takes that many |
| 6644 | 6665 | ** bytes (not characters) from the 2nd parameter as the error message. |
| | @@ -6701,10 +6722,29 @@ |
| 6701 | 6722 | ** when it has finished using that result. |
| 6702 | 6723 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
| 6703 | 6724 | ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT |
| 6704 | 6725 | ** then SQLite makes a copy of the result into space obtained |
| 6705 | 6726 | ** from [sqlite3_malloc()] before it returns. |
| 6727 | +** |
| 6728 | +** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and |
| 6729 | +** sqlite3_result_text16be() routines, and for sqlite3_result_text64() |
| 6730 | +** when the encoding is not UTF8, if the input UTF16 begins with a |
| 6731 | +** byte-order mark (BOM, U+FEFF) then the BOM is removed from the |
| 6732 | +** string and the rest of the string is interpreted according to the |
| 6733 | +** byte-order specified by the BOM. ^The byte-order specified by |
| 6734 | +** the BOM at the beginning of the text overrides the byte-order |
| 6735 | +** specified by the interface procedure. ^So, for example, if |
| 6736 | +** sqlite3_result_text16le() is invoked with text that begins |
| 6737 | +** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the |
| 6738 | +** first two bytes of input are skipped and the remaining input |
| 6739 | +** is interpreted as UTF16BE text. |
| 6740 | +** |
| 6741 | +** ^For UTF16 input text to the sqlite3_result_text16(), |
| 6742 | +** sqlite3_result_text16be(), sqlite3_result_text16le(), and |
| 6743 | +** sqlite3_result_text64() routines, if the text contains invalid |
| 6744 | +** UTF16 characters, the invalid characters might be converted |
| 6745 | +** into the unicode replacement character, U+FFFD. |
| 6706 | 6746 | ** |
| 6707 | 6747 | ** ^The sqlite3_result_value() interface sets the result of |
| 6708 | 6748 | ** the application-defined function to be a copy of the |
| 6709 | 6749 | ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The |
| 6710 | 6750 | ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] |
| | @@ -13369,10 +13409,25 @@ |
| 13369 | 13409 | #pragma warn -aus /* Assigned value is never used */ |
| 13370 | 13410 | #pragma warn -csu /* Comparing signed and unsigned */ |
| 13371 | 13411 | #pragma warn -spa /* Suspicious pointer arithmetic */ |
| 13372 | 13412 | #endif |
| 13373 | 13413 | |
| 13414 | +/* |
| 13415 | +** WAL mode depends on atomic aligned 32-bit loads and stores in a few |
| 13416 | +** places. The following macros try to make this explicit. |
| 13417 | +*/ |
| 13418 | +#ifndef __has_feature |
| 13419 | +# define __has_feature(x) 0 /* compatibility with non-clang compilers */ |
| 13420 | +#endif |
| 13421 | +#if GCC_VERSION>=4007000 || __has_feature(c_atomic) |
| 13422 | +# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED) |
| 13423 | +# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED) |
| 13424 | +#else |
| 13425 | +# define AtomicLoad(PTR) (*(PTR)) |
| 13426 | +# define AtomicStore(PTR,VAL) (*(PTR) = (VAL)) |
| 13427 | +#endif |
| 13428 | + |
| 13374 | 13429 | /* |
| 13375 | 13430 | ** Include standard header files as necessary |
| 13376 | 13431 | */ |
| 13377 | 13432 | #ifdef HAVE_STDINT_H |
| 13378 | 13433 | #include <stdint.h> |
| | @@ -17209,10 +17264,11 @@ |
| 17209 | 17264 | Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */ |
| 17210 | 17265 | char *zColl; /* Collating sequence. If NULL, use the default */ |
| 17211 | 17266 | u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ |
| 17212 | 17267 | char affinity; /* One of the SQLITE_AFF_... values */ |
| 17213 | 17268 | u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ |
| 17269 | + u8 hName; /* Column name hash for faster lookup */ |
| 17214 | 17270 | u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 17215 | 17271 | }; |
| 17216 | 17272 | |
| 17217 | 17273 | /* Allowed values for Column.colFlags: |
| 17218 | 17274 | */ |
| | @@ -19827,10 +19883,11 @@ |
| 19827 | 19883 | const char*, |
| 19828 | 19884 | const char*, |
| 19829 | 19885 | const char* |
| 19830 | 19886 | ); |
| 19831 | 19887 | SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr*); |
| 19888 | +SQLITE_PRIVATE u8 sqlite3StrIHash(const char*); |
| 19832 | 19889 | SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*); |
| 19833 | 19890 | SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*); |
| 19834 | 19891 | SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); |
| 19835 | 19892 | SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); |
| 19836 | 19893 | SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); |
| | @@ -22165,16 +22222,16 @@ |
| 22165 | 22222 | u8 nName; /* Length of th name */ |
| 22166 | 22223 | char *zName; /* Name of the transformation */ |
| 22167 | 22224 | double rLimit; /* Maximum NNN value for this transform */ |
| 22168 | 22225 | double rXform; /* Constant used for this transform */ |
| 22169 | 22226 | } aXformType[] = { |
| 22170 | | - { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) }, |
| 22171 | | - { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) }, |
| 22172 | | - { 0, 4, "hour", 128963628.0, 86400000.0/24.0 }, |
| 22173 | | - { 0, 3, "day", 5373485.0, 86400000.0 }, |
| 22174 | | - { 1, 5, "month", 176546.0, 30.0*86400000.0 }, |
| 22175 | | - { 2, 4, "year", 14713.0, 365.0*86400000.0 }, |
| 22227 | + { 0, 6, "second", 464269060800.0, 1000.0 }, |
| 22228 | + { 0, 6, "minute", 7737817680.0, 60000.0 }, |
| 22229 | + { 0, 4, "hour", 128963628.0, 3600000.0 }, |
| 22230 | + { 0, 3, "day", 5373485.0, 86400000.0 }, |
| 22231 | + { 1, 5, "month", 176546.0, 2592000000.0 }, |
| 22232 | + { 2, 4, "year", 14713.0, 31536000000.0 }, |
| 22176 | 22233 | }; |
| 22177 | 22234 | |
| 22178 | 22235 | /* |
| 22179 | 22236 | ** Process a modifier to a date-time stamp. The modifiers are |
| 22180 | 22237 | ** as follows: |
| | @@ -27907,11 +27964,11 @@ |
| 27907 | 27964 | */ |
| 27908 | 27965 | SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){ |
| 27909 | 27966 | if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ |
| 27910 | 27967 | db->mallocFailed = 1; |
| 27911 | 27968 | if( db->nVdbeExec>0 ){ |
| 27912 | | - db->u1.isInterrupted = 1; |
| 27969 | + AtomicStore(&db->u1.isInterrupted, 1); |
| 27913 | 27970 | } |
| 27914 | 27971 | DisableLookaside; |
| 27915 | 27972 | if( db->pParse ){ |
| 27916 | 27973 | db->pParse->rc = SQLITE_NOMEM_BKPT; |
| 27917 | 27974 | } |
| | @@ -27926,11 +27983,11 @@ |
| 27926 | 27983 | ** VDBEs. |
| 27927 | 27984 | */ |
| 27928 | 27985 | SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){ |
| 27929 | 27986 | if( db->mallocFailed && db->nVdbeExec==0 ){ |
| 27930 | 27987 | db->mallocFailed = 0; |
| 27931 | | - db->u1.isInterrupted = 0; |
| 27988 | + AtomicStore(&db->u1.isInterrupted, 0); |
| 27932 | 27989 | assert( db->lookaside.bDisable>0 ); |
| 27933 | 27990 | EnableLookaside; |
| 27934 | 27991 | } |
| 27935 | 27992 | } |
| 27936 | 27993 | |
| | @@ -31300,10 +31357,23 @@ |
| 31300 | 31357 | a = (unsigned char *)zLeft; |
| 31301 | 31358 | b = (unsigned char *)zRight; |
| 31302 | 31359 | while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 31303 | 31360 | return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; |
| 31304 | 31361 | } |
| 31362 | + |
| 31363 | +/* |
| 31364 | +** Compute an 8-bit hash on a string that is insensitive to case differences |
| 31365 | +*/ |
| 31366 | +SQLITE_PRIVATE u8 sqlite3StrIHash(const char *z){ |
| 31367 | + u8 h = 0; |
| 31368 | + if( z==0 ) return 0; |
| 31369 | + while( z[0] ){ |
| 31370 | + h += UpperToLower[(unsigned char)z[0]]; |
| 31371 | + z++; |
| 31372 | + } |
| 31373 | + return h; |
| 31374 | +} |
| 31305 | 31375 | |
| 31306 | 31376 | /* |
| 31307 | 31377 | ** Compute 10 to the E-th power. Examples: E==1 results in 10. |
| 31308 | 31378 | ** E==2 results in 100. E==50 results in 1.0e50. |
| 31309 | 31379 | ** |
| | @@ -37287,11 +37357,13 @@ |
| 37287 | 37357 | *(int*)pArg = fileHasMoved(pFile); |
| 37288 | 37358 | return SQLITE_OK; |
| 37289 | 37359 | } |
| 37290 | 37360 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 37291 | 37361 | case SQLITE_FCNTL_LOCK_TIMEOUT: { |
| 37362 | + int iOld = pFile->iBusyTimeout; |
| 37292 | 37363 | pFile->iBusyTimeout = *(int*)pArg; |
| 37364 | + *(int*)pArg = iOld; |
| 37293 | 37365 | return SQLITE_OK; |
| 37294 | 37366 | } |
| 37295 | 37367 | #endif |
| 37296 | 37368 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 37297 | 37369 | case SQLITE_FCNTL_MMAP_SIZE: { |
| | @@ -38108,10 +38180,28 @@ |
| 38108 | 38180 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED) |
| 38109 | 38181 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); |
| 38110 | 38182 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 38111 | 38183 | assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 38112 | 38184 | assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 38185 | + |
| 38186 | + /* Check that, if this to be a blocking lock, that locks have been |
| 38187 | + ** obtained in the following order. |
| 38188 | + ** |
| 38189 | + ** 1. Checkpointer lock (ofst==1). |
| 38190 | + ** 2. Recover lock (ofst==2). |
| 38191 | + ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 38192 | + ** 4. Write lock (ofst==0). |
| 38193 | + ** |
| 38194 | + ** In other words, if this is a blocking lock, none of the locks that |
| 38195 | + ** occur later in the above list than the lock being obtained may be |
| 38196 | + ** held. */ |
| 38197 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 38198 | + assert( pDbFd->iBusyTimeout==0 |
| 38199 | + || (flags & SQLITE_SHM_UNLOCK) || ofst==0 |
| 38200 | + || ((p->exclMask|p->sharedMask)&~((1<<ofst)-2))==0 |
| 38201 | + ); |
| 38202 | +#endif |
| 38113 | 38203 | |
| 38114 | 38204 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 38115 | 38205 | assert( n>1 || mask==(1<<ofst) ); |
| 38116 | 38206 | sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 38117 | 38207 | if( flags & SQLITE_SHM_UNLOCK ){ |
| | @@ -59322,22 +59412,10 @@ |
| 59322 | 59412 | # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X |
| 59323 | 59413 | #else |
| 59324 | 59414 | # define WALTRACE(X) |
| 59325 | 59415 | #endif |
| 59326 | 59416 | |
| 59327 | | -/* |
| 59328 | | -** WAL mode depends on atomic aligned 32-bit loads and stores in a few |
| 59329 | | -** places. The following macros try to make this explicit. |
| 59330 | | -*/ |
| 59331 | | -#if GCC_VESRION>=5004000 |
| 59332 | | -# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED) |
| 59333 | | -# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED) |
| 59334 | | -#else |
| 59335 | | -# define AtomicLoad(PTR) (*(PTR)) |
| 59336 | | -# define AtomicStore(PTR,VAL) (*(PTR) = (VAL)) |
| 59337 | | -#endif |
| 59338 | | - |
| 59339 | 59417 | /* |
| 59340 | 59418 | ** The maximum (and only) versions of the wal and wal-index formats |
| 59341 | 59419 | ** that may be interpreted by this version of SQLite. |
| 59342 | 59420 | ** |
| 59343 | 59421 | ** If a client begins recovering a WAL file and finds that (a) the checksum |
| | @@ -60203,10 +60281,15 @@ |
| 60203 | 60281 | static int walIndexRecover(Wal *pWal){ |
| 60204 | 60282 | int rc; /* Return Code */ |
| 60205 | 60283 | i64 nSize; /* Size of log file */ |
| 60206 | 60284 | u32 aFrameCksum[2] = {0, 0}; |
| 60207 | 60285 | int iLock; /* Lock offset to lock for checkpoint */ |
| 60286 | + |
| 60287 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 60288 | + int tmout = 0; |
| 60289 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 60290 | +#endif |
| 60208 | 60291 | |
| 60209 | 60292 | /* Obtain an exclusive lock on all byte in the locking range not already |
| 60210 | 60293 | ** locked by the caller. The caller is guaranteed to have locked the |
| 60211 | 60294 | ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte. |
| 60212 | 60295 | ** If successful, the same bytes that are locked here are unlocked before |
| | @@ -60950,11 +61033,11 @@ |
| 60950 | 61033 | |
| 60951 | 61034 | /* Iterate through the contents of the WAL, copying data to the db file */ |
| 60952 | 61035 | while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){ |
| 60953 | 61036 | i64 iOffset; |
| 60954 | 61037 | assert( walFramePgno(pWal, iFrame)==iDbpage ); |
| 60955 | | - if( db->u1.isInterrupted ){ |
| 61038 | + if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 60956 | 61039 | rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT; |
| 60957 | 61040 | break; |
| 60958 | 61041 | } |
| 60959 | 61042 | if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){ |
| 60960 | 61043 | continue; |
| | @@ -61663,11 +61746,12 @@ |
| 61663 | 61746 | && (mxReadMark<mxFrame || mxI==0) |
| 61664 | 61747 | ){ |
| 61665 | 61748 | for(i=1; i<WAL_NREADER; i++){ |
| 61666 | 61749 | rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1); |
| 61667 | 61750 | if( rc==SQLITE_OK ){ |
| 61668 | | - mxReadMark = AtomicStore(pInfo->aReadMark+i,mxFrame); |
| 61751 | + AtomicStore(pInfo->aReadMark+i,mxFrame); |
| 61752 | + mxReadMark = mxFrame; |
| 61669 | 61753 | mxI = i; |
| 61670 | 61754 | walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); |
| 61671 | 61755 | break; |
| 61672 | 61756 | }else if( rc!=SQLITE_BUSY ){ |
| 61673 | 61757 | return rc; |
| | @@ -61822,26 +61906,45 @@ |
| 61822 | 61906 | ** needs to be flushed. |
| 61823 | 61907 | */ |
| 61824 | 61908 | SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ |
| 61825 | 61909 | int rc; /* Return code */ |
| 61826 | 61910 | int cnt = 0; /* Number of TryBeginRead attempts */ |
| 61911 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61912 | + int tmout = 0; |
| 61913 | +#endif |
| 61827 | 61914 | |
| 61828 | 61915 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61829 | 61916 | int bChanged = 0; |
| 61830 | 61917 | WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 61831 | 61918 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 61832 | 61919 | bChanged = 1; |
| 61833 | 61920 | } |
| 61834 | 61921 | #endif |
| 61835 | 61922 | |
| 61923 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61924 | + /* Disable blocking locks. They are not useful when trying to open a |
| 61925 | + ** read-transaction, and blocking may cause deadlock anyway. */ |
| 61926 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 61927 | +#endif |
| 61928 | + |
| 61836 | 61929 | do{ |
| 61837 | 61930 | rc = walTryBeginRead(pWal, pChanged, 0, ++cnt); |
| 61838 | 61931 | }while( rc==WAL_RETRY ); |
| 61839 | 61932 | testcase( (rc&0xff)==SQLITE_BUSY ); |
| 61840 | 61933 | testcase( (rc&0xff)==SQLITE_IOERR ); |
| 61841 | 61934 | testcase( rc==SQLITE_PROTOCOL ); |
| 61842 | 61935 | testcase( rc==SQLITE_OK ); |
| 61936 | + |
| 61937 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61938 | + /* If they were disabled earlier and the read-transaction has been |
| 61939 | + ** successfully opened, re-enable blocking locks. This is because the |
| 61940 | + ** connection may attempt to upgrade to a write-transaction, which does |
| 61941 | + ** benefit from using blocking locks. */ |
| 61942 | + if( rc==SQLITE_OK ){ |
| 61943 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 61944 | + } |
| 61945 | +#endif |
| 61843 | 61946 | |
| 61844 | 61947 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61845 | 61948 | if( rc==SQLITE_OK ){ |
| 61846 | 61949 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 61847 | 61950 | /* At this point the client has a lock on an aReadMark[] slot holding |
| | @@ -73477,11 +73580,11 @@ |
| 73477 | 73580 | } |
| 73478 | 73581 | |
| 73479 | 73582 | /* Unless an error occurs, the following loop runs one iteration for each |
| 73480 | 73583 | ** page in the B-Tree structure (not including overflow pages). |
| 73481 | 73584 | */ |
| 73482 | | - while( rc==SQLITE_OK && !db->u1.isInterrupted ){ |
| 73585 | + while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){ |
| 73483 | 73586 | int iIdx; /* Index of child node in parent */ |
| 73484 | 73587 | MemPage *pPage; /* Current page of the b-tree */ |
| 73485 | 73588 | |
| 73486 | 73589 | /* If this is a leaf page or the tree is not an int-key tree, then |
| 73487 | 73590 | ** this page contains countable entries. Increment the entry counter |
| | @@ -73603,11 +73706,11 @@ |
| 73603 | 73706 | } |
| 73604 | 73707 | if( getPageReferenced(pCheck, iPage) ){ |
| 73605 | 73708 | checkAppendMsg(pCheck, "2nd reference to page %d", iPage); |
| 73606 | 73709 | return 1; |
| 73607 | 73710 | } |
| 73608 | | - if( pCheck->db->u1.isInterrupted ) return 1; |
| 73711 | + if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1; |
| 73609 | 73712 | setPageReferenced(pCheck, iPage); |
| 73610 | 73713 | return 0; |
| 73611 | 73714 | } |
| 73612 | 73715 | |
| 73613 | 73716 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| | @@ -79233,11 +79336,11 @@ |
| 79233 | 79336 | if( pOp->opcode==OP_Explain ) break; |
| 79234 | 79337 | if( pOp->opcode==OP_Init && p->pc>1 ) break; |
| 79235 | 79338 | } |
| 79236 | 79339 | |
| 79237 | 79340 | if( rc==SQLITE_OK ){ |
| 79238 | | - if( db->u1.isInterrupted ){ |
| 79341 | + if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 79239 | 79342 | p->rc = SQLITE_INTERRUPT; |
| 79240 | 79343 | rc = SQLITE_ERROR; |
| 79241 | 79344 | sqlite3VdbeError(p, sqlite3ErrStr(p->rc)); |
| 79242 | 79345 | }else{ |
| 79243 | 79346 | char *zP4; |
| | @@ -83028,11 +83131,11 @@ |
| 83028 | 83131 | /* If there are no other statements currently running, then |
| 83029 | 83132 | ** reset the interrupt flag. This prevents a call to sqlite3_interrupt |
| 83030 | 83133 | ** from interrupting a statement that has not yet started. |
| 83031 | 83134 | */ |
| 83032 | 83135 | if( db->nVdbeActive==0 ){ |
| 83033 | | - db->u1.isInterrupted = 0; |
| 83136 | + AtomicStore(&db->u1.isInterrupted, 0); |
| 83034 | 83137 | } |
| 83035 | 83138 | |
| 83036 | 83139 | assert( db->nVdbeWrite>0 || db->autoCommit==0 |
| 83037 | 83140 | || (db->nDeferredCons==0 && db->nDeferredImmCons==0) |
| 83038 | 83141 | ); |
| | @@ -85413,11 +85516,11 @@ |
| 85413 | 85516 | assert( p->bIsReader || p->readOnly!=0 ); |
| 85414 | 85517 | p->iCurrentTime = 0; |
| 85415 | 85518 | assert( p->explain==0 ); |
| 85416 | 85519 | p->pResultSet = 0; |
| 85417 | 85520 | db->busyHandler.nBusy = 0; |
| 85418 | | - if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 85521 | + if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt; |
| 85419 | 85522 | sqlite3VdbeIOTraceSql(p); |
| 85420 | 85523 | #ifdef SQLITE_DEBUG |
| 85421 | 85524 | sqlite3BeginBenignMalloc(); |
| 85422 | 85525 | if( p->pc==0 |
| 85423 | 85526 | && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0 |
| | @@ -85597,11 +85700,11 @@ |
| 85597 | 85700 | ** But that is not due to sloppy coding habits. The code is written this |
| 85598 | 85701 | ** way for performance, to avoid having to run the interrupt and progress |
| 85599 | 85702 | ** checks on every opcode. This helps sqlite3_step() to run about 1.5% |
| 85600 | 85703 | ** faster according to "valgrind --tool=cachegrind" */ |
| 85601 | 85704 | check_for_interrupt: |
| 85602 | | - if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 85705 | + if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt; |
| 85603 | 85706 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 85604 | 85707 | /* Call the progress callback if it is configured and the required number |
| 85605 | 85708 | ** of VDBE ops have been executed (either since this invocation of |
| 85606 | 85709 | ** sqlite3VdbeExec() or since last time the progress callback was called). |
| 85607 | 85710 | ** If the progress callback returns non-zero, exit the virtual machine with |
| | @@ -92705,11 +92808,11 @@ |
| 92705 | 92808 | |
| 92706 | 92809 | /* Jump to here if the sqlite3_interrupt() API sets the interrupt |
| 92707 | 92810 | ** flag. |
| 92708 | 92811 | */ |
| 92709 | 92812 | abort_due_to_interrupt: |
| 92710 | | - assert( db->u1.isInterrupted ); |
| 92813 | + assert( AtomicLoad(&db->u1.isInterrupted) ); |
| 92711 | 92814 | rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT; |
| 92712 | 92815 | p->rc = rc; |
| 92713 | 92816 | sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 92714 | 92817 | goto abort_due_to_error; |
| 92715 | 92818 | } |
| | @@ -96775,11 +96878,11 @@ |
| 96775 | 96878 | const char *zTab, |
| 96776 | 96879 | const char *zDb |
| 96777 | 96880 | ){ |
| 96778 | 96881 | int n; |
| 96779 | 96882 | const char *zSpan; |
| 96780 | | - if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0; |
| 96883 | + if( pItem->eEName!=ENAME_TAB ) return 0; |
| 96781 | 96884 | zSpan = pItem->zEName; |
| 96782 | 96885 | for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} |
| 96783 | 96886 | if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ |
| 96784 | 96887 | return 0; |
| 96785 | 96888 | } |
| | @@ -96929,10 +97032,11 @@ |
| 96929 | 97032 | ExprList *pEList; |
| 96930 | 97033 | SrcList *pSrcList = pNC->pSrcList; |
| 96931 | 97034 | |
| 96932 | 97035 | if( pSrcList ){ |
| 96933 | 97036 | for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ |
| 97037 | + u8 hCol; |
| 96934 | 97038 | pTab = pItem->pTab; |
| 96935 | 97039 | assert( pTab!=0 && pTab->zName!=0 ); |
| 96936 | 97040 | assert( pTab->nCol>0 ); |
| 96937 | 97041 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ |
| 96938 | 97042 | int hit = 0; |
| | @@ -96962,12 +97066,13 @@ |
| 96962 | 97066 | } |
| 96963 | 97067 | } |
| 96964 | 97068 | if( 0==(cntTab++) ){ |
| 96965 | 97069 | pMatch = pItem; |
| 96966 | 97070 | } |
| 97071 | + hCol = sqlite3StrIHash(zCol); |
| 96967 | 97072 | for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ |
| 96968 | | - if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 97073 | + if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 96969 | 97074 | /* If there has been exactly one prior match and this match |
| 96970 | 97075 | ** is for the right-hand table of a NATURAL JOIN or is in a |
| 96971 | 97076 | ** USING clause, then skip this match. |
| 96972 | 97077 | */ |
| 96973 | 97078 | if( cnt==1 ){ |
| | @@ -97024,14 +97129,15 @@ |
| 97024 | 97129 | } |
| 97025 | 97130 | #endif /* SQLITE_OMIT_UPSERT */ |
| 97026 | 97131 | |
| 97027 | 97132 | if( pTab ){ |
| 97028 | 97133 | int iCol; |
| 97134 | + u8 hCol = sqlite3StrIHash(zCol); |
| 97029 | 97135 | pSchema = pTab->pSchema; |
| 97030 | 97136 | cntTab++; |
| 97031 | 97137 | for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){ |
| 97032 | | - if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 97138 | + if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 97033 | 97139 | if( iCol==pTab->iPKey ){ |
| 97034 | 97140 | iCol = -1; |
| 97035 | 97141 | } |
| 97036 | 97142 | break; |
| 97037 | 97143 | } |
| | @@ -97828,11 +97934,11 @@ |
| 97828 | 97934 | nc.uNC.pEList = pEList; |
| 97829 | 97935 | nc.ncFlags = NC_AllowAgg|NC_UEList; |
| 97830 | 97936 | nc.nErr = 0; |
| 97831 | 97937 | db = pParse->db; |
| 97832 | 97938 | savedSuppErr = db->suppressErr; |
| 97833 | | - db->suppressErr = 1; |
| 97939 | + if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1; |
| 97834 | 97940 | rc = sqlite3ResolveExprNames(&nc, pE); |
| 97835 | 97941 | db->suppressErr = savedSuppErr; |
| 97836 | 97942 | if( rc ) return 0; |
| 97837 | 97943 | |
| 97838 | 97944 | /* Try to match the ORDER BY expression against an expression |
| | @@ -98463,15 +98569,45 @@ |
| 98463 | 98569 | SQLITE_PRIVATE int sqlite3ResolveExprListNames( |
| 98464 | 98570 | NameContext *pNC, /* Namespace to resolve expressions in. */ |
| 98465 | 98571 | ExprList *pList /* The expression list to be analyzed. */ |
| 98466 | 98572 | ){ |
| 98467 | 98573 | int i; |
| 98468 | | - if( pList ){ |
| 98469 | | - for(i=0; i<pList->nExpr; i++){ |
| 98470 | | - if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort; |
| 98574 | + int savedHasAgg = 0; |
| 98575 | + Walker w; |
| 98576 | + if( pList==0 ) return WRC_Continue; |
| 98577 | + w.pParse = pNC->pParse; |
| 98578 | + w.xExprCallback = resolveExprStep; |
| 98579 | + w.xSelectCallback = resolveSelectStep; |
| 98580 | + w.xSelectCallback2 = 0; |
| 98581 | + w.u.pNC = pNC; |
| 98582 | + savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 98583 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 98584 | + for(i=0; i<pList->nExpr; i++){ |
| 98585 | + Expr *pExpr = pList->a[i].pExpr; |
| 98586 | + if( pExpr==0 ) continue; |
| 98587 | +#if SQLITE_MAX_EXPR_DEPTH>0 |
| 98588 | + w.pParse->nHeight += pExpr->nHeight; |
| 98589 | + if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){ |
| 98590 | + return WRC_Abort; |
| 98471 | 98591 | } |
| 98592 | +#endif |
| 98593 | + sqlite3WalkExpr(&w, pExpr); |
| 98594 | +#if SQLITE_MAX_EXPR_DEPTH>0 |
| 98595 | + w.pParse->nHeight -= pExpr->nHeight; |
| 98596 | +#endif |
| 98597 | + assert( EP_Agg==NC_HasAgg ); |
| 98598 | + assert( EP_Win==NC_HasWin ); |
| 98599 | + testcase( pNC->ncFlags & NC_HasAgg ); |
| 98600 | + testcase( pNC->ncFlags & NC_HasWin ); |
| 98601 | + if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){ |
| 98602 | + ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) ); |
| 98603 | + savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 98604 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 98605 | + } |
| 98606 | + if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort; |
| 98472 | 98607 | } |
| 98608 | + pNC->ncFlags |= savedHasAgg; |
| 98473 | 98609 | return WRC_Continue; |
| 98474 | 98610 | } |
| 98475 | 98611 | |
| 98476 | 98612 | /* |
| 98477 | 98613 | ** Resolve all names in all expressions of a SELECT and in all |
| | @@ -100343,20 +100479,26 @@ |
| 100343 | 100479 | ExprList *pList, /* List to which to add the span. */ |
| 100344 | 100480 | Token *pName, /* Name to be added */ |
| 100345 | 100481 | int dequote /* True to cause the name to be dequoted */ |
| 100346 | 100482 | ){ |
| 100347 | 100483 | assert( pList!=0 || pParse->db->mallocFailed!=0 ); |
| 100484 | + assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 ); |
| 100348 | 100485 | if( pList ){ |
| 100349 | 100486 | struct ExprList_item *pItem; |
| 100350 | 100487 | assert( pList->nExpr>0 ); |
| 100351 | 100488 | pItem = &pList->a[pList->nExpr-1]; |
| 100352 | 100489 | assert( pItem->zEName==0 ); |
| 100353 | 100490 | assert( pItem->eEName==ENAME_NAME ); |
| 100354 | 100491 | pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); |
| 100355 | | - if( dequote ) sqlite3Dequote(pItem->zEName); |
| 100356 | | - if( IN_RENAME_OBJECT ){ |
| 100357 | | - sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName); |
| 100492 | + if( dequote ){ |
| 100493 | + /* If dequote==0, then pName->z does not point to part of a DDL |
| 100494 | + ** statement handled by the parser. And so no token need be added |
| 100495 | + ** to the token-map. */ |
| 100496 | + sqlite3Dequote(pItem->zEName); |
| 100497 | + if( IN_RENAME_OBJECT ){ |
| 100498 | + sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName); |
| 100499 | + } |
| 100358 | 100500 | } |
| 100359 | 100501 | } |
| 100360 | 100502 | } |
| 100361 | 100503 | |
| 100362 | 100504 | /* |
| | @@ -101497,10 +101639,12 @@ |
| 101497 | 101639 | struct ExprList_item *pItem; |
| 101498 | 101640 | int r1, r2; |
| 101499 | 101641 | affinity = sqlite3ExprAffinity(pLeft); |
| 101500 | 101642 | if( affinity<=SQLITE_AFF_NONE ){ |
| 101501 | 101643 | affinity = SQLITE_AFF_BLOB; |
| 101644 | + }else if( affinity==SQLITE_AFF_REAL ){ |
| 101645 | + affinity = SQLITE_AFF_NUMERIC; |
| 101502 | 101646 | } |
| 101503 | 101647 | if( pKeyInfo ){ |
| 101504 | 101648 | assert( sqlite3KeyInfoIsWriteable(pKeyInfo) ); |
| 101505 | 101649 | pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 101506 | 101650 | } |
| | @@ -101735,10 +101879,11 @@ |
| 101735 | 101879 | int destStep6 = 0; /* Start of code for Step 6 */ |
| 101736 | 101880 | int addrTruthOp; /* Address of opcode that determines the IN is true */ |
| 101737 | 101881 | int destNotNull; /* Jump here if a comparison is not true in step 6 */ |
| 101738 | 101882 | int addrTop; /* Top of the step-6 loop */ |
| 101739 | 101883 | int iTab = 0; /* Index to use */ |
| 101884 | + u8 okConstFactor = pParse->okConstFactor; |
| 101740 | 101885 | |
| 101741 | 101886 | assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 101742 | 101887 | pLeft = pExpr->pLeft; |
| 101743 | 101888 | if( sqlite3ExprCheckIN(pParse, pExpr) ) return; |
| 101744 | 101889 | zAff = exprINAffinity(pParse, pExpr); |
| | @@ -101779,12 +101924,18 @@ |
| 101779 | 101924 | ** |
| 101780 | 101925 | ** sqlite3FindInIndex() might have reordered the fields of the LHS vector |
| 101781 | 101926 | ** so that the fields are in the same order as an existing index. The |
| 101782 | 101927 | ** aiMap[] array contains a mapping from the original LHS field order to |
| 101783 | 101928 | ** the field order that matches the RHS index. |
| 101784 | | - */ |
| 101929 | + ** |
| 101930 | + ** Avoid factoring the LHS of the IN(...) expression out of the loop, |
| 101931 | + ** even if it is constant, as OP_Affinity may be used on the register |
| 101932 | + ** by code generated below. */ |
| 101933 | + assert( pParse->okConstFactor==okConstFactor ); |
| 101934 | + pParse->okConstFactor = 0; |
| 101785 | 101935 | rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy); |
| 101936 | + pParse->okConstFactor = okConstFactor; |
| 101786 | 101937 | for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */ |
| 101787 | 101938 | if( i==nVector ){ |
| 101788 | 101939 | /* LHS fields are not reordered */ |
| 101789 | 101940 | rLhs = rLhsOrig; |
| 101790 | 101941 | }else{ |
| | @@ -101806,25 +101957,17 @@ |
| 101806 | 101957 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 101807 | 101958 | int labelOk = sqlite3VdbeMakeLabel(pParse); |
| 101808 | 101959 | int r2, regToFree; |
| 101809 | 101960 | int regCkNull = 0; |
| 101810 | 101961 | int ii; |
| 101811 | | - int bLhsReal; /* True if the LHS of the IN has REAL affinity */ |
| 101812 | 101962 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 101813 | 101963 | if( destIfNull!=destIfFalse ){ |
| 101814 | 101964 | regCkNull = sqlite3GetTempReg(pParse); |
| 101815 | 101965 | sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull); |
| 101816 | 101966 | } |
| 101817 | | - bLhsReal = sqlite3ExprAffinity(pExpr->pLeft)==SQLITE_AFF_REAL; |
| 101818 | 101967 | for(ii=0; ii<pList->nExpr; ii++){ |
| 101819 | | - if( bLhsReal ){ |
| 101820 | | - r2 = regToFree = sqlite3GetTempReg(pParse); |
| 101821 | | - sqlite3ExprCode(pParse, pList->a[ii].pExpr, r2); |
| 101822 | | - sqlite3VdbeAddOp4(v, OP_Affinity, r2, 1, 0, "E", P4_STATIC); |
| 101823 | | - }else{ |
| 101824 | | - r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree); |
| 101825 | | - } |
| 101968 | + r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree); |
| 101826 | 101969 | if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){ |
| 101827 | 101970 | sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull); |
| 101828 | 101971 | } |
| 101829 | 101972 | sqlite3ReleaseTempReg(pParse, regToFree); |
| 101830 | 101973 | if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){ |
| | @@ -102394,14 +102537,10 @@ |
| 102394 | 102537 | } |
| 102395 | 102538 | if( aff>SQLITE_AFF_BLOB ){ |
| 102396 | 102539 | static const char zAff[] = "B\000C\000D\000E"; |
| 102397 | 102540 | assert( SQLITE_AFF_BLOB=='A' ); |
| 102398 | 102541 | assert( SQLITE_AFF_TEXT=='B' ); |
| 102399 | | - if( iReg!=target ){ |
| 102400 | | - sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target); |
| 102401 | | - iReg = target; |
| 102402 | | - } |
| 102403 | 102542 | sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0, |
| 102404 | 102543 | &zAff[(aff-'B')*2], P4_STATIC); |
| 102405 | 102544 | } |
| 102406 | 102545 | return iReg; |
| 102407 | 102546 | } |
| | @@ -105020,10 +105159,11 @@ |
| 105020 | 105159 | } |
| 105021 | 105160 | memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol); |
| 105022 | 105161 | for(i=0; i<pNew->nCol; i++){ |
| 105023 | 105162 | Column *pCol = &pNew->aCol[i]; |
| 105024 | 105163 | pCol->zName = sqlite3DbStrDup(db, pCol->zName); |
| 105164 | + pCol->hName = sqlite3StrIHash(pCol->zName); |
| 105025 | 105165 | pCol->zColl = 0; |
| 105026 | 105166 | pCol->pDflt = 0; |
| 105027 | 105167 | } |
| 105028 | 105168 | pNew->pSchema = db->aDb[iDb].pSchema; |
| 105029 | 105169 | pNew->addColOffset = pTab->addColOffset; |
| | @@ -105248,11 +105388,11 @@ |
| 105248 | 105388 | */ |
| 105249 | 105389 | SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){ |
| 105250 | 105390 | RenameToken *pNew; |
| 105251 | 105391 | assert( pPtr || pParse->db->mallocFailed ); |
| 105252 | 105392 | renameTokenCheckAll(pParse, pPtr); |
| 105253 | | - if( pParse->eParseMode!=PARSE_MODE_UNMAP ){ |
| 105393 | + if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){ |
| 105254 | 105394 | pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken)); |
| 105255 | 105395 | if( pNew ){ |
| 105256 | 105396 | pNew->p = pPtr; |
| 105257 | 105397 | pNew->t = *pToken; |
| 105258 | 105398 | pNew->pNext = pParse->pRename; |
| | @@ -105305,10 +105445,25 @@ |
| 105305 | 105445 | sqlite3WalkSelect(pWalker, p); |
| 105306 | 105446 | sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols); |
| 105307 | 105447 | } |
| 105308 | 105448 | } |
| 105309 | 105449 | } |
| 105450 | + |
| 105451 | +/* |
| 105452 | +** Unmap all tokens in the IdList object passed as the second argument. |
| 105453 | +*/ |
| 105454 | +static void unmapColumnIdlistNames( |
| 105455 | + Parse *pParse, |
| 105456 | + IdList *pIdList |
| 105457 | +){ |
| 105458 | + if( pIdList ){ |
| 105459 | + int ii; |
| 105460 | + for(ii=0; ii<pIdList->nId; ii++){ |
| 105461 | + sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName); |
| 105462 | + } |
| 105463 | + } |
| 105464 | +} |
| 105310 | 105465 | |
| 105311 | 105466 | /* |
| 105312 | 105467 | ** Walker callback used by sqlite3RenameExprUnmap(). |
| 105313 | 105468 | */ |
| 105314 | 105469 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| | @@ -105327,10 +105482,11 @@ |
| 105327 | 105482 | if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */ |
| 105328 | 105483 | SrcList *pSrc = p->pSrc; |
| 105329 | 105484 | for(i=0; i<pSrc->nSrc; i++){ |
| 105330 | 105485 | sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName); |
| 105331 | 105486 | if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort; |
| 105487 | + unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing); |
| 105332 | 105488 | } |
| 105333 | 105489 | } |
| 105334 | 105490 | |
| 105335 | 105491 | renameWalkWith(pWalker, p); |
| 105336 | 105492 | return WRC_Continue; |
| | @@ -105534,10 +105690,11 @@ |
| 105534 | 105690 | renameTokenFind(pParse, pCtx, (void*)zName); |
| 105535 | 105691 | } |
| 105536 | 105692 | } |
| 105537 | 105693 | } |
| 105538 | 105694 | } |
| 105695 | + |
| 105539 | 105696 | |
| 105540 | 105697 | /* |
| 105541 | 105698 | ** Parse the SQL statement zSql using Parse object (*p). The Parse object |
| 105542 | 105699 | ** is initialized by this function before it is used. |
| 105543 | 105700 | */ |
| | @@ -109619,10 +109776,11 @@ |
| 109619 | 109776 | int i; |
| 109620 | 109777 | Column *pCol; |
| 109621 | 109778 | assert( pTable!=0 ); |
| 109622 | 109779 | if( (pCol = pTable->aCol)!=0 ){ |
| 109623 | 109780 | for(i=0; i<pTable->nCol; i++, pCol++){ |
| 109781 | + assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) ); |
| 109624 | 109782 | sqlite3DbFree(db, pCol->zName); |
| 109625 | 109783 | sqlite3ExprDelete(db, pCol->pDflt); |
| 109626 | 109784 | sqlite3DbFree(db, pCol->zColl); |
| 109627 | 109785 | } |
| 109628 | 109786 | sqlite3DbFree(db, pTable->aCol); |
| | @@ -110267,10 +110425,11 @@ |
| 110267 | 110425 | p->aCol = aNew; |
| 110268 | 110426 | } |
| 110269 | 110427 | pCol = &p->aCol[p->nCol]; |
| 110270 | 110428 | memset(pCol, 0, sizeof(p->aCol[0])); |
| 110271 | 110429 | pCol->zName = z; |
| 110430 | + pCol->hName = sqlite3StrIHash(z); |
| 110272 | 110431 | sqlite3ColumnPropertiesFromName(p, pCol); |
| 110273 | 110432 | |
| 110274 | 110433 | if( pType->n==0 ){ |
| 110275 | 110434 | /* If there is no type specified, columns have the default affinity |
| 110276 | 110435 | ** 'BLOB' with a default size of 4 bytes. */ |
| | @@ -129768,10 +129927,11 @@ |
| 129768 | 129927 | } |
| 129769 | 129928 | zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); |
| 129770 | 129929 | if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); |
| 129771 | 129930 | } |
| 129772 | 129931 | pCol->zName = zName; |
| 129932 | + pCol->hName = sqlite3StrIHash(zName); |
| 129773 | 129933 | sqlite3ColumnPropertiesFromName(0, pCol); |
| 129774 | 129934 | if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ |
| 129775 | 129935 | sqlite3OomFault(db); |
| 129776 | 129936 | } |
| 129777 | 129937 | } |
| | @@ -131221,11 +131381,14 @@ |
| 131221 | 131381 | if( ExprHasProperty(pExpr, EP_FromJoin) |
| 131222 | 131382 | && pExpr->iRightJoinTable==pSubst->iTable |
| 131223 | 131383 | ){ |
| 131224 | 131384 | pExpr->iRightJoinTable = pSubst->iNewTable; |
| 131225 | 131385 | } |
| 131226 | | - if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){ |
| 131386 | + if( pExpr->op==TK_COLUMN |
| 131387 | + && pExpr->iTable==pSubst->iTable |
| 131388 | + && !ExprHasProperty(pExpr, EP_FixedCol) |
| 131389 | + ){ |
| 131227 | 131390 | if( pExpr->iColumn<0 ){ |
| 131228 | 131391 | pExpr->op = TK_NULL; |
| 131229 | 131392 | }else{ |
| 131230 | 131393 | Expr *pNew; |
| 131231 | 131394 | Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr; |
| | @@ -133133,10 +133296,11 @@ |
| 133133 | 133296 | Vdbe *v = pParse->pVdbe; |
| 133134 | 133297 | int i; |
| 133135 | 133298 | struct AggInfo_func *pFunc; |
| 133136 | 133299 | int nReg = pAggInfo->nFunc + pAggInfo->nColumn; |
| 133137 | 133300 | if( nReg==0 ) return; |
| 133301 | + if( pParse->nErr ) return; |
| 133138 | 133302 | #ifdef SQLITE_DEBUG |
| 133139 | 133303 | /* Verify that all AggInfo registers are within the range specified by |
| 133140 | 133304 | ** AggInfo.mnReg..AggInfo.mxReg */ |
| 133141 | 133305 | assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 ); |
| 133142 | 133306 | for(i=0; i<pAggInfo->nColumn; i++){ |
| | @@ -156491,14 +156655,15 @@ |
| 156491 | 156655 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 156492 | 156656 | ** regardless of the value of expr1. |
| 156493 | 156657 | */ |
| 156494 | 156658 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy202); |
| 156495 | 156659 | yymsp[-4].minor.yy202 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy192 ? "1" : "0"); |
| 156496 | | - }else if( 0 && yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){ |
| 156660 | + }else if( yymsp[-1].minor.yy242->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy242->a[0].pExpr) ){ |
| 156497 | 156661 | Expr *pRHS = yymsp[-1].minor.yy242->a[0].pExpr; |
| 156498 | 156662 | yymsp[-1].minor.yy242->a[0].pExpr = 0; |
| 156499 | 156663 | sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy242); |
| 156664 | + pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); |
| 156500 | 156665 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy202, pRHS); |
| 156501 | 156666 | if( yymsp[-3].minor.yy192 ) yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy202, 0); |
| 156502 | 156667 | }else{ |
| 156503 | 156668 | yymsp[-4].minor.yy202 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy202, 0); |
| 156504 | 156669 | if( yymsp[-4].minor.yy202 ){ |
| | @@ -158376,11 +158541,11 @@ |
| 158376 | 158541 | VVA_ONLY( u8 startedWithOom = db->mallocFailed ); |
| 158377 | 158542 | |
| 158378 | 158543 | assert( zSql!=0 ); |
| 158379 | 158544 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 158380 | 158545 | if( db->nVdbeActive==0 ){ |
| 158381 | | - db->u1.isInterrupted = 0; |
| 158546 | + AtomicStore(&db->u1.isInterrupted, 0); |
| 158382 | 158547 | } |
| 158383 | 158548 | pParse->rc = SQLITE_OK; |
| 158384 | 158549 | pParse->zTail = zSql; |
| 158385 | 158550 | assert( pzErrMsg!=0 ); |
| 158386 | 158551 | #ifdef SQLITE_DEBUG |
| | @@ -158421,11 +158586,11 @@ |
| 158421 | 158586 | ); |
| 158422 | 158587 | #else |
| 158423 | 158588 | if( tokenType>=TK_SPACE ){ |
| 158424 | 158589 | assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); |
| 158425 | 158590 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 158426 | | - if( db->u1.isInterrupted ){ |
| 158591 | + if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 158427 | 158592 | pParse->rc = SQLITE_INTERRUPT; |
| 158428 | 158593 | break; |
| 158429 | 158594 | } |
| 158430 | 158595 | if( tokenType==TK_SPACE ){ |
| 158431 | 158596 | zSql += n; |
| | @@ -160632,13 +160797,25 @@ |
| 160632 | 160797 | int delay, prior; |
| 160633 | 160798 | |
| 160634 | 160799 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 160635 | 160800 | if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){ |
| 160636 | 160801 | if( count ){ |
| 160637 | | - tmout = 0; |
| 160638 | | - sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout); |
| 160639 | | - return 0; |
| 160802 | + /* If this is the second or later invocation of the busy-handler, |
| 160803 | + ** but tmout==0, then code in wal.c must have disabled the blocking |
| 160804 | + ** lock before the SQLITE_BUSY error was hit. In this case, no delay |
| 160805 | + ** occurred while waiting for the lock, so fall through to the xSleep() |
| 160806 | + ** code below to delay a while before retrying the lock. |
| 160807 | + ** |
| 160808 | + ** Alternatively, if tmout!=0, then SQLite has already waited |
| 160809 | + ** sqlite3.busyTimeout ms for a lock. In this case, return 0 to |
| 160810 | + ** indicate that the lock should not be retried and the SQLITE_BUSY |
| 160811 | + ** error returned to the application. */ |
| 160812 | + if( tmout ){ |
| 160813 | + tmout = 0; |
| 160814 | + sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout); |
| 160815 | + return 0; |
| 160816 | + } |
| 160640 | 160817 | }else{ |
| 160641 | 160818 | return 1; |
| 160642 | 160819 | } |
| 160643 | 160820 | } |
| 160644 | 160821 | #else |
| | @@ -160784,11 +160961,11 @@ |
| 160784 | 160961 | if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){ |
| 160785 | 160962 | (void)SQLITE_MISUSE_BKPT; |
| 160786 | 160963 | return; |
| 160787 | 160964 | } |
| 160788 | 160965 | #endif |
| 160789 | | - db->u1.isInterrupted = 1; |
| 160966 | + AtomicStore(&db->u1.isInterrupted, 1); |
| 160790 | 160967 | } |
| 160791 | 160968 | |
| 160792 | 160969 | |
| 160793 | 160970 | /* |
| 160794 | 160971 | ** This function is exactly the same as sqlite3_create_function(), except |
| | @@ -161406,11 +161583,11 @@ |
| 161406 | 161583 | rc = sqlite3ApiExit(db, rc); |
| 161407 | 161584 | |
| 161408 | 161585 | /* If there are no active statements, clear the interrupt flag at this |
| 161409 | 161586 | ** point. */ |
| 161410 | 161587 | if( db->nVdbeActive==0 ){ |
| 161411 | | - db->u1.isInterrupted = 0; |
| 161588 | + AtomicStore(&db->u1.isInterrupted, 0); |
| 161412 | 161589 | } |
| 161413 | 161590 | |
| 161414 | 161591 | sqlite3_mutex_leave(db->mutex); |
| 161415 | 161592 | return rc; |
| 161416 | 161593 | #endif |
| | @@ -176558,10 +176735,11 @@ |
| 176558 | 176735 | ** b-tree node. And that the final byte of the doclist is 0x00. If either |
| 176559 | 176736 | ** of these statements is untrue, then the data structure is corrupt. |
| 176560 | 176737 | */ |
| 176561 | 176738 | if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode) |
| 176562 | 176739 | || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1]) |
| 176740 | + || pReader->nDoclist==0 |
| 176563 | 176741 | ){ |
| 176564 | 176742 | return FTS_CORRUPT_VTAB; |
| 176565 | 176743 | } |
| 176566 | 176744 | return SQLITE_OK; |
| 176567 | 176745 | } |
| | @@ -223728,11 +223906,11 @@ |
| 223728 | 223906 | int nArg, /* Number of args */ |
| 223729 | 223907 | sqlite3_value **apUnused /* Function arguments */ |
| 223730 | 223908 | ){ |
| 223731 | 223909 | assert( nArg==0 ); |
| 223732 | 223910 | UNUSED_PARAM2(nArg, apUnused); |
| 223733 | | - sqlite3_result_text(pCtx, "fts5: 2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84f525", -1, SQLITE_TRANSIENT); |
| 223911 | + sqlite3_result_text(pCtx, "fts5: 2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3e248c", -1, SQLITE_TRANSIENT); |
| 223734 | 223912 | } |
| 223735 | 223913 | |
| 223736 | 223914 | /* |
| 223737 | 223915 | ** Return true if zName is the extension on one of the shadow tables used |
| 223738 | 223916 | ** by this module. |
| | @@ -228510,12 +228688,12 @@ |
| 228510 | 228688 | } |
| 228511 | 228689 | #endif /* SQLITE_CORE */ |
| 228512 | 228690 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228513 | 228691 | |
| 228514 | 228692 | /************** End of stmt.c ************************************************/ |
| 228515 | | -#if __LINE__!=228515 |
| 228693 | +#if __LINE__!=228693 |
| 228516 | 228694 | #undef SQLITE_SOURCE_ID |
| 228517 | | -#define SQLITE_SOURCE_ID "2020-03-21 23:10:38 5d14a1c4f2fc17de98ad685ad1422cdfda89dfccb00afcaf32ee416b6f84alt2" |
| 228695 | +#define SQLITE_SOURCE_ID "2020-04-18 14:12:00 d5b0def96ba6d90f47bc96fab1ccf9c501d84885d086744035b16fd96f3ealt2" |
| 228518 | 228696 | #endif |
| 228519 | 228697 | /* Return the source-id for this library */ |
| 228520 | 228698 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228521 | 228699 | /************************** End of sqlite3.c ******************************/ |
| 228522 | 228700 | |