Fossil SCM

Another update to the built-in SQLite code. The last one is working fine, but SQLite is nearing release and so we want to give it a good shake-out.

drh 2011-04-06 02:56 trunk
Commit 5d699b625e7c3d5466127ac293cac03e8d5d2674
2 files changed +254 -269 +2 -2
+254 -269
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.6"
654654
#define SQLITE_VERSION_NUMBER 3007006
655
-#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906"
655
+#define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1675,11 +1675,11 @@
16751675
** changes to a [database connection]. The interface is similar to
16761676
** [sqlite3_config()] except that the changes apply to a single
16771677
** [database connection] (specified in the first argument).
16781678
**
16791679
** The second argument to sqlite3_db_config(D,V,...) is the
1680
-** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1680
+** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
16811681
** that indicates what aspect of the [database connection] is being configured.
16821682
** Subsequent arguments vary depending on the configuration verb.
16831683
**
16841684
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
16851685
** the call is considered successful.
@@ -7833,22 +7833,22 @@
78337833
SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*);
78347834
#ifndef NDEBUG
78357835
/* These routines are used inside assert() statements only. */
78367836
SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*);
78377837
SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*);
7838
-SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree*);
7838
+SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
78397839
#endif
78407840
#else
78417841
78427842
# define sqlite3BtreeLeave(X)
7843
-# define sqlite3BtreeMutexCounter(X) 0
78447843
# define sqlite3BtreeEnterCursor(X)
78457844
# define sqlite3BtreeLeaveCursor(X)
78467845
# define sqlite3BtreeLeaveAll(X)
78477846
78487847
# define sqlite3BtreeHoldsMutex(X) 1
78497848
# define sqlite3BtreeHoldsAllMutexes(X) 1
7849
+# define sqlite3SchemaMutexHeld(X,Y,Z) 1
78507850
#endif
78517851
78527852
78537853
#endif /* _BTREE_H_ */
78547854
@@ -7963,11 +7963,11 @@
79637963
#define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
79647964
#define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
79657965
#define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
79667966
#define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
79677967
#define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
7968
-#define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */
7968
+#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
79697969
#define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
79707970
#define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
79717971
#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
79727972
#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
79737973
#define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
@@ -8998,10 +8998,24 @@
89988998
Schema *pSchema; /* Pointer to database schema (possibly shared) */
89998999
};
90009000
90019001
/*
90029002
** An instance of the following structure stores a database schema.
9003
+**
9004
+** Most Schema objects are associated with a Btree. The exception is
9005
+** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
9006
+** In shared cache mode, a single Schema object can be shared by multiple
9007
+** Btrees that refer to the same underlying BtShared object.
9008
+**
9009
+** Schema objects are automatically deallocated when the last Btree that
9010
+** references them is destroyed. The TEMP Schema is manually freed by
9011
+** sqlite3_close().
9012
+*
9013
+** A thread must be holding a mutex on the corresponding Btree in order
9014
+** to access Schema content. This implies that the thread must also be
9015
+** holding a mutex on the sqlite3 connection pointer that owns the Btree.
9016
+** For a TEMP Schema, on the connection mutex is required.
90039017
*/
90049018
struct Schema {
90059019
int schema_cookie; /* Database schema version number for this file */
90069020
int iGeneration; /* Generation counter. Incremented with each change */
90079021
Hash tblHash; /* All tables indexed by name */
@@ -9514,11 +9528,11 @@
95149528
** implementation. sqlite3_vtab* handles can not be shared between
95159529
** database connections, even when the rest of the in-memory database
95169530
** schema is shared, as the implementation often stores the database
95179531
** connection handle passed to it via the xConnect() or xCreate() method
95189532
** during initialization internally. This database connection handle may
9519
-** then used by the virtual table implementation to access real tables
9533
+** then be used by the virtual table implementation to access real tables
95209534
** within the database. So that they appear as part of the callers
95219535
** transaction, these accesses need to be made via the same database
95229536
** connection as that used to execute SQL operations on the virtual table.
95239537
**
95249538
** All VTable objects that correspond to a single table in a shared
@@ -11272,11 +11286,11 @@
1127211286
SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
1127311287
#ifndef SQLITE_OMIT_WSD
1127411288
SQLITE_PRIVATE int sqlite3PendingByte;
1127511289
#endif
1127611290
#endif
11277
-SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
11291
+SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
1127811292
SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
1127911293
SQLITE_PRIVATE void sqlite3AlterFunctions(void);
1128011294
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
1128111295
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
1128211296
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
@@ -11299,11 +11313,11 @@
1129911313
SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
1130011314
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
1130111315
SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
1130211316
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
1130311317
SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
11304
-SQLITE_PRIVATE void sqlite3SchemaFree(void *);
11318
+SQLITE_PRIVATE void sqlite3SchemaClear(void *);
1130511319
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
1130611320
SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
1130711321
SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
1130811322
SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
1130911323
void (*)(sqlite3_context*,int,sqlite3_value **),
@@ -12479,11 +12493,10 @@
1247912493
u8 usesStmtJournal; /* True if uses a statement journal */
1248012494
u8 readOnly; /* True for read-only statements */
1248112495
u8 isPrepareV2; /* True if prepared with prepare_v2() */
1248212496
int nChange; /* Number of db changes made since last reset */
1248312497
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
12484
- u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */
1248512498
int iStatement; /* Statement number (or 0 if has not opened stmt) */
1248612499
int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
1248712500
#ifndef SQLITE_OMIT_TRACE
1248812501
i64 startTime; /* Time when query started - used for profiling */
1248912502
#endif
@@ -12563,13 +12576,18 @@
1256312576
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1256412577
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1256512578
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1256612579
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
1256712580
SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12568
-SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
12569
-SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
12570
-SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe*);
12581
+
12582
+#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
12583
+SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
12584
+SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
12585
+#else
12586
+# define sqlite3VdbeEnter(X)
12587
+# define sqlite3VdbeLeave(X)
12588
+#endif
1257112589
1257212590
#ifdef SQLITE_DEBUG
1257312591
SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);
1257412592
#endif
1257512593
@@ -12742,10 +12760,11 @@
1274212760
*/
1274312761
case SQLITE_DBSTATUS_SCHEMA_USED: {
1274412762
int i; /* Used to iterate through schemas */
1274512763
int nByte = 0; /* Used to accumulate return value */
1274612764
12765
+ sqlite3BtreeEnterAll(db);
1274712766
db->pnBytesFreed = &nByte;
1274812767
for(i=0; i<db->nDb; i++){
1274912768
Schema *pSchema = db->aDb[i].pSchema;
1275012769
if( ALWAYS(pSchema!=0) ){
1275112770
HashElem *p;
@@ -12768,10 +12787,11 @@
1276812787
sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
1276912788
}
1277012789
}
1277112790
}
1277212791
db->pnBytesFreed = 0;
12792
+ sqlite3BtreeLeaveAll(db);
1277312793
1277412794
*pHighwater = 0;
1277512795
*pCurrent = nByte;
1277612796
break;
1277712797
}
@@ -15879,11 +15899,11 @@
1587915899
** Space for tracking which blocks are checked out and the size
1588015900
** of each block. One byte per block.
1588115901
*/
1588215902
u8 *aCtrl;
1588315903
15884
-} mem5 = { 0 };
15904
+} mem5;
1588515905
1588615906
/*
1588715907
** Access the static variable through a macro for SQLITE_OMIT_WSD
1588815908
*/
1588915909
#define mem5 GLOBAL(struct Mem5Global, mem5)
@@ -16194,11 +16214,11 @@
1619416214
** memsys5Log(8) -> 3
1619516215
** memsys5Log(9) -> 4
1619616216
*/
1619716217
static int memsys5Log(int iValue){
1619816218
int iLog;
16199
- for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
16219
+ for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
1620016220
return iLog;
1620116221
}
1620216222
1620316223
/*
1620416224
** Initialize the memory allocator.
@@ -18064,11 +18084,11 @@
1806418084
pSlot = (ScratchFreeslot*)p;
1806518085
sqlite3_mutex_enter(mem0.mutex);
1806618086
pSlot->pNext = mem0.pScratchFree;
1806718087
mem0.pScratchFree = pSlot;
1806818088
mem0.nScratchFree++;
18069
- assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch );
18089
+ assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
1807018090
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
1807118091
sqlite3_mutex_leave(mem0.mutex);
1807218092
}else{
1807318093
/* Release memory back to the heap */
1807418094
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
@@ -38547,10 +38567,23 @@
3854738567
/* Verify that the page list is in accending order */
3854838568
for(p=pList; p && p->pDirty; p=p->pDirty){
3854938569
assert( p->pgno < p->pDirty->pgno );
3855038570
}
3855138571
#endif
38572
+
38573
+ if( isCommit ){
38574
+ /* If a WAL transaction is being committed, there is no point in writing
38575
+ ** any pages with page numbers greater than nTruncate into the WAL file.
38576
+ ** They will never be read by any client. So remove them from the pDirty
38577
+ ** list here. */
38578
+ PgHdr *p;
38579
+ PgHdr **ppNext = &pList;
38580
+ for(p=pList; (*ppNext = p); p=p->pDirty){
38581
+ if( p->pgno<=nTruncate ) ppNext = &p->pDirty;
38582
+ }
38583
+ assert( pList );
38584
+ }
3855238585
3855338586
if( pList->pgno==1 ) pager_write_changecounter(pList);
3855438587
rc = sqlite3WalFrames(pPager->pWal,
3855538588
pPager->pageSize, pList, nTruncate, isCommit, syncFlags
3855638589
);
@@ -38560,10 +38593,11 @@
3856038593
sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
3856138594
}
3856238595
}
3856338596
3856438597
#ifdef SQLITE_CHECK_PAGES
38598
+ pList = sqlite3PcacheDirtyList(pPager->pPCache);
3856538599
for(p=pList; p; p=p->pDirty){
3856638600
pager_set_pagehash(p);
3856738601
}
3856838602
#endif
3856938603
@@ -45510,11 +45544,11 @@
4551045544
4551145545
4551245546
/* The following value is the maximum cell size assuming a maximum page
4551345547
** size give above.
4551445548
*/
45515
-#define MX_CELL_SIZE(pBt) (pBt->pageSize-8)
45549
+#define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8))
4551645550
4551745551
/* The maximum number of cells on a single page of the database. This
4551845552
** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself
4551945553
** plus 2 bytes for the index to the cell in the page header). Such
4552045554
** small cells will be rare, but they are possible.
@@ -45727,11 +45761,10 @@
4572745761
BtShared *pNext; /* Next on a list of sharable BtShared structs */
4572845762
BtLock *pLock; /* List of locks held on this shared-btree struct */
4572945763
Btree *pWriter; /* Btree with currently open write transaction */
4573045764
u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
4573145765
u8 isPending; /* If waiting for read-locks to clear */
45732
- u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */
4573345766
#endif
4573445767
u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
4573545768
};
4573645769
4573745770
/*
@@ -45966,32 +45999,14 @@
4596645999
assert( p->locked==1 );
4596746000
assert( sqlite3_mutex_held(pBt->mutex) );
4596846001
assert( sqlite3_mutex_held(p->db->mutex) );
4596946002
assert( p->db==pBt->db );
4597046003
45971
- pBt->iMutexCounter++;
4597246004
sqlite3_mutex_leave(pBt->mutex);
4597346005
p->locked = 0;
4597446006
}
4597546007
45976
-#ifdef SQLITE_DEBUG
45977
-/*
45978
-** Return the number of times that the mutex has been exited for
45979
-** the given btree.
45980
-**
45981
-** This is a small circular counter that wraps around to zero on
45982
-** overflow. It is used only for sanity checking - to verify that
45983
-** mutexes are held continously by asserting that the value of
45984
-** this counter at the beginning of a region is the same as at
45985
-** the end.
45986
-*/
45987
-SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree *p){
45988
- assert( p->locked==1 || p->sharable==0 );
45989
- return p->pBt->iMutexCounter;
45990
-}
45991
-#endif
45992
-
4599346008
/*
4599446009
** Enter a mutex on the given BTree object.
4599546010
**
4599646011
** If the object is not sharable, then no mutex is ever required
4599746012
** and this routine is a no-op. The underlying mutex is non-recursive.
@@ -46032,28 +46047,10 @@
4603246047
4603346048
if( !p->sharable ) return;
4603446049
p->wantToLock++;
4603546050
if( p->locked ) return;
4603646051
46037
- /* Increment the mutex counter on all locked btrees in the same
46038
- ** database connection. This simulates the unlocking that would
46039
- ** occur on a worst-case mutex dead-lock avoidance scenario.
46040
- */
46041
-#ifdef SQLITE_DEBUG
46042
- {
46043
- int ii;
46044
- sqlite3 *db = p->db;
46045
- Btree *pOther;
46046
- for(ii=0; ii<db->nDb; ii++){
46047
- if( ii==1 ) continue;
46048
- pOther = db->aDb[ii].pBt;
46049
- if( pOther==0 || pOther->sharable==0 || pOther->locked==0 ) continue;
46050
- pOther->pBt->iMutexCounter++;
46051
- }
46052
- }
46053
-#endif
46054
-
4605546052
/* In most cases, we should be able to acquire the lock we
4605646053
** want without having to go throught the ascending lock
4605746054
** procedure that follows. Just be sure not to block.
4605846055
*/
4605946056
if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
@@ -46143,49 +46140,24 @@
4614346140
** two or more btrees in common both try to lock all their btrees
4614446141
** at the same instant.
4614546142
*/
4614646143
SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
4614746144
int i;
46148
- Btree *p, *pLater;
46145
+ Btree *p;
4614946146
assert( sqlite3_mutex_held(db->mutex) );
4615046147
for(i=0; i<db->nDb; i++){
4615146148
p = db->aDb[i].pBt;
46152
- assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db );
46153
- if( p && p->sharable ){
46154
- p->wantToLock++;
46155
- if( !p->locked ){
46156
- assert( p->wantToLock==1 );
46157
- while( p->pPrev ) p = p->pPrev;
46158
- /* Reason for ALWAYS: There must be at least one unlocked Btree in
46159
- ** the chain. Otherwise the !p->locked test above would have failed */
46160
- while( p->locked && ALWAYS(p->pNext) ) p = p->pNext;
46161
- for(pLater = p->pNext; pLater; pLater=pLater->pNext){
46162
- if( pLater->locked ){
46163
- unlockBtreeMutex(pLater);
46164
- }
46165
- }
46166
- while( p ){
46167
- lockBtreeMutex(p);
46168
- p = p->pNext;
46169
- }
46170
- }
46171
- }
46149
+ if( p ) sqlite3BtreeEnter(p);
4617246150
}
4617346151
}
4617446152
SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
4617546153
int i;
4617646154
Btree *p;
4617746155
assert( sqlite3_mutex_held(db->mutex) );
4617846156
for(i=0; i<db->nDb; i++){
4617946157
p = db->aDb[i].pBt;
46180
- if( p && p->sharable ){
46181
- assert( p->wantToLock>0 );
46182
- p->wantToLock--;
46183
- if( p->wantToLock==0 ){
46184
- unlockBtreeMutex(p);
46185
- }
46186
- }
46158
+ if( p ) sqlite3BtreeLeave(p);
4618746159
}
4618846160
}
4618946161
4619046162
#ifndef NDEBUG
4619146163
/*
@@ -46209,10 +46181,35 @@
4620946181
}
4621046182
return 1;
4621146183
}
4621246184
#endif /* NDEBUG */
4621346185
46186
+#ifndef NDEBUG
46187
+/*
46188
+** Return true if the correct mutexes are held for accessing the
46189
+** db->aDb[iDb].pSchema structure. The mutexes required for schema
46190
+** access are:
46191
+**
46192
+** (1) The mutex on db
46193
+** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
46194
+**
46195
+** If pSchema is not NULL, then iDb is computed from pSchema and
46196
+** db using sqlite3SchemaToIndex().
46197
+*/
46198
+SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
46199
+ Btree *p;
46200
+ assert( db!=0 );
46201
+ if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
46202
+ assert( iDb>=0 && iDb<db->nDb );
46203
+ if( !sqlite3_mutex_held(db->mutex) ) return 0;
46204
+ if( iDb==1 ) return 1;
46205
+ p = db->aDb[iDb].pBt;
46206
+ assert( p!=0 );
46207
+ return p->sharable==0 || p->locked==1;
46208
+}
46209
+#endif /* NDEBUG */
46210
+
4621446211
#else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
4621546212
/*
4621646213
** The following are special cases for mutex enter routines for use
4621746214
** in single threaded applications that use shared cache. Except for
4621846215
** these two routines, all mutex operations are no-ops in that case and
@@ -47466,11 +47463,11 @@
4746647463
** is no way that the allocation can extend off the end of the page.
4746747464
** The assert() below verifies the previous sentence.
4746847465
*/
4746947466
top -= nByte;
4747047467
put2byte(&data[hdr+5], top);
47471
- assert( top+nByte <= pPage->pBt->usableSize );
47468
+ assert( top+nByte <= (int)pPage->pBt->usableSize );
4747247469
*pIdx = top;
4747347470
return SQLITE_OK;
4747447471
}
4747547472
4747647473
/*
@@ -47487,11 +47484,11 @@
4748747484
unsigned char *data = pPage->aData;
4748847485
4748947486
assert( pPage->pBt!=0 );
4749047487
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
4749147488
assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
47492
- assert( (start + size)<=pPage->pBt->usableSize );
47489
+ assert( (start + size) <= (int)pPage->pBt->usableSize );
4749347490
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
4749447491
assert( size>=0 ); /* Minimum cell size is 4 */
4749547492
4749647493
if( pPage->pBt->secureDelete ){
4749747494
/* Overwrite deleted information with zeros when the secure_delete
@@ -47530,11 +47527,11 @@
4753047527
/* Coalesce adjacent free blocks */
4753147528
addr = hdr + 1;
4753247529
while( (pbegin = get2byte(&data[addr]))>0 ){
4753347530
int pnext, psize, x;
4753447531
assert( pbegin>addr );
47535
- assert( pbegin<=pPage->pBt->usableSize-4 );
47532
+ assert( pbegin <= (int)pPage->pBt->usableSize-4 );
4753647533
pnext = get2byte(&data[pbegin]);
4753747534
psize = get2byte(&data[pbegin+2]);
4753847535
if( pbegin + psize + 3 >= pnext && pnext>0 ){
4753947536
int frag = pnext - (pbegin+psize);
4754047537
if( (frag<0) || (frag>(int)data[hdr+7]) ){
@@ -51737,11 +51734,11 @@
5173751734
rc = allocateSpace(pPage, sz, &idx);
5173851735
if( rc ){ *pRC = rc; return; }
5173951736
/* The allocateSpace() routine guarantees the following two properties
5174051737
** if it returns success */
5174151738
assert( idx >= end+2 );
51742
- assert( idx+sz <= pPage->pBt->usableSize );
51739
+ assert( idx+sz <= (int)pPage->pBt->usableSize );
5174351740
pPage->nCell++;
5174451741
pPage->nFree -= (u16)(2 + sz);
5174551742
memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
5174651743
if( iChild ){
5174751744
put4byte(&data[idx], iChild);
@@ -51780,11 +51777,12 @@
5178051777
const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
5178151778
const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
5178251779
5178351780
assert( pPage->nOverflow==0 );
5178451781
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
51785
- assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921);
51782
+ assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
51783
+ && (int)MX_CELL(pPage->pBt)<=10921);
5178651784
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5178751785
5178851786
/* Check that the page has just been zeroed by zeroPage() */
5178951787
assert( pPage->nCell==0 );
5179051788
assert( get2byteNotZero(&data[hdr+5])==nUsable );
@@ -51994,11 +51992,11 @@
5199451992
int iData;
5199551993
5199651994
5199751995
assert( pFrom->isInit );
5199851996
assert( pFrom->nFree>=iToHdr );
51999
- assert( get2byte(&aFrom[iFromHdr+5])<=pBt->usableSize );
51997
+ assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize );
5200051998
5200151999
/* Copy the b-tree node content from page pFrom to page pTo. */
5200252000
iData = get2byte(&aFrom[iFromHdr+5]);
5200352001
memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
5200452002
memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell);
@@ -52261,11 +52259,11 @@
5226152259
assert( nCell<nMaxCells );
5226252260
szCell[nCell] = sz;
5226352261
pTemp = &aSpace1[iSpace1];
5226452262
iSpace1 += sz;
5226552263
assert( sz<=pBt->maxLocal+23 );
52266
- assert( iSpace1<=pBt->pageSize );
52264
+ assert( iSpace1 <= (int)pBt->pageSize );
5226752265
memcpy(pTemp, apDiv[i], sz);
5226852266
apCell[nCell] = pTemp+leafCorrection;
5226952267
assert( leafCorrection==0 || leafCorrection==4 );
5227052268
szCell[nCell] = szCell[nCell] - leafCorrection;
5227152269
if( !pOld->leaf ){
@@ -52505,11 +52503,11 @@
5250552503
sz = cellSizePtr(pParent, pCell);
5250652504
}
5250752505
}
5250852506
iOvflSpace += sz;
5250952507
assert( sz<=pBt->maxLocal+23 );
52510
- assert( iOvflSpace<=pBt->pageSize );
52508
+ assert( iOvflSpace <= (int)pBt->pageSize );
5251152509
insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
5251252510
if( rc!=SQLITE_OK ) goto balance_cleanup;
5251352511
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5251452512
5251552513
j++;
@@ -52950,11 +52948,11 @@
5295052948
newCell = pBt->pTmpSpace;
5295152949
if( newCell==0 ) return SQLITE_NOMEM;
5295252950
rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
5295352951
if( rc ) goto end_insert;
5295452952
assert( szNew==cellSizePtr(pPage, newCell) );
52955
- assert( szNew<=MX_CELL_SIZE(pBt) );
52953
+ assert( szNew <= MX_CELL_SIZE(pBt) );
5295652954
idx = pCur->aiIdx[pCur->iPage];
5295752955
if( loc==0 ){
5295852956
u16 szOld;
5295952957
assert( idx<pPage->nCell );
5296052958
rc = sqlite3PagerWrite(pPage->pDbPage);
@@ -53090,11 +53088,11 @@
5309053088
Pgno n = pCur->apPage[iCellDepth+1]->pgno;
5309153089
unsigned char *pTmp;
5309253090
5309353091
pCell = findCell(pLeaf, pLeaf->nCell-1);
5309453092
nCell = cellSizePtr(pLeaf, pCell);
53095
- assert( MX_CELL_SIZE(pBt)>=nCell );
53093
+ assert( MX_CELL_SIZE(pBt) >= nCell );
5309653094
5309753095
allocateTempSpace(pBt);
5309853096
pTmp = pBt->pTmpSpace;
5309953097
5310053098
rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -54784,11 +54782,11 @@
5478454782
&& (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK
5478554783
){
5478654784
int nDestTruncate;
5478754785
5478854786
if( p->pDestDb ){
54789
- sqlite3ResetInternalSchema(p->pDestDb, 0);
54787
+ sqlite3ResetInternalSchema(p->pDestDb, -1);
5479054788
}
5479154789
5479254790
/* Set nDestTruncate to the final number of pages in the destination
5479354791
** database. The complication here is that the destination page
5479454792
** size may be different to the source page size.
@@ -57181,40 +57179,16 @@
5718157179
** The prepared statements need to know in advance the complete set of
5718257180
** attached databases that they will be using. A mask of these databases
5718357181
** is maintained in p->btreeMask and is used for locking and other purposes.
5718457182
*/
5718557183
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
57186
- assert( i>=0 && i<p->db->nDb && i<sizeof(yDbMask)*8 );
57184
+ assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
5718757185
assert( i<(int)sizeof(p->btreeMask)*8 );
5718857186
p->btreeMask |= ((yDbMask)1)<<i;
5718957187
}
5719057188
57191
-/*
57192
-** Compute the sum of all mutex counters for all btrees in the
57193
-** given prepared statement.
57194
-*/
57195
-#ifndef SQLITE_OMIT_SHARED_CACHE
57196
-static u32 mutexCounterSum(Vdbe *p){
57197
- u32 cntSum = 0;
57198
-#ifdef SQLITE_DEBUG
57199
- int i;
57200
- yDbMask mask;
57201
- sqlite3 *db = p->db;
57202
- Db *aDb = db->aDb;
57203
- int nDb = db->nDb;
57204
- for(i=0, mask=1; i<nDb; i++, mask += mask){
57205
- if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57206
- cntSum += sqlite3BtreeMutexCounter(aDb[i].pBt);
57207
- }
57208
- }
57209
-#else
57210
- UNUSED_PARAMETER(p);
57211
-#endif
57212
- return cntSum;
57213
-}
57214
-#endif
57215
-
57189
+#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
5721657190
/*
5721757191
** If SQLite is compiled to support shared-cache mode and to be threadsafe,
5721857192
** this routine obtains the mutex associated with each BtShared structure
5721957193
** that may be accessed by the VM passed as an argument. In doing so it also
5722057194
** sets the BtShared.db member of each of the BtShared structures, ensuring
@@ -57233,11 +57207,10 @@
5723357207
** corresponding to btrees that use shared cache. Then the runtime of
5723457208
** this routine is N*N. But as N is rarely more than 1, this should not
5723557209
** be a problem.
5723657210
*/
5723757211
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
57238
-#ifndef SQLITE_OMIT_SHARED_CACHE
5723957212
int i;
5724057213
yDbMask mask;
5724157214
sqlite3 *db = p->db;
5724257215
Db *aDb = db->aDb;
5724357216
int nDb = db->nDb;
@@ -57244,67 +57217,31 @@
5724457217
for(i=0, mask=1; i<nDb; i++, mask += mask){
5724557218
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
5724657219
sqlite3BtreeEnter(aDb[i].pBt);
5724757220
}
5724857221
}
57249
- p->iMutexCounter = mutexCounterSum(p);
57250
-#else
57251
- UNUSED_PARAMETER(p);
57222
+}
5725257223
#endif
57253
-}
5725457224
57225
+#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
5725557226
/*
5725657227
** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
5725757228
*/
5725857229
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
57259
-#ifndef SQLITE_OMIT_SHARED_CACHE
5726057230
int i;
5726157231
yDbMask mask;
5726257232
sqlite3 *db = p->db;
5726357233
Db *aDb = db->aDb;
5726457234
int nDb = db->nDb;
5726557235
57266
- /* Assert that the all mutexes have been held continously since
57267
- ** the most recent sqlite3VdbeEnter() or sqlite3VdbeMutexResync().
57268
- */
57269
- assert( mutexCounterSum(p) == p->iMutexCounter );
57270
-
5727157236
for(i=0, mask=1; i<nDb; i++, mask += mask){
5727257237
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
5727357238
sqlite3BtreeLeave(aDb[i].pBt);
5727457239
}
5727557240
}
57276
-#else
57277
- UNUSED_PARAMETER(p);
57278
-#endif
57279
-}
57280
-
57281
-/*
57282
-** Recompute the sum of the mutex counters on all btrees used by the
57283
-** prepared statement p.
57284
-**
57285
-** Call this routine while holding a sqlite3VdbeEnter() after doing something
57286
-** that might cause one or more of the individual mutexes held by the
57287
-** prepared statement to be released. Calling sqlite3BtreeEnter() on
57288
-** any BtShared mutex which is not used by the prepared statement is one
57289
-** way to cause one or more of the mutexes in the prepared statement
57290
-** to be temporarily released. The anti-deadlocking logic in
57291
-** sqlite3BtreeEnter() can cause mutexes to be released temporarily then
57292
-** reacquired.
57293
-**
57294
-** Calling this routine is an acknowledgement that some of the individual
57295
-** mutexes in the prepared statement might have been released and reacquired.
57296
-** So checks to verify that mutex-protected content did not change
57297
-** unexpectedly should accompany any call to this routine.
57298
-*/
57299
-SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe *p){
57300
-#if !defined(SQLITE_OMIT_SHARED_CACHE) && defined(SQLITE_DEBUG)
57301
- p->iMutexCounter = mutexCounterSum(p);
57302
-#else
57303
- UNUSED_PARAMETER(p);
57304
-#endif
57305
-}
57241
+}
57242
+#endif
5730657243
5730757244
#if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
5730857245
/*
5730957246
** Print a single opcode. This routine is used for debugging only.
5731057247
*/
@@ -58504,16 +58441,15 @@
5850458441
p->nChange = 0;
5850558442
}
5850658443
5850758444
/* Rollback or commit any schema changes that occurred. */
5850858445
if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
58509
- sqlite3ResetInternalSchema(db, 0);
58446
+ sqlite3ResetInternalSchema(db, -1);
5851058447
db->flags = (db->flags | SQLITE_InternChanges);
5851158448
}
5851258449
5851358450
/* Release the locks */
58514
- sqlite3VdbeMutexResync(p);
5851558451
sqlite3VdbeLeave(p);
5851658452
}
5851758453
5851858454
/* We have successfully halted and closed the VM. Record this fact. */
5851958455
if( p->pc>=0 ){
@@ -60190,11 +60126,15 @@
6019060126
** __attribute__((aligned(8))) macro. */
6019160127
static const Mem nullMem
6019260128
#if defined(SQLITE_DEBUG) && defined(__GNUC__)
6019360129
__attribute__((aligned(8)))
6019460130
#endif
60195
- = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
60131
+ = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0,
60132
+#ifdef SQLITE_DEBUG
60133
+ 0, 0, /* pScopyFrom, pFiller */
60134
+#endif
60135
+ 0, 0 };
6019660136
6019760137
if( pVm && ALWAYS(pVm->db) ){
6019860138
sqlite3_mutex_enter(pVm->db->mutex);
6019960139
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
6020060140
}
@@ -61604,11 +61544,11 @@
6160461544
int pc=0; /* The program counter */
6160561545
Op *aOp = p->aOp; /* Copy of p->aOp */
6160661546
Op *pOp; /* Current operation */
6160761547
int rc = SQLITE_OK; /* Value to return */
6160861548
sqlite3 *db = p->db; /* The database */
61609
- u8 resetSchemaOnFault = 0; /* Reset schema after an error if true */
61549
+ u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
6161061550
u8 encoding = ENC(db); /* The database encoding */
6161161551
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6161261552
int checkProgress; /* True if progress callbacks are enabled */
6161361553
int nProgressOps = 0; /* Opcodes executed since progress callback. */
6161461554
#endif
@@ -62868,11 +62808,10 @@
6286862808
assert( pOp[-1].p4type==P4_COLLSEQ );
6286962809
assert( pOp[-1].opcode==OP_CollSeq );
6287062810
u.ag.ctx.pColl = pOp[-1].p4.pColl;
6287162811
}
6287262812
(*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
62873
- sqlite3VdbeMutexResync(p);
6287462813
if( db->mallocFailed ){
6287562814
/* Even though a malloc() has failed, the implementation of the
6287662815
** user function may have called an sqlite3_result_XXX() function
6287762816
** to return a value. The following call releases any resources
6287862817
** associated with such a value.
@@ -62879,21 +62818,10 @@
6287962818
*/
6288062819
sqlite3VdbeMemRelease(&u.ag.ctx.s);
6288162820
goto no_mem;
6288262821
}
6288362822
62884
- /* The app-defined function has done something that as caused this
62885
- ** statement to expire. (Perhaps the function called sqlite3_exec()
62886
- ** with a CREATE TABLE statement.)
62887
- */
62888
-#if 0
62889
- if( p->expired ){
62890
- rc = SQLITE_ABORT;
62891
- break;
62892
- }
62893
-#endif
62894
-
6289562823
/* If any auxiliary data functions have been called by this user function,
6289662824
** immediately call the destructor for any non-static values.
6289762825
*/
6289862826
if( u.ag.ctx.pVdbeFunc ){
6289962827
sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1);
@@ -62911,10 +62839,19 @@
6291162839
sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding);
6291262840
sqlite3VdbeMemMove(pOut, &u.ag.ctx.s);
6291362841
if( sqlite3VdbeMemTooBig(pOut) ){
6291462842
goto too_big;
6291562843
}
62844
+
62845
+#if 0
62846
+ /* The app-defined function has done something that as caused this
62847
+ ** statement to expire. (Perhaps the function called sqlite3_exec()
62848
+ ** with a CREATE TABLE statement.)
62849
+ */
62850
+ if( p->expired ) rc = SQLITE_ABORT;
62851
+#endif
62852
+
6291662853
REGISTER_TRACE(pOp->p3, pOut);
6291762854
UPDATE_MAX_BLOBSIZE(pOut);
6291862855
break;
6291962856
}
6292062857
@@ -64155,12 +64092,11 @@
6415564092
goto abort_due_to_error;
6415664093
}
6415764094
}
6415864095
if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6415964096
sqlite3ExpirePreparedStatements(db);
64160
- sqlite3ResetInternalSchema(db, 0);
64161
- sqlite3VdbeMutexResync(p);
64097
+ sqlite3ResetInternalSchema(db, -1);
6416264098
db->flags = (db->flags | SQLITE_InternChanges);
6416364099
}
6416464100
}
6416564101
6416664102
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -64384,10 +64320,11 @@
6438464320
assert( pOp->p2<SQLITE_N_BTREE_META );
6438564321
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6438664322
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6438764323
u.au.pDb = &db->aDb[pOp->p1];
6438864324
assert( u.au.pDb->pBt!=0 );
64325
+ assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6438964326
pIn3 = &aMem[pOp->p3];
6439064327
sqlite3VdbeMemIntegerify(pIn3);
6439164328
/* See note about index shifting on OP_ReadCookie */
6439264329
rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i);
6439364330
if( pOp->p2==BTREE_SCHEMA_VERSION ){
@@ -64432,16 +64369,17 @@
6443264369
Btree *pBt;
6443364370
#endif /* local variables moved into u.av */
6443464371
6443564372
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6443664373
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
64374
+ assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6443764375
u.av.pBt = db->aDb[pOp->p1].pBt;
6443864376
if( u.av.pBt ){
6443964377
sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
6444064378
u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6444164379
}else{
64442
- u.av.iMeta = 0;
64380
+ u.av.iGen = u.av.iMeta = 0;
6444364381
}
6444464382
if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){
6444564383
sqlite3DbFree(db, p->zErrMsg);
6444664384
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
6444764385
/* If the schema-cookie from the database file matches the cookie
@@ -64457,11 +64395,10 @@
6445764395
** to be invalidated whenever sqlite3_step() is called from within
6445864396
** a v-table method.
6445964397
*/
6446064398
if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
6446164399
sqlite3ResetInternalSchema(db, pOp->p1);
64462
- sqlite3VdbeMutexResync(p);
6446364400
}
6446464401
6446564402
p->expired = 1;
6446664403
rc = SQLITE_SCHEMA;
6446764404
}
@@ -64544,10 +64481,11 @@
6454464481
u.aw.pDb = &db->aDb[u.aw.iDb];
6454564482
u.aw.pX = u.aw.pDb->pBt;
6454664483
assert( u.aw.pX!=0 );
6454764484
if( pOp->opcode==OP_OpenWrite ){
6454864485
u.aw.wrFlag = 1;
64486
+ assert( sqlite3SchemaMutexHeld(db, u.aw.iDb, 0) );
6454964487
if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){
6455064488
p->minWriteFileFormat = u.aw.pDb->pSchema->file_format;
6455164489
}
6455264490
}else{
6455364491
u.aw.wrFlag = 0;
@@ -66081,12 +66019,14 @@
6608166019
rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
6608266020
pOut->flags = MEM_Int;
6608366021
pOut->u.i = u.br.iMoved;
6608466022
#ifndef SQLITE_OMIT_AUTOVACUUM
6608566023
if( rc==SQLITE_OK && u.br.iMoved!=0 ){
66086
- sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1);
66087
- resetSchemaOnFault = 1;
66024
+ sqlite3RootPageMoved(db, u.br.iDb, u.br.iMoved, pOp->p1);
66025
+ /* All OP_Destroy operations occur on the same btree */
66026
+ assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.br.iDb+1 );
66027
+ resetSchemaOnFault = u.br.iDb+1;
6608866028
}
6608966029
#endif
6609066030
}
6609166031
break;
6609266032
}
@@ -66764,27 +66704,15 @@
6676466704
assert( pOp[-1].p4type==P4_COLLSEQ );
6676566705
assert( pOp[-1].opcode==OP_CollSeq );
6676666706
u.cb.ctx.pColl = pOp[-1].p4.pColl;
6676766707
}
6676866708
(u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */
66769
- sqlite3VdbeMutexResync(p);
6677066709
if( u.cb.ctx.isError ){
6677166710
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
6677266711
rc = u.cb.ctx.isError;
6677366712
}
6677466713
66775
- /* The app-defined function has done something that as caused this
66776
- ** statement to expire. (Perhaps the function called sqlite3_exec()
66777
- ** with a CREATE TABLE statement.)
66778
- */
66779
-#if 0
66780
- if( p->expired ){
66781
- rc = SQLITE_ABORT;
66782
- break;
66783
- }
66784
-#endif
66785
-
6678666714
sqlite3VdbeMemRelease(&u.cb.ctx.s);
6678766715
6678866716
break;
6678966717
}
6679066718
@@ -66806,15 +66734,12 @@
6680666734
#endif /* local variables moved into u.cc */
6680766735
assert( pOp->p1>0 && pOp->p1<=p->nMem );
6680866736
u.cc.pMem = &aMem[pOp->p1];
6680966737
assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
6681066738
rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc);
66811
- sqlite3VdbeMutexResync(p);
6681266739
if( rc ){
6681366740
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem));
66814
- }else if( p->expired ){
66815
- rc = SQLITE_ABORT;
6681666741
}
6681766742
sqlite3VdbeChangeEncoding(u.cc.pMem, encoding);
6681866743
UPDATE_MAX_BLOBSIZE(u.cc.pMem);
6681966744
if( sqlite3VdbeMemTooBig(u.cc.pMem) ){
6682066745
goto too_big;
@@ -66889,28 +66814,10 @@
6688966814
|| u.ce.eNew==PAGER_JOURNALMODE_WAL
6689066815
|| u.ce.eNew==PAGER_JOURNALMODE_QUERY
6689166816
);
6689266817
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6689366818
66894
- /* This opcode is used in two places: PRAGMA journal_mode and ATTACH.
66895
- ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called
66896
- ** when the statement is prepared and so p->btreeMask!=0. All mutexes
66897
- ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree()
66898
- ** is not called when the statement is prepared because it requires the
66899
- ** iDb index of the database as a parameter, and the database has not
66900
- ** yet been attached so that index is unavailable. We have to wait
66901
- ** until runtime (now) to get the mutex on the newly attached database.
66902
- ** No other mutexes are required by the ATTACH command so this is safe
66903
- ** to do.
66904
- */
66905
- if( p->btreeMask==0 ){
66906
- /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed
66907
- ** database. */
66908
- sqlite3VdbeUsesBtree(p, pOp->p1);
66909
- sqlite3VdbeEnter(p);
66910
- }
66911
-
6691266819
u.ce.pBt = db->aDb[pOp->p1].pBt;
6691366820
u.ce.pPager = sqlite3BtreePager(u.ce.pBt);
6691466821
u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager);
6691566822
if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld;
6691666823
if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld;
@@ -67560,13 +67467,12 @@
6756067467
sqlite3_log(rc, "statement aborts at %d: [%s] %s",
6756167468
pc, p->zSql, p->zErrMsg);
6756267469
sqlite3VdbeHalt(p);
6756367470
if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
6756467471
rc = SQLITE_ERROR;
67565
- if( resetSchemaOnFault ){
67566
- sqlite3ResetInternalSchema(db, 0);
67567
- sqlite3VdbeMutexResync(p);
67472
+ if( resetSchemaOnFault>0 ){
67473
+ sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
6756867474
}
6756967475
6757067476
/* This is the only way out of this procedure. We have to
6757167477
** release the mutexes on btrees that were acquired at the
6757267478
** top. */
@@ -72266,11 +72172,11 @@
7226672172
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7226772173
assert( pExpr->u.zToken!=0 );
7226872174
assert( pExpr->u.zToken[0]!=0 );
7226972175
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
7227072176
if( pExpr->u.zToken[1]!=0 ){
72271
- sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, 0);
72177
+ sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT);
7227272178
}
7227372179
break;
7227472180
}
7227572181
case TK_REGISTER: {
7227672182
inReg = pExpr->iTable;
@@ -74655,10 +74561,11 @@
7465574561
return;
7465674562
}
7465774563
assert( sqlite3BtreeHoldsAllMutexes(db) );
7465874564
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7465974565
assert( iDb>=0 );
74566
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7466074567
#ifndef SQLITE_OMIT_AUTHORIZATION
7466174568
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
7466274569
db->aDb[iDb].zName ) ){
7466374570
return;
7466474571
}
@@ -74896,10 +74803,11 @@
7489674803
sqlite3BeginWriteOperation(pParse, 0, iDb);
7489774804
iStatCur = pParse->nTab;
7489874805
pParse->nTab += 2;
7489974806
openStatTable(pParse, iDb, iStatCur, 0, 0);
7490074807
iMem = pParse->nMem+1;
74808
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7490174809
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
7490274810
Table *pTab = (Table*)sqliteHashData(k);
7490374811
analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
7490474812
}
7490574813
loadAnalysis(pParse, iDb);
@@ -75106,13 +75014,13 @@
7510675014
char *zSql;
7510775015
int rc;
7510875016
7510975017
assert( iDb>=0 && iDb<db->nDb );
7511075018
assert( db->aDb[iDb].pBt!=0 );
75111
- assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
7511275019
7511375020
/* Clear any prior statistics */
75021
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7511475022
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
7511575023
Index *pIdx = sqliteHashData(i);
7511675024
sqlite3DefaultRowEst(pIdx);
7511775025
sqlite3DeleteIndexSamples(db, pIdx);
7511875026
pIdx->aSample = 0;
@@ -75421,11 +75329,11 @@
7542175329
if( db->aDb[iDb].pBt ){
7542275330
sqlite3BtreeClose(db->aDb[iDb].pBt);
7542375331
db->aDb[iDb].pBt = 0;
7542475332
db->aDb[iDb].pSchema = 0;
7542575333
}
75426
- sqlite3ResetInternalSchema(db, 0);
75334
+ sqlite3ResetInternalSchema(db, -1);
7542775335
db->nDb = iDb;
7542875336
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
7542975337
db->mallocFailed = 1;
7543075338
sqlite3DbFree(db, zErrDyn);
7543175339
zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -75493,11 +75401,11 @@
7549375401
}
7549475402
7549575403
sqlite3BtreeClose(pDb->pBt);
7549675404
pDb->pBt = 0;
7549775405
pDb->pSchema = 0;
75498
- sqlite3ResetInternalSchema(db, 0);
75406
+ sqlite3ResetInternalSchema(db, -1);
7549975407
return;
7550075408
7550175409
detach_error:
7550275410
sqlite3_result_error(context, zErr, -1);
7550375411
}
@@ -76171,10 +76079,11 @@
7617176079
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
7617276080
if( (mask & pParse->cookieMask)==0 ) continue;
7617376081
sqlite3VdbeUsesBtree(v, iDb);
7617476082
sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
7617576083
if( db->init.busy==0 ){
76084
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7617676085
sqlite3VdbeAddOp3(v, OP_VerifyCookie,
7617776086
iDb, pParse->cookieValue[iDb],
7617876087
db->aDb[iDb].pSchema->iGeneration);
7617976088
}
7618076089
}
@@ -76286,13 +76195,16 @@
7628676195
Table *p = 0;
7628776196
int i;
7628876197
int nName;
7628976198
assert( zName!=0 );
7629076199
nName = sqlite3Strlen30(zName);
76200
+ /* All mutexes are required for schema access. Make sure we hold them. */
76201
+ assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
7629176202
for(i=OMIT_TEMPDB; i<db->nDb; i++){
7629276203
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
7629376204
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
76205
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
7629476206
p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
7629576207
if( p ) break;
7629676208
}
7629776209
return p;
7629876210
}
@@ -76348,15 +76260,18 @@
7634876260
*/
7634976261
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
7635076262
Index *p = 0;
7635176263
int i;
7635276264
int nName = sqlite3Strlen30(zName);
76265
+ /* All mutexes are required for schema access. Make sure we hold them. */
76266
+ assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
7635376267
for(i=OMIT_TEMPDB; i<db->nDb; i++){
7635476268
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
7635576269
Schema *pSchema = db->aDb[j].pSchema;
7635676270
assert( pSchema );
7635776271
if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
76272
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
7635876273
p = sqlite3HashFind(&pSchema->idxHash, zName, nName);
7635976274
if( p ) break;
7636076275
}
7636176276
return p;
7636276277
}
@@ -76379,12 +76294,14 @@
7637976294
** with the index.
7638076295
*/
7638176296
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
7638276297
Index *pIndex;
7638376298
int len;
76384
- Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
76299
+ Hash *pHash;
7638576300
76301
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76302
+ pHash = &db->aDb[iDb].pSchema->idxHash;
7638676303
len = sqlite3Strlen30(zIdxName);
7638776304
pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
7638876305
if( ALWAYS(pIndex) ){
7638976306
if( pIndex->pTable->pIndex==pIndex ){
7639076307
pIndex->pTable->pIndex = pIndex->pNext;
@@ -76408,30 +76325,46 @@
7640876325
** a single database. This routine is called to reclaim memory
7640976326
** before the database closes. It is also called during a rollback
7641076327
** if there were schema changes during the transaction or if a
7641176328
** schema-cookie mismatch occurs.
7641276329
**
76413
-** If iDb==0 then reset the internal schema tables for all database
76414
-** files. If iDb>=1 then reset the internal schema for only the
76330
+** If iDb<0 then reset the internal schema tables for all database
76331
+** files. If iDb>=0 then reset the internal schema for only the
7641576332
** single file indicated.
7641676333
*/
7641776334
SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
7641876335
int i, j;
76419
- assert( iDb>=0 && iDb<db->nDb );
76336
+ assert( iDb<db->nDb );
7642076337
76421
- if( iDb==0 ){
76422
- sqlite3BtreeEnterAll(db);
76338
+ if( iDb>=0 ){
76339
+ /* Case 1: Reset the single schema identified by iDb */
76340
+ Db *pDb = &db->aDb[iDb];
76341
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76342
+ assert( pDb->pSchema!=0 );
76343
+ sqlite3SchemaClear(pDb->pSchema);
76344
+
76345
+ /* If any database other than TEMP is reset, then also reset TEMP
76346
+ ** since TEMP might be holding triggers that reference tables in the
76347
+ ** other database.
76348
+ */
76349
+ if( iDb!=1 ){
76350
+ pDb = &db->aDb[1];
76351
+ assert( pDb->pSchema!=0 );
76352
+ sqlite3SchemaClear(pDb->pSchema);
76353
+ }
76354
+ return;
7642376355
}
76424
- for(i=iDb; i<db->nDb; i++){
76356
+ /* Case 2 (from here to the end): Reset all schemas for all attached
76357
+ ** databases. */
76358
+ assert( iDb<0 );
76359
+ sqlite3BtreeEnterAll(db);
76360
+ for(i=0; i<db->nDb; i++){
7642576361
Db *pDb = &db->aDb[i];
7642676362
if( pDb->pSchema ){
76427
- assert(i==1 || (pDb->pBt && sqlite3BtreeHoldsMutex(pDb->pBt)));
76428
- sqlite3SchemaFree(pDb->pSchema);
76363
+ sqlite3SchemaClear(pDb->pSchema);
7642976364
}
76430
- if( iDb>0 ) return;
7643176365
}
76432
- assert( iDb==0 );
7643376366
db->flags &= ~SQLITE_InternChanges;
7643476367
sqlite3VtabUnlockList(db);
7643576368
sqlite3BtreeLeaveAll(db);
7643676369
7643776370
/* If one or more of the auxiliary database files has been closed,
@@ -76513,10 +76446,11 @@
7651376446
if( !db || db->pnBytesFreed==0 ){
7651476447
char *zName = pIndex->zName;
7651576448
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
7651676449
&pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
7651776450
);
76451
+ assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
7651876452
assert( pOld==pIndex || pOld==0 );
7651976453
}
7652076454
freeIndex(db, pIndex);
7652176455
}
7652276456
@@ -76547,10 +76481,11 @@
7654776481
Db *pDb;
7654876482
7654976483
assert( db!=0 );
7655076484
assert( iDb>=0 && iDb<db->nDb );
7655176485
assert( zTabName );
76486
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7655276487
testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
7655376488
pDb = &db->aDb[iDb];
7655476489
p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
7655576490
sqlite3Strlen30(zTabName),0);
7655676491
sqlite3DeleteTable(db, p);
@@ -76831,10 +76766,11 @@
7683176766
** then record a pointer to this table in the main database structure
7683276767
** so that INSERT can find the table easily.
7683376768
*/
7683476769
#ifndef SQLITE_OMIT_AUTOINCREMENT
7683576770
if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
76771
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7683676772
pTable->pSchema->pSeqTab = pTable;
7683776773
}
7683876774
#endif
7683976775
7684076776
/* Begin generating the code that will insert the table record into
@@ -77291,10 +77227,11 @@
7729177227
*/
7729277228
SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){
7729377229
int r1 = sqlite3GetTempReg(pParse);
7729477230
sqlite3 *db = pParse->db;
7729577231
Vdbe *v = pParse->pVdbe;
77232
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7729677233
sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
7729777234
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1);
7729877235
sqlite3ReleaseTempReg(pParse, r1);
7729977236
}
7730077237
@@ -77398,11 +77335,11 @@
7739877335
sqlite3_snprintf(n-k, &zStmt[k], zSep);
7739977336
k += sqlite3Strlen30(&zStmt[k]);
7740077337
zSep = zSep2;
7740177338
identPut(zStmt, &k, pCol->zName);
7740277339
assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 );
77403
- assert( pCol->affinity-SQLITE_AFF_TEXT < sizeof(azType)/sizeof(azType[0]) );
77340
+ assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) );
7740477341
testcase( pCol->affinity==SQLITE_AFF_TEXT );
7740577342
testcase( pCol->affinity==SQLITE_AFF_NONE );
7740677343
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
7740777344
testcase( pCol->affinity==SQLITE_AFF_INTEGER );
7740877345
testcase( pCol->affinity==SQLITE_AFF_REAL );
@@ -77593,10 +77530,11 @@
7759377530
/* Check to see if we need to create an sqlite_sequence table for
7759477531
** keeping track of autoincrement keys.
7759577532
*/
7759677533
if( p->tabFlags & TF_Autoincrement ){
7759777534
Db *pDb = &db->aDb[iDb];
77535
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7759877536
if( pDb->pSchema->pSeqTab==0 ){
7759977537
sqlite3NestedParse(pParse,
7760077538
"CREATE TABLE %Q.sqlite_sequence(name,seq)",
7760177539
pDb->zName
7760277540
);
@@ -77613,10 +77551,11 @@
7761377551
/* Add the table to the in-memory representation of the database.
7761477552
*/
7761577553
if( db->init.busy ){
7761677554
Table *pOld;
7761777555
Schema *pSchema = p->pSchema;
77556
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7761877557
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
7761977558
sqlite3Strlen30(p->zName),p);
7762077559
if( pOld ){
7762177560
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
7762277561
db->mallocFailed = 1;
@@ -77797,10 +77736,11 @@
7779777736
pTable->nCol = pSelTab->nCol;
7779877737
pTable->aCol = pSelTab->aCol;
7779977738
pSelTab->nCol = 0;
7780077739
pSelTab->aCol = 0;
7780177740
sqlite3DeleteTable(db, pSelTab);
77741
+ assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
7780277742
pTable->pSchema->flags |= DB_UnresetViews;
7780377743
}else{
7780477744
pTable->nCol = 0;
7780577745
nErr++;
7780677746
}
@@ -77817,10 +77757,11 @@
7781777757
/*
7781877758
** Clear the column names from every VIEW in database idx.
7781977759
*/
7782077760
static void sqliteViewResetAll(sqlite3 *db, int idx){
7782177761
HashElem *i;
77762
+ assert( sqlite3SchemaMutexHeld(db, idx, 0) );
7782277763
if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
7782377764
for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
7782477765
Table *pTab = sqliteHashData(i);
7782577766
if( pTab->pSelect ){
7782677767
sqliteDeleteColumnNames(db, pTab);
@@ -77850,14 +77791,17 @@
7785077791
** We must continue looping until all tables and indices with
7785177792
** rootpage==iFrom have been converted to have a rootpage of iTo
7785277793
** in order to be certain that we got the right one.
7785377794
*/
7785477795
#ifndef SQLITE_OMIT_AUTOVACUUM
77855
-SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){
77796
+SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
7785677797
HashElem *pElem;
7785777798
Hash *pHash;
77799
+ Db *pDb;
7785877800
77801
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77802
+ pDb = &db->aDb[iDb];
7785977803
pHash = &pDb->pSchema->tblHash;
7786077804
for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){
7786177805
Table *pTab = sqliteHashData(pElem);
7786277806
if( pTab->tnum==iFrom ){
7786377807
pTab->tnum = iTo;
@@ -78227,10 +78171,11 @@
7822778171
}
7822878172
pFKey->isDeferred = 0;
7822978173
pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
7823078174
pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
7823178175
78176
+ assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
7823278177
pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
7823378178
pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey
7823478179
);
7823578180
if( pNextTo==pFKey ){
7823678181
db->mallocFailed = 1;
@@ -78582,10 +78527,11 @@
7858278527
pIndex->pTable = pTab;
7858378528
pIndex->nColumn = pList->nExpr;
7858478529
pIndex->onError = (u8)onError;
7858578530
pIndex->autoIndex = (u8)(pName==0);
7858678531
pIndex->pSchema = db->aDb[iDb].pSchema;
78532
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7858778533
7858878534
/* Check to see if we should honor DESC requests on index columns
7858978535
*/
7859078536
if( pDb->pSchema->file_format>=4 ){
7859178537
sortOrderMask = -1; /* Honor DESC */
@@ -78711,10 +78657,11 @@
7871178657
/* Link the new Index structure to its table and to the other
7871278658
** in-memory database structures.
7871378659
*/
7871478660
if( db->init.busy ){
7871578661
Index *p;
78662
+ assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
7871678663
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
7871778664
pIndex->zName, sqlite3Strlen30(pIndex->zName),
7871878665
pIndex);
7871978666
if( p ){
7872078667
assert( p==pIndex ); /* Malloc must have failed */
@@ -79464,10 +79411,11 @@
7946479411
yDbMask mask;
7946579412
7946679413
assert( iDb<db->nDb );
7946779414
assert( db->aDb[iDb].pBt!=0 || iDb==1 );
7946879415
assert( iDb<SQLITE_MAX_ATTACHED+2 );
79416
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
7946979417
mask = ((yDbMask)1)<<iDb;
7947079418
if( (pToplevel->cookieMask & mask)==0 ){
7947179419
pToplevel->cookieMask |= mask;
7947279420
pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
7947379421
if( !OMIT_TEMPDB && iDb==1 ){
@@ -79591,10 +79539,11 @@
7959179539
int iDb; /* The database index number */
7959279540
sqlite3 *db = pParse->db; /* The database connection */
7959379541
HashElem *k; /* For looping over tables in pDb */
7959479542
Table *pTab; /* A table in the database */
7959579543
79544
+ assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
7959679545
for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
7959779546
assert( pDb!=0 );
7959879547
for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
7959979548
pTab = (Table*)sqliteHashData(k);
7960079549
reindexTable(pParse, pTab, zColl);
@@ -80109,16 +80058,16 @@
8010980058
}
8011080059
8011180060
/*
8011280061
** Free all resources held by the schema structure. The void* argument points
8011380062
** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
80114
-** pointer itself, it just cleans up subsiduary resources (i.e. the contents
80063
+** pointer itself, it just cleans up subsidiary resources (i.e. the contents
8011580064
** of the schema hash tables).
8011680065
**
8011780066
** The Schema.cache_size variable is not cleared.
8011880067
*/
80119
-SQLITE_PRIVATE void sqlite3SchemaFree(void *p){
80068
+SQLITE_PRIVATE void sqlite3SchemaClear(void *p){
8012080069
Hash temp1;
8012180070
Hash temp2;
8012280071
HashElem *pElem;
8012380072
Schema *pSchema = (Schema *)p;
8012480073
@@ -80149,11 +80098,11 @@
8014980098
** a new one if necessary.
8015080099
*/
8015180100
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
8015280101
Schema * p;
8015380102
if( pBt ){
80154
- p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
80103
+ p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear);
8015580104
}else{
8015680105
p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
8015780106
}
8015880107
if( !p ){
8015980108
db->mallocFailed = 1;
@@ -80183,13 +80132,22 @@
8018380132
** This file contains C code routines that are called by the parser
8018480133
** in order to generate code for DELETE FROM statements.
8018580134
*/
8018680135
8018780136
/*
80188
-** Look up every table that is named in pSrc. If any table is not found,
80189
-** add an error message to pParse->zErrMsg and return NULL. If all tables
80190
-** are found, return a pointer to the last table.
80137
+** While a SrcList can in general represent multiple tables and subqueries
80138
+** (as in the FROM clause of a SELECT statement) in this case it contains
80139
+** the name of a single table, as one might find in an INSERT, DELETE,
80140
+** or UPDATE statement. Look up that table in the symbol table and
80141
+** return a pointer. Set an error message and return NULL if the table
80142
+** name is not found or if any other error occurs.
80143
+**
80144
+** The following fields are initialized appropriate in pSrc:
80145
+**
80146
+** pSrc->a[0].pTab Pointer to the Table object
80147
+** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one
80148
+**
8019180149
*/
8019280150
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
8019380151
struct SrcList_item *pItem = pSrc->a;
8019480152
Table *pTab;
8019580153
assert( pItem && pSrc->nSrc==1 );
@@ -80704,11 +80662,11 @@
8070480662
** fire the INSTEAD OF triggers). */
8070580663
if( pTab->pSelect==0 ){
8070680664
sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
8070780665
sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
8070880666
if( count ){
80709
- sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
80667
+ sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
8071080668
}
8071180669
}
8071280670
8071380671
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
8071480672
** handle rows (possibly in other tables) that refer via a foreign key
@@ -80795,11 +80753,11 @@
8079580753
sqlite3ColumnDefault(v, pTab, idx, -1);
8079680754
}
8079780755
}
8079880756
if( doMakeRec ){
8079980757
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
80800
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
80758
+ sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
8080180759
}
8080280760
sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
8080380761
return regBase;
8080480762
}
8080580763
@@ -82792,11 +82750,11 @@
8279282750
}
8279382751
sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
8279482752
}
8279582753
8279682754
sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
82797
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
82755
+ sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
8279882756
sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
8279982757
8280082758
sqlite3ReleaseTempReg(pParse, regRec);
8280182759
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
8280282760
}
@@ -83548,10 +83506,11 @@
8354883506
*/
8354983507
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
8355083508
FKey *pFKey; /* Iterator variable */
8355183509
FKey *pNext; /* Copy of pFKey->pNextFrom */
8355283510
83511
+ assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
8355383512
for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
8355483513
8355583514
/* Remove the FK from the fkeyHash hash table. */
8355683515
if( !db || db->pnBytesFreed==0 ){
8355783516
if( pFKey->pPrevTo ){
@@ -83707,11 +83666,11 @@
8370783666
zColAff[pTab->nCol] = '\0';
8370883667
8370983668
pTab->zColAff = zColAff;
8371083669
}
8371183670
83712
- sqlite3VdbeChangeP4(v, -1, pTab->zColAff, 0);
83671
+ sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
8371383672
}
8371483673
8371583674
/*
8371683675
** Return non-zero if the table pTab in database iDb or any of its indices
8371783676
** have been opened at any point in the VDBE program beginning at location
@@ -83821,10 +83780,11 @@
8382183780
8382283781
assert( v ); /* We failed long ago if this is not so */
8382383782
for(p = pParse->pAinc; p; p = p->pNext){
8382483783
pDb = &db->aDb[p->iDb];
8382583784
memId = p->regCtr;
83785
+ assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
8382683786
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
8382783787
addr = sqlite3VdbeCurrentAddr(v);
8382883788
sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
8382983789
sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
8383083790
sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
@@ -83871,10 +83831,11 @@
8387183831
int j1, j2, j3, j4, j5;
8387283832
int iRec;
8387383833
int memId = p->regCtr;
8387483834
8387583835
iRec = sqlite3GetTempReg(pParse);
83836
+ assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
8387683837
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
8387783838
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
8387883839
j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
8387983840
j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
8388083841
j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
@@ -84911,11 +84872,11 @@
8491184872
sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i);
8491284873
}
8491384874
}
8491484875
sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
8491584876
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
84916
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
84877
+ sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
8491784878
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
8491884879
8491984880
#ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
8492084881
sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
8492184882
continue; /* Treat pIdx as if it is not a UNIQUE index */
@@ -85057,11 +85018,11 @@
8505785018
if( useSeekResult ){
8505885019
pik_flags |= OPFLAG_USESEEKRESULT;
8505985020
}
8506085021
sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid);
8506185022
if( !pParse->nested ){
85062
- sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
85023
+ sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
8506385024
}
8506485025
sqlite3VdbeChangeP5(v, pik_flags);
8506585026
}
8506685027
8506785028
/*
@@ -86752,11 +86713,11 @@
8675286713
"from within a transaction");
8675386714
return SQLITE_ERROR;
8675486715
}
8675586716
sqlite3BtreeClose(db->aDb[1].pBt);
8675686717
db->aDb[1].pBt = 0;
86757
- sqlite3ResetInternalSchema(db, 0);
86718
+ sqlite3ResetInternalSchema(db, -1);
8675886719
}
8675986720
return SQLITE_OK;
8676086721
}
8676186722
#endif /* SQLITE_PAGER_PRAGMAS */
8676286723
@@ -87025,10 +86986,11 @@
8702586986
}else{
8702686987
int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
8702786988
sqlite3BeginWriteOperation(pParse, 0, iDb);
8702886989
sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
8702986990
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
86991
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
8703086992
pDb->pSchema->cache_size = size;
8703186993
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
8703286994
}
8703386995
}else
8703486996
@@ -87327,10 +87289,11 @@
8732787289
** to its default value when the database is closed and reopened.
8732887290
** N should be a positive integer.
8732987291
*/
8733087292
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
8733187293
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
87294
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
8733287295
if( !zRight ){
8733387296
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
8733487297
}else{
8733587298
int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
8733687299
pDb->pSchema->cache_size = size;
@@ -87747,10 +87710,11 @@
8774787710
/* Do an integrity check of the B-Tree
8774887711
**
8774987712
** Begin by filling registers 2, 3, ... with the root pages numbers
8775087713
** for all tables and indices in the database.
8775187714
*/
87715
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
8775287716
pTbls = &db->aDb[i].pSchema->tblHash;
8775387717
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
8775487718
Table *pTab = sqliteHashData(x);
8775587719
Index *pIdx;
8775687720
sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
@@ -87812,11 +87776,11 @@
8781287776
r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0);
8781387777
jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1);
8781487778
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
8781587779
sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
8781687780
sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
87817
- sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC);
87781
+ sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT);
8781887782
sqlite3VdbeJumpHere(v, addr+9);
8781987783
sqlite3VdbeJumpHere(v, jmp2);
8782087784
}
8782187785
sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
8782287786
sqlite3VdbeJumpHere(v, loopTop);
@@ -87842,11 +87806,11 @@
8784287806
sqlite3VdbeChangeP1(v, addr+3, j+2);
8784387807
sqlite3VdbeChangeP2(v, addr+3, addr+2);
8784487808
sqlite3VdbeJumpHere(v, addr+4);
8784587809
sqlite3VdbeChangeP4(v, addr+6,
8784687810
"wrong # of entries in index ", P4_STATIC);
87847
- sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC);
87811
+ sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_TRANSIENT);
8784887812
}
8784987813
}
8785087814
}
8785187815
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
8785287816
sqlite3VdbeChangeP2(v, addr, -mxErr);
@@ -88498,11 +88462,11 @@
8849888462
}
8849988463
#endif
8850088464
}
8850188465
if( db->mallocFailed ){
8850288466
rc = SQLITE_NOMEM;
88503
- sqlite3ResetInternalSchema(db, 0);
88467
+ sqlite3ResetInternalSchema(db, -1);
8850488468
}
8850588469
if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
8850688470
/* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
8850788471
** the schema loaded, even if errors occurred. In this situation the
8850888472
** current sqlite3_prepare() operation will fail, but the following one
@@ -88630,11 +88594,13 @@
8863088594
8863188595
/* Read the schema cookie from the database. If it does not match the
8863288596
** value stored as part of the in-memory schema representation,
8863388597
** set Parse.rc to SQLITE_SCHEMA. */
8863488598
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
88599
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
8863588600
if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
88601
+ sqlite3ResetInternalSchema(db, iDb);
8863688602
pParse->rc = SQLITE_SCHEMA;
8863788603
}
8863888604
8863988605
/* Close the transaction, if one was opened. */
8864088606
if( openedTransaction ){
@@ -88772,13 +88738,10 @@
8877288738
}
8877388739
if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
8877488740
if( pParse->checkSchema ){
8877588741
schemaIsValid(pParse);
8877688742
}
88777
- if( pParse->rc==SQLITE_SCHEMA ){
88778
- sqlite3ResetInternalSchema(db, 0);
88779
- }
8878088743
if( db->mallocFailed ){
8878188744
pParse->rc = SQLITE_NOMEM;
8878288745
}
8878388746
if( pzTail ){
8878488747
*pzTail = pParse->zTail;
@@ -93735,10 +93698,11 @@
9373593698
return 0;
9373693699
}
9373793700
9373893701
if( pTmpSchema!=pTab->pSchema ){
9373993702
HashElem *p;
93703
+ assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
9374093704
for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
9374193705
Trigger *pTrig = (Trigger *)sqliteHashData(p);
9374293706
if( pTrig->pTabSchema==pTab->pSchema
9374393707
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName)
9374493708
){
@@ -93846,10 +93810,11 @@
9384693810
** specified name exists */
9384793811
zName = sqlite3NameFromToken(db, pName);
9384893812
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
9384993813
goto trigger_cleanup;
9385093814
}
93815
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9385193816
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
9385293817
zName, sqlite3Strlen30(zName)) ){
9385393818
if( !noErr ){
9385493819
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
9385593820
}
@@ -93985,10 +93950,11 @@
9398593950
}
9398693951
9398793952
if( db->init.busy ){
9398893953
Trigger *pLink = pTrig;
9398993954
Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
93955
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9399093956
pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);
9399193957
if( pTrig ){
9399293958
db->mallocFailed = 1;
9399393959
}else if( pLink->pSchema==pLink->pTabSchema ){
9399493960
Table *pTab;
@@ -94166,13 +94132,15 @@
9416694132
9416794133
assert( pName->nSrc==1 );
9416894134
zDb = pName->a[0].zDatabase;
9416994135
zName = pName->a[0].zName;
9417094136
nName = sqlite3Strlen30(zName);
94137
+ assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
9417194138
for(i=OMIT_TEMPDB; i<db->nDb; i++){
9417294139
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
9417394140
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
94141
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
9417494142
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
9417594143
if( pTrigger ) break;
9417694144
}
9417794145
if( !pTrigger ){
9417894146
if( !noErr ){
@@ -94242,11 +94210,11 @@
9424294210
};
9424394211
9424494212
sqlite3BeginWriteOperation(pParse, 0, iDb);
9424594213
sqlite3OpenMasterTable(pParse, iDb);
9424694214
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
94247
- sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, 0);
94215
+ sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
9424894216
sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
9424994217
sqlite3ChangeCookie(pParse, iDb);
9425094218
sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
9425194219
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
9425294220
if( pParse->nMem<3 ){
@@ -94257,12 +94225,15 @@
9425794225
9425894226
/*
9425994227
** Remove a trigger from the hash tables of the sqlite* pointer.
9426094228
*/
9426194229
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
94262
- Hash *pHash = &(db->aDb[iDb].pSchema->trigHash);
9426394230
Trigger *pTrigger;
94231
+ Hash *pHash;
94232
+
94233
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94234
+ pHash = &(db->aDb[iDb].pSchema->trigHash);
9426494235
pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0);
9426594236
if( ALWAYS(pTrigger) ){
9426694237
if( pTrigger->pSchema==pTrigger->pTabSchema ){
9426794238
Table *pTab = tableOfTrigger(pTrigger);
9426894239
Trigger **pp;
@@ -95782,14 +95753,17 @@
9578295753
sqlite3BtreeClose(pDb->pBt);
9578395754
pDb->pBt = 0;
9578495755
pDb->pSchema = 0;
9578595756
}
9578695757
95787
- sqlite3ResetInternalSchema(db, 0);
95758
+ /* This both clears the schemas and reduces the size of the db->aDb[]
95759
+ ** array. */
95760
+ sqlite3ResetInternalSchema(db, -1);
9578895761
9578995762
return rc;
9579095763
}
95764
+
9579195765
#endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
9579295766
9579395767
/************** End of vacuum.c **********************************************/
9579495768
/************** Begin file vtab.c ********************************************/
9579595769
/*
@@ -95839,11 +95813,11 @@
9583995813
}
9584095814
sqlite3DbFree(db, pDel);
9584195815
if( pDel==pMod ){
9584295816
db->mallocFailed = 1;
9584395817
}
95844
- sqlite3ResetInternalSchema(db, 0);
95818
+ sqlite3ResetInternalSchema(db, -1);
9584595819
}else if( xDestroy ){
9584695820
xDestroy(pAux);
9584795821
}
9584895822
rc = sqlite3ApiExit(db, SQLITE_OK);
9584995823
sqlite3_mutex_leave(db->mutex);
@@ -95936,14 +95910,13 @@
9593695910
9593795911
/* Assert that the mutex (if any) associated with the BtShared database
9593895912
** that contains table p is held by the caller. See header comments
9593995913
** above function sqlite3VtabUnlockList() for an explanation of why
9594095914
** this makes it safe to access the sqlite3.pDisconnect list of any
95941
- ** database connection that may have an entry in the p->pVTable list. */
95942
- assert( db==0 ||
95943
- sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt)
95944
- );
95915
+ ** database connection that may have an entry in the p->pVTable list.
95916
+ */
95917
+ assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
9594595918
9594695919
while( pVTable ){
9594795920
sqlite3 *db2 = pVTable->db;
9594895921
VTable *pNext = pVTable->pNext;
9594995922
assert( db2 );
@@ -96178,10 +96151,11 @@
9617896151
else {
9617996152
Table *pOld;
9618096153
Schema *pSchema = pTab->pSchema;
9618196154
const char *zName = pTab->zName;
9618296155
int nName = sqlite3Strlen30(zName);
96156
+ assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
9618396157
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
9618496158
if( pOld ){
9618596159
db->mallocFailed = 1;
9618696160
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
9618796161
return;
@@ -97132,11 +97106,11 @@
9713297106
** Return the bitmask for the given cursor number. Return 0 if
9713397107
** iCursor is not in the set.
9713497108
*/
9713597109
static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){
9713697110
int i;
97137
- assert( pMaskSet->n<=sizeof(Bitmask)*8 );
97111
+ assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 );
9713897112
for(i=0; i<pMaskSet->n; i++){
9713997113
if( pMaskSet->ix[i]==iCursor ){
9714097114
return ((Bitmask)1)<<i;
9714197115
}
9714297116
}
@@ -107007,11 +106981,12 @@
107007106981
if( !sqlite3SafetyCheckSickOrOk(db) ){
107008106982
return SQLITE_MISUSE_BKPT;
107009106983
}
107010106984
sqlite3_mutex_enter(db->mutex);
107011106985
107012
- sqlite3ResetInternalSchema(db, 0);
106986
+ /* Force xDestroy calls on all virtual tables */
106987
+ sqlite3ResetInternalSchema(db, -1);
107013106988
107014106989
/* If a transaction is open, the ResetInternalSchema() call above
107015106990
** will not have called the xDisconnect() method on any virtual
107016106991
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
107017106992
** call will do so. We need to do this before the check for active
@@ -107050,11 +107025,11 @@
107050107025
if( j!=1 ){
107051107026
pDb->pSchema = 0;
107052107027
}
107053107028
}
107054107029
}
107055
- sqlite3ResetInternalSchema(db, 0);
107030
+ sqlite3ResetInternalSchema(db, -1);
107056107031
107057107032
/* Tell the code in notify.c that the connection no longer holds any
107058107033
** locks and does not require any further unlock-notify callbacks.
107059107034
*/
107060107035
sqlite3ConnectionClosed(db);
@@ -107141,11 +107116,11 @@
107141107116
sqlite3VtabRollback(db);
107142107117
sqlite3EndBenignMalloc();
107143107118
107144107119
if( db->flags&SQLITE_InternChanges ){
107145107120
sqlite3ExpirePreparedStatements(db);
107146
- sqlite3ResetInternalSchema(db, 0);
107121
+ sqlite3ResetInternalSchema(db, -1);
107147107122
}
107148107123
107149107124
/* Any deferred constraint violations have now been resolved. */
107150107125
db->nDeferredCons = 0;
107151107126
@@ -107210,11 +107185,11 @@
107210107185
#if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
107211107186
static const u8 delays[] =
107212107187
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
107213107188
static const u8 totals[] =
107214107189
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
107215
-# define NDELAY (sizeof(delays)/sizeof(delays[0]))
107190
+# define NDELAY ArraySize(delays)
107216107191
sqlite3 *db = (sqlite3 *)ptr;
107217107192
int timeout = db->busyTimeout;
107218107193
int delay, prior;
107219107194
107220107195
assert( count>=0 );
@@ -113734,10 +113709,12 @@
113734113709
int nDb; /* Result of strlen(zDb) */
113735113710
int nFts3; /* Result of strlen(zFts3) */
113736113711
int nByte; /* Bytes of space to allocate here */
113737113712
int rc; /* value returned by declare_vtab() */
113738113713
Fts3auxTable *p; /* Virtual table object to return */
113714
+
113715
+ UNUSED_PARAMETER(pUnused);
113739113716
113740113717
/* The user should specify a single argument - the name of an fts3 table. */
113741113718
if( argc!=4 ){
113742113719
*pzErr = sqlite3_mprintf(
113743113720
"wrong number of arguments to fts4aux constructor"
@@ -113803,10 +113780,12 @@
113803113780
){
113804113781
int i;
113805113782
int iEq = -1;
113806113783
int iGe = -1;
113807113784
int iLe = -1;
113785
+
113786
+ UNUSED_PARAMETER(pVTab);
113808113787
113809113788
/* This vtab delivers always results in "ORDER BY term ASC" order. */
113810113789
if( pInfo->nOrderBy==1
113811113790
&& pInfo->aOrderBy[0].iColumn==0
113812113791
&& pInfo->aOrderBy[0].desc==0
@@ -113851,10 +113830,12 @@
113851113830
/*
113852113831
** xOpen - Open a cursor.
113853113832
*/
113854113833
static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
113855113834
Fts3auxCursor *pCsr; /* Pointer to cursor object to return */
113835
+
113836
+ UNUSED_PARAMETER(pVTab);
113856113837
113857113838
pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor));
113858113839
if( !pCsr ) return SQLITE_NOMEM;
113859113840
memset(pCsr, 0, sizeof(Fts3auxCursor));
113860113841
@@ -114000,10 +113981,12 @@
114000113981
){
114001113982
Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor;
114002113983
Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
114003113984
int rc;
114004113985
int isScan;
113986
+
113987
+ UNUSED_PARAMETER(nVal);
114005113988
114006113989
assert( idxStr==0 );
114007113990
assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
114008113991
|| idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
114009113992
|| idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -122428,11 +122411,11 @@
122428122411
pCsr->nConstraint = argc;
122429122412
if( !pCsr->aConstraint ){
122430122413
rc = SQLITE_NOMEM;
122431122414
}else{
122432122415
memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
122433
- assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 );
122416
+ assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 );
122434122417
for(ii=0; ii<argc; ii++){
122435122418
RtreeConstraint *p = &pCsr->aConstraint[ii];
122436122419
p->op = idxStr[ii*2];
122437122420
p->iCoord = idxStr[ii*2+1]-'a';
122438122421
if( p->op==RTREE_MATCH ){
@@ -122521,11 +122504,11 @@
122521122504
char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
122522122505
memset(zIdxStr, 0, sizeof(zIdxStr));
122523122506
UNUSED_PARAMETER(tab);
122524122507
122525122508
assert( pIdxInfo->idxStr==0 );
122526
- for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){
122509
+ for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
122527122510
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
122528122511
122529122512
if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
122530122513
/* We have an equality constraint on the rowid. Use strategy 1. */
122531122514
int jj;
@@ -124644,10 +124627,12 @@
124644124627
static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
124645124628
UErrorCode status = U_ZERO_ERROR;
124646124629
URegularExpression *pExpr;
124647124630
UBool res;
124648124631
const UChar *zString = sqlite3_value_text16(apArg[1]);
124632
+
124633
+ (void)nArg; /* Unused parameter */
124649124634
124650124635
/* If the left hand side of the regexp operator is NULL,
124651124636
** then the result is also NULL.
124652124637
*/
124653124638
if( !zString ){
@@ -124873,11 +124858,11 @@
124873124858
};
124874124859
124875124860
int rc = SQLITE_OK;
124876124861
int i;
124877124862
124878
- for(i=0; rc==SQLITE_OK && i<(sizeof(scalars)/sizeof(struct IcuScalar)); i++){
124863
+ for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
124879124864
struct IcuScalar *p = &scalars[i];
124880124865
rc = sqlite3_create_function(
124881124866
db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
124882124867
);
124883124868
}
124884124869
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1675,11 +1675,11 @@
1675 ** changes to a [database connection]. The interface is similar to
1676 ** [sqlite3_config()] except that the changes apply to a single
1677 ** [database connection] (specified in the first argument).
1678 **
1679 ** The second argument to sqlite3_db_config(D,V,...) is the
1680 ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1681 ** that indicates what aspect of the [database connection] is being configured.
1682 ** Subsequent arguments vary depending on the configuration verb.
1683 **
1684 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1685 ** the call is considered successful.
@@ -7833,22 +7833,22 @@
7833 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*);
7834 #ifndef NDEBUG
7835 /* These routines are used inside assert() statements only. */
7836 SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*);
7837 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*);
7838 SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree*);
7839 #endif
7840 #else
7841
7842 # define sqlite3BtreeLeave(X)
7843 # define sqlite3BtreeMutexCounter(X) 0
7844 # define sqlite3BtreeEnterCursor(X)
7845 # define sqlite3BtreeLeaveCursor(X)
7846 # define sqlite3BtreeLeaveAll(X)
7847
7848 # define sqlite3BtreeHoldsMutex(X) 1
7849 # define sqlite3BtreeHoldsAllMutexes(X) 1
 
