Fossil SCM
Update the built-in version of SQLite to the lastest in the stable trunk version.
Commit
4cd9309c508373c6aa4a371941835bd1512c5ac2
Parent
769e3d8e56a30ff…
2 files changed
+182
-43
+3
-1
+182
-43
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -650,11 +650,11 @@ | ||
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 652 | */ |
| 653 | 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | 654 | #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" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -1023,10 +1023,12 @@ | ||
| 1023 | 1023 | #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
| 1024 | 1024 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 1025 | 1025 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 1026 | 1026 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 1027 | 1027 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 1028 | + | |
| 1029 | +/* Reserved: 0x00F00000 */ | |
| 1028 | 1030 | |
| 1029 | 1031 | /* |
| 1030 | 1032 | ** CAPI3REF: Device Characteristics |
| 1031 | 1033 | ** |
| 1032 | 1034 | ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
| @@ -23557,10 +23559,23 @@ | ||
| 23557 | 23559 | } |
| 23558 | 23560 | #define fcntl lockTrace |
| 23559 | 23561 | #endif /* SQLITE_LOCK_TRACE */ |
| 23560 | 23562 | |
| 23561 | 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 | + | |
| 23562 | 23577 | |
| 23563 | 23578 | /* |
| 23564 | 23579 | ** This routine translates a standard POSIX errno code into something |
| 23565 | 23580 | ** useful to the clients of the sqlite3 functions. Specifically, it is |
| 23566 | 23581 | ** intended to translate a variety of "try again" errors into SQLITE_BUSY |
| @@ -23898,10 +23913,79 @@ | ||
| 23898 | 23913 | |
| 23899 | 23914 | /* |
| 23900 | 23915 | ** A lists of all unixInodeInfo objects. |
| 23901 | 23916 | */ |
| 23902 | 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 | + | |
| 23903 | 23987 | |
| 23904 | 23988 | /* |
| 23905 | 23989 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. |
| 23906 | 23990 | ** If all such file descriptors are closed without error, the list is |
| 23907 | 23991 | ** cleared and SQLITE_OK returned. |
| @@ -23918,11 +24002,11 @@ | ||
| 23918 | 24002 | UnixUnusedFd *pNext; |
| 23919 | 24003 | for(p=pInode->pUnused; p; p=pNext){ |
| 23920 | 24004 | pNext = p->pNext; |
| 23921 | 24005 | if( close(p->fd) ){ |
| 23922 | 24006 | pFile->lastErrno = errno; |
| 23923 | - rc = SQLITE_IOERR_CLOSE; | |
| 24007 | + rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); | |
| 23924 | 24008 | p->pNext = pError; |
| 23925 | 24009 | pError = p; |
| 23926 | 24010 | }else{ |
| 23927 | 24011 | sqlite3_free(p); |
| 23928 | 24012 | } |
| @@ -24006,11 +24090,11 @@ | ||
| 24006 | 24090 | ** in the header of every SQLite database. In this way, if there |
| 24007 | 24091 | ** is a race condition such that another thread has already populated |
| 24008 | 24092 | ** the first page of the database, no damage is done. |
| 24009 | 24093 | */ |
| 24010 | 24094 | 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 ); | |
| 24012 | 24096 | if( rc!=1 ){ |
| 24013 | 24097 | pFile->lastErrno = errno; |
| 24014 | 24098 | return SQLITE_IOERR; |
| 24015 | 24099 | } |
| 24016 | 24100 | rc = fstat(fd, &statbuf); |
| @@ -24428,10 +24512,15 @@ | ||
| 24428 | 24512 | ** 2: [....W] |
| 24429 | 24513 | ** 3: [RRRRW] |
| 24430 | 24514 | ** 4: [RRRR.] |
| 24431 | 24515 | */ |
| 24432 | 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 | |
| 24433 | 24522 | if( handleNFSUnlock ){ |
| 24434 | 24523 | off_t divSize = SHARED_SIZE - 1; |
| 24435 | 24524 | |
| 24436 | 24525 | lock.l_type = F_UNLCK; |
| 24437 | 24526 | lock.l_whence = SEEK_SET; |
| @@ -24467,11 +24556,13 @@ | ||
| 24467 | 24556 | if( IS_LOCK_ERROR(rc) ){ |
| 24468 | 24557 | pFile->lastErrno = tErrno; |
| 24469 | 24558 | } |
| 24470 | 24559 | goto end_unlock; |
| 24471 | 24560 | } |
| 24472 | - }else{ | |
| 24561 | + }else | |
| 24562 | +#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | |
| 24563 | + { | |
| 24473 | 24564 | lock.l_type = F_RDLCK; |
| 24474 | 24565 | lock.l_whence = SEEK_SET; |
| 24475 | 24566 | lock.l_start = SHARED_FIRST; |
| 24476 | 24567 | lock.l_len = SHARED_SIZE; |
| 24477 | 24568 | if( fcntl(h, F_SETLK, &lock)==(-1) ){ |
| @@ -24571,20 +24662,20 @@ | ||
| 24571 | 24662 | if( pFile ){ |
| 24572 | 24663 | if( pFile->dirfd>=0 ){ |
| 24573 | 24664 | int err = close(pFile->dirfd); |
| 24574 | 24665 | if( err ){ |
| 24575 | 24666 | pFile->lastErrno = errno; |
| 24576 | - return SQLITE_IOERR_DIR_CLOSE; | |
| 24667 | + return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); | |
| 24577 | 24668 | }else{ |
| 24578 | 24669 | pFile->dirfd=-1; |
| 24579 | 24670 | } |
| 24580 | 24671 | } |
| 24581 | 24672 | if( pFile->h>=0 ){ |
| 24582 | 24673 | int err = close(pFile->h); |
| 24583 | 24674 | if( err ){ |
| 24584 | 24675 | pFile->lastErrno = errno; |
| 24585 | - return SQLITE_IOERR_CLOSE; | |
| 24676 | + return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); | |
| 24586 | 24677 | } |
| 24587 | 24678 | } |
| 24588 | 24679 | #if OS_VXWORKS |
| 24589 | 24680 | if( pFile->pId ){ |
| 24590 | 24681 | if( pFile->isDelete ){ |
| @@ -24882,10 +24973,24 @@ | ||
| 24882 | 24973 | ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if |
| 24883 | 24974 | ** compiling for VXWORKS. |
| 24884 | 24975 | */ |
| 24885 | 24976 | #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS |
| 24886 | 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 | + | |
| 24887 | 24992 | /* |
| 24888 | 24993 | ** This routine checks if there is a RESERVED lock held on the specified |
| 24889 | 24994 | ** file by this or any other process. If such a lock is held, set *pResOut |
| 24890 | 24995 | ** to a non-zero value otherwise *pResOut is set to zero. The return value |
| 24891 | 24996 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. |
| @@ -24905,14 +25010,14 @@ | ||
| 24905 | 25010 | } |
| 24906 | 25011 | |
| 24907 | 25012 | /* Otherwise see if some other process holds it. */ |
| 24908 | 25013 | if( !reserved ){ |
| 24909 | 25014 | /* 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); | |
| 24911 | 25016 | if( !lrc ){ |
| 24912 | 25017 | /* got the lock, unlock it */ |
| 24913 | - lrc = flock(pFile->h, LOCK_UN); | |
| 25018 | + lrc = robust_flock(pFile->h, LOCK_UN); | |
| 24914 | 25019 | if ( lrc ) { |
| 24915 | 25020 | int tErrno = errno; |
| 24916 | 25021 | /* unlock failed with an error */ |
| 24917 | 25022 | lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 24918 | 25023 | if( IS_LOCK_ERROR(lrc) ){ |
| @@ -24985,11 +25090,11 @@ | ||
| 24985 | 25090 | return SQLITE_OK; |
| 24986 | 25091 | } |
| 24987 | 25092 | |
| 24988 | 25093 | /* grab an exclusive lock */ |
| 24989 | 25094 | |
| 24990 | - if (flock(pFile->h, LOCK_EX | LOCK_NB)) { | |
| 25095 | + if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) { | |
| 24991 | 25096 | int tErrno = errno; |
| 24992 | 25097 | /* didn't get, must be busy */ |
| 24993 | 25098 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24994 | 25099 | if( IS_LOCK_ERROR(rc) ){ |
| 24995 | 25100 | pFile->lastErrno = tErrno; |
| @@ -25034,11 +25139,11 @@ | ||
| 25034 | 25139 | pFile->eFileLock = eFileLock; |
| 25035 | 25140 | return SQLITE_OK; |
| 25036 | 25141 | } |
| 25037 | 25142 | |
| 25038 | 25143 | /* no, really, unlock. */ |
| 25039 | - int rc = flock(pFile->h, LOCK_UN); | |
| 25144 | + int rc = robust_flock(pFile->h, LOCK_UN); | |
| 25040 | 25145 | if (rc) { |
| 25041 | 25146 | int r, tErrno = errno; |
| 25042 | 25147 | r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25043 | 25148 | if( IS_LOCK_ERROR(r) ){ |
| 25044 | 25149 | pFile->lastErrno = tErrno; |
| @@ -25771,14 +25876,14 @@ | ||
| 25771 | 25876 | #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) |
| 25772 | 25877 | i64 newOffset; |
| 25773 | 25878 | #endif |
| 25774 | 25879 | TIMER_START; |
| 25775 | 25880 | #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 ); | |
| 25777 | 25882 | SimulateIOError( got = -1 ); |
| 25778 | 25883 | #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 ); | |
| 25780 | 25885 | SimulateIOError( got = -1 ); |
| 25781 | 25886 | #else |
| 25782 | 25887 | newOffset = lseek(id->h, offset, SEEK_SET); |
| 25783 | 25888 | SimulateIOError( newOffset-- ); |
| 25784 | 25889 | if( newOffset!=offset ){ |
| @@ -25787,11 +25892,11 @@ | ||
| 25787 | 25892 | }else{ |
| 25788 | 25893 | ((unixFile*)id)->lastErrno = 0; |
| 25789 | 25894 | } |
| 25790 | 25895 | return -1; |
| 25791 | 25896 | } |
| 25792 | - got = read(id->h, pBuf, cnt); | |
| 25897 | + do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); | |
| 25793 | 25898 | #endif |
| 25794 | 25899 | TIMER_END; |
| 25795 | 25900 | if( got<0 ){ |
| 25796 | 25901 | ((unixFile*)id)->lastErrno = errno; |
| 25797 | 25902 | } |
| @@ -25849,13 +25954,13 @@ | ||
| 25849 | 25954 | #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) |
| 25850 | 25955 | i64 newOffset; |
| 25851 | 25956 | #endif |
| 25852 | 25957 | TIMER_START; |
| 25853 | 25958 | #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 ); | |
| 25855 | 25960 | #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 ); | |
| 25857 | 25962 | #else |
| 25858 | 25963 | newOffset = lseek(id->h, offset, SEEK_SET); |
| 25859 | 25964 | if( newOffset!=offset ){ |
| 25860 | 25965 | if( newOffset == -1 ){ |
| 25861 | 25966 | ((unixFile*)id)->lastErrno = errno; |
| @@ -25862,11 +25967,11 @@ | ||
| 25862 | 25967 | }else{ |
| 25863 | 25968 | ((unixFile*)id)->lastErrno = 0; |
| 25864 | 25969 | } |
| 25865 | 25970 | return -1; |
| 25866 | 25971 | } |
| 25867 | - got = write(id->h, pBuf, cnt); | |
| 25972 | + do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); | |
| 25868 | 25973 | #endif |
| 25869 | 25974 | TIMER_END; |
| 25870 | 25975 | if( got<0 ){ |
| 25871 | 25976 | ((unixFile*)id)->lastErrno = errno; |
| 25872 | 25977 | } |
| @@ -26102,11 +26207,11 @@ | ||
| 26102 | 26207 | OSTRACE(("SYNC %-3d\n", pFile->h)); |
| 26103 | 26208 | rc = full_fsync(pFile->h, isFullsync, isDataOnly); |
| 26104 | 26209 | SimulateIOError( rc=1 ); |
| 26105 | 26210 | if( rc ){ |
| 26106 | 26211 | pFile->lastErrno = errno; |
| 26107 | - return SQLITE_IOERR_FSYNC; | |
| 26212 | + return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); | |
| 26108 | 26213 | } |
| 26109 | 26214 | if( pFile->dirfd>=0 ){ |
| 26110 | 26215 | int err; |
| 26111 | 26216 | OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, |
| 26112 | 26217 | HAVE_FULLFSYNC, isFullsync)); |
| @@ -26129,11 +26234,11 @@ | ||
| 26129 | 26234 | err = close(pFile->dirfd); /* Only need to sync once, so close the */ |
| 26130 | 26235 | if( err==0 ){ /* directory when we are done */ |
| 26131 | 26236 | pFile->dirfd = -1; |
| 26132 | 26237 | }else{ |
| 26133 | 26238 | pFile->lastErrno = errno; |
| 26134 | - rc = SQLITE_IOERR_DIR_CLOSE; | |
| 26239 | + rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); | |
| 26135 | 26240 | } |
| 26136 | 26241 | } |
| 26137 | 26242 | return rc; |
| 26138 | 26243 | } |
| 26139 | 26244 | |
| @@ -26153,14 +26258,14 @@ | ||
| 26153 | 26258 | */ |
| 26154 | 26259 | if( pFile->szChunk ){ |
| 26155 | 26260 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 26156 | 26261 | } |
| 26157 | 26262 | |
| 26158 | - rc = ftruncate(pFile->h, (off_t)nByte); | |
| 26263 | + rc = robust_ftruncate(pFile->h, (off_t)nByte); | |
| 26159 | 26264 | if( rc ){ |
| 26160 | 26265 | pFile->lastErrno = errno; |
| 26161 | - return SQLITE_IOERR_TRUNCATE; | |
| 26266 | + return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); | |
| 26162 | 26267 | }else{ |
| 26163 | 26268 | #ifndef NDEBUG |
| 26164 | 26269 | /* If we are doing a normal write to a database file (as opposed to |
| 26165 | 26270 | ** doing a hot-journal rollback or a write to some file other than a |
| 26166 | 26271 | ** normal database file) and we truncate the file to zero length, |
| @@ -26228,13 +26333,15 @@ | ||
| 26228 | 26333 | if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; |
| 26229 | 26334 | |
| 26230 | 26335 | nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; |
| 26231 | 26336 | if( nSize>(i64)buf.st_size ){ |
| 26232 | 26337 | #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; | |
| 26236 | 26343 | #else |
| 26237 | 26344 | /* If the OS does not have posix_fallocate(), fake it. First use |
| 26238 | 26345 | ** ftruncate() to set the file size, then write a single byte to |
| 26239 | 26346 | ** the last byte in each block within the extended region. This |
| 26240 | 26347 | ** is the same technique used by glibc to implement posix_fallocate() |
| @@ -26242,13 +26349,13 @@ | ||
| 26242 | 26349 | */ |
| 26243 | 26350 | int nBlk = buf.st_blksize; /* File-system block size */ |
| 26244 | 26351 | i64 iWrite; /* Next offset to write to */ |
| 26245 | 26352 | int nWrite; /* Return value from seekAndWrite() */ |
| 26246 | 26353 | |
| 26247 | - if( ftruncate(pFile->h, nSize) ){ | |
| 26354 | + if( robust_ftruncate(pFile->h, nSize) ){ | |
| 26248 | 26355 | pFile->lastErrno = errno; |
| 26249 | - return SQLITE_IOERR_TRUNCATE; | |
| 26356 | + return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); | |
| 26250 | 26357 | } |
| 26251 | 26358 | iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1; |
| 26252 | 26359 | do { |
| 26253 | 26360 | nWrite = seekAndWrite(pFile, iWrite, "", 1); |
| 26254 | 26361 | iWrite += nBlk; |
| @@ -26593,21 +26700,21 @@ | ||
| 26593 | 26700 | goto shm_open_err; |
| 26594 | 26701 | } |
| 26595 | 26702 | |
| 26596 | 26703 | pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777)); |
| 26597 | 26704 | if( pShmNode->h<0 ){ |
| 26598 | - rc = SQLITE_CANTOPEN_BKPT; | |
| 26705 | + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); | |
| 26599 | 26706 | goto shm_open_err; |
| 26600 | 26707 | } |
| 26601 | 26708 | |
| 26602 | 26709 | /* Check to see if another process is holding the dead-man switch. |
| 26603 | 26710 | ** If not, truncate the file to zero length. |
| 26604 | 26711 | */ |
| 26605 | 26712 | rc = SQLITE_OK; |
| 26606 | 26713 | 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); | |
| 26609 | 26716 | } |
| 26610 | 26717 | } |
| 26611 | 26718 | if( rc==SQLITE_OK ){ |
| 26612 | 26719 | rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1); |
| 26613 | 26720 | } |
| @@ -26708,12 +26815,12 @@ | ||
| 26708 | 26815 | ** |
| 26709 | 26816 | ** Alternatively, if bExtend is true, use ftruncate() to allocate |
| 26710 | 26817 | ** the requested memory region. |
| 26711 | 26818 | */ |
| 26712 | 26819 | 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); | |
| 26715 | 26822 | goto shmpage_out; |
| 26716 | 26823 | } |
| 26717 | 26824 | } |
| 26718 | 26825 | |
| 26719 | 26826 | /* Map the requested memory region into this processes address space. */ |
| @@ -27428,11 +27535,11 @@ | ||
| 27428 | 27535 | #endif |
| 27429 | 27536 | OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); |
| 27430 | 27537 | } |
| 27431 | 27538 | } |
| 27432 | 27539 | *pFd = fd; |
| 27433 | - return (fd>=0?SQLITE_OK:SQLITE_CANTOPEN_BKPT); | |
| 27540 | + return (fd>=0?SQLITE_OK:unixLogError(SQLITE_CANTOPEN_BKPT, "open", zDirname)); | |
| 27434 | 27541 | } |
| 27435 | 27542 | |
| 27436 | 27543 | /* |
| 27437 | 27544 | ** Return the name of a directory in which to put temporary files. |
| 27438 | 27545 | ** If no suitable temporary file directory can be found, return NULL. |
| @@ -27769,11 +27876,11 @@ | ||
| 27769 | 27876 | flags |= SQLITE_OPEN_READONLY; |
| 27770 | 27877 | openFlags |= O_RDONLY; |
| 27771 | 27878 | fd = open(zName, openFlags, openMode); |
| 27772 | 27879 | } |
| 27773 | 27880 | if( fd<0 ){ |
| 27774 | - rc = SQLITE_CANTOPEN_BKPT; | |
| 27881 | + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); | |
| 27775 | 27882 | goto open_finished; |
| 27776 | 27883 | } |
| 27777 | 27884 | } |
| 27778 | 27885 | assert( fd>=0 ); |
| 27779 | 27886 | if( pOutFlags ){ |
| @@ -27901,11 +28008,11 @@ | ||
| 27901 | 28008 | ){ |
| 27902 | 28009 | int rc = SQLITE_OK; |
| 27903 | 28010 | UNUSED_PARAMETER(NotUsed); |
| 27904 | 28011 | SimulateIOError(return SQLITE_IOERR_DELETE); |
| 27905 | 28012 | if( unlink(zPath)==(-1) && errno!=ENOENT ){ |
| 27906 | - return SQLITE_IOERR_DELETE; | |
| 28013 | + return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); | |
| 27907 | 28014 | } |
| 27908 | 28015 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 27909 | 28016 | if( dirSync ){ |
| 27910 | 28017 | int fd; |
| 27911 | 28018 | rc = openDirectory(zPath, &fd); |
| @@ -27914,14 +28021,14 @@ | ||
| 27914 | 28021 | if( fsync(fd)==-1 ) |
| 27915 | 28022 | #else |
| 27916 | 28023 | if( fsync(fd) ) |
| 27917 | 28024 | #endif |
| 27918 | 28025 | { |
| 27919 | - rc = SQLITE_IOERR_DIR_FSYNC; | |
| 28026 | + rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); | |
| 27920 | 28027 | } |
| 27921 | 28028 | if( close(fd)&&!rc ){ |
| 27922 | - rc = SQLITE_IOERR_DIR_CLOSE; | |
| 28029 | + rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath); | |
| 27923 | 28030 | } |
| 27924 | 28031 | } |
| 27925 | 28032 | } |
| 27926 | 28033 | #endif |
| 27927 | 28034 | return rc; |
| @@ -28001,11 +28108,11 @@ | ||
| 28001 | 28108 | if( zPath[0]=='/' ){ |
| 28002 | 28109 | sqlite3_snprintf(nOut, zOut, "%s", zPath); |
| 28003 | 28110 | }else{ |
| 28004 | 28111 | int nCwd; |
| 28005 | 28112 | if( getcwd(zOut, nOut-1)==0 ){ |
| 28006 | - return SQLITE_CANTOPEN_BKPT; | |
| 28113 | + return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); | |
| 28007 | 28114 | } |
| 28008 | 28115 | nCwd = (int)strlen(zOut); |
| 28009 | 28116 | sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath); |
| 28010 | 28117 | } |
| 28011 | 28118 | return SQLITE_OK; |
| @@ -28105,11 +28212,11 @@ | ||
| 28105 | 28212 | pid = getpid(); |
| 28106 | 28213 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 28107 | 28214 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 28108 | 28215 | nBuf = sizeof(t) + sizeof(pid); |
| 28109 | 28216 | }else{ |
| 28110 | - nBuf = read(fd, zBuf, nBuf); | |
| 28217 | + do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); | |
| 28111 | 28218 | close(fd); |
| 28112 | 28219 | } |
| 28113 | 28220 | } |
| 28114 | 28221 | #endif |
| 28115 | 28222 | return nBuf; |
| @@ -28866,27 +28973,31 @@ | ||
| 28866 | 28973 | strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN); |
| 28867 | 28974 | }else{ |
| 28868 | 28975 | strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN); |
| 28869 | 28976 | } |
| 28870 | 28977 | writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]); |
| 28871 | - ftruncate(conchFile->h, writeSize); | |
| 28978 | + robust_ftruncate(conchFile->h, writeSize); | |
| 28872 | 28979 | rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0); |
| 28873 | 28980 | fsync(conchFile->h); |
| 28874 | 28981 | /* If we created a new conch file (not just updated the contents of a |
| 28875 | 28982 | ** valid conch file), try to match the permissions of the database |
| 28876 | 28983 | */ |
| 28877 | 28984 | if( rc==SQLITE_OK && createConch ){ |
| 28878 | 28985 | struct stat buf; |
| 28986 | + int rc; | |
| 28879 | 28987 | int err = fstat(pFile->h, &buf); |
| 28880 | 28988 | if( err==0 ){ |
| 28881 | 28989 | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | |
| 28882 | 28990 | S_IROTH|S_IWOTH); |
| 28883 | 28991 | /* try to match the database file R/W permissions, ignore failure */ |
| 28884 | 28992 | #ifndef SQLITE_PROXY_DEBUG |
| 28885 | 28993 | fchmod(conchFile->h, cmode); |
| 28886 | 28994 | #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 ){ | |
| 28888 | 28999 | int code = errno; |
| 28889 | 29000 | fprintf(stderr, "fchmod %o FAILED with %d %s\n", |
| 28890 | 29001 | cmode, code, strerror(code)); |
| 28891 | 29002 | } else { |
| 28892 | 29003 | fprintf(stderr, "fchmod %o SUCCEDED\n",cmode); |
| @@ -41641,12 +41752,12 @@ | ||
| 41641 | 41752 | int rc; /* Return code */ |
| 41642 | 41753 | |
| 41643 | 41754 | assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK ); |
| 41644 | 41755 | rc = pagerLockDb(pPager, EXCLUSIVE_LOCK); |
| 41645 | 41756 | 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. */ | |
| 41648 | 41759 | pagerUnlockDb(pPager, SHARED_LOCK); |
| 41649 | 41760 | } |
| 41650 | 41761 | |
| 41651 | 41762 | return rc; |
| 41652 | 41763 | } |
| @@ -63784,11 +63895,11 @@ | ||
| 63784 | 63895 | */ |
| 63785 | 63896 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 63786 | 63897 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 63787 | 63898 | } |
| 63788 | 63899 | |
| 63789 | - sqlite3ExpirePreparedStatements(db); | |
| 63900 | + p->expired = 1; | |
| 63790 | 63901 | rc = SQLITE_SCHEMA; |
| 63791 | 63902 | } |
| 63792 | 63903 | break; |
| 63793 | 63904 | } |
| 63794 | 63905 | |
| @@ -91936,10 +92047,36 @@ | ||
| 91936 | 92047 | } |
| 91937 | 92048 | pAggInfo->directMode = 0; |
| 91938 | 92049 | sqlite3ExprCacheClear(pParse); |
| 91939 | 92050 | } |
| 91940 | 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 | + | |
| 91941 | 92078 | /* |
| 91942 | 92079 | ** Generate code for the SELECT statement given in the p argument. |
| 91943 | 92080 | ** |
| 91944 | 92081 | ** The results are distributed in various ways depending on the |
| 91945 | 92082 | ** contents of the SelectDest structure pointed to by argument pDest |
| @@ -92547,10 +92684,11 @@ | ||
| 92547 | 92684 | if( pKeyInfo ){ |
| 92548 | 92685 | sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF); |
| 92549 | 92686 | } |
| 92550 | 92687 | sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem); |
| 92551 | 92688 | sqlite3VdbeAddOp1(v, OP_Close, iCsr); |
| 92689 | + explainSimpleCount(pParse, pTab, pBest); | |
| 92552 | 92690 | }else |
| 92553 | 92691 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 92554 | 92692 | { |
| 92555 | 92693 | /* Check if the query is of one of the following forms: |
| 92556 | 92694 | ** |
| @@ -107389,11 +107527,12 @@ | ||
| 107389 | 107527 | /* Remove harmful bits from the flags parameter |
| 107390 | 107528 | ** |
| 107391 | 107529 | ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were |
| 107392 | 107530 | ** dealt with in the previous code block. Besides these, the only |
| 107393 | 107531 | ** 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 | |
| 107395 | 107534 | ** off all other flags. |
| 107396 | 107535 | */ |
| 107397 | 107536 | flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 107398 | 107537 | SQLITE_OPEN_EXCLUSIVE | |
| 107399 | 107538 | SQLITE_OPEN_MAIN_DB | |
| 107400 | 107539 |
| --- 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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -480,10 +480,12 @@ | ||
| 480 | 480 | #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
| 481 | 481 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 482 | 482 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 483 | 483 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 484 | 484 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 485 | + | |
| 486 | +/* Reserved: 0x00F00000 */ | |
| 485 | 487 | |
| 486 | 488 | /* |
| 487 | 489 | ** CAPI3REF: Device Characteristics |
| 488 | 490 | ** |
| 489 | 491 | ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
| 490 | 492 |
| --- 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 |