Fossil SCM

merge drh fix (additionally, sqlite3 updates)

bch 2012-01-11 21:50 status_redo merge
Commit 6a39f43dc06f966f040ca09f783692bdef738a85
4 files changed +189 -149 +1 -1 +16 -2 +16 -2
+189 -149
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -657,11 +657,11 @@
657657
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
658658
** [sqlite_version()] and [sqlite_source_id()].
659659
*/
660660
#define SQLITE_VERSION "3.7.10"
661661
#define SQLITE_VERSION_NUMBER 3007010
662
-#define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983"
662
+#define SQLITE_SOURCE_ID "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
663663
664664
/*
665665
** CAPI3REF: Run-Time Library Version Numbers
666666
** KEYWORDS: sqlite3_version, sqlite3_sourceid
667667
**
@@ -9396,17 +9396,19 @@
93969396
SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
93979397
SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
93989398
SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
93999399
SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
94009400
SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
9401
+SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
94019402
#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
94029403
SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
94039404
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
94049405
SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
94059406
SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
94069407
SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
94079408
SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
9409
+
94089410
94099411
/*
94109412
** Functions for accessing sqlite3_vfs methods
94119413
*/
94129414
SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
@@ -13244,12 +13246,14 @@
1324413246
#endif
1324513247
SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
1324613248
1324713249
#ifndef SQLITE_OMIT_INCRBLOB
1324813250
SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
13251
+ #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
1324913252
#else
1325013253
#define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
13254
+ #define ExpandBlob(P) SQLITE_OK
1325113255
#endif
1325213256
1325313257
#endif /* !defined(_VDBEINT_H_) */
1325413258
1325513259
/************** End of vdbeInt.h *********************************************/
@@ -14715,14 +14719,27 @@
1471514719
}
1471614720
SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){
1471714721
DO_OS_MALLOC_TEST(id);
1471814722
return id->pMethods->xCheckReservedLock(id, pResOut);
1471914723
}
14724
+
14725
+/*
14726
+** Use sqlite3OsFileControl() when we are doing something that might fail
14727
+** and we need to know about the failures. Use sqlite3OsFileControlHint()
14728
+** when simply tossing information over the wall to the VFS and we do not
14729
+** really care if the VFS receives and understands the information since it
14730
+** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
14731
+** routine has no return value since the return value would be meaningless.
14732
+*/
1472014733
SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
1472114734
DO_OS_MALLOC_TEST(id);
1472214735
return id->pMethods->xFileControl(id, op, pArg);
1472314736
}
14737
+SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
14738
+ (void)id->pMethods->xFileControl(id, op, pArg);
14739
+}
14740
+
1472414741
SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){
1472514742
int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
1472614743
return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
1472714744
}
1472814745
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
@@ -14769,10 +14786,11 @@
1476914786
assert( rc==SQLITE_OK || pFile->pMethods==0 );
1477014787
return rc;
1477114788
}
1477214789
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
1477314790
DO_OS_MALLOC_TEST(0);
14791
+ assert( dirSync==0 || dirSync==1 );
1477414792
return pVfs->xDelete(pVfs, zPath, dirSync);
1477514793
}
1477614794
SQLITE_PRIVATE int sqlite3OsAccess(
1477714795
sqlite3_vfs *pVfs,
1477814796
const char *zPath,
@@ -22113,31 +22131,26 @@
2211322131
** characters of the original suffix.
2211422132
**
2211522133
** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
2211622134
** do the suffix shortening regardless of URI parameter.
2211722135
**
22118
-** Assume that zBaseFilename contains two \000 terminator bytes (so that
22119
-** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both
22120
-** zero terminator bytes into the end of the revised name.
22121
-**
2212222136
** Examples:
2212322137
**
2212422138
** test.db-journal => test.nal
2212522139
** test.db-wal => test.wal
2212622140
** test.db-shm => test.shm
2212722141
** test.db-mj7f3319fa => test.9fa
2212822142
*/
2212922143
SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
22130
- assert( zBaseFilename[strlen(zBaseFilename)+1]==0 );
2213122144
#if SQLITE_ENABLE_8_3_NAMES<2
2213222145
if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) )
2213322146
#endif
2213422147
{
2213522148
int i, sz;
2213622149
sz = sqlite3Strlen30(z);
2213722150
for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
22138
- if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5);
22151
+ if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4);
2213922152
}
2214022153
}
2214122154
#endif
2214222155
2214322156
/************** End of util.c ************************************************/
@@ -24941,11 +24954,10 @@
2494124954
#endif
2494224955
#if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
2494324956
unsigned fsFlags; /* cached details from statfs() */
2494424957
#endif
2494524958
#if OS_VXWORKS
24946
- int isDelete; /* Delete on close if true */
2494724959
struct vxworksFileId *pId; /* Unique file ID */
2494824960
#endif
2494924961
#ifndef NDEBUG
2495024962
/* The next group of variables are used to track whether or not the
2495124963
** transaction counter in bytes 24-27 of database files are updated
@@ -24976,10 +24988,13 @@
2497624988
# define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
2497724989
#else
2497824990
# define UNIXFILE_DIRSYNC 0x00
2497924991
#endif
2498024992
#define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
24993
+#define UNIXFILE_DELETE 0x20 /* Delete on close */
24994
+#define UNIXFILE_URI 0x40 /* Filename might have query parameters */
24995
+#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
2498124996
2498224997
/*
2498324998
** Include code that is common to all os_*.c files
2498424999
*/
2498525000
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -26689,11 +26704,11 @@
2668926704
robust_close(pFile, pFile->h, __LINE__);
2669026705
pFile->h = -1;
2669126706
}
2669226707
#if OS_VXWORKS
2669326708
if( pFile->pId ){
26694
- if( pFile->isDelete ){
26709
+ if( pFile->ctrlFlags & UNIXFILE_DELETE ){
2669526710
osUnlink(pFile->pId->zCanonicalName);
2669626711
}
2669726712
vxworksReleaseFileId(pFile->pId);
2669826713
pFile->pId = 0;
2669926714
}
@@ -28796,11 +28811,11 @@
2879628811
pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
2879728812
if( pShmNode==0 ){
2879828813
rc = SQLITE_NOMEM;
2879928814
goto shm_open_err;
2880028815
}
28801
- memset(pShmNode, 0, sizeof(*pShmNode));
28816
+ memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
2880228817
zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
2880328818
#ifdef SQLITE_SHM_DIRECTORY
2880428819
sqlite3_snprintf(nShmFilename, zShmFilename,
2880528820
SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
2880628821
(u32)sStat.st_ino, (u32)sStat.st_dev);
@@ -29479,28 +29494,20 @@
2947929494
** Initialize the contents of the unixFile structure pointed to by pId.
2948029495
*/
2948129496
static int fillInUnixFile(
2948229497
sqlite3_vfs *pVfs, /* Pointer to vfs object */
2948329498
int h, /* Open file descriptor of file being opened */
29484
- int syncDir, /* True to sync directory on first sync */
2948529499
sqlite3_file *pId, /* Write to the unixFile structure here */
2948629500
const char *zFilename, /* Name of the file being opened */
29487
- int noLock, /* Omit locking if true */
29488
- int isDelete, /* Delete on close if true */
29489
- int isReadOnly /* True if the file is opened read-only */
29501
+ int ctrlFlags /* Zero or more UNIXFILE_* values */
2949029502
){
2949129503
const sqlite3_io_methods *pLockingStyle;
2949229504
unixFile *pNew = (unixFile *)pId;
2949329505
int rc = SQLITE_OK;
2949429506
2949529507
assert( pNew->pInode==NULL );
2949629508
29497
- /* Parameter isDelete is only used on vxworks. Express this explicitly
29498
- ** here to prevent compiler warnings about unused parameters.
29499
- */
29500
- UNUSED_PARAMETER(isDelete);
29501
-
2950229509
/* Usually the path zFilename should not be a relative pathname. The
2950329510
** exception is when opening the proxy "conch" file in builds that
2950429511
** include the special Apple locking styles.
2950529512
*/
2950629513
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29509,39 +29516,34 @@
2950929516
#else
2951029517
assert( zFilename==0 || zFilename[0]=='/' );
2951129518
#endif
2951229519
2951329520
/* No locking occurs in temporary files */
29514
- assert( zFilename!=0 || noLock );
29521
+ assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
2951529522
2951629523
OSTRACE(("OPEN %-3d %s\n", h, zFilename));
2951729524
pNew->h = h;
2951829525
pNew->pVfs = pVfs;
2951929526
pNew->zPath = zFilename;
29520
- pNew->ctrlFlags = 0;
29521
- if( sqlite3_uri_boolean(zFilename, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
29527
+ pNew->ctrlFlags = (u8)ctrlFlags;
29528
+ if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
29529
+ "psow", SQLITE_POWERSAFE_OVERWRITE) ){
2952229530
pNew->ctrlFlags |= UNIXFILE_PSOW;
2952329531
}
2952429532
if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
2952529533
pNew->ctrlFlags |= UNIXFILE_EXCL;
2952629534
}
29527
- if( isReadOnly ){
29528
- pNew->ctrlFlags |= UNIXFILE_RDONLY;
29529
- }
29530
- if( syncDir ){
29531
- pNew->ctrlFlags |= UNIXFILE_DIRSYNC;
29532
- }
2953329535
2953429536
#if OS_VXWORKS
2953529537
pNew->pId = vxworksFindFileId(zFilename);
2953629538
if( pNew->pId==0 ){
29537
- noLock = 1;
29539
+ ctrlFlags |= UNIXFILE_NOLOCK;
2953829540
rc = SQLITE_NOMEM;
2953929541
}
2954029542
#endif
2954129543
29542
- if( noLock ){
29544
+ if( ctrlFlags & UNIXFILE_NOLOCK ){
2954329545
pLockingStyle = &nolockIoMethods;
2954429546
}else{
2954529547
pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
2954629548
#if SQLITE_ENABLE_LOCKING_STYLE
2954729549
/* Cache zFilename in the locking context (AFP and dotlock override) for
@@ -29658,11 +29660,11 @@
2965829660
if( h>=0 ) robust_close(pNew, h, __LINE__);
2965929661
h = -1;
2966029662
osUnlink(zFilename);
2966129663
isDelete = 0;
2966229664
}
29663
- pNew->isDelete = isDelete;
29665
+ if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE;
2966429666
#endif
2966529667
if( rc!=SQLITE_OK ){
2966629668
if( h>=0 ) robust_close(pNew, h, __LINE__);
2966729669
}else{
2966829670
pNew->pMethod = pLockingStyle;
@@ -29723,22 +29725,23 @@
2972329725
if( zDir==0 ) zDir = ".";
2972429726
2972529727
/* Check that the output buffer is large enough for the temporary file
2972629728
** name. If it is not, return SQLITE_ERROR.
2972729729
*/
29728
- if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= (size_t)nBuf ){
29730
+ if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){
2972929731
return SQLITE_ERROR;
2973029732
}
2973129733
2973229734
do{
29733
- sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
29735
+ sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
2973429736
j = (int)strlen(zBuf);
2973529737
sqlite3_randomness(15, &zBuf[j]);
2973629738
for(i=0; i<15; i++, j++){
2973729739
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
2973829740
}
2973929741
zBuf[j] = 0;
29742
+ zBuf[j+1] = 0;
2974029743
}while( osAccess(zBuf,0)==0 );
2974129744
return SQLITE_OK;
2974229745
}
2974329746
2974429747
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
@@ -29913,10 +29916,11 @@
2991329916
int fd = -1; /* File descriptor returned by open() */
2991429917
int openFlags = 0; /* Flags to pass to open() */
2991529918
int eType = flags&0xFFFFFF00; /* Type of file to open */
2991629919
int noLock; /* True to omit locking primitives */
2991729920
int rc = SQLITE_OK; /* Function Return Code */
29921
+ int ctrlFlags = 0; /* UNIXFILE_* flags */
2991829922
2991929923
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
2992029924
int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
2992129925
int isCreate = (flags & SQLITE_OPEN_CREATE);
2992229926
int isReadonly = (flags & SQLITE_OPEN_READONLY);
@@ -29939,11 +29943,11 @@
2993929943
));
2994029944
2994129945
/* If argument zPath is a NULL pointer, this function is required to open
2994229946
** a temporary file. Use this buffer to store the file name in.
2994329947
*/
29944
- char zTmpname[MAX_PATHNAME+1];
29948
+ char zTmpname[MAX_PATHNAME+2];
2994529949
const char *zName = zPath;
2994629950
2994729951
/* Check the following statements are true:
2994829952
**
2994929953
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
@@ -29982,18 +29986,28 @@
2998229986
if( !pUnused ){
2998329987
return SQLITE_NOMEM;
2998429988
}
2998529989
}
2998629990
p->pUnused = pUnused;
29991
+
29992
+ /* Database filenames are double-zero terminated if they are not
29993
+ ** URIs with parameters. Hence, they can always be passed into
29994
+ ** sqlite3_uri_parameter(). */
29995
+ assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
29996
+
2998729997
}else if( !zName ){
2998829998
/* If zName is NULL, the upper layer is requesting a temp file. */
2998929999
assert(isDelete && !syncDir);
29990
- rc = unixGetTempname(MAX_PATHNAME+1, zTmpname);
30000
+ rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
2999130001
if( rc!=SQLITE_OK ){
2999230002
return rc;
2999330003
}
2999430004
zName = zTmpname;
30005
+
30006
+ /* Generated temporary filenames are always double-zero terminated
30007
+ ** for use by sqlite3_uri_parameter(). */
30008
+ assert( zName[strlen(zName)+1]==0 );
2999530009
}
2999630010
2999730011
/* Determine the value of the flags parameter passed to POSIX function
2999830012
** open(). These must be calculated even if open() is not called, as
2999930013
** they may be stored as part of the file handle and used by the
@@ -30066,11 +30080,18 @@
3006630080
}
3006730081
if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
3006830082
((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
3006930083
}
3007030084
#endif
30071
-
30085
+
30086
+ /* Set up appropriate ctrlFlags */
30087
+ if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
30088
+ if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
30089
+ if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK;
30090
+ if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
30091
+ if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
30092
+
3007230093
#if SQLITE_ENABLE_LOCKING_STYLE
3007330094
#if SQLITE_PREFER_PROXY_LOCKING
3007430095
isAutoProxy = 1;
3007530096
#endif
3007630097
if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){
@@ -30096,12 +30117,11 @@
3009630117
goto open_finished;
3009730118
}
3009830119
useProxy = !(fsInfo.f_flags&MNT_LOCAL);
3009930120
}
3010030121
if( useProxy ){
30101
- rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
30102
- isDelete, isReadonly);
30122
+ rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
3010330123
if( rc==SQLITE_OK ){
3010430124
rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
3010530125
if( rc!=SQLITE_OK ){
3010630126
/* Use unixClose to clean up the resources added in fillInUnixFile
3010730127
** and clear all the structure's references. Specifically,
@@ -30114,12 +30134,12 @@
3011430134
goto open_finished;
3011530135
}
3011630136
}
3011730137
#endif
3011830138
30119
- rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
30120
- isDelete, isReadonly);
30139
+ rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
30140
+
3012130141
open_finished:
3012230142
if( rc!=SQLITE_OK ){
3012330143
sqlite3_free(p->pUnused);
3012430144
}
3012530145
return rc;
@@ -30140,11 +30160,11 @@
3014030160
SimulateIOError(return SQLITE_IOERR_DELETE);
3014130161
if( osUnlink(zPath)==(-1) && errno!=ENOENT ){
3014230162
return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
3014330163
}
3014430164
#ifndef SQLITE_DISABLE_DIRSYNC
30145
- if( dirSync ){
30165
+ if( (dirSync & 1)!=0 ){
3014630166
int fd;
3014730167
rc = osOpenDirectory(zPath, &fd);
3014830168
if( rc==SQLITE_OK ){
3014930169
#if OS_VXWORKS
3015030170
if( fsync(fd)==-1 )
@@ -30786,11 +30806,11 @@
3078630806
dummyVfs.zName = "dummy";
3078730807
pUnused->fd = fd;
3078830808
pUnused->flags = openFlags;
3078930809
pNew->pUnused = pUnused;
3079030810
30791
- rc = fillInUnixFile(&dummyVfs, fd, 0, (sqlite3_file*)pNew, path, 0, 0, 0);
30811
+ rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
3079230812
if( rc==SQLITE_OK ){
3079330813
*ppFile = pNew;
3079430814
return SQLITE_OK;
3079530815
}
3079630816
end_create_proxy:
@@ -34388,11 +34408,13 @@
3438834408
winClose((sqlite3_file *)&p->hFile);
3438934409
SimulateIOErrorBenign(0);
3439034410
}
3439134411
if( deleteFlag ){
3439234412
SimulateIOErrorBenign(1);
34413
+ sqlite3BeginBenignMalloc();
3439334414
winDelete(pVfs, p->zFilename, 0);
34415
+ sqlite3EndBenignMalloc();
3439434416
SimulateIOErrorBenign(0);
3439534417
}
3439634418
*pp = p->pNext;
3439734419
sqlite3_free(p->aRegion);
3439834420
sqlite3_free(p);
@@ -34423,16 +34445,16 @@
3442334445
*/
3442434446
p = sqlite3_malloc( sizeof(*p) );
3442534447
if( p==0 ) return SQLITE_IOERR_NOMEM;
3442634448
memset(p, 0, sizeof(*p));
3442734449
nName = sqlite3Strlen30(pDbFd->zPath);
34428
- pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 16 );
34450
+ pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 );
3442934451
if( pNew==0 ){
3443034452
sqlite3_free(p);
3443134453
return SQLITE_IOERR_NOMEM;
3443234454
}
34433
- memset(pNew, 0, sizeof(*pNew));
34455
+ memset(pNew, 0, sizeof(*pNew) + nName + 17);
3443434456
pNew->zFilename = (char*)&pNew[1];
3443534457
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
3443634458
sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
3443734459
3443834460
/* Look to see if there is an existing winShmNode that can be used.
@@ -34464,11 +34486,10 @@
3446434486
pShmNode->zFilename, /* Name of the file (UTF-8) */
3446534487
(sqlite3_file*)&pShmNode->hFile, /* File handle here */
3446634488
SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
3446734489
0);
3446834490
if( SQLITE_OK!=rc ){
34469
- rc = SQLITE_CANTOPEN_BKPT;
3447034491
goto shm_open_err;
3447134492
}
3447234493
3447334494
/* Check to see if another process is holding the dead-man switch.
3447434495
** If not, truncate the file to zero length.
@@ -34887,11 +34908,11 @@
3488734908
static char zChars[] =
3488834909
"abcdefghijklmnopqrstuvwxyz"
3488934910
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3489034911
"0123456789";
3489134912
size_t i, j;
34892
- char zTempPath[MAX_PATH+1];
34913
+ char zTempPath[MAX_PATH+2];
3489334914
3489434915
/* It's odd to simulate an io-error here, but really this is just
3489534916
** using the io-error infrastructure to test that SQLite handles this
3489634917
** function failing.
3489734918
*/
@@ -34930,25 +34951,26 @@
3493034951
}
3493134952
3493234953
/* Check that the output buffer is large enough for the temporary file
3493334954
** name. If it is not, return SQLITE_ERROR.
3493434955
*/
34935
- if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
34956
+ if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
3493634957
return SQLITE_ERROR;
3493734958
}
3493834959
3493934960
for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
3494034961
zTempPath[i] = 0;
3494134962
34942
- sqlite3_snprintf(nBuf-17, zBuf,
34963
+ sqlite3_snprintf(nBuf-18, zBuf,
3494334964
"%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
3494434965
j = sqlite3Strlen30(zBuf);
3494534966
sqlite3_randomness(15, &zBuf[j]);
3494634967
for(i=0; i<15; i++, j++){
3494734968
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
3494834969
}
3494934970
zBuf[j] = 0;
34971
+ zBuf[j+1] = 0;
3495034972
3495134973
OSTRACE(("TEMP FILENAME: %s\n", zBuf));
3495234974
return SQLITE_OK;
3495334975
}
3495434976
@@ -34977,11 +34999,11 @@
3497734999
int cnt = 0;
3497835000
3497935001
/* If argument zPath is a NULL pointer, this function is required to open
3498035002
** a temporary file. Use this buffer to store the file name in.
3498135003
*/
34982
- char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
35004
+ char zTmpname[MAX_PATH+2]; /* Buffer used to create temp filename */
3498335005
3498435006
int rc = SQLITE_OK; /* Function Return Code */
3498535007
#if !defined(NDEBUG) || SQLITE_OS_WINCE
3498635008
int eType = flags&0xFFFFFF00; /* Type of file to open */
3498735009
#endif
@@ -35036,16 +35058,23 @@
3503635058
/* If the second argument to this function is NULL, generate a
3503735059
** temporary file name to use
3503835060
*/
3503935061
if( !zUtf8Name ){
3504035062
assert(isDelete && !isOpenJournal);
35041
- rc = getTempname(MAX_PATH+1, zTmpname);
35063
+ rc = getTempname(MAX_PATH+2, zTmpname);
3504235064
if( rc!=SQLITE_OK ){
3504335065
return rc;
3504435066
}
3504535067
zUtf8Name = zTmpname;
3504635068
}
35069
+
35070
+ /* Database filenames are double-zero terminated if they are not
35071
+ ** URIs with parameters. Hence, they can always be passed into
35072
+ ** sqlite3_uri_parameter().
35073
+ */
35074
+ assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) ||
35075
+ zUtf8Name[strlen(zUtf8Name)+1]==0 );
3504735076
3504835077
/* Convert the filename to the system encoding. */
3504935078
zConverted = convertUtf8Filename(zUtf8Name);
3505035079
if( zConverted==0 ){
3505135080
return SQLITE_IOERR_NOMEM;
@@ -36721,11 +36750,11 @@
3672136750
** of.
3672236751
**
3672336752
** Mode 1 uses more memory (since PCache instances are not able to rob
3672436753
** unused pages from other PCaches) but it also operates without a mutex,
3672536754
** and is therefore often faster. Mode 2 requires a mutex in order to be
36726
-** threadsafe, but is able recycle pages more efficient.
36755
+** threadsafe, but recycles pages more efficiently.
3672736756
**
3672836757
** For mode (1), PGroup.mutex is NULL. For mode (2) there is only a single
3672936758
** PGroup which is the pcache1.grp global variable and its mutex is
3673036759
** SQLITE_MUTEX_STATIC_LRU.
3673136760
*/
@@ -36747,11 +36776,11 @@
3674736776
** opaque sqlite3_pcache* handles.
3674836777
*/
3674936778
struct PCache1 {
3675036779
/* Cache configuration parameters. Page size (szPage) and the purgeable
3675136780
** flag (bPurgeable) are set when the cache is created. nMax may be
36752
- ** modified at any time by a call to the pcache1CacheSize() method.
36781
+ ** modified at any time by a call to the pcache1Cachesize() method.
3675336782
** The PGroup mutex must be held when accessing nMax.
3675436783
*/
3675536784
PGroup *pGroup; /* PGroup this cache belongs to */
3675636785
int szPage; /* Size of allocated pages in bytes */
3675736786
int szExtra; /* Size of extra space in bytes */
@@ -37038,11 +37067,11 @@
3703837067
** it is desirable to avoid allocating a new page cache entry because
3703937068
** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
3704037069
** for all page cache needs and we should not need to spill the
3704137070
** allocation onto the heap.
3704237071
**
37043
-** Or, the heap is used for all page cache memory put the heap is
37072
+** Or, the heap is used for all page cache memory but the heap is
3704437073
** under memory pressure, then again it is desirable to avoid
3704537074
** allocating a new page cache entry in order to avoid stressing
3704637075
** the heap even further.
3704737076
*/
3704837077
static int pcache1UnderMemoryPressure(PCache1 *pCache){
@@ -37349,11 +37378,11 @@
3734937378
** means to try really hard to allocate a new page.
3735037379
**
3735137380
** For a non-purgeable cache (a cache used as the storage for an in-memory
3735237381
** database) there is really no difference between createFlag 1 and 2. So
3735337382
** the calling function (pcache.c) will never have a createFlag of 1 on
37354
-** a non-purgable cache.
37383
+** a non-purgeable cache.
3735537384
**
3735637385
** There are three different approaches to obtaining space for a page,
3735737386
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
3735837387
**
3735937388
** 1. Regardless of the value of createFlag, the cache is searched for a
@@ -40743,14 +40772,13 @@
4074340772
rc = sqlite3OsFileSize(pPager->fd, &currentSize);
4074440773
newSize = szPage*(i64)nPage;
4074540774
if( rc==SQLITE_OK && currentSize!=newSize ){
4074640775
if( currentSize>newSize ){
4074740776
rc = sqlite3OsTruncate(pPager->fd, newSize);
40748
- }else{
40777
+ }else if( (currentSize+szPage)<=newSize ){
4074940778
char *pTmp = pPager->pTmpSpace;
4075040779
memset(pTmp, 0, szPage);
40751
- testcase( (newSize-szPage) < currentSize );
4075240780
testcase( (newSize-szPage) == currentSize );
4075340781
testcase( (newSize-szPage) > currentSize );
4075440782
rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
4075540783
}
4075640784
if( rc==SQLITE_OK ){
@@ -41004,14 +41032,15 @@
4100441032
/* Following a rollback, the database file should be back in its original
4100541033
** state prior to the start of the transaction, so invoke the
4100641034
** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
4100741035
** assertion that the transaction counter was modified.
4100841036
*/
41009
- assert(
41010
- pPager->fd->pMethods==0 ||
41011
- sqlite3OsFileControl(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0)>=SQLITE_OK
41012
- );
41037
+#ifdef SQLITE_DEBUG
41038
+ if( pPager->fd->pMethods ){
41039
+ sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
41040
+ }
41041
+#endif
4101341042
4101441043
/* If this playback is happening automatically as a result of an IO or
4101541044
** malloc error that occurred after the change-counter was updated but
4101641045
** before the transaction was committed, then the change-counter
4101741046
** modification may just have been reverted. If this happens in exclusive
@@ -41344,14 +41373,11 @@
4134441373
int rc = sqlite3OsFileSize(pPager->fd, &n);
4134541374
if( rc!=SQLITE_OK ){
4134641375
return rc;
4134741376
}
4134841377
}
41349
- nPage = (Pgno)(n / pPager->pageSize);
41350
- if( nPage==0 && n>0 ){
41351
- nPage = 1;
41352
- }
41378
+ nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
4135341379
}
4135441380
4135541381
/* If the current number of pages in the file is greater than the
4135641382
** configured maximum pager number, increase the allowed limit so
4135741383
** that the file can be read.
@@ -41778,11 +41804,11 @@
4177841804
if( !pNew ) rc = SQLITE_NOMEM;
4177941805
}
4178041806
4178141807
if( rc==SQLITE_OK ){
4178241808
pager_reset(pPager);
41783
- pPager->dbSize = (Pgno)(nByte/pageSize);
41809
+ pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
4178441810
pPager->pageSize = pageSize;
4178541811
sqlite3PageFree(pPager->pTmpSpace);
4178641812
pPager->pTmpSpace = pNew;
4178741813
sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
4178841814
}
@@ -42286,13 +42312,11 @@
4228642312
** file size will be.
4228742313
*/
4228842314
assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
4228942315
if( rc==SQLITE_OK && pPager->dbSize>pPager->dbHintSize ){
4229042316
sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
42291
- sqlite3BeginBenignMalloc();
42292
- sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
42293
- sqlite3EndBenignMalloc();
42317
+ sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
4229442318
pPager->dbHintSize = pPager->dbSize;
4229542319
}
4229642320
4229742321
while( rc==SQLITE_OK && pList ){
4229842322
Pgno pgno = pList->pgno;
@@ -44312,11 +44336,12 @@
4431244336
}else{
4431344337
rc = pager_playback(pPager, 0);
4431444338
}
4431544339
4431644340
assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
44317
- assert( rc==SQLITE_OK || rc==SQLITE_FULL || (rc&0xFF)==SQLITE_IOERR );
44341
+ assert( rc==SQLITE_OK || rc==SQLITE_FULL
44342
+ || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
4431844343
4431944344
/* If an error occurs during a ROLLBACK, we can no longer trust the pager
4432044345
** cache. So call pager_error() on the way out to make any error persistent.
4432144346
*/
4432244347
return pager_error(pPager, rc);
@@ -46887,11 +46912,11 @@
4688746912
*/
4688846913
if( rc==SQLITE_OK ){
4688946914
i64 nReq = ((i64)mxPage * szPage);
4689046915
rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
4689146916
if( rc==SQLITE_OK && nSize<nReq ){
46892
- sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
46917
+ sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
4689346918
}
4689446919
}
4689546920
4689646921
/* Iterate through the contents of the WAL, copying data to the db file. */
4689746922
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
@@ -47003,11 +47028,13 @@
4700347028
rc = sqlite3WalCheckpoint(
4700447029
pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
4700547030
);
4700647031
if( rc==SQLITE_OK ){
4700747032
int bPersist = -1;
47008
- sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist);
47033
+ sqlite3OsFileControlHint(
47034
+ pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
47035
+ );
4700947036
if( bPersist!=1 ){
4701047037
/* Try to delete the WAL file if the checkpoint completed and
4701147038
** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
4701247039
** mode (!bPersist) */
4701347040
isDelete = 1;
@@ -47024,11 +47051,13 @@
4702447051
}
4702547052
4702647053
walIndexClose(pWal, isDelete);
4702747054
sqlite3OsClose(pWal->pWalFd);
4702847055
if( isDelete ){
47056
+ sqlite3BeginBenignMalloc();
4702947057
sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
47058
+ sqlite3EndBenignMalloc();
4703047059
}
4703147060
WALTRACE(("WAL%p: closed\n", pWal));
4703247061
sqlite3_free((void *)pWal->apWiData);
4703347062
sqlite3_free(pWal);
4703447063
}
@@ -48525,10 +48554,11 @@
4852548554
u8 intKey; /* True if intkey flag is set */
4852648555
u8 leaf; /* True if leaf flag is set */
4852748556
u8 hasData; /* True if this page stores data */
4852848557
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
4852948558
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
48559
+ u8 max1bytePayload; /* min(maxLocal,127) */
4853048560
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
4853148561
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
4853248562
u16 cellOffset; /* Index in aData of first cell pointer */
4853348563
u16 nFree; /* Number of free bytes on the page */
4853448564
u16 nCell; /* Number of cells on this page, local and ovfl */
@@ -48655,21 +48685,18 @@
4865548685
struct BtShared {
4865648686
Pager *pPager; /* The page cache */
4865748687
sqlite3 *db; /* Database connection currently using this Btree */
4865848688
BtCursor *pCursor; /* A list of all open cursors */
4865948689
MemPage *pPage1; /* First page of the database */
48660
- u8 readOnly; /* True if the underlying file is readonly */
48661
- u8 pageSizeFixed; /* True if the page size can no longer be changed */
48662
- u8 secureDelete; /* True if secure_delete is enabled */
48663
- u8 initiallyEmpty; /* Database is empty at start of transaction */
4866448690
u8 openFlags; /* Flags to sqlite3BtreeOpen() */
4866548691
#ifndef SQLITE_OMIT_AUTOVACUUM
4866648692
u8 autoVacuum; /* True if auto-vacuum is enabled */
4866748693
u8 incrVacuum; /* True if incr-vacuum is enabled */
4866848694
#endif
4866948695
u8 inTransaction; /* Transaction state */
48670
- u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
48696
+ u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */
48697
+ u16 btsFlags; /* Boolean parameters. See BTS_* macros below */
4867148698
u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
4867248699
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
4867348700
u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
4867448701
u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
4867548702
u32 pageSize; /* Total number of bytes on a page */
@@ -48683,16 +48710,25 @@
4868348710
#ifndef SQLITE_OMIT_SHARED_CACHE
4868448711
int nRef; /* Number of references to this structure */
4868548712
BtShared *pNext; /* Next on a list of sharable BtShared structs */
4868648713
BtLock *pLock; /* List of locks held on this shared-btree struct */
4868748714
Btree *pWriter; /* Btree with currently open write transaction */
48688
- u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
48689
- u8 isPending; /* If waiting for read-locks to clear */
4869048715
#endif
4869148716
u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
4869248717
};
4869348718
48719
+/*
48720
+** Allowed values for BtShared.btsFlags
48721
+*/
48722
+#define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
48723
+#define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
48724
+#define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
48725
+#define BTS_INITIALLY_EMPTY 0x0008 /* Database was empty at trans start */
48726
+#define BTS_NO_WAL 0x0010 /* Do not open write-ahead-log files */
48727
+#define BTS_EXCLUSIVE 0x0020 /* pWriter has an exclusive lock */
48728
+#define BTS_PENDING 0x0040 /* Waiting for read-locks to clear */
48729
+
4869448730
/*
4869548731
** An instance of the following structure is used to hold information
4869648732
** about a cell. The parseCellPtr() function fills in this structure
4869748733
** based on information extract from the raw disk page.
4869848734
*/
@@ -49410,11 +49446,11 @@
4941049446
}
4941149447
4941249448
/* If some other connection is holding an exclusive lock, the
4941349449
** requested lock may not be obtained.
4941449450
*/
49415
- if( pBt->pWriter!=p && pBt->isExclusive ){
49451
+ if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
4941649452
sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
4941749453
return SQLITE_LOCKED_SHAREDCACHE;
4941849454
}
4941949455
4942049456
for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
@@ -49431,11 +49467,11 @@
4943149467
assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
4943249468
if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
4943349469
sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
4943449470
if( eLock==WRITE_LOCK ){
4943549471
assert( p==pBt->pWriter );
49436
- pBt->isPending = 1;
49472
+ pBt->btsFlags |= BTS_PENDING;
4943749473
}
4943849474
return SQLITE_LOCKED_SHAREDCACHE;
4943949475
}
4944049476
}
4944149477
return SQLITE_OK;
@@ -49519,11 +49555,11 @@
4951949555
/*
4952049556
** Release all the table locks (locks obtained via calls to
4952149557
** the setSharedCacheTableLock() procedure) held by Btree object p.
4952249558
**
4952349559
** This function assumes that Btree p has an open read or write
49524
-** transaction. If it does not, then the BtShared.isPending variable
49560
+** transaction. If it does not, then the BTS_PENDING flag
4952549561
** may be incorrectly cleared.
4952649562
*/
4952749563
static void clearAllSharedCacheTableLocks(Btree *p){
4952849564
BtShared *pBt = p->pBt;
4952949565
BtLock **ppIter = &pBt->pLock;
@@ -49532,11 +49568,11 @@
4953249568
assert( p->sharable || 0==*ppIter );
4953349569
assert( p->inTrans>0 );
4953449570
4953549571
while( *ppIter ){
4953649572
BtLock *pLock = *ppIter;
49537
- assert( pBt->isExclusive==0 || pBt->pWriter==pLock->pBtree );
49573
+ assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
4953849574
assert( pLock->pBtree->inTrans>=pLock->eLock );
4953949575
if( pLock->pBtree==p ){
4954049576
*ppIter = pLock->pNext;
4954149577
assert( pLock->iTable!=1 || pLock==&p->lock );
4954249578
if( pLock->iTable!=1 ){
@@ -49545,26 +49581,25 @@
4954549581
}else{
4954649582
ppIter = &pLock->pNext;
4954749583
}
4954849584
}
4954949585
49550
- assert( pBt->isPending==0 || pBt->pWriter );
49586
+ assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
4955149587
if( pBt->pWriter==p ){
4955249588
pBt->pWriter = 0;
49553
- pBt->isExclusive = 0;
49554
- pBt->isPending = 0;
49589
+ pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
4955549590
}else if( pBt->nTransaction==2 ){
4955649591
/* This function is called when Btree p is concluding its
4955749592
** transaction. If there currently exists a writer, and p is not
4955849593
** that writer, then the number of locks held by connections other
4955949594
** than the writer must be about to drop to zero. In this case
49560
- ** set the isPending flag to 0.
49595
+ ** set the BTS_PENDING flag to 0.
4956149596
**
49562
- ** If there is not currently a writer, then BtShared.isPending must
49597
+ ** If there is not currently a writer, then BTS_PENDING must
4956349598
** be zero already. So this next line is harmless in that case.
4956449599
*/
49565
- pBt->isPending = 0;
49600
+ pBt->btsFlags &= ~BTS_PENDING;
4956649601
}
4956749602
}
4956849603
4956949604
/*
4957049605
** This function changes all write-locks held by Btree p into read-locks.
@@ -49572,12 +49607,11 @@
4957249607
static void downgradeAllSharedCacheTableLocks(Btree *p){
4957349608
BtShared *pBt = p->pBt;
4957449609
if( pBt->pWriter==p ){
4957549610
BtLock *pLock;
4957649611
pBt->pWriter = 0;
49577
- pBt->isExclusive = 0;
49578
- pBt->isPending = 0;
49612
+ pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
4957949613
for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
4958049614
assert( pLock->eLock==READ_LOCK || pLock->pBtree==p );
4958149615
pLock->eLock = READ_LOCK;
4958249616
}
4958349617
}
@@ -50431,11 +50465,11 @@
5043150465
assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
5043250466
assert( (start + size) <= (int)pPage->pBt->usableSize );
5043350467
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5043450468
assert( size>=0 ); /* Minimum cell size is 4 */
5043550469
50436
- if( pPage->pBt->secureDelete ){
50470
+ if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
5043750471
/* Overwrite deleted information with zeros when the secure_delete
5043850472
** option is enabled */
5043950473
memset(&data[start], 0, size);
5044050474
}
5044150475
@@ -50534,10 +50568,11 @@
5053450568
pPage->maxLocal = pBt->maxLocal;
5053550569
pPage->minLocal = pBt->minLocal;
5053650570
}else{
5053750571
return SQLITE_CORRUPT_BKPT;
5053850572
}
50573
+ pPage->max1bytePayload = pBt->max1bytePayload;
5053950574
return SQLITE_OK;
5054050575
}
5054150576
5054250577
/*
5054350578
** Initialize the auxiliary information for a disk block.
@@ -50669,11 +50704,11 @@
5066950704
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
5067050705
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
5067150706
assert( sqlite3PagerGetData(pPage->pDbPage) == data );
5067250707
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5067350708
assert( sqlite3_mutex_held(pBt->mutex) );
50674
- if( pBt->secureDelete ){
50709
+ if( pBt->btsFlags & BTS_SECURE_DELETE ){
5067550710
memset(&data[hdr], 0, pBt->usableSize - hdr);
5067650711
}
5067750712
data[hdr] = (char)flags;
5067850713
first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
5067950714
memset(&data[hdr+1], 0, 4);
@@ -51022,13 +51057,13 @@
5102251057
sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
5102351058
p->pBt = pBt;
5102451059
5102551060
pBt->pCursor = 0;
5102651061
pBt->pPage1 = 0;
51027
- pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager);
51062
+ if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
5102851063
#ifdef SQLITE_SECURE_DELETE
51029
- pBt->secureDelete = 1;
51064
+ pBt->btsFlags |= BTS_SECURE_DELETE;
5103051065
#endif
5103151066
pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
5103251067
if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
5103351068
|| ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
5103451069
pBt->pageSize = 0;
@@ -51045,11 +51080,11 @@
5104551080
}
5104651081
#endif
5104751082
nReserve = 0;
5104851083
}else{
5104951084
nReserve = zDbHeader[20];
51050
- pBt->pageSizeFixed = 1;
51085
+ pBt->btsFlags |= BTS_PAGESIZE_FIXED;
5105151086
#ifndef SQLITE_OMIT_AUTOVACUUM
5105251087
pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
5105351088
pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
5105451089
#endif
5105551090
}
@@ -51333,19 +51368,19 @@
5133351368
** at the beginning of a page.
5133451369
**
5133551370
** If parameter nReserve is less than zero, then the number of reserved
5133651371
** bytes per page is left unchanged.
5133751372
**
51338
-** If the iFix!=0 then the pageSizeFixed flag is set so that the page size
51373
+** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
5133951374
** and autovacuum mode can no longer be changed.
5134051375
*/
5134151376
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
5134251377
int rc = SQLITE_OK;
5134351378
BtShared *pBt = p->pBt;
5134451379
assert( nReserve>=-1 && nReserve<=255 );
5134551380
sqlite3BtreeEnter(p);
51346
- if( pBt->pageSizeFixed ){
51381
+ if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
5134751382
sqlite3BtreeLeave(p);
5134851383
return SQLITE_READONLY;
5134951384
}
5135051385
if( nReserve<0 ){
5135151386
nReserve = pBt->pageSize - pBt->usableSize;
@@ -51358,11 +51393,11 @@
5135851393
pBt->pageSize = (u32)pageSize;
5135951394
freeTempSpace(pBt);
5136051395
}
5136151396
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
5136251397
pBt->usableSize = pBt->pageSize - (u16)nReserve;
51363
- if( iFix ) pBt->pageSizeFixed = 1;
51398
+ if( iFix ) pBt->btsFlags |= BTS_PAGESIZE_FIXED;
5136451399
sqlite3BtreeLeave(p);
5136551400
return rc;
5136651401
}
5136751402
5136851403
/*
@@ -51398,22 +51433,23 @@
5139851433
sqlite3BtreeLeave(p);
5139951434
return n;
5140051435
}
5140151436
5140251437
/*
51403
-** Set the secureDelete flag if newFlag is 0 or 1. If newFlag is -1,
51404
-** then make no changes. Always return the value of the secureDelete
51438
+** Set the BTS_SECURE_DELETE flag if newFlag is 0 or 1. If newFlag is -1,
51439
+** then make no changes. Always return the value of the BTS_SECURE_DELETE
5140551440
** setting after the change.
5140651441
*/
5140751442
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
5140851443
int b;
5140951444
if( p==0 ) return 0;
5141051445
sqlite3BtreeEnter(p);
5141151446
if( newFlag>=0 ){
51412
- p->pBt->secureDelete = (newFlag!=0) ? 1 : 0;
51447
+ p->pBt->btsFlags &= ~BTS_SECURE_DELETE;
51448
+ if( newFlag ) p->pBt->btsFlags |= BTS_SECURE_DELETE;
5141351449
}
51414
- b = p->pBt->secureDelete;
51450
+ b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
5141551451
sqlite3BtreeLeave(p);
5141651452
return b;
5141751453
}
5141851454
#endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
5141951455
@@ -51430,11 +51466,11 @@
5143051466
BtShared *pBt = p->pBt;
5143151467
int rc = SQLITE_OK;
5143251468
u8 av = (u8)autoVacuum;
5143351469
5143451470
sqlite3BtreeEnter(p);
51435
- if( pBt->pageSizeFixed && (av ?1:0)!=pBt->autoVacuum ){
51471
+ if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
5143651472
rc = SQLITE_READONLY;
5143751473
}else{
5143851474
pBt->autoVacuum = av ?1:0;
5143951475
pBt->incrVacuum = av==2 ?1:0;
5144051476
}
@@ -51504,18 +51540,18 @@
5150451540
goto page1_init_failed;
5150551541
}
5150651542
5150751543
#ifdef SQLITE_OMIT_WAL
5150851544
if( page1[18]>1 ){
51509
- pBt->readOnly = 1;
51545
+ pBt->btsFlags |= BTS_READ_ONLY;
5151051546
}
5151151547
if( page1[19]>1 ){
5151251548
goto page1_init_failed;
5151351549
}
5151451550
#else
5151551551
if( page1[18]>2 ){
51516
- pBt->readOnly = 1;
51552
+ pBt->btsFlags |= BTS_READ_ONLY;
5151751553
}
5151851554
if( page1[19]>2 ){
5151951555
goto page1_init_failed;
5152051556
}
5152151557
@@ -51525,11 +51561,11 @@
5152551561
** The caller detects this and calls this function again. This is
5152651562
** required as the version of page 1 currently in the page1 buffer
5152751563
** may not be the latest version - there may be a newer one in the log
5152851564
** file.
5152951565
*/
51530
- if( page1[19]==2 && pBt->doNotUseWAL==0 ){
51566
+ if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
5153151567
int isOpen = 0;
5153251568
rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
5153351569
if( rc!=SQLITE_OK ){
5153451570
goto page1_init_failed;
5153551571
}else if( isOpen==0 ){
@@ -51602,10 +51638,15 @@
5160251638
*/
5160351639
pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
5160451640
pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
5160551641
pBt->maxLeaf = (u16)(pBt->usableSize - 35);
5160651642
pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
51643
+ if( pBt->maxLocal>127 ){
51644
+ pBt->max1bytePayload = 127;
51645
+ }else{
51646
+ pBt->max1bytePayload = (u8)pBt->maxLocal;
51647
+ }
5160751648
assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
5160851649
pBt->pPage1 = pPage1;
5160951650
pBt->nPage = nPage;
5161051651
return SQLITE_OK;
5161151652
@@ -51665,11 +51706,11 @@
5166551706
data[21] = 64;
5166651707
data[22] = 32;
5166751708
data[23] = 32;
5166851709
memset(&data[24], 0, 100-24);
5166951710
zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
51670
- pBt->pageSizeFixed = 1;
51711
+ pBt->btsFlags |= BTS_PAGESIZE_FIXED;
5167151712
#ifndef SQLITE_OMIT_AUTOVACUUM
5167251713
assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
5167351714
assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
5167451715
put4byte(&data[36 + 4*4], pBt->autoVacuum);
5167551716
put4byte(&data[36 + 7*4], pBt->incrVacuum);
@@ -51729,21 +51770,23 @@
5172951770
if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
5173051771
goto trans_begun;
5173151772
}
5173251773
5173351774
/* Write transactions are not possible on a read-only database */
51734
- if( pBt->readOnly && wrflag ){
51775
+ if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
5173551776
rc = SQLITE_READONLY;
5173651777
goto trans_begun;
5173751778
}
5173851779
5173951780
#ifndef SQLITE_OMIT_SHARED_CACHE
5174051781
/* If another database handle has already opened a write transaction
5174151782
** on this shared-btree structure and a second write transaction is
5174251783
** requested, return SQLITE_LOCKED.
5174351784
*/
51744
- if( (wrflag && pBt->inTransaction==TRANS_WRITE) || pBt->isPending ){
51785
+ if( (wrflag && pBt->inTransaction==TRANS_WRITE)
51786
+ || (pBt->btsFlags & BTS_PENDING)!=0
51787
+ ){
5174551788
pBlock = pBt->pWriter->db;
5174651789
}else if( wrflag>1 ){
5174751790
BtLock *pIter;
5174851791
for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
5174951792
if( pIter->pBtree!=p ){
@@ -51763,11 +51806,12 @@
5176351806
** page 1. So if some other shared-cache client already has a write-lock
5176451807
** on page 1, the transaction cannot be opened. */
5176551808
rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
5176651809
if( SQLITE_OK!=rc ) goto trans_begun;
5176751810
51768
- pBt->initiallyEmpty = (u8)(pBt->nPage==0);
51811
+ pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
51812
+ if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
5176951813
do {
5177051814
/* Call lockBtree() until either pBt->pPage1 is populated or
5177151815
** lockBtree() returns something other than SQLITE_OK. lockBtree()
5177251816
** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
5177351817
** reading page 1 it discovers that the page-size of the database
@@ -51775,11 +51819,11 @@
5177551819
** pBt->pageSize to the page-size of the file on disk.
5177651820
*/
5177751821
while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
5177851822
5177951823
if( rc==SQLITE_OK && wrflag ){
51780
- if( pBt->readOnly ){
51824
+ if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
5178151825
rc = SQLITE_READONLY;
5178251826
}else{
5178351827
rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
5178451828
if( rc==SQLITE_OK ){
5178551829
rc = newDatabase(pBt);
@@ -51812,11 +51856,12 @@
5181251856
if( wrflag ){
5181351857
MemPage *pPage1 = pBt->pPage1;
5181451858
#ifndef SQLITE_OMIT_SHARED_CACHE
5181551859
assert( !pBt->pWriter );
5181651860
pBt->pWriter = p;
51817
- pBt->isExclusive = (u8)(wrflag>1);
51861
+ pBt->btsFlags &= ~BTS_EXCLUSIVE;
51862
+ if( wrflag>1 ) pBt->btsFlags |= BTS_EXCLUSIVE;
5181851863
#endif
5181951864
5182051865
/* If the db-size header field is incorrect (as it may be if an old
5182151866
** client has been writing the database file), update it now. Doing
5182251867
** this sooner rather than later means the database size can safely
@@ -52541,11 +52586,11 @@
5254152586
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p, int iStatement){
5254252587
int rc;
5254352588
BtShared *pBt = p->pBt;
5254452589
sqlite3BtreeEnter(p);
5254552590
assert( p->inTrans==TRANS_WRITE );
52546
- assert( pBt->readOnly==0 );
52591
+ assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
5254752592
assert( iStatement>0 );
5254852593
assert( iStatement>p->db->nSavepoint );
5254952594
assert( pBt->inTransaction==TRANS_WRITE );
5255052595
/* At the pager level, a statement transaction is a savepoint with
5255152596
** an index greater than all savepoints created explicitly using
@@ -52576,11 +52621,13 @@
5257652621
assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
5257752622
assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
5257852623
sqlite3BtreeEnter(p);
5257952624
rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
5258052625
if( rc==SQLITE_OK ){
52581
- if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
52626
+ if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
52627
+ pBt->nPage = 0;
52628
+ }
5258252629
rc = newDatabase(pBt);
5258352630
pBt->nPage = get4byte(28 + pBt->pPage1->aData);
5258452631
5258552632
/* The database size was written into the offset 28 of the header
5258652633
** when the transaction started, so we know that the value at offset
@@ -52646,11 +52693,11 @@
5264652693
/* Assert that the caller has opened the required transaction. */
5264752694
assert( p->inTrans>TRANS_NONE );
5264852695
assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
5264952696
assert( pBt->pPage1 && pBt->pPage1->aData );
5265052697
52651
- if( NEVER(wrFlag && pBt->readOnly) ){
52698
+ if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
5265252699
return SQLITE_READONLY;
5265352700
}
5265452701
if( iTable==1 && btreePagecount(pBt)==0 ){
5265552702
assert( wrFlag==0 );
5265652703
iTable = 0;
@@ -53726,22 +53773,21 @@
5372653773
** the entire cell by checking for the cases where the record is
5372753774
** stored entirely within the b-tree page by inspecting the first
5372853775
** 2 bytes of the cell.
5372953776
*/
5373053777
int nCell = pCell[0];
53731
- if( !(nCell & 0x80)
53732
- && nCell<=pPage->maxLocal
53733
- && (pCell+nCell+1)<=pPage->aDataEnd
53778
+ if( nCell<=pPage->max1bytePayload
53779
+ /* && (pCell+nCell)<pPage->aDataEnd */
5373453780
){
5373553781
/* This branch runs if the record-size field of the cell is a
5373653782
** single byte varint and the record fits entirely on the main
5373753783
** b-tree page. */
5373853784
testcase( pCell+nCell+1==pPage->aDataEnd );
5373953785
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
5374053786
}else if( !(pCell[1] & 0x80)
5374153787
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
53742
- && (pCell+nCell+2)<=pPage->aDataEnd
53788
+ /* && (pCell+nCell+2)<=pPage->aDataEnd */
5374353789
){
5374453790
/* The record-size field is a 2 byte varint and the record
5374553791
** fits entirely on the main b-tree page. */
5374653792
testcase( pCell+nCell+2==pPage->aDataEnd );
5374753793
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54283,11 +54329,11 @@
5428354329
rc = sqlite3PagerWrite(pPage1->pDbPage);
5428454330
if( rc ) goto freepage_out;
5428554331
nFree = get4byte(&pPage1->aData[36]);
5428654332
put4byte(&pPage1->aData[36], nFree+1);
5428754333
54288
- if( pBt->secureDelete ){
54334
+ if( pBt->btsFlags & BTS_SECURE_DELETE ){
5428954335
/* If the secure_delete option is enabled, then
5429054336
** always fully overwrite deleted information with zeros.
5429154337
*/
5429254338
if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
5429354339
|| ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
@@ -54344,11 +54390,11 @@
5434454390
*/
5434554391
rc = sqlite3PagerWrite(pTrunk->pDbPage);
5434654392
if( rc==SQLITE_OK ){
5434754393
put4byte(&pTrunk->aData[4], nLeaf+1);
5434854394
put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
54349
- if( pPage && !pBt->secureDelete ){
54395
+ if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
5435054396
sqlite3PagerDontWrite(pPage->pDbPage);
5435154397
}
5435254398
rc = btreeSetHasContent(pBt, iPage);
5435354399
}
5435454400
TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
@@ -55185,11 +55231,11 @@
5518555231
** But not if we are in secure-delete mode. In secure-delete mode,
5518655232
** the dropCell() routine will overwrite the entire cell with zeroes.
5518755233
** In this case, temporarily copy the cell into the aOvflSpace[]
5518855234
** buffer. It will be copied out again as soon as the aSpace[] buffer
5518955235
** is allocated. */
55190
- if( pBt->secureDelete ){
55236
+ if( pBt->btsFlags & BTS_SECURE_DELETE ){
5519155237
int iOff;
5519255238
5519355239
iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
5519455240
if( (iOff+szNew[i])>(int)pBt->usableSize ){
5519555241
rc = SQLITE_CORRUPT_BKPT;
@@ -55927,11 +55973,12 @@
5592755973
assert( pCur->skipNext!=SQLITE_OK );
5592855974
return pCur->skipNext;
5592955975
}
5593055976
5593155977
assert( cursorHoldsMutex(pCur) );
55932
- assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE && !pBt->readOnly );
55978
+ assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE
55979
+ && (pBt->btsFlags & BTS_READ_ONLY)==0 );
5593355980
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
5593455981
5593555982
/* Assert that the caller has been consistent. If this cursor was opened
5593655983
** expecting an index b-tree, then the caller should be inserting blob
5593755984
** keys with no associated data. If the cursor was opened expecting an
@@ -56056,11 +56103,11 @@
5605656103
int iCellIdx; /* Index of cell to delete */
5605756104
int iCellDepth; /* Depth of node containing pCell */
5605856105
5605956106
assert( cursorHoldsMutex(pCur) );
5606056107
assert( pBt->inTransaction==TRANS_WRITE );
56061
- assert( !pBt->readOnly );
56108
+ assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
5606256109
assert( pCur->wrFlag );
5606356110
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
5606456111
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
5606556112
5606656113
if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell)
@@ -56177,11 +56224,11 @@
5617756224
int rc;
5617856225
int ptfFlags; /* Page-type flage for the root page of new table */
5617956226
5618056227
assert( sqlite3BtreeHoldsMutex(p) );
5618156228
assert( pBt->inTransaction==TRANS_WRITE );
56182
- assert( !pBt->readOnly );
56229
+ assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
5618356230
5618456231
#ifdef SQLITE_OMIT_AUTOVACUUM
5618556232
rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
5618656233
if( rc ){
5618756234
return rc;
@@ -56551,11 +56598,13 @@
5655156598
*pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
5655256599
5655356600
/* If auto-vacuum is disabled in this build and this is an auto-vacuum
5655456601
** database, mark the database as read-only. */
5655556602
#ifdef SQLITE_OMIT_AUTOVACUUM
56556
- if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1;
56603
+ if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
56604
+ pBt->btsFlags |= BTS_READ_ONLY;
56605
+ }
5655756606
#endif
5655856607
5655956608
sqlite3BtreeLeave(p);
5656056609
}
5656156610
@@ -57351,11 +57400,12 @@
5735157400
** (e) the cursor points at a valid row of an intKey table.
5735257401
*/
5735357402
if( !pCsr->wrFlag ){
5735457403
return SQLITE_READONLY;
5735557404
}
57356
- assert( !pCsr->pBt->readOnly && pCsr->pBt->inTransaction==TRANS_WRITE );
57405
+ assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
57406
+ && pCsr->pBt->inTransaction==TRANS_WRITE );
5735757407
assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
5735857408
assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
5735957409
assert( pCsr->apPage[pCsr->iPage]->intKey );
5736057410
5736157411
return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
@@ -57391,11 +57441,12 @@
5739157441
assert( iVersion==1 || iVersion==2 );
5739257442
5739357443
/* If setting the version fields to 1, do not automatically open the
5739457444
** WAL connection, even if the version fields are currently set to 2.
5739557445
*/
57396
- pBt->doNotUseWAL = (u8)(iVersion==1);
57446
+ pBt->btsFlags &= ~BTS_NO_WAL;
57447
+ if( iVersion==1 ) pBt->btsFlags |= BTS_NO_WAL;
5739757448
5739857449
rc = sqlite3BtreeBeginTrans(pBtree, 0);
5739957450
if( rc==SQLITE_OK ){
5740057451
u8 *aData = pBt->pPage1->aData;
5740157452
if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){
@@ -57408,11 +57459,11 @@
5740857459
}
5740957460
}
5741057461
}
5741157462
}
5741257463
57413
- pBt->doNotUseWAL = 0;
57464
+ pBt->btsFlags &= ~BTS_NO_WAL;
5741457465
return rc;
5741557466
}
5741657467
5741757468
/************** End of btree.c ***********************************************/
5741857469
/************** Begin file backup.c ******************************************/
@@ -58092,13 +58143,13 @@
5809258143
5809358144
assert( sqlite3BtreeIsInTrans(pTo) );
5809458145
pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
5809558146
if( pFd->pMethods ){
5809658147
i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
58097
- sqlite3BeginBenignMalloc();
58098
- sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
58099
- sqlite3EndBenignMalloc();
58148
+ rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
58149
+ if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
58150
+ if( rc ) goto copy_finished;
5810058151
}
5810158152
5810258153
/* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
5810358154
** to 0. This is used by the implementations of sqlite3_backup_step()
5810458155
** and sqlite3_backup_finish() to detect that they are being called
@@ -58119,16 +58170,17 @@
5811958170
*/
5812058171
sqlite3_backup_step(&b, 0x7FFFFFFF);
5812158172
assert( b.rc!=SQLITE_OK );
5812258173
rc = sqlite3_backup_finish(&b);
5812358174
if( rc==SQLITE_OK ){
58124
- pTo->pBt->pageSizeFixed = 0;
58175
+ pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
5812558176
}else{
5812658177
sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
5812758178
}
5812858179
5812958180
assert( sqlite3BtreeIsInTrans(pTo)==0 );
58181
+copy_finished:
5813058182
sqlite3BtreeLeave(pFrom);
5813158183
sqlite3BtreeLeave(pTo);
5813258184
return rc;
5813358185
}
5813458186
#endif /* SQLITE_OMIT_VACUUM */
@@ -58151,16 +58203,10 @@
5815158203
** stores a single value in the VDBE. Mem is an opaque structure visible
5815258204
** only within the VDBE. Interface routines refer to a Mem using the
5815358205
** name sqlite_value
5815458206
*/
5815558207
58156
-/*
58157
-** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
58158
-** P if required.
58159
-*/
58160
-#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
58161
-
5816258208
/*
5816358209
** If pMem is an object with a valid string representation, this routine
5816458210
** ensures the internal encoding for the string representation is
5816558211
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
5816658212
**
@@ -58256,11 +58302,11 @@
5825658302
*/
5825758303
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
5825858304
int f;
5825958305
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
5826058306
assert( (pMem->flags&MEM_RowSet)==0 );
58261
- expandBlob(pMem);
58307
+ ExpandBlob(pMem);
5826258308
f = pMem->flags;
5826358309
if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){
5826458310
if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
5826558311
return SQLITE_NOMEM;
5826658312
}
@@ -59093,11 +59139,11 @@
5909359139
if( pVal->flags&MEM_Null ){
5909459140
return 0;
5909559141
}
5909659142
assert( (MEM_Blob>>3) == MEM_Str );
5909759143
pVal->flags |= (pVal->flags & MEM_Blob)>>3;
59098
- expandBlob(pVal);
59144
+ ExpandBlob(pVal);
5909959145
if( pVal->flags&MEM_Str ){
5910059146
sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);
5910159147
if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
5910259148
assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
5910359149
if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
@@ -64300,16 +64346,10 @@
6430064346
*/
6430164347
#define Deephemeralize(P) \
6430264348
if( ((P)->flags&MEM_Ephem)!=0 \
6430364349
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6430464350
64305
-/*
64306
-** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
64307
-** P if required.
64308
-*/
64309
-#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
64310
-
6431164351
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
6431264352
#ifdef SQLITE_OMIT_MERGE_SORT
6431364353
# define isSorter(x) 0
6431464354
#else
6431564355
# define isSorter(x) ((x)->pSorter!=0)
@@ -92659,11 +92699,11 @@
9265992699
if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
9266092700
if( !zRight ){
9266192701
Pager *pPager = sqlite3BtreePager(pDb->pBt);
9266292702
char *proxy_file_path = NULL;
9266392703
sqlite3_file *pFile = sqlite3PagerFile(pPager);
92664
- sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
92704
+ sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
9266592705
&proxy_file_path);
9266692706
9266792707
if( proxy_file_path ){
9266892708
sqlite3VdbeSetNumCols(v, 1);
9266992709
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
@@ -123271,11 +123311,11 @@
123271123311
typedef struct porter_tokenizer {
123272123312
sqlite3_tokenizer base; /* Base class */
123273123313
} porter_tokenizer;
123274123314
123275123315
/*
123276
-** Class derived from sqlit3_tokenizer_cursor
123316
+** Class derived from sqlite3_tokenizer_cursor
123277123317
*/
123278123318
typedef struct porter_tokenizer_cursor {
123279123319
sqlite3_tokenizer_cursor base;
123280123320
const char *zInput; /* input we are tokenizing */
123281123321
int nInput; /* size of the input */
123282123322
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -657,11 +657,11 @@
657 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
658 ** [sqlite_version()] and [sqlite_source_id()].
659 */
660 #define SQLITE_VERSION "3.7.10"
661 #define SQLITE_VERSION_NUMBER 3007010
662 #define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983"
663
664 /*
665 ** CAPI3REF: Run-Time Library Version Numbers
666 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
667 **
@@ -9396,17 +9396,19 @@
9396 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
9397 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
9398 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
9399 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
9400 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
 
9401 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
9402 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
9403 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
9404 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
9405 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
9406 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
9407 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
 
9408
9409 /*
9410 ** Functions for accessing sqlite3_vfs methods
9411 */
9412 SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
@@ -13244,12 +13246,14 @@
13244 #endif
13245 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
13246
13247 #ifndef SQLITE_OMIT_INCRBLOB
13248 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
 
13249 #else
13250 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
 
13251 #endif
13252
13253 #endif /* !defined(_VDBEINT_H_) */
13254
13255 /************** End of vdbeInt.h *********************************************/
@@ -14715,14 +14719,27 @@
14715 }
14716 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){
14717 DO_OS_MALLOC_TEST(id);
14718 return id->pMethods->xCheckReservedLock(id, pResOut);
14719 }
 
 
 
 
 
 
 
 
 
14720 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
14721 DO_OS_MALLOC_TEST(id);
14722 return id->pMethods->xFileControl(id, op, pArg);
14723 }
 
 
 
 
14724 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){
14725 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
14726 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
14727 }
14728 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
@@ -14769,10 +14786,11 @@
14769 assert( rc==SQLITE_OK || pFile->pMethods==0 );
14770 return rc;
14771 }
14772 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
14773 DO_OS_MALLOC_TEST(0);
 
14774 return pVfs->xDelete(pVfs, zPath, dirSync);
14775 }
14776 SQLITE_PRIVATE int sqlite3OsAccess(
14777 sqlite3_vfs *pVfs,
14778 const char *zPath,
@@ -22113,31 +22131,26 @@
22113 ** characters of the original suffix.
22114 **
22115 ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
22116 ** do the suffix shortening regardless of URI parameter.
22117 **
22118 ** Assume that zBaseFilename contains two \000 terminator bytes (so that
22119 ** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both
22120 ** zero terminator bytes into the end of the revised name.
22121 **
22122 ** Examples:
22123 **
22124 ** test.db-journal => test.nal
22125 ** test.db-wal => test.wal
22126 ** test.db-shm => test.shm
22127 ** test.db-mj7f3319fa => test.9fa
22128 */
22129 SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
22130 assert( zBaseFilename[strlen(zBaseFilename)+1]==0 );
22131 #if SQLITE_ENABLE_8_3_NAMES<2
22132 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) )
22133 #endif
22134 {
22135 int i, sz;
22136 sz = sqlite3Strlen30(z);
22137 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
22138 if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5);
22139 }
22140 }
22141 #endif
22142
22143 /************** End of util.c ************************************************/
@@ -24941,11 +24954,10 @@
24941 #endif
24942 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
24943 unsigned fsFlags; /* cached details from statfs() */
24944 #endif
24945 #if OS_VXWORKS
24946 int isDelete; /* Delete on close if true */
24947 struct vxworksFileId *pId; /* Unique file ID */
24948 #endif
24949 #ifndef NDEBUG
24950 /* The next group of variables are used to track whether or not the
24951 ** transaction counter in bytes 24-27 of database files are updated
@@ -24976,10 +24988,13 @@
24976 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
24977 #else
24978 # define UNIXFILE_DIRSYNC 0x00
24979 #endif
24980 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
 
 
 
24981
24982 /*
24983 ** Include code that is common to all os_*.c files
24984 */
24985 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -26689,11 +26704,11 @@
26689 robust_close(pFile, pFile->h, __LINE__);
26690 pFile->h = -1;
26691 }
26692 #if OS_VXWORKS
26693 if( pFile->pId ){
26694 if( pFile->isDelete ){
26695 osUnlink(pFile->pId->zCanonicalName);
26696 }
26697 vxworksReleaseFileId(pFile->pId);
26698 pFile->pId = 0;
26699 }
@@ -28796,11 +28811,11 @@
28796 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
28797 if( pShmNode==0 ){
28798 rc = SQLITE_NOMEM;
28799 goto shm_open_err;
28800 }
28801 memset(pShmNode, 0, sizeof(*pShmNode));
28802 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
28803 #ifdef SQLITE_SHM_DIRECTORY
28804 sqlite3_snprintf(nShmFilename, zShmFilename,
28805 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
28806 (u32)sStat.st_ino, (u32)sStat.st_dev);
@@ -29479,28 +29494,20 @@
29479 ** Initialize the contents of the unixFile structure pointed to by pId.
29480 */
29481 static int fillInUnixFile(
29482 sqlite3_vfs *pVfs, /* Pointer to vfs object */
29483 int h, /* Open file descriptor of file being opened */
29484 int syncDir, /* True to sync directory on first sync */
29485 sqlite3_file *pId, /* Write to the unixFile structure here */
29486 const char *zFilename, /* Name of the file being opened */
29487 int noLock, /* Omit locking if true */
29488 int isDelete, /* Delete on close if true */
29489 int isReadOnly /* True if the file is opened read-only */
29490 ){
29491 const sqlite3_io_methods *pLockingStyle;
29492 unixFile *pNew = (unixFile *)pId;
29493 int rc = SQLITE_OK;
29494
29495 assert( pNew->pInode==NULL );
29496
29497 /* Parameter isDelete is only used on vxworks. Express this explicitly
29498 ** here to prevent compiler warnings about unused parameters.
29499 */
29500 UNUSED_PARAMETER(isDelete);
29501
29502 /* Usually the path zFilename should not be a relative pathname. The
29503 ** exception is when opening the proxy "conch" file in builds that
29504 ** include the special Apple locking styles.
29505 */
29506 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29509,39 +29516,34 @@
29509 #else
29510 assert( zFilename==0 || zFilename[0]=='/' );
29511 #endif
29512
29513 /* No locking occurs in temporary files */
29514 assert( zFilename!=0 || noLock );
29515
29516 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
29517 pNew->h = h;
29518 pNew->pVfs = pVfs;
29519 pNew->zPath = zFilename;
29520 pNew->ctrlFlags = 0;
29521 if( sqlite3_uri_boolean(zFilename, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
 
29522 pNew->ctrlFlags |= UNIXFILE_PSOW;
29523 }
29524 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
29525 pNew->ctrlFlags |= UNIXFILE_EXCL;
29526 }
29527 if( isReadOnly ){
29528 pNew->ctrlFlags |= UNIXFILE_RDONLY;
29529 }
29530 if( syncDir ){
29531 pNew->ctrlFlags |= UNIXFILE_DIRSYNC;
29532 }
29533
29534 #if OS_VXWORKS
29535 pNew->pId = vxworksFindFileId(zFilename);
29536 if( pNew->pId==0 ){
29537 noLock = 1;
29538 rc = SQLITE_NOMEM;
29539 }
29540 #endif
29541
29542 if( noLock ){
29543 pLockingStyle = &nolockIoMethods;
29544 }else{
29545 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
29546 #if SQLITE_ENABLE_LOCKING_STYLE
29547 /* Cache zFilename in the locking context (AFP and dotlock override) for
@@ -29658,11 +29660,11 @@
29658 if( h>=0 ) robust_close(pNew, h, __LINE__);
29659 h = -1;
29660 osUnlink(zFilename);
29661 isDelete = 0;
29662 }
29663 pNew->isDelete = isDelete;
29664 #endif
29665 if( rc!=SQLITE_OK ){
29666 if( h>=0 ) robust_close(pNew, h, __LINE__);
29667 }else{
29668 pNew->pMethod = pLockingStyle;
@@ -29723,22 +29725,23 @@
29723 if( zDir==0 ) zDir = ".";
29724
29725 /* Check that the output buffer is large enough for the temporary file
29726 ** name. If it is not, return SQLITE_ERROR.
29727 */
29728 if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= (size_t)nBuf ){
29729 return SQLITE_ERROR;
29730 }
29731
29732 do{
29733 sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
29734 j = (int)strlen(zBuf);
29735 sqlite3_randomness(15, &zBuf[j]);
29736 for(i=0; i<15; i++, j++){
29737 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
29738 }
29739 zBuf[j] = 0;
 
29740 }while( osAccess(zBuf,0)==0 );
29741 return SQLITE_OK;
29742 }
29743
29744 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
@@ -29913,10 +29916,11 @@
29913 int fd = -1; /* File descriptor returned by open() */
29914 int openFlags = 0; /* Flags to pass to open() */
29915 int eType = flags&0xFFFFFF00; /* Type of file to open */
29916 int noLock; /* True to omit locking primitives */
29917 int rc = SQLITE_OK; /* Function Return Code */
 