7850 #endif
7851
7852
7853 #endif /* _BTREE_H_ */
7854
@@ -7963,11 +7963,11 @@
7963 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
7964 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
7965 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
7966 #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
7967 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
7968 #define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */
7969 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
7970 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
7971 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
7972 #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
7973 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
@@ -8998,10 +8998,24 @@
8998 Schema *pSchema; /* Pointer to database schema (possibly shared) */
8999 };
9000
9001 /*
9002 ** An instance of the following structure stores a database schema.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9003 */
9004 struct Schema {
9005 int schema_cookie; /* Database schema version number for this file */
9006 int iGeneration; /* Generation counter. Incremented with each change */
9007 Hash tblHash; /* All tables indexed by name */
@@ -9514,11 +9528,11 @@
9514 ** implementation. sqlite3_vtab* handles can not be shared between
9515 ** database connections, even when the rest of the in-memory database
9516 ** schema is shared, as the implementation often stores the database
9517 ** connection handle passed to it via the xConnect() or xCreate() method
9518 ** during initialization internally. This database connection handle may
9519 ** then used by the virtual table implementation to access real tables
9520 ** within the database. So that they appear as part of the callers
9521 ** transaction, these accesses need to be made via the same database
9522 ** connection as that used to execute SQL operations on the virtual table.
9523 **
9524 ** All VTable objects that correspond to a single table in a shared
@@ -11272,11 +11286,11 @@
11272 SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
11273 #ifndef SQLITE_OMIT_WSD
11274 SQLITE_PRIVATE int sqlite3PendingByte;
11275 #endif
11276 #endif
11277 SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
11278 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
11279 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
11280 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
11281 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
11282 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
@@ -11299,11 +11313,11 @@
11299 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
11300 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
11301 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
11302 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
11303 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
11304 SQLITE_PRIVATE void sqlite3SchemaFree(void *);
11305 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
11306 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11307 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
11308 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
11309 void (*)(sqlite3_context*,int,sqlite3_value **),
@@ -12479,11 +12493,10 @@
12479 u8 usesStmtJournal; /* True if uses a statement journal */
12480 u8 readOnly; /* True for read-only statements */
12481 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12482 int nChange; /* Number of db changes made since last reset */
12483 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
12484 u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */
12485 int iStatement; /* Statement number (or 0 if has not opened stmt) */
12486 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12487 #ifndef SQLITE_OMIT_TRACE
12488 i64 startTime; /* Time when query started - used for profiling */
12489 #endif
@@ -12563,13 +12576,18 @@
12563 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12564 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12565 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12566 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12567 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12568 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
12569 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
12570 SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe*);
 
 
 
 
 
