Fossil SCM
Update the built-in SQLite to the 3.8.12 alpha that includes the ShmBarrier fix.
Commit
96e698d23c3929e51013e378d9b3542179e38560
Parent
9271b4bb350532d…
2 files changed
+371
-159
+12
-7
+371
-159
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -325,11 +325,11 @@ | ||
| 325 | 325 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 326 | 326 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 327 | 327 | */ |
| 328 | 328 | #define SQLITE_VERSION "3.8.12" |
| 329 | 329 | #define SQLITE_VERSION_NUMBER 3008012 |
| 330 | -#define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a" | |
| 330 | +#define SQLITE_SOURCE_ID "2015-09-24 18:47:59 668fc1ebaf426f9eed3ed7865e41f1023dafebfb" | |
| 331 | 331 | |
| 332 | 332 | /* |
| 333 | 333 | ** CAPI3REF: Run-Time Library Version Numbers |
| 334 | 334 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 335 | 335 | ** |
| @@ -336,11 +336,11 @@ | ||
| 336 | 336 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 337 | 337 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 338 | 338 | ** but are associated with the library instead of the header file. ^(Cautious |
| 339 | 339 | ** programmers might include assert() statements in their application to |
| 340 | 340 | ** verify that values returned by these interfaces match the macros in |
| 341 | -** the header, and thus insure that the application is | |
| 341 | +** the header, and thus ensure that the application is | |
| 342 | 342 | ** compiled with matching library and header files. |
| 343 | 343 | ** |
| 344 | 344 | ** <blockquote><pre> |
| 345 | 345 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 346 | 346 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -586,11 +586,11 @@ | ||
| 586 | 586 | ** is not changed. |
| 587 | 587 | ** |
| 588 | 588 | ** Restrictions: |
| 589 | 589 | ** |
| 590 | 590 | ** <ul> |
| 591 | -** <li> The application must insure that the 1st parameter to sqlite3_exec() | |
| 591 | +** <li> The application must ensure that the 1st parameter to sqlite3_exec() | |
| 592 | 592 | ** is a valid and open [database connection]. |
| 593 | 593 | ** <li> The application must not close the [database connection] specified by |
| 594 | 594 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 595 | 595 | ** <li> The application must not modify the SQL statement text passed into |
| 596 | 596 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1579,13 +1579,15 @@ | ||
| 1579 | 1579 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1580 | 1580 | ** the application. The default configuration is recommended for most |
| 1581 | 1581 | ** applications and so this routine is usually not necessary. It is |
| 1582 | 1582 | ** provided to support rare applications with unusual needs. |
| 1583 | 1583 | ** |
| 1584 | -** The sqlite3_config() interface is not threadsafe. The application | |
| 1585 | -** must insure that no other SQLite interfaces are invoked by other | |
| 1586 | -** threads while sqlite3_config() is running. Furthermore, sqlite3_config() | |
| 1584 | +** <b>The sqlite3_config() interface is not threadsafe. The application | |
| 1585 | +** must ensure that no other SQLite interfaces are invoked by other | |
| 1586 | +** threads while sqlite3_config() is running.</b> | |
| 1587 | +** | |
| 1588 | +** The sqlite3_config() interface | |
| 1587 | 1589 | ** may only be invoked prior to library initialization using |
| 1588 | 1590 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1589 | 1591 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1590 | 1592 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1591 | 1593 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3840,11 +3842,11 @@ | ||
| 3840 | 3842 | ** name must be given in UTF-8 even if the original statement |
| 3841 | 3843 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3842 | 3844 | ** |
| 3843 | 3845 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3844 | 3846 | ** [sqlite3_bind_parameter_count()], and |
| 3845 | -** [sqlite3_bind_parameter_index()]. | |
| 3847 | +** [sqlite3_bind_parameter_name()]. | |
| 3846 | 3848 | */ |
| 3847 | 3849 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3848 | 3850 | |
| 3849 | 3851 | /* |
| 3850 | 3852 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6337,10 +6339,13 @@ | ||
| 6337 | 6339 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6338 | 6340 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6339 | 6341 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6340 | 6342 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6341 | 6343 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6344 | +** <li> SQLITE_MUTEX_STATIC_VFS1 | |
| 6345 | +** <li> SQLITE_MUTEX_STATIC_VFS2 | |
| 6346 | +** <li> SQLITE_MUTEX_STATIC_VFS3 | |
| 6342 | 6347 | ** </ul> |
| 6343 | 6348 | ** |
| 6344 | 6349 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6345 | 6350 | ** cause sqlite3_mutex_alloc() to create |
| 6346 | 6351 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| @@ -9623,11 +9628,11 @@ | ||
| 9623 | 9628 | int bias, |
| 9624 | 9629 | int *pRes |
| 9625 | 9630 | ); |
| 9626 | 9631 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 9627 | 9632 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 9628 | -SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*); | |
| 9633 | +SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, int); | |
| 9629 | 9634 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, |
| 9630 | 9635 | const void *pData, int nData, |
| 9631 | 9636 | int nZero, int bias, int seekResult); |
| 9632 | 9637 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 9633 | 9638 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| @@ -10339,10 +10344,13 @@ | ||
| 10339 | 10344 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 10340 | 10345 | |
| 10341 | 10346 | /* Functions used to configure a Pager object. */ |
| 10342 | 10347 | SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); |
| 10343 | 10348 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 10349 | +#ifdef SQLITE_HAS_CODEC | |
| 10350 | +SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); | |
| 10351 | +#endif | |
| 10344 | 10352 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 10345 | 10353 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 10346 | 10354 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 10347 | 10355 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| 10348 | 10356 | SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); |
| @@ -12341,10 +12349,11 @@ | ||
| 12341 | 12349 | #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */ |
| 12342 | 12350 | #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ |
| 12343 | 12351 | #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ |
| 12344 | 12352 | #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ |
| 12345 | 12353 | #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ |
| 12354 | +#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */ | |
| 12346 | 12355 | |
| 12347 | 12356 | /* Allowed return values from sqlite3WhereIsDistinct() |
| 12348 | 12357 | */ |
| 12349 | 12358 | #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ |
| 12350 | 12359 | #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ |
| @@ -13184,11 +13193,11 @@ | ||
| 13184 | 13193 | SQLITE_PRIVATE int sqlite3MutexEnd(void); |
| 13185 | 13194 | #endif |
| 13186 | 13195 | #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) |
| 13187 | 13196 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void); |
| 13188 | 13197 | #else |
| 13189 | -# define sqlite3MemoryBarrier(); | |
| 13198 | +# define sqlite3MemoryBarrier() | |
| 13190 | 13199 | #endif |
| 13191 | 13200 | |
| 13192 | 13201 | SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); |
| 13193 | 13202 | SQLITE_PRIVATE void sqlite3StatusUp(int, int); |
| 13194 | 13203 | SQLITE_PRIVATE void sqlite3StatusDown(int, int); |
| @@ -13369,10 +13378,13 @@ | ||
| 13369 | 13378 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 13370 | 13379 | SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*); |
| 13371 | 13380 | SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*); |
| 13372 | 13381 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 13373 | 13382 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 13383 | +#define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ | |
| 13384 | +#define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ | |
| 13385 | +#define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ | |
| 13374 | 13386 | SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); |
| 13375 | 13387 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 13376 | 13388 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 13377 | 13389 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 13378 | 13390 | SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); |
| @@ -13429,12 +13441,13 @@ | ||
| 13429 | 13441 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 13430 | 13442 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 13431 | 13443 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 13432 | 13444 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 13433 | 13445 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 13434 | -SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); | |
| 13435 | -SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*); | |
| 13446 | +SQLITE_PRIVATE void sqlite3GenerateRowDelete( | |
| 13447 | + Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); | |
| 13448 | +SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); | |
| 13436 | 13449 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 13437 | 13450 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 13438 | 13451 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 13439 | 13452 | u8,u8,int,int*); |
| 13440 | 13453 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| @@ -19319,11 +19332,11 @@ | ||
| 19319 | 19332 | ** For debugging purposes, record when the mutex subsystem is initialized |
| 19320 | 19333 | ** and uninitialized so that we can assert() if there is an attempt to |
| 19321 | 19334 | ** allocate a mutex while the system is uninitialized. |
| 19322 | 19335 | */ |
| 19323 | 19336 | static SQLITE_WSD int mutexIsInit = 0; |
| 19324 | -#endif /* SQLITE_DEBUG */ | |
| 19337 | +#endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */ | |
| 19325 | 19338 | |
| 19326 | 19339 | |
| 19327 | 19340 | #ifndef SQLITE_MUTEX_OMIT |
| 19328 | 19341 | /* |
| 19329 | 19342 | ** Initialize the mutex system. |
| @@ -19353,10 +19366,11 @@ | ||
| 19353 | 19366 | pTo->xMutexHeld = pFrom->xMutexHeld; |
| 19354 | 19367 | pTo->xMutexNotheld = pFrom->xMutexNotheld; |
| 19355 | 19368 | sqlite3MemoryBarrier(); |
| 19356 | 19369 | pTo->xMutexAlloc = pFrom->xMutexAlloc; |
| 19357 | 19370 | } |
| 19371 | + assert( sqlite3GlobalConfig.mutex.xMutexInit ); | |
| 19358 | 19372 | rc = sqlite3GlobalConfig.mutex.xMutexInit(); |
| 19359 | 19373 | |
| 19360 | 19374 | #ifdef SQLITE_DEBUG |
| 19361 | 19375 | GLOBAL(int, mutexIsInit) = 1; |
| 19362 | 19376 | #endif |
| @@ -19387,26 +19401,29 @@ | ||
| 19387 | 19401 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){ |
| 19388 | 19402 | #ifndef SQLITE_OMIT_AUTOINIT |
| 19389 | 19403 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 19390 | 19404 | if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 19391 | 19405 | #endif |
| 19406 | + assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); | |
| 19392 | 19407 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19393 | 19408 | } |
| 19394 | 19409 | |
| 19395 | 19410 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| 19396 | 19411 | if( !sqlite3GlobalConfig.bCoreMutex ){ |
| 19397 | 19412 | return 0; |
| 19398 | 19413 | } |
| 19399 | 19414 | assert( GLOBAL(int, mutexIsInit) ); |
| 19415 | + assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); | |
| 19400 | 19416 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19401 | 19417 | } |
| 19402 | 19418 | |
| 19403 | 19419 | /* |
| 19404 | 19420 | ** Free a dynamic mutex. |
| 19405 | 19421 | */ |
| 19406 | 19422 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){ |
| 19407 | 19423 | if( p ){ |
| 19424 | + assert( sqlite3GlobalConfig.mutex.xMutexFree ); | |
| 19408 | 19425 | sqlite3GlobalConfig.mutex.xMutexFree(p); |
| 19409 | 19426 | } |
| 19410 | 19427 | } |
| 19411 | 19428 | |
| 19412 | 19429 | /* |
| @@ -19413,10 +19430,11 @@ | ||
| 19413 | 19430 | ** Obtain the mutex p. If some other thread already has the mutex, block |
| 19414 | 19431 | ** until it can be obtained. |
| 19415 | 19432 | */ |
| 19416 | 19433 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){ |
| 19417 | 19434 | if( p ){ |
| 19435 | + assert( sqlite3GlobalConfig.mutex.xMutexEnter ); | |
| 19418 | 19436 | sqlite3GlobalConfig.mutex.xMutexEnter(p); |
| 19419 | 19437 | } |
| 19420 | 19438 | } |
| 19421 | 19439 | |
| 19422 | 19440 | /* |
| @@ -19424,10 +19442,11 @@ | ||
| 19424 | 19442 | ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. |
| 19425 | 19443 | */ |
| 19426 | 19444 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){ |
| 19427 | 19445 | int rc = SQLITE_OK; |
| 19428 | 19446 | if( p ){ |
| 19447 | + assert( sqlite3GlobalConfig.mutex.xMutexTry ); | |
| 19429 | 19448 | return sqlite3GlobalConfig.mutex.xMutexTry(p); |
| 19430 | 19449 | } |
| 19431 | 19450 | return rc; |
| 19432 | 19451 | } |
| 19433 | 19452 | |
| @@ -19437,10 +19456,11 @@ | ||
| 19437 | 19456 | ** is not currently entered. If a NULL pointer is passed as an argument |
| 19438 | 19457 | ** this function is a no-op. |
| 19439 | 19458 | */ |
| 19440 | 19459 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){ |
| 19441 | 19460 | if( p ){ |
| 19461 | + assert( sqlite3GlobalConfig.mutex.xMutexLeave ); | |
| 19442 | 19462 | sqlite3GlobalConfig.mutex.xMutexLeave(p); |
| 19443 | 19463 | } |
| 19444 | 19464 | } |
| 19445 | 19465 | |
| 19446 | 19466 | #ifndef NDEBUG |
| @@ -19447,13 +19467,15 @@ | ||
| 19447 | 19467 | /* |
| 19448 | 19468 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 19449 | 19469 | ** intended for use inside assert() statements. |
| 19450 | 19470 | */ |
| 19451 | 19471 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){ |
| 19472 | + assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); | |
| 19452 | 19473 | return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); |
| 19453 | 19474 | } |
| 19454 | 19475 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 19476 | + assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); | |
| 19455 | 19477 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 19456 | 19478 | } |
| 19457 | 19479 | #endif |
| 19458 | 19480 | |
| 19459 | 19481 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| @@ -19764,11 +19786,11 @@ | ||
| 19764 | 19786 | ** Try to provide a memory barrier operation, needed for initialization only. |
| 19765 | 19787 | */ |
| 19766 | 19788 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void){ |
| 19767 | 19789 | #if defined(SQLITE_MEMORY_BARRIER) |
| 19768 | 19790 | SQLITE_MEMORY_BARRIER; |
| 19769 | -#elif defined(__GNUC__) | |
| 19791 | +#elif defined(__GNUC__) && GCC_VERSION>=4001000 | |
| 19770 | 19792 | __sync_synchronize(); |
| 19771 | 19793 | #endif |
| 19772 | 19794 | } |
| 19773 | 19795 | |
| 19774 | 19796 | /* |
| @@ -30682,11 +30704,12 @@ | ||
| 30682 | 30704 | */ |
| 30683 | 30705 | static void unixShmBarrier( |
| 30684 | 30706 | sqlite3_file *fd /* Database file holding the shared memory */ |
| 30685 | 30707 | ){ |
| 30686 | 30708 | UNUSED_PARAMETER(fd); |
| 30687 | - unixEnterMutex(); | |
| 30709 | + sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ | |
| 30710 | + unixEnterMutex(); /* Also mutex, for redundancy */ | |
| 30688 | 30711 | unixLeaveMutex(); |
| 30689 | 30712 | } |
| 30690 | 30713 | |
| 30691 | 30714 | /* |
| 30692 | 30715 | ** Close a connection to shared-memory. Delete the underlying |
| @@ -37637,12 +37660,12 @@ | ||
| 37637 | 37660 | */ |
| 37638 | 37661 | static void winShmBarrier( |
| 37639 | 37662 | sqlite3_file *fd /* Database holding the shared memory */ |
| 37640 | 37663 | ){ |
| 37641 | 37664 | UNUSED_PARAMETER(fd); |
| 37642 | - /* MemoryBarrier(); // does not work -- do not know why not */ | |
| 37643 | - winShmEnterMutex(); | |
| 37665 | + sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ | |
| 37666 | + winShmEnterMutex(); /* Also mutex, for redundancy */ | |
| 37644 | 37667 | winShmLeaveMutex(); |
| 37645 | 37668 | } |
| 37646 | 37669 | |
| 37647 | 37670 | /* |
| 37648 | 37671 | ** This function is called to obtain a pointer to region iRegion of the |
| @@ -40930,11 +40953,11 @@ | ||
| 40930 | 40953 | ** this mutex is not held. */ |
| 40931 | 40954 | assert( pcache1.separateCache==0 ); |
| 40932 | 40955 | assert( pCache->pGroup==&pcache1.grp ); |
| 40933 | 40956 | pcache1LeaveMutex(pCache->pGroup); |
| 40934 | 40957 | #endif |
| 40935 | - if( benignMalloc ) sqlite3BeginBenignMalloc(); | |
| 40958 | + if( benignMalloc ){ sqlite3BeginBenignMalloc(); } | |
| 40936 | 40959 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 40937 | 40960 | pPg = pcache1Alloc(pCache->szPage); |
| 40938 | 40961 | p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); |
| 40939 | 40962 | if( !pPg || !p ){ |
| 40940 | 40963 | pcache1Free(pPg); |
| @@ -40943,11 +40966,11 @@ | ||
| 40943 | 40966 | } |
| 40944 | 40967 | #else |
| 40945 | 40968 | pPg = pcache1Alloc(pCache->szAlloc); |
| 40946 | 40969 | p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; |
| 40947 | 40970 | #endif |
| 40948 | - if( benignMalloc ) sqlite3EndBenignMalloc(); | |
| 40971 | + if( benignMalloc ){ sqlite3EndBenignMalloc(); } | |
| 40949 | 40972 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40950 | 40973 | pcache1EnterMutex(pCache->pGroup); |
| 40951 | 40974 | #endif |
| 40952 | 40975 | if( pPg==0 ) return 0; |
| 40953 | 40976 | p->page.pBuf = pPg; |
| @@ -44522,10 +44545,24 @@ | ||
| 44522 | 44545 | } |
| 44523 | 44546 | } |
| 44524 | 44547 | #else |
| 44525 | 44548 | # define pagerReportSize(X) /* No-op if we do not support a codec */ |
| 44526 | 44549 | #endif |
| 44550 | + | |
| 44551 | +#ifdef SQLITE_HAS_CODEC | |
| 44552 | +/* | |
| 44553 | +** Make sure the number of reserved bits is the same in the destination | |
| 44554 | +** pager as it is in the source. This comes up when a VACUUM changes the | |
| 44555 | +** number of reserved bits to the "optimal" amount. | |
| 44556 | +*/ | |
| 44557 | +SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager *pDest, Pager *pSrc){ | |
| 44558 | + if( pDest->nReserve!=pSrc->nReserve ){ | |
| 44559 | + pDest->nReserve = pSrc->nReserve; | |
| 44560 | + pagerReportSize(pDest); | |
| 44561 | + } | |
| 44562 | +} | |
| 44563 | +#endif | |
| 44527 | 44564 | |
| 44528 | 44565 | /* |
| 44529 | 44566 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 44530 | 44567 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 44531 | 44568 | ** The page begins at offset *pOffset into the file. The *pOffset |
| @@ -54479,10 +54516,53 @@ | ||
| 54479 | 54516 | pCur->apPage[i] = 0; |
| 54480 | 54517 | } |
| 54481 | 54518 | pCur->iPage = -1; |
| 54482 | 54519 | } |
| 54483 | 54520 | |
| 54521 | +/* | |
| 54522 | +** The cursor passed as the only argument must point to a valid entry | |
| 54523 | +** when this function is called (i.e. have eState==CURSOR_VALID). This | |
| 54524 | +** function saves the current cursor key in variables pCur->nKey and | |
| 54525 | +** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error | |
| 54526 | +** code otherwise. | |
| 54527 | +** | |
| 54528 | +** If the cursor is open on an intkey table, then the integer key | |
| 54529 | +** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to | |
| 54530 | +** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is | |
| 54531 | +** set to point to a malloced buffer pCur->nKey bytes in size containing | |
| 54532 | +** the key. | |
| 54533 | +*/ | |
| 54534 | +static int saveCursorKey(BtCursor *pCur){ | |
| 54535 | + int rc; | |
| 54536 | + assert( CURSOR_VALID==pCur->eState ); | |
| 54537 | + assert( 0==pCur->pKey ); | |
| 54538 | + assert( cursorHoldsMutex(pCur) ); | |
| 54539 | + | |
| 54540 | + rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); | |
| 54541 | + assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ | |
| 54542 | + | |
| 54543 | + /* If this is an intKey table, then the above call to BtreeKeySize() | |
| 54544 | + ** stores the integer key in pCur->nKey. In this case this value is | |
| 54545 | + ** all that is required. Otherwise, if pCur is not open on an intKey | |
| 54546 | + ** table, then malloc space for and store the pCur->nKey bytes of key | |
| 54547 | + ** data. */ | |
| 54548 | + if( 0==pCur->curIntKey ){ | |
| 54549 | + void *pKey = sqlite3Malloc( pCur->nKey ); | |
| 54550 | + if( pKey ){ | |
| 54551 | + rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); | |
| 54552 | + if( rc==SQLITE_OK ){ | |
| 54553 | + pCur->pKey = pKey; | |
| 54554 | + }else{ | |
| 54555 | + sqlite3_free(pKey); | |
| 54556 | + } | |
| 54557 | + }else{ | |
| 54558 | + rc = SQLITE_NOMEM; | |
| 54559 | + } | |
| 54560 | + } | |
| 54561 | + assert( !pCur->curIntKey || !pCur->pKey ); | |
| 54562 | + return rc; | |
| 54563 | +} | |
| 54484 | 54564 | |
| 54485 | 54565 | /* |
| 54486 | 54566 | ** Save the current cursor position in the variables BtCursor.nKey |
| 54487 | 54567 | ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK. |
| 54488 | 54568 | ** |
| @@ -54499,34 +54579,12 @@ | ||
| 54499 | 54579 | if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 54500 | 54580 | pCur->eState = CURSOR_VALID; |
| 54501 | 54581 | }else{ |
| 54502 | 54582 | pCur->skipNext = 0; |
| 54503 | 54583 | } |
| 54504 | - rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); | |
| 54505 | - assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ | |
| 54506 | - | |
| 54507 | - /* If this is an intKey table, then the above call to BtreeKeySize() | |
| 54508 | - ** stores the integer key in pCur->nKey. In this case this value is | |
| 54509 | - ** all that is required. Otherwise, if pCur is not open on an intKey | |
| 54510 | - ** table, then malloc space for and store the pCur->nKey bytes of key | |
| 54511 | - ** data. | |
| 54512 | - */ | |
| 54513 | - if( 0==pCur->curIntKey ){ | |
| 54514 | - void *pKey = sqlite3Malloc( pCur->nKey ); | |
| 54515 | - if( pKey ){ | |
| 54516 | - rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); | |
| 54517 | - if( rc==SQLITE_OK ){ | |
| 54518 | - pCur->pKey = pKey; | |
| 54519 | - }else{ | |
| 54520 | - sqlite3_free(pKey); | |
| 54521 | - } | |
| 54522 | - }else{ | |
| 54523 | - rc = SQLITE_NOMEM; | |
| 54524 | - } | |
| 54525 | - } | |
| 54526 | - assert( !pCur->curIntKey || !pCur->pKey ); | |
| 54527 | - | |
| 54584 | + | |
| 54585 | + rc = saveCursorKey(pCur); | |
| 54528 | 54586 | if( rc==SQLITE_OK ){ |
| 54529 | 54587 | btreeReleaseAllCursorPages(pCur); |
| 54530 | 54588 | pCur->eState = CURSOR_REQUIRESEEK; |
| 54531 | 54589 | } |
| 54532 | 54590 | |
| @@ -61914,22 +61972,28 @@ | ||
| 61914 | 61972 | end_insert: |
| 61915 | 61973 | return rc; |
| 61916 | 61974 | } |
| 61917 | 61975 | |
| 61918 | 61976 | /* |
| 61919 | -** Delete the entry that the cursor is pointing to. The cursor | |
| 61920 | -** is left pointing at an arbitrary location. | |
| 61977 | +** Delete the entry that the cursor is pointing to. | |
| 61978 | +** | |
| 61979 | +** If the second parameter is zero, then the cursor is left pointing at an | |
| 61980 | +** arbitrary location after the delete. If it is non-zero, then the cursor | |
| 61981 | +** is left in a state such that the next call to BtreeNext() or BtreePrev() | |
| 61982 | +** moves it to the same row as it would if the call to BtreeDelete() had | |
| 61983 | +** been omitted. | |
| 61921 | 61984 | */ |
| 61922 | -SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){ | |
| 61985 | +SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){ | |
| 61923 | 61986 | Btree *p = pCur->pBtree; |
| 61924 | 61987 | BtShared *pBt = p->pBt; |
| 61925 | 61988 | int rc; /* Return code */ |
| 61926 | 61989 | MemPage *pPage; /* Page to delete cell from */ |
| 61927 | 61990 | unsigned char *pCell; /* Pointer to cell to delete */ |
| 61928 | 61991 | int iCellIdx; /* Index of cell to delete */ |
| 61929 | 61992 | int iCellDepth; /* Depth of node containing pCell */ |
| 61930 | 61993 | u16 szCell; /* Size of the cell being deleted */ |
| 61994 | + int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */ | |
| 61931 | 61995 | |
| 61932 | 61996 | assert( cursorHoldsMutex(pCur) ); |
| 61933 | 61997 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 61934 | 61998 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 61935 | 61999 | assert( pCur->curFlags & BTCF_WriteFlag ); |
| @@ -61955,14 +62019,11 @@ | ||
| 61955 | 62019 | rc = sqlite3BtreePrevious(pCur, ¬Used); |
| 61956 | 62020 | if( rc ) return rc; |
| 61957 | 62021 | } |
| 61958 | 62022 | |
| 61959 | 62023 | /* Save the positions of any other cursors open on this table before |
| 61960 | - ** making any modifications. Make the page containing the entry to be | |
| 61961 | - ** deleted writable. Then free any overflow pages associated with the | |
| 61962 | - ** entry and finally remove the cell itself from within the page. | |
| 61963 | - */ | |
| 62024 | + ** making any modifications. */ | |
| 61964 | 62025 | if( pCur->curFlags & BTCF_Multiple ){ |
| 61965 | 62026 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 61966 | 62027 | if( rc ) return rc; |
| 61967 | 62028 | } |
| 61968 | 62029 | |
| @@ -61970,10 +62031,35 @@ | ||
| 61970 | 62031 | ** invalidate any incrblob cursors open on the row being deleted. */ |
| 61971 | 62032 | if( pCur->pKeyInfo==0 ){ |
| 61972 | 62033 | invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 61973 | 62034 | } |
| 61974 | 62035 | |
| 62036 | + /* If the bPreserve flag is set to true, then the cursor position must | |
| 62037 | + ** be preserved following this delete operation. If the current delete | |
| 62038 | + ** will cause a b-tree rebalance, then this is done by saving the cursor | |
| 62039 | + ** key and leaving the cursor in CURSOR_REQUIRESEEK state before | |
| 62040 | + ** returning. | |
| 62041 | + ** | |
| 62042 | + ** Or, if the current delete will not cause a rebalance, then the cursor | |
| 62043 | + ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately | |
| 62044 | + ** before or after the deleted entry. In this case set bSkipnext to true. */ | |
| 62045 | + if( bPreserve ){ | |
| 62046 | + if( !pPage->leaf | |
| 62047 | + || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) | |
| 62048 | + ){ | |
| 62049 | + /* A b-tree rebalance will be required after deleting this entry. | |
| 62050 | + ** Save the cursor key. */ | |
| 62051 | + rc = saveCursorKey(pCur); | |
| 62052 | + if( rc ) return rc; | |
| 62053 | + }else{ | |
| 62054 | + bSkipnext = 1; | |
| 62055 | + } | |
| 62056 | + } | |
| 62057 | + | |
| 62058 | + /* Make the page containing the entry to be deleted writable. Then free any | |
| 62059 | + ** overflow pages associated with the entry and finally remove the cell | |
| 62060 | + ** itself from within the page. */ | |
| 61975 | 62061 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 61976 | 62062 | if( rc ) return rc; |
| 61977 | 62063 | rc = clearCell(pPage, pCell, &szCell); |
| 61978 | 62064 | dropCell(pPage, iCellIdx, szCell, &rc); |
| 61979 | 62065 | if( rc ) return rc; |
| @@ -62023,11 +62109,27 @@ | ||
| 62023 | 62109 | } |
| 62024 | 62110 | rc = balance(pCur); |
| 62025 | 62111 | } |
| 62026 | 62112 | |
| 62027 | 62113 | if( rc==SQLITE_OK ){ |
| 62028 | - moveToRoot(pCur); | |
| 62114 | + if( bSkipnext ){ | |
| 62115 | + assert( bPreserve && pCur->iPage==iCellDepth ); | |
| 62116 | + assert( pPage==pCur->apPage[pCur->iPage] ); | |
| 62117 | + assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell ); | |
| 62118 | + pCur->eState = CURSOR_SKIPNEXT; | |
| 62119 | + if( iCellIdx>=pPage->nCell ){ | |
| 62120 | + pCur->skipNext = -1; | |
| 62121 | + pCur->aiIdx[iCellDepth] = pPage->nCell-1; | |
| 62122 | + }else{ | |
| 62123 | + pCur->skipNext = 1; | |
| 62124 | + } | |
| 62125 | + }else{ | |
| 62126 | + rc = moveToRoot(pCur); | |
| 62127 | + if( bPreserve ){ | |
| 62128 | + pCur->eState = CURSOR_REQUIRESEEK; | |
| 62129 | + } | |
| 62130 | + } | |
| 62029 | 62131 | } |
| 62030 | 62132 | return rc; |
| 62031 | 62133 | } |
| 62032 | 62134 | |
| 62033 | 62135 | /* |
| @@ -62745,10 +62847,14 @@ | ||
| 62745 | 62847 | } |
| 62746 | 62848 | } |
| 62747 | 62849 | #endif |
| 62748 | 62850 | iPage = get4byte(pOvflData); |
| 62749 | 62851 | sqlite3PagerUnref(pOvflPage); |
| 62852 | + | |
| 62853 | + if( isFreeList && N<(iPage!=0) ){ | |
| 62854 | + checkAppendMsg(pCheck, "free-page count in header is too small"); | |
| 62855 | + } | |
| 62750 | 62856 | } |
| 62751 | 62857 | } |
| 62752 | 62858 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 62753 | 62859 | |
| 62754 | 62860 | /* |
| @@ -64237,10 +64343,14 @@ | ||
| 64237 | 64343 | memset(&b, 0, sizeof(b)); |
| 64238 | 64344 | b.pSrcDb = pFrom->db; |
| 64239 | 64345 | b.pSrc = pFrom; |
| 64240 | 64346 | b.pDest = pTo; |
| 64241 | 64347 | b.iNext = 1; |
| 64348 | + | |
| 64349 | +#ifdef SQLITE_HAS_CODEC | |
| 64350 | + sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom)); | |
| 64351 | +#endif | |
| 64242 | 64352 | |
| 64243 | 64353 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 64244 | 64354 | ** file. By passing this as the number of pages to copy to |
| 64245 | 64355 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 64246 | 64356 | ** within a single call (unless an error occurs). The assert() statement |
| @@ -71166,22 +71276,23 @@ | ||
| 71166 | 71276 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 71167 | 71277 | __attribute__((aligned(8))) |
| 71168 | 71278 | #endif |
| 71169 | 71279 | = { |
| 71170 | 71280 | /* .u = */ {0}, |
| 71171 | - /* .flags = */ MEM_Null, | |
| 71172 | - /* .enc = */ 0, | |
| 71173 | - /* .n = */ 0, | |
| 71174 | - /* .z = */ 0, | |
| 71175 | - /* .zMalloc = */ 0, | |
| 71176 | - /* .szMalloc = */ 0, | |
| 71177 | - /* .iPadding1 = */ 0, | |
| 71178 | - /* .db = */ 0, | |
| 71179 | - /* .xDel = */ 0, | |
| 71281 | + /* .flags = */ (u16)MEM_Null, | |
| 71282 | + /* .enc = */ (u8)0, | |
| 71283 | + /* .eSubtype = */ (u8)0, | |
| 71284 | + /* .n = */ (int)0, | |
| 71285 | + /* .z = */ (char*)0, | |
| 71286 | + /* .zMalloc = */ (char*)0, | |
| 71287 | + /* .szMalloc = */ (int)0, | |
| 71288 | + /* .uTemp = */ (u32)0, | |
| 71289 | + /* .db = */ (sqlite3*)0, | |
| 71290 | + /* .xDel = */ (void(*)(void*))0, | |
| 71180 | 71291 | #ifdef SQLITE_DEBUG |
| 71181 | - /* .pScopyFrom = */ 0, | |
| 71182 | - /* .pFiller = */ 0, | |
| 71292 | + /* .pScopyFrom = */ (Mem*)0, | |
| 71293 | + /* .pFiller = */ (void*)0, | |
| 71183 | 71294 | #endif |
| 71184 | 71295 | }; |
| 71185 | 71296 | return &nullMem; |
| 71186 | 71297 | } |
| 71187 | 71298 | |
| @@ -76172,13 +76283,14 @@ | ||
| 76172 | 76283 | /* Opcode: NotExists P1 P2 P3 * * |
| 76173 | 76284 | ** Synopsis: intkey=r[P3] |
| 76174 | 76285 | ** |
| 76175 | 76286 | ** P1 is the index of a cursor open on an SQL table btree (with integer |
| 76176 | 76287 | ** keys). P3 is an integer rowid. If P1 does not contain a record with |
| 76177 | -** rowid P3 then jump immediately to P2. If P1 does contain a record | |
| 76178 | -** with rowid P3 then leave the cursor pointing at that record and fall | |
| 76179 | -** through to the next instruction. | |
| 76288 | +** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an | |
| 76289 | +** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then | |
| 76290 | +** leave the cursor pointing at that record and fall through to the next | |
| 76291 | +** instruction. | |
| 76180 | 76292 | ** |
| 76181 | 76293 | ** The OP_NotFound opcode performs the same operation on index btrees |
| 76182 | 76294 | ** (with arbitrary multi-value keys). |
| 76183 | 76295 | ** |
| 76184 | 76296 | ** This opcode leaves the cursor in a state where it cannot be advanced |
| @@ -76206,17 +76318,25 @@ | ||
| 76206 | 76318 | pCrsr = pC->pCursor; |
| 76207 | 76319 | assert( pCrsr!=0 ); |
| 76208 | 76320 | res = 0; |
| 76209 | 76321 | iKey = pIn3->u.i; |
| 76210 | 76322 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 76323 | + assert( rc==SQLITE_OK || res==0 ); | |
| 76211 | 76324 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 76212 | 76325 | pC->nullRow = 0; |
| 76213 | 76326 | pC->cacheStatus = CACHE_STALE; |
| 76214 | 76327 | pC->deferredMoveto = 0; |
| 76215 | 76328 | VdbeBranchTaken(res!=0,2); |
| 76216 | 76329 | pC->seekResult = res; |
| 76217 | - if( res!=0 ) goto jump_to_p2; | |
| 76330 | + if( res!=0 ){ | |
| 76331 | + assert( rc==SQLITE_OK ); | |
| 76332 | + if( pOp->p2==0 ){ | |
| 76333 | + rc = SQLITE_CORRUPT_BKPT; | |
| 76334 | + }else{ | |
| 76335 | + goto jump_to_p2; | |
| 76336 | + } | |
| 76337 | + } | |
| 76218 | 76338 | break; |
| 76219 | 76339 | } |
| 76220 | 76340 | |
| 76221 | 76341 | /* Opcode: Sequence P1 P2 * * * |
| 76222 | 76342 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -76478,18 +76598,19 @@ | ||
| 76478 | 76598 | assert( pC->iDb>=0 ); |
| 76479 | 76599 | } |
| 76480 | 76600 | break; |
| 76481 | 76601 | } |
| 76482 | 76602 | |
| 76483 | -/* Opcode: Delete P1 P2 * P4 * | |
| 76603 | +/* Opcode: Delete P1 P2 * P4 P5 | |
| 76484 | 76604 | ** |
| 76485 | 76605 | ** Delete the record at which the P1 cursor is currently pointing. |
| 76486 | 76606 | ** |
| 76487 | -** The cursor will be left pointing at either the next or the previous | |
| 76488 | -** record in the table. If it is left pointing at the next record, then | |
| 76489 | -** the next Next instruction will be a no-op. Hence it is OK to delete | |
| 76490 | -** a record from within a Next loop. | |
| 76607 | +** If the P5 parameter is non-zero, the cursor will be left pointing at | |
| 76608 | +** either the next or the previous record in the table. If it is left | |
| 76609 | +** pointing at the next record, then the next Next instruction will be a | |
| 76610 | +** no-op. As a result, in this case it is OK to delete a record from within a | |
| 76611 | +** Next loop. If P5 is zero, then the cursor is left in an undefined state. | |
| 76491 | 76612 | ** |
| 76492 | 76613 | ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is |
| 76493 | 76614 | ** incremented (otherwise not). |
| 76494 | 76615 | ** |
| 76495 | 76616 | ** P1 must not be pseudo-table. It has to be a real table with |
| @@ -76500,33 +76621,39 @@ | ||
| 76500 | 76621 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 76501 | 76622 | ** using OP_NotFound prior to invoking this opcode. |
| 76502 | 76623 | */ |
| 76503 | 76624 | case OP_Delete: { |
| 76504 | 76625 | VdbeCursor *pC; |
| 76626 | + u8 hasUpdateCallback; | |
| 76505 | 76627 | |
| 76506 | 76628 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 76507 | 76629 | pC = p->apCsr[pOp->p1]; |
| 76508 | 76630 | assert( pC!=0 ); |
| 76509 | 76631 | assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 76510 | 76632 | assert( pC->deferredMoveto==0 ); |
| 76633 | + | |
| 76634 | + hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable; | |
| 76635 | + if( pOp->p5 && hasUpdateCallback ){ | |
| 76636 | + sqlite3BtreeKeySize(pC->pCursor, &pC->movetoTarget); | |
| 76637 | + } | |
| 76511 | 76638 | |
| 76512 | 76639 | #ifdef SQLITE_DEBUG |
| 76513 | 76640 | /* The seek operation that positioned the cursor prior to OP_Delete will |
| 76514 | 76641 | ** have also set the pC->movetoTarget field to the rowid of the row that |
| 76515 | 76642 | ** is being deleted */ |
| 76516 | - if( pOp->p4.z && pC->isTable ){ | |
| 76643 | + if( pOp->p4.z && pC->isTable && pOp->p5==0 ){ | |
| 76517 | 76644 | i64 iKey = 0; |
| 76518 | 76645 | sqlite3BtreeKeySize(pC->pCursor, &iKey); |
| 76519 | 76646 | assert( pC->movetoTarget==iKey ); |
| 76520 | 76647 | } |
| 76521 | 76648 | #endif |
| 76522 | 76649 | |
| 76523 | - rc = sqlite3BtreeDelete(pC->pCursor); | |
| 76650 | + rc = sqlite3BtreeDelete(pC->pCursor, pOp->p5); | |
| 76524 | 76651 | pC->cacheStatus = CACHE_STALE; |
| 76525 | 76652 | |
| 76526 | 76653 | /* Invoke the update-hook if required. */ |
| 76527 | - if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ | |
| 76654 | + if( rc==SQLITE_OK && hasUpdateCallback ){ | |
| 76528 | 76655 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 76529 | 76656 | db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); |
| 76530 | 76657 | assert( pC->iDb>=0 ); |
| 76531 | 76658 | } |
| 76532 | 76659 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| @@ -77061,11 +77188,11 @@ | ||
| 77061 | 77188 | #ifdef SQLITE_DEBUG |
| 77062 | 77189 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 77063 | 77190 | #endif |
| 77064 | 77191 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 77065 | 77192 | if( rc==SQLITE_OK && res==0 ){ |
| 77066 | - rc = sqlite3BtreeDelete(pCrsr); | |
| 77193 | + rc = sqlite3BtreeDelete(pCrsr, 0); | |
| 77067 | 77194 | } |
| 77068 | 77195 | assert( pC->deferredMoveto==0 ); |
| 77069 | 77196 | pC->cacheStatus = CACHE_STALE; |
| 77070 | 77197 | break; |
| 77071 | 77198 | } |
| @@ -83123,12 +83250,17 @@ | ||
| 83123 | 83250 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 83124 | 83251 | |
| 83125 | 83252 | /* |
| 83126 | 83253 | ** Perhaps the name is a reference to the ROWID |
| 83127 | 83254 | */ |
| 83128 | - if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol) | |
| 83129 | - && VisibleRowid(pMatch->pTab) ){ | |
| 83255 | + if( cnt==0 | |
| 83256 | + && cntTab==1 | |
| 83257 | + && pMatch | |
| 83258 | + && (pNC->ncFlags & NC_IdxExpr)==0 | |
| 83259 | + && sqlite3IsRowid(zCol) | |
| 83260 | + && VisibleRowid(pMatch->pTab) | |
| 83261 | + ){ | |
| 83130 | 83262 | cnt = 1; |
| 83131 | 83263 | pExpr->iColumn = -1; /* IMP: R-44911-55124 */ |
| 83132 | 83264 | pExpr->affinity = SQLITE_AFF_INTEGER; |
| 83133 | 83265 | } |
| 83134 | 83266 | |
| @@ -92416,11 +92548,11 @@ | ||
| 92416 | 92548 | }else{ |
| 92417 | 92549 | sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); |
| 92418 | 92550 | } |
| 92419 | 92551 | pParse->checkSchema = 1; |
| 92420 | 92552 | } |
| 92421 | -#if SQLITE_USER_AUTHENICATION | |
| 92553 | +#if SQLITE_USER_AUTHENTICATION | |
| 92422 | 92554 | else if( pParse->db->auth.authLevel<UAUTH_User ){ |
| 92423 | 92555 | sqlite3ErrorMsg(pParse, "user not authenticated"); |
| 92424 | 92556 | p = 0; |
| 92425 | 92557 | } |
| 92426 | 92558 | #endif |
| @@ -97188,11 +97320,11 @@ | ||
| 97188 | 97320 | AuthContext sContext; /* Authorization context */ |
| 97189 | 97321 | NameContext sNC; /* Name context to resolve expressions in */ |
| 97190 | 97322 | int iDb; /* Database number */ |
| 97191 | 97323 | int memCnt = -1; /* Memory cell used for change counting */ |
| 97192 | 97324 | int rcauth; /* Value returned by authorization callback */ |
| 97193 | - int okOnePass; /* True for one-pass algorithm without the FIFO */ | |
| 97325 | + int eOnePass; /* ONEPASS_OFF or _SINGLE or _MULTI */ | |
| 97194 | 97326 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 97195 | 97327 | u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */ |
| 97196 | 97328 | Index *pPk; /* The PRIMARY KEY index on the table */ |
| 97197 | 97329 | int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */ |
| 97198 | 97330 | i16 nPk = 1; /* Number of columns in the PRIMARY KEY */ |
| @@ -97200,16 +97332,16 @@ | ||
| 97200 | 97332 | i16 nKey; /* Number of memory cells in the row key */ |
| 97201 | 97333 | int iEphCur = 0; /* Ephemeral table holding all primary key values */ |
| 97202 | 97334 | int iRowSet = 0; /* Register for rowset of rows to delete */ |
| 97203 | 97335 | int addrBypass = 0; /* Address of jump over the delete logic */ |
| 97204 | 97336 | int addrLoop = 0; /* Top of the delete loop */ |
| 97205 | - int addrDelete = 0; /* Jump directly to the delete logic */ | |
| 97206 | 97337 | int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ |
| 97207 | 97338 | |
| 97208 | 97339 | #ifndef SQLITE_OMIT_TRIGGER |
| 97209 | 97340 | int isView; /* True if attempting to delete from a view */ |
| 97210 | 97341 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 97342 | + int bComplex; /* True if there are either triggers or FKs */ | |
| 97211 | 97343 | #endif |
| 97212 | 97344 | |
| 97213 | 97345 | memset(&sContext, 0, sizeof(sContext)); |
| 97214 | 97346 | db = pParse->db; |
| 97215 | 97347 | if( pParse->nErr || db->mallocFailed ){ |
| @@ -97229,13 +97361,15 @@ | ||
| 97229 | 97361 | ** deleted from is a view |
| 97230 | 97362 | */ |
| 97231 | 97363 | #ifndef SQLITE_OMIT_TRIGGER |
| 97232 | 97364 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 97233 | 97365 | isView = pTab->pSelect!=0; |
| 97366 | + bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); | |
| 97234 | 97367 | #else |
| 97235 | 97368 | # define pTrigger 0 |
| 97236 | 97369 | # define isView 0 |
| 97370 | +# define bComplex 0 | |
| 97237 | 97371 | #endif |
| 97238 | 97372 | #ifdef SQLITE_OMIT_VIEW |
| 97239 | 97373 | # undef isView |
| 97240 | 97374 | # define isView 0 |
| 97241 | 97375 | #endif |
| @@ -97312,12 +97446,14 @@ | ||
| 97312 | 97446 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 97313 | 97447 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 97314 | 97448 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 97315 | 97449 | ** this optimization caused the row change count (the value returned by |
| 97316 | 97450 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 97317 | - if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) | |
| 97318 | - && 0==sqlite3FkRequired(pParse, pTab, 0, 0) | |
| 97451 | + if( rcauth==SQLITE_OK | |
| 97452 | + && pWhere==0 | |
| 97453 | + && !bComplex | |
| 97454 | + && !IsVirtual(pTab) | |
| 97319 | 97455 | ){ |
| 97320 | 97456 | assert( !isView ); |
| 97321 | 97457 | sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 97322 | 97458 | if( HasRowid(pTab) ){ |
| 97323 | 97459 | sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt, |
| @@ -97328,10 +97464,12 @@ | ||
| 97328 | 97464 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| 97329 | 97465 | } |
| 97330 | 97466 | }else |
| 97331 | 97467 | #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ |
| 97332 | 97468 | { |
| 97469 | + u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK; | |
| 97470 | + wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW); | |
| 97333 | 97471 | if( HasRowid(pTab) ){ |
| 97334 | 97472 | /* For a rowid table, initialize the RowSet to an empty set */ |
| 97335 | 97473 | pPk = 0; |
| 97336 | 97474 | nPk = 1; |
| 97337 | 97475 | iRowSet = ++pParse->nMem; |
| @@ -97348,17 +97486,22 @@ | ||
| 97348 | 97486 | addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk); |
| 97349 | 97487 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 97350 | 97488 | } |
| 97351 | 97489 | |
| 97352 | 97490 | /* Construct a query to find the rowid or primary key for every row |
| 97353 | - ** to be deleted, based on the WHERE clause. | |
| 97491 | + ** to be deleted, based on the WHERE clause. Set variable eOnePass | |
| 97492 | + ** to indicate the strategy used to implement this delete: | |
| 97493 | + ** | |
| 97494 | + ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values. | |
| 97495 | + ** ONEPASS_SINGLE: One-pass approach - at most one row deleted. | |
| 97496 | + ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted. | |
| 97354 | 97497 | */ |
| 97355 | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, | |
| 97356 | - WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK, | |
| 97357 | - iTabCur+1); | |
| 97498 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1); | |
| 97358 | 97499 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 97359 | - okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); | |
| 97500 | + eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); | |
| 97501 | + assert( IsVirtual(pTab)==0 || eOnePass==ONEPASS_OFF ); | |
| 97502 | + assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF ); | |
| 97360 | 97503 | |
| 97361 | 97504 | /* Keep track of the number of rows to be deleted */ |
| 97362 | 97505 | if( db->flags & SQLITE_CountRows ){ |
| 97363 | 97506 | sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1); |
| 97364 | 97507 | } |
| @@ -97375,15 +97518,14 @@ | ||
| 97375 | 97518 | iKey = pParse->nMem + 1; |
| 97376 | 97519 | iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0); |
| 97377 | 97520 | if( iKey>pParse->nMem ) pParse->nMem = iKey; |
| 97378 | 97521 | } |
| 97379 | 97522 | |
| 97380 | - if( okOnePass ){ | |
| 97381 | - /* For ONEPASS, no need to store the rowid/primary-key. There is only | |
| 97523 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 97524 | + /* For ONEPASS, no need to store the rowid/primary-key. There is only | |
| 97382 | 97525 | ** one, so just keep it in its register(s) and fall through to the |
| 97383 | - ** delete code. | |
| 97384 | - */ | |
| 97526 | + ** delete code. */ | |
| 97385 | 97527 | nKey = nPk; /* OP_Found will use an unpacked key */ |
| 97386 | 97528 | aToOpen = sqlite3DbMallocRaw(db, nIdx+2); |
| 97387 | 97529 | if( aToOpen==0 ){ |
| 97388 | 97530 | sqlite3WhereEnd(pWInfo); |
| 97389 | 97531 | goto delete_from_cleanup; |
| @@ -97391,53 +97533,56 @@ | ||
| 97391 | 97533 | memset(aToOpen, 1, nIdx+1); |
| 97392 | 97534 | aToOpen[nIdx+1] = 0; |
| 97393 | 97535 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0; |
| 97394 | 97536 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0; |
| 97395 | 97537 | if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen); |
| 97396 | - addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */ | |
| 97397 | - }else if( pPk ){ | |
| 97398 | - /* Construct a composite key for the row to be deleted and remember it */ | |
| 97399 | - iKey = ++pParse->nMem; | |
| 97400 | - nKey = 0; /* Zero tells OP_Found to use a composite key */ | |
| 97401 | - sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, | |
| 97402 | - sqlite3IndexAffinityStr(pParse->db, pPk), nPk); | |
| 97403 | - sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); | |
| 97404 | - }else{ | |
| 97405 | - /* Get the rowid of the row to be deleted and remember it in the RowSet */ | |
| 97406 | - nKey = 1; /* OP_Seek always uses a single rowid */ | |
| 97407 | - sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); | |
| 97408 | - } | |
| 97409 | - | |
| 97410 | - /* End of the WHERE loop */ | |
| 97411 | - sqlite3WhereEnd(pWInfo); | |
| 97412 | - if( okOnePass ){ | |
| 97413 | - /* Bypass the delete logic below if the WHERE loop found zero rows */ | |
| 97538 | + }else{ | |
| 97539 | + if( pPk ){ | |
| 97540 | + /* Add the PK key for this row to the temporary table */ | |
| 97541 | + iKey = ++pParse->nMem; | |
| 97542 | + nKey = 0; /* Zero tells OP_Found to use a composite key */ | |
| 97543 | + sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, | |
| 97544 | + sqlite3IndexAffinityStr(pParse->db, pPk), nPk); | |
| 97545 | + sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); | |
| 97546 | + }else{ | |
| 97547 | + /* Add the rowid of the row to be deleted to the RowSet */ | |
| 97548 | + nKey = 1; /* OP_Seek always uses a single rowid */ | |
| 97549 | + sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); | |
| 97550 | + } | |
| 97551 | + } | |
| 97552 | + | |
| 97553 | + /* If this DELETE cannot use the ONEPASS strategy, this is the | |
| 97554 | + ** end of the WHERE loop */ | |
| 97555 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 97414 | 97556 | addrBypass = sqlite3VdbeMakeLabel(v); |
| 97415 | - sqlite3VdbeGoto(v, addrBypass); | |
| 97416 | - sqlite3VdbeJumpHere(v, addrDelete); | |
| 97557 | + }else{ | |
| 97558 | + sqlite3WhereEnd(pWInfo); | |
| 97417 | 97559 | } |
| 97418 | 97560 | |
| 97419 | 97561 | /* Unless this is a view, open cursors for the table we are |
| 97420 | 97562 | ** deleting from and all its indices. If this is a view, then the |
| 97421 | 97563 | ** only effect this statement has is to fire the INSTEAD OF |
| 97422 | 97564 | ** triggers. |
| 97423 | 97565 | */ |
| 97424 | 97566 | if( !isView ){ |
| 97567 | + int iAddrOnce = 0; | |
| 97568 | + if( eOnePass==ONEPASS_MULTI ){ | |
| 97569 | + iAddrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v); | |
| 97570 | + } | |
| 97425 | 97571 | testcase( IsVirtual(pTab) ); |
| 97426 | 97572 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen, |
| 97427 | 97573 | &iDataCur, &iIdxCur); |
| 97428 | 97574 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 97429 | 97575 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 97576 | + if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce); | |
| 97430 | 97577 | } |
| 97431 | 97578 | |
| 97432 | 97579 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 97433 | 97580 | ** where-clause loop above. |
| 97434 | 97581 | */ |
| 97435 | - if( okOnePass ){ | |
| 97436 | - /* Just one row. Hence the top-of-loop is a no-op */ | |
| 97582 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 97437 | 97583 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 97438 | - assert( !IsVirtual(pTab) ); | |
| 97439 | 97584 | if( aToOpen[iDataCur-iTabCur] ){ |
| 97440 | 97585 | assert( pPk!=0 || pTab->pSelect!=0 ); |
| 97441 | 97586 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 97442 | 97587 | VdbeCoverage(v); |
| 97443 | 97588 | } |
| @@ -97461,17 +97606,22 @@ | ||
| 97461 | 97606 | sqlite3MayAbort(pParse); |
| 97462 | 97607 | }else |
| 97463 | 97608 | #endif |
| 97464 | 97609 | { |
| 97465 | 97610 | int count = (pParse->nested==0); /* True to count changes */ |
| 97611 | + int iIdxNoSeek = -1; | |
| 97612 | + if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){ | |
| 97613 | + iIdxNoSeek = aiCurOnePass[1]; | |
| 97614 | + } | |
| 97466 | 97615 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 97467 | - iKey, nKey, count, OE_Default, okOnePass); | |
| 97616 | + iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek); | |
| 97468 | 97617 | } |
| 97469 | 97618 | |
| 97470 | 97619 | /* End of the loop over all rowids/primary-keys. */ |
| 97471 | - if( okOnePass ){ | |
| 97620 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 97472 | 97621 | sqlite3VdbeResolveLabel(v, addrBypass); |
| 97622 | + sqlite3WhereEnd(pWInfo); | |
| 97473 | 97623 | }else if( pPk ){ |
| 97474 | 97624 | sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v); |
| 97475 | 97625 | sqlite3VdbeJumpHere(v, addrLoop); |
| 97476 | 97626 | }else{ |
| 97477 | 97627 | sqlite3VdbeGoto(v, addrLoop); |
| @@ -97539,10 +97689,29 @@ | ||
| 97539 | 97689 | ** |
| 97540 | 97690 | ** 3. The primary key for the row to be deleted must be stored in a |
| 97541 | 97691 | ** sequence of nPk memory cells starting at iPk. If nPk==0 that means |
| 97542 | 97692 | ** that a search record formed from OP_MakeRecord is contained in the |
| 97543 | 97693 | ** single memory location iPk. |
| 97694 | +** | |
| 97695 | +** eMode: | |
| 97696 | +** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or | |
| 97697 | +** ONEPASS_MULTI. If eMode is not ONEPASS_OFF, then the cursor | |
| 97698 | +** iDataCur already points to the row to delete. If eMode is ONEPASS_OFF | |
| 97699 | +** then this function must seek iDataCur to the entry identified by iPk | |
| 97700 | +** and nPk before reading from it. | |
| 97701 | +** | |
| 97702 | +** If eMode is ONEPASS_MULTI, then this call is being made as part | |
| 97703 | +** of a ONEPASS delete that affects multiple rows. In this case, if | |
| 97704 | +** iIdxNoSeek is a valid cursor number (>=0), then its position should | |
| 97705 | +** be preserved following the delete operation. Or, if iIdxNoSeek is not | |
| 97706 | +** a valid cursor number, the position of iDataCur should be preserved | |
| 97707 | +** instead. | |
| 97708 | +** | |
| 97709 | +** iIdxNoSeek: | |
| 97710 | +** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an | |
| 97711 | +** index cursor (from within array of cursors starting at iIdxCur) that | |
| 97712 | +** already points to the index entry to be deleted. | |
| 97544 | 97713 | */ |
| 97545 | 97714 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 97546 | 97715 | Parse *pParse, /* Parsing context */ |
| 97547 | 97716 | Table *pTab, /* Table containing the row to be deleted */ |
| 97548 | 97717 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -97550,11 +97719,12 @@ | ||
| 97550 | 97719 | int iIdxCur, /* First index cursor */ |
| 97551 | 97720 | int iPk, /* First memory cell containing the PRIMARY KEY */ |
| 97552 | 97721 | i16 nPk, /* Number of PRIMARY KEY memory cells */ |
| 97553 | 97722 | u8 count, /* If non-zero, increment the row change counter */ |
| 97554 | 97723 | u8 onconf, /* Default ON CONFLICT policy for triggers */ |
| 97555 | - u8 bNoSeek /* iDataCur is already pointing to the row to delete */ | |
| 97724 | + u8 eMode, /* ONEPASS_OFF, _SINGLE, or _MULTI. See above */ | |
| 97725 | + int iIdxNoSeek /* Cursor number of cursor that does not need seeking */ | |
| 97556 | 97726 | ){ |
| 97557 | 97727 | Vdbe *v = pParse->pVdbe; /* Vdbe */ |
| 97558 | 97728 | int iOld = 0; /* First register in OLD.* array */ |
| 97559 | 97729 | int iLabel; /* Label resolved to end of generated code */ |
| 97560 | 97730 | u8 opSeek; /* Seek opcode */ |
| @@ -97567,11 +97737,11 @@ | ||
| 97567 | 97737 | /* Seek cursor iCur to the row to delete. If this row no longer exists |
| 97568 | 97738 | ** (this can happen if a trigger program has already deleted it), do |
| 97569 | 97739 | ** not attempt to delete it or fire any DELETE triggers. */ |
| 97570 | 97740 | iLabel = sqlite3VdbeMakeLabel(v); |
| 97571 | 97741 | opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound; |
| 97572 | - if( !bNoSeek ){ | |
| 97742 | + if( eMode==ONEPASS_OFF ){ | |
| 97573 | 97743 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 97574 | 97744 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 97575 | 97745 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 97576 | 97746 | } |
| 97577 | 97747 | |
| @@ -97627,15 +97797,19 @@ | ||
| 97627 | 97797 | |
| 97628 | 97798 | /* Delete the index and table entries. Skip this step if pTab is really |
| 97629 | 97799 | ** a view (in which case the only effect of the DELETE statement is to |
| 97630 | 97800 | ** fire the INSTEAD OF triggers). */ |
| 97631 | 97801 | if( pTab->pSelect==0 ){ |
| 97632 | - sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0); | |
| 97802 | + sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); | |
| 97633 | 97803 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 97634 | 97804 | if( count ){ |
| 97635 | 97805 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); |
| 97636 | 97806 | } |
| 97807 | + if( iIdxNoSeek>=0 ){ | |
| 97808 | + sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); | |
| 97809 | + } | |
| 97810 | + sqlite3VdbeChangeP5(v, eMode==ONEPASS_MULTI); | |
| 97637 | 97811 | } |
| 97638 | 97812 | |
| 97639 | 97813 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 97640 | 97814 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 97641 | 97815 | ** to the row just deleted. */ |
| @@ -97674,11 +97848,12 @@ | ||
| 97674 | 97848 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete( |
| 97675 | 97849 | Parse *pParse, /* Parsing and code generating context */ |
| 97676 | 97850 | Table *pTab, /* Table containing the row to be deleted */ |
| 97677 | 97851 | int iDataCur, /* Cursor of table holding data. */ |
| 97678 | 97852 | int iIdxCur, /* First index cursor */ |
| 97679 | - int *aRegIdx /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */ | |
| 97853 | + int *aRegIdx, /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */ | |
| 97854 | + int iIdxNoSeek /* Do not delete from this cursor */ | |
| 97680 | 97855 | ){ |
| 97681 | 97856 | int i; /* Index loop counter */ |
| 97682 | 97857 | int r1 = -1; /* Register holding an index key */ |
| 97683 | 97858 | int iPartIdxLabel; /* Jump destination for skipping partial index entries */ |
| 97684 | 97859 | Index *pIdx; /* Current index */ |
| @@ -97690,15 +97865,16 @@ | ||
| 97690 | 97865 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 97691 | 97866 | for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ |
| 97692 | 97867 | assert( iIdxCur+i!=iDataCur || pPk==pIdx ); |
| 97693 | 97868 | if( aRegIdx!=0 && aRegIdx[i]==0 ) continue; |
| 97694 | 97869 | if( pIdx==pPk ) continue; |
| 97870 | + if( iIdxCur+i==iIdxNoSeek ) continue; | |
| 97695 | 97871 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 97696 | 97872 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 97697 | - &iPartIdxLabel, pPrior, r1); | |
| 97873 | + &iPartIdxLabel, pPrior, r1); | |
| 97698 | 97874 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 97699 | - pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); | |
| 97875 | + pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); | |
| 97700 | 97876 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 97701 | 97877 | pPrior = pIdx; |
| 97702 | 97878 | } |
| 97703 | 97879 | } |
| 97704 | 97880 | |
| @@ -102350,14 +102526,17 @@ | ||
| 102350 | 102526 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102351 | 102527 | } |
| 102352 | 102528 | if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){ |
| 102353 | 102529 | sqlite3MultiWrite(pParse); |
| 102354 | 102530 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102355 | - regNewData, 1, 0, OE_Replace, 1); | |
| 102356 | - }else if( pTab->pIndex ){ | |
| 102357 | - sqlite3MultiWrite(pParse); | |
| 102358 | - sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0); | |
| 102531 | + regNewData, 1, 0, OE_Replace, | |
| 102532 | + ONEPASS_SINGLE, -1); | |
| 102533 | + }else{ | |
| 102534 | + if( pTab->pIndex ){ | |
| 102535 | + sqlite3MultiWrite(pParse); | |
| 102536 | + sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1); | |
| 102537 | + } | |
| 102359 | 102538 | } |
| 102360 | 102539 | seenReplace = 1; |
| 102361 | 102540 | break; |
| 102362 | 102541 | } |
| 102363 | 102542 | case OE_Ignore: { |
| @@ -102531,11 +102710,12 @@ | ||
| 102531 | 102710 | sqlite3MultiWrite(pParse); |
| 102532 | 102711 | if( db->flags&SQLITE_RecTriggers ){ |
| 102533 | 102712 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102534 | 102713 | } |
| 102535 | 102714 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102536 | - regR, nPkField, 0, OE_Replace, pIdx==pPk); | |
| 102715 | + regR, nPkField, 0, OE_Replace, | |
| 102716 | + (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1); | |
| 102537 | 102717 | seenReplace = 1; |
| 102538 | 102718 | break; |
| 102539 | 102719 | } |
| 102540 | 102720 | } |
| 102541 | 102721 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -112115,13 +112295,16 @@ | ||
| 112115 | 112295 | return WRC_Abort; |
| 112116 | 112296 | } |
| 112117 | 112297 | pTab->nRef++; |
| 112118 | 112298 | #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) |
| 112119 | 112299 | if( pTab->pSelect || IsVirtual(pTab) ){ |
| 112120 | - /* We reach here if the named table is a really a view */ | |
| 112121 | 112300 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 112122 | 112301 | assert( pFrom->pSelect==0 ); |
| 112302 | + if( pFrom->fg.isTabFunc && !IsVirtual(pTab) ){ | |
| 112303 | + sqlite3ErrorMsg(pParse, "'%s' is not a function", pTab->zName); | |
| 112304 | + return WRC_Abort; | |
| 112305 | + } | |
| 112123 | 112306 | pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 112124 | 112307 | sqlite3SelectSetName(pFrom->pSelect, pTab->zName); |
| 112125 | 112308 | sqlite3WalkSelect(pWalker, pFrom->pSelect); |
| 112126 | 112309 | } |
| 112127 | 112310 | #endif |
| @@ -115381,11 +115564,11 @@ | ||
| 115381 | 115564 | }else{ |
| 115382 | 115565 | j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid); |
| 115383 | 115566 | } |
| 115384 | 115567 | VdbeCoverageNeverTaken(v); |
| 115385 | 115568 | } |
| 115386 | - sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx); | |
| 115569 | + sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1); | |
| 115387 | 115570 | |
| 115388 | 115571 | /* If changing the record number, delete the old record. */ |
| 115389 | 115572 | if( hasFK || chngKey || pPk!=0 ){ |
| 115390 | 115573 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 115391 | 115574 | } |
| @@ -117596,11 +117779,11 @@ | ||
| 117596 | 117779 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 117597 | 117780 | LogEst nRowOut; /* Estimated number of output rows */ |
| 117598 | 117781 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 117599 | 117782 | i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ |
| 117600 | 117783 | u8 sorted; /* True if really sorted (not just grouped) */ |
| 117601 | - u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */ | |
| 117784 | + u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */ | |
| 117602 | 117785 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 117603 | 117786 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ |
| 117604 | 117787 | u8 nLevel; /* Number of nested loop */ |
| 117605 | 117788 | int iTop; /* The very beginning of the WHERE loop */ |
| 117606 | 117789 | int iContinue; /* Jump here to continue with next record */ |
| @@ -117763,11 +117946,11 @@ | ||
| 117763 | 117946 | ** is run and there is an index on (a, b), then this function returns a |
| 117764 | 117947 | ** string similar to: |
| 117765 | 117948 | ** |
| 117766 | 117949 | ** "a=? AND b>?" |
| 117767 | 117950 | */ |
| 117768 | -static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ | |
| 117951 | +static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){ | |
| 117769 | 117952 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117770 | 117953 | u16 nEq = pLoop->u.btree.nEq; |
| 117771 | 117954 | u16 nSkip = pLoop->nSkip; |
| 117772 | 117955 | int i, j; |
| 117773 | 117956 | |
| @@ -117864,11 +118047,11 @@ | ||
| 117864 | 118047 | zFmt = "INDEX %s"; |
| 117865 | 118048 | } |
| 117866 | 118049 | if( zFmt ){ |
| 117867 | 118050 | sqlite3StrAccumAppend(&str, " USING ", 7); |
| 117868 | 118051 | sqlite3XPrintf(&str, 0, zFmt, pIdx->zName); |
| 117869 | - explainIndexRange(&str, pLoop, pItem->pTab); | |
| 118052 | + explainIndexRange(&str, pLoop); | |
| 117870 | 118053 | } |
| 117871 | 118054 | }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ |
| 117872 | 118055 | const char *zRangeOp; |
| 117873 | 118056 | if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ |
| 117874 | 118057 | zRangeOp = "="; |
| @@ -118212,12 +118395,12 @@ | ||
| 118212 | 118395 | VdbeCoverageIf(v, bRev==0); |
| 118213 | 118396 | VdbeCoverageIf(v, bRev!=0); |
| 118214 | 118397 | sqlite3VdbeJumpHere(v, j); |
| 118215 | 118398 | for(j=0; j<nSkip; j++){ |
| 118216 | 118399 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j); |
| 118217 | - assert( pIdx->aiColumn[j]>=0 ); | |
| 118218 | - VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName)); | |
| 118400 | + testcase( pIdx->aiColumn[j]==(-2) ); | |
| 118401 | + VdbeComment((v, "%s", explainIndexColumnName(pIdx, j))); | |
| 118219 | 118402 | } |
| 118220 | 118403 | } |
| 118221 | 118404 | |
| 118222 | 118405 | /* Evaluate the equality constraints |
| 118223 | 118406 | */ |
| @@ -118767,11 +118950,16 @@ | ||
| 118767 | 118950 | /* pIdx is a covering index. No need to access the main table. */ |
| 118768 | 118951 | }else if( HasRowid(pIdx->pTable) ){ |
| 118769 | 118952 | iRowidReg = ++pParse->nMem; |
| 118770 | 118953 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 118771 | 118954 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 118772 | - sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ | |
| 118955 | + if( pWInfo->eOnePass!=ONEPASS_OFF ){ | |
| 118956 | + sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); | |
| 118957 | + VdbeCoverage(v); | |
| 118958 | + }else{ | |
| 118959 | + sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ | |
| 118960 | + } | |
| 118773 | 118961 | }else if( iCur!=iIdxCur ){ |
| 118774 | 118962 | Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 118775 | 118963 | iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 118776 | 118964 | for(j=0; j<pPk->nKeyCol; j++){ |
| 118777 | 118965 | k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); |
| @@ -120618,13 +120806,15 @@ | ||
| 120618 | 120806 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo *pWInfo){ |
| 120619 | 120807 | return pWInfo->iBreak; |
| 120620 | 120808 | } |
| 120621 | 120809 | |
| 120622 | 120810 | /* |
| 120623 | -** Return TRUE if an UPDATE or DELETE statement can operate directly on | |
| 120624 | -** the rowids returned by a WHERE clause. Return FALSE if doing an | |
| 120625 | -** UPDATE or DELETE might change subsequent WHERE clause results. | |
| 120811 | +** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to | |
| 120812 | +** operate directly on the rowis returned by a WHERE clause. Return | |
| 120813 | +** ONEPASS_SINGLE (1) if the statement can operation directly because only | |
| 120814 | +** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass | |
| 120815 | +** optimization can be used on multiple | |
| 120626 | 120816 | ** |
| 120627 | 120817 | ** If the ONEPASS optimization is used (if this routine returns true) |
| 120628 | 120818 | ** then also write the indices of open cursors used by ONEPASS |
| 120629 | 120819 | ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data |
| 120630 | 120820 | ** table and iaCur[1] gets the cursor used by an auxiliary index. |
| @@ -120634,11 +120824,11 @@ | ||
| 120634 | 120824 | ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is |
| 120635 | 120825 | ** unable to use the ONEPASS optimization. |
| 120636 | 120826 | */ |
| 120637 | 120827 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){ |
| 120638 | 120828 | memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2); |
| 120639 | - return pWInfo->okOnePass; | |
| 120829 | + return pWInfo->eOnePass; | |
| 120640 | 120830 | } |
| 120641 | 120831 | |
| 120642 | 120832 | /* |
| 120643 | 120833 | ** Move the content of pSrc into pDest |
| 120644 | 120834 | */ |
| @@ -120729,25 +120919,24 @@ | ||
| 120729 | 120919 | int k = pScan->k; /* Where to start scanning */ |
| 120730 | 120920 | |
| 120731 | 120921 | while( pScan->iEquiv<=pScan->nEquiv ){ |
| 120732 | 120922 | iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 120733 | 120923 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 120734 | - assert( iColumn!=(-2) || pScan->pIdxExpr!=0 ); | |
| 120924 | + if( iColumn==(-2) && pScan->pIdxExpr==0 ) return 0; | |
| 120735 | 120925 | while( (pWC = pScan->pWC)!=0 ){ |
| 120736 | 120926 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 120737 | 120927 | if( pTerm->leftCursor==iCur |
| 120738 | 120928 | && pTerm->u.leftColumn==iColumn |
| 120739 | 120929 | && (iColumn!=(-2) |
| 120740 | - || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) | |
| 120930 | + || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) | |
| 120741 | 120931 | && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) |
| 120742 | 120932 | ){ |
| 120743 | 120933 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 120744 | 120934 | && pScan->nEquiv<ArraySize(pScan->aiCur) |
| 120935 | + && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN | |
| 120745 | 120936 | ){ |
| 120746 | 120937 | int j; |
| 120747 | - pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight); | |
| 120748 | - assert( pX->op==TK_COLUMN ); | |
| 120749 | 120938 | for(j=0; j<pScan->nEquiv; j++){ |
| 120750 | 120939 | if( pScan->aiCur[j]==pX->iTable |
| 120751 | 120940 | && pScan->aiColumn[j]==pX->iColumn ){ |
| 120752 | 120941 | break; |
| 120753 | 120942 | } |
| @@ -122969,21 +123158,28 @@ | ||
| 122969 | 123158 | WhereLoopBuilder *pBuilder, |
| 122970 | 123159 | Index *pIndex, |
| 122971 | 123160 | int iCursor |
| 122972 | 123161 | ){ |
| 122973 | 123162 | ExprList *pOB; |
| 123163 | + ExprList *aColExpr; | |
| 122974 | 123164 | int ii, jj; |
| 122975 | 123165 | |
| 122976 | 123166 | if( pIndex->bUnordered ) return 0; |
| 122977 | 123167 | if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0; |
| 122978 | 123168 | for(ii=0; ii<pOB->nExpr; ii++){ |
| 122979 | 123169 | Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr); |
| 122980 | - if( pExpr->op!=TK_COLUMN ) return 0; | |
| 122981 | - if( pExpr->iTable==iCursor ){ | |
| 123170 | + if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){ | |
| 122982 | 123171 | if( pExpr->iColumn<0 ) return 1; |
| 122983 | 123172 | for(jj=0; jj<pIndex->nKeyCol; jj++){ |
| 122984 | 123173 | if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1; |
| 123174 | + } | |
| 123175 | + }else if( (aColExpr = pIndex->aColExpr)!=0 ){ | |
| 123176 | + for(jj=0; jj<pIndex->nKeyCol; jj++){ | |
| 123177 | + if( pIndex->aiColumn[jj]!=(-2) ) continue; | |
| 123178 | + if( sqlite3ExprCompare(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){ | |
| 123179 | + return 1; | |
| 123180 | + } | |
| 122985 | 123181 | } |
| 122986 | 123182 | } |
| 122987 | 123183 | } |
| 122988 | 123184 | return 0; |
| 122989 | 123185 | } |
| @@ -123128,11 +123324,11 @@ | ||
| 123128 | 123324 | if( !pBuilder->pOrSet /* Not part of an OR optimization */ |
| 123129 | 123325 | && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0 |
| 123130 | 123326 | && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0 |
| 123131 | 123327 | && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */ |
| 123132 | 123328 | && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */ |
| 123133 | - && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */ | |
| 123329 | + && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */ | |
| 123134 | 123330 | && !pSrc->fg.isCorrelated /* Not a correlated subquery */ |
| 123135 | 123331 | && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ |
| 123136 | 123332 | ){ |
| 123137 | 123333 | /* Generate auto-index WhereLoops */ |
| 123138 | 123334 | WhereTerm *pTerm; |
| @@ -123812,13 +124008,19 @@ | ||
| 123812 | 124008 | if( MASKBIT(i) & obSat ) continue; |
| 123813 | 124009 | pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr); |
| 123814 | 124010 | testcase( wctrlFlags & WHERE_GROUPBY ); |
| 123815 | 124011 | testcase( wctrlFlags & WHERE_DISTINCTBY ); |
| 123816 | 124012 | if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0; |
| 123817 | - if( pOBExpr->op!=TK_COLUMN ) continue; | |
| 123818 | - if( pOBExpr->iTable!=iCur ) continue; | |
| 123819 | - if( pOBExpr->iColumn!=iColumn ) continue; | |
| 124013 | + if( iColumn>=(-1) ){ | |
| 124014 | + if( pOBExpr->op!=TK_COLUMN ) continue; | |
| 124015 | + if( pOBExpr->iTable!=iCur ) continue; | |
| 124016 | + if( pOBExpr->iColumn!=iColumn ) continue; | |
| 124017 | + }else{ | |
| 124018 | + if( sqlite3ExprCompare(pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){ | |
| 124019 | + continue; | |
| 124020 | + } | |
| 124021 | + } | |
| 123820 | 124022 | if( iColumn>=0 ){ |
| 123821 | 124023 | pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr); |
| 123822 | 124024 | if( !pColl ) pColl = db->pDfltColl; |
| 123823 | 124025 | if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue; |
| 123824 | 124026 | } |
| @@ -124507,10 +124709,14 @@ | ||
| 124507 | 124709 | WhereLoop *pLoop; /* Pointer to a single WhereLoop object */ |
| 124508 | 124710 | int ii; /* Loop counter */ |
| 124509 | 124711 | sqlite3 *db; /* Database connection */ |
| 124510 | 124712 | int rc; /* Return code */ |
| 124511 | 124713 | |
| 124714 | + assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || ( | |
| 124715 | + (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 | |
| 124716 | + && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 | |
| 124717 | + )); | |
| 124512 | 124718 | |
| 124513 | 124719 | /* Variable initialization */ |
| 124514 | 124720 | db = pParse->db; |
| 124515 | 124721 | memset(&sWLB, 0, sizeof(sWLB)); |
| 124516 | 124722 | |
| @@ -124562,10 +124768,11 @@ | ||
| 124562 | 124768 | pWInfo->pOrderBy = pOrderBy; |
| 124563 | 124769 | pWInfo->pResultSet = pResultSet; |
| 124564 | 124770 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 124565 | 124771 | pWInfo->wctrlFlags = wctrlFlags; |
| 124566 | 124772 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 124773 | + assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ | |
| 124567 | 124774 | pMaskSet = &pWInfo->sMaskSet; |
| 124568 | 124775 | sWLB.pWInfo = pWInfo; |
| 124569 | 124776 | sWLB.pWC = &pWInfo->sWC; |
| 124570 | 124777 | sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); |
| 124571 | 124778 | assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) ); |
| @@ -124748,15 +124955,20 @@ | ||
| 124748 | 124955 | ** to use a one-pass algorithm, determine if this is appropriate. |
| 124749 | 124956 | ** The one-pass algorithm only works if the WHERE clause constrains |
| 124750 | 124957 | ** the statement to update or delete a single row. |
| 124751 | 124958 | */ |
| 124752 | 124959 | assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); |
| 124753 | - if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 | |
| 124754 | - && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){ | |
| 124755 | - pWInfo->okOnePass = 1; | |
| 124756 | - if( HasRowid(pTabList->a[0].pTab) ){ | |
| 124757 | - pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY; | |
| 124960 | + if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){ | |
| 124961 | + int wsFlags = pWInfo->a[0].pWLoop->wsFlags; | |
| 124962 | + int bOnerow = (wsFlags & WHERE_ONEROW)!=0; | |
| 124963 | + if( bOnerow || ( (wctrlFlags & WHERE_ONEPASS_MULTIROW) | |
| 124964 | + && 0==(wsFlags & WHERE_VIRTUALTABLE) | |
| 124965 | + )){ | |
| 124966 | + pWInfo->eOnePass = bOnerow ? ONEPASS_SINGLE : ONEPASS_MULTI; | |
| 124967 | + if( HasRowid(pTabList->a[0].pTab) ){ | |
| 124968 | + pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY; | |
| 124969 | + } | |
| 124758 | 124970 | } |
| 124759 | 124971 | } |
| 124760 | 124972 | |
| 124761 | 124973 | /* Open all tables in the pTabList and any indices selected for |
| 124762 | 124974 | ** searching those tables. |
| @@ -124783,19 +124995,19 @@ | ||
| 124783 | 124995 | }else |
| 124784 | 124996 | #endif |
| 124785 | 124997 | if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 124786 | 124998 | && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){ |
| 124787 | 124999 | int op = OP_OpenRead; |
| 124788 | - if( pWInfo->okOnePass ){ | |
| 125000 | + if( pWInfo->eOnePass!=ONEPASS_OFF ){ | |
| 124789 | 125001 | op = OP_OpenWrite; |
| 124790 | 125002 | pWInfo->aiCurOnePass[0] = pTabItem->iCursor; |
| 124791 | 125003 | }; |
| 124792 | 125004 | sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op); |
| 124793 | 125005 | assert( pTabItem->iCursor==pLevel->iTabCur ); |
| 124794 | - testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 ); | |
| 124795 | - testcase( !pWInfo->okOnePass && pTab->nCol==BMS ); | |
| 124796 | - if( !pWInfo->okOnePass && pTab->nCol<BMS && HasRowid(pTab) ){ | |
| 125006 | + testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 ); | |
| 125007 | + testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS ); | |
| 125008 | + if( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol<BMS && HasRowid(pTab) ){ | |
| 124797 | 125009 | Bitmask b = pTabItem->colUsed; |
| 124798 | 125010 | int n = 0; |
| 124799 | 125011 | for(; b; b=b>>1, n++){} |
| 124800 | 125012 | sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1, |
| 124801 | 125013 | SQLITE_INT_TO_PTR(n), P4_INT32); |
| @@ -124819,11 +125031,11 @@ | ||
| 124819 | 125031 | ){ |
| 124820 | 125032 | /* This is one term of an OR-optimization using the PRIMARY KEY of a |
| 124821 | 125033 | ** WITHOUT ROWID table. No need for a separate index */ |
| 124822 | 125034 | iIndexCur = pLevel->iTabCur; |
| 124823 | 125035 | op = 0; |
| 124824 | - }else if( pWInfo->okOnePass ){ | |
| 125036 | + }else if( pWInfo->eOnePass!=ONEPASS_OFF ){ | |
| 124825 | 125037 | Index *pJ = pTabItem->pTab->pIndex; |
| 124826 | 125038 | iIndexCur = iIdxCur; |
| 124827 | 125039 | assert( wctrlFlags & WHERE_ONEPASS_DESIRED ); |
| 124828 | 125040 | while( ALWAYS(pJ) && pJ!=pIx ){ |
| 124829 | 125041 | iIndexCur++; |
| @@ -125027,11 +125239,11 @@ | ||
| 125027 | 125239 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 125028 | 125240 | && pTab->pSelect==0 |
| 125029 | 125241 | && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 |
| 125030 | 125242 | ){ |
| 125031 | 125243 | int ws = pLoop->wsFlags; |
| 125032 | - if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){ | |
| 125244 | + if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){ | |
| 125033 | 125245 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| 125034 | 125246 | } |
| 125035 | 125247 | if( (ws & WHERE_INDEXED)!=0 |
| 125036 | 125248 | && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 |
| 125037 | 125249 | && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1] |
| 125038 | 125250 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -325,11 +325,11 @@ | |
| 325 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 326 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 327 | */ |
| 328 | #define SQLITE_VERSION "3.8.12" |
| 329 | #define SQLITE_VERSION_NUMBER 3008012 |
| 330 | #define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a" |
| 331 | |
| 332 | /* |
| 333 | ** CAPI3REF: Run-Time Library Version Numbers |
| 334 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 335 | ** |
| @@ -336,11 +336,11 @@ | |
| 336 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 337 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 338 | ** but are associated with the library instead of the header file. ^(Cautious |
| 339 | ** programmers might include assert() statements in their application to |
| 340 | ** verify that values returned by these interfaces match the macros in |
| 341 | ** the header, and thus insure that the application is |
| 342 | ** compiled with matching library and header files. |
| 343 | ** |
| 344 | ** <blockquote><pre> |
| 345 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 346 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -586,11 +586,11 @@ | |
| 586 | ** is not changed. |
| 587 | ** |
| 588 | ** Restrictions: |
| 589 | ** |
| 590 | ** <ul> |
| 591 | ** <li> The application must insure that the 1st parameter to sqlite3_exec() |
| 592 | ** is a valid and open [database connection]. |
| 593 | ** <li> The application must not close the [database connection] specified by |
| 594 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 595 | ** <li> The application must not modify the SQL statement text passed into |
| 596 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1579,13 +1579,15 @@ | |
| 1579 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1580 | ** the application. The default configuration is recommended for most |
| 1581 | ** applications and so this routine is usually not necessary. It is |
| 1582 | ** provided to support rare applications with unusual needs. |
| 1583 | ** |
| 1584 | ** The sqlite3_config() interface is not threadsafe. The application |
| 1585 | ** must insure that no other SQLite interfaces are invoked by other |
| 1586 | ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() |
| 1587 | ** may only be invoked prior to library initialization using |
| 1588 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1589 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1590 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1591 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3840,11 +3842,11 @@ | |
| 3840 | ** name must be given in UTF-8 even if the original statement |
| 3841 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3842 | ** |
| 3843 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3844 | ** [sqlite3_bind_parameter_count()], and |
| 3845 | ** [sqlite3_bind_parameter_index()]. |
| 3846 | */ |
| 3847 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3848 | |
| 3849 | /* |
| 3850 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6337,10 +6339,13 @@ | |
| 6337 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6338 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6339 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6340 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6341 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6342 | ** </ul> |
| 6343 | ** |
| 6344 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6345 | ** cause sqlite3_mutex_alloc() to create |
| 6346 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| @@ -9623,11 +9628,11 @@ | |
| 9623 | int bias, |
| 9624 | int *pRes |
| 9625 | ); |
| 9626 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 9627 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 9628 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*); |
| 9629 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, |
| 9630 | const void *pData, int nData, |
| 9631 | int nZero, int bias, int seekResult); |
| 9632 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 9633 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| @@ -10339,10 +10344,13 @@ | |
| 10339 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 10340 | |
| 10341 | /* Functions used to configure a Pager object. */ |
| 10342 | SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); |
| 10343 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 10344 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 10345 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 10346 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 10347 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| 10348 | SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); |
| @@ -12341,10 +12349,11 @@ | |
| 12341 | #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */ |
| 12342 | #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ |
| 12343 | #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ |
| 12344 | #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ |
| 12345 | #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ |
| 12346 | |
| 12347 | /* Allowed return values from sqlite3WhereIsDistinct() |
| 12348 | */ |
| 12349 | #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ |
| 12350 | #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ |
| @@ -13184,11 +13193,11 @@ | |
| 13184 | SQLITE_PRIVATE int sqlite3MutexEnd(void); |
| 13185 | #endif |
| 13186 | #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) |
| 13187 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void); |
| 13188 | #else |
| 13189 | # define sqlite3MemoryBarrier(); |
| 13190 | #endif |
| 13191 | |
| 13192 | SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); |
| 13193 | SQLITE_PRIVATE void sqlite3StatusUp(int, int); |
| 13194 | SQLITE_PRIVATE void sqlite3StatusDown(int, int); |
| @@ -13369,10 +13378,13 @@ | |
| 13369 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 13370 | SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*); |
| 13371 | SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*); |
| 13372 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 13373 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 13374 | SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); |
| 13375 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 13376 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 13377 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 13378 | SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); |
| @@ -13429,12 +13441,13 @@ | |
| 13429 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 13430 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 13431 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 13432 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 13433 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 13434 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| 13435 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*); |
| 13436 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 13437 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 13438 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 13439 | u8,u8,int,int*); |
| 13440 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| @@ -19319,11 +19332,11 @@ | |
| 19319 | ** For debugging purposes, record when the mutex subsystem is initialized |
| 19320 | ** and uninitialized so that we can assert() if there is an attempt to |
| 19321 | ** allocate a mutex while the system is uninitialized. |
| 19322 | */ |
| 19323 | static SQLITE_WSD int mutexIsInit = 0; |
| 19324 | #endif /* SQLITE_DEBUG */ |
| 19325 | |
| 19326 | |
| 19327 | #ifndef SQLITE_MUTEX_OMIT |
| 19328 | /* |
| 19329 | ** Initialize the mutex system. |
| @@ -19353,10 +19366,11 @@ | |
| 19353 | pTo->xMutexHeld = pFrom->xMutexHeld; |
| 19354 | pTo->xMutexNotheld = pFrom->xMutexNotheld; |
| 19355 | sqlite3MemoryBarrier(); |
| 19356 | pTo->xMutexAlloc = pFrom->xMutexAlloc; |
| 19357 | } |
| 19358 | rc = sqlite3GlobalConfig.mutex.xMutexInit(); |
| 19359 | |
| 19360 | #ifdef SQLITE_DEBUG |
| 19361 | GLOBAL(int, mutexIsInit) = 1; |
| 19362 | #endif |
| @@ -19387,26 +19401,29 @@ | |
| 19387 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){ |
| 19388 | #ifndef SQLITE_OMIT_AUTOINIT |
| 19389 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 19390 | if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 19391 | #endif |
| 19392 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19393 | } |
| 19394 | |
| 19395 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| 19396 | if( !sqlite3GlobalConfig.bCoreMutex ){ |
| 19397 | return 0; |
| 19398 | } |
| 19399 | assert( GLOBAL(int, mutexIsInit) ); |
| 19400 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19401 | } |
| 19402 | |
| 19403 | /* |
| 19404 | ** Free a dynamic mutex. |
| 19405 | */ |
| 19406 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){ |
| 19407 | if( p ){ |
| 19408 | sqlite3GlobalConfig.mutex.xMutexFree(p); |
| 19409 | } |
| 19410 | } |
| 19411 | |
| 19412 | /* |
| @@ -19413,10 +19430,11 @@ | |
| 19413 | ** Obtain the mutex p. If some other thread already has the mutex, block |
| 19414 | ** until it can be obtained. |
| 19415 | */ |
| 19416 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){ |
| 19417 | if( p ){ |
| 19418 | sqlite3GlobalConfig.mutex.xMutexEnter(p); |
| 19419 | } |
| 19420 | } |
| 19421 | |
| 19422 | /* |
| @@ -19424,10 +19442,11 @@ | |
| 19424 | ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. |
| 19425 | */ |
| 19426 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){ |
| 19427 | int rc = SQLITE_OK; |
| 19428 | if( p ){ |
| 19429 | return sqlite3GlobalConfig.mutex.xMutexTry(p); |
| 19430 | } |
| 19431 | return rc; |
| 19432 | } |
| 19433 | |
| @@ -19437,10 +19456,11 @@ | |
| 19437 | ** is not currently entered. If a NULL pointer is passed as an argument |
| 19438 | ** this function is a no-op. |
| 19439 | */ |
| 19440 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){ |
| 19441 | if( p ){ |
| 19442 | sqlite3GlobalConfig.mutex.xMutexLeave(p); |
| 19443 | } |
| 19444 | } |
| 19445 | |
| 19446 | #ifndef NDEBUG |
| @@ -19447,13 +19467,15 @@ | |
| 19447 | /* |
| 19448 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 19449 | ** intended for use inside assert() statements. |
| 19450 | */ |
| 19451 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){ |
| 19452 | return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); |
| 19453 | } |
| 19454 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 19455 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 19456 | } |
| 19457 | #endif |
| 19458 | |
| 19459 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| @@ -19764,11 +19786,11 @@ | |
| 19764 | ** Try to provide a memory barrier operation, needed for initialization only. |
| 19765 | */ |
| 19766 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void){ |
| 19767 | #if defined(SQLITE_MEMORY_BARRIER) |
| 19768 | SQLITE_MEMORY_BARRIER; |
| 19769 | #elif defined(__GNUC__) |
| 19770 | __sync_synchronize(); |
| 19771 | #endif |
| 19772 | } |
| 19773 | |
| 19774 | /* |
| @@ -30682,11 +30704,12 @@ | |
| 30682 | */ |
| 30683 | static void unixShmBarrier( |
| 30684 | sqlite3_file *fd /* Database file holding the shared memory */ |
| 30685 | ){ |
| 30686 | UNUSED_PARAMETER(fd); |
| 30687 | unixEnterMutex(); |
| 30688 | unixLeaveMutex(); |
| 30689 | } |
| 30690 | |
| 30691 | /* |
| 30692 | ** Close a connection to shared-memory. Delete the underlying |
| @@ -37637,12 +37660,12 @@ | |
| 37637 | */ |
| 37638 | static void winShmBarrier( |
| 37639 | sqlite3_file *fd /* Database holding the shared memory */ |
| 37640 | ){ |
| 37641 | UNUSED_PARAMETER(fd); |
| 37642 | /* MemoryBarrier(); // does not work -- do not know why not */ |
| 37643 | winShmEnterMutex(); |
| 37644 | winShmLeaveMutex(); |
| 37645 | } |
| 37646 | |
| 37647 | /* |
| 37648 | ** This function is called to obtain a pointer to region iRegion of the |
| @@ -40930,11 +40953,11 @@ | |
| 40930 | ** this mutex is not held. */ |
| 40931 | assert( pcache1.separateCache==0 ); |
| 40932 | assert( pCache->pGroup==&pcache1.grp ); |
| 40933 | pcache1LeaveMutex(pCache->pGroup); |
| 40934 | #endif |
| 40935 | if( benignMalloc ) sqlite3BeginBenignMalloc(); |
| 40936 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 40937 | pPg = pcache1Alloc(pCache->szPage); |
| 40938 | p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); |
| 40939 | if( !pPg || !p ){ |
| 40940 | pcache1Free(pPg); |
| @@ -40943,11 +40966,11 @@ | |
| 40943 | } |
| 40944 | #else |
| 40945 | pPg = pcache1Alloc(pCache->szAlloc); |
| 40946 | p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; |
| 40947 | #endif |
| 40948 | if( benignMalloc ) sqlite3EndBenignMalloc(); |
| 40949 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40950 | pcache1EnterMutex(pCache->pGroup); |
| 40951 | #endif |
| 40952 | if( pPg==0 ) return 0; |
| 40953 | p->page.pBuf = pPg; |
| @@ -44522,10 +44545,24 @@ | |
| 44522 | } |
| 44523 | } |
| 44524 | #else |
| 44525 | # define pagerReportSize(X) /* No-op if we do not support a codec */ |
| 44526 | #endif |
| 44527 | |
| 44528 | /* |
| 44529 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 44530 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 44531 | ** The page begins at offset *pOffset into the file. The *pOffset |
| @@ -54479,10 +54516,53 @@ | |
| 54479 | pCur->apPage[i] = 0; |
| 54480 | } |
| 54481 | pCur->iPage = -1; |
| 54482 | } |
| 54483 | |
| 54484 | |
| 54485 | /* |
| 54486 | ** Save the current cursor position in the variables BtCursor.nKey |
| 54487 | ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK. |
| 54488 | ** |
| @@ -54499,34 +54579,12 @@ | |
| 54499 | if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 54500 | pCur->eState = CURSOR_VALID; |
| 54501 | }else{ |
| 54502 | pCur->skipNext = 0; |
| 54503 | } |
| 54504 | rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); |
| 54505 | assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ |
| 54506 | |
| 54507 | /* If this is an intKey table, then the above call to BtreeKeySize() |
| 54508 | ** stores the integer key in pCur->nKey. In this case this value is |
| 54509 | ** all that is required. Otherwise, if pCur is not open on an intKey |
| 54510 | ** table, then malloc space for and store the pCur->nKey bytes of key |
| 54511 | ** data. |
| 54512 | */ |
| 54513 | if( 0==pCur->curIntKey ){ |
| 54514 | void *pKey = sqlite3Malloc( pCur->nKey ); |
| 54515 | if( pKey ){ |
| 54516 | rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); |
| 54517 | if( rc==SQLITE_OK ){ |
| 54518 | pCur->pKey = pKey; |
| 54519 | }else{ |
| 54520 | sqlite3_free(pKey); |
| 54521 | } |
| 54522 | }else{ |
| 54523 | rc = SQLITE_NOMEM; |
| 54524 | } |
| 54525 | } |
| 54526 | assert( !pCur->curIntKey || !pCur->pKey ); |
| 54527 | |
| 54528 | if( rc==SQLITE_OK ){ |
| 54529 | btreeReleaseAllCursorPages(pCur); |
| 54530 | pCur->eState = CURSOR_REQUIRESEEK; |
| 54531 | } |
| 54532 | |
| @@ -61914,22 +61972,28 @@ | |
| 61914 | end_insert: |
| 61915 | return rc; |
| 61916 | } |
| 61917 | |
| 61918 | /* |
| 61919 | ** Delete the entry that the cursor is pointing to. The cursor |
| 61920 | ** is left pointing at an arbitrary location. |
| 61921 | */ |
| 61922 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){ |
| 61923 | Btree *p = pCur->pBtree; |
| 61924 | BtShared *pBt = p->pBt; |
| 61925 | int rc; /* Return code */ |
| 61926 | MemPage *pPage; /* Page to delete cell from */ |
| 61927 | unsigned char *pCell; /* Pointer to cell to delete */ |
| 61928 | int iCellIdx; /* Index of cell to delete */ |
| 61929 | int iCellDepth; /* Depth of node containing pCell */ |
| 61930 | u16 szCell; /* Size of the cell being deleted */ |
| 61931 | |
| 61932 | assert( cursorHoldsMutex(pCur) ); |
| 61933 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 61934 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 61935 | assert( pCur->curFlags & BTCF_WriteFlag ); |
| @@ -61955,14 +62019,11 @@ | |
| 61955 | rc = sqlite3BtreePrevious(pCur, ¬Used); |
| 61956 | if( rc ) return rc; |
| 61957 | } |
| 61958 | |
| 61959 | /* Save the positions of any other cursors open on this table before |
| 61960 | ** making any modifications. Make the page containing the entry to be |
| 61961 | ** deleted writable. Then free any overflow pages associated with the |
| 61962 | ** entry and finally remove the cell itself from within the page. |
| 61963 | */ |
| 61964 | if( pCur->curFlags & BTCF_Multiple ){ |
| 61965 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 61966 | if( rc ) return rc; |
| 61967 | } |
| 61968 | |
| @@ -61970,10 +62031,35 @@ | |
| 61970 | ** invalidate any incrblob cursors open on the row being deleted. */ |
| 61971 | if( pCur->pKeyInfo==0 ){ |
| 61972 | invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 61973 | } |
| 61974 | |
| 61975 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 61976 | if( rc ) return rc; |
| 61977 | rc = clearCell(pPage, pCell, &szCell); |
| 61978 | dropCell(pPage, iCellIdx, szCell, &rc); |
| 61979 | if( rc ) return rc; |
| @@ -62023,11 +62109,27 @@ | |
| 62023 | } |
| 62024 | rc = balance(pCur); |
| 62025 | } |
| 62026 | |
| 62027 | if( rc==SQLITE_OK ){ |
| 62028 | moveToRoot(pCur); |
| 62029 | } |
| 62030 | return rc; |
| 62031 | } |
| 62032 | |
| 62033 | /* |
| @@ -62745,10 +62847,14 @@ | |
| 62745 | } |
| 62746 | } |
| 62747 | #endif |
| 62748 | iPage = get4byte(pOvflData); |
| 62749 | sqlite3PagerUnref(pOvflPage); |
| 62750 | } |
| 62751 | } |
| 62752 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 62753 | |
| 62754 | /* |
| @@ -64237,10 +64343,14 @@ | |
| 64237 | memset(&b, 0, sizeof(b)); |
| 64238 | b.pSrcDb = pFrom->db; |
| 64239 | b.pSrc = pFrom; |
| 64240 | b.pDest = pTo; |
| 64241 | b.iNext = 1; |
| 64242 | |
| 64243 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 64244 | ** file. By passing this as the number of pages to copy to |
| 64245 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 64246 | ** within a single call (unless an error occurs). The assert() statement |
| @@ -71166,22 +71276,23 @@ | |
| 71166 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 71167 | __attribute__((aligned(8))) |
| 71168 | #endif |
| 71169 | = { |
| 71170 | /* .u = */ {0}, |
| 71171 | /* .flags = */ MEM_Null, |
| 71172 | /* .enc = */ 0, |
| 71173 | /* .n = */ 0, |
| 71174 | /* .z = */ 0, |
| 71175 | /* .zMalloc = */ 0, |
| 71176 | /* .szMalloc = */ 0, |
| 71177 | /* .iPadding1 = */ 0, |
| 71178 | /* .db = */ 0, |
| 71179 | /* .xDel = */ 0, |
| 71180 | #ifdef SQLITE_DEBUG |
| 71181 | /* .pScopyFrom = */ 0, |
| 71182 | /* .pFiller = */ 0, |
| 71183 | #endif |
| 71184 | }; |
| 71185 | return &nullMem; |
| 71186 | } |
| 71187 | |
| @@ -76172,13 +76283,14 @@ | |
| 76172 | /* Opcode: NotExists P1 P2 P3 * * |
| 76173 | ** Synopsis: intkey=r[P3] |
| 76174 | ** |
| 76175 | ** P1 is the index of a cursor open on an SQL table btree (with integer |
| 76176 | ** keys). P3 is an integer rowid. If P1 does not contain a record with |
| 76177 | ** rowid P3 then jump immediately to P2. If P1 does contain a record |
| 76178 | ** with rowid P3 then leave the cursor pointing at that record and fall |
| 76179 | ** through to the next instruction. |
| 76180 | ** |
| 76181 | ** The OP_NotFound opcode performs the same operation on index btrees |
| 76182 | ** (with arbitrary multi-value keys). |
| 76183 | ** |
| 76184 | ** This opcode leaves the cursor in a state where it cannot be advanced |
| @@ -76206,17 +76318,25 @@ | |
| 76206 | pCrsr = pC->pCursor; |
| 76207 | assert( pCrsr!=0 ); |
| 76208 | res = 0; |
| 76209 | iKey = pIn3->u.i; |
| 76210 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 76211 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 76212 | pC->nullRow = 0; |
| 76213 | pC->cacheStatus = CACHE_STALE; |
| 76214 | pC->deferredMoveto = 0; |
| 76215 | VdbeBranchTaken(res!=0,2); |
| 76216 | pC->seekResult = res; |
| 76217 | if( res!=0 ) goto jump_to_p2; |
| 76218 | break; |
| 76219 | } |
| 76220 | |
| 76221 | /* Opcode: Sequence P1 P2 * * * |
| 76222 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -76478,18 +76598,19 @@ | |
| 76478 | assert( pC->iDb>=0 ); |
| 76479 | } |
| 76480 | break; |
| 76481 | } |
| 76482 | |
| 76483 | /* Opcode: Delete P1 P2 * P4 * |
| 76484 | ** |
| 76485 | ** Delete the record at which the P1 cursor is currently pointing. |
| 76486 | ** |
| 76487 | ** The cursor will be left pointing at either the next or the previous |
| 76488 | ** record in the table. If it is left pointing at the next record, then |
| 76489 | ** the next Next instruction will be a no-op. Hence it is OK to delete |
| 76490 | ** a record from within a Next loop. |
| 76491 | ** |
| 76492 | ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is |
| 76493 | ** incremented (otherwise not). |
| 76494 | ** |
| 76495 | ** P1 must not be pseudo-table. It has to be a real table with |
| @@ -76500,33 +76621,39 @@ | |
| 76500 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 76501 | ** using OP_NotFound prior to invoking this opcode. |
| 76502 | */ |
| 76503 | case OP_Delete: { |
| 76504 | VdbeCursor *pC; |
| 76505 | |
| 76506 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 76507 | pC = p->apCsr[pOp->p1]; |
| 76508 | assert( pC!=0 ); |
| 76509 | assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 76510 | assert( pC->deferredMoveto==0 ); |
| 76511 | |
| 76512 | #ifdef SQLITE_DEBUG |
| 76513 | /* The seek operation that positioned the cursor prior to OP_Delete will |
| 76514 | ** have also set the pC->movetoTarget field to the rowid of the row that |
| 76515 | ** is being deleted */ |
| 76516 | if( pOp->p4.z && pC->isTable ){ |
| 76517 | i64 iKey = 0; |
| 76518 | sqlite3BtreeKeySize(pC->pCursor, &iKey); |
| 76519 | assert( pC->movetoTarget==iKey ); |
| 76520 | } |
| 76521 | #endif |
| 76522 | |
| 76523 | rc = sqlite3BtreeDelete(pC->pCursor); |
| 76524 | pC->cacheStatus = CACHE_STALE; |
| 76525 | |
| 76526 | /* Invoke the update-hook if required. */ |
| 76527 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ |
| 76528 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 76529 | db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); |
| 76530 | assert( pC->iDb>=0 ); |
| 76531 | } |
| 76532 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| @@ -77061,11 +77188,11 @@ | |
| 77061 | #ifdef SQLITE_DEBUG |
| 77062 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 77063 | #endif |
| 77064 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 77065 | if( rc==SQLITE_OK && res==0 ){ |
| 77066 | rc = sqlite3BtreeDelete(pCrsr); |
| 77067 | } |
| 77068 | assert( pC->deferredMoveto==0 ); |
| 77069 | pC->cacheStatus = CACHE_STALE; |
| 77070 | break; |
| 77071 | } |
| @@ -83123,12 +83250,17 @@ | |
| 83123 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 83124 | |
| 83125 | /* |
| 83126 | ** Perhaps the name is a reference to the ROWID |
| 83127 | */ |
| 83128 | if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol) |
| 83129 | && VisibleRowid(pMatch->pTab) ){ |
| 83130 | cnt = 1; |
| 83131 | pExpr->iColumn = -1; /* IMP: R-44911-55124 */ |
| 83132 | pExpr->affinity = SQLITE_AFF_INTEGER; |
| 83133 | } |
| 83134 | |
| @@ -92416,11 +92548,11 @@ | |
| 92416 | }else{ |
| 92417 | sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); |
| 92418 | } |
| 92419 | pParse->checkSchema = 1; |
| 92420 | } |
| 92421 | #if SQLITE_USER_AUTHENICATION |
| 92422 | else if( pParse->db->auth.authLevel<UAUTH_User ){ |
| 92423 | sqlite3ErrorMsg(pParse, "user not authenticated"); |
| 92424 | p = 0; |
| 92425 | } |
| 92426 | #endif |
| @@ -97188,11 +97320,11 @@ | |
| 97188 | AuthContext sContext; /* Authorization context */ |
| 97189 | NameContext sNC; /* Name context to resolve expressions in */ |
| 97190 | int iDb; /* Database number */ |
| 97191 | int memCnt = -1; /* Memory cell used for change counting */ |
| 97192 | int rcauth; /* Value returned by authorization callback */ |
| 97193 | int okOnePass; /* True for one-pass algorithm without the FIFO */ |
| 97194 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 97195 | u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */ |
| 97196 | Index *pPk; /* The PRIMARY KEY index on the table */ |
| 97197 | int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */ |
| 97198 | i16 nPk = 1; /* Number of columns in the PRIMARY KEY */ |
| @@ -97200,16 +97332,16 @@ | |
| 97200 | i16 nKey; /* Number of memory cells in the row key */ |
| 97201 | int iEphCur = 0; /* Ephemeral table holding all primary key values */ |
| 97202 | int iRowSet = 0; /* Register for rowset of rows to delete */ |
| 97203 | int addrBypass = 0; /* Address of jump over the delete logic */ |
| 97204 | int addrLoop = 0; /* Top of the delete loop */ |
| 97205 | int addrDelete = 0; /* Jump directly to the delete logic */ |
| 97206 | int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ |
| 97207 | |
| 97208 | #ifndef SQLITE_OMIT_TRIGGER |
| 97209 | int isView; /* True if attempting to delete from a view */ |
| 97210 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 97211 | #endif |
| 97212 | |
| 97213 | memset(&sContext, 0, sizeof(sContext)); |
| 97214 | db = pParse->db; |
| 97215 | if( pParse->nErr || db->mallocFailed ){ |
| @@ -97229,13 +97361,15 @@ | |
| 97229 | ** deleted from is a view |
| 97230 | */ |
| 97231 | #ifndef SQLITE_OMIT_TRIGGER |
| 97232 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 97233 | isView = pTab->pSelect!=0; |
| 97234 | #else |
| 97235 | # define pTrigger 0 |
| 97236 | # define isView 0 |
| 97237 | #endif |
| 97238 | #ifdef SQLITE_OMIT_VIEW |
| 97239 | # undef isView |
| 97240 | # define isView 0 |
| 97241 | #endif |
| @@ -97312,12 +97446,14 @@ | |
| 97312 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 97313 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 97314 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 97315 | ** this optimization caused the row change count (the value returned by |
| 97316 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 97317 | if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) |
| 97318 | && 0==sqlite3FkRequired(pParse, pTab, 0, 0) |
| 97319 | ){ |
| 97320 | assert( !isView ); |
| 97321 | sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 97322 | if( HasRowid(pTab) ){ |
| 97323 | sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt, |
| @@ -97328,10 +97464,12 @@ | |
| 97328 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| 97329 | } |
| 97330 | }else |
| 97331 | #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ |
| 97332 | { |
| 97333 | if( HasRowid(pTab) ){ |
| 97334 | /* For a rowid table, initialize the RowSet to an empty set */ |
| 97335 | pPk = 0; |
| 97336 | nPk = 1; |
| 97337 | iRowSet = ++pParse->nMem; |
| @@ -97348,17 +97486,22 @@ | |
| 97348 | addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk); |
| 97349 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 97350 | } |
| 97351 | |
| 97352 | /* Construct a query to find the rowid or primary key for every row |
| 97353 | ** to be deleted, based on the WHERE clause. |
| 97354 | */ |
| 97355 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, |
| 97356 | WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK, |
| 97357 | iTabCur+1); |
| 97358 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 97359 | okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 97360 | |
| 97361 | /* Keep track of the number of rows to be deleted */ |
| 97362 | if( db->flags & SQLITE_CountRows ){ |
| 97363 | sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1); |
| 97364 | } |
| @@ -97375,15 +97518,14 @@ | |
| 97375 | iKey = pParse->nMem + 1; |
| 97376 | iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0); |
| 97377 | if( iKey>pParse->nMem ) pParse->nMem = iKey; |
| 97378 | } |
| 97379 | |
| 97380 | if( okOnePass ){ |
| 97381 | /* For ONEPASS, no need to store the rowid/primary-key. There is only |
| 97382 | ** one, so just keep it in its register(s) and fall through to the |
| 97383 | ** delete code. |
| 97384 | */ |
| 97385 | nKey = nPk; /* OP_Found will use an unpacked key */ |
| 97386 | aToOpen = sqlite3DbMallocRaw(db, nIdx+2); |
| 97387 | if( aToOpen==0 ){ |
| 97388 | sqlite3WhereEnd(pWInfo); |
| 97389 | goto delete_from_cleanup; |
| @@ -97391,53 +97533,56 @@ | |
| 97391 | memset(aToOpen, 1, nIdx+1); |
| 97392 | aToOpen[nIdx+1] = 0; |
| 97393 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0; |
| 97394 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0; |
| 97395 | if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen); |
| 97396 | addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */ |
| 97397 | }else if( pPk ){ |
| 97398 | /* Construct a composite key for the row to be deleted and remember it */ |
| 97399 | iKey = ++pParse->nMem; |
| 97400 | nKey = 0; /* Zero tells OP_Found to use a composite key */ |
| 97401 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, |
| 97402 | sqlite3IndexAffinityStr(pParse->db, pPk), nPk); |
| 97403 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); |
| 97404 | }else{ |
| 97405 | /* Get the rowid of the row to be deleted and remember it in the RowSet */ |
| 97406 | nKey = 1; /* OP_Seek always uses a single rowid */ |
| 97407 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); |
| 97408 | } |
| 97409 | |
| 97410 | /* End of the WHERE loop */ |
| 97411 | sqlite3WhereEnd(pWInfo); |
| 97412 | if( okOnePass ){ |
| 97413 | /* Bypass the delete logic below if the WHERE loop found zero rows */ |
| 97414 | addrBypass = sqlite3VdbeMakeLabel(v); |
| 97415 | sqlite3VdbeGoto(v, addrBypass); |
| 97416 | sqlite3VdbeJumpHere(v, addrDelete); |
| 97417 | } |
| 97418 | |
| 97419 | /* Unless this is a view, open cursors for the table we are |
| 97420 | ** deleting from and all its indices. If this is a view, then the |
| 97421 | ** only effect this statement has is to fire the INSTEAD OF |
| 97422 | ** triggers. |
| 97423 | */ |
| 97424 | if( !isView ){ |
| 97425 | testcase( IsVirtual(pTab) ); |
| 97426 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen, |
| 97427 | &iDataCur, &iIdxCur); |
| 97428 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 97429 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 97430 | } |
| 97431 | |
| 97432 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 97433 | ** where-clause loop above. |
| 97434 | */ |
| 97435 | if( okOnePass ){ |
| 97436 | /* Just one row. Hence the top-of-loop is a no-op */ |
| 97437 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 97438 | assert( !IsVirtual(pTab) ); |
| 97439 | if( aToOpen[iDataCur-iTabCur] ){ |
| 97440 | assert( pPk!=0 || pTab->pSelect!=0 ); |
| 97441 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 97442 | VdbeCoverage(v); |
| 97443 | } |
| @@ -97461,17 +97606,22 @@ | |
| 97461 | sqlite3MayAbort(pParse); |
| 97462 | }else |
| 97463 | #endif |
| 97464 | { |
| 97465 | int count = (pParse->nested==0); /* True to count changes */ |
| 97466 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 97467 | iKey, nKey, count, OE_Default, okOnePass); |
| 97468 | } |
| 97469 | |
| 97470 | /* End of the loop over all rowids/primary-keys. */ |
| 97471 | if( okOnePass ){ |
| 97472 | sqlite3VdbeResolveLabel(v, addrBypass); |
| 97473 | }else if( pPk ){ |
| 97474 | sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v); |
| 97475 | sqlite3VdbeJumpHere(v, addrLoop); |
| 97476 | }else{ |
| 97477 | sqlite3VdbeGoto(v, addrLoop); |
| @@ -97539,10 +97689,29 @@ | |
| 97539 | ** |
| 97540 | ** 3. The primary key for the row to be deleted must be stored in a |
| 97541 | ** sequence of nPk memory cells starting at iPk. If nPk==0 that means |
| 97542 | ** that a search record formed from OP_MakeRecord is contained in the |
| 97543 | ** single memory location iPk. |
| 97544 | */ |
| 97545 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 97546 | Parse *pParse, /* Parsing context */ |
| 97547 | Table *pTab, /* Table containing the row to be deleted */ |
| 97548 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -97550,11 +97719,12 @@ | |
| 97550 | int iIdxCur, /* First index cursor */ |
| 97551 | int iPk, /* First memory cell containing the PRIMARY KEY */ |
| 97552 | i16 nPk, /* Number of PRIMARY KEY memory cells */ |
| 97553 | u8 count, /* If non-zero, increment the row change counter */ |
| 97554 | u8 onconf, /* Default ON CONFLICT policy for triggers */ |
| 97555 | u8 bNoSeek /* iDataCur is already pointing to the row to delete */ |
| 97556 | ){ |
| 97557 | Vdbe *v = pParse->pVdbe; /* Vdbe */ |
| 97558 | int iOld = 0; /* First register in OLD.* array */ |
| 97559 | int iLabel; /* Label resolved to end of generated code */ |
| 97560 | u8 opSeek; /* Seek opcode */ |
| @@ -97567,11 +97737,11 @@ | |
| 97567 | /* Seek cursor iCur to the row to delete. If this row no longer exists |
| 97568 | ** (this can happen if a trigger program has already deleted it), do |
| 97569 | ** not attempt to delete it or fire any DELETE triggers. */ |
| 97570 | iLabel = sqlite3VdbeMakeLabel(v); |
| 97571 | opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound; |
| 97572 | if( !bNoSeek ){ |
| 97573 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 97574 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 97575 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 97576 | } |
| 97577 | |
| @@ -97627,15 +97797,19 @@ | |
| 97627 | |
| 97628 | /* Delete the index and table entries. Skip this step if pTab is really |
| 97629 | ** a view (in which case the only effect of the DELETE statement is to |
| 97630 | ** fire the INSTEAD OF triggers). */ |
| 97631 | if( pTab->pSelect==0 ){ |
| 97632 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0); |
| 97633 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 97634 | if( count ){ |
| 97635 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); |
| 97636 | } |
| 97637 | } |
| 97638 | |
| 97639 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 97640 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 97641 | ** to the row just deleted. */ |
| @@ -97674,11 +97848,12 @@ | |
| 97674 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete( |
| 97675 | Parse *pParse, /* Parsing and code generating context */ |
| 97676 | Table *pTab, /* Table containing the row to be deleted */ |
| 97677 | int iDataCur, /* Cursor of table holding data. */ |
| 97678 | int iIdxCur, /* First index cursor */ |
| 97679 | int *aRegIdx /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */ |
| 97680 | ){ |
| 97681 | int i; /* Index loop counter */ |
| 97682 | int r1 = -1; /* Register holding an index key */ |
| 97683 | int iPartIdxLabel; /* Jump destination for skipping partial index entries */ |
| 97684 | Index *pIdx; /* Current index */ |
| @@ -97690,15 +97865,16 @@ | |
| 97690 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 97691 | for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ |
| 97692 | assert( iIdxCur+i!=iDataCur || pPk==pIdx ); |
| 97693 | if( aRegIdx!=0 && aRegIdx[i]==0 ) continue; |
| 97694 | if( pIdx==pPk ) continue; |
| 97695 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 97696 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 97697 | &iPartIdxLabel, pPrior, r1); |
| 97698 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 97699 | pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); |
| 97700 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 97701 | pPrior = pIdx; |
| 97702 | } |
| 97703 | } |
| 97704 | |
| @@ -102350,14 +102526,17 @@ | |
| 102350 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102351 | } |
| 102352 | if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){ |
| 102353 | sqlite3MultiWrite(pParse); |
| 102354 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102355 | regNewData, 1, 0, OE_Replace, 1); |
| 102356 | }else if( pTab->pIndex ){ |
| 102357 | sqlite3MultiWrite(pParse); |
| 102358 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0); |
| 102359 | } |
| 102360 | seenReplace = 1; |
| 102361 | break; |
| 102362 | } |
| 102363 | case OE_Ignore: { |
| @@ -102531,11 +102710,12 @@ | |
| 102531 | sqlite3MultiWrite(pParse); |
| 102532 | if( db->flags&SQLITE_RecTriggers ){ |
| 102533 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102534 | } |
| 102535 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102536 | regR, nPkField, 0, OE_Replace, pIdx==pPk); |
| 102537 | seenReplace = 1; |
| 102538 | break; |
| 102539 | } |
| 102540 | } |
| 102541 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -112115,13 +112295,16 @@ | |
| 112115 | return WRC_Abort; |
| 112116 | } |
| 112117 | pTab->nRef++; |
| 112118 | #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) |
| 112119 | if( pTab->pSelect || IsVirtual(pTab) ){ |
| 112120 | /* We reach here if the named table is a really a view */ |
| 112121 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 112122 | assert( pFrom->pSelect==0 ); |
| 112123 | pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 112124 | sqlite3SelectSetName(pFrom->pSelect, pTab->zName); |
| 112125 | sqlite3WalkSelect(pWalker, pFrom->pSelect); |
| 112126 | } |
| 112127 | #endif |
| @@ -115381,11 +115564,11 @@ | |
| 115381 | }else{ |
| 115382 | j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid); |
| 115383 | } |
| 115384 | VdbeCoverageNeverTaken(v); |
| 115385 | } |
| 115386 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx); |
| 115387 | |
| 115388 | /* If changing the record number, delete the old record. */ |
| 115389 | if( hasFK || chngKey || pPk!=0 ){ |
| 115390 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 115391 | } |
| @@ -117596,11 +117779,11 @@ | |
| 117596 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 117597 | LogEst nRowOut; /* Estimated number of output rows */ |
| 117598 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 117599 | i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ |
| 117600 | u8 sorted; /* True if really sorted (not just grouped) */ |
| 117601 | u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */ |
| 117602 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 117603 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ |
| 117604 | u8 nLevel; /* Number of nested loop */ |
| 117605 | int iTop; /* The very beginning of the WHERE loop */ |
| 117606 | int iContinue; /* Jump here to continue with next record */ |
| @@ -117763,11 +117946,11 @@ | |
| 117763 | ** is run and there is an index on (a, b), then this function returns a |
| 117764 | ** string similar to: |
| 117765 | ** |
| 117766 | ** "a=? AND b>?" |
| 117767 | */ |
| 117768 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ |
| 117769 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117770 | u16 nEq = pLoop->u.btree.nEq; |
| 117771 | u16 nSkip = pLoop->nSkip; |
| 117772 | int i, j; |
| 117773 | |
| @@ -117864,11 +118047,11 @@ | |
| 117864 | zFmt = "INDEX %s"; |
| 117865 | } |
| 117866 | if( zFmt ){ |
| 117867 | sqlite3StrAccumAppend(&str, " USING ", 7); |
| 117868 | sqlite3XPrintf(&str, 0, zFmt, pIdx->zName); |
| 117869 | explainIndexRange(&str, pLoop, pItem->pTab); |
| 117870 | } |
| 117871 | }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ |
| 117872 | const char *zRangeOp; |
| 117873 | if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ |
| 117874 | zRangeOp = "="; |
| @@ -118212,12 +118395,12 @@ | |
| 118212 | VdbeCoverageIf(v, bRev==0); |
| 118213 | VdbeCoverageIf(v, bRev!=0); |
| 118214 | sqlite3VdbeJumpHere(v, j); |
| 118215 | for(j=0; j<nSkip; j++){ |
| 118216 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j); |
| 118217 | assert( pIdx->aiColumn[j]>=0 ); |
| 118218 | VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName)); |
| 118219 | } |
| 118220 | } |
| 118221 | |
| 118222 | /* Evaluate the equality constraints |
| 118223 | */ |
| @@ -118767,11 +118950,16 @@ | |
| 118767 | /* pIdx is a covering index. No need to access the main table. */ |
| 118768 | }else if( HasRowid(pIdx->pTable) ){ |
| 118769 | iRowidReg = ++pParse->nMem; |
| 118770 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 118771 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 118772 | sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ |
| 118773 | }else if( iCur!=iIdxCur ){ |
| 118774 | Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 118775 | iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 118776 | for(j=0; j<pPk->nKeyCol; j++){ |
| 118777 | k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); |
| @@ -120618,13 +120806,15 @@ | |
| 120618 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo *pWInfo){ |
| 120619 | return pWInfo->iBreak; |
| 120620 | } |
| 120621 | |
| 120622 | /* |
| 120623 | ** Return TRUE if an UPDATE or DELETE statement can operate directly on |
| 120624 | ** the rowids returned by a WHERE clause. Return FALSE if doing an |
| 120625 | ** UPDATE or DELETE might change subsequent WHERE clause results. |
| 120626 | ** |
| 120627 | ** If the ONEPASS optimization is used (if this routine returns true) |
| 120628 | ** then also write the indices of open cursors used by ONEPASS |
| 120629 | ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data |
| 120630 | ** table and iaCur[1] gets the cursor used by an auxiliary index. |
| @@ -120634,11 +120824,11 @@ | |
| 120634 | ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is |
| 120635 | ** unable to use the ONEPASS optimization. |
| 120636 | */ |
| 120637 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){ |
| 120638 | memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2); |
| 120639 | return pWInfo->okOnePass; |
| 120640 | } |
| 120641 | |
| 120642 | /* |
| 120643 | ** Move the content of pSrc into pDest |
| 120644 | */ |
| @@ -120729,25 +120919,24 @@ | |
| 120729 | int k = pScan->k; /* Where to start scanning */ |
| 120730 | |
| 120731 | while( pScan->iEquiv<=pScan->nEquiv ){ |
| 120732 | iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 120733 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 120734 | assert( iColumn!=(-2) || pScan->pIdxExpr!=0 ); |
| 120735 | while( (pWC = pScan->pWC)!=0 ){ |
| 120736 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 120737 | if( pTerm->leftCursor==iCur |
| 120738 | && pTerm->u.leftColumn==iColumn |
| 120739 | && (iColumn!=(-2) |
| 120740 | || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) |
| 120741 | && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) |
| 120742 | ){ |
| 120743 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 120744 | && pScan->nEquiv<ArraySize(pScan->aiCur) |
| 120745 | ){ |
| 120746 | int j; |
| 120747 | pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight); |
| 120748 | assert( pX->op==TK_COLUMN ); |
| 120749 | for(j=0; j<pScan->nEquiv; j++){ |
| 120750 | if( pScan->aiCur[j]==pX->iTable |
| 120751 | && pScan->aiColumn[j]==pX->iColumn ){ |
| 120752 | break; |
| 120753 | } |
| @@ -122969,21 +123158,28 @@ | |
| 122969 | WhereLoopBuilder *pBuilder, |
| 122970 | Index *pIndex, |
| 122971 | int iCursor |
| 122972 | ){ |
| 122973 | ExprList *pOB; |
| 122974 | int ii, jj; |
| 122975 | |
| 122976 | if( pIndex->bUnordered ) return 0; |
| 122977 | if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0; |
| 122978 | for(ii=0; ii<pOB->nExpr; ii++){ |
| 122979 | Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr); |
| 122980 | if( pExpr->op!=TK_COLUMN ) return 0; |
| 122981 | if( pExpr->iTable==iCursor ){ |
| 122982 | if( pExpr->iColumn<0 ) return 1; |
| 122983 | for(jj=0; jj<pIndex->nKeyCol; jj++){ |
| 122984 | if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1; |
| 122985 | } |
| 122986 | } |
| 122987 | } |
| 122988 | return 0; |
| 122989 | } |
| @@ -123128,11 +123324,11 @@ | |
| 123128 | if( !pBuilder->pOrSet /* Not part of an OR optimization */ |
| 123129 | && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0 |
| 123130 | && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0 |
| 123131 | && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */ |
| 123132 | && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */ |
| 123133 | && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */ |
| 123134 | && !pSrc->fg.isCorrelated /* Not a correlated subquery */ |
| 123135 | && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ |
| 123136 | ){ |
| 123137 | /* Generate auto-index WhereLoops */ |
| 123138 | WhereTerm *pTerm; |
| @@ -123812,13 +124008,19 @@ | |
| 123812 | if( MASKBIT(i) & obSat ) continue; |
| 123813 | pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr); |
| 123814 | testcase( wctrlFlags & WHERE_GROUPBY ); |
| 123815 | testcase( wctrlFlags & WHERE_DISTINCTBY ); |
| 123816 | if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0; |
| 123817 | if( pOBExpr->op!=TK_COLUMN ) continue; |
| 123818 | if( pOBExpr->iTable!=iCur ) continue; |
| 123819 | if( pOBExpr->iColumn!=iColumn ) continue; |
| 123820 | if( iColumn>=0 ){ |
| 123821 | pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr); |
| 123822 | if( !pColl ) pColl = db->pDfltColl; |
| 123823 | if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue; |
| 123824 | } |
| @@ -124507,10 +124709,14 @@ | |
| 124507 | WhereLoop *pLoop; /* Pointer to a single WhereLoop object */ |
| 124508 | int ii; /* Loop counter */ |
| 124509 | sqlite3 *db; /* Database connection */ |
| 124510 | int rc; /* Return code */ |
| 124511 | |
| 124512 | |
| 124513 | /* Variable initialization */ |
| 124514 | db = pParse->db; |
| 124515 | memset(&sWLB, 0, sizeof(sWLB)); |
| 124516 | |
| @@ -124562,10 +124768,11 @@ | |
| 124562 | pWInfo->pOrderBy = pOrderBy; |
| 124563 | pWInfo->pResultSet = pResultSet; |
| 124564 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 124565 | pWInfo->wctrlFlags = wctrlFlags; |
| 124566 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 124567 | pMaskSet = &pWInfo->sMaskSet; |
| 124568 | sWLB.pWInfo = pWInfo; |
| 124569 | sWLB.pWC = &pWInfo->sWC; |
| 124570 | sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); |
| 124571 | assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) ); |
| @@ -124748,15 +124955,20 @@ | |
| 124748 | ** to use a one-pass algorithm, determine if this is appropriate. |
| 124749 | ** The one-pass algorithm only works if the WHERE clause constrains |
| 124750 | ** the statement to update or delete a single row. |
| 124751 | */ |
| 124752 | assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); |
| 124753 | if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 |
| 124754 | && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){ |
| 124755 | pWInfo->okOnePass = 1; |
| 124756 | if( HasRowid(pTabList->a[0].pTab) ){ |
| 124757 | pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY; |
| 124758 | } |
| 124759 | } |
| 124760 | |
| 124761 | /* Open all tables in the pTabList and any indices selected for |
| 124762 | ** searching those tables. |
| @@ -124783,19 +124995,19 @@ | |
| 124783 | }else |
| 124784 | #endif |
| 124785 | if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 124786 | && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){ |
| 124787 | int op = OP_OpenRead; |
| 124788 | if( pWInfo->okOnePass ){ |
| 124789 | op = OP_OpenWrite; |
| 124790 | pWInfo->aiCurOnePass[0] = pTabItem->iCursor; |
| 124791 | }; |
| 124792 | sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op); |
| 124793 | assert( pTabItem->iCursor==pLevel->iTabCur ); |
| 124794 | testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 ); |
| 124795 | testcase( !pWInfo->okOnePass && pTab->nCol==BMS ); |
| 124796 | if( !pWInfo->okOnePass && pTab->nCol<BMS && HasRowid(pTab) ){ |
| 124797 | Bitmask b = pTabItem->colUsed; |
| 124798 | int n = 0; |
| 124799 | for(; b; b=b>>1, n++){} |
| 124800 | sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1, |
| 124801 | SQLITE_INT_TO_PTR(n), P4_INT32); |
| @@ -124819,11 +125031,11 @@ | |
| 124819 | ){ |
| 124820 | /* This is one term of an OR-optimization using the PRIMARY KEY of a |
| 124821 | ** WITHOUT ROWID table. No need for a separate index */ |
| 124822 | iIndexCur = pLevel->iTabCur; |
| 124823 | op = 0; |
| 124824 | }else if( pWInfo->okOnePass ){ |
| 124825 | Index *pJ = pTabItem->pTab->pIndex; |
| 124826 | iIndexCur = iIdxCur; |
| 124827 | assert( wctrlFlags & WHERE_ONEPASS_DESIRED ); |
| 124828 | while( ALWAYS(pJ) && pJ!=pIx ){ |
| 124829 | iIndexCur++; |
| @@ -125027,11 +125239,11 @@ | |
| 125027 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 125028 | && pTab->pSelect==0 |
| 125029 | && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 |
| 125030 | ){ |
| 125031 | int ws = pLoop->wsFlags; |
| 125032 | if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){ |
| 125033 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| 125034 | } |
| 125035 | if( (ws & WHERE_INDEXED)!=0 |
| 125036 | && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 |
| 125037 | && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1] |
| 125038 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -325,11 +325,11 @@ | |
| 325 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 326 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 327 | */ |
| 328 | #define SQLITE_VERSION "3.8.12" |
| 329 | #define SQLITE_VERSION_NUMBER 3008012 |
| 330 | #define SQLITE_SOURCE_ID "2015-09-24 18:47:59 668fc1ebaf426f9eed3ed7865e41f1023dafebfb" |
| 331 | |
| 332 | /* |
| 333 | ** CAPI3REF: Run-Time Library Version Numbers |
| 334 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 335 | ** |
| @@ -336,11 +336,11 @@ | |
| 336 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 337 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 338 | ** but are associated with the library instead of the header file. ^(Cautious |
| 339 | ** programmers might include assert() statements in their application to |
| 340 | ** verify that values returned by these interfaces match the macros in |
| 341 | ** the header, and thus ensure that the application is |
| 342 | ** compiled with matching library and header files. |
| 343 | ** |
| 344 | ** <blockquote><pre> |
| 345 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 346 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -586,11 +586,11 @@ | |
| 586 | ** is not changed. |
| 587 | ** |
| 588 | ** Restrictions: |
| 589 | ** |
| 590 | ** <ul> |
| 591 | ** <li> The application must ensure that the 1st parameter to sqlite3_exec() |
| 592 | ** is a valid and open [database connection]. |
| 593 | ** <li> The application must not close the [database connection] specified by |
| 594 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 595 | ** <li> The application must not modify the SQL statement text passed into |
| 596 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1579,13 +1579,15 @@ | |
| 1579 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1580 | ** the application. The default configuration is recommended for most |
| 1581 | ** applications and so this routine is usually not necessary. It is |
| 1582 | ** provided to support rare applications with unusual needs. |
| 1583 | ** |
| 1584 | ** <b>The sqlite3_config() interface is not threadsafe. The application |
| 1585 | ** must ensure that no other SQLite interfaces are invoked by other |
| 1586 | ** threads while sqlite3_config() is running.</b> |
| 1587 | ** |
| 1588 | ** The sqlite3_config() interface |
| 1589 | ** may only be invoked prior to library initialization using |
| 1590 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1591 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1592 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1593 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3840,11 +3842,11 @@ | |
| 3842 | ** name must be given in UTF-8 even if the original statement |
| 3843 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3844 | ** |
| 3845 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3846 | ** [sqlite3_bind_parameter_count()], and |
| 3847 | ** [sqlite3_bind_parameter_name()]. |
| 3848 | */ |
| 3849 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3850 | |
| 3851 | /* |
| 3852 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6337,10 +6339,13 @@ | |
| 6339 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6340 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6341 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6342 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6343 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6344 | ** <li> SQLITE_MUTEX_STATIC_VFS1 |
| 6345 | ** <li> SQLITE_MUTEX_STATIC_VFS2 |
| 6346 | ** <li> SQLITE_MUTEX_STATIC_VFS3 |
| 6347 | ** </ul> |
| 6348 | ** |
| 6349 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6350 | ** cause sqlite3_mutex_alloc() to create |
| 6351 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| @@ -9623,11 +9628,11 @@ | |
| 9628 | int bias, |
| 9629 | int *pRes |
| 9630 | ); |
| 9631 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 9632 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 9633 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, int); |
| 9634 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, |
| 9635 | const void *pData, int nData, |
| 9636 | int nZero, int bias, int seekResult); |
| 9637 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 9638 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| @@ -10339,10 +10344,13 @@ | |
| 10344 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 10345 | |
| 10346 | /* Functions used to configure a Pager object. */ |
| 10347 | SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); |
| 10348 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 10349 | #ifdef SQLITE_HAS_CODEC |
| 10350 | SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); |
| 10351 | #endif |
| 10352 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 10353 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 10354 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 10355 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| 10356 | SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); |
| @@ -12341,10 +12349,11 @@ | |
| 12349 | #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */ |
| 12350 | #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ |
| 12351 | #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ |
| 12352 | #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ |
| 12353 | #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ |
| 12354 | #define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */ |
| 12355 | |
| 12356 | /* Allowed return values from sqlite3WhereIsDistinct() |
| 12357 | */ |
| 12358 | #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ |
| 12359 | #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ |
| @@ -13184,11 +13193,11 @@ | |
| 13193 | SQLITE_PRIVATE int sqlite3MutexEnd(void); |
| 13194 | #endif |
| 13195 | #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) |
| 13196 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void); |
| 13197 | #else |
| 13198 | # define sqlite3MemoryBarrier() |
| 13199 | #endif |
| 13200 | |
| 13201 | SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); |
| 13202 | SQLITE_PRIVATE void sqlite3StatusUp(int, int); |
| 13203 | SQLITE_PRIVATE void sqlite3StatusDown(int, int); |
| @@ -13369,10 +13378,13 @@ | |
| 13378 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 13379 | SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*); |
| 13380 | SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*); |
| 13381 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 13382 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 13383 | #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ |
| 13384 | #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ |
| 13385 | #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ |
| 13386 | SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); |
| 13387 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 13388 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 13389 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 13390 | SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); |
| @@ -13429,12 +13441,13 @@ | |
| 13441 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 13442 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 13443 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 13444 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 13445 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 13446 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 13447 | Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); |
| 13448 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); |
| 13449 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 13450 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 13451 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 13452 | u8,u8,int,int*); |
| 13453 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| @@ -19319,11 +19332,11 @@ | |
| 19332 | ** For debugging purposes, record when the mutex subsystem is initialized |
| 19333 | ** and uninitialized so that we can assert() if there is an attempt to |
| 19334 | ** allocate a mutex while the system is uninitialized. |
| 19335 | */ |
| 19336 | static SQLITE_WSD int mutexIsInit = 0; |
| 19337 | #endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */ |
| 19338 | |
| 19339 | |
| 19340 | #ifndef SQLITE_MUTEX_OMIT |
| 19341 | /* |
| 19342 | ** Initialize the mutex system. |
| @@ -19353,10 +19366,11 @@ | |
| 19366 | pTo->xMutexHeld = pFrom->xMutexHeld; |
| 19367 | pTo->xMutexNotheld = pFrom->xMutexNotheld; |
| 19368 | sqlite3MemoryBarrier(); |
| 19369 | pTo->xMutexAlloc = pFrom->xMutexAlloc; |
| 19370 | } |
| 19371 | assert( sqlite3GlobalConfig.mutex.xMutexInit ); |
| 19372 | rc = sqlite3GlobalConfig.mutex.xMutexInit(); |
| 19373 | |
| 19374 | #ifdef SQLITE_DEBUG |
| 19375 | GLOBAL(int, mutexIsInit) = 1; |
| 19376 | #endif |
| @@ -19387,26 +19401,29 @@ | |
| 19401 | SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){ |
| 19402 | #ifndef SQLITE_OMIT_AUTOINIT |
| 19403 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 19404 | if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 19405 | #endif |
| 19406 | assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); |
| 19407 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19408 | } |
| 19409 | |
| 19410 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| 19411 | if( !sqlite3GlobalConfig.bCoreMutex ){ |
| 19412 | return 0; |
| 19413 | } |
| 19414 | assert( GLOBAL(int, mutexIsInit) ); |
| 19415 | assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); |
| 19416 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 19417 | } |
| 19418 | |
| 19419 | /* |
| 19420 | ** Free a dynamic mutex. |
| 19421 | */ |
| 19422 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){ |
| 19423 | if( p ){ |
| 19424 | assert( sqlite3GlobalConfig.mutex.xMutexFree ); |
| 19425 | sqlite3GlobalConfig.mutex.xMutexFree(p); |
| 19426 | } |
| 19427 | } |
| 19428 | |
| 19429 | /* |
| @@ -19413,10 +19430,11 @@ | |
| 19430 | ** Obtain the mutex p. If some other thread already has the mutex, block |
| 19431 | ** until it can be obtained. |
| 19432 | */ |
| 19433 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){ |
| 19434 | if( p ){ |
| 19435 | assert( sqlite3GlobalConfig.mutex.xMutexEnter ); |
| 19436 | sqlite3GlobalConfig.mutex.xMutexEnter(p); |
| 19437 | } |
| 19438 | } |
| 19439 | |
| 19440 | /* |
| @@ -19424,10 +19442,11 @@ | |
| 19442 | ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. |
| 19443 | */ |
| 19444 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){ |
| 19445 | int rc = SQLITE_OK; |
| 19446 | if( p ){ |
| 19447 | assert( sqlite3GlobalConfig.mutex.xMutexTry ); |
| 19448 | return sqlite3GlobalConfig.mutex.xMutexTry(p); |
| 19449 | } |
| 19450 | return rc; |
| 19451 | } |
| 19452 | |
| @@ -19437,10 +19456,11 @@ | |
| 19456 | ** is not currently entered. If a NULL pointer is passed as an argument |
| 19457 | ** this function is a no-op. |
| 19458 | */ |
| 19459 | SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){ |
| 19460 | if( p ){ |
| 19461 | assert( sqlite3GlobalConfig.mutex.xMutexLeave ); |
| 19462 | sqlite3GlobalConfig.mutex.xMutexLeave(p); |
| 19463 | } |
| 19464 | } |
| 19465 | |
| 19466 | #ifndef NDEBUG |
| @@ -19447,13 +19467,15 @@ | |
| 19467 | /* |
| 19468 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 19469 | ** intended for use inside assert() statements. |
| 19470 | */ |
| 19471 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){ |
| 19472 | assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); |
| 19473 | return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); |
| 19474 | } |
| 19475 | SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){ |
| 19476 | assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); |
| 19477 | return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
| 19478 | } |
| 19479 | #endif |
| 19480 | |
| 19481 | #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
| @@ -19764,11 +19786,11 @@ | |
| 19786 | ** Try to provide a memory barrier operation, needed for initialization only. |
| 19787 | */ |
| 19788 | SQLITE_PRIVATE void sqlite3MemoryBarrier(void){ |
| 19789 | #if defined(SQLITE_MEMORY_BARRIER) |
| 19790 | SQLITE_MEMORY_BARRIER; |
| 19791 | #elif defined(__GNUC__) && GCC_VERSION>=4001000 |
| 19792 | __sync_synchronize(); |
| 19793 | #endif |
| 19794 | } |
| 19795 | |
| 19796 | /* |
| @@ -30682,11 +30704,12 @@ | |
| 30704 | */ |
| 30705 | static void unixShmBarrier( |
| 30706 | sqlite3_file *fd /* Database file holding the shared memory */ |
| 30707 | ){ |
| 30708 | UNUSED_PARAMETER(fd); |
| 30709 | sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ |
| 30710 | unixEnterMutex(); /* Also mutex, for redundancy */ |
| 30711 | unixLeaveMutex(); |
| 30712 | } |
| 30713 | |
| 30714 | /* |
| 30715 | ** Close a connection to shared-memory. Delete the underlying |
| @@ -37637,12 +37660,12 @@ | |
| 37660 | */ |
| 37661 | static void winShmBarrier( |
| 37662 | sqlite3_file *fd /* Database holding the shared memory */ |
| 37663 | ){ |
| 37664 | UNUSED_PARAMETER(fd); |
| 37665 | sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ |
| 37666 | winShmEnterMutex(); /* Also mutex, for redundancy */ |
| 37667 | winShmLeaveMutex(); |
| 37668 | } |
| 37669 | |
| 37670 | /* |
| 37671 | ** This function is called to obtain a pointer to region iRegion of the |
| @@ -40930,11 +40953,11 @@ | |
| 40953 | ** this mutex is not held. */ |
| 40954 | assert( pcache1.separateCache==0 ); |
| 40955 | assert( pCache->pGroup==&pcache1.grp ); |
| 40956 | pcache1LeaveMutex(pCache->pGroup); |
| 40957 | #endif |
| 40958 | if( benignMalloc ){ sqlite3BeginBenignMalloc(); } |
| 40959 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 40960 | pPg = pcache1Alloc(pCache->szPage); |
| 40961 | p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); |
| 40962 | if( !pPg || !p ){ |
| 40963 | pcache1Free(pPg); |
| @@ -40943,11 +40966,11 @@ | |
| 40966 | } |
| 40967 | #else |
| 40968 | pPg = pcache1Alloc(pCache->szAlloc); |
| 40969 | p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; |
| 40970 | #endif |
| 40971 | if( benignMalloc ){ sqlite3EndBenignMalloc(); } |
| 40972 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40973 | pcache1EnterMutex(pCache->pGroup); |
| 40974 | #endif |
| 40975 | if( pPg==0 ) return 0; |
| 40976 | p->page.pBuf = pPg; |
| @@ -44522,10 +44545,24 @@ | |
| 44545 | } |
| 44546 | } |
| 44547 | #else |
| 44548 | # define pagerReportSize(X) /* No-op if we do not support a codec */ |
| 44549 | #endif |
| 44550 | |
| 44551 | #ifdef SQLITE_HAS_CODEC |
| 44552 | /* |
| 44553 | ** Make sure the number of reserved bits is the same in the destination |
| 44554 | ** pager as it is in the source. This comes up when a VACUUM changes the |
| 44555 | ** number of reserved bits to the "optimal" amount. |
| 44556 | */ |
| 44557 | SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager *pDest, Pager *pSrc){ |
| 44558 | if( pDest->nReserve!=pSrc->nReserve ){ |
| 44559 | pDest->nReserve = pSrc->nReserve; |
| 44560 | pagerReportSize(pDest); |
| 44561 | } |
| 44562 | } |
| 44563 | #endif |
| 44564 | |
| 44565 | /* |
| 44566 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 44567 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 44568 | ** The page begins at offset *pOffset into the file. The *pOffset |
| @@ -54479,10 +54516,53 @@ | |
| 54516 | pCur->apPage[i] = 0; |
| 54517 | } |
| 54518 | pCur->iPage = -1; |
| 54519 | } |
| 54520 | |
| 54521 | /* |
| 54522 | ** The cursor passed as the only argument must point to a valid entry |
| 54523 | ** when this function is called (i.e. have eState==CURSOR_VALID). This |
| 54524 | ** function saves the current cursor key in variables pCur->nKey and |
| 54525 | ** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error |
| 54526 | ** code otherwise. |
| 54527 | ** |
| 54528 | ** If the cursor is open on an intkey table, then the integer key |
| 54529 | ** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to |
| 54530 | ** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is |
| 54531 | ** set to point to a malloced buffer pCur->nKey bytes in size containing |
| 54532 | ** the key. |
| 54533 | */ |
| 54534 | static int saveCursorKey(BtCursor *pCur){ |
| 54535 | int rc; |
| 54536 | assert( CURSOR_VALID==pCur->eState ); |
| 54537 | assert( 0==pCur->pKey ); |
| 54538 | assert( cursorHoldsMutex(pCur) ); |
| 54539 | |
| 54540 | rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); |
| 54541 | assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ |
| 54542 | |
| 54543 | /* If this is an intKey table, then the above call to BtreeKeySize() |
| 54544 | ** stores the integer key in pCur->nKey. In this case this value is |
| 54545 | ** all that is required. Otherwise, if pCur is not open on an intKey |
| 54546 | ** table, then malloc space for and store the pCur->nKey bytes of key |
| 54547 | ** data. */ |
| 54548 | if( 0==pCur->curIntKey ){ |
| 54549 | void *pKey = sqlite3Malloc( pCur->nKey ); |
| 54550 | if( pKey ){ |
| 54551 | rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); |
| 54552 | if( rc==SQLITE_OK ){ |
| 54553 | pCur->pKey = pKey; |
| 54554 | }else{ |
| 54555 | sqlite3_free(pKey); |
| 54556 | } |
| 54557 | }else{ |
| 54558 | rc = SQLITE_NOMEM; |
| 54559 | } |
| 54560 | } |
| 54561 | assert( !pCur->curIntKey || !pCur->pKey ); |
| 54562 | return rc; |
| 54563 | } |
| 54564 | |
| 54565 | /* |
| 54566 | ** Save the current cursor position in the variables BtCursor.nKey |
| 54567 | ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK. |
| 54568 | ** |
| @@ -54499,34 +54579,12 @@ | |
| 54579 | if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 54580 | pCur->eState = CURSOR_VALID; |
| 54581 | }else{ |
| 54582 | pCur->skipNext = 0; |
| 54583 | } |
| 54584 | |
| 54585 | rc = saveCursorKey(pCur); |
| 54586 | if( rc==SQLITE_OK ){ |
| 54587 | btreeReleaseAllCursorPages(pCur); |
| 54588 | pCur->eState = CURSOR_REQUIRESEEK; |
| 54589 | } |
| 54590 | |
| @@ -61914,22 +61972,28 @@ | |
| 61972 | end_insert: |
| 61973 | return rc; |
| 61974 | } |
| 61975 | |
| 61976 | /* |
| 61977 | ** Delete the entry that the cursor is pointing to. |
| 61978 | ** |
| 61979 | ** If the second parameter is zero, then the cursor is left pointing at an |
| 61980 | ** arbitrary location after the delete. If it is non-zero, then the cursor |
| 61981 | ** is left in a state such that the next call to BtreeNext() or BtreePrev() |
| 61982 | ** moves it to the same row as it would if the call to BtreeDelete() had |
| 61983 | ** been omitted. |
| 61984 | */ |
| 61985 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){ |
| 61986 | Btree *p = pCur->pBtree; |
| 61987 | BtShared *pBt = p->pBt; |
| 61988 | int rc; /* Return code */ |
| 61989 | MemPage *pPage; /* Page to delete cell from */ |
| 61990 | unsigned char *pCell; /* Pointer to cell to delete */ |
| 61991 | int iCellIdx; /* Index of cell to delete */ |
| 61992 | int iCellDepth; /* Depth of node containing pCell */ |
| 61993 | u16 szCell; /* Size of the cell being deleted */ |
| 61994 | int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */ |
| 61995 | |
| 61996 | assert( cursorHoldsMutex(pCur) ); |
| 61997 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 61998 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 61999 | assert( pCur->curFlags & BTCF_WriteFlag ); |
| @@ -61955,14 +62019,11 @@ | |
| 62019 | rc = sqlite3BtreePrevious(pCur, ¬Used); |
| 62020 | if( rc ) return rc; |
| 62021 | } |
| 62022 | |
| 62023 | /* Save the positions of any other cursors open on this table before |
| 62024 | ** making any modifications. */ |
| 62025 | if( pCur->curFlags & BTCF_Multiple ){ |
| 62026 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 62027 | if( rc ) return rc; |
| 62028 | } |
| 62029 | |
| @@ -61970,10 +62031,35 @@ | |
| 62031 | ** invalidate any incrblob cursors open on the row being deleted. */ |
| 62032 | if( pCur->pKeyInfo==0 ){ |
| 62033 | invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 62034 | } |
| 62035 | |
| 62036 | /* If the bPreserve flag is set to true, then the cursor position must |
| 62037 | ** be preserved following this delete operation. If the current delete |
| 62038 | ** will cause a b-tree rebalance, then this is done by saving the cursor |
| 62039 | ** key and leaving the cursor in CURSOR_REQUIRESEEK state before |
| 62040 | ** returning. |
| 62041 | ** |
| 62042 | ** Or, if the current delete will not cause a rebalance, then the cursor |
| 62043 | ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately |
| 62044 | ** before or after the deleted entry. In this case set bSkipnext to true. */ |
| 62045 | if( bPreserve ){ |
| 62046 | if( !pPage->leaf |
| 62047 | || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 62048 | ){ |
| 62049 | /* A b-tree rebalance will be required after deleting this entry. |
| 62050 | ** Save the cursor key. */ |
| 62051 | rc = saveCursorKey(pCur); |
| 62052 | if( rc ) return rc; |
| 62053 | }else{ |
| 62054 | bSkipnext = 1; |
| 62055 | } |
| 62056 | } |
| 62057 | |
| 62058 | /* Make the page containing the entry to be deleted writable. Then free any |
| 62059 | ** overflow pages associated with the entry and finally remove the cell |
| 62060 | ** itself from within the page. */ |
| 62061 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 62062 | if( rc ) return rc; |
| 62063 | rc = clearCell(pPage, pCell, &szCell); |
| 62064 | dropCell(pPage, iCellIdx, szCell, &rc); |
| 62065 | if( rc ) return rc; |
| @@ -62023,11 +62109,27 @@ | |
| 62109 | } |
| 62110 | rc = balance(pCur); |
| 62111 | } |
| 62112 | |
| 62113 | if( rc==SQLITE_OK ){ |
| 62114 | if( bSkipnext ){ |
| 62115 | assert( bPreserve && pCur->iPage==iCellDepth ); |
| 62116 | assert( pPage==pCur->apPage[pCur->iPage] ); |
| 62117 | assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell ); |
| 62118 | pCur->eState = CURSOR_SKIPNEXT; |
| 62119 | if( iCellIdx>=pPage->nCell ){ |
| 62120 | pCur->skipNext = -1; |
| 62121 | pCur->aiIdx[iCellDepth] = pPage->nCell-1; |
| 62122 | }else{ |
| 62123 | pCur->skipNext = 1; |
| 62124 | } |
| 62125 | }else{ |
| 62126 | rc = moveToRoot(pCur); |
| 62127 | if( bPreserve ){ |
| 62128 | pCur->eState = CURSOR_REQUIRESEEK; |
| 62129 | } |
| 62130 | } |
| 62131 | } |
| 62132 | return rc; |
| 62133 | } |
| 62134 | |
| 62135 | /* |
| @@ -62745,10 +62847,14 @@ | |
| 62847 | } |
| 62848 | } |
| 62849 | #endif |
| 62850 | iPage = get4byte(pOvflData); |
| 62851 | sqlite3PagerUnref(pOvflPage); |
| 62852 | |
| 62853 | if( isFreeList && N<(iPage!=0) ){ |
| 62854 | checkAppendMsg(pCheck, "free-page count in header is too small"); |
| 62855 | } |
| 62856 | } |
| 62857 | } |
| 62858 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 62859 | |
| 62860 | /* |
| @@ -64237,10 +64343,14 @@ | |
| 64343 | memset(&b, 0, sizeof(b)); |
| 64344 | b.pSrcDb = pFrom->db; |
| 64345 | b.pSrc = pFrom; |
| 64346 | b.pDest = pTo; |
| 64347 | b.iNext = 1; |
| 64348 | |
| 64349 | #ifdef SQLITE_HAS_CODEC |
| 64350 | sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom)); |
| 64351 | #endif |
| 64352 | |
| 64353 | /* 0x7FFFFFFF is the hard limit for the number of pages in a database |
| 64354 | ** file. By passing this as the number of pages to copy to |
| 64355 | ** sqlite3_backup_step(), we can guarantee that the copy finishes |
| 64356 | ** within a single call (unless an error occurs). The assert() statement |
| @@ -71166,22 +71276,23 @@ | |
| 71276 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 71277 | __attribute__((aligned(8))) |
| 71278 | #endif |
| 71279 | = { |
| 71280 | /* .u = */ {0}, |
| 71281 | /* .flags = */ (u16)MEM_Null, |
| 71282 | /* .enc = */ (u8)0, |
| 71283 | /* .eSubtype = */ (u8)0, |
| 71284 | /* .n = */ (int)0, |
| 71285 | /* .z = */ (char*)0, |
| 71286 | /* .zMalloc = */ (char*)0, |
| 71287 | /* .szMalloc = */ (int)0, |
| 71288 | /* .uTemp = */ (u32)0, |
| 71289 | /* .db = */ (sqlite3*)0, |
| 71290 | /* .xDel = */ (void(*)(void*))0, |
| 71291 | #ifdef SQLITE_DEBUG |
| 71292 | /* .pScopyFrom = */ (Mem*)0, |
| 71293 | /* .pFiller = */ (void*)0, |
| 71294 | #endif |
| 71295 | }; |
| 71296 | return &nullMem; |
| 71297 | } |
| 71298 | |
| @@ -76172,13 +76283,14 @@ | |
| 76283 | /* Opcode: NotExists P1 P2 P3 * * |
| 76284 | ** Synopsis: intkey=r[P3] |
| 76285 | ** |
| 76286 | ** P1 is the index of a cursor open on an SQL table btree (with integer |
| 76287 | ** keys). P3 is an integer rowid. If P1 does not contain a record with |
| 76288 | ** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an |
| 76289 | ** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then |
| 76290 | ** leave the cursor pointing at that record and fall through to the next |
| 76291 | ** instruction. |
| 76292 | ** |
| 76293 | ** The OP_NotFound opcode performs the same operation on index btrees |
| 76294 | ** (with arbitrary multi-value keys). |
| 76295 | ** |
| 76296 | ** This opcode leaves the cursor in a state where it cannot be advanced |
| @@ -76206,17 +76318,25 @@ | |
| 76318 | pCrsr = pC->pCursor; |
| 76319 | assert( pCrsr!=0 ); |
| 76320 | res = 0; |
| 76321 | iKey = pIn3->u.i; |
| 76322 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 76323 | assert( rc==SQLITE_OK || res==0 ); |
| 76324 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 76325 | pC->nullRow = 0; |
| 76326 | pC->cacheStatus = CACHE_STALE; |
| 76327 | pC->deferredMoveto = 0; |
| 76328 | VdbeBranchTaken(res!=0,2); |
| 76329 | pC->seekResult = res; |
| 76330 | if( res!=0 ){ |
| 76331 | assert( rc==SQLITE_OK ); |
| 76332 | if( pOp->p2==0 ){ |
| 76333 | rc = SQLITE_CORRUPT_BKPT; |
| 76334 | }else{ |
| 76335 | goto jump_to_p2; |
| 76336 | } |
| 76337 | } |
| 76338 | break; |
| 76339 | } |
| 76340 | |
| 76341 | /* Opcode: Sequence P1 P2 * * * |
| 76342 | ** Synopsis: r[P2]=cursor[P1].ctr++ |
| @@ -76478,18 +76598,19 @@ | |
| 76598 | assert( pC->iDb>=0 ); |
| 76599 | } |
| 76600 | break; |
| 76601 | } |
| 76602 | |
| 76603 | /* Opcode: Delete P1 P2 * P4 P5 |
| 76604 | ** |
| 76605 | ** Delete the record at which the P1 cursor is currently pointing. |
| 76606 | ** |
| 76607 | ** If the P5 parameter is non-zero, the cursor will be left pointing at |
| 76608 | ** either the next or the previous record in the table. If it is left |
| 76609 | ** pointing at the next record, then the next Next instruction will be a |
| 76610 | ** no-op. As a result, in this case it is OK to delete a record from within a |
| 76611 | ** Next loop. If P5 is zero, then the cursor is left in an undefined state. |
| 76612 | ** |
| 76613 | ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is |
| 76614 | ** incremented (otherwise not). |
| 76615 | ** |
| 76616 | ** P1 must not be pseudo-table. It has to be a real table with |
| @@ -76500,33 +76621,39 @@ | |
| 76621 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 76622 | ** using OP_NotFound prior to invoking this opcode. |
| 76623 | */ |
| 76624 | case OP_Delete: { |
| 76625 | VdbeCursor *pC; |
| 76626 | u8 hasUpdateCallback; |
| 76627 | |
| 76628 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 76629 | pC = p->apCsr[pOp->p1]; |
| 76630 | assert( pC!=0 ); |
| 76631 | assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 76632 | assert( pC->deferredMoveto==0 ); |
| 76633 | |
| 76634 | hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable; |
| 76635 | if( pOp->p5 && hasUpdateCallback ){ |
| 76636 | sqlite3BtreeKeySize(pC->pCursor, &pC->movetoTarget); |
| 76637 | } |
| 76638 | |
| 76639 | #ifdef SQLITE_DEBUG |
| 76640 | /* The seek operation that positioned the cursor prior to OP_Delete will |
| 76641 | ** have also set the pC->movetoTarget field to the rowid of the row that |
| 76642 | ** is being deleted */ |
| 76643 | if( pOp->p4.z && pC->isTable && pOp->p5==0 ){ |
| 76644 | i64 iKey = 0; |
| 76645 | sqlite3BtreeKeySize(pC->pCursor, &iKey); |
| 76646 | assert( pC->movetoTarget==iKey ); |
| 76647 | } |
| 76648 | #endif |
| 76649 | |
| 76650 | rc = sqlite3BtreeDelete(pC->pCursor, pOp->p5); |
| 76651 | pC->cacheStatus = CACHE_STALE; |
| 76652 | |
| 76653 | /* Invoke the update-hook if required. */ |
| 76654 | if( rc==SQLITE_OK && hasUpdateCallback ){ |
| 76655 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 76656 | db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); |
| 76657 | assert( pC->iDb>=0 ); |
| 76658 | } |
| 76659 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| @@ -77061,11 +77188,11 @@ | |
| 77188 | #ifdef SQLITE_DEBUG |
| 77189 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 77190 | #endif |
| 77191 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 77192 | if( rc==SQLITE_OK && res==0 ){ |
| 77193 | rc = sqlite3BtreeDelete(pCrsr, 0); |
| 77194 | } |
| 77195 | assert( pC->deferredMoveto==0 ); |
| 77196 | pC->cacheStatus = CACHE_STALE; |
| 77197 | break; |
| 77198 | } |
| @@ -83123,12 +83250,17 @@ | |
| 83250 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 83251 | |
| 83252 | /* |
| 83253 | ** Perhaps the name is a reference to the ROWID |
| 83254 | */ |
| 83255 | if( cnt==0 |
| 83256 | && cntTab==1 |
| 83257 | && pMatch |
| 83258 | && (pNC->ncFlags & NC_IdxExpr)==0 |
| 83259 | && sqlite3IsRowid(zCol) |
| 83260 | && VisibleRowid(pMatch->pTab) |
| 83261 | ){ |
| 83262 | cnt = 1; |
| 83263 | pExpr->iColumn = -1; /* IMP: R-44911-55124 */ |
| 83264 | pExpr->affinity = SQLITE_AFF_INTEGER; |
| 83265 | } |
| 83266 | |
| @@ -92416,11 +92548,11 @@ | |
| 92548 | }else{ |
| 92549 | sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); |
| 92550 | } |
| 92551 | pParse->checkSchema = 1; |
| 92552 | } |
| 92553 | #if SQLITE_USER_AUTHENTICATION |
| 92554 | else if( pParse->db->auth.authLevel<UAUTH_User ){ |
| 92555 | sqlite3ErrorMsg(pParse, "user not authenticated"); |
| 92556 | p = 0; |
| 92557 | } |
| 92558 | #endif |
| @@ -97188,11 +97320,11 @@ | |
| 97320 | AuthContext sContext; /* Authorization context */ |
| 97321 | NameContext sNC; /* Name context to resolve expressions in */ |
| 97322 | int iDb; /* Database number */ |
| 97323 | int memCnt = -1; /* Memory cell used for change counting */ |
| 97324 | int rcauth; /* Value returned by authorization callback */ |
| 97325 | int eOnePass; /* ONEPASS_OFF or _SINGLE or _MULTI */ |
| 97326 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 97327 | u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */ |
| 97328 | Index *pPk; /* The PRIMARY KEY index on the table */ |
| 97329 | int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */ |
| 97330 | i16 nPk = 1; /* Number of columns in the PRIMARY KEY */ |
| @@ -97200,16 +97332,16 @@ | |
| 97332 | i16 nKey; /* Number of memory cells in the row key */ |
| 97333 | int iEphCur = 0; /* Ephemeral table holding all primary key values */ |
| 97334 | int iRowSet = 0; /* Register for rowset of rows to delete */ |
| 97335 | int addrBypass = 0; /* Address of jump over the delete logic */ |
| 97336 | int addrLoop = 0; /* Top of the delete loop */ |
| 97337 | int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ |
| 97338 | |
| 97339 | #ifndef SQLITE_OMIT_TRIGGER |
| 97340 | int isView; /* True if attempting to delete from a view */ |
| 97341 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 97342 | int bComplex; /* True if there are either triggers or FKs */ |
| 97343 | #endif |
| 97344 | |
| 97345 | memset(&sContext, 0, sizeof(sContext)); |
| 97346 | db = pParse->db; |
| 97347 | if( pParse->nErr || db->mallocFailed ){ |
| @@ -97229,13 +97361,15 @@ | |
| 97361 | ** deleted from is a view |
| 97362 | */ |
| 97363 | #ifndef SQLITE_OMIT_TRIGGER |
| 97364 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 97365 | isView = pTab->pSelect!=0; |
| 97366 | bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| 97367 | #else |
| 97368 | # define pTrigger 0 |
| 97369 | # define isView 0 |
| 97370 | # define bComplex 0 |
| 97371 | #endif |
| 97372 | #ifdef SQLITE_OMIT_VIEW |
| 97373 | # undef isView |
| 97374 | # define isView 0 |
| 97375 | #endif |
| @@ -97312,12 +97446,14 @@ | |
| 97446 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 97447 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 97448 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 97449 | ** this optimization caused the row change count (the value returned by |
| 97450 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 97451 | if( rcauth==SQLITE_OK |
| 97452 | && pWhere==0 |
| 97453 | && !bComplex |
| 97454 | && !IsVirtual(pTab) |
| 97455 | ){ |
| 97456 | assert( !isView ); |
| 97457 | sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 97458 | if( HasRowid(pTab) ){ |
| 97459 | sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt, |
| @@ -97328,10 +97464,12 @@ | |
| 97464 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| 97465 | } |
| 97466 | }else |
| 97467 | #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ |
| 97468 | { |
| 97469 | u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK; |
| 97470 | wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW); |
| 97471 | if( HasRowid(pTab) ){ |
| 97472 | /* For a rowid table, initialize the RowSet to an empty set */ |
| 97473 | pPk = 0; |
| 97474 | nPk = 1; |
| 97475 | iRowSet = ++pParse->nMem; |
| @@ -97348,17 +97486,22 @@ | |
| 97486 | addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk); |
| 97487 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 97488 | } |
| 97489 | |
| 97490 | /* Construct a query to find the rowid or primary key for every row |
| 97491 | ** to be deleted, based on the WHERE clause. Set variable eOnePass |
| 97492 | ** to indicate the strategy used to implement this delete: |
| 97493 | ** |
| 97494 | ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values. |
| 97495 | ** ONEPASS_SINGLE: One-pass approach - at most one row deleted. |
| 97496 | ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted. |
| 97497 | */ |
| 97498 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1); |
| 97499 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 97500 | eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 97501 | assert( IsVirtual(pTab)==0 || eOnePass==ONEPASS_OFF ); |
| 97502 | assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF ); |
| 97503 | |
| 97504 | /* Keep track of the number of rows to be deleted */ |
| 97505 | if( db->flags & SQLITE_CountRows ){ |
| 97506 | sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1); |
| 97507 | } |
| @@ -97375,15 +97518,14 @@ | |
| 97518 | iKey = pParse->nMem + 1; |
| 97519 | iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0); |
| 97520 | if( iKey>pParse->nMem ) pParse->nMem = iKey; |
| 97521 | } |
| 97522 | |
| 97523 | if( eOnePass!=ONEPASS_OFF ){ |
| 97524 | /* For ONEPASS, no need to store the rowid/primary-key. There is only |
| 97525 | ** one, so just keep it in its register(s) and fall through to the |
| 97526 | ** delete code. */ |
| 97527 | nKey = nPk; /* OP_Found will use an unpacked key */ |
| 97528 | aToOpen = sqlite3DbMallocRaw(db, nIdx+2); |
| 97529 | if( aToOpen==0 ){ |
| 97530 | sqlite3WhereEnd(pWInfo); |
| 97531 | goto delete_from_cleanup; |
| @@ -97391,53 +97533,56 @@ | |
| 97533 | memset(aToOpen, 1, nIdx+1); |
| 97534 | aToOpen[nIdx+1] = 0; |
| 97535 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0; |
| 97536 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0; |
| 97537 | if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen); |
| 97538 | }else{ |
| 97539 | if( pPk ){ |
| 97540 | /* Add the PK key for this row to the temporary table */ |
| 97541 | iKey = ++pParse->nMem; |
| 97542 | nKey = 0; /* Zero tells OP_Found to use a composite key */ |
| 97543 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, |
| 97544 | sqlite3IndexAffinityStr(pParse->db, pPk), nPk); |
| 97545 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); |
| 97546 | }else{ |
| 97547 | /* Add the rowid of the row to be deleted to the RowSet */ |
| 97548 | nKey = 1; /* OP_Seek always uses a single rowid */ |
| 97549 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); |
| 97550 | } |
| 97551 | } |
| 97552 | |
| 97553 | /* If this DELETE cannot use the ONEPASS strategy, this is the |
| 97554 | ** end of the WHERE loop */ |
| 97555 | if( eOnePass!=ONEPASS_OFF ){ |
| 97556 | addrBypass = sqlite3VdbeMakeLabel(v); |
| 97557 | }else{ |
| 97558 | sqlite3WhereEnd(pWInfo); |
| 97559 | } |
| 97560 | |
| 97561 | /* Unless this is a view, open cursors for the table we are |
| 97562 | ** deleting from and all its indices. If this is a view, then the |
| 97563 | ** only effect this statement has is to fire the INSTEAD OF |
| 97564 | ** triggers. |
| 97565 | */ |
| 97566 | if( !isView ){ |
| 97567 | int iAddrOnce = 0; |
| 97568 | if( eOnePass==ONEPASS_MULTI ){ |
| 97569 | iAddrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v); |
| 97570 | } |
| 97571 | testcase( IsVirtual(pTab) ); |
| 97572 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen, |
| 97573 | &iDataCur, &iIdxCur); |
| 97574 | assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); |
| 97575 | assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); |
| 97576 | if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce); |
| 97577 | } |
| 97578 | |
| 97579 | /* Set up a loop over the rowids/primary-keys that were found in the |
| 97580 | ** where-clause loop above. |
| 97581 | */ |
| 97582 | if( eOnePass!=ONEPASS_OFF ){ |
| 97583 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 97584 | if( aToOpen[iDataCur-iTabCur] ){ |
| 97585 | assert( pPk!=0 || pTab->pSelect!=0 ); |
| 97586 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 97587 | VdbeCoverage(v); |
| 97588 | } |
| @@ -97461,17 +97606,22 @@ | |
| 97606 | sqlite3MayAbort(pParse); |
| 97607 | }else |
| 97608 | #endif |
| 97609 | { |
| 97610 | int count = (pParse->nested==0); /* True to count changes */ |
| 97611 | int iIdxNoSeek = -1; |
| 97612 | if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){ |
| 97613 | iIdxNoSeek = aiCurOnePass[1]; |
| 97614 | } |
| 97615 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 97616 | iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek); |
| 97617 | } |
| 97618 | |
| 97619 | /* End of the loop over all rowids/primary-keys. */ |
| 97620 | if( eOnePass!=ONEPASS_OFF ){ |
| 97621 | sqlite3VdbeResolveLabel(v, addrBypass); |
| 97622 | sqlite3WhereEnd(pWInfo); |
| 97623 | }else if( pPk ){ |
| 97624 | sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v); |
| 97625 | sqlite3VdbeJumpHere(v, addrLoop); |
| 97626 | }else{ |
| 97627 | sqlite3VdbeGoto(v, addrLoop); |
| @@ -97539,10 +97689,29 @@ | |
| 97689 | ** |
| 97690 | ** 3. The primary key for the row to be deleted must be stored in a |
| 97691 | ** sequence of nPk memory cells starting at iPk. If nPk==0 that means |
| 97692 | ** that a search record formed from OP_MakeRecord is contained in the |
| 97693 | ** single memory location iPk. |
| 97694 | ** |
| 97695 | ** eMode: |
| 97696 | ** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or |
| 97697 | ** ONEPASS_MULTI. If eMode is not ONEPASS_OFF, then the cursor |
| 97698 | ** iDataCur already points to the row to delete. If eMode is ONEPASS_OFF |
| 97699 | ** then this function must seek iDataCur to the entry identified by iPk |
| 97700 | ** and nPk before reading from it. |
| 97701 | ** |
| 97702 | ** If eMode is ONEPASS_MULTI, then this call is being made as part |
| 97703 | ** of a ONEPASS delete that affects multiple rows. In this case, if |
| 97704 | ** iIdxNoSeek is a valid cursor number (>=0), then its position should |
| 97705 | ** be preserved following the delete operation. Or, if iIdxNoSeek is not |
| 97706 | ** a valid cursor number, the position of iDataCur should be preserved |
| 97707 | ** instead. |
| 97708 | ** |
| 97709 | ** iIdxNoSeek: |
| 97710 | ** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an |
| 97711 | ** index cursor (from within array of cursors starting at iIdxCur) that |
| 97712 | ** already points to the index entry to be deleted. |
| 97713 | */ |
| 97714 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 97715 | Parse *pParse, /* Parsing context */ |
| 97716 | Table *pTab, /* Table containing the row to be deleted */ |
| 97717 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -97550,11 +97719,12 @@ | |
| 97719 | int iIdxCur, /* First index cursor */ |
| 97720 | int iPk, /* First memory cell containing the PRIMARY KEY */ |
| 97721 | i16 nPk, /* Number of PRIMARY KEY memory cells */ |
| 97722 | u8 count, /* If non-zero, increment the row change counter */ |
| 97723 | u8 onconf, /* Default ON CONFLICT policy for triggers */ |
| 97724 | u8 eMode, /* ONEPASS_OFF, _SINGLE, or _MULTI. See above */ |
| 97725 | int iIdxNoSeek /* Cursor number of cursor that does not need seeking */ |
| 97726 | ){ |
| 97727 | Vdbe *v = pParse->pVdbe; /* Vdbe */ |
| 97728 | int iOld = 0; /* First register in OLD.* array */ |
| 97729 | int iLabel; /* Label resolved to end of generated code */ |
| 97730 | u8 opSeek; /* Seek opcode */ |
| @@ -97567,11 +97737,11 @@ | |
| 97737 | /* Seek cursor iCur to the row to delete. If this row no longer exists |
| 97738 | ** (this can happen if a trigger program has already deleted it), do |
| 97739 | ** not attempt to delete it or fire any DELETE triggers. */ |
| 97740 | iLabel = sqlite3VdbeMakeLabel(v); |
| 97741 | opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound; |
| 97742 | if( eMode==ONEPASS_OFF ){ |
| 97743 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 97744 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 97745 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 97746 | } |
| 97747 | |
| @@ -97627,15 +97797,19 @@ | |
| 97797 | |
| 97798 | /* Delete the index and table entries. Skip this step if pTab is really |
| 97799 | ** a view (in which case the only effect of the DELETE statement is to |
| 97800 | ** fire the INSTEAD OF triggers). */ |
| 97801 | if( pTab->pSelect==0 ){ |
| 97802 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 97803 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 97804 | if( count ){ |
| 97805 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); |
| 97806 | } |
| 97807 | if( iIdxNoSeek>=0 ){ |
| 97808 | sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); |
| 97809 | } |
| 97810 | sqlite3VdbeChangeP5(v, eMode==ONEPASS_MULTI); |
| 97811 | } |
| 97812 | |
| 97813 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 97814 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 97815 | ** to the row just deleted. */ |
| @@ -97674,11 +97848,12 @@ | |
| 97848 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete( |
| 97849 | Parse *pParse, /* Parsing and code generating context */ |
| 97850 | Table *pTab, /* Table containing the row to be deleted */ |
| 97851 | int iDataCur, /* Cursor of table holding data. */ |
| 97852 | int iIdxCur, /* First index cursor */ |
| 97853 | int *aRegIdx, /* Only delete if aRegIdx!=0 && aRegIdx[i]>0 */ |
| 97854 | int iIdxNoSeek /* Do not delete from this cursor */ |
| 97855 | ){ |
| 97856 | int i; /* Index loop counter */ |
| 97857 | int r1 = -1; /* Register holding an index key */ |
| 97858 | int iPartIdxLabel; /* Jump destination for skipping partial index entries */ |
| 97859 | Index *pIdx; /* Current index */ |
| @@ -97690,15 +97865,16 @@ | |
| 97865 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 97866 | for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ |
| 97867 | assert( iIdxCur+i!=iDataCur || pPk==pIdx ); |
| 97868 | if( aRegIdx!=0 && aRegIdx[i]==0 ) continue; |
| 97869 | if( pIdx==pPk ) continue; |
| 97870 | if( iIdxCur+i==iIdxNoSeek ) continue; |
| 97871 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 97872 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 97873 | &iPartIdxLabel, pPrior, r1); |
| 97874 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 97875 | pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); |
| 97876 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 97877 | pPrior = pIdx; |
| 97878 | } |
| 97879 | } |
| 97880 | |
| @@ -102350,14 +102526,17 @@ | |
| 102526 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102527 | } |
| 102528 | if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){ |
| 102529 | sqlite3MultiWrite(pParse); |
| 102530 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102531 | regNewData, 1, 0, OE_Replace, |
| 102532 | ONEPASS_SINGLE, -1); |
| 102533 | }else{ |
| 102534 | if( pTab->pIndex ){ |
| 102535 | sqlite3MultiWrite(pParse); |
| 102536 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1); |
| 102537 | } |
| 102538 | } |
| 102539 | seenReplace = 1; |
| 102540 | break; |
| 102541 | } |
| 102542 | case OE_Ignore: { |
| @@ -102531,11 +102710,12 @@ | |
| 102710 | sqlite3MultiWrite(pParse); |
| 102711 | if( db->flags&SQLITE_RecTriggers ){ |
| 102712 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 102713 | } |
| 102714 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 102715 | regR, nPkField, 0, OE_Replace, |
| 102716 | (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1); |
| 102717 | seenReplace = 1; |
| 102718 | break; |
| 102719 | } |
| 102720 | } |
| 102721 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -112115,13 +112295,16 @@ | |
| 112295 | return WRC_Abort; |
| 112296 | } |
| 112297 | pTab->nRef++; |
| 112298 | #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) |
| 112299 | if( pTab->pSelect || IsVirtual(pTab) ){ |
| 112300 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 112301 | assert( pFrom->pSelect==0 ); |
| 112302 | if( pFrom->fg.isTabFunc && !IsVirtual(pTab) ){ |
| 112303 | sqlite3ErrorMsg(pParse, "'%s' is not a function", pTab->zName); |
| 112304 | return WRC_Abort; |
| 112305 | } |
| 112306 | pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 112307 | sqlite3SelectSetName(pFrom->pSelect, pTab->zName); |
| 112308 | sqlite3WalkSelect(pWalker, pFrom->pSelect); |
| 112309 | } |
| 112310 | #endif |
| @@ -115381,11 +115564,11 @@ | |
| 115564 | }else{ |
| 115565 | j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid); |
| 115566 | } |
| 115567 | VdbeCoverageNeverTaken(v); |
| 115568 | } |
| 115569 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1); |
| 115570 | |
| 115571 | /* If changing the record number, delete the old record. */ |
| 115572 | if( hasFK || chngKey || pPk!=0 ){ |
| 115573 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 115574 | } |
| @@ -117596,11 +117779,11 @@ | |
| 117779 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 117780 | LogEst nRowOut; /* Estimated number of output rows */ |
| 117781 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 117782 | i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ |
| 117783 | u8 sorted; /* True if really sorted (not just grouped) */ |
| 117784 | u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */ |
| 117785 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 117786 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ |
| 117787 | u8 nLevel; /* Number of nested loop */ |
| 117788 | int iTop; /* The very beginning of the WHERE loop */ |
| 117789 | int iContinue; /* Jump here to continue with next record */ |
| @@ -117763,11 +117946,11 @@ | |
| 117946 | ** is run and there is an index on (a, b), then this function returns a |
| 117947 | ** string similar to: |
| 117948 | ** |
| 117949 | ** "a=? AND b>?" |
| 117950 | */ |
| 117951 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){ |
| 117952 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117953 | u16 nEq = pLoop->u.btree.nEq; |
| 117954 | u16 nSkip = pLoop->nSkip; |
| 117955 | int i, j; |
| 117956 | |
| @@ -117864,11 +118047,11 @@ | |
| 118047 | zFmt = "INDEX %s"; |
| 118048 | } |
| 118049 | if( zFmt ){ |
| 118050 | sqlite3StrAccumAppend(&str, " USING ", 7); |
| 118051 | sqlite3XPrintf(&str, 0, zFmt, pIdx->zName); |
| 118052 | explainIndexRange(&str, pLoop); |
| 118053 | } |
| 118054 | }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ |
| 118055 | const char *zRangeOp; |
| 118056 | if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ |
| 118057 | zRangeOp = "="; |
| @@ -118212,12 +118395,12 @@ | |
| 118395 | VdbeCoverageIf(v, bRev==0); |
| 118396 | VdbeCoverageIf(v, bRev!=0); |
| 118397 | sqlite3VdbeJumpHere(v, j); |
| 118398 | for(j=0; j<nSkip; j++){ |
| 118399 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j); |
| 118400 | testcase( pIdx->aiColumn[j]==(-2) ); |
| 118401 | VdbeComment((v, "%s", explainIndexColumnName(pIdx, j))); |
| 118402 | } |
| 118403 | } |
| 118404 | |
| 118405 | /* Evaluate the equality constraints |
| 118406 | */ |
| @@ -118767,11 +118950,16 @@ | |
| 118950 | /* pIdx is a covering index. No need to access the main table. */ |
| 118951 | }else if( HasRowid(pIdx->pTable) ){ |
| 118952 | iRowidReg = ++pParse->nMem; |
| 118953 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 118954 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 118955 | if( pWInfo->eOnePass!=ONEPASS_OFF ){ |
| 118956 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); |
| 118957 | VdbeCoverage(v); |
| 118958 | }else{ |
| 118959 | sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ |
| 118960 | } |
| 118961 | }else if( iCur!=iIdxCur ){ |
| 118962 | Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 118963 | iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 118964 | for(j=0; j<pPk->nKeyCol; j++){ |
| 118965 | k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); |
| @@ -120618,13 +120806,15 @@ | |
| 120806 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo *pWInfo){ |
| 120807 | return pWInfo->iBreak; |
| 120808 | } |
| 120809 | |
| 120810 | /* |
| 120811 | ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to |
| 120812 | ** operate directly on the rowis returned by a WHERE clause. Return |
| 120813 | ** ONEPASS_SINGLE (1) if the statement can operation directly because only |
| 120814 | ** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass |
| 120815 | ** optimization can be used on multiple |
| 120816 | ** |
| 120817 | ** If the ONEPASS optimization is used (if this routine returns true) |
| 120818 | ** then also write the indices of open cursors used by ONEPASS |
| 120819 | ** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data |
| 120820 | ** table and iaCur[1] gets the cursor used by an auxiliary index. |
| @@ -120634,11 +120824,11 @@ | |
| 120824 | ** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is |
| 120825 | ** unable to use the ONEPASS optimization. |
| 120826 | */ |
| 120827 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){ |
| 120828 | memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2); |
| 120829 | return pWInfo->eOnePass; |
| 120830 | } |
| 120831 | |
| 120832 | /* |
| 120833 | ** Move the content of pSrc into pDest |
| 120834 | */ |
| @@ -120729,25 +120919,24 @@ | |
| 120919 | int k = pScan->k; /* Where to start scanning */ |
| 120920 | |
| 120921 | while( pScan->iEquiv<=pScan->nEquiv ){ |
| 120922 | iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 120923 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 120924 | if( iColumn==(-2) && pScan->pIdxExpr==0 ) return 0; |
| 120925 | while( (pWC = pScan->pWC)!=0 ){ |
| 120926 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 120927 | if( pTerm->leftCursor==iCur |
| 120928 | && pTerm->u.leftColumn==iColumn |
| 120929 | && (iColumn!=(-2) |
| 120930 | || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) |
| 120931 | && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) |
| 120932 | ){ |
| 120933 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 120934 | && pScan->nEquiv<ArraySize(pScan->aiCur) |
| 120935 | && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN |
| 120936 | ){ |
| 120937 | int j; |
| 120938 | for(j=0; j<pScan->nEquiv; j++){ |
| 120939 | if( pScan->aiCur[j]==pX->iTable |
| 120940 | && pScan->aiColumn[j]==pX->iColumn ){ |
| 120941 | break; |
| 120942 | } |
| @@ -122969,21 +123158,28 @@ | |
| 123158 | WhereLoopBuilder *pBuilder, |
| 123159 | Index *pIndex, |
| 123160 | int iCursor |
| 123161 | ){ |
| 123162 | ExprList *pOB; |
| 123163 | ExprList *aColExpr; |
| 123164 | int ii, jj; |
| 123165 | |
| 123166 | if( pIndex->bUnordered ) return 0; |
| 123167 | if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0; |
| 123168 | for(ii=0; ii<pOB->nExpr; ii++){ |
| 123169 | Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr); |
| 123170 | if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){ |
| 123171 | if( pExpr->iColumn<0 ) return 1; |
| 123172 | for(jj=0; jj<pIndex->nKeyCol; jj++){ |
| 123173 | if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1; |
| 123174 | } |
| 123175 | }else if( (aColExpr = pIndex->aColExpr)!=0 ){ |
| 123176 | for(jj=0; jj<pIndex->nKeyCol; jj++){ |
| 123177 | if( pIndex->aiColumn[jj]!=(-2) ) continue; |
| 123178 | if( sqlite3ExprCompare(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){ |
| 123179 | return 1; |
| 123180 | } |
| 123181 | } |
| 123182 | } |
| 123183 | } |
| 123184 | return 0; |
| 123185 | } |
| @@ -123128,11 +123324,11 @@ | |
| 123324 | if( !pBuilder->pOrSet /* Not part of an OR optimization */ |
| 123325 | && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0 |
| 123326 | && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0 |
| 123327 | && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */ |
| 123328 | && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */ |
| 123329 | && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */ |
| 123330 | && !pSrc->fg.isCorrelated /* Not a correlated subquery */ |
| 123331 | && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ |
| 123332 | ){ |
| 123333 | /* Generate auto-index WhereLoops */ |
| 123334 | WhereTerm *pTerm; |
| @@ -123812,13 +124008,19 @@ | |
| 124008 | if( MASKBIT(i) & obSat ) continue; |
| 124009 | pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr); |
| 124010 | testcase( wctrlFlags & WHERE_GROUPBY ); |
| 124011 | testcase( wctrlFlags & WHERE_DISTINCTBY ); |
| 124012 | if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0; |
| 124013 | if( iColumn>=(-1) ){ |
| 124014 | if( pOBExpr->op!=TK_COLUMN ) continue; |
| 124015 | if( pOBExpr->iTable!=iCur ) continue; |
| 124016 | if( pOBExpr->iColumn!=iColumn ) continue; |
| 124017 | }else{ |
| 124018 | if( sqlite3ExprCompare(pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){ |
| 124019 | continue; |
| 124020 | } |
| 124021 | } |
| 124022 | if( iColumn>=0 ){ |
| 124023 | pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr); |
| 124024 | if( !pColl ) pColl = db->pDfltColl; |
| 124025 | if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue; |
| 124026 | } |
| @@ -124507,10 +124709,14 @@ | |
| 124709 | WhereLoop *pLoop; /* Pointer to a single WhereLoop object */ |
| 124710 | int ii; /* Loop counter */ |
| 124711 | sqlite3 *db; /* Database connection */ |
| 124712 | int rc; /* Return code */ |
| 124713 | |
| 124714 | assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || ( |
| 124715 | (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 |
| 124716 | && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 |
| 124717 | )); |
| 124718 | |
| 124719 | /* Variable initialization */ |
| 124720 | db = pParse->db; |
| 124721 | memset(&sWLB, 0, sizeof(sWLB)); |
| 124722 | |
| @@ -124562,10 +124768,11 @@ | |
| 124768 | pWInfo->pOrderBy = pOrderBy; |
| 124769 | pWInfo->pResultSet = pResultSet; |
| 124770 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 124771 | pWInfo->wctrlFlags = wctrlFlags; |
| 124772 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 124773 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| 124774 | pMaskSet = &pWInfo->sMaskSet; |
| 124775 | sWLB.pWInfo = pWInfo; |
| 124776 | sWLB.pWC = &pWInfo->sWC; |
| 124777 | sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); |
| 124778 | assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) ); |
| @@ -124748,15 +124955,20 @@ | |
| 124955 | ** to use a one-pass algorithm, determine if this is appropriate. |
| 124956 | ** The one-pass algorithm only works if the WHERE clause constrains |
| 124957 | ** the statement to update or delete a single row. |
| 124958 | */ |
| 124959 | assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); |
| 124960 | if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){ |
| 124961 | int wsFlags = pWInfo->a[0].pWLoop->wsFlags; |
| 124962 | int bOnerow = (wsFlags & WHERE_ONEROW)!=0; |
| 124963 | if( bOnerow || ( (wctrlFlags & WHERE_ONEPASS_MULTIROW) |
| 124964 | && 0==(wsFlags & WHERE_VIRTUALTABLE) |
| 124965 | )){ |
| 124966 | pWInfo->eOnePass = bOnerow ? ONEPASS_SINGLE : ONEPASS_MULTI; |
| 124967 | if( HasRowid(pTabList->a[0].pTab) ){ |
| 124968 | pWInfo->a[0].pWLoop->wsFlags &= ~WHERE_IDX_ONLY; |
| 124969 | } |
| 124970 | } |
| 124971 | } |
| 124972 | |
| 124973 | /* Open all tables in the pTabList and any indices selected for |
| 124974 | ** searching those tables. |
| @@ -124783,19 +124995,19 @@ | |
| 124995 | }else |
| 124996 | #endif |
| 124997 | if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 124998 | && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){ |
| 124999 | int op = OP_OpenRead; |
| 125000 | if( pWInfo->eOnePass!=ONEPASS_OFF ){ |
| 125001 | op = OP_OpenWrite; |
| 125002 | pWInfo->aiCurOnePass[0] = pTabItem->iCursor; |
| 125003 | }; |
| 125004 | sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op); |
| 125005 | assert( pTabItem->iCursor==pLevel->iTabCur ); |
| 125006 | testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 ); |
| 125007 | testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS ); |
| 125008 | if( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol<BMS && HasRowid(pTab) ){ |
| 125009 | Bitmask b = pTabItem->colUsed; |
| 125010 | int n = 0; |
| 125011 | for(; b; b=b>>1, n++){} |
| 125012 | sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1, |
| 125013 | SQLITE_INT_TO_PTR(n), P4_INT32); |
| @@ -124819,11 +125031,11 @@ | |
| 125031 | ){ |
| 125032 | /* This is one term of an OR-optimization using the PRIMARY KEY of a |
| 125033 | ** WITHOUT ROWID table. No need for a separate index */ |
| 125034 | iIndexCur = pLevel->iTabCur; |
| 125035 | op = 0; |
| 125036 | }else if( pWInfo->eOnePass!=ONEPASS_OFF ){ |
| 125037 | Index *pJ = pTabItem->pTab->pIndex; |
| 125038 | iIndexCur = iIdxCur; |
| 125039 | assert( wctrlFlags & WHERE_ONEPASS_DESIRED ); |
| 125040 | while( ALWAYS(pJ) && pJ!=pIx ){ |
| 125041 | iIndexCur++; |
| @@ -125027,11 +125239,11 @@ | |
| 125239 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 125240 | && pTab->pSelect==0 |
| 125241 | && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 |
| 125242 | ){ |
| 125243 | int ws = pLoop->wsFlags; |
| 125244 | if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){ |
| 125245 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| 125246 | } |
| 125247 | if( (ws & WHERE_INDEXED)!=0 |
| 125248 | && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 |
| 125249 | && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1] |
| 125250 |
+12
-7
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -111,11 +111,11 @@ | ||
| 111 | 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | 113 | */ |
| 114 | 114 | #define SQLITE_VERSION "3.8.12" |
| 115 | 115 | #define SQLITE_VERSION_NUMBER 3008012 |
| 116 | -#define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a" | |
| 116 | +#define SQLITE_SOURCE_ID "2015-09-24 18:47:59 668fc1ebaf426f9eed3ed7865e41f1023dafebfb" | |
| 117 | 117 | |
| 118 | 118 | /* |
| 119 | 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | 121 | ** |
| @@ -122,11 +122,11 @@ | ||
| 122 | 122 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 123 | 123 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 124 | 124 | ** but are associated with the library instead of the header file. ^(Cautious |
| 125 | 125 | ** programmers might include assert() statements in their application to |
| 126 | 126 | ** verify that values returned by these interfaces match the macros in |
| 127 | -** the header, and thus insure that the application is | |
| 127 | +** the header, and thus ensure that the application is | |
| 128 | 128 | ** compiled with matching library and header files. |
| 129 | 129 | ** |
| 130 | 130 | ** <blockquote><pre> |
| 131 | 131 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 132 | 132 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -372,11 +372,11 @@ | ||
| 372 | 372 | ** is not changed. |
| 373 | 373 | ** |
| 374 | 374 | ** Restrictions: |
| 375 | 375 | ** |
| 376 | 376 | ** <ul> |
| 377 | -** <li> The application must insure that the 1st parameter to sqlite3_exec() | |
| 377 | +** <li> The application must ensure that the 1st parameter to sqlite3_exec() | |
| 378 | 378 | ** is a valid and open [database connection]. |
| 379 | 379 | ** <li> The application must not close the [database connection] specified by |
| 380 | 380 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 381 | 381 | ** <li> The application must not modify the SQL statement text passed into |
| 382 | 382 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1365,13 +1365,15 @@ | ||
| 1365 | 1365 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1366 | 1366 | ** the application. The default configuration is recommended for most |
| 1367 | 1367 | ** applications and so this routine is usually not necessary. It is |
| 1368 | 1368 | ** provided to support rare applications with unusual needs. |
| 1369 | 1369 | ** |
| 1370 | -** The sqlite3_config() interface is not threadsafe. The application | |
| 1371 | -** must insure that no other SQLite interfaces are invoked by other | |
| 1372 | -** threads while sqlite3_config() is running. Furthermore, sqlite3_config() | |
| 1370 | +** <b>The sqlite3_config() interface is not threadsafe. The application | |
| 1371 | +** must ensure that no other SQLite interfaces are invoked by other | |
| 1372 | +** threads while sqlite3_config() is running.</b> | |
| 1373 | +** | |
| 1374 | +** The sqlite3_config() interface | |
| 1373 | 1375 | ** may only be invoked prior to library initialization using |
| 1374 | 1376 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1375 | 1377 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1376 | 1378 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1377 | 1379 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3626,11 +3628,11 @@ | ||
| 3626 | 3628 | ** name must be given in UTF-8 even if the original statement |
| 3627 | 3629 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3628 | 3630 | ** |
| 3629 | 3631 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3630 | 3632 | ** [sqlite3_bind_parameter_count()], and |
| 3631 | -** [sqlite3_bind_parameter_index()]. | |
| 3633 | +** [sqlite3_bind_parameter_name()]. | |
| 3632 | 3634 | */ |
| 3633 | 3635 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3634 | 3636 | |
| 3635 | 3637 | /* |
| 3636 | 3638 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6123,10 +6125,13 @@ | ||
| 6123 | 6125 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6124 | 6126 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6125 | 6127 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6126 | 6128 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6127 | 6129 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6130 | +** <li> SQLITE_MUTEX_STATIC_VFS1 | |
| 6131 | +** <li> SQLITE_MUTEX_STATIC_VFS2 | |
| 6132 | +** <li> SQLITE_MUTEX_STATIC_VFS3 | |
| 6128 | 6133 | ** </ul> |
| 6129 | 6134 | ** |
| 6130 | 6135 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6131 | 6136 | ** cause sqlite3_mutex_alloc() to create |
| 6132 | 6137 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 6133 | 6138 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -111,11 +111,11 @@ | |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.8.12" |
| 115 | #define SQLITE_VERSION_NUMBER 3008012 |
| 116 | #define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| @@ -122,11 +122,11 @@ | |
| 122 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 123 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 124 | ** but are associated with the library instead of the header file. ^(Cautious |
| 125 | ** programmers might include assert() statements in their application to |
| 126 | ** verify that values returned by these interfaces match the macros in |
| 127 | ** the header, and thus insure that the application is |
| 128 | ** compiled with matching library and header files. |
| 129 | ** |
| 130 | ** <blockquote><pre> |
| 131 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 132 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -372,11 +372,11 @@ | |
| 372 | ** is not changed. |
| 373 | ** |
| 374 | ** Restrictions: |
| 375 | ** |
| 376 | ** <ul> |
| 377 | ** <li> The application must insure that the 1st parameter to sqlite3_exec() |
| 378 | ** is a valid and open [database connection]. |
| 379 | ** <li> The application must not close the [database connection] specified by |
| 380 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 381 | ** <li> The application must not modify the SQL statement text passed into |
| 382 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1365,13 +1365,15 @@ | |
| 1365 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1366 | ** the application. The default configuration is recommended for most |
| 1367 | ** applications and so this routine is usually not necessary. It is |
| 1368 | ** provided to support rare applications with unusual needs. |
| 1369 | ** |
| 1370 | ** The sqlite3_config() interface is not threadsafe. The application |
| 1371 | ** must insure that no other SQLite interfaces are invoked by other |
| 1372 | ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() |
| 1373 | ** may only be invoked prior to library initialization using |
| 1374 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1375 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1376 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1377 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3626,11 +3628,11 @@ | |
| 3626 | ** name must be given in UTF-8 even if the original statement |
| 3627 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3628 | ** |
| 3629 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3630 | ** [sqlite3_bind_parameter_count()], and |
| 3631 | ** [sqlite3_bind_parameter_index()]. |
| 3632 | */ |
| 3633 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3634 | |
| 3635 | /* |
| 3636 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6123,10 +6125,13 @@ | |
| 6123 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6124 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6125 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6126 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6127 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6128 | ** </ul> |
| 6129 | ** |
| 6130 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6131 | ** cause sqlite3_mutex_alloc() to create |
| 6132 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 6133 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -111,11 +111,11 @@ | |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.8.12" |
| 115 | #define SQLITE_VERSION_NUMBER 3008012 |
| 116 | #define SQLITE_SOURCE_ID "2015-09-24 18:47:59 668fc1ebaf426f9eed3ed7865e41f1023dafebfb" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| @@ -122,11 +122,11 @@ | |
| 122 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 123 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 124 | ** but are associated with the library instead of the header file. ^(Cautious |
| 125 | ** programmers might include assert() statements in their application to |
| 126 | ** verify that values returned by these interfaces match the macros in |
| 127 | ** the header, and thus ensure that the application is |
| 128 | ** compiled with matching library and header files. |
| 129 | ** |
| 130 | ** <blockquote><pre> |
| 131 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 132 | ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| @@ -372,11 +372,11 @@ | |
| 372 | ** is not changed. |
| 373 | ** |
| 374 | ** Restrictions: |
| 375 | ** |
| 376 | ** <ul> |
| 377 | ** <li> The application must ensure that the 1st parameter to sqlite3_exec() |
| 378 | ** is a valid and open [database connection]. |
| 379 | ** <li> The application must not close the [database connection] specified by |
| 380 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 381 | ** <li> The application must not modify the SQL statement text passed into |
| 382 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| @@ -1365,13 +1365,15 @@ | |
| 1365 | ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1366 | ** the application. The default configuration is recommended for most |
| 1367 | ** applications and so this routine is usually not necessary. It is |
| 1368 | ** provided to support rare applications with unusual needs. |
| 1369 | ** |
| 1370 | ** <b>The sqlite3_config() interface is not threadsafe. The application |
| 1371 | ** must ensure that no other SQLite interfaces are invoked by other |
| 1372 | ** threads while sqlite3_config() is running.</b> |
| 1373 | ** |
| 1374 | ** The sqlite3_config() interface |
| 1375 | ** may only be invoked prior to library initialization using |
| 1376 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1377 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1378 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1379 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| @@ -3626,11 +3628,11 @@ | |
| 3628 | ** name must be given in UTF-8 even if the original statement |
| 3629 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 3630 | ** |
| 3631 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 3632 | ** [sqlite3_bind_parameter_count()], and |
| 3633 | ** [sqlite3_bind_parameter_name()]. |
| 3634 | */ |
| 3635 | SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 3636 | |
| 3637 | /* |
| 3638 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| @@ -6123,10 +6125,13 @@ | |
| 6125 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6126 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6127 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6128 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6129 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6130 | ** <li> SQLITE_MUTEX_STATIC_VFS1 |
| 6131 | ** <li> SQLITE_MUTEX_STATIC_VFS2 |
| 6132 | ** <li> SQLITE_MUTEX_STATIC_VFS3 |
| 6133 | ** </ul> |
| 6134 | ** |
| 6135 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6136 | ** cause sqlite3_mutex_alloc() to create |
| 6137 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 6138 |