Fossil SCM

Update the built-in version of SQLite to the lastest in the stable trunk version.

drh 2011-03-01 22:23 trunk
Commit 4cd9309c508373c6aa4a371941835bd1512c5ac2
2 files changed +182 -43 +3 -1
+182 -43
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.6"
654654
#define SQLITE_VERSION_NUMBER 3007006
655
-#define SQLITE_SOURCE_ID "2011-02-19 23:18:12 e87d499a4f8a456111c1f96ca6da31d0810fb7c8"
655
+#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1023,10 +1023,12 @@
10231023
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
10241024
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
10251025
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
10261026
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
10271027
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
1028
+
1029
+/* Reserved: 0x00F00000 */
10281030
10291031
/*
10301032
** CAPI3REF: Device Characteristics
10311033
**
10321034
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -23557,10 +23559,23 @@
2355723559
}
2355823560
#define fcntl lockTrace
2355923561
#endif /* SQLITE_LOCK_TRACE */
2356023562
2356123563
23564
+/*
23565
+** Retry ftruncate() calls that fail due to EINTR
23566
+*/
23567
+#ifdef EINTR
23568
+static int robust_ftruncate(int h, sqlite3_int64 sz){
23569
+ int rc;
23570
+ do{ rc = ftruncate(h,sz); }while( rc<0 && errno==EINTR );
23571
+ return rc;
23572
+}
23573
+#else
23574
+# define robust_ftruncate(a,b) ftruncate(a,b)
23575
+#endif
23576
+
2356223577
2356323578
/*
2356423579
** This routine translates a standard POSIX errno code into something
2356523580
** useful to the clients of the sqlite3 functions. Specifically, it is
2356623581
** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23898,10 +23913,79 @@
2389823913
2389923914
/*
2390023915
** A lists of all unixInodeInfo objects.
2390123916
*/
2390223917
static unixInodeInfo *inodeList = 0;
23918
+
23919
+/*
23920
+**
23921
+** This function - unixLogError_x(), is only ever called via the macro
23922
+** unixLogError().
23923
+**
23924
+** It is invoked after an error occurs in an OS function and errno has been
23925
+** set. It logs a message using sqlite3_log() containing the current value of
23926
+** errno and, if possible, the human-readable equivalent from strerror() or
23927
+** strerror_r().
23928
+**
23929
+** The first argument passed to the macro should be the error code that
23930
+** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
23931
+** The two subsequent arguments should be the name of the OS function that
23932
+** failed (e.g. "unlink", "open") and the the associated file-system path,
23933
+** if any.
23934
+*/
23935
+#define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__)
23936
+static int unixLogError_x(
23937
+ int errcode, /* SQLite error code */
23938
+ const char *zFunc, /* Name of OS function that failed */
23939
+ const char *zPath, /* File path associated with error */
23940
+ int iLine /* Source line number where error occurred */
23941
+){
23942
+ char *zErr; /* Message from strerror() or equivalent */
23943
+
23944
+ /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
23945
+ ** the strerror() function to obtain the human-readable error message
23946
+ ** equivalent to errno. Otherwise, use strerror_r().
23947
+ */
23948
+#if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R)
23949
+ char aErr[80];
23950
+ memset(aErr, 0, sizeof(aErr));
23951
+ zErr = aErr;
23952
+
23953
+ /* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
23954
+ ** assume that the system provides the the GNU version of strerror_r() that
23955
+ ** returns a pointer to a buffer containing the error message. That pointer
23956
+ ** may point to aErr[], or it may point to some static storage somewhere.
23957
+ ** Otherwise, assume that the system provides the POSIX version of
23958
+ ** strerror_r(), which always writes an error message into aErr[].
23959
+ **
23960
+ ** If the code incorrectly assumes that it is the POSIX version that is
23961
+ ** available, the error message will often be an empty string. Not a
23962
+ ** huge problem. Incorrectly concluding that the GNU version is available
23963
+ ** could lead to a segfault though.
23964
+ */
23965
+#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
23966
+ zErr =
23967
+# endif
23968
+ strerror_r(errno, aErr, sizeof(aErr)-1);
23969
+
23970
+#elif SQLITE_THREADSAFE
23971
+ /* This is a threadsafe build, but strerror_r() is not available. */
23972
+ zErr = "";
23973
+#else
23974
+ /* Non-threadsafe build, use strerror(). */
23975
+ zErr = strerror(errno);
23976
+#endif
23977
+
23978
+ assert( errcode!=SQLITE_OK );
23979
+ sqlite3_log(errcode,
23980
+ "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s",
23981
+ zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a")
23982
+ );
23983
+
23984
+ return errcode;
23985
+}
23986
+
2390323987
2390423988
/*
2390523989
** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
2390623990
** If all such file descriptors are closed without error, the list is
2390723991
** cleared and SQLITE_OK returned.
@@ -23918,11 +24002,11 @@
2391824002
UnixUnusedFd *pNext;
2391924003
for(p=pInode->pUnused; p; p=pNext){
2392024004
pNext = p->pNext;
2392124005
if( close(p->fd) ){
2392224006
pFile->lastErrno = errno;
23923
- rc = SQLITE_IOERR_CLOSE;
24007
+ rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
2392424008
p->pNext = pError;
2392524009
pError = p;
2392624010
}else{
2392724011
sqlite3_free(p);
2392824012
}
@@ -24006,11 +24090,11 @@
2400624090
** in the header of every SQLite database. In this way, if there
2400724091
** is a race condition such that another thread has already populated
2400824092
** the first page of the database, no damage is done.
2400924093
*/
2401024094
if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24011
- rc = write(fd, "S", 1);
24095
+ do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR );
2401224096
if( rc!=1 ){
2401324097
pFile->lastErrno = errno;
2401424098
return SQLITE_IOERR;
2401524099
}
2401624100
rc = fstat(fd, &statbuf);
@@ -24428,10 +24512,15 @@
2442824512
** 2: [....W]
2442924513
** 3: [RRRRW]
2443024514
** 4: [RRRR.]
2443124515
*/
2443224516
if( eFileLock==SHARED_LOCK ){
24517
+
24518
+#if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
24519
+ assert( handleNFSUnlock==0 );
24520
+#endif
24521
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2443324522
if( handleNFSUnlock ){
2443424523
off_t divSize = SHARED_SIZE - 1;
2443524524
2443624525
lock.l_type = F_UNLCK;
2443724526
lock.l_whence = SEEK_SET;
@@ -24467,11 +24556,13 @@
2446724556
if( IS_LOCK_ERROR(rc) ){
2446824557
pFile->lastErrno = tErrno;
2446924558
}
2447024559
goto end_unlock;
2447124560
}
24472
- }else{
24561
+ }else
24562
+#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
24563
+ {
2447324564
lock.l_type = F_RDLCK;
2447424565
lock.l_whence = SEEK_SET;
2447524566
lock.l_start = SHARED_FIRST;
2447624567
lock.l_len = SHARED_SIZE;
2447724568
if( fcntl(h, F_SETLK, &lock)==(-1) ){
@@ -24571,20 +24662,20 @@
2457124662
if( pFile ){
2457224663
if( pFile->dirfd>=0 ){
2457324664
int err = close(pFile->dirfd);
2457424665
if( err ){
2457524666
pFile->lastErrno = errno;
24576
- return SQLITE_IOERR_DIR_CLOSE;
24667
+ return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
2457724668
}else{
2457824669
pFile->dirfd=-1;
2457924670
}
2458024671
}
2458124672
if( pFile->h>=0 ){
2458224673
int err = close(pFile->h);
2458324674
if( err ){
2458424675
pFile->lastErrno = errno;
24585
- return SQLITE_IOERR_CLOSE;
24676
+ return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
2458624677
}
2458724678
}
2458824679
#if OS_VXWORKS
2458924680
if( pFile->pId ){
2459024681
if( pFile->isDelete ){
@@ -24882,10 +24973,24 @@
2488224973
** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if
2488324974
** compiling for VXWORKS.
2488424975
*/
2488524976
#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
2488624977
24978
+/*
24979
+** Retry flock() calls that fail with EINTR
24980
+*/
24981
+#ifdef EINTR
24982
+static int robust_flock(int fd, int op){
24983
+ int rc;
24984
+ do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR );
24985
+ return rc;
24986
+}
24987
+#else
24988
+# define robust_flock(a,b) flock(a,b)
24989
+#endif
24990
+
24991
+
2488724992
/*
2488824993
** This routine checks if there is a RESERVED lock held on the specified
2488924994
** file by this or any other process. If such a lock is held, set *pResOut
2489024995
** to a non-zero value otherwise *pResOut is set to zero. The return value
2489124996
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
@@ -24905,14 +25010,14 @@
2490525010
}
2490625011
2490725012
/* Otherwise see if some other process holds it. */
2490825013
if( !reserved ){
2490925014
/* attempt to get the lock */
24910
- int lrc = flock(pFile->h, LOCK_EX | LOCK_NB);
25015
+ int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
2491125016
if( !lrc ){
2491225017
/* got the lock, unlock it */
24913
- lrc = flock(pFile->h, LOCK_UN);
25018
+ lrc = robust_flock(pFile->h, LOCK_UN);
2491425019
if ( lrc ) {
2491525020
int tErrno = errno;
2491625021
/* unlock failed with an error */
2491725022
lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2491825023
if( IS_LOCK_ERROR(lrc) ){
@@ -24985,11 +25090,11 @@
2498525090
return SQLITE_OK;
2498625091
}
2498725092
2498825093
/* grab an exclusive lock */
2498925094
24990
- if (flock(pFile->h, LOCK_EX | LOCK_NB)) {
25095
+ if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
2499125096
int tErrno = errno;
2499225097
/* didn't get, must be busy */
2499325098
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2499425099
if( IS_LOCK_ERROR(rc) ){
2499525100
pFile->lastErrno = tErrno;
@@ -25034,11 +25139,11 @@
2503425139
pFile->eFileLock = eFileLock;
2503525140
return SQLITE_OK;
2503625141
}
2503725142
2503825143
/* no, really, unlock. */
25039
- int rc = flock(pFile->h, LOCK_UN);
25144
+ int rc = robust_flock(pFile->h, LOCK_UN);
2504025145
if (rc) {
2504125146
int r, tErrno = errno;
2504225147
r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2504325148
if( IS_LOCK_ERROR(r) ){
2504425149
pFile->lastErrno = tErrno;
@@ -25771,14 +25876,14 @@
2577125876
#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
2577225877
i64 newOffset;
2577325878
#endif
2577425879
TIMER_START;
2577525880
#if defined(USE_PREAD)
25776
- got = pread(id->h, pBuf, cnt, offset);
25881
+ do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2577725882
SimulateIOError( got = -1 );
2577825883
#elif defined(USE_PREAD64)
25779
- got = pread64(id->h, pBuf, cnt, offset);
25884
+ do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2578025885
SimulateIOError( got = -1 );
2578125886
#else
2578225887
newOffset = lseek(id->h, offset, SEEK_SET);
2578325888
SimulateIOError( newOffset-- );
2578425889
if( newOffset!=offset ){
@@ -25787,11 +25892,11 @@
2578725892
}else{
2578825893
((unixFile*)id)->lastErrno = 0;
2578925894
}
2579025895
return -1;
2579125896
}
25792
- got = read(id->h, pBuf, cnt);
25897
+ do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
2579325898
#endif
2579425899
TIMER_END;
2579525900
if( got<0 ){
2579625901
((unixFile*)id)->lastErrno = errno;
2579725902
}
@@ -25849,13 +25954,13 @@
2584925954
#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
2585025955
i64 newOffset;
2585125956
#endif
2585225957
TIMER_START;
2585325958
#if defined(USE_PREAD)
25854
- got = pwrite(id->h, pBuf, cnt, offset);
25959
+ do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2585525960
#elif defined(USE_PREAD64)
25856
- got = pwrite64(id->h, pBuf, cnt, offset);
25961
+ do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2585725962
#else
2585825963
newOffset = lseek(id->h, offset, SEEK_SET);
2585925964
if( newOffset!=offset ){
2586025965
if( newOffset == -1 ){
2586125966
((unixFile*)id)->lastErrno = errno;
@@ -25862,11 +25967,11 @@
2586225967
}else{
2586325968
((unixFile*)id)->lastErrno = 0;
2586425969
}
2586525970
return -1;
2586625971
}
25867
- got = write(id->h, pBuf, cnt);
25972
+ do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
2586825973
#endif
2586925974
TIMER_END;
2587025975
if( got<0 ){
2587125976
((unixFile*)id)->lastErrno = errno;
2587225977
}
@@ -26102,11 +26207,11 @@
2610226207
OSTRACE(("SYNC %-3d\n", pFile->h));
2610326208
rc = full_fsync(pFile->h, isFullsync, isDataOnly);
2610426209
SimulateIOError( rc=1 );
2610526210
if( rc ){
2610626211
pFile->lastErrno = errno;
26107
- return SQLITE_IOERR_FSYNC;
26212
+ return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
2610826213
}
2610926214
if( pFile->dirfd>=0 ){
2611026215
int err;
2611126216
OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
2611226217
HAVE_FULLFSYNC, isFullsync));
@@ -26129,11 +26234,11 @@
2612926234
err = close(pFile->dirfd); /* Only need to sync once, so close the */
2613026235
if( err==0 ){ /* directory when we are done */
2613126236
pFile->dirfd = -1;
2613226237
}else{
2613326238
pFile->lastErrno = errno;
26134
- rc = SQLITE_IOERR_DIR_CLOSE;
26239
+ rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
2613526240
}
2613626241
}
2613726242
return rc;
2613826243
}
2613926244
@@ -26153,14 +26258,14 @@
2615326258
*/
2615426259
if( pFile->szChunk ){
2615526260
nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
2615626261
}
2615726262
26158
- rc = ftruncate(pFile->h, (off_t)nByte);
26263
+ rc = robust_ftruncate(pFile->h, (off_t)nByte);
2615926264
if( rc ){
2616026265
pFile->lastErrno = errno;
26161
- return SQLITE_IOERR_TRUNCATE;
26266
+ return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2616226267
}else{
2616326268
#ifndef NDEBUG
2616426269
/* If we are doing a normal write to a database file (as opposed to
2616526270
** doing a hot-journal rollback or a write to some file other than a
2616626271
** normal database file) and we truncate the file to zero length,
@@ -26228,13 +26333,15 @@
2622826333
if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
2622926334
2623026335
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
2623126336
if( nSize>(i64)buf.st_size ){
2623226337
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
26233
- if( posix_fallocate(pFile->h, buf.st_size, nSize-buf.st_size) ){
26234
- return SQLITE_IOERR_WRITE;
26235
- }
26338
+ int rc;
26339
+ do{
26340
+ rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size;
26341
+ }while( rc<0 && errno=EINTR );
26342
+ if( rc ) return SQLITE_IOERR_WRITE;
2623626343
#else
2623726344
/* If the OS does not have posix_fallocate(), fake it. First use
2623826345
** ftruncate() to set the file size, then write a single byte to
2623926346
** the last byte in each block within the extended region. This
2624026347
** is the same technique used by glibc to implement posix_fallocate()
@@ -26242,13 +26349,13 @@
2624226349
*/
2624326350
int nBlk = buf.st_blksize; /* File-system block size */
2624426351
i64 iWrite; /* Next offset to write to */
2624526352
int nWrite; /* Return value from seekAndWrite() */
2624626353
26247
- if( ftruncate(pFile->h, nSize) ){
26354
+ if( robust_ftruncate(pFile->h, nSize) ){
2624826355
pFile->lastErrno = errno;
26249
- return SQLITE_IOERR_TRUNCATE;
26356
+ return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2625026357
}
2625126358
iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
2625226359
do {
2625326360
nWrite = seekAndWrite(pFile, iWrite, "", 1);
2625426361
iWrite += nBlk;
@@ -26593,21 +26700,21 @@
2659326700
goto shm_open_err;
2659426701
}
2659526702
2659626703
pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
2659726704
if( pShmNode->h<0 ){
26598
- rc = SQLITE_CANTOPEN_BKPT;
26705
+ rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
2659926706
goto shm_open_err;
2660026707
}
2660126708
2660226709
/* Check to see if another process is holding the dead-man switch.
2660326710
** If not, truncate the file to zero length.
2660426711
*/
2660526712
rc = SQLITE_OK;
2660626713
if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
26607
- if( ftruncate(pShmNode->h, 0) ){
26608
- rc = SQLITE_IOERR_SHMOPEN;
26714
+ if( robust_ftruncate(pShmNode->h, 0) ){
26715
+ rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
2660926716
}
2661026717
}
2661126718
if( rc==SQLITE_OK ){
2661226719
rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
2661326720
}
@@ -26708,12 +26815,12 @@
2670826815
**
2670926816
** Alternatively, if bExtend is true, use ftruncate() to allocate
2671026817
** the requested memory region.
2671126818
*/
2671226819
if( !bExtend ) goto shmpage_out;
26713
- if( ftruncate(pShmNode->h, nByte) ){
26714
- rc = SQLITE_IOERR_SHMSIZE;
26820
+ if( robust_ftruncate(pShmNode->h, nByte) ){
26821
+ rc = unixLogError(SQLITE_IOERR_SHMSIZE,"ftruncate",pShmNode->zFilename);
2671526822
goto shmpage_out;
2671626823
}
2671726824
}
2671826825
2671926826
/* Map the requested memory region into this processes address space. */
@@ -27428,11 +27535,11 @@
2742827535
#endif
2742927536
OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
2743027537
}
2743127538
}
2743227539
*pFd = fd;
27433
- return (fd>=0?SQLITE_OK:SQLITE_CANTOPEN_BKPT);
27540
+ return (fd>=0?SQLITE_OK:unixLogError(SQLITE_CANTOPEN_BKPT, "open", zDirname));
2743427541
}
2743527542
2743627543
/*
2743727544
** Return the name of a directory in which to put temporary files.
2743827545
** If no suitable temporary file directory can be found, return NULL.
@@ -27769,11 +27876,11 @@
2776927876
flags |= SQLITE_OPEN_READONLY;
2777027877
openFlags |= O_RDONLY;
2777127878
fd = open(zName, openFlags, openMode);
2777227879
}
2777327880
if( fd<0 ){
27774
- rc = SQLITE_CANTOPEN_BKPT;
27881
+ rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
2777527882
goto open_finished;
2777627883
}
2777727884
}
2777827885
assert( fd>=0 );
2777927886
if( pOutFlags ){
@@ -27901,11 +28008,11 @@
2790128008
){
2790228009
int rc = SQLITE_OK;
2790328010
UNUSED_PARAMETER(NotUsed);
2790428011
SimulateIOError(return SQLITE_IOERR_DELETE);
2790528012
if( unlink(zPath)==(-1) && errno!=ENOENT ){
27906
- return SQLITE_IOERR_DELETE;
28013
+ return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
2790728014
}
2790828015
#ifndef SQLITE_DISABLE_DIRSYNC
2790928016
if( dirSync ){
2791028017
int fd;
2791128018
rc = openDirectory(zPath, &fd);
@@ -27914,14 +28021,14 @@
2791428021
if( fsync(fd)==-1 )
2791528022
#else
2791628023
if( fsync(fd) )
2791728024
#endif
2791828025
{
27919
- rc = SQLITE_IOERR_DIR_FSYNC;
28026
+ rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
2792028027
}
2792128028
if( close(fd)&&!rc ){
27922
- rc = SQLITE_IOERR_DIR_CLOSE;
28029
+ rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath);
2792328030
}
2792428031
}
2792528032
}
2792628033
#endif
2792728034
return rc;
@@ -28001,11 +28108,11 @@
2800128108
if( zPath[0]=='/' ){
2800228109
sqlite3_snprintf(nOut, zOut, "%s", zPath);
2800328110
}else{
2800428111
int nCwd;
2800528112
if( getcwd(zOut, nOut-1)==0 ){
28006
- return SQLITE_CANTOPEN_BKPT;
28113
+ return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
2800728114
}
2800828115
nCwd = (int)strlen(zOut);
2800928116
sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
2801028117
}
2801128118
return SQLITE_OK;
@@ -28105,11 +28212,11 @@
2810528212
pid = getpid();
2810628213
memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
2810728214
assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
2810828215
nBuf = sizeof(t) + sizeof(pid);
2810928216
}else{
28110
- nBuf = read(fd, zBuf, nBuf);
28217
+ do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
2811128218
close(fd);
2811228219
}
2811328220
}
2811428221
#endif
2811528222
return nBuf;
@@ -28866,27 +28973,31 @@
2886628973
strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN);
2886728974
}else{
2886828975
strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
2886928976
}
2887028977
writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
28871
- ftruncate(conchFile->h, writeSize);
28978
+ robust_ftruncate(conchFile->h, writeSize);
2887228979
rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
2887328980
fsync(conchFile->h);
2887428981
/* If we created a new conch file (not just updated the contents of a
2887528982
** valid conch file), try to match the permissions of the database
2887628983
*/
2887728984
if( rc==SQLITE_OK && createConch ){
2887828985
struct stat buf;
28986
+ int rc;
2887928987
int err = fstat(pFile->h, &buf);
2888028988
if( err==0 ){
2888128989
mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
2888228990
S_IROTH|S_IWOTH);
2888328991
/* try to match the database file R/W permissions, ignore failure */
2888428992
#ifndef SQLITE_PROXY_DEBUG
2888528993
fchmod(conchFile->h, cmode);
2888628994
#else
28887
- if( fchmod(conchFile->h, cmode)!=0 ){
28995
+ do{
28996
+ rc = fchmod(conchFile->h, cmode);
28997
+ }while( rc==(-1) && errno==EINTR );
28998
+ if( rc!=0 ){
2888828999
int code = errno;
2888929000
fprintf(stderr, "fchmod %o FAILED with %d %s\n",
2889029001
cmode, code, strerror(code));
2889129002
} else {
2889229003
fprintf(stderr, "fchmod %o SUCCEDED\n",cmode);
@@ -41641,12 +41752,12 @@
4164141752
int rc; /* Return code */
4164241753
4164341754
assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
4164441755
rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
4164541756
if( rc!=SQLITE_OK ){
41646
- /* If the attempt to grab the pending lock failed, release the
41647
- ** exclusive lock that may have been obtained instead. */
41757
+ /* If the attempt to grab the exclusive lock failed, release the
41758
+ ** pending lock that may have been obtained instead. */
4164841759
pagerUnlockDb(pPager, SHARED_LOCK);
4164941760
}
4165041761
4165141762
return rc;
4165241763
}
@@ -63784,11 +63895,11 @@
6378463895
*/
6378563896
if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
6378663897
sqlite3ResetInternalSchema(db, pOp->p1);
6378763898
}
6378863899
63789
- sqlite3ExpirePreparedStatements(db);
63900
+ p->expired = 1;
6379063901
rc = SQLITE_SCHEMA;
6379163902
}
6379263903
break;
6379363904
}
6379463905
@@ -91936,10 +92047,36 @@
9193692047
}
9193792048
pAggInfo->directMode = 0;
9193892049
sqlite3ExprCacheClear(pParse);
9193992050
}
9194092051
92052
+/*
92053
+** Add a single OP_Explain instruction to the VDBE to explain a simple
92054
+** count(*) query ("SELECT count(*) FROM pTab").
92055
+*/
92056
+#ifndef SQLITE_OMIT_EXPLAIN
92057
+static void explainSimpleCount(
92058
+ Parse *pParse, /* Parse context */
92059
+ Table *pTab, /* Table being queried */
92060
+ Index *pIdx /* Index used to optimize scan, or NULL */
92061
+){
92062
+ if( pParse->explain==2 ){
92063
+ char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s %s%s(~%d rows)",
92064
+ pTab->zName,
92065
+ pIdx ? "USING COVERING INDEX " : "",
92066
+ pIdx ? pIdx->zName : "",
92067
+ pTab->nRowEst
92068
+ );
92069
+ sqlite3VdbeAddOp4(
92070
+ pParse->pVdbe, OP_Explain, pParse->iSelectId, 0, 0, zEqp, P4_DYNAMIC
92071
+ );
92072
+ }
92073
+}
92074
+#else
92075
+# define explainSimpleCount(a,b,c)
92076
+#endif
92077
+
9194192078
/*
9194292079
** Generate code for the SELECT statement given in the p argument.
9194392080
**
9194492081
** The results are distributed in various ways depending on the
9194592082
** contents of the SelectDest structure pointed to by argument pDest
@@ -92547,10 +92684,11 @@
9254792684
if( pKeyInfo ){
9254892685
sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
9254992686
}
9255092687
sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
9255192688
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
92689
+ explainSimpleCount(pParse, pTab, pBest);
9255292690
}else
9255392691
#endif /* SQLITE_OMIT_BTREECOUNT */
9255492692
{
9255592693
/* Check if the query is of one of the following forms:
9255692694
**
@@ -107389,11 +107527,12 @@
107389107527
/* Remove harmful bits from the flags parameter
107390107528
**
107391107529
** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
107392107530
** dealt with in the previous code block. Besides these, the only
107393107531
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
107394
- ** SQLITE_OPEN_READWRITE, and SQLITE_OPEN_CREATE. Silently mask
107532
+ ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
107533
+ ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
107395107534
** off all other flags.
107396107535
*/
107397107536
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
107398107537
SQLITE_OPEN_EXCLUSIVE |
107399107538
SQLITE_OPEN_MAIN_DB |
107400107539
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-02-19 23:18:12 e87d499a4f8a456111c1f96ca6da31d0810fb7c8"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1023,10 +1023,12 @@
1023 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
1024 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
1025 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
1026 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
1027 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
 
 
1028
1029 /*
1030 ** CAPI3REF: Device Characteristics
1031 **
1032 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -23557,10 +23559,23 @@
23557 }
23558 #define fcntl lockTrace
23559 #endif /* SQLITE_LOCK_TRACE */
23560
23561
 
 
 
 
 
 
 
 
 
 
 
 
 
23562
23563 /*
23564 ** This routine translates a standard POSIX errno code into something
23565 ** useful to the clients of the sqlite3 functions. Specifically, it is
23566 ** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23898,10 +23913,79 @@
23898
23899 /*
23900 ** A lists of all unixInodeInfo objects.
23901 */
23902 static unixInodeInfo *inodeList = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23903
23904 /*
23905 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
23906 ** If all such file descriptors are closed without error, the list is
23907 ** cleared and SQLITE_OK returned.
@@ -23918,11 +24002,11 @@
23918 UnixUnusedFd *pNext;
23919 for(p=pInode->pUnused; p; p=pNext){
23920 pNext = p->pNext;
23921 if( close(p->fd) ){
23922 pFile->lastErrno = errno;
23923 rc = SQLITE_IOERR_CLOSE;
23924 p->pNext = pError;
23925 pError = p;
23926 }else{
23927 sqlite3_free(p);
23928 }
@@ -24006,11 +24090,11 @@
24006 ** in the header of every SQLite database. In this way, if there
24007 ** is a race condition such that another thread has already populated
24008 ** the first page of the database, no damage is done.
24009 */
24010 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24011 rc = write(fd, "S", 1);
24012 if( rc!=1 ){
24013 pFile->lastErrno = errno;
24014 return SQLITE_IOERR;
24015 }
24016 rc = fstat(fd, &statbuf);
@@ -24428,10 +24512,15 @@
24428 ** 2: [....W]
24429 ** 3: [RRRRW]
24430 ** 4: [RRRR.]
24431 */
24432 if( eFileLock==SHARED_LOCK ){
 
 
 
 
 
24433 if( handleNFSUnlock ){
24434 off_t divSize = SHARED_SIZE - 1;
24435
24436 lock.l_type = F_UNLCK;
24437 lock.l_whence = SEEK_SET;
@@ -24467,11 +24556,13 @@
24467 if( IS_LOCK_ERROR(rc) ){
24468 pFile->lastErrno = tErrno;
24469 }
24470 goto end_unlock;
24471 }
24472 }else{
 
 
24473 lock.l_type = F_RDLCK;
24474 lock.l_whence = SEEK_SET;
24475 lock.l_start = SHARED_FIRST;
24476 lock.l_len = SHARED_SIZE;
24477 if( fcntl(h, F_SETLK, &lock)==(-1) ){
@@ -24571,20 +24662,20 @@
24571 if( pFile ){
24572 if( pFile->dirfd>=0 ){
24573 int err = close(pFile->dirfd);
24574 if( err ){
24575 pFile->lastErrno = errno;
24576 return SQLITE_IOERR_DIR_CLOSE;
24577 }else{
24578 pFile->dirfd=-1;
24579 }
24580 }
24581 if( pFile->h>=0 ){
24582 int err = close(pFile->h);
24583 if( err ){
24584 pFile->lastErrno = errno;
24585 return SQLITE_IOERR_CLOSE;
24586 }
24587 }
24588 #if OS_VXWORKS
24589 if( pFile->pId ){
24590 if( pFile->isDelete ){
@@ -24882,10 +24973,24 @@
24882 ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if
24883 ** compiling for VXWORKS.
24884 */
24885 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
24886
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24887 /*
24888 ** This routine checks if there is a RESERVED lock held on the specified
24889 ** file by this or any other process. If such a lock is held, set *pResOut
24890 ** to a non-zero value otherwise *pResOut is set to zero. The return value
24891 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
@@ -24905,14 +25010,14 @@
24905 }
24906
24907 /* Otherwise see if some other process holds it. */
24908 if( !reserved ){
24909 /* attempt to get the lock */
24910 int lrc = flock(pFile->h, LOCK_EX | LOCK_NB);
24911 if( !lrc ){
24912 /* got the lock, unlock it */
24913 lrc = flock(pFile->h, LOCK_UN);
24914 if ( lrc ) {
24915 int tErrno = errno;
24916 /* unlock failed with an error */
24917 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24918 if( IS_LOCK_ERROR(lrc) ){
@@ -24985,11 +25090,11 @@
24985 return SQLITE_OK;
24986 }
24987
24988 /* grab an exclusive lock */
24989
24990 if (flock(pFile->h, LOCK_EX | LOCK_NB)) {
24991 int tErrno = errno;
24992 /* didn't get, must be busy */
24993 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
24994 if( IS_LOCK_ERROR(rc) ){
24995 pFile->lastErrno = tErrno;
@@ -25034,11 +25139,11 @@
25034 pFile->eFileLock = eFileLock;
25035 return SQLITE_OK;
25036 }
25037
25038 /* no, really, unlock. */
25039 int rc = flock(pFile->h, LOCK_UN);
25040 if (rc) {
25041 int r, tErrno = errno;
25042 r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
25043 if( IS_LOCK_ERROR(r) ){
25044 pFile->lastErrno = tErrno;
@@ -25771,14 +25876,14 @@
25771 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
25772 i64 newOffset;
25773 #endif
25774 TIMER_START;
25775 #if defined(USE_PREAD)
25776 got = pread(id->h, pBuf, cnt, offset);
25777 SimulateIOError( got = -1 );
25778 #elif defined(USE_PREAD64)
25779 got = pread64(id->h, pBuf, cnt, offset);
25780 SimulateIOError( got = -1 );
25781 #else
25782 newOffset = lseek(id->h, offset, SEEK_SET);
25783 SimulateIOError( newOffset-- );
25784 if( newOffset!=offset ){
@@ -25787,11 +25892,11 @@
25787 }else{
25788 ((unixFile*)id)->lastErrno = 0;
25789 }
25790 return -1;
25791 }
25792 got = read(id->h, pBuf, cnt);
25793 #endif
25794 TIMER_END;
25795 if( got<0 ){
25796 ((unixFile*)id)->lastErrno = errno;
25797 }
@@ -25849,13 +25954,13 @@
25849 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
25850 i64 newOffset;
25851 #endif
25852 TIMER_START;
25853 #if defined(USE_PREAD)
25854 got = pwrite(id->h, pBuf, cnt, offset);
25855 #elif defined(USE_PREAD64)
25856 got = pwrite64(id->h, pBuf, cnt, offset);
25857 #else
25858 newOffset = lseek(id->h, offset, SEEK_SET);
25859 if( newOffset!=offset ){
25860 if( newOffset == -1 ){
25861 ((unixFile*)id)->lastErrno = errno;
@@ -25862,11 +25967,11 @@
25862 }else{
25863 ((unixFile*)id)->lastErrno = 0;
25864 }
25865 return -1;
25866 }
25867 got = write(id->h, pBuf, cnt);
25868 #endif
25869 TIMER_END;
25870 if( got<0 ){
25871 ((unixFile*)id)->lastErrno = errno;
25872 }
@@ -26102,11 +26207,11 @@
26102 OSTRACE(("SYNC %-3d\n", pFile->h));
26103 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
26104 SimulateIOError( rc=1 );
26105 if( rc ){
26106 pFile->lastErrno = errno;
26107 return SQLITE_IOERR_FSYNC;
26108 }
26109 if( pFile->dirfd>=0 ){
26110 int err;
26111 OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
26112 HAVE_FULLFSYNC, isFullsync));
@@ -26129,11 +26234,11 @@
26129 err = close(pFile->dirfd); /* Only need to sync once, so close the */
26130 if( err==0 ){ /* directory when we are done */
26131 pFile->dirfd = -1;
26132 }else{
26133 pFile->lastErrno = errno;
26134 rc = SQLITE_IOERR_DIR_CLOSE;
26135 }
26136 }
26137 return rc;
26138 }
26139
@@ -26153,14 +26258,14 @@
26153 */
26154 if( pFile->szChunk ){
26155 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
26156 }
26157
26158 rc = ftruncate(pFile->h, (off_t)nByte);
26159 if( rc ){
26160 pFile->lastErrno = errno;
26161 return SQLITE_IOERR_TRUNCATE;
26162 }else{
26163 #ifndef NDEBUG
26164 /* If we are doing a normal write to a database file (as opposed to
26165 ** doing a hot-journal rollback or a write to some file other than a
26166 ** normal database file) and we truncate the file to zero length,
@@ -26228,13 +26333,15 @@
26228 if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
26229
26230 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
26231 if( nSize>(i64)buf.st_size ){
26232 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
26233 if( posix_fallocate(pFile->h, buf.st_size, nSize-buf.st_size) ){
26234 return SQLITE_IOERR_WRITE;
26235 }
 
 
26236 #else
26237 /* If the OS does not have posix_fallocate(), fake it. First use
26238 ** ftruncate() to set the file size, then write a single byte to
26239 ** the last byte in each block within the extended region. This
26240 ** is the same technique used by glibc to implement posix_fallocate()
@@ -26242,13 +26349,13 @@
26242 */
26243 int nBlk = buf.st_blksize; /* File-system block size */
26244 i64 iWrite; /* Next offset to write to */
26245 int nWrite; /* Return value from seekAndWrite() */
26246
26247 if( ftruncate(pFile->h, nSize) ){
26248 pFile->lastErrno = errno;
26249 return SQLITE_IOERR_TRUNCATE;
26250 }
26251 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
26252 do {
26253 nWrite = seekAndWrite(pFile, iWrite, "", 1);
26254 iWrite += nBlk;
@@ -26593,21 +26700,21 @@
26593 goto shm_open_err;
26594 }
26595
26596 pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
26597 if( pShmNode->h<0 ){
26598 rc = SQLITE_CANTOPEN_BKPT;
26599 goto shm_open_err;
26600 }
26601
26602 /* Check to see if another process is holding the dead-man switch.
26603 ** If not, truncate the file to zero length.
26604 */
26605 rc = SQLITE_OK;
26606 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
26607 if( ftruncate(pShmNode->h, 0) ){
26608 rc = SQLITE_IOERR_SHMOPEN;
26609 }
26610 }
26611 if( rc==SQLITE_OK ){
26612 rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
26613 }
@@ -26708,12 +26815,12 @@
26708 **
26709 ** Alternatively, if bExtend is true, use ftruncate() to allocate
26710 ** the requested memory region.
26711 */
26712 if( !bExtend ) goto shmpage_out;
26713 if( ftruncate(pShmNode->h, nByte) ){
26714 rc = SQLITE_IOERR_SHMSIZE;
26715 goto shmpage_out;
26716 }
26717 }
26718
26719 /* Map the requested memory region into this processes address space. */
@@ -27428,11 +27535,11 @@
27428 #endif
27429 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
27430 }
27431 }
27432 *pFd = fd;
27433 return (fd>=0?SQLITE_OK:SQLITE_CANTOPEN_BKPT);
27434 }
27435
27436 /*
27437 ** Return the name of a directory in which to put temporary files.
27438 ** If no suitable temporary file directory can be found, return NULL.
@@ -27769,11 +27876,11 @@
27769 flags |= SQLITE_OPEN_READONLY;
27770 openFlags |= O_RDONLY;
27771 fd = open(zName, openFlags, openMode);
27772 }
27773 if( fd<0 ){
27774 rc = SQLITE_CANTOPEN_BKPT;
27775 goto open_finished;
27776 }
27777 }
27778 assert( fd>=0 );
27779 if( pOutFlags ){
@@ -27901,11 +28008,11 @@
27901 ){
27902 int rc = SQLITE_OK;
27903 UNUSED_PARAMETER(NotUsed);
27904 SimulateIOError(return SQLITE_IOERR_DELETE);
27905 if( unlink(zPath)==(-1) && errno!=ENOENT ){
27906 return SQLITE_IOERR_DELETE;
27907 }
27908 #ifndef SQLITE_DISABLE_DIRSYNC
27909 if( dirSync ){
27910 int fd;
27911 rc = openDirectory(zPath, &fd);
@@ -27914,14 +28021,14 @@
27914 if( fsync(fd)==-1 )
27915 #else
27916 if( fsync(fd) )
27917 #endif
27918 {
27919 rc = SQLITE_IOERR_DIR_FSYNC;
27920 }
27921 if( close(fd)&&!rc ){
27922 rc = SQLITE_IOERR_DIR_CLOSE;
27923 }
27924 }
27925 }
27926 #endif
27927 return rc;
@@ -28001,11 +28108,11 @@
28001 if( zPath[0]=='/' ){
28002 sqlite3_snprintf(nOut, zOut, "%s", zPath);
28003 }else{
28004 int nCwd;
28005 if( getcwd(zOut, nOut-1)==0 ){
28006 return SQLITE_CANTOPEN_BKPT;
28007 }
28008 nCwd = (int)strlen(zOut);
28009 sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
28010 }
28011 return SQLITE_OK;
@@ -28105,11 +28212,11 @@
28105 pid = getpid();
28106 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28107 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28108 nBuf = sizeof(t) + sizeof(pid);
28109 }else{
28110 nBuf = read(fd, zBuf, nBuf);
28111 close(fd);
28112 }
28113 }
28114 #endif
28115 return nBuf;
@@ -28866,27 +28973,31 @@
28866 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN);
28867 }else{
28868 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
28869 }
28870 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
28871 ftruncate(conchFile->h, writeSize);
28872 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
28873 fsync(conchFile->h);
28874 /* If we created a new conch file (not just updated the contents of a
28875 ** valid conch file), try to match the permissions of the database
28876 */
28877 if( rc==SQLITE_OK && createConch ){
28878 struct stat buf;
 
28879 int err = fstat(pFile->h, &buf);
28880 if( err==0 ){
28881 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
28882 S_IROTH|S_IWOTH);
28883 /* try to match the database file R/W permissions, ignore failure */
28884 #ifndef SQLITE_PROXY_DEBUG
28885 fchmod(conchFile->h, cmode);
28886 #else
28887 if( fchmod(conchFile->h, cmode)!=0 ){
 
 
 
28888 int code = errno;
28889 fprintf(stderr, "fchmod %o FAILED with %d %s\n",
28890 cmode, code, strerror(code));
28891 } else {
28892 fprintf(stderr, "fchmod %o SUCCEDED\n",cmode);
@@ -41641,12 +41752,12 @@
41641 int rc; /* Return code */
41642
41643 assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
41644 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
41645 if( rc!=SQLITE_OK ){
41646 /* If the attempt to grab the pending lock failed, release the
41647 ** exclusive lock that may have been obtained instead. */
41648 pagerUnlockDb(pPager, SHARED_LOCK);
41649 }
41650
41651 return rc;
41652 }
@@ -63784,11 +63895,11 @@
63784 */
63785 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
63786 sqlite3ResetInternalSchema(db, pOp->p1);
63787 }
63788
63789 sqlite3ExpirePreparedStatements(db);
63790 rc = SQLITE_SCHEMA;
63791 }
63792 break;
63793 }
63794
@@ -91936,10 +92047,36 @@
91936 }
91937 pAggInfo->directMode = 0;
91938 sqlite3ExprCacheClear(pParse);
91939 }
91940
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91941 /*
91942 ** Generate code for the SELECT statement given in the p argument.
91943 **
91944 ** The results are distributed in various ways depending on the
91945 ** contents of the SelectDest structure pointed to by argument pDest
@@ -92547,10 +92684,11 @@
92547 if( pKeyInfo ){
92548 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
92549 }
92550 sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
92551 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
 
92552 }else
92553 #endif /* SQLITE_OMIT_BTREECOUNT */
92554 {
92555 /* Check if the query is of one of the following forms:
92556 **
@@ -107389,11 +107527,12 @@
107389 /* Remove harmful bits from the flags parameter
107390 **
107391 ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
107392 ** dealt with in the previous code block. Besides these, the only
107393 ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
107394 ** SQLITE_OPEN_READWRITE, and SQLITE_OPEN_CREATE. Silently mask
 
107395 ** off all other flags.
107396 */
107397 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
107398 SQLITE_OPEN_EXCLUSIVE |
107399 SQLITE_OPEN_MAIN_DB |
107400
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1023,10 +1023,12 @@
1023 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
1024 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
1025 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
1026 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
1027 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
1028
1029 /* Reserved: 0x00F00000 */
1030
1031 /*
1032 ** CAPI3REF: Device Characteristics
1033 **
1034 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -23557,10 +23559,23 @@
23559 }
23560 #define fcntl lockTrace
23561 #endif /* SQLITE_LOCK_TRACE */
23562
23563
23564 /*
23565 ** Retry ftruncate() calls that fail due to EINTR
23566 */
23567 #ifdef EINTR
23568 static int robust_ftruncate(int h, sqlite3_int64 sz){
23569 int rc;
23570 do{ rc = ftruncate(h,sz); }while( rc<0 && errno==EINTR );
23571 return rc;
23572 }
23573 #else
23574 # define robust_ftruncate(a,b) ftruncate(a,b)
23575 #endif
23576
23577
23578 /*
23579 ** This routine translates a standard POSIX errno code into something
23580 ** useful to the clients of the sqlite3 functions. Specifically, it is
23581 ** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23898,10 +23913,79 @@
23913
23914 /*
23915 ** A lists of all unixInodeInfo objects.
23916 */
23917 static unixInodeInfo *inodeList = 0;
23918
23919 /*
23920 **
23921 ** This function - unixLogError_x(), is only ever called via the macro
23922 ** unixLogError().
23923 **
23924 ** It is invoked after an error occurs in an OS function and errno has been
23925 ** set. It logs a message using sqlite3_log() containing the current value of
23926 ** errno and, if possible, the human-readable equivalent from strerror() or
23927 ** strerror_r().
23928 **
23929 ** The first argument passed to the macro should be the error code that
23930 ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
23931 ** The two subsequent arguments should be the name of the OS function that
23932 ** failed (e.g. "unlink", "open") and the the associated file-system path,
23933 ** if any.
23934 */
23935 #define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__)
23936 static int unixLogError_x(
23937 int errcode, /* SQLite error code */
23938 const char *zFunc, /* Name of OS function that failed */
23939 const char *zPath, /* File path associated with error */
23940 int iLine /* Source line number where error occurred */
23941 ){
23942 char *zErr; /* Message from strerror() or equivalent */
23943
23944 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
23945 ** the strerror() function to obtain the human-readable error message
23946 ** equivalent to errno. Otherwise, use strerror_r().
23947 */
23948 #if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R)
23949 char aErr[80];
23950 memset(aErr, 0, sizeof(aErr));
23951 zErr = aErr;
23952
23953 /* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
23954 ** assume that the system provides the the GNU version of strerror_r() that
23955 ** returns a pointer to a buffer containing the error message. That pointer
23956 ** may point to aErr[], or it may point to some static storage somewhere.
23957 ** Otherwise, assume that the system provides the POSIX version of
23958 ** strerror_r(), which always writes an error message into aErr[].
23959 **
23960 ** If the code incorrectly assumes that it is the POSIX version that is
23961 ** available, the error message will often be an empty string. Not a
23962 ** huge problem. Incorrectly concluding that the GNU version is available
23963 ** could lead to a segfault though.
23964 */
23965 #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
23966 zErr =
23967 # endif
23968 strerror_r(errno, aErr, sizeof(aErr)-1);
23969
23970 #elif SQLITE_THREADSAFE
23971 /* This is a threadsafe build, but strerror_r() is not available. */
23972 zErr = "";
23973 #else
23974 /* Non-threadsafe build, use strerror(). */
23975 zErr = strerror(errno);
23976 #endif
23977
23978 assert( errcode!=SQLITE_OK );
23979 sqlite3_log(errcode,
23980 "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s",
23981 zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a")
23982 );
23983
23984 return errcode;
23985 }
23986
23987
23988 /*
23989 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
23990 ** If all such file descriptors are closed without error, the list is
23991 ** cleared and SQLITE_OK returned.
@@ -23918,11 +24002,11 @@
24002 UnixUnusedFd *pNext;
24003 for(p=pInode->pUnused; p; p=pNext){
24004 pNext = p->pNext;
24005 if( close(p->fd) ){
24006 pFile->lastErrno = errno;
24007 rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24008 p->pNext = pError;
24009 pError = p;
24010 }else{
24011 sqlite3_free(p);
24012 }
@@ -24006,11 +24090,11 @@
24090 ** in the header of every SQLite database. In this way, if there
24091 ** is a race condition such that another thread has already populated
24092 ** the first page of the database, no damage is done.
24093 */
24094 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24095 do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR );
24096 if( rc!=1 ){
24097 pFile->lastErrno = errno;
24098 return SQLITE_IOERR;
24099 }
24100 rc = fstat(fd, &statbuf);
@@ -24428,10 +24512,15 @@
24512 ** 2: [....W]
24513 ** 3: [RRRRW]
24514 ** 4: [RRRR.]
24515 */
24516 if( eFileLock==SHARED_LOCK ){
24517
24518 #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
24519 assert( handleNFSUnlock==0 );
24520 #endif
24521 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24522 if( handleNFSUnlock ){
24523 off_t divSize = SHARED_SIZE - 1;
24524
24525 lock.l_type = F_UNLCK;
24526 lock.l_whence = SEEK_SET;
@@ -24467,11 +24556,13 @@
24556 if( IS_LOCK_ERROR(rc) ){
24557 pFile->lastErrno = tErrno;
24558 }
24559 goto end_unlock;
24560 }
24561 }else
24562 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
24563 {
24564 lock.l_type = F_RDLCK;
24565 lock.l_whence = SEEK_SET;
24566 lock.l_start = SHARED_FIRST;
24567 lock.l_len = SHARED_SIZE;
24568 if( fcntl(h, F_SETLK, &lock)==(-1) ){
@@ -24571,20 +24662,20 @@
24662 if( pFile ){
24663 if( pFile->dirfd>=0 ){
24664 int err = close(pFile->dirfd);
24665 if( err ){
24666 pFile->lastErrno = errno;
24667 return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
24668 }else{
24669 pFile->dirfd=-1;
24670 }
24671 }
24672 if( pFile->h>=0 ){
24673 int err = close(pFile->h);
24674 if( err ){
24675 pFile->lastErrno = errno;
24676 return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24677 }
24678 }
24679 #if OS_VXWORKS
24680 if( pFile->pId ){
24681 if( pFile->isDelete ){
@@ -24882,10 +24973,24 @@
24973 ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if
24974 ** compiling for VXWORKS.
24975 */
24976 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
24977
24978 /*
24979 ** Retry flock() calls that fail with EINTR
24980 */
24981 #ifdef EINTR
24982 static int robust_flock(int fd, int op){
24983 int rc;
24984 do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR );
24985 return rc;
24986 }
24987 #else
24988 # define robust_flock(a,b) flock(a,b)
24989 #endif
24990
24991
24992 /*
24993 ** This routine checks if there is a RESERVED lock held on the specified
24994 ** file by this or any other process. If such a lock is held, set *pResOut
24995 ** to a non-zero value otherwise *pResOut is set to zero. The return value
24996 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
@@ -24905,14 +25010,14 @@
25010 }
25011
25012 /* Otherwise see if some other process holds it. */
25013 if( !reserved ){
25014 /* attempt to get the lock */
25015 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
25016 if( !lrc ){
25017 /* got the lock, unlock it */
25018 lrc = robust_flock(pFile->h, LOCK_UN);
25019 if ( lrc ) {
25020 int tErrno = errno;
25021 /* unlock failed with an error */
25022 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
25023 if( IS_LOCK_ERROR(lrc) ){
@@ -24985,11 +25090,11 @@
25090 return SQLITE_OK;
25091 }
25092
25093 /* grab an exclusive lock */
25094
25095 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
25096 int tErrno = errno;
25097 /* didn't get, must be busy */
25098 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
25099 if( IS_LOCK_ERROR(rc) ){
25100 pFile->lastErrno = tErrno;
@@ -25034,11 +25139,11 @@
25139 pFile->eFileLock = eFileLock;
25140 return SQLITE_OK;
25141 }
25142
25143 /* no, really, unlock. */
25144 int rc = robust_flock(pFile->h, LOCK_UN);
25145 if (rc) {
25146 int r, tErrno = errno;
25147 r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
25148 if( IS_LOCK_ERROR(r) ){
25149 pFile->lastErrno = tErrno;
@@ -25771,14 +25876,14 @@
25876 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
25877 i64 newOffset;
25878 #endif
25879 TIMER_START;
25880 #if defined(USE_PREAD)
25881 do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25882 SimulateIOError( got = -1 );
25883 #elif defined(USE_PREAD64)
25884 do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25885 SimulateIOError( got = -1 );
25886 #else
25887 newOffset = lseek(id->h, offset, SEEK_SET);
25888 SimulateIOError( newOffset-- );
25889 if( newOffset!=offset ){
@@ -25787,11 +25892,11 @@
25892 }else{
25893 ((unixFile*)id)->lastErrno = 0;
25894 }
25895 return -1;
25896 }
25897 do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
25898 #endif
25899 TIMER_END;
25900 if( got<0 ){
25901 ((unixFile*)id)->lastErrno = errno;
25902 }
@@ -25849,13 +25954,13 @@
25954 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
25955 i64 newOffset;
25956 #endif
25957 TIMER_START;
25958 #if defined(USE_PREAD)
25959 do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25960 #elif defined(USE_PREAD64)
25961 do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25962 #else
25963 newOffset = lseek(id->h, offset, SEEK_SET);
25964 if( newOffset!=offset ){
25965 if( newOffset == -1 ){
25966 ((unixFile*)id)->lastErrno = errno;
@@ -25862,11 +25967,11 @@
25967 }else{
25968 ((unixFile*)id)->lastErrno = 0;
25969 }
25970 return -1;
25971 }
25972 do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
25973 #endif
25974 TIMER_END;
25975 if( got<0 ){
25976 ((unixFile*)id)->lastErrno = errno;
25977 }
@@ -26102,11 +26207,11 @@
26207 OSTRACE(("SYNC %-3d\n", pFile->h));
26208 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
26209 SimulateIOError( rc=1 );
26210 if( rc ){
26211 pFile->lastErrno = errno;
26212 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
26213 }
26214 if( pFile->dirfd>=0 ){
26215 int err;
26216 OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
26217 HAVE_FULLFSYNC, isFullsync));
@@ -26129,11 +26234,11 @@
26234 err = close(pFile->dirfd); /* Only need to sync once, so close the */
26235 if( err==0 ){ /* directory when we are done */
26236 pFile->dirfd = -1;
26237 }else{
26238 pFile->lastErrno = errno;
26239 rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
26240 }
26241 }
26242 return rc;
26243 }
26244
@@ -26153,14 +26258,14 @@
26258 */
26259 if( pFile->szChunk ){
26260 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
26261 }
26262
26263 rc = robust_ftruncate(pFile->h, (off_t)nByte);
26264 if( rc ){
26265 pFile->lastErrno = errno;
26266 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
26267 }else{
26268 #ifndef NDEBUG
26269 /* If we are doing a normal write to a database file (as opposed to
26270 ** doing a hot-journal rollback or a write to some file other than a
26271 ** normal database file) and we truncate the file to zero length,
@@ -26228,13 +26333,15 @@
26333 if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
26334
26335 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
26336 if( nSize>(i64)buf.st_size ){
26337 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
26338 int rc;
26339 do{
26340 rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size;
26341 }while( rc<0 && errno=EINTR );
26342 if( rc ) return SQLITE_IOERR_WRITE;
26343 #else
26344 /* If the OS does not have posix_fallocate(), fake it. First use
26345 ** ftruncate() to set the file size, then write a single byte to
26346 ** the last byte in each block within the extended region. This
26347 ** is the same technique used by glibc to implement posix_fallocate()
@@ -26242,13 +26349,13 @@
26349 */
26350 int nBlk = buf.st_blksize; /* File-system block size */
26351 i64 iWrite; /* Next offset to write to */
26352 int nWrite; /* Return value from seekAndWrite() */
26353
26354 if( robust_ftruncate(pFile->h, nSize) ){
26355 pFile->lastErrno = errno;
26356 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
26357 }
26358 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
26359 do {
26360 nWrite = seekAndWrite(pFile, iWrite, "", 1);
26361 iWrite += nBlk;
@@ -26593,21 +26700,21 @@
26700 goto shm_open_err;
26701 }
26702
26703 pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
26704 if( pShmNode->h<0 ){
26705 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
26706 goto shm_open_err;
26707 }
26708
26709 /* Check to see if another process is holding the dead-man switch.
26710 ** If not, truncate the file to zero length.
26711 */
26712 rc = SQLITE_OK;
26713 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
26714 if( robust_ftruncate(pShmNode->h, 0) ){
26715 rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
26716 }
26717 }
26718 if( rc==SQLITE_OK ){
26719 rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
26720 }
@@ -26708,12 +26815,12 @@
26815 **
26816 ** Alternatively, if bExtend is true, use ftruncate() to allocate
26817 ** the requested memory region.
26818 */
26819 if( !bExtend ) goto shmpage_out;
26820 if( robust_ftruncate(pShmNode->h, nByte) ){
26821 rc = unixLogError(SQLITE_IOERR_SHMSIZE,"ftruncate",pShmNode->zFilename);
26822 goto shmpage_out;
26823 }
26824 }
26825
26826 /* Map the requested memory region into this processes address space. */
@@ -27428,11 +27535,11 @@
27535 #endif
27536 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
27537 }
27538 }
27539 *pFd = fd;
27540 return (fd>=0?SQLITE_OK:unixLogError(SQLITE_CANTOPEN_BKPT, "open", zDirname));
27541 }
27542
27543 /*
27544 ** Return the name of a directory in which to put temporary files.
27545 ** If no suitable temporary file directory can be found, return NULL.
@@ -27769,11 +27876,11 @@
27876 flags |= SQLITE_OPEN_READONLY;
27877 openFlags |= O_RDONLY;
27878 fd = open(zName, openFlags, openMode);
27879 }
27880 if( fd<0 ){
27881 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
27882 goto open_finished;
27883 }
27884 }
27885 assert( fd>=0 );
27886 if( pOutFlags ){
@@ -27901,11 +28008,11 @@
28008 ){
28009 int rc = SQLITE_OK;
28010 UNUSED_PARAMETER(NotUsed);
28011 SimulateIOError(return SQLITE_IOERR_DELETE);
28012 if( unlink(zPath)==(-1) && errno!=ENOENT ){
28013 return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
28014 }
28015 #ifndef SQLITE_DISABLE_DIRSYNC
28016 if( dirSync ){
28017 int fd;
28018 rc = openDirectory(zPath, &fd);
@@ -27914,14 +28021,14 @@
28021 if( fsync(fd)==-1 )
28022 #else
28023 if( fsync(fd) )
28024 #endif
28025 {
28026 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
28027 }
28028 if( close(fd)&&!rc ){
28029 rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath);
28030 }
28031 }
28032 }
28033 #endif
28034 return rc;
@@ -28001,11 +28108,11 @@
28108 if( zPath[0]=='/' ){
28109 sqlite3_snprintf(nOut, zOut, "%s", zPath);
28110 }else{
28111 int nCwd;
28112 if( getcwd(zOut, nOut-1)==0 ){
28113 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
28114 }
28115 nCwd = (int)strlen(zOut);
28116 sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
28117 }
28118 return SQLITE_OK;
@@ -28105,11 +28212,11 @@
28212 pid = getpid();
28213 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28214 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28215 nBuf = sizeof(t) + sizeof(pid);
28216 }else{
28217 do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28218 close(fd);
28219 }
28220 }
28221 #endif
28222 return nBuf;
@@ -28866,27 +28973,31 @@
28973 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN);
28974 }else{
28975 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
28976 }
28977 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
28978 robust_ftruncate(conchFile->h, writeSize);
28979 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
28980 fsync(conchFile->h);
28981 /* If we created a new conch file (not just updated the contents of a
28982 ** valid conch file), try to match the permissions of the database
28983 */
28984 if( rc==SQLITE_OK && createConch ){
28985 struct stat buf;
28986 int rc;
28987 int err = fstat(pFile->h, &buf);
28988 if( err==0 ){
28989 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
28990 S_IROTH|S_IWOTH);
28991 /* try to match the database file R/W permissions, ignore failure */
28992 #ifndef SQLITE_PROXY_DEBUG
28993 fchmod(conchFile->h, cmode);
28994 #else
28995 do{
28996 rc = fchmod(conchFile->h, cmode);
28997 }while( rc==(-1) && errno==EINTR );
28998 if( rc!=0 ){
28999 int code = errno;
29000 fprintf(stderr, "fchmod %o FAILED with %d %s\n",
29001 cmode, code, strerror(code));
29002 } else {
29003 fprintf(stderr, "fchmod %o SUCCEDED\n",cmode);
@@ -41641,12 +41752,12 @@
41752 int rc; /* Return code */
41753
41754 assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
41755 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
41756 if( rc!=SQLITE_OK ){
41757 /* If the attempt to grab the exclusive lock failed, release the
41758 ** pending lock that may have been obtained instead. */
41759 pagerUnlockDb(pPager, SHARED_LOCK);
41760 }
41761
41762 return rc;
41763 }
@@ -63784,11 +63895,11 @@
63895 */
63896 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
63897 sqlite3ResetInternalSchema(db, pOp->p1);
63898 }
63899
63900 p->expired = 1;
63901 rc = SQLITE_SCHEMA;
63902 }
63903 break;
63904 }
63905
@@ -91936,10 +92047,36 @@
92047 }
92048 pAggInfo->directMode = 0;
92049 sqlite3ExprCacheClear(pParse);
92050 }
92051
92052 /*
92053 ** Add a single OP_Explain instruction to the VDBE to explain a simple
92054 ** count(*) query ("SELECT count(*) FROM pTab").
92055 */
92056 #ifndef SQLITE_OMIT_EXPLAIN
92057 static void explainSimpleCount(
92058 Parse *pParse, /* Parse context */
92059 Table *pTab, /* Table being queried */
92060 Index *pIdx /* Index used to optimize scan, or NULL */
92061 ){
92062 if( pParse->explain==2 ){
92063 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s %s%s(~%d rows)",
92064 pTab->zName,
92065 pIdx ? "USING COVERING INDEX " : "",
92066 pIdx ? pIdx->zName : "",
92067 pTab->nRowEst
92068 );
92069 sqlite3VdbeAddOp4(
92070 pParse->pVdbe, OP_Explain, pParse->iSelectId, 0, 0, zEqp, P4_DYNAMIC
92071 );
92072 }
92073 }
92074 #else
92075 # define explainSimpleCount(a,b,c)
92076 #endif
92077
92078 /*
92079 ** Generate code for the SELECT statement given in the p argument.
92080 **
92081 ** The results are distributed in various ways depending on the
92082 ** contents of the SelectDest structure pointed to by argument pDest
@@ -92547,10 +92684,11 @@
92684 if( pKeyInfo ){
92685 sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
92686 }
92687 sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
92688 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
92689 explainSimpleCount(pParse, pTab, pBest);
92690 }else
92691 #endif /* SQLITE_OMIT_BTREECOUNT */
92692 {
92693 /* Check if the query is of one of the following forms:
92694 **
@@ -107389,11 +107527,12 @@
107527 /* Remove harmful bits from the flags parameter
107528 **
107529 ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
107530 ** dealt with in the previous code block. Besides these, the only
107531 ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
107532 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
107533 ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
107534 ** off all other flags.
107535 */
107536 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
107537 SQLITE_OPEN_EXCLUSIVE |
107538 SQLITE_OPEN_MAIN_DB |
107539
+3 -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.6"
111111
#define SQLITE_VERSION_NUMBER 3007006
112
-#define SQLITE_SOURCE_ID "2011-02-19 23:18:12 e87d499a4f8a456111c1f96ca6da31d0810fb7c8"
112
+#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -480,10 +480,12 @@
480480
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
481481
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
482482
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
483483
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
484484
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
485
+
486
+/* Reserved: 0x00F00000 */
485487
486488
/*
487489
** CAPI3REF: Device Characteristics
488490
**
489491
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
490492
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-02-19 23:18:12 e87d499a4f8a456111c1f96ca6da31d0810fb7c8"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -480,10 +480,12 @@
480 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
481 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
482 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
483 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
484 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
 
 
485
486 /*
487 ** CAPI3REF: Device Characteristics
488 **
489 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
490
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -480,10 +480,12 @@
480 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
481 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
482 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
483 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
484 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
485
486 /* Reserved: 0x00F00000 */
487
488 /*
489 ** CAPI3REF: Device Characteristics
490 **
491 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
492

Keyboard Shortcuts

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