Fossil SCM

Upgrade the built-in SQLite to the latest 3.8.6 alpha from upstream.

mistachkin 2014-07-31 19:02 trunk
Commit 5ce85eb6f84350dce5eeed42972e14d73e092983
2 files changed +624 -231 +10 -4
+624 -231
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222222
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223223
** [sqlite_version()] and [sqlite_source_id()].
224224
*/
225225
#define SQLITE_VERSION "3.8.6"
226226
#define SQLITE_VERSION_NUMBER 3008006
227
-#define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
227
+#define SQLITE_SOURCE_ID "2014-07-31 18:54:01 1e5489faff093d6a8e538061e45532f9050e9459"
228228
229229
/*
230230
** CAPI3REF: Run-Time Library Version Numbers
231231
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232232
**
@@ -5993,14 +5993,16 @@
59935993
** <ul>
59945994
** <li> SQLITE_MUTEX_FAST
59955995
** <li> SQLITE_MUTEX_RECURSIVE
59965996
** <li> SQLITE_MUTEX_STATIC_MASTER
59975997
** <li> SQLITE_MUTEX_STATIC_MEM
5998
-** <li> SQLITE_MUTEX_STATIC_MEM2
5998
+** <li> SQLITE_MUTEX_STATIC_OPEN
59995999
** <li> SQLITE_MUTEX_STATIC_PRNG
60006000
** <li> SQLITE_MUTEX_STATIC_LRU
6001
-** <li> SQLITE_MUTEX_STATIC_LRU2
6001
+** <li> SQLITE_MUTEX_STATIC_PMEM
6002
+** <li> SQLITE_MUTEX_STATIC_APP1
6003
+** <li> SQLITE_MUTEX_STATIC_APP2
60026004
** </ul>)^
60036005
**
60046006
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
60056007
** cause sqlite3_mutex_alloc() to create
60066008
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6200,10 +6202,13 @@
62006202
#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
62016203
#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
62026204
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
62036205
#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
62046206
#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6207
+#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6208
+#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6209
+#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
62056210
62066211
/*
62076212
** CAPI3REF: Retrieve the mutex for a database connection
62086213
**
62096214
** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6295,11 +6300,12 @@
62956300
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
62966301
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
62976302
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
62986303
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
62996304
#define SQLITE_TESTCTRL_BYTEORDER 22
6300
-#define SQLITE_TESTCTRL_LAST 22
6305
+#define SQLITE_TESTCTRL_ISINIT 23
6306
+#define SQLITE_TESTCTRL_LAST 23
63016307
63026308
/*
63036309
** CAPI3REF: SQLite Runtime Status
63046310
**
63056311
** ^This interface is used to retrieve runtime status information
@@ -9325,14 +9331,14 @@
93259331
#define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */
93269332
#define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */
93279333
#define OP_SorterOpen 57
93289334
#define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
93299335
#define OP_Close 59
9330
-#define OP_SeekLT 60
9331
-#define OP_SeekLE 61
9332
-#define OP_SeekGE 62
9333
-#define OP_SeekGT 63
9336
+#define OP_SeekLT 60 /* synopsis: key=r[P3@P4] */
9337
+#define OP_SeekLE 61 /* synopsis: key=r[P3@P4] */
9338
+#define OP_SeekGE 62 /* synopsis: key=r[P3@P4] */
9339
+#define OP_SeekGT 63 /* synopsis: key=r[P3@P4] */
93349340
#define OP_Seek 64 /* synopsis: intkey=r[P2] */
93359341
#define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */
93369342
#define OP_NotFound 66 /* synopsis: key=r[P3@P4] */
93379343
#define OP_Found 67 /* synopsis: key=r[P3@P4] */
93389344
#define OP_NotExists 68 /* synopsis: intkey=r[P3] */
@@ -9360,11 +9366,11 @@
93609366
#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
93619367
#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
93629368
#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
93639369
#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
93649370
#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9365
-#define OP_SorterCompare 95 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9371
+#define OP_SorterCompare 95 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
93669372
#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
93679373
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
93689374
#define OP_SorterData 98 /* synopsis: r[P2]=data */
93699375
#define OP_RowKey 99 /* synopsis: r[P2]=key */
93709376
#define OP_RowData 100 /* synopsis: r[P2]=data */
@@ -12852,11 +12858,11 @@
1285212858
#ifdef SQLITE_ENABLE_8_3_NAMES
1285312859
SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
1285412860
#else
1285512861
# define sqlite3FileSuffix3(X,Y)
1285612862
#endif
12857
-SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,int);
12863
+SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,u8);
1285812864
1285912865
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1286012866
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1286112867
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1286212868
void(*)(void*));
@@ -13927,10 +13933,13 @@
1392713933
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
1392813934
int seekResult; /* Result of previous sqlite3BtreeMoveto() */
1392913935
int pseudoTableReg; /* Register holding pseudotable content. */
1393013936
i16 nField; /* Number of fields in the header */
1393113937
u16 nHdrParsed; /* Number of header fields parsed so far */
13938
+#ifdef SQLITE_DEBUG
13939
+ u8 seekOp; /* Most recent seek operation on this cursor */
13940
+#endif
1393213941
i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
1393313942
u8 nullRow; /* True if pointing to a row with no data */
1393413943
u8 rowidIsValid; /* True if lastRowid is valid */
1393513944
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1393613945
Bool isEphemeral:1; /* True for an ephemeral table */
@@ -18448,11 +18457,11 @@
1844818457
/*
1844918458
** Retrieve a pointer to a static mutex or allocate a new dynamic one.
1845018459
*/
1845118460
SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
1845218461
#ifndef SQLITE_OMIT_AUTOINIT
18453
- if( sqlite3_initialize() ) return 0;
18462
+ if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
1845418463
#endif
1845518464
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
1845618465
}
1845718466
1845818467
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -18629,11 +18638,11 @@
1862918638
** The sqlite3_mutex_alloc() routine allocates a new
1863018639
** mutex and returns a pointer to it. If it returns NULL
1863118640
** that means that a mutex could not be allocated.
1863218641
*/
1863318642
static sqlite3_mutex *debugMutexAlloc(int id){
18634
- static sqlite3_debug_mutex aStatic[6];
18643
+ static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1];
1863518644
sqlite3_debug_mutex *pNew = 0;
1863618645
switch( id ){
1863718646
case SQLITE_MUTEX_FAST:
1863818647
case SQLITE_MUTEX_RECURSIVE: {
1863918648
pNew = sqlite3Malloc(sizeof(*pNew));
@@ -18826,14 +18835,17 @@
1882618835
** <ul>
1882718836
** <li> SQLITE_MUTEX_FAST
1882818837
** <li> SQLITE_MUTEX_RECURSIVE
1882918838
** <li> SQLITE_MUTEX_STATIC_MASTER
1883018839
** <li> SQLITE_MUTEX_STATIC_MEM
18831
-** <li> SQLITE_MUTEX_STATIC_MEM2
18840
+** <li> SQLITE_MUTEX_STATIC_OPEN
1883218841
** <li> SQLITE_MUTEX_STATIC_PRNG
1883318842
** <li> SQLITE_MUTEX_STATIC_LRU
1883418843
** <li> SQLITE_MUTEX_STATIC_PMEM
18844
+** <li> SQLITE_MUTEX_STATIC_APP1
18845
+** <li> SQLITE_MUTEX_STATIC_APP2
18846
+** <li> SQLITE_MUTEX_STATIC_APP3
1883518847
** </ul>
1883618848
**
1883718849
** The first two constants cause sqlite3_mutex_alloc() to create
1883818850
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
1883918851
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -18858,10 +18870,13 @@
1885818870
** mutex types, the same mutex is returned on every call that has
1885918871
** the same type number.
1886018872
*/
1886118873
static sqlite3_mutex *pthreadMutexAlloc(int iType){
1886218874
static sqlite3_mutex staticMutexes[] = {
18875
+ SQLITE3_MUTEX_INITIALIZER,
18876
+ SQLITE3_MUTEX_INITIALIZER,
18877
+ SQLITE3_MUTEX_INITIALIZER,
1886318878
SQLITE3_MUTEX_INITIALIZER,
1886418879
SQLITE3_MUTEX_INITIALIZER,
1886518880
SQLITE3_MUTEX_INITIALIZER,
1886618881
SQLITE3_MUTEX_INITIALIZER,
1886718882
SQLITE3_MUTEX_INITIALIZER,
@@ -19093,14 +19108,227 @@
1909319108
** May you do good and not evil.
1909419109
** May you find forgiveness for yourself and forgive others.
1909519110
** May you share freely, never taking more than you give.
1909619111
**
1909719112
*************************************************************************
19098
-** This file contains the C functions that implement mutexes for win32
19113
+** This file contains the C functions that implement mutexes for Win32.
1909919114
*/
1910019115
1910119116
#if SQLITE_OS_WIN
19117
+/*
19118
+** Include code that is common to all os_*.c files
19119
+*/
19120
+/************** Include os_common.h in the middle of mutex_w32.c *************/
19121
+/************** Begin file os_common.h ***************************************/
19122
+/*
19123
+** 2004 May 22
19124
+**
19125
+** The author disclaims copyright to this source code. In place of
19126
+** a legal notice, here is a blessing:
19127
+**
19128
+** May you do good and not evil.
19129
+** May you find forgiveness for yourself and forgive others.
19130
+** May you share freely, never taking more than you give.
19131
+**
19132
+******************************************************************************
19133
+**
19134
+** This file contains macros and a little bit of code that is common to
19135
+** all of the platform-specific files (os_*.c) and is #included into those
19136
+** files.
19137
+**
19138
+** This file should be #included by the os_*.c files only. It is not a
19139
+** general purpose header file.
19140
+*/
19141
+#ifndef _OS_COMMON_H_
19142
+#define _OS_COMMON_H_
19143
+
19144
+/*
19145
+** At least two bugs have slipped in because we changed the MEMORY_DEBUG
19146
+** macro to SQLITE_DEBUG and some older makefiles have not yet made the
19147
+** switch. The following code should catch this problem at compile-time.
19148
+*/
19149
+#ifdef MEMORY_DEBUG
19150
+# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19151
+#endif
19152
+
19153
+#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19154
+# ifndef SQLITE_DEBUG_OS_TRACE
19155
+# define SQLITE_DEBUG_OS_TRACE 0
19156
+# endif
19157
+ int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19158
+# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19159
+#else
19160
+# define OSTRACE(X)
19161
+#endif
19162
+
19163
+/*
19164
+** Macros for performance tracing. Normally turned off. Only works
19165
+** on i486 hardware.
19166
+*/
19167
+#ifdef SQLITE_PERFORMANCE_TRACE
19168
+
19169
+/*
19170
+** hwtime.h contains inline assembler code for implementing
19171
+** high-performance timing routines.
19172
+*/
19173
+/************** Include hwtime.h in the middle of os_common.h ****************/
19174
+/************** Begin file hwtime.h ******************************************/
19175
+/*
19176
+** 2008 May 27
19177
+**
19178
+** The author disclaims copyright to this source code. In place of
19179
+** a legal notice, here is a blessing:
19180
+**
19181
+** May you do good and not evil.
19182
+** May you find forgiveness for yourself and forgive others.
19183
+** May you share freely, never taking more than you give.
19184
+**
19185
+******************************************************************************
19186
+**
19187
+** This file contains inline asm code for retrieving "high-performance"
19188
+** counters for x86 class CPUs.
19189
+*/
19190
+#ifndef _HWTIME_H_
19191
+#define _HWTIME_H_
19192
+
19193
+/*
19194
+** The following routine only works on pentium-class (or newer) processors.
19195
+** It uses the RDTSC opcode to read the cycle count value out of the
19196
+** processor and returns that value. This can be used for high-res
19197
+** profiling.
19198
+*/
19199
+#if (defined(__GNUC__) || defined(_MSC_VER)) && \
19200
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
19201
+
19202
+ #if defined(__GNUC__)
19203
+
19204
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
19205
+ unsigned int lo, hi;
19206
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
19207
+ return (sqlite_uint64)hi << 32 | lo;
19208
+ }
19209
+
19210
+ #elif defined(_MSC_VER)
19211
+
19212
+ __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
19213
+ __asm {
19214
+ rdtsc
19215
+ ret ; return value at EDX:EAX
19216
+ }
19217
+ }
19218
+
19219
+ #endif
19220
+
19221
+#elif (defined(__GNUC__) && defined(__x86_64__))
19222
+
19223
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
19224
+ unsigned long val;
19225
+ __asm__ __volatile__ ("rdtsc" : "=A" (val));
19226
+ return val;
19227
+ }
19228
+
19229
+#elif (defined(__GNUC__) && defined(__ppc__))
19230
+
19231
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
19232
+ unsigned long long retval;
19233
+ unsigned long junk;
19234
+ __asm__ __volatile__ ("\n\
19235
+ 1: mftbu %1\n\
19236
+ mftb %L0\n\
19237
+ mftbu %0\n\
19238
+ cmpw %0,%1\n\
19239
+ bne 1b"
19240
+ : "=r" (retval), "=r" (junk));
19241
+ return retval;
19242
+ }
19243
+
19244
+#else
19245
+
19246
+ #error Need implementation of sqlite3Hwtime() for your platform.
19247
+
19248
+ /*
19249
+ ** To compile without implementing sqlite3Hwtime() for your platform,
19250
+ ** you can remove the above #error and use the following
19251
+ ** stub function. You will lose timing support for many
19252
+ ** of the debugging and testing utilities, but it should at
19253
+ ** least compile and run.
19254
+ */
19255
+SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
19256
+
19257
+#endif
19258
+
19259
+#endif /* !defined(_HWTIME_H_) */
19260
+
19261
+/************** End of hwtime.h **********************************************/
19262
+/************** Continuing where we left off in os_common.h ******************/
19263
+
19264
+static sqlite_uint64 g_start;
19265
+static sqlite_uint64 g_elapsed;
19266
+#define TIMER_START g_start=sqlite3Hwtime()
19267
+#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
19268
+#define TIMER_ELAPSED g_elapsed
19269
+#else
19270
+#define TIMER_START
19271
+#define TIMER_END
19272
+#define TIMER_ELAPSED ((sqlite_uint64)0)
19273
+#endif
19274
+
19275
+/*
19276
+** If we compile with the SQLITE_TEST macro set, then the following block
19277
+** of code will give us the ability to simulate a disk I/O error. This
19278
+** is used for testing the I/O recovery logic.
19279
+*/
19280
+#ifdef SQLITE_TEST
19281
+SQLITE_API int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
19282
+SQLITE_API int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
19283
+SQLITE_API int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
19284
+SQLITE_API int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
19285
+SQLITE_API int sqlite3_io_error_benign = 0; /* True if errors are benign */
19286
+SQLITE_API int sqlite3_diskfull_pending = 0;
19287
+SQLITE_API int sqlite3_diskfull = 0;
19288
+#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
19289
+#define SimulateIOError(CODE) \
19290
+ if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
19291
+ || sqlite3_io_error_pending-- == 1 ) \
19292
+ { local_ioerr(); CODE; }
19293
+static void local_ioerr(){
19294
+ IOTRACE(("IOERR\n"));
19295
+ sqlite3_io_error_hit++;
19296
+ if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
19297
+}
19298
+#define SimulateDiskfullError(CODE) \
19299
+ if( sqlite3_diskfull_pending ){ \
19300
+ if( sqlite3_diskfull_pending == 1 ){ \
19301
+ local_ioerr(); \
19302
+ sqlite3_diskfull = 1; \
19303
+ sqlite3_io_error_hit = 1; \
19304
+ CODE; \
19305
+ }else{ \
19306
+ sqlite3_diskfull_pending--; \
19307
+ } \
19308
+ }
19309
+#else
19310
+#define SimulateIOErrorBenign(X)
19311
+#define SimulateIOError(A)
19312
+#define SimulateDiskfullError(A)
19313
+#endif
19314
+
19315
+/*
19316
+** When testing, keep a count of the number of open files.
19317
+*/
19318
+#ifdef SQLITE_TEST
19319
+SQLITE_API int sqlite3_open_file_count = 0;
19320
+#define OpenCounter(X) sqlite3_open_file_count+=(X)
19321
+#else
19322
+#define OpenCounter(X)
19323
+#endif
19324
+
19325
+#endif /* !defined(_OS_COMMON_H_) */
19326
+
19327
+/************** End of os_common.h *******************************************/
19328
+/************** Continuing where we left off in mutex_w32.c ******************/
19329
+
1910219330
/*
1910319331
** Include the header file for the Windows VFS.
1910419332
*/
1910519333
/************** Include os_win.h in the middle of mutex_w32.c ****************/
1910619334
/************** Begin file os_win.h ******************************************/
@@ -19176,11 +19404,11 @@
1917619404
/************** Continuing where we left off in mutex_w32.c ******************/
1917719405
#endif
1917819406
1917919407
/*
1918019408
** The code in this file is only used if we are compiling multithreaded
19181
-** on a win32 system.
19409
+** on a Win32 system.
1918219410
*/
1918319411
#ifdef SQLITE_MUTEX_W32
1918419412
1918519413
/*
1918619414
** Each recursive mutex is an instance of the following structure.
@@ -19189,94 +19417,75 @@
1918919417
CRITICAL_SECTION mutex; /* Mutex controlling the lock */
1919019418
int id; /* Mutex type */
1919119419
#ifdef SQLITE_DEBUG
1919219420
volatile int nRef; /* Number of enterances */
1919319421
volatile DWORD owner; /* Thread holding this mutex */
19194
- int trace; /* True to trace changes */
19422
+ volatile int trace; /* True to trace changes */
1919519423
#endif
1919619424
};
19425
+
19426
+/*
19427
+** These are the initializer values used when declaring a "static" mutex
19428
+** on Win32. It should be noted that all mutexes require initialization
19429
+** on the Win32 platform.
19430
+*/
1919719431
#define SQLITE_W32_MUTEX_INITIALIZER { 0 }
19432
+
1919819433
#ifdef SQLITE_DEBUG
19199
-#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, 0L, (DWORD)0, 0 }
19434
+#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, \
19435
+ 0L, (DWORD)0, 0 }
1920019436
#else
1920119437
#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 }
1920219438
#endif
1920319439
19204
-/*
19205
-** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
19206
-** or WinCE. Return false (zero) for Win95, Win98, or WinME.
19207
-**
19208
-** Here is an interesting observation: Win95, Win98, and WinME lack
19209
-** the LockFileEx() API. But we can still statically link against that
19210
-** API as long as we don't call it win running Win95/98/ME. A call to
19211
-** this routine is used to determine if the host is Win95/98/ME or
19212
-** WinNT/2K/XP so that we will know whether or not we can safely call
19213
-** the LockFileEx() API.
19214
-**
19215
-** mutexIsNT() is only used for the TryEnterCriticalSection() API call,
19216
-** which is only available if your application was compiled with
19217
-** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
19218
-** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
19219
-** this out as well.
19220
-*/
19221
-#if 0
19222
-#if SQLITE_OS_WINCE || SQLITE_OS_WINRT
19223
-# define mutexIsNT() (1)
19224
-#else
19225
- static int mutexIsNT(void){
19226
- static int osType = 0;
19227
- if( osType==0 ){
19228
- OSVERSIONINFO sInfo;
19229
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
19230
- GetVersionEx(&sInfo);
19231
- osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
19232
- }
19233
- return osType==2;
19234
- }
19235
-#endif /* SQLITE_OS_WINCE || SQLITE_OS_WINRT */
19236
-#endif
19237
-
1923819440
#ifdef SQLITE_DEBUG
1923919441
/*
1924019442
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
1924119443
** intended for use only inside assert() statements.
1924219444
*/
1924319445
static int winMutexHeld(sqlite3_mutex *p){
1924419446
return p->nRef!=0 && p->owner==GetCurrentThreadId();
1924519447
}
19448
+
1924619449
static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
1924719450
return p->nRef==0 || p->owner!=tid;
1924819451
}
19452
+
1924919453
static int winMutexNotheld(sqlite3_mutex *p){
19250
- DWORD tid = GetCurrentThreadId();
19454
+ DWORD tid = GetCurrentThreadId();
1925119455
return winMutexNotheld2(p, tid);
1925219456
}
1925319457
#endif
1925419458
19255
-
1925619459
/*
1925719460
** Initialize and deinitialize the mutex subsystem.
1925819461
*/
19259
-static sqlite3_mutex winMutex_staticMutexes[6] = {
19462
+static sqlite3_mutex winMutex_staticMutexes[] = {
19463
+ SQLITE3_MUTEX_INITIALIZER,
19464
+ SQLITE3_MUTEX_INITIALIZER,
19465
+ SQLITE3_MUTEX_INITIALIZER,
1926019466
SQLITE3_MUTEX_INITIALIZER,
1926119467
SQLITE3_MUTEX_INITIALIZER,
1926219468
SQLITE3_MUTEX_INITIALIZER,
1926319469
SQLITE3_MUTEX_INITIALIZER,
1926419470
SQLITE3_MUTEX_INITIALIZER,
1926519471
SQLITE3_MUTEX_INITIALIZER
1926619472
};
19473
+
1926719474
static int winMutex_isInit = 0;
19268
-/* As winMutexInit() and winMutexEnd() are called as part
19269
-** of the sqlite3_initialize and sqlite3_shutdown()
19270
-** processing, the "interlocked" magic is probably not
19271
-** strictly necessary.
19475
+static int winMutex_isNt = -1; /* <0 means "need to query" */
19476
+
19477
+/* As the winMutexInit() and winMutexEnd() functions are called as part
19478
+** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
19479
+** "interlocked" magic used here is probably not strictly necessary.
1927219480
*/
19273
-static LONG winMutex_lock = 0;
19481
+static LONG volatile winMutex_lock = 0;
1927419482
19483
+SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
1927519484
SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
1927619485
19277
-static int winMutexInit(void){
19486
+static int winMutexInit(void){
1927819487
/* The first to increment to 1 does actual initialization */
1927919488
if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
1928019489
int i;
1928119490
for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
1928219491
#if SQLITE_OS_WINRT
@@ -19285,20 +19494,21 @@
1928519494
InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
1928619495
#endif
1928719496
}
1928819497
winMutex_isInit = 1;
1928919498
}else{
19290
- /* Someone else is in the process of initing the static mutexes */
19499
+ /* Another thread is (in the process of) initializing the static
19500
+ ** mutexes */
1929119501
while( !winMutex_isInit ){
1929219502
sqlite3_win32_sleep(1);
1929319503
}
1929419504
}
19295
- return SQLITE_OK;
19505
+ return SQLITE_OK;
1929619506
}
1929719507
19298
-static int winMutexEnd(void){
19299
- /* The first to decrement to 0 does actual shutdown
19508
+static int winMutexEnd(void){
19509
+ /* The first to decrement to 0 does actual shutdown
1930019510
** (which should be the last to shutdown.) */
1930119511
if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
1930219512
if( winMutex_isInit==1 ){
1930319513
int i;
1930419514
for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
@@ -19305,11 +19515,11 @@
1930519515
DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
1930619516
}
1930719517
winMutex_isInit = 0;
1930819518
}
1930919519
}
19310
- return SQLITE_OK;
19520
+ return SQLITE_OK;
1931119521
}
1931219522
1931319523
/*
1931419524
** The sqlite3_mutex_alloc() routine allocates a new
1931519525
** mutex and returns a pointer to it. If it returns NULL
@@ -19320,14 +19530,17 @@
1932019530
** <ul>
1932119531
** <li> SQLITE_MUTEX_FAST
1932219532
** <li> SQLITE_MUTEX_RECURSIVE
1932319533
** <li> SQLITE_MUTEX_STATIC_MASTER
1932419534
** <li> SQLITE_MUTEX_STATIC_MEM
19325
-** <li> SQLITE_MUTEX_STATIC_MEM2
19535
+** <li> SQLITE_MUTEX_STATIC_OPEN
1932619536
** <li> SQLITE_MUTEX_STATIC_PRNG
1932719537
** <li> SQLITE_MUTEX_STATIC_LRU
1932819538
** <li> SQLITE_MUTEX_STATIC_PMEM
19539
+** <li> SQLITE_MUTEX_STATIC_APP1
19540
+** <li> SQLITE_MUTEX_STATIC_APP2
19541
+** <li> SQLITE_MUTEX_STATIC_APP3
1932919542
** </ul>
1933019543
**
1933119544
** The first two constants cause sqlite3_mutex_alloc() to create
1933219545
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
1933319546
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19346,11 +19559,11 @@
1934619559
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
1934719560
** SQLITE_MUTEX_RECURSIVE.
1934819561
**
1934919562
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
1935019563
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
19351
-** returns a different mutex on every call. But for the static
19564
+** returns a different mutex on every call. But for the static
1935219565
** mutex types, the same mutex is returned on every call that has
1935319566
** the same type number.
1935419567
*/
1935519568
static sqlite3_mutex *winMutexAlloc(int iType){
1935619569
sqlite3_mutex *p;
@@ -19357,13 +19570,16 @@
1935719570
1935819571
switch( iType ){
1935919572
case SQLITE_MUTEX_FAST:
1936019573
case SQLITE_MUTEX_RECURSIVE: {
1936119574
p = sqlite3MallocZero( sizeof(*p) );
19362
- if( p ){
19575
+ if( p ){
1936319576
#ifdef SQLITE_DEBUG
1936419577
p->id = iType;
19578
+#ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
19579
+ p->trace = 1;
19580
+#endif
1936519581
#endif
1936619582
#if SQLITE_OS_WINRT
1936719583
InitializeCriticalSectionEx(&p->mutex, 0, 0);
1936819584
#else
1936919585
InitializeCriticalSection(&p->mutex);
@@ -19370,16 +19586,19 @@
1937019586
#endif
1937119587
}
1937219588
break;
1937319589
}
1937419590
default: {
19375
- assert( winMutex_isInit==1 );
1937619591
assert( iType-2 >= 0 );
1937719592
assert( iType-2 < ArraySize(winMutex_staticMutexes) );
19593
+ assert( winMutex_isInit==1 );
1937819594
p = &winMutex_staticMutexes[iType-2];
1937919595
#ifdef SQLITE_DEBUG
1938019596
p->id = iType;
19597
+#ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
19598
+ p->trace = 1;
19599
+#endif
1938119600
#endif
1938219601
break;
1938319602
}
1938419603
}
1938519604
return p;
@@ -19391,12 +19610,15 @@
1939119610
** allocated mutex. SQLite is careful to deallocate every
1939219611
** mutex that it allocates.
1939319612
*/
1939419613
static void winMutexFree(sqlite3_mutex *p){
1939519614
assert( p );
19615
+#ifdef SQLITE_DEBUG
1939619616
assert( p->nRef==0 && p->owner==0 );
1939719617
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19618
+#endif
19619
+ assert( winMutex_isInit==1 );
1939819620
DeleteCriticalSection(&p->mutex);
1939919621
sqlite3_free(p);
1940019622
}
1940119623
1940219624
/*
@@ -19409,53 +19631,71 @@
1940919631
** mutex must be exited an equal number of times before another thread
1941019632
** can enter. If the same thread tries to enter any other kind of mutex
1941119633
** more than once, the behavior is undefined.
1941219634
*/
1941319635
static void winMutexEnter(sqlite3_mutex *p){
19636
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
19637
+ DWORD tid = GetCurrentThreadId();
19638
+#endif
1941419639
#ifdef SQLITE_DEBUG
19415
- DWORD tid = GetCurrentThreadId();
19640
+ assert( p );
1941619641
assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
19642
+#else
19643
+ assert( p );
1941719644
#endif
19645
+ assert( winMutex_isInit==1 );
1941819646
EnterCriticalSection(&p->mutex);
1941919647
#ifdef SQLITE_DEBUG
1942019648
assert( p->nRef>0 || p->owner==0 );
19421
- p->owner = tid;
19649
+ p->owner = tid;
1942219650
p->nRef++;
1942319651
if( p->trace ){
19424
- printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
19652
+ OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
19653
+ tid, p, p->trace, p->nRef));
1942519654
}
1942619655
#endif
1942719656
}
19657
+
1942819658
static int winMutexTry(sqlite3_mutex *p){
19429
-#ifndef NDEBUG
19430
- DWORD tid = GetCurrentThreadId();
19659
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
19660
+ DWORD tid = GetCurrentThreadId();
1943119661
#endif
1943219662
int rc = SQLITE_BUSY;
19663
+ assert( p );
1943319664
assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
1943419665
/*
1943519666
** The sqlite3_mutex_try() routine is very rarely used, and when it
1943619667
** is used it is merely an optimization. So it is OK for it to always
19437
- ** fail.
19668
+ ** fail.
1943819669
**
1943919670
** The TryEnterCriticalSection() interface is only available on WinNT.
1944019671
** And some windows compilers complain if you try to use it without
1944119672
** first doing some #defines that prevent SQLite from building on Win98.
1944219673
** For that reason, we will omit this optimization for now. See
1944319674
** ticket #2685.
1944419675
*/
19445
-#if 0
19446
- if( mutexIsNT() && TryEnterCriticalSection(&p->mutex) ){
19676
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
19677
+ assert( winMutex_isInit==1 );
19678
+ assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
19679
+ if( winMutex_isNt<0 ){
19680
+ winMutex_isNt = sqlite3_win32_is_nt();
19681
+ }
19682
+ assert( winMutex_isNt==0 || winMutex_isNt==1 );
19683
+ if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
19684
+#ifdef SQLITE_DEBUG
1944719685
p->owner = tid;
1944819686
p->nRef++;
19687
+#endif
1944919688
rc = SQLITE_OK;
1945019689
}
1945119690
#else
1945219691
UNUSED_PARAMETER(p);
1945319692
#endif
1945419693
#ifdef SQLITE_DEBUG
19455
- if( rc==SQLITE_OK && p->trace ){
19456
- printf("try mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
19694
+ if( p->trace ){
19695
+ OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
19696
+ tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
1945719697
}
1945819698
#endif
1945919699
return rc;
1946019700
}
1946119701
@@ -19464,22 +19704,27 @@
1946419704
** previously entered by the same thread. The behavior
1946519705
** is undefined if the mutex is not currently entered or
1946619706
** is not currently allocated. SQLite will never do either.
1946719707
*/
1946819708
static void winMutexLeave(sqlite3_mutex *p){
19469
-#ifndef NDEBUG
19709
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
1947019710
DWORD tid = GetCurrentThreadId();
19711
+#endif
19712
+ assert( p );
19713
+#ifdef SQLITE_DEBUG
1947119714
assert( p->nRef>0 );
1947219715
assert( p->owner==tid );
1947319716
p->nRef--;
1947419717
if( p->nRef==0 ) p->owner = 0;
1947519718
assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
1947619719
#endif
19720
+ assert( winMutex_isInit==1 );
1947719721
LeaveCriticalSection(&p->mutex);
1947819722
#ifdef SQLITE_DEBUG
1947919723
if( p->trace ){
19480
- printf("leave mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
19724
+ OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
19725
+ tid, p, p->trace, p->nRef));
1948119726
}
1948219727
#endif
1948319728
}
1948419729
1948519730
SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -19497,13 +19742,13 @@
1949719742
#else
1949819743
0,
1949919744
0
1950019745
#endif
1950119746
};
19502
-
1950319747
return &sMutex;
1950419748
}
19749
+
1950519750
#endif /* SQLITE_MUTEX_W32 */
1950619751
1950719752
/************** End of mutex_w32.c *******************************************/
1950819753
/************** Begin file malloc.c ******************************************/
1950919754
/*
@@ -23718,14 +23963,14 @@
2371823963
/* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"),
2371923964
/* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"),
2372023965
/* 57 */ "SorterOpen" OpHelp(""),
2372123966
/* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
2372223967
/* 59 */ "Close" OpHelp(""),
23723
- /* 60 */ "SeekLT" OpHelp(""),
23724
- /* 61 */ "SeekLE" OpHelp(""),
23725
- /* 62 */ "SeekGE" OpHelp(""),
23726
- /* 63 */ "SeekGT" OpHelp(""),
23968
+ /* 60 */ "SeekLT" OpHelp("key=r[P3@P4]"),
23969
+ /* 61 */ "SeekLE" OpHelp("key=r[P3@P4]"),
23970
+ /* 62 */ "SeekGE" OpHelp("key=r[P3@P4]"),
23971
+ /* 63 */ "SeekGT" OpHelp("key=r[P3@P4]"),
2372723972
/* 64 */ "Seek" OpHelp("intkey=r[P2]"),
2372823973
/* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"),
2372923974
/* 66 */ "NotFound" OpHelp("key=r[P3@P4]"),
2373023975
/* 67 */ "Found" OpHelp("key=r[P3@P4]"),
2373123976
/* 68 */ "NotExists" OpHelp("intkey=r[P3]"),
@@ -23753,11 +23998,11 @@
2375323998
/* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2375423999
/* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2375524000
/* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2375624001
/* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2375724002
/* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23758
- /* 95 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
24003
+ /* 95 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
2375924004
/* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2376024005
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
2376124006
/* 98 */ "SorterData" OpHelp("r[P2]=data"),
2376224007
/* 99 */ "RowKey" OpHelp("r[P2]=key"),
2376324008
/* 100 */ "RowData" OpHelp("r[P2]=data"),
@@ -32160,14 +32405,14 @@
3216032405
**
3216132406
** In order to facilitate testing on a WinNT system, the test fixture
3216232407
** can manually set this value to 1 to emulate Win98 behavior.
3216332408
*/
3216432409
#ifdef SQLITE_TEST
32165
-SQLITE_API int sqlite3_os_type = 0;
32410
+SQLITE_API LONG volatile sqlite3_os_type = 0;
3216632411
#elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
3216732412
defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
32168
-static int sqlite3_os_type = 0;
32413
+static LONG volatile sqlite3_os_type = 0;
3216932414
#endif
3217032415
3217132416
#ifndef SYSCALL
3217232417
# define SYSCALL sqlite3_syscall_ptr
3217332418
#endif
@@ -32793,10 +33038,15 @@
3279333038
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3279433039
#endif
3279533040
3279633041
#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
3279733042
LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
33043
+
33044
+ { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
33045
+
33046
+#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*, \
33047
+ LONG,LONG))aSyscall[76].pCurrent)
3279833048
3279933049
}; /* End of the overrideable system calls */
3280033050
3280133051
/*
3280233052
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -33044,26 +33294,33 @@
3304433294
#elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
3304533295
# define osIsNT() (1)
3304633296
#elif !defined(SQLITE_WIN32_HAS_WIDE)
3304733297
# define osIsNT() (0)
3304833298
#else
33049
- static int osIsNT(void){
33050
- if( sqlite3_os_type==0 ){
33299
+# define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
33300
+#endif
33301
+
33302
+/*
33303
+** This function determines if the machine is running a version of Windows
33304
+** based on the NT kernel.
33305
+*/
33306
+SQLITE_API int sqlite3_win32_is_nt(void){
33307
+ if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
3305133308
#if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
33052
- OSVERSIONINFOW sInfo;
33053
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33054
- osGetVersionExW(&sInfo);
33309
+ OSVERSIONINFOW sInfo;
33310
+ sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33311
+ osGetVersionExW(&sInfo);
3305533312
#else
33056
- OSVERSIONINFOA sInfo;
33057
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33058
- osGetVersionExA(&sInfo);
33059
-#endif
33060
- sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
33061
- }
33062
- return sqlite3_os_type==2;
33063
- }
33064
-#endif
33313
+ OSVERSIONINFOA sInfo;
33314
+ sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33315
+ osGetVersionExA(&sInfo);
33316
+#endif
33317
+ osInterlockedCompareExchange(&sqlite3_os_type,
33318
+ (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33319
+ }
33320
+ return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33321
+}
3306533322
3306633323
#ifdef SQLITE_WIN32_MALLOC
3306733324
/*
3306833325
** Allocate nBytes of memory.
3306933326
*/
@@ -37215,11 +37472,11 @@
3721537472
};
3721637473
#endif
3721737474
3721837475
/* Double-check that the aSyscall[] array has been constructed
3721937476
** correctly. See ticket [bb3a86e890c8e96ab] */
37220
- assert( ArraySize(aSyscall)==76 );
37477
+ assert( ArraySize(aSyscall)==77 );
3722137478
3722237479
/* get memory map allocation granularity */
3722337480
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
3722437481
#if SQLITE_OS_WINRT
3722537482
osGetNativeSystemInfo(&winSysInfo);
@@ -52907,11 +53164,11 @@
5290753164
return pBt->nPage;
5290853165
}
5290953166
SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
5291053167
assert( sqlite3BtreeHoldsMutex(p) );
5291153168
assert( ((p->pBt->nPage)&0x8000000)==0 );
52912
- return (int)btreePagecount(p->pBt);
53169
+ return btreePagecount(p->pBt);
5291353170
}
5291453171
5291553172
/*
5291653173
** Get a page from the pager and initialize it. This routine is just a
5291753174
** convenience wrapper around separate calls to btreeGetPage() and
@@ -64735,11 +64992,11 @@
6473564992
/*
6473664993
** Return the serial-type for the value stored in pMem.
6473764994
*/
6473864995
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
6473964996
int flags = pMem->flags;
64740
- int n;
64997
+ u32 n;
6474164998
6474264999
if( flags&MEM_Null ){
6474365000
return 0;
6474465001
}
6474565002
if( flags&MEM_Int ){
@@ -64765,15 +65022,15 @@
6476565022
}
6476665023
if( flags&MEM_Real ){
6476765024
return 7;
6476865025
}
6476965026
assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
64770
- n = pMem->n;
65027
+ assert( pMem->n>=0 );
65028
+ n = (u32)pMem->n;
6477165029
if( flags & MEM_Zero ){
6477265030
n += pMem->u.nZero;
6477365031
}
64774
- assert( n>=0 );
6477565032
return ((n*2) + 12 + ((flags&MEM_Str)!=0));
6477665033
}
6477765034
6477865035
/*
6477965036
** Return the length of the data corresponding to the supplied serial-type.
@@ -67845,25 +68102,25 @@
6784568102
** do so without loss of information. In other words, if the string
6784668103
** looks like a number, convert it into a number. If it does not
6784768104
** look like a number, leave it alone.
6784868105
*/
6784968106
static void applyNumericAffinity(Mem *pRec){
67850
- if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
67851
- double rValue;
67852
- i64 iValue;
67853
- u8 enc = pRec->enc;
67854
- if( (pRec->flags&MEM_Str)==0 ) return;
67855
- if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
67856
- if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
67857
- pRec->u.i = iValue;
67858
- pRec->flags |= MEM_Int;
67859
- }else{
67860
- pRec->r = rValue;
67861
- pRec->flags |= MEM_Real;
67862
- }
67863
- }
67864
-}
68107
+ double rValue;
68108
+ i64 iValue;
68109
+ u8 enc = pRec->enc;
68110
+ if( (pRec->flags&MEM_Str)==0 ) return;
68111
+ if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
68112
+ if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
68113
+ pRec->u.i = iValue;
68114
+ pRec->flags |= MEM_Int;
68115
+ }else{
68116
+ pRec->r = rValue;
68117
+ pRec->flags |= MEM_Real;
68118
+ }
68119
+}
68120
+#define ApplyNumericAffinity(X) \
68121
+ if(((X)->flags&(MEM_Real|MEM_Int))==0){applyNumericAffinity(X);}
6786568122
6786668123
/*
6786768124
** Processing is determine by the affinity parameter:
6786868125
**
6786968126
** SQLITE_AFF_INTEGER:
@@ -67896,11 +68153,11 @@
6789668153
}
6789768154
pRec->flags &= ~(MEM_Real|MEM_Int);
6789868155
}else if( affinity!=SQLITE_AFF_NONE ){
6789968156
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
6790068157
|| affinity==SQLITE_AFF_NUMERIC );
67901
- applyNumericAffinity(pRec);
68158
+ ApplyNumericAffinity(pRec);
6790268159
if( pRec->flags & MEM_Real ){
6790368160
sqlite3VdbeIntegerAffinity(pRec);
6790468161
}
6790568162
}
6790668163
}
@@ -68477,16 +68734,18 @@
6847768734
break;
6847868735
}
6847968736
6848068737
/* Opcode: InitCoroutine P1 P2 P3 * *
6848168738
**
68482
-** Set up register P1 so that it will OP_Yield to the co-routine
68739
+** Set up register P1 so that it will Yield to the coroutine
6848368740
** located at address P3.
6848468741
**
68485
-** If P2!=0 then the co-routine implementation immediately follows
68486
-** this opcode. So jump over the co-routine implementation to
68742
+** If P2!=0 then the coroutine implementation immediately follows
68743
+** this opcode. So jump over the coroutine implementation to
6848768744
** address P2.
68745
+**
68746
+** See also: EndCoroutine
6848868747
*/
6848968748
case OP_InitCoroutine: { /* jump */
6849068749
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
6849168750
assert( pOp->p2>=0 && pOp->p2<p->nOp );
6849268751
assert( pOp->p3>=0 && pOp->p3<p->nOp );
@@ -68498,13 +68757,15 @@
6849868757
break;
6849968758
}
6850068759
6850168760
/* Opcode: EndCoroutine P1 * * * *
6850268761
**
68503
-** The instruction at the address in register P1 is an OP_Yield.
68504
-** Jump to the P2 parameter of that OP_Yield.
68762
+** The instruction at the address in register P1 is an Yield.
68763
+** Jump to the P2 parameter of that Yield.
6850568764
** After the jump, register P1 becomes undefined.
68765
+**
68766
+** See also: InitCoroutine
6850668767
*/
6850768768
case OP_EndCoroutine: { /* in1 */
6850868769
VdbeOp *pCaller;
6850968770
pIn1 = &aMem[pOp->p1];
6851068771
assert( pIn1->flags==MEM_Int );
@@ -68517,15 +68778,20 @@
6851768778
break;
6851868779
}
6851968780
6852068781
/* Opcode: Yield P1 P2 * * *
6852168782
**
68522
-** Swap the program counter with the value in register P1.
68783
+** Swap the program counter with the value in register P1. This
68784
+** has the effect of yielding to a coroutine.
6852368785
**
68524
-** If the co-routine ends with OP_Yield or OP_Return then continue
68525
-** to the next instruction. But if the co-routine ends with
68526
-** OP_EndCoroutine, jump immediately to P2.
68786
+** If the coroutine that is launched by this instruction ends with
68787
+** Yield or Return then continue to the next instruction. But if
68788
+** the coroutine launched by this instruction ends with
68789
+** EndCoroutine, then jump to P2 rather than continuing with the
68790
+** next instruction.
68791
+**
68792
+** See also: InitCoroutine
6852768793
*/
6852868794
case OP_Yield: { /* in1, jump */
6852968795
int pcDest;
6853068796
pIn1 = &aMem[pOp->p1];
6853168797
assert( VdbeMemDynamic(pIn1)==0 );
@@ -69906,14 +70172,18 @@
6990670172
break;
6990770173
}
6990870174
6990970175
/* Opcode: Once P1 P2 * * *
6991070176
**
69911
-** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
69912
-** set the flag and fall through to the next instruction. In other words,
69913
-** this opcode causes all following opcodes up through P2 (but not including
69914
-** P2) to run just once and to be skipped on subsequent times through the loop.
70177
+** Check the "once" flag number P1. If it is set, jump to instruction P2.
70178
+** Otherwise, set the flag and fall through to the next instruction.
70179
+** In other words, this opcode causes all following opcodes up through P2
70180
+** (but not including P2) to run just once and to be skipped on subsequent
70181
+** times through the loop.
70182
+**
70183
+** All "once" flags are initially cleared whenever a prepared statement
70184
+** first begins to run.
6991570185
*/
6991670186
case OP_Once: { /* jump */
6991770187
assert( pOp->p1<p->nOnceFlag );
6991870188
VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
6991970189
if( p->aOnceFlag[pOp->p1] ){
@@ -71191,11 +71461,11 @@
7119171461
sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
7119271462
p->apCsr[pOp->p1] = 0;
7119371463
break;
7119471464
}
7119571465
71196
-/* Opcode: SeekGe P1 P2 P3 P4 *
71466
+/* Opcode: SeekGE P1 P2 P3 P4 *
7119771467
** Synopsis: key=r[P3@P4]
7119871468
**
7119971469
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
7120071470
** use the value in register P3 as the key. If cursor P1 refers
7120171471
** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71202,14 +71472,18 @@
7120271472
** that are used as an unpacked index key.
7120371473
**
7120471474
** Reposition cursor P1 so that it points to the smallest entry that
7120571475
** is greater than or equal to the key value. If there are no records
7120671476
** greater than or equal to the key and P2 is not zero, then jump to P2.
71477
+**
71478
+** This opcode leaves the cursor configured to move in forward order,
71479
+** from the begining toward the end. In other words, the cursor is
71480
+** configured to use Next, not Prev.
7120771481
**
7120871482
** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
7120971483
*/
71210
-/* Opcode: SeekGt P1 P2 P3 P4 *
71484
+/* Opcode: SeekGT P1 P2 P3 P4 *
7121171485
** Synopsis: key=r[P3@P4]
7121271486
**
7121371487
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
7121471488
** use the value in register P3 as a key. If cursor P1 refers
7121571489
** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71216,14 +71490,18 @@
7121671490
** that are used as an unpacked index key.
7121771491
**
7121871492
** Reposition cursor P1 so that it points to the smallest entry that
7121971493
** is greater than the key value. If there are no records greater than
7122071494
** the key and P2 is not zero, then jump to P2.
71495
+**
71496
+** This opcode leaves the cursor configured to move in forward order,
71497
+** from the begining toward the end. In other words, the cursor is
71498
+** configured to use Next, not Prev.
7122171499
**
7122271500
** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
7122371501
*/
71224
-/* Opcode: SeekLt P1 P2 P3 P4 *
71502
+/* Opcode: SeekLT P1 P2 P3 P4 *
7122571503
** Synopsis: key=r[P3@P4]
7122671504
**
7122771505
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
7122871506
** use the value in register P3 as a key. If cursor P1 refers
7122971507
** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71230,14 +71508,18 @@
7123071508
** that are used as an unpacked index key.
7123171509
**
7123271510
** Reposition cursor P1 so that it points to the largest entry that
7123371511
** is less than the key value. If there are no records less than
7123471512
** the key and P2 is not zero, then jump to P2.
71513
+**
71514
+** This opcode leaves the cursor configured to move in reverse order,
71515
+** from the end toward the beginning. In other words, the cursor is
71516
+** configured to use Prev, not Next.
7123571517
**
7123671518
** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
7123771519
*/
71238
-/* Opcode: SeekLe P1 P2 P3 P4 *
71520
+/* Opcode: SeekLE P1 P2 P3 P4 *
7123971521
** Synopsis: key=r[P3@P4]
7124071522
**
7124171523
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
7124271524
** use the value in register P3 as a key. If cursor P1 refers
7124371525
** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71244,10 +71526,14 @@
7124471526
** that are used as an unpacked index key.
7124571527
**
7124671528
** Reposition cursor P1 so that it points to the largest entry that
7124771529
** is less than or equal to the key value. If there are no records
7124871530
** less than or equal to the key and P2 is not zero, then jump to P2.
71531
+**
71532
+** This opcode leaves the cursor configured to move in reverse order,
71533
+** from the end toward the beginning. In other words, the cursor is
71534
+** configured to use Prev, not Next.
7124971535
**
7125071536
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
7125171537
*/
7125271538
case OP_SeekLT: /* jump, in3 */
7125371539
case OP_SeekLE: /* jump, in3 */
@@ -71270,16 +71556,19 @@
7127071556
assert( OP_SeekGT == OP_SeekLT+3 );
7127171557
assert( pC->isOrdered );
7127271558
assert( pC->pCursor!=0 );
7127371559
oc = pOp->opcode;
7127471560
pC->nullRow = 0;
71561
+#ifdef SQLITE_DEBUG
71562
+ pC->seekOp = pOp->opcode;
71563
+#endif
7127571564
if( pC->isTable ){
7127671565
/* The input value in P3 might be of any type: integer, real, string,
7127771566
** blob, or NULL. But it needs to be an integer before we can do
7127871567
** the seek, so covert it. */
7127971568
pIn3 = &aMem[pOp->p3];
71280
- applyNumericAffinity(pIn3);
71569
+ ApplyNumericAffinity(pIn3);
7128171570
iKey = sqlite3VdbeIntValue(pIn3);
7128271571
pC->rowidIsValid = 0;
7128371572
7128471573
/* If the P3 value could not be converted into an integer without
7128571574
** loss of information, then special processing is required... */
@@ -71424,10 +71713,14 @@
7142471713
** record.
7142571714
**
7142671715
** Cursor P1 is on an index btree. If the record identified by P3 and P4
7142771716
** is a prefix of any entry in P1 then a jump is made to P2 and
7142871717
** P1 is left pointing at the matching entry.
71718
+**
71719
+** This operation leaves the cursor in a state where it cannot be
71720
+** advanced in either direction. In other words, the Next and Prev
71721
+** opcodes do not work after this operation.
7142971722
**
7143071723
** See also: NotFound, NoConflict, NotExists. SeekGe
7143171724
*/
7143271725
/* Opcode: NotFound P1 P2 P3 P4 *
7143371726
** Synopsis: key=r[P3@P4]
@@ -71439,10 +71732,14 @@
7143971732
** Cursor P1 is on an index btree. If the record identified by P3 and P4
7144071733
** is not the prefix of any entry in P1 then a jump is made to P2. If P1
7144171734
** does contain an entry whose prefix matches the P3/P4 record then control
7144271735
** falls through to the next instruction and P1 is left pointing at the
7144371736
** matching entry.
71737
+**
71738
+** This operation leaves the cursor in a state where it cannot be
71739
+** advanced in either direction. In other words, the Next and Prev
71740
+** opcodes do not work after this operation.
7144471741
**
7144571742
** See also: Found, NotExists, NoConflict
7144671743
*/
7144771744
/* Opcode: NoConflict P1 P2 P3 P4 *
7144871745
** Synopsis: key=r[P3@P4]
@@ -71458,10 +71755,14 @@
7145871755
** immediately to P2. If there is a match, fall through and leave the P1
7145971756
** cursor pointing to the matching row.
7146071757
**
7146171758
** This opcode is similar to OP_NotFound with the exceptions that the
7146271759
** branch is always taken if any part of the search key input is NULL.
71760
+**
71761
+** This operation leaves the cursor in a state where it cannot be
71762
+** advanced in either direction. In other words, the Next and Prev
71763
+** opcodes do not work after this operation.
7146371764
**
7146471765
** See also: NotFound, Found, NotExists
7146571766
*/
7146671767
case OP_NoConflict: /* jump, in3 */
7146771768
case OP_NotFound: /* jump, in3 */
@@ -71481,10 +71782,13 @@
7148171782
7148271783
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7148371784
assert( pOp->p4type==P4_INT32 );
7148471785
pC = p->apCsr[pOp->p1];
7148571786
assert( pC!=0 );
71787
+#ifdef SQLITE_DEBUG
71788
+ pC->seekOp = 0;
71789
+#endif
7148671790
pIn3 = &aMem[pOp->p3];
7148771791
assert( pC->pCursor!=0 );
7148871792
assert( pC->isTable==0 );
7148971793
pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
7149071794
if( pOp->p4.i>0 ){
@@ -71551,10 +71855,14 @@
7155171855
** with rowid P3 then leave the cursor pointing at that record and fall
7155271856
** through to the next instruction.
7155371857
**
7155471858
** The OP_NotFound opcode performs the same operation on index btrees
7155571859
** (with arbitrary multi-value keys).
71860
+**
71861
+** This opcode leaves the cursor in a state where it cannot be advanced
71862
+** in either direction. In other words, the Next and Prev opcodes will
71863
+** not work following this opcode.
7155671864
**
7155771865
** See also: Found, NotFound, NoConflict
7155871866
*/
7155971867
case OP_NotExists: { /* jump, in3 */
7156071868
VdbeCursor *pC;
@@ -71565,10 +71873,13 @@
7156571873
pIn3 = &aMem[pOp->p3];
7156671874
assert( pIn3->flags & MEM_Int );
7156771875
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7156871876
pC = p->apCsr[pOp->p1];
7156971877
assert( pC!=0 );
71878
+#ifdef SQLITE_DEBUG
71879
+ pC->seekOp = 0;
71880
+#endif
7157071881
assert( pC->isTable );
7157171882
assert( pC->pseudoTableReg==0 );
7157271883
pCrsr = pC->pCursor;
7157371884
assert( pCrsr!=0 );
7157471885
res = 0;
@@ -71927,16 +72238,16 @@
7192772238
p->nChange = 0;
7192872239
break;
7192972240
}
7193072241
7193172242
/* Opcode: SorterCompare P1 P2 P3 P4
71932
-** Synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2
72243
+** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
7193372244
**
7193472245
** P1 is a sorter cursor. This instruction compares a prefix of the
7193572246
** the record blob in register P3 against a prefix of the entry that
71936
-** the sorter cursor currently points to. The final P4 fields of both
71937
-** the P3 and sorter record are ignored.
72247
+** the sorter cursor currently points to. Only the first P4 fields
72248
+** of r[P3] and the sorter record are compared.
7193872249
**
7193972250
** If either P3 or the sorter contains a NULL in one of their significant
7194072251
** fields (not counting the P4 fields at the end which are ignored) then
7194172252
** the comparison is assumed to be equal.
7194272253
**
@@ -71944,18 +72255,18 @@
7194472255
** each other. Jump to P2 if they are different.
7194572256
*/
7194672257
case OP_SorterCompare: {
7194772258
VdbeCursor *pC;
7194872259
int res;
71949
- int nIgnore;
72260
+ int nKeyCol;
7195072261
7195172262
pC = p->apCsr[pOp->p1];
7195272263
assert( isSorter(pC) );
7195372264
assert( pOp->p4type==P4_INT32 );
7195472265
pIn3 = &aMem[pOp->p3];
71955
- nIgnore = pOp->p4.i;
71956
- rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
72266
+ nKeyCol = pOp->p4.i;
72267
+ rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
7195772268
VdbeBranchTaken(res!=0,2);
7195872269
if( res ){
7195972270
pc = pOp->p2-1;
7196072271
}
7196172272
break;
@@ -72131,15 +72442,19 @@
7213172442
break;
7213272443
}
7213372444
7213472445
/* Opcode: Last P1 P2 * * *
7213572446
**
72136
-** The next use of the Rowid or Column or Next instruction for P1
72447
+** The next use of the Rowid or Column or Prev instruction for P1
7213772448
** will refer to the last entry in the database table or index.
7213872449
** If the table or index is empty and P2>0, then jump immediately to P2.
7213972450
** If P2 is 0 or if the table or index is not empty, fall through
7214072451
** to the following instruction.
72452
+**
72453
+** This opcode leaves the cursor configured to move in reverse order,
72454
+** from the end toward the beginning. In other words, the cursor is
72455
+** configured to use Prev, not Next.
7214172456
*/
7214272457
case OP_Last: { /* jump */
7214372458
VdbeCursor *pC;
7214472459
BtCursor *pCrsr;
7214572460
int res;
@@ -72153,10 +72468,13 @@
7215372468
rc = sqlite3BtreeLast(pCrsr, &res);
7215472469
pC->nullRow = (u8)res;
7215572470
pC->deferredMoveto = 0;
7215672471
pC->rowidIsValid = 0;
7215772472
pC->cacheStatus = CACHE_STALE;
72473
+#ifdef SQLITE_DEBUG
72474
+ pC->seekOp = OP_Last;
72475
+#endif
7215872476
if( pOp->p2>0 ){
7215972477
VdbeBranchTaken(res!=0,2);
7216072478
if( res ) pc = pOp->p2 - 1;
7216172479
}
7216272480
break;
@@ -72189,10 +72507,14 @@
7218972507
** The next use of the Rowid or Column or Next instruction for P1
7219072508
** will refer to the first entry in the database table or index.
7219172509
** If the table or index is empty and P2>0, then jump immediately to P2.
7219272510
** If P2 is 0 or if the table or index is not empty, fall through
7219372511
** to the following instruction.
72512
+**
72513
+** This opcode leaves the cursor configured to move in forward order,
72514
+** from the begining toward the end. In other words, the cursor is
72515
+** configured to use Next, not Prev.
7219472516
*/
7219572517
case OP_Rewind: { /* jump */
7219672518
VdbeCursor *pC;
7219772519
BtCursor *pCrsr;
7219872520
int res;
@@ -72200,10 +72522,13 @@
7220072522
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7220172523
pC = p->apCsr[pOp->p1];
7220272524
assert( pC!=0 );
7220372525
assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
7220472526
res = 1;
72527
+#ifdef SQLITE_DEBUG
72528
+ pC->seekOp = OP_Rewind;
72529
+#endif
7220572530
if( isSorter(pC) ){
7220672531
rc = sqlite3VdbeSorterRewind(db, pC, &res);
7220772532
}else{
7220872533
pCrsr = pC->pCursor;
7220972534
assert( pCrsr );
@@ -72225,10 +72550,14 @@
7222572550
**
7222672551
** Advance cursor P1 so that it points to the next key/data pair in its
7222772552
** table or index. If there are no more key/value pairs then fall through
7222872553
** to the following instruction. But if the cursor advance was successful,
7222972554
** jump immediately to P2.
72555
+**
72556
+** The Next opcode is only valid following an SeekGT, SeekGE, or
72557
+** OP_Rewind opcode used to position the cursor. Next is not allowed
72558
+** to follow SeekLT, SeekLE, or OP_Last.
7223072559
**
7223172560
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
7223272561
** been opened prior to this opcode or the program will segfault.
7223372562
**
7223472563
** The P3 value is a hint to the btree implementation. If P3==1, that
@@ -72244,20 +72573,25 @@
7224472573
**
7224572574
** See also: Prev, NextIfOpen
7224672575
*/
7224772576
/* Opcode: NextIfOpen P1 P2 P3 P4 P5
7224872577
**
72249
-** This opcode works just like OP_Next except that if cursor P1 is not
72578
+** This opcode works just like Next except that if cursor P1 is not
7225072579
** open it behaves a no-op.
7225172580
*/
7225272581
/* Opcode: Prev P1 P2 P3 P4 P5
7225372582
**
7225472583
** Back up cursor P1 so that it points to the previous key/data pair in its
7225572584
** table or index. If there is no previous key/value pairs then fall through
7225672585
** to the following instruction. But if the cursor backup was successful,
7225772586
** jump immediately to P2.
7225872587
**
72588
+**
72589
+** The Prev opcode is only valid following an SeekLT, SeekLE, or
72590
+** OP_Last opcode used to position the cursor. Prev is not allowed
72591
+** to follow SeekGT, SeekGE, or OP_Rewind.
72592
+**
7225972593
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
7226072594
** not open then the behavior is undefined.
7226172595
**
7226272596
** The P3 value is a hint to the btree implementation. If P3==1, that
7226372597
** means P1 is an SQL index and that this instruction could have been
@@ -72270,11 +72604,11 @@
7227072604
** If P5 is positive and the jump is taken, then event counter
7227172605
** number P5-1 in the prepared statement is incremented.
7227272606
*/
7227372607
/* Opcode: PrevIfOpen P1 P2 P3 P4 P5
7227472608
**
72275
-** This opcode works just like OP_Prev except that if cursor P1 is not
72609
+** This opcode works just like Prev except that if cursor P1 is not
7227672610
** open it behaves a no-op.
7227772611
*/
7227872612
case OP_SorterNext: { /* jump */
7227972613
VdbeCursor *pC;
7228072614
int res;
@@ -72301,10 +72635,20 @@
7230172635
testcase( res==1 );
7230272636
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
7230372637
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
7230472638
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
7230572639
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
72640
+
72641
+ /* The Next opcode is only used after SeekGT, SeekGE, and Rewind.
72642
+ ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
72643
+ assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen
72644
+ || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
72645
+ || pC->seekOp==OP_Rewind );
72646
+ assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen
72647
+ || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
72648
+ || pC->seekOp==OP_Last );
72649
+
7230672650
rc = pOp->p4.xAdvance(pC->pCursor, &res);
7230772651
next_tail:
7230872652
pC->cacheStatus = CACHE_STALE;
7230972653
VdbeBranchTaken(res==0,2);
7231072654
if( res==0 ){
@@ -72781,11 +73125,12 @@
7278173125
7278273126
/* Opcode: DropTable P1 * * P4 *
7278373127
**
7278473128
** Remove the internal (in-memory) data structures that describe
7278573129
** the table named P4 in database P1. This is called after a table
72786
-** is dropped in order to keep the internal representation of the
73130
+** is dropped from disk (using the Destroy opcode) in order to keep
73131
+** the internal representation of the
7278773132
** schema consistent with what is on disk.
7278873133
*/
7278973134
case OP_DropTable: {
7279073135
sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
7279173136
break;
@@ -72793,11 +73138,12 @@
7279373138
7279473139
/* Opcode: DropIndex P1 * * P4 *
7279573140
**
7279673141
** Remove the internal (in-memory) data structures that describe
7279773142
** the index named P4 in database P1. This is called after an index
72798
-** is dropped in order to keep the internal representation of the
73143
+** is dropped from disk (using the Destroy opcode)
73144
+** in order to keep the internal representation of the
7279973145
** schema consistent with what is on disk.
7280073146
*/
7280173147
case OP_DropIndex: {
7280273148
sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
7280373149
break;
@@ -72805,11 +73151,12 @@
7280573151
7280673152
/* Opcode: DropTrigger P1 * * P4 *
7280773153
**
7280873154
** Remove the internal (in-memory) data structures that describe
7280973155
** the trigger named P4 in database P1. This is called after a trigger
72810
-** is dropped in order to keep the internal representation of the
73156
+** is dropped from disk (using the Destroy opcode) in order to keep
73157
+** the internal representation of the
7281173158
** schema consistent with what is on disk.
7281273159
*/
7281373160
case OP_DropTrigger: {
7281473161
sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
7281573162
break;
@@ -75011,11 +75358,11 @@
7501175358
** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
7501275359
** has been allocated and contains an unpacked record that is used as key2.
7501375360
*/
7501475361
static void vdbeSorterCompare(
7501575362
const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
75016
- int nIgnore, /* Ignore the last nIgnore fields */
75363
+ int nKeyCol, /* Num of columns. 0 means "all" */
7501775364
const void *pKey1, int nKey1, /* Left side of comparison */
7501875365
const void *pKey2, int nKey2, /* Right side of comparison */
7501975366
int *pRes /* OUT: Result of comparison */
7502075367
){
7502175368
KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -75025,14 +75372,13 @@
7502575372
7502675373
if( pKey2 ){
7502775374
sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
7502875375
}
7502975376
75030
- if( nIgnore ){
75031
- r2->nField = pKeyInfo->nField - nIgnore;
75032
- assert( r2->nField>0 );
75033
- for(i=0; i<r2->nField; i++){
75377
+ if( nKeyCol ){
75378
+ r2->nField = nKeyCol;
75379
+ for(i=0; i<nKeyCol; i++){
7503475380
if( r2->aMem[i].flags & MEM_Null ){
7503575381
*pRes = -1;
7503675382
return;
7503775383
}
7503875384
}
@@ -75710,18 +76056,18 @@
7571076056
** key.
7571176057
*/
7571276058
SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
7571376059
const VdbeCursor *pCsr, /* Sorter cursor */
7571476060
Mem *pVal, /* Value to compare to current sorter key */
75715
- int nIgnore, /* Ignore this many fields at the end */
76061
+ int nKeyCol, /* Only compare this many fields */
7571676062
int *pRes /* OUT: Result of comparison */
7571776063
){
7571876064
VdbeSorter *pSorter = pCsr->pSorter;
7571976065
void *pKey; int nKey; /* Sorter key to compare pVal with */
7572076066
7572176067
pKey = vdbeSorterRowkey(pSorter, &nKey);
75722
- vdbeSorterCompare(pCsr, nIgnore, pVal->z, pVal->n, pKey, nKey, pRes);
76068
+ vdbeSorterCompare(pCsr, nKeyCol, pVal->z, pVal->n, pKey, nKey, pRes);
7572376069
return SQLITE_OK;
7572476070
}
7572576071
7572676072
/************** End of vdbesort.c ********************************************/
7572776073
/************** Begin file journal.c *****************************************/
@@ -79474,11 +79820,11 @@
7947479820
}
7947579821
}
7947679822
}
7947779823
7947879824
if( eType==0 ){
79479
- /* Could not found an existing table or index to use as the RHS b-tree.
79825
+ /* Could not find an existing table or index to use as the RHS b-tree.
7948079826
** We will have to generate an ephemeral table to do the job.
7948179827
*/
7948279828
u32 savedNQueryLoop = pParse->nQueryLoop;
7948379829
int rMayHaveNull = 0;
7948479830
eType = IN_INDEX_EPH;
@@ -79604,24 +79950,27 @@
7960479950
/* Case 1: expr IN (SELECT ...)
7960579951
**
7960679952
** Generate code to write the results of the select into the temporary
7960779953
** table allocated and opened above.
7960879954
*/
79955
+ Select *pSelect = pExpr->x.pSelect;
7960979956
SelectDest dest;
7961079957
ExprList *pEList;
7961179958
7961279959
assert( !isRowid );
7961379960
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
7961479961
dest.affSdst = (u8)affinity;
7961579962
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
79616
- pExpr->x.pSelect->iLimit = 0;
79963
+ pSelect->iLimit = 0;
79964
+ testcase( pSelect->selFlags & SF_Distinct );
79965
+ pSelect->selFlags &= ~SF_Distinct;
7961779966
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
79618
- if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
79967
+ if( sqlite3Select(pParse, pSelect, &dest) ){
7961979968
sqlite3KeyInfoUnref(pKeyInfo);
7962079969
return 0;
7962179970
}
79622
- pEList = pExpr->x.pSelect->pEList;
79971
+ pEList = pSelect->pEList;
7962379972
assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
7962479973
assert( pEList!=0 );
7962579974
assert( pEList->nExpr>0 );
7962679975
assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
7962779976
pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
@@ -83315,19 +83664,24 @@
8331583664
}
8331683665
8331783666
/*
8331883667
** Implementation of the stat_init(N,K,C) SQL function. The three parameters
8331983668
** are:
83320
-** N: The number of columns in the index including the rowid/pk
83321
-** K: The number of columns in the index excluding the rowid/pk
83322
-** C: The number of rows in the index
83323
-**
83324
-** C is only used for STAT3 and STAT4.
83325
-**
83326
-** For ordinary rowid tables, N==K+1. But for WITHOUT ROWID tables,
83327
-** N=K+P where P is the number of columns in the primary key. For the
83328
-** covering index that implements the original WITHOUT ROWID table, N==K.
83669
+** N: The number of columns in the index including the rowid/pk (note 1)
83670
+** K: The number of columns in the index excluding the rowid/pk.
83671
+** C: The number of rows in the index (note 2)
83672
+**
83673
+** Note 1: In the special case of the covering index that implements a
83674
+** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
83675
+** total number of columns in the table.
83676
+**
83677
+** Note 2: C is only used for STAT3 and STAT4.
83678
+**
83679
+** For indexes on ordinary rowid tables, N==K+1. But for indexes on
83680
+** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
83681
+** PRIMARY KEY of the table. The covering index that implements the
83682
+** original WITHOUT ROWID table as N==K as a special case.
8332983683
**
8333083684
** This routine allocates the Stat4Accum object in heap memory. The return
8333183685
** value is a pointer to the the Stat4Accum object encoded as a blob (i.e.
8333283686
** the size of the blob is sizeof(void*) bytes).
8333383687
*/
@@ -83633,11 +83987,14 @@
8363383987
** P Pointer to the Stat4Accum object created by stat_init()
8363483988
** C Index of left-most column to differ from previous row
8363583989
** R Rowid for the current row. Might be a key record for
8363683990
** WITHOUT ROWID tables.
8363783991
**
83638
-** The SQL function always returns NULL.
83992
+** This SQL function always returns NULL. It's purpose it to accumulate
83993
+** statistical data and/or samples in the Stat4Accum object about the
83994
+** index being analyzed. The stat_get() SQL function will later be used to
83995
+** extract relevant information for constructing the sqlite_statN tables.
8363983996
**
8364083997
** The R parameter is only used for STAT3 and STAT4
8364183998
*/
8364283999
static void statPush(
8364384000
sqlite3_context *context,
@@ -83727,11 +84084,14 @@
8372784084
#define STAT_GET_NLT 3 /* "nlt" column of stat[34] entry */
8372884085
#define STAT_GET_NDLT 4 /* "ndlt" column of stat[34] entry */
8372984086
8373084087
/*
8373184088
** Implementation of the stat_get(P,J) SQL function. This routine is
83732
-** used to query the results. Content is returned for parameter J
84089
+** used to query statistical information that has been gathered into
84090
+** the Stat4Accum object by prior calls to stat_push(). The P parameter
84091
+** is a BLOB which is decoded into a pointer to the Stat4Accum objects.
84092
+** The content to returned is determined by the parameter J
8373384093
** which is one of the STAT_GET_xxxx values defined above.
8373484094
**
8373584095
** If neither STAT3 nor STAT4 are enabled, then J is always
8373684096
** STAT_GET_STAT1 and is hence omitted and this routine becomes
8373784097
** a one-parameter function, stat_get(P), that always returns the
@@ -83946,28 +84306,27 @@
8394684306
pParse->nTab = MAX(pParse->nTab, iTab);
8394784307
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
8394884308
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
8394984309
8395084310
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
83951
- int nCol; /* Number of columns indexed by pIdx */
83952
- int *aGotoChng; /* Array of jump instruction addresses */
84311
+ int nCol; /* Number of columns in pIdx. "N" */
8395384312
int addrRewind; /* Address of "OP_Rewind iIdxCur" */
83954
- int addrGotoChng0; /* Address of "Goto addr_chng_0" */
8395584313
int addrNextRow; /* Address of "next_row:" */
8395684314
const char *zIdxName; /* Name of the index */
84315
+ int nColTest; /* Number of columns to test for changes */
8395784316
8395884317
if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
8395984318
if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
8396084319
if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
8396184320
nCol = pIdx->nKeyCol;
8396284321
zIdxName = pTab->zName;
84322
+ nColTest = nCol - 1;
8396384323
}else{
8396484324
nCol = pIdx->nColumn;
8396584325
zIdxName = pIdx->zName;
84326
+ nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
8396684327
}
83967
- aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
83968
- if( aGotoChng==0 ) continue;
8396984328
8397084329
/* Populate the register containing the index name. */
8397184330
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
8397284331
VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
8397384332
@@ -83992,11 +84351,11 @@
8399284351
** regPrev(0) = idx(0)
8399384352
** chng_addr_1:
8399484353
** regPrev(1) = idx(1)
8399584354
** ...
8399684355
**
83997
- ** chng_addr_N:
84356
+ ** endDistinctTest:
8399884357
** regRowid = idx(rowid)
8399984358
** stat_push(P, regChng, regRowid)
8400084359
** Next csr
8400184360
** if !eof(csr) goto next_row;
8400284361
**
@@ -84005,24 +84364,27 @@
8400584364
8400684365
/* Make sure there are enough memory cells allocated to accommodate
8400784366
** the regPrev array and a trailing rowid (the rowid slot is required
8400884367
** when building a record to insert into the sample column of
8400984368
** the sqlite_stat4 table. */
84010
- pParse->nMem = MAX(pParse->nMem, regPrev+nCol);
84369
+ pParse->nMem = MAX(pParse->nMem, regPrev+nColTest);
8401184370
8401284371
/* Open a read-only cursor on the index being analyzed. */
8401384372
assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
8401484373
sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
8401584374
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
8401684375
VdbeComment((v, "%s", pIdx->zName));
8401784376
8401884377
/* Invoke the stat_init() function. The arguments are:
8401984378
**
84020
- ** (1) the number of columns in the index including the rowid,
84021
- ** (2) the number of rows in the index,
84379
+ ** (1) the number of columns in the index including the rowid
84380
+ ** (or for a WITHOUT ROWID table, the number of PK columns),
84381
+ ** (2) the number of columns in the key without the rowid/pk
84382
+ ** (3) the number of rows in the index,
8402284383
**
84023
- ** The second argument is only used for STAT3 and STAT4
84384
+ **
84385
+ ** The third argument is only used for STAT3 and STAT4
8402484386
*/
8402584387
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8402684388
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3);
8402784389
#endif
8402884390
sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1);
@@ -84040,56 +84402,73 @@
8404084402
**
8404184403
*/
8404284404
addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
8404384405
VdbeCoverage(v);
8404484406
sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
84045
- addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
84046
-
84047
- /*
84048
- ** next_row:
84049
- ** regChng = 0
84050
- ** if( idx(0) != regPrev(0) ) goto chng_addr_0
84051
- ** regChng = 1
84052
- ** if( idx(1) != regPrev(1) ) goto chng_addr_1
84053
- ** ...
84054
- ** regChng = N
84055
- ** goto chng_addr_N
84056
- */
8405784407
addrNextRow = sqlite3VdbeCurrentAddr(v);
84058
- for(i=0; i<nCol-1; i++){
84059
- char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
84060
- sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
84061
- sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
84062
- aGotoChng[i] =
84063
- sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
84064
- sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
84065
- VdbeCoverage(v);
84066
- }
84067
- sqlite3VdbeAddOp2(v, OP_Integer, nCol-1, regChng);
84068
- aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
84069
-
84070
- /*
84071
- ** chng_addr_0:
84072
- ** regPrev(0) = idx(0)
84073
- ** chng_addr_1:
84074
- ** regPrev(1) = idx(1)
84075
- ** ...
84076
- */
84077
- sqlite3VdbeJumpHere(v, addrGotoChng0);
84078
- for(i=0; i<nCol-1; i++){
84079
- sqlite3VdbeJumpHere(v, aGotoChng[i]);
84080
- sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
84081
- }
84082
-
84408
+
84409
+ if( nColTest>0 ){
84410
+ int endDistinctTest = sqlite3VdbeMakeLabel(v);
84411
+ int *aGotoChng; /* Array of jump instruction addresses */
84412
+ aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
84413
+ if( aGotoChng==0 ) continue;
84414
+
84415
+ /*
84416
+ ** next_row:
84417
+ ** regChng = 0
84418
+ ** if( idx(0) != regPrev(0) ) goto chng_addr_0
84419
+ ** regChng = 1
84420
+ ** if( idx(1) != regPrev(1) ) goto chng_addr_1
84421
+ ** ...
84422
+ ** regChng = N
84423
+ ** goto endDistinctTest
84424
+ */
84425
+ sqlite3VdbeAddOp0(v, OP_Goto);
84426
+ addrNextRow = sqlite3VdbeCurrentAddr(v);
84427
+ if( nColTest==1 && pIdx->nKeyCol==1 && pIdx->onError!=OE_None ){
84428
+ /* For a single-column UNIQUE index, once we have found a non-NULL
84429
+ ** row, we know that all the rest will be distinct, so skip
84430
+ ** subsequent distinctness tests. */
84431
+ sqlite3VdbeAddOp2(v, OP_NotNull, regPrev, endDistinctTest);
84432
+ VdbeCoverage(v);
84433
+ }
84434
+ for(i=0; i<nColTest; i++){
84435
+ char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
84436
+ sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
84437
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
84438
+ aGotoChng[i] =
84439
+ sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
84440
+ sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
84441
+ VdbeCoverage(v);
84442
+ }
84443
+ sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
84444
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
84445
+
84446
+
84447
+ /*
84448
+ ** chng_addr_0:
84449
+ ** regPrev(0) = idx(0)
84450
+ ** chng_addr_1:
84451
+ ** regPrev(1) = idx(1)
84452
+ ** ...
84453
+ */
84454
+ sqlite3VdbeJumpHere(v, addrNextRow-1);
84455
+ for(i=0; i<nColTest; i++){
84456
+ sqlite3VdbeJumpHere(v, aGotoChng[i]);
84457
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
84458
+ }
84459
+ sqlite3VdbeResolveLabel(v, endDistinctTest);
84460
+ sqlite3DbFree(db, aGotoChng);
84461
+ }
84462
+
8408384463
/*
8408484464
** chng_addr_N:
8408584465
** regRowid = idx(rowid) // STAT34 only
8408684466
** stat_push(P, regChng, regRowid) // 3rd parameter STAT34 only
8408784467
** Next csr
8408884468
** if !eof(csr) goto next_row;
8408984469
*/
84090
- sqlite3VdbeJumpHere(v, aGotoChng[nCol]);
8409184470
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8409284471
assert( regRowid==(regStat4+2) );
8409384472
if( HasRowid(pTab) ){
8409484473
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
8409584474
}else{
@@ -84163,11 +84542,10 @@
8416384542
}
8416484543
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
8416584544
8416684545
/* End of analysis */
8416784546
sqlite3VdbeJumpHere(v, addrRewind);
84168
- sqlite3DbFree(db, aGotoChng);
8416984547
}
8417084548
8417184549
8417284550
/* Create a single sqlite_stat1 entry containing NULL as the index
8417384551
** name and the row count as the content.
@@ -88308,11 +88686,11 @@
8830888686
if( pIndex->onError!=OE_None && pKey!=0 ){
8830988687
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
8831088688
sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
8831188689
addr2 = sqlite3VdbeCurrentAddr(v);
8831288690
sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
88313
- pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
88691
+ pIndex->nKeyCol); VdbeCoverage(v);
8831488692
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
8831588693
}else{
8831688694
addr2 = sqlite3VdbeCurrentAddr(v);
8831788695
}
8831888696
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
@@ -98186,11 +98564,11 @@
9818698564
** Note that the values returned are one less that the values that
9818798565
** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
9818898566
** to support legacy SQL code. The safety level used to be boolean
9818998567
** and older scripts may have used numbers 0 for OFF and 1 for ON.
9819098568
*/
98191
-static u8 getSafetyLevel(const char *z, int omitFull, int dflt){
98569
+static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt){
9819298570
/* 123456789 123456789 */
9819398571
static const char zText[] = "onoffalseyestruefull";
9819498572
static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
9819598573
static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
9819698574
static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
@@ -98208,11 +98586,11 @@
9820898586
}
9820998587
9821098588
/*
9821198589
** Interpret the given string as a boolean value.
9821298590
*/
98213
-SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, int dflt){
98591
+SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, u8 dflt){
9821498592
return getSafetyLevel(z,1,dflt)!=0;
9821598593
}
9821698594
9821798595
/* The sqlite3GetBoolean() function is used by other modules but the
9821898596
** remainder of this file is specific to PRAGMA processing. So omit
@@ -112398,11 +112776,12 @@
112398112776
int nEq = pLoop->u.btree.nEq;
112399112777
sqlite3 *db = pParse->db;
112400112778
int nLower = -1;
112401112779
int nUpper = p->nSample+1;
112402112780
int rc = SQLITE_OK;
112403
- u8 aff = p->pTable->aCol[ p->aiColumn[nEq] ].affinity;
112781
+ int iCol = p->aiColumn[nEq];
112782
+ u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
112404112783
CollSeq *pColl;
112405112784
112406112785
sqlite3_value *p1 = 0; /* Value extracted from pLower */
112407112786
sqlite3_value *p2 = 0; /* Value extracted from pUpper */
112408112787
sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -122593,11 +122972,11 @@
122593122972
122594122973
/*
122595122974
** Return a static string containing the name corresponding to the error code
122596122975
** specified in the argument.
122597122976
*/
122598
-#if defined(SQLITE_TEST)
122977
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
122599122978
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
122600122979
const char *zName = 0;
122601122980
int i, origRc = rc;
122602122981
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
122603122982
switch( rc ){
@@ -124897,10 +125276,20 @@
124897125276
sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
124898125277
sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
124899125278
#endif
124900125279
break;
124901125280
}
125281
+
125282
+ /* sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
125283
+ **
125284
+ ** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
125285
+ ** not.
125286
+ */
125287
+ case SQLITE_TESTCTRL_ISINIT: {
125288
+ if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
125289
+ break;
125290
+ }
124902125291
124903125292
}
124904125293
va_end(ap);
124905125294
#endif /* SQLITE_OMIT_BUILTIN_TEST */
124906125295
return rc;
@@ -145542,13 +145931,17 @@
145542145931
int rc = SQLITE_OK;
145543145932
int iCell = 0;
145544145933
145545145934
rtreeReference(pRtree);
145546145935
145936
+ /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
145547145937
freeCursorConstraints(pCsr);
145938
+ sqlite3_free(pCsr->aPoint);
145939
+ memset(pCsr, 0, sizeof(RtreeCursor));
145940
+ pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
145941
+
145548145942
pCsr->iStrategy = idxNum;
145549
-
145550145943
if( idxNum==1 ){
145551145944
/* Special case - lookup by rowid. */
145552145945
RtreeNode *pLeaf; /* Leaf on which the required cell resides */
145553145946
RtreeSearchPoint *p; /* Search point for the the leaf */
145554145947
i64 iRowid = sqlite3_value_int64(argv[0]);
145555145948
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.6"
226 #define SQLITE_VERSION_NUMBER 3008006
227 #define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -5993,14 +5993,16 @@
5993 ** <ul>
5994 ** <li> SQLITE_MUTEX_FAST
5995 ** <li> SQLITE_MUTEX_RECURSIVE
5996 ** <li> SQLITE_MUTEX_STATIC_MASTER
5997 ** <li> SQLITE_MUTEX_STATIC_MEM
5998 ** <li> SQLITE_MUTEX_STATIC_MEM2
5999 ** <li> SQLITE_MUTEX_STATIC_PRNG
6000 ** <li> SQLITE_MUTEX_STATIC_LRU
6001 ** <li> SQLITE_MUTEX_STATIC_LRU2
 
 
6002 ** </ul>)^
6003 **
6004 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
6005 ** cause sqlite3_mutex_alloc() to create
6006 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6200,10 +6202,13 @@
6200 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
6201 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
6202 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
6203 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6204 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
 
 
 
6205
6206 /*
6207 ** CAPI3REF: Retrieve the mutex for a database connection
6208 **
6209 ** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6295,11 +6300,12 @@
6295 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6296 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6297 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6298 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6299 #define SQLITE_TESTCTRL_BYTEORDER 22
6300 #define SQLITE_TESTCTRL_LAST 22
 
6301
6302 /*
6303 ** CAPI3REF: SQLite Runtime Status
6304 **
6305 ** ^This interface is used to retrieve runtime status information
@@ -9325,14 +9331,14 @@
9325 #define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */
9326 #define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */
9327 #define OP_SorterOpen 57
9328 #define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
9329 #define OP_Close 59
9330 #define OP_SeekLT 60
9331 #define OP_SeekLE 61
9332 #define OP_SeekGE 62
9333 #define OP_SeekGT 63
9334 #define OP_Seek 64 /* synopsis: intkey=r[P2] */
9335 #define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */
9336 #define OP_NotFound 66 /* synopsis: key=r[P3@P4] */
9337 #define OP_Found 67 /* synopsis: key=r[P3@P4] */
9338 #define OP_NotExists 68 /* synopsis: intkey=r[P3] */
@@ -9360,11 +9366,11 @@
9360 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9361 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9362 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9363 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9364 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9365 #define OP_SorterCompare 95 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9366 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9367 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9368 #define OP_SorterData 98 /* synopsis: r[P2]=data */
9369 #define OP_RowKey 99 /* synopsis: r[P2]=key */
9370 #define OP_RowData 100 /* synopsis: r[P2]=data */
@@ -12852,11 +12858,11 @@
12852 #ifdef SQLITE_ENABLE_8_3_NAMES
12853 SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
12854 #else
12855 # define sqlite3FileSuffix3(X,Y)
12856 #endif
12857 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,int);
12858
12859 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12860 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12861 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12862 void(*)(void*));
@@ -13927,10 +13933,13 @@
13927 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13928 int seekResult; /* Result of previous sqlite3BtreeMoveto() */
13929 int pseudoTableReg; /* Register holding pseudotable content. */
13930 i16 nField; /* Number of fields in the header */
13931 u16 nHdrParsed; /* Number of header fields parsed so far */
 
 
 
13932 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
13933 u8 nullRow; /* True if pointing to a row with no data */
13934 u8 rowidIsValid; /* True if lastRowid is valid */
13935 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13936 Bool isEphemeral:1; /* True for an ephemeral table */
@@ -18448,11 +18457,11 @@
18448 /*
18449 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18450 */
18451 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18452 #ifndef SQLITE_OMIT_AUTOINIT
18453 if( sqlite3_initialize() ) return 0;
18454 #endif
18455 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18456 }
18457
18458 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -18629,11 +18638,11 @@
18629 ** The sqlite3_mutex_alloc() routine allocates a new
18630 ** mutex and returns a pointer to it. If it returns NULL
18631 ** that means that a mutex could not be allocated.
18632 */
18633 static sqlite3_mutex *debugMutexAlloc(int id){
18634 static sqlite3_debug_mutex aStatic[6];
18635 sqlite3_debug_mutex *pNew = 0;
18636 switch( id ){
18637 case SQLITE_MUTEX_FAST:
18638 case SQLITE_MUTEX_RECURSIVE: {
18639 pNew = sqlite3Malloc(sizeof(*pNew));
@@ -18826,14 +18835,17 @@
18826 ** <ul>
18827 ** <li> SQLITE_MUTEX_FAST
18828 ** <li> SQLITE_MUTEX_RECURSIVE
18829 ** <li> SQLITE_MUTEX_STATIC_MASTER
18830 ** <li> SQLITE_MUTEX_STATIC_MEM
18831 ** <li> SQLITE_MUTEX_STATIC_MEM2
18832 ** <li> SQLITE_MUTEX_STATIC_PRNG
18833 ** <li> SQLITE_MUTEX_STATIC_LRU
18834 ** <li> SQLITE_MUTEX_STATIC_PMEM
 
 
 
18835 ** </ul>
18836 **
18837 ** The first two constants cause sqlite3_mutex_alloc() to create
18838 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
18839 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -18858,10 +18870,13 @@
18858 ** mutex types, the same mutex is returned on every call that has
18859 ** the same type number.
18860 */
18861 static sqlite3_mutex *pthreadMutexAlloc(int iType){
18862 static sqlite3_mutex staticMutexes[] = {
 
 
 
18863 SQLITE3_MUTEX_INITIALIZER,
18864 SQLITE3_MUTEX_INITIALIZER,
18865 SQLITE3_MUTEX_INITIALIZER,
18866 SQLITE3_MUTEX_INITIALIZER,
18867 SQLITE3_MUTEX_INITIALIZER,
@@ -19093,14 +19108,227 @@
19093 ** May you do good and not evil.
19094 ** May you find forgiveness for yourself and forgive others.
19095 ** May you share freely, never taking more than you give.
19096 **
19097 *************************************************************************
19098 ** This file contains the C functions that implement mutexes for win32
19099 */
19100
19101 #if SQLITE_OS_WIN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19102 /*
19103 ** Include the header file for the Windows VFS.
19104 */
19105 /************** Include os_win.h in the middle of mutex_w32.c ****************/
19106 /************** Begin file os_win.h ******************************************/
@@ -19176,11 +19404,11 @@
19176 /************** Continuing where we left off in mutex_w32.c ******************/
19177 #endif
19178
19179 /*
19180 ** The code in this file is only used if we are compiling multithreaded
19181 ** on a win32 system.
19182 */
19183 #ifdef SQLITE_MUTEX_W32
19184
19185 /*
19186 ** Each recursive mutex is an instance of the following structure.
@@ -19189,94 +19417,75 @@
19189 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
19190 int id; /* Mutex type */
19191 #ifdef SQLITE_DEBUG
19192 volatile int nRef; /* Number of enterances */
19193 volatile DWORD owner; /* Thread holding this mutex */
19194 int trace; /* True to trace changes */
19195 #endif
19196 };
 
 
 
 
 
 
19197 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
 
19198 #ifdef SQLITE_DEBUG
19199 #define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, 0L, (DWORD)0, 0 }
 
19200 #else
19201 #define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 }
19202 #endif
19203
19204 /*
19205 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
19206 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
19207 **
19208 ** Here is an interesting observation: Win95, Win98, and WinME lack
19209 ** the LockFileEx() API. But we can still statically link against that
19210 ** API as long as we don't call it win running Win95/98/ME. A call to
19211 ** this routine is used to determine if the host is Win95/98/ME or
19212 ** WinNT/2K/XP so that we will know whether or not we can safely call
19213 ** the LockFileEx() API.
19214 **
19215 ** mutexIsNT() is only used for the TryEnterCriticalSection() API call,
19216 ** which is only available if your application was compiled with
19217 ** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
19218 ** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
19219 ** this out as well.
19220 */
19221 #if 0
19222 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT
19223 # define mutexIsNT() (1)
19224 #else
19225 static int mutexIsNT(void){
19226 static int osType = 0;
19227 if( osType==0 ){
19228 OSVERSIONINFO sInfo;
19229 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
19230 GetVersionEx(&sInfo);
19231 osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
19232 }
19233 return osType==2;
19234 }
19235 #endif /* SQLITE_OS_WINCE || SQLITE_OS_WINRT */
19236 #endif
19237
19238 #ifdef SQLITE_DEBUG
19239 /*
19240 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
19241 ** intended for use only inside assert() statements.
19242 */
19243 static int winMutexHeld(sqlite3_mutex *p){
19244 return p->nRef!=0 && p->owner==GetCurrentThreadId();
19245 }
 
19246 static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
19247 return p->nRef==0 || p->owner!=tid;
19248 }
 
19249 static int winMutexNotheld(sqlite3_mutex *p){
19250 DWORD tid = GetCurrentThreadId();
19251 return winMutexNotheld2(p, tid);
19252 }
19253 #endif
19254
19255
19256 /*
19257 ** Initialize and deinitialize the mutex subsystem.
19258 */
19259 static sqlite3_mutex winMutex_staticMutexes[6] = {
 
 
 
19260 SQLITE3_MUTEX_INITIALIZER,
19261 SQLITE3_MUTEX_INITIALIZER,
19262 SQLITE3_MUTEX_INITIALIZER,
19263 SQLITE3_MUTEX_INITIALIZER,
19264 SQLITE3_MUTEX_INITIALIZER,
19265 SQLITE3_MUTEX_INITIALIZER
19266 };
 
19267 static int winMutex_isInit = 0;
19268 /* As winMutexInit() and winMutexEnd() are called as part
19269 ** of the sqlite3_initialize and sqlite3_shutdown()
19270 ** processing, the "interlocked" magic is probably not
19271 ** strictly necessary.
 
19272 */
19273 static LONG winMutex_lock = 0;
19274
 
19275 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
19276
19277 static int winMutexInit(void){
19278 /* The first to increment to 1 does actual initialization */
19279 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
19280 int i;
19281 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
19282 #if SQLITE_OS_WINRT
@@ -19285,20 +19494,21 @@
19285 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
19286 #endif
19287 }
19288 winMutex_isInit = 1;
19289 }else{
19290 /* Someone else is in the process of initing the static mutexes */
 
19291 while( !winMutex_isInit ){
19292 sqlite3_win32_sleep(1);
19293 }
19294 }
19295 return SQLITE_OK;
19296 }
19297
19298 static int winMutexEnd(void){
19299 /* The first to decrement to 0 does actual shutdown
19300 ** (which should be the last to shutdown.) */
19301 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
19302 if( winMutex_isInit==1 ){
19303 int i;
19304 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
@@ -19305,11 +19515,11 @@
19305 DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
19306 }
19307 winMutex_isInit = 0;
19308 }
19309 }
19310 return SQLITE_OK;
19311 }
19312
19313 /*
19314 ** The sqlite3_mutex_alloc() routine allocates a new
19315 ** mutex and returns a pointer to it. If it returns NULL
@@ -19320,14 +19530,17 @@
19320 ** <ul>
19321 ** <li> SQLITE_MUTEX_FAST
19322 ** <li> SQLITE_MUTEX_RECURSIVE
19323 ** <li> SQLITE_MUTEX_STATIC_MASTER
19324 ** <li> SQLITE_MUTEX_STATIC_MEM
19325 ** <li> SQLITE_MUTEX_STATIC_MEM2
19326 ** <li> SQLITE_MUTEX_STATIC_PRNG
19327 ** <li> SQLITE_MUTEX_STATIC_LRU
19328 ** <li> SQLITE_MUTEX_STATIC_PMEM
 
 
 
19329 ** </ul>
19330 **
19331 ** The first two constants cause sqlite3_mutex_alloc() to create
19332 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
19333 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19346,11 +19559,11 @@
19346 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
19347 ** SQLITE_MUTEX_RECURSIVE.
19348 **
19349 ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
19350 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
19351 ** returns a different mutex on every call. But for the static
19352 ** mutex types, the same mutex is returned on every call that has
19353 ** the same type number.
19354 */
19355 static sqlite3_mutex *winMutexAlloc(int iType){
19356 sqlite3_mutex *p;
@@ -19357,13 +19570,16 @@
19357
19358 switch( iType ){
19359 case SQLITE_MUTEX_FAST:
19360 case SQLITE_MUTEX_RECURSIVE: {
19361 p = sqlite3MallocZero( sizeof(*p) );
19362 if( p ){
19363 #ifdef SQLITE_DEBUG
19364 p->id = iType;
 
 
 
19365 #endif
19366 #if SQLITE_OS_WINRT
19367 InitializeCriticalSectionEx(&p->mutex, 0, 0);
19368 #else
19369 InitializeCriticalSection(&p->mutex);
@@ -19370,16 +19586,19 @@
19370 #endif
19371 }
19372 break;
19373 }
19374 default: {
19375 assert( winMutex_isInit==1 );
19376 assert( iType-2 >= 0 );
19377 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
 
19378 p = &winMutex_staticMutexes[iType-2];
19379 #ifdef SQLITE_DEBUG
19380 p->id = iType;
 
 
 
19381 #endif
19382 break;
19383 }
19384 }
19385 return p;
@@ -19391,12 +19610,15 @@
19391 ** allocated mutex. SQLite is careful to deallocate every
19392 ** mutex that it allocates.
19393 */
19394 static void winMutexFree(sqlite3_mutex *p){
19395 assert( p );
 
19396 assert( p->nRef==0 && p->owner==0 );
19397 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
 
 
19398 DeleteCriticalSection(&p->mutex);
19399 sqlite3_free(p);
19400 }
19401
19402 /*
@@ -19409,53 +19631,71 @@
19409 ** mutex must be exited an equal number of times before another thread
19410 ** can enter. If the same thread tries to enter any other kind of mutex
19411 ** more than once, the behavior is undefined.
19412 */
19413 static void winMutexEnter(sqlite3_mutex *p){
 
 
 
19414 #ifdef SQLITE_DEBUG
19415 DWORD tid = GetCurrentThreadId();
19416 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
 
 
19417 #endif
 
19418 EnterCriticalSection(&p->mutex);
19419 #ifdef SQLITE_DEBUG
19420 assert( p->nRef>0 || p->owner==0 );
19421 p->owner = tid;
19422 p->nRef++;
19423 if( p->trace ){
19424 printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
 
19425 }
19426 #endif
19427 }
 
19428 static int winMutexTry(sqlite3_mutex *p){
19429 #ifndef NDEBUG
19430 DWORD tid = GetCurrentThreadId();
19431 #endif
19432 int rc = SQLITE_BUSY;
 
19433 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
19434 /*
19435 ** The sqlite3_mutex_try() routine is very rarely used, and when it
19436 ** is used it is merely an optimization. So it is OK for it to always
19437 ** fail.
19438 **
19439 ** The TryEnterCriticalSection() interface is only available on WinNT.
19440 ** And some windows compilers complain if you try to use it without
19441 ** first doing some #defines that prevent SQLite from building on Win98.
19442 ** For that reason, we will omit this optimization for now. See
19443 ** ticket #2685.
19444 */
19445 #if 0
19446 if( mutexIsNT() && TryEnterCriticalSection(&p->mutex) ){
 
 
 
 
 
 
 
19447 p->owner = tid;
19448 p->nRef++;
 
19449 rc = SQLITE_OK;
19450 }
19451 #else
19452 UNUSED_PARAMETER(p);
19453 #endif
19454 #ifdef SQLITE_DEBUG
19455 if( rc==SQLITE_OK && p->trace ){
19456 printf("try mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
 
19457 }
19458 #endif
19459 return rc;
19460 }
19461
@@ -19464,22 +19704,27 @@
19464 ** previously entered by the same thread. The behavior
19465 ** is undefined if the mutex is not currently entered or
19466 ** is not currently allocated. SQLite will never do either.
19467 */
19468 static void winMutexLeave(sqlite3_mutex *p){
19469 #ifndef NDEBUG
19470 DWORD tid = GetCurrentThreadId();
 
 
 
19471 assert( p->nRef>0 );
19472 assert( p->owner==tid );
19473 p->nRef--;
19474 if( p->nRef==0 ) p->owner = 0;
19475 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
19476 #endif
 
19477 LeaveCriticalSection(&p->mutex);
19478 #ifdef SQLITE_DEBUG
19479 if( p->trace ){
19480 printf("leave mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
 
19481 }
19482 #endif
19483 }
19484
19485 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -19497,13 +19742,13 @@
19497 #else
19498 0,
19499 0
19500 #endif
19501 };
19502
19503 return &sMutex;
19504 }
 
19505 #endif /* SQLITE_MUTEX_W32 */
19506
19507 /************** End of mutex_w32.c *******************************************/
19508 /************** Begin file malloc.c ******************************************/
19509 /*
@@ -23718,14 +23963,14 @@
23718 /* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23719 /* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23720 /* 57 */ "SorterOpen" OpHelp(""),
23721 /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23722 /* 59 */ "Close" OpHelp(""),
23723 /* 60 */ "SeekLT" OpHelp(""),
23724 /* 61 */ "SeekLE" OpHelp(""),
23725 /* 62 */ "SeekGE" OpHelp(""),
23726 /* 63 */ "SeekGT" OpHelp(""),
23727 /* 64 */ "Seek" OpHelp("intkey=r[P2]"),
23728 /* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23729 /* 66 */ "NotFound" OpHelp("key=r[P3@P4]"),
23730 /* 67 */ "Found" OpHelp("key=r[P3@P4]"),
23731 /* 68 */ "NotExists" OpHelp("intkey=r[P3]"),
@@ -23753,11 +23998,11 @@
23753 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23754 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23755 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23756 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23757 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23758 /* 95 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23759 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23760 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23761 /* 98 */ "SorterData" OpHelp("r[P2]=data"),
23762 /* 99 */ "RowKey" OpHelp("r[P2]=key"),
23763 /* 100 */ "RowData" OpHelp("r[P2]=data"),
@@ -32160,14 +32405,14 @@
32160 **
32161 ** In order to facilitate testing on a WinNT system, the test fixture
32162 ** can manually set this value to 1 to emulate Win98 behavior.
32163 */
32164 #ifdef SQLITE_TEST
32165 SQLITE_API int sqlite3_os_type = 0;
32166 #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
32167 defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
32168 static int sqlite3_os_type = 0;
32169 #endif
32170
32171 #ifndef SYSCALL
32172 # define SYSCALL sqlite3_syscall_ptr
32173 #endif
@@ -32793,10 +33038,15 @@
32793 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
32794 #endif
32795
32796 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
32797 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
 
 
 
 
 
32798
32799 }; /* End of the overrideable system calls */
32800
32801 /*
32802 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -33044,26 +33294,33 @@
33044 #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
33045 # define osIsNT() (1)
33046 #elif !defined(SQLITE_WIN32_HAS_WIDE)
33047 # define osIsNT() (0)
33048 #else
33049 static int osIsNT(void){
33050 if( sqlite3_os_type==0 ){
 
 
 
 
 
 
 
33051 #if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
33052 OSVERSIONINFOW sInfo;
33053 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33054 osGetVersionExW(&sInfo);
33055 #else
33056 OSVERSIONINFOA sInfo;
33057 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33058 osGetVersionExA(&sInfo);
33059 #endif
33060 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
33061 }
33062 return sqlite3_os_type==2;
33063 }
33064 #endif
33065
33066 #ifdef SQLITE_WIN32_MALLOC
33067 /*
33068 ** Allocate nBytes of memory.
33069 */
@@ -37215,11 +37472,11 @@
37215 };
37216 #endif
37217
37218 /* Double-check that the aSyscall[] array has been constructed
37219 ** correctly. See ticket [bb3a86e890c8e96ab] */
37220 assert( ArraySize(aSyscall)==76 );
37221
37222 /* get memory map allocation granularity */
37223 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
37224 #if SQLITE_OS_WINRT
37225 osGetNativeSystemInfo(&winSysInfo);
@@ -52907,11 +53164,11 @@
52907 return pBt->nPage;
52908 }
52909 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
52910 assert( sqlite3BtreeHoldsMutex(p) );
52911 assert( ((p->pBt->nPage)&0x8000000)==0 );
52912 return (int)btreePagecount(p->pBt);
52913 }
52914
52915 /*
52916 ** Get a page from the pager and initialize it. This routine is just a
52917 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -64735,11 +64992,11 @@
64735 /*
64736 ** Return the serial-type for the value stored in pMem.
64737 */
64738 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
64739 int flags = pMem->flags;
64740 int n;
64741
64742 if( flags&MEM_Null ){
64743 return 0;
64744 }
64745 if( flags&MEM_Int ){
@@ -64765,15 +65022,15 @@
64765 }
64766 if( flags&MEM_Real ){
64767 return 7;
64768 }
64769 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
64770 n = pMem->n;
 