29918
29919 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
29920 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
29921 int isCreate = (flags & SQLITE_OPEN_CREATE);
29922 int isReadonly = (flags & SQLITE_OPEN_READONLY);
@@ -29939,11 +29943,11 @@
29939 ));
29940
29941 /* If argument zPath is a NULL pointer, this function is required to open
29942 ** a temporary file. Use this buffer to store the file name in.
29943 */
29944 char zTmpname[MAX_PATHNAME+1];
29945 const char *zName = zPath;
29946
29947 /* Check the following statements are true:
29948 **
29949 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
@@ -29982,18 +29986,28 @@
29982 if( !pUnused ){
29983 return SQLITE_NOMEM;
29984 }
29985 }
29986 p->pUnused = pUnused;
 
 
 
 
 
 
29987 }else if( !zName ){
29988 /* If zName is NULL, the upper layer is requesting a temp file. */
29989 assert(isDelete && !syncDir);
29990 rc = unixGetTempname(MAX_PATHNAME+1, zTmpname);
29991 if( rc!=SQLITE_OK ){
29992 return rc;
29993 }
29994 zName = zTmpname;
 
 
 
 
29995 }
29996
29997 /* Determine the value of the flags parameter passed to POSIX function
29998 ** open(). These must be calculated even if open() is not called, as
29999 ** they may be stored as part of the file handle and used by the
@@ -30066,11 +30080,18 @@
30066 }
30067 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
30068 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
30069 }
30070 #endif
30071
 
 
 
 
 
 
 
30072 #if SQLITE_ENABLE_LOCKING_STYLE
30073 #if SQLITE_PREFER_PROXY_LOCKING
30074 isAutoProxy = 1;
30075 #endif
30076 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){
@@ -30096,12 +30117,11 @@
30096 goto open_finished;
30097 }
30098 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
30099 }
30100 if( useProxy ){
30101 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
30102 isDelete, isReadonly);
30103 if( rc==SQLITE_OK ){
30104 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
30105 if( rc!=SQLITE_OK ){
30106 /* Use unixClose to clean up the resources added in fillInUnixFile
30107 ** and clear all the structure's references. Specifically,
@@ -30114,12 +30134,12 @@
30114 goto open_finished;
30115 }
30116 }
30117 #endif
30118
30119 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
30120 isDelete, isReadonly);
30121 open_finished:
30122 if( rc!=SQLITE_OK ){
30123 sqlite3_free(p->pUnused);
30124 }
30125 return rc;
@@ -30140,11 +30160,11 @@
30140 SimulateIOError(return SQLITE_IOERR_DELETE);
30141 if( osUnlink(zPath)==(-1) && errno!=ENOENT ){
30142 return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
30143 }
30144 #ifndef SQLITE_DISABLE_DIRSYNC
30145 if( dirSync ){
30146 int fd;
30147 rc = osOpenDirectory(zPath, &fd);
30148 if( rc==SQLITE_OK ){
30149 #if OS_VXWORKS
30150 if( fsync(fd)==-1 )
@@ -30786,11 +30806,11 @@
30786 dummyVfs.zName = "dummy";
30787 pUnused->fd = fd;
30788 pUnused->flags = openFlags;
30789 pNew->pUnused = pUnused;
30790
30791 rc = fillInUnixFile(&dummyVfs, fd, 0, (sqlite3_file*)pNew, path, 0, 0, 0);
30792 if( rc==SQLITE_OK ){
30793 *ppFile = pNew;
30794 return SQLITE_OK;
30795 }
30796 end_create_proxy:
@@ -34388,11 +34408,13 @@
34388 winClose((sqlite3_file *)&p->hFile);
34389 SimulateIOErrorBenign(0);
34390 }
34391 if( deleteFlag ){
34392 SimulateIOErrorBenign(1);
 
34393 winDelete(pVfs, p->zFilename, 0);
 
34394 SimulateIOErrorBenign(0);
34395 }
34396 *pp = p->pNext;
34397 sqlite3_free(p->aRegion);
34398 sqlite3_free(p);
@@ -34423,16 +34445,16 @@
34423 */
34424 p = sqlite3_malloc( sizeof(*p) );
34425 if( p==0 ) return SQLITE_IOERR_NOMEM;
34426 memset(p, 0, sizeof(*p));
34427 nName = sqlite3Strlen30(pDbFd->zPath);
34428 pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 16 );
34429 if( pNew==0 ){
34430 sqlite3_free(p);
34431 return SQLITE_IOERR_NOMEM;
34432 }
34433 memset(pNew, 0, sizeof(*pNew));
34434 pNew->zFilename = (char*)&pNew[1];
34435 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
34436 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
34437
34438 /* Look to see if there is an existing winShmNode that can be used.
@@ -34464,11 +34486,10 @@
34464 pShmNode->zFilename, /* Name of the file (UTF-8) */
34465 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
34466 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
34467 0);
34468 if( SQLITE_OK!=rc ){
34469 rc = SQLITE_CANTOPEN_BKPT;
34470 goto shm_open_err;
34471 }
34472
34473 /* Check to see if another process is holding the dead-man switch.
34474 ** If not, truncate the file to zero length.
@@ -34887,11 +34908,11 @@
34887 static char zChars[] =
34888 "abcdefghijklmnopqrstuvwxyz"
34889 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34890 "0123456789";
34891 size_t i, j;
34892 char zTempPath[MAX_PATH+1];
34893
34894 /* It's odd to simulate an io-error here, but really this is just
34895 ** using the io-error infrastructure to test that SQLite handles this
34896 ** function failing.
34897 */
@@ -34930,25 +34951,26 @@
34930 }
34931
34932 /* Check that the output buffer is large enough for the temporary file
34933 ** name. If it is not, return SQLITE_ERROR.
34934 */
34935 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
34936 return SQLITE_ERROR;
34937 }
34938
34939 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
34940 zTempPath[i] = 0;
34941
34942 sqlite3_snprintf(nBuf-17, zBuf,
34943 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
34944 j = sqlite3Strlen30(zBuf);
34945 sqlite3_randomness(15, &zBuf[j]);
34946 for(i=0; i<15; i++, j++){
34947 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
34948 }
34949 zBuf[j] = 0;
 
34950
34951 OSTRACE(("TEMP FILENAME: %s\n", zBuf));
34952 return SQLITE_OK;
34953 }
34954
@@ -34977,11 +34999,11 @@
34977 int cnt = 0;
34978
34979 /* If argument zPath is a NULL pointer, this function is required to open
34980 ** a temporary file. Use this buffer to store the file name in.
34981 */
34982 char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
34983
34984 int rc = SQLITE_OK; /* Function Return Code */
34985 #if !defined(NDEBUG) || SQLITE_OS_WINCE
34986 int eType = flags&0xFFFFFF00; /* Type of file to open */
34987 #endif
@@ -35036,16 +35058,23 @@
35036 /* If the second argument to this function is NULL, generate a
35037 ** temporary file name to use
35038 */
35039 if( !zUtf8Name ){
35040 assert(isDelete && !isOpenJournal);
35041 rc = getTempname(MAX_PATH+1, zTmpname);
35042 if( rc!=SQLITE_OK ){
35043 return rc;
35044 }
35045 zUtf8Name = zTmpname;
35046 }
 
 
 
 
 
 
 