12571
12572 #ifdef SQLITE_DEBUG
12573 SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);
12574 #endif
12575
@@ -12742,10 +12760,11 @@
12742 */
12743 case SQLITE_DBSTATUS_SCHEMA_USED: {
12744 int i; /* Used to iterate through schemas */
12745 int nByte = 0; /* Used to accumulate return value */
12746
 
12747 db->pnBytesFreed = &nByte;
12748 for(i=0; i<db->nDb; i++){
12749 Schema *pSchema = db->aDb[i].pSchema;
12750 if( ALWAYS(pSchema!=0) ){
12751 HashElem *p;
@@ -12768,10 +12787,11 @@
12768 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12769 }
12770 }
12771 }
12772 db->pnBytesFreed = 0;
 
12773
12774 *pHighwater = 0;
12775 *pCurrent = nByte;
12776 break;
12777 }
@@ -15879,11 +15899,11 @@
15879 ** Space for tracking which blocks are checked out and the size
15880 ** of each block. One byte per block.
15881 */
15882 u8 *aCtrl;
15883
15884 } mem5 = { 0 };
15885
15886 /*
15887 ** Access the static variable through a macro for SQLITE_OMIT_WSD
15888 */
15889 #define mem5 GLOBAL(struct Mem5Global, mem5)
@@ -16194,11 +16214,11 @@
16194 ** memsys5Log(8) -> 3
16195 ** memsys5Log(9) -> 4
16196 */
16197 static int memsys5Log(int iValue){
16198 int iLog;
16199 for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
16200 return iLog;
16201 }
16202
16203 /*
16204 ** Initialize the memory allocator.
@@ -18064,11 +18084,11 @@
18064 pSlot = (ScratchFreeslot*)p;
18065 sqlite3_mutex_enter(mem0.mutex);
18066 pSlot->pNext = mem0.pScratchFree;
18067 mem0.pScratchFree = pSlot;
18068 mem0.nScratchFree++;
18069 assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch );
18070 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
18071 sqlite3_mutex_leave(mem0.mutex);
18072 }else{
18073 /* Release memory back to the heap */
18074 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
@@ -38547,10 +38567,23 @@
38547 /* Verify that the page list is in accending order */
38548 for(p=pList; p && p->pDirty; p=p->pDirty){
38549 assert( p->pgno < p->pDirty->pgno );
38550 }
38551 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
38552
38553 if( pList->pgno==1 ) pager_write_changecounter(pList);
38554 rc = sqlite3WalFrames(pPager->pWal,
38555 pPager->pageSize, pList, nTruncate, isCommit, syncFlags
38556 );
@@ -38560,10 +38593,11 @@
38560 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
38561 }
38562 }
38563
38564 #ifdef SQLITE_CHECK_PAGES
 