64771 if( flags & MEM_Zero ){
64772 n += pMem->u.nZero;
64773 }
64774 assert( n>=0 );
64775 return ((n*2) + 12 + ((flags&MEM_Str)!=0));
64776 }
64777
64778 /*
64779 ** Return the length of the data corresponding to the supplied serial-type.
@@ -67845,25 +68102,25 @@
67845 ** do so without loss of information. In other words, if the string
67846 ** looks like a number, convert it into a number. If it does not
67847 ** look like a number, leave it alone.
67848 */
67849 static void applyNumericAffinity(Mem *pRec){
67850 if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
67851 double rValue;
67852 i64 iValue;
67853 u8 enc = pRec->enc;
67854 if( (pRec->flags&MEM_Str)==0 ) return;
67855 if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
67856 if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
67857 pRec->u.i = iValue;
67858 pRec->flags |= MEM_Int;
67859 }else{
67860 pRec->r = rValue;
67861 pRec->flags |= MEM_Real;
67862 }
67863 }
67864 }
67865
67866 /*
67867 ** Processing is determine by the affinity parameter:
67868 **
67869 ** SQLITE_AFF_INTEGER:
@@ -67896,11 +68153,11 @@
67896 }
67897 pRec->flags &= ~(MEM_Real|MEM_Int);
67898 }else if( affinity!=SQLITE_AFF_NONE ){
67899 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
67900 || affinity==SQLITE_AFF_NUMERIC );
67901 applyNumericAffinity(pRec);
67902 if( pRec->flags & MEM_Real ){
67903 sqlite3VdbeIntegerAffinity(pRec);
67904 }
67905 }
67906 }
@@ -68477,16 +68734,18 @@
68477 break;
68478 }
68479
68480 /* Opcode: InitCoroutine P1 P2 P3 * *
68481 **
68482 ** Set up register P1 so that it will OP_Yield to the co-routine
68483 ** located at address P3.
68484 **
68485 ** If P2!=0 then the co-routine implementation immediately follows
68486 ** this opcode. So jump over the co-routine implementation to
68487 ** address P2.
 
 
68488 */
68489 case OP_InitCoroutine: { /* jump */
68490 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
68491 assert( pOp->p2>=0 && pOp->p2<p->nOp );
68492 assert( pOp->p3>=0 && pOp->p3<p->nOp );
@@ -68498,13 +68757,15 @@
68498 break;
68499 }
68500
68501 /* Opcode: EndCoroutine P1 * * * *
68502 **
68503 ** The instruction at the address in register P1 is an OP_Yield.
68504 ** Jump to the P2 parameter of that OP_Yield.
68505 ** After the jump, register P1 becomes undefined.
 
 
68506 */
68507 case OP_EndCoroutine: { /* in1 */
68508 VdbeOp *pCaller;
68509 pIn1 = &aMem[pOp->p1];
68510 assert( pIn1->flags==MEM_Int );
@@ -68517,15 +68778,20 @@
68517 break;
68518 }
68519
68520 /* Opcode: Yield P1 P2 * * *
68521 **
68522 ** Swap the program counter with the value in register P1.
 
68523 **
68524 ** If the co-routine ends with OP_Yield or OP_Return then continue
68525 ** to the next instruction. But if the co-routine ends with
68526 ** OP_EndCoroutine, jump immediately to P2.
 
 
 
 
68527 */
68528 case OP_Yield: { /* in1, jump */
68529 int pcDest;
68530 pIn1 = &aMem[pOp->p1];
68531 assert( VdbeMemDynamic(pIn1)==0 );
@@ -69906,14 +70172,18 @@
69906 break;
69907 }
69908
69909 /* Opcode: Once P1 P2 * * *
69910 **
69911 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
69912 ** set the flag and fall through to the next instruction. In other words,
69913 ** this opcode causes all following opcodes up through P2 (but not including
69914 ** P2) to run just once and to be skipped on subsequent times through the loop.
 
 
 
 
69915 */
69916 case OP_Once: { /* jump */
69917 assert( pOp->p1<p->nOnceFlag );
69918 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
69919 if( p->aOnceFlag[pOp->p1] ){
@@ -71191,11 +71461,11 @@
71191 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
71192 p->apCsr[pOp->p1] = 0;
71193 break;
71194 }
71195
71196 /* Opcode: SeekGe P1 P2 P3 P4 *
71197 ** Synopsis: key=r[P3@P4]
71198 **
71199 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71200 ** use the value in register P3 as the key. If cursor P1 refers
71201 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71202,14 +71472,18 @@
71202 ** that are used as an unpacked index key.
71203 **
71204 ** Reposition cursor P1 so that it points to the smallest entry that
71205 ** is greater than or equal to the key value. If there are no records
71206 ** greater than or equal to the key and P2 is not zero, then jump to P2.
 
 
 
 
71207 **
71208 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
71209 */
71210 /* Opcode: SeekGt P1 P2 P3 P4 *
71211 ** Synopsis: key=r[P3@P4]
71212 **
71213 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71214 ** use the value in register P3 as a key. If cursor P1 refers
71215 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71216,14 +71490,18 @@
71216 ** that are used as an unpacked index key.
71217 **
71218 ** Reposition cursor P1 so that it points to the smallest entry that
71219 ** is greater than the key value. If there are no records greater than
71220 ** the key and P2 is not zero, then jump to P2.
 
 
 
 
71221 **
71222 ** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
71223 */
71224 /* Opcode: SeekLt P1 P2 P3 P4 *
71225 ** Synopsis: key=r[P3@P4]
71226 **
71227 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71228 ** use the value in register P3 as a key. If cursor P1 refers
71229 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71230,14 +71508,18 @@
71230 ** that are used as an unpacked index key.
71231 **
71232 ** Reposition cursor P1 so that it points to the largest entry that
71233 ** is less than the key value. If there are no records less than
71234 ** the key and P2 is not zero, then jump to P2.
 
 
 
 
71235 **
71236 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
71237 */
71238 /* Opcode: SeekLe P1 P2 P3 P4 *
71239 ** Synopsis: key=r[P3@P4]
71240 **
71241 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71242 ** use the value in register P3 as a key. If cursor P1 refers
71243 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71244,10 +71526,14 @@
71244 ** that are used as an unpacked index key.
71245 **
71246 ** Reposition cursor P1 so that it points to the largest entry that
71247 ** is less than or equal to the key value. If there are no records
71248 ** less than or equal to the key and P2 is not zero, then jump to P2.
 
 
 
 
71249 **
71250 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
71251 */
71252 case OP_SeekLT: /* jump, in3 */
71253 case OP_SeekLE: /* jump, in3 */
@@ -71270,16 +71556,19 @@
71270 assert( OP_SeekGT == OP_SeekLT+3 );
71271 assert( pC->isOrdered );
71272 assert( pC->pCursor!=0 );
71273 oc = pOp->opcode;
71274 pC->nullRow = 0;
 
 
 
71275 if( pC->isTable ){
71276 /* The input value in P3 might be of any type: integer, real, string,
71277 ** blob, or NULL. But it needs to be an integer before we can do
71278 ** the seek, so covert it. */
71279 pIn3 = &aMem[pOp->p3];
71280 applyNumericAffinity(pIn3);
71281 iKey = sqlite3VdbeIntValue(pIn3);
71282 pC->rowidIsValid = 0;
71283
71284 /* If the P3 value could not be converted into an integer without
71285 ** loss of information, then special processing is required... */
@@ -71424,10 +71713,14 @@
71424 ** record.
71425 **
71426 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
71427 ** is a prefix of any entry in P1 then a jump is made to P2 and
71428 ** P1 is left pointing at the matching entry.
 
 
 
 
71429 **
71430 ** See also: NotFound, NoConflict, NotExists. SeekGe
71431 */
71432 /* Opcode: NotFound P1 P2 P3 P4 *
71433 ** Synopsis: key=r[P3@P4]
@@ -71439,10 +71732,14 @@
71439 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
71440 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
71441 ** does contain an entry whose prefix matches the P3/P4 record then control
71442 ** falls through to the next instruction and P1 is left pointing at the
71443 ** matching entry.
 
 
 
 
71444 **
71445 ** See also: Found, NotExists, NoConflict
71446 */
71447 /* Opcode: NoConflict P1 P2 P3 P4 *
71448 ** Synopsis: key=r[P3@P4]
@@ -71458,10 +71755,14 @@
71458 ** immediately to P2. If there is a match, fall through and leave the P1
71459 ** cursor pointing to the matching row.
71460 **
71461 ** This opcode is similar to OP_NotFound with the exceptions that the
71462 ** branch is always taken if any part of the search key input is NULL.
 
 
 
 
71463 **
71464 ** See also: NotFound, Found, NotExists
71465 */
71466 case OP_NoConflict: /* jump, in3 */
71467 case OP_NotFound: /* jump, in3 */
@@ -71481,10 +71782,13 @@
71481
71482 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71483 assert( pOp->p4type==P4_INT32 );
71484 pC = p->apCsr[pOp->p1];
71485 assert( pC!=0 );
 
 
 
71486 pIn3 = &aMem[pOp->p3];
71487 assert( pC->pCursor!=0 );
71488 assert( pC->isTable==0 );
71489 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
71490 if( pOp->p4.i>0 ){
@@ -71551,10 +71855,14 @@
71551 ** with rowid P3 then leave the cursor pointing at that record and fall
71552 ** through to the next instruction.
71553 **
71554 ** The OP_NotFound opcode performs the same operation on index btrees
71555 ** (with arbitrary multi-value keys).
 
 
 
 
71556 **
71557 ** See also: Found, NotFound, NoConflict
71558 */
71559 case OP_NotExists: { /* jump, in3 */
71560 VdbeCursor *pC;
@@ -71565,10 +71873,13 @@
71565 pIn3 = &aMem[pOp->p3];
71566 assert( pIn3->flags & MEM_Int );
71567 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71568 pC = p->apCsr[pOp->p1];
71569 assert( pC!=0 );
 
 
 
71570 assert( pC->isTable );
71571 assert( pC->pseudoTableReg==0 );
71572 pCrsr = pC->pCursor;
71573 assert( pCrsr!=0 );
71574 res = 0;
@@ -71927,16 +72238,16 @@
71927 p->nChange = 0;
71928 break;
71929 }
71930
71931 /* Opcode: SorterCompare P1 P2 P3 P4
71932 ** Synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2
71933 **
71934 ** P1 is a sorter cursor. This instruction compares a prefix of the
71935 ** the record blob in register P3 against a prefix of the entry that
71936 ** the sorter cursor currently points to. The final P4 fields of both
71937 ** the P3 and sorter record are ignored.
71938 **
71939 ** If either P3 or the sorter contains a NULL in one of their significant
71940 ** fields (not counting the P4 fields at the end which are ignored) then
71941 ** the comparison is assumed to be equal.
71942 **
@@ -71944,18 +72255,18 @@
71944 ** each other. Jump to P2 if they are different.
71945 */
71946 case OP_SorterCompare: {
71947 VdbeCursor *pC;
71948 int res;
71949 int nIgnore;
71950
71951 pC = p->apCsr[pOp->p1];
71952 assert( isSorter(pC) );
71953 assert( pOp->p4type==P4_INT32 );
71954 pIn3 = &aMem[pOp->p3];
71955 nIgnore = pOp->p4.i;
71956 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
71957 VdbeBranchTaken(res!=0,2);
71958 if( res ){
71959 pc = pOp->p2-1;
71960 }
71961 break;
@@ -72131,15 +72442,19 @@
72131 break;
72132 }
72133
72134 /* Opcode: Last P1 P2 * * *
72135 **
72136 ** The next use of the Rowid or Column or Next instruction for P1
72137 ** will refer to the last entry in the database table or index.
72138 ** If the table or index is empty and P2>0, then jump immediately to P2.
72139 ** If P2 is 0 or if the table or index is not empty, fall through
72140 ** to the following instruction.
 
 
 
 
72141 */
72142 case OP_Last: { /* jump */
72143 VdbeCursor *pC;
72144 BtCursor *pCrsr;
72145 int res;
@@ -72153,10 +72468,13 @@
72153 rc = sqlite3BtreeLast(pCrsr, &res);
72154 pC->nullRow = (u8)res;
72155 pC->deferredMoveto = 0;
72156 pC->rowidIsValid = 0;
72157 pC->cacheStatus = CACHE_STALE;
 
 
 
72158 if( pOp->p2>0 ){
72159 VdbeBranchTaken(res!=0,2);
72160 if( res ) pc = pOp->p2 - 1;
72161 }
72162 break;
@@ -72189,10 +72507,14 @@
72189 ** The next use of the Rowid or Column or Next instruction for P1
72190 ** will refer to the first entry in the database table or index.
72191 ** If the table or index is empty and P2>0, then jump immediately to P2.
72192 ** If P2 is 0 or if the table or index is not empty, fall through
72193 ** to the following instruction.
 
 
 
 
72194 */
72195 case OP_Rewind: { /* jump */
72196 VdbeCursor *pC;
72197 BtCursor *pCrsr;
72198 int res;
@@ -72200,10 +72522,13 @@
72200 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
72201 pC = p->apCsr[pOp->p1];
72202 assert( pC!=0 );
72203 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
72204 res = 1;
 
 
 
72205 if( isSorter(pC) ){
72206 rc = sqlite3VdbeSorterRewind(db, pC, &res);
72207 }else{
72208 pCrsr = pC->pCursor;
72209 assert( pCrsr );
@@ -72225,10 +72550,14 @@
72225 **
72226 ** Advance cursor P1 so that it points to the next key/data pair in its
72227 ** table or index. If there are no more key/value pairs then fall through
72228 ** to the following instruction. But if the cursor advance was successful,
72229 ** jump immediately to P2.
 
 
 
 
72230 **
72231 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
72232 ** been opened prior to this opcode or the program will segfault.
72233 **
72234 ** The P3 value is a hint to the btree implementation. If P3==1, that
@@ -72244,20 +72573,25 @@
72244 **
72245 ** See also: Prev, NextIfOpen
72246 */
72247 /* Opcode: NextIfOpen P1 P2 P3 P4 P5
72248 **
72249 ** This opcode works just like OP_Next except that if cursor P1 is not
72250 ** open it behaves a no-op.
72251 */
72252 /* Opcode: Prev P1 P2 P3 P4 P5
72253 **
72254 ** Back up cursor P1 so that it points to the previous key/data pair in its
72255 ** table or index. If there is no previous key/value pairs then fall through
72256 ** to the following instruction. But if the cursor backup was successful,
72257 ** jump immediately to P2.
72258 **
 
 
 
 
 
72259 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
72260 ** not open then the behavior is undefined.
72261 **
72262 ** The P3 value is a hint to the btree implementation. If P3==1, that
72263 ** means P1 is an SQL index and that this instruction could have been
@@ -72270,11 +72604,11 @@
72270 ** If P5 is positive and the jump is taken, then event counter
72271 ** number P5-1 in the prepared statement is incremented.
72272 */
72273 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
72274 **
72275 ** This opcode works just like OP_Prev except that if cursor P1 is not
72276 ** open it behaves a no-op.
72277 */
72278 case OP_SorterNext: { /* jump */
72279 VdbeCursor *pC;
72280 int res;
@@ -72301,10 +72635,20 @@
72301 testcase( res==1 );
72302 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
72303 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
72304 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
72305 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
 
 
 
 
 
 
 
 
 
 
72306 rc = pOp->p4.xAdvance(pC->pCursor, &res);
72307 next_tail:
72308 pC->cacheStatus = CACHE_STALE;
72309 VdbeBranchTaken(res==0,2);
72310 if( res==0 ){
@@ -72781,11 +73125,12 @@
72781
72782 /* Opcode: DropTable P1 * * P4 *
72783 **
72784 ** Remove the internal (in-memory) data structures that describe
72785 ** the table named P4 in database P1. This is called after a table
72786 ** is dropped in order to keep the internal representation of the
 
72787 ** schema consistent with what is on disk.
72788 */
72789 case OP_DropTable: {
72790 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
72791 break;
@@ -72793,11 +73138,12 @@
72793
72794 /* Opcode: DropIndex P1 * * P4 *
72795 **
72796 ** Remove the internal (in-memory) data structures that describe
72797 ** the index named P4 in database P1. This is called after an index
72798 ** is dropped in order to keep the internal representation of the
 
72799 ** schema consistent with what is on disk.
72800 */
72801 case OP_DropIndex: {
72802 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
72803 break;
@@ -72805,11 +73151,12 @@
72805
72806 /* Opcode: DropTrigger P1 * * P4 *
72807 **
72808 ** Remove the internal (in-memory) data structures that describe
72809 ** the trigger named P4 in database P1. This is called after a trigger
72810 ** is dropped in order to keep the internal representation of the
 
72811 ** schema consistent with what is on disk.
72812 */
72813 case OP_DropTrigger: {
72814 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
72815 break;
@@ -75011,11 +75358,11 @@
75011 ** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
75012 ** has been allocated and contains an unpacked record that is used as key2.
75013 */
75014 static void vdbeSorterCompare(
75015 const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
75016 int nIgnore, /* Ignore the last nIgnore fields */
75017 const void *pKey1, int nKey1, /* Left side of comparison */
75018 const void *pKey2, int nKey2, /* Right side of comparison */
75019 int *pRes /* OUT: Result of comparison */
75020 ){
75021 KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -75025,14 +75372,13 @@
75025
75026 if( pKey2 ){
75027 sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
75028 }
75029
75030 if( nIgnore ){
75031 r2->nField = pKeyInfo->nField - nIgnore;
75032 assert( r2->nField>0 );
75033 for(i=0; i<r2->nField; i++){
75034 if( r2->aMem[i].flags & MEM_Null ){
75035 *pRes = -1;
75036 return;
75037 }
75038 }
@@ -75710,18 +76056,18 @@
75710 ** key.
75711 */
75712 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
75713 const VdbeCursor *pCsr, /* Sorter cursor */
75714 Mem *pVal, /* Value to compare to current sorter key */
75715 int nIgnore, /* Ignore this many fields at the end */
75716 int *pRes /* OUT: Result of comparison */
75717 ){
75718 VdbeSorter *pSorter = pCsr->pSorter;
75719 void *pKey; int nKey; /* Sorter key to compare pVal with */
75720
75721 pKey = vdbeSorterRowkey(pSorter, &nKey);
75722 vdbeSorterCompare(pCsr, nIgnore, pVal->z, pVal->n, pKey, nKey, pRes);
75723 return SQLITE_OK;
75724 }
75725
75726 /************** End of vdbesort.c ********************************************/
75727 /************** Begin file journal.c *****************************************/
@@ -79474,11 +79820,11 @@
79474 }
79475 }
79476 }
79477
79478 if( eType==0 ){
79479 /* Could not found an existing table or index to use as the RHS b-tree.
79480 ** We will have to generate an ephemeral table to do the job.
79481 */
79482 u32 savedNQueryLoop = pParse->nQueryLoop;
79483 int rMayHaveNull = 0;
79484 eType = IN_INDEX_EPH;
@@ -79604,24 +79950,27 @@
79604 /* Case 1: expr IN (SELECT ...)
79605 **
79606 ** Generate code to write the results of the select into the temporary
79607 ** table allocated and opened above.
79608 */
 
79609 SelectDest dest;
79610 ExprList *pEList;
79611
79612 assert( !isRowid );
79613 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
79614 dest.affSdst = (u8)affinity;
79615 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
79616 pExpr->x.pSelect->iLimit = 0;
 
 
79617 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
79618 if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
79619 sqlite3KeyInfoUnref(pKeyInfo);
79620 return 0;
79621 }
79622 pEList = pExpr->x.pSelect->pEList;
79623 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
79624 assert( pEList!=0 );
79625 assert( pEList->nExpr>0 );
79626 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
79627 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
@@ -83315,19 +83664,24 @@
83315 }
83316
83317 /*
83318 ** Implementation of the stat_init(N,K,C) SQL function. The three parameters
83319 ** are:
83320 ** N: The number of columns in the index including the rowid/pk
83321 ** K: The number of columns in the index excluding the rowid/pk
83322 ** C: The number of rows in the index
83323 **
83324 ** C is only used for STAT3 and STAT4.
83325 **
83326 ** For ordinary rowid tables, N==K+1. But for WITHOUT ROWID tables,
83327 ** N=K+P where P is the number of columns in the primary key. For the
83328 ** covering index that implements the original WITHOUT ROWID table, N==K.
 
 
 
 
 
83329 **
83330 ** This routine allocates the Stat4Accum object in heap memory. The return
83331 ** value is a pointer to the the Stat4Accum object encoded as a blob (i.e.
83332 ** the size of the blob is sizeof(void*) bytes).
83333 */
@@ -83633,11 +83987,14 @@
83633 ** P Pointer to the Stat4Accum object created by stat_init()
83634 ** C Index of left-most column to differ from previous row
83635 ** R Rowid for the current row. Might be a key record for
83636 ** WITHOUT ROWID tables.
83637 **
83638 ** The SQL function always returns NULL.
 
 
 
83639 **
83640 ** The R parameter is only used for STAT3 and STAT4
83641 */
83642 static void statPush(
83643 sqlite3_context *context,
@@ -83727,11 +84084,14 @@
83727 #define STAT_GET_NLT 3 /* "nlt" column of stat[34] entry */
83728 #define STAT_GET_NDLT 4 /* "ndlt" column of stat[34] entry */
83729
83730 /*
83731 ** Implementation of the stat_get(P,J) SQL function. This routine is
83732 ** used to query the results. Content is returned for parameter J
 
 
 
83733 ** which is one of the STAT_GET_xxxx values defined above.
83734 **
83735 ** If neither STAT3 nor STAT4 are enabled, then J is always
83736 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
83737 ** a one-parameter function, stat_get(P), that always returns the
@@ -83946,28 +84306,27 @@
83946 pParse->nTab = MAX(pParse->nTab, iTab);
83947 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
83948 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
83949
83950 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
83951 int nCol; /* Number of columns indexed by pIdx */
83952 int *aGotoChng; /* Array of jump instruction addresses */
83953 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
83954 int addrGotoChng0; /* Address of "Goto addr_chng_0" */
83955 int addrNextRow; /* Address of "next_row:" */
83956 const char *zIdxName; /* Name of the index */
 
83957
83958 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
83959 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
83960 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
83961 nCol = pIdx->nKeyCol;
83962 zIdxName = pTab->zName;
 
83963 }else{
83964 nCol = pIdx->nColumn;
83965 zIdxName = pIdx->zName;
 
83966 }
83967 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
83968 if( aGotoChng==0 ) continue;
83969
83970 /* Populate the register containing the index name. */
83971 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
83972 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
83973
@@ -83992,11 +84351,11 @@
83992 ** regPrev(0) = idx(0)
83993 ** chng_addr_1:
83994 ** regPrev(1) = idx(1)
83995 ** ...
83996 **
83997 ** chng_addr_N:
83998 ** regRowid = idx(rowid)
83999 ** stat_push(P, regChng, regRowid)
84000 ** Next csr
84001 ** if !eof(csr) goto next_row;
84002 **
@@ -84005,24 +84364,27 @@
84005
84006 /* Make sure there are enough memory cells allocated to accommodate
84007 ** the regPrev array and a trailing rowid (the rowid slot is required
84008 ** when building a record to insert into the sample column of
84009 ** the sqlite_stat4 table. */
84010 pParse->nMem = MAX(pParse->nMem, regPrev+nCol);
84011
84012 /* Open a read-only cursor on the index being analyzed. */
84013 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
84014 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
84015 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
84016 VdbeComment((v, "%s", pIdx->zName));
84017
84018 /* Invoke the stat_init() function. The arguments are:
84019 **
84020 ** (1) the number of columns in the index including the rowid,
84021 ** (2) the number of rows in the index,
 
 
84022 **
84023 ** The second argument is only used for STAT3 and STAT4
 
84024 */
84025 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
84026 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3);
84027 #endif
84028 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1);
@@ -84040,56 +84402,73 @@
84040 **
84041 */
84042 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
84043 VdbeCoverage(v);
84044 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
84045 addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
84046
84047 /*
84048 ** next_row:
84049 ** regChng = 0
84050 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
84051 ** regChng = 1
84052 ** if( idx(1) != regPrev(1) ) goto chng_addr_1
84053 ** ...
84054 ** regChng = N
84055 ** goto chng_addr_N
84056 */
84057 addrNextRow = sqlite3VdbeCurrentAddr(v);
84058 for(i=0; i<nCol-1; i++){
84059 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
84060 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
84061 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
84062 aGotoChng[i] =
84063 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
84064 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
84065 VdbeCoverage(v);
84066 }
84067 sqlite3VdbeAddOp2(v, OP_Integer, nCol-1, regChng);
84068 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
84069
84070 /*
84071 ** chng_addr_0:
84072 ** regPrev(0) = idx(0)
84073 ** chng_addr_1:
84074 ** regPrev(1) = idx(1)
84075 ** ...
84076 */
84077 sqlite3VdbeJumpHere(v, addrGotoChng0);
84078 for(i=0; i<nCol-1; i++){
84079 sqlite3VdbeJumpHere(v, aGotoChng[i]);
84080 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
84081 }
84082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84083 /*
84084 ** chng_addr_N:
84085 ** regRowid = idx(rowid) // STAT34 only
84086 ** stat_push(P, regChng, regRowid) // 3rd parameter STAT34 only
84087 ** Next csr
84088 ** if !eof(csr) goto next_row;
84089 */
84090 sqlite3VdbeJumpHere(v, aGotoChng[nCol]);
84091 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
84092 assert( regRowid==(regStat4+2) );
84093 if( HasRowid(pTab) ){
84094 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
84095 }else{
@@ -84163,11 +84542,10 @@
84163 }
84164 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
84165
84166 /* End of analysis */
84167 sqlite3VdbeJumpHere(v, addrRewind);
84168 sqlite3DbFree(db, aGotoChng);
84169 }
84170
84171
84172 /* Create a single sqlite_stat1 entry containing NULL as the index
84173 ** name and the row count as the content.
@@ -88308,11 +88686,11 @@
88308 if( pIndex->onError!=OE_None && pKey!=0 ){
88309 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
88310 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
88311 addr2 = sqlite3VdbeCurrentAddr(v);
88312 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
88313 pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
88314 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
88315 }else{
88316 addr2 = sqlite3VdbeCurrentAddr(v);
88317 }
88318 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
@@ -98186,11 +98564,11 @@
98186 ** Note that the values returned are one less that the values that
98187 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
98188 ** to support legacy SQL code. The safety level used to be boolean
98189 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
98190 */
98191 static u8 getSafetyLevel(const char *z, int omitFull, int dflt){
98192 /* 123456789 123456789 */
98193 static const char zText[] = "onoffalseyestruefull";
98194 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
98195 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
98196 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
@@ -98208,11 +98586,11 @@
98208 }
98209
98210 /*
98211 ** Interpret the given string as a boolean value.
98212 */
98213 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, int dflt){
98214 return getSafetyLevel(z,1,dflt)!=0;
98215 }
98216
98217 /* The sqlite3GetBoolean() function is used by other modules but the
98218 ** remainder of this file is specific to PRAGMA processing. So omit
@@ -112398,11 +112776,12 @@
112398 int nEq = pLoop->u.btree.nEq;
112399 sqlite3 *db = pParse->db;
112400 int nLower = -1;
112401 int nUpper = p->nSample+1;
112402 int rc = SQLITE_OK;
112403 u8 aff = p->pTable->aCol[ p->aiColumn[nEq] ].affinity;
 
112404 CollSeq *pColl;
112405
112406 sqlite3_value *p1 = 0; /* Value extracted from pLower */
112407 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
112408 sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -122593,11 +122972,11 @@
122593
122594 /*
122595 ** Return a static string containing the name corresponding to the error code
122596 ** specified in the argument.
122597 */
122598 #if defined(SQLITE_TEST)
122599 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
122600 const char *zName = 0;
122601 int i, origRc = rc;
122602 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
122603 switch( rc ){
@@ -124897,10 +125276,20 @@
124897 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
124898 sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
124899 #endif
124900 break;
124901 }
 
 
 
 
 
 
 
 
 
 
124902
124903 }
124904 va_end(ap);
124905 #endif /* SQLITE_OMIT_BUILTIN_TEST */
124906 return rc;
@@ -145542,13 +145931,17 @@
145542 int rc = SQLITE_OK;
145543 int iCell = 0;
145544
145545 rtreeReference(pRtree);
145546
 
145547 freeCursorConstraints(pCsr);
 
 
 
 
145548 pCsr->iStrategy = idxNum;
145549
145550 if( idxNum==1 ){
145551 /* Special case - lookup by rowid. */
145552 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
145553 RtreeSearchPoint *p; /* Search point for the the leaf */
145554 i64 iRowid = sqlite3_value_int64(argv[0]);
145555
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.6"
226 #define SQLITE_VERSION_NUMBER 3008006
227 #define SQLITE_SOURCE_ID "2014-07-31 18:54:01 1e5489faff093d6a8e538061e45532f9050e9459"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -5993,14 +5993,16 @@
5993 ** <ul>
5994 ** <li> SQLITE_MUTEX_FAST
5995 ** <li> SQLITE_MUTEX_RECURSIVE
5996 ** <li> SQLITE_MUTEX_STATIC_MASTER
5997 ** <li> SQLITE_MUTEX_STATIC_MEM
5998 ** <li> SQLITE_MUTEX_STATIC_OPEN
5999 ** <li> SQLITE_MUTEX_STATIC_PRNG
6000 ** <li> SQLITE_MUTEX_STATIC_LRU
6001 ** <li> SQLITE_MUTEX_STATIC_PMEM
6002 ** <li> SQLITE_MUTEX_STATIC_APP1
6003 ** <li> SQLITE_MUTEX_STATIC_APP2
6004 ** </ul>)^
6005 **
6006 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
6007 ** cause sqlite3_mutex_alloc() to create
6008 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6200,10 +6202,13 @@
6202 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
6203 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
6204 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
6205 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6206 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6207 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6208 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6209 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6210
6211 /*
6212 ** CAPI3REF: Retrieve the mutex for a database connection
6213 **
6214 ** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6295,11 +6300,12 @@
6300 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6301 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6302 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6303 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6304 #define SQLITE_TESTCTRL_BYTEORDER 22
6305 #define SQLITE_TESTCTRL_ISINIT 23
6306 #define SQLITE_TESTCTRL_LAST 23
6307
6308 /*
6309 ** CAPI3REF: SQLite Runtime Status
6310 **
6311 ** ^This interface is used to retrieve runtime status information
@@ -9325,14 +9331,14 @@
9331 #define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */
9332 #define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */
9333 #define OP_SorterOpen 57
9334 #define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
9335 #define OP_Close 59
9336 #define OP_SeekLT 60 /* synopsis: key=r[P3@P4] */
9337 #define OP_SeekLE 61 /* synopsis: key=r[P3@P4] */
9338 #define OP_SeekGE 62 /* synopsis: key=r[P3@P4] */
9339 #define OP_SeekGT 63 /* synopsis: key=r[P3@P4] */
9340 #define OP_Seek 64 /* synopsis: intkey=r[P2] */
9341 #define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */
9342 #define OP_NotFound 66 /* synopsis: key=r[P3@P4] */
9343 #define OP_Found 67 /* synopsis: key=r[P3@P4] */
9344 #define OP_NotExists 68 /* synopsis: intkey=r[P3] */
@@ -9360,11 +9366,11 @@
9366 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9367 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9368 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9369 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9370 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9371 #define OP_SorterCompare 95 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
9372 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9373 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9374 #define OP_SorterData 98 /* synopsis: r[P2]=data */
9375 #define OP_RowKey 99 /* synopsis: r[P2]=key */
9376 #define OP_RowData 100 /* synopsis: r[P2]=data */
@@ -12852,11 +12858,11 @@
12858 #ifdef SQLITE_ENABLE_8_3_NAMES
12859 SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
12860 #else
12861 # define sqlite3FileSuffix3(X,Y)
12862 #endif
12863 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,u8);
12864
12865 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12866 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12867 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12868 void(*)(void*));
@@ -13927,10 +13933,13 @@
13933 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13934 int seekResult; /* Result of previous sqlite3BtreeMoveto() */
13935 int pseudoTableReg; /* Register holding pseudotable content. */
13936 i16 nField; /* Number of fields in the header */
13937 u16 nHdrParsed; /* Number of header fields parsed so far */
13938 #ifdef SQLITE_DEBUG
13939 u8 seekOp; /* Most recent seek operation on this cursor */
13940 #endif
13941 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
13942 u8 nullRow; /* True if pointing to a row with no data */
13943 u8 rowidIsValid; /* True if lastRowid is valid */
13944 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13945 Bool isEphemeral:1; /* True for an ephemeral table */
@@ -18448,11 +18457,11 @@
18457 /*
18458 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18459 */
18460 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18461 #ifndef SQLITE_OMIT_AUTOINIT
18462 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
18463 #endif
18464 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18465 }
18466
18467 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -18629,11 +18638,11 @@
18638 ** The sqlite3_mutex_alloc() routine allocates a new
18639 ** mutex and returns a pointer to it. If it returns NULL
18640 ** that means that a mutex could not be allocated.
18641 */
18642 static sqlite3_mutex *debugMutexAlloc(int id){
18643 static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1];
18644 sqlite3_debug_mutex *pNew = 0;
18645 switch( id ){
18646 case SQLITE_MUTEX_FAST:
18647 case SQLITE_MUTEX_RECURSIVE: {
18648 pNew = sqlite3Malloc(sizeof(*pNew));
@@ -18826,14 +18835,17 @@
18835 ** <ul>
18836 ** <li> SQLITE_MUTEX_FAST
18837 ** <li> SQLITE_MUTEX_RECURSIVE
18838 ** <li> SQLITE_MUTEX_STATIC_MASTER
18839 ** <li> SQLITE_MUTEX_STATIC_MEM
18840 ** <li> SQLITE_MUTEX_STATIC_OPEN
18841 ** <li> SQLITE_MUTEX_STATIC_PRNG
18842 ** <li> SQLITE_MUTEX_STATIC_LRU
18843 ** <li> SQLITE_MUTEX_STATIC_PMEM
18844 ** <li> SQLITE_MUTEX_STATIC_APP1
18845 ** <li> SQLITE_MUTEX_STATIC_APP2
18846 ** <li> SQLITE_MUTEX_STATIC_APP3
18847 ** </ul>
18848 **
18849 ** The first two constants cause sqlite3_mutex_alloc() to create
18850 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
18851 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -18858,10 +18870,13 @@
18870 ** mutex types, the same mutex is returned on every call that has
18871 ** the same type number.
18872 */
18873 static sqlite3_mutex *pthreadMutexAlloc(int iType){
18874 static sqlite3_mutex staticMutexes[] = {
18875 SQLITE3_MUTEX_INITIALIZER,
18876 SQLITE3_MUTEX_INITIALIZER,
18877 SQLITE3_MUTEX_INITIALIZER,
18878 SQLITE3_MUTEX_INITIALIZER,
18879 SQLITE3_MUTEX_INITIALIZER,
18880 SQLITE3_MUTEX_INITIALIZER,
18881 SQLITE3_MUTEX_INITIALIZER,
18882 SQLITE3_MUTEX_INITIALIZER,
@@ -19093,14 +19108,227 @@
19108 ** May you do good and not evil.
19109 ** May you find forgiveness for yourself and forgive others.
19110 ** May you share freely, never taking more than you give.
19111 **
19112 *************************************************************************
19113 ** This file contains the C functions that implement mutexes for Win32.
19114 */
19115
19116 #if SQLITE_OS_WIN
19117 /*
19118 ** Include code that is common to all os_*.c files
19119 */
19120 /************** Include os_common.h in the middle of mutex_w32.c *************/
19121 /************** Begin file os_common.h ***************************************/
19122 /*
19123 ** 2004 May 22
19124 **
19125 ** The author disclaims copyright to this source code. In place of
19126 ** a legal notice, here is a blessing:
19127 **
19128 ** May you do good and not evil.
19129 ** May you find forgiveness for yourself and forgive others.
19130 ** May you share freely, never taking more than you give.
19131 **
19132 ******************************************************************************
19133 **
19134 ** This file contains macros and a little bit of code that is common to
19135 ** all of the platform-specific files (os_*.c) and is #included into those
19136 ** files.
19137 **
19138 ** This file should be #included by the os_*.c files only. It is not a
19139 ** general purpose header file.
19140 */
19141 #ifndef _OS_COMMON_H_
19142 #define _OS_COMMON_H_
19143
19144 /*
19145 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
19146 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
19147 ** switch. The following code should catch this problem at compile-time.
19148 */
19149 #ifdef MEMORY_DEBUG
19150 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19151 #endif
19152
19153 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19154 # ifndef SQLITE_DEBUG_OS_TRACE
19155 # define SQLITE_DEBUG_OS_TRACE 0
19156 # endif
19157 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19158 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19159 #else
19160 # define OSTRACE(X)
19161 #endif
19162
19163 /*
19164 ** Macros for performance tracing. Normally turned off. Only works
19165 ** on i486 hardware.
19166 */
19167 #ifdef SQLITE_PERFORMANCE_TRACE
19168
19169 /*
19170 ** hwtime.h contains inline assembler code for implementing
19171 ** high-performance timing routines.
19172 */
19173 /************** Include hwtime.h in the middle of os_common.h ****************/
19174 /************** Begin file hwtime.h ******************************************/
19175 /*
19176 ** 2008 May 27
19177 **
19178 ** The author disclaims copyright to this source code. In place of
19179 ** a legal notice, here is a blessing:
19180 **
19181 ** May you do good and not evil.
19182 ** May you find forgiveness for yourself and forgive others.
19183 ** May you share freely, never taking more than you give.
19184 **
19185 ******************************************************************************
19186 **
19187 ** This file contains inline asm code for retrieving "high-performance"
19188 ** counters for x86 class CPUs.
19189 */
19190 #ifndef _HWTIME_H_
19191 #define _HWTIME_H_
19192
19193 /*
19194 ** The following routine only works on pentium-class (or newer) processors.
19195 ** It uses the RDTSC opcode to read the cycle count value out of the
19196 ** processor and returns that value. This can be used for high-res
19197 ** profiling.
19198 */
19199 #if (defined(__GNUC__) || defined(_MSC_VER)) && \
19200 (defined(i386) || defined(__i386__) || defined(_M_IX86))
19201
19202 #if defined(__GNUC__)
19203
19204 __inline__ sqlite_uint64 sqlite3Hwtime(void){
19205 unsigned int lo, hi;
19206 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
19207 return (sqlite_uint64)hi << 32 | lo;
19208 }
19209
19210 #elif defined(_MSC_VER)
19211
19212 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
19213 __asm {
19214 rdtsc
19215 ret ; return value at EDX:EAX
19216 }
19217 }
19218
19219 #endif
19220
19221 #elif (defined(__GNUC__) && defined(__x86_64__))
19222
19223 __inline__ sqlite_uint64 sqlite3Hwtime(void){
19224 unsigned long val;
19225 __asm__ __volatile__ ("rdtsc" : "=A" (val));
19226 return val;
19227 }
19228
19229 #elif (defined(__GNUC__) && defined(__ppc__))
19230
19231 __inline__ sqlite_uint64 sqlite3Hwtime(void){
19232 unsigned long long retval;
19233 unsigned long junk;
19234 __asm__ __volatile__ ("\n\
19235 1: mftbu %1\n\
19236 mftb %L0\n\
19237 mftbu %0\n\
19238 cmpw %0,%1\n\
19239 bne 1b"
19240 : "=r" (retval), "=r" (junk));
19241 return retval;
19242 }
19243
19244 #else
19245
19246 #error Need implementation of sqlite3Hwtime() for your platform.
19247
19248 /*
19249 ** To compile without implementing sqlite3Hwtime() for your platform,
19250 ** you can remove the above #error and use the following
19251 ** stub function. You will lose timing support for many
19252 ** of the debugging and testing utilities, but it should at
19253 ** least compile and run.
19254 */
19255 SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
19256
19257 #endif
19258
19259 #endif /* !defined(_HWTIME_H_) */
19260
19261 /************** End of hwtime.h **********************************************/
19262 /************** Continuing where we left off in os_common.h ******************/
19263
19264 static sqlite_uint64 g_start;
19265 static sqlite_uint64 g_elapsed;
19266 #define TIMER_START g_start=sqlite3Hwtime()
19267 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
19268 #define TIMER_ELAPSED g_elapsed
19269 #else
19270 #define TIMER_START
19271 #define TIMER_END
19272 #define TIMER_ELAPSED ((sqlite_uint64)0)
19273 #endif
19274
19275 /*
19276 ** If we compile with the SQLITE_TEST macro set, then the following block
19277 ** of code will give us the ability to simulate a disk I/O error. This
19278 ** is used for testing the I/O recovery logic.
19279 */
19280 #ifdef SQLITE_TEST
19281 SQLITE_API int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
19282 SQLITE_API int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
19283 SQLITE_API int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
19284 SQLITE_API int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
19285 SQLITE_API int sqlite3_io_error_benign = 0; /* True if errors are benign */
19286 SQLITE_API int sqlite3_diskfull_pending = 0;
19287 SQLITE_API int sqlite3_diskfull = 0;
19288 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)
19289 #define SimulateIOError(CODE) \
19290 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
19291 || sqlite3_io_error_pending-- == 1 ) \
19292 { local_ioerr(); CODE; }
19293 static void local_ioerr(){
19294 IOTRACE(("IOERR\n"));
19295 sqlite3_io_error_hit++;
19296 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;
19297 }
19298 #define SimulateDiskfullError(CODE) \
19299 if( sqlite3_diskfull_pending ){ \
19300 if( sqlite3_diskfull_pending == 1 ){ \
19301 local_ioerr(); \
19302 sqlite3_diskfull = 1; \
19303 sqlite3_io_error_hit = 1; \
19304 CODE; \
19305 }else{ \
19306 sqlite3_diskfull_pending--; \
19307 } \
19308 }
19309 #else
19310 #define SimulateIOErrorBenign(X)
19311 #define SimulateIOError(A)
19312 #define SimulateDiskfullError(A)
19313 #endif
19314
19315 /*
19316 ** When testing, keep a count of the number of open files.
19317 */
19318 #ifdef SQLITE_TEST
19319 SQLITE_API int sqlite3_open_file_count = 0;
19320 #define OpenCounter(X) sqlite3_open_file_count+=(X)
19321 #else
19322 #define OpenCounter(X)
19323 #endif
19324
19325 #endif /* !defined(_OS_COMMON_H_) */
19326
19327 /************** End of os_common.h *******************************************/
19328 /************** Continuing where we left off in mutex_w32.c ******************/
19329
19330 /*
19331 ** Include the header file for the Windows VFS.
19332 */
19333 /************** Include os_win.h in the middle of mutex_w32.c ****************/
19334 /************** Begin file os_win.h ******************************************/
@@ -19176,11 +19404,11 @@
19404 /************** Continuing where we left off in mutex_w32.c ******************/
19405 #endif
19406
19407 /*
19408 ** The code in this file is only used if we are compiling multithreaded
19409 ** on a Win32 system.
19410 */
19411 #ifdef SQLITE_MUTEX_W32
19412
19413 /*
19414 ** Each recursive mutex is an instance of the following structure.
@@ -19189,94 +19417,75 @@
19417 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
19418 int id; /* Mutex type */
19419 #ifdef SQLITE_DEBUG
19420 volatile int nRef; /* Number of enterances */
19421 volatile DWORD owner; /* Thread holding this mutex */
19422 volatile int trace; /* True to trace changes */
19423 #endif
19424 };
19425
19426 /*
19427 ** These are the initializer values used when declaring a "static" mutex
19428 ** on Win32. It should be noted that all mutexes require initialization
19429 ** on the Win32 platform.
19430 */
19431 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
19432
19433 #ifdef SQLITE_DEBUG
19434 #define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, \
19435 0L, (DWORD)0, 0 }
19436 #else
19437 #define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 }
19438 #endif
19439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19440 #ifdef SQLITE_DEBUG
19441 /*
19442 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
19443 ** intended for use only inside assert() statements.
19444 */
19445 static int winMutexHeld(sqlite3_mutex *p){
19446 return p->nRef!=0 && p->owner==GetCurrentThreadId();
19447 }
19448
19449 static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
19450 return p->nRef==0 || p->owner!=tid;
19451 }
19452
19453 static int winMutexNotheld(sqlite3_mutex *p){
19454 DWORD tid = GetCurrentThreadId();
19455 return winMutexNotheld2(p, tid);
19456 }
19457 #endif
19458
 
