Fossil SCM

Update the built-in SQLite to the latest 3.7.7 alpha.

drh 2011-06-03 14:24 trunk
Commit 9f9047d686817a00a335a74756c67d3c2d108fb6
3 files changed +8 -3 +417 -281 +5 -3
+8 -3
--- src/shell.c
+++ src/shell.c
@@ -2300,10 +2300,15 @@
23002300
&& nArg==2
23012301
){
23022302
enableTimer = booleanValue(azArg[1]);
23032303
}else
23042304
2305
+ if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
2306
+ printf("SQLite %s %s\n",
2307
+ sqlite3_libversion(), sqlite3_sourceid());
2308
+ }else
2309
+
23052310
if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
23062311
int j;
23072312
assert( nArg<=ArraySize(azArg) );
23082313
for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
23092314
p->colWidth[j-1] = atoi(azArg[j]);
@@ -2840,11 +2845,11 @@
28402845
}else if( strcmp(z,"-stats")==0 ){
28412846
data.statsOn = 1;
28422847
}else if( strcmp(z,"-bail")==0 ){
28432848
bail_on_error = 1;
28442849
}else if( strcmp(z,"-version")==0 ){
2845
- printf("%s\n", sqlite3_libversion());
2850
+ printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
28462851
return 0;
28472852
}else if( strcmp(z,"-interactive")==0 ){
28482853
stdin_is_interactive = 1;
28492854
}else if( strcmp(z,"-batch")==0 ){
28502855
stdin_is_interactive = 0;
@@ -2885,14 +2890,14 @@
28852890
if( stdin_is_interactive ){
28862891
char *zHome;
28872892
char *zHistory = 0;
28882893
int nHistory;
28892894
printf(
2890
- "SQLite version %s\n"
2895
+ "SQLite version %s %.19s\n"
28912896
"Enter \".help\" for instructions\n"
28922897
"Enter SQL statements terminated with a \";\"\n",
2893
- sqlite3_libversion()
2898
+ sqlite3_libversion(), sqlite3_sourceid()
28942899
);
28952900
zHome = find_home_dir();
28962901
if( zHome ){
28972902
nHistory = strlen30(zHome) + 20;
28982903
if( (zHistory = malloc(nHistory))!=0 ){
28992904
--- src/shell.c
+++ src/shell.c
@@ -2300,10 +2300,15 @@
2300 && nArg==2
2301 ){
2302 enableTimer = booleanValue(azArg[1]);
2303 }else
2304
 
 
 
 
 
2305 if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
2306 int j;
2307 assert( nArg<=ArraySize(azArg) );
2308 for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
2309 p->colWidth[j-1] = atoi(azArg[j]);
@@ -2840,11 +2845,11 @@
2840 }else if( strcmp(z,"-stats")==0 ){
2841 data.statsOn = 1;
2842 }else if( strcmp(z,"-bail")==0 ){
2843 bail_on_error = 1;
2844 }else if( strcmp(z,"-version")==0 ){
2845 printf("%s\n", sqlite3_libversion());
2846 return 0;
2847 }else if( strcmp(z,"-interactive")==0 ){
2848 stdin_is_interactive = 1;
2849 }else if( strcmp(z,"-batch")==0 ){
2850 stdin_is_interactive = 0;
@@ -2885,14 +2890,14 @@
2885 if( stdin_is_interactive ){
2886 char *zHome;
2887 char *zHistory = 0;
2888 int nHistory;
2889 printf(
2890 "SQLite version %s\n"
2891 "Enter \".help\" for instructions\n"
2892 "Enter SQL statements terminated with a \";\"\n",
2893 sqlite3_libversion()
2894 );
2895 zHome = find_home_dir();
2896 if( zHome ){
2897 nHistory = strlen30(zHome) + 20;
2898 if( (zHistory = malloc(nHistory))!=0 ){
2899
--- src/shell.c
+++ src/shell.c
@@ -2300,10 +2300,15 @@
2300 && nArg==2
2301 ){
2302 enableTimer = booleanValue(azArg[1]);
2303 }else
2304
2305 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
2306 printf("SQLite %s %s\n",
2307 sqlite3_libversion(), sqlite3_sourceid());
2308 }else
2309
2310 if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
2311 int j;
2312 assert( nArg<=ArraySize(azArg) );
2313 for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
2314 p->colWidth[j-1] = atoi(azArg[j]);
@@ -2840,11 +2845,11 @@
2845 }else if( strcmp(z,"-stats")==0 ){
2846 data.statsOn = 1;
2847 }else if( strcmp(z,"-bail")==0 ){
2848 bail_on_error = 1;
2849 }else if( strcmp(z,"-version")==0 ){
2850 printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
2851 return 0;
2852 }else if( strcmp(z,"-interactive")==0 ){
2853 stdin_is_interactive = 1;
2854 }else if( strcmp(z,"-batch")==0 ){
2855 stdin_is_interactive = 0;
@@ -2885,14 +2890,14 @@
2890 if( stdin_is_interactive ){
2891 char *zHome;
2892 char *zHistory = 0;
2893 int nHistory;
2894 printf(
2895 "SQLite version %s %.19s\n"
2896 "Enter \".help\" for instructions\n"
2897 "Enter SQL statements terminated with a \";\"\n",
2898 sqlite3_libversion(), sqlite3_sourceid()
2899 );
2900 zHome = find_home_dir();
2901 if( zHome ){
2902 nHistory = strlen30(zHome) + 20;
2903 if( (zHistory = malloc(nHistory))!=0 ){
2904
+417 -281
--- 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.7"
654654
#define SQLITE_VERSION_NUMBER 3007007
655
-#define SQLITE_SOURCE_ID "2011-05-20 01:50:01 2018d4e108872f2436df046636401b89cfde589d"
655
+#define SQLITE_SOURCE_ID "2011-06-03 14:19:10 0206bc6f87bb9393218a380fc5b18039d334a8d8"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1000,10 +1000,12 @@
10001000
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
10011001
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
10021002
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
10031003
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
10041004
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1005
+#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1006
+#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
10051007
10061008
/*
10071009
** CAPI3REF: Flags For File Open Operations
10081010
**
10091011
** These bit values are intended for use in the
@@ -1305,15 +1307,15 @@
13051307
*/
13061308
typedef struct sqlite3_mutex sqlite3_mutex;
13071309
13081310
/*
13091311
** CAPI3REF: OS Interface Object
1310
-** KEYWORDS: VFS VFSes
13111312
**
13121313
** An instance of the sqlite3_vfs object defines the interface between
13131314
** the SQLite core and the underlying operating system. The "vfs"
1314
-** in the name of the object stands for "virtual file system".
1315
+** in the name of the object stands for "virtual file system". See
1316
+** the [VFS | VFS documentation] for further information.
13151317
**
13161318
** The value of the iVersion field is initially 1 but may be larger in
13171319
** future versions of SQLite. Additional fields may be appended to this
13181320
** object when the iVersion value is increased. Note that the structure
13191321
** of the sqlite3_vfs object changes in the transaction between
@@ -8494,19 +8496,20 @@
84948496
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
84958497
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
84968498
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
84978499
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
84988500
SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
8499
-SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int);
8501
+SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
85008502
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
85018503
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
85028504
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
85038505
#ifdef SQLITE_DEBUG
85048506
SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
85058507
SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
85068508
#endif
85078509
SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
8510
+SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
85088511
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
85098512
SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
85108513
SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
85118514
SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
85128515
SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
@@ -9832,10 +9835,11 @@
98329835
sqlite3 *db; /* Database connection associated with this table */
98339836
Module *pMod; /* Pointer to module implementation */
98349837
sqlite3_vtab *pVtab; /* Pointer to vtab instance */
98359838
int nRef; /* Number of pointers to this structure */
98369839
u8 bConstraint; /* True if constraints are supported */
9840
+ int iSavepoint; /* Depth of the SAVEPOINT stack */
98379841
VTable *pNext; /* Next in linked list (see above) */
98389842
};
98399843
98409844
/*
98419845
** Each SQL table is represented in memory by an instance of the
@@ -10826,13 +10830,12 @@
1082610830
1082710831
/* Above is constant between recursions. Below is reset before and after
1082810832
** each recursion */
1082910833
1083010834
int nVar; /* Number of '?' variables seen in the SQL so far */
10831
- int nVarExpr; /* Number of used slots in apVarExpr[] */
10832
- int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */
10833
- Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */
10835
+ int nzVar; /* Number of available slots in azVar[] */
10836
+ char **azVar; /* Pointers to names of parameters */
1083410837
Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
1083510838
int nAlias; /* Number of aliased result set columns */
1083610839
int nAliasAlloc; /* Number of allocated slots for aAlias[] */
1083710840
int *aAlias; /* Register used to hold aliased result */
1083810841
u8 explain; /* True if the EXPLAIN flag is found on the query */
@@ -12761,15 +12764,15 @@
1276112764
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
1276212765
VdbeCursor **apCsr; /* One element of this array for each open cursor */
1276312766
Mem *aVar; /* Values for the OP_Variable opcode. */
1276412767
char **azVar; /* Name of variables */
1276512768
ynVar nVar; /* Number of entries in aVar[] */
12769
+ ynVar nzVar; /* Number of entries in azVar[] */
1276612770
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1276712771
int pc; /* The program counter */
1276812772
int rc; /* Value to return */
1276912773
u8 errorAction; /* Recovery action to do in case of an error */
12770
- u8 okVar; /* True if azVar[] has been initialized */
1277112774
u8 explain; /* True if EXPLAIN present on SQL command */
1277212775
u8 changeCntOn; /* True to update the change-counter */
1277312776
u8 expired; /* True if the VM needs to be recompiled */
1277412777
u8 runOnlyOnce; /* Automatically expire on reset */
1277512778
u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -27963,11 +27966,12 @@
2796327966
unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */
2796427967
sqlite3_mutex *mutex; /* Mutex to access this object */
2796527968
char *zFilename; /* Name of the mmapped file */
2796627969
int h; /* Open file descriptor */
2796727970
int szRegion; /* Size of shared-memory regions */
27968
- int nRegion; /* Size of array apRegion */
27971
+ u16 nRegion; /* Size of array apRegion */
27972
+ u8 isReadonly; /* True if read-only */
2796927973
char **apRegion; /* Array of mapped shared-memory regions */
2797027974
int nRef; /* Number of unixShm objects pointing to this */
2797127975
unixShm *pFirst; /* All unixShm objects pointing to this */
2797227976
#ifdef SQLITE_DEBUG
2797327977
u8 exclMask; /* Mask of exclusive locks held */
@@ -28210,12 +28214,21 @@
2821028214
2821128215
if( pInode->bProcessLock==0 ){
2821228216
pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
2821328217
(sStat.st_mode & 0777));
2821428218
if( pShmNode->h<0 ){
28215
- rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
28216
- goto shm_open_err;
28219
+ const char *zRO;
28220
+ zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm");
28221
+ if( zRO && sqlite3GetBoolean(zRO) ){
28222
+ pShmNode->h = robust_open(zShmFilename, O_RDONLY,
28223
+ (sStat.st_mode & 0777));
28224
+ pShmNode->isReadonly = 1;
28225
+ }
28226
+ if( pShmNode->h<0 ){
28227
+ rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
28228
+ goto shm_open_err;
28229
+ }
2821728230
}
2821828231
2821928232
/* Check to see if another process is holding the dead-man switch.
2822028233
** If not, truncate the file to zero length.
2822128234
*/
@@ -28350,11 +28363,12 @@
2835028363
}
2835128364
pShmNode->apRegion = apNew;
2835228365
while(pShmNode->nRegion<=iRegion){
2835328366
void *pMem;
2835428367
if( pShmNode->h>=0 ){
28355
- pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
28368
+ pMem = mmap(0, szRegion,
28369
+ pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
2835628370
MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
2835728371
);
2835828372
if( pMem==MAP_FAILED ){
2835928373
rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
2836028374
goto shmpage_out;
@@ -28376,10 +28390,11 @@
2837628390
if( pShmNode->nRegion>iRegion ){
2837728391
*pp = pShmNode->apRegion[iRegion];
2837828392
}else{
2837928393
*pp = 0;
2838028394
}
28395
+ if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
2838128396
sqlite3_mutex_leave(pShmNode->mutex);
2838228397
return rc;
2838328398
}
2838428399
2838528400
/*
@@ -34873,10 +34888,17 @@
3487334888
if( !pPg ){
3487434889
for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
3487534890
}
3487634891
if( pPg ){
3487734892
int rc;
34893
+#ifdef SQLITE_LOG_CACHE_SPILL
34894
+ sqlite3_log(SQLITE_FULL,
34895
+ "spill page %d making room for %d - cache used: %d/%d",
34896
+ pPg->pgno, pgno,
34897
+ sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
34898
+ pCache->nMax);
34899
+#endif
3487834900
rc = pCache->xStress(pCache->pStress, pPg);
3487934901
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
3488034902
return rc;
3488134903
}
3488234904
}
@@ -43977,11 +43999,11 @@
4397743999
u32 szPage; /* Database page size */
4397844000
i16 readLock; /* Which read lock is being held. -1 for none */
4397944001
u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
4398044002
u8 writeLock; /* True if in a write transaction */
4398144003
u8 ckptLock; /* True if holding a checkpoint lock */
43982
- u8 readOnly; /* True if the WAL file is open read-only */
44004
+ u8 readOnly; /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
4398344005
WalIndexHdr hdr; /* Wal-index header for current transaction */
4398444006
const char *zWalName; /* Name of WAL file */
4398544007
u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
4398644008
#ifdef SQLITE_DEBUG
4398744009
u8 lockError; /* True if a locking error has occurred */
@@ -43993,10 +44015,17 @@
4399344015
*/
4399444016
#define WAL_NORMAL_MODE 0
4399544017
#define WAL_EXCLUSIVE_MODE 1
4399644018
#define WAL_HEAPMEMORY_MODE 2
4399744019
44020
+/*
44021
+** Possible values for WAL.readOnly
44022
+*/
44023
+#define WAL_RDWR 0 /* Normal read/write connection */
44024
+#define WAL_RDONLY 1 /* The WAL file is readonly */
44025
+#define WAL_SHM_RDONLY 2 /* The SHM file is readonly */
44026
+
4399844027
/*
4399944028
** Each page of the wal-index mapping contains a hash-table made up of
4400044029
** an array of HASHTABLE_NSLOT elements of the following type.
4400144030
*/
4400244031
typedef u16 ht_slot;
@@ -44086,10 +44115,14 @@
4408644115
if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
4408744116
}else{
4408844117
rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
4408944118
pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
4409044119
);
44120
+ if( rc==SQLITE_READONLY ){
44121
+ pWal->readOnly |= WAL_SHM_RDONLY;
44122
+ rc = SQLITE_OK;
44123
+ }
4409144124
}
4409244125
}
4409344126
4409444127
*ppPage = pWal->apWiData[iPage];
4409544128
assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
@@ -44833,11 +44866,11 @@
4483344866
4483444867
/* Open file handle on the write-ahead log file. */
4483544868
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
4483644869
rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
4483744870
if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
44838
- pRet->readOnly = 1;
44871
+ pRet->readOnly = WAL_RDONLY;
4483944872
}
4484044873
4484144874
if( rc!=SQLITE_OK ){
4484244875
walIndexClose(pRet, 0);
4484344876
sqlite3OsClose(pRet->pWalFd);
@@ -45474,25 +45507,32 @@
4547445507
4547545508
/* If the first attempt failed, it might have been due to a race
4547645509
** with a writer. So get a WRITE lock and try again.
4547745510
*/
4547845511
assert( badHdr==0 || pWal->writeLock==0 );
45479
- if( badHdr && SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
45480
- pWal->writeLock = 1;
45481
- if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
45482
- badHdr = walIndexTryHdr(pWal, pChanged);
45483
- if( badHdr ){
45484
- /* If the wal-index header is still malformed even while holding
45485
- ** a WRITE lock, it can only mean that the header is corrupted and
45486
- ** needs to be reconstructed. So run recovery to do exactly that.
45487
- */
45488
- rc = walIndexRecover(pWal);
45489
- *pChanged = 1;
45490
- }
45491
- }
45492
- pWal->writeLock = 0;
45493
- walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
45512
+ if( badHdr ){
45513
+ if( pWal->readOnly & WAL_SHM_RDONLY ){
45514
+ if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
45515
+ walUnlockShared(pWal, WAL_WRITE_LOCK);
45516
+ rc = SQLITE_READONLY_RECOVERY;
45517
+ }
45518
+ }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
45519
+ pWal->writeLock = 1;
45520
+ if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
45521
+ badHdr = walIndexTryHdr(pWal, pChanged);
45522
+ if( badHdr ){
45523
+ /* If the wal-index header is still malformed even while holding
45524
+ ** a WRITE lock, it can only mean that the header is corrupted and
45525
+ ** needs to be reconstructed. So run recovery to do exactly that.
45526
+ */
45527
+ rc = walIndexRecover(pWal);
45528
+ *pChanged = 1;
45529
+ }
45530
+ }
45531
+ pWal->writeLock = 0;
45532
+ walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
45533
+ }
4549445534
}
4549545535
4549645536
/* If the header is read successfully, check the version number to make
4549745537
** sure the wal-index was not constructed with some future format that
4549845538
** this version of SQLite cannot understand.
@@ -45675,11 +45715,13 @@
4567545715
mxI = i;
4567645716
}
4567745717
}
4567845718
/* There was once an "if" here. The extra "{" is to preserve indentation. */
4567945719
{
45680
- if( mxReadMark < pWal->hdr.mxFrame || mxI==0 ){
45720
+ if( (pWal->readOnly & WAL_SHM_RDONLY)==0
45721
+ && (mxReadMark<pWal->hdr.mxFrame || mxI==0)
45722
+ ){
4568145723
for(i=1; i<WAL_NREADER; i++){
4568245724
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
4568345725
if( rc==SQLITE_OK ){
4568445726
mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
4568545727
mxI = i;
@@ -45689,12 +45731,12 @@
4568945731
return rc;
4569045732
}
4569145733
}
4569245734
}
4569345735
if( mxI==0 ){
45694
- assert( rc==SQLITE_BUSY );
45695
- return WAL_RETRY;
45736
+ assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
45737
+ return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK;
4569645738
}
4569745739
4569845740
rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
4569945741
if( rc ){
4570045742
return rc==SQLITE_BUSY ? WAL_RETRY : rc;
@@ -46096,14 +46138,16 @@
4609646138
** set to a non-negative value. Log errors encountered
4609746139
** during the truncation attempt. */
4609846140
if( pWal->mxWalSize>=0 ){
4609946141
i64 sz;
4610046142
int rx;
46143
+ sqlite3BeginBenignMalloc();
4610146144
rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
4610246145
if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
4610346146
rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
4610446147
}
46148
+ sqlite3EndBenignMalloc();
4610546149
if( rx ){
4610646150
sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
4610746151
}
4610846152
}
4610946153
@@ -46330,10 +46374,11 @@
4633046374
int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
4633146375
4633246376
assert( pWal->ckptLock==0 );
4633346377
assert( pWal->writeLock==0 );
4633446378
46379
+ if( pWal->readOnly ) return SQLITE_READONLY;
4633546380
WALTRACE(("WAL%p: checkpoint begins\n", pWal));
4633646381
rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
4633746382
if( rc ){
4633846383
/* Usually this is SQLITE_BUSY meaning that another thread or process
4633946384
** is already running a checkpoint, or maybe a recovery. But it might
@@ -52812,14 +52857,14 @@
5281252857
** removes the reference to the cell from pPage.
5281352858
**
5281452859
** "sz" must be the number of bytes in the cell.
5281552860
*/
5281652861
static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
52817
- int i; /* Loop counter */
5281852862
u32 pc; /* Offset to cell content of cell being deleted */
5281952863
u8 *data; /* pPage->aData */
5282052864
u8 *ptr; /* Used to move bytes around within data[] */
52865
+ u8 *endPtr; /* End of loop */
5282152866
int rc; /* The return code */
5282252867
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
5282352868
5282452869
if( *pRC ) return;
5282552870
@@ -52840,13 +52885,15 @@
5284052885
rc = freeSpace(pPage, pc, sz);
5284152886
if( rc ){
5284252887
*pRC = rc;
5284352888
return;
5284452889
}
52845
- for(i=idx+1; i<pPage->nCell; i++, ptr+=2){
52890
+ endPtr = &data[pPage->cellOffset + 2*pPage->nCell - 2];
52891
+ while( ptr<endPtr ){
5284652892
ptr[0] = ptr[2];
5284752893
ptr[1] = ptr[3];
52894
+ ptr += 2;
5284852895
}
5284952896
pPage->nCell--;
5285052897
put2byte(&data[hdr+3], pPage->nCell);
5285152898
pPage->nFree += 2;
5285252899
}
@@ -58825,38 +58872,17 @@
5882558872
}
5882658873
return pBuf;
5882758874
}
5882858875
5882958876
/*
58830
-** Prepare a virtual machine for execution. This involves things such
58831
-** as allocating stack space and initializing the program counter.
58832
-** After the VDBE has be prepped, it can be executed by one or more
58833
-** calls to sqlite3VdbeExec().
58834
-**
58835
-** This is the only way to move a VDBE from VDBE_MAGIC_INIT to
58836
-** VDBE_MAGIC_RUN.
58837
-**
58838
-** This function may be called more than once on a single virtual machine.
58839
-** The first call is made while compiling the SQL statement. Subsequent
58840
-** calls are made as part of the process of resetting a statement to be
58841
-** re-executed (from a call to sqlite3_reset()). The nVar, nMem, nCursor
58842
-** and isExplain parameters are only passed correct values the first time
58843
-** the function is called. On subsequent calls, from sqlite3_reset(), nVar
58844
-** is passed -1 and nMem, nCursor and isExplain are all passed zero.
58877
+** Rewind the VDBE back to the beginning in preparation for
58878
+** running it.
5884558879
*/
58846
-SQLITE_PRIVATE void sqlite3VdbeMakeReady(
58847
- Vdbe *p, /* The VDBE */
58848
- int nVar, /* Number of '?' see in the SQL statement */
58849
- int nMem, /* Number of memory cells to allocate */
58850
- int nCursor, /* Number of cursors to allocate */
58851
- int nArg, /* Maximum number of args in SubPrograms */
58852
- int isExplain, /* True if the EXPLAIN keywords is present */
58853
- int usesStmtJournal /* True to set Vdbe.usesStmtJournal */
58854
-){
58855
- int n;
58856
- sqlite3 *db = p->db;
58857
-
58880
+SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
58881
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
58882
+ int i;
58883
+#endif
5885858884
assert( p!=0 );
5885958885
assert( p->magic==VDBE_MAGIC_INIT );
5886058886
5886158887
/* There should be at least one opcode.
5886258888
*/
@@ -58863,10 +58889,75 @@
5886358889
assert( p->nOp>0 );
5886458890
5886558891
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
5886658892
p->magic = VDBE_MAGIC_RUN;
5886758893
58894
+#ifdef SQLITE_DEBUG
58895
+ for(i=1; i<p->nMem; i++){
58896
+ assert( p->aMem[i].db==p->db );
58897
+ }
58898
+#endif
58899
+ p->pc = -1;
58900
+ p->rc = SQLITE_OK;
58901
+ p->errorAction = OE_Abort;
58902
+ p->magic = VDBE_MAGIC_RUN;
58903
+ p->nChange = 0;
58904
+ p->cacheCtr = 1;
58905
+ p->minWriteFileFormat = 255;
58906
+ p->iStatement = 0;
58907
+ p->nFkConstraint = 0;
58908
+#ifdef VDBE_PROFILE
58909
+ for(i=0; i<p->nOp; i++){
58910
+ p->aOp[i].cnt = 0;
58911
+ p->aOp[i].cycles = 0;
58912
+ }
58913
+#endif
58914
+}
58915
+
58916
+/*
58917
+** Prepare a virtual machine for execution for the first time after
58918
+** creating the virtual machine. This involves things such
58919
+** as allocating stack space and initializing the program counter.
58920
+** After the VDBE has be prepped, it can be executed by one or more
58921
+** calls to sqlite3VdbeExec().
58922
+**
58923
+** This function may be called exact once on a each virtual machine.
58924
+** After this routine is called the VM has been "packaged" and is ready
58925
+** to run. After this routine is called, futher calls to
58926
+** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
58927
+** the Vdbe from the Parse object that helped generate it so that the
58928
+** the Vdbe becomes an independent entity and the Parse object can be
58929
+** destroyed.
58930
+**
58931
+** Use the sqlite3VdbeRewind() procedure to restore a virtual machine back
58932
+** to its initial state after it has been run.
58933
+*/
58934
+SQLITE_PRIVATE void sqlite3VdbeMakeReady(
58935
+ Vdbe *p, /* The VDBE */
58936
+ Parse *pParse /* Parsing context */
58937
+){
58938
+ sqlite3 *db; /* The database connection */
58939
+ int nVar; /* Number of parameters */
58940
+ int nMem; /* Number of VM memory registers */
58941
+ int nCursor; /* Number of cursors required */
58942
+ int nArg; /* Number of arguments in subprograms */
58943
+ int n; /* Loop counter */
58944
+ u8 *zCsr; /* Memory available for allocation */
58945
+ u8 *zEnd; /* First byte past allocated memory */
58946
+ int nByte; /* How much extra memory is needed */
58947
+
58948
+ assert( p!=0 );
58949
+ assert( p->nOp>0 );
58950
+ assert( pParse!=0 );
58951
+ assert( p->magic==VDBE_MAGIC_INIT );
58952
+ db = p->db;
58953
+ assert( db->mallocFailed==0 );
58954
+ nVar = pParse->nVar;
58955
+ nMem = pParse->nMem;
58956
+ nCursor = pParse->nTab;
58957
+ nArg = pParse->nMaxArg;
58958
+
5886858959
/* For each cursor required, also allocate a memory cell. Memory
5886958960
** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
5887058961
** the vdbe program. Instead they are used to allocate space for
5887158962
** VdbeCursor/BtCursor structures. The blob of memory associated with
5887258963
** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
@@ -58875,95 +58966,72 @@
5887558966
** See also: allocateCursor().
5887658967
*/
5887758968
nMem += nCursor;
5887858969
5887958970
/* Allocate space for memory registers, SQL variables, VDBE cursors and
58880
- ** an array to marshal SQL function arguments in. This is only done the
58881
- ** first time this function is called for a given VDBE, not when it is
58882
- ** being called from sqlite3_reset() to reset the virtual machine.
58883
- */
58884
- if( nVar>=0 && ALWAYS(db->mallocFailed==0) ){
58885
- u8 *zCsr = (u8 *)&p->aOp[p->nOp]; /* Memory avaliable for alloation */
58886
- u8 *zEnd = (u8 *)&p->aOp[p->nOpAlloc]; /* First byte past available mem */
58887
- int nByte; /* How much extra memory needed */
58888
-
58889
- resolveP2Values(p, &nArg);
58890
- p->usesStmtJournal = (u8)usesStmtJournal;
58891
- if( isExplain && nMem<10 ){
58892
- nMem = 10;
58893
- }
58894
- memset(zCsr, 0, zEnd-zCsr);
58895
- zCsr += (zCsr - (u8*)0)&7;
58896
- assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
58897
-
58898
- /* Memory for registers, parameters, cursor, etc, is allocated in two
58899
- ** passes. On the first pass, we try to reuse unused space at the
58900
- ** end of the opcode array. If we are unable to satisfy all memory
58901
- ** requirements by reusing the opcode array tail, then the second
58902
- ** pass will fill in the rest using a fresh allocation.
58903
- **
58904
- ** This two-pass approach that reuses as much memory as possible from
58905
- ** the leftover space at the end of the opcode array can significantly
58906
- ** reduce the amount of memory held by a prepared statement.
58907
- */
58908
- do {
58909
- nByte = 0;
58910
- p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
58911
- p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
58912
- p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
58913
- p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
58914
- p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
58915
- &zCsr, zEnd, &nByte);
58916
- if( nByte ){
58917
- p->pFree = sqlite3DbMallocZero(db, nByte);
58918
- }
58919
- zCsr = p->pFree;
58920
- zEnd = &zCsr[nByte];
58921
- }while( nByte && !db->mallocFailed );
58922
-
58923
- p->nCursor = (u16)nCursor;
58924
- if( p->aVar ){
58925
- p->nVar = (ynVar)nVar;
58926
- for(n=0; n<nVar; n++){
58927
- p->aVar[n].flags = MEM_Null;
58928
- p->aVar[n].db = db;
58929
- }
58930
- }
58931
- if( p->aMem ){
58932
- p->aMem--; /* aMem[] goes from 1..nMem */
58933
- p->nMem = nMem; /* not from 0..nMem-1 */
58934
- for(n=1; n<=nMem; n++){
58935
- p->aMem[n].flags = MEM_Null;
58936
- p->aMem[n].db = db;
58937
- }
58938
- }
58939
- }
58940
-#ifdef SQLITE_DEBUG
58941
- for(n=1; n<p->nMem; n++){
58942
- assert( p->aMem[n].db==db );
58943
- }
58944
-#endif
58945
-
58946
- p->pc = -1;
58947
- p->rc = SQLITE_OK;
58948
- p->errorAction = OE_Abort;
58949
- p->explain |= isExplain;
58950
- p->magic = VDBE_MAGIC_RUN;
58951
- p->nChange = 0;
58952
- p->cacheCtr = 1;
58953
- p->minWriteFileFormat = 255;
58954
- p->iStatement = 0;
58955
- p->nFkConstraint = 0;
58956
-#ifdef VDBE_PROFILE
58957
- {
58958
- int i;
58959
- for(i=0; i<p->nOp; i++){
58960
- p->aOp[i].cnt = 0;
58961
- p->aOp[i].cycles = 0;
58962
- }
58963
- }
58964
-#endif
58971
+ ** an array to marshal SQL function arguments in.
58972
+ */
58973
+ zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
58974
+ zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
58975
+
58976
+ resolveP2Values(p, &nArg);
58977
+ p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
58978
+ if( pParse->explain && nMem<10 ){
58979
+ nMem = 10;
58980
+ }
58981
+ memset(zCsr, 0, zEnd-zCsr);
58982
+ zCsr += (zCsr - (u8*)0)&7;
58983
+ assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
58984
+
58985
+ /* Memory for registers, parameters, cursor, etc, is allocated in two
58986
+ ** passes. On the first pass, we try to reuse unused space at the
58987
+ ** end of the opcode array. If we are unable to satisfy all memory
58988
+ ** requirements by reusing the opcode array tail, then the second
58989
+ ** pass will fill in the rest using a fresh allocation.
58990
+ **
58991
+ ** This two-pass approach that reuses as much memory as possible from
58992
+ ** the leftover space at the end of the opcode array can significantly
58993
+ ** reduce the amount of memory held by a prepared statement.
58994
+ */
58995
+ do {
58996
+ nByte = 0;
58997
+ p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
58998
+ p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
58999
+ p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
59000
+ p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
59001
+ p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
59002
+ &zCsr, zEnd, &nByte);
59003
+ if( nByte ){
59004
+ p->pFree = sqlite3DbMallocZero(db, nByte);
59005
+ }
59006
+ zCsr = p->pFree;
59007
+ zEnd = &zCsr[nByte];
59008
+ }while( nByte && !db->mallocFailed );
59009
+
59010
+ p->nCursor = (u16)nCursor;
59011
+ if( p->aVar ){
59012
+ p->nVar = (ynVar)nVar;
59013
+ for(n=0; n<nVar; n++){
59014
+ p->aVar[n].flags = MEM_Null;
59015
+ p->aVar[n].db = db;
59016
+ }
59017
+ }
59018
+ if( p->azVar ){
59019
+ p->nzVar = pParse->nzVar;
59020
+ memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
59021
+ memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
59022
+ }
59023
+ if( p->aMem ){
59024
+ p->aMem--; /* aMem[] goes from 1..nMem */
59025
+ p->nMem = nMem; /* not from 0..nMem-1 */
59026
+ for(n=1; n<=nMem; n++){
59027
+ p->aMem[n].flags = MEM_Null;
59028
+ p->aMem[n].db = db;
59029
+ }
59030
+ }
59031
+ p->explain = pParse->explain;
59032
+ sqlite3VdbeRewind(p);
5896559033
}
5896659034
5896759035
/*
5896859036
** Close a VDBE cursor and release all the resources that cursor
5896959037
** happens to hold.
@@ -59636,21 +59704,15 @@
5963659704
/* If eStatementOp is non-zero, then a statement transaction needs to
5963759705
** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
5963859706
** do so. If this operation returns an error, and the current statement
5963959707
** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
5964059708
** current statement error code.
59641
- **
59642
- ** Note that sqlite3VdbeCloseStatement() can only fail if eStatementOp
59643
- ** is SAVEPOINT_ROLLBACK. But if p->rc==SQLITE_OK then eStatementOp
59644
- ** must be SAVEPOINT_RELEASE. Hence the NEVER(p->rc==SQLITE_OK) in
59645
- ** the following code.
5964659709
*/
5964759710
if( eStatementOp ){
5964859711
rc = sqlite3VdbeCloseStatement(p, eStatementOp);
5964959712
if( rc ){
59650
- assert( eStatementOp==SAVEPOINT_ROLLBACK );
59651
- if( NEVER(p->rc==SQLITE_OK) || p->rc==SQLITE_CONSTRAINT ){
59713
+ if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){
5965259714
p->rc = rc;
5965359715
sqlite3DbFree(db, p->zErrMsg);
5965459716
p->zErrMsg = 0;
5965559717
}
5965659718
invalidateCursorsOnModifiedBtrees(db);
@@ -59839,18 +59901,20 @@
5983959901
** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
5984059902
** the database connection.
5984159903
*/
5984259904
SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
5984359905
SubProgram *pSub, *pNext;
59906
+ int i;
5984459907
assert( p->db==0 || p->db==db );
5984559908
releaseMemArray(p->aVar, p->nVar);
5984659909
releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
5984759910
for(pSub=p->pProgram; pSub; pSub=pNext){
5984859911
pNext = pSub->pNext;
5984959912
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
5985059913
sqlite3DbFree(db, pSub);
5985159914
}
59915
+ for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
5985259916
vdbeFreeOpArray(db, p->aOp, p->nOp);
5985359917
sqlite3DbFree(db, p->aLabel);
5985459918
sqlite3DbFree(db, p->aColName);
5985559919
sqlite3DbFree(db, p->zSql);
5985659920
sqlite3DbFree(db, p->pFree);
@@ -60292,11 +60356,11 @@
6029260356
u32 serial_type;
6029360357
6029460358
idx += getVarint32(&aKey[idx], serial_type);
6029560359
pMem->enc = pKeyInfo->enc;
6029660360
pMem->db = pKeyInfo->db;
60297
- pMem->flags = 0;
60361
+ /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
6029860362
pMem->zMalloc = 0;
6029960363
d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
6030060364
pMem++;
6030160365
u++;
6030260366
}
@@ -60307,10 +60371,11 @@
6030760371
6030860372
/*
6030960373
** This routine destroys a UnpackedRecord object.
6031060374
*/
6031160375
SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord *p){
60376
+#ifdef SQLITE_DEBUG
6031260377
int i;
6031360378
Mem *pMem;
6031460379
6031560380
assert( p!=0 );
6031660381
assert( p->flags & UNPACKED_NEED_DESTROY );
@@ -60320,10 +60385,11 @@
6032060385
** strings and blobs static. And none of the elements are
6032160386
** ever transformed, so there is never anything to delete.
6032260387
*/
6032360388
if( NEVER(pMem->zMalloc) ) sqlite3VdbeMemRelease(pMem);
6032460389
}
60390
+#endif
6032560391
if( p->flags & UNPACKED_NEED_FREE ){
6032660392
sqlite3DbFree(p->pKeyInfo->db, p);
6032760393
}
6032860394
}
6032960395
@@ -60755,11 +60821,11 @@
6075560821
rc = SQLITE_OK;
6075660822
}else{
6075760823
Vdbe *v = (Vdbe*)pStmt;
6075860824
sqlite3_mutex_enter(v->db->mutex);
6075960825
rc = sqlite3VdbeReset(v);
60760
- sqlite3VdbeMakeReady(v, -1, 0, 0, 0, 0, 0);
60826
+ sqlite3VdbeRewind(v);
6076160827
assert( (rc & (v->db->errMask))==rc );
6076260828
rc = sqlite3ApiExit(v->db, rc);
6076360829
sqlite3_mutex_leave(v->db->mutex);
6076460830
}
6076560831
return rc;
@@ -61820,48 +61886,21 @@
6182061886
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
6182161887
Vdbe *p = (Vdbe*)pStmt;
6182261888
return p ? p->nVar : 0;
6182361889
}
6182461890
61825
-/*
61826
-** Create a mapping from variable numbers to variable names
61827
-** in the Vdbe.azVar[] array, if such a mapping does not already
61828
-** exist.
61829
-*/
61830
-static void createVarMap(Vdbe *p){
61831
- if( !p->okVar ){
61832
- int j;
61833
- Op *pOp;
61834
- sqlite3_mutex_enter(p->db->mutex);
61835
- /* The race condition here is harmless. If two threads call this
61836
- ** routine on the same Vdbe at the same time, they both might end
61837
- ** up initializing the Vdbe.azVar[] array. That is a little extra
61838
- ** work but it results in the same answer.
61839
- */
61840
- for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
61841
- if( pOp->opcode==OP_Variable ){
61842
- assert( pOp->p1>0 && pOp->p1<=p->nVar );
61843
- p->azVar[pOp->p1-1] = pOp->p4.z;
61844
- }
61845
- }
61846
- p->okVar = 1;
61847
- sqlite3_mutex_leave(p->db->mutex);
61848
- }
61849
-}
61850
-
6185161891
/*
6185261892
** Return the name of a wildcard parameter. Return NULL if the index
6185361893
** is out of range or if the wildcard is unnamed.
6185461894
**
6185561895
** The result is always UTF-8.
6185661896
*/
6185761897
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
6185861898
Vdbe *p = (Vdbe*)pStmt;
61859
- if( p==0 || i<1 || i>p->nVar ){
61899
+ if( p==0 || i<1 || i>p->nzVar ){
6186061900
return 0;
6186161901
}
61862
- createVarMap(p);
6186361902
return p->azVar[i-1];
6186461903
}
6186561904
6186661905
/*
6186761906
** Given a wildcard parameter name, return the index of the variable
@@ -61871,13 +61910,12 @@
6187161910
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
6187261911
int i;
6187361912
if( p==0 ){
6187461913
return 0;
6187561914
}
61876
- createVarMap(p);
6187761915
if( zName ){
61878
- for(i=0; i<p->nVar; i++){
61916
+ for(i=0; i<p->nzVar; i++){
6187961917
const char *z = p->azVar[i];
6188061918
if( z && memcmp(z,zName,nName)==0 && z[nName]==0 ){
6188161919
return i+1;
6188261920
}
6188361921
}
@@ -63197,10 +63235,11 @@
6319763235
Mem **apArg;
6319863236
Mem *pX;
6319963237
} cm;
6320063238
struct OP_Trace_stack_vars {
6320163239
char *zTrace;
63240
+ char *z;
6320263241
} cn;
6320363242
} u;
6320463243
/* End automatically generated code
6320563244
********************************************************************/
6320663245
@@ -63623,10 +63662,11 @@
6362363662
#if 0 /* local variables moved into u.ab */
6362463663
Mem *pVar; /* Value being transferred */
6362563664
#endif /* local variables moved into u.ab */
6362663665
6362763666
assert( pOp->p1>0 && pOp->p1<=p->nVar );
63667
+ assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
6362863668
u.ab.pVar = &p->aVar[pOp->p1 - 1];
6362963669
if( sqlite3VdbeMemTooBig(u.ab.pVar) ){
6363063670
goto too_big;
6363163671
}
6363263672
sqlite3VdbeMemShallowCopy(pOut, u.ab.pVar, MEM_Static);
@@ -64415,19 +64455,19 @@
6441564455
6441664456
pIn1 = &aMem[pOp->p1];
6441764457
pIn3 = &aMem[pOp->p3];
6441864458
u.ai.flags1 = pIn1->flags;
6441964459
u.ai.flags3 = pIn3->flags;
64420
- if( (pIn1->flags | pIn3->flags)&MEM_Null ){
64460
+ if( (u.ai.flags1 | u.ai.flags3)&MEM_Null ){
6442164461
/* One or both operands are NULL */
6442264462
if( pOp->p5 & SQLITE_NULLEQ ){
6442364463
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
6442464464
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6442564465
** or not both operands are null.
6442664466
*/
6442764467
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
64428
- u.ai.res = (pIn1->flags & pIn3->flags & MEM_Null)==0;
64468
+ u.ai.res = (u.ai.flags1 & u.ai.flags3 & MEM_Null)==0;
6442964469
}else{
6443064470
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6443164471
** then the result is always NULL.
6443264472
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
6443364473
*/
@@ -65249,17 +65289,20 @@
6524965289
"SQL statements in progress");
6525065290
rc = SQLITE_BUSY;
6525165291
}else{
6525265292
u.aq.nName = sqlite3Strlen30(u.aq.zName);
6525365293
65294
+#ifndef SQLITE_OMIT_VIRTUALTABLE
6525465295
/* This call is Ok even if this savepoint is actually a transaction
6525565296
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
6525665297
** If this is a transaction savepoint being opened, it is guaranteed
6525765298
** that the db->aVTrans[] array is empty. */
6525865299
assert( db->autoCommit==0 || db->nVTrans==0 );
65259
- rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65300
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
65301
+ db->nStatement+db->nSavepoint);
6526065302
if( rc!=SQLITE_OK ) goto abort_due_to_error;
65303
+#endif
6526165304
6526265305
/* Create a new savepoint structure. */
6526365306
u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
6526465307
if( u.aq.pNew ){
6526565308
u.aq.pNew->zName = (char *)&u.aq.pNew[1];
@@ -65508,11 +65551,11 @@
6550865551
assert( db->nStatement>=0 && db->nSavepoint>=0 );
6550965552
db->nStatement++;
6551065553
p->iStatement = db->nSavepoint + db->nStatement;
6551165554
}
6551265555
65513
- rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65556
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
6551465557
if( rc==SQLITE_OK ){
6551565558
rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
6551665559
}
6551765560
6551865561
/* Store the current value of the database handles deferred constraint
@@ -68641,25 +68684,25 @@
6864168684
** the UTF-8 string contained in P4 is emitted on the trace callback.
6864268685
*/
6864368686
case OP_Trace: {
6864468687
#if 0 /* local variables moved into u.cn */
6864568688
char *zTrace;
68689
+ char *z;
6864668690
#endif /* local variables moved into u.cn */
6864768691
68648
- u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
68649
- if( u.cn.zTrace ){
68650
- if( db->xTrace ){
68651
- char *z = sqlite3VdbeExpandSql(p, u.cn.zTrace);
68652
- db->xTrace(db->pTraceArg, z);
68653
- sqlite3DbFree(db, z);
68654
- }
68692
+ if( db->xTrace && (u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
68693
+ u.cn.z = sqlite3VdbeExpandSql(p, u.cn.zTrace);
68694
+ db->xTrace(db->pTraceArg, u.cn.z);
68695
+ sqlite3DbFree(db, u.cn.z);
68696
+ }
6865568697
#ifdef SQLITE_DEBUG
68656
- if( (db->flags & SQLITE_SqlTrace)!=0 ){
68657
- sqlite3DebugPrintf("SQL-trace: %s\n", u.cn.zTrace);
68658
- }
68698
+ if( (db->flags & SQLITE_SqlTrace)!=0
68699
+ && (u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
68700
+ ){
68701
+ sqlite3DebugPrintf("SQL-trace: %s\n", u.cn.zTrace);
68702
+ }
6865968703
#endif /* SQLITE_DEBUG */
68660
- }
6866168704
break;
6866268705
}
6866368706
#endif
6866468707
6866568708
@@ -69080,11 +69123,14 @@
6908069123
** and offset cache without causing any IO.
6908169124
*/
6908269125
sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
6908369126
sqlite3VdbeChangeP2(v, 7, pTab->nCol);
6908469127
if( !db->mallocFailed ){
69085
- sqlite3VdbeMakeReady(v, 1, 1, 1, 0, 0, 0);
69128
+ pParse->nVar = 1;
69129
+ pParse->nMem = 1;
69130
+ pParse->nTab = 1;
69131
+ sqlite3VdbeMakeReady(v, pParse);
6908669132
}
6908769133
}
6908869134
6908969135
pBlob->flags = flags;
6909069136
pBlob->iCol = iCol;
@@ -71647,57 +71693,57 @@
7164771693
assert( z[0]!=0 );
7164871694
if( z[1]==0 ){
7164971695
/* Wildcard of the form "?". Assign the next variable number */
7165071696
assert( z[0]=='?' );
7165171697
pExpr->iColumn = (ynVar)(++pParse->nVar);
71652
- }else if( z[0]=='?' ){
71653
- /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
71654
- ** use it as the variable number */
71655
- i64 i;
71656
- int bOk = 0==sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
71657
- pExpr->iColumn = (ynVar)i;
71658
- testcase( i==0 );
71659
- testcase( i==1 );
71660
- testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
71661
- testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
71662
- if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71663
- sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
71664
- db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
71665
- }
71666
- if( i>pParse->nVar ){
71667
- pParse->nVar = (int)i;
71668
- }
71669
- }else{
71670
- /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
71671
- ** number as the prior appearance of the same name, or if the name
71672
- ** has never appeared before, reuse the same variable number
71673
- */
71674
- int i;
71675
- u32 n;
71676
- n = sqlite3Strlen30(z);
71677
- for(i=0; i<pParse->nVarExpr; i++){
71678
- Expr *pE = pParse->apVarExpr[i];
71679
- assert( pE!=0 );
71680
- if( memcmp(pE->u.zToken, z, n)==0 && pE->u.zToken[n]==0 ){
71681
- pExpr->iColumn = pE->iColumn;
71682
- break;
71683
- }
71684
- }
71685
- if( i>=pParse->nVarExpr ){
71686
- pExpr->iColumn = (ynVar)(++pParse->nVar);
71687
- if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
71688
- pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
71689
- pParse->apVarExpr =
71690
- sqlite3DbReallocOrFree(
71691
- db,
71692
- pParse->apVarExpr,
71693
- pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0])
71694
- );
71695
- }
71696
- if( !db->mallocFailed ){
71697
- assert( pParse->apVarExpr!=0 );
71698
- pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
71698
+ }else{
71699
+ ynVar x = 0;
71700
+ u32 n = sqlite3Strlen30(z);
71701
+ if( z[0]=='?' ){
71702
+ /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
71703
+ ** use it as the variable number */
71704
+ i64 i;
71705
+ int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
71706
+ pExpr->iColumn = x = (ynVar)i;
71707
+ testcase( i==0 );
71708
+ testcase( i==1 );
71709
+ testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
71710
+ testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
71711
+ if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71712
+ sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
71713
+ db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
71714
+ x = 0;
71715
+ }
71716
+ if( i>pParse->nVar ){
71717
+ pParse->nVar = (int)i;
71718
+ }
71719
+ }else{
71720
+ /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
71721
+ ** number as the prior appearance of the same name, or if the name
71722
+ ** has never appeared before, reuse the same variable number
71723
+ */
71724
+ ynVar i;
71725
+ for(i=0; i<pParse->nzVar; i++){
71726
+ if( pParse->azVar[i] && memcmp(pParse->azVar[i],z,n+1)==0 ){
71727
+ pExpr->iColumn = x = (ynVar)i+1;
71728
+ break;
71729
+ }
71730
+ }
71731
+ if( x==0 ) x = pExpr->iColumn = (ynVar)(++pParse->nVar);
71732
+ }
71733
+ if( x>0 ){
71734
+ if( x>pParse->nzVar ){
71735
+ char **a;
71736
+ a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
71737
+ if( a==0 ) return; /* Error reported through db->mallocFailed */
71738
+ pParse->azVar = a;
71739
+ memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0]));
71740
+ pParse->nzVar = x;
71741
+ }
71742
+ if( z[0]!='?' || pParse->azVar[x-1]==0 ){
71743
+ sqlite3DbFree(db, pParse->azVar[x-1]);
71744
+ pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
7169971745
}
7170071746
}
7170171747
}
7170271748
if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
7170371749
sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -73437,11 +73483,13 @@
7343773483
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7343873484
assert( pExpr->u.zToken!=0 );
7343973485
assert( pExpr->u.zToken[0]!=0 );
7344073486
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
7344173487
if( pExpr->u.zToken[1]!=0 ){
73442
- sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT);
73488
+ assert( pExpr->u.zToken[0]=='?'
73489
+ || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
73490
+ sqlite3VdbeChangeP4(v, -1, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
7344373491
}
7344473492
break;
7344573493
}
7344673494
case TK_REGISTER: {
7344773495
inReg = pExpr->iTable;
@@ -77408,13 +77456,11 @@
7740877456
#endif
7740977457
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
7741077458
/* A minimum of one cursor is required if autoincrement is used
7741177459
* See ticket [a696379c1f08866] */
7741277460
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
77413
- sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem,
77414
- pParse->nTab, pParse->nMaxArg, pParse->explain,
77415
- pParse->isMultiWrite && pParse->mayAbort);
77461
+ sqlite3VdbeMakeReady(v, pParse);
7741677462
pParse->rc = SQLITE_DONE;
7741777463
pParse->colNamesSet = 0;
7741877464
}else{
7741977465
pParse->rc = SQLITE_ERROR;
7742077466
}
@@ -81827,10 +81873,11 @@
8182781873
#ifndef SQLITE_OMIT_VIRTUALTABLE
8182881874
if( IsVirtual(pTab) ){
8182981875
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
8183081876
sqlite3VtabMakeWritable(pParse, pTab);
8183181877
sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
81878
+ sqlite3VdbeChangeP5(v, OE_Abort);
8183281879
sqlite3MayAbort(pParse);
8183381880
}else
8183481881
#endif
8183581882
{
8183681883
int count = (pParse->nested==0); /* True to count changes */
@@ -87947,14 +87994,10 @@
8794787994
**
8794887995
*************************************************************************
8794987996
** This file contains code used to implement the PRAGMA command.
8795087997
*/
8795187998
87952
-/* Ignore this whole file if pragmas are disabled
87953
-*/
87954
-#if !defined(SQLITE_OMIT_PRAGMA)
87955
-
8795687999
/*
8795788000
** Interpret the given string as a safety level. Return 0 for OFF,
8795888001
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
8795988002
** unrecognized string argument.
8796088003
**
@@ -87986,10 +88029,16 @@
8798688029
** Interpret the given string as a boolean value.
8798788030
*/
8798888031
SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
8798988032
return getSafetyLevel(z)&1;
8799088033
}
88034
+
88035
+/* The sqlite3GetBoolean() function is used by other modules but the
88036
+** remainder of this file is specific to PRAGMA processing. So omit
88037
+** the rest of the file if PRAGMAs are omitted from the build.
88038
+*/
88039
+#if !defined(SQLITE_OMIT_PRAGMA)
8799188040
8799288041
/*
8799388042
** Interpret the given string as a locking mode value.
8799488043
*/
8799588044
static int getLockingMode(const char *z){
@@ -97692,15 +97741,15 @@
9769297741
sqlite3DbFree(db, zErr);
9769397742
}
9769497743
9769597744
return rc;
9769697745
}
97697
-
9769897746
/*
97699
-** Add the virtual table pVTab to the array sqlite3.aVTrans[].
97747
+** Grow the db->aVTrans[] array so that there is room for at least one
97748
+** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
9770097749
*/
97701
-static int addToVTrans(sqlite3 *db, VTable *pVTab){
97750
+static int growVTrans(sqlite3 *db){
9770297751
const int ARRAY_INCR = 5;
9770397752
9770497753
/* Grow the sqlite3.aVTrans array if required */
9770597754
if( (db->nVTrans%ARRAY_INCR)==0 ){
9770697755
VTable **aVTrans;
@@ -97711,14 +97760,21 @@
9771197760
}
9771297761
memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
9771397762
db->aVTrans = aVTrans;
9771497763
}
9771597764
97765
+ return SQLITE_OK;
97766
+}
97767
+
97768
+/*
97769
+** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
97770
+** have already been reserved using growVTrans().
97771
+*/
97772
+static void addToVTrans(sqlite3 *db, VTable *pVTab){
9771697773
/* Add pVtab to the end of sqlite3.aVTrans */
9771797774
db->aVTrans[db->nVTrans++] = pVTab;
9771897775
sqlite3VtabLock(pVTab);
97719
- return SQLITE_OK;
9772097776
}
9772197777
9772297778
/*
9772397779
** This function is invoked by the vdbe to call the xCreate method
9772497780
** of the virtual table named zTab in database iDb.
@@ -97752,11 +97808,14 @@
9775297808
}
9775397809
9775497810
/* Justification of ALWAYS(): The xConstructor method is required to
9775597811
** create a valid sqlite3_vtab if it returns SQLITE_OK. */
9775697812
if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
97757
- rc = addToVTrans(db, sqlite3GetVTable(db, pTab));
97813
+ rc = growVTrans(db);
97814
+ if( rc==SQLITE_OK ){
97815
+ addToVTrans(db, sqlite3GetVTable(db, pTab));
97816
+ }
9775897817
}
9775997818
9776097819
return rc;
9776197820
}
9776297821
@@ -97868,10 +97927,11 @@
9786897927
if( p ){
9786997928
int (*x)(sqlite3_vtab *);
9787097929
x = *(int (**)(sqlite3_vtab *))((char *)p->pModule + offset);
9787197930
if( x ) x(p);
9787297931
}
97932
+ pVTab->iSavepoint = 0;
9787397933
sqlite3VtabUnlock(pVTab);
9787497934
}
9787597935
sqlite3DbFree(db, db->aVTrans);
9787697936
db->nVTrans = 0;
9787797937
db->aVTrans = 0;
@@ -97957,14 +98017,18 @@
9795798017
if( db->aVTrans[i]==pVTab ){
9795898018
return SQLITE_OK;
9795998019
}
9796098020
}
9796198021
97962
- /* Invoke the xBegin method */
97963
- rc = pModule->xBegin(pVTab->pVtab);
98022
+ /* Invoke the xBegin method. If successful, add the vtab to the
98023
+ ** sqlite3.aVTrans[] array. */
98024
+ rc = growVTrans(db);
9796498025
if( rc==SQLITE_OK ){
97965
- rc = addToVTrans(db, pVTab);
98026
+ rc = pModule->xBegin(pVTab->pVtab);
98027
+ if( rc==SQLITE_OK ){
98028
+ addToVTrans(db, pVTab);
98029
+ }
9796698030
}
9796798031
}
9796898032
return rc;
9796998033
}
9797098034
@@ -97985,28 +98049,33 @@
9798598049
*/
9798698050
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
9798798051
int rc = SQLITE_OK;
9798898052
9798998053
assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
98054
+ assert( iSavepoint>=0 );
9799098055
if( db->aVTrans ){
9799198056
int i;
9799298057
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
97993
- const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule;
98058
+ VTable *pVTab = db->aVTrans[i];
98059
+ const sqlite3_module *pMod = pVTab->pMod->pModule;
9799498060
if( pMod->iVersion>=2 ){
9799598061
int (*xMethod)(sqlite3_vtab *, int);
9799698062
switch( op ){
9799798063
case SAVEPOINT_BEGIN:
9799898064
xMethod = pMod->xSavepoint;
98065
+ pVTab->iSavepoint = iSavepoint+1;
9799998066
break;
9800098067
case SAVEPOINT_ROLLBACK:
9800198068
xMethod = pMod->xRollbackTo;
9800298069
break;
9800398070
default:
9800498071
xMethod = pMod->xRelease;
9800598072
break;
9800698073
}
98007
- if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
98074
+ if( xMethod && pVTab->iSavepoint>iSavepoint ){
98075
+ rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
98076
+ }
9800898077
}
9800998078
}
9801098079
}
9801198080
return rc;
9801298081
}
@@ -107264,13 +107333,12 @@
107264107333
return SQLITE_NOMEM;
107265107334
}
107266107335
assert( pParse->pNewTable==0 );
107267107336
assert( pParse->pNewTrigger==0 );
107268107337
assert( pParse->nVar==0 );
107269
- assert( pParse->nVarExpr==0 );
107270
- assert( pParse->nVarExprAlloc==0 );
107271
- assert( pParse->apVarExpr==0 );
107338
+ assert( pParse->nzVar==0 );
107339
+ assert( pParse->azVar==0 );
107272107340
enableLookaside = db->lookaside.bEnabled;
107273107341
if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
107274107342
while( !db->mallocFailed && zSql[i]!=0 ){
107275107343
assert( i>=0 );
107276107344
pParse->sLastToken.z = &zSql[i];
@@ -107360,11 +107428,12 @@
107360107428
*/
107361107429
sqlite3DeleteTable(db, pParse->pNewTable);
107362107430
}
107363107431
107364107432
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
107365
- sqlite3DbFree(db, pParse->apVarExpr);
107433
+ for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
107434
+ sqlite3DbFree(db, pParse->azVar);
107366107435
sqlite3DbFree(db, pParse->aAlias);
107367107436
while( pParse->pAinc ){
107368107437
AutoincInfo *p = pParse->pAinc;
107369107438
pParse->pAinc = p->pNext;
107370107439
sqlite3DbFree(db, p);
@@ -109692,13 +109761,13 @@
109692109761
}else{
109693109762
struct OpenMode {
109694109763
const char *z;
109695109764
int mode;
109696109765
} *aMode = 0;
109697
- char *zModeType;
109698
- int mask;
109699
- int limit;
109766
+ char *zModeType = 0;
109767
+ int mask = 0;
109768
+ int limit = 0;
109700109769
109701109770
if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
109702109771
static struct OpenMode aCacheMode[] = {
109703109772
{ "shared", SQLITE_OPEN_SHAREDCACHE },
109704109773
{ "private", SQLITE_OPEN_PRIVATECACHE },
@@ -111686,15 +111755,35 @@
111686111755
*/
111687111756
typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */
111688111757
typedef short int i16; /* 2-byte (or larger) signed integer */
111689111758
typedef unsigned int u32; /* 4-byte unsigned integer */
111690111759
typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */
111760
+
111691111761
/*
111692111762
** Macro used to suppress compiler warnings for unused parameters.
111693111763
*/
111694111764
#define UNUSED_PARAMETER(x) (void)(x)
111765
+
111766
+/*
111767
+** Activate assert() only if SQLITE_TEST is enabled.
111768
+*/
111769
+#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
111770
+# define NDEBUG 1
111771
+#endif
111772
+
111773
+/*
111774
+** The TESTONLY macro is used to enclose variable declarations or
111775
+** other bits of code that are needed to support the arguments
111776
+** within testcase() and assert() macros.
111777
+*/
111778
+#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
111779
+# define TESTONLY(X) X
111780
+#else
111781
+# define TESTONLY(X)
111695111782
#endif
111783
+
111784
+#endif /* SQLITE_AMALGAMATION */
111696111785
111697111786
typedef struct Fts3Table Fts3Table;
111698111787
typedef struct Fts3Cursor Fts3Cursor;
111699111788
typedef struct Fts3Expr Fts3Expr;
111700111789
typedef struct Fts3Phrase Fts3Phrase;
@@ -111745,10 +111834,20 @@
111745111834
*/
111746111835
int nMaxPendingData;
111747111836
int nPendingData;
111748111837
sqlite_int64 iPrevDocid;
111749111838
Fts3Hash pendingTerms;
111839
+
111840
+#if defined(SQLITE_DEBUG)
111841
+ /* State variables used for validating that the transaction control
111842
+ ** methods of the virtual table are called at appropriate times. These
111843
+ ** values do not contribution to the FTS computation; they are used for
111844
+ ** verifying the SQLite core.
111845
+ */
111846
+ int inTransaction; /* True after xBegin but before xCommit/xRollback */
111847
+ int mxSavepoint; /* Largest valid xSavepoint integer */
111848
+#endif
111750111849
};
111751111850
111752111851
/*
111753111852
** When the core wants to read from the virtual table, it creates a
111754111853
** virtual table cursor (an instance of the following structure) using
@@ -112655,10 +112754,12 @@
112655112754
p->pTokenizer = pTokenizer;
112656112755
p->nNodeSize = 1000;
112657112756
p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
112658112757
p->bHasDocsize = (isFts4 && bNoDocsize==0);
112659112758
p->bHasStat = isFts4;
112759
+ TESTONLY( p->inTransaction = -1 );
112760
+ TESTONLY( p->mxSavepoint = -1 );
112660112761
fts3HashInit(&p->pendingTerms, FTS3_HASH_STRING, 1);
112661112762
112662112763
/* Fill in the zName and zDb fields of the vtab structure. */
112663112764
zCsr = (char *)&p->azColumn[nCol];
112664112765
p->zName = zCsr;
@@ -114952,11 +115053,15 @@
114952115053
/*
114953115054
** Implementation of xBegin() method. This is a no-op.
114954115055
*/
114955115056
static int fts3BeginMethod(sqlite3_vtab *pVtab){
114956115057
UNUSED_PARAMETER(pVtab);
114957
- assert( ((Fts3Table *)pVtab)->nPendingData==0 );
115058
+ TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115059
+ assert( p->nPendingData==0 );
115060
+ assert( p->inTransaction!=1 );
115061
+ TESTONLY( p->inTransaction = 1 );
115062
+ TESTONLY( p->mxSavepoint = -1; );
114958115063
return SQLITE_OK;
114959115064
}
114960115065
114961115066
/*
114962115067
** Implementation of xCommit() method. This is a no-op. The contents of
@@ -114963,20 +115068,28 @@
114963115068
** the pending-terms hash-table have already been flushed into the database
114964115069
** by fts3SyncMethod().
114965115070
*/
114966115071
static int fts3CommitMethod(sqlite3_vtab *pVtab){
114967115072
UNUSED_PARAMETER(pVtab);
114968
- assert( ((Fts3Table *)pVtab)->nPendingData==0 );
115073
+ TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115074
+ assert( p->nPendingData==0 );
115075
+ assert( p->inTransaction!=0 );
115076
+ TESTONLY( p->inTransaction = 0 );
115077
+ TESTONLY( p->mxSavepoint = -1; );
114969115078
return SQLITE_OK;
114970115079
}
114971115080
114972115081
/*
114973115082
** Implementation of xRollback(). Discard the contents of the pending-terms
114974115083
** hash-table. Any changes made to the database are reverted by SQLite.
114975115084
*/
114976115085
static int fts3RollbackMethod(sqlite3_vtab *pVtab){
114977
- sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
115086
+ Fts3Table *p = (Fts3Table*)pVtab;
115087
+ sqlite3Fts3PendingTermsClear(p);
115088
+ assert( p->inTransaction!=0 );
115089
+ TESTONLY( p->inTransaction = 0 );
115090
+ TESTONLY( p->mxSavepoint = -1; );
114978115091
return SQLITE_OK;
114979115092
}
114980115093
114981115094
/*
114982115095
** Load the doclist associated with expression pExpr to pExpr->aDoclist.
@@ -115328,17 +115441,33 @@
115328115441
);
115329115442
return rc;
115330115443
}
115331115444
115332115445
static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
115333
- return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab);
115446
+ Fts3Table *p = (Fts3Table*)pVtab;
115447
+ UNUSED_PARAMETER(iSavepoint);
115448
+ assert( p->inTransaction );
115449
+ assert( p->mxSavepoint < iSavepoint );
115450
+ TESTONLY( p->mxSavepoint = iSavepoint );
115451
+ return sqlite3Fts3PendingTermsFlush(p);
115334115452
}
115335115453
static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
115454
+ TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115455
+ UNUSED_PARAMETER(iSavepoint);
115456
+ UNUSED_PARAMETER(pVtab);
115457
+ assert( p->inTransaction );
115458
+ assert( p->mxSavepoint >= iSavepoint );
115459
+ TESTONLY( p->mxSavepoint = iSavepoint-1 );
115336115460
return SQLITE_OK;
115337115461
}
115338115462
static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
115339
- sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
115463
+ Fts3Table *p = (Fts3Table*)pVtab;
115464
+ UNUSED_PARAMETER(iSavepoint);
115465
+ assert( p->inTransaction );
115466
+ assert( p->mxSavepoint >= iSavepoint );
115467
+ TESTONLY( p->mxSavepoint = iSavepoint );
115468
+ sqlite3Fts3PendingTermsClear(p);
115340115469
return SQLITE_OK;
115341115470
}
115342115471
115343115472
static const sqlite3_module fts3Module = {
115344115473
/* iVersion */ 2,
@@ -115833,10 +115962,11 @@
115833115962
Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
115834115963
int rc;
115835115964
int isScan;
115836115965
115837115966
UNUSED_PARAMETER(nVal);
115967
+ UNUSED_PARAMETER(idxStr);
115838115968
115839115969
assert( idxStr==0 );
115840115970
assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
115841115971
|| idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
115842115972
|| idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -115950,11 +116080,14 @@
115950116080
0, /* xBegin */
115951116081
0, /* xSync */
115952116082
0, /* xCommit */
115953116083
0, /* xRollback */
115954116084
0, /* xFindFunction */
115955
- 0 /* xRename */
116085
+ 0, /* xRename */
116086
+ 0, /* xSavepoint */
116087
+ 0, /* xRelease */
116088
+ 0 /* xRollbackTo */
115956116089
};
115957116090
int rc; /* Return code */
115958116091
115959116092
rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
115960116093
return rc;
@@ -125929,11 +126062,11 @@
125929126062
}
125930126063
return rc;
125931126064
}
125932126065
125933126066
static sqlite3_module rtreeModule = {
125934
- 0, /* iVersion */
126067
+ 0, /* iVersion */
125935126068
rtreeCreate, /* xCreate - create a table */
125936126069
rtreeConnect, /* xConnect - connect to an existing table */
125937126070
rtreeBestIndex, /* xBestIndex - Determine search strategy */
125938126071
rtreeDisconnect, /* xDisconnect - Disconnect from a table */
125939126072
rtreeDestroy, /* xDestroy - Drop a table */
@@ -125948,11 +126081,14 @@
125948126081
0, /* xBegin - begin transaction */
125949126082
0, /* xSync - sync transaction */
125950126083
0, /* xCommit - commit transaction */
125951126084
0, /* xRollback - rollback transaction */
125952126085
0, /* xFindFunction - function overloading */
125953
- rtreeRename /* xRename - rename the table */
126086
+ rtreeRename, /* xRename - rename the table */
126087
+ 0, /* xSavepoint */
126088
+ 0, /* xRelease */
126089
+ 0 /* xRollbackTo */
125954126090
};
125955126091
125956126092
static int rtreeSqlInit(
125957126093
Rtree *pRtree,
125958126094
sqlite3 *db,
125959126095
--- 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.7"
654 #define SQLITE_VERSION_NUMBER 3007007
655 #define SQLITE_SOURCE_ID "2011-05-20 01:50:01 2018d4e108872f2436df046636401b89cfde589d"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1000,10 +1000,12 @@
1000 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1001 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1002 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1003 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1004 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
 
 
1005
1006 /*
1007 ** CAPI3REF: Flags For File Open Operations
1008 **
1009 ** These bit values are intended for use in the
@@ -1305,15 +1307,15 @@
1305 */
1306 typedef struct sqlite3_mutex sqlite3_mutex;
1307
1308 /*
1309 ** CAPI3REF: OS Interface Object
1310 ** KEYWORDS: VFS VFSes
1311 **
1312 ** An instance of the sqlite3_vfs object defines the interface between
1313 ** the SQLite core and the underlying operating system. The "vfs"
1314 ** in the name of the object stands for "virtual file system".
 
1315 **
1316 ** The value of the iVersion field is initially 1 but may be larger in
1317 ** future versions of SQLite. Additional fields may be appended to this
1318 ** object when the iVersion value is increased. Note that the structure
1319 ** of the sqlite3_vfs object changes in the transaction between
@@ -8494,19 +8496,20 @@
8494 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
8495 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
8496 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
8497 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
8498 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
8499 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int);
8500 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
8501 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
8502 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
8503 #ifdef SQLITE_DEBUG
8504 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
8505 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
8506 #endif
8507 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
 
8508 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
8509 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
8510 SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
8511 SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
8512 SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
@@ -9832,10 +9835,11 @@
9832 sqlite3 *db; /* Database connection associated with this table */
9833 Module *pMod; /* Pointer to module implementation */
9834 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
9835 int nRef; /* Number of pointers to this structure */
9836 u8 bConstraint; /* True if constraints are supported */
 
9837 VTable *pNext; /* Next in linked list (see above) */
9838 };
9839
9840 /*
9841 ** Each SQL table is represented in memory by an instance of the
@@ -10826,13 +10830,12 @@
10826
10827 /* Above is constant between recursions. Below is reset before and after
10828 ** each recursion */
10829
10830 int nVar; /* Number of '?' variables seen in the SQL so far */
10831 int nVarExpr; /* Number of used slots in apVarExpr[] */
10832 int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */
10833 Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */
10834 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
10835 int nAlias; /* Number of aliased result set columns */
10836 int nAliasAlloc; /* Number of allocated slots for aAlias[] */
10837 int *aAlias; /* Register used to hold aliased result */
10838 u8 explain; /* True if the EXPLAIN flag is found on the query */
@@ -12761,15 +12764,15 @@
12761 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12762 VdbeCursor **apCsr; /* One element of this array for each open cursor */
12763 Mem *aVar; /* Values for the OP_Variable opcode. */
12764 char **azVar; /* Name of variables */
12765 ynVar nVar; /* Number of entries in aVar[] */
 
