Fossil SCM
Update to the latest SQLite snapshot that exposes the UTF8 to MBCS conversion routine in the windows driver to applications.
Commit
989fc1f2b6c71b0e1511360467d1f2bd54381f49
Parent
e3efeb6f29c45c0…
2 files changed
+217
-107
+4
-2
+217
-107
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | -** version 3.7.6. By combining all the individual C code files into this | |
| 3 | +** version 3.7.6.1. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -648,13 +648,13 @@ | ||
| 648 | 648 | ** |
| 649 | 649 | ** See also: [sqlite3_libversion()], |
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 652 | */ |
| 653 | -#define SQLITE_VERSION "3.7.6" | |
| 653 | +#define SQLITE_VERSION "3.7.6.1" | |
| 654 | 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | -#define SQLITE_SOURCE_ID "2011-04-12 01:58:40 f9d43fa363d54beab6f45db005abac0a7c0c47a7" | |
| 655 | +#define SQLITE_SOURCE_ID "2011-04-27 16:05:42 7b479b9bee93df909edecd44c7d6584d943b39c9" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -993,10 +993,12 @@ | ||
| 993 | 993 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 994 | 994 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 995 | 995 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 996 | 996 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 997 | 997 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 998 | +#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) | |
| 999 | +#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) | |
| 998 | 1000 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 999 | 1001 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1000 | 1002 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1001 | 1003 | |
| 1002 | 1004 | /* |
| @@ -17948,11 +17950,11 @@ | ||
| 17948 | 17950 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 17949 | 17951 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 17950 | 17952 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); |
| 17951 | 17953 | if( mem0.alarmCallback!=0 ){ |
| 17952 | 17954 | int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 17953 | - if( nUsed+nFull >= mem0.alarmThreshold ){ | |
| 17955 | + if( nUsed >= mem0.alarmThreshold - nFull ){ | |
| 17954 | 17956 | mem0.nearlyFull = 1; |
| 17955 | 17957 | sqlite3MallocAlarm(nFull); |
| 17956 | 17958 | }else{ |
| 17957 | 17959 | mem0.nearlyFull = 0; |
| 17958 | 17960 | } |
| @@ -18189,11 +18191,11 @@ | ||
| 18189 | 18191 | |
| 18190 | 18192 | /* |
| 18191 | 18193 | ** Change the size of an existing memory allocation |
| 18192 | 18194 | */ |
| 18193 | 18195 | SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){ |
| 18194 | - int nOld, nNew; | |
| 18196 | + int nOld, nNew, nDiff; | |
| 18195 | 18197 | void *pNew; |
| 18196 | 18198 | if( pOld==0 ){ |
| 18197 | 18199 | return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */ |
| 18198 | 18200 | } |
| 18199 | 18201 | if( nBytes<=0 ){ |
| @@ -18212,12 +18214,13 @@ | ||
| 18212 | 18214 | if( nOld==nNew ){ |
| 18213 | 18215 | pNew = pOld; |
| 18214 | 18216 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 18215 | 18217 | sqlite3_mutex_enter(mem0.mutex); |
| 18216 | 18218 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18217 | - if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >= | |
| 18218 | - mem0.alarmThreshold ){ | |
| 18219 | + nDiff = nNew - nOld; | |
| 18220 | + if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= | |
| 18221 | + mem0.alarmThreshold-nDiff ){ | |
| 18219 | 18222 | sqlite3MallocAlarm(nNew-nOld); |
| 18220 | 18223 | } |
| 18221 | 18224 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18222 | 18225 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18223 | 18226 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| @@ -18225,11 +18228,11 @@ | ||
| 18225 | 18228 | sqlite3MallocAlarm(nBytes); |
| 18226 | 18229 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18227 | 18230 | } |
| 18228 | 18231 | if( pNew ){ |
| 18229 | 18232 | nNew = sqlite3MallocSize(pNew); |
| 18230 | - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); | |
| 18233 | + sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff); | |
| 18231 | 18234 | } |
| 18232 | 18235 | sqlite3_mutex_leave(mem0.mutex); |
| 18233 | 18236 | }else{ |
| 18234 | 18237 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18235 | 18238 | } |
| @@ -24398,10 +24401,22 @@ | ||
| 24398 | 24401 | #if SQLITE_THREADSAFE |
| 24399 | 24402 | #define threadid pthread_self() |
| 24400 | 24403 | #else |
| 24401 | 24404 | #define threadid 0 |
| 24402 | 24405 | #endif |
| 24406 | + | |
| 24407 | +/* | |
| 24408 | +** Different Unix systems declare open() in different ways. Same use | |
| 24409 | +** open(const char*,int,mode_t). Others use open(const char*,int,...). | |
| 24410 | +** The difference is important when using a pointer to the function. | |
| 24411 | +** | |
| 24412 | +** The safest way to deal with the problem is to always use this wrapper | |
| 24413 | +** which always has the same well-defined interface. | |
| 24414 | +*/ | |
| 24415 | +static int posixOpen(const char *zFile, int flags, int mode){ | |
| 24416 | + return open(zFile, flags, mode); | |
| 24417 | +} | |
| 24403 | 24418 | |
| 24404 | 24419 | /* |
| 24405 | 24420 | ** Many system calls are accessed through pointer-to-functions so that |
| 24406 | 24421 | ** they may be overridden at runtime to facilitate fault injection during |
| 24407 | 24422 | ** testing and sandboxing. The following array holds the names and pointers |
| @@ -24410,11 +24425,11 @@ | ||
| 24410 | 24425 | static struct unix_syscall { |
| 24411 | 24426 | const char *zName; /* Name of the sytem call */ |
| 24412 | 24427 | sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ |
| 24413 | 24428 | sqlite3_syscall_ptr pDefault; /* Default value */ |
| 24414 | 24429 | } aSyscall[] = { |
| 24415 | - { "open", (sqlite3_syscall_ptr)open, 0 }, | |
| 24430 | + { "open", (sqlite3_syscall_ptr)posixOpen, 0 }, | |
| 24416 | 24431 | #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) |
| 24417 | 24432 | |
| 24418 | 24433 | { "close", (sqlite3_syscall_ptr)close, 0 }, |
| 24419 | 24434 | #define osClose ((int(*)(int))aSyscall[1].pCurrent) |
| 24420 | 24435 | |
| @@ -24448,11 +24463,11 @@ | ||
| 24448 | 24463 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24449 | 24464 | |
| 24450 | 24465 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24451 | 24466 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24452 | 24467 | |
| 24453 | -#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) | |
| 24468 | +#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | |
| 24454 | 24469 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24455 | 24470 | #else |
| 24456 | 24471 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24457 | 24472 | #endif |
| 24458 | 24473 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24465,11 +24480,11 @@ | ||
| 24465 | 24480 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24466 | 24481 | |
| 24467 | 24482 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24468 | 24483 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24469 | 24484 | |
| 24470 | -#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) | |
| 24485 | +#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | |
| 24471 | 24486 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24472 | 24487 | #else |
| 24473 | 24488 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24474 | 24489 | #endif |
| 24475 | 24490 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -24483,12 +24498,14 @@ | ||
| 24483 | 24498 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| 24484 | 24499 | aSyscall[13].pCurrent) |
| 24485 | 24500 | |
| 24486 | 24501 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 24487 | 24502 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 24503 | +#else | |
| 24504 | + { "fchmod", (sqlite3_syscall_ptr)0, 0 }, | |
| 24505 | +#endif | |
| 24488 | 24506 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 24489 | -#endif | |
| 24490 | 24507 | |
| 24491 | 24508 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 24492 | 24509 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 24493 | 24510 | #else |
| 24494 | 24511 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| @@ -25049,11 +25066,11 @@ | ||
| 25049 | 25066 | unixShmNode *pShmNode; /* Shared memory associated with this inode */ |
| 25050 | 25067 | int nLock; /* Number of outstanding file locks */ |
| 25051 | 25068 | UnixUnusedFd *pUnused; /* Unused file descriptors to close */ |
| 25052 | 25069 | unixInodeInfo *pNext; /* List of all unixInodeInfo objects */ |
| 25053 | 25070 | unixInodeInfo *pPrev; /* .... doubly linked */ |
| 25054 | -#if defined(SQLITE_ENABLE_LOCKING_STYLE) | |
| 25071 | +#if SQLITE_ENABLE_LOCKING_STYLE | |
| 25055 | 25072 | unsigned long long sharedByte; /* for AFP simulated shared lock */ |
| 25056 | 25073 | #endif |
| 25057 | 25074 | #if OS_VXWORKS |
| 25058 | 25075 | sem_t *pSem; /* Named POSIX semaphore */ |
| 25059 | 25076 | char aSemName[MAX_PATHNAME+2]; /* Name of that semaphore */ |
| @@ -27206,11 +27223,11 @@ | ||
| 27206 | 27223 | } |
| 27207 | 27224 | SimulateIOError(( wrote=(-1), amt=1 )); |
| 27208 | 27225 | SimulateDiskfullError(( wrote=0, amt=1 )); |
| 27209 | 27226 | |
| 27210 | 27227 | if( amt>0 ){ |
| 27211 | - if( wrote<0 ){ | |
| 27228 | + if( wrote<0 && pFile->lastErrno!=ENOSPC ){ | |
| 27212 | 27229 | /* lastErrno set by seekAndWrite */ |
| 27213 | 27230 | return SQLITE_IOERR_WRITE; |
| 27214 | 27231 | }else{ |
| 27215 | 27232 | pFile->lastErrno = 0; /* not a system error */ |
| 27216 | 27233 | return SQLITE_FULL; |
| @@ -28031,11 +28048,11 @@ | ||
| 28031 | 28048 | if( pShmNode->h>=0 ){ |
| 28032 | 28049 | pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE, |
| 28033 | 28050 | MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion |
| 28034 | 28051 | ); |
| 28035 | 28052 | if( pMem==MAP_FAILED ){ |
| 28036 | - rc = SQLITE_IOERR; | |
| 28053 | + rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); | |
| 28037 | 28054 | goto shmpage_out; |
| 28038 | 28055 | } |
| 28039 | 28056 | }else{ |
| 28040 | 28057 | pMem = sqlite3_malloc(szRegion); |
| 28041 | 28058 | if( pMem==0 ){ |
| @@ -30801,10 +30818,14 @@ | ||
| 30801 | 30818 | UNIXVFS("unix-nfs", nfsIoFinder ), |
| 30802 | 30819 | UNIXVFS("unix-proxy", proxyIoFinder ), |
| 30803 | 30820 | #endif |
| 30804 | 30821 | }; |
| 30805 | 30822 | unsigned int i; /* Loop counter */ |
| 30823 | + | |
| 30824 | + /* Double-check that the aSyscall[] array has been constructed | |
| 30825 | + ** correctly. See ticket [bb3a86e890c8e96ab] */ | |
| 30826 | + assert( ArraySize(aSyscall)==16 ); | |
| 30806 | 30827 | |
| 30807 | 30828 | /* Register all VFSes defined in the aVfs[] array */ |
| 30808 | 30829 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 30809 | 30830 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 30810 | 30831 | } |
| @@ -31147,10 +31168,11 @@ | ||
| 31147 | 31168 | HANDLE hShared; /* Shared memory segment used for locking */ |
| 31148 | 31169 | winceLock local; /* Locks obtained by this instance of winFile */ |
| 31149 | 31170 | winceLock *shared; /* Global shared lock memory for the file */ |
| 31150 | 31171 | #endif |
| 31151 | 31172 | }; |
| 31173 | + | |
| 31152 | 31174 | |
| 31153 | 31175 | /* |
| 31154 | 31176 | ** Forward prototypes. |
| 31155 | 31177 | */ |
| 31156 | 31178 | static int getSectorSize( |
| @@ -31315,11 +31337,11 @@ | ||
| 31315 | 31337 | |
| 31316 | 31338 | /* |
| 31317 | 31339 | ** Convert UTF-8 to multibyte character string. Space to hold the |
| 31318 | 31340 | ** returned string is obtained from malloc(). |
| 31319 | 31341 | */ |
| 31320 | -static char *utf8ToMbcs(const char *zFilename){ | |
| 31342 | +SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ | |
| 31321 | 31343 | char *zFilenameMbcs; |
| 31322 | 31344 | WCHAR *zTmpWide; |
| 31323 | 31345 | |
| 31324 | 31346 | zTmpWide = utf8ToUnicode(zFilename); |
| 31325 | 31347 | if( zTmpWide==0 ){ |
| @@ -31328,10 +31350,113 @@ | ||
| 31328 | 31350 | zFilenameMbcs = unicodeToMbcs(zTmpWide); |
| 31329 | 31351 | free(zTmpWide); |
| 31330 | 31352 | return zFilenameMbcs; |
| 31331 | 31353 | } |
| 31332 | 31354 | |
| 31355 | + | |
| 31356 | +/* | |
| 31357 | +** The return value of getLastErrorMsg | |
| 31358 | +** is zero if the error message fits in the buffer, or non-zero | |
| 31359 | +** otherwise (if the message was truncated). | |
| 31360 | +*/ | |
| 31361 | +static int getLastErrorMsg(int nBuf, char *zBuf){ | |
| 31362 | + /* FormatMessage returns 0 on failure. Otherwise it | |
| 31363 | + ** returns the number of TCHARs written to the output | |
| 31364 | + ** buffer, excluding the terminating null char. | |
| 31365 | + */ | |
| 31366 | + DWORD error = GetLastError(); | |
| 31367 | + DWORD dwLen = 0; | |
| 31368 | + char *zOut = 0; | |
| 31369 | + | |
| 31370 | + if( isNT() ){ | |
| 31371 | + WCHAR *zTempWide = NULL; | |
| 31372 | + dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
| 31373 | + NULL, | |
| 31374 | + error, | |
| 31375 | + 0, | |
| 31376 | + (LPWSTR) &zTempWide, | |
| 31377 | + 0, | |
| 31378 | + 0); | |
| 31379 | + if( dwLen > 0 ){ | |
| 31380 | + /* allocate a buffer and convert to UTF8 */ | |
| 31381 | + zOut = unicodeToUtf8(zTempWide); | |
| 31382 | + /* free the system buffer allocated by FormatMessage */ | |
| 31383 | + LocalFree(zTempWide); | |
| 31384 | + } | |
| 31385 | +/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. | |
| 31386 | +** Since the ASCII version of these Windows API do not exist for WINCE, | |
| 31387 | +** it's important to not reference them for WINCE builds. | |
| 31388 | +*/ | |
| 31389 | +#if SQLITE_OS_WINCE==0 | |
| 31390 | + }else{ | |
| 31391 | + char *zTemp = NULL; | |
| 31392 | + dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
| 31393 | + NULL, | |
| 31394 | + error, | |
| 31395 | + 0, | |
| 31396 | + (LPSTR) &zTemp, | |
| 31397 | + 0, | |
| 31398 | + 0); | |
| 31399 | + if( dwLen > 0 ){ | |
| 31400 | + /* allocate a buffer and convert to UTF8 */ | |
| 31401 | + zOut = sqlite3_win32_mbcs_to_utf8(zTemp); | |
| 31402 | + /* free the system buffer allocated by FormatMessage */ | |
| 31403 | + LocalFree(zTemp); | |
| 31404 | + } | |
| 31405 | +#endif | |
| 31406 | + } | |
| 31407 | + if( 0 == dwLen ){ | |
| 31408 | + sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error); | |
| 31409 | + }else{ | |
| 31410 | + /* copy a maximum of nBuf chars to output buffer */ | |
| 31411 | + sqlite3_snprintf(nBuf, zBuf, "%s", zOut); | |
| 31412 | + /* free the UTF8 buffer */ | |
| 31413 | + free(zOut); | |
| 31414 | + } | |
| 31415 | + return 0; | |
| 31416 | +} | |
| 31417 | + | |
| 31418 | +/* | |
| 31419 | +** | |
| 31420 | +** This function - winLogErrorAtLine() - is only ever called via the macro | |
| 31421 | +** winLogError(). | |
| 31422 | +** | |
| 31423 | +** This routine is invoked after an error occurs in an OS function. | |
| 31424 | +** It logs a message using sqlite3_log() containing the current value of | |
| 31425 | +** error code and, if possible, the human-readable equivalent from | |
| 31426 | +** FormatMessage. | |
| 31427 | +** | |
| 31428 | +** The first argument passed to the macro should be the error code that | |
| 31429 | +** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). | |
| 31430 | +** The two subsequent arguments should be the name of the OS function that | |
| 31431 | +** failed and the the associated file-system path, if any. | |
| 31432 | +*/ | |
| 31433 | +#define winLogError(a,b,c) winLogErrorAtLine(a,b,c,__LINE__) | |
| 31434 | +static int winLogErrorAtLine( | |
| 31435 | + int errcode, /* SQLite error code */ | |
| 31436 | + const char *zFunc, /* Name of OS function that failed */ | |
| 31437 | + const char *zPath, /* File path associated with error */ | |
| 31438 | + int iLine /* Source line number where error occurred */ | |
| 31439 | +){ | |
| 31440 | + char zMsg[500]; /* Human readable error text */ | |
| 31441 | + int i; /* Loop counter */ | |
| 31442 | + DWORD iErrno = GetLastError(); /* Error code */ | |
| 31443 | + | |
| 31444 | + zMsg[0] = 0; | |
| 31445 | + getLastErrorMsg(sizeof(zMsg), zMsg); | |
| 31446 | + assert( errcode!=SQLITE_OK ); | |
| 31447 | + if( zPath==0 ) zPath = ""; | |
| 31448 | + for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} | |
| 31449 | + zMsg[i] = 0; | |
| 31450 | + sqlite3_log(errcode, | |
| 31451 | + "os_win.c:%d: (%d) %s(%s) - %s", | |
| 31452 | + iLine, iErrno, zFunc, zPath, zMsg | |
| 31453 | + ); | |
| 31454 | + | |
| 31455 | + return errcode; | |
| 31456 | +} | |
| 31457 | + | |
| 31333 | 31458 | #if SQLITE_OS_WINCE |
| 31334 | 31459 | /************************************************************************* |
| 31335 | 31460 | ** This section contains code for WinCE only. |
| 31336 | 31461 | */ |
| 31337 | 31462 | /* |
| @@ -31404,10 +31529,11 @@ | ||
| 31404 | 31529 | |
| 31405 | 31530 | /* Create/open the named mutex */ |
| 31406 | 31531 | pFile->hMutex = CreateMutexW(NULL, FALSE, zName); |
| 31407 | 31532 | if (!pFile->hMutex){ |
| 31408 | 31533 | pFile->lastErrno = GetLastError(); |
| 31534 | + winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename); | |
| 31409 | 31535 | free(zName); |
| 31410 | 31536 | return FALSE; |
| 31411 | 31537 | } |
| 31412 | 31538 | |
| 31413 | 31539 | /* Acquire the mutex before continuing */ |
| @@ -31435,10 +31561,11 @@ | ||
| 31435 | 31561 | pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, |
| 31436 | 31562 | FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); |
| 31437 | 31563 | /* If mapping failed, close the shared memory handle and erase it */ |
| 31438 | 31564 | if (!pFile->shared){ |
| 31439 | 31565 | pFile->lastErrno = GetLastError(); |
| 31566 | + winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename); | |
| 31440 | 31567 | CloseHandle(pFile->hShared); |
| 31441 | 31568 | pFile->hShared = NULL; |
| 31442 | 31569 | } |
| 31443 | 31570 | } |
| 31444 | 31571 | |
| @@ -31680,10 +31807,11 @@ | ||
| 31680 | 31807 | ** GetLastError(). |
| 31681 | 31808 | */ |
| 31682 | 31809 | dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); |
| 31683 | 31810 | if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){ |
| 31684 | 31811 | pFile->lastErrno = GetLastError(); |
| 31812 | + winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath); | |
| 31685 | 31813 | return 1; |
| 31686 | 31814 | } |
| 31687 | 31815 | |
| 31688 | 31816 | return 0; |
| 31689 | 31817 | } |
| @@ -31725,11 +31853,12 @@ | ||
| 31725 | 31853 | free(pFile->zDeleteOnClose); |
| 31726 | 31854 | } |
| 31727 | 31855 | #endif |
| 31728 | 31856 | OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); |
| 31729 | 31857 | OpenCounter(-1); |
| 31730 | - return rc ? SQLITE_OK : SQLITE_IOERR; | |
| 31858 | + return rc ? SQLITE_OK | |
| 31859 | + : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath); | |
| 31731 | 31860 | } |
| 31732 | 31861 | |
| 31733 | 31862 | /* |
| 31734 | 31863 | ** Read data from a file into a buffer. Return SQLITE_OK if all |
| 31735 | 31864 | ** bytes were read successfully and SQLITE_IOERR if anything goes |
| @@ -31751,11 +31880,11 @@ | ||
| 31751 | 31880 | if( seekWinFile(pFile, offset) ){ |
| 31752 | 31881 | return SQLITE_FULL; |
| 31753 | 31882 | } |
| 31754 | 31883 | if( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| 31755 | 31884 | pFile->lastErrno = GetLastError(); |
| 31756 | - return SQLITE_IOERR_READ; | |
| 31885 | + return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath); | |
| 31757 | 31886 | } |
| 31758 | 31887 | if( nRead<(DWORD)amt ){ |
| 31759 | 31888 | /* Unread parts of the buffer must be zero-filled */ |
| 31760 | 31889 | memset(&((char*)pBuf)[nRead], 0, amt-nRead); |
| 31761 | 31890 | return SQLITE_IOERR_SHORT_READ; |
| @@ -31802,11 +31931,11 @@ | ||
| 31802 | 31931 | |
| 31803 | 31932 | if( rc ){ |
| 31804 | 31933 | if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){ |
| 31805 | 31934 | return SQLITE_FULL; |
| 31806 | 31935 | } |
| 31807 | - return SQLITE_IOERR_WRITE; | |
| 31936 | + return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath); | |
| 31808 | 31937 | } |
| 31809 | 31938 | return SQLITE_OK; |
| 31810 | 31939 | } |
| 31811 | 31940 | |
| 31812 | 31941 | /* |
| @@ -31830,14 +31959,14 @@ | ||
| 31830 | 31959 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 31831 | 31960 | } |
| 31832 | 31961 | |
| 31833 | 31962 | /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ |
| 31834 | 31963 | if( seekWinFile(pFile, nByte) ){ |
| 31835 | - rc = SQLITE_IOERR_TRUNCATE; | |
| 31964 | + rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath); | |
| 31836 | 31965 | }else if( 0==SetEndOfFile(pFile->h) ){ |
| 31837 | 31966 | pFile->lastErrno = GetLastError(); |
| 31838 | - rc = SQLITE_IOERR_TRUNCATE; | |
| 31967 | + rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath); | |
| 31839 | 31968 | } |
| 31840 | 31969 | |
| 31841 | 31970 | OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); |
| 31842 | 31971 | return rc; |
| 31843 | 31972 | } |
| @@ -31855,10 +31984,11 @@ | ||
| 31855 | 31984 | ** Make sure all writes to a particular file are committed to disk. |
| 31856 | 31985 | */ |
| 31857 | 31986 | static int winSync(sqlite3_file *id, int flags){ |
| 31858 | 31987 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG) |
| 31859 | 31988 | winFile *pFile = (winFile*)id; |
| 31989 | + BOOL rc; | |
| 31860 | 31990 | #else |
| 31861 | 31991 | UNUSED_PARAMETER(id); |
| 31862 | 31992 | #endif |
| 31863 | 31993 | |
| 31864 | 31994 | assert( pFile ); |
| @@ -31867,36 +31997,37 @@ | ||
| 31867 | 31997 | || (flags&0x0F)==SQLITE_SYNC_FULL |
| 31868 | 31998 | ); |
| 31869 | 31999 | |
| 31870 | 32000 | OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype)); |
| 31871 | 32001 | |
| 32002 | + /* Unix cannot, but some systems may return SQLITE_FULL from here. This | |
| 32003 | + ** line is to test that doing so does not cause any problems. | |
| 32004 | + */ | |
| 32005 | + SimulateDiskfullError( return SQLITE_FULL ); | |
| 32006 | + | |
| 31872 | 32007 | #ifndef SQLITE_TEST |
| 31873 | 32008 | UNUSED_PARAMETER(flags); |
| 31874 | 32009 | #else |
| 31875 | - if( flags & SQLITE_SYNC_FULL ){ | |
| 32010 | + if( (flags&0x0F)==SQLITE_SYNC_FULL ){ | |
| 31876 | 32011 | sqlite3_fullsync_count++; |
| 31877 | 32012 | } |
| 31878 | 32013 | sqlite3_sync_count++; |
| 31879 | 32014 | #endif |
| 31880 | 32015 | |
| 31881 | - /* Unix cannot, but some systems may return SQLITE_FULL from here. This | |
| 31882 | - ** line is to test that doing so does not cause any problems. | |
| 31883 | - */ | |
| 31884 | - SimulateDiskfullError( return SQLITE_FULL ); | |
| 31885 | - SimulateIOError( return SQLITE_IOERR; ); | |
| 31886 | - | |
| 31887 | 32016 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 31888 | 32017 | ** no-op |
| 31889 | 32018 | */ |
| 31890 | 32019 | #ifdef SQLITE_NO_SYNC |
| 31891 | 32020 | return SQLITE_OK; |
| 31892 | 32021 | #else |
| 31893 | - if( FlushFileBuffers(pFile->h) ){ | |
| 32022 | + rc = FlushFileBuffers(pFile->h); | |
| 32023 | + SimulateIOError( rc=FALSE ); | |
| 32024 | + if( rc ){ | |
| 31894 | 32025 | return SQLITE_OK; |
| 31895 | 32026 | }else{ |
| 31896 | 32027 | pFile->lastErrno = GetLastError(); |
| 31897 | - return SQLITE_IOERR; | |
| 32028 | + return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath); | |
| 31898 | 32029 | } |
| 31899 | 32030 | #endif |
| 31900 | 32031 | } |
| 31901 | 32032 | |
| 31902 | 32033 | /* |
| @@ -31913,11 +32044,11 @@ | ||
| 31913 | 32044 | lowerBits = GetFileSize(pFile->h, &upperBits); |
| 31914 | 32045 | if( (lowerBits == INVALID_FILE_SIZE) |
| 31915 | 32046 | && ((error = GetLastError()) != NO_ERROR) ) |
| 31916 | 32047 | { |
| 31917 | 32048 | pFile->lastErrno = error; |
| 31918 | - return SQLITE_IOERR_FSTAT; | |
| 32049 | + return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath); | |
| 31919 | 32050 | } |
| 31920 | 32051 | *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; |
| 31921 | 32052 | return SQLITE_OK; |
| 31922 | 32053 | } |
| 31923 | 32054 | |
| @@ -31952,10 +32083,11 @@ | ||
| 31952 | 32083 | res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); |
| 31953 | 32084 | #endif |
| 31954 | 32085 | } |
| 31955 | 32086 | if( res == 0 ){ |
| 31956 | 32087 | pFile->lastErrno = GetLastError(); |
| 32088 | + /* No need to log a failure to lock */ | |
| 31957 | 32089 | } |
| 31958 | 32090 | return res; |
| 31959 | 32091 | } |
| 31960 | 32092 | |
| 31961 | 32093 | /* |
| @@ -31972,10 +32104,11 @@ | ||
| 31972 | 32104 | res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); |
| 31973 | 32105 | #endif |
| 31974 | 32106 | } |
| 31975 | 32107 | if( res == 0 ){ |
| 31976 | 32108 | pFile->lastErrno = GetLastError(); |
| 32109 | + winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath); | |
| 31977 | 32110 | } |
| 31978 | 32111 | return res; |
| 31979 | 32112 | } |
| 31980 | 32113 | |
| 31981 | 32114 | /* |
| @@ -32172,11 +32305,11 @@ | ||
| 32172 | 32305 | if( type>=EXCLUSIVE_LOCK ){ |
| 32173 | 32306 | UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); |
| 32174 | 32307 | if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ |
| 32175 | 32308 | /* This should never happen. We should always be able to |
| 32176 | 32309 | ** reacquire the read lock */ |
| 32177 | - rc = SQLITE_IOERR_UNLOCK; | |
| 32310 | + rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath); | |
| 32178 | 32311 | } |
| 32179 | 32312 | } |
| 32180 | 32313 | if( type>=RESERVED_LOCK ){ |
| 32181 | 32314 | UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); |
| 32182 | 32315 | } |
| @@ -32529,11 +32662,11 @@ | ||
| 32529 | 32662 | ** If not, truncate the file to zero length. |
| 32530 | 32663 | */ |
| 32531 | 32664 | if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ |
| 32532 | 32665 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); |
| 32533 | 32666 | if( rc!=SQLITE_OK ){ |
| 32534 | - rc = SQLITE_IOERR_SHMOPEN; | |
| 32667 | + rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath); | |
| 32535 | 32668 | } |
| 32536 | 32669 | } |
| 32537 | 32670 | if( rc==SQLITE_OK ){ |
| 32538 | 32671 | winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); |
| 32539 | 32672 | rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); |
| @@ -32788,11 +32921,11 @@ | ||
| 32788 | 32921 | ** Check to see if it has been allocated (i.e. if the wal-index file is |
| 32789 | 32922 | ** large enough to contain the requested region). |
| 32790 | 32923 | */ |
| 32791 | 32924 | rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); |
| 32792 | 32925 | if( rc!=SQLITE_OK ){ |
| 32793 | - rc = SQLITE_IOERR_SHMSIZE; | |
| 32926 | + rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath); | |
| 32794 | 32927 | goto shmpage_out; |
| 32795 | 32928 | } |
| 32796 | 32929 | |
| 32797 | 32930 | if( sz<nByte ){ |
| 32798 | 32931 | /* The requested memory region does not exist. If isWrite is set to |
| @@ -32802,11 +32935,11 @@ | ||
| 32802 | 32935 | ** the requested memory region. |
| 32803 | 32936 | */ |
| 32804 | 32937 | if( !isWrite ) goto shmpage_out; |
| 32805 | 32938 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); |
| 32806 | 32939 | if( rc!=SQLITE_OK ){ |
| 32807 | - rc = SQLITE_IOERR_SHMSIZE; | |
| 32940 | + rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath); | |
| 32808 | 32941 | goto shmpage_out; |
| 32809 | 32942 | } |
| 32810 | 32943 | } |
| 32811 | 32944 | |
| 32812 | 32945 | /* Map the requested memory region into this processes address space. */ |
| @@ -32839,11 +32972,11 @@ | ||
| 32839 | 32972 | (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion, |
| 32840 | 32973 | pMap ? "ok" : "failed")); |
| 32841 | 32974 | } |
| 32842 | 32975 | if( !pMap ){ |
| 32843 | 32976 | pShmNode->lastErrno = GetLastError(); |
| 32844 | - rc = SQLITE_IOERR; | |
| 32977 | + rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath); | |
| 32845 | 32978 | if( hMap ) CloseHandle(hMap); |
| 32846 | 32979 | goto shmpage_out; |
| 32847 | 32980 | } |
| 32848 | 32981 | |
| 32849 | 32982 | pShmNode->aRegion[pShmNode->nRegion].pMap = pMap; |
| @@ -32921,11 +33054,11 @@ | ||
| 32921 | 33054 | zConverted = utf8ToUnicode(zFilename); |
| 32922 | 33055 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 32923 | 33056 | */ |
| 32924 | 33057 | #if SQLITE_OS_WINCE==0 |
| 32925 | 33058 | }else{ |
| 32926 | - zConverted = utf8ToMbcs(zFilename); | |
| 33059 | + zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); | |
| 32927 | 33060 | #endif |
| 32928 | 33061 | } |
| 32929 | 33062 | /* caller will handle out of memory */ |
| 32930 | 33063 | return zConverted; |
| 32931 | 33064 | } |
| @@ -33001,72 +33134,10 @@ | ||
| 33001 | 33134 | |
| 33002 | 33135 | OSTRACE(("TEMP FILENAME: %s\n", zBuf)); |
| 33003 | 33136 | return SQLITE_OK; |
| 33004 | 33137 | } |
| 33005 | 33138 | |
| 33006 | -/* | |
| 33007 | -** The return value of getLastErrorMsg | |
| 33008 | -** is zero if the error message fits in the buffer, or non-zero | |
| 33009 | -** otherwise (if the message was truncated). | |
| 33010 | -*/ | |
| 33011 | -static int getLastErrorMsg(int nBuf, char *zBuf){ | |
| 33012 | - /* FormatMessage returns 0 on failure. Otherwise it | |
| 33013 | - ** returns the number of TCHARs written to the output | |
| 33014 | - ** buffer, excluding the terminating null char. | |
| 33015 | - */ | |
| 33016 | - DWORD error = GetLastError(); | |
| 33017 | - DWORD dwLen = 0; | |
| 33018 | - char *zOut = 0; | |
| 33019 | - | |
| 33020 | - if( isNT() ){ | |
| 33021 | - WCHAR *zTempWide = NULL; | |
| 33022 | - dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
| 33023 | - NULL, | |
| 33024 | - error, | |
| 33025 | - 0, | |
| 33026 | - (LPWSTR) &zTempWide, | |
| 33027 | - 0, | |
| 33028 | - 0); | |
| 33029 | - if( dwLen > 0 ){ | |
| 33030 | - /* allocate a buffer and convert to UTF8 */ | |
| 33031 | - zOut = unicodeToUtf8(zTempWide); | |
| 33032 | - /* free the system buffer allocated by FormatMessage */ | |
| 33033 | - LocalFree(zTempWide); | |
| 33034 | - } | |
| 33035 | -/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. | |
| 33036 | -** Since the ASCII version of these Windows API do not exist for WINCE, | |
| 33037 | -** it's important to not reference them for WINCE builds. | |
| 33038 | -*/ | |
| 33039 | -#if SQLITE_OS_WINCE==0 | |
| 33040 | - }else{ | |
| 33041 | - char *zTemp = NULL; | |
| 33042 | - dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
| 33043 | - NULL, | |
| 33044 | - error, | |
| 33045 | - 0, | |
| 33046 | - (LPSTR) &zTemp, | |
| 33047 | - 0, | |
| 33048 | - 0); | |
| 33049 | - if( dwLen > 0 ){ | |
| 33050 | - /* allocate a buffer and convert to UTF8 */ | |
| 33051 | - zOut = sqlite3_win32_mbcs_to_utf8(zTemp); | |
| 33052 | - /* free the system buffer allocated by FormatMessage */ | |
| 33053 | - LocalFree(zTemp); | |
| 33054 | - } | |
| 33055 | -#endif | |
| 33056 | - } | |
| 33057 | - if( 0 == dwLen ){ | |
| 33058 | - sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error); | |
| 33059 | - }else{ | |
| 33060 | - /* copy a maximum of nBuf chars to output buffer */ | |
| 33061 | - sqlite3_snprintf(nBuf, zBuf, "%s", zOut); | |
| 33062 | - /* free the UTF8 buffer */ | |
| 33063 | - free(zOut); | |
| 33064 | - } | |
| 33065 | - return 0; | |
| 33066 | -} | |
| 33067 | - | |
| 33068 | 33139 | /* |
| 33069 | 33140 | ** Open a file. |
| 33070 | 33141 | */ |
| 33071 | 33142 | static int winOpen( |
| 33072 | 33143 | sqlite3_vfs *pVfs, /* Not used */ |
| @@ -33234,10 +33305,11 @@ | ||
| 33234 | 33305 | h, zName, dwDesiredAccess, |
| 33235 | 33306 | h==INVALID_HANDLE_VALUE ? "failed" : "ok")); |
| 33236 | 33307 | |
| 33237 | 33308 | if( h==INVALID_HANDLE_VALUE ){ |
| 33238 | 33309 | pFile->lastErrno = GetLastError(); |
| 33310 | + winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name); | |
| 33239 | 33311 | free(zConverted); |
| 33240 | 33312 | if( isReadWrite ){ |
| 33241 | 33313 | return winOpen(pVfs, zName, id, |
| 33242 | 33314 | ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags); |
| 33243 | 33315 | }else{ |
| @@ -33337,11 +33409,12 @@ | ||
| 33337 | 33409 | OSTRACE(("DELETE \"%s\" %s\n", zFilename, |
| 33338 | 33410 | ( (rc==INVALID_FILE_ATTRIBUTES) && (error==ERROR_FILE_NOT_FOUND)) ? |
| 33339 | 33411 | "ok" : "failed" )); |
| 33340 | 33412 | |
| 33341 | 33413 | return ( (rc == INVALID_FILE_ATTRIBUTES) |
| 33342 | - && (error == ERROR_FILE_NOT_FOUND)) ? SQLITE_OK : SQLITE_IOERR_DELETE; | |
| 33414 | + && (error == ERROR_FILE_NOT_FOUND)) ? SQLITE_OK : | |
| 33415 | + winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename); | |
| 33343 | 33416 | } |
| 33344 | 33417 | |
| 33345 | 33418 | /* |
| 33346 | 33419 | ** Check the existance and status of a file. |
| 33347 | 33420 | */ |
| @@ -33377,10 +33450,11 @@ | ||
| 33377 | 33450 | }else{ |
| 33378 | 33451 | attr = sAttrData.dwFileAttributes; |
| 33379 | 33452 | } |
| 33380 | 33453 | }else{ |
| 33381 | 33454 | if( GetLastError()!=ERROR_FILE_NOT_FOUND ){ |
| 33455 | + winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename); | |
| 33382 | 33456 | free(zConverted); |
| 33383 | 33457 | return SQLITE_IOERR_ACCESS; |
| 33384 | 33458 | }else{ |
| 33385 | 33459 | attr = INVALID_FILE_ATTRIBUTES; |
| 33386 | 33460 | } |
| @@ -59911,11 +59985,11 @@ | ||
| 59911 | 59985 | /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */ |
| 59912 | 59986 | VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */ |
| 59913 | 59987 | |
| 59914 | 59988 | /* Compilers may complain that mem1.u.i is potentially uninitialized. |
| 59915 | 59989 | ** We could initialize it, as shown here, to silence those complaints. |
| 59916 | - ** But in fact, mem1.u.i will never actually be used initialized, and doing | |
| 59990 | + ** But in fact, mem1.u.i will never actually be used uninitialized, and doing | |
| 59917 | 59991 | ** the unnecessary initialization has a measurable negative performance |
| 59918 | 59992 | ** impact, since this routine is a very high runner. And so, we choose |
| 59919 | 59993 | ** to ignore the compiler warnings and leave this variable uninitialized. |
| 59920 | 59994 | */ |
| 59921 | 59995 | /* mem1.u.i = 0; // not needed, here to silence compiler warning */ |
| @@ -82329,10 +82403,25 @@ | ||
| 82329 | 82403 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 82330 | 82404 | /* IMP: R-24470-31136 This function is an SQL wrapper around the |
| 82331 | 82405 | ** sqlite3_sourceid() C interface. */ |
| 82332 | 82406 | sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC); |
| 82333 | 82407 | } |
| 82408 | + | |
| 82409 | +/* | |
| 82410 | +** Implementation of the sqlite_log() function. This is a wrapper around | |
| 82411 | +** sqlite3_log(). The return value is NULL. The function exists purely for | |
| 82412 | +** its side-effects. | |
| 82413 | +*/ | |
| 82414 | +static void logFunc( | |
| 82415 | + sqlite3_context *context, | |
| 82416 | + int argc, | |
| 82417 | + sqlite3_value **argv | |
| 82418 | +){ | |
| 82419 | + UNUSED_PARAMETER(argc); | |
| 82420 | + UNUSED_PARAMETER(context); | |
| 82421 | + sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1])); | |
| 82422 | +} | |
| 82334 | 82423 | |
| 82335 | 82424 | /* |
| 82336 | 82425 | ** Implementation of the sqlite_compileoption_used() function. |
| 82337 | 82426 | ** The result is an integer that identifies if the compiler option |
| 82338 | 82427 | ** was used to build SQLite. |
| @@ -83097,10 +83186,11 @@ | ||
| 83097 | 83186 | FUNCTION(random, 0, 0, 0, randomFunc ), |
| 83098 | 83187 | FUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 83099 | 83188 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 83100 | 83189 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 83101 | 83190 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| 83191 | + FUNCTION(sqlite_log, 2, 0, 0, logFunc ), | |
| 83102 | 83192 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 83103 | 83193 | FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 83104 | 83194 | FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 83105 | 83195 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 83106 | 83196 | FUNCTION(quote, 1, 0, 0, quoteFunc ), |
| @@ -86073,10 +86163,22 @@ | ||
| 86073 | 86163 | } |
| 86074 | 86164 | #ifndef SQLITE_OMIT_CHECK |
| 86075 | 86165 | if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){ |
| 86076 | 86166 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 86077 | 86167 | } |
| 86168 | +#endif | |
| 86169 | +#ifndef SQLITE_OMIT_FOREIGN_KEY | |
| 86170 | + /* Disallow the transfer optimization if the destination table constains | |
| 86171 | + ** any foreign key constraints. This is more restrictive than necessary. | |
| 86172 | + ** But the main beneficiary of the transfer optimization is the VACUUM | |
| 86173 | + ** command, and the VACUUM command disables foreign key constraints. So | |
| 86174 | + ** the extra complication to make this rule less restrictive is probably | |
| 86175 | + ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] | |
| 86176 | + */ | |
| 86177 | + if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ | |
| 86178 | + return 0; | |
| 86179 | + } | |
| 86078 | 86180 | #endif |
| 86079 | 86181 | |
| 86080 | 86182 | /* If we get this far, it means either: |
| 86081 | 86183 | ** |
| 86082 | 86184 | ** * We can always do the transfer if the table contains an |
| @@ -94017,16 +94119,18 @@ | ||
| 94017 | 94119 | ** does, then we can assume that it consumes less space on disk and |
| 94018 | 94120 | ** will therefore be cheaper to scan to determine the query result. |
| 94019 | 94121 | ** In this case set iRoot to the root page number of the index b-tree |
| 94020 | 94122 | ** and pKeyInfo to the KeyInfo structure required to navigate the |
| 94021 | 94123 | ** index. |
| 94124 | + ** | |
| 94125 | + ** (2011-04-15) Do not do a full scan of an unordered index. | |
| 94022 | 94126 | ** |
| 94023 | 94127 | ** In practice the KeyInfo structure will not be used. It is only |
| 94024 | 94128 | ** passed to keep OP_OpenRead happy. |
| 94025 | 94129 | */ |
| 94026 | 94130 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 94027 | - if( !pBest || pIdx->nColumn<pBest->nColumn ){ | |
| 94131 | + if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){ | |
| 94028 | 94132 | pBest = pIdx; |
| 94029 | 94133 | } |
| 94030 | 94134 | } |
| 94031 | 94135 | if( pBest && pBest->nColumn<pTab->nCol ){ |
| 94032 | 94136 | iRoot = pBest->tnum; |
| @@ -118141,10 +118245,18 @@ | ||
| 118141 | 118245 | sqlite3_tokenizer_cursor *pCsr; |
| 118142 | 118246 | int (*xNext)(sqlite3_tokenizer_cursor *pCursor, |
| 118143 | 118247 | const char**,int*,int*,int*,int*); |
| 118144 | 118248 | |
| 118145 | 118249 | assert( pTokenizer && pModule ); |
| 118250 | + | |
| 118251 | + /* If the user has inserted a NULL value, this function may be called with | |
| 118252 | + ** zText==0. In this case, add zero token entries to the hash table and | |
| 118253 | + ** return early. */ | |
| 118254 | + if( zText==0 ){ | |
| 118255 | + *pnWord = 0; | |
| 118256 | + return SQLITE_OK; | |
| 118257 | + } | |
| 118146 | 118258 | |
| 118147 | 118259 | rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr); |
| 118148 | 118260 | if( rc!=SQLITE_OK ){ |
| 118149 | 118261 | return rc; |
| 118150 | 118262 | } |
| @@ -118232,15 +118344,13 @@ | ||
| 118232 | 118344 | */ |
| 118233 | 118345 | static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){ |
| 118234 | 118346 | int i; /* Iterator variable */ |
| 118235 | 118347 | for(i=2; i<p->nColumn+2; i++){ |
| 118236 | 118348 | const char *zText = (const char *)sqlite3_value_text(apVal[i]); |
| 118237 | - if( zText ){ | |
| 118238 | - int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]); | |
| 118239 | - if( rc!=SQLITE_OK ){ | |
| 118240 | - return rc; | |
| 118241 | - } | |
| 118349 | + int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]); | |
| 118350 | + if( rc!=SQLITE_OK ){ | |
| 118351 | + return rc; | |
| 118242 | 118352 | } |
| 118243 | 118353 | aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]); |
| 118244 | 118354 | } |
| 118245 | 118355 | return SQLITE_OK; |
| 118246 | 118356 | } |
| 118247 | 118357 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.7.6. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -648,13 +648,13 @@ | |
| 648 | ** |
| 649 | ** See also: [sqlite3_libversion()], |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-04-12 01:58:40 f9d43fa363d54beab6f45db005abac0a7c0c47a7" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -993,10 +993,12 @@ | |
| 993 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 994 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 995 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 996 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 997 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 998 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 999 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1000 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1001 | |
| 1002 | /* |
| @@ -17948,11 +17950,11 @@ | |
| 17948 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 17949 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 17950 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); |
| 17951 | if( mem0.alarmCallback!=0 ){ |
| 17952 | int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 17953 | if( nUsed+nFull >= mem0.alarmThreshold ){ |
| 17954 | mem0.nearlyFull = 1; |
| 17955 | sqlite3MallocAlarm(nFull); |
| 17956 | }else{ |
| 17957 | mem0.nearlyFull = 0; |
| 17958 | } |
| @@ -18189,11 +18191,11 @@ | |
| 18189 | |
| 18190 | /* |
| 18191 | ** Change the size of an existing memory allocation |
| 18192 | */ |
| 18193 | SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){ |
| 18194 | int nOld, nNew; |
| 18195 | void *pNew; |
| 18196 | if( pOld==0 ){ |
| 18197 | return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */ |
| 18198 | } |
| 18199 | if( nBytes<=0 ){ |
| @@ -18212,12 +18214,13 @@ | |
| 18212 | if( nOld==nNew ){ |
| 18213 | pNew = pOld; |
| 18214 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 18215 | sqlite3_mutex_enter(mem0.mutex); |
| 18216 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18217 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >= |
| 18218 | mem0.alarmThreshold ){ |
| 18219 | sqlite3MallocAlarm(nNew-nOld); |
| 18220 | } |
| 18221 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18222 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18223 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| @@ -18225,11 +18228,11 @@ | |
| 18225 | sqlite3MallocAlarm(nBytes); |
| 18226 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18227 | } |
| 18228 | if( pNew ){ |
| 18229 | nNew = sqlite3MallocSize(pNew); |
| 18230 | sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| 18231 | } |
| 18232 | sqlite3_mutex_leave(mem0.mutex); |
| 18233 | }else{ |
| 18234 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18235 | } |
| @@ -24398,10 +24401,22 @@ | |
| 24398 | #if SQLITE_THREADSAFE |
| 24399 | #define threadid pthread_self() |
| 24400 | #else |
| 24401 | #define threadid 0 |
| 24402 | #endif |
| 24403 | |
| 24404 | /* |
| 24405 | ** Many system calls are accessed through pointer-to-functions so that |
| 24406 | ** they may be overridden at runtime to facilitate fault injection during |
| 24407 | ** testing and sandboxing. The following array holds the names and pointers |
| @@ -24410,11 +24425,11 @@ | |
| 24410 | static struct unix_syscall { |
| 24411 | const char *zName; /* Name of the sytem call */ |
| 24412 | sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ |
| 24413 | sqlite3_syscall_ptr pDefault; /* Default value */ |
| 24414 | } aSyscall[] = { |
| 24415 | { "open", (sqlite3_syscall_ptr)open, 0 }, |
| 24416 | #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) |
| 24417 | |
| 24418 | { "close", (sqlite3_syscall_ptr)close, 0 }, |
| 24419 | #define osClose ((int(*)(int))aSyscall[1].pCurrent) |
| 24420 | |
| @@ -24448,11 +24463,11 @@ | |
| 24448 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24449 | |
| 24450 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24451 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24452 | |
| 24453 | #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 24454 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24455 | #else |
| 24456 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24457 | #endif |
| 24458 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24465,11 +24480,11 @@ | |
| 24465 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24466 | |
| 24467 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24468 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24469 | |
| 24470 | #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 24471 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24472 | #else |
| 24473 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24474 | #endif |
| 24475 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -24483,12 +24498,14 @@ | |
| 24483 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| 24484 | aSyscall[13].pCurrent) |
| 24485 | |
| 24486 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 24487 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 24488 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 24489 | #endif |
| 24490 | |
| 24491 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 24492 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 24493 | #else |
| 24494 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| @@ -25049,11 +25066,11 @@ | |
| 25049 | unixShmNode *pShmNode; /* Shared memory associated with this inode */ |
| 25050 | int nLock; /* Number of outstanding file locks */ |
| 25051 | UnixUnusedFd *pUnused; /* Unused file descriptors to close */ |
| 25052 | unixInodeInfo *pNext; /* List of all unixInodeInfo objects */ |
| 25053 | unixInodeInfo *pPrev; /* .... doubly linked */ |
| 25054 | #if defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 25055 | unsigned long long sharedByte; /* for AFP simulated shared lock */ |
| 25056 | #endif |
| 25057 | #if OS_VXWORKS |
| 25058 | sem_t *pSem; /* Named POSIX semaphore */ |
| 25059 | char aSemName[MAX_PATHNAME+2]; /* Name of that semaphore */ |
| @@ -27206,11 +27223,11 @@ | |
| 27206 | } |
| 27207 | SimulateIOError(( wrote=(-1), amt=1 )); |
| 27208 | SimulateDiskfullError(( wrote=0, amt=1 )); |
| 27209 | |
| 27210 | if( amt>0 ){ |
| 27211 | if( wrote<0 ){ |
| 27212 | /* lastErrno set by seekAndWrite */ |
| 27213 | return SQLITE_IOERR_WRITE; |
| 27214 | }else{ |
| 27215 | pFile->lastErrno = 0; /* not a system error */ |
| 27216 | return SQLITE_FULL; |
| @@ -28031,11 +28048,11 @@ | |
| 28031 | if( pShmNode->h>=0 ){ |
| 28032 | pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE, |
| 28033 | MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion |
| 28034 | ); |
| 28035 | if( pMem==MAP_FAILED ){ |
| 28036 | rc = SQLITE_IOERR; |
| 28037 | goto shmpage_out; |
| 28038 | } |
| 28039 | }else{ |
| 28040 | pMem = sqlite3_malloc(szRegion); |
| 28041 | if( pMem==0 ){ |
| @@ -30801,10 +30818,14 @@ | |
| 30801 | UNIXVFS("unix-nfs", nfsIoFinder ), |
| 30802 | UNIXVFS("unix-proxy", proxyIoFinder ), |
| 30803 | #endif |
| 30804 | }; |
| 30805 | unsigned int i; /* Loop counter */ |
| 30806 | |
| 30807 | /* Register all VFSes defined in the aVfs[] array */ |
| 30808 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 30809 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 30810 | } |
| @@ -31147,10 +31168,11 @@ | |
| 31147 | HANDLE hShared; /* Shared memory segment used for locking */ |
| 31148 | winceLock local; /* Locks obtained by this instance of winFile */ |
| 31149 | winceLock *shared; /* Global shared lock memory for the file */ |
| 31150 | #endif |
| 31151 | }; |
| 31152 | |
| 31153 | /* |
| 31154 | ** Forward prototypes. |
| 31155 | */ |
| 31156 | static int getSectorSize( |
| @@ -31315,11 +31337,11 @@ | |
| 31315 | |
| 31316 | /* |
| 31317 | ** Convert UTF-8 to multibyte character string. Space to hold the |
| 31318 | ** returned string is obtained from malloc(). |
| 31319 | */ |
| 31320 | static char *utf8ToMbcs(const char *zFilename){ |
| 31321 | char *zFilenameMbcs; |
| 31322 | WCHAR *zTmpWide; |
| 31323 | |
| 31324 | zTmpWide = utf8ToUnicode(zFilename); |
| 31325 | if( zTmpWide==0 ){ |
| @@ -31328,10 +31350,113 @@ | |
| 31328 | zFilenameMbcs = unicodeToMbcs(zTmpWide); |
| 31329 | free(zTmpWide); |
| 31330 | return zFilenameMbcs; |
| 31331 | } |
| 31332 | |
| 31333 | #if SQLITE_OS_WINCE |
| 31334 | /************************************************************************* |
| 31335 | ** This section contains code for WinCE only. |
| 31336 | */ |
| 31337 | /* |
| @@ -31404,10 +31529,11 @@ | |
| 31404 | |
| 31405 | /* Create/open the named mutex */ |
| 31406 | pFile->hMutex = CreateMutexW(NULL, FALSE, zName); |
| 31407 | if (!pFile->hMutex){ |
| 31408 | pFile->lastErrno = GetLastError(); |
| 31409 | free(zName); |
| 31410 | return FALSE; |
| 31411 | } |
| 31412 | |
| 31413 | /* Acquire the mutex before continuing */ |
| @@ -31435,10 +31561,11 @@ | |
| 31435 | pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, |
| 31436 | FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); |
| 31437 | /* If mapping failed, close the shared memory handle and erase it */ |
| 31438 | if (!pFile->shared){ |
| 31439 | pFile->lastErrno = GetLastError(); |
| 31440 | CloseHandle(pFile->hShared); |
| 31441 | pFile->hShared = NULL; |
| 31442 | } |
| 31443 | } |
| 31444 | |
| @@ -31680,10 +31807,11 @@ | |
| 31680 | ** GetLastError(). |
| 31681 | */ |
| 31682 | dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); |
| 31683 | if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){ |
| 31684 | pFile->lastErrno = GetLastError(); |
| 31685 | return 1; |
| 31686 | } |
| 31687 | |
| 31688 | return 0; |
| 31689 | } |
| @@ -31725,11 +31853,12 @@ | |
| 31725 | free(pFile->zDeleteOnClose); |
| 31726 | } |
| 31727 | #endif |
| 31728 | OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); |
| 31729 | OpenCounter(-1); |
| 31730 | return rc ? SQLITE_OK : SQLITE_IOERR; |
| 31731 | } |
| 31732 | |
| 31733 | /* |
| 31734 | ** Read data from a file into a buffer. Return SQLITE_OK if all |
| 31735 | ** bytes were read successfully and SQLITE_IOERR if anything goes |
| @@ -31751,11 +31880,11 @@ | |
| 31751 | if( seekWinFile(pFile, offset) ){ |
| 31752 | return SQLITE_FULL; |
| 31753 | } |
| 31754 | if( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| 31755 | pFile->lastErrno = GetLastError(); |
| 31756 | return SQLITE_IOERR_READ; |
| 31757 | } |
| 31758 | if( nRead<(DWORD)amt ){ |
| 31759 | /* Unread parts of the buffer must be zero-filled */ |
| 31760 | memset(&((char*)pBuf)[nRead], 0, amt-nRead); |
| 31761 | return SQLITE_IOERR_SHORT_READ; |
| @@ -31802,11 +31931,11 @@ | |
| 31802 | |
| 31803 | if( rc ){ |
| 31804 | if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){ |
| 31805 | return SQLITE_FULL; |
| 31806 | } |
| 31807 | return SQLITE_IOERR_WRITE; |
| 31808 | } |
| 31809 | return SQLITE_OK; |
| 31810 | } |
| 31811 | |
| 31812 | /* |
| @@ -31830,14 +31959,14 @@ | |
| 31830 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 31831 | } |
| 31832 | |
| 31833 | /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ |
| 31834 | if( seekWinFile(pFile, nByte) ){ |
| 31835 | rc = SQLITE_IOERR_TRUNCATE; |
| 31836 | }else if( 0==SetEndOfFile(pFile->h) ){ |
| 31837 | pFile->lastErrno = GetLastError(); |
| 31838 | rc = SQLITE_IOERR_TRUNCATE; |
| 31839 | } |
| 31840 | |
| 31841 | OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); |
| 31842 | return rc; |
| 31843 | } |
| @@ -31855,10 +31984,11 @@ | |
| 31855 | ** Make sure all writes to a particular file are committed to disk. |
| 31856 | */ |
| 31857 | static int winSync(sqlite3_file *id, int flags){ |
| 31858 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG) |
| 31859 | winFile *pFile = (winFile*)id; |
| 31860 | #else |
| 31861 | UNUSED_PARAMETER(id); |
| 31862 | #endif |
| 31863 | |
| 31864 | assert( pFile ); |
| @@ -31867,36 +31997,37 @@ | |
| 31867 | || (flags&0x0F)==SQLITE_SYNC_FULL |
| 31868 | ); |
| 31869 | |
| 31870 | OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype)); |
| 31871 | |
| 31872 | #ifndef SQLITE_TEST |
| 31873 | UNUSED_PARAMETER(flags); |
| 31874 | #else |
| 31875 | if( flags & SQLITE_SYNC_FULL ){ |
| 31876 | sqlite3_fullsync_count++; |
| 31877 | } |
| 31878 | sqlite3_sync_count++; |
| 31879 | #endif |
| 31880 | |
| 31881 | /* Unix cannot, but some systems may return SQLITE_FULL from here. This |
| 31882 | ** line is to test that doing so does not cause any problems. |
| 31883 | */ |
| 31884 | SimulateDiskfullError( return SQLITE_FULL ); |
| 31885 | SimulateIOError( return SQLITE_IOERR; ); |
| 31886 | |
| 31887 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 31888 | ** no-op |
| 31889 | */ |
| 31890 | #ifdef SQLITE_NO_SYNC |
| 31891 | return SQLITE_OK; |
| 31892 | #else |
| 31893 | if( FlushFileBuffers(pFile->h) ){ |
| 31894 | return SQLITE_OK; |
| 31895 | }else{ |
| 31896 | pFile->lastErrno = GetLastError(); |
| 31897 | return SQLITE_IOERR; |
| 31898 | } |
| 31899 | #endif |
| 31900 | } |
| 31901 | |
| 31902 | /* |
| @@ -31913,11 +32044,11 @@ | |
| 31913 | lowerBits = GetFileSize(pFile->h, &upperBits); |
| 31914 | if( (lowerBits == INVALID_FILE_SIZE) |
| 31915 | && ((error = GetLastError()) != NO_ERROR) ) |
| 31916 | { |
| 31917 | pFile->lastErrno = error; |
| 31918 | return SQLITE_IOERR_FSTAT; |
| 31919 | } |
| 31920 | *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; |
| 31921 | return SQLITE_OK; |
| 31922 | } |
| 31923 | |
| @@ -31952,10 +32083,11 @@ | |
| 31952 | res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); |
| 31953 | #endif |
| 31954 | } |
| 31955 | if( res == 0 ){ |
| 31956 | pFile->lastErrno = GetLastError(); |
| 31957 | } |
| 31958 | return res; |
| 31959 | } |
| 31960 | |
| 31961 | /* |
| @@ -31972,10 +32104,11 @@ | |
| 31972 | res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); |
| 31973 | #endif |
| 31974 | } |
| 31975 | if( res == 0 ){ |
| 31976 | pFile->lastErrno = GetLastError(); |
| 31977 | } |
| 31978 | return res; |
| 31979 | } |
| 31980 | |
| 31981 | /* |
| @@ -32172,11 +32305,11 @@ | |
| 32172 | if( type>=EXCLUSIVE_LOCK ){ |
| 32173 | UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); |
| 32174 | if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ |
| 32175 | /* This should never happen. We should always be able to |
| 32176 | ** reacquire the read lock */ |
| 32177 | rc = SQLITE_IOERR_UNLOCK; |
| 32178 | } |
| 32179 | } |
| 32180 | if( type>=RESERVED_LOCK ){ |
| 32181 | UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); |
| 32182 | } |
| @@ -32529,11 +32662,11 @@ | |
| 32529 | ** If not, truncate the file to zero length. |
| 32530 | */ |
| 32531 | if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ |
| 32532 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); |
| 32533 | if( rc!=SQLITE_OK ){ |
| 32534 | rc = SQLITE_IOERR_SHMOPEN; |
| 32535 | } |
| 32536 | } |
| 32537 | if( rc==SQLITE_OK ){ |
| 32538 | winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); |
| 32539 | rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); |
| @@ -32788,11 +32921,11 @@ | |
| 32788 | ** Check to see if it has been allocated (i.e. if the wal-index file is |
| 32789 | ** large enough to contain the requested region). |
| 32790 | */ |
| 32791 | rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); |
| 32792 | if( rc!=SQLITE_OK ){ |
| 32793 | rc = SQLITE_IOERR_SHMSIZE; |
| 32794 | goto shmpage_out; |
| 32795 | } |
| 32796 | |
| 32797 | if( sz<nByte ){ |
| 32798 | /* The requested memory region does not exist. If isWrite is set to |
| @@ -32802,11 +32935,11 @@ | |
| 32802 | ** the requested memory region. |
| 32803 | */ |
| 32804 | if( !isWrite ) goto shmpage_out; |
| 32805 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); |
| 32806 | if( rc!=SQLITE_OK ){ |
| 32807 | rc = SQLITE_IOERR_SHMSIZE; |
| 32808 | goto shmpage_out; |
| 32809 | } |
| 32810 | } |
| 32811 | |
| 32812 | /* Map the requested memory region into this processes address space. */ |
| @@ -32839,11 +32972,11 @@ | |
| 32839 | (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion, |
| 32840 | pMap ? "ok" : "failed")); |
| 32841 | } |
| 32842 | if( !pMap ){ |
| 32843 | pShmNode->lastErrno = GetLastError(); |
| 32844 | rc = SQLITE_IOERR; |
| 32845 | if( hMap ) CloseHandle(hMap); |
| 32846 | goto shmpage_out; |
| 32847 | } |
| 32848 | |
| 32849 | pShmNode->aRegion[pShmNode->nRegion].pMap = pMap; |
| @@ -32921,11 +33054,11 @@ | |
| 32921 | zConverted = utf8ToUnicode(zFilename); |
| 32922 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 32923 | */ |
| 32924 | #if SQLITE_OS_WINCE==0 |
| 32925 | }else{ |
| 32926 | zConverted = utf8ToMbcs(zFilename); |
| 32927 | #endif |
| 32928 | } |
| 32929 | /* caller will handle out of memory */ |
| 32930 | return zConverted; |
| 32931 | } |
| @@ -33001,72 +33134,10 @@ | |
| 33001 | |
| 33002 | OSTRACE(("TEMP FILENAME: %s\n", zBuf)); |
| 33003 | return SQLITE_OK; |
| 33004 | } |
| 33005 | |
| 33006 | /* |
| 33007 | ** The return value of getLastErrorMsg |
| 33008 | ** is zero if the error message fits in the buffer, or non-zero |
| 33009 | ** otherwise (if the message was truncated). |
| 33010 | */ |
| 33011 | static int getLastErrorMsg(int nBuf, char *zBuf){ |
| 33012 | /* FormatMessage returns 0 on failure. Otherwise it |
| 33013 | ** returns the number of TCHARs written to the output |
| 33014 | ** buffer, excluding the terminating null char. |
| 33015 | */ |
| 33016 | DWORD error = GetLastError(); |
| 33017 | DWORD dwLen = 0; |
| 33018 | char *zOut = 0; |
| 33019 | |
| 33020 | if( isNT() ){ |
| 33021 | WCHAR *zTempWide = NULL; |
| 33022 | dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 33023 | NULL, |
| 33024 | error, |
| 33025 | 0, |
| 33026 | (LPWSTR) &zTempWide, |
| 33027 | 0, |
| 33028 | 0); |
| 33029 | if( dwLen > 0 ){ |
| 33030 | /* allocate a buffer and convert to UTF8 */ |
| 33031 | zOut = unicodeToUtf8(zTempWide); |
| 33032 | /* free the system buffer allocated by FormatMessage */ |
| 33033 | LocalFree(zTempWide); |
| 33034 | } |
| 33035 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 33036 | ** Since the ASCII version of these Windows API do not exist for WINCE, |
| 33037 | ** it's important to not reference them for WINCE builds. |
| 33038 | */ |
| 33039 | #if SQLITE_OS_WINCE==0 |
| 33040 | }else{ |
| 33041 | char *zTemp = NULL; |
| 33042 | dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 33043 | NULL, |
| 33044 | error, |
| 33045 | 0, |
| 33046 | (LPSTR) &zTemp, |
| 33047 | 0, |
| 33048 | 0); |
| 33049 | if( dwLen > 0 ){ |
| 33050 | /* allocate a buffer and convert to UTF8 */ |
| 33051 | zOut = sqlite3_win32_mbcs_to_utf8(zTemp); |
| 33052 | /* free the system buffer allocated by FormatMessage */ |
| 33053 | LocalFree(zTemp); |
| 33054 | } |
| 33055 | #endif |
| 33056 | } |
| 33057 | if( 0 == dwLen ){ |
| 33058 | sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error); |
| 33059 | }else{ |
| 33060 | /* copy a maximum of nBuf chars to output buffer */ |
| 33061 | sqlite3_snprintf(nBuf, zBuf, "%s", zOut); |
| 33062 | /* free the UTF8 buffer */ |
| 33063 | free(zOut); |
| 33064 | } |
| 33065 | return 0; |
| 33066 | } |
| 33067 | |
| 33068 | /* |
| 33069 | ** Open a file. |
| 33070 | */ |
| 33071 | static int winOpen( |
| 33072 | sqlite3_vfs *pVfs, /* Not used */ |
| @@ -33234,10 +33305,11 @@ | |
| 33234 | h, zName, dwDesiredAccess, |
| 33235 | h==INVALID_HANDLE_VALUE ? "failed" : "ok")); |
| 33236 | |
| 33237 | if( h==INVALID_HANDLE_VALUE ){ |
| 33238 | pFile->lastErrno = GetLastError(); |
| 33239 | free(zConverted); |
| 33240 | if( isReadWrite ){ |
| 33241 | return winOpen(pVfs, zName, id, |
| 33242 | ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags); |
| 33243 | }else{ |
| @@ -33337,11 +33409,12 @@ | |
| 33337 | OSTRACE(("DELETE \"%s\" %s\n", zFilename, |
| 33338 | ( (rc==INVALID_FILE_ATTRIBUTES) && (error==ERROR_FILE_NOT_FOUND)) ? |
| 33339 | "ok" : "failed" )); |
| 33340 | |
| 33341 | return ( (rc == INVALID_FILE_ATTRIBUTES) |
| 33342 | && (error == ERROR_FILE_NOT_FOUND)) ? SQLITE_OK : SQLITE_IOERR_DELETE; |
| 33343 | } |
| 33344 | |
| 33345 | /* |
| 33346 | ** Check the existance and status of a file. |
| 33347 | */ |
| @@ -33377,10 +33450,11 @@ | |
| 33377 | }else{ |
| 33378 | attr = sAttrData.dwFileAttributes; |
| 33379 | } |
| 33380 | }else{ |
| 33381 | if( GetLastError()!=ERROR_FILE_NOT_FOUND ){ |
| 33382 | free(zConverted); |
| 33383 | return SQLITE_IOERR_ACCESS; |
| 33384 | }else{ |
| 33385 | attr = INVALID_FILE_ATTRIBUTES; |
| 33386 | } |
| @@ -59911,11 +59985,11 @@ | |
| 59911 | /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */ |
| 59912 | VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */ |
| 59913 | |
| 59914 | /* Compilers may complain that mem1.u.i is potentially uninitialized. |
| 59915 | ** We could initialize it, as shown here, to silence those complaints. |
| 59916 | ** But in fact, mem1.u.i will never actually be used initialized, and doing |
| 59917 | ** the unnecessary initialization has a measurable negative performance |
| 59918 | ** impact, since this routine is a very high runner. And so, we choose |
| 59919 | ** to ignore the compiler warnings and leave this variable uninitialized. |
| 59920 | */ |
| 59921 | /* mem1.u.i = 0; // not needed, here to silence compiler warning */ |
| @@ -82329,10 +82403,25 @@ | |
| 82329 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 82330 | /* IMP: R-24470-31136 This function is an SQL wrapper around the |
| 82331 | ** sqlite3_sourceid() C interface. */ |
| 82332 | sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC); |
| 82333 | } |
| 82334 | |
| 82335 | /* |
| 82336 | ** Implementation of the sqlite_compileoption_used() function. |
| 82337 | ** The result is an integer that identifies if the compiler option |
| 82338 | ** was used to build SQLite. |
| @@ -83097,10 +83186,11 @@ | |
| 83097 | FUNCTION(random, 0, 0, 0, randomFunc ), |
| 83098 | FUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 83099 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 83100 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 83101 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| 83102 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 83103 | FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 83104 | FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 83105 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 83106 | FUNCTION(quote, 1, 0, 0, quoteFunc ), |
| @@ -86073,10 +86163,22 @@ | |
| 86073 | } |
| 86074 | #ifndef SQLITE_OMIT_CHECK |
| 86075 | if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){ |
| 86076 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 86077 | } |
| 86078 | #endif |
| 86079 | |
| 86080 | /* If we get this far, it means either: |
| 86081 | ** |
| 86082 | ** * We can always do the transfer if the table contains an |
| @@ -94017,16 +94119,18 @@ | |
| 94017 | ** does, then we can assume that it consumes less space on disk and |
| 94018 | ** will therefore be cheaper to scan to determine the query result. |
| 94019 | ** In this case set iRoot to the root page number of the index b-tree |
| 94020 | ** and pKeyInfo to the KeyInfo structure required to navigate the |
| 94021 | ** index. |
| 94022 | ** |
| 94023 | ** In practice the KeyInfo structure will not be used. It is only |
| 94024 | ** passed to keep OP_OpenRead happy. |
| 94025 | */ |
| 94026 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 94027 | if( !pBest || pIdx->nColumn<pBest->nColumn ){ |
| 94028 | pBest = pIdx; |
| 94029 | } |
| 94030 | } |
| 94031 | if( pBest && pBest->nColumn<pTab->nCol ){ |
| 94032 | iRoot = pBest->tnum; |
| @@ -118141,10 +118245,18 @@ | |
| 118141 | sqlite3_tokenizer_cursor *pCsr; |
| 118142 | int (*xNext)(sqlite3_tokenizer_cursor *pCursor, |
| 118143 | const char**,int*,int*,int*,int*); |
| 118144 | |
| 118145 | assert( pTokenizer && pModule ); |
| 118146 | |
| 118147 | rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr); |
| 118148 | if( rc!=SQLITE_OK ){ |
| 118149 | return rc; |
| 118150 | } |
| @@ -118232,15 +118344,13 @@ | |
| 118232 | */ |
| 118233 | static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){ |
| 118234 | int i; /* Iterator variable */ |
| 118235 | for(i=2; i<p->nColumn+2; i++){ |
| 118236 | const char *zText = (const char *)sqlite3_value_text(apVal[i]); |
| 118237 | if( zText ){ |
| 118238 | int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]); |
| 118239 | if( rc!=SQLITE_OK ){ |
| 118240 | return rc; |
| 118241 | } |
| 118242 | } |
| 118243 | aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]); |
| 118244 | } |
| 118245 | return SQLITE_OK; |
| 118246 | } |
| 118247 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.7.6.1. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -648,13 +648,13 @@ | |
| 648 | ** |
| 649 | ** See also: [sqlite3_libversion()], |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6.1" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-04-27 16:05:42 7b479b9bee93df909edecd44c7d6584d943b39c9" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -993,10 +993,12 @@ | |
| 993 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 994 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 995 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 996 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 997 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 998 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 999 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1000 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1001 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1002 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1003 | |
| 1004 | /* |
| @@ -17948,11 +17950,11 @@ | |
| 17950 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 17951 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 17952 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); |
| 17953 | if( mem0.alarmCallback!=0 ){ |
| 17954 | int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 17955 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| 17956 | mem0.nearlyFull = 1; |
| 17957 | sqlite3MallocAlarm(nFull); |
| 17958 | }else{ |
| 17959 | mem0.nearlyFull = 0; |
| 17960 | } |
| @@ -18189,11 +18191,11 @@ | |
| 18191 | |
| 18192 | /* |
| 18193 | ** Change the size of an existing memory allocation |
| 18194 | */ |
| 18195 | SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){ |
| 18196 | int nOld, nNew, nDiff; |
| 18197 | void *pNew; |
| 18198 | if( pOld==0 ){ |
| 18199 | return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */ |
| 18200 | } |
| 18201 | if( nBytes<=0 ){ |
| @@ -18212,12 +18214,13 @@ | |
| 18214 | if( nOld==nNew ){ |
| 18215 | pNew = pOld; |
| 18216 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 18217 | sqlite3_mutex_enter(mem0.mutex); |
| 18218 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18219 | nDiff = nNew - nOld; |
| 18220 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 18221 | mem0.alarmThreshold-nDiff ){ |
| 18222 | sqlite3MallocAlarm(nNew-nOld); |
| 18223 | } |
| 18224 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18225 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18226 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| @@ -18225,11 +18228,11 @@ | |
| 18228 | sqlite3MallocAlarm(nBytes); |
| 18229 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18230 | } |
| 18231 | if( pNew ){ |
| 18232 | nNew = sqlite3MallocSize(pNew); |
| 18233 | sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff); |
| 18234 | } |
| 18235 | sqlite3_mutex_leave(mem0.mutex); |
| 18236 | }else{ |
| 18237 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18238 | } |
| @@ -24398,10 +24401,22 @@ | |
| 24401 | #if SQLITE_THREADSAFE |
| 24402 | #define threadid pthread_self() |
| 24403 | #else |
| 24404 | #define threadid 0 |
| 24405 | #endif |
| 24406 | |
| 24407 | /* |
| 24408 | ** Different Unix systems declare open() in different ways. Same use |
| 24409 | ** open(const char*,int,mode_t). Others use open(const char*,int,...). |
| 24410 | ** The difference is important when using a pointer to the function. |
| 24411 | ** |
| 24412 | ** The safest way to deal with the problem is to always use this wrapper |
| 24413 | ** which always has the same well-defined interface. |
| 24414 | */ |
| 24415 | static int posixOpen(const char *zFile, int flags, int mode){ |
| 24416 | return open(zFile, flags, mode); |
| 24417 | } |
| 24418 | |
| 24419 | /* |
| 24420 | ** Many system calls are accessed through pointer-to-functions so that |
| 24421 | ** they may be overridden at runtime to facilitate fault injection during |
| 24422 | ** testing and sandboxing. The following array holds the names and pointers |
| @@ -24410,11 +24425,11 @@ | |
| 24425 | static struct unix_syscall { |
| 24426 | const char *zName; /* Name of the sytem call */ |
| 24427 | sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ |
| 24428 | sqlite3_syscall_ptr pDefault; /* Default value */ |
| 24429 | } aSyscall[] = { |
| 24430 | { "open", (sqlite3_syscall_ptr)posixOpen, 0 }, |
| 24431 | #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) |
| 24432 | |
| 24433 | { "close", (sqlite3_syscall_ptr)close, 0 }, |
| 24434 | #define osClose ((int(*)(int))aSyscall[1].pCurrent) |
| 24435 | |
| @@ -24448,11 +24463,11 @@ | |
| 24463 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24464 | |
| 24465 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24466 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24467 | |
| 24468 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE |
| 24469 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24470 | #else |
| 24471 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24472 | #endif |
| 24473 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24465,11 +24480,11 @@ | |
| 24480 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24481 | |
| 24482 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24483 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24484 | |
| 24485 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE |
| 24486 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24487 | #else |
| 24488 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24489 | #endif |
| 24490 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -24483,12 +24498,14 @@ | |
| 24498 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| 24499 | aSyscall[13].pCurrent) |
| 24500 | |
| 24501 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 24502 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 24503 | #else |
| 24504 | { "fchmod", (sqlite3_syscall_ptr)0, 0 }, |
| 24505 | #endif |
| 24506 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 24507 | |
| 24508 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 24509 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 24510 | #else |
| 24511 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| @@ -25049,11 +25066,11 @@ | |
| 25066 | unixShmNode *pShmNode; /* Shared memory associated with this inode */ |
| 25067 | int nLock; /* Number of outstanding file locks */ |
| 25068 | UnixUnusedFd *pUnused; /* Unused file descriptors to close */ |
| 25069 | unixInodeInfo *pNext; /* List of all unixInodeInfo objects */ |
| 25070 | unixInodeInfo *pPrev; /* .... doubly linked */ |
| 25071 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 25072 | unsigned long long sharedByte; /* for AFP simulated shared lock */ |
| 25073 | #endif |
| 25074 | #if OS_VXWORKS |
| 25075 | sem_t *pSem; /* Named POSIX semaphore */ |
| 25076 | char aSemName[MAX_PATHNAME+2]; /* Name of that semaphore */ |
| @@ -27206,11 +27223,11 @@ | |
| 27223 | } |
| 27224 | SimulateIOError(( wrote=(-1), amt=1 )); |
| 27225 | SimulateDiskfullError(( wrote=0, amt=1 )); |
| 27226 | |
| 27227 | if( amt>0 ){ |
| 27228 | if( wrote<0 && pFile->lastErrno!=ENOSPC ){ |
| 27229 | /* lastErrno set by seekAndWrite */ |
| 27230 | return SQLITE_IOERR_WRITE; |
| 27231 | }else{ |
| 27232 | pFile->lastErrno = 0; /* not a system error */ |
| 27233 | return SQLITE_FULL; |
| @@ -28031,11 +28048,11 @@ | |
| 28048 | if( pShmNode->h>=0 ){ |
| 28049 | pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE, |
| 28050 | MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion |
| 28051 | ); |
| 28052 | if( pMem==MAP_FAILED ){ |
| 28053 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 28054 | goto shmpage_out; |
| 28055 | } |
| 28056 | }else{ |
| 28057 | pMem = sqlite3_malloc(szRegion); |
| 28058 | if( pMem==0 ){ |
| @@ -30801,10 +30818,14 @@ | |
| 30818 | UNIXVFS("unix-nfs", nfsIoFinder ), |
| 30819 | UNIXVFS("unix-proxy", proxyIoFinder ), |
| 30820 | #endif |
| 30821 | }; |
| 30822 | unsigned int i; /* Loop counter */ |
| 30823 | |
| 30824 | /* Double-check that the aSyscall[] array has been constructed |
| 30825 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 30826 | assert( ArraySize(aSyscall)==16 ); |
| 30827 | |
| 30828 | /* Register all VFSes defined in the aVfs[] array */ |
| 30829 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 30830 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 30831 | } |
| @@ -31147,10 +31168,11 @@ | |
| 31168 | HANDLE hShared; /* Shared memory segment used for locking */ |
| 31169 | winceLock local; /* Locks obtained by this instance of winFile */ |
| 31170 | winceLock *shared; /* Global shared lock memory for the file */ |
| 31171 | #endif |
| 31172 | }; |
| 31173 | |
| 31174 | |
| 31175 | /* |
| 31176 | ** Forward prototypes. |
| 31177 | */ |
| 31178 | static int getSectorSize( |
| @@ -31315,11 +31337,11 @@ | |
| 31337 | |
| 31338 | /* |
| 31339 | ** Convert UTF-8 to multibyte character string. Space to hold the |
| 31340 | ** returned string is obtained from malloc(). |
| 31341 | */ |
| 31342 | SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ |
| 31343 | char *zFilenameMbcs; |
| 31344 | WCHAR *zTmpWide; |
| 31345 | |
| 31346 | zTmpWide = utf8ToUnicode(zFilename); |
| 31347 | if( zTmpWide==0 ){ |
| @@ -31328,10 +31350,113 @@ | |
| 31350 | zFilenameMbcs = unicodeToMbcs(zTmpWide); |
| 31351 | free(zTmpWide); |
| 31352 | return zFilenameMbcs; |
| 31353 | } |
| 31354 | |
| 31355 | |
| 31356 | /* |
| 31357 | ** The return value of getLastErrorMsg |
| 31358 | ** is zero if the error message fits in the buffer, or non-zero |
| 31359 | ** otherwise (if the message was truncated). |
| 31360 | */ |
| 31361 | static int getLastErrorMsg(int nBuf, char *zBuf){ |
| 31362 | /* FormatMessage returns 0 on failure. Otherwise it |
| 31363 | ** returns the number of TCHARs written to the output |
| 31364 | ** buffer, excluding the terminating null char. |
| 31365 | */ |
| 31366 | DWORD error = GetLastError(); |
| 31367 | DWORD dwLen = 0; |
| 31368 | char *zOut = 0; |
| 31369 | |
| 31370 | if( isNT() ){ |
| 31371 | WCHAR *zTempWide = NULL; |
| 31372 | dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 31373 | NULL, |
| 31374 | error, |
| 31375 | 0, |
| 31376 | (LPWSTR) &zTempWide, |
| 31377 | 0, |
| 31378 | 0); |
| 31379 | if( dwLen > 0 ){ |
| 31380 | /* allocate a buffer and convert to UTF8 */ |
| 31381 | zOut = unicodeToUtf8(zTempWide); |
| 31382 | /* free the system buffer allocated by FormatMessage */ |
| 31383 | LocalFree(zTempWide); |
| 31384 | } |
| 31385 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 31386 | ** Since the ASCII version of these Windows API do not exist for WINCE, |
| 31387 | ** it's important to not reference them for WINCE builds. |
| 31388 | */ |
| 31389 | #if SQLITE_OS_WINCE==0 |
| 31390 | }else{ |
| 31391 | char *zTemp = NULL; |
| 31392 | dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 31393 | NULL, |
| 31394 | error, |
| 31395 | 0, |
| 31396 | (LPSTR) &zTemp, |
| 31397 | 0, |
| 31398 | 0); |
| 31399 | if( dwLen > 0 ){ |
| 31400 | /* allocate a buffer and convert to UTF8 */ |
| 31401 | zOut = sqlite3_win32_mbcs_to_utf8(zTemp); |
| 31402 | /* free the system buffer allocated by FormatMessage */ |
| 31403 | LocalFree(zTemp); |
| 31404 | } |
| 31405 | #endif |
| 31406 | } |
| 31407 | if( 0 == dwLen ){ |
| 31408 | sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error); |
| 31409 | }else{ |
| 31410 | /* copy a maximum of nBuf chars to output buffer */ |
| 31411 | sqlite3_snprintf(nBuf, zBuf, "%s", zOut); |
| 31412 | /* free the UTF8 buffer */ |
| 31413 | free(zOut); |
| 31414 | } |
| 31415 | return 0; |
| 31416 | } |
| 31417 | |
| 31418 | /* |
| 31419 | ** |
| 31420 | ** This function - winLogErrorAtLine() - is only ever called via the macro |
| 31421 | ** winLogError(). |
| 31422 | ** |
| 31423 | ** This routine is invoked after an error occurs in an OS function. |
| 31424 | ** It logs a message using sqlite3_log() containing the current value of |
| 31425 | ** error code and, if possible, the human-readable equivalent from |
| 31426 | ** FormatMessage. |
| 31427 | ** |
| 31428 | ** The first argument passed to the macro should be the error code that |
| 31429 | ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). |
| 31430 | ** The two subsequent arguments should be the name of the OS function that |
| 31431 | ** failed and the the associated file-system path, if any. |
| 31432 | */ |
| 31433 | #define winLogError(a,b,c) winLogErrorAtLine(a,b,c,__LINE__) |
| 31434 | static int winLogErrorAtLine( |
| 31435 | int errcode, /* SQLite error code */ |
| 31436 | const char *zFunc, /* Name of OS function that failed */ |
| 31437 | const char *zPath, /* File path associated with error */ |
| 31438 | int iLine /* Source line number where error occurred */ |
| 31439 | ){ |
| 31440 | char zMsg[500]; /* Human readable error text */ |
| 31441 | int i; /* Loop counter */ |
| 31442 | DWORD iErrno = GetLastError(); /* Error code */ |
| 31443 | |
| 31444 | zMsg[0] = 0; |
| 31445 | getLastErrorMsg(sizeof(zMsg), zMsg); |
| 31446 | assert( errcode!=SQLITE_OK ); |
| 31447 | if( zPath==0 ) zPath = ""; |
| 31448 | for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){} |
| 31449 | zMsg[i] = 0; |
| 31450 | sqlite3_log(errcode, |
| 31451 | "os_win.c:%d: (%d) %s(%s) - %s", |
| 31452 | iLine, iErrno, zFunc, zPath, zMsg |
| 31453 | ); |
| 31454 | |
| 31455 | return errcode; |
| 31456 | } |
| 31457 | |
| 31458 | #if SQLITE_OS_WINCE |
| 31459 | /************************************************************************* |
| 31460 | ** This section contains code for WinCE only. |
| 31461 | */ |
| 31462 | /* |
| @@ -31404,10 +31529,11 @@ | |
| 31529 | |
| 31530 | /* Create/open the named mutex */ |
| 31531 | pFile->hMutex = CreateMutexW(NULL, FALSE, zName); |
| 31532 | if (!pFile->hMutex){ |
| 31533 | pFile->lastErrno = GetLastError(); |
| 31534 | winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename); |
| 31535 | free(zName); |
| 31536 | return FALSE; |
| 31537 | } |
| 31538 | |
| 31539 | /* Acquire the mutex before continuing */ |
| @@ -31435,10 +31561,11 @@ | |
| 31561 | pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, |
| 31562 | FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); |
| 31563 | /* If mapping failed, close the shared memory handle and erase it */ |
| 31564 | if (!pFile->shared){ |
| 31565 | pFile->lastErrno = GetLastError(); |
| 31566 | winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename); |
| 31567 | CloseHandle(pFile->hShared); |
| 31568 | pFile->hShared = NULL; |
| 31569 | } |
| 31570 | } |
| 31571 | |
| @@ -31680,10 +31807,11 @@ | |
| 31807 | ** GetLastError(). |
| 31808 | */ |
| 31809 | dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); |
| 31810 | if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){ |
| 31811 | pFile->lastErrno = GetLastError(); |
| 31812 | winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath); |
| 31813 | return 1; |
| 31814 | } |
| 31815 | |
| 31816 | return 0; |
| 31817 | } |
| @@ -31725,11 +31853,12 @@ | |
| 31853 | free(pFile->zDeleteOnClose); |
| 31854 | } |
| 31855 | #endif |
| 31856 | OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); |
| 31857 | OpenCounter(-1); |
| 31858 | return rc ? SQLITE_OK |
| 31859 | : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath); |
| 31860 | } |
| 31861 | |
| 31862 | /* |
| 31863 | ** Read data from a file into a buffer. Return SQLITE_OK if all |
| 31864 | ** bytes were read successfully and SQLITE_IOERR if anything goes |
| @@ -31751,11 +31880,11 @@ | |
| 31880 | if( seekWinFile(pFile, offset) ){ |
| 31881 | return SQLITE_FULL; |
| 31882 | } |
| 31883 | if( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
| 31884 | pFile->lastErrno = GetLastError(); |
| 31885 | return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath); |
| 31886 | } |
| 31887 | if( nRead<(DWORD)amt ){ |
| 31888 | /* Unread parts of the buffer must be zero-filled */ |
| 31889 | memset(&((char*)pBuf)[nRead], 0, amt-nRead); |
| 31890 | return SQLITE_IOERR_SHORT_READ; |
| @@ -31802,11 +31931,11 @@ | |
| 31931 | |
| 31932 | if( rc ){ |
| 31933 | if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){ |
| 31934 | return SQLITE_FULL; |
| 31935 | } |
| 31936 | return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath); |
| 31937 | } |
| 31938 | return SQLITE_OK; |
| 31939 | } |
| 31940 | |
| 31941 | /* |
| @@ -31830,14 +31959,14 @@ | |
| 31959 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
| 31960 | } |
| 31961 | |
| 31962 | /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ |
| 31963 | if( seekWinFile(pFile, nByte) ){ |
| 31964 | rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath); |
| 31965 | }else if( 0==SetEndOfFile(pFile->h) ){ |
| 31966 | pFile->lastErrno = GetLastError(); |
| 31967 | rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath); |
| 31968 | } |
| 31969 | |
| 31970 | OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); |
| 31971 | return rc; |
| 31972 | } |
| @@ -31855,10 +31984,11 @@ | |
| 31984 | ** Make sure all writes to a particular file are committed to disk. |
| 31985 | */ |
| 31986 | static int winSync(sqlite3_file *id, int flags){ |
| 31987 | #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG) |
| 31988 | winFile *pFile = (winFile*)id; |
| 31989 | BOOL rc; |
| 31990 | #else |
| 31991 | UNUSED_PARAMETER(id); |
| 31992 | #endif |
| 31993 | |
| 31994 | assert( pFile ); |
| @@ -31867,36 +31997,37 @@ | |
| 31997 | || (flags&0x0F)==SQLITE_SYNC_FULL |
| 31998 | ); |
| 31999 | |
| 32000 | OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype)); |
| 32001 | |
| 32002 | /* Unix cannot, but some systems may return SQLITE_FULL from here. This |
| 32003 | ** line is to test that doing so does not cause any problems. |
| 32004 | */ |
| 32005 | SimulateDiskfullError( return SQLITE_FULL ); |
| 32006 | |
| 32007 | #ifndef SQLITE_TEST |
| 32008 | UNUSED_PARAMETER(flags); |
| 32009 | #else |
| 32010 | if( (flags&0x0F)==SQLITE_SYNC_FULL ){ |
| 32011 | sqlite3_fullsync_count++; |
| 32012 | } |
| 32013 | sqlite3_sync_count++; |
| 32014 | #endif |
| 32015 | |
| 32016 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 32017 | ** no-op |
| 32018 | */ |
| 32019 | #ifdef SQLITE_NO_SYNC |
| 32020 | return SQLITE_OK; |
| 32021 | #else |
| 32022 | rc = FlushFileBuffers(pFile->h); |
| 32023 | SimulateIOError( rc=FALSE ); |
| 32024 | if( rc ){ |
| 32025 | return SQLITE_OK; |
| 32026 | }else{ |
| 32027 | pFile->lastErrno = GetLastError(); |
| 32028 | return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath); |
| 32029 | } |
| 32030 | #endif |
| 32031 | } |
| 32032 | |
| 32033 | /* |
| @@ -31913,11 +32044,11 @@ | |
| 32044 | lowerBits = GetFileSize(pFile->h, &upperBits); |
| 32045 | if( (lowerBits == INVALID_FILE_SIZE) |
| 32046 | && ((error = GetLastError()) != NO_ERROR) ) |
| 32047 | { |
| 32048 | pFile->lastErrno = error; |
| 32049 | return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath); |
| 32050 | } |
| 32051 | *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; |
| 32052 | return SQLITE_OK; |
| 32053 | } |
| 32054 | |
| @@ -31952,10 +32083,11 @@ | |
| 32083 | res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0); |
| 32084 | #endif |
| 32085 | } |
| 32086 | if( res == 0 ){ |
| 32087 | pFile->lastErrno = GetLastError(); |
| 32088 | /* No need to log a failure to lock */ |
| 32089 | } |
| 32090 | return res; |
| 32091 | } |
| 32092 | |
| 32093 | /* |
| @@ -31972,10 +32104,11 @@ | |
| 32104 | res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); |
| 32105 | #endif |
| 32106 | } |
| 32107 | if( res == 0 ){ |
| 32108 | pFile->lastErrno = GetLastError(); |
| 32109 | winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath); |
| 32110 | } |
| 32111 | return res; |
| 32112 | } |
| 32113 | |
| 32114 | /* |
| @@ -32172,11 +32305,11 @@ | |
| 32305 | if( type>=EXCLUSIVE_LOCK ){ |
| 32306 | UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0); |
| 32307 | if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ |
| 32308 | /* This should never happen. We should always be able to |
| 32309 | ** reacquire the read lock */ |
| 32310 | rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath); |
| 32311 | } |
| 32312 | } |
| 32313 | if( type>=RESERVED_LOCK ){ |
| 32314 | UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0); |
| 32315 | } |
| @@ -32529,11 +32662,11 @@ | |
| 32662 | ** If not, truncate the file to zero length. |
| 32663 | */ |
| 32664 | if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ |
| 32665 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); |
| 32666 | if( rc!=SQLITE_OK ){ |
| 32667 | rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath); |
| 32668 | } |
| 32669 | } |
| 32670 | if( rc==SQLITE_OK ){ |
| 32671 | winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); |
| 32672 | rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); |
| @@ -32788,11 +32921,11 @@ | |
| 32921 | ** Check to see if it has been allocated (i.e. if the wal-index file is |
| 32922 | ** large enough to contain the requested region). |
| 32923 | */ |
| 32924 | rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); |
| 32925 | if( rc!=SQLITE_OK ){ |
| 32926 | rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath); |
| 32927 | goto shmpage_out; |
| 32928 | } |
| 32929 | |
| 32930 | if( sz<nByte ){ |
| 32931 | /* The requested memory region does not exist. If isWrite is set to |
| @@ -32802,11 +32935,11 @@ | |
| 32935 | ** the requested memory region. |
| 32936 | */ |
| 32937 | if( !isWrite ) goto shmpage_out; |
| 32938 | rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); |
| 32939 | if( rc!=SQLITE_OK ){ |
| 32940 | rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath); |
| 32941 | goto shmpage_out; |
| 32942 | } |
| 32943 | } |
| 32944 | |
| 32945 | /* Map the requested memory region into this processes address space. */ |
| @@ -32839,11 +32972,11 @@ | |
| 32972 | (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion, |
| 32973 | pMap ? "ok" : "failed")); |
| 32974 | } |
| 32975 | if( !pMap ){ |
| 32976 | pShmNode->lastErrno = GetLastError(); |
| 32977 | rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath); |
| 32978 | if( hMap ) CloseHandle(hMap); |
| 32979 | goto shmpage_out; |
| 32980 | } |
| 32981 | |
| 32982 | pShmNode->aRegion[pShmNode->nRegion].pMap = pMap; |
| @@ -32921,11 +33054,11 @@ | |
| 33054 | zConverted = utf8ToUnicode(zFilename); |
| 33055 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 33056 | */ |
| 33057 | #if SQLITE_OS_WINCE==0 |
| 33058 | }else{ |
| 33059 | zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); |
| 33060 | #endif |
| 33061 | } |
| 33062 | /* caller will handle out of memory */ |
| 33063 | return zConverted; |
| 33064 | } |
| @@ -33001,72 +33134,10 @@ | |
| 33134 | |
| 33135 | OSTRACE(("TEMP FILENAME: %s\n", zBuf)); |
| 33136 | return SQLITE_OK; |
| 33137 | } |
| 33138 | |
| 33139 | /* |
| 33140 | ** Open a file. |
| 33141 | */ |
| 33142 | static int winOpen( |
| 33143 | sqlite3_vfs *pVfs, /* Not used */ |
| @@ -33234,10 +33305,11 @@ | |
| 33305 | h, zName, dwDesiredAccess, |
| 33306 | h==INVALID_HANDLE_VALUE ? "failed" : "ok")); |
| 33307 | |
| 33308 | if( h==INVALID_HANDLE_VALUE ){ |
| 33309 | pFile->lastErrno = GetLastError(); |
| 33310 | winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name); |
| 33311 | free(zConverted); |
| 33312 | if( isReadWrite ){ |
| 33313 | return winOpen(pVfs, zName, id, |
| 33314 | ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags); |
| 33315 | }else{ |
| @@ -33337,11 +33409,12 @@ | |
| 33409 | OSTRACE(("DELETE \"%s\" %s\n", zFilename, |
| 33410 | ( (rc==INVALID_FILE_ATTRIBUTES) && (error==ERROR_FILE_NOT_FOUND)) ? |
| 33411 | "ok" : "failed" )); |
| 33412 | |
| 33413 | return ( (rc == INVALID_FILE_ATTRIBUTES) |
| 33414 | && (error == ERROR_FILE_NOT_FOUND)) ? SQLITE_OK : |
| 33415 | winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename); |
| 33416 | } |
| 33417 | |
| 33418 | /* |
| 33419 | ** Check the existance and status of a file. |
| 33420 | */ |
| @@ -33377,10 +33450,11 @@ | |
| 33450 | }else{ |
| 33451 | attr = sAttrData.dwFileAttributes; |
| 33452 | } |
| 33453 | }else{ |
| 33454 | if( GetLastError()!=ERROR_FILE_NOT_FOUND ){ |
| 33455 | winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename); |
| 33456 | free(zConverted); |
| 33457 | return SQLITE_IOERR_ACCESS; |
| 33458 | }else{ |
| 33459 | attr = INVALID_FILE_ATTRIBUTES; |
| 33460 | } |
| @@ -59911,11 +59985,11 @@ | |
| 59985 | /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */ |
| 59986 | VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */ |
| 59987 | |
| 59988 | /* Compilers may complain that mem1.u.i is potentially uninitialized. |
| 59989 | ** We could initialize it, as shown here, to silence those complaints. |
| 59990 | ** But in fact, mem1.u.i will never actually be used uninitialized, and doing |
| 59991 | ** the unnecessary initialization has a measurable negative performance |
| 59992 | ** impact, since this routine is a very high runner. And so, we choose |
| 59993 | ** to ignore the compiler warnings and leave this variable uninitialized. |
| 59994 | */ |
| 59995 | /* mem1.u.i = 0; // not needed, here to silence compiler warning */ |
| @@ -82329,10 +82403,25 @@ | |
| 82403 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 82404 | /* IMP: R-24470-31136 This function is an SQL wrapper around the |
| 82405 | ** sqlite3_sourceid() C interface. */ |
| 82406 | sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC); |
| 82407 | } |
| 82408 | |
| 82409 | /* |
| 82410 | ** Implementation of the sqlite_log() function. This is a wrapper around |
| 82411 | ** sqlite3_log(). The return value is NULL. The function exists purely for |
| 82412 | ** its side-effects. |
| 82413 | */ |
| 82414 | static void logFunc( |
| 82415 | sqlite3_context *context, |
| 82416 | int argc, |
| 82417 | sqlite3_value **argv |
| 82418 | ){ |
| 82419 | UNUSED_PARAMETER(argc); |
| 82420 | UNUSED_PARAMETER(context); |
| 82421 | sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1])); |
| 82422 | } |
| 82423 | |
| 82424 | /* |
| 82425 | ** Implementation of the sqlite_compileoption_used() function. |
| 82426 | ** The result is an integer that identifies if the compiler option |
| 82427 | ** was used to build SQLite. |
| @@ -83097,10 +83186,11 @@ | |
| 83186 | FUNCTION(random, 0, 0, 0, randomFunc ), |
| 83187 | FUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 83188 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 83189 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 83190 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| 83191 | FUNCTION(sqlite_log, 2, 0, 0, logFunc ), |
| 83192 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 83193 | FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 83194 | FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 83195 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 83196 | FUNCTION(quote, 1, 0, 0, quoteFunc ), |
| @@ -86073,10 +86163,22 @@ | |
| 86163 | } |
| 86164 | #ifndef SQLITE_OMIT_CHECK |
| 86165 | if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){ |
| 86166 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 86167 | } |
| 86168 | #endif |
| 86169 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 86170 | /* Disallow the transfer optimization if the destination table constains |
| 86171 | ** any foreign key constraints. This is more restrictive than necessary. |
| 86172 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 86173 | ** command, and the VACUUM command disables foreign key constraints. So |
| 86174 | ** the extra complication to make this rule less restrictive is probably |
| 86175 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 86176 | */ |
| 86177 | if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 86178 | return 0; |
| 86179 | } |
| 86180 | #endif |
| 86181 | |
| 86182 | /* If we get this far, it means either: |
| 86183 | ** |
| 86184 | ** * We can always do the transfer if the table contains an |
| @@ -94017,16 +94119,18 @@ | |
| 94119 | ** does, then we can assume that it consumes less space on disk and |
| 94120 | ** will therefore be cheaper to scan to determine the query result. |
| 94121 | ** In this case set iRoot to the root page number of the index b-tree |
| 94122 | ** and pKeyInfo to the KeyInfo structure required to navigate the |
| 94123 | ** index. |
| 94124 | ** |
| 94125 | ** (2011-04-15) Do not do a full scan of an unordered index. |
| 94126 | ** |
| 94127 | ** In practice the KeyInfo structure will not be used. It is only |
| 94128 | ** passed to keep OP_OpenRead happy. |
| 94129 | */ |
| 94130 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 94131 | if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){ |
| 94132 | pBest = pIdx; |
| 94133 | } |
| 94134 | } |
| 94135 | if( pBest && pBest->nColumn<pTab->nCol ){ |
| 94136 | iRoot = pBest->tnum; |
| @@ -118141,10 +118245,18 @@ | |
| 118245 | sqlite3_tokenizer_cursor *pCsr; |
| 118246 | int (*xNext)(sqlite3_tokenizer_cursor *pCursor, |
| 118247 | const char**,int*,int*,int*,int*); |
| 118248 | |
| 118249 | assert( pTokenizer && pModule ); |
| 118250 | |
| 118251 | /* If the user has inserted a NULL value, this function may be called with |
| 118252 | ** zText==0. In this case, add zero token entries to the hash table and |
| 118253 | ** return early. */ |
| 118254 | if( zText==0 ){ |
| 118255 | *pnWord = 0; |
| 118256 | return SQLITE_OK; |
| 118257 | } |
| 118258 | |
| 118259 | rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr); |
| 118260 | if( rc!=SQLITE_OK ){ |
| 118261 | return rc; |
| 118262 | } |
| @@ -118232,15 +118344,13 @@ | |
| 118344 | */ |
| 118345 | static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){ |
| 118346 | int i; /* Iterator variable */ |
| 118347 | for(i=2; i<p->nColumn+2; i++){ |
| 118348 | const char *zText = (const char *)sqlite3_value_text(apVal[i]); |
| 118349 | int rc = fts3PendingTermsAdd(p, zText, i-2, &aSz[i-2]); |
| 118350 | if( rc!=SQLITE_OK ){ |
| 118351 | return rc; |
| 118352 | } |
| 118353 | aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]); |
| 118354 | } |
| 118355 | return SQLITE_OK; |
| 118356 | } |
| 118357 |
+4
-2
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -105,13 +105,13 @@ | ||
| 105 | 105 | ** |
| 106 | 106 | ** See also: [sqlite3_libversion()], |
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | -#define SQLITE_VERSION "3.7.6" | |
| 110 | +#define SQLITE_VERSION "3.7.6.1" | |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | -#define SQLITE_SOURCE_ID "2011-04-12 01:58:40 f9d43fa363d54beab6f45db005abac0a7c0c47a7" | |
| 112 | +#define SQLITE_SOURCE_ID "2011-04-27 16:05:42 7b479b9bee93df909edecd44c7d6584d943b39c9" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -450,10 +450,12 @@ | ||
| 450 | 450 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 451 | 451 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 452 | 452 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 453 | 453 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 454 | 454 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 455 | +#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) | |
| 456 | +#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) | |
| 455 | 457 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 456 | 458 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 457 | 459 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 458 | 460 | |
| 459 | 461 | /* |
| 460 | 462 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-04-12 01:58:40 f9d43fa363d54beab6f45db005abac0a7c0c47a7" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -450,10 +450,12 @@ | |
| 450 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 451 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 452 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 453 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 454 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 455 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 456 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 457 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 458 | |
| 459 | /* |
| 460 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6.1" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-04-27 16:05:42 7b479b9bee93df909edecd44c7d6584d943b39c9" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -450,10 +450,12 @@ | |
| 450 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 451 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 452 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 453 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 454 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 455 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 456 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 457 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 458 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 459 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 460 | |
| 461 | /* |
| 462 |