19459 /*
19460 ** Initialize and deinitialize the mutex subsystem.
19461 */
19462 static sqlite3_mutex winMutex_staticMutexes[] = {
19463 SQLITE3_MUTEX_INITIALIZER,
19464 SQLITE3_MUTEX_INITIALIZER,
19465 SQLITE3_MUTEX_INITIALIZER,
19466 SQLITE3_MUTEX_INITIALIZER,
19467 SQLITE3_MUTEX_INITIALIZER,
19468 SQLITE3_MUTEX_INITIALIZER,
19469 SQLITE3_MUTEX_INITIALIZER,
19470 SQLITE3_MUTEX_INITIALIZER,
19471 SQLITE3_MUTEX_INITIALIZER
19472 };
19473
19474 static int winMutex_isInit = 0;
19475 static int winMutex_isNt = -1; /* <0 means "need to query" */
19476
19477 /* As the winMutexInit() and winMutexEnd() functions are called as part
19478 ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
19479 ** "interlocked" magic used here is probably not strictly necessary.
19480 */
19481 static LONG volatile winMutex_lock = 0;
19482
19483 SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
19484 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
19485
19486 static int winMutexInit(void){
19487 /* The first to increment to 1 does actual initialization */
19488 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
19489 int i;
19490 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
19491 #if SQLITE_OS_WINRT
@@ -19285,20 +19494,21 @@
19494 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
19495 #endif
19496 }
19497 winMutex_isInit = 1;
19498 }else{
19499 /* Another thread is (in the process of) initializing the static
19500 ** mutexes */
19501 while( !winMutex_isInit ){
19502 sqlite3_win32_sleep(1);
19503 }
19504 }
19505 return SQLITE_OK;
19506 }
19507
19508 static int winMutexEnd(void){
19509 /* The first to decrement to 0 does actual shutdown
19510 ** (which should be the last to shutdown.) */
19511 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
19512 if( winMutex_isInit==1 ){
19513 int i;
19514 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
@@ -19305,11 +19515,11 @@
19515 DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
19516 }
19517 winMutex_isInit = 0;
19518 }
19519 }
19520 return SQLITE_OK;
19521 }
19522
19523 /*
19524 ** The sqlite3_mutex_alloc() routine allocates a new
19525 ** mutex and returns a pointer to it. If it returns NULL
@@ -19320,14 +19530,17 @@
19530 ** <ul>
19531 ** <li> SQLITE_MUTEX_FAST
19532 ** <li> SQLITE_MUTEX_RECURSIVE
19533 ** <li> SQLITE_MUTEX_STATIC_MASTER
19534 ** <li> SQLITE_MUTEX_STATIC_MEM
19535 ** <li> SQLITE_MUTEX_STATIC_OPEN
19536 ** <li> SQLITE_MUTEX_STATIC_PRNG
19537 ** <li> SQLITE_MUTEX_STATIC_LRU
19538 ** <li> SQLITE_MUTEX_STATIC_PMEM
19539 ** <li> SQLITE_MUTEX_STATIC_APP1
19540 ** <li> SQLITE_MUTEX_STATIC_APP2
19541 ** <li> SQLITE_MUTEX_STATIC_APP3
19542 ** </ul>
19543 **
19544 ** The first two constants cause sqlite3_mutex_alloc() to create
19545 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
19546 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19346,11 +19559,11 @@
19559 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
19560 ** SQLITE_MUTEX_RECURSIVE.
19561 **
19562 ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
19563 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
19564 ** returns a different mutex on every call. But for the static
19565 ** mutex types, the same mutex is returned on every call that has
19566 ** the same type number.
19567 */
19568 static sqlite3_mutex *winMutexAlloc(int iType){
19569 sqlite3_mutex *p;
@@ -19357,13 +19570,16 @@
19570
19571 switch( iType ){
19572 case SQLITE_MUTEX_FAST:
19573 case SQLITE_MUTEX_RECURSIVE: {
19574 p = sqlite3MallocZero( sizeof(*p) );
19575 if( p ){
19576 #ifdef SQLITE_DEBUG
19577 p->id = iType;
19578 #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
19579 p->trace = 1;
19580 #endif
19581 #endif
19582 #if SQLITE_OS_WINRT
19583 InitializeCriticalSectionEx(&p->mutex, 0, 0);
19584 #else
19585 InitializeCriticalSection(&p->mutex);
@@ -19370,16 +19586,19 @@
19586 #endif
19587 }
19588 break;
19589 }
19590 default: {
 
19591 assert( iType-2 >= 0 );
19592 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
19593 assert( winMutex_isInit==1 );
19594 p = &winMutex_staticMutexes[iType-2];
19595 #ifdef SQLITE_DEBUG
19596 p->id = iType;
19597 #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
19598 p->trace = 1;
19599 #endif
19600 #endif
19601 break;
19602 }
19603 }
19604 return p;
@@ -19391,12 +19610,15 @@
19610 ** allocated mutex. SQLite is careful to deallocate every
19611 ** mutex that it allocates.
19612 */
19613 static void winMutexFree(sqlite3_mutex *p){
19614 assert( p );
19615 #ifdef SQLITE_DEBUG
19616 assert( p->nRef==0 && p->owner==0 );
19617 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
19618 #endif
19619 assert( winMutex_isInit==1 );
19620 DeleteCriticalSection(&p->mutex);
19621 sqlite3_free(p);
19622 }
19623
19624 /*
@@ -19409,53 +19631,71 @@
19631 ** mutex must be exited an equal number of times before another thread
19632 ** can enter. If the same thread tries to enter any other kind of mutex
19633 ** more than once, the behavior is undefined.
19634 */
19635 static void winMutexEnter(sqlite3_mutex *p){
19636 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
19637 DWORD tid = GetCurrentThreadId();
19638 #endif
19639 #ifdef SQLITE_DEBUG
19640 assert( p );
19641 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
19642 #else
19643 assert( p );
19644 #endif
19645 assert( winMutex_isInit==1 );
19646 EnterCriticalSection(&p->mutex);
19647 #ifdef SQLITE_DEBUG
19648 assert( p->nRef>0 || p->owner==0 );
19649 p->owner = tid;
19650 p->nRef++;
19651 if( p->trace ){
19652 OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
19653 tid, p, p->trace, p->nRef));
19654 }
19655 #endif
19656 }
19657
19658 static int winMutexTry(sqlite3_mutex *p){
19659 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
19660 DWORD tid = GetCurrentThreadId();
19661 #endif
19662 int rc = SQLITE_BUSY;
19663 assert( p );
19664 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
19665 /*
19666 ** The sqlite3_mutex_try() routine is very rarely used, and when it
19667 ** is used it is merely an optimization. So it is OK for it to always
19668 ** fail.
19669 **
19670 ** The TryEnterCriticalSection() interface is only available on WinNT.
19671 ** And some windows compilers complain if you try to use it without
19672 ** first doing some #defines that prevent SQLite from building on Win98.
19673 ** For that reason, we will omit this optimization for now. See
19674 ** ticket #2685.
19675 */
19676 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
19677 assert( winMutex_isInit==1 );
19678 assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
19679 if( winMutex_isNt<0 ){
19680 winMutex_isNt = sqlite3_win32_is_nt();
19681 }
19682 assert( winMutex_isNt==0 || winMutex_isNt==1 );
19683 if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
19684 #ifdef SQLITE_DEBUG
19685 p->owner = tid;
19686 p->nRef++;
19687 #endif
19688 rc = SQLITE_OK;
19689 }
19690 #else
19691 UNUSED_PARAMETER(p);
19692 #endif
19693 #ifdef SQLITE_DEBUG
19694 if( p->trace ){
19695 OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
19696 tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
19697 }
19698 #endif
19699 return rc;
19700 }
19701
@@ -19464,22 +19704,27 @@
19704 ** previously entered by the same thread. The behavior
19705 ** is undefined if the mutex is not currently entered or
19706 ** is not currently allocated. SQLite will never do either.
19707 */
19708 static void winMutexLeave(sqlite3_mutex *p){
19709 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
19710 DWORD tid = GetCurrentThreadId();
19711 #endif
19712 assert( p );
19713 #ifdef SQLITE_DEBUG
19714 assert( p->nRef>0 );
19715 assert( p->owner==tid );
19716 p->nRef--;
19717 if( p->nRef==0 ) p->owner = 0;
19718 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
19719 #endif
19720 assert( winMutex_isInit==1 );
19721 LeaveCriticalSection(&p->mutex);
19722 #ifdef SQLITE_DEBUG
19723 if( p->trace ){
19724 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
19725 tid, p, p->trace, p->nRef));
19726 }
19727 #endif
19728 }
19729
19730 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -19497,13 +19742,13 @@
19742 #else
19743 0,
19744 0
19745 #endif
19746 };
 
