Fossil SCM
Upgrade the built-in SQLite to the latest 3.8.6 alpha from upstream.
Commit
5ce85eb6f84350dce5eeed42972e14d73e092983
Parent
74ac0c925a98ee6…
2 files changed
+624
-231
+10
-4
+624
-231
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -222,11 +222,11 @@ | ||
| 222 | 222 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 223 | 223 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 224 | 224 | */ |
| 225 | 225 | #define SQLITE_VERSION "3.8.6" |
| 226 | 226 | #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" | |
| 228 | 228 | |
| 229 | 229 | /* |
| 230 | 230 | ** CAPI3REF: Run-Time Library Version Numbers |
| 231 | 231 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 232 | 232 | ** |
| @@ -5993,14 +5993,16 @@ | ||
| 5993 | 5993 | ** <ul> |
| 5994 | 5994 | ** <li> SQLITE_MUTEX_FAST |
| 5995 | 5995 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 5996 | 5996 | ** <li> SQLITE_MUTEX_STATIC_MASTER |
| 5997 | 5997 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 5998 | -** <li> SQLITE_MUTEX_STATIC_MEM2 | |
| 5998 | +** <li> SQLITE_MUTEX_STATIC_OPEN | |
| 5999 | 5999 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 6000 | 6000 | ** <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 | |
| 6002 | 6004 | ** </ul>)^ |
| 6003 | 6005 | ** |
| 6004 | 6006 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6005 | 6007 | ** cause sqlite3_mutex_alloc() to create |
| 6006 | 6008 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| @@ -6200,10 +6202,13 @@ | ||
| 6200 | 6202 | #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
| 6201 | 6203 | #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ |
| 6202 | 6204 | #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
| 6203 | 6205 | #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ |
| 6204 | 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 */ | |
| 6205 | 6210 | |
| 6206 | 6211 | /* |
| 6207 | 6212 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6208 | 6213 | ** |
| 6209 | 6214 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| @@ -6295,11 +6300,12 @@ | ||
| 6295 | 6300 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 6296 | 6301 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 |
| 6297 | 6302 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 6298 | 6303 | #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
| 6299 | 6304 | #define SQLITE_TESTCTRL_BYTEORDER 22 |
| 6300 | -#define SQLITE_TESTCTRL_LAST 22 | |
| 6305 | +#define SQLITE_TESTCTRL_ISINIT 23 | |
| 6306 | +#define SQLITE_TESTCTRL_LAST 23 | |
| 6301 | 6307 | |
| 6302 | 6308 | /* |
| 6303 | 6309 | ** CAPI3REF: SQLite Runtime Status |
| 6304 | 6310 | ** |
| 6305 | 6311 | ** ^This interface is used to retrieve runtime status information |
| @@ -9325,14 +9331,14 @@ | ||
| 9325 | 9331 | #define OP_OpenAutoindex 55 /* synopsis: nColumn=P2 */ |
| 9326 | 9332 | #define OP_OpenEphemeral 56 /* synopsis: nColumn=P2 */ |
| 9327 | 9333 | #define OP_SorterOpen 57 |
| 9328 | 9334 | #define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */ |
| 9329 | 9335 | #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] */ | |
| 9334 | 9340 | #define OP_Seek 64 /* synopsis: intkey=r[P2] */ |
| 9335 | 9341 | #define OP_NoConflict 65 /* synopsis: key=r[P3@P4] */ |
| 9336 | 9342 | #define OP_NotFound 66 /* synopsis: key=r[P3@P4] */ |
| 9337 | 9343 | #define OP_Found 67 /* synopsis: key=r[P3@P4] */ |
| 9338 | 9344 | #define OP_NotExists 68 /* synopsis: intkey=r[P3] */ |
| @@ -9360,11 +9366,11 @@ | ||
| 9360 | 9366 | #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 9361 | 9367 | #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 9362 | 9368 | #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 9363 | 9369 | #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 9364 | 9370 | #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 */ | |
| 9366 | 9372 | #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 9367 | 9373 | #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 9368 | 9374 | #define OP_SorterData 98 /* synopsis: r[P2]=data */ |
| 9369 | 9375 | #define OP_RowKey 99 /* synopsis: r[P2]=key */ |
| 9370 | 9376 | #define OP_RowData 100 /* synopsis: r[P2]=data */ |
| @@ -12852,11 +12858,11 @@ | ||
| 12852 | 12858 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| 12853 | 12859 | SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*); |
| 12854 | 12860 | #else |
| 12855 | 12861 | # define sqlite3FileSuffix3(X,Y) |
| 12856 | 12862 | #endif |
| 12857 | -SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,int); | |
| 12863 | +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,u8); | |
| 12858 | 12864 | |
| 12859 | 12865 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 12860 | 12866 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 12861 | 12867 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 12862 | 12868 | void(*)(void*)); |
| @@ -13927,10 +13933,13 @@ | ||
| 13927 | 13933 | KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ |
| 13928 | 13934 | int seekResult; /* Result of previous sqlite3BtreeMoveto() */ |
| 13929 | 13935 | int pseudoTableReg; /* Register holding pseudotable content. */ |
| 13930 | 13936 | i16 nField; /* Number of fields in the header */ |
| 13931 | 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 | |
| 13932 | 13941 | i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ |
| 13933 | 13942 | u8 nullRow; /* True if pointing to a row with no data */ |
| 13934 | 13943 | u8 rowidIsValid; /* True if lastRowid is valid */ |
| 13935 | 13944 | u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 13936 | 13945 | Bool isEphemeral:1; /* True for an ephemeral table */ |
| @@ -18448,11 +18457,11 @@ | ||
| 18448 | 18457 | /* |
| 18449 | 18458 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 18450 | 18459 | */ |
| 18451 | 18460 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 18452 | 18461 | #ifndef SQLITE_OMIT_AUTOINIT |
| 18453 | - if( sqlite3_initialize() ) return 0; | |
| 18462 | + if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; | |
| 18454 | 18463 | #endif |
| 18455 | 18464 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 18456 | 18465 | } |
| 18457 | 18466 | |
| 18458 | 18467 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| @@ -18629,11 +18638,11 @@ | ||
| 18629 | 18638 | ** The sqlite3_mutex_alloc() routine allocates a new |
| 18630 | 18639 | ** mutex and returns a pointer to it. If it returns NULL |
| 18631 | 18640 | ** that means that a mutex could not be allocated. |
| 18632 | 18641 | */ |
| 18633 | 18642 | static sqlite3_mutex *debugMutexAlloc(int id){ |
| 18634 | - static sqlite3_debug_mutex aStatic[6]; | |
| 18643 | + static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1]; | |
| 18635 | 18644 | sqlite3_debug_mutex *pNew = 0; |
| 18636 | 18645 | switch( id ){ |
| 18637 | 18646 | case SQLITE_MUTEX_FAST: |
| 18638 | 18647 | case SQLITE_MUTEX_RECURSIVE: { |
| 18639 | 18648 | pNew = sqlite3Malloc(sizeof(*pNew)); |
| @@ -18826,14 +18835,17 @@ | ||
| 18826 | 18835 | ** <ul> |
| 18827 | 18836 | ** <li> SQLITE_MUTEX_FAST |
| 18828 | 18837 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 18829 | 18838 | ** <li> SQLITE_MUTEX_STATIC_MASTER |
| 18830 | 18839 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 18831 | -** <li> SQLITE_MUTEX_STATIC_MEM2 | |
| 18840 | +** <li> SQLITE_MUTEX_STATIC_OPEN | |
| 18832 | 18841 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 18833 | 18842 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 18834 | 18843 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 18844 | +** <li> SQLITE_MUTEX_STATIC_APP1 | |
| 18845 | +** <li> SQLITE_MUTEX_STATIC_APP2 | |
| 18846 | +** <li> SQLITE_MUTEX_STATIC_APP3 | |
| 18835 | 18847 | ** </ul> |
| 18836 | 18848 | ** |
| 18837 | 18849 | ** The first two constants cause sqlite3_mutex_alloc() to create |
| 18838 | 18850 | ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 18839 | 18851 | ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. |
| @@ -18858,10 +18870,13 @@ | ||
| 18858 | 18870 | ** mutex types, the same mutex is returned on every call that has |
| 18859 | 18871 | ** the same type number. |
| 18860 | 18872 | */ |
| 18861 | 18873 | static sqlite3_mutex *pthreadMutexAlloc(int iType){ |
| 18862 | 18874 | static sqlite3_mutex staticMutexes[] = { |
| 18875 | + SQLITE3_MUTEX_INITIALIZER, | |
| 18876 | + SQLITE3_MUTEX_INITIALIZER, | |
| 18877 | + SQLITE3_MUTEX_INITIALIZER, | |
| 18863 | 18878 | SQLITE3_MUTEX_INITIALIZER, |
| 18864 | 18879 | SQLITE3_MUTEX_INITIALIZER, |
| 18865 | 18880 | SQLITE3_MUTEX_INITIALIZER, |
| 18866 | 18881 | SQLITE3_MUTEX_INITIALIZER, |
| 18867 | 18882 | SQLITE3_MUTEX_INITIALIZER, |
| @@ -19093,14 +19108,227 @@ | ||
| 19093 | 19108 | ** May you do good and not evil. |
| 19094 | 19109 | ** May you find forgiveness for yourself and forgive others. |
| 19095 | 19110 | ** May you share freely, never taking more than you give. |
| 19096 | 19111 | ** |
| 19097 | 19112 | ************************************************************************* |
| 19098 | -** This file contains the C functions that implement mutexes for win32 | |
| 19113 | +** This file contains the C functions that implement mutexes for Win32. | |
| 19099 | 19114 | */ |
| 19100 | 19115 | |
| 19101 | 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 | + | |
| 19102 | 19330 | /* |
| 19103 | 19331 | ** Include the header file for the Windows VFS. |
| 19104 | 19332 | */ |
| 19105 | 19333 | /************** Include os_win.h in the middle of mutex_w32.c ****************/ |
| 19106 | 19334 | /************** Begin file os_win.h ******************************************/ |
| @@ -19176,11 +19404,11 @@ | ||
| 19176 | 19404 | /************** Continuing where we left off in mutex_w32.c ******************/ |
| 19177 | 19405 | #endif |
| 19178 | 19406 | |
| 19179 | 19407 | /* |
| 19180 | 19408 | ** The code in this file is only used if we are compiling multithreaded |
| 19181 | -** on a win32 system. | |
| 19409 | +** on a Win32 system. | |
| 19182 | 19410 | */ |
| 19183 | 19411 | #ifdef SQLITE_MUTEX_W32 |
| 19184 | 19412 | |
| 19185 | 19413 | /* |
| 19186 | 19414 | ** Each recursive mutex is an instance of the following structure. |
| @@ -19189,94 +19417,75 @@ | ||
| 19189 | 19417 | CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 19190 | 19418 | int id; /* Mutex type */ |
| 19191 | 19419 | #ifdef SQLITE_DEBUG |
| 19192 | 19420 | volatile int nRef; /* Number of enterances */ |
| 19193 | 19421 | volatile DWORD owner; /* Thread holding this mutex */ |
| 19194 | - int trace; /* True to trace changes */ | |
| 19422 | + volatile int trace; /* True to trace changes */ | |
| 19195 | 19423 | #endif |
| 19196 | 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 | +*/ | |
| 19197 | 19431 | #define SQLITE_W32_MUTEX_INITIALIZER { 0 } |
| 19432 | + | |
| 19198 | 19433 | #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 } | |
| 19200 | 19436 | #else |
| 19201 | 19437 | #define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 } |
| 19202 | 19438 | #endif |
| 19203 | 19439 | |
| 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 | 19440 | #ifdef SQLITE_DEBUG |
| 19239 | 19441 | /* |
| 19240 | 19442 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are |
| 19241 | 19443 | ** intended for use only inside assert() statements. |
| 19242 | 19444 | */ |
| 19243 | 19445 | static int winMutexHeld(sqlite3_mutex *p){ |
| 19244 | 19446 | return p->nRef!=0 && p->owner==GetCurrentThreadId(); |
| 19245 | 19447 | } |
| 19448 | + | |
| 19246 | 19449 | static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){ |
| 19247 | 19450 | return p->nRef==0 || p->owner!=tid; |
| 19248 | 19451 | } |
| 19452 | + | |
| 19249 | 19453 | static int winMutexNotheld(sqlite3_mutex *p){ |
| 19250 | - DWORD tid = GetCurrentThreadId(); | |
| 19454 | + DWORD tid = GetCurrentThreadId(); | |
| 19251 | 19455 | return winMutexNotheld2(p, tid); |
| 19252 | 19456 | } |
| 19253 | 19457 | #endif |
| 19254 | 19458 | |
| 19255 | - | |
| 19256 | 19459 | /* |
| 19257 | 19460 | ** Initialize and deinitialize the mutex subsystem. |
| 19258 | 19461 | */ |
| 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, | |
| 19260 | 19466 | SQLITE3_MUTEX_INITIALIZER, |
| 19261 | 19467 | SQLITE3_MUTEX_INITIALIZER, |
| 19262 | 19468 | SQLITE3_MUTEX_INITIALIZER, |
| 19263 | 19469 | SQLITE3_MUTEX_INITIALIZER, |
| 19264 | 19470 | SQLITE3_MUTEX_INITIALIZER, |
| 19265 | 19471 | SQLITE3_MUTEX_INITIALIZER |
| 19266 | 19472 | }; |
| 19473 | + | |
| 19267 | 19474 | 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. | |
| 19272 | 19480 | */ |
| 19273 | -static LONG winMutex_lock = 0; | |
| 19481 | +static LONG volatile winMutex_lock = 0; | |
| 19274 | 19482 | |
| 19483 | +SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */ | |
| 19275 | 19484 | SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ |
| 19276 | 19485 | |
| 19277 | -static int winMutexInit(void){ | |
| 19486 | +static int winMutexInit(void){ | |
| 19278 | 19487 | /* The first to increment to 1 does actual initialization */ |
| 19279 | 19488 | if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ |
| 19280 | 19489 | int i; |
| 19281 | 19490 | for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ |
| 19282 | 19491 | #if SQLITE_OS_WINRT |
| @@ -19285,20 +19494,21 @@ | ||
| 19285 | 19494 | InitializeCriticalSection(&winMutex_staticMutexes[i].mutex); |
| 19286 | 19495 | #endif |
| 19287 | 19496 | } |
| 19288 | 19497 | winMutex_isInit = 1; |
| 19289 | 19498 | }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 */ | |
| 19291 | 19501 | while( !winMutex_isInit ){ |
| 19292 | 19502 | sqlite3_win32_sleep(1); |
| 19293 | 19503 | } |
| 19294 | 19504 | } |
| 19295 | - return SQLITE_OK; | |
| 19505 | + return SQLITE_OK; | |
| 19296 | 19506 | } |
| 19297 | 19507 | |
| 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 | |
| 19300 | 19510 | ** (which should be the last to shutdown.) */ |
| 19301 | 19511 | if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){ |
| 19302 | 19512 | if( winMutex_isInit==1 ){ |
| 19303 | 19513 | int i; |
| 19304 | 19514 | for(i=0; i<ArraySize(winMutex_staticMutexes); i++){ |
| @@ -19305,11 +19515,11 @@ | ||
| 19305 | 19515 | DeleteCriticalSection(&winMutex_staticMutexes[i].mutex); |
| 19306 | 19516 | } |
| 19307 | 19517 | winMutex_isInit = 0; |
| 19308 | 19518 | } |
| 19309 | 19519 | } |
| 19310 | - return SQLITE_OK; | |
| 19520 | + return SQLITE_OK; | |
| 19311 | 19521 | } |
| 19312 | 19522 | |
| 19313 | 19523 | /* |
| 19314 | 19524 | ** The sqlite3_mutex_alloc() routine allocates a new |
| 19315 | 19525 | ** mutex and returns a pointer to it. If it returns NULL |
| @@ -19320,14 +19530,17 @@ | ||
| 19320 | 19530 | ** <ul> |
| 19321 | 19531 | ** <li> SQLITE_MUTEX_FAST |
| 19322 | 19532 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 19323 | 19533 | ** <li> SQLITE_MUTEX_STATIC_MASTER |
| 19324 | 19534 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 19325 | -** <li> SQLITE_MUTEX_STATIC_MEM2 | |
| 19535 | +** <li> SQLITE_MUTEX_STATIC_OPEN | |
| 19326 | 19536 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 19327 | 19537 | ** <li> SQLITE_MUTEX_STATIC_LRU |
| 19328 | 19538 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 19539 | +** <li> SQLITE_MUTEX_STATIC_APP1 | |
| 19540 | +** <li> SQLITE_MUTEX_STATIC_APP2 | |
| 19541 | +** <li> SQLITE_MUTEX_STATIC_APP3 | |
| 19329 | 19542 | ** </ul> |
| 19330 | 19543 | ** |
| 19331 | 19544 | ** The first two constants cause sqlite3_mutex_alloc() to create |
| 19332 | 19545 | ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 19333 | 19546 | ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. |
| @@ -19346,11 +19559,11 @@ | ||
| 19346 | 19559 | ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or |
| 19347 | 19560 | ** SQLITE_MUTEX_RECURSIVE. |
| 19348 | 19561 | ** |
| 19349 | 19562 | ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST |
| 19350 | 19563 | ** 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 | |
| 19352 | 19565 | ** mutex types, the same mutex is returned on every call that has |
| 19353 | 19566 | ** the same type number. |
| 19354 | 19567 | */ |
| 19355 | 19568 | static sqlite3_mutex *winMutexAlloc(int iType){ |
| 19356 | 19569 | sqlite3_mutex *p; |
| @@ -19357,13 +19570,16 @@ | ||
| 19357 | 19570 | |
| 19358 | 19571 | switch( iType ){ |
| 19359 | 19572 | case SQLITE_MUTEX_FAST: |
| 19360 | 19573 | case SQLITE_MUTEX_RECURSIVE: { |
| 19361 | 19574 | p = sqlite3MallocZero( sizeof(*p) ); |
| 19362 | - if( p ){ | |
| 19575 | + if( p ){ | |
| 19363 | 19576 | #ifdef SQLITE_DEBUG |
| 19364 | 19577 | p->id = iType; |
| 19578 | +#ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC | |
| 19579 | + p->trace = 1; | |
| 19580 | +#endif | |
| 19365 | 19581 | #endif |
| 19366 | 19582 | #if SQLITE_OS_WINRT |
| 19367 | 19583 | InitializeCriticalSectionEx(&p->mutex, 0, 0); |
| 19368 | 19584 | #else |
| 19369 | 19585 | InitializeCriticalSection(&p->mutex); |
| @@ -19370,16 +19586,19 @@ | ||
| 19370 | 19586 | #endif |
| 19371 | 19587 | } |
| 19372 | 19588 | break; |
| 19373 | 19589 | } |
| 19374 | 19590 | default: { |
| 19375 | - assert( winMutex_isInit==1 ); | |
| 19376 | 19591 | assert( iType-2 >= 0 ); |
| 19377 | 19592 | assert( iType-2 < ArraySize(winMutex_staticMutexes) ); |
| 19593 | + assert( winMutex_isInit==1 ); | |
| 19378 | 19594 | p = &winMutex_staticMutexes[iType-2]; |
| 19379 | 19595 | #ifdef SQLITE_DEBUG |
| 19380 | 19596 | p->id = iType; |
| 19597 | +#ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC | |
| 19598 | + p->trace = 1; | |
| 19599 | +#endif | |
| 19381 | 19600 | #endif |
| 19382 | 19601 | break; |
| 19383 | 19602 | } |
| 19384 | 19603 | } |
| 19385 | 19604 | return p; |
| @@ -19391,12 +19610,15 @@ | ||
| 19391 | 19610 | ** allocated mutex. SQLite is careful to deallocate every |
| 19392 | 19611 | ** mutex that it allocates. |
| 19393 | 19612 | */ |
| 19394 | 19613 | static void winMutexFree(sqlite3_mutex *p){ |
| 19395 | 19614 | assert( p ); |
| 19615 | +#ifdef SQLITE_DEBUG | |
| 19396 | 19616 | assert( p->nRef==0 && p->owner==0 ); |
| 19397 | 19617 | assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); |
| 19618 | +#endif | |
| 19619 | + assert( winMutex_isInit==1 ); | |
| 19398 | 19620 | DeleteCriticalSection(&p->mutex); |
| 19399 | 19621 | sqlite3_free(p); |
| 19400 | 19622 | } |
| 19401 | 19623 | |
| 19402 | 19624 | /* |
| @@ -19409,53 +19631,71 @@ | ||
| 19409 | 19631 | ** mutex must be exited an equal number of times before another thread |
| 19410 | 19632 | ** can enter. If the same thread tries to enter any other kind of mutex |
| 19411 | 19633 | ** more than once, the behavior is undefined. |
| 19412 | 19634 | */ |
| 19413 | 19635 | static void winMutexEnter(sqlite3_mutex *p){ |
| 19636 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) | |
| 19637 | + DWORD tid = GetCurrentThreadId(); | |
| 19638 | +#endif | |
| 19414 | 19639 | #ifdef SQLITE_DEBUG |
| 19415 | - DWORD tid = GetCurrentThreadId(); | |
| 19640 | + assert( p ); | |
| 19416 | 19641 | assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); |
| 19642 | +#else | |
| 19643 | + assert( p ); | |
| 19417 | 19644 | #endif |
| 19645 | + assert( winMutex_isInit==1 ); | |
| 19418 | 19646 | EnterCriticalSection(&p->mutex); |
| 19419 | 19647 | #ifdef SQLITE_DEBUG |
| 19420 | 19648 | assert( p->nRef>0 || p->owner==0 ); |
| 19421 | - p->owner = tid; | |
| 19649 | + p->owner = tid; | |
| 19422 | 19650 | p->nRef++; |
| 19423 | 19651 | 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)); | |
| 19425 | 19654 | } |
| 19426 | 19655 | #endif |
| 19427 | 19656 | } |
| 19657 | + | |
| 19428 | 19658 | 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(); | |
| 19431 | 19661 | #endif |
| 19432 | 19662 | int rc = SQLITE_BUSY; |
| 19663 | + assert( p ); | |
| 19433 | 19664 | assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); |
| 19434 | 19665 | /* |
| 19435 | 19666 | ** The sqlite3_mutex_try() routine is very rarely used, and when it |
| 19436 | 19667 | ** is used it is merely an optimization. So it is OK for it to always |
| 19437 | - ** fail. | |
| 19668 | + ** fail. | |
| 19438 | 19669 | ** |
| 19439 | 19670 | ** The TryEnterCriticalSection() interface is only available on WinNT. |
| 19440 | 19671 | ** And some windows compilers complain if you try to use it without |
| 19441 | 19672 | ** first doing some #defines that prevent SQLite from building on Win98. |
| 19442 | 19673 | ** For that reason, we will omit this optimization for now. See |
| 19443 | 19674 | ** ticket #2685. |
| 19444 | 19675 | */ |
| 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 | |
| 19447 | 19685 | p->owner = tid; |
| 19448 | 19686 | p->nRef++; |
| 19687 | +#endif | |
| 19449 | 19688 | rc = SQLITE_OK; |
| 19450 | 19689 | } |
| 19451 | 19690 | #else |
| 19452 | 19691 | UNUSED_PARAMETER(p); |
| 19453 | 19692 | #endif |
| 19454 | 19693 | #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))); | |
| 19457 | 19697 | } |
| 19458 | 19698 | #endif |
| 19459 | 19699 | return rc; |
| 19460 | 19700 | } |
| 19461 | 19701 | |
| @@ -19464,22 +19704,27 @@ | ||
| 19464 | 19704 | ** previously entered by the same thread. The behavior |
| 19465 | 19705 | ** is undefined if the mutex is not currently entered or |
| 19466 | 19706 | ** is not currently allocated. SQLite will never do either. |
| 19467 | 19707 | */ |
| 19468 | 19708 | static void winMutexLeave(sqlite3_mutex *p){ |
| 19469 | -#ifndef NDEBUG | |
| 19709 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) | |
| 19470 | 19710 | DWORD tid = GetCurrentThreadId(); |
| 19711 | +#endif | |
| 19712 | + assert( p ); | |
| 19713 | +#ifdef SQLITE_DEBUG | |
| 19471 | 19714 | assert( p->nRef>0 ); |
| 19472 | 19715 | assert( p->owner==tid ); |
| 19473 | 19716 | p->nRef--; |
| 19474 | 19717 | if( p->nRef==0 ) p->owner = 0; |
| 19475 | 19718 | assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); |
| 19476 | 19719 | #endif |
| 19720 | + assert( winMutex_isInit==1 ); | |
| 19477 | 19721 | LeaveCriticalSection(&p->mutex); |
| 19478 | 19722 | #ifdef SQLITE_DEBUG |
| 19479 | 19723 | 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)); | |
| 19481 | 19726 | } |
| 19482 | 19727 | #endif |
| 19483 | 19728 | } |
| 19484 | 19729 | |
| 19485 | 19730 | SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ |
| @@ -19497,13 +19742,13 @@ | ||
| 19497 | 19742 | #else |
| 19498 | 19743 | 0, |
| 19499 | 19744 | 0 |
| 19500 | 19745 | #endif |
| 19501 | 19746 | }; |
| 19502 | - | |
| 19503 | 19747 | return &sMutex; |
| 19504 | 19748 | } |
| 19749 | + | |
| 19505 | 19750 | #endif /* SQLITE_MUTEX_W32 */ |
| 19506 | 19751 | |
| 19507 | 19752 | /************** End of mutex_w32.c *******************************************/ |
| 19508 | 19753 | /************** Begin file malloc.c ******************************************/ |
| 19509 | 19754 | /* |
| @@ -23718,14 +23963,14 @@ | ||
| 23718 | 23963 | /* 55 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 23719 | 23964 | /* 56 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 23720 | 23965 | /* 57 */ "SorterOpen" OpHelp(""), |
| 23721 | 23966 | /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 23722 | 23967 | /* 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]"), | |
| 23727 | 23972 | /* 64 */ "Seek" OpHelp("intkey=r[P2]"), |
| 23728 | 23973 | /* 65 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 23729 | 23974 | /* 66 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 23730 | 23975 | /* 67 */ "Found" OpHelp("key=r[P3@P4]"), |
| 23731 | 23976 | /* 68 */ "NotExists" OpHelp("intkey=r[P3]"), |
| @@ -23753,11 +23998,11 @@ | ||
| 23753 | 23998 | /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 23754 | 23999 | /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 23755 | 24000 | /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 23756 | 24001 | /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 23757 | 24002 | /* 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"), | |
| 23759 | 24004 | /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 23760 | 24005 | /* 97 */ "String8" OpHelp("r[P2]='P4'"), |
| 23761 | 24006 | /* 98 */ "SorterData" OpHelp("r[P2]=data"), |
| 23762 | 24007 | /* 99 */ "RowKey" OpHelp("r[P2]=key"), |
| 23763 | 24008 | /* 100 */ "RowData" OpHelp("r[P2]=data"), |
| @@ -32160,14 +32405,14 @@ | ||
| 32160 | 32405 | ** |
| 32161 | 32406 | ** In order to facilitate testing on a WinNT system, the test fixture |
| 32162 | 32407 | ** can manually set this value to 1 to emulate Win98 behavior. |
| 32163 | 32408 | */ |
| 32164 | 32409 | #ifdef SQLITE_TEST |
| 32165 | -SQLITE_API int sqlite3_os_type = 0; | |
| 32410 | +SQLITE_API LONG volatile sqlite3_os_type = 0; | |
| 32166 | 32411 | #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \ |
| 32167 | 32412 | 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; | |
| 32169 | 32414 | #endif |
| 32170 | 32415 | |
| 32171 | 32416 | #ifndef SYSCALL |
| 32172 | 32417 | # define SYSCALL sqlite3_syscall_ptr |
| 32173 | 32418 | #endif |
| @@ -32793,10 +33038,15 @@ | ||
| 32793 | 33038 | { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
| 32794 | 33039 | #endif |
| 32795 | 33040 | |
| 32796 | 33041 | #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \ |
| 32797 | 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) | |
| 32798 | 33048 | |
| 32799 | 33049 | }; /* End of the overrideable system calls */ |
| 32800 | 33050 | |
| 32801 | 33051 | /* |
| 32802 | 33052 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -33044,26 +33294,33 @@ | ||
| 33044 | 33294 | #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) |
| 33045 | 33295 | # define osIsNT() (1) |
| 33046 | 33296 | #elif !defined(SQLITE_WIN32_HAS_WIDE) |
| 33047 | 33297 | # define osIsNT() (0) |
| 33048 | 33298 | #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 ){ | |
| 33051 | 33308 | #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); | |
| 33055 | 33312 | #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 | +} | |
| 33065 | 33322 | |
| 33066 | 33323 | #ifdef SQLITE_WIN32_MALLOC |
| 33067 | 33324 | /* |
| 33068 | 33325 | ** Allocate nBytes of memory. |
| 33069 | 33326 | */ |
| @@ -37215,11 +37472,11 @@ | ||
| 37215 | 37472 | }; |
| 37216 | 37473 | #endif |
| 37217 | 37474 | |
| 37218 | 37475 | /* Double-check that the aSyscall[] array has been constructed |
| 37219 | 37476 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 37220 | - assert( ArraySize(aSyscall)==76 ); | |
| 37477 | + assert( ArraySize(aSyscall)==77 ); | |
| 37221 | 37478 | |
| 37222 | 37479 | /* get memory map allocation granularity */ |
| 37223 | 37480 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 37224 | 37481 | #if SQLITE_OS_WINRT |
| 37225 | 37482 | osGetNativeSystemInfo(&winSysInfo); |
| @@ -52907,11 +53164,11 @@ | ||
| 52907 | 53164 | return pBt->nPage; |
| 52908 | 53165 | } |
| 52909 | 53166 | SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){ |
| 52910 | 53167 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 52911 | 53168 | assert( ((p->pBt->nPage)&0x8000000)==0 ); |
| 52912 | - return (int)btreePagecount(p->pBt); | |
| 53169 | + return btreePagecount(p->pBt); | |
| 52913 | 53170 | } |
| 52914 | 53171 | |
| 52915 | 53172 | /* |
| 52916 | 53173 | ** Get a page from the pager and initialize it. This routine is just a |
| 52917 | 53174 | ** convenience wrapper around separate calls to btreeGetPage() and |
| @@ -64735,11 +64992,11 @@ | ||
| 64735 | 64992 | /* |
| 64736 | 64993 | ** Return the serial-type for the value stored in pMem. |
| 64737 | 64994 | */ |
| 64738 | 64995 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){ |
| 64739 | 64996 | int flags = pMem->flags; |
| 64740 | - int n; | |
| 64997 | + u32 n; | |
| 64741 | 64998 | |
| 64742 | 64999 | if( flags&MEM_Null ){ |
| 64743 | 65000 | return 0; |
| 64744 | 65001 | } |
| 64745 | 65002 | if( flags&MEM_Int ){ |
| @@ -64765,15 +65022,15 @@ | ||
| 64765 | 65022 | } |
| 64766 | 65023 | if( flags&MEM_Real ){ |
| 64767 | 65024 | return 7; |
| 64768 | 65025 | } |
| 64769 | 65026 | assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) ); |
| 64770 | - n = pMem->n; | |
| 65027 | + assert( pMem->n>=0 ); | |
| 65028 | + n = (u32)pMem->n; | |
| 64771 | 65029 | if( flags & MEM_Zero ){ |
| 64772 | 65030 | n += pMem->u.nZero; |
| 64773 | 65031 | } |
| 64774 | - assert( n>=0 ); | |
| 64775 | 65032 | return ((n*2) + 12 + ((flags&MEM_Str)!=0)); |
| 64776 | 65033 | } |
| 64777 | 65034 | |
| 64778 | 65035 | /* |
| 64779 | 65036 | ** Return the length of the data corresponding to the supplied serial-type. |
| @@ -67845,25 +68102,25 @@ | ||
| 67845 | 68102 | ** do so without loss of information. In other words, if the string |
| 67846 | 68103 | ** looks like a number, convert it into a number. If it does not |
| 67847 | 68104 | ** look like a number, leave it alone. |
| 67848 | 68105 | */ |
| 67849 | 68106 | 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);} | |
| 67865 | 68122 | |
| 67866 | 68123 | /* |
| 67867 | 68124 | ** Processing is determine by the affinity parameter: |
| 67868 | 68125 | ** |
| 67869 | 68126 | ** SQLITE_AFF_INTEGER: |
| @@ -67896,11 +68153,11 @@ | ||
| 67896 | 68153 | } |
| 67897 | 68154 | pRec->flags &= ~(MEM_Real|MEM_Int); |
| 67898 | 68155 | }else if( affinity!=SQLITE_AFF_NONE ){ |
| 67899 | 68156 | assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 67900 | 68157 | || affinity==SQLITE_AFF_NUMERIC ); |
| 67901 | - applyNumericAffinity(pRec); | |
| 68158 | + ApplyNumericAffinity(pRec); | |
| 67902 | 68159 | if( pRec->flags & MEM_Real ){ |
| 67903 | 68160 | sqlite3VdbeIntegerAffinity(pRec); |
| 67904 | 68161 | } |
| 67905 | 68162 | } |
| 67906 | 68163 | } |
| @@ -68477,16 +68734,18 @@ | ||
| 68477 | 68734 | break; |
| 68478 | 68735 | } |
| 68479 | 68736 | |
| 68480 | 68737 | /* Opcode: InitCoroutine P1 P2 P3 * * |
| 68481 | 68738 | ** |
| 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 | |
| 68483 | 68740 | ** located at address P3. |
| 68484 | 68741 | ** |
| 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 | |
| 68487 | 68744 | ** address P2. |
| 68745 | +** | |
| 68746 | +** See also: EndCoroutine | |
| 68488 | 68747 | */ |
| 68489 | 68748 | case OP_InitCoroutine: { /* jump */ |
| 68490 | 68749 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 68491 | 68750 | assert( pOp->p2>=0 && pOp->p2<p->nOp ); |
| 68492 | 68751 | assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| @@ -68498,13 +68757,15 @@ | ||
| 68498 | 68757 | break; |
| 68499 | 68758 | } |
| 68500 | 68759 | |
| 68501 | 68760 | /* Opcode: EndCoroutine P1 * * * * |
| 68502 | 68761 | ** |
| 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. | |
| 68505 | 68764 | ** After the jump, register P1 becomes undefined. |
| 68765 | +** | |
| 68766 | +** See also: InitCoroutine | |
| 68506 | 68767 | */ |
| 68507 | 68768 | case OP_EndCoroutine: { /* in1 */ |
| 68508 | 68769 | VdbeOp *pCaller; |
| 68509 | 68770 | pIn1 = &aMem[pOp->p1]; |
| 68510 | 68771 | assert( pIn1->flags==MEM_Int ); |
| @@ -68517,15 +68778,20 @@ | ||
| 68517 | 68778 | break; |
| 68518 | 68779 | } |
| 68519 | 68780 | |
| 68520 | 68781 | /* Opcode: Yield P1 P2 * * * |
| 68521 | 68782 | ** |
| 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. | |
| 68523 | 68785 | ** |
| 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 | |
| 68527 | 68793 | */ |
| 68528 | 68794 | case OP_Yield: { /* in1, jump */ |
| 68529 | 68795 | int pcDest; |
| 68530 | 68796 | pIn1 = &aMem[pOp->p1]; |
| 68531 | 68797 | assert( VdbeMemDynamic(pIn1)==0 ); |
| @@ -69906,14 +70172,18 @@ | ||
| 69906 | 70172 | break; |
| 69907 | 70173 | } |
| 69908 | 70174 | |
| 69909 | 70175 | /* Opcode: Once P1 P2 * * * |
| 69910 | 70176 | ** |
| 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. | |
| 69915 | 70185 | */ |
| 69916 | 70186 | case OP_Once: { /* jump */ |
| 69917 | 70187 | assert( pOp->p1<p->nOnceFlag ); |
| 69918 | 70188 | VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 69919 | 70189 | if( p->aOnceFlag[pOp->p1] ){ |
| @@ -71191,11 +71461,11 @@ | ||
| 71191 | 71461 | sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]); |
| 71192 | 71462 | p->apCsr[pOp->p1] = 0; |
| 71193 | 71463 | break; |
| 71194 | 71464 | } |
| 71195 | 71465 | |
| 71196 | -/* Opcode: SeekGe P1 P2 P3 P4 * | |
| 71466 | +/* Opcode: SeekGE P1 P2 P3 P4 * | |
| 71197 | 71467 | ** Synopsis: key=r[P3@P4] |
| 71198 | 71468 | ** |
| 71199 | 71469 | ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 71200 | 71470 | ** use the value in register P3 as the key. If cursor P1 refers |
| 71201 | 71471 | ** to an SQL index, then P3 is the first in an array of P4 registers |
| @@ -71202,14 +71472,18 @@ | ||
| 71202 | 71472 | ** that are used as an unpacked index key. |
| 71203 | 71473 | ** |
| 71204 | 71474 | ** Reposition cursor P1 so that it points to the smallest entry that |
| 71205 | 71475 | ** is greater than or equal to the key value. If there are no records |
| 71206 | 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. | |
| 71207 | 71481 | ** |
| 71208 | 71482 | ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe |
| 71209 | 71483 | */ |
| 71210 | -/* Opcode: SeekGt P1 P2 P3 P4 * | |
| 71484 | +/* Opcode: SeekGT P1 P2 P3 P4 * | |
| 71211 | 71485 | ** Synopsis: key=r[P3@P4] |
| 71212 | 71486 | ** |
| 71213 | 71487 | ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 71214 | 71488 | ** use the value in register P3 as a key. If cursor P1 refers |
| 71215 | 71489 | ** to an SQL index, then P3 is the first in an array of P4 registers |
| @@ -71216,14 +71490,18 @@ | ||
| 71216 | 71490 | ** that are used as an unpacked index key. |
| 71217 | 71491 | ** |
| 71218 | 71492 | ** Reposition cursor P1 so that it points to the smallest entry that |
| 71219 | 71493 | ** is greater than the key value. If there are no records greater than |
| 71220 | 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. | |
| 71221 | 71499 | ** |
| 71222 | 71500 | ** See also: Found, NotFound, SeekLt, SeekGe, SeekLe |
| 71223 | 71501 | */ |
| 71224 | -/* Opcode: SeekLt P1 P2 P3 P4 * | |
| 71502 | +/* Opcode: SeekLT P1 P2 P3 P4 * | |
| 71225 | 71503 | ** Synopsis: key=r[P3@P4] |
| 71226 | 71504 | ** |
| 71227 | 71505 | ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 71228 | 71506 | ** use the value in register P3 as a key. If cursor P1 refers |
| 71229 | 71507 | ** to an SQL index, then P3 is the first in an array of P4 registers |
| @@ -71230,14 +71508,18 @@ | ||
| 71230 | 71508 | ** that are used as an unpacked index key. |
| 71231 | 71509 | ** |
| 71232 | 71510 | ** Reposition cursor P1 so that it points to the largest entry that |
| 71233 | 71511 | ** is less than the key value. If there are no records less than |
| 71234 | 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. | |
| 71235 | 71517 | ** |
| 71236 | 71518 | ** See also: Found, NotFound, SeekGt, SeekGe, SeekLe |
| 71237 | 71519 | */ |
| 71238 | -/* Opcode: SeekLe P1 P2 P3 P4 * | |
| 71520 | +/* Opcode: SeekLE P1 P2 P3 P4 * | |
| 71239 | 71521 | ** Synopsis: key=r[P3@P4] |
| 71240 | 71522 | ** |
| 71241 | 71523 | ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 71242 | 71524 | ** use the value in register P3 as a key. If cursor P1 refers |
| 71243 | 71525 | ** to an SQL index, then P3 is the first in an array of P4 registers |
| @@ -71244,10 +71526,14 @@ | ||
| 71244 | 71526 | ** that are used as an unpacked index key. |
| 71245 | 71527 | ** |
| 71246 | 71528 | ** Reposition cursor P1 so that it points to the largest entry that |
| 71247 | 71529 | ** is less than or equal to the key value. If there are no records |
| 71248 | 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. | |
| 71249 | 71535 | ** |
| 71250 | 71536 | ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt |
| 71251 | 71537 | */ |
| 71252 | 71538 | case OP_SeekLT: /* jump, in3 */ |
| 71253 | 71539 | case OP_SeekLE: /* jump, in3 */ |
| @@ -71270,16 +71556,19 @@ | ||
| 71270 | 71556 | assert( OP_SeekGT == OP_SeekLT+3 ); |
| 71271 | 71557 | assert( pC->isOrdered ); |
| 71272 | 71558 | assert( pC->pCursor!=0 ); |
| 71273 | 71559 | oc = pOp->opcode; |
| 71274 | 71560 | pC->nullRow = 0; |
| 71561 | +#ifdef SQLITE_DEBUG | |
| 71562 | + pC->seekOp = pOp->opcode; | |
| 71563 | +#endif | |
| 71275 | 71564 | if( pC->isTable ){ |
| 71276 | 71565 | /* The input value in P3 might be of any type: integer, real, string, |
| 71277 | 71566 | ** blob, or NULL. But it needs to be an integer before we can do |
| 71278 | 71567 | ** the seek, so covert it. */ |
| 71279 | 71568 | pIn3 = &aMem[pOp->p3]; |
| 71280 | - applyNumericAffinity(pIn3); | |
| 71569 | + ApplyNumericAffinity(pIn3); | |
| 71281 | 71570 | iKey = sqlite3VdbeIntValue(pIn3); |
| 71282 | 71571 | pC->rowidIsValid = 0; |
| 71283 | 71572 | |
| 71284 | 71573 | /* If the P3 value could not be converted into an integer without |
| 71285 | 71574 | ** loss of information, then special processing is required... */ |
| @@ -71424,10 +71713,14 @@ | ||
| 71424 | 71713 | ** record. |
| 71425 | 71714 | ** |
| 71426 | 71715 | ** Cursor P1 is on an index btree. If the record identified by P3 and P4 |
| 71427 | 71716 | ** is a prefix of any entry in P1 then a jump is made to P2 and |
| 71428 | 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. | |
| 71429 | 71722 | ** |
| 71430 | 71723 | ** See also: NotFound, NoConflict, NotExists. SeekGe |
| 71431 | 71724 | */ |
| 71432 | 71725 | /* Opcode: NotFound P1 P2 P3 P4 * |
| 71433 | 71726 | ** Synopsis: key=r[P3@P4] |
| @@ -71439,10 +71732,14 @@ | ||
| 71439 | 71732 | ** Cursor P1 is on an index btree. If the record identified by P3 and P4 |
| 71440 | 71733 | ** is not the prefix of any entry in P1 then a jump is made to P2. If P1 |
| 71441 | 71734 | ** does contain an entry whose prefix matches the P3/P4 record then control |
| 71442 | 71735 | ** falls through to the next instruction and P1 is left pointing at the |
| 71443 | 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. | |
| 71444 | 71741 | ** |
| 71445 | 71742 | ** See also: Found, NotExists, NoConflict |
| 71446 | 71743 | */ |
| 71447 | 71744 | /* Opcode: NoConflict P1 P2 P3 P4 * |
| 71448 | 71745 | ** Synopsis: key=r[P3@P4] |
| @@ -71458,10 +71755,14 @@ | ||
| 71458 | 71755 | ** immediately to P2. If there is a match, fall through and leave the P1 |
| 71459 | 71756 | ** cursor pointing to the matching row. |
| 71460 | 71757 | ** |
| 71461 | 71758 | ** This opcode is similar to OP_NotFound with the exceptions that the |
| 71462 | 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. | |
| 71463 | 71764 | ** |
| 71464 | 71765 | ** See also: NotFound, Found, NotExists |
| 71465 | 71766 | */ |
| 71466 | 71767 | case OP_NoConflict: /* jump, in3 */ |
| 71467 | 71768 | case OP_NotFound: /* jump, in3 */ |
| @@ -71481,10 +71782,13 @@ | ||
| 71481 | 71782 | |
| 71482 | 71783 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71483 | 71784 | assert( pOp->p4type==P4_INT32 ); |
| 71484 | 71785 | pC = p->apCsr[pOp->p1]; |
| 71485 | 71786 | assert( pC!=0 ); |
| 71787 | +#ifdef SQLITE_DEBUG | |
| 71788 | + pC->seekOp = 0; | |
| 71789 | +#endif | |
| 71486 | 71790 | pIn3 = &aMem[pOp->p3]; |
| 71487 | 71791 | assert( pC->pCursor!=0 ); |
| 71488 | 71792 | assert( pC->isTable==0 ); |
| 71489 | 71793 | pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 71490 | 71794 | if( pOp->p4.i>0 ){ |
| @@ -71551,10 +71855,14 @@ | ||
| 71551 | 71855 | ** with rowid P3 then leave the cursor pointing at that record and fall |
| 71552 | 71856 | ** through to the next instruction. |
| 71553 | 71857 | ** |
| 71554 | 71858 | ** The OP_NotFound opcode performs the same operation on index btrees |
| 71555 | 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. | |
| 71556 | 71864 | ** |
| 71557 | 71865 | ** See also: Found, NotFound, NoConflict |
| 71558 | 71866 | */ |
| 71559 | 71867 | case OP_NotExists: { /* jump, in3 */ |
| 71560 | 71868 | VdbeCursor *pC; |
| @@ -71565,10 +71873,13 @@ | ||
| 71565 | 71873 | pIn3 = &aMem[pOp->p3]; |
| 71566 | 71874 | assert( pIn3->flags & MEM_Int ); |
| 71567 | 71875 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71568 | 71876 | pC = p->apCsr[pOp->p1]; |
| 71569 | 71877 | assert( pC!=0 ); |
| 71878 | +#ifdef SQLITE_DEBUG | |
| 71879 | + pC->seekOp = 0; | |
| 71880 | +#endif | |
| 71570 | 71881 | assert( pC->isTable ); |
| 71571 | 71882 | assert( pC->pseudoTableReg==0 ); |
| 71572 | 71883 | pCrsr = pC->pCursor; |
| 71573 | 71884 | assert( pCrsr!=0 ); |
| 71574 | 71885 | res = 0; |
| @@ -71927,16 +72238,16 @@ | ||
| 71927 | 72238 | p->nChange = 0; |
| 71928 | 72239 | break; |
| 71929 | 72240 | } |
| 71930 | 72241 | |
| 71931 | 72242 | /* 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 | |
| 71933 | 72244 | ** |
| 71934 | 72245 | ** P1 is a sorter cursor. This instruction compares a prefix of the |
| 71935 | 72246 | ** 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. | |
| 71938 | 72249 | ** |
| 71939 | 72250 | ** If either P3 or the sorter contains a NULL in one of their significant |
| 71940 | 72251 | ** fields (not counting the P4 fields at the end which are ignored) then |
| 71941 | 72252 | ** the comparison is assumed to be equal. |
| 71942 | 72253 | ** |
| @@ -71944,18 +72255,18 @@ | ||
| 71944 | 72255 | ** each other. Jump to P2 if they are different. |
| 71945 | 72256 | */ |
| 71946 | 72257 | case OP_SorterCompare: { |
| 71947 | 72258 | VdbeCursor *pC; |
| 71948 | 72259 | int res; |
| 71949 | - int nIgnore; | |
| 72260 | + int nKeyCol; | |
| 71950 | 72261 | |
| 71951 | 72262 | pC = p->apCsr[pOp->p1]; |
| 71952 | 72263 | assert( isSorter(pC) ); |
| 71953 | 72264 | assert( pOp->p4type==P4_INT32 ); |
| 71954 | 72265 | 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); | |
| 71957 | 72268 | VdbeBranchTaken(res!=0,2); |
| 71958 | 72269 | if( res ){ |
| 71959 | 72270 | pc = pOp->p2-1; |
| 71960 | 72271 | } |
| 71961 | 72272 | break; |
| @@ -72131,15 +72442,19 @@ | ||
| 72131 | 72442 | break; |
| 72132 | 72443 | } |
| 72133 | 72444 | |
| 72134 | 72445 | /* Opcode: Last P1 P2 * * * |
| 72135 | 72446 | ** |
| 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 | |
| 72137 | 72448 | ** will refer to the last entry in the database table or index. |
| 72138 | 72449 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 72139 | 72450 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 72140 | 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. | |
| 72141 | 72456 | */ |
| 72142 | 72457 | case OP_Last: { /* jump */ |
| 72143 | 72458 | VdbeCursor *pC; |
| 72144 | 72459 | BtCursor *pCrsr; |
| 72145 | 72460 | int res; |
| @@ -72153,10 +72468,13 @@ | ||
| 72153 | 72468 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 72154 | 72469 | pC->nullRow = (u8)res; |
| 72155 | 72470 | pC->deferredMoveto = 0; |
| 72156 | 72471 | pC->rowidIsValid = 0; |
| 72157 | 72472 | pC->cacheStatus = CACHE_STALE; |
| 72473 | +#ifdef SQLITE_DEBUG | |
| 72474 | + pC->seekOp = OP_Last; | |
| 72475 | +#endif | |
| 72158 | 72476 | if( pOp->p2>0 ){ |
| 72159 | 72477 | VdbeBranchTaken(res!=0,2); |
| 72160 | 72478 | if( res ) pc = pOp->p2 - 1; |
| 72161 | 72479 | } |
| 72162 | 72480 | break; |
| @@ -72189,10 +72507,14 @@ | ||
| 72189 | 72507 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 72190 | 72508 | ** will refer to the first entry in the database table or index. |
| 72191 | 72509 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 72192 | 72510 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 72193 | 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. | |
| 72194 | 72516 | */ |
| 72195 | 72517 | case OP_Rewind: { /* jump */ |
| 72196 | 72518 | VdbeCursor *pC; |
| 72197 | 72519 | BtCursor *pCrsr; |
| 72198 | 72520 | int res; |
| @@ -72200,10 +72522,13 @@ | ||
| 72200 | 72522 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 72201 | 72523 | pC = p->apCsr[pOp->p1]; |
| 72202 | 72524 | assert( pC!=0 ); |
| 72203 | 72525 | assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); |
| 72204 | 72526 | res = 1; |
| 72527 | +#ifdef SQLITE_DEBUG | |
| 72528 | + pC->seekOp = OP_Rewind; | |
| 72529 | +#endif | |
| 72205 | 72530 | if( isSorter(pC) ){ |
| 72206 | 72531 | rc = sqlite3VdbeSorterRewind(db, pC, &res); |
| 72207 | 72532 | }else{ |
| 72208 | 72533 | pCrsr = pC->pCursor; |
| 72209 | 72534 | assert( pCrsr ); |
| @@ -72225,10 +72550,14 @@ | ||
| 72225 | 72550 | ** |
| 72226 | 72551 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 72227 | 72552 | ** table or index. If there are no more key/value pairs then fall through |
| 72228 | 72553 | ** to the following instruction. But if the cursor advance was successful, |
| 72229 | 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. | |
| 72230 | 72559 | ** |
| 72231 | 72560 | ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have |
| 72232 | 72561 | ** been opened prior to this opcode or the program will segfault. |
| 72233 | 72562 | ** |
| 72234 | 72563 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| @@ -72244,20 +72573,25 @@ | ||
| 72244 | 72573 | ** |
| 72245 | 72574 | ** See also: Prev, NextIfOpen |
| 72246 | 72575 | */ |
| 72247 | 72576 | /* Opcode: NextIfOpen P1 P2 P3 P4 P5 |
| 72248 | 72577 | ** |
| 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 | |
| 72250 | 72579 | ** open it behaves a no-op. |
| 72251 | 72580 | */ |
| 72252 | 72581 | /* Opcode: Prev P1 P2 P3 P4 P5 |
| 72253 | 72582 | ** |
| 72254 | 72583 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 72255 | 72584 | ** table or index. If there is no previous key/value pairs then fall through |
| 72256 | 72585 | ** to the following instruction. But if the cursor backup was successful, |
| 72257 | 72586 | ** jump immediately to P2. |
| 72258 | 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 | +** | |
| 72259 | 72593 | ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is |
| 72260 | 72594 | ** not open then the behavior is undefined. |
| 72261 | 72595 | ** |
| 72262 | 72596 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 72263 | 72597 | ** means P1 is an SQL index and that this instruction could have been |
| @@ -72270,11 +72604,11 @@ | ||
| 72270 | 72604 | ** If P5 is positive and the jump is taken, then event counter |
| 72271 | 72605 | ** number P5-1 in the prepared statement is incremented. |
| 72272 | 72606 | */ |
| 72273 | 72607 | /* Opcode: PrevIfOpen P1 P2 P3 P4 P5 |
| 72274 | 72608 | ** |
| 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 | |
| 72276 | 72610 | ** open it behaves a no-op. |
| 72277 | 72611 | */ |
| 72278 | 72612 | case OP_SorterNext: { /* jump */ |
| 72279 | 72613 | VdbeCursor *pC; |
| 72280 | 72614 | int res; |
| @@ -72301,10 +72635,20 @@ | ||
| 72301 | 72635 | testcase( res==1 ); |
| 72302 | 72636 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 72303 | 72637 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 72304 | 72638 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 72305 | 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 | + | |
| 72306 | 72650 | rc = pOp->p4.xAdvance(pC->pCursor, &res); |
| 72307 | 72651 | next_tail: |
| 72308 | 72652 | pC->cacheStatus = CACHE_STALE; |
| 72309 | 72653 | VdbeBranchTaken(res==0,2); |
| 72310 | 72654 | if( res==0 ){ |
| @@ -72781,11 +73125,12 @@ | ||
| 72781 | 73125 | |
| 72782 | 73126 | /* Opcode: DropTable P1 * * P4 * |
| 72783 | 73127 | ** |
| 72784 | 73128 | ** Remove the internal (in-memory) data structures that describe |
| 72785 | 73129 | ** 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 | |
| 72787 | 73132 | ** schema consistent with what is on disk. |
| 72788 | 73133 | */ |
| 72789 | 73134 | case OP_DropTable: { |
| 72790 | 73135 | sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z); |
| 72791 | 73136 | break; |
| @@ -72793,11 +73138,12 @@ | ||
| 72793 | 73138 | |
| 72794 | 73139 | /* Opcode: DropIndex P1 * * P4 * |
| 72795 | 73140 | ** |
| 72796 | 73141 | ** Remove the internal (in-memory) data structures that describe |
| 72797 | 73142 | ** 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 | |
| 72799 | 73145 | ** schema consistent with what is on disk. |
| 72800 | 73146 | */ |
| 72801 | 73147 | case OP_DropIndex: { |
| 72802 | 73148 | sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z); |
| 72803 | 73149 | break; |
| @@ -72805,11 +73151,12 @@ | ||
| 72805 | 73151 | |
| 72806 | 73152 | /* Opcode: DropTrigger P1 * * P4 * |
| 72807 | 73153 | ** |
| 72808 | 73154 | ** Remove the internal (in-memory) data structures that describe |
| 72809 | 73155 | ** 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 | |
| 72811 | 73158 | ** schema consistent with what is on disk. |
| 72812 | 73159 | */ |
| 72813 | 73160 | case OP_DropTrigger: { |
| 72814 | 73161 | sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z); |
| 72815 | 73162 | break; |
| @@ -75011,11 +75358,11 @@ | ||
| 75011 | 75358 | ** If pKey2 is passed a NULL pointer, then it is assumed that the pCsr->aSpace |
| 75012 | 75359 | ** has been allocated and contains an unpacked record that is used as key2. |
| 75013 | 75360 | */ |
| 75014 | 75361 | static void vdbeSorterCompare( |
| 75015 | 75362 | const VdbeCursor *pCsr, /* Cursor object (for pKeyInfo) */ |
| 75016 | - int nIgnore, /* Ignore the last nIgnore fields */ | |
| 75363 | + int nKeyCol, /* Num of columns. 0 means "all" */ | |
| 75017 | 75364 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 75018 | 75365 | const void *pKey2, int nKey2, /* Right side of comparison */ |
| 75019 | 75366 | int *pRes /* OUT: Result of comparison */ |
| 75020 | 75367 | ){ |
| 75021 | 75368 | KeyInfo *pKeyInfo = pCsr->pKeyInfo; |
| @@ -75025,14 +75372,13 @@ | ||
| 75025 | 75372 | |
| 75026 | 75373 | if( pKey2 ){ |
| 75027 | 75374 | sqlite3VdbeRecordUnpack(pKeyInfo, nKey2, pKey2, r2); |
| 75028 | 75375 | } |
| 75029 | 75376 | |
| 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++){ | |
| 75034 | 75380 | if( r2->aMem[i].flags & MEM_Null ){ |
| 75035 | 75381 | *pRes = -1; |
| 75036 | 75382 | return; |
| 75037 | 75383 | } |
| 75038 | 75384 | } |
| @@ -75710,18 +76056,18 @@ | ||
| 75710 | 76056 | ** key. |
| 75711 | 76057 | */ |
| 75712 | 76058 | SQLITE_PRIVATE int sqlite3VdbeSorterCompare( |
| 75713 | 76059 | const VdbeCursor *pCsr, /* Sorter cursor */ |
| 75714 | 76060 | 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 */ | |
| 75716 | 76062 | int *pRes /* OUT: Result of comparison */ |
| 75717 | 76063 | ){ |
| 75718 | 76064 | VdbeSorter *pSorter = pCsr->pSorter; |
| 75719 | 76065 | void *pKey; int nKey; /* Sorter key to compare pVal with */ |
| 75720 | 76066 | |
| 75721 | 76067 | 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); | |
| 75723 | 76069 | return SQLITE_OK; |
| 75724 | 76070 | } |
| 75725 | 76071 | |
| 75726 | 76072 | /************** End of vdbesort.c ********************************************/ |
| 75727 | 76073 | /************** Begin file journal.c *****************************************/ |
| @@ -79474,11 +79820,11 @@ | ||
| 79474 | 79820 | } |
| 79475 | 79821 | } |
| 79476 | 79822 | } |
| 79477 | 79823 | |
| 79478 | 79824 | 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. | |
| 79480 | 79826 | ** We will have to generate an ephemeral table to do the job. |
| 79481 | 79827 | */ |
| 79482 | 79828 | u32 savedNQueryLoop = pParse->nQueryLoop; |
| 79483 | 79829 | int rMayHaveNull = 0; |
| 79484 | 79830 | eType = IN_INDEX_EPH; |
| @@ -79604,24 +79950,27 @@ | ||
| 79604 | 79950 | /* Case 1: expr IN (SELECT ...) |
| 79605 | 79951 | ** |
| 79606 | 79952 | ** Generate code to write the results of the select into the temporary |
| 79607 | 79953 | ** table allocated and opened above. |
| 79608 | 79954 | */ |
| 79955 | + Select *pSelect = pExpr->x.pSelect; | |
| 79609 | 79956 | SelectDest dest; |
| 79610 | 79957 | ExprList *pEList; |
| 79611 | 79958 | |
| 79612 | 79959 | assert( !isRowid ); |
| 79613 | 79960 | sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable); |
| 79614 | 79961 | dest.affSdst = (u8)affinity; |
| 79615 | 79962 | 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; | |
| 79617 | 79966 | testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */ |
| 79618 | - if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){ | |
| 79967 | + if( sqlite3Select(pParse, pSelect, &dest) ){ | |
| 79619 | 79968 | sqlite3KeyInfoUnref(pKeyInfo); |
| 79620 | 79969 | return 0; |
| 79621 | 79970 | } |
| 79622 | - pEList = pExpr->x.pSelect->pEList; | |
| 79971 | + pEList = pSelect->pEList; | |
| 79623 | 79972 | assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */ |
| 79624 | 79973 | assert( pEList!=0 ); |
| 79625 | 79974 | assert( pEList->nExpr>0 ); |
| 79626 | 79975 | assert( sqlite3KeyInfoIsWriteable(pKeyInfo) ); |
| 79627 | 79976 | pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, |
| @@ -83315,19 +83664,24 @@ | ||
| 83315 | 83664 | } |
| 83316 | 83665 | |
| 83317 | 83666 | /* |
| 83318 | 83667 | ** Implementation of the stat_init(N,K,C) SQL function. The three parameters |
| 83319 | 83668 | ** 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. | |
| 83329 | 83683 | ** |
| 83330 | 83684 | ** This routine allocates the Stat4Accum object in heap memory. The return |
| 83331 | 83685 | ** value is a pointer to the the Stat4Accum object encoded as a blob (i.e. |
| 83332 | 83686 | ** the size of the blob is sizeof(void*) bytes). |
| 83333 | 83687 | */ |
| @@ -83633,11 +83987,14 @@ | ||
| 83633 | 83987 | ** P Pointer to the Stat4Accum object created by stat_init() |
| 83634 | 83988 | ** C Index of left-most column to differ from previous row |
| 83635 | 83989 | ** R Rowid for the current row. Might be a key record for |
| 83636 | 83990 | ** WITHOUT ROWID tables. |
| 83637 | 83991 | ** |
| 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. | |
| 83639 | 83996 | ** |
| 83640 | 83997 | ** The R parameter is only used for STAT3 and STAT4 |
| 83641 | 83998 | */ |
| 83642 | 83999 | static void statPush( |
| 83643 | 84000 | sqlite3_context *context, |
| @@ -83727,11 +84084,14 @@ | ||
| 83727 | 84084 | #define STAT_GET_NLT 3 /* "nlt" column of stat[34] entry */ |
| 83728 | 84085 | #define STAT_GET_NDLT 4 /* "ndlt" column of stat[34] entry */ |
| 83729 | 84086 | |
| 83730 | 84087 | /* |
| 83731 | 84088 | ** 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 | |
| 83733 | 84093 | ** which is one of the STAT_GET_xxxx values defined above. |
| 83734 | 84094 | ** |
| 83735 | 84095 | ** If neither STAT3 nor STAT4 are enabled, then J is always |
| 83736 | 84096 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| 83737 | 84097 | ** a one-parameter function, stat_get(P), that always returns the |
| @@ -83946,28 +84306,27 @@ | ||
| 83946 | 84306 | pParse->nTab = MAX(pParse->nTab, iTab); |
| 83947 | 84307 | sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); |
| 83948 | 84308 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0); |
| 83949 | 84309 | |
| 83950 | 84310 | 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" */ | |
| 83953 | 84312 | int addrRewind; /* Address of "OP_Rewind iIdxCur" */ |
| 83954 | - int addrGotoChng0; /* Address of "Goto addr_chng_0" */ | |
| 83955 | 84313 | int addrNextRow; /* Address of "next_row:" */ |
| 83956 | 84314 | const char *zIdxName; /* Name of the index */ |
| 84315 | + int nColTest; /* Number of columns to test for changes */ | |
| 83957 | 84316 | |
| 83958 | 84317 | if( pOnlyIdx && pOnlyIdx!=pIdx ) continue; |
| 83959 | 84318 | if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0; |
| 83960 | 84319 | if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){ |
| 83961 | 84320 | nCol = pIdx->nKeyCol; |
| 83962 | 84321 | zIdxName = pTab->zName; |
| 84322 | + nColTest = nCol - 1; | |
| 83963 | 84323 | }else{ |
| 83964 | 84324 | nCol = pIdx->nColumn; |
| 83965 | 84325 | zIdxName = pIdx->zName; |
| 84326 | + nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1; | |
| 83966 | 84327 | } |
| 83967 | - aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1)); | |
| 83968 | - if( aGotoChng==0 ) continue; | |
| 83969 | 84328 | |
| 83970 | 84329 | /* Populate the register containing the index name. */ |
| 83971 | 84330 | sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0); |
| 83972 | 84331 | VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName)); |
| 83973 | 84332 | |
| @@ -83992,11 +84351,11 @@ | ||
| 83992 | 84351 | ** regPrev(0) = idx(0) |
| 83993 | 84352 | ** chng_addr_1: |
| 83994 | 84353 | ** regPrev(1) = idx(1) |
| 83995 | 84354 | ** ... |
| 83996 | 84355 | ** |
| 83997 | - ** chng_addr_N: | |
| 84356 | + ** endDistinctTest: | |
| 83998 | 84357 | ** regRowid = idx(rowid) |
| 83999 | 84358 | ** stat_push(P, regChng, regRowid) |
| 84000 | 84359 | ** Next csr |
| 84001 | 84360 | ** if !eof(csr) goto next_row; |
| 84002 | 84361 | ** |
| @@ -84005,24 +84364,27 @@ | ||
| 84005 | 84364 | |
| 84006 | 84365 | /* Make sure there are enough memory cells allocated to accommodate |
| 84007 | 84366 | ** the regPrev array and a trailing rowid (the rowid slot is required |
| 84008 | 84367 | ** when building a record to insert into the sample column of |
| 84009 | 84368 | ** the sqlite_stat4 table. */ |
| 84010 | - pParse->nMem = MAX(pParse->nMem, regPrev+nCol); | |
| 84369 | + pParse->nMem = MAX(pParse->nMem, regPrev+nColTest); | |
| 84011 | 84370 | |
| 84012 | 84371 | /* Open a read-only cursor on the index being analyzed. */ |
| 84013 | 84372 | assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) ); |
| 84014 | 84373 | sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb); |
| 84015 | 84374 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 84016 | 84375 | VdbeComment((v, "%s", pIdx->zName)); |
| 84017 | 84376 | |
| 84018 | 84377 | /* Invoke the stat_init() function. The arguments are: |
| 84019 | 84378 | ** |
| 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, | |
| 84022 | 84383 | ** |
| 84023 | - ** The second argument is only used for STAT3 and STAT4 | |
| 84384 | + ** | |
| 84385 | + ** The third argument is only used for STAT3 and STAT4 | |
| 84024 | 84386 | */ |
| 84025 | 84387 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 84026 | 84388 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3); |
| 84027 | 84389 | #endif |
| 84028 | 84390 | sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1); |
| @@ -84040,56 +84402,73 @@ | ||
| 84040 | 84402 | ** |
| 84041 | 84403 | */ |
| 84042 | 84404 | addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); |
| 84043 | 84405 | VdbeCoverage(v); |
| 84044 | 84406 | 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 | 84407 | 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 | + | |
| 84083 | 84463 | /* |
| 84084 | 84464 | ** chng_addr_N: |
| 84085 | 84465 | ** regRowid = idx(rowid) // STAT34 only |
| 84086 | 84466 | ** stat_push(P, regChng, regRowid) // 3rd parameter STAT34 only |
| 84087 | 84467 | ** Next csr |
| 84088 | 84468 | ** if !eof(csr) goto next_row; |
| 84089 | 84469 | */ |
| 84090 | - sqlite3VdbeJumpHere(v, aGotoChng[nCol]); | |
| 84091 | 84470 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 84092 | 84471 | assert( regRowid==(regStat4+2) ); |
| 84093 | 84472 | if( HasRowid(pTab) ){ |
| 84094 | 84473 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid); |
| 84095 | 84474 | }else{ |
| @@ -84163,11 +84542,10 @@ | ||
| 84163 | 84542 | } |
| 84164 | 84543 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 84165 | 84544 | |
| 84166 | 84545 | /* End of analysis */ |
| 84167 | 84546 | sqlite3VdbeJumpHere(v, addrRewind); |
| 84168 | - sqlite3DbFree(db, aGotoChng); | |
| 84169 | 84547 | } |
| 84170 | 84548 | |
| 84171 | 84549 | |
| 84172 | 84550 | /* Create a single sqlite_stat1 entry containing NULL as the index |
| 84173 | 84551 | ** name and the row count as the content. |
| @@ -88308,11 +88686,11 @@ | ||
| 88308 | 88686 | if( pIndex->onError!=OE_None && pKey!=0 ){ |
| 88309 | 88687 | int j2 = sqlite3VdbeCurrentAddr(v) + 3; |
| 88310 | 88688 | sqlite3VdbeAddOp2(v, OP_Goto, 0, j2); |
| 88311 | 88689 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 88312 | 88690 | sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord, |
| 88313 | - pKey->nField - pIndex->nKeyCol); VdbeCoverage(v); | |
| 88691 | + pIndex->nKeyCol); VdbeCoverage(v); | |
| 88314 | 88692 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 88315 | 88693 | }else{ |
| 88316 | 88694 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 88317 | 88695 | } |
| 88318 | 88696 | sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); |
| @@ -98186,11 +98564,11 @@ | ||
| 98186 | 98564 | ** Note that the values returned are one less that the values that |
| 98187 | 98565 | ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
| 98188 | 98566 | ** to support legacy SQL code. The safety level used to be boolean |
| 98189 | 98567 | ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 98190 | 98568 | */ |
| 98191 | -static u8 getSafetyLevel(const char *z, int omitFull, int dflt){ | |
| 98569 | +static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt){ | |
| 98192 | 98570 | /* 123456789 123456789 */ |
| 98193 | 98571 | static const char zText[] = "onoffalseyestruefull"; |
| 98194 | 98572 | static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; |
| 98195 | 98573 | static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; |
| 98196 | 98574 | static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; |
| @@ -98208,11 +98586,11 @@ | ||
| 98208 | 98586 | } |
| 98209 | 98587 | |
| 98210 | 98588 | /* |
| 98211 | 98589 | ** Interpret the given string as a boolean value. |
| 98212 | 98590 | */ |
| 98213 | -SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, int dflt){ | |
| 98591 | +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z, u8 dflt){ | |
| 98214 | 98592 | return getSafetyLevel(z,1,dflt)!=0; |
| 98215 | 98593 | } |
| 98216 | 98594 | |
| 98217 | 98595 | /* The sqlite3GetBoolean() function is used by other modules but the |
| 98218 | 98596 | ** remainder of this file is specific to PRAGMA processing. So omit |
| @@ -112398,11 +112776,12 @@ | ||
| 112398 | 112776 | int nEq = pLoop->u.btree.nEq; |
| 112399 | 112777 | sqlite3 *db = pParse->db; |
| 112400 | 112778 | int nLower = -1; |
| 112401 | 112779 | int nUpper = p->nSample+1; |
| 112402 | 112780 | 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; | |
| 112404 | 112783 | CollSeq *pColl; |
| 112405 | 112784 | |
| 112406 | 112785 | sqlite3_value *p1 = 0; /* Value extracted from pLower */ |
| 112407 | 112786 | sqlite3_value *p2 = 0; /* Value extracted from pUpper */ |
| 112408 | 112787 | sqlite3_value *pVal = 0; /* Value extracted from record */ |
| @@ -122593,11 +122972,11 @@ | ||
| 122593 | 122972 | |
| 122594 | 122973 | /* |
| 122595 | 122974 | ** Return a static string containing the name corresponding to the error code |
| 122596 | 122975 | ** specified in the argument. |
| 122597 | 122976 | */ |
| 122598 | -#if defined(SQLITE_TEST) | |
| 122977 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) | |
| 122599 | 122978 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 122600 | 122979 | const char *zName = 0; |
| 122601 | 122980 | int i, origRc = rc; |
| 122602 | 122981 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 122603 | 122982 | switch( rc ){ |
| @@ -124897,10 +125276,20 @@ | ||
| 124897 | 125276 | sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback); |
| 124898 | 125277 | sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*); |
| 124899 | 125278 | #endif |
| 124900 | 125279 | break; |
| 124901 | 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 | + } | |
| 124902 | 125291 | |
| 124903 | 125292 | } |
| 124904 | 125293 | va_end(ap); |
| 124905 | 125294 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 124906 | 125295 | return rc; |
| @@ -145542,13 +145931,17 @@ | ||
| 145542 | 145931 | int rc = SQLITE_OK; |
| 145543 | 145932 | int iCell = 0; |
| 145544 | 145933 | |
| 145545 | 145934 | rtreeReference(pRtree); |
| 145546 | 145935 | |
| 145936 | + /* Reset the cursor to the same state as rtreeOpen() leaves it in. */ | |
| 145547 | 145937 | freeCursorConstraints(pCsr); |
| 145938 | + sqlite3_free(pCsr->aPoint); | |
| 145939 | + memset(pCsr, 0, sizeof(RtreeCursor)); | |
| 145940 | + pCsr->base.pVtab = (sqlite3_vtab*)pRtree; | |
| 145941 | + | |
| 145548 | 145942 | pCsr->iStrategy = idxNum; |
| 145549 | - | |
| 145550 | 145943 | if( idxNum==1 ){ |
| 145551 | 145944 | /* Special case - lookup by rowid. */ |
| 145552 | 145945 | RtreeNode *pLeaf; /* Leaf on which the required cell resides */ |
| 145553 | 145946 | RtreeSearchPoint *p; /* Search point for the the leaf */ |
| 145554 | 145947 | i64 iRowid = sqlite3_value_int64(argv[0]); |
| 145555 | 145948 |
| --- 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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.6" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -5878,14 +5878,16 @@ | ||
| 5878 | 5878 | ** <ul> |
| 5879 | 5879 | ** <li> SQLITE_MUTEX_FAST |
| 5880 | 5880 | ** <li> SQLITE_MUTEX_RECURSIVE |
| 5881 | 5881 | ** <li> SQLITE_MUTEX_STATIC_MASTER |
| 5882 | 5882 | ** <li> SQLITE_MUTEX_STATIC_MEM |
| 5883 | -** <li> SQLITE_MUTEX_STATIC_MEM2 | |
| 5883 | +** <li> SQLITE_MUTEX_STATIC_OPEN | |
| 5884 | 5884 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 5885 | 5885 | ** <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 | |
| 5887 | 5889 | ** </ul>)^ |
| 5888 | 5890 | ** |
| 5889 | 5891 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 5890 | 5892 | ** cause sqlite3_mutex_alloc() to create |
| 5891 | 5893 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| @@ -6085,10 +6087,13 @@ | ||
| 6085 | 6087 | #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
| 6086 | 6088 | #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ |
| 6087 | 6089 | #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
| 6088 | 6090 | #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ |
| 6089 | 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 */ | |
| 6090 | 6095 | |
| 6091 | 6096 | /* |
| 6092 | 6097 | ** CAPI3REF: Retrieve the mutex for a database connection |
| 6093 | 6098 | ** |
| 6094 | 6099 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| @@ -6180,11 +6185,12 @@ | ||
| 6180 | 6185 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 6181 | 6186 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 |
| 6182 | 6187 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 6183 | 6188 | #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
| 6184 | 6189 | #define SQLITE_TESTCTRL_BYTEORDER 22 |
| 6185 | -#define SQLITE_TESTCTRL_LAST 22 | |
| 6190 | +#define SQLITE_TESTCTRL_ISINIT 23 | |
| 6191 | +#define SQLITE_TESTCTRL_LAST 23 | |
| 6186 | 6192 | |
| 6187 | 6193 | /* |
| 6188 | 6194 | ** CAPI3REF: SQLite Runtime Status |
| 6189 | 6195 | ** |
| 6190 | 6196 | ** ^This interface is used to retrieve runtime status information |
| 6191 | 6197 |
| --- 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 |