38565 for(p=pList; p; p=p->pDirty){
38566 pager_set_pagehash(p);
38567 }
38568 #endif
38569
@@ -45510,11 +45544,11 @@
45510
45511
45512 /* The following value is the maximum cell size assuming a maximum page
45513 ** size give above.
45514 */
45515 #define MX_CELL_SIZE(pBt) (pBt->pageSize-8)
45516
45517 /* The maximum number of cells on a single page of the database. This
45518 ** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself
45519 ** plus 2 bytes for the index to the cell in the page header). Such
45520 ** small cells will be rare, but they are possible.
@@ -45727,11 +45761,10 @@
45727 BtShared *pNext; /* Next on a list of sharable BtShared structs */
45728 BtLock *pLock; /* List of locks held on this shared-btree struct */
45729 Btree *pWriter; /* Btree with currently open write transaction */
45730 u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
45731 u8 isPending; /* If waiting for read-locks to clear */
45732 u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */
45733 #endif
45734 u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
45735 };
45736
45737 /*
@@ -45966,32 +45999,14 @@
45966 assert( p->locked==1 );
45967 assert( sqlite3_mutex_held(pBt->mutex) );
45968 assert( sqlite3_mutex_held(p->db->mutex) );
45969 assert( p->db==pBt->db );
45970
45971 pBt->iMutexCounter++;
45972 sqlite3_mutex_leave(pBt->mutex);
45973 p->locked = 0;
45974 }
45975
45976 #ifdef SQLITE_DEBUG
45977 /*
45978 ** Return the number of times that the mutex has been exited for
45979 ** the given btree.
45980 **
45981 ** This is a small circular counter that wraps around to zero on
45982 ** overflow. It is used only for sanity checking - to verify that
45983 ** mutexes are held continously by asserting that the value of
45984 ** this counter at the beginning of a region is the same as at
45985 ** the end.
45986 */
45987 SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree *p){
45988 assert( p->locked==1 || p->sharable==0 );
45989 return p->pBt->iMutexCounter;
45990 }
45991 #endif
45992
45993 /*
45994 ** Enter a mutex on the given BTree object.
45995 **
45996 ** If the object is not sharable, then no mutex is ever required
45997 ** and this routine is a no-op. The underlying mutex is non-recursive.
@@ -46032,28 +46047,10 @@
46032
46033 if( !p->sharable ) return;
46034 p->wantToLock++;
46035 if( p->locked ) return;
46036
46037 /* Increment the mutex counter on all locked btrees in the same
46038 ** database connection. This simulates the unlocking that would
46039 ** occur on a worst-case mutex dead-lock avoidance scenario.
46040 */
46041 #ifdef SQLITE_DEBUG
46042 {
46043 int ii;
46044 sqlite3 *db = p->db;
46045 Btree *pOther;
46046 for(ii=0; ii<db->nDb; ii++){
46047 if( ii==1 ) continue;
46048 pOther = db->aDb[ii].pBt;
46049 if( pOther==0 || pOther->sharable==0 || pOther->locked==0 ) continue;
46050 pOther->pBt->iMutexCounter++;
46051 }
46052 }
46053 #endif
46054
46055 /* In most cases, we should be able to acquire the lock we
46056 ** want without having to go throught the ascending lock
46057 ** procedure that follows. Just be sure not to block.
46058 */
46059 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
@@ -46143,49 +46140,24 @@
46143 ** two or more btrees in common both try to lock all their btrees
46144 ** at the same instant.
46145 */
46146 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
46147 int i;
46148 Btree *p, *pLater;
46149 assert( sqlite3_mutex_held(db->mutex) );
46150 for(i=0; i<db->nDb; i++){
46151 p = db->aDb[i].pBt;
46152 assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db );
46153 if( p && p->sharable ){
46154 p->wantToLock++;
46155 if( !p->locked ){
46156 assert( p->wantToLock==1 );
46157 while( p->pPrev ) p = p->pPrev;
46158 /* Reason for ALWAYS: There must be at least one unlocked Btree in
46159 ** the chain. Otherwise the !p->locked test above would have failed */
46160 while( p->locked && ALWAYS(p->pNext) ) p = p->pNext;
46161 for(pLater = p->pNext; pLater; pLater=pLater->pNext){
46162 if( pLater->locked ){
46163 unlockBtreeMutex(pLater);
46164 }
46165 }
46166 while( p ){
46167 lockBtreeMutex(p);
46168 p = p->pNext;
46169 }
46170 }
46171 }
46172 }
46173 }
46174 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
46175 int i;
46176 Btree *p;
46177 assert( sqlite3_mutex_held(db->mutex) );
46178 for(i=0; i<db->nDb; i++){
46179 p = db->aDb[i].pBt;
46180 if( p && p->sharable ){
46181 assert( p->wantToLock>0 );
46182 p->wantToLock--;
46183 if( p->wantToLock==0 ){
46184 unlockBtreeMutex(p);
46185 }
46186 }
46187 }
46188 }
46189
46190 #ifndef NDEBUG
46191 /*
@@ -46209,10 +46181,35 @@
46209 }
46210 return 1;
46211 }
46212 #endif /* NDEBUG */
46213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46214 #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
46215 /*
46216 ** The following are special cases for mutex enter routines for use
46217 ** in single threaded applications that use shared cache. Except for
46218 ** these two routines, all mutex operations are no-ops in that case and
@@ -47466,11 +47463,11 @@
47466 ** is no way that the allocation can extend off the end of the page.
47467 ** The assert() below verifies the previous sentence.
47468 */
47469 top -= nByte;
47470 put2byte(&data[hdr+5], top);
47471 assert( top+nByte <= pPage->pBt->usableSize );
47472 *pIdx = top;
47473 return SQLITE_OK;
47474 }
47475
47476 /*
@@ -47487,11 +47484,11 @@
47487 unsigned char *data = pPage->aData;
47488
47489 assert( pPage->pBt!=0 );
47490 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
47491 assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
47492 assert( (start + size)<=pPage->pBt->usableSize );
47493 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
47494 assert( size>=0 ); /* Minimum cell size is 4 */
47495
47496 if( pPage->pBt->secureDelete ){
47497 /* Overwrite deleted information with zeros when the secure_delete
@@ -47530,11 +47527,11 @@
47530 /* Coalesce adjacent free blocks */
47531 addr = hdr + 1;
47532 while( (pbegin = get2byte(&data[addr]))>0 ){
47533 int pnext, psize, x;
47534 assert( pbegin>addr );
47535 assert( pbegin<=pPage->pBt->usableSize-4 );
47536 pnext = get2byte(&data[pbegin]);
47537 psize = get2byte(&data[pbegin+2]);
47538 if( pbegin + psize + 3 >= pnext && pnext>0 ){
47539 int frag = pnext - (pbegin+psize);
47540 if( (frag<0) || (frag>(int)data[hdr+7]) ){
@@ -51737,11 +51734,11 @@
51737 rc = allocateSpace(pPage, sz, &idx);
51738 if( rc ){ *pRC = rc; return; }
51739 /* The allocateSpace() routine guarantees the following two properties
51740 ** if it returns success */
51741 assert( idx >= end+2 );
51742 assert( idx+sz <= pPage->pBt->usableSize );
51743 pPage->nCell++;
51744 pPage->nFree -= (u16)(2 + sz);
51745 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
51746 if( iChild ){
51747 put4byte(&data[idx], iChild);
@@ -51780,11 +51777,12 @@
51780 const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
51781 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
51782
51783 assert( pPage->nOverflow==0 );
51784 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
51785 assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921);
 
51786 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
51787
51788 /* Check that the page has just been zeroed by zeroPage() */
51789 assert( pPage->nCell==0 );
51790 assert( get2byteNotZero(&data[hdr+5])==nUsable );
@@ -51994,11 +51992,11 @@
51994 int iData;
51995
51996
51997 assert( pFrom->isInit );
51998 assert( pFrom->nFree>=iToHdr );
51999 assert( get2byte(&aFrom[iFromHdr+5])<=pBt->usableSize );
52000
52001 /* Copy the b-tree node content from page pFrom to page pTo. */
52002 iData = get2byte(&aFrom[iFromHdr+5]);
52003 memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
52004 memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell);
@@ -52261,11 +52259,11 @@
52261 assert( nCell<nMaxCells );
52262 szCell[nCell] = sz;
52263 pTemp = &aSpace1[iSpace1];
52264 iSpace1 += sz;
52265 assert( sz<=pBt->maxLocal+23 );
52266 assert( iSpace1<=pBt->pageSize );
52267 memcpy(pTemp, apDiv[i], sz);
52268 apCell[nCell] = pTemp+leafCorrection;
52269 assert( leafCorrection==0 || leafCorrection==4 );
52270 szCell[nCell] = szCell[nCell] - leafCorrection;
52271 if( !pOld->leaf ){
@@ -52505,11 +52503,11 @@
52505 sz = cellSizePtr(pParent, pCell);
52506 }
52507 }
52508 iOvflSpace += sz;
52509 assert( sz<=pBt->maxLocal+23 );
52510 assert( iOvflSpace<=pBt->pageSize );
52511 insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
52512 if( rc!=SQLITE_OK ) goto balance_cleanup;
52513 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
52514
52515 j++;
@@ -52950,11 +52948,11 @@
52950 newCell = pBt->pTmpSpace;
52951 if( newCell==0 ) return SQLITE_NOMEM;
52952 rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
52953 if( rc ) goto end_insert;
52954 assert( szNew==cellSizePtr(pPage, newCell) );
52955 assert( szNew<=MX_CELL_SIZE(pBt) );
52956 idx = pCur->aiIdx[pCur->iPage];
52957 if( loc==0 ){
52958 u16 szOld;
52959 assert( idx<pPage->nCell );
52960 rc = sqlite3PagerWrite(pPage->pDbPage);
@@ -53090,11 +53088,11 @@
53090 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
53091 unsigned char *pTmp;
53092
53093 pCell = findCell(pLeaf, pLeaf->nCell-1);
53094 nCell = cellSizePtr(pLeaf, pCell);
53095 assert( MX_CELL_SIZE(pBt)>=nCell );
53096
53097 allocateTempSpace(pBt);
53098 pTmp = pBt->pTmpSpace;
53099
53100 rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -54784,11 +54782,11 @@
54784 && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK
54785 ){
54786 int nDestTruncate;
54787
54788 if( p->pDestDb ){
54789 sqlite3ResetInternalSchema(p->pDestDb, 0);
54790 }
54791
54792 /* Set nDestTruncate to the final number of pages in the destination
54793 ** database. The complication here is that the destination page
54794 ** size may be different to the source page size.
@@ -57181,40 +57179,16 @@
57181 ** The prepared statements need to know in advance the complete set of
57182 ** attached databases that they will be using. A mask of these databases
57183 ** is maintained in p->btreeMask and is used for locking and other purposes.
57184 */
57185 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
57186 assert( i>=0 && i<p->db->nDb && i<sizeof(yDbMask)*8 );
57187 assert( i<(int)sizeof(p->btreeMask)*8 );
57188 p->btreeMask |= ((yDbMask)1)<<i;
57189 }
57190
57191 /*
57192 ** Compute the sum of all mutex counters for all btrees in the
57193 ** given prepared statement.
57194 */
57195 #ifndef SQLITE_OMIT_SHARED_CACHE
57196 static u32 mutexCounterSum(Vdbe *p){
57197 u32 cntSum = 0;
57198 #ifdef SQLITE_DEBUG
57199 int i;
57200 yDbMask mask;
57201 sqlite3 *db = p->db;
57202 Db *aDb = db->aDb;
57203 int nDb = db->nDb;
57204 for(i=0, mask=1; i<nDb; i++, mask += mask){
57205 if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57206 cntSum += sqlite3BtreeMutexCounter(aDb[i].pBt);
57207 }
57208 }
57209 #else
57210 UNUSED_PARAMETER(p);
57211 #endif
57212 return cntSum;
57213 }
57214 #endif
57215
57216 /*
57217 ** If SQLite is compiled to support shared-cache mode and to be threadsafe,
57218 ** this routine obtains the mutex associated with each BtShared structure
57219 ** that may be accessed by the VM passed as an argument. In doing so it also
57220 ** sets the BtShared.db member of each of the BtShared structures, ensuring
@@ -57233,11 +57207,10 @@
57233 ** corresponding to btrees that use shared cache. Then the runtime of
57234 ** this routine is N*N. But as N is rarely more than 1, this should not
57235 ** be a problem.
57236 */
57237 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
57238 #ifndef SQLITE_OMIT_SHARED_CACHE
57239 int i;
57240 yDbMask mask;
57241 sqlite3 *db = p->db;
57242 Db *aDb = db->aDb;
57243 int nDb = db->nDb;
@@ -57244,67 +57217,31 @@
57244 for(i=0, mask=1; i<nDb; i++, mask += mask){
57245 if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57246 sqlite3BtreeEnter(aDb[i].pBt);
57247 }
57248 }
57249 p->iMutexCounter = mutexCounterSum(p);
57250 #else
57251 UNUSED_PARAMETER(p);
57252 #endif
57253 }
57254
 