12766 u32 cacheCtr; /* VdbeCursor row cache generation counter */
12767 int pc; /* The program counter */
12768 int rc; /* Value to return */
12769 u8 errorAction; /* Recovery action to do in case of an error */
12770 u8 okVar; /* True if azVar[] has been initialized */
12771 u8 explain; /* True if EXPLAIN present on SQL command */
12772 u8 changeCntOn; /* True to update the change-counter */
12773 u8 expired; /* True if the VM needs to be recompiled */
12774 u8 runOnlyOnce; /* Automatically expire on reset */
12775 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -27963,11 +27966,12 @@
27963 unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */
27964 sqlite3_mutex *mutex; /* Mutex to access this object */
27965 char *zFilename; /* Name of the mmapped file */
27966 int h; /* Open file descriptor */
27967 int szRegion; /* Size of shared-memory regions */
27968 int nRegion; /* Size of array apRegion */
 
27969 char **apRegion; /* Array of mapped shared-memory regions */
27970 int nRef; /* Number of unixShm objects pointing to this */
27971 unixShm *pFirst; /* All unixShm objects pointing to this */
27972 #ifdef SQLITE_DEBUG
27973 u8 exclMask; /* Mask of exclusive locks held */
@@ -28210,12 +28214,21 @@
28210
28211 if( pInode->bProcessLock==0 ){
28212 pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
28213 (sStat.st_mode & 0777));
28214 if( pShmNode->h<0 ){
28215 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
28216 goto shm_open_err;
 
 
 
 
 
 
 
 
 
28217 }
28218
28219 /* Check to see if another process is holding the dead-man switch.
28220 ** If not, truncate the file to zero length.
28221 */
@@ -28350,11 +28363,12 @@
28350 }
28351 pShmNode->apRegion = apNew;
28352 while(pShmNode->nRegion<=iRegion){
28353 void *pMem;
28354 if( pShmNode->h>=0 ){
28355 pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
 
28356 MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
28357 );
28358 if( pMem==MAP_FAILED ){
28359 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
28360 goto shmpage_out;
@@ -28376,10 +28390,11 @@
28376 if( pShmNode->nRegion>iRegion ){
28377 *pp = pShmNode->apRegion[iRegion];
28378 }else{
28379 *pp = 0;
28380 }
 
28381 sqlite3_mutex_leave(pShmNode->mutex);
28382 return rc;
28383 }
28384
28385 /*
@@ -34873,10 +34888,17 @@
34873 if( !pPg ){
34874 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
34875 }
34876 if( pPg ){
34877 int rc;
 
 
 
 
 
 
 
34878 rc = pCache->xStress(pCache->pStress, pPg);
34879 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
34880 return rc;
34881 }
34882 }
@@ -43977,11 +43999,11 @@
43977 u32 szPage; /* Database page size */
43978 i16 readLock; /* Which read lock is being held. -1 for none */
43979 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
43980 u8 writeLock; /* True if in a write transaction */
43981 u8 ckptLock; /* True if holding a checkpoint lock */
43982 u8 readOnly; /* True if the WAL file is open read-only */
43983 WalIndexHdr hdr; /* Wal-index header for current transaction */
43984 const char *zWalName; /* Name of WAL file */
43985 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
43986 #ifdef SQLITE_DEBUG
43987 u8 lockError; /* True if a locking error has occurred */
@@ -43993,10 +44015,17 @@
43993 */
43994 #define WAL_NORMAL_MODE 0
43995 #define WAL_EXCLUSIVE_MODE 1
43996 #define WAL_HEAPMEMORY_MODE 2
43997
 
 
 
 
 
 
 
43998 /*
43999 ** Each page of the wal-index mapping contains a hash-table made up of
44000 ** an array of HASHTABLE_NSLOT elements of the following type.
44001 */
44002 typedef u16 ht_slot;
@@ -44086,10 +44115,14 @@
44086 if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
44087 }else{
44088 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
44089 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
44090 );
 
 
 
 
44091 }
44092 }
44093
44094 *ppPage = pWal->apWiData[iPage];
44095 assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
@@ -44833,11 +44866,11 @@
44833
44834 /* Open file handle on the write-ahead log file. */
44835 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
44836 rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
44837 if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
44838 pRet->readOnly = 1;
44839 }
44840
44841 if( rc!=SQLITE_OK ){
44842 walIndexClose(pRet, 0);
44843 sqlite3OsClose(pRet->pWalFd);
@@ -45474,25 +45507,32 @@
45474
45475 /* If the first attempt failed, it might have been due to a race
45476 ** with a writer. So get a WRITE lock and try again.
45477 */
45478 assert( badHdr==0 || pWal->writeLock==0 );
45479 if( badHdr && SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
45480 pWal->writeLock = 1;
45481 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
45482 badHdr = walIndexTryHdr(pWal, pChanged);
45483 if( badHdr ){
45484 /* If the wal-index header is still malformed even while holding
45485 ** a WRITE lock, it can only mean that the header is corrupted and
45486 ** needs to be reconstructed. So run recovery to do exactly that.
45487 */
45488 rc = walIndexRecover(pWal);
45489 *pChanged = 1;
45490 }
45491 }
45492 pWal->writeLock = 0;
45493 walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
 
 
 
 
 
 
 
45494 }
45495
45496 /* If the header is read successfully, check the version number to make
45497 ** sure the wal-index was not constructed with some future format that
45498 ** this version of SQLite cannot understand.
@@ -45675,11 +45715,13 @@
45675 mxI = i;
45676 }
45677 }
45678 /* There was once an "if" here. The extra "{" is to preserve indentation. */
45679 {
45680 if( mxReadMark < pWal->hdr.mxFrame || mxI==0 ){
 
 
45681 for(i=1; i<WAL_NREADER; i++){
45682 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
45683 if( rc==SQLITE_OK ){
45684 mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
45685 mxI = i;
@@ -45689,12 +45731,12 @@
45689 return rc;
45690 }
45691 }
45692 }
45693 if( mxI==0 ){
45694 assert( rc==SQLITE_BUSY );
45695 return WAL_RETRY;
45696 }
45697
45698 rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
45699 if( rc ){
45700 return rc==SQLITE_BUSY ? WAL_RETRY : rc;
@@ -46096,14 +46138,16 @@
46096 ** set to a non-negative value. Log errors encountered
46097 ** during the truncation attempt. */
46098 if( pWal->mxWalSize>=0 ){
46099 i64 sz;
46100 int rx;
 
46101 rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
46102 if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
46103 rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
46104 }
 
46105 if( rx ){
46106 sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
46107 }
46108 }
46109
@@ -46330,10 +46374,11 @@
46330 int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
46331
46332 assert( pWal->ckptLock==0 );
46333 assert( pWal->writeLock==0 );
46334
 
46335 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
46336 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
46337 if( rc ){
46338 /* Usually this is SQLITE_BUSY meaning that another thread or process
46339 ** is already running a checkpoint, or maybe a recovery. But it might
@@ -52812,14 +52857,14 @@
52812 ** removes the reference to the cell from pPage.
52813 **
52814 ** "sz" must be the number of bytes in the cell.
52815 */
52816 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
52817 int i; /* Loop counter */
52818 u32 pc; /* Offset to cell content of cell being deleted */
52819 u8 *data; /* pPage->aData */
52820 u8 *ptr; /* Used to move bytes around within data[] */
 
52821 int rc; /* The return code */
52822 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
52823
52824 if( *pRC ) return;
52825
@@ -52840,13 +52885,15 @@
52840 rc = freeSpace(pPage, pc, sz);
52841 if( rc ){
52842 *pRC = rc;
52843 return;
52844 }
52845 for(i=idx+1; i<pPage->nCell; i++, ptr+=2){
 
52846 ptr[0] = ptr[2];
52847 ptr[1] = ptr[3];
 
52848 }
52849 pPage->nCell--;
52850 put2byte(&data[hdr+3], pPage->nCell);
52851 pPage->nFree += 2;
52852 }
@@ -58825,38 +58872,17 @@
58825 }
58826 return pBuf;
58827 }
58828
58829 /*
58830 ** Prepare a virtual machine for execution. This involves things such
58831 ** as allocating stack space and initializing the program counter.
58832 ** After the VDBE has be prepped, it can be executed by one or more
58833 ** calls to sqlite3VdbeExec().
58834 **
58835 ** This is the only way to move a VDBE from VDBE_MAGIC_INIT to
58836 ** VDBE_MAGIC_RUN.
58837 **
58838 ** This function may be called more than once on a single virtual machine.
58839 ** The first call is made while compiling the SQL statement. Subsequent
58840 ** calls are made as part of the process of resetting a statement to be
58841 ** re-executed (from a call to sqlite3_reset()). The nVar, nMem, nCursor
58842 ** and isExplain parameters are only passed correct values the first time
58843 ** the function is called. On subsequent calls, from sqlite3_reset(), nVar
58844 ** is passed -1 and nMem, nCursor and isExplain are all passed zero.
58845 */
58846 SQLITE_PRIVATE void sqlite3VdbeMakeReady(
58847 Vdbe *p, /* The VDBE */
58848 int nVar, /* Number of '?' see in the SQL statement */
58849 int nMem, /* Number of memory cells to allocate */
58850 int nCursor, /* Number of cursors to allocate */
58851 int nArg, /* Maximum number of args in SubPrograms */
58852 int isExplain, /* True if the EXPLAIN keywords is present */
58853 int usesStmtJournal /* True to set Vdbe.usesStmtJournal */
58854 ){
58855 int n;
58856 sqlite3 *db = p->db;
58857
58858 assert( p!=0 );
58859 assert( p->magic==VDBE_MAGIC_INIT );
58860
58861 /* There should be at least one opcode.
58862 */
@@ -58863,10 +58889,75 @@
58863 assert( p->nOp>0 );
58864
58865 /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
58866 p->magic = VDBE_MAGIC_RUN;
58867
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58868 /* For each cursor required, also allocate a memory cell. Memory
58869 ** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
58870 ** the vdbe program. Instead they are used to allocate space for
58871 ** VdbeCursor/BtCursor structures. The blob of memory associated with
58872 ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
@@ -58875,95 +58966,72 @@
58875 ** See also: allocateCursor().
58876 */
58877 nMem += nCursor;
58878
58879 /* Allocate space for memory registers, SQL variables, VDBE cursors and
58880 ** an array to marshal SQL function arguments in. This is only done the
58881 ** first time this function is called for a given VDBE, not when it is
58882 ** being called from sqlite3_reset() to reset the virtual machine.
58883 */
58884 if( nVar>=0 && ALWAYS(db->mallocFailed==0) ){
58885 u8 *zCsr = (u8 *)&p->aOp[p->nOp]; /* Memory avaliable for alloation */
58886 u8 *zEnd = (u8 *)&p->aOp[p->nOpAlloc]; /* First byte past available mem */
58887 int nByte; /* How much extra memory needed */
58888
58889 resolveP2Values(p, &nArg);
58890 p->usesStmtJournal = (u8)usesStmtJournal;
58891 if( isExplain && nMem<10 ){
58892 nMem = 10;
58893 }
58894 memset(zCsr, 0, zEnd-zCsr);
58895 zCsr += (zCsr - (u8*)0)&7;
58896 assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
58897
58898 /* Memory for registers, parameters, cursor, etc, is allocated in two
58899 ** passes. On the first pass, we try to reuse unused space at the
58900 ** end of the opcode array. If we are unable to satisfy all memory
58901 ** requirements by reusing the opcode array tail, then the second
58902 ** pass will fill in the rest using a fresh allocation.
58903 **
58904 ** This two-pass approach that reuses as much memory as possible from
58905 ** the leftover space at the end of the opcode array can significantly
58906 ** reduce the amount of memory held by a prepared statement.
58907 */
58908 do {
58909 nByte = 0;
58910 p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
58911 p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
58912 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
58913 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
58914 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
58915 &zCsr, zEnd, &nByte);
58916 if( nByte ){
58917 p->pFree = sqlite3DbMallocZero(db, nByte);
58918 }
58919 zCsr = p->pFree;
58920 zEnd = &zCsr[nByte];
58921 }while( nByte && !db->mallocFailed );
58922
58923 p->nCursor = (u16)nCursor;
58924 if( p->aVar ){
58925 p->nVar = (ynVar)nVar;
58926 for(n=0; n<nVar; n++){
58927 p->aVar[n].flags = MEM_Null;
58928 p->aVar[n].db = db;
58929 }
58930 }
58931 if( p->aMem ){
58932 p->aMem--; /* aMem[] goes from 1..nMem */
58933 p->nMem = nMem; /* not from 0..nMem-1 */
58934 for(n=1; n<=nMem; n++){
58935 p->aMem[n].flags = MEM_Null;
58936 p->aMem[n].db = db;
58937 }
58938 }
58939 }
58940 #ifdef SQLITE_DEBUG
58941 for(n=1; n<p->nMem; n++){
58942 assert( p->aMem[n].db==db );
58943 }
58944 #endif
58945
58946 p->pc = -1;
58947 p->rc = SQLITE_OK;
58948 p->errorAction = OE_Abort;
58949 p->explain |= isExplain;
58950 p->magic = VDBE_MAGIC_RUN;
58951 p->nChange = 0;
58952 p->cacheCtr = 1;
58953 p->minWriteFileFormat = 255;
58954 p->iStatement = 0;
58955 p->nFkConstraint = 0;
58956 #ifdef VDBE_PROFILE
58957 {
58958 int i;
58959 for(i=0; i<p->nOp; i++){
58960 p->aOp[i].cnt = 0;
58961 p->aOp[i].cycles = 0;
58962 }
58963 }
58964 #endif
58965 }
58966
58967 /*
58968 ** Close a VDBE cursor and release all the resources that cursor
58969 ** happens to hold.
@@ -59636,21 +59704,15 @@
59636 /* If eStatementOp is non-zero, then a statement transaction needs to
59637 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
59638 ** do so. If this operation returns an error, and the current statement
59639 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
59640 ** current statement error code.
59641 **
59642 ** Note that sqlite3VdbeCloseStatement() can only fail if eStatementOp
59643 ** is SAVEPOINT_ROLLBACK. But if p->rc==SQLITE_OK then eStatementOp
59644 ** must be SAVEPOINT_RELEASE. Hence the NEVER(p->rc==SQLITE_OK) in
59645 ** the following code.
59646 */
59647 if( eStatementOp ){
59648 rc = sqlite3VdbeCloseStatement(p, eStatementOp);
59649 if( rc ){
59650 assert( eStatementOp==SAVEPOINT_ROLLBACK );
59651 if( NEVER(p->rc==SQLITE_OK) || p->rc==SQLITE_CONSTRAINT ){
59652 p->rc = rc;
59653 sqlite3DbFree(db, p->zErrMsg);
59654 p->zErrMsg = 0;
59655 }
59656 invalidateCursorsOnModifiedBtrees(db);
@@ -59839,18 +59901,20 @@
59839 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
59840 ** the database connection.
59841 */
59842 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
59843 SubProgram *pSub, *pNext;
 
59844 assert( p->db==0 || p->db==db );
59845 releaseMemArray(p->aVar, p->nVar);
59846 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
59847 for(pSub=p->pProgram; pSub; pSub=pNext){
59848 pNext = pSub->pNext;
59849 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
59850 sqlite3DbFree(db, pSub);
59851 }
 
59852 vdbeFreeOpArray(db, p->aOp, p->nOp);
59853 sqlite3DbFree(db, p->aLabel);
59854 sqlite3DbFree(db, p->aColName);
59855 sqlite3DbFree(db, p->zSql);
59856 sqlite3DbFree(db, p->pFree);
@@ -60292,11 +60356,11 @@
60292 u32 serial_type;
60293
60294 idx += getVarint32(&aKey[idx], serial_type);
60295 pMem->enc = pKeyInfo->enc;
60296 pMem->db = pKeyInfo->db;
60297 pMem->flags = 0;
60298 pMem->zMalloc = 0;
60299 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
60300 pMem++;
60301 u++;
60302 }
@@ -60307,10 +60371,11 @@
60307
60308 /*
60309 ** This routine destroys a UnpackedRecord object.
60310 */
60311 SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord *p){
 
60312 int i;
60313 Mem *pMem;
60314
60315 assert( p!=0 );
60316 assert( p->flags & UNPACKED_NEED_DESTROY );
@@ -60320,10 +60385,11 @@
60320 ** strings and blobs static. And none of the elements are
60321 ** ever transformed, so there is never anything to delete.
60322 */
60323 if( NEVER(pMem->zMalloc) ) sqlite3VdbeMemRelease(pMem);
60324 }
 
