Fossil SCM

Update the built-in SQLite to the 3.8.12 alpha that includes the ShmBarrier fix.

drh 2015-09-25 00:02 trunk
Commit 96e698d23c3929e51013e378d9b3542179e38560
2 files changed +371 -159 +12 -7
+371 -159
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328328
#define SQLITE_VERSION "3.8.12"
329329
#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"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -336,11 +336,11 @@
336336
** These interfaces provide the same information as the [SQLITE_VERSION],
337337
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
338338
** but are associated with the library instead of the header file. ^(Cautious
339339
** programmers might include assert() statements in their application to
340340
** 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
342342
** compiled with matching library and header files.
343343
**
344344
** <blockquote><pre>
345345
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
346346
** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
@@ -586,11 +586,11 @@
586586
** is not changed.
587587
**
588588
** Restrictions:
589589
**
590590
** <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()
592592
** is a valid and open [database connection].
593593
** <li> The application must not close the [database connection] specified by
594594
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
595595
** <li> The application must not modify the SQL statement text passed into
596596
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
@@ -1579,13 +1579,15 @@
15791579
** changes to SQLite in order to tune SQLite to the specific needs of
15801580
** the application. The default configuration is recommended for most
15811581
** applications and so this routine is usually not necessary. It is
15821582
** provided to support rare applications with unusual needs.
15831583
**
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
15871589
** may only be invoked prior to library initialization using
15881590
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
15891591
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
15901592
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
15911593
** Note, however, that ^sqlite3_config() can be called as part of the
@@ -3840,11 +3842,11 @@
38403842
** name must be given in UTF-8 even if the original statement
38413843
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
38423844
**
38433845
** See also: [sqlite3_bind_blob|sqlite3_bind()],
38443846
** [sqlite3_bind_parameter_count()], and
3845
-** [sqlite3_bind_parameter_index()].
3847
+** [sqlite3_bind_parameter_name()].
38463848
*/
38473849
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
38483850
38493851
/*
38503852
** CAPI3REF: Reset All Bindings On A Prepared Statement
@@ -6337,10 +6339,13 @@
63376339
** <li> SQLITE_MUTEX_STATIC_LRU
63386340
** <li> SQLITE_MUTEX_STATIC_PMEM
63396341
** <li> SQLITE_MUTEX_STATIC_APP1
63406342
** <li> SQLITE_MUTEX_STATIC_APP2
63416343
** <li> SQLITE_MUTEX_STATIC_APP3
6344
+** <li> SQLITE_MUTEX_STATIC_VFS1
6345
+** <li> SQLITE_MUTEX_STATIC_VFS2
6346
+** <li> SQLITE_MUTEX_STATIC_VFS3
63426347
** </ul>
63436348
**
63446349
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
63456350
** cause sqlite3_mutex_alloc() to create
63466351
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -9623,11 +9628,11 @@
96239628
int bias,
96249629
int *pRes
96259630
);
96269631
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*);
96279632
SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
9628
-SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*);
9633
+SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, int);
96299634
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
96309635
const void *pData, int nData,
96319636
int nZero, int bias, int seekResult);
96329637
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
96339638
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
@@ -10339,10 +10344,13 @@
1033910344
SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
1034010345
1034110346
/* Functions used to configure a Pager object. */
1034210347
SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
1034310348
SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
10349
+#ifdef SQLITE_HAS_CODEC
10350
+SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*);
10351
+#endif
1034410352
SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
1034510353
SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
1034610354
SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
1034710355
SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
1034810356
SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned);
@@ -12341,10 +12349,11 @@
1234112349
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1234212350
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
1234312351
#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1234412352
#define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
1234512353
#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
12354
+#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
1234612355
1234712356
/* Allowed return values from sqlite3WhereIsDistinct()
1234812357
*/
1234912358
#define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
1235012359
#define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13184,11 +13193,11 @@
1318413193
SQLITE_PRIVATE int sqlite3MutexEnd(void);
1318513194
#endif
1318613195
#if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP)
1318713196
SQLITE_PRIVATE void sqlite3MemoryBarrier(void);
1318813197
#else
13189
-# define sqlite3MemoryBarrier();
13198
+# define sqlite3MemoryBarrier()
1319013199
#endif
1319113200
1319213201
SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
1319313202
SQLITE_PRIVATE void sqlite3StatusUp(int, int);
1319413203
SQLITE_PRIVATE void sqlite3StatusDown(int, int);
@@ -13369,10 +13378,13 @@
1336913378
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
1337013379
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
1337113380
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
1337213381
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
1337313382
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 */
1337413386
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
1337513387
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1337613388
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1337713389
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1337813390
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
@@ -13429,12 +13441,13 @@
1342913441
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
1343013442
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1343113443
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
1343213444
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1343313445
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);
1343613449
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
1343713450
SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
1343813451
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
1343913452
u8,u8,int,int*);
1344013453
SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
@@ -19319,11 +19332,11 @@
1931919332
** For debugging purposes, record when the mutex subsystem is initialized
1932019333
** and uninitialized so that we can assert() if there is an attempt to
1932119334
** allocate a mutex while the system is uninitialized.
1932219335
*/
1932319336
static SQLITE_WSD int mutexIsInit = 0;
19324
-#endif /* SQLITE_DEBUG */
19337
+#endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
1932519338
1932619339
1932719340
#ifndef SQLITE_MUTEX_OMIT
1932819341
/*
1932919342
** Initialize the mutex system.
@@ -19353,10 +19366,11 @@
1935319366
pTo->xMutexHeld = pFrom->xMutexHeld;
1935419367
pTo->xMutexNotheld = pFrom->xMutexNotheld;
1935519368
sqlite3MemoryBarrier();
1935619369
pTo->xMutexAlloc = pFrom->xMutexAlloc;
1935719370
}
19371
+ assert( sqlite3GlobalConfig.mutex.xMutexInit );
1935819372
rc = sqlite3GlobalConfig.mutex.xMutexInit();
1935919373
1936019374
#ifdef SQLITE_DEBUG
1936119375
GLOBAL(int, mutexIsInit) = 1;
1936219376
#endif
@@ -19387,26 +19401,29 @@
1938719401
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){
1938819402
#ifndef SQLITE_OMIT_AUTOINIT
1938919403
if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
1939019404
if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
1939119405
#endif
19406
+ assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
1939219407
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
1939319408
}
1939419409
1939519410
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
1939619411
if( !sqlite3GlobalConfig.bCoreMutex ){
1939719412
return 0;
1939819413
}
1939919414
assert( GLOBAL(int, mutexIsInit) );
19415
+ assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
1940019416
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
1940119417
}
1940219418
1940319419
/*
1940419420
** Free a dynamic mutex.
1940519421
*/
1940619422
SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){
1940719423
if( p ){
19424
+ assert( sqlite3GlobalConfig.mutex.xMutexFree );
1940819425
sqlite3GlobalConfig.mutex.xMutexFree(p);
1940919426
}
1941019427
}
1941119428
1941219429
/*
@@ -19413,10 +19430,11 @@
1941319430
** Obtain the mutex p. If some other thread already has the mutex, block
1941419431
** until it can be obtained.
1941519432
*/
1941619433
SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){
1941719434
if( p ){
19435
+ assert( sqlite3GlobalConfig.mutex.xMutexEnter );
1941819436
sqlite3GlobalConfig.mutex.xMutexEnter(p);
1941919437
}
1942019438
}
1942119439
1942219440
/*
@@ -19424,10 +19442,11 @@
1942419442
** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
1942519443
*/
1942619444
SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){
1942719445
int rc = SQLITE_OK;
1942819446
if( p ){
19447
+ assert( sqlite3GlobalConfig.mutex.xMutexTry );
1942919448
return sqlite3GlobalConfig.mutex.xMutexTry(p);
1943019449
}
1943119450
return rc;
1943219451
}
1943319452
@@ -19437,10 +19456,11 @@
1943719456
** is not currently entered. If a NULL pointer is passed as an argument
1943819457
** this function is a no-op.
1943919458
*/
1944019459
SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){
1944119460
if( p ){
19461
+ assert( sqlite3GlobalConfig.mutex.xMutexLeave );
1944219462
sqlite3GlobalConfig.mutex.xMutexLeave(p);
1944319463
}
1944419464
}
1944519465
1944619466
#ifndef NDEBUG
@@ -19447,13 +19467,15 @@
1944719467
/*
1944819468
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
1944919469
** intended for use inside assert() statements.
1945019470
*/
1945119471
SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){
19472
+ assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
1945219473
return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
1945319474
}
1945419475
SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){
19476
+ assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
1945519477
return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
1945619478
}
1945719479
#endif
1945819480
1945919481
#endif /* !defined(SQLITE_MUTEX_OMIT) */
@@ -19764,11 +19786,11 @@
1976419786
** Try to provide a memory barrier operation, needed for initialization only.
1976519787
*/
1976619788
SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
1976719789
#if defined(SQLITE_MEMORY_BARRIER)
1976819790
SQLITE_MEMORY_BARRIER;
19769
-#elif defined(__GNUC__)
19791
+#elif defined(__GNUC__) && GCC_VERSION>=4001000
1977019792
__sync_synchronize();
1977119793
#endif
1977219794
}
1977319795
1977419796
/*
@@ -30682,11 +30704,12 @@
3068230704
*/
3068330705
static void unixShmBarrier(
3068430706
sqlite3_file *fd /* Database file holding the shared memory */
3068530707
){
3068630708
UNUSED_PARAMETER(fd);
30687
- unixEnterMutex();
30709
+ sqlite3MemoryBarrier(); /* compiler-defined memory barrier */
30710
+ unixEnterMutex(); /* Also mutex, for redundancy */
3068830711
unixLeaveMutex();
3068930712
}
3069030713
3069130714
/*
3069230715
** Close a connection to shared-memory. Delete the underlying
@@ -37637,12 +37660,12 @@
3763737660
*/
3763837661
static void winShmBarrier(
3763937662
sqlite3_file *fd /* Database holding the shared memory */
3764037663
){
3764137664
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 */
3764437667
winShmLeaveMutex();
3764537668
}
3764637669
3764737670
/*
3764837671
** This function is called to obtain a pointer to region iRegion of the
@@ -40930,11 +40953,11 @@
4093040953
** this mutex is not held. */
4093140954
assert( pcache1.separateCache==0 );
4093240955
assert( pCache->pGroup==&pcache1.grp );
4093340956
pcache1LeaveMutex(pCache->pGroup);
4093440957
#endif
40935
- if( benignMalloc ) sqlite3BeginBenignMalloc();
40958
+ if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
4093640959
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4093740960
pPg = pcache1Alloc(pCache->szPage);
4093840961
p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
4093940962
if( !pPg || !p ){
4094040963
pcache1Free(pPg);
@@ -40943,11 +40966,11 @@
4094340966
}
4094440967
#else
4094540968
pPg = pcache1Alloc(pCache->szAlloc);
4094640969
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
4094740970
#endif
40948
- if( benignMalloc ) sqlite3EndBenignMalloc();
40971
+ if( benignMalloc ){ sqlite3EndBenignMalloc(); }
4094940972
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4095040973
pcache1EnterMutex(pCache->pGroup);
4095140974
#endif
4095240975
if( pPg==0 ) return 0;
4095340976
p->page.pBuf = pPg;
@@ -44522,10 +44545,24 @@
4452244545
}
4452344546
}
4452444547
#else
4452544548
# define pagerReportSize(X) /* No-op if we do not support a codec */
4452644549
#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
4452744564
4452844565
/*
4452944566
** Read a single page from either the journal file (if isMainJrnl==1) or
4453044567
** from the sub-journal (if isMainJrnl==0) and playback that page.
4453144568
** The page begins at offset *pOffset into the file. The *pOffset
@@ -54479,10 +54516,53 @@
5447954516
pCur->apPage[i] = 0;
5448054517
}
5448154518
pCur->iPage = -1;
5448254519
}
5448354520
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
+}
5448454564
5448554565
/*
5448654566
** Save the current cursor position in the variables BtCursor.nKey
5448754567
** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
5448854568
**
@@ -54499,34 +54579,12 @@
5449954579
if( pCur->eState==CURSOR_SKIPNEXT ){
5450054580
pCur->eState = CURSOR_VALID;
5450154581
}else{
5450254582
pCur->skipNext = 0;
5450354583
}
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);
5452854586
if( rc==SQLITE_OK ){
5452954587
btreeReleaseAllCursorPages(pCur);
5453054588
pCur->eState = CURSOR_REQUIRESEEK;
5453154589
}
5453254590
@@ -61914,22 +61972,28 @@
6191461972
end_insert:
6191561973
return rc;
6191661974
}
6191761975
6191861976
/*
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.
6192161984
*/
61922
-SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
61985
+SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){
6192361986
Btree *p = pCur->pBtree;
6192461987
BtShared *pBt = p->pBt;
6192561988
int rc; /* Return code */
6192661989
MemPage *pPage; /* Page to delete cell from */
6192761990
unsigned char *pCell; /* Pointer to cell to delete */
6192861991
int iCellIdx; /* Index of cell to delete */
6192961992
int iCellDepth; /* Depth of node containing pCell */
6193061993
u16 szCell; /* Size of the cell being deleted */
61994
+ int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
6193161995
6193261996
assert( cursorHoldsMutex(pCur) );
6193361997
assert( pBt->inTransaction==TRANS_WRITE );
6193461998
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
6193561999
assert( pCur->curFlags & BTCF_WriteFlag );
@@ -61955,14 +62019,11 @@
6195562019
rc = sqlite3BtreePrevious(pCur, &notUsed);
6195662020
if( rc ) return rc;
6195762021
}
6195862022
6195962023
/* 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. */
6196462025
if( pCur->curFlags & BTCF_Multiple ){
6196562026
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
6196662027
if( rc ) return rc;
6196762028
}
6196862029
@@ -61970,10 +62031,35 @@
6197062031
** invalidate any incrblob cursors open on the row being deleted. */
6197162032
if( pCur->pKeyInfo==0 ){
6197262033
invalidateIncrblobCursors(p, pCur->info.nKey, 0);
6197362034
}
6197462035
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. */
6197562061
rc = sqlite3PagerWrite(pPage->pDbPage);
6197662062
if( rc ) return rc;
6197762063
rc = clearCell(pPage, pCell, &szCell);
6197862064
dropCell(pPage, iCellIdx, szCell, &rc);
6197962065
if( rc ) return rc;
@@ -62023,11 +62109,27 @@
6202362109
}
6202462110
rc = balance(pCur);
6202562111
}
6202662112
6202762113
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
+ }
6202962131
}
6203062132
return rc;
6203162133
}
6203262134
6203362135
/*
@@ -62745,10 +62847,14 @@
6274562847
}
6274662848
}
6274762849
#endif
6274862850
iPage = get4byte(pOvflData);
6274962851
sqlite3PagerUnref(pOvflPage);
62852
+
62853
+ if( isFreeList && N<(iPage!=0) ){
62854
+ checkAppendMsg(pCheck, "free-page count in header is too small");
62855
+ }
6275062856
}
6275162857
}
6275262858
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
6275362859
6275462860
/*
@@ -64237,10 +64343,14 @@
6423764343
memset(&b, 0, sizeof(b));
6423864344
b.pSrcDb = pFrom->db;
6423964345
b.pSrc = pFrom;
6424064346
b.pDest = pTo;
6424164347
b.iNext = 1;
64348
+
64349
+#ifdef SQLITE_HAS_CODEC
64350
+ sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom));
64351
+#endif
6424264352
6424364353
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
6424464354
** file. By passing this as the number of pages to copy to
6424564355
** sqlite3_backup_step(), we can guarantee that the copy finishes
6424664356
** within a single call (unless an error occurs). The assert() statement
@@ -71166,22 +71276,23 @@
7116671276
#if defined(SQLITE_DEBUG) && defined(__GNUC__)
7116771277
__attribute__((aligned(8)))
7116871278
#endif
7116971279
= {
7117071280
/* .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,
7118071291
#ifdef SQLITE_DEBUG
71181
- /* .pScopyFrom = */ 0,
71182
- /* .pFiller = */ 0,
71292
+ /* .pScopyFrom = */ (Mem*)0,
71293
+ /* .pFiller = */ (void*)0,
7118371294
#endif
7118471295
};
7118571296
return &nullMem;
7118671297
}
7118771298
@@ -76172,13 +76283,14 @@
7617276283
/* Opcode: NotExists P1 P2 P3 * *
7617376284
** Synopsis: intkey=r[P3]
7617476285
**
7617576286
** P1 is the index of a cursor open on an SQL table btree (with integer
7617676287
** 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.
7618076292
**
7618176293
** The OP_NotFound opcode performs the same operation on index btrees
7618276294
** (with arbitrary multi-value keys).
7618376295
**
7618476296
** This opcode leaves the cursor in a state where it cannot be advanced
@@ -76206,17 +76318,25 @@
7620676318
pCrsr = pC->pCursor;
7620776319
assert( pCrsr!=0 );
7620876320
res = 0;
7620976321
iKey = pIn3->u.i;
7621076322
rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
76323
+ assert( rc==SQLITE_OK || res==0 );
7621176324
pC->movetoTarget = iKey; /* Used by OP_Delete */
7621276325
pC->nullRow = 0;
7621376326
pC->cacheStatus = CACHE_STALE;
7621476327
pC->deferredMoveto = 0;
7621576328
VdbeBranchTaken(res!=0,2);
7621676329
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
+ }
7621876338
break;
7621976339
}
7622076340
7622176341
/* Opcode: Sequence P1 P2 * * *
7622276342
** Synopsis: r[P2]=cursor[P1].ctr++
@@ -76478,18 +76598,19 @@
7647876598
assert( pC->iDb>=0 );
7647976599
}
7648076600
break;
7648176601
}
7648276602
76483
-/* Opcode: Delete P1 P2 * P4 *
76603
+/* Opcode: Delete P1 P2 * P4 P5
7648476604
**
7648576605
** Delete the record at which the P1 cursor is currently pointing.
7648676606
**
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.
7649176612
**
7649276613
** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is
7649376614
** incremented (otherwise not).
7649476615
**
7649576616
** P1 must not be pseudo-table. It has to be a real table with
@@ -76500,33 +76621,39 @@
7650076621
** If P4 is not NULL then the P1 cursor must have been positioned
7650176622
** using OP_NotFound prior to invoking this opcode.
7650276623
*/
7650376624
case OP_Delete: {
7650476625
VdbeCursor *pC;
76626
+ u8 hasUpdateCallback;
7650576627
7650676628
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7650776629
pC = p->apCsr[pOp->p1];
7650876630
assert( pC!=0 );
7650976631
assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
7651076632
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
+ }
7651176638
7651276639
#ifdef SQLITE_DEBUG
7651376640
/* The seek operation that positioned the cursor prior to OP_Delete will
7651476641
** have also set the pC->movetoTarget field to the rowid of the row that
7651576642
** is being deleted */
76516
- if( pOp->p4.z && pC->isTable ){
76643
+ if( pOp->p4.z && pC->isTable && pOp->p5==0 ){
7651776644
i64 iKey = 0;
7651876645
sqlite3BtreeKeySize(pC->pCursor, &iKey);
7651976646
assert( pC->movetoTarget==iKey );
7652076647
}
7652176648
#endif
7652276649
76523
- rc = sqlite3BtreeDelete(pC->pCursor);
76650
+ rc = sqlite3BtreeDelete(pC->pCursor, pOp->p5);
7652476651
pC->cacheStatus = CACHE_STALE;
7652576652
7652676653
/* Invoke the update-hook if required. */
76527
- if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
76654
+ if( rc==SQLITE_OK && hasUpdateCallback ){
7652876655
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
7652976656
db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
7653076657
assert( pC->iDb>=0 );
7653176658
}
7653276659
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
@@ -77061,11 +77188,11 @@
7706177188
#ifdef SQLITE_DEBUG
7706277189
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7706377190
#endif
7706477191
rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
7706577192
if( rc==SQLITE_OK && res==0 ){
77066
- rc = sqlite3BtreeDelete(pCrsr);
77193
+ rc = sqlite3BtreeDelete(pCrsr, 0);
7706777194
}
7706877195
assert( pC->deferredMoveto==0 );
7706977196
pC->cacheStatus = CACHE_STALE;
7707077197
break;
7707177198
}
@@ -83123,12 +83250,17 @@
8312383250
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
8312483251
8312583252
/*
8312683253
** Perhaps the name is a reference to the ROWID
8312783254
*/
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
+ ){
8313083262
cnt = 1;
8313183263
pExpr->iColumn = -1; /* IMP: R-44911-55124 */
8313283264
pExpr->affinity = SQLITE_AFF_INTEGER;
8313383265
}
8313483266
@@ -92416,11 +92548,11 @@
9241692548
}else{
9241792549
sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
9241892550
}
9241992551
pParse->checkSchema = 1;
9242092552
}
92421
-#if SQLITE_USER_AUTHENICATION
92553
+#if SQLITE_USER_AUTHENTICATION
9242292554
else if( pParse->db->auth.authLevel<UAUTH_User ){
9242392555
sqlite3ErrorMsg(pParse, "user not authenticated");
9242492556
p = 0;
9242592557
}
9242692558
#endif
@@ -97188,11 +97320,11 @@
9718897320
AuthContext sContext; /* Authorization context */
9718997321
NameContext sNC; /* Name context to resolve expressions in */
9719097322
int iDb; /* Database number */
9719197323
int memCnt = -1; /* Memory cell used for change counting */
9719297324
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 */
9719497326
int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
9719597327
u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
9719697328
Index *pPk; /* The PRIMARY KEY index on the table */
9719797329
int iPk = 0; /* First of nPk registers holding PRIMARY KEY value */
9719897330
i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
@@ -97200,16 +97332,16 @@
9720097332
i16 nKey; /* Number of memory cells in the row key */
9720197333
int iEphCur = 0; /* Ephemeral table holding all primary key values */
9720297334
int iRowSet = 0; /* Register for rowset of rows to delete */
9720397335
int addrBypass = 0; /* Address of jump over the delete logic */
9720497336
int addrLoop = 0; /* Top of the delete loop */
97205
- int addrDelete = 0; /* Jump directly to the delete logic */
9720697337
int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
9720797338
9720897339
#ifndef SQLITE_OMIT_TRIGGER
9720997340
int isView; /* True if attempting to delete from a view */
9721097341
Trigger *pTrigger; /* List of table triggers, if required */
97342
+ int bComplex; /* True if there are either triggers or FKs */
9721197343
#endif
9721297344
9721397345
memset(&sContext, 0, sizeof(sContext));
9721497346
db = pParse->db;
9721597347
if( pParse->nErr || db->mallocFailed ){
@@ -97229,13 +97361,15 @@
9722997361
** deleted from is a view
9723097362
*/
9723197363
#ifndef SQLITE_OMIT_TRIGGER
9723297364
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
9723397365
isView = pTab->pSelect!=0;
97366
+ bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
9723497367
#else
9723597368
# define pTrigger 0
9723697369
# define isView 0
97370
+# define bComplex 0
9723797371
#endif
9723897372
#ifdef SQLITE_OMIT_VIEW
9723997373
# undef isView
9724097374
# define isView 0
9724197375
#endif
@@ -97312,12 +97446,14 @@
9731297446
#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
9731397447
/* Special case: A DELETE without a WHERE clause deletes everything.
9731497448
** It is easier just to erase the whole table. Prior to version 3.6.5,
9731597449
** this optimization caused the row change count (the value returned by
9731697450
** 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)
9731997455
){
9732097456
assert( !isView );
9732197457
sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
9732297458
if( HasRowid(pTab) ){
9732397459
sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
@@ -97328,10 +97464,12 @@
9732897464
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
9732997465
}
9733097466
}else
9733197467
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
9733297468
{
97469
+ u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
97470
+ wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
9733397471
if( HasRowid(pTab) ){
9733497472
/* For a rowid table, initialize the RowSet to an empty set */
9733597473
pPk = 0;
9733697474
nPk = 1;
9733797475
iRowSet = ++pParse->nMem;
@@ -97348,17 +97486,22 @@
9734897486
addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
9734997487
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
9735097488
}
9735197489
9735297490
/* 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.
9735497497
*/
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);
9735897499
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 );
9736097503
9736197504
/* Keep track of the number of rows to be deleted */
9736297505
if( db->flags & SQLITE_CountRows ){
9736397506
sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
9736497507
}
@@ -97375,15 +97518,14 @@
9737597518
iKey = pParse->nMem + 1;
9737697519
iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
9737797520
if( iKey>pParse->nMem ) pParse->nMem = iKey;
9737897521
}
9737997522
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
9738297525
** one, so just keep it in its register(s) and fall through to the
97383
- ** delete code.
97384
- */
97526
+ ** delete code. */
9738597527
nKey = nPk; /* OP_Found will use an unpacked key */
9738697528
aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
9738797529
if( aToOpen==0 ){
9738897530
sqlite3WhereEnd(pWInfo);
9738997531
goto delete_from_cleanup;
@@ -97391,53 +97533,56 @@
9739197533
memset(aToOpen, 1, nIdx+1);
9739297534
aToOpen[nIdx+1] = 0;
9739397535
if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
9739497536
if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
9739597537
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 ){
9741497556
addrBypass = sqlite3VdbeMakeLabel(v);
97415
- sqlite3VdbeGoto(v, addrBypass);
97416
- sqlite3VdbeJumpHere(v, addrDelete);
97557
+ }else{
97558
+ sqlite3WhereEnd(pWInfo);
9741797559
}
9741897560
9741997561
/* Unless this is a view, open cursors for the table we are
9742097562
** deleting from and all its indices. If this is a view, then the
9742197563
** only effect this statement has is to fire the INSTEAD OF
9742297564
** triggers.
9742397565
*/
9742497566
if( !isView ){
97567
+ int iAddrOnce = 0;
97568
+ if( eOnePass==ONEPASS_MULTI ){
97569
+ iAddrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v);
97570
+ }
9742597571
testcase( IsVirtual(pTab) );
9742697572
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
9742797573
&iDataCur, &iIdxCur);
9742897574
assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur );
9742997575
assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 );
97576
+ if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce);
9743097577
}
9743197578
9743297579
/* Set up a loop over the rowids/primary-keys that were found in the
9743397580
** where-clause loop above.
9743497581
*/
97435
- if( okOnePass ){
97436
- /* Just one row. Hence the top-of-loop is a no-op */
97582
+ if( eOnePass!=ONEPASS_OFF ){
9743797583
assert( nKey==nPk ); /* OP_Found will use an unpacked key */
97438
- assert( !IsVirtual(pTab) );
9743997584
if( aToOpen[iDataCur-iTabCur] ){
9744097585
assert( pPk!=0 || pTab->pSelect!=0 );
9744197586
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
9744297587
VdbeCoverage(v);
9744397588
}
@@ -97461,17 +97606,22 @@
9746197606
sqlite3MayAbort(pParse);
9746297607
}else
9746397608
#endif
9746497609
{
9746597610
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
+ }
9746697615
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
97467
- iKey, nKey, count, OE_Default, okOnePass);
97616
+ iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek);
9746897617
}
9746997618
9747097619
/* End of the loop over all rowids/primary-keys. */
97471
- if( okOnePass ){
97620
+ if( eOnePass!=ONEPASS_OFF ){
9747297621
sqlite3VdbeResolveLabel(v, addrBypass);
97622
+ sqlite3WhereEnd(pWInfo);
9747397623
}else if( pPk ){
9747497624
sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
9747597625
sqlite3VdbeJumpHere(v, addrLoop);
9747697626
}else{
9747797627
sqlite3VdbeGoto(v, addrLoop);
@@ -97539,10 +97689,29 @@
9753997689
**
9754097690
** 3. The primary key for the row to be deleted must be stored in a
9754197691
** sequence of nPk memory cells starting at iPk. If nPk==0 that means
9754297692
** that a search record formed from OP_MakeRecord is contained in the
9754397693
** 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.
9754497713
*/
9754597714
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
9754697715
Parse *pParse, /* Parsing context */
9754797716
Table *pTab, /* Table containing the row to be deleted */
9754897717
Trigger *pTrigger, /* List of triggers to (potentially) fire */
@@ -97550,11 +97719,12 @@
9755097719
int iIdxCur, /* First index cursor */
9755197720
int iPk, /* First memory cell containing the PRIMARY KEY */
9755297721
i16 nPk, /* Number of PRIMARY KEY memory cells */
9755397722
u8 count, /* If non-zero, increment the row change counter */
9755497723
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 */
9755697726
){
9755797727
Vdbe *v = pParse->pVdbe; /* Vdbe */
9755897728
int iOld = 0; /* First register in OLD.* array */
9755997729
int iLabel; /* Label resolved to end of generated code */
9756097730
u8 opSeek; /* Seek opcode */
@@ -97567,11 +97737,11 @@
9756797737
/* Seek cursor iCur to the row to delete. If this row no longer exists
9756897738
** (this can happen if a trigger program has already deleted it), do
9756997739
** not attempt to delete it or fire any DELETE triggers. */
9757097740
iLabel = sqlite3VdbeMakeLabel(v);
9757197741
opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
97572
- if( !bNoSeek ){
97742
+ if( eMode==ONEPASS_OFF ){
9757397743
sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
9757497744
VdbeCoverageIf(v, opSeek==OP_NotExists);
9757597745
VdbeCoverageIf(v, opSeek==OP_NotFound);
9757697746
}
9757797747
@@ -97627,15 +97797,19 @@
9762797797
9762897798
/* Delete the index and table entries. Skip this step if pTab is really
9762997799
** a view (in which case the only effect of the DELETE statement is to
9763097800
** fire the INSTEAD OF triggers). */
9763197801
if( pTab->pSelect==0 ){
97632
- sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
97802
+ sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
9763397803
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
9763497804
if( count ){
9763597805
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
9763697806
}
97807
+ if( iIdxNoSeek>=0 ){
97808
+ sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
97809
+ }
97810
+ sqlite3VdbeChangeP5(v, eMode==ONEPASS_MULTI);
9763797811
}
9763897812
9763997813
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
9764097814
** handle rows (possibly in other tables) that refer via a foreign key
9764197815
** to the row just deleted. */
@@ -97674,11 +97848,12 @@
9767497848
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(
9767597849
Parse *pParse, /* Parsing and code generating context */
9767697850
Table *pTab, /* Table containing the row to be deleted */
9767797851
int iDataCur, /* Cursor of table holding data. */
9767897852
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 */
9768097855
){
9768197856
int i; /* Index loop counter */
9768297857
int r1 = -1; /* Register holding an index key */
9768397858
int iPartIdxLabel; /* Jump destination for skipping partial index entries */
9768497859
Index *pIdx; /* Current index */
@@ -97690,15 +97865,16 @@
9769097865
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
9769197866
for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
9769297867
assert( iIdxCur+i!=iDataCur || pPk==pIdx );
9769397868
if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
9769497869
if( pIdx==pPk ) continue;
97870
+ if( iIdxCur+i==iIdxNoSeek ) continue;
9769597871
VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
9769697872
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
97697
- &iPartIdxLabel, pPrior, r1);
97873
+ &iPartIdxLabel, pPrior, r1);
9769897874
sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,
97699
- pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
97875
+ pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
9770097876
sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
9770197877
pPrior = pIdx;
9770297878
}
9770397879
}
9770497880
@@ -102350,14 +102526,17 @@
102350102526
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
102351102527
}
102352102528
if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
102353102529
sqlite3MultiWrite(pParse);
102354102530
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
+ }
102359102538
}
102360102539
seenReplace = 1;
102361102540
break;
102362102541
}
102363102542
case OE_Ignore: {
@@ -102531,11 +102710,12 @@
102531102710
sqlite3MultiWrite(pParse);
102532102711
if( db->flags&SQLITE_RecTriggers ){
102533102712
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
102534102713
}
102535102714
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);
102537102717
seenReplace = 1;
102538102718
break;
102539102719
}
102540102720
}
102541102721
sqlite3VdbeResolveLabel(v, addrUniqueOk);
@@ -112115,13 +112295,16 @@
112115112295
return WRC_Abort;
112116112296
}
112117112297
pTab->nRef++;
112118112298
#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
112119112299
if( pTab->pSelect || IsVirtual(pTab) ){
112120
- /* We reach here if the named table is a really a view */
112121112300
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
112122112301
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
+ }
112123112306
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
112124112307
sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
112125112308
sqlite3WalkSelect(pWalker, pFrom->pSelect);
112126112309
}
112127112310
#endif
@@ -115381,11 +115564,11 @@
115381115564
}else{
115382115565
j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
115383115566
}
115384115567
VdbeCoverageNeverTaken(v);
115385115568
}
115386
- sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
115569
+ sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1);
115387115570
115388115571
/* If changing the record number, delete the old record. */
115389115572
if( hasFK || chngKey || pPk!=0 ){
115390115573
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
115391115574
}
@@ -117596,11 +117779,11 @@
117596117779
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
117597117780
LogEst nRowOut; /* Estimated number of output rows */
117598117781
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
117599117782
i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */
117600117783
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 */
117602117785
u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
117603117786
u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
117604117787
u8 nLevel; /* Number of nested loop */
117605117788
int iTop; /* The very beginning of the WHERE loop */
117606117789
int iContinue; /* Jump here to continue with next record */
@@ -117763,11 +117946,11 @@
117763117946
** is run and there is an index on (a, b), then this function returns a
117764117947
** string similar to:
117765117948
**
117766117949
** "a=? AND b>?"
117767117950
*/
117768
-static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117951
+static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){
117769117952
Index *pIndex = pLoop->u.btree.pIndex;
117770117953
u16 nEq = pLoop->u.btree.nEq;
117771117954
u16 nSkip = pLoop->nSkip;
117772117955
int i, j;
117773117956
@@ -117864,11 +118047,11 @@
117864118047
zFmt = "INDEX %s";
117865118048
}
117866118049
if( zFmt ){
117867118050
sqlite3StrAccumAppend(&str, " USING ", 7);
117868118051
sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
117869
- explainIndexRange(&str, pLoop, pItem->pTab);
118052
+ explainIndexRange(&str, pLoop);
117870118053
}
117871118054
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
117872118055
const char *zRangeOp;
117873118056
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
117874118057
zRangeOp = "=";
@@ -118212,12 +118395,12 @@
118212118395
VdbeCoverageIf(v, bRev==0);
118213118396
VdbeCoverageIf(v, bRev!=0);
118214118397
sqlite3VdbeJumpHere(v, j);
118215118398
for(j=0; j<nSkip; j++){
118216118399
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)));
118219118402
}
118220118403
}
118221118404
118222118405
/* Evaluate the equality constraints
118223118406
*/
@@ -118767,11 +118950,16 @@
118767118950
/* pIdx is a covering index. No need to access the main table. */
118768118951
}else if( HasRowid(pIdx->pTable) ){
118769118952
iRowidReg = ++pParse->nMem;
118770118953
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
118771118954
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
+ }
118773118961
}else if( iCur!=iIdxCur ){
118774118962
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
118775118963
iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
118776118964
for(j=0; j<pPk->nKeyCol; j++){
118777118965
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
@@ -120618,13 +120806,15 @@
120618120806
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo *pWInfo){
120619120807
return pWInfo->iBreak;
120620120808
}
120621120809
120622120810
/*
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
120626120816
**
120627120817
** If the ONEPASS optimization is used (if this routine returns true)
120628120818
** then also write the indices of open cursors used by ONEPASS
120629120819
** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
120630120820
** table and iaCur[1] gets the cursor used by an auxiliary index.
@@ -120634,11 +120824,11 @@
120634120824
** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
120635120825
** unable to use the ONEPASS optimization.
120636120826
*/
120637120827
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){
120638120828
memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);
120639
- return pWInfo->okOnePass;
120829
+ return pWInfo->eOnePass;
120640120830
}
120641120831
120642120832
/*
120643120833
** Move the content of pSrc into pDest
120644120834
*/
@@ -120729,25 +120919,24 @@
120729120919
int k = pScan->k; /* Where to start scanning */
120730120920
120731120921
while( pScan->iEquiv<=pScan->nEquiv ){
120732120922
iCur = pScan->aiCur[pScan->iEquiv-1];
120733120923
iColumn = pScan->aiColumn[pScan->iEquiv-1];
120734
- assert( iColumn!=(-2) || pScan->pIdxExpr!=0 );
120924
+ if( iColumn==(-2) && pScan->pIdxExpr==0 ) return 0;
120735120925
while( (pWC = pScan->pWC)!=0 ){
120736120926
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
120737120927
if( pTerm->leftCursor==iCur
120738120928
&& pTerm->u.leftColumn==iColumn
120739120929
&& (iColumn!=(-2)
120740
- || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
120930
+ || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
120741120931
&& (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
120742120932
){
120743120933
if( (pTerm->eOperator & WO_EQUIV)!=0
120744120934
&& pScan->nEquiv<ArraySize(pScan->aiCur)
120935
+ && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
120745120936
){
120746120937
int j;
120747
- pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
120748
- assert( pX->op==TK_COLUMN );
120749120938
for(j=0; j<pScan->nEquiv; j++){
120750120939
if( pScan->aiCur[j]==pX->iTable
120751120940
&& pScan->aiColumn[j]==pX->iColumn ){
120752120941
break;
120753120942
}
@@ -122969,21 +123158,28 @@
122969123158
WhereLoopBuilder *pBuilder,
122970123159
Index *pIndex,
122971123160
int iCursor
122972123161
){
122973123162
ExprList *pOB;
123163
+ ExprList *aColExpr;
122974123164
int ii, jj;
122975123165
122976123166
if( pIndex->bUnordered ) return 0;
122977123167
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
122978123168
for(ii=0; ii<pOB->nExpr; ii++){
122979123169
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 ){
122982123171
if( pExpr->iColumn<0 ) return 1;
122983123172
for(jj=0; jj<pIndex->nKeyCol; jj++){
122984123173
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
+ }
122985123181
}
122986123182
}
122987123183
}
122988123184
return 0;
122989123185
}
@@ -123128,11 +123324,11 @@
123128123324
if( !pBuilder->pOrSet /* Not part of an OR optimization */
123129123325
&& (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
123130123326
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
123131123327
&& pSrc->pIBIndex==0 /* Has no INDEXED BY clause */
123132123328
&& !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?) */
123134123330
&& !pSrc->fg.isCorrelated /* Not a correlated subquery */
123135123331
&& !pSrc->fg.isRecursive /* Not a recursive common table expression. */
123136123332
){
123137123333
/* Generate auto-index WhereLoops */
123138123334
WhereTerm *pTerm;
@@ -123812,13 +124008,19 @@
123812124008
if( MASKBIT(i) & obSat ) continue;
123813124009
pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
123814124010
testcase( wctrlFlags & WHERE_GROUPBY );
123815124011
testcase( wctrlFlags & WHERE_DISTINCTBY );
123816124012
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
+ }
123820124022
if( iColumn>=0 ){
123821124023
pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
123822124024
if( !pColl ) pColl = db->pDfltColl;
123823124025
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
123824124026
}
@@ -124507,10 +124709,14 @@
124507124709
WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
124508124710
int ii; /* Loop counter */
124509124711
sqlite3 *db; /* Database connection */
124510124712
int rc; /* Return code */
124511124713
124714
+ assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || (
124715
+ (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
124716
+ && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
124717
+ ));
124512124718
124513124719
/* Variable initialization */
124514124720
db = pParse->db;
124515124721
memset(&sWLB, 0, sizeof(sWLB));
124516124722
@@ -124562,10 +124768,11 @@
124562124768
pWInfo->pOrderBy = pOrderBy;
124563124769
pWInfo->pResultSet = pResultSet;
124564124770
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
124565124771
pWInfo->wctrlFlags = wctrlFlags;
124566124772
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
124773
+ assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
124567124774
pMaskSet = &pWInfo->sMaskSet;
124568124775
sWLB.pWInfo = pWInfo;
124569124776
sWLB.pWC = &pWInfo->sWC;
124570124777
sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo);
124571124778
assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) );
@@ -124748,15 +124955,20 @@
124748124955
** to use a one-pass algorithm, determine if this is appropriate.
124749124956
** The one-pass algorithm only works if the WHERE clause constrains
124750124957
** the statement to update or delete a single row.
124751124958
*/
124752124959
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
+ }
124758124970
}
124759124971
}
124760124972
124761124973
/* Open all tables in the pTabList and any indices selected for
124762124974
** searching those tables.
@@ -124783,19 +124995,19 @@
124783124995
}else
124784124996
#endif
124785124997
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
124786124998
&& (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){
124787124999
int op = OP_OpenRead;
124788
- if( pWInfo->okOnePass ){
125000
+ if( pWInfo->eOnePass!=ONEPASS_OFF ){
124789125001
op = OP_OpenWrite;
124790125002
pWInfo->aiCurOnePass[0] = pTabItem->iCursor;
124791125003
};
124792125004
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
124793125005
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) ){
124797125009
Bitmask b = pTabItem->colUsed;
124798125010
int n = 0;
124799125011
for(; b; b=b>>1, n++){}
124800125012
sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
124801125013
SQLITE_INT_TO_PTR(n), P4_INT32);
@@ -124819,11 +125031,11 @@
124819125031
){
124820125032
/* This is one term of an OR-optimization using the PRIMARY KEY of a
124821125033
** WITHOUT ROWID table. No need for a separate index */
124822125034
iIndexCur = pLevel->iTabCur;
124823125035
op = 0;
124824
- }else if( pWInfo->okOnePass ){
125036
+ }else if( pWInfo->eOnePass!=ONEPASS_OFF ){
124825125037
Index *pJ = pTabItem->pTab->pIndex;
124826125038
iIndexCur = iIdxCur;
124827125039
assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
124828125040
while( ALWAYS(pJ) && pJ!=pIx ){
124829125041
iIndexCur++;
@@ -125027,11 +125239,11 @@
125027125239
if( (pTab->tabFlags & TF_Ephemeral)==0
125028125240
&& pTab->pSelect==0
125029125241
&& (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
125030125242
){
125031125243
int ws = pLoop->wsFlags;
125032
- if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
125244
+ if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
125033125245
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
125034125246
}
125035125247
if( (ws & WHERE_INDEXED)!=0
125036125248
&& (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
125037125249
&& pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
125038125250
--- 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, &notUsed);
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, &notUsed);
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 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.8.12"
115115
#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"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -122,11 +122,11 @@
122122
** These interfaces provide the same information as the [SQLITE_VERSION],
123123
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
124124
** but are associated with the library instead of the header file. ^(Cautious
125125
** programmers might include assert() statements in their application to
126126
** 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
128128
** compiled with matching library and header files.
129129
**
130130
** <blockquote><pre>
131131
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
132132
** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
@@ -372,11 +372,11 @@
372372
** is not changed.
373373
**
374374
** Restrictions:
375375
**
376376
** <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()
378378
** is a valid and open [database connection].
379379
** <li> The application must not close the [database connection] specified by
380380
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
381381
** <li> The application must not modify the SQL statement text passed into
382382
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
@@ -1365,13 +1365,15 @@
13651365
** changes to SQLite in order to tune SQLite to the specific needs of
13661366
** the application. The default configuration is recommended for most
13671367
** applications and so this routine is usually not necessary. It is
13681368
** provided to support rare applications with unusual needs.
13691369
**
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
13731375
** may only be invoked prior to library initialization using
13741376
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
13751377
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
13761378
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
13771379
** Note, however, that ^sqlite3_config() can be called as part of the
@@ -3626,11 +3628,11 @@
36263628
** name must be given in UTF-8 even if the original statement
36273629
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
36283630
**
36293631
** See also: [sqlite3_bind_blob|sqlite3_bind()],
36303632
** [sqlite3_bind_parameter_count()], and
3631
-** [sqlite3_bind_parameter_index()].
3633
+** [sqlite3_bind_parameter_name()].
36323634
*/
36333635
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
36343636
36353637
/*
36363638
** CAPI3REF: Reset All Bindings On A Prepared Statement
@@ -6123,10 +6125,13 @@
61236125
** <li> SQLITE_MUTEX_STATIC_LRU
61246126
** <li> SQLITE_MUTEX_STATIC_PMEM
61256127
** <li> SQLITE_MUTEX_STATIC_APP1
61266128
** <li> SQLITE_MUTEX_STATIC_APP2
61276129
** <li> SQLITE_MUTEX_STATIC_APP3
6130
+** <li> SQLITE_MUTEX_STATIC_VFS1
6131
+** <li> SQLITE_MUTEX_STATIC_VFS2
6132
+** <li> SQLITE_MUTEX_STATIC_VFS3
61286133
** </ul>
61296134
**
61306135
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
61316136
** cause sqlite3_mutex_alloc() to create
61326137
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
61336138
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button