57255 /*
57256 ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
57257 */
57258 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
57259 #ifndef SQLITE_OMIT_SHARED_CACHE
57260 int i;
57261 yDbMask mask;
57262 sqlite3 *db = p->db;
57263 Db *aDb = db->aDb;
57264 int nDb = db->nDb;
57265
57266 /* Assert that the all mutexes have been held continously since
57267 ** the most recent sqlite3VdbeEnter() or sqlite3VdbeMutexResync().
57268 */
57269 assert( mutexCounterSum(p) == p->iMutexCounter );
57270
57271 for(i=0, mask=1; i<nDb; i++, mask += mask){
57272 if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57273 sqlite3BtreeLeave(aDb[i].pBt);
57274 }
57275 }
57276 #else
57277 UNUSED_PARAMETER(p);
57278 #endif
57279 }
57280
57281 /*
57282 ** Recompute the sum of the mutex counters on all btrees used by the
57283 ** prepared statement p.
57284 **
57285 ** Call this routine while holding a sqlite3VdbeEnter() after doing something
57286 ** that might cause one or more of the individual mutexes held by the
57287 ** prepared statement to be released. Calling sqlite3BtreeEnter() on
57288 ** any BtShared mutex which is not used by the prepared statement is one
57289 ** way to cause one or more of the mutexes in the prepared statement
57290 ** to be temporarily released. The anti-deadlocking logic in
57291 ** sqlite3BtreeEnter() can cause mutexes to be released temporarily then
57292 ** reacquired.
57293 **
57294 ** Calling this routine is an acknowledgement that some of the individual
57295 ** mutexes in the prepared statement might have been released and reacquired.
57296 ** So checks to verify that mutex-protected content did not change
57297 ** unexpectedly should accompany any call to this routine.
57298 */
57299 SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe *p){
57300 #if !defined(SQLITE_OMIT_SHARED_CACHE) && defined(SQLITE_DEBUG)
57301 p->iMutexCounter = mutexCounterSum(p);
57302 #else
57303 UNUSED_PARAMETER(p);
57304 #endif
57305 }
57306
57307 #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
57308 /*
57309 ** Print a single opcode. This routine is used for debugging only.
57310 */
@@ -58504,16 +58441,15 @@
58504 p->nChange = 0;
58505 }
58506
58507 /* Rollback or commit any schema changes that occurred. */
58508 if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
58509 sqlite3ResetInternalSchema(db, 0);
58510 db->flags = (db->flags | SQLITE_InternChanges);
58511 }
58512
58513 /* Release the locks */
58514 sqlite3VdbeMutexResync(p);
58515 sqlite3VdbeLeave(p);
58516 }
58517
58518 /* We have successfully halted and closed the VM. Record this fact. */
58519 if( p->pc>=0 ){
@@ -60190,11 +60126,15 @@
60190 ** __attribute__((aligned(8))) macro. */
60191 static const Mem nullMem
60192 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
60193 __attribute__((aligned(8)))
60194 #endif
60195 = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
 
 
 
 
60196
60197 if( pVm && ALWAYS(pVm->db) ){
60198 sqlite3_mutex_enter(pVm->db->mutex);
60199 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
60200 }
@@ -61604,11 +61544,11 @@
61604 int pc=0; /* The program counter */
61605 Op *aOp = p->aOp; /* Copy of p->aOp */
61606 Op *pOp; /* Current operation */
61607 int rc = SQLITE_OK; /* Value to return */
61608 sqlite3 *db = p->db; /* The database */
61609 u8 resetSchemaOnFault = 0; /* Reset schema after an error if true */
61610 u8 encoding = ENC(db); /* The database encoding */
61611 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
61612 int checkProgress; /* True if progress callbacks are enabled */
61613 int nProgressOps = 0; /* Opcodes executed since progress callback. */
61614 #endif
@@ -62868,11 +62808,10 @@
62868 assert( pOp[-1].p4type==P4_COLLSEQ );
62869 assert( pOp[-1].opcode==OP_CollSeq );
62870 u.ag.ctx.pColl = pOp[-1].p4.pColl;
62871 }
62872 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
62873 sqlite3VdbeMutexResync(p);
62874 if( db->mallocFailed ){
62875 /* Even though a malloc() has failed, the implementation of the
62876 ** user function may have called an sqlite3_result_XXX() function
62877 ** to return a value. The following call releases any resources
62878 ** associated with such a value.
@@ -62879,21 +62818,10 @@
62879 */
62880 sqlite3VdbeMemRelease(&u.ag.ctx.s);
62881 goto no_mem;
62882 }
62883
62884 /* The app-defined function has done something that as caused this
62885 ** statement to expire. (Perhaps the function called sqlite3_exec()
62886 ** with a CREATE TABLE statement.)
62887 */
62888 #if 0
62889 if( p->expired ){
62890 rc = SQLITE_ABORT;
62891 break;
62892 }
62893 #endif
62894
62895 /* If any auxiliary data functions have been called by this user function,
62896 ** immediately call the destructor for any non-static values.
62897 */
62898 if( u.ag.ctx.pVdbeFunc ){
62899 sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1);
@@ -62911,10 +62839,19 @@
62911 sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding);
62912 sqlite3VdbeMemMove(pOut, &u.ag.ctx.s);
62913 if( sqlite3VdbeMemTooBig(pOut) ){
62914 goto too_big;
62915 }
 
 
 
 
 
 
 
 
 
62916 REGISTER_TRACE(pOp->p3, pOut);
62917 UPDATE_MAX_BLOBSIZE(pOut);
62918 break;
62919 }
62920
@@ -64155,12 +64092,11 @@
64155 goto abort_due_to_error;
64156 }
64157 }
64158 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
64159 sqlite3ExpirePreparedStatements(db);
64160 sqlite3ResetInternalSchema(db, 0);
64161 sqlite3VdbeMutexResync(p);
64162 db->flags = (db->flags | SQLITE_InternChanges);
64163 }
64164 }
64165
64166 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -64384,10 +64320,11 @@
64384 assert( pOp->p2<SQLITE_N_BTREE_META );
64385 assert( pOp->p1>=0 && pOp->p1<db->nDb );
64386 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
64387 u.au.pDb = &db->aDb[pOp->p1];
64388 assert( u.au.pDb->pBt!=0 );
 
64389 pIn3 = &aMem[pOp->p3];
64390 sqlite3VdbeMemIntegerify(pIn3);
64391 /* See note about index shifting on OP_ReadCookie */
64392 rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i);
64393 if( pOp->p2==BTREE_SCHEMA_VERSION ){
@@ -64432,16 +64369,17 @@
64432 Btree *pBt;
64433 #endif /* local variables moved into u.av */
64434
64435 assert( pOp->p1>=0 && pOp->p1<db->nDb );
64436 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
 
64437 u.av.pBt = db->aDb[pOp->p1].pBt;
64438 if( u.av.pBt ){
64439 sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
64440 u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
64441 }else{
64442 u.av.iMeta = 0;
64443 }
64444 if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){
64445 sqlite3DbFree(db, p->zErrMsg);
64446 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
64447 /* If the schema-cookie from the database file matches the cookie
@@ -64457,11 +64395,10 @@
64457 ** to be invalidated whenever sqlite3_step() is called from within
64458 ** a v-table method.
64459 */
64460 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
64461 sqlite3ResetInternalSchema(db, pOp->p1);
64462 sqlite3VdbeMutexResync(p);
64463 }
64464
64465 p->expired = 1;
64466 rc = SQLITE_SCHEMA;
64467 }
@@ -64544,10 +64481,11 @@
64544 u.aw.pDb = &db->aDb[u.aw.iDb];
64545 u.aw.pX = u.aw.pDb->pBt;
64546 assert( u.aw.pX!=0 );
64547 if( pOp->opcode==OP_OpenWrite ){
64548 u.aw.wrFlag = 1;
 
64549 if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){
64550 p->minWriteFileFormat = u.aw.pDb->pSchema->file_format;
64551 }
64552 }else{
64553 u.aw.wrFlag = 0;
@@ -66081,12 +66019,14 @@
66081 rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
66082 pOut->flags = MEM_Int;
66083 pOut->u.i = u.br.iMoved;
66084 #ifndef SQLITE_OMIT_AUTOVACUUM
66085 if( rc==SQLITE_OK && u.br.iMoved!=0 ){
66086 sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1);
66087 resetSchemaOnFault = 1;
 
 
66088 }
66089 #endif
66090 }
66091 break;
66092 }
@@ -66764,27 +66704,15 @@
66764 assert( pOp[-1].p4type==P4_COLLSEQ );
66765 assert( pOp[-1].opcode==OP_CollSeq );
66766 u.cb.ctx.pColl = pOp[-1].p4.pColl;
66767 }
66768 (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */
66769 sqlite3VdbeMutexResync(p);
66770 if( u.cb.ctx.isError ){
66771 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
66772 rc = u.cb.ctx.isError;
66773 }
66774
66775 /* The app-defined function has done something that as caused this
66776 ** statement to expire. (Perhaps the function called sqlite3_exec()
66777 ** with a CREATE TABLE statement.)
66778 */
66779 #if 0
66780 if( p->expired ){
66781 rc = SQLITE_ABORT;
66782 break;
66783 }
66784 #endif
66785
66786 sqlite3VdbeMemRelease(&u.cb.ctx.s);
66787
66788 break;
66789 }
66790
@@ -66806,15 +66734,12 @@
66806 #endif /* local variables moved into u.cc */
66807 assert( pOp->p1>0 && pOp->p1<=p->nMem );
66808 u.cc.pMem = &aMem[pOp->p1];
66809 assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
66810 rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc);
66811 sqlite3VdbeMutexResync(p);
66812 if( rc ){
66813 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem));
66814 }else if( p->expired ){
66815 rc = SQLITE_ABORT;
66816 }
66817 sqlite3VdbeChangeEncoding(u.cc.pMem, encoding);
66818 UPDATE_MAX_BLOBSIZE(u.cc.pMem);
66819 if( sqlite3VdbeMemTooBig(u.cc.pMem) ){
66820 goto too_big;
@@ -66889,28 +66814,10 @@
66889 || u.ce.eNew==PAGER_JOURNALMODE_WAL
66890 || u.ce.eNew==PAGER_JOURNALMODE_QUERY
66891 );
66892 assert( pOp->p1>=0 && pOp->p1<db->nDb );
66893
66894 /* This opcode is used in two places: PRAGMA journal_mode and ATTACH.
66895 ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called
66896 ** when the statement is prepared and so p->btreeMask!=0. All mutexes
66897 ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree()
66898 ** is not called when the statement is prepared because it requires the
66899 ** iDb index of the database as a parameter, and the database has not
66900 ** yet been attached so that index is unavailable. We have to wait
66901 ** until runtime (now) to get the mutex on the newly attached database.
66902 ** No other mutexes are required by the ATTACH command so this is safe
66903 ** to do.
66904 */
66905 if( p->btreeMask==0 ){
66906 /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed
66907 ** database. */
66908 sqlite3VdbeUsesBtree(p, pOp->p1);
66909 sqlite3VdbeEnter(p);
66910 }
66911
66912 u.ce.pBt = db->aDb[pOp->p1].pBt;
66913 u.ce.pPager = sqlite3BtreePager(u.ce.pBt);
66914 u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager);
66915 if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld;
66916 if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld;
@@ -67560,13 +67467,12 @@
67560 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
67561 pc, p->zSql, p->zErrMsg);
67562 sqlite3VdbeHalt(p);
67563 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
67564 rc = SQLITE_ERROR;
67565 if( resetSchemaOnFault ){
67566 sqlite3ResetInternalSchema(db, 0);
67567 sqlite3VdbeMutexResync(p);
67568 }
67569
67570 /* This is the only way out of this procedure. We have to
67571 ** release the mutexes on btrees that were acquired at the
67572 ** top. */
@@ -72266,11 +72172,11 @@
72266 assert( !ExprHasProperty(pExpr, EP_IntValue) );
72267 assert( pExpr->u.zToken!=0 );
72268 assert( pExpr->u.zToken[0]!=0 );
72269 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
72270 if( pExpr->u.zToken[1]!=0 ){
72271 sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, 0);
72272 }
72273 break;
72274 }
72275 case TK_REGISTER: {
72276 inReg = pExpr->iTable;
@@ -74655,10 +74561,11 @@
74655 return;
74656 }
74657 assert( sqlite3BtreeHoldsAllMutexes(db) );
74658 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
74659 assert( iDb>=0 );
 
74660 #ifndef SQLITE_OMIT_AUTHORIZATION
74661 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
74662 db->aDb[iDb].zName ) ){
74663 return;
74664 }
@@ -74896,10 +74803,11 @@
74896 sqlite3BeginWriteOperation(pParse, 0, iDb);
74897 iStatCur = pParse->nTab;
74898 pParse->nTab += 2;
74899 openStatTable(pParse, iDb, iStatCur, 0, 0);
74900 iMem = pParse->nMem+1;
 
74901 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
74902 Table *pTab = (Table*)sqliteHashData(k);
74903 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
74904 }
74905 loadAnalysis(pParse, iDb);
@@ -75106,13 +75014,13 @@
75106 char *zSql;
75107 int rc;
75108
75109 assert( iDb>=0 && iDb<db->nDb );
75110 assert( db->aDb[iDb].pBt!=0 );
75111 assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
75112
75113 /* Clear any prior statistics */
 
75114 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
75115 Index *pIdx = sqliteHashData(i);
75116 sqlite3DefaultRowEst(pIdx);
75117 sqlite3DeleteIndexSamples(db, pIdx);
75118 pIdx->aSample = 0;
@@ -75421,11 +75329,11 @@
75421 if( db->aDb[iDb].pBt ){
75422 sqlite3BtreeClose(db->aDb[iDb].pBt);
75423 db->aDb[iDb].pBt = 0;
75424 db->aDb[iDb].pSchema = 0;
75425 }
75426 sqlite3ResetInternalSchema(db, 0);
75427 db->nDb = iDb;
75428 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
75429 db->mallocFailed = 1;
75430 sqlite3DbFree(db, zErrDyn);
75431 zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -75493,11 +75401,11 @@
75493 }
75494
75495 sqlite3BtreeClose(pDb->pBt);
75496 pDb->pBt = 0;
75497 pDb->pSchema = 0;
75498 sqlite3ResetInternalSchema(db, 0);
75499 return;
75500
75501 detach_error:
75502 sqlite3_result_error(context, zErr, -1);
75503 }
@@ -76171,10 +76079,11 @@
76171 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
76172 if( (mask & pParse->cookieMask)==0 ) continue;
76173 sqlite3VdbeUsesBtree(v, iDb);
76174 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
76175 if( db->init.busy==0 ){
 
76176 sqlite3VdbeAddOp3(v, OP_VerifyCookie,
76177 iDb, pParse->cookieValue[iDb],
76178 db->aDb[iDb].pSchema->iGeneration);
76179 }
76180 }
@@ -76286,13 +76195,16 @@
76286 Table *p = 0;
76287 int i;
76288 int nName;
76289 assert( zName!=0 );
76290 nName = sqlite3Strlen30(zName);
 
 
76291 for(i=OMIT_TEMPDB; i<db->nDb; i++){
76292 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
76293 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
 
76294 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
76295 if( p ) break;
76296 }
76297 return p;
76298 }
@@ -76348,15 +76260,18 @@
76348 */
76349 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
76350 Index *p = 0;
76351 int i;
76352 int nName = sqlite3Strlen30(zName);
 
 
76353 for(i=OMIT_TEMPDB; i<db->nDb; i++){
76354 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
76355 Schema *pSchema = db->aDb[j].pSchema;
76356 assert( pSchema );
76357 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
 
76358 p = sqlite3HashFind(&pSchema->idxHash, zName, nName);
76359 if( p ) break;
76360 }
76361 return p;
76362 }
@@ -76379,12 +76294,14 @@
76379 ** with the index.
76380 */
76381 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
76382 Index *pIndex;
76383 int len;
76384 Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
76385
 
 
76386 len = sqlite3Strlen30(zIdxName);
76387 pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
76388 if( ALWAYS(pIndex) ){
76389 if( pIndex->pTable->pIndex==pIndex ){
76390 pIndex->pTable->pIndex = pIndex->pNext;
@@ -76408,30 +76325,46 @@
76408 ** a single database. This routine is called to reclaim memory
76409 ** before the database closes. It is also called during a rollback
76410 ** if there were schema changes during the transaction or if a
76411 ** schema-cookie mismatch occurs.
76412 **
76413 ** If iDb==0 then reset the internal schema tables for all database
76414 ** files. If iDb>=1 then reset the internal schema for only the
76415 ** single file indicated.
76416 */
76417 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
76418 int i, j;
76419 assert( iDb>=0 && iDb<db->nDb );
76420
76421 if( iDb==0 ){
76422 sqlite3BtreeEnterAll(db);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76423 }
76424 for(i=iDb; i<db->nDb; i++){
 
 
 
 
76425 Db *pDb = &db->aDb[i];
76426 if( pDb->pSchema ){
76427 assert(i==1 || (pDb->pBt && sqlite3BtreeHoldsMutex(pDb->pBt)));
76428 sqlite3SchemaFree(pDb->pSchema);
76429 }
76430 if( iDb>0 ) return;
76431 }
76432 assert( iDb==0 );
76433 db->flags &= ~SQLITE_InternChanges;
76434 sqlite3VtabUnlockList(db);
76435 sqlite3BtreeLeaveAll(db);
76436
76437 /* If one or more of the auxiliary database files has been closed,
@@ -76513,10 +76446,11 @@
76513 if( !db || db->pnBytesFreed==0 ){
76514 char *zName = pIndex->zName;
76515 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
76516 &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
76517 );
 
76518 assert( pOld==pIndex || pOld==0 );
76519 }
76520 freeIndex(db, pIndex);
76521 }
76522
@@ -76547,10 +76481,11 @@
76547 Db *pDb;
76548
76549 assert( db!=0 );
76550 assert( iDb>=0 && iDb<db->nDb );
76551 assert( zTabName );
 
76552 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
76553 pDb = &db->aDb[iDb];
76554 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
76555 sqlite3Strlen30(zTabName),0);
76556 sqlite3DeleteTable(db, p);
@@ -76831,10 +76766,11 @@
76831 ** then record a pointer to this table in the main database structure
76832 ** so that INSERT can find the table easily.
76833 */
76834 #ifndef SQLITE_OMIT_AUTOINCREMENT
76835 if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
 
76836 pTable->pSchema->pSeqTab = pTable;
76837 }
76838 #endif
76839
76840 /* Begin generating the code that will insert the table record into
@@ -77291,10 +77227,11 @@
77291 */
77292 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){
77293 int r1 = sqlite3GetTempReg(pParse);
77294 sqlite3 *db = pParse->db;
77295 Vdbe *v = pParse->pVdbe;
 
77296 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
77297 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1);
77298 sqlite3ReleaseTempReg(pParse, r1);
77299 }
77300
@@ -77398,11 +77335,11 @@
77398 sqlite3_snprintf(n-k, &zStmt[k], zSep);
77399 k += sqlite3Strlen30(&zStmt[k]);
77400 zSep = zSep2;
77401 identPut(zStmt, &k, pCol->zName);
77402 assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 );
77403 assert( pCol->affinity-SQLITE_AFF_TEXT < sizeof(azType)/sizeof(azType[0]) );
77404 testcase( pCol->affinity==SQLITE_AFF_TEXT );
77405 testcase( pCol->affinity==SQLITE_AFF_NONE );
77406 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
77407 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
77408 testcase( pCol->affinity==SQLITE_AFF_REAL );
@@ -77593,10 +77530,11 @@
77593 /* Check to see if we need to create an sqlite_sequence table for
77594 ** keeping track of autoincrement keys.
77595 */
77596 if( p->tabFlags & TF_Autoincrement ){
77597 Db *pDb = &db->aDb[iDb];
 
77598 if( pDb->pSchema->pSeqTab==0 ){
77599 sqlite3NestedParse(pParse,
77600 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
77601 pDb->zName
77602 );
@@ -77613,10 +77551,11 @@
77613 /* Add the table to the in-memory representation of the database.
77614 */
77615 if( db->init.busy ){
77616 Table *pOld;
77617 Schema *pSchema = p->pSchema;
 
77618 pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
77619 sqlite3Strlen30(p->zName),p);
77620 if( pOld ){
77621 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
77622 db->mallocFailed = 1;
@@ -77797,10 +77736,11 @@
77797 pTable->nCol = pSelTab->nCol;
77798 pTable->aCol = pSelTab->aCol;
77799 pSelTab->nCol = 0;
77800 pSelTab->aCol = 0;
77801 sqlite3DeleteTable(db, pSelTab);
 
77802 pTable->pSchema->flags |= DB_UnresetViews;
77803 }else{
77804 pTable->nCol = 0;
77805 nErr++;
77806 }
@@ -77817,10 +77757,11 @@
77817 /*
77818 ** Clear the column names from every VIEW in database idx.
77819 */
77820 static void sqliteViewResetAll(sqlite3 *db, int idx){
77821 HashElem *i;
 
77822 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
77823 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
77824 Table *pTab = sqliteHashData(i);
77825 if( pTab->pSelect ){
77826 sqliteDeleteColumnNames(db, pTab);
@@ -77850,14 +77791,17 @@
77850 ** We must continue looping until all tables and indices with
77851 ** rootpage==iFrom have been converted to have a rootpage of iTo
77852 ** in order to be certain that we got the right one.
77853 */
77854 #ifndef SQLITE_OMIT_AUTOVACUUM
77855 SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){
77856 HashElem *pElem;
77857 Hash *pHash;
 
77858
 
 
77859 pHash = &pDb->pSchema->tblHash;
77860 for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){
77861 Table *pTab = sqliteHashData(pElem);
77862 if( pTab->tnum==iFrom ){
77863 pTab->tnum = iTo;
@@ -78227,10 +78171,11 @@
78227 }
78228 pFKey->isDeferred = 0;
78229 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
78230 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
78231
 
78232 pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
78233 pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey
78234 );
78235 if( pNextTo==pFKey ){
78236 db->mallocFailed = 1;
@@ -78582,10 +78527,11 @@
78582 pIndex->pTable = pTab;
78583 pIndex->nColumn = pList->nExpr;
78584 pIndex->onError = (u8)onError;
78585 pIndex->autoIndex = (u8)(pName==0);
78586 pIndex->pSchema = db->aDb[iDb].pSchema;
 
78587
78588 /* Check to see if we should honor DESC requests on index columns
78589 */
78590 if( pDb->pSchema->file_format>=4 ){
78591 sortOrderMask = -1; /* Honor DESC */
@@ -78711,10 +78657,11 @@
78711 /* Link the new Index structure to its table and to the other
78712 ** in-memory database structures.
78713 */
78714 if( db->init.busy ){
78715 Index *p;
 
78716 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
78717 pIndex->zName, sqlite3Strlen30(pIndex->zName),
78718 pIndex);
78719 if( p ){
78720 assert( p==pIndex ); /* Malloc must have failed */
@@ -79464,10 +79411,11 @@
79464 yDbMask mask;
79465
79466 assert( iDb<db->nDb );
79467 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
79468 assert( iDb<SQLITE_MAX_ATTACHED+2 );
 
79469 mask = ((yDbMask)1)<<iDb;
79470 if( (pToplevel->cookieMask & mask)==0 ){
79471 pToplevel->cookieMask |= mask;
79472 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
79473 if( !OMIT_TEMPDB && iDb==1 ){
@@ -79591,10 +79539,11 @@
79591 int iDb; /* The database index number */
79592 sqlite3 *db = pParse->db; /* The database connection */
79593 HashElem *k; /* For looping over tables in pDb */
79594 Table *pTab; /* A table in the database */
79595
 
79596 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
79597 assert( pDb!=0 );
79598 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
79599 pTab = (Table*)sqliteHashData(k);
79600 reindexTable(pParse, pTab, zColl);
@@ -80109,16 +80058,16 @@
80109 }
80110
80111 /*
80112 ** Free all resources held by the schema structure. The void* argument points
80113 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
80114 ** pointer itself, it just cleans up subsiduary resources (i.e. the contents
80115 ** of the schema hash tables).
80116 **
80117 ** The Schema.cache_size variable is not cleared.
80118 */
80119 SQLITE_PRIVATE void sqlite3SchemaFree(void *p){
80120 Hash temp1;
80121 Hash temp2;
80122 HashElem *pElem;
80123 Schema *pSchema = (Schema *)p;
80124
@@ -80149,11 +80098,11 @@
80149 ** a new one if necessary.
80150 */
80151 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
80152 Schema * p;
80153 if( pBt ){
80154 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
80155 }else{
80156 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
80157 }
80158 if( !p ){
80159 db->mallocFailed = 1;
@@ -80183,13 +80132,22 @@
80183 ** This file contains C code routines that are called by the parser
80184 ** in order to generate code for DELETE FROM statements.
80185 */
80186
80187 /*
80188 ** Look up every table that is named in pSrc. If any table is not found,
80189 ** add an error message to pParse->zErrMsg and return NULL. If all tables
80190 ** are found, return a pointer to the last table.
 
 
 
 
 
 
 
 
 
80191 */
80192 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
80193 struct SrcList_item *pItem = pSrc->a;
80194 Table *pTab;
80195 assert( pItem && pSrc->nSrc==1 );
@@ -80704,11 +80662,11 @@
80704 ** fire the INSTEAD OF triggers). */
80705 if( pTab->pSelect==0 ){
80706 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
80707 sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
80708 if( count ){
80709 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
80710 }
80711 }
80712
80713 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
80714 ** handle rows (possibly in other tables) that refer via a foreign key
@@ -80795,11 +80753,11 @@
80795 sqlite3ColumnDefault(v, pTab, idx, -1);
80796 }
80797 }
80798 if( doMakeRec ){
80799 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
80800 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
80801 }
80802 sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
80803 return regBase;
80804 }
80805
@@ -82792,11 +82750,11 @@
82792 }
82793 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
82794 }
82795
82796 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
82797 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
82798 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
82799
82800 sqlite3ReleaseTempReg(pParse, regRec);
82801 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
82802 }
@@ -83548,10 +83506,11 @@
83548 */
83549 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
83550 FKey *pFKey; /* Iterator variable */
83551 FKey *pNext; /* Copy of pFKey->pNextFrom */
83552
 
83553 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
83554
83555 /* Remove the FK from the fkeyHash hash table. */
83556 if( !db || db->pnBytesFreed==0 ){
83557 if( pFKey->pPrevTo ){
@@ -83707,11 +83666,11 @@
83707 zColAff[pTab->nCol] = '\0';
83708
83709 pTab->zColAff = zColAff;
83710 }
83711
83712 sqlite3VdbeChangeP4(v, -1, pTab->zColAff, 0);
83713 }
83714
83715 /*
83716 ** Return non-zero if the table pTab in database iDb or any of its indices
83717 ** have been opened at any point in the VDBE program beginning at location
@@ -83821,10 +83780,11 @@
83821
83822 assert( v ); /* We failed long ago if this is not so */
83823 for(p = pParse->pAinc; p; p = p->pNext){
83824 pDb = &db->aDb[p->iDb];
83825 memId = p->regCtr;
 
83826 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
83827 addr = sqlite3VdbeCurrentAddr(v);
83828 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
83829 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
83830 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
@@ -83871,10 +83831,11 @@
83871 int j1, j2, j3, j4, j5;
83872 int iRec;
83873 int memId = p->regCtr;
83874
83875 iRec = sqlite3GetTempReg(pParse);
 
83876 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
83877 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
83878 j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
83879 j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
83880 j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
@@ -84911,11 +84872,11 @@
84911 sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i);
84912 }
84913 }
84914 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
84915 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
84916 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
84917 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
84918
84919 #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
84920 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
84921 continue; /* Treat pIdx as if it is not a UNIQUE index */
@@ -85057,11 +85018,11 @@
85057 if( useSeekResult ){
85058 pik_flags |= OPFLAG_USESEEKRESULT;
85059 }
85060 sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid);
85061 if( !pParse->nested ){
85062 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
85063 }
85064 sqlite3VdbeChangeP5(v, pik_flags);
85065 }
85066
85067 /*
@@ -86752,11 +86713,11 @@
86752 "from within a transaction");
86753 return SQLITE_ERROR;
86754 }
86755 sqlite3BtreeClose(db->aDb[1].pBt);
86756 db->aDb[1].pBt = 0;
86757 sqlite3ResetInternalSchema(db, 0);
86758 }
86759 return SQLITE_OK;
86760 }
86761 #endif /* SQLITE_PAGER_PRAGMAS */
86762
@@ -87025,10 +86986,11 @@
87025 }else{
87026 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
87027 sqlite3BeginWriteOperation(pParse, 0, iDb);
87028 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
87029 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
 
87030 pDb->pSchema->cache_size = size;
87031 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
87032 }
87033 }else
87034
@@ -87327,10 +87289,11 @@
87327 ** to its default value when the database is closed and reopened.
87328 ** N should be a positive integer.
87329 */
87330 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
87331 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
 