60325 if( p->flags & UNPACKED_NEED_FREE ){
60326 sqlite3DbFree(p->pKeyInfo->db, p);
60327 }
60328 }
60329
@@ -60755,11 +60821,11 @@
60755 rc = SQLITE_OK;
60756 }else{
60757 Vdbe *v = (Vdbe*)pStmt;
60758 sqlite3_mutex_enter(v->db->mutex);
60759 rc = sqlite3VdbeReset(v);
60760 sqlite3VdbeMakeReady(v, -1, 0, 0, 0, 0, 0);
60761 assert( (rc & (v->db->errMask))==rc );
60762 rc = sqlite3ApiExit(v->db, rc);
60763 sqlite3_mutex_leave(v->db->mutex);
60764 }
60765 return rc;
@@ -61820,48 +61886,21 @@
61820 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
61821 Vdbe *p = (Vdbe*)pStmt;
61822 return p ? p->nVar : 0;
61823 }
61824
61825 /*
61826 ** Create a mapping from variable numbers to variable names
61827 ** in the Vdbe.azVar[] array, if such a mapping does not already
61828 ** exist.
61829 */
61830 static void createVarMap(Vdbe *p){
61831 if( !p->okVar ){
61832 int j;
61833 Op *pOp;
61834 sqlite3_mutex_enter(p->db->mutex);
61835 /* The race condition here is harmless. If two threads call this
61836 ** routine on the same Vdbe at the same time, they both might end
61837 ** up initializing the Vdbe.azVar[] array. That is a little extra
61838 ** work but it results in the same answer.
61839 */
61840 for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
61841 if( pOp->opcode==OP_Variable ){
61842 assert( pOp->p1>0 && pOp->p1<=p->nVar );
61843 p->azVar[pOp->p1-1] = pOp->p4.z;
61844 }
61845 }
61846 p->okVar = 1;
61847 sqlite3_mutex_leave(p->db->mutex);
61848 }
61849 }
61850
61851 /*
61852 ** Return the name of a wildcard parameter. Return NULL if the index
61853 ** is out of range or if the wildcard is unnamed.
61854 **
61855 ** The result is always UTF-8.
61856 */
61857 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
61858 Vdbe *p = (Vdbe*)pStmt;
61859 if( p==0 || i<1 || i>p->nVar ){
61860 return 0;
61861 }
61862 createVarMap(p);
61863 return p->azVar[i-1];
61864 }
61865
61866 /*
61867 ** Given a wildcard parameter name, return the index of the variable
@@ -61871,13 +61910,12 @@
61871 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
61872 int i;
61873 if( p==0 ){
61874 return 0;
61875 }
61876 createVarMap(p);
61877 if( zName ){
61878 for(i=0; i<p->nVar; i++){
61879 const char *z = p->azVar[i];
61880 if( z && memcmp(z,zName,nName)==0 && z[nName]==0 ){
61881 return i+1;
61882 }
61883 }
@@ -63197,10 +63235,11 @@
63197 Mem **apArg;
63198 Mem *pX;
63199 } cm;
63200 struct OP_Trace_stack_vars {
63201 char *zTrace;
 
63202 } cn;
63203 } u;
63204 /* End automatically generated code
63205 ********************************************************************/
63206
@@ -63623,10 +63662,11 @@
63623 #if 0 /* local variables moved into u.ab */
63624 Mem *pVar; /* Value being transferred */
63625 #endif /* local variables moved into u.ab */
63626
63627 assert( pOp->p1>0 && pOp->p1<=p->nVar );
 