35047
35048 /* Convert the filename to the system encoding. */
35049 zConverted = convertUtf8Filename(zUtf8Name);
35050 if( zConverted==0 ){
35051 return SQLITE_IOERR_NOMEM;
@@ -36721,11 +36750,11 @@
36721 ** of.
36722 **
36723 ** Mode 1 uses more memory (since PCache instances are not able to rob
36724 ** unused pages from other PCaches) but it also operates without a mutex,
36725 ** and is therefore often faster. Mode 2 requires a mutex in order to be
36726 ** threadsafe, but is able recycle pages more efficient.
36727 **
36728 ** For mode (1), PGroup.mutex is NULL. For mode (2) there is only a single
36729 ** PGroup which is the pcache1.grp global variable and its mutex is
36730 ** SQLITE_MUTEX_STATIC_LRU.
36731 */
@@ -36747,11 +36776,11 @@
36747 ** opaque sqlite3_pcache* handles.
36748 */
36749 struct PCache1 {
36750 /* Cache configuration parameters. Page size (szPage) and the purgeable
36751 ** flag (bPurgeable) are set when the cache is created. nMax may be
36752 ** modified at any time by a call to the pcache1CacheSize() method.
36753 ** The PGroup mutex must be held when accessing nMax.
36754 */
36755 PGroup *pGroup; /* PGroup this cache belongs to */
36756 int szPage; /* Size of allocated pages in bytes */
36757 int szExtra; /* Size of extra space in bytes */
@@ -37038,11 +37067,11 @@
37038 ** it is desirable to avoid allocating a new page cache entry because
37039 ** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
37040 ** for all page cache needs and we should not need to spill the
37041 ** allocation onto the heap.
37042 **
37043 ** Or, the heap is used for all page cache memory put the heap is
37044 ** under memory pressure, then again it is desirable to avoid
37045 ** allocating a new page cache entry in order to avoid stressing
37046 ** the heap even further.
37047 */
37048 static int pcache1UnderMemoryPressure(PCache1 *pCache){
@@ -37349,11 +37378,11 @@
37349 ** means to try really hard to allocate a new page.
37350 **
37351 ** For a non-purgeable cache (a cache used as the storage for an in-memory
37352 ** database) there is really no difference between createFlag 1 and 2. So
37353 ** the calling function (pcache.c) will never have a createFlag of 1 on
37354 ** a non-purgable cache.
37355 **
37356 ** There are three different approaches to obtaining space for a page,
37357 ** depending on the value of parameter createFlag (which may be 0, 1 or 2).
37358 **
37359 ** 1. Regardless of the value of createFlag, the cache is searched for a
@@ -40743,14 +40772,13 @@
40743 rc = sqlite3OsFileSize(pPager->fd, &currentSize);
40744 newSize = szPage*(i64)nPage;
40745 if( rc==SQLITE_OK && currentSize!=newSize ){
40746 if( currentSize>newSize ){
40747 rc = sqlite3OsTruncate(pPager->fd, newSize);
40748 }else{
40749 char *pTmp = pPager->pTmpSpace;
40750 memset(pTmp, 0, szPage);
40751 testcase( (newSize-szPage) < currentSize );
40752 testcase( (newSize-szPage) == currentSize );
40753 testcase( (newSize-szPage) > currentSize );
40754 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
40755 }
40756 if( rc==SQLITE_OK ){
@@ -41004,14 +41032,15 @@
41004 /* Following a rollback, the database file should be back in its original
41005 ** state prior to the start of the transaction, so invoke the
41006 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
41007 ** assertion that the transaction counter was modified.
41008 */
41009 assert(
41010 pPager->fd->pMethods==0 ||
41011 sqlite3OsFileControl(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0)>=SQLITE_OK
41012 );
 
41013
41014 /* If this playback is happening automatically as a result of an IO or
41015 ** malloc error that occurred after the change-counter was updated but
41016 ** before the transaction was committed, then the change-counter
41017 ** modification may just have been reverted. If this happens in exclusive
@@ -41344,14 +41373,11 @@
41344 int rc = sqlite3OsFileSize(pPager->fd, &n);
41345 if( rc!=SQLITE_OK ){
41346 return rc;
41347 }
41348 }
41349 nPage = (Pgno)(n / pPager->pageSize);
41350 if( nPage==0 && n>0 ){
41351 nPage = 1;
41352 }
41353 }
41354
41355 /* If the current number of pages in the file is greater than the
41356 ** configured maximum pager number, increase the allowed limit so
41357 ** that the file can be read.
@@ -41778,11 +41804,11 @@
41778 if( !pNew ) rc = SQLITE_NOMEM;
41779 }
41780
41781 if( rc==SQLITE_OK ){
41782 pager_reset(pPager);
41783 pPager->dbSize = (Pgno)(nByte/pageSize);
41784 pPager->pageSize = pageSize;
41785 sqlite3PageFree(pPager->pTmpSpace);
41786 pPager->pTmpSpace = pNew;
41787 sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
41788 }
@@ -42286,13 +42312,11 @@
42286 ** file size will be.
42287 */
42288 assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
42289 if( rc==SQLITE_OK && pPager->dbSize>pPager->dbHintSize ){
42290 sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
42291 sqlite3BeginBenignMalloc();
42292 sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
42293 sqlite3EndBenignMalloc();
42294 pPager->dbHintSize = pPager->dbSize;
42295 }
42296
42297 while( rc==SQLITE_OK && pList ){
42298 Pgno pgno = pList->pgno;
@@ -44312,11 +44336,12 @@
44312 }else{
44313 rc = pager_playback(pPager, 0);
44314 }
44315
44316 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
44317 assert( rc==SQLITE_OK || rc==SQLITE_FULL || (rc&0xFF)==SQLITE_IOERR );
 
44318
44319 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
44320 ** cache. So call pager_error() on the way out to make any error persistent.
44321 */
44322 return pager_error(pPager, rc);
@@ -46887,11 +46912,11 @@
46887 */
46888 if( rc==SQLITE_OK ){
46889 i64 nReq = ((i64)mxPage * szPage);
46890 rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
46891 if( rc==SQLITE_OK && nSize<nReq ){
46892 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
46893 }
46894 }
46895
46896 /* Iterate through the contents of the WAL, copying data to the db file. */
46897 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
@@ -47003,11 +47028,13 @@
47003 rc = sqlite3WalCheckpoint(
47004 pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
47005 );
47006 if( rc==SQLITE_OK ){
47007 int bPersist = -1;
47008 sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist);
 
 
47009 if( bPersist!=1 ){
47010 /* Try to delete the WAL file if the checkpoint completed and
47011 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
47012 ** mode (!bPersist) */
47013 isDelete = 1;
@@ -47024,11 +47051,13 @@
47024 }
47025
47026 walIndexClose(pWal, isDelete);
47027 sqlite3OsClose(pWal->pWalFd);
47028 if( isDelete ){
 
47029 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
 
47030 }
47031 WALTRACE(("WAL%p: closed\n", pWal));
47032 sqlite3_free((void *)pWal->apWiData);
47033 sqlite3_free(pWal);
47034 }
@@ -48525,10 +48554,11 @@
48525 u8 intKey; /* True if intkey flag is set */
48526 u8 leaf; /* True if leaf flag is set */
48527 u8 hasData; /* True if this page stores data */
48528 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
48529 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
 
48530 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
48531 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
48532 u16 cellOffset; /* Index in aData of first cell pointer */
48533 u16 nFree; /* Number of free bytes on the page */
48534 u16 nCell; /* Number of cells on this page, local and ovfl */
@@ -48655,21 +48685,18 @@
48655 struct BtShared {
48656 Pager *pPager; /* The page cache */
48657 sqlite3 *db; /* Database connection currently using this Btree */
48658 BtCursor *pCursor; /* A list of all open cursors */
48659 MemPage *pPage1; /* First page of the database */
48660 u8 readOnly; /* True if the underlying file is readonly */
48661 u8 pageSizeFixed; /* True if the page size can no longer be changed */
48662 u8 secureDelete; /* True if secure_delete is enabled */
48663 u8 initiallyEmpty; /* Database is empty at start of transaction */
48664 u8 openFlags; /* Flags to sqlite3BtreeOpen() */
48665 #ifndef SQLITE_OMIT_AUTOVACUUM
48666 u8 autoVacuum; /* True if auto-vacuum is enabled */
48667 u8 incrVacuum; /* True if incr-vacuum is enabled */
48668 #endif
48669 u8 inTransaction; /* Transaction state */
48670 u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
 
48671 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
48672 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
48673 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
48674 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
48675 u32 pageSize; /* Total number of bytes on a page */
@@ -48683,16 +48710,25 @@
48683 #ifndef SQLITE_OMIT_SHARED_CACHE
48684 int nRef; /* Number of references to this structure */
48685 BtShared *pNext; /* Next on a list of sharable BtShared structs */
48686 BtLock *pLock; /* List of locks held on this shared-btree struct */
48687 Btree *pWriter; /* Btree with currently open write transaction */
48688 u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
48689 u8 isPending; /* If waiting for read-locks to clear */
48690 #endif
48691 u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
48692 };
48693
 
 
 
 
 
 
 
 
 
 
 
48694 /*
48695 ** An instance of the following structure is used to hold information
48696 ** about a cell. The parseCellPtr() function fills in this structure
48697 ** based on information extract from the raw disk page.
48698 */
@@ -49410,11 +49446,11 @@
49410 }
49411
49412 /* If some other connection is holding an exclusive lock, the
49413 ** requested lock may not be obtained.
49414 */
49415 if( pBt->pWriter!=p && pBt->isExclusive ){
49416 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
49417 return SQLITE_LOCKED_SHAREDCACHE;
49418 }
49419
49420 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
@@ -49431,11 +49467,11 @@
49431 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
49432 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
49433 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
49434 if( eLock==WRITE_LOCK ){
49435 assert( p==pBt->pWriter );
49436 pBt->isPending = 1;
49437 }
49438 return SQLITE_LOCKED_SHAREDCACHE;
49439 }
49440 }
49441 return SQLITE_OK;
@@ -49519,11 +49555,11 @@
49519 /*
49520 ** Release all the table locks (locks obtained via calls to
49521 ** the setSharedCacheTableLock() procedure) held by Btree object p.
49522 **
49523 ** This function assumes that Btree p has an open read or write
49524 ** transaction. If it does not, then the BtShared.isPending variable
49525 ** may be incorrectly cleared.
49526 */
49527 static void clearAllSharedCacheTableLocks(Btree *p){
49528 BtShared *pBt = p->pBt;
49529 BtLock **ppIter = &pBt->pLock;
@@ -49532,11 +49568,11 @@
49532 assert( p->sharable || 0==*ppIter );
49533 assert( p->inTrans>0 );
49534
49535 while( *ppIter ){
49536 BtLock *pLock = *ppIter;
49537 assert( pBt->isExclusive==0 || pBt->pWriter==pLock->pBtree );
49538 assert( pLock->pBtree->inTrans>=pLock->eLock );
49539 if( pLock->pBtree==p ){
49540 *ppIter = pLock->pNext;
49541 assert( pLock->iTable!=1 || pLock==&p->lock );
49542 if( pLock->iTable!=1 ){
@@ -49545,26 +49581,25 @@
49545 }else{
49546 ppIter = &pLock->pNext;
49547 }
49548 }
49549
49550 assert( pBt->isPending==0 || pBt->pWriter );
49551 if( pBt->pWriter==p ){
49552 pBt->pWriter = 0;
49553 pBt->isExclusive = 0;
49554 pBt->isPending = 0;
49555 }else if( pBt->nTransaction==2 ){
49556 /* This function is called when Btree p is concluding its
49557 ** transaction. If there currently exists a writer, and p is not
49558 ** that writer, then the number of locks held by connections other
49559 ** than the writer must be about to drop to zero. In this case
49560 ** set the isPending flag to 0.
49561 **
49562 ** If there is not currently a writer, then BtShared.isPending must
49563 ** be zero already. So this next line is harmless in that case.
49564 */
49565 pBt->isPending = 0;
49566 }
49567 }
49568
49569 /*
49570 ** This function changes all write-locks held by Btree p into read-locks.
@@ -49572,12 +49607,11 @@
49572 static void downgradeAllSharedCacheTableLocks(Btree *p){
49573 BtShared *pBt = p->pBt;
49574 if( pBt->pWriter==p ){
49575 BtLock *pLock;
49576 pBt->pWriter = 0;
49577 pBt->isExclusive = 0;
49578 pBt->isPending = 0;
49579 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
49580 assert( pLock->eLock==READ_LOCK || pLock->pBtree==p );
49581 pLock->eLock = READ_LOCK;
49582 }
49583 }
@@ -50431,11 +50465,11 @@
50431 assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
50432 assert( (start + size) <= (int)pPage->pBt->usableSize );
50433 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
50434 assert( size>=0 ); /* Minimum cell size is 4 */
50435
50436 if( pPage->pBt->secureDelete ){
50437 /* Overwrite deleted information with zeros when the secure_delete
50438 ** option is enabled */
50439 memset(&data[start], 0, size);
50440 }
50441
@@ -50534,10 +50568,11 @@
50534 pPage->maxLocal = pBt->maxLocal;
50535 pPage->minLocal = pBt->minLocal;
50536 }else{
50537 return SQLITE_CORRUPT_BKPT;
50538 }
 
50539 return SQLITE_OK;
50540 }
50541
50542 /*
50543 ** Initialize the auxiliary information for a disk block.
@@ -50669,11 +50704,11 @@
50669 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
50670 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
50671 assert( sqlite3PagerGetData(pPage->pDbPage) == data );
50672 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
50673 assert( sqlite3_mutex_held(pBt->mutex) );
50674 if( pBt->secureDelete ){
50675 memset(&data[hdr], 0, pBt->usableSize - hdr);
50676 }
50677 data[hdr] = (char)flags;
50678 first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
50679 memset(&data[hdr+1], 0, 4);
@@ -51022,13 +51057,13 @@
51022 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
51023 p->pBt = pBt;
51024
51025 pBt->pCursor = 0;
51026 pBt->pPage1 = 0;
51027 pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager);
51028 #ifdef SQLITE_SECURE_DELETE
51029 pBt->secureDelete = 1;
51030 #endif
51031 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
51032 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
51033 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
51034 pBt->pageSize = 0;
@@ -51045,11 +51080,11 @@
51045 }
51046 #endif
51047 nReserve = 0;
51048 }else{
51049 nReserve = zDbHeader[20];
51050 pBt->pageSizeFixed = 1;
51051 #ifndef SQLITE_OMIT_AUTOVACUUM
51052 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
51053 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
51054 #endif
51055 }
@@ -51333,19 +51368,19 @@
51333 ** at the beginning of a page.
51334 **
51335 ** If parameter nReserve is less than zero, then the number of reserved
51336 ** bytes per page is left unchanged.
51337 **
51338 ** If the iFix!=0 then the pageSizeFixed flag is set so that the page size
51339 ** and autovacuum mode can no longer be changed.
51340 */
51341 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
51342 int rc = SQLITE_OK;
51343 BtShared *pBt = p->pBt;
51344 assert( nReserve>=-1 && nReserve<=255 );
51345 sqlite3BtreeEnter(p);
51346 if( pBt->pageSizeFixed ){
51347 sqlite3BtreeLeave(p);
51348 return SQLITE_READONLY;
51349 }
51350 if( nReserve<0 ){
51351 nReserve = pBt->pageSize - pBt->usableSize;
@@ -51358,11 +51393,11 @@
51358 pBt->pageSize = (u32)pageSize;
51359 freeTempSpace(pBt);
51360 }
51361 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
51362 pBt->usableSize = pBt->pageSize - (u16)nReserve;
51363 if( iFix ) pBt->pageSizeFixed = 1;
51364 sqlite3BtreeLeave(p);
51365 return rc;
51366 }
51367
51368 /*
@@ -51398,22 +51433,23 @@
51398 sqlite3BtreeLeave(p);
51399 return n;
51400 }
51401
51402 /*
51403 ** Set the secureDelete flag if newFlag is 0 or 1. If newFlag is -1,
51404 ** then make no changes. Always return the value of the secureDelete
51405 ** setting after the change.
51406 */
51407 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
51408 int b;
51409 if( p==0 ) return 0;
51410 sqlite3BtreeEnter(p);
51411 if( newFlag>=0 ){
51412 p->pBt->secureDelete = (newFlag!=0) ? 1 : 0;
 
51413 }
51414 b = p->pBt->secureDelete;
51415 sqlite3BtreeLeave(p);
51416 return b;
51417 }
51418 #endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
51419
@@ -51430,11 +51466,11 @@
51430 BtShared *pBt = p->pBt;
51431 int rc = SQLITE_OK;
51432 u8 av = (u8)autoVacuum;
51433
51434 sqlite3BtreeEnter(p);
51435 if( pBt->pageSizeFixed && (av ?1:0)!=pBt->autoVacuum ){
51436 rc = SQLITE_READONLY;
51437 }else{
51438 pBt->autoVacuum = av ?1:0;
51439 pBt->incrVacuum = av==2 ?1:0;
51440 }
@@ -51504,18 +51540,18 @@
51504 goto page1_init_failed;
51505 }
51506
51507 #ifdef SQLITE_OMIT_WAL
51508 if( page1[18]>1 ){
51509 pBt->readOnly = 1;
51510 }
51511 if( page1[19]>1 ){
51512 goto page1_init_failed;
51513 }
51514 #else
51515 if( page1[18]>2 ){
51516 pBt->readOnly = 1;
51517 }
51518 if( page1[19]>2 ){
51519 goto page1_init_failed;
51520 }
51521
@@ -51525,11 +51561,11 @@
51525 ** The caller detects this and calls this function again. This is
51526 ** required as the version of page 1 currently in the page1 buffer
51527 ** may not be the latest version - there may be a newer one in the log
51528 ** file.
51529 */
51530 if( page1[19]==2 && pBt->doNotUseWAL==0 ){
51531 int isOpen = 0;
51532 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
51533 if( rc!=SQLITE_OK ){
51534 goto page1_init_failed;
51535 }else if( isOpen==0 ){
@@ -51602,10 +51638,15 @@
51602 */
51603 pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
51604 pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
51605 pBt->maxLeaf = (u16)(pBt->usableSize - 35);
51606 pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
 
 
 
 
 
51607 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
51608 pBt->pPage1 = pPage1;
51609 pBt->nPage = nPage;
51610 return SQLITE_OK;
51611
@@ -51665,11 +51706,11 @@
51665 data[21] = 64;
51666 data[22] = 32;
51667 data[23] = 32;
51668 memset(&data[24], 0, 100-24);
51669 zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
51670 pBt->pageSizeFixed = 1;
51671 #ifndef SQLITE_OMIT_AUTOVACUUM
51672 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
51673 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
51674 put4byte(&data[36 + 4*4], pBt->autoVacuum);
51675 put4byte(&data[36 + 7*4], pBt->incrVacuum);
@@ -51729,21 +51770,23 @@
51729 if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
51730 goto trans_begun;
51731 }
51732
51733 /* Write transactions are not possible on a read-only database */
51734 if( pBt->readOnly && wrflag ){
51735 rc = SQLITE_READONLY;
51736 goto trans_begun;
51737 }
51738
51739 #ifndef SQLITE_OMIT_SHARED_CACHE
51740 /* If another database handle has already opened a write transaction
51741 ** on this shared-btree structure and a second write transaction is
51742 ** requested, return SQLITE_LOCKED.
51743 */
51744 if( (wrflag && pBt->inTransaction==TRANS_WRITE) || pBt->isPending ){
 
 
51745 pBlock = pBt->pWriter->db;
51746 }else if( wrflag>1 ){
51747 BtLock *pIter;
51748 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
51749 if( pIter->pBtree!=p ){
@@ -51763,11 +51806,12 @@
51763 ** page 1. So if some other shared-cache client already has a write-lock
51764 ** on page 1, the transaction cannot be opened. */
51765 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
51766 if( SQLITE_OK!=rc ) goto trans_begun;
51767
51768 pBt->initiallyEmpty = (u8)(pBt->nPage==0);
 
51769 do {
51770 /* Call lockBtree() until either pBt->pPage1 is populated or
51771 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
51772 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
51773 ** reading page 1 it discovers that the page-size of the database
@@ -51775,11 +51819,11 @@
51775 ** pBt->pageSize to the page-size of the file on disk.
51776 */
51777 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
51778
51779 if( rc==SQLITE_OK && wrflag ){
51780 if( pBt->readOnly ){
51781 rc = SQLITE_READONLY;
51782 }else{
51783 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
51784 if( rc==SQLITE_OK ){
51785 rc = newDatabase(pBt);
@@ -51812,11 +51856,12 @@
51812 if( wrflag ){
51813 MemPage *pPage1 = pBt->pPage1;
51814 #ifndef SQLITE_OMIT_SHARED_CACHE
51815 assert( !pBt->pWriter );
51816 pBt->pWriter = p;
51817 pBt->isExclusive = (u8)(wrflag>1);
 
51818 #endif
51819
51820 /* If the db-size header field is incorrect (as it may be if an old
51821 ** client has been writing the database file), update it now. Doing
51822 ** this sooner rather than later means the database size can safely
@@ -52541,11 +52586,11 @@
52541 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p, int iStatement){
52542 int rc;
52543 BtShared *pBt = p->pBt;
52544 sqlite3BtreeEnter(p);
52545 assert( p->inTrans==TRANS_WRITE );
52546 assert( pBt->readOnly==0 );
52547 assert( iStatement>0 );
52548 assert( iStatement>p->db->nSavepoint );
52549 assert( pBt->inTransaction==TRANS_WRITE );
52550 /* At the pager level, a statement transaction is a savepoint with
52551 ** an index greater than all savepoints created explicitly using
@@ -52576,11 +52621,13 @@
52576 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
52577 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
52578 sqlite3BtreeEnter(p);
52579 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
52580 if( rc==SQLITE_OK ){
52581 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
 
 
52582 rc = newDatabase(pBt);
52583 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
52584
52585 /* The database size was written into the offset 28 of the header
52586 ** when the transaction started, so we know that the value at offset
@@ -52646,11 +52693,11 @@
52646 /* Assert that the caller has opened the required transaction. */
52647 assert( p->inTrans>TRANS_NONE );
52648 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
52649 assert( pBt->pPage1 && pBt->pPage1->aData );
52650
52651 if( NEVER(wrFlag && pBt->readOnly) ){
52652 return SQLITE_READONLY;
52653 }
52654 if( iTable==1 && btreePagecount(pBt)==0 ){
52655 assert( wrFlag==0 );
52656 iTable = 0;
@@ -53726,22 +53773,21 @@
53726 ** the entire cell by checking for the cases where the record is
53727 ** stored entirely within the b-tree page by inspecting the first
53728 ** 2 bytes of the cell.
53729 */
53730 int nCell = pCell[0];
53731 if( !(nCell & 0x80)
53732 && nCell<=pPage->maxLocal
53733 && (pCell+nCell+1)<=pPage->aDataEnd
53734 ){
53735 /* This branch runs if the record-size field of the cell is a
53736 ** single byte varint and the record fits entirely on the main
53737 ** b-tree page. */
53738 testcase( pCell+nCell+1==pPage->aDataEnd );
53739 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
53740 }else if( !(pCell[1] & 0x80)
53741 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
53742 && (pCell+nCell+2)<=pPage->aDataEnd
53743 ){
53744 /* The record-size field is a 2 byte varint and the record
53745 ** fits entirely on the main b-tree page. */
53746 testcase( pCell+nCell+2==pPage->aDataEnd );
53747 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54283,11 +54329,11 @@
54283 rc = sqlite3PagerWrite(pPage1->pDbPage);
54284 if( rc ) goto freepage_out;
54285 nFree = get4byte(&pPage1->aData[36]);
54286 put4byte(&pPage1->aData[36], nFree+1);
54287
54288 if( pBt->secureDelete ){
54289 /* If the secure_delete option is enabled, then
54290 ** always fully overwrite deleted information with zeros.
54291 */
54292 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
54293 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
@@ -54344,11 +54390,11 @@
54344 */
54345 rc = sqlite3PagerWrite(pTrunk->pDbPage);
54346 if( rc==SQLITE_OK ){
54347 put4byte(&pTrunk->aData[4], nLeaf+1);
54348 put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
54349 if( pPage && !pBt->secureDelete ){
54350 sqlite3PagerDontWrite(pPage->pDbPage);
54351 }
54352 rc = btreeSetHasContent(pBt, iPage);
54353 }
54354 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
@@ -55185,11 +55231,11 @@
55185 ** But not if we are in secure-delete mode. In secure-delete mode,
55186 ** the dropCell() routine will overwrite the entire cell with zeroes.
55187 ** In this case, temporarily copy the cell into the aOvflSpace[]
55188 ** buffer. It will be copied out again as soon as the aSpace[] buffer
55189 ** is allocated. */
55190 if( pBt->secureDelete ){
55191 int iOff;
55192
55193 iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
55194 if( (iOff+szNew[i])>(int)pBt->usableSize ){
55195 rc = SQLITE_CORRUPT_BKPT;
@@ -55927,11 +55973,12 @@
55927 assert( pCur->skipNext!=SQLITE_OK );
55928 return pCur->skipNext;
55929 }
55930
55931 assert( cursorHoldsMutex(pCur) );
55932 assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE && !pBt->readOnly );
 
55933 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
55934
55935 /* Assert that the caller has been consistent. If this cursor was opened
55936 ** expecting an index b-tree, then the caller should be inserting blob
55937 ** keys with no associated data. If the cursor was opened expecting an
@@ -56056,11 +56103,11 @@
56056 int iCellIdx; /* Index of cell to delete */
56057 int iCellDepth; /* Depth of node containing pCell */
56058
56059 assert( cursorHoldsMutex(pCur) );
56060 assert( pBt->inTransaction==TRANS_WRITE );
56061 assert( !pBt->readOnly );
56062 assert( pCur->wrFlag );
56063 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
56064 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
56065
56066 if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell)
@@ -56177,11 +56224,11 @@
56177 int rc;
56178 int ptfFlags; /* Page-type flage for the root page of new table */
56179
56180 assert( sqlite3BtreeHoldsMutex(p) );
56181 assert( pBt->inTransaction==TRANS_WRITE );
56182 assert( !pBt->readOnly );
56183
56184 #ifdef SQLITE_OMIT_AUTOVACUUM
56185 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
56186 if( rc ){
56187 return rc;
@@ -56551,11 +56598,13 @@
56551 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
56552
56553 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
56554 ** database, mark the database as read-only. */
56555 #ifdef SQLITE_OMIT_AUTOVACUUM
56556 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1;
 
 
56557 #endif
56558
56559 sqlite3BtreeLeave(p);
56560 }
56561
@@ -57351,11 +57400,12 @@
57351 ** (e) the cursor points at a valid row of an intKey table.
57352 */
57353 if( !pCsr->wrFlag ){
57354 return SQLITE_READONLY;
57355 }
57356 assert( !pCsr->pBt->readOnly && pCsr->pBt->inTransaction==TRANS_WRITE );
 
57357 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
57358 assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
57359 assert( pCsr->apPage[pCsr->iPage]->intKey );
57360
57361 return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
@@ -57391,11 +57441,12 @@
57391 assert( iVersion==1 || iVersion==2 );
57392
57393 /* If setting the version fields to 1, do not automatically open the
57394 ** WAL connection, even if the version fields are currently set to 2.
57395 */
57396 pBt->doNotUseWAL = (u8)(iVersion==1);
 
57397
57398 rc = sqlite3BtreeBeginTrans(pBtree, 0);
57399 if( rc==SQLITE_OK ){
57400 u8 *aData = pBt->pPage1->aData;
57401 if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){
@@ -57408,11 +57459,11 @@
57408 }
57409 }
57410 }
57411 }
57412
57413 pBt->doNotUseWAL = 0;
57414 return rc;
57415 }
57416
57417 /************** End of btree.c ***********************************************/
57418 /************** Begin file backup.c ******************************************/
@@ -58092,13 +58143,13 @@
58092
58093 assert( sqlite3BtreeIsInTrans(pTo) );
58094 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
58095 if( pFd->pMethods ){
58096 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
58097 sqlite3BeginBenignMalloc();
58098 sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
58099 sqlite3EndBenignMalloc();
58100 }
58101
58102 /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
58103 ** to 0. This is used by the implementations of sqlite3_backup_step()
58104 ** and sqlite3_backup_finish() to detect that they are being called
@@ -58119,16 +58170,17 @@
58119 */
58120 sqlite3_backup_step(&b, 0x7FFFFFFF);
58121 assert( b.rc!=SQLITE_OK );
58122 rc = sqlite3_backup_finish(&b);
58123 if( rc==SQLITE_OK ){
58124 pTo->pBt->pageSizeFixed = 0;
58125 }else{
58126 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
58127 }
58128
58129 assert( sqlite3BtreeIsInTrans(pTo)==0 );
 
58130 sqlite3BtreeLeave(pFrom);
58131 sqlite3BtreeLeave(pTo);
58132 return rc;
58133 }
58134 #endif /* SQLITE_OMIT_VACUUM */
@@ -58151,16 +58203,10 @@
58151 ** stores a single value in the VDBE. Mem is an opaque structure visible
58152 ** only within the VDBE. Interface routines refer to a Mem using the
58153 ** name sqlite_value
58154 */
58155
58156 /*
58157 ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
58158 ** P if required.
58159 */
58160 #define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
58161
58162 /*
58163 ** If pMem is an object with a valid string representation, this routine
58164 ** ensures the internal encoding for the string representation is
58165 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
58166 **
@@ -58256,11 +58302,11 @@
58256 */
58257 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
58258 int f;
58259 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58260 assert( (pMem->flags&MEM_RowSet)==0 );
58261 expandBlob(pMem);
58262 f = pMem->flags;
58263 if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){
58264 if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
58265 return SQLITE_NOMEM;
58266 }
@@ -59093,11 +59139,11 @@
59093 if( pVal->flags&MEM_Null ){
59094 return 0;
59095 }
59096 assert( (MEM_Blob>>3) == MEM_Str );
59097 pVal->flags |= (pVal->flags & MEM_Blob)>>3;
59098 expandBlob(pVal);
59099 if( pVal->flags&MEM_Str ){
59100 sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);
59101 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
59102 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
59103 if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
@@ -64300,16 +64346,10 @@
64300 */
64301 #define Deephemeralize(P) \
64302 if( ((P)->flags&MEM_Ephem)!=0 \
64303 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
64304
64305 /*
64306 ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
64307 ** P if required.
64308 */
64309 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
64310
64311 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
64312 #ifdef SQLITE_OMIT_MERGE_SORT
64313 # define isSorter(x) 0
64314 #else
64315 # define isSorter(x) ((x)->pSorter!=0)
@@ -92659,11 +92699,11 @@
92659 if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
92660 if( !zRight ){
92661 Pager *pPager = sqlite3BtreePager(pDb->pBt);
92662 char *proxy_file_path = NULL;
92663 sqlite3_file *pFile = sqlite3PagerFile(pPager);
92664 sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
92665 &proxy_file_path);
92666
92667 if( proxy_file_path ){
92668 sqlite3VdbeSetNumCols(v, 1);
92669 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
@@ -123271,11 +123311,11 @@
123271 typedef struct porter_tokenizer {
123272 sqlite3_tokenizer base; /* Base class */
123273 } porter_tokenizer;
123274
123275 /*
123276 ** Class derived from sqlit3_tokenizer_cursor
123277 */
123278 typedef struct porter_tokenizer_cursor {
123279 sqlite3_tokenizer_cursor base;
123280 const char *zInput; /* input we are tokenizing */
123281 int nInput; /* size of the input */
123282
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -657,11 +657,11 @@
657 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
658 ** [sqlite_version()] and [sqlite_source_id()].
659 */
660 #define SQLITE_VERSION "3.7.10"
661 #define SQLITE_VERSION_NUMBER 3007010
662 #define SQLITE_SOURCE_ID "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
663
664 /*
665 ** CAPI3REF: Run-Time Library Version Numbers
666 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
667 **
@@ -9396,17 +9396,19 @@
9396 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
9397 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
9398 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
9399 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
9400 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
9401 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
9402 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
9403 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
9404 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
9405 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
9406 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
9407 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
9408 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
9409
9410
9411 /*
9412 ** Functions for accessing sqlite3_vfs methods
9413 */
9414 SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
@@ -13244,12 +13246,14 @@
13246 #endif
13247 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
13248
13249 #ifndef SQLITE_OMIT_INCRBLOB
13250 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
13251 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
13252 #else
13253 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
13254 #define ExpandBlob(P) SQLITE_OK
13255 #endif
13256
13257 #endif /* !defined(_VDBEINT_H_) */
13258
13259 /************** End of vdbeInt.h *********************************************/
@@ -14715,14 +14719,27 @@
14719 }
14720 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){
14721 DO_OS_MALLOC_TEST(id);
14722 return id->pMethods->xCheckReservedLock(id, pResOut);
14723 }
14724
14725 /*
14726 ** Use sqlite3OsFileControl() when we are doing something that might fail
14727 ** and we need to know about the failures. Use sqlite3OsFileControlHint()
14728 ** when simply tossing information over the wall to the VFS and we do not
14729 ** really care if the VFS receives and understands the information since it
14730 ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
14731 ** routine has no return value since the return value would be meaningless.
14732 */
14733 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
14734 DO_OS_MALLOC_TEST(id);
14735 return id->pMethods->xFileControl(id, op, pArg);
14736 }
14737 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
14738 (void)id->pMethods->xFileControl(id, op, pArg);
14739 }
14740
14741 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){
14742 int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
14743 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
14744 }
14745 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
@@ -14769,10 +14786,11 @@
14786 assert( rc==SQLITE_OK || pFile->pMethods==0 );
14787 return rc;
14788 }
14789 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
14790 DO_OS_MALLOC_TEST(0);
14791 assert( dirSync==0 || dirSync==1 );
14792 return pVfs->xDelete(pVfs, zPath, dirSync);
14793 }
14794 SQLITE_PRIVATE int sqlite3OsAccess(
14795 sqlite3_vfs *pVfs,
14796 const char *zPath,
@@ -22113,31 +22131,26 @@
22131 ** characters of the original suffix.
22132 **
22133 ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
22134 ** do the suffix shortening regardless of URI parameter.
22135 **
 
 
 
 
22136 ** Examples:
22137 **
22138 ** test.db-journal => test.nal
22139 ** test.db-wal => test.wal
22140 ** test.db-shm => test.shm
22141 ** test.db-mj7f3319fa => test.9fa
22142 */
22143 SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
 
22144 #if SQLITE_ENABLE_8_3_NAMES<2
22145 if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) )
22146 #endif
22147 {
22148 int i, sz;
22149 sz = sqlite3Strlen30(z);
22150 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
22151 if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4);
22152 }
22153 }
22154 #endif
22155
22156 /************** End of util.c ************************************************/
@@ -24941,11 +24954,10 @@
24954 #endif
24955 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
24956 unsigned fsFlags; /* cached details from statfs() */
24957 #endif
24958 #if OS_VXWORKS
 