87332 if( !zRight ){
87333 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
87334 }else{
87335 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
87336 pDb->pSchema->cache_size = size;
@@ -87747,10 +87710,11 @@
87747 /* Do an integrity check of the B-Tree
87748 **
87749 ** Begin by filling registers 2, 3, ... with the root pages numbers
87750 ** for all tables and indices in the database.
87751 */
 
87752 pTbls = &db->aDb[i].pSchema->tblHash;
87753 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
87754 Table *pTab = sqliteHashData(x);
87755 Index *pIdx;
87756 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
@@ -87812,11 +87776,11 @@
87812 r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0);
87813 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1);
87814 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
87815 sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
87816 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
87817 sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC);
87818 sqlite3VdbeJumpHere(v, addr+9);
87819 sqlite3VdbeJumpHere(v, jmp2);
87820 }
87821 sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
87822 sqlite3VdbeJumpHere(v, loopTop);
@@ -87842,11 +87806,11 @@
87842 sqlite3VdbeChangeP1(v, addr+3, j+2);
87843 sqlite3VdbeChangeP2(v, addr+3, addr+2);
87844 sqlite3VdbeJumpHere(v, addr+4);
87845 sqlite3VdbeChangeP4(v, addr+6,
87846 "wrong # of entries in index ", P4_STATIC);
87847 sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC);
87848 }
87849 }
87850 }
87851 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
87852 sqlite3VdbeChangeP2(v, addr, -mxErr);
@@ -88498,11 +88462,11 @@
88498 }
88499 #endif
88500 }
88501 if( db->mallocFailed ){
88502 rc = SQLITE_NOMEM;
88503 sqlite3ResetInternalSchema(db, 0);
88504 }
88505 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
88506 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
88507 ** the schema loaded, even if errors occurred. In this situation the
88508 ** current sqlite3_prepare() operation will fail, but the following one
@@ -88630,11 +88594,13 @@
88630
88631 /* Read the schema cookie from the database. If it does not match the
88632 ** value stored as part of the in-memory schema representation,
88633 ** set Parse.rc to SQLITE_SCHEMA. */
88634 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
 
88635 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
 
88636 pParse->rc = SQLITE_SCHEMA;
88637 }
88638
88639 /* Close the transaction, if one was opened. */
88640 if( openedTransaction ){
@@ -88772,13 +88738,10 @@
88772 }
88773 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
88774 if( pParse->checkSchema ){
88775 schemaIsValid(pParse);
88776 }
88777 if( pParse->rc==SQLITE_SCHEMA ){
88778 sqlite3ResetInternalSchema(db, 0);
88779 }
88780 if( db->mallocFailed ){
88781 pParse->rc = SQLITE_NOMEM;
88782 }
88783 if( pzTail ){
88784 *pzTail = pParse->zTail;
@@ -93735,10 +93698,11 @@
93735 return 0;
93736 }
93737
93738 if( pTmpSchema!=pTab->pSchema ){
93739 HashElem *p;
 
93740 for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
93741 Trigger *pTrig = (Trigger *)sqliteHashData(p);
93742 if( pTrig->pTabSchema==pTab->pSchema
93743 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
93744 ){
@@ -93846,10 +93810,11 @@
93846 ** specified name exists */
93847 zName = sqlite3NameFromToken(db, pName);
93848 if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
93849 goto trigger_cleanup;
93850 }
 
93851 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
93852 zName, sqlite3Strlen30(zName)) ){
93853 if( !noErr ){
93854 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
93855 }
@@ -93985,10 +93950,11 @@
93985 }
93986
93987 if( db->init.busy ){
93988 Trigger *pLink = pTrig;
93989 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
 
93990 pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);
93991 if( pTrig ){
93992 db->mallocFailed = 1;
93993 }else if( pLink->pSchema==pLink->pTabSchema ){
93994 Table *pTab;
@@ -94166,13 +94132,15 @@
94166
94167 assert( pName->nSrc==1 );
94168 zDb = pName->a[0].zDatabase;
94169 zName = pName->a[0].zName;
94170 nName = sqlite3Strlen30(zName);
 
94171 for(i=OMIT_TEMPDB; i<db->nDb; i++){
94172 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
94173 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
 
94174 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
94175 if( pTrigger ) break;
94176 }
94177 if( !pTrigger ){
94178 if( !noErr ){
@@ -94242,11 +94210,11 @@
94242 };
94243
94244 sqlite3BeginWriteOperation(pParse, 0, iDb);
94245 sqlite3OpenMasterTable(pParse, iDb);
94246 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
94247 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, 0);
94248 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
94249 sqlite3ChangeCookie(pParse, iDb);
94250 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
94251 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
94252 if( pParse->nMem<3 ){
@@ -94257,12 +94225,15 @@
94257
94258 /*
94259 ** Remove a trigger from the hash tables of the sqlite* pointer.
94260 */
94261 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
94262 Hash *pHash = &(db->aDb[iDb].pSchema->trigHash);
94263 Trigger *pTrigger;
 
 
 
 
94264 pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0);
94265 if( ALWAYS(pTrigger) ){
94266 if( pTrigger->pSchema==pTrigger->pTabSchema ){
94267 Table *pTab = tableOfTrigger(pTrigger);
94268 Trigger **pp;
@@ -95782,14 +95753,17 @@
95782 sqlite3BtreeClose(pDb->pBt);
95783 pDb->pBt = 0;
95784 pDb->pSchema = 0;
95785 }
95786
95787 sqlite3ResetInternalSchema(db, 0);
 
 
95788
95789 return rc;
95790 }
 
95791 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
95792
95793 /************** End of vacuum.c **********************************************/
95794 /************** Begin file vtab.c ********************************************/
95795 /*
@@ -95839,11 +95813,11 @@
95839 }
95840 sqlite3DbFree(db, pDel);
95841 if( pDel==pMod ){
95842 db->mallocFailed = 1;
95843 }
95844 sqlite3ResetInternalSchema(db, 0);
95845 }else if( xDestroy ){
95846 xDestroy(pAux);
95847 }
95848 rc = sqlite3ApiExit(db, SQLITE_OK);
95849 sqlite3_mutex_leave(db->mutex);
@@ -95936,14 +95910,13 @@
95936
95937 /* Assert that the mutex (if any) associated with the BtShared database
95938 ** that contains table p is held by the caller. See header comments
95939 ** above function sqlite3VtabUnlockList() for an explanation of why
95940 ** this makes it safe to access the sqlite3.pDisconnect list of any
95941 ** database connection that may have an entry in the p->pVTable list. */
95942 assert( db==0 ||
95943 sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt)
95944 );
95945
95946 while( pVTable ){
95947 sqlite3 *db2 = pVTable->db;
95948 VTable *pNext = pVTable->pNext;
95949 assert( db2 );
@@ -96178,10 +96151,11 @@
96178 else {
96179 Table *pOld;
96180 Schema *pSchema = pTab->pSchema;
96181 const char *zName = pTab->zName;
96182 int nName = sqlite3Strlen30(zName);
 
96183 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
96184 if( pOld ){
96185 db->mallocFailed = 1;
96186 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
96187 return;
@@ -97132,11 +97106,11 @@
97132 ** Return the bitmask for the given cursor number. Return 0 if
97133 ** iCursor is not in the set.
97134 */
97135 static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){
97136 int i;
97137 assert( pMaskSet->n<=sizeof(Bitmask)*8 );
97138 for(i=0; i<pMaskSet->n; i++){
97139 if( pMaskSet->ix[i]==iCursor ){
97140 return ((Bitmask)1)<<i;
97141 }
97142 }
@@ -107007,11 +106981,12 @@
107007 if( !sqlite3SafetyCheckSickOrOk(db) ){
107008 return SQLITE_MISUSE_BKPT;
107009 }
107010 sqlite3_mutex_enter(db->mutex);
107011
107012 sqlite3ResetInternalSchema(db, 0);
 
107013
107014 /* If a transaction is open, the ResetInternalSchema() call above
107015 ** will not have called the xDisconnect() method on any virtual
107016 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
107017 ** call will do so. We need to do this before the check for active
@@ -107050,11 +107025,11 @@
107050 if( j!=1 ){
107051 pDb->pSchema = 0;
107052 }
107053 }
107054 }
107055 sqlite3ResetInternalSchema(db, 0);
107056
107057 /* Tell the code in notify.c that the connection no longer holds any
107058 ** locks and does not require any further unlock-notify callbacks.
107059 */
107060 sqlite3ConnectionClosed(db);
@@ -107141,11 +107116,11 @@
107141 sqlite3VtabRollback(db);
107142 sqlite3EndBenignMalloc();
107143
107144 if( db->flags&SQLITE_InternChanges ){
107145 sqlite3ExpirePreparedStatements(db);
107146 sqlite3ResetInternalSchema(db, 0);
107147 }
107148
107149 /* Any deferred constraint violations have now been resolved. */
107150 db->nDeferredCons = 0;
107151
@@ -107210,11 +107185,11 @@
107210 #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
107211 static const u8 delays[] =
107212 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
107213 static const u8 totals[] =
107214 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
107215 # define NDELAY (sizeof(delays)/sizeof(delays[0]))
107216 sqlite3 *db = (sqlite3 *)ptr;
107217 int timeout = db->busyTimeout;
107218 int delay, prior;
107219
107220 assert( count>=0 );
@@ -113734,10 +113709,12 @@
113734 int nDb; /* Result of strlen(zDb) */
113735 int nFts3; /* Result of strlen(zFts3) */
113736 int nByte; /* Bytes of space to allocate here */
113737 int rc; /* value returned by declare_vtab() */
113738 Fts3auxTable *p; /* Virtual table object to return */
 
 
113739
113740 /* The user should specify a single argument - the name of an fts3 table. */
113741 if( argc!=4 ){
113742 *pzErr = sqlite3_mprintf(
113743 "wrong number of arguments to fts4aux constructor"
@@ -113803,10 +113780,12 @@
113803 ){
113804 int i;
113805 int iEq = -1;
113806 int iGe = -1;
113807 int iLe = -1;
 
 
113808
113809 /* This vtab delivers always results in "ORDER BY term ASC" order. */
113810 if( pInfo->nOrderBy==1
113811 && pInfo->aOrderBy[0].iColumn==0
113812 && pInfo->aOrderBy[0].desc==0
@@ -113851,10 +113830,12 @@
113851 /*
113852 ** xOpen - Open a cursor.
113853 */
113854 static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
113855 Fts3auxCursor *pCsr; /* Pointer to cursor object to return */
 
 
113856
113857 pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor));
113858 if( !pCsr ) return SQLITE_NOMEM;
113859 memset(pCsr, 0, sizeof(Fts3auxCursor));
113860
@@ -114000,10 +113981,12 @@
114000 ){
114001 Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor;
114002 Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
114003 int rc;
114004 int isScan;
 
 
114005
114006 assert( idxStr==0 );
114007 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
114008 || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
114009 || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -122428,11 +122411,11 @@
122428 pCsr->nConstraint = argc;
122429 if( !pCsr->aConstraint ){
122430 rc = SQLITE_NOMEM;
122431 }else{
122432 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
122433 assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 );
122434 for(ii=0; ii<argc; ii++){
122435 RtreeConstraint *p = &pCsr->aConstraint[ii];
122436 p->op = idxStr[ii*2];
122437 p->iCoord = idxStr[ii*2+1]-'a';
122438 if( p->op==RTREE_MATCH ){
@@ -122521,11 +122504,11 @@
122521 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
122522 memset(zIdxStr, 0, sizeof(zIdxStr));
122523 UNUSED_PARAMETER(tab);
122524
122525 assert( pIdxInfo->idxStr==0 );
122526 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){
122527 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
122528
122529 if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
122530 /* We have an equality constraint on the rowid. Use strategy 1. */
122531 int jj;
@@ -124644,10 +124627,12 @@
124644 static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
124645 UErrorCode status = U_ZERO_ERROR;
124646 URegularExpression *pExpr;
124647 UBool res;
124648 const UChar *zString = sqlite3_value_text16(apArg[1]);
 
 
124649
124650 /* If the left hand side of the regexp operator is NULL,
124651 ** then the result is also NULL.
124652 */
124653 if( !zString ){
@@ -124873,11 +124858,11 @@
124873 };
124874
124875 int rc = SQLITE_OK;
124876 int i;
124877
124878 for(i=0; rc==SQLITE_OK && i<(sizeof(scalars)/sizeof(struct IcuScalar)); i++){
124879 struct IcuScalar *p = &scalars[i];
124880 rc = sqlite3_create_function(
124881 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
124882 );
124883 }
124884
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1675,11 +1675,11 @@
1675 ** changes to a [database connection]. The interface is similar to
1676 ** [sqlite3_config()] except that the changes apply to a single
1677 ** [database connection] (specified in the first argument).
1678 **
1679 ** The second argument to sqlite3_db_config(D,V,...) is the
1680 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1681 ** that indicates what aspect of the [database connection] is being configured.
1682 ** Subsequent arguments vary depending on the configuration verb.
1683 **
1684 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1685 ** the call is considered successful.
@@ -7833,22 +7833,22 @@
7833 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*);
7834 #ifndef NDEBUG
7835 /* These routines are used inside assert() statements only. */
7836 SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*);
7837 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*);
7838 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
7839 #endif
7840 #else
7841
7842 # define sqlite3BtreeLeave(X)
 
7843 # define sqlite3BtreeEnterCursor(X)
7844 # define sqlite3BtreeLeaveCursor(X)
7845 # define sqlite3BtreeLeaveAll(X)
7846
7847 # define sqlite3BtreeHoldsMutex(X) 1
7848 # define sqlite3BtreeHoldsAllMutexes(X) 1
7849 # define sqlite3SchemaMutexHeld(X,Y,Z) 1
7850 #endif
7851
7852
7853 #endif /* _BTREE_H_ */
7854
@@ -7963,11 +7963,11 @@
7963 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
7964 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
7965 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
7966 #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
7967 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
7968 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
7969 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
7970 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
7971 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
7972 #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
7973 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
@@ -8998,10 +8998,24 @@
8998 Schema *pSchema; /* Pointer to database schema (possibly shared) */
8999 };
9000
9001 /*
9002 ** An instance of the following structure stores a database schema.
9003 **
9004 ** Most Schema objects are associated with a Btree. The exception is
9005 ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
9006 ** In shared cache mode, a single Schema object can be shared by multiple
9007 ** Btrees that refer to the same underlying BtShared object.
9008 **
9009 ** Schema objects are automatically deallocated when the last Btree that
9010 ** references them is destroyed. The TEMP Schema is manually freed by
9011 ** sqlite3_close().
9012 *
9013 ** A thread must be holding a mutex on the corresponding Btree in order
9014 ** to access Schema content. This implies that the thread must also be
9015 ** holding a mutex on the sqlite3 connection pointer that owns the Btree.
9016 ** For a TEMP Schema, on the connection mutex is required.
9017 */
9018 struct Schema {
9019 int schema_cookie; /* Database schema version number for this file */
9020 int iGeneration; /* Generation counter. Incremented with each change */
9021 Hash tblHash; /* All tables indexed by name */
@@ -9514,11 +9528,11 @@
9528 ** implementation. sqlite3_vtab* handles can not be shared between
9529 ** database connections, even when the rest of the in-memory database
9530 ** schema is shared, as the implementation often stores the database
9531 ** connection handle passed to it via the xConnect() or xCreate() method
9532 ** during initialization internally. This database connection handle may
9533 ** then be used by the virtual table implementation to access real tables
9534 ** within the database. So that they appear as part of the callers
9535 ** transaction, these accesses need to be made via the same database
9536 ** connection as that used to execute SQL operations on the virtual table.
9537 **
9538 ** All VTable objects that correspond to a single table in a shared
@@ -11272,11 +11286,11 @@
11286 SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
11287 #ifndef SQLITE_OMIT_WSD
11288 SQLITE_PRIVATE int sqlite3PendingByte;
11289 #endif
11290 #endif
11291 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
11292 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
11293 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
11294 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
11295 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
11296 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
@@ -11299,11 +11313,11 @@
11313 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
11314 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
11315 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
11316 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
11317 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
11318 SQLITE_PRIVATE void sqlite3SchemaClear(void *);
11319 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
11320 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11321 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
11322 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
11323 void (*)(sqlite3_context*,int,sqlite3_value **),
@@ -12479,11 +12493,10 @@
12493 u8 usesStmtJournal; /* True if uses a statement journal */
12494 u8 readOnly; /* True for read-only statements */
12495 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12496 int nChange; /* Number of db changes made since last reset */
12497 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
 
12498 int iStatement; /* Statement number (or 0 if has not opened stmt) */
12499 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12500 #ifndef SQLITE_OMIT_TRACE
12501 i64 startTime; /* Time when query started - used for profiling */
12502 #endif
@@ -12563,13 +12576,18 @@
12576 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12577 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12578 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12579 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12580 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12581
12582 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
12583 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
12584 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
12585 #else
12586 # define sqlite3VdbeEnter(X)
12587 # define sqlite3VdbeLeave(X)
12588 #endif
12589
12590 #ifdef SQLITE_DEBUG
12591 SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);
12592 #endif
12593
@@ -12742,10 +12760,11 @@
12760 */
12761 case SQLITE_DBSTATUS_SCHEMA_USED: {
12762 int i; /* Used to iterate through schemas */
12763 int nByte = 0; /* Used to accumulate return value */
12764
12765 sqlite3BtreeEnterAll(db);
12766 db->pnBytesFreed = &nByte;
12767 for(i=0; i<db->nDb; i++){
12768 Schema *pSchema = db->aDb[i].pSchema;
12769 if( ALWAYS(pSchema!=0) ){
12770 HashElem *p;
@@ -12768,10 +12787,11 @@
12787 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12788 }
12789 }
12790 }
12791 db->pnBytesFreed = 0;
12792 sqlite3BtreeLeaveAll(db);
12793
12794 *pHighwater = 0;
12795 *pCurrent = nByte;
12796 break;
12797 }
@@ -15879,11 +15899,11 @@
15899 ** Space for tracking which blocks are checked out and the size
15900 ** of each block. One byte per block.
15901 */
15902 u8 *aCtrl;
15903
15904 } mem5;
15905
15906 /*
15907 ** Access the static variable through a macro for SQLITE_OMIT_WSD
15908 */
15909 #define mem5 GLOBAL(struct Mem5Global, mem5)
@@ -16194,11 +16214,11 @@
16214 ** memsys5Log(8) -> 3
16215 ** memsys5Log(9) -> 4
16216 */
16217 static int memsys5Log(int iValue){
16218 int iLog;
16219 for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
16220 return iLog;
16221 }
16222
16223 /*
16224 ** Initialize the memory allocator.
@@ -18064,11 +18084,11 @@
18084 pSlot = (ScratchFreeslot*)p;
18085 sqlite3_mutex_enter(mem0.mutex);
18086 pSlot->pNext = mem0.pScratchFree;
18087 mem0.pScratchFree = pSlot;
18088 mem0.nScratchFree++;
18089 assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
18090 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
18091 sqlite3_mutex_leave(mem0.mutex);
18092 }else{
18093 /* Release memory back to the heap */
18094 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
@@ -38547,10 +38567,23 @@
38567 /* Verify that the page list is in accending order */
38568 for(p=pList; p && p->pDirty; p=p->pDirty){
38569 assert( p->pgno < p->pDirty->pgno );
38570 }
38571 #endif
38572
38573 if( isCommit ){
38574 /* If a WAL transaction is being committed, there is no point in writing
38575 ** any pages with page numbers greater than nTruncate into the WAL file.
38576 ** They will never be read by any client. So remove them from the pDirty
38577 ** list here. */
38578 PgHdr *p;
38579 PgHdr **ppNext = &pList;
38580 for(p=pList; (*ppNext = p); p=p->pDirty){
38581 if( p->pgno<=nTruncate ) ppNext = &p->pDirty;
38582 }
38583 assert( pList );
38584 }
38585
38586 if( pList->pgno==1 ) pager_write_changecounter(pList);
38587 rc = sqlite3WalFrames(pPager->pWal,
38588 pPager->pageSize, pList, nTruncate, isCommit, syncFlags
38589 );
@@ -38560,10 +38593,11 @@
38593 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
38594 }
38595 }
38596
38597 #ifdef SQLITE_CHECK_PAGES
38598 pList = sqlite3PcacheDirtyList(pPager->pPCache);
38599 for(p=pList; p; p=p->pDirty){
38600 pager_set_pagehash(p);
38601 }
38602 #endif
38603
@@ -45510,11 +45544,11 @@
45544
45545
45546 /* The following value is the maximum cell size assuming a maximum page
45547 ** size give above.
45548 */
45549 #define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8))
45550
45551 /* The maximum number of cells on a single page of the database. This
45552 ** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself
45553 ** plus 2 bytes for the index to the cell in the page header). Such
45554 ** small cells will be rare, but they are possible.
@@ -45727,11 +45761,10 @@
45761 BtShared *pNext; /* Next on a list of sharable BtShared structs */
45762 BtLock *pLock; /* List of locks held on this shared-btree struct */
45763 Btree *pWriter; /* Btree with currently open write transaction */
45764 u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
45765 u8 isPending; /* If waiting for read-locks to clear */
 