63628 u.ab.pVar = &p->aVar[pOp->p1 - 1];
63629 if( sqlite3VdbeMemTooBig(u.ab.pVar) ){
63630 goto too_big;
63631 }
63632 sqlite3VdbeMemShallowCopy(pOut, u.ab.pVar, MEM_Static);
@@ -64415,19 +64455,19 @@
64415
64416 pIn1 = &aMem[pOp->p1];
64417 pIn3 = &aMem[pOp->p3];
64418 u.ai.flags1 = pIn1->flags;
64419 u.ai.flags3 = pIn3->flags;
64420 if( (pIn1->flags | pIn3->flags)&MEM_Null ){
64421 /* One or both operands are NULL */
64422 if( pOp->p5 & SQLITE_NULLEQ ){
64423 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
64424 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
64425 ** or not both operands are null.
64426 */
64427 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
64428 u.ai.res = (pIn1->flags & pIn3->flags & MEM_Null)==0;
64429 }else{
64430 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
64431 ** then the result is always NULL.
64432 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
64433 */
@@ -65249,17 +65289,20 @@
65249 "SQL statements in progress");
65250 rc = SQLITE_BUSY;
65251 }else{
65252 u.aq.nName = sqlite3Strlen30(u.aq.zName);
65253
 
65254 /* This call is Ok even if this savepoint is actually a transaction
65255 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
65256 ** If this is a transaction savepoint being opened, it is guaranteed
65257 ** that the db->aVTrans[] array is empty. */
65258 assert( db->autoCommit==0 || db->nVTrans==0 );
65259 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
 
65260 if( rc!=SQLITE_OK ) goto abort_due_to_error;
 
65261
65262 /* Create a new savepoint structure. */
65263 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
65264 if( u.aq.pNew ){
65265 u.aq.pNew->zName = (char *)&u.aq.pNew[1];
@@ -65508,11 +65551,11 @@
65508 assert( db->nStatement>=0 && db->nSavepoint>=0 );
65509 db->nStatement++;
65510 p->iStatement = db->nSavepoint + db->nStatement;
65511 }
65512
65513 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65514 if( rc==SQLITE_OK ){
65515 rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65516 }
65517
65518 /* Store the current value of the database handles deferred constraint
@@ -68641,25 +68684,25 @@
68641 ** the UTF-8 string contained in P4 is emitted on the trace callback.
68642 */
68643 case OP_Trace: {
68644 #if 0 /* local variables moved into u.cn */
68645 char *zTrace;
 
68646 #endif /* local variables moved into u.cn */
68647
68648 u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
68649 if( u.cn.zTrace ){
68650 if( db->xTrace ){
68651 char *z = sqlite3VdbeExpandSql(p, u.cn.zTrace);
68652 db->xTrace(db->pTraceArg, z);
68653 sqlite3DbFree(db, z);
68654 }
68655 #ifdef SQLITE_DEBUG
68656 if( (db->flags & SQLITE_SqlTrace)!=0 ){
68657 sqlite3DebugPrintf("SQL-trace: %s\n", u.cn.zTrace);
68658 }
 
 
68659 #endif /* SQLITE_DEBUG */
68660 }
68661 break;
68662 }
68663 #endif
68664
68665
@@ -69080,11 +69123,14 @@
69080 ** and offset cache without causing any IO.
69081 */
69082 sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
69083 sqlite3VdbeChangeP2(v, 7, pTab->nCol);
69084 if( !db->mallocFailed ){
69085 sqlite3VdbeMakeReady(v, 1, 1, 1, 0, 0, 0);
 
 
 
69086 }
69087 }
69088
69089 pBlob->flags = flags;
69090 pBlob->iCol = iCol;
@@ -71647,57 +71693,57 @@
71647 assert( z[0]!=0 );
71648 if( z[1]==0 ){
71649 /* Wildcard of the form "?". Assign the next variable number */
71650 assert( z[0]=='?' );
71651 pExpr->iColumn = (ynVar)(++pParse->nVar);
71652 }else if( z[0]=='?' ){
71653 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
71654 ** use it as the variable number */
71655 i64 i;
71656 int bOk = 0==sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
71657 pExpr->iColumn = (ynVar)i;
71658 testcase( i==0 );
71659 testcase( i==1 );
71660 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
71661 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
71662 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71663 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
71664 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
71665 }
71666 if( i>pParse->nVar ){
71667 pParse->nVar = (int)i;
71668 }
71669 }else{
71670 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
71671 ** number as the prior appearance of the same name, or if the name
71672 ** has never appeared before, reuse the same variable number
71673 */
71674 int i;
71675 u32 n;
71676 n = sqlite3Strlen30(z);
71677 for(i=0; i<pParse->nVarExpr; i++){
71678 Expr *pE = pParse->apVarExpr[i];
71679 assert( pE!=0 );
71680 if( memcmp(pE->u.zToken, z, n)==0 && pE->u.zToken[n]==0 ){
71681 pExpr->iColumn = pE->iColumn;
71682 break;
71683 }
71684 }
71685 if( i>=pParse->nVarExpr ){
71686 pExpr->iColumn = (ynVar)(++pParse->nVar);
71687 if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
71688 pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
71689 pParse->apVarExpr =
71690 sqlite3DbReallocOrFree(
71691 db,
71692 pParse->apVarExpr,
71693 pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0])
71694 );
71695 }
71696 if( !db->mallocFailed ){
71697 assert( pParse->apVarExpr!=0 );
71698 pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
71699 }
71700 }
71701 }
71702 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71703 sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -73437,11 +73483,13 @@
73437 assert( !ExprHasProperty(pExpr, EP_IntValue) );
73438 assert( pExpr->u.zToken!=0 );
73439 assert( pExpr->u.zToken[0]!=0 );
73440 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
73441 if( pExpr->u.zToken[1]!=0 ){
73442 sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT);
 
 
73443 }
73444 break;
73445 }
73446 case TK_REGISTER: {
73447 inReg = pExpr->iTable;
@@ -77408,13 +77456,11 @@
77408 #endif
77409 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
77410 /* A minimum of one cursor is required if autoincrement is used
77411 * See ticket [a696379c1f08866] */
77412 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
77413 sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem,
77414 pParse->nTab, pParse->nMaxArg, pParse->explain,
77415 pParse->isMultiWrite && pParse->mayAbort);
77416 pParse->rc = SQLITE_DONE;
77417 pParse->colNamesSet = 0;
77418 }else{
77419 pParse->rc = SQLITE_ERROR;
77420 }
@@ -81827,10 +81873,11 @@
81827 #ifndef SQLITE_OMIT_VIRTUALTABLE
81828 if( IsVirtual(pTab) ){
81829 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
81830 sqlite3VtabMakeWritable(pParse, pTab);
81831 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
 
81832 sqlite3MayAbort(pParse);
81833 }else
81834 #endif
81835 {
81836 int count = (pParse->nested==0); /* True to count changes */
@@ -87947,14 +87994,10 @@
87947 **
87948 *************************************************************************
87949 ** This file contains code used to implement the PRAGMA command.
87950 */
87951
87952 /* Ignore this whole file if pragmas are disabled
87953 */
87954 #if !defined(SQLITE_OMIT_PRAGMA)
87955
87956 /*
87957 ** Interpret the given string as a safety level. Return 0 for OFF,
87958 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
87959 ** unrecognized string argument.
87960 **
@@ -87986,10 +88029,16 @@
87986 ** Interpret the given string as a boolean value.
87987 */
87988 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
87989 return getSafetyLevel(z)&1;
87990 }
 
 
 
 
 
 
87991
87992 /*
87993 ** Interpret the given string as a locking mode value.
87994 */
87995 static int getLockingMode(const char *z){
@@ -97692,15 +97741,15 @@
97692 sqlite3DbFree(db, zErr);
97693 }
97694
97695 return rc;
97696 }
97697
97698 /*
97699 ** Add the virtual table pVTab to the array sqlite3.aVTrans[].
 
97700 */
97701 static int addToVTrans(sqlite3 *db, VTable *pVTab){
97702 const int ARRAY_INCR = 5;
97703
97704 /* Grow the sqlite3.aVTrans array if required */
97705 if( (db->nVTrans%ARRAY_INCR)==0 ){
97706 VTable **aVTrans;
@@ -97711,14 +97760,21 @@
97711 }
97712 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
97713 db->aVTrans = aVTrans;
97714 }
97715
 
 
 
 
 
 
 
 
97716 /* Add pVtab to the end of sqlite3.aVTrans */
97717 db->aVTrans[db->nVTrans++] = pVTab;
97718 sqlite3VtabLock(pVTab);
97719 return SQLITE_OK;
97720 }
97721
97722 /*
97723 ** This function is invoked by the vdbe to call the xCreate method
97724 ** of the virtual table named zTab in database iDb.
@@ -97752,11 +97808,14 @@
97752 }
97753
97754 /* Justification of ALWAYS(): The xConstructor method is required to
97755 ** create a valid sqlite3_vtab if it returns SQLITE_OK. */
97756 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
97757 rc = addToVTrans(db, sqlite3GetVTable(db, pTab));
 
 
 