19747 return &sMutex;
19748 }
19749
19750 #endif /* SQLITE_MUTEX_W32 */
19751
19752 /************** End of mutex_w32.c *******************************************/
19753 /************** Begin file malloc.c ******************************************/
19754 /*
@@ -23718,14 +23963,14 @@
23963 /* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23964 /* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23965 /* 57 */ "SorterOpen" OpHelp(""),
23966 /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23967 /* 59 */ "Close" OpHelp(""),
23968 /* 60 */ "SeekLT" OpHelp("key=r[P3@P4]"),
23969 /* 61 */ "SeekLE" OpHelp("key=r[P3@P4]"),
23970 /* 62 */ "SeekGE" OpHelp("key=r[P3@P4]"),
23971 /* 63 */ "SeekGT" OpHelp("key=r[P3@P4]"),
23972 /* 64 */ "Seek" OpHelp("intkey=r[P2]"),
23973 /* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23974 /* 66 */ "NotFound" OpHelp("key=r[P3@P4]"),
23975 /* 67 */ "Found" OpHelp("key=r[P3@P4]"),
23976 /* 68 */ "NotExists" OpHelp("intkey=r[P3]"),
@@ -23753,11 +23998,11 @@
23998 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23999 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
24000 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
24001 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
24002 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
24003 /* 95 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
24004 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
24005 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
24006 /* 98 */ "SorterData" OpHelp("r[P2]=data"),
24007 /* 99 */ "RowKey" OpHelp("r[P2]=key"),
24008 /* 100 */ "RowData" OpHelp("r[P2]=data"),
@@ -32160,14 +32405,14 @@
32405 **
32406 ** In order to facilitate testing on a WinNT system, the test fixture
32407 ** can manually set this value to 1 to emulate Win98 behavior.
32408 */
32409 #ifdef SQLITE_TEST
32410 SQLITE_API LONG volatile sqlite3_os_type = 0;
32411 #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
32412 defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
32413 static LONG volatile sqlite3_os_type = 0;
32414 #endif
32415
32416 #ifndef SYSCALL
32417 # define SYSCALL sqlite3_syscall_ptr
32418 #endif
@@ -32793,10 +33038,15 @@
33038 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
33039 #endif
33040
33041 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
33042 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
33043
33044 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
33045
33046 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*, \
33047 LONG,LONG))aSyscall[76].pCurrent)
33048
33049 }; /* End of the overrideable system calls */
33050
33051 /*
33052 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -33044,26 +33294,33 @@
33294 #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
33295 # define osIsNT() (1)
33296 #elif !defined(SQLITE_WIN32_HAS_WIDE)
33297 # define osIsNT() (0)
33298 #else
33299 # define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
33300 #endif
33301
33302 /*
33303 ** This function determines if the machine is running a version of Windows
33304 ** based on the NT kernel.
33305 */
33306 SQLITE_API int sqlite3_win32_is_nt(void){
33307 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
33308 #if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
33309 OSVERSIONINFOW sInfo;
33310 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33311 osGetVersionExW(&sInfo);
33312 #else
33313 OSVERSIONINFOA sInfo;
33314 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33315 osGetVersionExA(&sInfo);
33316 #endif
33317 osInterlockedCompareExchange(&sqlite3_os_type,
33318 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33319 }
33320 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33321 }
33322
33323 #ifdef SQLITE_WIN32_MALLOC
33324 /*
33325 ** Allocate nBytes of memory.
33326 */
@@ -37215,11 +37472,11 @@
37472 };
37473 #endif
37474
37475 /* Double-check that the aSyscall[] array has been constructed
37476 ** correctly. See ticket [bb3a86e890c8e96ab] */
37477 assert( ArraySize(aSyscall)==77 );
37478
37479 /* get memory map allocation granularity */
37480 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
37481 #if SQLITE_OS_WINRT
37482 osGetNativeSystemInfo(&winSysInfo);
@@ -52907,11 +53164,11 @@
53164 return pBt->nPage;
53165 }
53166 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
53167 assert( sqlite3BtreeHoldsMutex(p) );
53168 assert( ((p->pBt->nPage)&0x8000000)==0 );
53169 return btreePagecount(p->pBt);
53170 }
53171
53172 /*
53173 ** Get a page from the pager and initialize it. This routine is just a
53174 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -64735,11 +64992,11 @@
64992 /*
64993 ** Return the serial-type for the value stored in pMem.
64994 */
64995 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
64996 int flags = pMem->flags;
64997 u32 n;
64998
64999 if( flags&MEM_Null ){
65000 return 0;
65001 }
65002 if( flags&MEM_Int ){
@@ -64765,15 +65022,15 @@
65022 }
65023 if( flags&MEM_Real ){
65024 return 7;
65025 }
65026 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
65027 assert( pMem->n>=0 );
65028 n = (u32)pMem->n;
65029 if( flags & MEM_Zero ){
65030 n += pMem->u.nZero;
65031 }
 
