Fossil SCM

Update to the latest SQLite snapshot that exposes the UTF8 to MBCS conversion routine in the windows driver to applications.

drh 2011-04-27 16:07 trunk
Commit 989fc1f2b6c71b0e1511360467d1f2bd54381f49
2 files changed +217 -107 +4 -2
+217 -107
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** 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
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -648,13 +648,13 @@
648648
**
649649
** See also: [sqlite3_libversion()],
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653
-#define SQLITE_VERSION "3.7.6"
653
+#define SQLITE_VERSION "3.7.6.1"
654654
#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"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -993,10 +993,12 @@
993993
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
994994
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
995995
#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
996996
#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
997997
#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))
9981000
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
9991001
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
10001002
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
10011003
10021004
/*
@@ -17948,11 +17950,11 @@
1794817950
assert( sqlite3_mutex_held(mem0.mutex) );
1794917951
nFull = sqlite3GlobalConfig.m.xRoundup(n);
1795017952
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
1795117953
if( mem0.alarmCallback!=0 ){
1795217954
int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
17953
- if( nUsed+nFull >= mem0.alarmThreshold ){
17955
+ if( nUsed >= mem0.alarmThreshold - nFull ){
1795417956
mem0.nearlyFull = 1;
1795517957
sqlite3MallocAlarm(nFull);
1795617958
}else{
1795717959
mem0.nearlyFull = 0;
1795817960
}
@@ -18189,11 +18191,11 @@
1818918191
1819018192
/*
1819118193
** Change the size of an existing memory allocation
1819218194
*/
1819318195
SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
18194
- int nOld, nNew;
18196
+ int nOld, nNew, nDiff;
1819518197
void *pNew;
1819618198
if( pOld==0 ){
1819718199
return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
1819818200
}
1819918201
if( nBytes<=0 ){
@@ -18212,12 +18214,13 @@
1821218214
if( nOld==nNew ){
1821318215
pNew = pOld;
1821418216
}else if( sqlite3GlobalConfig.bMemstat ){
1821518217
sqlite3_mutex_enter(mem0.mutex);
1821618218
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 ){
1821918222
sqlite3MallocAlarm(nNew-nOld);
1822018223
}
1822118224
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
1822218225
assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
1822318226
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
@@ -18225,11 +18228,11 @@
1822518228
sqlite3MallocAlarm(nBytes);
1822618229
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1822718230
}
1822818231
if( pNew ){
1822918232
nNew = sqlite3MallocSize(pNew);
18230
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
18233
+ sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff);
1823118234
}
1823218235
sqlite3_mutex_leave(mem0.mutex);
1823318236
}else{
1823418237
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1823518238
}
@@ -24398,10 +24401,22 @@
2439824401
#if SQLITE_THREADSAFE
2439924402
#define threadid pthread_self()
2440024403
#else
2440124404
#define threadid 0
2440224405
#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
+}
2440324418
2440424419
/*
2440524420
** Many system calls are accessed through pointer-to-functions so that
2440624421
** they may be overridden at runtime to facilitate fault injection during
2440724422
** testing and sandboxing. The following array holds the names and pointers
@@ -24410,11 +24425,11 @@
2441024425
static struct unix_syscall {
2441124426
const char *zName; /* Name of the sytem call */
2441224427
sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
2441324428
sqlite3_syscall_ptr pDefault; /* Default value */
2441424429
} aSyscall[] = {
24415
- { "open", (sqlite3_syscall_ptr)open, 0 },
24430
+ { "open", (sqlite3_syscall_ptr)posixOpen, 0 },
2441624431
#define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
2441724432
2441824433
{ "close", (sqlite3_syscall_ptr)close, 0 },
2441924434
#define osClose ((int(*)(int))aSyscall[1].pCurrent)
2442024435
@@ -24448,11 +24463,11 @@
2444824463
#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
2444924464
2445024465
{ "read", (sqlite3_syscall_ptr)read, 0 },
2445124466
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
2445224467
24453
-#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
24468
+#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
2445424469
{ "pread", (sqlite3_syscall_ptr)pread, 0 },
2445524470
#else
2445624471
{ "pread", (sqlite3_syscall_ptr)0, 0 },
2445724472
#endif
2445824473
#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
@@ -24465,11 +24480,11 @@
2446524480
#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
2446624481
2446724482
{ "write", (sqlite3_syscall_ptr)write, 0 },
2446824483
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
2446924484
24470
-#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
24485
+#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
2447124486
{ "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
2447224487
#else
2447324488
{ "pwrite", (sqlite3_syscall_ptr)0, 0 },
2447424489
#endif
2447524490
#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
@@ -24483,12 +24498,14 @@
2448324498
#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
2448424499
aSyscall[13].pCurrent)
2448524500
2448624501
#if SQLITE_ENABLE_LOCKING_STYLE
2448724502
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
24503
+#else
24504
+ { "fchmod", (sqlite3_syscall_ptr)0, 0 },
24505
+#endif
2448824506
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
24489
-#endif
2449024507
2449124508
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
2449224509
{ "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
2449324510
#else
2449424511
{ "fallocate", (sqlite3_syscall_ptr)0, 0 },
@@ -25049,11 +25066,11 @@
2504925066
unixShmNode *pShmNode; /* Shared memory associated with this inode */
2505025067
int nLock; /* Number of outstanding file locks */
2505125068
UnixUnusedFd *pUnused; /* Unused file descriptors to close */
2505225069
unixInodeInfo *pNext; /* List of all unixInodeInfo objects */
2505325070
unixInodeInfo *pPrev; /* .... doubly linked */
25054
-#if defined(SQLITE_ENABLE_LOCKING_STYLE)
25071
+#if SQLITE_ENABLE_LOCKING_STYLE
2505525072
unsigned long long sharedByte; /* for AFP simulated shared lock */
2505625073
#endif
2505725074
#if OS_VXWORKS
2505825075
sem_t *pSem; /* Named POSIX semaphore */
2505925076
char aSemName[MAX_PATHNAME+2]; /* Name of that semaphore */
@@ -27206,11 +27223,11 @@
2720627223
}
2720727224
SimulateIOError(( wrote=(-1), amt=1 ));
2720827225
SimulateDiskfullError(( wrote=0, amt=1 ));
2720927226
2721027227
if( amt>0 ){
27211
- if( wrote<0 ){
27228
+ if( wrote<0 && pFile->lastErrno!=ENOSPC ){
2721227229
/* lastErrno set by seekAndWrite */
2721327230
return SQLITE_IOERR_WRITE;
2721427231
}else{
2721527232
pFile->lastErrno = 0; /* not a system error */
2721627233
return SQLITE_FULL;
@@ -28031,11 +28048,11 @@
2803128048
if( pShmNode->h>=0 ){
2803228049
pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
2803328050
MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
2803428051
);
2803528052
if( pMem==MAP_FAILED ){
28036
- rc = SQLITE_IOERR;
28053
+ rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
2803728054
goto shmpage_out;
2803828055
}
2803928056
}else{
2804028057
pMem = sqlite3_malloc(szRegion);
2804128058
if( pMem==0 ){
@@ -30801,10 +30818,14 @@
3080130818
UNIXVFS("unix-nfs", nfsIoFinder ),
3080230819
UNIXVFS("unix-proxy", proxyIoFinder ),
3080330820
#endif
3080430821
};
3080530822
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 );
3080630827
3080730828
/* Register all VFSes defined in the aVfs[] array */
3080830829
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
3080930830
sqlite3_vfs_register(&aVfs[i], i==0);
3081030831
}
@@ -31147,10 +31168,11 @@
3114731168
HANDLE hShared; /* Shared memory segment used for locking */
3114831169
winceLock local; /* Locks obtained by this instance of winFile */
3114931170
winceLock *shared; /* Global shared lock memory for the file */
3115031171
#endif
3115131172
};
31173
+
3115231174
3115331175
/*
3115431176
** Forward prototypes.
3115531177
*/
3115631178
static int getSectorSize(
@@ -31315,11 +31337,11 @@
3131531337
3131631338
/*
3131731339
** Convert UTF-8 to multibyte character string. Space to hold the
3131831340
** returned string is obtained from malloc().
3131931341
*/
31320
-static char *utf8ToMbcs(const char *zFilename){
31342
+SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){
3132131343
char *zFilenameMbcs;
3132231344
WCHAR *zTmpWide;
3132331345
3132431346
zTmpWide = utf8ToUnicode(zFilename);
3132531347
if( zTmpWide==0 ){
@@ -31328,10 +31350,113 @@
3132831350
zFilenameMbcs = unicodeToMbcs(zTmpWide);
3132931351
free(zTmpWide);
3133031352
return zFilenameMbcs;
3133131353
}
3133231354
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
+
3133331458
#if SQLITE_OS_WINCE
3133431459
/*************************************************************************
3133531460
** This section contains code for WinCE only.
3133631461
*/
3133731462
/*
@@ -31404,10 +31529,11 @@
3140431529
3140531530
/* Create/open the named mutex */
3140631531
pFile->hMutex = CreateMutexW(NULL, FALSE, zName);
3140731532
if (!pFile->hMutex){
3140831533
pFile->lastErrno = GetLastError();
31534
+ winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename);
3140931535
free(zName);
3141031536
return FALSE;
3141131537
}
3141231538
3141331539
/* Acquire the mutex before continuing */
@@ -31435,10 +31561,11 @@
3143531561
pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared,
3143631562
FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
3143731563
/* If mapping failed, close the shared memory handle and erase it */
3143831564
if (!pFile->shared){
3143931565
pFile->lastErrno = GetLastError();
31566
+ winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename);
3144031567
CloseHandle(pFile->hShared);
3144131568
pFile->hShared = NULL;
3144231569
}
3144331570
}
3144431571
@@ -31680,10 +31807,11 @@
3168031807
** GetLastError().
3168131808
*/
3168231809
dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
3168331810
if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){
3168431811
pFile->lastErrno = GetLastError();
31812
+ winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath);
3168531813
return 1;
3168631814
}
3168731815
3168831816
return 0;
3168931817
}
@@ -31725,11 +31853,12 @@
3172531853
free(pFile->zDeleteOnClose);
3172631854
}
3172731855
#endif
3172831856
OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
3172931857
OpenCounter(-1);
31730
- return rc ? SQLITE_OK : SQLITE_IOERR;
31858
+ return rc ? SQLITE_OK
31859
+ : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath);
3173131860
}
3173231861
3173331862
/*
3173431863
** Read data from a file into a buffer. Return SQLITE_OK if all
3173531864
** bytes were read successfully and SQLITE_IOERR if anything goes
@@ -31751,11 +31880,11 @@
3175131880
if( seekWinFile(pFile, offset) ){
3175231881
return SQLITE_FULL;
3175331882
}
3175431883
if( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
3175531884
pFile->lastErrno = GetLastError();
31756
- return SQLITE_IOERR_READ;
31885
+ return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath);
3175731886
}
3175831887
if( nRead<(DWORD)amt ){
3175931888
/* Unread parts of the buffer must be zero-filled */
3176031889
memset(&((char*)pBuf)[nRead], 0, amt-nRead);
3176131890
return SQLITE_IOERR_SHORT_READ;
@@ -31802,11 +31931,11 @@
3180231931
3180331932
if( rc ){
3180431933
if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
3180531934
return SQLITE_FULL;
3180631935
}
31807
- return SQLITE_IOERR_WRITE;
31936
+ return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath);
3180831937
}
3180931938
return SQLITE_OK;
3181031939
}
3181131940
3181231941
/*
@@ -31830,14 +31959,14 @@
3183031959
nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
3183131960
}
3183231961
3183331962
/* SetEndOfFile() returns non-zero when successful, or zero when it fails. */
3183431963
if( seekWinFile(pFile, nByte) ){
31835
- rc = SQLITE_IOERR_TRUNCATE;
31964
+ rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath);
3183631965
}else if( 0==SetEndOfFile(pFile->h) ){
3183731966
pFile->lastErrno = GetLastError();
31838
- rc = SQLITE_IOERR_TRUNCATE;
31967
+ rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath);
3183931968
}
3184031969
3184131970
OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok"));
3184231971
return rc;
3184331972
}
@@ -31855,10 +31984,11 @@
3185531984
** Make sure all writes to a particular file are committed to disk.
3185631985
*/
3185731986
static int winSync(sqlite3_file *id, int flags){
3185831987
#if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG)
3185931988
winFile *pFile = (winFile*)id;
31989
+ BOOL rc;
3186031990
#else
3186131991
UNUSED_PARAMETER(id);
3186231992
#endif
3186331993
3186431994
assert( pFile );
@@ -31867,36 +31997,37 @@
3186731997
|| (flags&0x0F)==SQLITE_SYNC_FULL
3186831998
);
3186931999
3187032000
OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
3187132001
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
+
3187232007
#ifndef SQLITE_TEST
3187332008
UNUSED_PARAMETER(flags);
3187432009
#else
31875
- if( flags & SQLITE_SYNC_FULL ){
32010
+ if( (flags&0x0F)==SQLITE_SYNC_FULL ){
3187632011
sqlite3_fullsync_count++;
3187732012
}
3187832013
sqlite3_sync_count++;
3187932014
#endif
3188032015
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
-
3188732016
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
3188832017
** no-op
3188932018
*/
3189032019
#ifdef SQLITE_NO_SYNC
3189132020
return SQLITE_OK;
3189232021
#else
31893
- if( FlushFileBuffers(pFile->h) ){
32022
+ rc = FlushFileBuffers(pFile->h);
32023
+ SimulateIOError( rc=FALSE );
32024
+ if( rc ){
3189432025
return SQLITE_OK;
3189532026
}else{
3189632027
pFile->lastErrno = GetLastError();
31897
- return SQLITE_IOERR;
32028
+ return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath);
3189832029
}
3189932030
#endif
3190032031
}
3190132032
3190232033
/*
@@ -31913,11 +32044,11 @@
3191332044
lowerBits = GetFileSize(pFile->h, &upperBits);
3191432045
if( (lowerBits == INVALID_FILE_SIZE)
3191532046
&& ((error = GetLastError()) != NO_ERROR) )
3191632047
{
3191732048
pFile->lastErrno = error;
31918
- return SQLITE_IOERR_FSTAT;
32049
+ return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath);
3191932050
}
3192032051
*pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
3192132052
return SQLITE_OK;
3192232053
}
3192332054
@@ -31952,10 +32083,11 @@
3195232083
res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
3195332084
#endif
3195432085
}
3195532086
if( res == 0 ){
3195632087
pFile->lastErrno = GetLastError();
32088
+ /* No need to log a failure to lock */
3195732089
}
3195832090
return res;
3195932091
}
3196032092
3196132093
/*
@@ -31972,10 +32104,11 @@
3197232104
res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
3197332105
#endif
3197432106
}
3197532107
if( res == 0 ){
3197632108
pFile->lastErrno = GetLastError();
32109
+ winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath);
3197732110
}
3197832111
return res;
3197932112
}
3198032113
3198132114
/*
@@ -32172,11 +32305,11 @@
3217232305
if( type>=EXCLUSIVE_LOCK ){
3217332306
UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
3217432307
if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
3217532308
/* This should never happen. We should always be able to
3217632309
** reacquire the read lock */
32177
- rc = SQLITE_IOERR_UNLOCK;
32310
+ rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath);
3217832311
}
3217932312
}
3218032313
if( type>=RESERVED_LOCK ){
3218132314
UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
3218232315
}
@@ -32529,11 +32662,11 @@
3252932662
** If not, truncate the file to zero length.
3253032663
*/
3253132664
if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
3253232665
rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
3253332666
if( rc!=SQLITE_OK ){
32534
- rc = SQLITE_IOERR_SHMOPEN;
32667
+ rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath);
3253532668
}
3253632669
}
3253732670
if( rc==SQLITE_OK ){
3253832671
winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
3253932672
rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1);
@@ -32788,11 +32921,11 @@
3278832921
** Check to see if it has been allocated (i.e. if the wal-index file is
3278932922
** large enough to contain the requested region).
3279032923
*/
3279132924
rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz);
3279232925
if( rc!=SQLITE_OK ){
32793
- rc = SQLITE_IOERR_SHMSIZE;
32926
+ rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath);
3279432927
goto shmpage_out;
3279532928
}
3279632929
3279732930
if( sz<nByte ){
3279832931
/* The requested memory region does not exist. If isWrite is set to
@@ -32802,11 +32935,11 @@
3280232935
** the requested memory region.
3280332936
*/
3280432937
if( !isWrite ) goto shmpage_out;
3280532938
rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte);
3280632939
if( rc!=SQLITE_OK ){
32807
- rc = SQLITE_IOERR_SHMSIZE;
32940
+ rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath);
3280832941
goto shmpage_out;
3280932942
}
3281032943
}
3281132944
3281232945
/* Map the requested memory region into this processes address space. */
@@ -32839,11 +32972,11 @@
3283932972
(int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
3284032973
pMap ? "ok" : "failed"));
3284132974
}
3284232975
if( !pMap ){
3284332976
pShmNode->lastErrno = GetLastError();
32844
- rc = SQLITE_IOERR;
32977
+ rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath);
3284532978
if( hMap ) CloseHandle(hMap);
3284632979
goto shmpage_out;
3284732980
}
3284832981
3284932982
pShmNode->aRegion[pShmNode->nRegion].pMap = pMap;
@@ -32921,11 +33054,11 @@
3292133054
zConverted = utf8ToUnicode(zFilename);
3292233055
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
3292333056
*/
3292433057
#if SQLITE_OS_WINCE==0
3292533058
}else{
32926
- zConverted = utf8ToMbcs(zFilename);
33059
+ zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
3292733060
#endif
3292833061
}
3292933062
/* caller will handle out of memory */
3293033063
return zConverted;
3293133064
}
@@ -33001,72 +33134,10 @@
3300133134
3300233135
OSTRACE(("TEMP FILENAME: %s\n", zBuf));
3300333136
return SQLITE_OK;
3300433137
}
3300533138
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
-
3306833139
/*
3306933140
** Open a file.
3307033141
*/
3307133142
static int winOpen(
3307233143
sqlite3_vfs *pVfs, /* Not used */
@@ -33234,10 +33305,11 @@
3323433305
h, zName, dwDesiredAccess,
3323533306
h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
3323633307
3323733308
if( h==INVALID_HANDLE_VALUE ){
3323833309
pFile->lastErrno = GetLastError();
33310
+ winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name);
3323933311
free(zConverted);
3324033312
if( isReadWrite ){
3324133313
return winOpen(pVfs, zName, id,
3324233314
((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
3324333315
}else{
@@ -33337,11 +33409,12 @@
3333733409
OSTRACE(("DELETE \"%s\" %s\n", zFilename,
3333833410
( (rc==INVALID_FILE_ATTRIBUTES) && (error==ERROR_FILE_NOT_FOUND)) ?
3333933411
"ok" : "failed" ));
3334033412
3334133413
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);
3334333416
}
3334433417
3334533418
/*
3334633419
** Check the existance and status of a file.
3334733420
*/
@@ -33377,10 +33450,11 @@
3337733450
}else{
3337833451
attr = sAttrData.dwFileAttributes;
3337933452
}
3338033453
}else{
3338133454
if( GetLastError()!=ERROR_FILE_NOT_FOUND ){
33455
+ winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename);
3338233456
free(zConverted);
3338333457
return SQLITE_IOERR_ACCESS;
3338433458
}else{
3338533459
attr = INVALID_FILE_ATTRIBUTES;
3338633460
}
@@ -59911,11 +59985,11 @@
5991159985
/* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
5991259986
VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
5991359987
5991459988
/* Compilers may complain that mem1.u.i is potentially uninitialized.
5991559989
** 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
5991759991
** the unnecessary initialization has a measurable negative performance
5991859992
** impact, since this routine is a very high runner. And so, we choose
5991959993
** to ignore the compiler warnings and leave this variable uninitialized.
5992059994
*/
5992159995
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
@@ -82329,10 +82403,25 @@
8232982403
UNUSED_PARAMETER2(NotUsed, NotUsed2);
8233082404
/* IMP: R-24470-31136 This function is an SQL wrapper around the
8233182405
** sqlite3_sourceid() C interface. */
8233282406
sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC);
8233382407
}
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
+}
8233482423
8233582424
/*
8233682425
** Implementation of the sqlite_compileoption_used() function.
8233782426
** The result is an integer that identifies if the compiler option
8233882427
** was used to build SQLite.
@@ -83097,10 +83186,11 @@
8309783186
FUNCTION(random, 0, 0, 0, randomFunc ),
8309883187
FUNCTION(randomblob, 1, 0, 0, randomBlob ),
8309983188
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
8310083189
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
8310183190
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
83191
+ FUNCTION(sqlite_log, 2, 0, 0, logFunc ),
8310283192
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
8310383193
FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
8310483194
FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
8310583195
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
8310683196
FUNCTION(quote, 1, 0, 0, quoteFunc ),
@@ -86073,10 +86163,22 @@
8607386163
}
8607486164
#ifndef SQLITE_OMIT_CHECK
8607586165
if( pDest->pCheck && sqlite3ExprCompare(pSrc->pCheck, pDest->pCheck) ){
8607686166
return 0; /* Tables have different CHECK constraints. Ticket #2252 */
8607786167
}
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
+ }
8607886180
#endif
8607986181
8608086182
/* If we get this far, it means either:
8608186183
**
8608286184
** * We can always do the transfer if the table contains an
@@ -94017,16 +94119,18 @@
9401794119
** does, then we can assume that it consumes less space on disk and
9401894120
** will therefore be cheaper to scan to determine the query result.
9401994121
** In this case set iRoot to the root page number of the index b-tree
9402094122
** and pKeyInfo to the KeyInfo structure required to navigate the
9402194123
** index.
94124
+ **
94125
+ ** (2011-04-15) Do not do a full scan of an unordered index.
9402294126
**
9402394127
** In practice the KeyInfo structure will not be used. It is only
9402494128
** passed to keep OP_OpenRead happy.
9402594129
*/
9402694130
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) ){
9402894132
pBest = pIdx;
9402994133
}
9403094134
}
9403194135
if( pBest && pBest->nColumn<pTab->nCol ){
9403294136
iRoot = pBest->tnum;
@@ -118141,10 +118245,18 @@
118141118245
sqlite3_tokenizer_cursor *pCsr;
118142118246
int (*xNext)(sqlite3_tokenizer_cursor *pCursor,
118143118247
const char**,int*,int*,int*,int*);
118144118248
118145118249
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
+ }
118146118258
118147118259
rc = pModule->xOpen(pTokenizer, zText, -1, &pCsr);
118148118260
if( rc!=SQLITE_OK ){
118149118261
return rc;
118150118262
}
@@ -118232,15 +118344,13 @@
118232118344
*/
118233118345
static int fts3InsertTerms(Fts3Table *p, sqlite3_value **apVal, u32 *aSz){
118234118346
int i; /* Iterator variable */
118235118347
for(i=2; i<p->nColumn+2; i++){
118236118348
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;
118242118352
}
118243118353
aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
118244118354
}
118245118355
return SQLITE_OK;
118246118356
}
118247118357
--- 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 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.6"
110
+#define SQLITE_VERSION "3.7.6.1"
111111
#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"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -450,10 +450,12 @@
450450
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
451451
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
452452
#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
453453
#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
454454
#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))
455457
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
456458
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
457459
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
458460
459461
/*
460462
--- 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

Keyboard Shortcuts

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