97758 }
97759
97760 return rc;
97761 }
97762
@@ -97868,10 +97927,11 @@
97868 if( p ){
97869 int (*x)(sqlite3_vtab *);
97870 x = *(int (**)(sqlite3_vtab *))((char *)p->pModule + offset);
97871 if( x ) x(p);
97872 }
 
97873 sqlite3VtabUnlock(pVTab);
97874 }
97875 sqlite3DbFree(db, db->aVTrans);
97876 db->nVTrans = 0;
97877 db->aVTrans = 0;
@@ -97957,14 +98017,18 @@
97957 if( db->aVTrans[i]==pVTab ){
97958 return SQLITE_OK;
97959 }
97960 }
97961
97962 /* Invoke the xBegin method */
97963 rc = pModule->xBegin(pVTab->pVtab);
 
97964 if( rc==SQLITE_OK ){
97965 rc = addToVTrans(db, pVTab);
 
 
 
97966 }
97967 }
97968 return rc;
97969 }
97970
@@ -97985,28 +98049,33 @@
97985 */
97986 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
97987 int rc = SQLITE_OK;
97988
97989 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
 
97990 if( db->aVTrans ){
97991 int i;
97992 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
97993 const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule;
 
97994 if( pMod->iVersion>=2 ){
97995 int (*xMethod)(sqlite3_vtab *, int);
97996 switch( op ){
97997 case SAVEPOINT_BEGIN:
97998 xMethod = pMod->xSavepoint;
 
97999 break;
98000 case SAVEPOINT_ROLLBACK:
98001 xMethod = pMod->xRollbackTo;
98002 break;
98003 default:
98004 xMethod = pMod->xRelease;
98005 break;
98006 }
98007 if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
 
 
98008 }
98009 }
98010 }
98011 return rc;
98012 }
@@ -107264,13 +107333,12 @@
107264 return SQLITE_NOMEM;
107265 }
107266 assert( pParse->pNewTable==0 );
107267 assert( pParse->pNewTrigger==0 );
107268 assert( pParse->nVar==0 );
107269 assert( pParse->nVarExpr==0 );
107270 assert( pParse->nVarExprAlloc==0 );
107271 assert( pParse->apVarExpr==0 );
107272 enableLookaside = db->lookaside.bEnabled;
107273 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
107274 while( !db->mallocFailed && zSql[i]!=0 ){
107275 assert( i>=0 );
107276 pParse->sLastToken.z = &zSql[i];
@@ -107360,11 +107428,12 @@
107360 */
107361 sqlite3DeleteTable(db, pParse->pNewTable);
107362 }
107363
107364 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
107365 sqlite3DbFree(db, pParse->apVarExpr);
 