24959 struct vxworksFileId *pId; /* Unique file ID */
24960 #endif
24961 #ifndef NDEBUG
24962 /* The next group of variables are used to track whether or not the
24963 ** transaction counter in bytes 24-27 of database files are updated
@@ -24976,10 +24988,13 @@
24988 # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
24989 #else
24990 # define UNIXFILE_DIRSYNC 0x00
24991 #endif
24992 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
24993 #define UNIXFILE_DELETE 0x20 /* Delete on close */
24994 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
24995 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
24996
24997 /*
24998 ** Include code that is common to all os_*.c files
24999 */
25000 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -26689,11 +26704,11 @@
26704 robust_close(pFile, pFile->h, __LINE__);
26705 pFile->h = -1;
26706 }
26707 #if OS_VXWORKS
26708 if( pFile->pId ){
26709 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
26710 osUnlink(pFile->pId->zCanonicalName);
26711 }
26712 vxworksReleaseFileId(pFile->pId);
26713 pFile->pId = 0;
26714 }
@@ -28796,11 +28811,11 @@
28811 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
28812 if( pShmNode==0 ){
28813 rc = SQLITE_NOMEM;
28814 goto shm_open_err;
28815 }
28816 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
28817 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
28818 #ifdef SQLITE_SHM_DIRECTORY
28819 sqlite3_snprintf(nShmFilename, zShmFilename,
28820 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
28821 (u32)sStat.st_ino, (u32)sStat.st_dev);
@@ -29479,28 +29494,20 @@
29494 ** Initialize the contents of the unixFile structure pointed to by pId.
29495 */
29496 static int fillInUnixFile(
29497 sqlite3_vfs *pVfs, /* Pointer to vfs object */
29498 int h, /* Open file descriptor of file being opened */
 
29499 sqlite3_file *pId, /* Write to the unixFile structure here */
29500 const char *zFilename, /* Name of the file being opened */
29501 int ctrlFlags /* Zero or more UNIXFILE_* values */
 
 
29502 ){
29503 const sqlite3_io_methods *pLockingStyle;
29504 unixFile *pNew = (unixFile *)pId;
29505 int rc = SQLITE_OK;
29506
29507 assert( pNew->pInode==NULL );
29508
 
 
 
 
 
29509 /* Usually the path zFilename should not be a relative pathname. The
29510 ** exception is when opening the proxy "conch" file in builds that
29511 ** include the special Apple locking styles.
29512 */
29513 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29509,39 +29516,34 @@
29516 #else
29517 assert( zFilename==0 || zFilename[0]=='/' );
29518 #endif
29519
29520 /* No locking occurs in temporary files */
29521 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
29522
29523 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
29524 pNew->h = h;
29525 pNew->pVfs = pVfs;
29526 pNew->zPath = zFilename;
29527 pNew->ctrlFlags = (u8)ctrlFlags;
29528 if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
29529 "psow", SQLITE_POWERSAFE_OVERWRITE) ){
29530 pNew->ctrlFlags |= UNIXFILE_PSOW;
29531 }
29532 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
29533 pNew->ctrlFlags |= UNIXFILE_EXCL;
29534 }
 
 
 
 
 
 
29535
29536 #if OS_VXWORKS
29537 pNew->pId = vxworksFindFileId(zFilename);
29538 if( pNew->pId==0 ){
29539 ctrlFlags |= UNIXFILE_NOLOCK;
29540 rc = SQLITE_NOMEM;
29541 }
29542 #endif
29543
29544 if( ctrlFlags & UNIXFILE_NOLOCK ){
29545 pLockingStyle = &nolockIoMethods;
29546 }else{
29547 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
29548 #if SQLITE_ENABLE_LOCKING_STYLE
29549 /* Cache zFilename in the locking context (AFP and dotlock override) for
@@ -29658,11 +29660,11 @@
29660 if( h>=0 ) robust_close(pNew, h, __LINE__);
29661 h = -1;
29662 osUnlink(zFilename);
29663 isDelete = 0;
29664 }
29665 if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE;
29666 #endif
29667 if( rc!=SQLITE_OK ){
29668 if( h>=0 ) robust_close(pNew, h, __LINE__);
29669 }else{
29670 pNew->pMethod = pLockingStyle;
@@ -29723,22 +29725,23 @@
29725 if( zDir==0 ) zDir = ".";
29726
29727 /* Check that the output buffer is large enough for the temporary file
29728 ** name. If it is not, return SQLITE_ERROR.
29729 */
29730 if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){
29731 return SQLITE_ERROR;
29732 }
29733
29734 do{
29735 sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
29736 j = (int)strlen(zBuf);
29737 sqlite3_randomness(15, &zBuf[j]);
29738 for(i=0; i<15; i++, j++){
29739 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
29740 }
29741 zBuf[j] = 0;
29742 zBuf[j+1] = 0;
29743 }while( osAccess(zBuf,0)==0 );
29744 return SQLITE_OK;
29745 }
29746
29747 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
@@ -29913,10 +29916,11 @@
29916 int fd = -1; /* File descriptor returned by open() */
29917 int openFlags = 0; /* Flags to pass to open() */
29918 int eType = flags&0xFFFFFF00; /* Type of file to open */
29919 int noLock; /* True to omit locking primitives */
29920 int rc = SQLITE_OK; /* Function Return Code */
29921 int ctrlFlags = 0; /* UNIXFILE_* flags */
29922
29923 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
29924 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
29925 int isCreate = (flags & SQLITE_OPEN_CREATE);
29926 int isReadonly = (flags & SQLITE_OPEN_READONLY);
@@ -29939,11 +29943,11 @@
29943 ));
29944
29945 /* If argument zPath is a NULL pointer, this function is required to open
29946 ** a temporary file. Use this buffer to store the file name in.
29947 */
29948 char zTmpname[MAX_PATHNAME+2];
29949 const char *zName = zPath;
29950
29951 /* Check the following statements are true:
29952 **
29953 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
@@ -29982,18 +29986,28 @@
29986 if( !pUnused ){
29987 return SQLITE_NOMEM;
29988 }
29989 }
29990 p->pUnused = pUnused;
29991
29992 /* Database filenames are double-zero terminated if they are not
29993 ** URIs with parameters. Hence, they can always be passed into
29994 ** sqlite3_uri_parameter(). */
29995 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
29996
29997 }else if( !zName ){
29998 /* If zName is NULL, the upper layer is requesting a temp file. */
29999 assert(isDelete && !syncDir);
30000 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
30001 if( rc!=SQLITE_OK ){
30002 return rc;
30003 }
30004 zName = zTmpname;
30005
30006 /* Generated temporary filenames are always double-zero terminated
30007 ** for use by sqlite3_uri_parameter(). */
30008 assert( zName[strlen(zName)+1]==0 );
30009 }
30010
30011 /* Determine the value of the flags parameter passed to POSIX function
30012 ** open(). These must be calculated even if open() is not called, as
30013 ** they may be stored as part of the file handle and used by the
@@ -30066,11 +30080,18 @@
30080 }
30081 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
30082 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
30083 }
30084 #endif
30085
30086 /* Set up appropriate ctrlFlags */
30087 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
30088 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
30089 if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK;
30090 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
30091 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
30092
30093 #if SQLITE_ENABLE_LOCKING_STYLE
30094 #if SQLITE_PREFER_PROXY_LOCKING
30095 isAutoProxy = 1;
30096 #endif
30097 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){
@@ -30096,12 +30117,11 @@
30117 goto open_finished;
30118 }
30119 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
30120 }
30121 if( useProxy ){
30122 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
 
30123 if( rc==SQLITE_OK ){
30124 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
30125 if( rc!=SQLITE_OK ){
30126 /* Use unixClose to clean up the resources added in fillInUnixFile
30127 ** and clear all the structure's references. Specifically,
@@ -30114,12 +30134,12 @@
30134 goto open_finished;
30135 }
30136 }
30137 #endif
30138
30139 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
30140
30141 open_finished:
30142 if( rc!=SQLITE_OK ){
30143 sqlite3_free(p->pUnused);
30144 }
30145 return rc;
@@ -30140,11 +30160,11 @@
30160 SimulateIOError(return SQLITE_IOERR_DELETE);
30161 if( osUnlink(zPath)==(-1) && errno!=ENOENT ){
30162 return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
30163 }
30164 #ifndef SQLITE_DISABLE_DIRSYNC
30165 if( (dirSync & 1)!=0 ){
30166 int fd;
30167 rc = osOpenDirectory(zPath, &fd);
30168 if( rc==SQLITE_OK ){
30169 #if OS_VXWORKS
30170 if( fsync(fd)==-1 )
@@ -30786,11 +30806,11 @@
30806 dummyVfs.zName = "dummy";
30807 pUnused->fd = fd;
30808 pUnused->flags = openFlags;
30809 pNew->pUnused = pUnused;
30810
30811 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
30812 if( rc==SQLITE_OK ){
30813 *ppFile = pNew;
30814 return SQLITE_OK;
30815 }
30816 end_create_proxy:
@@ -34388,11 +34408,13 @@
34408 winClose((sqlite3_file *)&p->hFile);
34409 SimulateIOErrorBenign(0);
34410 }
34411 if( deleteFlag ){
34412 SimulateIOErrorBenign(1);
34413 sqlite3BeginBenignMalloc();
34414 winDelete(pVfs, p->zFilename, 0);
34415 sqlite3EndBenignMalloc();
34416 SimulateIOErrorBenign(0);
34417 }
34418 *pp = p->pNext;
34419 sqlite3_free(p->aRegion);
34420 sqlite3_free(p);
@@ -34423,16 +34445,16 @@
34445 */
34446 p = sqlite3_malloc( sizeof(*p) );
34447 if( p==0 ) return SQLITE_IOERR_NOMEM;
34448 memset(p, 0, sizeof(*p));
34449 nName = sqlite3Strlen30(pDbFd->zPath);
34450 pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 17 );
34451 if( pNew==0 ){
34452 sqlite3_free(p);
34453 return SQLITE_IOERR_NOMEM;
34454 }
34455 memset(pNew, 0, sizeof(*pNew) + nName + 17);
34456 pNew->zFilename = (char*)&pNew[1];
34457 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
34458 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
34459
34460 /* Look to see if there is an existing winShmNode that can be used.
@@ -34464,11 +34486,10 @@
34486 pShmNode->zFilename, /* Name of the file (UTF-8) */
34487 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
34488 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
34489 0);
34490 if( SQLITE_OK!=rc ){
 
34491 goto shm_open_err;
34492 }
34493
34494 /* Check to see if another process is holding the dead-man switch.
34495 ** If not, truncate the file to zero length.
@@ -34887,11 +34908,11 @@
34908 static char zChars[] =
34909 "abcdefghijklmnopqrstuvwxyz"
34910 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34911 "0123456789";
34912 size_t i, j;
34913 char zTempPath[MAX_PATH+2];
34914
34915 /* It's odd to simulate an io-error here, but really this is just
34916 ** using the io-error infrastructure to test that SQLite handles this
34917 ** function failing.
34918 */
@@ -34930,25 +34951,26 @@
34951 }
34952
34953 /* Check that the output buffer is large enough for the temporary file
34954 ** name. If it is not, return SQLITE_ERROR.
34955 */
34956 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
34957 return SQLITE_ERROR;
34958 }
34959
34960 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
34961 zTempPath[i] = 0;
34962
34963 sqlite3_snprintf(nBuf-18, zBuf,
34964 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
34965 j = sqlite3Strlen30(zBuf);
34966 sqlite3_randomness(15, &zBuf[j]);
34967 for(i=0; i<15; i++, j++){
34968 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
34969 }
34970 zBuf[j] = 0;
34971 zBuf[j+1] = 0;
34972
34973 OSTRACE(("TEMP FILENAME: %s\n", zBuf));
34974 return SQLITE_OK;
34975 }
34976
@@ -34977,11 +34999,11 @@
34999 int cnt = 0;
35000
35001 /* If argument zPath is a NULL pointer, this function is required to open
35002 ** a temporary file. Use this buffer to store the file name in.
35003 */
35004 char zTmpname[MAX_PATH+2]; /* Buffer used to create temp filename */
35005
35006 int rc = SQLITE_OK; /* Function Return Code */
35007 #if !defined(NDEBUG) || SQLITE_OS_WINCE
35008 int eType = flags&0xFFFFFF00; /* Type of file to open */
35009 #endif
@@ -35036,16 +35058,23 @@
35058 /* If the second argument to this function is NULL, generate a
35059 ** temporary file name to use
35060 */
35061 if( !zUtf8Name ){
35062 assert(isDelete && !isOpenJournal);
35063 rc = getTempname(MAX_PATH+2, zTmpname);
35064 if( rc!=SQLITE_OK ){
35065 return rc;
35066 }
35067 zUtf8Name = zTmpname;
35068 }
35069
35070 /* Database filenames are double-zero terminated if they are not
35071 ** URIs with parameters. Hence, they can always be passed into
35072 ** sqlite3_uri_parameter().
35073 */
35074 assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) ||
35075 zUtf8Name[strlen(zUtf8Name)+1]==0 );
35076
35077 /* Convert the filename to the system encoding. */
35078 zConverted = convertUtf8Filename(zUtf8Name);
35079 if( zConverted==0 ){
35080 return SQLITE_IOERR_NOMEM;
@@ -36721,11 +36750,11 @@
36750 ** of.
36751 **
36752 ** Mode 1 uses more memory (since PCache instances are not able to rob
36753 ** unused pages from other PCaches) but it also operates without a mutex,
36754 ** and is therefore often faster. Mode 2 requires a mutex in order to be
36755 ** threadsafe, but recycles pages more efficiently.
36756 **
36757 ** For mode (1), PGroup.mutex is NULL. For mode (2) there is only a single
36758 ** PGroup which is the pcache1.grp global variable and its mutex is
36759 ** SQLITE_MUTEX_STATIC_LRU.
36760 */
@@ -36747,11 +36776,11 @@
36776 ** opaque sqlite3_pcache* handles.
36777 */
36778 struct PCache1 {
36779 /* Cache configuration parameters. Page size (szPage) and the purgeable
36780 ** flag (bPurgeable) are set when the cache is created. nMax may be
36781 ** modified at any time by a call to the pcache1Cachesize() method.
36782 ** The PGroup mutex must be held when accessing nMax.
36783 */
36784 PGroup *pGroup; /* PGroup this cache belongs to */
36785 int szPage; /* Size of allocated pages in bytes */
36786 int szExtra; /* Size of extra space in bytes */
@@ -37038,11 +37067,11 @@
37067 ** it is desirable to avoid allocating a new page cache entry because
37068 ** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
37069 ** for all page cache needs and we should not need to spill the
37070 ** allocation onto the heap.
37071 **
37072 ** Or, the heap is used for all page cache memory but the heap is
37073 ** under memory pressure, then again it is desirable to avoid
37074 ** allocating a new page cache entry in order to avoid stressing
37075 ** the heap even further.
37076 */
37077 static int pcache1UnderMemoryPressure(PCache1 *pCache){
@@ -37349,11 +37378,11 @@
37378 ** means to try really hard to allocate a new page.
37379 **
37380 ** For a non-purgeable cache (a cache used as the storage for an in-memory
37381 ** database) there is really no difference between createFlag 1 and 2. So
37382 ** the calling function (pcache.c) will never have a createFlag of 1 on
37383 ** a non-purgeable cache.
37384 **
37385 ** There are three different approaches to obtaining space for a page,
37386 ** depending on the value of parameter createFlag (which may be 0, 1 or 2).
37387 **
37388 ** 1. Regardless of the value of createFlag, the cache is searched for a
@@ -40743,14 +40772,13 @@
40772 rc = sqlite3OsFileSize(pPager->fd, &currentSize);
40773 newSize = szPage*(i64)nPage;
40774 if( rc==SQLITE_OK && currentSize!=newSize ){
40775 if( currentSize>newSize ){
40776 rc = sqlite3OsTruncate(pPager->fd, newSize);
40777 }else if( (currentSize+szPage)<=newSize ){
40778 char *pTmp = pPager->pTmpSpace;
40779 memset(pTmp, 0, szPage);
 
40780 testcase( (newSize-szPage) == currentSize );
40781 testcase( (newSize-szPage) > currentSize );
40782 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
40783 }
40784 if( rc==SQLITE_OK ){
@@ -41004,14 +41032,15 @@
41032 /* Following a rollback, the database file should be back in its original
41033 ** state prior to the start of the transaction, so invoke the
41034 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
41035 ** assertion that the transaction counter was modified.
41036 */
41037 #ifdef SQLITE_DEBUG
41038 if( pPager->fd->pMethods ){
41039 sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
41040 }
41041 #endif
41042
41043 /* If this playback is happening automatically as a result of an IO or
41044 ** malloc error that occurred after the change-counter was updated but
41045 ** before the transaction was committed, then the change-counter
41046 ** modification may just have been reverted. If this happens in exclusive
@@ -41344,14 +41373,11 @@
41373 int rc = sqlite3OsFileSize(pPager->fd, &n);
41374 if( rc!=SQLITE_OK ){
41375 return rc;
41376 }
41377 }
41378 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
 
 
 
41379 }
41380
41381 /* If the current number of pages in the file is greater than the
41382 ** configured maximum pager number, increase the allowed limit so
41383 ** that the file can be read.
@@ -41778,11 +41804,11 @@
41804 if( !pNew ) rc = SQLITE_NOMEM;
41805 }
41806
41807 if( rc==SQLITE_OK ){
41808 pager_reset(pPager);
41809 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
41810 pPager->pageSize = pageSize;
41811 sqlite3PageFree(pPager->pTmpSpace);
41812 pPager->pTmpSpace = pNew;
41813 sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
41814 }
@@ -42286,13 +42312,11 @@
42312 ** file size will be.
42313 */
42314 assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
42315 if( rc==SQLITE_OK && pPager->dbSize>pPager->dbHintSize ){
42316 sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
42317 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
 
 
42318 pPager->dbHintSize = pPager->dbSize;
42319 }
42320
42321 while( rc==SQLITE_OK && pList ){
42322 Pgno pgno = pList->pgno;
@@ -44312,11 +44336,12 @@
44336 }else{
44337 rc = pager_playback(pPager, 0);
44338 }
44339
44340 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
44341 assert( rc==SQLITE_OK || rc==SQLITE_FULL
44342 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
44343
44344 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
44345 ** cache. So call pager_error() on the way out to make any error persistent.
44346 */
44347 return pager_error(pPager, rc);
@@ -46887,11 +46912,11 @@
46912 */
46913 if( rc==SQLITE_OK ){
46914 i64 nReq = ((i64)mxPage * szPage);
46915 rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
46916 if( rc==SQLITE_OK && nSize<nReq ){
46917 sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
46918 }
46919 }
46920
46921 /* Iterate through the contents of the WAL, copying data to the db file. */
46922 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
@@ -47003,11 +47028,13 @@
47028 rc = sqlite3WalCheckpoint(
47029 pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
47030 );
47031 if( rc==SQLITE_OK ){
47032 int bPersist = -1;
47033 sqlite3OsFileControlHint(
47034 pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
47035 );
47036 if( bPersist!=1 ){
47037 /* Try to delete the WAL file if the checkpoint completed and
47038 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
47039 ** mode (!bPersist) */
47040 isDelete = 1;
@@ -47024,11 +47051,13 @@
47051 }
47052
47053 walIndexClose(pWal, isDelete);
47054 sqlite3OsClose(pWal->pWalFd);
47055 if( isDelete ){
47056 sqlite3BeginBenignMalloc();
47057 sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
47058 sqlite3EndBenignMalloc();
47059 }
47060 WALTRACE(("WAL%p: closed\n", pWal));
47061 sqlite3_free((void *)pWal->apWiData);
47062 sqlite3_free(pWal);
47063 }
@@ -48525,10 +48554,11 @@
48554 u8 intKey; /* True if intkey flag is set */
48555 u8 leaf; /* True if leaf flag is set */
48556 u8 hasData; /* True if this page stores data */
48557 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
48558 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
48559 u8 max1bytePayload; /* min(maxLocal,127) */
48560 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
48561 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
48562 u16 cellOffset; /* Index in aData of first cell pointer */
48563 u16 nFree; /* Number of free bytes on the page */
48564 u16 nCell; /* Number of cells on this page, local and ovfl */
@@ -48655,21 +48685,18 @@
48685 struct BtShared {
48686 Pager *pPager; /* The page cache */
48687 sqlite3 *db; /* Database connection currently using this Btree */
48688 BtCursor *pCursor; /* A list of all open cursors */
48689 MemPage *pPage1; /* First page of the database */
 
 
 
 
48690 u8 openFlags; /* Flags to sqlite3BtreeOpen() */
48691 #ifndef SQLITE_OMIT_AUTOVACUUM
48692 u8 autoVacuum; /* True if auto-vacuum is enabled */
48693 u8 incrVacuum; /* True if incr-vacuum is enabled */
48694 #endif
48695 u8 inTransaction; /* Transaction state */
48696 u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */
48697 u16 btsFlags; /* Boolean parameters. See BTS_* macros below */
48698 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
48699 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
48700 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
48701 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
48702 u32 pageSize; /* Total number of bytes on a page */
@@ -48683,16 +48710,25 @@
48710 #ifndef SQLITE_OMIT_SHARED_CACHE
48711 int nRef; /* Number of references to this structure */
48712 BtShared *pNext; /* Next on a list of sharable BtShared structs */
48713 BtLock *pLock; /* List of locks held on this shared-btree struct */
48714 Btree *pWriter; /* Btree with currently open write transaction */
 
 
48715 #endif
48716 u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
48717 };
48718
48719 /*
48720 ** Allowed values for BtShared.btsFlags
48721 */
48722 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
48723 #define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
48724 #define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
48725 #define BTS_INITIALLY_EMPTY 0x0008 /* Database was empty at trans start */
48726 #define BTS_NO_WAL 0x0010 /* Do not open write-ahead-log files */
48727 #define BTS_EXCLUSIVE 0x0020 /* pWriter has an exclusive lock */
48728 #define BTS_PENDING 0x0040 /* Waiting for read-locks to clear */
48729
48730 /*
48731 ** An instance of the following structure is used to hold information
48732 ** about a cell. The parseCellPtr() function fills in this structure
48733 ** based on information extract from the raw disk page.
48734 */
@@ -49410,11 +49446,11 @@
49446 }
49447
49448 /* If some other connection is holding an exclusive lock, the
49449 ** requested lock may not be obtained.
49450 */
49451 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
49452 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
49453 return SQLITE_LOCKED_SHAREDCACHE;
49454 }
49455
49456 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
@@ -49431,11 +49467,11 @@
49467 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
49468 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
49469 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
49470 if( eLock==WRITE_LOCK ){
49471 assert( p==pBt->pWriter );
49472 pBt->btsFlags |= BTS_PENDING;
49473 }
49474 return SQLITE_LOCKED_SHAREDCACHE;
49475 }
49476 }
49477 return SQLITE_OK;
@@ -49519,11 +49555,11 @@
49555 /*
49556 ** Release all the table locks (locks obtained via calls to
49557 ** the setSharedCacheTableLock() procedure) held by Btree object p.
49558 **
49559 ** This function assumes that Btree p has an open read or write
49560 ** transaction. If it does not, then the BTS_PENDING flag
49561 ** may be incorrectly cleared.
49562 */
49563 static void clearAllSharedCacheTableLocks(Btree *p){
49564 BtShared *pBt = p->pBt;
49565 BtLock **ppIter = &pBt->pLock;
@@ -49532,11 +49568,11 @@
49568 assert( p->sharable || 0==*ppIter );
49569 assert( p->inTrans>0 );
49570
49571 while( *ppIter ){
49572 BtLock *pLock = *ppIter;
49573 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
49574 assert( pLock->pBtree->inTrans>=pLock->eLock );
49575 if( pLock->pBtree==p ){
49576 *ppIter = pLock->pNext;
49577 assert( pLock->iTable!=1 || pLock==&p->lock );
49578 if( pLock->iTable!=1 ){
@@ -49545,26 +49581,25 @@
49581 }else{
49582 ppIter = &pLock->pNext;
49583 }
49584 }
49585
49586 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
49587 if( pBt->pWriter==p ){
49588 pBt->pWriter = 0;
49589 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
 
49590 }else if( pBt->nTransaction==2 ){
49591 /* This function is called when Btree p is concluding its
49592 ** transaction. If there currently exists a writer, and p is not
49593 ** that writer, then the number of locks held by connections other
49594 ** than the writer must be about to drop to zero. In this case
49595 ** set the BTS_PENDING flag to 0.
49596 **
49597 ** If there is not currently a writer, then BTS_PENDING must
49598 ** be zero already. So this next line is harmless in that case.
49599 */
49600 pBt->btsFlags &= ~BTS_PENDING;
49601 }
49602 }
49603
49604 /*
49605 ** This function changes all write-locks held by Btree p into read-locks.
@@ -49572,12 +49607,11 @@
49607 static void downgradeAllSharedCacheTableLocks(Btree *p){
49608 BtShared *pBt = p->pBt;
49609 if( pBt->pWriter==p ){
49610 BtLock *pLock;
49611 pBt->pWriter = 0;
49612 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
 
49613 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
49614 assert( pLock->eLock==READ_LOCK || pLock->pBtree==p );
49615 pLock->eLock = READ_LOCK;
49616 }
49617 }
@@ -50431,11 +50465,11 @@
50465 assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
50466 assert( (start + size) <= (int)pPage->pBt->usableSize );
50467 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
50468 assert( size>=0 ); /* Minimum cell size is 4 */
50469
50470 if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
50471 /* Overwrite deleted information with zeros when the secure_delete
50472 ** option is enabled */
50473 memset(&data[start], 0, size);
50474 }
50475
@@ -50534,10 +50568,11 @@
50568 pPage->maxLocal = pBt->maxLocal;
50569 pPage->minLocal = pBt->minLocal;
50570 }else{
50571 return SQLITE_CORRUPT_BKPT;
50572 }
50573 pPage->max1bytePayload = pBt->max1bytePayload;
50574 return SQLITE_OK;
50575 }
50576
50577 /*
50578 ** Initialize the auxiliary information for a disk block.
@@ -50669,11 +50704,11 @@
50704 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
50705 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
50706 assert( sqlite3PagerGetData(pPage->pDbPage) == data );
50707 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
50708 assert( sqlite3_mutex_held(pBt->mutex) );
50709 if( pBt->btsFlags & BTS_SECURE_DELETE ){
50710 memset(&data[hdr], 0, pBt->usableSize - hdr);
50711 }
50712 data[hdr] = (char)flags;
50713 first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
50714 memset(&data[hdr+1], 0, 4);
@@ -51022,13 +51057,13 @@
51057 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
51058 p->pBt = pBt;
51059
51060 pBt->pCursor = 0;
51061 pBt->pPage1 = 0;
51062 if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
51063 #ifdef SQLITE_SECURE_DELETE
51064 pBt->btsFlags |= BTS_SECURE_DELETE;
51065 #endif
51066 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
51067 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
51068 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
51069 pBt->pageSize = 0;
@@ -51045,11 +51080,11 @@
51080 }
51081 #endif
51082 nReserve = 0;
51083 }else{
51084 nReserve = zDbHeader[20];
51085 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
51086 #ifndef SQLITE_OMIT_AUTOVACUUM
51087 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
51088 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
51089 #endif
51090 }
@@ -51333,19 +51368,19 @@
51368 ** at the beginning of a page.
51369 **
51370 ** If parameter nReserve is less than zero, then the number of reserved
51371 ** bytes per page is left unchanged.
51372 **
51373 ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
51374 ** and autovacuum mode can no longer be changed.
51375 */
51376 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
51377 int rc = SQLITE_OK;
51378 BtShared *pBt = p->pBt;
51379 assert( nReserve>=-1 && nReserve<=255 );
51380 sqlite3BtreeEnter(p);
51381 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
51382 sqlite3BtreeLeave(p);
51383 return SQLITE_READONLY;
51384 }
51385 if( nReserve<0 ){
51386 nReserve = pBt->pageSize - pBt->usableSize;
@@ -51358,11 +51393,11 @@
51393 pBt->pageSize = (u32)pageSize;
51394 freeTempSpace(pBt);
51395 }
51396 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
51397 pBt->usableSize = pBt->pageSize - (u16)nReserve;
51398 if( iFix ) pBt->btsFlags |= BTS_PAGESIZE_FIXED;
51399 sqlite3BtreeLeave(p);
51400 return rc;
51401 }
51402
51403 /*
@@ -51398,22 +51433,23 @@
51433 sqlite3BtreeLeave(p);
51434 return n;
51435 }
51436
51437 /*
51438 ** Set the BTS_SECURE_DELETE flag if newFlag is 0 or 1. If newFlag is -1,
51439 ** then make no changes. Always return the value of the BTS_SECURE_DELETE
51440 ** setting after the change.
51441 */
51442 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
51443 int b;
51444 if( p==0 ) return 0;
51445 sqlite3BtreeEnter(p);
51446 if( newFlag>=0 ){
51447 p->pBt->btsFlags &= ~BTS_SECURE_DELETE;
51448 if( newFlag ) p->pBt->btsFlags |= BTS_SECURE_DELETE;
51449 }
51450 b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
51451 sqlite3BtreeLeave(p);
51452 return b;
51453 }
51454 #endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
51455
@@ -51430,11 +51466,11 @@
51466 BtShared *pBt = p->pBt;
51467 int rc = SQLITE_OK;
51468 u8 av = (u8)autoVacuum;
51469
51470 sqlite3BtreeEnter(p);
51471 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
51472 rc = SQLITE_READONLY;
51473 }else{
51474 pBt->autoVacuum = av ?1:0;
51475 pBt->incrVacuum = av==2 ?1:0;
51476 }
@@ -51504,18 +51540,18 @@
51540 goto page1_init_failed;
51541 }
51542
51543 #ifdef SQLITE_OMIT_WAL
51544 if( page1[18]>1 ){
51545 pBt->btsFlags |= BTS_READ_ONLY;
51546 }
51547 if( page1[19]>1 ){
51548 goto page1_init_failed;
51549 }
51550 #else
51551 if( page1[18]>2 ){
51552 pBt->btsFlags |= BTS_READ_ONLY;
51553 }
51554 if( page1[19]>2 ){
51555 goto page1_init_failed;
51556 }
51557
@@ -51525,11 +51561,11 @@
51561 ** The caller detects this and calls this function again. This is
51562 ** required as the version of page 1 currently in the page1 buffer
51563 ** may not be the latest version - there may be a newer one in the log
51564 ** file.
51565 */
51566 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
51567 int isOpen = 0;
51568 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
51569 if( rc!=SQLITE_OK ){
51570 goto page1_init_failed;
51571 }else if( isOpen==0 ){
@@ -51602,10 +51638,15 @@
51638 */
51639 pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
51640 pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
51641 pBt->maxLeaf = (u16)(pBt->usableSize - 35);
51642 pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
51643 if( pBt->maxLocal>127 ){
51644 pBt->max1bytePayload = 127;
51645 }else{
51646 pBt->max1bytePayload = (u8)pBt->maxLocal;
51647 }
51648 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
51649 pBt->pPage1 = pPage1;
51650 pBt->nPage = nPage;
51651 return SQLITE_OK;
51652
@@ -51665,11 +51706,11 @@
51706 data[21] = 64;
51707 data[22] = 32;
51708 data[23] = 32;
51709 memset(&data[24], 0, 100-24);
51710 zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
51711 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
51712 #ifndef SQLITE_OMIT_AUTOVACUUM
51713 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
51714 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
51715 put4byte(&data[36 + 4*4], pBt->autoVacuum);
51716 put4byte(&data[36 + 7*4], pBt->incrVacuum);
@@ -51729,21 +51770,23 @@
51770 if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
51771 goto trans_begun;
51772 }
51773
51774 /* Write transactions are not possible on a read-only database */
51775 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
51776 rc = SQLITE_READONLY;
51777 goto trans_begun;
51778 }
51779
51780 #ifndef SQLITE_OMIT_SHARED_CACHE
51781 /* If another database handle has already opened a write transaction
51782 ** on this shared-btree structure and a second write transaction is
51783 ** requested, return SQLITE_LOCKED.
51784 */
51785 if( (wrflag && pBt->inTransaction==TRANS_WRITE)
51786 || (pBt->btsFlags & BTS_PENDING)!=0
51787 ){
51788 pBlock = pBt->pWriter->db;
51789 }else if( wrflag>1 ){
51790 BtLock *pIter;
51791 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
51792 if( pIter->pBtree!=p ){
@@ -51763,11 +51806,12 @@
51806 ** page 1. So if some other shared-cache client already has a write-lock
51807 ** on page 1, the transaction cannot be opened. */
51808 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
51809 if( SQLITE_OK!=rc ) goto trans_begun;
51810
51811 pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
51812 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
51813 do {
51814 /* Call lockBtree() until either pBt->pPage1 is populated or
51815 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
51816 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
51817 ** reading page 1 it discovers that the page-size of the database
@@ -51775,11 +51819,11 @@
51819 ** pBt->pageSize to the page-size of the file on disk.
51820 */
51821 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
51822
51823 if( rc==SQLITE_OK && wrflag ){
51824 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
51825 rc = SQLITE_READONLY;
51826 }else{
51827 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
51828 if( rc==SQLITE_OK ){
51829 rc = newDatabase(pBt);
@@ -51812,11 +51856,12 @@
51856 if( wrflag ){
51857 MemPage *pPage1 = pBt->pPage1;
51858 #ifndef SQLITE_OMIT_SHARED_CACHE
51859 assert( !pBt->pWriter );
51860 pBt->pWriter = p;
51861 pBt->btsFlags &= ~BTS_EXCLUSIVE;
51862 if( wrflag>1 ) pBt->btsFlags |= BTS_EXCLUSIVE;
51863 #endif
51864
51865 /* If the db-size header field is incorrect (as it may be if an old
51866 ** client has been writing the database file), update it now. Doing
51867 ** this sooner rather than later means the database size can safely
@@ -52541,11 +52586,11 @@
52586 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p, int iStatement){
52587 int rc;
52588 BtShared *pBt = p->pBt;
52589 sqlite3BtreeEnter(p);
52590 assert( p->inTrans==TRANS_WRITE );
52591 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
52592 assert( iStatement>0 );
52593 assert( iStatement>p->db->nSavepoint );
52594 assert( pBt->inTransaction==TRANS_WRITE );
52595 /* At the pager level, a statement transaction is a savepoint with
52596 ** an index greater than all savepoints created explicitly using
@@ -52576,11 +52621,13 @@
52621 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
52622 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
52623 sqlite3BtreeEnter(p);
52624 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
52625 if( rc==SQLITE_OK ){
52626 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
52627 pBt->nPage = 0;
52628 }
52629 rc = newDatabase(pBt);
52630 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
52631
52632 /* The database size was written into the offset 28 of the header
52633 ** when the transaction started, so we know that the value at offset
@@ -52646,11 +52693,11 @@
52693 /* Assert that the caller has opened the required transaction. */
52694 assert( p->inTrans>TRANS_NONE );
52695 assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
52696 assert( pBt->pPage1 && pBt->pPage1->aData );
52697
52698 if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
52699 return SQLITE_READONLY;
52700 }
52701 if( iTable==1 && btreePagecount(pBt)==0 ){
52702 assert( wrFlag==0 );
52703 iTable = 0;
@@ -53726,22 +53773,21 @@
53773 ** the entire cell by checking for the cases where the record is
53774 ** stored entirely within the b-tree page by inspecting the first
53775 ** 2 bytes of the cell.
53776 */
53777 int nCell = pCell[0];
53778 if( nCell<=pPage->max1bytePayload
53779 /* && (pCell+nCell)<pPage->aDataEnd */
 
53780 ){
53781 /* This branch runs if the record-size field of the cell is a
53782 ** single byte varint and the record fits entirely on the main
53783 ** b-tree page. */
53784 testcase( pCell+nCell+1==pPage->aDataEnd );
53785 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
53786 }else if( !(pCell[1] & 0x80)
53787 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
53788 /* && (pCell+nCell+2)<=pPage->aDataEnd */
53789 ){
53790 /* The record-size field is a 2 byte varint and the record
53791 ** fits entirely on the main b-tree page. */
53792 testcase( pCell+nCell+2==pPage->aDataEnd );
53793 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -54283,11 +54329,11 @@
54329 rc = sqlite3PagerWrite(pPage1->pDbPage);
54330 if( rc ) goto freepage_out;
54331 nFree = get4byte(&pPage1->aData[36]);
54332 put4byte(&pPage1->aData[36], nFree+1);
54333
54334 if( pBt->btsFlags & BTS_SECURE_DELETE ){
54335 /* If the secure_delete option is enabled, then
54336 ** always fully overwrite deleted information with zeros.
54337 */
54338 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
54339 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
@@ -54344,11 +54390,11 @@
54390 */
54391 rc = sqlite3PagerWrite(pTrunk->pDbPage);
54392 if( rc==SQLITE_OK ){
54393 put4byte(&pTrunk->aData[4], nLeaf+1);
54394 put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
54395 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
54396 sqlite3PagerDontWrite(pPage->pDbPage);
54397 }
54398 rc = btreeSetHasContent(pBt, iPage);
54399 }
54400 TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
@@ -55185,11 +55231,11 @@
55231 ** But not if we are in secure-delete mode. In secure-delete mode,
55232 ** the dropCell() routine will overwrite the entire cell with zeroes.
55233 ** In this case, temporarily copy the cell into the aOvflSpace[]
55234 ** buffer. It will be copied out again as soon as the aSpace[] buffer
55235 ** is allocated. */
55236 if( pBt->btsFlags & BTS_SECURE_DELETE ){
55237 int iOff;
55238
55239 iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
55240 if( (iOff+szNew[i])>(int)pBt->usableSize ){
55241 rc = SQLITE_CORRUPT_BKPT;
@@ -55927,11 +55973,12 @@
55973 assert( pCur->skipNext!=SQLITE_OK );
55974 return pCur->skipNext;
55975 }
55976
55977 assert( cursorHoldsMutex(pCur) );
55978 assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE
55979 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
55980 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
55981
55982 /* Assert that the caller has been consistent. If this cursor was opened
55983 ** expecting an index b-tree, then the caller should be inserting blob
55984 ** keys with no associated data. If the cursor was opened expecting an
@@ -56056,11 +56103,11 @@
56103 int iCellIdx; /* Index of cell to delete */
56104 int iCellDepth; /* Depth of node containing pCell */
56105
56106 assert( cursorHoldsMutex(pCur) );
56107 assert( pBt->inTransaction==TRANS_WRITE );
56108 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
56109 assert( pCur->wrFlag );
56110 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
56111 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
56112
56113 if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell)
@@ -56177,11 +56224,11 @@
56224 int rc;
56225 int ptfFlags; /* Page-type flage for the root page of new table */
56226
56227 assert( sqlite3BtreeHoldsMutex(p) );
56228 assert( pBt->inTransaction==TRANS_WRITE );
56229 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
56230
56231 #ifdef SQLITE_OMIT_AUTOVACUUM
56232 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
56233 if( rc ){
56234 return rc;
@@ -56551,11 +56598,13 @@
56598 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
56599
56600 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
56601 ** database, mark the database as read-only. */
56602 #ifdef SQLITE_OMIT_AUTOVACUUM
56603 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
56604 pBt->btsFlags |= BTS_READ_ONLY;
56605 }
56606 #endif
56607
56608 sqlite3BtreeLeave(p);
56609 }
56610
@@ -57351,11 +57400,12 @@
57400 ** (e) the cursor points at a valid row of an intKey table.
57401 */
57402 if( !pCsr->wrFlag ){
57403 return SQLITE_READONLY;
57404 }
57405 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
57406 && pCsr->pBt->inTransaction==TRANS_WRITE );
57407 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
57408 assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
57409 assert( pCsr->apPage[pCsr->iPage]->intKey );
57410
57411 return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
@@ -57391,11 +57441,12 @@
57441 assert( iVersion==1 || iVersion==2 );
57442
57443 /* If setting the version fields to 1, do not automatically open the
57444 ** WAL connection, even if the version fields are currently set to 2.
57445 */
57446 pBt->btsFlags &= ~BTS_NO_WAL;
57447 if( iVersion==1 ) pBt->btsFlags |= BTS_NO_WAL;
57448
57449 rc = sqlite3BtreeBeginTrans(pBtree, 0);
57450 if( rc==SQLITE_OK ){
57451 u8 *aData = pBt->pPage1->aData;
57452 if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){
@@ -57408,11 +57459,11 @@
57459 }
57460 }
57461 }
57462 }
57463
57464 pBt->btsFlags &= ~BTS_NO_WAL;
57465 return rc;
57466 }
57467
57468 /************** End of btree.c ***********************************************/
57469 /************** Begin file backup.c ******************************************/
@@ -58092,13 +58143,13 @@
58143
58144 assert( sqlite3BtreeIsInTrans(pTo) );
58145 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
58146 if( pFd->pMethods ){
58147 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
58148 rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
58149 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
58150 if( rc ) goto copy_finished;
58151 }
58152
58153 /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
58154 ** to 0. This is used by the implementations of sqlite3_backup_step()
58155 ** and sqlite3_backup_finish() to detect that they are being called
@@ -58119,16 +58170,17 @@
58170 */
58171 sqlite3_backup_step(&b, 0x7FFFFFFF);
58172 assert( b.rc!=SQLITE_OK );
58173 rc = sqlite3_backup_finish(&b);
58174 if( rc==SQLITE_OK ){
58175 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
58176 }else{
58177 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
58178 }
58179
58180 assert( sqlite3BtreeIsInTrans(pTo)==0 );
58181 copy_finished:
58182 sqlite3BtreeLeave(pFrom);
58183 sqlite3BtreeLeave(pTo);
58184 return rc;
58185 }
58186 #endif /* SQLITE_OMIT_VACUUM */
@@ -58151,16 +58203,10 @@
58203 ** stores a single value in the VDBE. Mem is an opaque structure visible
58204 ** only within the VDBE. Interface routines refer to a Mem using the
58205 ** name sqlite_value
58206 */
58207
 
 
 
 
 
 
58208 /*
58209 ** If pMem is an object with a valid string representation, this routine
58210 ** ensures the internal encoding for the string representation is
58211 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
58212 **
@@ -58256,11 +58302,11 @@
58302 */
58303 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
58304 int f;
58305 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58306 assert( (pMem->flags&MEM_RowSet)==0 );
58307 ExpandBlob(pMem);
58308 f = pMem->flags;
58309 if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){
58310 if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
58311 return SQLITE_NOMEM;
58312 }
@@ -59093,11 +59139,11 @@
59139 if( pVal->flags&MEM_Null ){
59140 return 0;
59141 }
59142 assert( (MEM_Blob>>3) == MEM_Str );
59143 pVal->flags |= (pVal->flags & MEM_Blob)>>3;
59144 ExpandBlob(pVal);
59145 if( pVal->flags&MEM_Str ){
59146 sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);
59147 if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&SQLITE_PTR_TO_INT(pVal->z)) ){
59148 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
59149 if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
@@ -64300,16 +64346,10 @@
64346 */
64347 #define Deephemeralize(P) \
64348 if( ((P)->flags&MEM_Ephem)!=0 \
64349 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
64350
 
 
 
 
 
 
64351 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
64352 #ifdef SQLITE_OMIT_MERGE_SORT
64353 # define isSorter(x) 0
64354 #else
64355 # define isSorter(x) ((x)->pSorter!=0)
@@ -92659,11 +92699,11 @@
92699 if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
92700 if( !zRight ){
92701 Pager *pPager = sqlite3BtreePager(pDb->pBt);
92702 char *proxy_file_path = NULL;
92703 sqlite3_file *pFile = sqlite3PagerFile(pPager);
92704 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
92705 &proxy_file_path);
92706
92707 if( proxy_file_path ){
92708 sqlite3VdbeSetNumCols(v, 1);
92709 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
@@ -123271,11 +123311,11 @@
123311 typedef struct porter_tokenizer {
123312 sqlite3_tokenizer base; /* Base class */
123313 } porter_tokenizer;
123314
123315 /*
123316 ** Class derived from sqlite3_tokenizer_cursor
123317 */
123318 typedef struct porter_tokenizer_cursor {
123319 sqlite3_tokenizer_cursor base;
123320 const char *zInput; /* input we are tokenizing */
123321 int nInput; /* size of the input */
123322
+1 -1
--- 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.10"
111111
#define SQLITE_VERSION_NUMBER 3007010
112
-#define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983"
112
+#define SQLITE_SOURCE_ID "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- 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.10"
111 #define SQLITE_VERSION_NUMBER 3007010
112 #define SQLITE_SOURCE_ID "2012-01-05 12:38:02 1378f905d37544701776d38987fe7a312b255983"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- 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.10"
111 #define SQLITE_VERSION_NUMBER 3007010
112 #define SQLITE_SOURCE_ID "2012-01-11 16:16:08 9e31a275ef494ea8713a1d60a15b84157e57c3ff"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
+16 -2
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185185
if( origSize!=file_wd_size(0) ){
186186
/* A file size change is definitive - the file has changed. No
187187
** need to check the sha1sum */
188188
chnged = 1;
189189
}
190
- }
191
- if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
190
+ }else if( chnged==1 && rid!=0 && !isDeleted ){
191
+ /* File is believed to have changed but it is the same size.
192
+ ** Double check that it really has changed by looking at content. */
193
+ assert( origSize==currentSize );
194
+ db_ephemeral_blob(&q, 5, &origCksum);
195
+ if( sha1sum_file(zName, &fileCksum) ){
196
+ blob_zero(&fileCksum);
197
+ }
198
+ if( blob_compare(&fileCksum, &origCksum)==0 ) chnged = 0;
199
+ blob_reset(&origCksum);
200
+ blob_reset(&fileCksum);
201
+ }else if( chnged==0 && (useMtime==0 || currentMtime!=oldMtime) ){
202
+ /* For files that were formerly believed to be unchanged, if their
203
+ ** mtime changes, or unconditionally if --sha1sum is used, check
204
+ ** to see if they have been edited by looking at their SHA1 sum */
205
+ assert( origSize==currentSize );
192206
db_ephemeral_blob(&q, 5, &origCksum);
193207
if( sha1sum_file(zName, &fileCksum) ){
194208
blob_zero(&fileCksum);
195209
}
196210
if( blob_compare(&fileCksum, &origCksum) ){
197211
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185 if( origSize!=file_wd_size(0) ){
186 /* A file size change is definitive - the file has changed. No
187 ** need to check the sha1sum */
188 chnged = 1;
189 }
190 }
191 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192 db_ephemeral_blob(&q, 5, &origCksum);
193 if( sha1sum_file(zName, &fileCksum) ){
194 blob_zero(&fileCksum);
195 }
196 if( blob_compare(&fileCksum, &origCksum) ){
197
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185 if( origSize!=file_wd_size(0) ){
186 /* A file size change is definitive - the file has changed. No
187 ** need to check the sha1sum */
188 chnged = 1;
189 }
190 }else if( chnged==1 && rid!=0 && !isDeleted ){
191 /* File is believed to have changed but it is the same size.
192 ** Double check that it really has changed by looking at content. */
193 assert( origSize==currentSize );
194 db_ephemeral_blob(&q, 5, &origCksum);
195 if( sha1sum_file(zName, &fileCksum) ){
196 blob_zero(&fileCksum);
197 }
198 if( blob_compare(&fileCksum, &origCksum)==0 ) chnged = 0;
199 blob_reset(&origCksum);
200 blob_reset(&fileCksum);
201 }else if( chnged==0 && (useMtime==0 || currentMtime!=oldMtime) ){
202 /* For files that were formerly believed to be unchanged, if their
203 ** mtime changes, or unconditionally if --sha1sum is used, check
204 ** to see if they have been edited by looking at their SHA1 sum */
205 assert( origSize==currentSize );
206 db_ephemeral_blob(&q, 5, &origCksum);
207 if( sha1sum_file(zName, &fileCksum) ){
208 blob_zero(&fileCksum);
209 }
210 if( blob_compare(&fileCksum, &origCksum) ){
211
+16 -2
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185185
if( origSize!=file_wd_size(0) ){
186186
/* A file size change is definitive - the file has changed. No
187187
** need to check the sha1sum */
188188
chnged = 1;
189189
}
190
- }
191
- if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
190
+ }else if( chnged==1 && rid!=0 && !isDeleted ){
191
+ /* File is believed to have changed but it is the same size.
192
+ ** Double check that it really has changed by looking at content. */
193
+ assert( origSize==currentSize );
194
+ db_ephemeral_blob(&q, 5, &origCksum);
195
+ if( sha1sum_file(zName, &fileCksum) ){
196
+ blob_zero(&fileCksum);
197
+ }
198
+ if( blob_compare(&fileCksum, &origCksum)==0 ) chnged = 0;
199
+ blob_reset(&origCksum);
200
+ blob_reset(&fileCksum);
201
+ }else if( chnged==0 && (useMtime==0 || currentMtime!=oldMtime) ){
202
+ /* For files that were formerly believed to be unchanged, if their
203
+ ** mtime changes, or unconditionally if --sha1sum is used, check
204
+ ** to see if they have been edited by looking at their SHA1 sum */
205
+ assert( origSize==currentSize );
192206
db_ephemeral_blob(&q, 5, &origCksum);
193207
if( sha1sum_file(zName, &fileCksum) ){
194208
blob_zero(&fileCksum);
195209
}
196210
if( blob_compare(&fileCksum, &origCksum) ){
197211
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185 if( origSize!=file_wd_size(0) ){
186 /* A file size change is definitive - the file has changed. No
187 ** need to check the sha1sum */
188 chnged = 1;
189 }
190 }
191 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192 db_ephemeral_blob(&q, 5, &origCksum);
193 if( sha1sum_file(zName, &fileCksum) ){
194 blob_zero(&fileCksum);
195 }
196 if( blob_compare(&fileCksum, &origCksum) ){
197
--- src/vfile.c
+++ src/vfile.c
@@ -185,12 +185,26 @@
185 if( origSize!=file_wd_size(0) ){
186 /* A file size change is definitive - the file has changed. No
187 ** need to check the sha1sum */
188 chnged = 1;
189 }
190 }else if( chnged==1 && rid!=0 && !isDeleted ){
191 /* File is believed to have changed but it is the same size.
192 ** Double check that it really has changed by looking at content. */
193 assert( origSize==currentSize );
194 db_ephemeral_blob(&q, 5, &origCksum);
195 if( sha1sum_file(zName, &fileCksum) ){
196 blob_zero(&fileCksum);
197 }
198 if( blob_compare(&fileCksum, &origCksum)==0 ) chnged = 0;
199 blob_reset(&origCksum);
200 blob_reset(&fileCksum);
201 }else if( chnged==0 && (useMtime==0 || currentMtime!=oldMtime) ){
202 /* For files that were formerly believed to be unchanged, if their
203 ** mtime changes, or unconditionally if --sha1sum is used, check
204 ** to see if they have been edited by looking at their SHA1 sum */
205 assert( origSize==currentSize );
206 db_ephemeral_blob(&q, 5, &origCksum);
207 if( sha1sum_file(zName, &fileCksum) ){
208 blob_zero(&fileCksum);
209 }
210 if( blob_compare(&fileCksum, &origCksum) ){
211

Keyboard Shortcuts

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