45766 #endif
45767 u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
45768 };
45769
45770 /*
@@ -45966,32 +45999,14 @@
45999 assert( p->locked==1 );
46000 assert( sqlite3_mutex_held(pBt->mutex) );
46001 assert( sqlite3_mutex_held(p->db->mutex) );
46002 assert( p->db==pBt->db );
46003
 
46004 sqlite3_mutex_leave(pBt->mutex);
46005 p->locked = 0;
46006 }
46007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46008 /*
46009 ** Enter a mutex on the given BTree object.
46010 **
46011 ** If the object is not sharable, then no mutex is ever required
46012 ** and this routine is a no-op. The underlying mutex is non-recursive.
@@ -46032,28 +46047,10 @@
46047
46048 if( !p->sharable ) return;
46049 p->wantToLock++;
46050 if( p->locked ) return;
46051
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46052 /* In most cases, we should be able to acquire the lock we
46053 ** want without having to go throught the ascending lock
46054 ** procedure that follows. Just be sure not to block.
46055 */
46056 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
@@ -46143,49 +46140,24 @@
46140 ** two or more btrees in common both try to lock all their btrees
46141 ** at the same instant.
46142 */
46143 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
46144 int i;
46145 Btree *p;
46146 assert( sqlite3_mutex_held(db->mutex) );
46147 for(i=0; i<db->nDb; i++){
46148 p = db->aDb[i].pBt;
46149 if( p ) sqlite3BtreeEnter(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46150 }
46151 }
46152 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
46153 int i;
46154 Btree *p;
46155 assert( sqlite3_mutex_held(db->mutex) );
46156 for(i=0; i<db->nDb; i++){
46157 p = db->aDb[i].pBt;
46158 if( p ) sqlite3BtreeLeave(p);
 
 
 
 
 
 
46159 }
46160 }
46161
46162 #ifndef NDEBUG
46163 /*
@@ -46209,10 +46181,35 @@
46181 }
46182 return 1;
46183 }
46184 #endif /* NDEBUG */
46185
46186 #ifndef NDEBUG
46187 /*
46188 ** Return true if the correct mutexes are held for accessing the
46189 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
46190 ** access are:
46191 **
46192 ** (1) The mutex on db
46193 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
46194 **
46195 ** If pSchema is not NULL, then iDb is computed from pSchema and
46196 ** db using sqlite3SchemaToIndex().
46197 */
46198 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
46199 Btree *p;
46200 assert( db!=0 );
46201 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
46202 assert( iDb>=0 && iDb<db->nDb );
46203 if( !sqlite3_mutex_held(db->mutex) ) return 0;
46204 if( iDb==1 ) return 1;
46205 p = db->aDb[iDb].pBt;
46206 assert( p!=0 );
46207 return p->sharable==0 || p->locked==1;
46208 }
46209 #endif /* NDEBUG */
46210
46211 #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
46212 /*
46213 ** The following are special cases for mutex enter routines for use
46214 ** in single threaded applications that use shared cache. Except for
46215 ** these two routines, all mutex operations are no-ops in that case and
@@ -47466,11 +47463,11 @@
47463 ** is no way that the allocation can extend off the end of the page.
47464 ** The assert() below verifies the previous sentence.
47465 */
47466 top -= nByte;
47467 put2byte(&data[hdr+5], top);
47468 assert( top+nByte <= (int)pPage->pBt->usableSize );
47469 *pIdx = top;
47470 return SQLITE_OK;
47471 }
47472
47473 /*
@@ -47487,11 +47484,11 @@
47484 unsigned char *data = pPage->aData;
47485
47486 assert( pPage->pBt!=0 );
47487 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
47488 assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
47489 assert( (start + size) <= (int)pPage->pBt->usableSize );
47490 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
47491 assert( size>=0 ); /* Minimum cell size is 4 */
47492
47493 if( pPage->pBt->secureDelete ){
47494 /* Overwrite deleted information with zeros when the secure_delete
@@ -47530,11 +47527,11 @@
47527 /* Coalesce adjacent free blocks */
47528 addr = hdr + 1;
47529 while( (pbegin = get2byte(&data[addr]))>0 ){
47530 int pnext, psize, x;
47531 assert( pbegin>addr );
47532 assert( pbegin <= (int)pPage->pBt->usableSize-4 );
47533 pnext = get2byte(&data[pbegin]);
47534 psize = get2byte(&data[pbegin+2]);
47535 if( pbegin + psize + 3 >= pnext && pnext>0 ){
47536 int frag = pnext - (pbegin+psize);
47537 if( (frag<0) || (frag>(int)data[hdr+7]) ){
@@ -51737,11 +51734,11 @@
51734 rc = allocateSpace(pPage, sz, &idx);
51735 if( rc ){ *pRC = rc; return; }
51736 /* The allocateSpace() routine guarantees the following two properties
51737 ** if it returns success */
51738 assert( idx >= end+2 );
51739 assert( idx+sz <= (int)pPage->pBt->usableSize );
51740 pPage->nCell++;
51741 pPage->nFree -= (u16)(2 + sz);
51742 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
51743 if( iChild ){
51744 put4byte(&data[idx], iChild);
@@ -51780,11 +51777,12 @@
51777 const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
51778 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
51779
51780 assert( pPage->nOverflow==0 );
51781 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
51782 assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
51783 && (int)MX_CELL(pPage->pBt)<=10921);
51784 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
51785
51786 /* Check that the page has just been zeroed by zeroPage() */
51787 assert( pPage->nCell==0 );
51788 assert( get2byteNotZero(&data[hdr+5])==nUsable );
@@ -51994,11 +51992,11 @@
51992 int iData;
51993
51994
51995 assert( pFrom->isInit );
51996 assert( pFrom->nFree>=iToHdr );
51997 assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize );
51998
51999 /* Copy the b-tree node content from page pFrom to page pTo. */
52000 iData = get2byte(&aFrom[iFromHdr+5]);
52001 memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
52002 memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell);
@@ -52261,11 +52259,11 @@
52259 assert( nCell<nMaxCells );
52260 szCell[nCell] = sz;
52261 pTemp = &aSpace1[iSpace1];
52262 iSpace1 += sz;
52263 assert( sz<=pBt->maxLocal+23 );
52264 assert( iSpace1 <= (int)pBt->pageSize );
52265 memcpy(pTemp, apDiv[i], sz);
52266 apCell[nCell] = pTemp+leafCorrection;
52267 assert( leafCorrection==0 || leafCorrection==4 );
52268 szCell[nCell] = szCell[nCell] - leafCorrection;
52269 if( !pOld->leaf ){
@@ -52505,11 +52503,11 @@
52503 sz = cellSizePtr(pParent, pCell);
52504 }
52505 }
52506 iOvflSpace += sz;
52507 assert( sz<=pBt->maxLocal+23 );
52508 assert( iOvflSpace <= (int)pBt->pageSize );
52509 insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
52510 if( rc!=SQLITE_OK ) goto balance_cleanup;
52511 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
52512
52513 j++;
@@ -52950,11 +52948,11 @@
52948 newCell = pBt->pTmpSpace;
52949 if( newCell==0 ) return SQLITE_NOMEM;
52950 rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
52951 if( rc ) goto end_insert;
52952 assert( szNew==cellSizePtr(pPage, newCell) );
52953 assert( szNew <= MX_CELL_SIZE(pBt) );
52954 idx = pCur->aiIdx[pCur->iPage];
52955 if( loc==0 ){
52956 u16 szOld;
52957 assert( idx<pPage->nCell );
52958 rc = sqlite3PagerWrite(pPage->pDbPage);
@@ -53090,11 +53088,11 @@
53088 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
53089 unsigned char *pTmp;
53090
53091 pCell = findCell(pLeaf, pLeaf->nCell-1);
53092 nCell = cellSizePtr(pLeaf, pCell);
53093 assert( MX_CELL_SIZE(pBt) >= nCell );
53094
53095 allocateTempSpace(pBt);
53096 pTmp = pBt->pTmpSpace;
53097
53098 rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -54784,11 +54782,11 @@
54782 && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK
54783 ){
54784 int nDestTruncate;
54785
54786 if( p->pDestDb ){
54787 sqlite3ResetInternalSchema(p->pDestDb, -1);
54788 }
54789
54790 /* Set nDestTruncate to the final number of pages in the destination
54791 ** database. The complication here is that the destination page
54792 ** size may be different to the source page size.
@@ -57181,40 +57179,16 @@
57179 ** The prepared statements need to know in advance the complete set of
57180 ** attached databases that they will be using. A mask of these databases
57181 ** is maintained in p->btreeMask and is used for locking and other purposes.
57182 */
57183 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
57184 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
57185 assert( i<(int)sizeof(p->btreeMask)*8 );
57186 p->btreeMask |= ((yDbMask)1)<<i;
57187 }
57188
57189 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57190 /*
57191 ** If SQLite is compiled to support shared-cache mode and to be threadsafe,
57192 ** this routine obtains the mutex associated with each BtShared structure
57193 ** that may be accessed by the VM passed as an argument. In doing so it also
57194 ** sets the BtShared.db member of each of the BtShared structures, ensuring
@@ -57233,11 +57207,10 @@
57207 ** corresponding to btrees that use shared cache. Then the runtime of
57208 ** this routine is N*N. But as N is rarely more than 1, this should not
57209 ** be a problem.
57210 */
57211 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){
 
57212 int i;
57213 yDbMask mask;
57214 sqlite3 *db = p->db;
57215 Db *aDb = db->aDb;
57216 int nDb = db->nDb;
@@ -57244,67 +57217,31 @@
57217 for(i=0, mask=1; i<nDb; i++, mask += mask){
57218 if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57219 sqlite3BtreeEnter(aDb[i].pBt);
57220 }
57221 }
57222 }
 
 
57223 #endif
 
57224
57225 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
57226 /*
57227 ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
57228 */
57229 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){
 
57230 int i;
57231 yDbMask mask;
57232 sqlite3 *db = p->db;
57233 Db *aDb = db->aDb;
57234 int nDb = db->nDb;
57235
 
 
 
 
 
57236 for(i=0, mask=1; i<nDb; i++, mask += mask){
57237 if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
57238 sqlite3BtreeLeave(aDb[i].pBt);
57239 }
57240 }
57241 }
57242 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57243
57244 #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
57245 /*
57246 ** Print a single opcode. This routine is used for debugging only.
57247 */
@@ -58504,16 +58441,15 @@
58441 p->nChange = 0;
58442 }
58443
58444 /* Rollback or commit any schema changes that occurred. */
58445 if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
58446 sqlite3ResetInternalSchema(db, -1);
58447 db->flags = (db->flags | SQLITE_InternChanges);
58448 }
58449
58450 /* Release the locks */
 
58451 sqlite3VdbeLeave(p);
58452 }
58453
58454 /* We have successfully halted and closed the VM. Record this fact. */
58455 if( p->pc>=0 ){
@@ -60190,11 +60126,15 @@
60126 ** __attribute__((aligned(8))) macro. */
60127 static const Mem nullMem
60128 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
60129 __attribute__((aligned(8)))
60130 #endif
60131 = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0,
60132 #ifdef SQLITE_DEBUG
60133 0, 0, /* pScopyFrom, pFiller */
60134 #endif
60135 0, 0 };
60136
60137 if( pVm && ALWAYS(pVm->db) ){
60138 sqlite3_mutex_enter(pVm->db->mutex);
60139 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
60140 }
@@ -61604,11 +61544,11 @@
61544 int pc=0; /* The program counter */
61545 Op *aOp = p->aOp; /* Copy of p->aOp */
61546 Op *pOp; /* Current operation */
61547 int rc = SQLITE_OK; /* Value to return */
61548 sqlite3 *db = p->db; /* The database */
61549 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
61550 u8 encoding = ENC(db); /* The database encoding */
61551 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
61552 int checkProgress; /* True if progress callbacks are enabled */
61553 int nProgressOps = 0; /* Opcodes executed since progress callback. */
61554 #endif
@@ -62868,11 +62808,10 @@
62808 assert( pOp[-1].p4type==P4_COLLSEQ );
62809 assert( pOp[-1].opcode==OP_CollSeq );
62810 u.ag.ctx.pColl = pOp[-1].p4.pColl;
62811 }
62812 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
 
62813 if( db->mallocFailed ){
62814 /* Even though a malloc() has failed, the implementation of the
62815 ** user function may have called an sqlite3_result_XXX() function
62816 ** to return a value. The following call releases any resources
62817 ** associated with such a value.
@@ -62879,21 +62818,10 @@
62818 */
62819 sqlite3VdbeMemRelease(&u.ag.ctx.s);
62820 goto no_mem;
62821 }
62822
 
 
 
 
 
 
 
 
 
 
 
62823 /* If any auxiliary data functions have been called by this user function,
62824 ** immediately call the destructor for any non-static values.
62825 */
62826 if( u.ag.ctx.pVdbeFunc ){
62827 sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1);
@@ -62911,10 +62839,19 @@
62839 sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding);
62840 sqlite3VdbeMemMove(pOut, &u.ag.ctx.s);
62841 if( sqlite3VdbeMemTooBig(pOut) ){
62842 goto too_big;
62843 }
62844
62845 #if 0
62846 /* The app-defined function has done something that as caused this
62847 ** statement to expire. (Perhaps the function called sqlite3_exec()
62848 ** with a CREATE TABLE statement.)
62849 */
62850 if( p->expired ) rc = SQLITE_ABORT;
62851 #endif
62852
62853 REGISTER_TRACE(pOp->p3, pOut);
62854 UPDATE_MAX_BLOBSIZE(pOut);
62855 break;
62856 }
62857
@@ -64155,12 +64092,11 @@
64092 goto abort_due_to_error;
64093 }
64094 }
64095 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
64096 sqlite3ExpirePreparedStatements(db);
64097 sqlite3ResetInternalSchema(db, -1);
 
64098 db->flags = (db->flags | SQLITE_InternChanges);
64099 }
64100 }
64101
64102 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
@@ -64384,10 +64320,11 @@
64320 assert( pOp->p2<SQLITE_N_BTREE_META );
64321 assert( pOp->p1>=0 && pOp->p1<db->nDb );
64322 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
64323 u.au.pDb = &db->aDb[pOp->p1];
64324 assert( u.au.pDb->pBt!=0 );
64325 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
64326 pIn3 = &aMem[pOp->p3];
64327 sqlite3VdbeMemIntegerify(pIn3);
64328 /* See note about index shifting on OP_ReadCookie */
64329 rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i);
64330 if( pOp->p2==BTREE_SCHEMA_VERSION ){
@@ -64432,16 +64369,17 @@
64369 Btree *pBt;
64370 #endif /* local variables moved into u.av */
64371
64372 assert( pOp->p1>=0 && pOp->p1<db->nDb );
64373 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
64374 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
64375 u.av.pBt = db->aDb[pOp->p1].pBt;
64376 if( u.av.pBt ){
64377 sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
64378 u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
64379 }else{
64380 u.av.iGen = u.av.iMeta = 0;
64381 }
64382 if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){
64383 sqlite3DbFree(db, p->zErrMsg);
64384 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
64385 /* If the schema-cookie from the database file matches the cookie
@@ -64457,11 +64395,10 @@
64395 ** to be invalidated whenever sqlite3_step() is called from within
64396 ** a v-table method.
64397 */
64398 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
64399 sqlite3ResetInternalSchema(db, pOp->p1);
 
64400 }
64401
64402 p->expired = 1;
64403 rc = SQLITE_SCHEMA;
64404 }
@@ -64544,10 +64481,11 @@
64481 u.aw.pDb = &db->aDb[u.aw.iDb];
64482 u.aw.pX = u.aw.pDb->pBt;
64483 assert( u.aw.pX!=0 );
64484 if( pOp->opcode==OP_OpenWrite ){
64485 u.aw.wrFlag = 1;
64486 assert( sqlite3SchemaMutexHeld(db, u.aw.iDb, 0) );
64487 if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){
64488 p->minWriteFileFormat = u.aw.pDb->pSchema->file_format;
64489 }
64490 }else{
64491 u.aw.wrFlag = 0;
@@ -66081,12 +66019,14 @@
66019 rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
66020 pOut->flags = MEM_Int;
66021 pOut->u.i = u.br.iMoved;
66022 #ifndef SQLITE_OMIT_AUTOVACUUM
66023 if( rc==SQLITE_OK && u.br.iMoved!=0 ){
66024 sqlite3RootPageMoved(db, u.br.iDb, u.br.iMoved, pOp->p1);
66025 /* All OP_Destroy operations occur on the same btree */
66026 assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.br.iDb+1 );
66027 resetSchemaOnFault = u.br.iDb+1;
66028 }
66029 #endif
66030 }
66031 break;
66032 }
@@ -66764,27 +66704,15 @@
66704 assert( pOp[-1].p4type==P4_COLLSEQ );
66705 assert( pOp[-1].opcode==OP_CollSeq );
66706 u.cb.ctx.pColl = pOp[-1].p4.pColl;
66707 }
66708 (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */
 
66709 if( u.cb.ctx.isError ){
66710 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
66711 rc = u.cb.ctx.isError;
66712 }
66713
 
 
 
 
 
 
 
 
 
 
 
66714 sqlite3VdbeMemRelease(&u.cb.ctx.s);
66715
66716 break;
66717 }
66718
@@ -66806,15 +66734,12 @@
66734 #endif /* local variables moved into u.cc */
66735 assert( pOp->p1>0 && pOp->p1<=p->nMem );
66736 u.cc.pMem = &aMem[pOp->p1];
66737 assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
66738 rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc);
 
66739 if( rc ){
66740 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem));
 
 
66741 }
66742 sqlite3VdbeChangeEncoding(u.cc.pMem, encoding);
66743 UPDATE_MAX_BLOBSIZE(u.cc.pMem);
66744 if( sqlite3VdbeMemTooBig(u.cc.pMem) ){
66745 goto too_big;
@@ -66889,28 +66814,10 @@
66814 || u.ce.eNew==PAGER_JOURNALMODE_WAL
66815 || u.ce.eNew==PAGER_JOURNALMODE_QUERY
66816 );
66817 assert( pOp->p1>=0 && pOp->p1<db->nDb );
66818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66819 u.ce.pBt = db->aDb[pOp->p1].pBt;
66820 u.ce.pPager = sqlite3BtreePager(u.ce.pBt);
66821 u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager);
66822 if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld;
66823 if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld;
@@ -67560,13 +67467,12 @@
67467 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
67468 pc, p->zSql, p->zErrMsg);
67469 sqlite3VdbeHalt(p);
67470 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
67471 rc = SQLITE_ERROR;
67472 if( resetSchemaOnFault>0 ){
67473 sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
 
67474 }
67475
67476 /* This is the only way out of this procedure. We have to
67477 ** release the mutexes on btrees that were acquired at the
67478 ** top. */
@@ -72266,11 +72172,11 @@
72172 assert( !ExprHasProperty(pExpr, EP_IntValue) );
72173 assert( pExpr->u.zToken!=0 );
72174 assert( pExpr->u.zToken[0]!=0 );
72175 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
72176 if( pExpr->u.zToken[1]!=0 ){
72177 sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT);
72178 }
72179 break;
72180 }
72181 case TK_REGISTER: {
72182 inReg = pExpr->iTable;
@@ -74655,10 +74561,11 @@
74561 return;
74562 }
74563 assert( sqlite3BtreeHoldsAllMutexes(db) );
74564 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
74565 assert( iDb>=0 );
74566 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
74567 #ifndef SQLITE_OMIT_AUTHORIZATION
74568 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
74569 db->aDb[iDb].zName ) ){
74570 return;
74571 }
@@ -74896,10 +74803,11 @@
74803 sqlite3BeginWriteOperation(pParse, 0, iDb);
74804 iStatCur = pParse->nTab;
74805 pParse->nTab += 2;
74806 openStatTable(pParse, iDb, iStatCur, 0, 0);
74807 iMem = pParse->nMem+1;
74808 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
74809 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
74810 Table *pTab = (Table*)sqliteHashData(k);
74811 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
74812 }
74813 loadAnalysis(pParse, iDb);
@@ -75106,13 +75014,13 @@
75014 char *zSql;
75015 int rc;
75016
75017 assert( iDb>=0 && iDb<db->nDb );
75018 assert( db->aDb[iDb].pBt!=0 );
 