107366 sqlite3DbFree(db, pParse->aAlias);
107367 while( pParse->pAinc ){
107368 AutoincInfo *p = pParse->pAinc;
107369 pParse->pAinc = p->pNext;
107370 sqlite3DbFree(db, p);
@@ -109692,13 +109761,13 @@
109692 }else{
109693 struct OpenMode {
109694 const char *z;
109695 int mode;
109696 } *aMode = 0;
109697 char *zModeType;
109698 int mask;
109699 int limit;
109700
109701 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
109702 static struct OpenMode aCacheMode[] = {
109703 { "shared", SQLITE_OPEN_SHAREDCACHE },
109704 { "private", SQLITE_OPEN_PRIVATECACHE },
@@ -111686,15 +111755,35 @@
111686 */
111687 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */
111688 typedef short int i16; /* 2-byte (or larger) signed integer */
111689 typedef unsigned int u32; /* 4-byte unsigned integer */
111690 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */
 
111691 /*
111692 ** Macro used to suppress compiler warnings for unused parameters.
111693 */
111694 #define UNUSED_PARAMETER(x) (void)(x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111695 #endif
 
 
111696
111697 typedef struct Fts3Table Fts3Table;
111698 typedef struct Fts3Cursor Fts3Cursor;
111699 typedef struct Fts3Expr Fts3Expr;
111700 typedef struct Fts3Phrase Fts3Phrase;
@@ -111745,10 +111834,20 @@
111745 */
111746 int nMaxPendingData;
111747 int nPendingData;
111748 sqlite_int64 iPrevDocid;
111749 Fts3Hash pendingTerms;
 
 
 
 
 
 
 
 
 
 
111750 };
111751
111752 /*
111753 ** When the core wants to read from the virtual table, it creates a
111754 ** virtual table cursor (an instance of the following structure) using
@@ -112655,10 +112754,12 @@
112655 p->pTokenizer = pTokenizer;
112656 p->nNodeSize = 1000;
112657 p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
112658 p->bHasDocsize = (isFts4 && bNoDocsize==0);
112659 p->bHasStat = isFts4;
 
 
112660 fts3HashInit(&p->pendingTerms, FTS3_HASH_STRING, 1);
112661
112662 /* Fill in the zName and zDb fields of the vtab structure. */
112663 zCsr = (char *)&p->azColumn[nCol];
112664 p->zName = zCsr;
@@ -114952,11 +115053,15 @@
114952 /*
114953 ** Implementation of xBegin() method. This is a no-op.
114954 */
114955 static int fts3BeginMethod(sqlite3_vtab *pVtab){
114956 UNUSED_PARAMETER(pVtab);
114957 assert( ((Fts3Table *)pVtab)->nPendingData==0 );
 
 
 
 
114958 return SQLITE_OK;
114959 }
114960
114961 /*
114962 ** Implementation of xCommit() method. This is a no-op. The contents of
@@ -114963,20 +115068,28 @@
114963 ** the pending-terms hash-table have already been flushed into the database
114964 ** by fts3SyncMethod().
114965 */
114966 static int fts3CommitMethod(sqlite3_vtab *pVtab){
114967 UNUSED_PARAMETER(pVtab);
114968 assert( ((Fts3Table *)pVtab)->nPendingData==0 );
 
 
 
 
114969 return SQLITE_OK;
114970 }
114971
114972 /*
114973 ** Implementation of xRollback(). Discard the contents of the pending-terms
114974 ** hash-table. Any changes made to the database are reverted by SQLite.
114975 */
114976 static int fts3RollbackMethod(sqlite3_vtab *pVtab){
114977 sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
 
 
 
 
114978 return SQLITE_OK;
114979 }
114980
114981 /*
114982 ** Load the doclist associated with expression pExpr to pExpr->aDoclist.
@@ -115328,17 +115441,33 @@
115328 );
115329 return rc;
115330 }
115331
115332 static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
115333 return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab);
 
 
 
 
 
115334 }
115335 static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
 
 
 
 
 
 
115336 return SQLITE_OK;
115337 }
115338 static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
115339 sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
 
 
 
 
 
115340 return SQLITE_OK;
115341 }
115342
115343 static const sqlite3_module fts3Module = {
115344 /* iVersion */ 2,
@@ -115833,10 +115962,11 @@
115833 Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
115834 int rc;
115835 int isScan;
115836
115837 UNUSED_PARAMETER(nVal);
 
115838
115839 assert( idxStr==0 );
115840 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
115841 || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
115842 || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -115950,11 +116080,14 @@
115950 0, /* xBegin */
115951 0, /* xSync */
115952 0, /* xCommit */
115953 0, /* xRollback */
115954 0, /* xFindFunction */
115955 0 /* xRename */
 
 
 
115956 };
115957 int rc; /* Return code */
115958
115959 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
115960 return rc;
@@ -125929,11 +126062,11 @@
125929 }
125930 return rc;
125931 }
125932
125933 static sqlite3_module rtreeModule = {
125934 0, /* iVersion */
125935 rtreeCreate, /* xCreate - create a table */
125936 rtreeConnect, /* xConnect - connect to an existing table */
125937 rtreeBestIndex, /* xBestIndex - Determine search strategy */
125938 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
125939 rtreeDestroy, /* xDestroy - Drop a table */
@@ -125948,11 +126081,14 @@
125948 0, /* xBegin - begin transaction */
125949 0, /* xSync - sync transaction */
125950 0, /* xCommit - commit transaction */
125951 0, /* xRollback - rollback transaction */
125952 0, /* xFindFunction - function overloading */
125953 rtreeRename /* xRename - rename the table */
 
 
 
125954 };
125955
125956 static int rtreeSqlInit(
125957 Rtree *pRtree,
125958 sqlite3 *db,
125959
--- 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.7"
654 #define SQLITE_VERSION_NUMBER 3007007
655 #define SQLITE_SOURCE_ID "2011-06-03 14:19:10 0206bc6f87bb9393218a380fc5b18039d334a8d8"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1000,10 +1000,12 @@
1000 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1001 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1002 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1003 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1004 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1005 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1006 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1007
1008 /*
1009 ** CAPI3REF: Flags For File Open Operations
1010 **
1011 ** These bit values are intended for use in the
@@ -1305,15 +1307,15 @@
1307 */
1308 typedef struct sqlite3_mutex sqlite3_mutex;
1309
1310 /*
1311 ** CAPI3REF: OS Interface Object
 
1312 **
1313 ** An instance of the sqlite3_vfs object defines the interface between
1314 ** the SQLite core and the underlying operating system. The "vfs"
1315 ** in the name of the object stands for "virtual file system". See
1316 ** the [VFS | VFS documentation] for further information.
1317 **
1318 ** The value of the iVersion field is initially 1 but may be larger in
1319 ** future versions of SQLite. Additional fields may be appended to this
1320 ** object when the iVersion value is increased. Note that the structure
1321 ** of the sqlite3_vfs object changes in the transaction between
@@ -8494,19 +8496,20 @@
8496 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
8497 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
8498 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
8499 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
8500 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
8501 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
8502 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
8503 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
8504 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
8505 #ifdef SQLITE_DEBUG
8506 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
8507 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
8508 #endif
8509 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
8510 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
8511 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
8512 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
8513 SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
8514 SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
8515 SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
@@ -9832,10 +9835,11 @@
9835 sqlite3 *db; /* Database connection associated with this table */
9836 Module *pMod; /* Pointer to module implementation */
9837 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
9838 int nRef; /* Number of pointers to this structure */
9839 u8 bConstraint; /* True if constraints are supported */
9840 int iSavepoint; /* Depth of the SAVEPOINT stack */
9841 VTable *pNext; /* Next in linked list (see above) */
9842 };
9843
9844 /*
9845 ** Each SQL table is represented in memory by an instance of the
@@ -10826,13 +10830,12 @@
10830
10831 /* Above is constant between recursions. Below is reset before and after
10832 ** each recursion */
10833
10834 int nVar; /* Number of '?' variables seen in the SQL so far */
10835 int nzVar; /* Number of available slots in azVar[] */
10836 char **azVar; /* Pointers to names of parameters */
 
10837 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
10838 int nAlias; /* Number of aliased result set columns */
10839 int nAliasAlloc; /* Number of allocated slots for aAlias[] */
10840 int *aAlias; /* Register used to hold aliased result */
10841 u8 explain; /* True if the EXPLAIN flag is found on the query */
@@ -12761,15 +12764,15 @@
12764 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12765 VdbeCursor **apCsr; /* One element of this array for each open cursor */
12766 Mem *aVar; /* Values for the OP_Variable opcode. */
12767 char **azVar; /* Name of variables */
12768 ynVar nVar; /* Number of entries in aVar[] */
12769 ynVar nzVar; /* Number of entries in azVar[] */
12770 u32 cacheCtr; /* VdbeCursor row cache generation counter */
12771 int pc; /* The program counter */
12772 int rc; /* Value to return */
12773 u8 errorAction; /* Recovery action to do in case of an error */
 