65032 return ((n*2) + 12 + ((flags&MEM_Str)!=0));
65033 }
65034
65035 /*
65036 ** Return the length of the data corresponding to the supplied serial-type.
@@ -67845,25 +68102,25 @@
68102 ** do so without loss of information. In other words, if the string
68103 ** looks like a number, convert it into a number. If it does not
68104 ** look like a number, leave it alone.
68105 */
68106 static void applyNumericAffinity(Mem *pRec){
68107 double rValue;
68108 i64 iValue;
68109 u8 enc = pRec->enc;
68110 if( (pRec->flags&MEM_Str)==0 ) return;
68111 if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
68112 if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
68113 pRec->u.i = iValue;
68114 pRec->flags |= MEM_Int;
68115 }else{
68116 pRec->r = rValue;
68117 pRec->flags |= MEM_Real;
68118 }
68119 }
68120 #define ApplyNumericAffinity(X) \
68121 if(((X)->flags&(MEM_Real|MEM_Int))==0){applyNumericAffinity(X);}
68122
68123 /*
68124 ** Processing is determine by the affinity parameter:
68125 **
68126 ** SQLITE_AFF_INTEGER:
@@ -67896,11 +68153,11 @@
68153 }
68154 pRec->flags &= ~(MEM_Real|MEM_Int);
68155 }else if( affinity!=SQLITE_AFF_NONE ){
68156 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
68157 || affinity==SQLITE_AFF_NUMERIC );
68158 ApplyNumericAffinity(pRec);
68159 if( pRec->flags & MEM_Real ){
68160 sqlite3VdbeIntegerAffinity(pRec);
68161 }
68162 }
68163 }
@@ -68477,16 +68734,18 @@
68734 break;
68735 }
68736
68737 /* Opcode: InitCoroutine P1 P2 P3 * *
68738 **
68739 ** Set up register P1 so that it will Yield to the coroutine
68740 ** located at address P3.
68741 **
68742 ** If P2!=0 then the coroutine implementation immediately follows
68743 ** this opcode. So jump over the coroutine implementation to
68744 ** address P2.
68745 **
68746 ** See also: EndCoroutine
68747 */
68748 case OP_InitCoroutine: { /* jump */
68749 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
68750 assert( pOp->p2>=0 && pOp->p2<p->nOp );
68751 assert( pOp->p3>=0 && pOp->p3<p->nOp );
@@ -68498,13 +68757,15 @@
68757 break;
68758 }
68759
68760 /* Opcode: EndCoroutine P1 * * * *
68761 **
68762 ** The instruction at the address in register P1 is an Yield.
68763 ** Jump to the P2 parameter of that Yield.
68764 ** After the jump, register P1 becomes undefined.
68765 **
68766 ** See also: InitCoroutine
68767 */
68768 case OP_EndCoroutine: { /* in1 */
68769 VdbeOp *pCaller;
68770 pIn1 = &aMem[pOp->p1];
68771 assert( pIn1->flags==MEM_Int );
@@ -68517,15 +68778,20 @@
68778 break;
68779 }
68780
68781 /* Opcode: Yield P1 P2 * * *
68782 **
68783 ** Swap the program counter with the value in register P1. This
68784 ** has the effect of yielding to a coroutine.
68785 **
68786 ** If the coroutine that is launched by this instruction ends with
68787 ** Yield or Return then continue to the next instruction. But if
68788 ** the coroutine launched by this instruction ends with
68789 ** EndCoroutine, then jump to P2 rather than continuing with the
68790 ** next instruction.
68791 **
68792 ** See also: InitCoroutine
68793 */
68794 case OP_Yield: { /* in1, jump */
68795 int pcDest;
68796 pIn1 = &aMem[pOp->p1];
68797 assert( VdbeMemDynamic(pIn1)==0 );
@@ -69906,14 +70172,18 @@
70172 break;
70173 }
70174
70175 /* Opcode: Once P1 P2 * * *
70176 **
70177 ** Check the "once" flag number P1. If it is set, jump to instruction P2.
70178 ** Otherwise, set the flag and fall through to the next instruction.
70179 ** In other words, this opcode causes all following opcodes up through P2
70180 ** (but not including P2) to run just once and to be skipped on subsequent
70181 ** times through the loop.
70182 **
70183 ** All "once" flags are initially cleared whenever a prepared statement
70184 ** first begins to run.
70185 */
70186 case OP_Once: { /* jump */
70187 assert( pOp->p1<p->nOnceFlag );
70188 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
70189 if( p->aOnceFlag[pOp->p1] ){
@@ -71191,11 +71461,11 @@
71461 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
71462 p->apCsr[pOp->p1] = 0;
71463 break;
71464 }
71465
71466 /* Opcode: SeekGE P1 P2 P3 P4 *
71467 ** Synopsis: key=r[P3@P4]
71468 **
71469 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71470 ** use the value in register P3 as the key. If cursor P1 refers
71471 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71202,14 +71472,18 @@
71472 ** that are used as an unpacked index key.
71473 **
71474 ** Reposition cursor P1 so that it points to the smallest entry that
71475 ** is greater than or equal to the key value. If there are no records
71476 ** greater than or equal to the key and P2 is not zero, then jump to P2.
71477 **
71478 ** This opcode leaves the cursor configured to move in forward order,
71479 ** from the begining toward the end. In other words, the cursor is
71480 ** configured to use Next, not Prev.
71481 **
71482 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
71483 */
71484 /* Opcode: SeekGT P1 P2 P3 P4 *
71485 ** Synopsis: key=r[P3@P4]
71486 **
71487 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71488 ** use the value in register P3 as a key. If cursor P1 refers
71489 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71216,14 +71490,18 @@
71490 ** that are used as an unpacked index key.
71491 **
71492 ** Reposition cursor P1 so that it points to the smallest entry that
71493 ** is greater than the key value. If there are no records greater than
71494 ** the key and P2 is not zero, then jump to P2.
71495 **
71496 ** This opcode leaves the cursor configured to move in forward order,
71497 ** from the begining toward the end. In other words, the cursor is
71498 ** configured to use Next, not Prev.
71499 **
71500 ** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
71501 */
71502 /* Opcode: SeekLT P1 P2 P3 P4 *
71503 ** Synopsis: key=r[P3@P4]
71504 **
71505 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71506 ** use the value in register P3 as a key. If cursor P1 refers
71507 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71230,14 +71508,18 @@
71508 ** that are used as an unpacked index key.
71509 **
71510 ** Reposition cursor P1 so that it points to the largest entry that
71511 ** is less than the key value. If there are no records less than
71512 ** the key and P2 is not zero, then jump to P2.
71513 **
71514 ** This opcode leaves the cursor configured to move in reverse order,
71515 ** from the end toward the beginning. In other words, the cursor is
71516 ** configured to use Prev, not Next.
71517 **
71518 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
71519 */
71520 /* Opcode: SeekLE P1 P2 P3 P4 *
71521 ** Synopsis: key=r[P3@P4]
71522 **
71523 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
71524 ** use the value in register P3 as a key. If cursor P1 refers
71525 ** to an SQL index, then P3 is the first in an array of P4 registers
@@ -71244,10 +71526,14 @@
71526 ** that are used as an unpacked index key.
71527 **
71528 ** Reposition cursor P1 so that it points to the largest entry that
71529 ** is less than or equal to the key value. If there are no records
71530 ** less than or equal to the key and P2 is not zero, then jump to P2.
71531 **
71532 ** This opcode leaves the cursor configured to move in reverse order,
71533 ** from the end toward the beginning. In other words, the cursor is
71534 ** configured to use Prev, not Next.
71535 **
71536 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
71537 */
71538 case OP_SeekLT: /* jump, in3 */
71539 case OP_SeekLE: /* jump, in3 */
@@ -71270,16 +71556,19 @@
71556 assert( OP_SeekGT == OP_SeekLT+3 );
71557 assert( pC->isOrdered );
71558 assert( pC->pCursor!=0 );
71559 oc = pOp->opcode;
71560 pC->nullRow = 0;
71561 #ifdef SQLITE_DEBUG
71562 pC->seekOp = pOp->opcode;
71563 #endif
71564 if( pC->isTable ){
71565 /* The input value in P3 might be of any type: integer, real, string,
71566 ** blob, or NULL. But it needs to be an integer before we can do
71567 ** the seek, so covert it. */
71568 pIn3 = &aMem[pOp->p3];
71569 ApplyNumericAffinity(pIn3);
71570 iKey = sqlite3VdbeIntValue(pIn3);
71571 pC->rowidIsValid = 0;
71572
71573 /* If the P3 value could not be converted into an integer without
71574 ** loss of information, then special processing is required... */
@@ -71424,10 +71713,14 @@
71713 ** record.
71714 **
71715 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
71716 ** is a prefix of any entry in P1 then a jump is made to P2 and
71717 ** P1 is left pointing at the matching entry.
71718 **
71719 ** This operation leaves the cursor in a state where it cannot be
71720 ** advanced in either direction. In other words, the Next and Prev
71721 ** opcodes do not work after this operation.
71722 **
71723 ** See also: NotFound, NoConflict, NotExists. SeekGe
71724 */
71725 /* Opcode: NotFound P1 P2 P3 P4 *
71726 ** Synopsis: key=r[P3@P4]
@@ -71439,10 +71732,14 @@
71732 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
71733 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
71734 ** does contain an entry whose prefix matches the P3/P4 record then control
71735 ** falls through to the next instruction and P1 is left pointing at the
71736 ** matching entry.
71737 **
71738 ** This operation leaves the cursor in a state where it cannot be
71739 ** advanced in either direction. In other words, the Next and Prev
71740 ** opcodes do not work after this operation.
71741 **
71742 ** See also: Found, NotExists, NoConflict
71743 */
71744 /* Opcode: NoConflict P1 P2 P3 P4 *
71745 ** Synopsis: key=r[P3@P4]
@@ -71458,10 +71755,14 @@
71755 ** immediately to P2. If there is a match, fall through and leave the P1
71756 ** cursor pointing to the matching row.
71757 **
71758 ** This opcode is similar to OP_NotFound with the exceptions that the
71759 ** branch is always taken if any part of the search key input is NULL.
71760 **
71761 ** This operation leaves the cursor in a state where it cannot be
71762 ** advanced in either direction. In other words, the Next and Prev
71763 ** opcodes do not work after this operation.
71764 **
71765 ** See also: NotFound, Found, NotExists
71766 */
71767 case OP_NoConflict: /* jump, in3 */
71768 case OP_NotFound: /* jump, in3 */
@@ -71481,10 +71782,13 @@
71782
71783 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71784 assert( pOp->p4type==P4_INT32 );
71785 pC = p->apCsr[pOp->p1];
71786 assert( pC!=0 );
71787 #ifdef SQLITE_DEBUG
71788 pC->seekOp = 0;
71789 #endif
71790 pIn3 = &aMem[pOp->p3];
71791 assert( pC->pCursor!=0 );
71792 assert( pC->isTable==0 );
71793 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
71794 if( pOp->p4.i>0 ){
@@ -71551,10 +71855,14 @@
71855 ** with rowid P3 then leave the cursor pointing at that record and fall
71856 ** through to the next instruction.
71857 **
71858 ** The OP_NotFound opcode performs the same operation on index btrees
71859 ** (with arbitrary multi-value keys).
71860 **
71861 ** This opcode leaves the cursor in a state where it cannot be advanced
71862 ** in either direction. In other words, the Next and Prev opcodes will
71863 ** not work following this opcode.
71864 **
71865 ** See also: Found, NotFound, NoConflict
71866 */
71867 case OP_NotExists: { /* jump, in3 */
71868 VdbeCursor *pC;
@@ -71565,10 +71873,13 @@
71873 pIn3 = &aMem[pOp->p3];
71874 assert( pIn3->flags & MEM_Int );
71875 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71876 pC = p->apCsr[pOp->p1];
71877 assert( pC!=0 );
71878 #ifdef SQLITE_DEBUG
71879 pC->seekOp = 0;
71880 #endif
71881 assert( pC->isTable );
71882 assert( pC->pseudoTableReg==0 );
71883 pCrsr = pC->pCursor;
71884 assert( pCrsr!=0 );
71885 res = 0;
@@ -71927,16 +72238,16 @@
72238 p->nChange = 0;
72239 break;
72240 }
72241
72242 /* Opcode: SorterCompare P1 P2 P3 P4
72243 ** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
72244 **
72245 ** P1 is a sorter cursor. This instruction compares a prefix of the
72246 ** the record blob in register P3 against a prefix of the entry that
72247 ** the sorter cursor currently points to. Only the first P4 fields
72248 ** of r[P3] and the sorter record are compared.
72249 **
72250 ** If either P3 or the sorter contains a NULL in one of their significant
72251 ** fields (not counting the P4 fields at the end which are ignored) then
72252 ** the comparison is assumed to be equal.
72253 **
@@ -71944,18 +72255,18 @@
72255 ** each other. Jump to P2 if they are different.
72256 */
72257 case OP_SorterCompare: {
72258 VdbeCursor *pC;
72259 int res;
72260 int nKeyCol;
72261
72262 pC = p->apCsr[pOp->p1];
72263 assert( isSorter(pC) );
72264 assert( pOp->p4type==P4_INT32 );
72265 pIn3 = &aMem[pOp->p3];
72266 nKeyCol = pOp->p4.i;
72267 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
72268 VdbeBranchTaken(res!=0,2);
72269 if( res ){
72270 pc = pOp->p2-1;
72271 }
72272 break;
@@ -72131,15 +72442,19 @@
72442 break;
72443 }
72444
72445 /* Opcode: Last P1 P2 * * *
72446 **
72447 ** The next use of the Rowid or Column or Prev instruction for P1
72448 ** will refer to the last entry in the database table or index.
72449 ** If the table or index is empty and P2>0, then jump immediately to P2.
72450 ** If P2 is 0 or if the table or index is not empty, fall through
72451 ** to the following instruction.
72452 **
72453 ** This opcode leaves the cursor configured to move in reverse order,
72454 ** from the end toward the beginning. In other words, the cursor is
72455 ** configured to use Prev, not Next.
72456 */
72457 case OP_Last: { /* jump */
72458 VdbeCursor *pC;
72459 BtCursor *pCrsr;
72460 int res;
@@ -72153,10 +72468,13 @@
72468 rc = sqlite3BtreeLast(pCrsr, &res);
72469 pC->nullRow = (u8)res;
72470 pC->deferredMoveto = 0;
72471 pC->rowidIsValid = 0;
72472 pC->cacheStatus = CACHE_STALE;
72473 #ifdef SQLITE_DEBUG
72474 pC->seekOp = OP_Last;
72475 #endif
72476 if( pOp->p2>0 ){
72477 VdbeBranchTaken(res!=0,2);
72478 if( res ) pc = pOp->p2 - 1;
72479 }
72480 break;
@@ -72189,10 +72507,14 @@
72507 ** The next use of the Rowid or Column or Next instruction for P1
72508 ** will refer to the first entry in the database table or index.
72509 ** If the table or index is empty and P2>0, then jump immediately to P2.
72510 ** If P2 is 0 or if the table or index is not empty, fall through
72511 ** to the following instruction.
72512 **
72513 ** This opcode leaves the cursor configured to move in forward order,
72514 ** from the begining toward the end. In other words, the cursor is
72515 ** configured to use Next, not Prev.
72516 */
72517 case OP_Rewind: { /* jump */
72518 VdbeCursor *pC;
72519 BtCursor *pCrsr;
72520 int res;
@@ -72200,10 +72522,13 @@
72522 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
72523 pC = p->apCsr[pOp->p1];
72524 assert( pC!=0 );
72525 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
72526 res = 1;
72527 #ifdef SQLITE_DEBUG
72528 pC->seekOp = OP_Rewind;
72529 #endif
72530 if( isSorter(pC) ){
72531 rc = sqlite3VdbeSorterRewind(db, pC, &res);
72532 }else{
72533 pCrsr = pC->pCursor;
72534 assert( pCrsr );
@@ -72225,10 +72550,14 @@
72550 **
72551 ** Advance cursor P1 so that it points to the next key/data pair in its
72552 ** table or index. If there are no more key/value pairs then fall through
72553 ** to the following instruction. But if the cursor advance was successful,
72554 ** jump immediately to P2.
72555 **
72556 ** The Next opcode is only valid following an SeekGT, SeekGE, or
72557 ** OP_Rewind opcode used to position the cursor. Next is not allowed
72558 ** to follow SeekLT, SeekLE, or OP_Last.
72559 **
72560 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
72561 ** been opened prior to this opcode or the program will segfault.
72562 **
72563 ** The P3 value is a hint to the btree implementation. If P3==1, that
@@ -72244,20 +72573,25 @@
72573 **
72574 ** See also: Prev, NextIfOpen
72575 */
72576 /* Opcode: NextIfOpen P1 P2 P3 P4 P5
72577 **
72578 ** This opcode works just like Next except that if cursor P1 is not
72579 ** open it behaves a no-op.
72580 */
72581 /* Opcode: Prev P1 P2 P3 P4 P5
72582 **
72583 ** Back up cursor P1 so that it points to the previous key/data pair in its
72584 ** table or index. If there is no previous key/value pairs then fall through
72585 ** to the following instruction. But if the cursor backup was successful,
72586 ** jump immediately to P2.
72587 **
72588 **
72589 ** The Prev opcode is only valid following an SeekLT, SeekLE, or
72590 ** OP_Last opcode used to position the cursor. Prev is not allowed
72591 ** to follow SeekGT, SeekGE, or OP_Rewind.
72592 **
72593 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
72594 ** not open then the behavior is undefined.
72595 **
72596 ** The P3 value is a hint to the btree implementation. If P3==1, that
72597 ** means P1 is an SQL index and that this instruction could have been
@@ -72270,11 +72604,11 @@
72604 ** If P5 is positive and the jump is taken, then event counter
72605 ** number P5-1 in the prepared statement is incremented.
72606 */
72607 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
72608 **
72609 ** This opcode works just like Prev except that if cursor P1 is not
72610 ** open it behaves a no-op.
72611 */
72612 case OP_SorterNext: { /* jump */
72613 VdbeCursor *pC;
72614 int res;
@@ -72301,10 +72635,20 @@
72635 testcase( res==1 );
72636 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
72637 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
72638 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
72639 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
72640
72641 /* The Next opcode is only used after SeekGT, SeekGE, and Rewind.
72642 ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
72643 assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen
72644 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
72645 || pC->seekOp==OP_Rewind );
72646 assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen
72647 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
72648 || pC->seekOp==OP_Last );
72649
72650 rc = pOp->p4.xAdvance(pC->pCursor, &res);
72651 next_tail:
72652 pC->cacheStatus = CACHE_STALE;
72653 VdbeBranchTaken(res==0,2);
72654 if( res==0 ){
@@ -72781,11 +73125,12 @@
73125
73126 /* Opcode: DropTable P1 * * P4 *
73127 **
73128 ** Remove the internal (in-memory) data structures that describe
73129 ** the table named P4 in database P1. This is called after a table
73130 ** is dropped from disk (using the Destroy opcode) in order to keep
73131 ** the internal representation of the
73132 ** schema consistent with what is on disk.
73133 */
73134 case OP_DropTable: {
73135 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
73136 break;
@@ -72793,11 +73138,12 @@
73138
73139 /* Opcode: DropIndex P1 * * P4 *
73140 **
73141 ** Remove the internal (in-memory) data structures that describe
73142 ** the index named P4 in database P1. This is called after an index
73143 ** is dropped from disk (using the Destroy opcode)
73144 ** in order to keep the internal representation of the
73145 ** schema consistent with what is on disk.
73146 */
73147 case OP_DropIndex: {
73148 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
73149 break;
@@ -72805,11 +73151,12 @@
73151
73152 /* Opcode: DropTrigger P1 * * P4 *
73153 **
73154 ** Remove the internal (in-memory) data structures that describe
73155 ** the trigger named P4 in database P1. This is called after a trigger
73156 ** is dropped from disk (using the Destroy opcode) in order to keep
73157 ** the internal representation of the
73158 ** schema consistent with what is on disk.
73159 */
73160 case OP_DropTrigger: {
73161 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
73162 break;
@@ -75011,11 +75358,11 @@
75358 ** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace
75359 ** has been allocated and contains an unpacked record that is used as key2.
75360 */
75361 static void vdbeSorterCompare(
75362 const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */
75363 int nKeyCol, /* Num of columns. 0 means "all" */
75364 const void *pKey1, int nKey1, /* Left side of comparison */
75365 const void *pKey2, int nKey2, /* Right side of comparison */
75366 int *pRes /* OUT: Result of comparison */
75367 ){
75368 KeyInfo *pKeyInfo = pCsr->pKeyInfo;
@@ -75025,14 +75372,13 @@
75372
75373 if( pKey2 ){
75374 sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2);
75375 }
75376
75377 if( nKeyCol ){
75378 r2->nField = nKeyCol;
75379 for(i=0; i<nKeyCol; i++){
 
75380 if( r2->aMem[i].flags & MEM_Null ){
75381 *pRes = -1;
75382 return;
75383 }
75384 }
@@ -75710,18 +76056,18 @@
76056 ** key.
76057 */
76058 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(
76059 const VdbeCursor *pCsr, /* Sorter cursor */
76060 Mem *pVal, /* Value to compare to current sorter key */
76061 int nKeyCol, /* Only compare this many fields */
76062 int *pRes /* OUT: Result of comparison */
76063 ){
76064 VdbeSorter *pSorter = pCsr->pSorter;
76065 void *pKey; int nKey; /* Sorter key to compare pVal with */
76066
76067 pKey = vdbeSorterRowkey(pSorter, &nKey);
76068 vdbeSorterCompare(pCsr, nKeyCol, pVal->z, pVal->n, pKey, nKey, pRes);
76069 return SQLITE_OK;
76070 }
76071
76072 /************** End of vdbesort.c ********************************************/
76073 /************** Begin file journal.c *****************************************/
@@ -79474,11 +79820,11 @@
79820 }
79821 }
79822 }
79823
79824 if( eType==0 ){
79825 /* Could not find an existing table or index to use as the RHS b-tree.
79826 ** We will have to generate an ephemeral table to do the job.
79827 */
79828 u32 savedNQueryLoop = pParse->nQueryLoop;
79829 int rMayHaveNull = 0;
79830 eType = IN_INDEX_EPH;
@@ -79604,24 +79950,27 @@
79950 /* Case 1: expr IN (SELECT ...)
79951 **
79952 ** Generate code to write the results of the select into the temporary
79953 ** table allocated and opened above.
79954 */
79955 Select *pSelect = pExpr->x.pSelect;
79956 SelectDest dest;
79957 ExprList *pEList;
79958
79959 assert( !isRowid );
79960 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
79961 dest.affSdst = (u8)affinity;
79962 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
79963 pSelect->iLimit = 0;
79964 testcase( pSelect->selFlags & SF_Distinct );
79965 pSelect->selFlags &= ~SF_Distinct;
79966 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
79967 if( sqlite3Select(pParse, pSelect, &dest) ){
79968 sqlite3KeyInfoUnref(pKeyInfo);
79969 return 0;
79970 }
79971 pEList = pSelect->pEList;
79972 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
79973 assert( pEList!=0 );
79974 assert( pEList->nExpr>0 );
79975 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
79976 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
@@ -83315,19 +83664,24 @@
83664 }
83665
83666 /*
83667 ** Implementation of the stat_init(N,K,C) SQL function. The three parameters
83668 ** are:
83669 ** N: The number of columns in the index including the rowid/pk (note 1)
83670 ** K: The number of columns in the index excluding the rowid/pk.
83671 ** C: The number of rows in the index (note 2)
83672 **
83673 ** Note 1: In the special case of the covering index that implements a
83674 ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
83675 ** total number of columns in the table.
83676 **
83677 ** Note 2: C is only used for STAT3 and STAT4.
83678 **
83679 ** For indexes on ordinary rowid tables, N==K+1. But for indexes on
83680 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
83681 ** PRIMARY KEY of the table. The covering index that implements the
83682 ** original WITHOUT ROWID table as N==K as a special case.
83683 **
83684 ** This routine allocates the Stat4Accum object in heap memory. The return
83685 ** value is a pointer to the the Stat4Accum object encoded as a blob (i.e.
83686 ** the size of the blob is sizeof(void*) bytes).
83687 */
@@ -83633,11 +83987,14 @@
83987 ** P Pointer to the Stat4Accum object created by stat_init()
83988 ** C Index of left-most column to differ from previous row
83989 ** R Rowid for the current row. Might be a key record for
83990 ** WITHOUT ROWID tables.
83991 **
83992 ** This SQL function always returns NULL. It's purpose it to accumulate
83993 ** statistical data and/or samples in the Stat4Accum object about the
83994 ** index being analyzed. The stat_get() SQL function will later be used to
83995 ** extract relevant information for constructing the sqlite_statN tables.
83996 **
83997 ** The R parameter is only used for STAT3 and STAT4
83998 */
83999 static void statPush(
84000 sqlite3_context *context,
@@ -83727,11 +84084,14 @@
84084 #define STAT_GET_NLT 3 /* "nlt" column of stat[34] entry */
84085 #define STAT_GET_NDLT 4 /* "ndlt" column of stat[34] entry */
84086
84087 /*
84088 ** Implementation of the stat_get(P,J) SQL function. This routine is
84089 ** used to query statistical information that has been gathered into
84090 ** the Stat4Accum object by prior calls to stat_push(). The P parameter
84091 ** is a BLOB which is decoded into a pointer to the Stat4Accum objects.
84092 ** The content to returned is determined by the parameter J
84093 ** which is one of the STAT_GET_xxxx values defined above.
84094 **
84095 ** If neither STAT3 nor STAT4 are enabled, then J is always
84096 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
84097 ** a one-parameter function, stat_get(P), that always returns the
@@ -83946,28 +84306,27 @@
84306 pParse->nTab = MAX(pParse->nTab, iTab);
84307 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
84308 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
84309
84310 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
84311 int nCol; /* Number of columns in pIdx. "N" */
 
84312 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
 
84313 int addrNextRow; /* Address of "next_row:" */
84314 const char *zIdxName; /* Name of the index */
84315 int nColTest; /* Number of columns to test for changes */
84316
84317 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
84318 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
84319 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
84320 nCol = pIdx->nKeyCol;
84321 zIdxName = pTab->zName;
84322 nColTest = nCol - 1;
84323 }else{
84324 nCol = pIdx->nColumn;
84325 zIdxName = pIdx->zName;
84326 nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
84327 }
 
 
84328
84329 /* Populate the register containing the index name. */
84330 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
84331 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
84332
@@ -83992,11 +84351,11 @@
84351 ** regPrev(0) = idx(0)
84352 ** chng_addr_1:
84353 ** regPrev(1) = idx(1)
84354 ** ...
84355 **
84356 ** endDistinctTest:
84357 ** regRowid = idx(rowid)
84358 ** stat_push(P, regChng, regRowid)
84359 ** Next csr
84360 ** if !eof(csr) goto next_row;
84361 **
@@ -84005,24 +84364,27 @@
84364
84365 /* Make sure there are enough memory cells allocated to accommodate
84366 ** the regPrev array and a trailing rowid (the rowid slot is required
84367 ** when building a record to insert into the sample column of
84368 ** the sqlite_stat4 table. */
84369 pParse->nMem = MAX(pParse->nMem, regPrev+nColTest);
84370
84371 /* Open a read-only cursor on the index being analyzed. */
84372 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
84373 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
84374 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
84375 VdbeComment((v, "%s", pIdx->zName));
84376
84377 /* Invoke the stat_init() function. The arguments are:
84378 **
84379 ** (1) the number of columns in the index including the rowid
84380 ** (or for a WITHOUT ROWID table, the number of PK columns),
84381 ** (2) the number of columns in the key without the rowid/pk
84382 ** (3) the number of rows in the index,
84383 **
84384 **
84385 ** The third argument is only used for STAT3 and STAT4
84386 */
84387 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
84388 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3);
84389 #endif
84390 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1);
@@ -84040,56 +84402,73 @@
84402 **
84403 */
84404 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
84405 VdbeCoverage(v);
84406 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
 
 
 
 
 
 
 
 
 
 
 
 
84407 addrNextRow = sqlite3VdbeCurrentAddr(v);
84408
84409 if( nColTest>0 ){
84410 int endDistinctTest = sqlite3VdbeMakeLabel(v);
84411 int *aGotoChng; /* Array of jump instruction addresses */
84412 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
84413 if( aGotoChng==0 ) continue;
84414
84415 /*
84416 ** next_row:
84417 ** regChng = 0
84418 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
84419 ** regChng = 1
84420 ** if( idx(1) != regPrev(1) ) goto chng_addr_1
84421 ** ...
84422 ** regChng = N
84423 ** goto endDistinctTest
84424 */
84425 sqlite3VdbeAddOp0(v, OP_Goto);
84426 addrNextRow = sqlite3VdbeCurrentAddr(v);
84427 if( nColTest==1 && pIdx->nKeyCol==1 && pIdx->onError!=OE_None ){
84428 /* For a single-column UNIQUE index, once we have found a non-NULL
84429 ** row, we know that all the rest will be distinct, so skip
84430 ** subsequent distinctness tests. */
84431 sqlite3VdbeAddOp2(v, OP_NotNull, regPrev, endDistinctTest);
84432 VdbeCoverage(v);
84433 }
84434 for(i=0; i<nColTest; i++){
84435 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
84436 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
84437 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
84438 aGotoChng[i] =
84439 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
84440 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
84441 VdbeCoverage(v);
84442 }
84443 sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
84444 sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
84445
84446
84447 /*
84448 ** chng_addr_0:
84449 ** regPrev(0) = idx(0)
84450 ** chng_addr_1:
84451 ** regPrev(1) = idx(1)
84452 ** ...
84453 */
84454 sqlite3VdbeJumpHere(v, addrNextRow-1);
84455 for(i=0; i<nColTest; i++){
84456 sqlite3VdbeJumpHere(v, aGotoChng[i]);
84457 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
84458 }
84459 sqlite3VdbeResolveLabel(v, endDistinctTest);
84460 sqlite3DbFree(db, aGotoChng);
84461 }
84462
84463 /*
84464 ** chng_addr_N:
84465 ** regRowid = idx(rowid) // STAT34 only
84466 ** stat_push(P, regChng, regRowid) // 3rd parameter STAT34 only
84467 ** Next csr
84468 ** if !eof(csr) goto next_row;
84469 */
 
84470 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
84471 assert( regRowid==(regStat4+2) );
84472 if( HasRowid(pTab) ){
84473 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
84474 }else{
@@ -84163,11 +84542,10 @@
84542 }
84543 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
84544
84545 /* End of analysis */
84546 sqlite3VdbeJumpHere(v, addrRewind);
 
84547 }
84548
84549
84550 /* Create a single sqlite_stat1 entry containing NULL as the index
84551 ** name and the row count as the content.
@@ -88308,11 +88686,11 @@
88686 if( pIndex->onError!=OE_None && pKey!=0 ){
88687 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
88688 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
88689 addr2 = sqlite3VdbeCurrentAddr(v);
88690 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
88691 pIndex->nKeyCol); VdbeCoverage(v);
88692 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
88693 }else{
88694 addr2 = sqlite3VdbeCurrentAddr(v);
88695 }
88696 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
@@ -98186,11 +98564,11 @@
98564 ** Note that the values returned are one less that the values that
98565 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
98566 ** to support legacy SQL code. The safety level used to be boolean
98567 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
98568 */
98569 static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt){
98570 /* 123456789 123456789 */
98571 static const char zText[] = "onoffalseyestruefull";
98572 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
98573 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
98574 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
@@ -98208,11 +98586,11 @@
98586 }
98587
98588 /*
98589 ** Interpret the given string as a boolean value.
98590 */
98591 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, u8 dflt){
98592 return getSafetyLevel(z,1,dflt)!=0;
98593 }
98594
98595 /* The sqlite3GetBoolean() function is used by other modules but the
98596 ** remainder of this file is specific to PRAGMA processing. So omit
@@ -112398,11 +112776,12 @@
112776 int nEq = pLoop->u.btree.nEq;
112777 sqlite3 *db = pParse->db;
112778 int nLower = -1;
112779 int nUpper = p->nSample+1;
112780 int rc = SQLITE_OK;
112781 int iCol = p->aiColumn[nEq];
112782 u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
112783 CollSeq *pColl;
112784
112785 sqlite3_value *p1 = 0; /* Value extracted from pLower */
112786 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
112787 sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -122593,11 +122972,11 @@
122972
122973 /*
122974 ** Return a static string containing the name corresponding to the error code
122975 ** specified in the argument.
122976 */
122977 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
122978 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
122979 const char *zName = 0;
122980 int i, origRc = rc;
122981 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
122982 switch( rc ){
@@ -124897,10 +125276,20 @@
125276 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
125277 sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
125278 #endif
125279 break;
125280 }
125281
125282 /* sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
125283 **
125284 ** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
125285 ** not.
125286 */
125287 case SQLITE_TESTCTRL_ISINIT: {
125288 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
125289 break;
125290 }
125291
125292 }
125293 va_end(ap);
125294 #endif /* SQLITE_OMIT_BUILTIN_TEST */
125295 return rc;
@@ -145542,13 +145931,17 @@
145931 int rc = SQLITE_OK;
145932 int iCell = 0;
145933
145934 rtreeReference(pRtree);
145935
145936 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
145937 freeCursorConstraints(pCsr);
145938 sqlite3_free(pCsr->aPoint);
145939 memset(pCsr, 0, sizeof(RtreeCursor));
145940 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
145941
145942 pCsr->iStrategy = idxNum;
 
145943 if( idxNum==1 ){
145944 /* Special case - lookup by rowid. */
145945 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
145946 RtreeSearchPoint *p; /* Search point for the the leaf */
145947 i64 iRowid = sqlite3_value_int64(argv[0]);
145948
+10 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.6"
111111
#define SQLITE_VERSION_NUMBER 3008006
112
-#define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
112
+#define SQLITE_SOURCE_ID "2014-07-31 18:54:01 1e5489faff093d6a8e538061e45532f9050e9459"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -5878,14 +5878,16 @@
58785878
** <ul>
58795879
** <li> SQLITE_MUTEX_FAST
58805880
** <li> SQLITE_MUTEX_RECURSIVE
58815881
** <li> SQLITE_MUTEX_STATIC_MASTER
58825882
** <li> SQLITE_MUTEX_STATIC_MEM
5883
-** <li> SQLITE_MUTEX_STATIC_MEM2
5883
+** <li> SQLITE_MUTEX_STATIC_OPEN
58845884
** <li> SQLITE_MUTEX_STATIC_PRNG
58855885
** <li> SQLITE_MUTEX_STATIC_LRU
5886
-** <li> SQLITE_MUTEX_STATIC_LRU2
5886
+** <li> SQLITE_MUTEX_STATIC_PMEM
5887
+** <li> SQLITE_MUTEX_STATIC_APP1
5888
+** <li> SQLITE_MUTEX_STATIC_APP2
58875889
** </ul>)^
58885890
**
58895891
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
58905892
** cause sqlite3_mutex_alloc() to create
58915893
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6085,10 +6087,13 @@
60856087
#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
60866088
#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
60876089
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
60886090
#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
60896091
#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6092
+#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6093
+#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6094
+#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
60906095
60916096
/*
60926097
** CAPI3REF: Retrieve the mutex for a database connection
60936098
**
60946099
** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6180,11 +6185,12 @@
61806185
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
61816186
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
61826187
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
61836188
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
61846189
#define SQLITE_TESTCTRL_BYTEORDER 22
6185
-#define SQLITE_TESTCTRL_LAST 22
6190
+#define SQLITE_TESTCTRL_ISINIT 23
6191
+#define SQLITE_TESTCTRL_LAST 23
61866192
61876193
/*
61886194
** CAPI3REF: SQLite Runtime Status
61896195
**
61906196
** ^This interface is used to retrieve runtime status information
61916197
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.6"
111 #define SQLITE_VERSION_NUMBER 3008006
112 #define SQLITE_SOURCE_ID "2014-07-24 12:39:59 fb1048cb2b613a0dbfe625a5df05e9dcd736a433"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -5878,14 +5878,16 @@
5878 ** <ul>
5879 ** <li> SQLITE_MUTEX_FAST
5880 ** <li> SQLITE_MUTEX_RECURSIVE
5881 ** <li> SQLITE_MUTEX_STATIC_MASTER
5882 ** <li> SQLITE_MUTEX_STATIC_MEM
5883 ** <li> SQLITE_MUTEX_STATIC_MEM2
5884 ** <li> SQLITE_MUTEX_STATIC_PRNG
5885 ** <li> SQLITE_MUTEX_STATIC_LRU
5886 ** <li> SQLITE_MUTEX_STATIC_LRU2
 
 
5887 ** </ul>)^
5888 **
5889 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5890 ** cause sqlite3_mutex_alloc() to create
5891 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6085,10 +6087,13 @@
6085 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
6086 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
6087 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
6088 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6089 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
 
 
 
6090
6091 /*
6092 ** CAPI3REF: Retrieve the mutex for a database connection
6093 **
6094 ** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6180,11 +6185,12 @@
6180 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6181 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6182 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6183 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6184 #define SQLITE_TESTCTRL_BYTEORDER 22
6185 #define SQLITE_TESTCTRL_LAST 22
 
6186
6187 /*
6188 ** CAPI3REF: SQLite Runtime Status
6189 **
6190 ** ^This interface is used to retrieve runtime status information
6191
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.6"
111 #define SQLITE_VERSION_NUMBER 3008006
112 #define SQLITE_SOURCE_ID "2014-07-31 18:54:01 1e5489faff093d6a8e538061e45532f9050e9459"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -5878,14 +5878,16 @@
5878 ** <ul>
5879 ** <li> SQLITE_MUTEX_FAST
5880 ** <li> SQLITE_MUTEX_RECURSIVE
5881 ** <li> SQLITE_MUTEX_STATIC_MASTER
5882 ** <li> SQLITE_MUTEX_STATIC_MEM
5883 ** <li> SQLITE_MUTEX_STATIC_OPEN
5884 ** <li> SQLITE_MUTEX_STATIC_PRNG
5885 ** <li> SQLITE_MUTEX_STATIC_LRU
5886 ** <li> SQLITE_MUTEX_STATIC_PMEM
5887 ** <li> SQLITE_MUTEX_STATIC_APP1
5888 ** <li> SQLITE_MUTEX_STATIC_APP2
5889 ** </ul>)^
5890 **
5891 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5892 ** cause sqlite3_mutex_alloc() to create
5893 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
@@ -6085,10 +6087,13 @@
6087 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
6088 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
6089 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
6090 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6091 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6092 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6093 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6094 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6095
6096 /*
6097 ** CAPI3REF: Retrieve the mutex for a database connection
6098 **
6099 ** ^This interface returns a pointer the [sqlite3_mutex] object that
@@ -6180,11 +6185,12 @@
6185 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6186 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6187 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6188 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6189 #define SQLITE_TESTCTRL_BYTEORDER 22
6190 #define SQLITE_TESTCTRL_ISINIT 23
6191 #define SQLITE_TESTCTRL_LAST 23
6192
6193 /*
6194 ** CAPI3REF: SQLite Runtime Status
6195 **
6196 ** ^This interface is used to retrieve runtime status information
6197

Keyboard Shortcuts

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