75019
75020 /* Clear any prior statistics */
75021 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
75022 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
75023 Index *pIdx = sqliteHashData(i);
75024 sqlite3DefaultRowEst(pIdx);
75025 sqlite3DeleteIndexSamples(db, pIdx);
75026 pIdx->aSample = 0;
@@ -75421,11 +75329,11 @@
75329 if( db->aDb[iDb].pBt ){
75330 sqlite3BtreeClose(db->aDb[iDb].pBt);
75331 db->aDb[iDb].pBt = 0;
75332 db->aDb[iDb].pSchema = 0;
75333 }
75334 sqlite3ResetInternalSchema(db, -1);
75335 db->nDb = iDb;
75336 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
75337 db->mallocFailed = 1;
75338 sqlite3DbFree(db, zErrDyn);
75339 zErrDyn = sqlite3MPrintf(db, "out of memory");
@@ -75493,11 +75401,11 @@
75401 }
75402
75403 sqlite3BtreeClose(pDb->pBt);
75404 pDb->pBt = 0;
75405 pDb->pSchema = 0;
75406 sqlite3ResetInternalSchema(db, -1);
75407 return;
75408
75409 detach_error:
75410 sqlite3_result_error(context, zErr, -1);
75411 }
@@ -76171,10 +76079,11 @@
76079 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
76080 if( (mask & pParse->cookieMask)==0 ) continue;
76081 sqlite3VdbeUsesBtree(v, iDb);
76082 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
76083 if( db->init.busy==0 ){
76084 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76085 sqlite3VdbeAddOp3(v, OP_VerifyCookie,
76086 iDb, pParse->cookieValue[iDb],
76087 db->aDb[iDb].pSchema->iGeneration);
76088 }
76089 }
@@ -76286,13 +76195,16 @@
76195 Table *p = 0;
76196 int i;
76197 int nName;
76198 assert( zName!=0 );
76199 nName = sqlite3Strlen30(zName);
76200 /* All mutexes are required for schema access. Make sure we hold them. */
76201 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
76202 for(i=OMIT_TEMPDB; i<db->nDb; i++){
76203 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
76204 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
76205 assert( sqlite3SchemaMutexHeld(db, j, 0) );
76206 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
76207 if( p ) break;
76208 }
76209 return p;
76210 }
@@ -76348,15 +76260,18 @@
76260 */
76261 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
76262 Index *p = 0;
76263 int i;
76264 int nName = sqlite3Strlen30(zName);
76265 /* All mutexes are required for schema access. Make sure we hold them. */
76266 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
76267 for(i=OMIT_TEMPDB; i<db->nDb; i++){
76268 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
76269 Schema *pSchema = db->aDb[j].pSchema;
76270 assert( pSchema );
76271 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
76272 assert( sqlite3SchemaMutexHeld(db, j, 0) );
76273 p = sqlite3HashFind(&pSchema->idxHash, zName, nName);
76274 if( p ) break;
76275 }
76276 return p;
76277 }
@@ -76379,12 +76294,14 @@
76294 ** with the index.
76295 */
76296 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
76297 Index *pIndex;
76298 int len;
76299 Hash *pHash;
76300
76301 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76302 pHash = &db->aDb[iDb].pSchema->idxHash;
76303 len = sqlite3Strlen30(zIdxName);
76304 pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
76305 if( ALWAYS(pIndex) ){
76306 if( pIndex->pTable->pIndex==pIndex ){
76307 pIndex->pTable->pIndex = pIndex->pNext;
@@ -76408,30 +76325,46 @@
76325 ** a single database. This routine is called to reclaim memory
76326 ** before the database closes. It is also called during a rollback
76327 ** if there were schema changes during the transaction or if a
76328 ** schema-cookie mismatch occurs.
76329 **
76330 ** If iDb<0 then reset the internal schema tables for all database
76331 ** files. If iDb>=0 then reset the internal schema for only the
76332 ** single file indicated.
76333 */
76334 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
76335 int i, j;
76336 assert( iDb<db->nDb );
76337
76338 if( iDb>=0 ){
76339 /* Case 1: Reset the single schema identified by iDb */
76340 Db *pDb = &db->aDb[iDb];
76341 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76342 assert( pDb->pSchema!=0 );
76343 sqlite3SchemaClear(pDb->pSchema);
76344
76345 /* If any database other than TEMP is reset, then also reset TEMP
76346 ** since TEMP might be holding triggers that reference tables in the
76347 ** other database.
76348 */
76349 if( iDb!=1 ){
76350 pDb = &db->aDb[1];
76351 assert( pDb->pSchema!=0 );
76352 sqlite3SchemaClear(pDb->pSchema);
76353 }
76354 return;
76355 }
76356 /* Case 2 (from here to the end): Reset all schemas for all attached
76357 ** databases. */
76358 assert( iDb<0 );
76359 sqlite3BtreeEnterAll(db);
76360 for(i=0; i<db->nDb; i++){
76361 Db *pDb = &db->aDb[i];
76362 if( pDb->pSchema ){
76363 sqlite3SchemaClear(pDb->pSchema);
 
76364 }
 
76365 }
 
76366 db->flags &= ~SQLITE_InternChanges;
76367 sqlite3VtabUnlockList(db);
76368 sqlite3BtreeLeaveAll(db);
76369
76370 /* If one or more of the auxiliary database files has been closed,
@@ -76513,10 +76446,11 @@
76446 if( !db || db->pnBytesFreed==0 ){
76447 char *zName = pIndex->zName;
76448 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
76449 &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
76450 );
76451 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
76452 assert( pOld==pIndex || pOld==0 );
76453 }
76454 freeIndex(db, pIndex);
76455 }
76456
@@ -76547,10 +76481,11 @@
76481 Db *pDb;
76482
76483 assert( db!=0 );
76484 assert( iDb>=0 && iDb<db->nDb );
76485 assert( zTabName );
76486 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76487 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
76488 pDb = &db->aDb[iDb];
76489 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
76490 sqlite3Strlen30(zTabName),0);
76491 sqlite3DeleteTable(db, p);
@@ -76831,10 +76766,11 @@
76766 ** then record a pointer to this table in the main database structure
76767 ** so that INSERT can find the table easily.
76768 */
76769 #ifndef SQLITE_OMIT_AUTOINCREMENT
76770 if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
76771 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76772 pTable->pSchema->pSeqTab = pTable;
76773 }
76774 #endif
76775
76776 /* Begin generating the code that will insert the table record into
@@ -77291,10 +77227,11 @@
77227 */
77228 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){
77229 int r1 = sqlite3GetTempReg(pParse);
77230 sqlite3 *db = pParse->db;
77231 Vdbe *v = pParse->pVdbe;
77232 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77233 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
77234 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1);
77235 sqlite3ReleaseTempReg(pParse, r1);
77236 }
77237
@@ -77398,11 +77335,11 @@
77335 sqlite3_snprintf(n-k, &zStmt[k], zSep);
77336 k += sqlite3Strlen30(&zStmt[k]);
77337 zSep = zSep2;
77338 identPut(zStmt, &k, pCol->zName);
77339 assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 );
77340 assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) );
77341 testcase( pCol->affinity==SQLITE_AFF_TEXT );
77342 testcase( pCol->affinity==SQLITE_AFF_NONE );
77343 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
77344 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
77345 testcase( pCol->affinity==SQLITE_AFF_REAL );
@@ -77593,10 +77530,11 @@
77530 /* Check to see if we need to create an sqlite_sequence table for
77531 ** keeping track of autoincrement keys.
77532 */
77533 if( p->tabFlags & TF_Autoincrement ){
77534 Db *pDb = &db->aDb[iDb];
77535 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77536 if( pDb->pSchema->pSeqTab==0 ){
77537 sqlite3NestedParse(pParse,
77538 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
77539 pDb->zName
77540 );
@@ -77613,10 +77551,11 @@
77551 /* Add the table to the in-memory representation of the database.
77552 */
77553 if( db->init.busy ){
77554 Table *pOld;
77555 Schema *pSchema = p->pSchema;
77556 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77557 pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
77558 sqlite3Strlen30(p->zName),p);
77559 if( pOld ){
77560 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
77561 db->mallocFailed = 1;
@@ -77797,10 +77736,11 @@
77736 pTable->nCol = pSelTab->nCol;
77737 pTable->aCol = pSelTab->aCol;
77738 pSelTab->nCol = 0;
77739 pSelTab->aCol = 0;
77740 sqlite3DeleteTable(db, pSelTab);
77741 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
77742 pTable->pSchema->flags |= DB_UnresetViews;
77743 }else{
77744 pTable->nCol = 0;
77745 nErr++;
77746 }
@@ -77817,10 +77757,11 @@
77757 /*
77758 ** Clear the column names from every VIEW in database idx.
77759 */
77760 static void sqliteViewResetAll(sqlite3 *db, int idx){
77761 HashElem *i;
77762 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
77763 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
77764 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
77765 Table *pTab = sqliteHashData(i);
77766 if( pTab->pSelect ){
77767 sqliteDeleteColumnNames(db, pTab);
@@ -77850,14 +77791,17 @@
77791 ** We must continue looping until all tables and indices with
77792 ** rootpage==iFrom have been converted to have a rootpage of iTo
77793 ** in order to be certain that we got the right one.
77794 */
77795 #ifndef SQLITE_OMIT_AUTOVACUUM
77796 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
77797 HashElem *pElem;
77798 Hash *pHash;
77799 Db *pDb;
77800
77801 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
77802 pDb = &db->aDb[iDb];
77803 pHash = &pDb->pSchema->tblHash;
77804 for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){
77805 Table *pTab = sqliteHashData(pElem);
77806 if( pTab->tnum==iFrom ){
77807 pTab->tnum = iTo;
@@ -78227,10 +78171,11 @@
78171 }
78172 pFKey->isDeferred = 0;
78173 pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */
78174 pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
78175
78176 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
78177 pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
78178 pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey
78179 );
78180 if( pNextTo==pFKey ){
78181 db->mallocFailed = 1;
@@ -78582,10 +78527,11 @@
78527 pIndex->pTable = pTab;
78528 pIndex->nColumn = pList->nExpr;
78529 pIndex->onError = (u8)onError;
78530 pIndex->autoIndex = (u8)(pName==0);
78531 pIndex->pSchema = db->aDb[iDb].pSchema;
78532 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
78533
78534 /* Check to see if we should honor DESC requests on index columns
78535 */
78536 if( pDb->pSchema->file_format>=4 ){
78537 sortOrderMask = -1; /* Honor DESC */
@@ -78711,10 +78657,11 @@
78657 /* Link the new Index structure to its table and to the other
78658 ** in-memory database structures.
78659 */
78660 if( db->init.busy ){
78661 Index *p;
78662 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
78663 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
78664 pIndex->zName, sqlite3Strlen30(pIndex->zName),
78665 pIndex);
78666 if( p ){
78667 assert( p==pIndex ); /* Malloc must have failed */
@@ -79464,10 +79411,11 @@
79411 yDbMask mask;
79412
79413 assert( iDb<db->nDb );
79414 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
79415 assert( iDb<SQLITE_MAX_ATTACHED+2 );
79416 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
79417 mask = ((yDbMask)1)<<iDb;
79418 if( (pToplevel->cookieMask & mask)==0 ){
79419 pToplevel->cookieMask |= mask;
79420 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
79421 if( !OMIT_TEMPDB && iDb==1 ){
@@ -79591,10 +79539,11 @@
79539 int iDb; /* The database index number */
79540 sqlite3 *db = pParse->db; /* The database connection */
79541 HashElem *k; /* For looping over tables in pDb */
79542 Table *pTab; /* A table in the database */
79543
79544 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
79545 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
79546 assert( pDb!=0 );
79547 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
79548 pTab = (Table*)sqliteHashData(k);
79549 reindexTable(pParse, pTab, zColl);
@@ -80109,16 +80058,16 @@
80058 }
80059
80060 /*
80061 ** Free all resources held by the schema structure. The void* argument points
80062 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
80063 ** pointer itself, it just cleans up subsidiary resources (i.e. the contents
80064 ** of the schema hash tables).
80065 **
80066 ** The Schema.cache_size variable is not cleared.
80067 */
80068 SQLITE_PRIVATE void sqlite3SchemaClear(void *p){
80069 Hash temp1;
80070 Hash temp2;
80071 HashElem *pElem;
80072 Schema *pSchema = (Schema *)p;
80073
@@ -80149,11 +80098,11 @@
80098 ** a new one if necessary.
80099 */
80100 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
80101 Schema * p;
80102 if( pBt ){
80103 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear);
80104 }else{
80105 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
80106 }
80107 if( !p ){
80108 db->mallocFailed = 1;
@@ -80183,13 +80132,22 @@
80132 ** This file contains C code routines that are called by the parser
80133 ** in order to generate code for DELETE FROM statements.
80134 */
80135
80136 /*
80137 ** While a SrcList can in general represent multiple tables and subqueries
80138 ** (as in the FROM clause of a SELECT statement) in this case it contains
80139 ** the name of a single table, as one might find in an INSERT, DELETE,
80140 ** or UPDATE statement. Look up that table in the symbol table and
80141 ** return a pointer. Set an error message and return NULL if the table
80142 ** name is not found or if any other error occurs.
80143 **
80144 ** The following fields are initialized appropriate in pSrc:
80145 **
80146 ** pSrc->a[0].pTab Pointer to the Table object
80147 ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one
80148 **
80149 */
80150 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
80151 struct SrcList_item *pItem = pSrc->a;
80152 Table *pTab;
80153 assert( pItem && pSrc->nSrc==1 );
@@ -80704,11 +80662,11 @@
80662 ** fire the INSTEAD OF triggers). */
80663 if( pTab->pSelect==0 ){
80664 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
80665 sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
80666 if( count ){
80667 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
80668 }
80669 }
80670
80671 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
80672 ** handle rows (possibly in other tables) that refer via a foreign key
@@ -80795,11 +80753,11 @@
80753 sqlite3ColumnDefault(v, pTab, idx, -1);
80754 }
80755 }
80756 if( doMakeRec ){
80757 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
80758 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
80759 }
80760 sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
80761 return regBase;
80762 }
80763
@@ -82792,11 +82750,11 @@
82750 }
82751 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
82752 }
82753
82754 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
82755 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
82756 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
82757
82758 sqlite3ReleaseTempReg(pParse, regRec);
82759 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
82760 }
@@ -83548,10 +83506,11 @@
83506 */
83507 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
83508 FKey *pFKey; /* Iterator variable */
83509 FKey *pNext; /* Copy of pFKey->pNextFrom */
83510
83511 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
83512 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
83513
83514 /* Remove the FK from the fkeyHash hash table. */
83515 if( !db || db->pnBytesFreed==0 ){
83516 if( pFKey->pPrevTo ){
@@ -83707,11 +83666,11 @@
83666 zColAff[pTab->nCol] = '\0';
83667
83668 pTab->zColAff = zColAff;
83669 }
83670
83671 sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
83672 }
83673
83674 /*
83675 ** Return non-zero if the table pTab in database iDb or any of its indices
83676 ** have been opened at any point in the VDBE program beginning at location
@@ -83821,10 +83780,11 @@
83780
83781 assert( v ); /* We failed long ago if this is not so */
83782 for(p = pParse->pAinc; p; p = p->pNext){
83783 pDb = &db->aDb[p->iDb];
83784 memId = p->regCtr;
83785 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
83786 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
83787 addr = sqlite3VdbeCurrentAddr(v);
83788 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
83789 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
83790 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
@@ -83871,10 +83831,11 @@
83831 int j1, j2, j3, j4, j5;
83832 int iRec;
83833 int memId = p->regCtr;
83834
83835 iRec = sqlite3GetTempReg(pParse);
83836 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
83837 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
83838 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
83839 j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
83840 j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
83841 j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
@@ -84911,11 +84872,11 @@
84872 sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i);
84873 }
84874 }
84875 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
84876 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
84877 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
84878 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
84879
84880 #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
84881 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
84882 continue; /* Treat pIdx as if it is not a UNIQUE index */
@@ -85057,11 +85018,11 @@
85018 if( useSeekResult ){
85019 pik_flags |= OPFLAG_USESEEKRESULT;
85020 }
85021 sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid);
85022 if( !pParse->nested ){
85023 sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
85024 }
85025 sqlite3VdbeChangeP5(v, pik_flags);
85026 }
85027
85028 /*
@@ -86752,11 +86713,11 @@
86713 "from within a transaction");
86714 return SQLITE_ERROR;
86715 }
86716 sqlite3BtreeClose(db->aDb[1].pBt);
86717 db->aDb[1].pBt = 0;
86718 sqlite3ResetInternalSchema(db, -1);
86719 }
86720 return SQLITE_OK;
86721 }
86722 #endif /* SQLITE_PAGER_PRAGMAS */
86723
@@ -87025,10 +86986,11 @@
86986 }else{
86987 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
86988 sqlite3BeginWriteOperation(pParse, 0, iDb);
86989 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
86990 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
86991 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
86992 pDb->pSchema->cache_size = size;
86993 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
86994 }
86995 }else
86996
@@ -87327,10 +87289,11 @@
87289 ** to its default value when the database is closed and reopened.
87290 ** N should be a positive integer.
87291 */
87292 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
87293 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
87294 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87295 if( !zRight ){
87296 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
87297 }else{
87298 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
87299 pDb->pSchema->cache_size = size;
@@ -87747,10 +87710,11 @@
87710 /* Do an integrity check of the B-Tree
87711 **
87712 ** Begin by filling registers 2, 3, ... with the root pages numbers
87713 ** for all tables and indices in the database.
87714 */
87715 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87716 pTbls = &db->aDb[i].pSchema->tblHash;
87717 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
87718 Table *pTab = sqliteHashData(x);
87719 Index *pIdx;
87720 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
@@ -87812,11 +87776,11 @@
87776 r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0);
87777 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1);
87778 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
87779 sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
87780 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
87781 sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT);
87782 sqlite3VdbeJumpHere(v, addr+9);
87783 sqlite3VdbeJumpHere(v, jmp2);
87784 }
87785 sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
87786 sqlite3VdbeJumpHere(v, loopTop);
@@ -87842,11 +87806,11 @@
87806 sqlite3VdbeChangeP1(v, addr+3, j+2);
87807 sqlite3VdbeChangeP2(v, addr+3, addr+2);
87808 sqlite3VdbeJumpHere(v, addr+4);
87809 sqlite3VdbeChangeP4(v, addr+6,
87810 "wrong # of entries in index ", P4_STATIC);
87811 sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_TRANSIENT);
87812 }
87813 }
87814 }
87815 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
87816 sqlite3VdbeChangeP2(v, addr, -mxErr);
@@ -88498,11 +88462,11 @@
88462 }
88463 #endif
88464 }
88465 if( db->mallocFailed ){
88466 rc = SQLITE_NOMEM;
88467 sqlite3ResetInternalSchema(db, -1);
88468 }
88469 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
88470 /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
88471 ** the schema loaded, even if errors occurred. In this situation the
88472 ** current sqlite3_prepare() operation will fail, but the following one
@@ -88630,11 +88594,13 @@
88594
88595 /* Read the schema cookie from the database. If it does not match the
88596 ** value stored as part of the in-memory schema representation,
88597 ** set Parse.rc to SQLITE_SCHEMA. */
88598 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
88599 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88600 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
88601 sqlite3ResetInternalSchema(db, iDb);
88602 pParse->rc = SQLITE_SCHEMA;
88603 }
88604
88605 /* Close the transaction, if one was opened. */
88606 if( openedTransaction ){
@@ -88772,13 +88738,10 @@
88738 }
88739 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
88740 if( pParse->checkSchema ){
88741 schemaIsValid(pParse);
88742 }
 
 
 
88743 if( db->mallocFailed ){
88744 pParse->rc = SQLITE_NOMEM;
88745 }
88746 if( pzTail ){
88747 *pzTail = pParse->zTail;
@@ -93735,10 +93698,11 @@
93698 return 0;
93699 }
93700
93701 if( pTmpSchema!=pTab->pSchema ){
93702 HashElem *p;
93703 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
93704 for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
93705 Trigger *pTrig = (Trigger *)sqliteHashData(p);
93706 if( pTrig->pTabSchema==pTab->pSchema
93707 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
93708 ){
@@ -93846,10 +93810,11 @@
93810 ** specified name exists */
93811 zName = sqlite3NameFromToken(db, pName);
93812 if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
93813 goto trigger_cleanup;
93814 }
93815 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93816 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
93817 zName, sqlite3Strlen30(zName)) ){
93818 if( !noErr ){
93819 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
93820 }
@@ -93985,10 +93950,11 @@
93950 }
93951
93952 if( db->init.busy ){
93953 Trigger *pLink = pTrig;
93954 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
93955 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93956 pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);
93957 if( pTrig ){
93958 db->mallocFailed = 1;
93959 }else if( pLink->pSchema==pLink->pTabSchema ){
93960 Table *pTab;
@@ -94166,13 +94132,15 @@
94132
94133 assert( pName->nSrc==1 );
94134 zDb = pName->a[0].zDatabase;
94135 zName = pName->a[0].zName;
94136 nName = sqlite3Strlen30(zName);
94137 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
94138 for(i=OMIT_TEMPDB; i<db->nDb; i++){
94139 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
94140 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
94141 assert( sqlite3SchemaMutexHeld(db, j, 0) );
94142 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
94143 if( pTrigger ) break;
94144 }
94145 if( !pTrigger ){
94146 if( !noErr ){
@@ -94242,11 +94210,11 @@
94210 };
94211
94212 sqlite3BeginWriteOperation(pParse, 0, iDb);
94213 sqlite3OpenMasterTable(pParse, iDb);
94214 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
94215 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
94216 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
94217 sqlite3ChangeCookie(pParse, iDb);
94218 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
94219 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
94220 if( pParse->nMem<3 ){
@@ -94257,12 +94225,15 @@
94225
94226 /*
94227 ** Remove a trigger from the hash tables of the sqlite* pointer.
94228 */
94229 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
 
94230 Trigger *pTrigger;
94231 Hash *pHash;
94232
94233 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94234 pHash = &(db->aDb[iDb].pSchema->trigHash);
94235 pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0);
94236 if( ALWAYS(pTrigger) ){
94237 if( pTrigger->pSchema==pTrigger->pTabSchema ){
94238 Table *pTab = tableOfTrigger(pTrigger);
94239 Trigger **pp;
@@ -95782,14 +95753,17 @@
95753 sqlite3BtreeClose(pDb->pBt);
95754 pDb->pBt = 0;
95755 pDb->pSchema = 0;
95756 }
95757
95758 /* This both clears the schemas and reduces the size of the db->aDb[]
95759 ** array. */
95760 sqlite3ResetInternalSchema(db, -1);
95761
95762 return rc;
95763 }
95764
95765 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */
95766
95767 /************** End of vacuum.c **********************************************/
95768 /************** Begin file vtab.c ********************************************/
95769 /*
@@ -95839,11 +95813,11 @@
95813 }
95814 sqlite3DbFree(db, pDel);
95815 if( pDel==pMod ){
95816 db->mallocFailed = 1;
95817 }
95818 sqlite3ResetInternalSchema(db, -1);
95819 }else if( xDestroy ){
95820 xDestroy(pAux);
95821 }
95822 rc = sqlite3ApiExit(db, SQLITE_OK);
95823 sqlite3_mutex_leave(db->mutex);
@@ -95936,14 +95910,13 @@
95910
95911 /* Assert that the mutex (if any) associated with the BtShared database
95912 ** that contains table p is held by the caller. See header comments
95913 ** above function sqlite3VtabUnlockList() for an explanation of why
95914 ** this makes it safe to access the sqlite3.pDisconnect list of any
95915 ** database connection that may have an entry in the p->pVTable list.
95916 */
95917 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
 
95918
95919 while( pVTable ){
95920 sqlite3 *db2 = pVTable->db;
95921 VTable *pNext = pVTable->pNext;
95922 assert( db2 );
@@ -96178,10 +96151,11 @@
96151 else {
96152 Table *pOld;
96153 Schema *pSchema = pTab->pSchema;
96154 const char *zName = pTab->zName;
96155 int nName = sqlite3Strlen30(zName);
96156 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
96157 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
96158 if( pOld ){
96159 db->mallocFailed = 1;
96160 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
96161 return;
@@ -97132,11 +97106,11 @@
97106 ** Return the bitmask for the given cursor number. Return 0 if
97107 ** iCursor is not in the set.
97108 */
97109 static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){
97110 int i;
97111 assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 );
97112 for(i=0; i<pMaskSet->n; i++){
97113 if( pMaskSet->ix[i]==iCursor ){
97114 return ((Bitmask)1)<<i;
97115 }
97116 }
@@ -107007,11 +106981,12 @@
106981 if( !sqlite3SafetyCheckSickOrOk(db) ){
106982 return SQLITE_MISUSE_BKPT;
106983 }
106984 sqlite3_mutex_enter(db->mutex);
106985
106986 /* Force xDestroy calls on all virtual tables */
106987 sqlite3ResetInternalSchema(db, -1);
106988
106989 /* If a transaction is open, the ResetInternalSchema() call above
106990 ** will not have called the xDisconnect() method on any virtual
106991 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
106992 ** call will do so. We need to do this before the check for active
@@ -107050,11 +107025,11 @@
107025 if( j!=1 ){
107026 pDb->pSchema = 0;
107027 }
107028 }
107029 }
107030 sqlite3ResetInternalSchema(db, -1);
107031
107032 /* Tell the code in notify.c that the connection no longer holds any
107033 ** locks and does not require any further unlock-notify callbacks.
107034 */
107035 sqlite3ConnectionClosed(db);
@@ -107141,11 +107116,11 @@
107116 sqlite3VtabRollback(db);
107117 sqlite3EndBenignMalloc();
107118
107119 if( db->flags&SQLITE_InternChanges ){
107120 sqlite3ExpirePreparedStatements(db);
107121 sqlite3ResetInternalSchema(db, -1);
107122 }
107123
107124 /* Any deferred constraint violations have now been resolved. */
107125 db->nDeferredCons = 0;
107126
@@ -107210,11 +107185,11 @@
107185 #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
107186 static const u8 delays[] =
107187 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
107188 static const u8 totals[] =
107189 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
107190 # define NDELAY ArraySize(delays)
107191 sqlite3 *db = (sqlite3 *)ptr;
107192 int timeout = db->busyTimeout;
107193 int delay, prior;
107194
107195 assert( count>=0 );
@@ -113734,10 +113709,12 @@
113709 int nDb; /* Result of strlen(zDb) */
113710 int nFts3; /* Result of strlen(zFts3) */
113711 int nByte; /* Bytes of space to allocate here */
113712 int rc; /* value returned by declare_vtab() */
113713 Fts3auxTable *p; /* Virtual table object to return */
113714
113715 UNUSED_PARAMETER(pUnused);
113716
113717 /* The user should specify a single argument - the name of an fts3 table. */
113718 if( argc!=4 ){
113719 *pzErr = sqlite3_mprintf(
113720 "wrong number of arguments to fts4aux constructor"
@@ -113803,10 +113780,12 @@
113780 ){
113781 int i;
113782 int iEq = -1;
113783 int iGe = -1;
113784 int iLe = -1;
113785
113786 UNUSED_PARAMETER(pVTab);
113787
113788 /* This vtab delivers always results in "ORDER BY term ASC" order. */
113789 if( pInfo->nOrderBy==1
113790 && pInfo->aOrderBy[0].iColumn==0
113791 && pInfo->aOrderBy[0].desc==0
@@ -113851,10 +113830,12 @@
113830 /*
113831 ** xOpen - Open a cursor.
113832 */
113833 static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
113834 Fts3auxCursor *pCsr; /* Pointer to cursor object to return */
113835
113836 UNUSED_PARAMETER(pVTab);
113837
113838 pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor));
113839 if( !pCsr ) return SQLITE_NOMEM;
113840 memset(pCsr, 0, sizeof(Fts3auxCursor));
113841
@@ -114000,10 +113981,12 @@
113981 ){
113982 Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor;
113983 Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
113984 int rc;
113985 int isScan;
113986
113987 UNUSED_PARAMETER(nVal);
113988
113989 assert( idxStr==0 );
113990 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
113991 || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
113992 || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -122428,11 +122411,11 @@
122411 pCsr->nConstraint = argc;
122412 if( !pCsr->aConstraint ){
122413 rc = SQLITE_NOMEM;
122414 }else{
122415 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
122416 assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 );
122417 for(ii=0; ii<argc; ii++){
122418 RtreeConstraint *p = &pCsr->aConstraint[ii];
122419 p->op = idxStr[ii*2];
122420 p->iCoord = idxStr[ii*2+1]-'a';
122421 if( p->op==RTREE_MATCH ){
@@ -122521,11 +122504,11 @@
122504 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
122505 memset(zIdxStr, 0, sizeof(zIdxStr));
122506 UNUSED_PARAMETER(tab);
122507
122508 assert( pIdxInfo->idxStr==0 );
122509 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
122510 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
122511
122512 if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
122513 /* We have an equality constraint on the rowid. Use strategy 1. */
122514 int jj;
@@ -124644,10 +124627,12 @@
124627 static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
124628 UErrorCode status = U_ZERO_ERROR;
124629 URegularExpression *pExpr;
124630 UBool res;
124631 const UChar *zString = sqlite3_value_text16(apArg[1]);
124632
124633 (void)nArg; /* Unused parameter */
124634
124635 /* If the left hand side of the regexp operator is NULL,
124636 ** then the result is also NULL.
124637 */
124638 if( !zString ){
@@ -124873,11 +124858,11 @@
124858 };
124859
124860 int rc = SQLITE_OK;
124861 int i;
124862
124863 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
124864 struct IcuScalar *p = &scalars[i];
124865 rc = sqlite3_create_function(
124866 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
124867 );
124868 }
124869
+2 -2
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.6"
111111
#define SQLITE_VERSION_NUMBER 3007006
112
-#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906"
112
+#define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1132,11 +1132,11 @@
11321132
** changes to a [database connection]. The interface is similar to
11331133
** [sqlite3_config()] except that the changes apply to a single
11341134
** [database connection] (specified in the first argument).
11351135
**
11361136
** The second argument to sqlite3_db_config(D,V,...) is the
1137
-** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1137
+** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
11381138
** that indicates what aspect of the [database connection] is being configured.
11391139
** Subsequent arguments vary depending on the configuration verb.
11401140
**
11411141
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
11421142
** the call is considered successful.
11431143
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1132,11 +1132,11 @@
1132 ** changes to a [database connection]. The interface is similar to
1133 ** [sqlite3_config()] except that the changes apply to a single
1134 ** [database connection] (specified in the first argument).
1135 **
1136 ** The second argument to sqlite3_db_config(D,V,...) is the
1137 ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1138 ** that indicates what aspect of the [database connection] is being configured.
1139 ** Subsequent arguments vary depending on the configuration verb.
1140 **
1141 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1142 ** the call is considered successful.
1143
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1132,11 +1132,11 @@
1132 ** changes to a [database connection]. The interface is similar to
1133 ** [sqlite3_config()] except that the changes apply to a single
1134 ** [database connection] (specified in the first argument).
1135 **
1136 ** The second argument to sqlite3_db_config(D,V,...) is the
1137 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1138 ** that indicates what aspect of the [database connection] is being configured.
1139 ** Subsequent arguments vary depending on the configuration verb.
1140 **
1141 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1142 ** the call is considered successful.
1143

Keyboard Shortcuts

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