12774 u8 explain; /* True if EXPLAIN present on SQL command */
12775 u8 changeCntOn; /* True to update the change-counter */
12776 u8 expired; /* True if the VM needs to be recompiled */
12777 u8 runOnlyOnce; /* Automatically expire on reset */
12778 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -27963,11 +27966,12 @@
27966 unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */
27967 sqlite3_mutex *mutex; /* Mutex to access this object */
27968 char *zFilename; /* Name of the mmapped file */
27969 int h; /* Open file descriptor */
27970 int szRegion; /* Size of shared-memory regions */
27971 u16 nRegion; /* Size of array apRegion */
27972 u8 isReadonly; /* True if read-only */
27973 char **apRegion; /* Array of mapped shared-memory regions */
27974 int nRef; /* Number of unixShm objects pointing to this */
27975 unixShm *pFirst; /* All unixShm objects pointing to this */
27976 #ifdef SQLITE_DEBUG
27977 u8 exclMask; /* Mask of exclusive locks held */
@@ -28210,12 +28214,21 @@
28214
28215 if( pInode->bProcessLock==0 ){
28216 pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
28217 (sStat.st_mode & 0777));
28218 if( pShmNode->h<0 ){
28219 const char *zRO;
28220 zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm");
28221 if( zRO && sqlite3GetBoolean(zRO) ){
28222 pShmNode->h = robust_open(zShmFilename, O_RDONLY,
28223 (sStat.st_mode & 0777));
28224 pShmNode->isReadonly = 1;
28225 }
28226 if( pShmNode->h<0 ){
28227 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
28228 goto shm_open_err;
28229 }
28230 }
28231
28232 /* Check to see if another process is holding the dead-man switch.
28233 ** If not, truncate the file to zero length.
28234 */
@@ -28350,11 +28363,12 @@
28363 }
28364 pShmNode->apRegion = apNew;
28365 while(pShmNode->nRegion<=iRegion){
28366 void *pMem;
28367 if( pShmNode->h>=0 ){
28368 pMem = mmap(0, szRegion,
28369 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
28370 MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
28371 );
28372 if( pMem==MAP_FAILED ){
28373 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
28374 goto shmpage_out;
@@ -28376,10 +28390,11 @@
28390 if( pShmNode->nRegion>iRegion ){
28391 *pp = pShmNode->apRegion[iRegion];
28392 }else{
28393 *pp = 0;
28394 }
28395 if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
28396 sqlite3_mutex_leave(pShmNode->mutex);
28397 return rc;
28398 }
28399
28400 /*
@@ -34873,10 +34888,17 @@
34888 if( !pPg ){
34889 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
34890 }
34891 if( pPg ){
34892 int rc;
34893 #ifdef SQLITE_LOG_CACHE_SPILL
34894 sqlite3_log(SQLITE_FULL,
34895 "spill page %d making room for %d - cache used: %d/%d",
34896 pPg->pgno, pgno,
34897 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
34898 pCache->nMax);
34899 #endif
34900 rc = pCache->xStress(pCache->pStress, pPg);
34901 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
34902 return rc;
34903 }
34904 }
@@ -43977,11 +43999,11 @@
43999 u32 szPage; /* Database page size */
44000 i16 readLock; /* Which read lock is being held. -1 for none */
44001 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
44002 u8 writeLock; /* True if in a write transaction */
44003 u8 ckptLock; /* True if holding a checkpoint lock */
44004 u8 readOnly; /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
44005 WalIndexHdr hdr; /* Wal-index header for current transaction */
44006 const char *zWalName; /* Name of WAL file */
44007 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
44008 #ifdef SQLITE_DEBUG
44009 u8 lockError; /* True if a locking error has occurred */
@@ -43993,10 +44015,17 @@
44015 */
44016 #define WAL_NORMAL_MODE 0
44017 #define WAL_EXCLUSIVE_MODE 1
44018 #define WAL_HEAPMEMORY_MODE 2
44019
44020 /*
44021 ** Possible values for WAL.readOnly
44022 */
44023 #define WAL_RDWR 0 /* Normal read/write connection */
44024 #define WAL_RDONLY 1 /* The WAL file is readonly */
44025 #define WAL_SHM_RDONLY 2 /* The SHM file is readonly */
44026
44027 /*
44028 ** Each page of the wal-index mapping contains a hash-table made up of
44029 ** an array of HASHTABLE_NSLOT elements of the following type.
44030 */
44031 typedef u16 ht_slot;
@@ -44086,10 +44115,14 @@
44115 if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
44116 }else{
44117 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
44118 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
44119 );
44120 if( rc==SQLITE_READONLY ){
44121 pWal->readOnly |= WAL_SHM_RDONLY;
44122 rc = SQLITE_OK;
44123 }
44124 }
44125 }
44126
44127 *ppPage = pWal->apWiData[iPage];
44128 assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
@@ -44833,11 +44866,11 @@
44866
44867 /* Open file handle on the write-ahead log file. */
44868 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
44869 rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
44870 if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
44871 pRet->readOnly = WAL_RDONLY;
44872 }
44873
44874 if( rc!=SQLITE_OK ){
44875 walIndexClose(pRet, 0);
44876 sqlite3OsClose(pRet->pWalFd);
@@ -45474,25 +45507,32 @@
45507
45508 /* If the first attempt failed, it might have been due to a race
45509 ** with a writer. So get a WRITE lock and try again.
45510 */
45511 assert( badHdr==0 || pWal->writeLock==0 );
45512 if( badHdr ){
45513 if( pWal->readOnly & WAL_SHM_RDONLY ){
45514 if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
45515 walUnlockShared(pWal, WAL_WRITE_LOCK);
45516 rc = SQLITE_READONLY_RECOVERY;
45517 }
45518 }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
45519 pWal->writeLock = 1;
45520 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
45521 badHdr = walIndexTryHdr(pWal, pChanged);
45522 if( badHdr ){
45523 /* If the wal-index header is still malformed even while holding
45524 ** a WRITE lock, it can only mean that the header is corrupted and
45525 ** needs to be reconstructed. So run recovery to do exactly that.
45526 */
45527 rc = walIndexRecover(pWal);
45528 *pChanged = 1;
45529 }
45530 }
45531 pWal->writeLock = 0;
45532 walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
45533 }
45534 }
45535
45536 /* If the header is read successfully, check the version number to make
45537 ** sure the wal-index was not constructed with some future format that
45538 ** this version of SQLite cannot understand.
@@ -45675,11 +45715,13 @@
45715 mxI = i;
45716 }
45717 }
45718 /* There was once an "if" here. The extra "{" is to preserve indentation. */
45719 {
45720 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
45721 && (mxReadMark<pWal->hdr.mxFrame || mxI==0)
45722 ){
45723 for(i=1; i<WAL_NREADER; i++){
45724 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
45725 if( rc==SQLITE_OK ){
45726 mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
45727 mxI = i;
@@ -45689,12 +45731,12 @@
45731 return rc;
45732 }
45733 }
45734 }
45735 if( mxI==0 ){
45736 assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
45737 return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK;
45738 }
45739
45740 rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
45741 if( rc ){
45742 return rc==SQLITE_BUSY ? WAL_RETRY : rc;
@@ -46096,14 +46138,16 @@
46138 ** set to a non-negative value. Log errors encountered
46139 ** during the truncation attempt. */
46140 if( pWal->mxWalSize>=0 ){
46141 i64 sz;
46142 int rx;
46143 sqlite3BeginBenignMalloc();
46144 rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
46145 if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
46146 rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
46147 }
46148 sqlite3EndBenignMalloc();
46149 if( rx ){
46150 sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
46151 }
46152 }
46153
@@ -46330,10 +46374,11 @@
46374 int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
46375
46376 assert( pWal->ckptLock==0 );
46377 assert( pWal->writeLock==0 );
46378
46379 if( pWal->readOnly ) return SQLITE_READONLY;
46380 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
46381 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
46382 if( rc ){
46383 /* Usually this is SQLITE_BUSY meaning that another thread or process
46384 ** is already running a checkpoint, or maybe a recovery. But it might
@@ -52812,14 +52857,14 @@
52857 ** removes the reference to the cell from pPage.
52858 **
52859 ** "sz" must be the number of bytes in the cell.
52860 */
52861 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
 
52862 u32 pc; /* Offset to cell content of cell being deleted */
52863 u8 *data; /* pPage->aData */
52864 u8 *ptr; /* Used to move bytes around within data[] */
52865 u8 *endPtr; /* End of loop */
52866 int rc; /* The return code */
52867 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
52868
52869 if( *pRC ) return;
52870
@@ -52840,13 +52885,15 @@
52885 rc = freeSpace(pPage, pc, sz);
52886 if( rc ){
52887 *pRC = rc;
52888 return;
52889 }
52890 endPtr = &data[pPage->cellOffset + 2*pPage->nCell - 2];
52891 while( ptr<endPtr ){
52892 ptr[0] = ptr[2];
52893 ptr[1] = ptr[3];
52894 ptr += 2;
52895 }
52896 pPage->nCell--;
52897 put2byte(&data[hdr+3], pPage->nCell);
52898 pPage->nFree += 2;
52899 }
@@ -58825,38 +58872,17 @@
58872 }
58873 return pBuf;
58874 }
58875
58876 /*
58877 ** Rewind the VDBE back to the beginning in preparation for
58878 ** running it.
 
 
 
 
 
 
 
 
 
 
 
 
 
58879 */
58880 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
58881 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
58882 int i;
58883 #endif
 
 
 
 
 
 
 
 
58884 assert( p!=0 );
58885 assert( p->magic==VDBE_MAGIC_INIT );
58886
58887 /* There should be at least one opcode.
58888 */
@@ -58863,10 +58889,75 @@
58889 assert( p->nOp>0 );
58890
58891 /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
58892 p->magic = VDBE_MAGIC_RUN;
58893
58894 #ifdef SQLITE_DEBUG
58895 for(i=1; i<p->nMem; i++){
58896 assert( p->aMem[i].db==p->db );
58897 }
58898 #endif
58899 p->pc = -1;
58900 p->rc = SQLITE_OK;
58901 p->errorAction = OE_Abort;
58902 p->magic = VDBE_MAGIC_RUN;
58903 p->nChange = 0;
58904 p->cacheCtr = 1;
58905 p->minWriteFileFormat = 255;
58906 p->iStatement = 0;
58907 p->nFkConstraint = 0;
58908 #ifdef VDBE_PROFILE
58909 for(i=0; i<p->nOp; i++){
58910 p->aOp[i].cnt = 0;
58911 p->aOp[i].cycles = 0;
58912 }
58913 #endif
58914 }
58915
58916 /*
58917 ** Prepare a virtual machine for execution for the first time after
58918 ** creating the virtual machine. This involves things such
58919 ** as allocating stack space and initializing the program counter.
58920 ** After the VDBE has be prepped, it can be executed by one or more
58921 ** calls to sqlite3VdbeExec().
58922 **
58923 ** This function may be called exact once on a each virtual machine.
58924 ** After this routine is called the VM has been "packaged" and is ready
58925 ** to run. After this routine is called, futher calls to
58926 ** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
58927 ** the Vdbe from the Parse object that helped generate it so that the
58928 ** the Vdbe becomes an independent entity and the Parse object can be
58929 ** destroyed.
58930 **
58931 ** Use the sqlite3VdbeRewind() procedure to restore a virtual machine back
58932 ** to its initial state after it has been run.
58933 */
58934 SQLITE_PRIVATE void sqlite3VdbeMakeReady(
58935 Vdbe *p, /* The VDBE */
58936 Parse *pParse /* Parsing context */
58937 ){
58938 sqlite3 *db; /* The database connection */
58939 int nVar; /* Number of parameters */
58940 int nMem; /* Number of VM memory registers */
58941 int nCursor; /* Number of cursors required */
58942 int nArg; /* Number of arguments in subprograms */
58943 int n; /* Loop counter */
58944 u8 *zCsr; /* Memory available for allocation */
58945 u8 *zEnd; /* First byte past allocated memory */
58946 int nByte; /* How much extra memory is needed */
58947
58948 assert( p!=0 );
58949 assert( p->nOp>0 );
58950 assert( pParse!=0 );
58951 assert( p->magic==VDBE_MAGIC_INIT );
58952 db = p->db;
58953 assert( db->mallocFailed==0 );
58954 nVar = pParse->nVar;
58955 nMem = pParse->nMem;
58956 nCursor = pParse->nTab;
58957 nArg = pParse->nMaxArg;
58958
58959 /* For each cursor required, also allocate a memory cell. Memory
58960 ** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
58961 ** the vdbe program. Instead they are used to allocate space for
58962 ** VdbeCursor/BtCursor structures. The blob of memory associated with
58963 ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
@@ -58875,95 +58966,72 @@
58966 ** See also: allocateCursor().
58967 */
58968 nMem += nCursor;
58969
58970 /* Allocate space for memory registers, SQL variables, VDBE cursors and
58971 ** an array to marshal SQL function arguments in.
58972 */
58973 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
58974 zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
58975
58976 resolveP2Values(p, &nArg);
58977 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
58978 if( pParse->explain && nMem<10 ){
58979 nMem = 10;
58980 }
58981 memset(zCsr, 0, zEnd-zCsr);
58982 zCsr += (zCsr - (u8*)0)&7;
58983 assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
58984
58985 /* Memory for registers, parameters, cursor, etc, is allocated in two
58986 ** passes. On the first pass, we try to reuse unused space at the
58987 ** end of the opcode array. If we are unable to satisfy all memory
58988 ** requirements by reusing the opcode array tail, then the second
58989 ** pass will fill in the rest using a fresh allocation.
58990 **
58991 ** This two-pass approach that reuses as much memory as possible from
58992 ** the leftover space at the end of the opcode array can significantly
58993 ** reduce the amount of memory held by a prepared statement.
58994 */
58995 do {
58996 nByte = 0;
58997 p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
58998 p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
58999 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
59000 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
59001 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
59002 &zCsr, zEnd, &nByte);
59003 if( nByte ){
59004 p->pFree = sqlite3DbMallocZero(db, nByte);
59005 }
59006 zCsr = p->pFree;
59007 zEnd = &zCsr[nByte];
59008 }while( nByte && !db->mallocFailed );
59009
59010 p->nCursor = (u16)nCursor;
59011 if( p->aVar ){
59012 p->nVar = (ynVar)nVar;
59013 for(n=0; n<nVar; n++){
59014 p->aVar[n].flags = MEM_Null;
59015 p->aVar[n].db = db;
59016 }
59017 }
59018 if( p->azVar ){
59019 p->nzVar = pParse->nzVar;
59020 memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
59021 memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
59022 }
59023 if( p->aMem ){
59024 p->aMem--; /* aMem[] goes from 1..nMem */
59025 p->nMem = nMem; /* not from 0..nMem-1 */
59026 for(n=1; n<=nMem; n++){
59027 p->aMem[n].flags = MEM_Null;
59028 p->aMem[n].db = db;
59029 }
59030 }
59031 p->explain = pParse->explain;
59032 sqlite3VdbeRewind(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59033 }
59034
59035 /*
59036 ** Close a VDBE cursor and release all the resources that cursor
59037 ** happens to hold.
@@ -59636,21 +59704,15 @@
59704 /* If eStatementOp is non-zero, then a statement transaction needs to
59705 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
59706 ** do so. If this operation returns an error, and the current statement
59707 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
59708 ** current statement error code.
 
 
 
 
 
59709 */
59710 if( eStatementOp ){
59711 rc = sqlite3VdbeCloseStatement(p, eStatementOp);
59712 if( rc ){
59713 if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){
 
59714 p->rc = rc;
59715 sqlite3DbFree(db, p->zErrMsg);
59716 p->zErrMsg = 0;
59717 }
59718 invalidateCursorsOnModifiedBtrees(db);
@@ -59839,18 +59901,20 @@
59901 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
59902 ** the database connection.
59903 */
59904 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
59905 SubProgram *pSub, *pNext;
59906 int i;
59907 assert( p->db==0 || p->db==db );
59908 releaseMemArray(p->aVar, p->nVar);
59909 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
59910 for(pSub=p->pProgram; pSub; pSub=pNext){
59911 pNext = pSub->pNext;
59912 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
59913 sqlite3DbFree(db, pSub);
59914 }
59915 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
59916 vdbeFreeOpArray(db, p->aOp, p->nOp);
59917 sqlite3DbFree(db, p->aLabel);
59918 sqlite3DbFree(db, p->aColName);
59919 sqlite3DbFree(db, p->zSql);
59920 sqlite3DbFree(db, p->pFree);
@@ -60292,11 +60356,11 @@
60356 u32 serial_type;
60357
60358 idx += getVarint32(&aKey[idx], serial_type);
60359 pMem->enc = pKeyInfo->enc;
60360 pMem->db = pKeyInfo->db;
60361 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
60362 pMem->zMalloc = 0;
60363 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
60364 pMem++;
60365 u++;
60366 }
@@ -60307,10 +60371,11 @@
60371
60372 /*
60373 ** This routine destroys a UnpackedRecord object.
60374 */
60375 SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord *p){
60376 #ifdef SQLITE_DEBUG
60377 int i;
60378 Mem *pMem;
60379
60380 assert( p!=0 );
60381 assert( p->flags & UNPACKED_NEED_DESTROY );
@@ -60320,10 +60385,11 @@
60385 ** strings and blobs static. And none of the elements are
60386 ** ever transformed, so there is never anything to delete.
60387 */
60388 if( NEVER(pMem->zMalloc) ) sqlite3VdbeMemRelease(pMem);
60389 }
60390 #endif
60391 if( p->flags & UNPACKED_NEED_FREE ){
60392 sqlite3DbFree(p->pKeyInfo->db, p);
60393 }
60394 }
60395
@@ -60755,11 +60821,11 @@
60821 rc = SQLITE_OK;
60822 }else{
60823 Vdbe *v = (Vdbe*)pStmt;
60824 sqlite3_mutex_enter(v->db->mutex);
60825 rc = sqlite3VdbeReset(v);
60826 sqlite3VdbeRewind(v);
60827 assert( (rc & (v->db->errMask))==rc );
60828 rc = sqlite3ApiExit(v->db, rc);
60829 sqlite3_mutex_leave(v->db->mutex);
60830 }
60831 return rc;
@@ -61820,48 +61886,21 @@
61886 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
61887 Vdbe *p = (Vdbe*)pStmt;
61888 return p ? p->nVar : 0;
61889 }
61890
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61891 /*
61892 ** Return the name of a wildcard parameter. Return NULL if the index
61893 ** is out of range or if the wildcard is unnamed.
61894 **
61895 ** The result is always UTF-8.
61896 */
61897 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
61898 Vdbe *p = (Vdbe*)pStmt;
61899 if( p==0 || i<1 || i>p->nzVar ){
61900 return 0;
61901 }
 
61902 return p->azVar[i-1];
61903 }
61904
61905 /*
61906 ** Given a wildcard parameter name, return the index of the variable
@@ -61871,13 +61910,12 @@
61910 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
61911 int i;
61912 if( p==0 ){
61913 return 0;
61914 }
 
61915 if( zName ){
61916 for(i=0; i<p->nzVar; i++){
61917 const char *z = p->azVar[i];
61918 if( z && memcmp(z,zName,nName)==0 && z[nName]==0 ){
61919 return i+1;
61920 }
61921 }
@@ -63197,10 +63235,11 @@
63235 Mem **apArg;
63236 Mem *pX;
63237 } cm;
63238 struct OP_Trace_stack_vars {
63239 char *zTrace;
63240 char *z;
63241 } cn;
63242 } u;
63243 /* End automatically generated code
63244 ********************************************************************/
63245
@@ -63623,10 +63662,11 @@
63662 #if 0 /* local variables moved into u.ab */
63663 Mem *pVar; /* Value being transferred */
63664 #endif /* local variables moved into u.ab */
63665
63666 assert( pOp->p1>0 && pOp->p1<=p->nVar );
63667 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
63668 u.ab.pVar = &p->aVar[pOp->p1 - 1];
63669 if( sqlite3VdbeMemTooBig(u.ab.pVar) ){
63670 goto too_big;
63671 }
63672 sqlite3VdbeMemShallowCopy(pOut, u.ab.pVar, MEM_Static);
@@ -64415,19 +64455,19 @@
64455
64456 pIn1 = &aMem[pOp->p1];
64457 pIn3 = &aMem[pOp->p3];
64458 u.ai.flags1 = pIn1->flags;
64459 u.ai.flags3 = pIn3->flags;
64460 if( (u.ai.flags1 | u.ai.flags3)&MEM_Null ){
64461 /* One or both operands are NULL */
64462 if( pOp->p5 & SQLITE_NULLEQ ){
64463 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
64464 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
64465 ** or not both operands are null.
64466 */
64467 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
64468 u.ai.res = (u.ai.flags1 & u.ai.flags3 & MEM_Null)==0;
64469 }else{
64470 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
64471 ** then the result is always NULL.
64472 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
64473 */
@@ -65249,17 +65289,20 @@
65289 "SQL statements in progress");
65290 rc = SQLITE_BUSY;
65291 }else{
65292 u.aq.nName = sqlite3Strlen30(u.aq.zName);
65293
65294 #ifndef SQLITE_OMIT_VIRTUALTABLE
65295 /* This call is Ok even if this savepoint is actually a transaction
65296 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
65297 ** If this is a transaction savepoint being opened, it is guaranteed
65298 ** that the db->aVTrans[] array is empty. */
65299 assert( db->autoCommit==0 || db->nVTrans==0 );
65300 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
65301 db->nStatement+db->nSavepoint);
65302 if( rc!=SQLITE_OK ) goto abort_due_to_error;
65303 #endif
65304
65305 /* Create a new savepoint structure. */
65306 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
65307 if( u.aq.pNew ){
65308 u.aq.pNew->zName = (char *)&u.aq.pNew[1];
@@ -65508,11 +65551,11 @@
65551 assert( db->nStatement>=0 && db->nSavepoint>=0 );
65552 db->nStatement++;
65553 p->iStatement = db->nSavepoint + db->nStatement;
65554 }
65555
65556 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
65557 if( rc==SQLITE_OK ){
65558 rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65559 }
65560
65561 /* Store the current value of the database handles deferred constraint
@@ -68641,25 +68684,25 @@
68684 ** the UTF-8 string contained in P4 is emitted on the trace callback.
68685 */
68686 case OP_Trace: {
68687 #if 0 /* local variables moved into u.cn */
68688 char *zTrace;
68689 char *z;
68690 #endif /* local variables moved into u.cn */
68691
68692 if( db->xTrace && (u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
68693 u.cn.z = sqlite3VdbeExpandSql(p, u.cn.zTrace);
68694 db->xTrace(db->pTraceArg, u.cn.z);
68695 sqlite3DbFree(db, u.cn.z);
68696 }
 
 
68697 #ifdef SQLITE_DEBUG
68698 if( (db->flags & SQLITE_SqlTrace)!=0
68699 && (u.cn.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
68700 ){
68701 sqlite3DebugPrintf("SQL-trace: %s\n", u.cn.zTrace);
68702 }
68703 #endif /* SQLITE_DEBUG */
 
68704 break;
68705 }
68706 #endif
68707
68708
@@ -69080,11 +69123,14 @@
69123 ** and offset cache without causing any IO.
69124 */
69125 sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
69126 sqlite3VdbeChangeP2(v, 7, pTab->nCol);
69127 if( !db->mallocFailed ){
69128 pParse->nVar = 1;
69129 pParse->nMem = 1;
69130 pParse->nTab = 1;
69131 sqlite3VdbeMakeReady(v, pParse);
69132 }
69133 }
69134
69135 pBlob->flags = flags;
69136 pBlob->iCol = iCol;
@@ -71647,57 +71693,57 @@
71693 assert( z[0]!=0 );
71694 if( z[1]==0 ){
71695 /* Wildcard of the form "?". Assign the next variable number */
71696 assert( z[0]=='?' );
71697 pExpr->iColumn = (ynVar)(++pParse->nVar);
71698 }else{
71699 ynVar x = 0;
71700 u32 n = sqlite3Strlen30(z);
71701 if( z[0]=='?' ){
71702 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
71703 ** use it as the variable number */
71704 i64 i;
71705 int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
71706 pExpr->iColumn = x = (ynVar)i;
71707 testcase( i==0 );
71708 testcase( i==1 );
71709 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
71710 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
71711 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71712 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
71713 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
71714 x = 0;
71715 }
71716 if( i>pParse->nVar ){
71717 pParse->nVar = (int)i;
71718 }
71719 }else{
71720 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
71721 ** number as the prior appearance of the same name, or if the name
71722 ** has never appeared before, reuse the same variable number
71723 */
71724 ynVar i;
71725 for(i=0; i<pParse->nzVar; i++){
71726 if( pParse->azVar[i] && memcmp(pParse->azVar[i],z,n+1)==0 ){
71727 pExpr->iColumn = x = (ynVar)i+1;
71728 break;
71729 }
71730 }
71731 if( x==0 ) x = pExpr->iColumn = (ynVar)(++pParse->nVar);
71732 }
71733 if( x>0 ){
71734 if( x>pParse->nzVar ){
71735 char **a;
71736 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
71737 if( a==0 ) return; /* Error reported through db->mallocFailed */
71738 pParse->azVar = a;
71739 memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0]));
71740 pParse->nzVar = x;
71741 }
71742 if( z[0]!='?' || pParse->azVar[x-1]==0 ){
71743 sqlite3DbFree(db, pParse->azVar[x-1]);
71744 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
71745 }
71746 }
71747 }
71748 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
71749 sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -73437,11 +73483,13 @@
73483 assert( !ExprHasProperty(pExpr, EP_IntValue) );
73484 assert( pExpr->u.zToken!=0 );
73485 assert( pExpr->u.zToken[0]!=0 );
73486 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
73487 if( pExpr->u.zToken[1]!=0 ){
73488 assert( pExpr->u.zToken[0]=='?'
73489 || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
73490 sqlite3VdbeChangeP4(v, -1, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
73491 }
73492 break;
73493 }
73494 case TK_REGISTER: {
73495 inReg = pExpr->iTable;
@@ -77408,13 +77456,11 @@
77456 #endif
77457 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
77458 /* A minimum of one cursor is required if autoincrement is used
77459 * See ticket [a696379c1f08866] */
77460 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
77461 sqlite3VdbeMakeReady(v, pParse);
 
 
77462 pParse->rc = SQLITE_DONE;
77463 pParse->colNamesSet = 0;
77464 }else{
77465 pParse->rc = SQLITE_ERROR;
77466 }
@@ -81827,10 +81873,11 @@
81873 #ifndef SQLITE_OMIT_VIRTUALTABLE
81874 if( IsVirtual(pTab) ){
81875 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
81876 sqlite3VtabMakeWritable(pParse, pTab);
81877 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
81878 sqlite3VdbeChangeP5(v, OE_Abort);
81879 sqlite3MayAbort(pParse);
81880 }else
81881 #endif
81882 {
81883 int count = (pParse->nested==0); /* True to count changes */
@@ -87947,14 +87994,10 @@
87994 **
87995 *************************************************************************
87996 ** This file contains code used to implement the PRAGMA command.
87997 */
87998
 
 
 
 
87999 /*
88000 ** Interpret the given string as a safety level. Return 0 for OFF,
88001 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
88002 ** unrecognized string argument.
88003 **
@@ -87986,10 +88029,16 @@
88029 ** Interpret the given string as a boolean value.
88030 */
88031 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
88032 return getSafetyLevel(z)&1;
88033 }
88034
88035 /* The sqlite3GetBoolean() function is used by other modules but the
88036 ** remainder of this file is specific to PRAGMA processing. So omit
88037 ** the rest of the file if PRAGMAs are omitted from the build.
88038 */
88039 #if !defined(SQLITE_OMIT_PRAGMA)
88040
88041 /*
88042 ** Interpret the given string as a locking mode value.
88043 */
88044 static int getLockingMode(const char *z){
@@ -97692,15 +97741,15 @@
97741 sqlite3DbFree(db, zErr);
97742 }
97743
97744 return rc;
97745 }
 
97746 /*
97747 ** Grow the db->aVTrans[] array so that there is room for at least one
97748 ** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
97749 */
97750 static int growVTrans(sqlite3 *db){
97751 const int ARRAY_INCR = 5;
97752
97753 /* Grow the sqlite3.aVTrans array if required */
97754 if( (db->nVTrans%ARRAY_INCR)==0 ){
97755 VTable **aVTrans;
@@ -97711,14 +97760,21 @@
97760 }
97761 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
97762 db->aVTrans = aVTrans;
97763 }
97764
97765 return SQLITE_OK;
97766 }
97767
97768 /*
97769 ** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
97770 ** have already been reserved using growVTrans().
97771 */
97772 static void addToVTrans(sqlite3 *db, VTable *pVTab){
97773 /* Add pVtab to the end of sqlite3.aVTrans */
97774 db->aVTrans[db->nVTrans++] = pVTab;
97775 sqlite3VtabLock(pVTab);
 
97776 }
97777
97778 /*
97779 ** This function is invoked by the vdbe to call the xCreate method
97780 ** of the virtual table named zTab in database iDb.
@@ -97752,11 +97808,14 @@
97808 }
97809
97810 /* Justification of ALWAYS(): The xConstructor method is required to
97811 ** create a valid sqlite3_vtab if it returns SQLITE_OK. */
97812 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
97813 rc = growVTrans(db);
97814 if( rc==SQLITE_OK ){
97815 addToVTrans(db, sqlite3GetVTable(db, pTab));
97816 }
97817 }
97818
97819 return rc;
97820 }
97821
@@ -97868,10 +97927,11 @@
97927 if( p ){
97928 int (*x)(sqlite3_vtab *);
97929 x = *(int (**)(sqlite3_vtab *))((char *)p->pModule + offset);
97930 if( x ) x(p);
97931 }
97932 pVTab->iSavepoint = 0;
97933 sqlite3VtabUnlock(pVTab);
97934 }
97935 sqlite3DbFree(db, db->aVTrans);
97936 db->nVTrans = 0;
97937 db->aVTrans = 0;
@@ -97957,14 +98017,18 @@
98017 if( db->aVTrans[i]==pVTab ){
98018 return SQLITE_OK;
98019 }
98020 }
98021
98022 /* Invoke the xBegin method. If successful, add the vtab to the
98023 ** sqlite3.aVTrans[] array. */
98024 rc = growVTrans(db);
98025 if( rc==SQLITE_OK ){
98026 rc = pModule->xBegin(pVTab->pVtab);
98027 if( rc==SQLITE_OK ){
98028 addToVTrans(db, pVTab);
98029 }
98030 }
98031 }
98032 return rc;
98033 }
98034
@@ -97985,28 +98049,33 @@
98049 */
98050 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
98051 int rc = SQLITE_OK;
98052
98053 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
98054 assert( iSavepoint>=0 );
98055 if( db->aVTrans ){
98056 int i;
98057 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
98058 VTable *pVTab = db->aVTrans[i];
98059 const sqlite3_module *pMod = pVTab->pMod->pModule;
98060 if( pMod->iVersion>=2 ){
98061 int (*xMethod)(sqlite3_vtab *, int);
98062 switch( op ){
98063 case SAVEPOINT_BEGIN:
98064 xMethod = pMod->xSavepoint;
98065 pVTab->iSavepoint = iSavepoint+1;
98066 break;
98067 case SAVEPOINT_ROLLBACK:
98068 xMethod = pMod->xRollbackTo;
98069 break;
98070 default:
98071 xMethod = pMod->xRelease;
98072 break;
98073 }
98074 if( xMethod && pVTab->iSavepoint>iSavepoint ){
98075 rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
98076 }
98077 }
98078 }
98079 }
98080 return rc;
98081 }
@@ -107264,13 +107333,12 @@
107333 return SQLITE_NOMEM;
107334 }
107335 assert( pParse->pNewTable==0 );
107336 assert( pParse->pNewTrigger==0 );
107337 assert( pParse->nVar==0 );
107338 assert( pParse->nzVar==0 );
107339 assert( pParse->azVar==0 );
 
107340 enableLookaside = db->lookaside.bEnabled;
107341 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
107342 while( !db->mallocFailed && zSql[i]!=0 ){
107343 assert( i>=0 );
107344 pParse->sLastToken.z = &zSql[i];
@@ -107360,11 +107428,12 @@
107428 */
107429 sqlite3DeleteTable(db, pParse->pNewTable);
107430 }
107431
107432 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
107433 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
107434 sqlite3DbFree(db, pParse->azVar);
107435 sqlite3DbFree(db, pParse->aAlias);
107436 while( pParse->pAinc ){
107437 AutoincInfo *p = pParse->pAinc;
107438 pParse->pAinc = p->pNext;
107439 sqlite3DbFree(db, p);
@@ -109692,13 +109761,13 @@
109761 }else{
109762 struct OpenMode {
109763 const char *z;
109764 int mode;
109765 } *aMode = 0;
109766 char *zModeType = 0;
109767 int mask = 0;
109768 int limit = 0;
109769
109770 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
109771 static struct OpenMode aCacheMode[] = {
109772 { "shared", SQLITE_OPEN_SHAREDCACHE },
109773 { "private", SQLITE_OPEN_PRIVATECACHE },
@@ -111686,15 +111755,35 @@
111755 */
111756 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */
111757 typedef short int i16; /* 2-byte (or larger) signed integer */
111758 typedef unsigned int u32; /* 4-byte unsigned integer */
111759 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */
111760
111761 /*
111762 ** Macro used to suppress compiler warnings for unused parameters.
111763 */
111764 #define UNUSED_PARAMETER(x) (void)(x)
111765
111766 /*
111767 ** Activate assert() only if SQLITE_TEST is enabled.
111768 */
111769 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
111770 # define NDEBUG 1
111771 #endif
111772
111773 /*
111774 ** The TESTONLY macro is used to enclose variable declarations or
111775 ** other bits of code that are needed to support the arguments
111776 ** within testcase() and assert() macros.
111777 */
111778 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
111779 # define TESTONLY(X) X
111780 #else
111781 # define TESTONLY(X)
111782 #endif
111783
111784 #endif /* SQLITE_AMALGAMATION */
111785
111786 typedef struct Fts3Table Fts3Table;
111787 typedef struct Fts3Cursor Fts3Cursor;
111788 typedef struct Fts3Expr Fts3Expr;
111789 typedef struct Fts3Phrase Fts3Phrase;
@@ -111745,10 +111834,20 @@
111834 */
111835 int nMaxPendingData;
111836 int nPendingData;
111837 sqlite_int64 iPrevDocid;
111838 Fts3Hash pendingTerms;
111839
111840 #if defined(SQLITE_DEBUG)
111841 /* State variables used for validating that the transaction control
111842 ** methods of the virtual table are called at appropriate times. These
111843 ** values do not contribution to the FTS computation; they are used for
111844 ** verifying the SQLite core.
111845 */
111846 int inTransaction; /* True after xBegin but before xCommit/xRollback */
111847 int mxSavepoint; /* Largest valid xSavepoint integer */
111848 #endif
111849 };
111850
111851 /*
111852 ** When the core wants to read from the virtual table, it creates a
111853 ** virtual table cursor (an instance of the following structure) using
@@ -112655,10 +112754,12 @@
112754 p->pTokenizer = pTokenizer;
112755 p->nNodeSize = 1000;
112756 p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
112757 p->bHasDocsize = (isFts4 && bNoDocsize==0);
112758 p->bHasStat = isFts4;
112759 TESTONLY( p->inTransaction = -1 );
112760 TESTONLY( p->mxSavepoint = -1 );
112761 fts3HashInit(&p->pendingTerms, FTS3_HASH_STRING, 1);
112762
112763 /* Fill in the zName and zDb fields of the vtab structure. */
112764 zCsr = (char *)&p->azColumn[nCol];
112765 p->zName = zCsr;
@@ -114952,11 +115053,15 @@
115053 /*
115054 ** Implementation of xBegin() method. This is a no-op.
115055 */
115056 static int fts3BeginMethod(sqlite3_vtab *pVtab){
115057 UNUSED_PARAMETER(pVtab);
115058 TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115059 assert( p->nPendingData==0 );
115060 assert( p->inTransaction!=1 );
115061 TESTONLY( p->inTransaction = 1 );
115062 TESTONLY( p->mxSavepoint = -1; );
115063 return SQLITE_OK;
115064 }
115065
115066 /*
115067 ** Implementation of xCommit() method. This is a no-op. The contents of
@@ -114963,20 +115068,28 @@
115068 ** the pending-terms hash-table have already been flushed into the database
115069 ** by fts3SyncMethod().
115070 */
115071 static int fts3CommitMethod(sqlite3_vtab *pVtab){
115072 UNUSED_PARAMETER(pVtab);
115073 TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115074 assert( p->nPendingData==0 );
115075 assert( p->inTransaction!=0 );
115076 TESTONLY( p->inTransaction = 0 );
115077 TESTONLY( p->mxSavepoint = -1; );
115078 return SQLITE_OK;
115079 }
115080
115081 /*
115082 ** Implementation of xRollback(). Discard the contents of the pending-terms
115083 ** hash-table. Any changes made to the database are reverted by SQLite.
115084 */
115085 static int fts3RollbackMethod(sqlite3_vtab *pVtab){
115086 Fts3Table *p = (Fts3Table*)pVtab;
115087 sqlite3Fts3PendingTermsClear(p);
115088 assert( p->inTransaction!=0 );
115089 TESTONLY( p->inTransaction = 0 );
115090 TESTONLY( p->mxSavepoint = -1; );
115091 return SQLITE_OK;
115092 }
115093
115094 /*
115095 ** Load the doclist associated with expression pExpr to pExpr->aDoclist.
@@ -115328,17 +115441,33 @@
115441 );
115442 return rc;
115443 }
115444
115445 static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
115446 Fts3Table *p = (Fts3Table*)pVtab;
115447 UNUSED_PARAMETER(iSavepoint);
115448 assert( p->inTransaction );
115449 assert( p->mxSavepoint < iSavepoint );
115450 TESTONLY( p->mxSavepoint = iSavepoint );
115451 return sqlite3Fts3PendingTermsFlush(p);
115452 }
115453 static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
115454 TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
115455 UNUSED_PARAMETER(iSavepoint);
115456 UNUSED_PARAMETER(pVtab);
115457 assert( p->inTransaction );
115458 assert( p->mxSavepoint >= iSavepoint );
115459 TESTONLY( p->mxSavepoint = iSavepoint-1 );
115460 return SQLITE_OK;
115461 }
115462 static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
115463 Fts3Table *p = (Fts3Table*)pVtab;
115464 UNUSED_PARAMETER(iSavepoint);
115465 assert( p->inTransaction );
115466 assert( p->mxSavepoint >= iSavepoint );
115467 TESTONLY( p->mxSavepoint = iSavepoint );
115468 sqlite3Fts3PendingTermsClear(p);
115469 return SQLITE_OK;
115470 }
115471
115472 static const sqlite3_module fts3Module = {
115473 /* iVersion */ 2,
@@ -115833,10 +115962,11 @@
115962 Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab;
115963 int rc;
115964 int isScan;
115965
115966 UNUSED_PARAMETER(nVal);
115967 UNUSED_PARAMETER(idxStr);
115968
115969 assert( idxStr==0 );
115970 assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0
115971 || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT
115972 || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT)
@@ -115950,11 +116080,14 @@
116080 0, /* xBegin */
116081 0, /* xSync */
116082 0, /* xCommit */
116083 0, /* xRollback */
116084 0, /* xFindFunction */
116085 0, /* xRename */
116086 0, /* xSavepoint */
116087 0, /* xRelease */
116088 0 /* xRollbackTo */
116089 };
116090 int rc; /* Return code */
116091
116092 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
116093 return rc;
@@ -125929,11 +126062,11 @@
126062 }
126063 return rc;
126064 }
126065
126066 static sqlite3_module rtreeModule = {
126067 0, /* iVersion */
126068 rtreeCreate, /* xCreate - create a table */
126069 rtreeConnect, /* xConnect - connect to an existing table */
126070 rtreeBestIndex, /* xBestIndex - Determine search strategy */
126071 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
126072 rtreeDestroy, /* xDestroy - Drop a table */
@@ -125948,11 +126081,14 @@
126081 0, /* xBegin - begin transaction */
126082 0, /* xSync - sync transaction */
126083 0, /* xCommit - commit transaction */
126084 0, /* xRollback - rollback transaction */
126085 0, /* xFindFunction - function overloading */
126086 rtreeRename, /* xRename - rename the table */
126087 0, /* xSavepoint */
126088 0, /* xRelease */
126089 0 /* xRollbackTo */
126090 };
126091
126092 static int rtreeSqlInit(
126093 Rtree *pRtree,
126094 sqlite3 *db,
126095
+5 -3
--- 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.7"
111111
#define SQLITE_VERSION_NUMBER 3007007
112
-#define SQLITE_SOURCE_ID "2011-05-20 01:50:01 2018d4e108872f2436df046636401b89cfde589d"
112
+#define SQLITE_SOURCE_ID "2011-06-03 14:19:10 0206bc6f87bb9393218a380fc5b18039d334a8d8"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -457,10 +457,12 @@
457457
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
458458
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
459459
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
460460
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
461461
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
462
+#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
463
+#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
462464
463465
/*
464466
** CAPI3REF: Flags For File Open Operations
465467
**
466468
** These bit values are intended for use in the
@@ -762,15 +764,15 @@
762764
*/
763765
typedef struct sqlite3_mutex sqlite3_mutex;
764766
765767
/*
766768
** CAPI3REF: OS Interface Object
767
-** KEYWORDS: VFS VFSes
768769
**
769770
** An instance of the sqlite3_vfs object defines the interface between
770771
** the SQLite core and the underlying operating system. The "vfs"
771
-** in the name of the object stands for "virtual file system".
772
+** in the name of the object stands for "virtual file system". See
773
+** the [VFS | VFS documentation] for further information.
772774
**
773775
** The value of the iVersion field is initially 1 but may be larger in
774776
** future versions of SQLite. Additional fields may be appended to this
775777
** object when the iVersion value is increased. Note that the structure
776778
** of the sqlite3_vfs object changes in the transaction between
777779
--- 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.7"
111 #define SQLITE_VERSION_NUMBER 3007007
112 #define SQLITE_SOURCE_ID "2011-05-20 01:50:01 2018d4e108872f2436df046636401b89cfde589d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -457,10 +457,12 @@
457 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
458 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
459 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
460 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
461 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
 
 
462
463 /*
464 ** CAPI3REF: Flags For File Open Operations
465 **
466 ** These bit values are intended for use in the
@@ -762,15 +764,15 @@
762 */
763 typedef struct sqlite3_mutex sqlite3_mutex;
764
765 /*
766 ** CAPI3REF: OS Interface Object
767 ** KEYWORDS: VFS VFSes
768 **
769 ** An instance of the sqlite3_vfs object defines the interface between
770 ** the SQLite core and the underlying operating system. The "vfs"
771 ** in the name of the object stands for "virtual file system".
 
772 **
773 ** The value of the iVersion field is initially 1 but may be larger in
774 ** future versions of SQLite. Additional fields may be appended to this
775 ** object when the iVersion value is increased. Note that the structure
776 ** of the sqlite3_vfs object changes in the transaction between
777
--- 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.7"
111 #define SQLITE_VERSION_NUMBER 3007007
112 #define SQLITE_SOURCE_ID "2011-06-03 14:19:10 0206bc6f87bb9393218a380fc5b18039d334a8d8"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -457,10 +457,12 @@
457 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
458 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
459 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
460 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
461 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
462 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
463 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
464
465 /*
466 ** CAPI3REF: Flags For File Open Operations
467 **
468 ** These bit values are intended for use in the
@@ -762,15 +764,15 @@
764 */
765 typedef struct sqlite3_mutex sqlite3_mutex;
766
767 /*
768 ** CAPI3REF: OS Interface Object
 
769 **
770 ** An instance of the sqlite3_vfs object defines the interface between
771 ** the SQLite core and the underlying operating system. The "vfs"
772 ** in the name of the object stands for "virtual file system". See
773 ** the [VFS | VFS documentation] for further information.
774 **
775 ** The value of the iVersion field is initially 1 but may be larger in
776 ** future versions of SQLite. Additional fields may be appended to this
777 ** object when the iVersion value is increased. Note that the structure
778 ** of the sqlite3_vfs object changes in the transaction between
779

Keyboard Shortcuts

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