| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.20.1. By combining all the individual C code files into this |
| 3 | +** version 3.21.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -206,10 +206,13 @@ |
| 206 | 206 | #if SQLITE_ENABLE_API_ARMOR |
| 207 | 207 | "ENABLE_API_ARMOR", |
| 208 | 208 | #endif |
| 209 | 209 | #if SQLITE_ENABLE_ATOMIC_WRITE |
| 210 | 210 | "ENABLE_ATOMIC_WRITE", |
| 211 | +#endif |
| 212 | +#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 213 | + "ENABLE_BATCH_ATOMIC_WRITE", |
| 211 | 214 | #endif |
| 212 | 215 | #if SQLITE_ENABLE_CEROD |
| 213 | 216 | "ENABLE_CEROD", |
| 214 | 217 | #endif |
| 215 | 218 | #if SQLITE_ENABLE_COLUMN_METADATA |
| | @@ -825,18 +828,10 @@ |
| 825 | 828 | */ |
| 826 | 829 | #ifndef SQLITE_TCLAPI |
| 827 | 830 | # define SQLITE_TCLAPI |
| 828 | 831 | #endif |
| 829 | 832 | |
| 830 | | -/* |
| 831 | | -** Make sure that rand_s() is available on Windows systems with MSVC 2005 |
| 832 | | -** or higher. |
| 833 | | -*/ |
| 834 | | -#if defined(_MSC_VER) && _MSC_VER>=1400 |
| 835 | | -# define _CRT_RAND_S |
| 836 | | -#endif |
| 837 | | - |
| 838 | 833 | /* |
| 839 | 834 | ** Include the header file used to customize the compiler options for MSVC. |
| 840 | 835 | ** This should be done first so that it can successfully prevent spurious |
| 841 | 836 | ** compiler warnings due to subsequent content in this file and other files |
| 842 | 837 | ** that are included by this file. |
| | @@ -1142,19 +1137,21 @@ |
| 1142 | 1137 | ** <a href="http://www.fossil-scm.org/">Fossil configuration management |
| 1143 | 1138 | ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to |
| 1144 | 1139 | ** a string which identifies a particular check-in of SQLite |
| 1145 | 1140 | ** within its configuration management system. ^The SQLITE_SOURCE_ID |
| 1146 | 1141 | ** string contains the date and time of the check-in (UTC) and a SHA1 |
| 1147 | | -** or SHA3-256 hash of the entire source tree. |
| 1142 | +** or SHA3-256 hash of the entire source tree. If the source code has |
| 1143 | +** been edited in any way since it was last checked in, then the last |
| 1144 | +** four hexadecimal digits of the hash may be modified. |
| 1148 | 1145 | ** |
| 1149 | 1146 | ** See also: [sqlite3_libversion()], |
| 1150 | 1147 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1151 | 1148 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1152 | 1149 | */ |
| 1153 | | -#define SQLITE_VERSION "3.20.1" |
| 1154 | | -#define SQLITE_VERSION_NUMBER 3020001 |
| 1155 | | -#define SQLITE_SOURCE_ID "2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34" |
| 1150 | +#define SQLITE_VERSION "3.21.0" |
| 1151 | +#define SQLITE_VERSION_NUMBER 3021000 |
| 1152 | +#define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595c9d0" |
| 1156 | 1153 | |
| 1157 | 1154 | /* |
| 1158 | 1155 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1159 | 1156 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1160 | 1157 | ** |
| | @@ -1166,23 +1163,25 @@ |
| 1166 | 1163 | ** the header, and thus ensure that the application is |
| 1167 | 1164 | ** compiled with matching library and header files. |
| 1168 | 1165 | ** |
| 1169 | 1166 | ** <blockquote><pre> |
| 1170 | 1167 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 1171 | | -** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| 1168 | +** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 ); |
| 1172 | 1169 | ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); |
| 1173 | 1170 | ** </pre></blockquote>)^ |
| 1174 | 1171 | ** |
| 1175 | 1172 | ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] |
| 1176 | 1173 | ** macro. ^The sqlite3_libversion() function returns a pointer to the |
| 1177 | 1174 | ** to the sqlite3_version[] string constant. The sqlite3_libversion() |
| 1178 | 1175 | ** function is provided for use in DLLs since DLL users usually do not have |
| 1179 | 1176 | ** direct access to string constants within the DLL. ^The |
| 1180 | 1177 | ** sqlite3_libversion_number() function returns an integer equal to |
| 1181 | | -** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns |
| 1178 | +** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns |
| 1182 | 1179 | ** a pointer to a string constant whose value is the same as the |
| 1183 | | -** [SQLITE_SOURCE_ID] C preprocessor macro. |
| 1180 | +** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built |
| 1181 | +** using an edited copy of [the amalgamation], then the last four characters |
| 1182 | +** of the hash might be different from [SQLITE_SOURCE_ID].)^ |
| 1184 | 1183 | ** |
| 1185 | 1184 | ** See also: [sqlite_version()] and [sqlite_source_id()]. |
| 1186 | 1185 | */ |
| 1187 | 1186 | SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
| 1188 | 1187 | SQLITE_API const char *sqlite3_libversion(void); |
| | @@ -1459,11 +1458,11 @@ |
| 1459 | 1458 | #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ |
| 1460 | 1459 | #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ |
| 1461 | 1460 | #define SQLITE_FULL 13 /* Insertion failed because database is full */ |
| 1462 | 1461 | #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ |
| 1463 | 1462 | #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ |
| 1464 | | -#define SQLITE_EMPTY 16 /* Not used */ |
| 1463 | +#define SQLITE_EMPTY 16 /* Internal use only */ |
| 1465 | 1464 | #define SQLITE_SCHEMA 17 /* The database schema changed */ |
| 1466 | 1465 | #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ |
| 1467 | 1466 | #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ |
| 1468 | 1467 | #define SQLITE_MISMATCH 20 /* Data type mismatch */ |
| 1469 | 1468 | #define SQLITE_MISUSE 21 /* Library used incorrectly */ |
| | @@ -1521,10 +1520,13 @@ |
| 1521 | 1520 | #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) |
| 1522 | 1521 | #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) |
| 1523 | 1522 | #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) |
| 1524 | 1523 | #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) |
| 1525 | 1524 | #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) |
| 1525 | +#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) |
| 1526 | +#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) |
| 1527 | +#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) |
| 1526 | 1528 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1527 | 1529 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1528 | 1530 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1529 | 1531 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1530 | 1532 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| | @@ -1607,10 +1609,15 @@ |
| 1607 | 1609 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 1608 | 1610 | ** flag indicates that a file cannot be deleted when open. The |
| 1609 | 1611 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 1610 | 1612 | ** read-only media and cannot be changed even by processes with |
| 1611 | 1613 | ** elevated privileges. |
| 1614 | +** |
| 1615 | +** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying |
| 1616 | +** filesystem supports doing multiple write operations atomically when those |
| 1617 | +** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and |
| 1618 | +** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. |
| 1612 | 1619 | */ |
| 1613 | 1620 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 1614 | 1621 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 1615 | 1622 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 1616 | 1623 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| | @@ -1622,10 +1629,11 @@ |
| 1622 | 1629 | #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 |
| 1623 | 1630 | #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 |
| 1624 | 1631 | #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 |
| 1625 | 1632 | #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 |
| 1626 | 1633 | #define SQLITE_IOCAP_IMMUTABLE 0x00002000 |
| 1634 | +#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 |
| 1627 | 1635 | |
| 1628 | 1636 | /* |
| 1629 | 1637 | ** CAPI3REF: File Locking Levels |
| 1630 | 1638 | ** |
| 1631 | 1639 | ** SQLite uses one of these integer values as the second |
| | @@ -1756,10 +1764,11 @@ |
| 1756 | 1764 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 1757 | 1765 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 1758 | 1766 | ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
| 1759 | 1767 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
| 1760 | 1768 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
| 1769 | +** <li> [SQLITE_IOCAP_BATCH_ATOMIC] |
| 1761 | 1770 | ** </ul> |
| 1762 | 1771 | ** |
| 1763 | 1772 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 1764 | 1773 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 1765 | 1774 | ** mean that writes of blocks that are nnn bytes in size and |
| | @@ -2039,10 +2048,44 @@ |
| 2039 | 2048 | ** |
| 2040 | 2049 | ** <li>[[SQLITE_FCNTL_RBU]] |
| 2041 | 2050 | ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by |
| 2042 | 2051 | ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for |
| 2043 | 2052 | ** this opcode. |
| 2053 | +** |
| 2054 | +** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]] |
| 2055 | +** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then |
| 2056 | +** the file descriptor is placed in "batch write mode", which |
| 2057 | +** means all subsequent write operations will be deferred and done |
| 2058 | +** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems |
| 2059 | +** that do not support batch atomic writes will return SQLITE_NOTFOUND. |
| 2060 | +** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to |
| 2061 | +** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or |
| 2062 | +** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make |
| 2063 | +** no VFS interface calls on the same [sqlite3_file] file descriptor |
| 2064 | +** except for calls to the xWrite method and the xFileControl method |
| 2065 | +** with [SQLITE_FCNTL_SIZE_HINT]. |
| 2066 | +** |
| 2067 | +** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]] |
| 2068 | +** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write |
| 2069 | +** operations since the previous successful call to |
| 2070 | +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically. |
| 2071 | +** This file control returns [SQLITE_OK] if and only if the writes were |
| 2072 | +** all performed successfully and have been committed to persistent storage. |
| 2073 | +** ^Regardless of whether or not it is successful, this file control takes |
| 2074 | +** the file descriptor out of batch write mode so that all subsequent |
| 2075 | +** write operations are independent. |
| 2076 | +** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without |
| 2077 | +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
| 2078 | +** |
| 2079 | +** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]] |
| 2080 | +** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write |
| 2081 | +** operations since the previous successful call to |
| 2082 | +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back. |
| 2083 | +** ^This file control takes the file descriptor out of batch write mode |
| 2084 | +** so that all subsequent write operations are independent. |
| 2085 | +** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without |
| 2086 | +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
| 2044 | 2087 | ** </ul> |
| 2045 | 2088 | */ |
| 2046 | 2089 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 2047 | 2090 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
| 2048 | 2091 | #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
| | @@ -2070,10 +2113,13 @@ |
| 2070 | 2113 | #define SQLITE_FCNTL_RBU 26 |
| 2071 | 2114 | #define SQLITE_FCNTL_VFS_POINTER 27 |
| 2072 | 2115 | #define SQLITE_FCNTL_JOURNAL_POINTER 28 |
| 2073 | 2116 | #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 |
| 2074 | 2117 | #define SQLITE_FCNTL_PDB 30 |
| 2118 | +#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 |
| 2119 | +#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 |
| 2120 | +#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 |
| 2075 | 2121 | |
| 2076 | 2122 | /* deprecated names */ |
| 2077 | 2123 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 2078 | 2124 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 2079 | 2125 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -2639,10 +2685,20 @@ |
| 2639 | 2685 | ** The [sqlite3_mem_methods] |
| 2640 | 2686 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 2641 | 2687 | ** This option can be used to overload the default memory allocation |
| 2642 | 2688 | ** routines with a wrapper that simulations memory allocation failure or |
| 2643 | 2689 | ** tracks memory usage, for example. </dd> |
| 2690 | +** |
| 2691 | +** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt> |
| 2692 | +** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of |
| 2693 | +** type int, interpreted as a boolean, which if true provides a hint to |
| 2694 | +** SQLite that it should avoid large memory allocations if possible. |
| 2695 | +** SQLite will run faster if it is free to make large memory allocations, |
| 2696 | +** but some application might prefer to run slower in exchange for |
| 2697 | +** guarantees about memory fragmentation that are possible if large |
| 2698 | +** allocations are avoided. This hint is normally off. |
| 2699 | +** </dd> |
| 2644 | 2700 | ** |
| 2645 | 2701 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 2646 | 2702 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 2647 | 2703 | ** interpreted as a boolean, which enables or disables the collection of |
| 2648 | 2704 | ** memory allocation statistics. ^(When memory allocation statistics are |
| | @@ -2657,29 +2713,11 @@ |
| 2657 | 2713 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 2658 | 2714 | ** allocation statistics are disabled by default. |
| 2659 | 2715 | ** </dd> |
| 2660 | 2716 | ** |
| 2661 | 2717 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 2662 | | -** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer |
| 2663 | | -** that SQLite can use for scratch memory. ^(There are three arguments |
| 2664 | | -** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte |
| 2665 | | -** aligned memory buffer from which the scratch allocations will be |
| 2666 | | -** drawn, the size of each scratch allocation (sz), |
| 2667 | | -** and the maximum number of scratch allocations (N).)^ |
| 2668 | | -** The first argument must be a pointer to an 8-byte aligned buffer |
| 2669 | | -** of at least sz*N bytes of memory. |
| 2670 | | -** ^SQLite will not use more than one scratch buffers per thread. |
| 2671 | | -** ^SQLite will never request a scratch buffer that is more than 6 |
| 2672 | | -** times the database page size. |
| 2673 | | -** ^If SQLite needs needs additional |
| 2674 | | -** scratch memory beyond what is provided by this configuration option, then |
| 2675 | | -** [sqlite3_malloc()] will be used to obtain the memory needed.<p> |
| 2676 | | -** ^When the application provides any amount of scratch memory using |
| 2677 | | -** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large |
| 2678 | | -** [sqlite3_malloc|heap allocations]. |
| 2679 | | -** This can help [Robson proof|prevent memory allocation failures] due to heap |
| 2680 | | -** fragmentation in low-memory embedded systems. |
| 2718 | +** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used. |
| 2681 | 2719 | ** </dd> |
| 2682 | 2720 | ** |
| 2683 | 2721 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 2684 | 2722 | ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool |
| 2685 | 2723 | ** that SQLite can use for the database page cache with the default page |
| | @@ -2711,12 +2749,11 @@ |
| 2711 | 2749 | ** additional cache line. </dd> |
| 2712 | 2750 | ** |
| 2713 | 2751 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 2714 | 2752 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 2715 | 2753 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 2716 | | -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and |
| 2717 | | -** [SQLITE_CONFIG_PAGECACHE]. |
| 2754 | +** beyond those provided for by [SQLITE_CONFIG_PAGECACHE]. |
| 2718 | 2755 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 2719 | 2756 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 2720 | 2757 | ** [SQLITE_ERROR] if invoked otherwise. |
| 2721 | 2758 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 2722 | 2759 | ** An 8-byte aligned pointer to the memory, |
| | @@ -2905,11 +2942,11 @@ |
| 2905 | 2942 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2906 | 2943 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2907 | 2944 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 2908 | 2945 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| 2909 | 2946 | #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
| 2910 | | -#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ |
| 2947 | +#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ |
| 2911 | 2948 | #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
| 2912 | 2949 | #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
| 2913 | 2950 | #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
| 2914 | 2951 | #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
| 2915 | 2952 | #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
| | @@ -2926,10 +2963,11 @@ |
| 2926 | 2963 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 2927 | 2964 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 2928 | 2965 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2929 | 2966 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2930 | 2967 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2968 | +#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 2931 | 2969 | |
| 2932 | 2970 | /* |
| 2933 | 2971 | ** CAPI3REF: Database Connection Configuration Options |
| 2934 | 2972 | ** |
| 2935 | 2973 | ** These constants are the available integer configuration options that |
| | @@ -4126,14 +4164,14 @@ |
| 4126 | 4164 | ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
| 4127 | 4165 | ** |
| 4128 | 4166 | ** ^If [URI filename] interpretation is enabled, and the filename argument |
| 4129 | 4167 | ** begins with "file:", then the filename is interpreted as a URI. ^URI |
| 4130 | 4168 | ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
| 4131 | | -** set in the fourth argument to sqlite3_open_v2(), or if it has |
| 4169 | +** set in the third argument to sqlite3_open_v2(), or if it has |
| 4132 | 4170 | ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
| 4133 | 4171 | ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
| 4134 | | -** As of SQLite version 3.7.7, URI filename interpretation is turned off |
| 4172 | +** URI filename interpretation is turned off |
| 4135 | 4173 | ** by default, but future releases of SQLite might enable URI filename |
| 4136 | 4174 | ** interpretation by default. See "[URI filenames]" for additional |
| 4137 | 4175 | ** information. |
| 4138 | 4176 | ** |
| 4139 | 4177 | ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
| | @@ -4803,12 +4841,13 @@ |
| 4803 | 4841 | ** |
| 4804 | 4842 | ** ^The sqlite3_value objects that are passed as parameters into the |
| 4805 | 4843 | ** implementation of [application-defined SQL functions] are protected. |
| 4806 | 4844 | ** ^The sqlite3_value object returned by |
| 4807 | 4845 | ** [sqlite3_column_value()] is unprotected. |
| 4808 | | -** Unprotected sqlite3_value objects may only be used with |
| 4809 | | -** [sqlite3_result_value()] and [sqlite3_bind_value()]. |
| 4846 | +** Unprotected sqlite3_value objects may only be used as arguments |
| 4847 | +** to [sqlite3_result_value()], [sqlite3_bind_value()], and |
| 4848 | +** [sqlite3_value_dup()]. |
| 4810 | 4849 | ** The [sqlite3_value_blob | sqlite3_value_type()] family of |
| 4811 | 4850 | ** interfaces require protected sqlite3_value objects. |
| 4812 | 4851 | */ |
| 4813 | 4852 | typedef struct sqlite3_value sqlite3_value; |
| 4814 | 4853 | |
| | @@ -5226,11 +5265,11 @@ |
| 5226 | 5265 | ** For all versions of SQLite up to and including 3.6.23.1, a call to |
| 5227 | 5266 | ** [sqlite3_reset()] was required after sqlite3_step() returned anything |
| 5228 | 5267 | ** other than [SQLITE_ROW] before any subsequent invocation of |
| 5229 | 5268 | ** sqlite3_step(). Failure to reset the prepared statement using |
| 5230 | 5269 | ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from |
| 5231 | | -** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]), |
| 5270 | +** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1], |
| 5232 | 5271 | ** sqlite3_step() began |
| 5233 | 5272 | ** calling [sqlite3_reset()] automatically in this circumstance rather |
| 5234 | 5273 | ** than returning [SQLITE_MISUSE]. This is not considered a compatibility |
| 5235 | 5274 | ** break because any application that ever receives an SQLITE_MISUSE error |
| 5236 | 5275 | ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option |
| | @@ -7230,19 +7269,24 @@ |
| 7230 | 7269 | ** These macros defined the allowed values for the |
| 7231 | 7270 | ** [sqlite3_index_info].aConstraint[].op field. Each value represents |
| 7232 | 7271 | ** an operator that is part of a constraint term in the wHERE clause of |
| 7233 | 7272 | ** a query that uses a [virtual table]. |
| 7234 | 7273 | */ |
| 7235 | | -#define SQLITE_INDEX_CONSTRAINT_EQ 2 |
| 7236 | | -#define SQLITE_INDEX_CONSTRAINT_GT 4 |
| 7237 | | -#define SQLITE_INDEX_CONSTRAINT_LE 8 |
| 7238 | | -#define SQLITE_INDEX_CONSTRAINT_LT 16 |
| 7239 | | -#define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 7240 | | -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 7241 | | -#define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
| 7242 | | -#define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
| 7243 | | -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
| 7274 | +#define SQLITE_INDEX_CONSTRAINT_EQ 2 |
| 7275 | +#define SQLITE_INDEX_CONSTRAINT_GT 4 |
| 7276 | +#define SQLITE_INDEX_CONSTRAINT_LE 8 |
| 7277 | +#define SQLITE_INDEX_CONSTRAINT_LT 16 |
| 7278 | +#define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 7279 | +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 7280 | +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
| 7281 | +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
| 7282 | +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
| 7283 | +#define SQLITE_INDEX_CONSTRAINT_NE 68 |
| 7284 | +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 |
| 7285 | +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 |
| 7286 | +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 |
| 7287 | +#define SQLITE_INDEX_CONSTRAINT_IS 72 |
| 7244 | 7288 | |
| 7245 | 7289 | /* |
| 7246 | 7290 | ** CAPI3REF: Register A Virtual Table Implementation |
| 7247 | 7291 | ** METHOD: sqlite3 |
| 7248 | 7292 | ** |
| | @@ -7990,11 +8034,11 @@ |
| 7990 | 8034 | #define SQLITE_TESTCTRL_ASSERT 12 |
| 7991 | 8035 | #define SQLITE_TESTCTRL_ALWAYS 13 |
| 7992 | 8036 | #define SQLITE_TESTCTRL_RESERVE 14 |
| 7993 | 8037 | #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 |
| 7994 | 8038 | #define SQLITE_TESTCTRL_ISKEYWORD 16 |
| 7995 | | -#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 |
| 8039 | +#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ |
| 7996 | 8040 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 7997 | 8041 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ |
| 7998 | 8042 | #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 |
| 7999 | 8043 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 8000 | 8044 | #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
| | @@ -8049,12 +8093,11 @@ |
| 8049 | 8093 | ** <dl> |
| 8050 | 8094 | ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 8051 | 8095 | ** <dd>This parameter is the current amount of memory checked out |
| 8052 | 8096 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 8053 | 8097 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 8054 | | -** and internal memory usage by the SQLite library. Scratch memory |
| 8055 | | -** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 8098 | +** and internal memory usage by the SQLite library. Auxiliary page-cache |
| 8056 | 8099 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 8057 | 8100 | ** this parameter. The amount returned is the sum of the allocation |
| 8058 | 8101 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 8059 | 8102 | ** |
| 8060 | 8103 | ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| | @@ -8088,33 +8131,18 @@ |
| 8088 | 8131 | ** <dd>This parameter records the largest memory allocation request |
| 8089 | 8132 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 8090 | 8133 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 8091 | 8134 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 8092 | 8135 | ** |
| 8093 | | -** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 8094 | | -** <dd>This parameter returns the number of allocations used out of the |
| 8095 | | -** [scratch memory allocator] configured using |
| 8096 | | -** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 8097 | | -** in bytes. Since a single thread may only have one scratch allocation |
| 8098 | | -** outstanding at time, this parameter also reports the number of threads |
| 8099 | | -** using scratch memory at the same time.</dd>)^ |
| 8136 | +** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 8137 | +** <dd>No longer used.</dd> |
| 8100 | 8138 | ** |
| 8101 | 8139 | ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 8102 | | -** <dd>This parameter returns the number of bytes of scratch memory |
| 8103 | | -** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 8104 | | -** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 8105 | | -** returned include overflows because the requested allocation was too |
| 8106 | | -** larger (that is, because the requested allocation was larger than the |
| 8107 | | -** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 8108 | | -** slots were available. |
| 8109 | | -** </dd>)^ |
| 8140 | +** <dd>No longer used.</dd> |
| 8110 | 8141 | ** |
| 8111 | | -** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 8112 | | -** <dd>This parameter records the largest memory allocation request |
| 8113 | | -** handed to [scratch memory allocator]. Only the value returned in the |
| 8114 | | -** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 8115 | | -** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 8142 | +** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 8143 | +** <dd>No longer used.</dd> |
| 8116 | 8144 | ** |
| 8117 | 8145 | ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 8118 | 8146 | ** <dd>The *pHighwater parameter records the deepest parser stack. |
| 8119 | 8147 | ** The *pCurrent value is undefined. The *pHighwater value is only |
| 8120 | 8148 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| | @@ -8123,16 +8151,16 @@ |
| 8123 | 8151 | ** New status parameters may be added from time to time. |
| 8124 | 8152 | */ |
| 8125 | 8153 | #define SQLITE_STATUS_MEMORY_USED 0 |
| 8126 | 8154 | #define SQLITE_STATUS_PAGECACHE_USED 1 |
| 8127 | 8155 | #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 |
| 8128 | | -#define SQLITE_STATUS_SCRATCH_USED 3 |
| 8129 | | -#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 |
| 8156 | +#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */ |
| 8157 | +#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */ |
| 8130 | 8158 | #define SQLITE_STATUS_MALLOC_SIZE 5 |
| 8131 | 8159 | #define SQLITE_STATUS_PARSER_STACK 6 |
| 8132 | 8160 | #define SQLITE_STATUS_PAGECACHE_SIZE 7 |
| 8133 | | -#define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 8161 | +#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */ |
| 8134 | 8162 | #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 8135 | 8163 | |
| 8136 | 8164 | /* |
| 8137 | 8165 | ** CAPI3REF: Database Connection Status |
| 8138 | 8166 | ** METHOD: sqlite3 |
| | @@ -12412,67 +12440,67 @@ |
| 12412 | 12440 | #define TK_LP 22 |
| 12413 | 12441 | #define TK_RP 23 |
| 12414 | 12442 | #define TK_AS 24 |
| 12415 | 12443 | #define TK_WITHOUT 25 |
| 12416 | 12444 | #define TK_COMMA 26 |
| 12417 | | -#define TK_ID 27 |
| 12418 | | -#define TK_ABORT 28 |
| 12419 | | -#define TK_ACTION 29 |
| 12420 | | -#define TK_AFTER 30 |
| 12421 | | -#define TK_ANALYZE 31 |
| 12422 | | -#define TK_ASC 32 |
| 12423 | | -#define TK_ATTACH 33 |
| 12424 | | -#define TK_BEFORE 34 |
| 12425 | | -#define TK_BY 35 |
| 12426 | | -#define TK_CASCADE 36 |
| 12427 | | -#define TK_CAST 37 |
| 12428 | | -#define TK_COLUMNKW 38 |
| 12429 | | -#define TK_CONFLICT 39 |
| 12430 | | -#define TK_DATABASE 40 |
| 12431 | | -#define TK_DESC 41 |
| 12432 | | -#define TK_DETACH 42 |
| 12433 | | -#define TK_EACH 43 |
| 12434 | | -#define TK_FAIL 44 |
| 12435 | | -#define TK_FOR 45 |
| 12436 | | -#define TK_IGNORE 46 |
| 12437 | | -#define TK_INITIALLY 47 |
| 12438 | | -#define TK_INSTEAD 48 |
| 12439 | | -#define TK_LIKE_KW 49 |
| 12440 | | -#define TK_MATCH 50 |
| 12441 | | -#define TK_NO 51 |
| 12442 | | -#define TK_KEY 52 |
| 12443 | | -#define TK_OF 53 |
| 12444 | | -#define TK_OFFSET 54 |
| 12445 | | -#define TK_PRAGMA 55 |
| 12446 | | -#define TK_RAISE 56 |
| 12447 | | -#define TK_RECURSIVE 57 |
| 12448 | | -#define TK_REPLACE 58 |
| 12449 | | -#define TK_RESTRICT 59 |
| 12450 | | -#define TK_ROW 60 |
| 12451 | | -#define TK_TRIGGER 61 |
| 12452 | | -#define TK_VACUUM 62 |
| 12453 | | -#define TK_VIEW 63 |
| 12454 | | -#define TK_VIRTUAL 64 |
| 12455 | | -#define TK_WITH 65 |
| 12456 | | -#define TK_REINDEX 66 |
| 12457 | | -#define TK_RENAME 67 |
| 12458 | | -#define TK_CTIME_KW 68 |
| 12459 | | -#define TK_ANY 69 |
| 12460 | | -#define TK_OR 70 |
| 12461 | | -#define TK_AND 71 |
| 12462 | | -#define TK_IS 72 |
| 12463 | | -#define TK_BETWEEN 73 |
| 12464 | | -#define TK_IN 74 |
| 12465 | | -#define TK_ISNULL 75 |
| 12466 | | -#define TK_NOTNULL 76 |
| 12467 | | -#define TK_NE 77 |
| 12468 | | -#define TK_EQ 78 |
| 12469 | | -#define TK_GT 79 |
| 12470 | | -#define TK_LE 80 |
| 12471 | | -#define TK_LT 81 |
| 12472 | | -#define TK_GE 82 |
| 12473 | | -#define TK_ESCAPE 83 |
| 12445 | +#define TK_ABORT 27 |
| 12446 | +#define TK_ACTION 28 |
| 12447 | +#define TK_AFTER 29 |
| 12448 | +#define TK_ANALYZE 30 |
| 12449 | +#define TK_ASC 31 |
| 12450 | +#define TK_ATTACH 32 |
| 12451 | +#define TK_BEFORE 33 |
| 12452 | +#define TK_BY 34 |
| 12453 | +#define TK_CASCADE 35 |
| 12454 | +#define TK_CAST 36 |
| 12455 | +#define TK_CONFLICT 37 |
| 12456 | +#define TK_DATABASE 38 |
| 12457 | +#define TK_DESC 39 |
| 12458 | +#define TK_DETACH 40 |
| 12459 | +#define TK_EACH 41 |
| 12460 | +#define TK_FAIL 42 |
| 12461 | +#define TK_OR 43 |
| 12462 | +#define TK_AND 44 |
| 12463 | +#define TK_IS 45 |
| 12464 | +#define TK_MATCH 46 |
| 12465 | +#define TK_LIKE_KW 47 |
| 12466 | +#define TK_BETWEEN 48 |
| 12467 | +#define TK_IN 49 |
| 12468 | +#define TK_ISNULL 50 |
| 12469 | +#define TK_NOTNULL 51 |
| 12470 | +#define TK_NE 52 |
| 12471 | +#define TK_EQ 53 |
| 12472 | +#define TK_GT 54 |
| 12473 | +#define TK_LE 55 |
| 12474 | +#define TK_LT 56 |
| 12475 | +#define TK_GE 57 |
| 12476 | +#define TK_ESCAPE 58 |
| 12477 | +#define TK_ID 59 |
| 12478 | +#define TK_COLUMNKW 60 |
| 12479 | +#define TK_FOR 61 |
| 12480 | +#define TK_IGNORE 62 |
| 12481 | +#define TK_INITIALLY 63 |
| 12482 | +#define TK_INSTEAD 64 |
| 12483 | +#define TK_NO 65 |
| 12484 | +#define TK_KEY 66 |
| 12485 | +#define TK_OF 67 |
| 12486 | +#define TK_OFFSET 68 |
| 12487 | +#define TK_PRAGMA 69 |
| 12488 | +#define TK_RAISE 70 |
| 12489 | +#define TK_RECURSIVE 71 |
| 12490 | +#define TK_REPLACE 72 |
| 12491 | +#define TK_RESTRICT 73 |
| 12492 | +#define TK_ROW 74 |
| 12493 | +#define TK_TRIGGER 75 |
| 12494 | +#define TK_VACUUM 76 |
| 12495 | +#define TK_VIEW 77 |
| 12496 | +#define TK_VIRTUAL 78 |
| 12497 | +#define TK_WITH 79 |
| 12498 | +#define TK_REINDEX 80 |
| 12499 | +#define TK_RENAME 81 |
| 12500 | +#define TK_CTIME_KW 82 |
| 12501 | +#define TK_ANY 83 |
| 12474 | 12502 | #define TK_BITAND 84 |
| 12475 | 12503 | #define TK_BITOR 85 |
| 12476 | 12504 | #define TK_LSHIFT 86 |
| 12477 | 12505 | #define TK_RSHIFT 87 |
| 12478 | 12506 | #define TK_PLUS 88 |
| | @@ -12528,32 +12556,27 @@ |
| 12528 | 12556 | #define TK_THEN 138 |
| 12529 | 12557 | #define TK_ELSE 139 |
| 12530 | 12558 | #define TK_INDEX 140 |
| 12531 | 12559 | #define TK_ALTER 141 |
| 12532 | 12560 | #define TK_ADD 142 |
| 12533 | | -#define TK_TO_TEXT 143 |
| 12534 | | -#define TK_TO_BLOB 144 |
| 12535 | | -#define TK_TO_NUMERIC 145 |
| 12536 | | -#define TK_TO_INT 146 |
| 12537 | | -#define TK_TO_REAL 147 |
| 12538 | | -#define TK_ISNOT 148 |
| 12539 | | -#define TK_END_OF_FILE 149 |
| 12540 | | -#define TK_UNCLOSED_STRING 150 |
| 12541 | | -#define TK_FUNCTION 151 |
| 12542 | | -#define TK_COLUMN 152 |
| 12543 | | -#define TK_AGG_FUNCTION 153 |
| 12544 | | -#define TK_AGG_COLUMN 154 |
| 12545 | | -#define TK_UMINUS 155 |
| 12546 | | -#define TK_UPLUS 156 |
| 12547 | | -#define TK_REGISTER 157 |
| 12548 | | -#define TK_VECTOR 158 |
| 12549 | | -#define TK_SELECT_COLUMN 159 |
| 12550 | | -#define TK_IF_NULL_ROW 160 |
| 12551 | | -#define TK_ASTERISK 161 |
| 12552 | | -#define TK_SPAN 162 |
| 12553 | | -#define TK_SPACE 163 |
| 12554 | | -#define TK_ILLEGAL 164 |
| 12561 | +#define TK_ISNOT 143 |
| 12562 | +#define TK_FUNCTION 144 |
| 12563 | +#define TK_COLUMN 145 |
| 12564 | +#define TK_AGG_FUNCTION 146 |
| 12565 | +#define TK_AGG_COLUMN 147 |
| 12566 | +#define TK_UMINUS 148 |
| 12567 | +#define TK_UPLUS 149 |
| 12568 | +#define TK_REGISTER 150 |
| 12569 | +#define TK_VECTOR 151 |
| 12570 | +#define TK_SELECT_COLUMN 152 |
| 12571 | +#define TK_IF_NULL_ROW 153 |
| 12572 | +#define TK_ASTERISK 154 |
| 12573 | +#define TK_SPAN 155 |
| 12574 | +#define TK_END_OF_FILE 156 |
| 12575 | +#define TK_UNCLOSED_STRING 157 |
| 12576 | +#define TK_SPACE 158 |
| 12577 | +#define TK_ILLEGAL 159 |
| 12555 | 12578 | |
| 12556 | 12579 | /* The token codes above must all fit in 8 bits */ |
| 12557 | 12580 | #define TKFLG_MASK 0xff |
| 12558 | 12581 | |
| 12559 | 12582 | /* Flags that can be added to a token code when it is not |
| | @@ -12669,10 +12692,19 @@ |
| 12669 | 12692 | */ |
| 12670 | 12693 | #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 12671 | 12694 | # define SQLITE_DEFAULT_PCACHE_INITSZ 20 |
| 12672 | 12695 | #endif |
| 12673 | 12696 | |
| 12697 | +/* |
| 12698 | +** The compile-time options SQLITE_MMAP_READWRITE and |
| 12699 | +** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another. |
| 12700 | +** You must choose one or the other (or neither) but not both. |
| 12701 | +*/ |
| 12702 | +#if defined(SQLITE_MMAP_READWRITE) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 12703 | +#error Cannot use both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 12704 | +#endif |
| 12705 | + |
| 12674 | 12706 | /* |
| 12675 | 12707 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 12676 | 12708 | ** ourselves. |
| 12677 | 12709 | */ |
| 12678 | 12710 | #ifndef offsetof |
| | @@ -13371,10 +13403,11 @@ |
| 13371 | 13403 | int iTable, /* Index of root page */ |
| 13372 | 13404 | int wrFlag, /* 1 for writing. 0 for read-only */ |
| 13373 | 13405 | struct KeyInfo*, /* First argument to compare function */ |
| 13374 | 13406 | BtCursor *pCursor /* Space to write cursor structure */ |
| 13375 | 13407 | ); |
| 13408 | +SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void); |
| 13376 | 13409 | SQLITE_PRIVATE int sqlite3BtreeCursorSize(void); |
| 13377 | 13410 | SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*); |
| 13378 | 13411 | SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned); |
| 13379 | 13412 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 13380 | 13413 | SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...); |
| | @@ -13689,91 +13722,91 @@ |
| 13689 | 13722 | /* Automatically generated. Do not edit */ |
| 13690 | 13723 | /* See the tool/mkopcodeh.tcl script for details */ |
| 13691 | 13724 | #define OP_Savepoint 0 |
| 13692 | 13725 | #define OP_AutoCommit 1 |
| 13693 | 13726 | #define OP_Transaction 2 |
| 13694 | | -#define OP_SorterNext 3 |
| 13695 | | -#define OP_PrevIfOpen 4 |
| 13696 | | -#define OP_NextIfOpen 5 |
| 13697 | | -#define OP_Prev 6 |
| 13698 | | -#define OP_Next 7 |
| 13727 | +#define OP_SorterNext 3 /* jump */ |
| 13728 | +#define OP_PrevIfOpen 4 /* jump */ |
| 13729 | +#define OP_NextIfOpen 5 /* jump */ |
| 13730 | +#define OP_Prev 6 /* jump */ |
| 13731 | +#define OP_Next 7 /* jump */ |
| 13699 | 13732 | #define OP_Checkpoint 8 |
| 13700 | 13733 | #define OP_JournalMode 9 |
| 13701 | 13734 | #define OP_Vacuum 10 |
| 13702 | | -#define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */ |
| 13735 | +#define OP_VFilter 11 /* jump, synopsis: iplan=r[P3] zplan='P4' */ |
| 13703 | 13736 | #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */ |
| 13704 | | -#define OP_Goto 13 |
| 13705 | | -#define OP_Gosub 14 |
| 13706 | | -#define OP_InitCoroutine 15 |
| 13707 | | -#define OP_Yield 16 |
| 13708 | | -#define OP_MustBeInt 17 |
| 13709 | | -#define OP_Jump 18 |
| 13737 | +#define OP_Goto 13 /* jump */ |
| 13738 | +#define OP_Gosub 14 /* jump */ |
| 13739 | +#define OP_InitCoroutine 15 /* jump */ |
| 13740 | +#define OP_Yield 16 /* jump */ |
| 13741 | +#define OP_MustBeInt 17 /* jump */ |
| 13742 | +#define OP_Jump 18 /* jump */ |
| 13710 | 13743 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 13711 | | -#define OP_Once 20 |
| 13712 | | -#define OP_If 21 |
| 13713 | | -#define OP_IfNot 22 |
| 13714 | | -#define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 13715 | | -#define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */ |
| 13716 | | -#define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */ |
| 13717 | | -#define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */ |
| 13718 | | -#define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */ |
| 13719 | | -#define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */ |
| 13720 | | -#define OP_NotFound 29 /* synopsis: key=r[P3@P4] */ |
| 13721 | | -#define OP_Found 30 /* synopsis: key=r[P3@P4] */ |
| 13722 | | -#define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */ |
| 13723 | | -#define OP_NotExists 32 /* synopsis: intkey=r[P3] */ |
| 13724 | | -#define OP_Last 33 |
| 13725 | | -#define OP_IfSmaller 34 |
| 13726 | | -#define OP_SorterSort 35 |
| 13727 | | -#define OP_Sort 36 |
| 13728 | | -#define OP_Rewind 37 |
| 13729 | | -#define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */ |
| 13730 | | -#define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */ |
| 13731 | | -#define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */ |
| 13732 | | -#define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */ |
| 13733 | | -#define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */ |
| 13734 | | -#define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 13735 | | -#define OP_Program 44 |
| 13736 | | -#define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 13737 | | -#define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 13738 | | -#define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 13739 | | -#define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 13740 | | -#define OP_IncrVacuum 49 |
| 13741 | | -#define OP_VNext 50 |
| 13742 | | -#define OP_Init 51 /* synopsis: Start at P2 */ |
| 13743 | | -#define OP_Return 52 |
| 13744 | | -#define OP_EndCoroutine 53 |
| 13745 | | -#define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */ |
| 13746 | | -#define OP_Halt 55 |
| 13747 | | -#define OP_Integer 56 /* synopsis: r[P2]=P1 */ |
| 13748 | | -#define OP_Int64 57 /* synopsis: r[P2]=P4 */ |
| 13749 | | -#define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */ |
| 13750 | | -#define OP_Null 59 /* synopsis: r[P2..P3]=NULL */ |
| 13751 | | -#define OP_SoftNull 60 /* synopsis: r[P1]=NULL */ |
| 13752 | | -#define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */ |
| 13753 | | -#define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 13754 | | -#define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 13755 | | -#define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 13756 | | -#define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */ |
| 13757 | | -#define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */ |
| 13758 | | -#define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */ |
| 13759 | | -#define OP_CollSeq 68 |
| 13760 | | -#define OP_AddImm 69 /* synopsis: r[P1]=r[P1]+P2 */ |
| 13761 | | -#define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 13762 | | -#define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 13763 | | -#define OP_RealAffinity 72 |
| 13764 | | -#define OP_Cast 73 /* synopsis: affinity(r[P1]) */ |
| 13765 | | -#define OP_Permutation 74 |
| 13766 | | -#define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 13767 | | -#define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 13768 | | -#define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */ |
| 13769 | | -#define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */ |
| 13770 | | -#define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */ |
| 13771 | | -#define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */ |
| 13772 | | -#define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */ |
| 13773 | | -#define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */ |
| 13774 | | -#define OP_ElseNotEq 83 /* same as TK_ESCAPE */ |
| 13744 | +#define OP_Once 20 /* jump */ |
| 13745 | +#define OP_If 21 /* jump */ |
| 13746 | +#define OP_IfNot 22 /* jump */ |
| 13747 | +#define OP_IfNullRow 23 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 13748 | +#define OP_SeekLT 24 /* jump, synopsis: key=r[P3@P4] */ |
| 13749 | +#define OP_SeekLE 25 /* jump, synopsis: key=r[P3@P4] */ |
| 13750 | +#define OP_SeekGE 26 /* jump, synopsis: key=r[P3@P4] */ |
| 13751 | +#define OP_SeekGT 27 /* jump, synopsis: key=r[P3@P4] */ |
| 13752 | +#define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */ |
| 13753 | +#define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */ |
| 13754 | +#define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */ |
| 13755 | +#define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */ |
| 13756 | +#define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */ |
| 13757 | +#define OP_Last 33 /* jump */ |
| 13758 | +#define OP_IfSmaller 34 /* jump */ |
| 13759 | +#define OP_SorterSort 35 /* jump */ |
| 13760 | +#define OP_Sort 36 /* jump */ |
| 13761 | +#define OP_Rewind 37 /* jump */ |
| 13762 | +#define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */ |
| 13763 | +#define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */ |
| 13764 | +#define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 13765 | +#define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */ |
| 13766 | +#define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */ |
| 13767 | +#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 13768 | +#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 13769 | +#define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 13770 | +#define OP_Program 46 /* jump */ |
| 13771 | +#define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */ |
| 13772 | +#define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 13773 | +#define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 13774 | +#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 13775 | +#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 13776 | +#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */ |
| 13777 | +#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */ |
| 13778 | +#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */ |
| 13779 | +#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */ |
| 13780 | +#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */ |
| 13781 | +#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */ |
| 13782 | +#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 13783 | +#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 13784 | +#define OP_IncrVacuum 60 /* jump */ |
| 13785 | +#define OP_VNext 61 /* jump */ |
| 13786 | +#define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 13787 | +#define OP_Return 63 |
| 13788 | +#define OP_EndCoroutine 64 |
| 13789 | +#define OP_HaltIfNull 65 /* synopsis: if r[P3]=null halt */ |
| 13790 | +#define OP_Halt 66 |
| 13791 | +#define OP_Integer 67 /* synopsis: r[P2]=P1 */ |
| 13792 | +#define OP_Int64 68 /* synopsis: r[P2]=P4 */ |
| 13793 | +#define OP_String 69 /* synopsis: r[P2]='P4' (len=P1) */ |
| 13794 | +#define OP_Null 70 /* synopsis: r[P2..P3]=NULL */ |
| 13795 | +#define OP_SoftNull 71 /* synopsis: r[P1]=NULL */ |
| 13796 | +#define OP_Blob 72 /* synopsis: r[P2]=P4 (len=P1) */ |
| 13797 | +#define OP_Variable 73 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 13798 | +#define OP_Move 74 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 13799 | +#define OP_Copy 75 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 13800 | +#define OP_SCopy 76 /* synopsis: r[P2]=r[P1] */ |
| 13801 | +#define OP_IntCopy 77 /* synopsis: r[P2]=r[P1] */ |
| 13802 | +#define OP_ResultRow 78 /* synopsis: output=r[P1@P2] */ |
| 13803 | +#define OP_CollSeq 79 |
| 13804 | +#define OP_AddImm 80 /* synopsis: r[P1]=r[P1]+P2 */ |
| 13805 | +#define OP_RealAffinity 81 |
| 13806 | +#define OP_Cast 82 /* synopsis: affinity(r[P1]) */ |
| 13807 | +#define OP_Permutation 83 |
| 13775 | 13808 | #define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 13776 | 13809 | #define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 13777 | 13810 | #define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 13778 | 13811 | #define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 13779 | 13812 | #define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -13811,21 +13844,21 @@ |
| 13811 | 13844 | #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 13812 | 13845 | #define OP_SorterData 121 /* synopsis: r[P2]=data */ |
| 13813 | 13846 | #define OP_RowData 122 /* synopsis: r[P2]=data */ |
| 13814 | 13847 | #define OP_Rowid 123 /* synopsis: r[P2]=rowid */ |
| 13815 | 13848 | #define OP_NullRow 124 |
| 13816 | | -#define OP_SorterInsert 125 /* synopsis: key=r[P2] */ |
| 13817 | | -#define OP_IdxInsert 126 /* synopsis: key=r[P2] */ |
| 13818 | | -#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */ |
| 13819 | | -#define OP_DeferredSeek 128 /* synopsis: Move P3 to P1.rowid if needed */ |
| 13820 | | -#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */ |
| 13821 | | -#define OP_Destroy 130 |
| 13822 | | -#define OP_Clear 131 |
| 13849 | +#define OP_SeekEnd 125 |
| 13850 | +#define OP_SorterInsert 126 /* synopsis: key=r[P2] */ |
| 13851 | +#define OP_IdxInsert 127 /* synopsis: key=r[P2] */ |
| 13852 | +#define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */ |
| 13853 | +#define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */ |
| 13854 | +#define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */ |
| 13855 | +#define OP_Destroy 131 |
| 13823 | 13856 | #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 13824 | | -#define OP_ResetSorter 133 |
| 13825 | | -#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 13826 | | -#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */ |
| 13857 | +#define OP_Clear 133 |
| 13858 | +#define OP_ResetSorter 134 |
| 13859 | +#define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 13827 | 13860 | #define OP_SqlExec 136 |
| 13828 | 13861 | #define OP_ParseSchema 137 |
| 13829 | 13862 | #define OP_LoadAnalysis 138 |
| 13830 | 13863 | #define OP_DropTable 139 |
| 13831 | 13864 | #define OP_DropIndex 140 |
| | @@ -13871,22 +13904,22 @@ |
| 13871 | 13904 | /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 13872 | 13905 | /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\ |
| 13873 | 13906 | /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\ |
| 13874 | 13907 | /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\ |
| 13875 | 13908 | /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 13876 | | -/* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\ |
| 13877 | | -/* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\ |
| 13878 | | -/* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\ |
| 13879 | | -/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x02, 0x26, 0x26,\ |
| 13880 | | -/* 72 */ 0x02, 0x02, 0x00, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\ |
| 13881 | | -/* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\ |
| 13909 | +/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\ |
| 13910 | +/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 13911 | +/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\ |
| 13912 | +/* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\ |
| 13913 | +/* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 13914 | +/* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\ |
| 13882 | 13915 | /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\ |
| 13883 | 13916 | /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 13884 | 13917 | /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 13885 | 13918 | /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 13886 | | -/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\ |
| 13887 | | -/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\ |
| 13919 | +/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\ |
| 13920 | +/* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\ |
| 13888 | 13921 | /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\ |
| 13889 | 13922 | /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\ |
| 13890 | 13923 | /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 13891 | 13924 | /* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 13892 | 13925 | } |
| | @@ -13895,11 +13928,11 @@ |
| 13895 | 13928 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 13896 | 13929 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 13897 | 13930 | ** generated this include file strives to group all JUMP opcodes |
| 13898 | 13931 | ** together near the beginning of the list. |
| 13899 | 13932 | */ |
| 13900 | | -#define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */ |
| 13933 | +#define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */ |
| 13901 | 13934 | |
| 13902 | 13935 | /************** End of opcodes.h *********************************************/ |
| 13903 | 13936 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 13904 | 13937 | |
| 13905 | 13938 | /* |
| | @@ -14213,10 +14246,11 @@ |
| 14213 | 14246 | SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); |
| 14214 | 14247 | SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 14215 | 14248 | SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 14216 | 14249 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 14217 | 14250 | SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); |
| 14251 | +SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*); |
| 14218 | 14252 | |
| 14219 | 14253 | /* Operations on page references. */ |
| 14220 | 14254 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 14221 | 14255 | SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 14222 | 14256 | SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| | @@ -14349,10 +14383,12 @@ |
| 14349 | 14383 | ** pCache is grouped with the public elements for efficiency. |
| 14350 | 14384 | */ |
| 14351 | 14385 | i16 nRef; /* Number of users of this page */ |
| 14352 | 14386 | PgHdr *pDirtyNext; /* Next element in list of dirty pages */ |
| 14353 | 14387 | PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */ |
| 14388 | + /* NB: pDirtyNext and pDirtyPrev are undefined if the |
| 14389 | + ** PgHdr object is not dirty */ |
| 14354 | 14390 | }; |
| 14355 | 14391 | |
| 14356 | 14392 | /* Bit values for PgHdr.flags */ |
| 14357 | 14393 | #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */ |
| 14358 | 14394 | #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */ |
| | @@ -14942,10 +14978,11 @@ |
| 14942 | 14978 | ** changes and so the view will need to be reset. |
| 14943 | 14979 | */ |
| 14944 | 14980 | #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ |
| 14945 | 14981 | #define DB_UnresetViews 0x0002 /* Some views have defined column names */ |
| 14946 | 14982 | #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ |
| 14983 | +#define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */ |
| 14947 | 14984 | |
| 14948 | 14985 | /* |
| 14949 | 14986 | ** The number of different kinds of things that can be limited |
| 14950 | 14987 | ** using the sqlite3_limit() interface. |
| 14951 | 14988 | */ |
| | @@ -14973,13 +15010,13 @@ |
| 14973 | 15010 | */ |
| 14974 | 15011 | struct Lookaside { |
| 14975 | 15012 | u32 bDisable; /* Only operate the lookaside when zero */ |
| 14976 | 15013 | u16 sz; /* Size of each buffer in bytes */ |
| 14977 | 15014 | u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ |
| 14978 | | - int nOut; /* Number of buffers currently checked out */ |
| 14979 | | - int mxOut; /* Highwater mark for nOut */ |
| 14980 | | - int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 15015 | + u32 nSlot; /* Number of lookaside slots allocated */ |
| 15016 | + u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 15017 | + LookasideSlot *pInit; /* List of buffers not previously used */ |
| 14981 | 15018 | LookasideSlot *pFree; /* List of available buffers */ |
| 14982 | 15019 | void *pStart; /* First byte of available memory space */ |
| 14983 | 15020 | void *pEnd; /* First byte past end of available space */ |
| 14984 | 15021 | }; |
| 14985 | 15022 | struct LookasideSlot { |
| | @@ -15054,13 +15091,15 @@ |
| 15054 | 15091 | struct Vdbe *pVdbe; /* List of active virtual machines */ |
| 15055 | 15092 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 15056 | 15093 | sqlite3_mutex *mutex; /* Connection mutex */ |
| 15057 | 15094 | Db *aDb; /* All backends */ |
| 15058 | 15095 | int nDb; /* Number of backends currently in use */ |
| 15059 | | - int flags; /* Miscellaneous flags. See below */ |
| 15096 | + u32 mDbFlags; /* flags recording internal state */ |
| 15097 | + u32 flags; /* flags settable by pragmas. See below */ |
| 15060 | 15098 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 15061 | 15099 | i64 szMmap; /* Default mmap_size setting */ |
| 15100 | + u32 nSchemaLock; /* Do not reset the schema when non-zero */ |
| 15062 | 15101 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 15063 | 15102 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 15064 | 15103 | int errMask; /* & result codes with this before returning */ |
| 15065 | 15104 | int iSysErrno; /* Errno value from last system error */ |
| 15066 | 15105 | u16 dbOptFlags; /* Flags to enable/disable optimizations */ |
| | @@ -15208,31 +15247,32 @@ |
| 15208 | 15247 | #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */ |
| 15209 | 15248 | #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */ |
| 15210 | 15249 | #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */ |
| 15211 | 15250 | #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */ |
| 15212 | 15251 | #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */ |
| 15213 | | -#define SQLITE_EnableTrigger 0x00020000 /* True to enable triggers */ |
| 15214 | | -#define SQLITE_DeferFKs 0x00040000 /* Defer all FK constraints */ |
| 15215 | | -#define SQLITE_QueryOnly 0x00080000 /* Disable database changes */ |
| 15216 | | -#define SQLITE_CellSizeCk 0x00100000 /* Check btree cell sizes on load */ |
| 15217 | | -#define SQLITE_Fts3Tokenizer 0x00200000 /* Enable fts3_tokenizer(2) */ |
| 15218 | | -#define SQLITE_EnableQPSG 0x00400000 /* Query Planner Stability Guarantee */ |
| 15219 | | -/* The next four values are not used by PRAGMAs or by sqlite3_dbconfig() and |
| 15220 | | -** could be factored out into a separate bit vector of the sqlite3 object. */ |
| 15221 | | -#define SQLITE_InternChanges 0x00800000 /* Uncommitted Hash table changes */ |
| 15222 | | -#define SQLITE_LoadExtFunc 0x01000000 /* Enable load_extension() SQL func */ |
| 15223 | | -#define SQLITE_PreferBuiltin 0x02000000 /* Preference to built-in funcs */ |
| 15224 | | -#define SQLITE_Vacuum 0x04000000 /* Currently in a VACUUM */ |
| 15252 | +#define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */ |
| 15253 | +#define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */ |
| 15254 | +#define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */ |
| 15255 | +#define SQLITE_QueryOnly 0x00100000 /* Disable database changes */ |
| 15256 | +#define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */ |
| 15257 | +#define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */ |
| 15258 | +#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */ |
| 15225 | 15259 | /* Flags used only if debugging */ |
| 15226 | 15260 | #ifdef SQLITE_DEBUG |
| 15227 | 15261 | #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */ |
| 15228 | 15262 | #define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */ |
| 15229 | 15263 | #define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */ |
| 15230 | 15264 | #define SQLITE_VdbeAddopTrace 0x40000000 /* Trace sqlite3VdbeAddOp() calls */ |
| 15231 | 15265 | #define SQLITE_VdbeEQP 0x80000000 /* Debug EXPLAIN QUERY PLAN */ |
| 15232 | 15266 | #endif |
| 15233 | 15267 | |
| 15268 | +/* |
| 15269 | +** Allowed values for sqlite3.mDbFlags |
| 15270 | +*/ |
| 15271 | +#define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */ |
| 15272 | +#define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */ |
| 15273 | +#define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */ |
| 15234 | 15274 | |
| 15235 | 15275 | /* |
| 15236 | 15276 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 15237 | 15277 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| 15238 | 15278 | ** selectively disable various optimizations. |
| | @@ -15779,12 +15819,12 @@ |
| 15779 | 15819 | ** for the rowid at the end. |
| 15780 | 15820 | */ |
| 15781 | 15821 | struct KeyInfo { |
| 15782 | 15822 | u32 nRef; /* Number of references to this KeyInfo object */ |
| 15783 | 15823 | u8 enc; /* Text encoding - one of the SQLITE_UTF* values */ |
| 15784 | | - u16 nField; /* Number of key columns in the index */ |
| 15785 | | - u16 nXField; /* Number of columns beyond the key columns */ |
| 15824 | + u16 nKeyField; /* Number of key columns in the index */ |
| 15825 | + u16 nAllField; /* Total columns, including key plus others */ |
| 15786 | 15826 | sqlite3 *db; /* The database connection */ |
| 15787 | 15827 | u8 *aSortOrder; /* Sort order for each column. */ |
| 15788 | 15828 | CollSeq *aColl[1]; /* Collating sequence for each term of the key */ |
| 15789 | 15829 | }; |
| 15790 | 15830 | |
| | @@ -15827,12 +15867,12 @@ |
| 15827 | 15867 | KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 15828 | 15868 | Mem *aMem; /* Values */ |
| 15829 | 15869 | u16 nField; /* Number of entries in apMem[] */ |
| 15830 | 15870 | i8 default_rc; /* Comparison result if keys are equal */ |
| 15831 | 15871 | u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 15832 | | - i8 r1; /* Value to return if (lhs > rhs) */ |
| 15833 | | - i8 r2; /* Value to return if (rhs < lhs) */ |
| 15872 | + i8 r1; /* Value to return if (lhs < rhs) */ |
| 15873 | + i8 r2; /* Value to return if (lhs > rhs) */ |
| 15834 | 15874 | u8 eqSeen; /* True if an equality comparison has been seen */ |
| 15835 | 15875 | }; |
| 15836 | 15876 | |
| 15837 | 15877 | |
| 15838 | 15878 | /* |
| | @@ -16112,11 +16152,12 @@ |
| 16112 | 16152 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 16113 | 16153 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| 16114 | 16154 | ** TK_COLUMN: the value of p5 for OP_Column |
| 16115 | 16155 | ** TK_AGG_FUNCTION: nesting depth */ |
| 16116 | 16156 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 16117 | | - Table *pTab; /* Table for TK_COLUMN expressions. */ |
| 16157 | + Table *pTab; /* Table for TK_COLUMN expressions. Can be NULL |
| 16158 | + ** for a column of an index on an expression */ |
| 16118 | 16159 | }; |
| 16119 | 16160 | |
| 16120 | 16161 | /* |
| 16121 | 16162 | ** The following are the meanings of bits in the Expr.flags field. |
| 16122 | 16163 | */ |
| | @@ -16200,11 +16241,10 @@ |
| 16200 | 16241 | ** of the result column in the form: DATABASE.TABLE.COLUMN. This later |
| 16201 | 16242 | ** form is used for name resolution with nested FROM clauses. |
| 16202 | 16243 | */ |
| 16203 | 16244 | struct ExprList { |
| 16204 | 16245 | int nExpr; /* Number of expressions on the list */ |
| 16205 | | - int nAlloc; /* Number of a[] slots allocated */ |
| 16206 | 16246 | struct ExprList_item { /* For each expression in the list */ |
| 16207 | 16247 | Expr *pExpr; /* The parse tree for this expression */ |
| 16208 | 16248 | char *zName; /* Token associated with this expression */ |
| 16209 | 16249 | char *zSpan; /* Original text of the expression */ |
| 16210 | 16250 | u8 sortOrder; /* 1 for DESC or 0 for ASC */ |
| | @@ -16725,11 +16765,11 @@ |
| 16725 | 16765 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 16726 | 16766 | #endif |
| 16727 | 16767 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 16728 | 16768 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 16729 | 16769 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 16730 | | - int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */ |
| 16770 | + int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */ |
| 16731 | 16771 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 16732 | 16772 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 16733 | 16773 | u32 newmask; /* Mask of new.* columns referenced */ |
| 16734 | 16774 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 16735 | 16775 | u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ |
| | @@ -16954,15 +16994,14 @@ |
| 16954 | 16994 | ** An objected used to accumulate the text of a string where we |
| 16955 | 16995 | ** do not necessarily know how big the string will be in the end. |
| 16956 | 16996 | */ |
| 16957 | 16997 | struct StrAccum { |
| 16958 | 16998 | sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 16959 | | - char *zBase; /* A base allocation. Not from malloc. */ |
| 16960 | 16999 | char *zText; /* The string collected so far */ |
| 16961 | | - u32 nChar; /* Length of the string so far */ |
| 16962 | 17000 | u32 nAlloc; /* Amount of space allocated in zText */ |
| 16963 | 17001 | u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ |
| 17002 | + u32 nChar; /* Length of the string so far */ |
| 16964 | 17003 | u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 16965 | 17004 | u8 printfFlags; /* SQLITE_PRINTF flags below */ |
| 16966 | 17005 | }; |
| 16967 | 17006 | #define STRACCUM_NOMEM 1 |
| 16968 | 17007 | #define STRACCUM_TOOBIG 2 |
| | @@ -16993,10 +17032,11 @@ |
| 16993 | 17032 | int bMemstat; /* True to enable memory status */ |
| 16994 | 17033 | int bCoreMutex; /* True to enable core mutexing */ |
| 16995 | 17034 | int bFullMutex; /* True to enable full mutexing */ |
| 16996 | 17035 | int bOpenUri; /* True to interpret filenames as URIs */ |
| 16997 | 17036 | int bUseCis; /* Use covering indices for full-scans */ |
| 17037 | + int bSmallMalloc; /* Avoid large memory allocations if true */ |
| 16998 | 17038 | int mxStrlen; /* Maximum string length */ |
| 16999 | 17039 | int neverCorrupt; /* Database is always well-formed */ |
| 17000 | 17040 | int szLookaside; /* Default lookaside buffer size */ |
| 17001 | 17041 | int nLookaside; /* Default lookaside buffer count */ |
| 17002 | 17042 | int nStmtSpill; /* Stmt-journal spill-to-disk threshold */ |
| | @@ -17006,13 +17046,10 @@ |
| 17006 | 17046 | void *pHeap; /* Heap storage space */ |
| 17007 | 17047 | int nHeap; /* Size of pHeap[] */ |
| 17008 | 17048 | int mnReq, mxReq; /* Min and max heap requests sizes */ |
| 17009 | 17049 | sqlite3_int64 szMmap; /* mmap() space per open file */ |
| 17010 | 17050 | sqlite3_int64 mxMmap; /* Maximum value for szMmap */ |
| 17011 | | - void *pScratch; /* Scratch memory */ |
| 17012 | | - int szScratch; /* Size of each scratch buffer */ |
| 17013 | | - int nScratch; /* Number of scratch buffers */ |
| 17014 | 17051 | void *pPage; /* Page cache memory */ |
| 17015 | 17052 | int szPage; /* Size of each page in pPage[] */ |
| 17016 | 17053 | int nPage; /* Number of pages in pPage[] */ |
| 17017 | 17054 | int mxParserStack; /* maximum depth of the parser stack */ |
| 17018 | 17055 | int sharedCacheEnabled; /* true if shared-cache mode enabled */ |
| | @@ -17095,10 +17132,11 @@ |
| 17095 | 17132 | SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*); |
| 17096 | 17133 | SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*); |
| 17097 | 17134 | SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*); |
| 17098 | 17135 | SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*); |
| 17099 | 17136 | SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*); |
| 17137 | +SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*); |
| 17100 | 17138 | #ifdef SQLITE_DEBUG |
| 17101 | 17139 | SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*); |
| 17102 | 17140 | #endif |
| 17103 | 17141 | |
| 17104 | 17142 | /* |
| | @@ -17247,12 +17285,10 @@ |
| 17247 | 17285 | SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64); |
| 17248 | 17286 | SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*); |
| 17249 | 17287 | SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*); |
| 17250 | 17288 | SQLITE_PRIVATE int sqlite3MallocSize(void*); |
| 17251 | 17289 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*); |
| 17252 | | -SQLITE_PRIVATE void *sqlite3ScratchMalloc(int); |
| 17253 | | -SQLITE_PRIVATE void sqlite3ScratchFree(void*); |
| 17254 | 17290 | SQLITE_PRIVATE void *sqlite3PageMalloc(int); |
| 17255 | 17291 | SQLITE_PRIVATE void sqlite3PageFree(void*); |
| 17256 | 17292 | SQLITE_PRIVATE void sqlite3MemSetDefault(void); |
| 17257 | 17293 | #ifndef SQLITE_UNTESTABLE |
| 17258 | 17294 | SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); |
| | @@ -17304,10 +17340,11 @@ |
| 17304 | 17340 | |
| 17305 | 17341 | SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); |
| 17306 | 17342 | SQLITE_PRIVATE void sqlite3StatusUp(int, int); |
| 17307 | 17343 | SQLITE_PRIVATE void sqlite3StatusDown(int, int); |
| 17308 | 17344 | SQLITE_PRIVATE void sqlite3StatusHighwater(int, int); |
| 17345 | +SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*); |
| 17309 | 17346 | |
| 17310 | 17347 | /* Access to mutexes used by sqlite3_status() */ |
| 17311 | 17348 | SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void); |
| 17312 | 17349 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void); |
| 17313 | 17350 | |
| | @@ -18023,11 +18060,12 @@ |
| 18023 | 18060 | #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */ |
| 18024 | 18061 | SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*); |
| 18025 | 18062 | |
| 18026 | 18063 | SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); |
| 18027 | 18064 | SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *); |
| 18028 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 18065 | +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 18066 | + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 18029 | 18067 | SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *); |
| 18030 | 18068 | #endif |
| 18031 | 18069 | |
| 18032 | 18070 | SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p); |
| 18033 | 18071 | SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *); |
| | @@ -18109,12 +18147,11 @@ |
| 18109 | 18147 | # define sqlite3MemdebugHasType(X,Y) 1 |
| 18110 | 18148 | # define sqlite3MemdebugNoType(X,Y) 1 |
| 18111 | 18149 | #endif |
| 18112 | 18150 | #define MEMTYPE_HEAP 0x01 /* General heap allocations */ |
| 18113 | 18151 | #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */ |
| 18114 | | -#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */ |
| 18115 | | -#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */ |
| 18152 | +#define MEMTYPE_PCACHE 0x04 /* Page cache allocations */ |
| 18116 | 18153 | |
| 18117 | 18154 | /* |
| 18118 | 18155 | ** Threading interface |
| 18119 | 18156 | */ |
| 18120 | 18157 | #if SQLITE_MAX_WORKER_THREADS>0 |
| | @@ -18339,10 +18376,11 @@ |
| 18339 | 18376 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 18340 | 18377 | 1, /* bCoreMutex */ |
| 18341 | 18378 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 18342 | 18379 | SQLITE_USE_URI, /* bOpenUri */ |
| 18343 | 18380 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 18381 | + 0, /* bSmallMalloc */ |
| 18344 | 18382 | 0x7ffffffe, /* mxStrlen */ |
| 18345 | 18383 | 0, /* neverCorrupt */ |
| 18346 | 18384 | SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */ |
| 18347 | 18385 | SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
| 18348 | 18386 | {0,0,0,0,0,0,0,0}, /* m */ |
| | @@ -18351,13 +18389,10 @@ |
| 18351 | 18389 | (void*)0, /* pHeap */ |
| 18352 | 18390 | 0, /* nHeap */ |
| 18353 | 18391 | 0, 0, /* mnHeap, mxHeap */ |
| 18354 | 18392 | SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */ |
| 18355 | 18393 | SQLITE_MAX_MMAP_SIZE, /* mxMmap */ |
| 18356 | | - (void*)0, /* pScratch */ |
| 18357 | | - 0, /* szScratch */ |
| 18358 | | - 0, /* nScratch */ |
| 18359 | 18394 | (void*)0, /* pPage */ |
| 18360 | 18395 | 0, /* szPage */ |
| 18361 | 18396 | SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */ |
| 18362 | 18397 | 0, /* mxParserStack */ |
| 18363 | 18398 | 0, /* sharedCacheEnabled */ |
| | @@ -18555,22 +18590,22 @@ |
| 18555 | 18590 | ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that |
| 18556 | 18591 | ** the cache is out of date. */ |
| 18557 | 18592 | u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */ |
| 18558 | 18593 | int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0 |
| 18559 | 18594 | ** if there have been no prior seeks on the cursor. */ |
| 18560 | | - /* NB: seekResult does not distinguish between "no seeks have ever occurred |
| 18561 | | - ** on this cursor" and "the most recent seek was an exact match". */ |
| 18595 | + /* seekResult does not distinguish between "no seeks have ever occurred |
| 18596 | + ** on this cursor" and "the most recent seek was an exact match". |
| 18597 | + ** For CURTYPE_PSEUDO, seekResult is the register holding the record */ |
| 18562 | 18598 | |
| 18563 | 18599 | /* When a new VdbeCursor is allocated, only the fields above are zeroed. |
| 18564 | 18600 | ** The fields that follow are uninitialized, and must be individually |
| 18565 | 18601 | ** initialized prior to first use. */ |
| 18566 | 18602 | VdbeCursor *pAltCursor; /* Associated index cursor from which to read */ |
| 18567 | 18603 | union { |
| 18568 | | - BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */ |
| 18569 | | - sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */ |
| 18570 | | - int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */ |
| 18571 | | - VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ |
| 18604 | + BtCursor *pCursor; /* CURTYPE_BTREE or _PSEUDO. Btree cursor */ |
| 18605 | + sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */ |
| 18606 | + VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ |
| 18572 | 18607 | } uc; |
| 18573 | 18608 | KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ |
| 18574 | 18609 | u32 iHdrOffset; /* Offset to next unparsed byte of the header */ |
| 18575 | 18610 | Pgno pgnoRoot; /* Root page of the open btree cursor */ |
| 18576 | 18611 | i16 nField; /* Number of fields in the header */ |
| | @@ -19124,11 +19159,10 @@ |
| 19124 | 19159 | assert( op>=0 && op<ArraySize(statMutex) ); |
| 19125 | 19160 | assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() |
| 19126 | 19161 | : sqlite3MallocMutex()) ); |
| 19127 | 19162 | assert( op==SQLITE_STATUS_MALLOC_SIZE |
| 19128 | 19163 | || op==SQLITE_STATUS_PAGECACHE_SIZE |
| 19129 | | - || op==SQLITE_STATUS_SCRATCH_SIZE |
| 19130 | 19164 | || op==SQLITE_STATUS_PARSER_STACK ); |
| 19131 | 19165 | if( newValue>wsdStat.mxValue[op] ){ |
| 19132 | 19166 | wsdStat.mxValue[op] = newValue; |
| 19133 | 19167 | } |
| 19134 | 19168 | } |
| | @@ -19172,10 +19206,32 @@ |
| 19172 | 19206 | *pCurrent = (int)iCur; |
| 19173 | 19207 | *pHighwater = (int)iHwtr; |
| 19174 | 19208 | } |
| 19175 | 19209 | return rc; |
| 19176 | 19210 | } |
| 19211 | + |
| 19212 | +/* |
| 19213 | +** Return the number of LookasideSlot elements on the linked list |
| 19214 | +*/ |
| 19215 | +static u32 countLookasideSlots(LookasideSlot *p){ |
| 19216 | + u32 cnt = 0; |
| 19217 | + while( p ){ |
| 19218 | + p = p->pNext; |
| 19219 | + cnt++; |
| 19220 | + } |
| 19221 | + return cnt; |
| 19222 | +} |
| 19223 | + |
| 19224 | +/* |
| 19225 | +** Count the number of slots of lookaside memory that are outstanding |
| 19226 | +*/ |
| 19227 | +SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){ |
| 19228 | + u32 nInit = countLookasideSlots(db->lookaside.pInit); |
| 19229 | + u32 nFree = countLookasideSlots(db->lookaside.pFree); |
| 19230 | + if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit; |
| 19231 | + return db->lookaside.nSlot - (nInit+nFree); |
| 19232 | +} |
| 19177 | 19233 | |
| 19178 | 19234 | /* |
| 19179 | 19235 | ** Query status information for a single database connection |
| 19180 | 19236 | */ |
| 19181 | 19237 | SQLITE_API int sqlite3_db_status( |
| | @@ -19192,14 +19248,19 @@ |
| 19192 | 19248 | } |
| 19193 | 19249 | #endif |
| 19194 | 19250 | sqlite3_mutex_enter(db->mutex); |
| 19195 | 19251 | switch( op ){ |
| 19196 | 19252 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 19197 | | - *pCurrent = db->lookaside.nOut; |
| 19198 | | - *pHighwater = db->lookaside.mxOut; |
| 19253 | + *pCurrent = sqlite3LookasideUsed(db, pHighwater); |
| 19199 | 19254 | if( resetFlag ){ |
| 19200 | | - db->lookaside.mxOut = db->lookaside.nOut; |
| 19255 | + LookasideSlot *p = db->lookaside.pFree; |
| 19256 | + if( p ){ |
| 19257 | + while( p->pNext ) p = p->pNext; |
| 19258 | + p->pNext = db->lookaside.pInit; |
| 19259 | + db->lookaside.pInit = db->lookaside.pFree; |
| 19260 | + db->lookaside.pFree = 0; |
| 19261 | + } |
| 19201 | 19262 | } |
| 19202 | 19263 | break; |
| 19203 | 19264 | } |
| 19204 | 19265 | |
| 19205 | 19266 | case SQLITE_DBSTATUS_LOOKASIDE_HIT: |
| | @@ -20706,11 +20767,11 @@ |
| 20706 | 20767 | SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file *id, i64 size){ |
| 20707 | 20768 | return id->pMethods->xTruncate(id, size); |
| 20708 | 20769 | } |
| 20709 | 20770 | SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *id, int flags){ |
| 20710 | 20771 | DO_OS_MALLOC_TEST(id); |
| 20711 | | - return id->pMethods->xSync(id, flags); |
| 20772 | + return flags ? id->pMethods->xSync(id, flags) : SQLITE_OK; |
| 20712 | 20773 | } |
| 20713 | 20774 | SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){ |
| 20714 | 20775 | DO_OS_MALLOC_TEST(id); |
| 20715 | 20776 | return id->pMethods->xFileSize(id, pSize); |
| 20716 | 20777 | } |
| | @@ -24776,41 +24837,23 @@ |
| 24776 | 24837 | UNUSED_PARAMETER(n); |
| 24777 | 24838 | return 0; |
| 24778 | 24839 | #endif |
| 24779 | 24840 | } |
| 24780 | 24841 | |
| 24781 | | -/* |
| 24782 | | -** An instance of the following object records the location of |
| 24783 | | -** each unused scratch buffer. |
| 24784 | | -*/ |
| 24785 | | -typedef struct ScratchFreeslot { |
| 24786 | | - struct ScratchFreeslot *pNext; /* Next unused scratch buffer */ |
| 24787 | | -} ScratchFreeslot; |
| 24788 | | - |
| 24789 | 24842 | /* |
| 24790 | 24843 | ** State information local to the memory allocation subsystem. |
| 24791 | 24844 | */ |
| 24792 | 24845 | static SQLITE_WSD struct Mem0Global { |
| 24793 | 24846 | sqlite3_mutex *mutex; /* Mutex to serialize access */ |
| 24794 | 24847 | sqlite3_int64 alarmThreshold; /* The soft heap limit */ |
| 24795 | 24848 | |
| 24796 | | - /* |
| 24797 | | - ** Pointers to the end of sqlite3GlobalConfig.pScratch memory |
| 24798 | | - ** (so that a range test can be used to determine if an allocation |
| 24799 | | - ** being freed came from pScratch) and a pointer to the list of |
| 24800 | | - ** unused scratch allocations. |
| 24801 | | - */ |
| 24802 | | - void *pScratchEnd; |
| 24803 | | - ScratchFreeslot *pScratchFree; |
| 24804 | | - u32 nScratchFree; |
| 24805 | | - |
| 24806 | 24849 | /* |
| 24807 | 24850 | ** True if heap is nearly "full" where "full" is defined by the |
| 24808 | 24851 | ** sqlite3_soft_heap_limit() setting. |
| 24809 | 24852 | */ |
| 24810 | 24853 | int nearlyFull; |
| 24811 | | -} mem0 = { 0, 0, 0, 0, 0, 0 }; |
| 24854 | +} mem0 = { 0, 0, 0 }; |
| 24812 | 24855 | |
| 24813 | 24856 | #define mem0 GLOBAL(struct Mem0Global, mem0) |
| 24814 | 24857 | |
| 24815 | 24858 | /* |
| 24816 | 24859 | ** Return the memory allocator mutex. sqlite3_status() needs it. |
| | @@ -24876,32 +24919,10 @@ |
| 24876 | 24919 | if( sqlite3GlobalConfig.m.xMalloc==0 ){ |
| 24877 | 24920 | sqlite3MemSetDefault(); |
| 24878 | 24921 | } |
| 24879 | 24922 | memset(&mem0, 0, sizeof(mem0)); |
| 24880 | 24923 | mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); |
| 24881 | | - if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100 |
| 24882 | | - && sqlite3GlobalConfig.nScratch>0 ){ |
| 24883 | | - int i, n, sz; |
| 24884 | | - ScratchFreeslot *pSlot; |
| 24885 | | - sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch); |
| 24886 | | - sqlite3GlobalConfig.szScratch = sz; |
| 24887 | | - pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch; |
| 24888 | | - n = sqlite3GlobalConfig.nScratch; |
| 24889 | | - mem0.pScratchFree = pSlot; |
| 24890 | | - mem0.nScratchFree = n; |
| 24891 | | - for(i=0; i<n-1; i++){ |
| 24892 | | - pSlot->pNext = (ScratchFreeslot*)(sz+(char*)pSlot); |
| 24893 | | - pSlot = pSlot->pNext; |
| 24894 | | - } |
| 24895 | | - pSlot->pNext = 0; |
| 24896 | | - mem0.pScratchEnd = (void*)&pSlot[1]; |
| 24897 | | - }else{ |
| 24898 | | - mem0.pScratchEnd = 0; |
| 24899 | | - sqlite3GlobalConfig.pScratch = 0; |
| 24900 | | - sqlite3GlobalConfig.szScratch = 0; |
| 24901 | | - sqlite3GlobalConfig.nScratch = 0; |
| 24902 | | - } |
| 24903 | 24924 | if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512 |
| 24904 | 24925 | || sqlite3GlobalConfig.nPage<=0 ){ |
| 24905 | 24926 | sqlite3GlobalConfig.pPage = 0; |
| 24906 | 24927 | sqlite3GlobalConfig.szPage = 0; |
| 24907 | 24928 | } |
| | @@ -25048,109 +25069,10 @@ |
| 25048 | 25069 | if( sqlite3_initialize() ) return 0; |
| 25049 | 25070 | #endif |
| 25050 | 25071 | return sqlite3Malloc(n); |
| 25051 | 25072 | } |
| 25052 | 25073 | |
| 25053 | | -/* |
| 25054 | | -** Each thread may only have a single outstanding allocation from |
| 25055 | | -** xScratchMalloc(). We verify this constraint in the single-threaded |
| 25056 | | -** case by setting scratchAllocOut to 1 when an allocation |
| 25057 | | -** is outstanding clearing it when the allocation is freed. |
| 25058 | | -*/ |
| 25059 | | -#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 25060 | | -static int scratchAllocOut = 0; |
| 25061 | | -#endif |
| 25062 | | - |
| 25063 | | - |
| 25064 | | -/* |
| 25065 | | -** Allocate memory that is to be used and released right away. |
| 25066 | | -** This routine is similar to alloca() in that it is not intended |
| 25067 | | -** for situations where the memory might be held long-term. This |
| 25068 | | -** routine is intended to get memory to old large transient data |
| 25069 | | -** structures that would not normally fit on the stack of an |
| 25070 | | -** embedded processor. |
| 25071 | | -*/ |
| 25072 | | -SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){ |
| 25073 | | - void *p; |
| 25074 | | - assert( n>0 ); |
| 25075 | | - |
| 25076 | | - sqlite3_mutex_enter(mem0.mutex); |
| 25077 | | - sqlite3StatusHighwater(SQLITE_STATUS_SCRATCH_SIZE, n); |
| 25078 | | - if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){ |
| 25079 | | - p = mem0.pScratchFree; |
| 25080 | | - mem0.pScratchFree = mem0.pScratchFree->pNext; |
| 25081 | | - mem0.nScratchFree--; |
| 25082 | | - sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1); |
| 25083 | | - sqlite3_mutex_leave(mem0.mutex); |
| 25084 | | - }else{ |
| 25085 | | - sqlite3_mutex_leave(mem0.mutex); |
| 25086 | | - p = sqlite3Malloc(n); |
| 25087 | | - if( sqlite3GlobalConfig.bMemstat && p ){ |
| 25088 | | - sqlite3_mutex_enter(mem0.mutex); |
| 25089 | | - sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p)); |
| 25090 | | - sqlite3_mutex_leave(mem0.mutex); |
| 25091 | | - } |
| 25092 | | - sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH); |
| 25093 | | - } |
| 25094 | | - assert( sqlite3_mutex_notheld(mem0.mutex) ); |
| 25095 | | - |
| 25096 | | - |
| 25097 | | -#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 25098 | | - /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch |
| 25099 | | - ** buffers per thread. |
| 25100 | | - ** |
| 25101 | | - ** This can only be checked in single-threaded mode. |
| 25102 | | - */ |
| 25103 | | - assert( scratchAllocOut==0 ); |
| 25104 | | - if( p ) scratchAllocOut++; |
| 25105 | | -#endif |
| 25106 | | - |
| 25107 | | - return p; |
| 25108 | | -} |
| 25109 | | -SQLITE_PRIVATE void sqlite3ScratchFree(void *p){ |
| 25110 | | - if( p ){ |
| 25111 | | - |
| 25112 | | -#if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 25113 | | - /* Verify that no more than two scratch allocation per thread |
| 25114 | | - ** is outstanding at one time. (This is only checked in the |
| 25115 | | - ** single-threaded case since checking in the multi-threaded case |
| 25116 | | - ** would be much more complicated.) */ |
| 25117 | | - assert( scratchAllocOut>=1 && scratchAllocOut<=2 ); |
| 25118 | | - scratchAllocOut--; |
| 25119 | | -#endif |
| 25120 | | - |
| 25121 | | - if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){ |
| 25122 | | - /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */ |
| 25123 | | - ScratchFreeslot *pSlot; |
| 25124 | | - pSlot = (ScratchFreeslot*)p; |
| 25125 | | - sqlite3_mutex_enter(mem0.mutex); |
| 25126 | | - pSlot->pNext = mem0.pScratchFree; |
| 25127 | | - mem0.pScratchFree = pSlot; |
| 25128 | | - mem0.nScratchFree++; |
| 25129 | | - assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch ); |
| 25130 | | - sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1); |
| 25131 | | - sqlite3_mutex_leave(mem0.mutex); |
| 25132 | | - }else{ |
| 25133 | | - /* Release memory back to the heap */ |
| 25134 | | - assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); |
| 25135 | | - assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) ); |
| 25136 | | - sqlite3MemdebugSetType(p, MEMTYPE_HEAP); |
| 25137 | | - if( sqlite3GlobalConfig.bMemstat ){ |
| 25138 | | - int iSize = sqlite3MallocSize(p); |
| 25139 | | - sqlite3_mutex_enter(mem0.mutex); |
| 25140 | | - sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize); |
| 25141 | | - sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize); |
| 25142 | | - sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1); |
| 25143 | | - sqlite3GlobalConfig.m.xFree(p); |
| 25144 | | - sqlite3_mutex_leave(mem0.mutex); |
| 25145 | | - }else{ |
| 25146 | | - sqlite3GlobalConfig.m.xFree(p); |
| 25147 | | - } |
| 25148 | | - } |
| 25149 | | - } |
| 25150 | | -} |
| 25151 | | - |
| 25152 | 25074 | /* |
| 25153 | 25075 | ** TRUE if p is a lookaside memory allocation from db |
| 25154 | 25076 | */ |
| 25155 | 25077 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 25156 | 25078 | static int isLookaside(sqlite3 *db, void *p){ |
| | @@ -25237,11 +25159,10 @@ |
| 25237 | 25159 | /* Trash all content in the buffer being freed */ |
| 25238 | 25160 | memset(p, 0xaa, db->lookaside.sz); |
| 25239 | 25161 | #endif |
| 25240 | 25162 | pBuf->pNext = db->lookaside.pFree; |
| 25241 | 25163 | db->lookaside.pFree = pBuf; |
| 25242 | | - db->lookaside.nOut--; |
| 25243 | 25164 | return; |
| 25244 | 25165 | } |
| 25245 | 25166 | } |
| 25246 | 25167 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 25247 | 25168 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| | @@ -25398,20 +25319,20 @@ |
| 25398 | 25319 | assert( db->pnBytesFreed==0 ); |
| 25399 | 25320 | if( db->lookaside.bDisable==0 ){ |
| 25400 | 25321 | assert( db->mallocFailed==0 ); |
| 25401 | 25322 | if( n>db->lookaside.sz ){ |
| 25402 | 25323 | db->lookaside.anStat[1]++; |
| 25403 | | - }else if( (pBuf = db->lookaside.pFree)==0 ){ |
| 25404 | | - db->lookaside.anStat[2]++; |
| 25405 | | - }else{ |
| 25324 | + }else if( (pBuf = db->lookaside.pFree)!=0 ){ |
| 25406 | 25325 | db->lookaside.pFree = pBuf->pNext; |
| 25407 | | - db->lookaside.nOut++; |
| 25326 | + db->lookaside.anStat[0]++; |
| 25327 | + return (void*)pBuf; |
| 25328 | + }else if( (pBuf = db->lookaside.pInit)!=0 ){ |
| 25329 | + db->lookaside.pInit = pBuf->pNext; |
| 25408 | 25330 | db->lookaside.anStat[0]++; |
| 25409 | | - if( db->lookaside.nOut>db->lookaside.mxOut ){ |
| 25410 | | - db->lookaside.mxOut = db->lookaside.nOut; |
| 25411 | | - } |
| 25412 | 25331 | return (void*)pBuf; |
| 25332 | + }else{ |
| 25333 | + db->lookaside.anStat[2]++; |
| 25413 | 25334 | } |
| 25414 | 25335 | }else if( db->mallocFailed ){ |
| 25415 | 25336 | return 0; |
| 25416 | 25337 | } |
| 25417 | 25338 | #else |
| | @@ -26245,11 +26166,11 @@ |
| 26245 | 26166 | zExtra = bufpt; |
| 26246 | 26167 | } |
| 26247 | 26168 | if( precision>=0 ){ |
| 26248 | 26169 | for(length=0; length<precision && bufpt[length]; length++){} |
| 26249 | 26170 | }else{ |
| 26250 | | - length = sqlite3Strlen30(bufpt); |
| 26171 | + length = 0x7fffffff & (int)strlen(bufpt); |
| 26251 | 26172 | } |
| 26252 | 26173 | break; |
| 26253 | 26174 | case etSQLESCAPE: /* Escape ' characters */ |
| 26254 | 26175 | case etSQLESCAPE2: /* Escape ' and enclose in '...' */ |
| 26255 | 26176 | case etSQLESCAPE3: { /* Escape " characters */ |
| | @@ -26371,11 +26292,10 @@ |
| 26371 | 26292 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 26372 | 26293 | return N; |
| 26373 | 26294 | }else{ |
| 26374 | 26295 | char *zOld = isMalloced(p) ? p->zText : 0; |
| 26375 | 26296 | i64 szNew = p->nChar; |
| 26376 | | - assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
| 26377 | 26297 | szNew += N + 1; |
| 26378 | 26298 | if( szNew+p->nChar<=p->mxAlloc ){ |
| 26379 | 26299 | /* Force exponential buffer size growth as long as it does not overflow, |
| 26380 | 26300 | ** to avoid having to call this routine too often */ |
| 26381 | 26301 | szNew += p->nChar; |
| | @@ -26413,11 +26333,10 @@ |
| 26413 | 26333 | SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){ |
| 26414 | 26334 | testcase( p->nChar + (i64)N > 0x7fffffff ); |
| 26415 | 26335 | if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ |
| 26416 | 26336 | return; |
| 26417 | 26337 | } |
| 26418 | | - assert( (p->zText==p->zBase)==!isMalloced(p) ); |
| 26419 | 26338 | while( (N--)>0 ) p->zText[p->nChar++] = c; |
| 26420 | 26339 | } |
| 26421 | 26340 | |
| 26422 | 26341 | /* |
| 26423 | 26342 | ** The StrAccum "p" is not large enough to accept N new bytes of z[]. |
| | @@ -26431,11 +26350,10 @@ |
| 26431 | 26350 | N = sqlite3StrAccumEnlarge(p, N); |
| 26432 | 26351 | if( N>0 ){ |
| 26433 | 26352 | memcpy(&p->zText[p->nChar], z, N); |
| 26434 | 26353 | p->nChar += N; |
| 26435 | 26354 | } |
| 26436 | | - assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
| 26437 | 26355 | } |
| 26438 | 26356 | |
| 26439 | 26357 | /* |
| 26440 | 26358 | ** Append N bytes of text from z to the StrAccum object. Increase the |
| 26441 | 26359 | ** size of the memory allocation for StrAccum if necessary. |
| | @@ -26466,23 +26384,24 @@ |
| 26466 | 26384 | ** Finish off a string by making sure it is zero-terminated. |
| 26467 | 26385 | ** Return a pointer to the resulting string. Return a NULL |
| 26468 | 26386 | ** pointer if any kind of error was encountered. |
| 26469 | 26387 | */ |
| 26470 | 26388 | static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){ |
| 26389 | + char *zText; |
| 26471 | 26390 | assert( p->mxAlloc>0 && !isMalloced(p) ); |
| 26472 | | - p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 26473 | | - if( p->zText ){ |
| 26474 | | - memcpy(p->zText, p->zBase, p->nChar+1); |
| 26391 | + zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 26392 | + if( zText ){ |
| 26393 | + memcpy(zText, p->zText, p->nChar+1); |
| 26475 | 26394 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 26476 | 26395 | }else{ |
| 26477 | 26396 | setStrAccumError(p, STRACCUM_NOMEM); |
| 26478 | 26397 | } |
| 26479 | | - return p->zText; |
| 26398 | + p->zText = zText; |
| 26399 | + return zText; |
| 26480 | 26400 | } |
| 26481 | 26401 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 26482 | 26402 | if( p->zText ){ |
| 26483 | | - assert( (p->zText==p->zBase)==!isMalloced(p) ); |
| 26484 | 26403 | p->zText[p->nChar] = 0; |
| 26485 | 26404 | if( p->mxAlloc>0 && !isMalloced(p) ){ |
| 26486 | 26405 | return strAccumFinishRealloc(p); |
| 26487 | 26406 | } |
| 26488 | 26407 | } |
| | @@ -26491,11 +26410,10 @@ |
| 26491 | 26410 | |
| 26492 | 26411 | /* |
| 26493 | 26412 | ** Reset an StrAccum string. Reclaim all malloced memory. |
| 26494 | 26413 | */ |
| 26495 | 26414 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ |
| 26496 | | - assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); |
| 26497 | 26415 | if( isMalloced(p) ){ |
| 26498 | 26416 | sqlite3DbFree(p->db, p->zText); |
| 26499 | 26417 | p->printfFlags &= ~SQLITE_PRINTF_MALLOCED; |
| 26500 | 26418 | } |
| 26501 | 26419 | p->zText = 0; |
| | @@ -26514,15 +26432,15 @@ |
| 26514 | 26432 | ** n then no memory allocations ever occur. |
| 26515 | 26433 | ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory |
| 26516 | 26434 | ** allocations will ever occur. |
| 26517 | 26435 | */ |
| 26518 | 26436 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ |
| 26519 | | - p->zText = p->zBase = zBase; |
| 26437 | + p->zText = zBase; |
| 26520 | 26438 | p->db = db; |
| 26521 | | - p->nChar = 0; |
| 26522 | 26439 | p->nAlloc = n; |
| 26523 | 26440 | p->mxAlloc = mx; |
| 26441 | + p->nChar = 0; |
| 26524 | 26442 | p->accError = 0; |
| 26525 | 26443 | p->printfFlags = 0; |
| 26526 | 26444 | } |
| 26527 | 26445 | |
| 26528 | 26446 | /* |
| | @@ -28679,11 +28597,15 @@ |
| 28679 | 28597 | } |
| 28680 | 28598 | }else{ assert( e>=342 ); |
| 28681 | 28599 | if( esign<0 ){ |
| 28682 | 28600 | result = 0.0*s; |
| 28683 | 28601 | }else{ |
| 28602 | +#ifdef INFINITY |
| 28603 | + result = INFINITY*s; |
| 28604 | +#else |
| 28684 | 28605 | result = 1e308*1e308*s; /* Infinity */ |
| 28606 | +#endif |
| 28685 | 28607 | } |
| 28686 | 28608 | } |
| 28687 | 28609 | }else{ |
| 28688 | 28610 | /* 1.0e+22 is the largest power of 10 than can be |
| 28689 | 28611 | ** represented exactly. */ |
| | @@ -28741,20 +28663,16 @@ |
| 28741 | 28663 | |
| 28742 | 28664 | /* |
| 28743 | 28665 | ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This |
| 28744 | 28666 | ** routine does *not* accept hexadecimal notation. |
| 28745 | 28667 | ** |
| 28746 | | -** If the zNum value is representable as a 64-bit twos-complement |
| 28747 | | -** integer, then write that value into *pNum and return 0. |
| 28748 | | -** |
| 28749 | | -** If zNum is exactly 9223372036854775808, return 2. This special |
| 28750 | | -** case is broken out because while 9223372036854775808 cannot be a |
| 28751 | | -** signed 64-bit integer, its negative -9223372036854775808 can be. |
| 28752 | | -** |
| 28753 | | -** If zNum is too big for a 64-bit integer and is not |
| 28754 | | -** 9223372036854775808 or if zNum contains any non-numeric text, |
| 28755 | | -** then return 1. |
| 28668 | +** Returns: |
| 28669 | +** |
| 28670 | +** 0 Successful transformation. Fits in a 64-bit signed integer. |
| 28671 | +** 1 Excess text after the integer value |
| 28672 | +** 2 Integer too large for a 64-bit signed integer or is malformed |
| 28673 | +** 3 Special case of 9223372036854775808 |
| 28756 | 28674 | ** |
| 28757 | 28675 | ** length is the number of bytes in the string (bytes, not characters). |
| 28758 | 28676 | ** The string is not necessarily zero-terminated. The encoding is |
| 28759 | 28677 | ** given by enc. |
| 28760 | 28678 | */ |
| | @@ -28763,10 +28681,11 @@ |
| 28763 | 28681 | u64 u = 0; |
| 28764 | 28682 | int neg = 0; /* assume positive */ |
| 28765 | 28683 | int i; |
| 28766 | 28684 | int c = 0; |
| 28767 | 28685 | int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ |
| 28686 | + int rc; /* Baseline return code */ |
| 28768 | 28687 | const char *zStart; |
| 28769 | 28688 | const char *zEnd = zNum + length; |
| 28770 | 28689 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 28771 | 28690 | if( enc==SQLITE_UTF8 ){ |
| 28772 | 28691 | incr = 1; |
| | @@ -28802,35 +28721,39 @@ |
| 28802 | 28721 | testcase( i==18 ); |
| 28803 | 28722 | testcase( i==19 ); |
| 28804 | 28723 | testcase( i==20 ); |
| 28805 | 28724 | if( &zNum[i]<zEnd /* Extra bytes at the end */ |
| 28806 | 28725 | || (i==0 && zStart==zNum) /* No digits */ |
| 28807 | | - || i>19*incr /* Too many digits */ |
| 28808 | 28726 | || nonNum /* UTF16 with high-order bytes non-zero */ |
| 28809 | 28727 | ){ |
| 28728 | + rc = 1; |
| 28729 | + }else{ |
| 28730 | + rc = 0; |
| 28731 | + } |
| 28732 | + if( i>19*incr ){ /* Too many digits */ |
| 28810 | 28733 | /* zNum is empty or contains non-numeric text or is longer |
| 28811 | 28734 | ** than 19 digits (thus guaranteeing that it is too large) */ |
| 28812 | | - return 1; |
| 28735 | + return 2; |
| 28813 | 28736 | }else if( i<19*incr ){ |
| 28814 | 28737 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| 28815 | 28738 | assert( u<=LARGEST_INT64 ); |
| 28816 | | - return 0; |
| 28739 | + return rc; |
| 28817 | 28740 | }else{ |
| 28818 | 28741 | /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */ |
| 28819 | 28742 | c = compare2pow63(zNum, incr); |
| 28820 | 28743 | if( c<0 ){ |
| 28821 | 28744 | /* zNum is less than 9223372036854775808 so it fits */ |
| 28822 | 28745 | assert( u<=LARGEST_INT64 ); |
| 28823 | | - return 0; |
| 28746 | + return rc; |
| 28824 | 28747 | }else if( c>0 ){ |
| 28825 | 28748 | /* zNum is greater than 9223372036854775808 so it overflows */ |
| 28826 | | - return 1; |
| 28749 | + return 2; |
| 28827 | 28750 | }else{ |
| 28828 | 28751 | /* zNum is exactly 9223372036854775808. Fits if negative. The |
| 28829 | 28752 | ** special case 2 overflow if positive */ |
| 28830 | 28753 | assert( u-1==LARGEST_INT64 ); |
| 28831 | | - return neg ? 0 : 2; |
| 28754 | + return neg ? rc : 3; |
| 28832 | 28755 | } |
| 28833 | 28756 | } |
| 28834 | 28757 | } |
| 28835 | 28758 | |
| 28836 | 28759 | /* |
| | @@ -28839,12 +28762,13 @@ |
| 28839 | 28762 | ** whereas sqlite3Atoi64() does not. |
| 28840 | 28763 | ** |
| 28841 | 28764 | ** Returns: |
| 28842 | 28765 | ** |
| 28843 | 28766 | ** 0 Successful transformation. Fits in a 64-bit signed integer. |
| 28844 | | -** 1 Integer too large for a 64-bit signed integer or is malformed |
| 28845 | | -** 2 Special case of 9223372036854775808 |
| 28767 | +** 1 Excess text after the integer value |
| 28768 | +** 2 Integer too large for a 64-bit signed integer or is malformed |
| 28769 | +** 3 Special case of 9223372036854775808 |
| 28846 | 28770 | */ |
| 28847 | 28771 | SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){ |
| 28848 | 28772 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 28849 | 28773 | if( z[0]=='0' |
| 28850 | 28774 | && (z[1]=='x' || z[1]=='X') |
| | @@ -28854,11 +28778,11 @@ |
| 28854 | 28778 | for(i=2; z[i]=='0'; i++){} |
| 28855 | 28779 | for(k=i; sqlite3Isxdigit(z[k]); k++){ |
| 28856 | 28780 | u = u*16 + sqlite3HexToInt(z[k]); |
| 28857 | 28781 | } |
| 28858 | 28782 | memcpy(pOut, &u, 8); |
| 28859 | | - return (z[k]==0 && k-i<=16) ? 0 : 1; |
| 28783 | + return (z[k]==0 && k-i<=16) ? 0 : 2; |
| 28860 | 28784 | }else |
| 28861 | 28785 | #endif /* SQLITE_OMIT_HEX_INTEGER */ |
| 28862 | 28786 | { |
| 28863 | 28787 | return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8); |
| 28864 | 28788 | } |
| | @@ -29464,11 +29388,11 @@ |
| 29464 | 29388 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 29465 | 29389 | ** Return 0 on success. Or if the operation would have resulted in an |
| 29466 | 29390 | ** overflow, leave *pA unchanged and return 1. |
| 29467 | 29391 | */ |
| 29468 | 29392 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 29469 | | -#if GCC_VERSION>=5004000 |
| 29393 | +#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER) |
| 29470 | 29394 | return __builtin_add_overflow(*pA, iB, pA); |
| 29471 | 29395 | #else |
| 29472 | 29396 | i64 iA = *pA; |
| 29473 | 29397 | testcase( iA==0 ); testcase( iA==1 ); |
| 29474 | 29398 | testcase( iB==-1 ); testcase( iB==0 ); |
| | @@ -29484,11 +29408,11 @@ |
| 29484 | 29408 | *pA += iB; |
| 29485 | 29409 | return 0; |
| 29486 | 29410 | #endif |
| 29487 | 29411 | } |
| 29488 | 29412 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 29489 | | -#if GCC_VERSION>=5004000 |
| 29413 | +#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER) |
| 29490 | 29414 | return __builtin_sub_overflow(*pA, iB, pA); |
| 29491 | 29415 | #else |
| 29492 | 29416 | testcase( iB==SMALLEST_INT64+1 ); |
| 29493 | 29417 | if( iB==SMALLEST_INT64 ){ |
| 29494 | 29418 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| | @@ -29499,11 +29423,11 @@ |
| 29499 | 29423 | return sqlite3AddInt64(pA, -iB); |
| 29500 | 29424 | } |
| 29501 | 29425 | #endif |
| 29502 | 29426 | } |
| 29503 | 29427 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 29504 | | -#if GCC_VERSION>=5004000 |
| 29428 | +#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER) |
| 29505 | 29429 | return __builtin_mul_overflow(*pA, iB, pA); |
| 29506 | 29430 | #else |
| 29507 | 29431 | i64 iA = *pA; |
| 29508 | 29432 | if( iB>0 ){ |
| 29509 | 29433 | if( iA>LARGEST_INT64/iB ) return 1; |
| | @@ -29601,12 +29525,18 @@ |
| 29601 | 29525 | LogEst y = 40; |
| 29602 | 29526 | if( x<8 ){ |
| 29603 | 29527 | if( x<2 ) return 0; |
| 29604 | 29528 | while( x<8 ){ y -= 10; x <<= 1; } |
| 29605 | 29529 | }else{ |
| 29530 | +#if GCC_VERSION>=5004000 |
| 29531 | + int i = 60 - __builtin_clzll(x); |
| 29532 | + y += i*10; |
| 29533 | + x >>= i; |
| 29534 | +#else |
| 29606 | 29535 | while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/ |
| 29607 | 29536 | while( x>15 ){ y += 10; x >>= 1; } |
| 29537 | +#endif |
| 29608 | 29538 | } |
| 29609 | 29539 | return a[x&7] + y - 10; |
| 29610 | 29540 | } |
| 29611 | 29541 | |
| 29612 | 29542 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -30083,51 +30013,51 @@ |
| 30083 | 30013 | /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 30084 | 30014 | /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 30085 | 30015 | /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 30086 | 30016 | /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 30087 | 30017 | /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 30088 | | - /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 30089 | | - /* 44 */ "Program" OpHelp(""), |
| 30090 | | - /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 30091 | | - /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 30092 | | - /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 30093 | | - /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 30094 | | - /* 49 */ "IncrVacuum" OpHelp(""), |
| 30095 | | - /* 50 */ "VNext" OpHelp(""), |
| 30096 | | - /* 51 */ "Init" OpHelp("Start at P2"), |
| 30097 | | - /* 52 */ "Return" OpHelp(""), |
| 30098 | | - /* 53 */ "EndCoroutine" OpHelp(""), |
| 30099 | | - /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 30100 | | - /* 55 */ "Halt" OpHelp(""), |
| 30101 | | - /* 56 */ "Integer" OpHelp("r[P2]=P1"), |
| 30102 | | - /* 57 */ "Int64" OpHelp("r[P2]=P4"), |
| 30103 | | - /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 30104 | | - /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 30105 | | - /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 30106 | | - /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 30107 | | - /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 30108 | | - /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 30109 | | - /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 30110 | | - /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 30111 | | - /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 30112 | | - /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 30113 | | - /* 68 */ "CollSeq" OpHelp(""), |
| 30114 | | - /* 69 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 30115 | | - /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 30116 | | - /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 30117 | | - /* 72 */ "RealAffinity" OpHelp(""), |
| 30118 | | - /* 73 */ "Cast" OpHelp("affinity(r[P1])"), |
| 30119 | | - /* 74 */ "Permutation" OpHelp(""), |
| 30120 | | - /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 30121 | | - /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 30122 | | - /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"), |
| 30123 | | - /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"), |
| 30124 | | - /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"), |
| 30125 | | - /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"), |
| 30126 | | - /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"), |
| 30127 | | - /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"), |
| 30128 | | - /* 83 */ "ElseNotEq" OpHelp(""), |
| 30018 | + /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 30019 | + /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 30020 | + /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 30021 | + /* 46 */ "Program" OpHelp(""), |
| 30022 | + /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 30023 | + /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 30024 | + /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 30025 | + /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 30026 | + /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 30027 | + /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"), |
| 30028 | + /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"), |
| 30029 | + /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"), |
| 30030 | + /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"), |
| 30031 | + /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"), |
| 30032 | + /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"), |
| 30033 | + /* 58 */ "ElseNotEq" OpHelp(""), |
| 30034 | + /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 30035 | + /* 60 */ "IncrVacuum" OpHelp(""), |
| 30036 | + /* 61 */ "VNext" OpHelp(""), |
| 30037 | + /* 62 */ "Init" OpHelp("Start at P2"), |
| 30038 | + /* 63 */ "Return" OpHelp(""), |
| 30039 | + /* 64 */ "EndCoroutine" OpHelp(""), |
| 30040 | + /* 65 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 30041 | + /* 66 */ "Halt" OpHelp(""), |
| 30042 | + /* 67 */ "Integer" OpHelp("r[P2]=P1"), |
| 30043 | + /* 68 */ "Int64" OpHelp("r[P2]=P4"), |
| 30044 | + /* 69 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 30045 | + /* 70 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 30046 | + /* 71 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 30047 | + /* 72 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 30048 | + /* 73 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 30049 | + /* 74 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 30050 | + /* 75 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 30051 | + /* 76 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 30052 | + /* 77 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 30053 | + /* 78 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 30054 | + /* 79 */ "CollSeq" OpHelp(""), |
| 30055 | + /* 80 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 30056 | + /* 81 */ "RealAffinity" OpHelp(""), |
| 30057 | + /* 82 */ "Cast" OpHelp("affinity(r[P1])"), |
| 30058 | + /* 83 */ "Permutation" OpHelp(""), |
| 30129 | 30059 | /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 30130 | 30060 | /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 30131 | 30061 | /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 30132 | 30062 | /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 30133 | 30063 | /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -30165,21 +30095,21 @@ |
| 30165 | 30095 | /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 30166 | 30096 | /* 121 */ "SorterData" OpHelp("r[P2]=data"), |
| 30167 | 30097 | /* 122 */ "RowData" OpHelp("r[P2]=data"), |
| 30168 | 30098 | /* 123 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 30169 | 30099 | /* 124 */ "NullRow" OpHelp(""), |
| 30170 | | - /* 125 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 30171 | | - /* 126 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 30172 | | - /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 30173 | | - /* 128 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 30174 | | - /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 30175 | | - /* 130 */ "Destroy" OpHelp(""), |
| 30176 | | - /* 131 */ "Clear" OpHelp(""), |
| 30100 | + /* 125 */ "SeekEnd" OpHelp(""), |
| 30101 | + /* 126 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 30102 | + /* 127 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 30103 | + /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 30104 | + /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 30105 | + /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 30106 | + /* 131 */ "Destroy" OpHelp(""), |
| 30177 | 30107 | /* 132 */ "Real" OpHelp("r[P2]=P4"), |
| 30178 | | - /* 133 */ "ResetSorter" OpHelp(""), |
| 30179 | | - /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 30180 | | - /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 30108 | + /* 133 */ "Clear" OpHelp(""), |
| 30109 | + /* 134 */ "ResetSorter" OpHelp(""), |
| 30110 | + /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 30181 | 30111 | /* 136 */ "SqlExec" OpHelp(""), |
| 30182 | 30112 | /* 137 */ "ParseSchema" OpHelp(""), |
| 30183 | 30113 | /* 138 */ "LoadAnalysis" OpHelp(""), |
| 30184 | 30114 | /* 139 */ "DropTable" OpHelp(""), |
| 30185 | 30115 | /* 140 */ "DropIndex" OpHelp(""), |
| | @@ -30307,20 +30237,21 @@ |
| 30307 | 30237 | ** standard include files. |
| 30308 | 30238 | */ |
| 30309 | 30239 | #include <sys/types.h> |
| 30310 | 30240 | #include <sys/stat.h> |
| 30311 | 30241 | #include <fcntl.h> |
| 30242 | +#include <sys/ioctl.h> |
| 30312 | 30243 | #include <unistd.h> |
| 30313 | 30244 | /* #include <time.h> */ |
| 30314 | 30245 | #include <sys/time.h> |
| 30315 | 30246 | #include <errno.h> |
| 30316 | 30247 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 30317 | 30248 | # include <sys/mman.h> |
| 30318 | 30249 | #endif |
| 30319 | 30250 | |
| 30320 | 30251 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 30321 | | -# include <sys/ioctl.h> |
| 30252 | +/* # include <sys/ioctl.h> */ |
| 30322 | 30253 | # include <sys/file.h> |
| 30323 | 30254 | # include <sys/param.h> |
| 30324 | 30255 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
| 30325 | 30256 | |
| 30326 | 30257 | #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ |
| | @@ -30426,11 +30357,11 @@ |
| 30426 | 30357 | int h; /* The file descriptor */ |
| 30427 | 30358 | unsigned char eFileLock; /* The type of lock held on this fd */ |
| 30428 | 30359 | unsigned short int ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */ |
| 30429 | 30360 | int lastErrno; /* The unix errno from last I/O error */ |
| 30430 | 30361 | void *lockingContext; /* Locking style specific state */ |
| 30431 | | - UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */ |
| 30362 | + UnixUnusedFd *pPreallocatedUnused; /* Pre-allocated UnixUnusedFd */ |
| 30432 | 30363 | const char *zPath; /* Name of the file */ |
| 30433 | 30364 | unixShm *pShm; /* Shared memory segment information */ |
| 30434 | 30365 | int szChunk; /* Configured by FCNTL_CHUNK_SIZE */ |
| 30435 | 30366 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 30436 | 30367 | int nFetchOut; /* Number of outstanding xFetch refs */ |
| | @@ -30437,14 +30368,12 @@ |
| 30437 | 30368 | sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */ |
| 30438 | 30369 | sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */ |
| 30439 | 30370 | sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */ |
| 30440 | 30371 | void *pMapRegion; /* Memory mapped region */ |
| 30441 | 30372 | #endif |
| 30442 | | -#ifdef __QNXNTO__ |
| 30443 | 30373 | int sectorSize; /* Device sector size */ |
| 30444 | 30374 | int deviceCharacteristics; /* Precomputed device characteristics */ |
| 30445 | | -#endif |
| 30446 | 30375 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 30447 | 30376 | int openFlags; /* The flags specified at open() */ |
| 30448 | 30377 | #endif |
| 30449 | 30378 | #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) |
| 30450 | 30379 | unsigned fsFlags; /* cached details from statfs() */ |
| | @@ -30742,10 +30671,24 @@ |
| 30742 | 30671 | ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined. |
| 30743 | 30672 | */ |
| 30744 | 30673 | #ifdef __ANDROID__ |
| 30745 | 30674 | # define lseek lseek64 |
| 30746 | 30675 | #endif |
| 30676 | + |
| 30677 | +#ifdef __linux__ |
| 30678 | +/* |
| 30679 | +** Linux-specific IOCTL magic numbers used for controlling F2FS |
| 30680 | +*/ |
| 30681 | +#define F2FS_IOCTL_MAGIC 0xf5 |
| 30682 | +#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) |
| 30683 | +#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) |
| 30684 | +#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) |
| 30685 | +#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) |
| 30686 | +#define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, u32) |
| 30687 | +#define F2FS_FEATURE_ATOMIC_WRITE 0x0004 |
| 30688 | +#endif /* __linux__ */ |
| 30689 | + |
| 30747 | 30690 | |
| 30748 | 30691 | /* |
| 30749 | 30692 | ** Different Unix systems declare open() in different ways. Same use |
| 30750 | 30693 | ** open(const char*,int,mode_t). Others use open(const char*,int,...). |
| 30751 | 30694 | ** The difference is important when using a pointer to the function. |
| | @@ -30914,10 +30857,13 @@ |
| 30914 | 30857 | { "lstat", (sqlite3_syscall_ptr)lstat, 0 }, |
| 30915 | 30858 | #else |
| 30916 | 30859 | { "lstat", (sqlite3_syscall_ptr)0, 0 }, |
| 30917 | 30860 | #endif |
| 30918 | 30861 | #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent) |
| 30862 | + |
| 30863 | + { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 }, |
| 30864 | +#define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent) |
| 30919 | 30865 | |
| 30920 | 30866 | }; /* End of the overrideable system calls */ |
| 30921 | 30867 | |
| 30922 | 30868 | |
| 30923 | 30869 | /* |
| | @@ -31519,11 +31465,12 @@ |
| 31519 | 31465 | }; |
| 31520 | 31466 | |
| 31521 | 31467 | /* |
| 31522 | 31468 | ** A lists of all unixInodeInfo objects. |
| 31523 | 31469 | */ |
| 31524 | | -static unixInodeInfo *inodeList = 0; |
| 31470 | +static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */ |
| 31471 | +static unsigned int nUnusedFd = 0; /* Total unused file descriptors */ |
| 31525 | 31472 | |
| 31526 | 31473 | /* |
| 31527 | 31474 | ** |
| 31528 | 31475 | ** This function - unixLogErrorAtLine(), is only ever called via the macro |
| 31529 | 31476 | ** unixLogError(). |
| | @@ -31629,10 +31576,11 @@ |
| 31629 | 31576 | UnixUnusedFd *pNext; |
| 31630 | 31577 | for(p=pInode->pUnused; p; p=pNext){ |
| 31631 | 31578 | pNext = p->pNext; |
| 31632 | 31579 | robust_close(pFile, p->fd, __LINE__); |
| 31633 | 31580 | sqlite3_free(p); |
| 31581 | + nUnusedFd--; |
| 31634 | 31582 | } |
| 31635 | 31583 | pInode->pUnused = 0; |
| 31636 | 31584 | } |
| 31637 | 31585 | |
| 31638 | 31586 | /* |
| | @@ -31661,10 +31609,11 @@ |
| 31661 | 31609 | pInode->pNext->pPrev = pInode->pPrev; |
| 31662 | 31610 | } |
| 31663 | 31611 | sqlite3_free(pInode); |
| 31664 | 31612 | } |
| 31665 | 31613 | } |
| 31614 | + assert( inodeList!=0 || nUnusedFd==0 ); |
| 31666 | 31615 | } |
| 31667 | 31616 | |
| 31668 | 31617 | /* |
| 31669 | 31618 | ** Given a file descriptor, locate the unixInodeInfo object that |
| 31670 | 31619 | ** describes that file descriptor. Create a new one if necessary. The |
| | @@ -31730,10 +31679,11 @@ |
| 31730 | 31679 | #if OS_VXWORKS |
| 31731 | 31680 | fileId.pId = pFile->pId; |
| 31732 | 31681 | #else |
| 31733 | 31682 | fileId.ino = (u64)statbuf.st_ino; |
| 31734 | 31683 | #endif |
| 31684 | + assert( inodeList!=0 || nUnusedFd==0 ); |
| 31735 | 31685 | pInode = inodeList; |
| 31736 | 31686 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 31737 | 31687 | pInode = pInode->pNext; |
| 31738 | 31688 | } |
| 31739 | 31689 | if( pInode==0 ){ |
| | @@ -32149,15 +32099,16 @@ |
| 32149 | 32099 | ** Add the file descriptor used by file handle pFile to the corresponding |
| 32150 | 32100 | ** pUnused list. |
| 32151 | 32101 | */ |
| 32152 | 32102 | static void setPendingFd(unixFile *pFile){ |
| 32153 | 32103 | unixInodeInfo *pInode = pFile->pInode; |
| 32154 | | - UnixUnusedFd *p = pFile->pUnused; |
| 32104 | + UnixUnusedFd *p = pFile->pPreallocatedUnused; |
| 32155 | 32105 | p->pNext = pInode->pUnused; |
| 32156 | 32106 | pInode->pUnused = p; |
| 32157 | 32107 | pFile->h = -1; |
| 32158 | | - pFile->pUnused = 0; |
| 32108 | + pFile->pPreallocatedUnused = 0; |
| 32109 | + nUnusedFd++; |
| 32159 | 32110 | } |
| 32160 | 32111 | |
| 32161 | 32112 | /* |
| 32162 | 32113 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock |
| 32163 | 32114 | ** must be either NO_LOCK or SHARED_LOCK. |
| | @@ -32378,11 +32329,11 @@ |
| 32378 | 32329 | pFile->zPath = 0; |
| 32379 | 32330 | } |
| 32380 | 32331 | #endif |
| 32381 | 32332 | OSTRACE(("CLOSE %-3d\n", pFile->h)); |
| 32382 | 32333 | OpenCounter(-1); |
| 32383 | | - sqlite3_free(pFile->pUnused); |
| 32334 | + sqlite3_free(pFile->pPreallocatedUnused); |
| 32384 | 32335 | memset(pFile, 0, sizeof(unixFile)); |
| 32385 | 32336 | return SQLITE_OK; |
| 32386 | 32337 | } |
| 32387 | 32338 | |
| 32388 | 32339 | /* |
| | @@ -32715,11 +32666,11 @@ |
| 32715 | 32666 | } |
| 32716 | 32667 | } |
| 32717 | 32668 | OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved)); |
| 32718 | 32669 | |
| 32719 | 32670 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 32720 | | - if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){ |
| 32671 | + if( (rc & 0xff) == SQLITE_IOERR ){ |
| 32721 | 32672 | rc = SQLITE_OK; |
| 32722 | 32673 | reserved=1; |
| 32723 | 32674 | } |
| 32724 | 32675 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ |
| 32725 | 32676 | *pResOut = reserved; |
| | @@ -32782,11 +32733,11 @@ |
| 32782 | 32733 | pFile->eFileLock = eFileLock; |
| 32783 | 32734 | } |
| 32784 | 32735 | OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock), |
| 32785 | 32736 | rc==SQLITE_OK ? "ok" : "failed")); |
| 32786 | 32737 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 32787 | | - if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){ |
| 32738 | + if( (rc & 0xff) == SQLITE_IOERR ){ |
| 32788 | 32739 | rc = SQLITE_BUSY; |
| 32789 | 32740 | } |
| 32790 | 32741 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ |
| 32791 | 32742 | return rc; |
| 32792 | 32743 | } |
| | @@ -33319,11 +33270,11 @@ |
| 33319 | 33270 | if( failed && (failed2 = afpSetLock(context->dbPath, pFile, |
| 33320 | 33271 | SHARED_FIRST + pInode->sharedByte, 1, 1)) ){ |
| 33321 | 33272 | /* Can't reestablish the shared lock. Sqlite can't deal, this is |
| 33322 | 33273 | ** a critical I/O error |
| 33323 | 33274 | */ |
| 33324 | | - rc = ((failed & SQLITE_IOERR) == SQLITE_IOERR) ? failed2 : |
| 33275 | + rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 : |
| 33325 | 33276 | SQLITE_IOERR_LOCK; |
| 33326 | 33277 | goto afp_end_lock; |
| 33327 | 33278 | } |
| 33328 | 33279 | }else{ |
| 33329 | 33280 | rc = failed; |
| | @@ -33599,11 +33550,11 @@ |
| 33599 | 33550 | assert( amt>0 ); |
| 33600 | 33551 | |
| 33601 | 33552 | /* If this is a database file (not a journal, master-journal or temp |
| 33602 | 33553 | ** file), the bytes in the locking range should never be read or written. */ |
| 33603 | 33554 | #if 0 |
| 33604 | | - assert( pFile->pUnused==0 |
| 33555 | + assert( pFile->pPreallocatedUnused==0 |
| 33605 | 33556 | || offset>=PENDING_BYTE+512 |
| 33606 | 33557 | || offset+amt<=PENDING_BYTE |
| 33607 | 33558 | ); |
| 33608 | 33559 | #endif |
| 33609 | 33560 | |
| | @@ -33712,11 +33663,11 @@ |
| 33712 | 33663 | assert( amt>0 ); |
| 33713 | 33664 | |
| 33714 | 33665 | /* If this is a database file (not a journal, master-journal or temp |
| 33715 | 33666 | ** file), the bytes in the locking range should never be read or written. */ |
| 33716 | 33667 | #if 0 |
| 33717 | | - assert( pFile->pUnused==0 |
| 33668 | + assert( pFile->pPreallocatedUnused==0 |
| 33718 | 33669 | || offset>=PENDING_BYTE+512 |
| 33719 | 33670 | || offset+amt<=PENDING_BYTE |
| 33720 | 33671 | ); |
| 33721 | 33672 | #endif |
| 33722 | 33673 | |
| | @@ -34192,10 +34143,25 @@ |
| 34192 | 34143 | ** Information and control of an open file handle. |
| 34193 | 34144 | */ |
| 34194 | 34145 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| 34195 | 34146 | unixFile *pFile = (unixFile*)id; |
| 34196 | 34147 | switch( op ){ |
| 34148 | +#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 34149 | + case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: { |
| 34150 | + int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE); |
| 34151 | + return rc ? SQLITE_IOERR_BEGIN_ATOMIC : SQLITE_OK; |
| 34152 | + } |
| 34153 | + case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: { |
| 34154 | + int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE); |
| 34155 | + return rc ? SQLITE_IOERR_COMMIT_ATOMIC : SQLITE_OK; |
| 34156 | + } |
| 34157 | + case SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: { |
| 34158 | + int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE); |
| 34159 | + return rc ? SQLITE_IOERR_ROLLBACK_ATOMIC : SQLITE_OK; |
| 34160 | + } |
| 34161 | +#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */ |
| 34162 | + |
| 34197 | 34163 | case SQLITE_FCNTL_LOCKSTATE: { |
| 34198 | 34164 | *(int*)pArg = pFile->eFileLock; |
| 34199 | 34165 | return SQLITE_OK; |
| 34200 | 34166 | } |
| 34201 | 34167 | case SQLITE_FCNTL_LAST_ERRNO: { |
| | @@ -34242,10 +34208,18 @@ |
| 34242 | 34208 | i64 newLimit = *(i64*)pArg; |
| 34243 | 34209 | int rc = SQLITE_OK; |
| 34244 | 34210 | if( newLimit>sqlite3GlobalConfig.mxMmap ){ |
| 34245 | 34211 | newLimit = sqlite3GlobalConfig.mxMmap; |
| 34246 | 34212 | } |
| 34213 | + |
| 34214 | + /* The value of newLimit may be eventually cast to (size_t) and passed |
| 34215 | + ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a |
| 34216 | + ** 64-bit type. */ |
| 34217 | + if( newLimit>0 && sizeof(size_t)<8 ){ |
| 34218 | + newLimit = (newLimit & 0x7FFFFFFF); |
| 34219 | + } |
| 34220 | + |
| 34247 | 34221 | *(i64*)pArg = pFile->mmapSizeMax; |
| 34248 | 34222 | if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ |
| 34249 | 34223 | pFile->mmapSizeMax = newLimit; |
| 34250 | 34224 | if( pFile->mmapSize>0 ){ |
| 34251 | 34225 | unixUnmapfile(pFile); |
| | @@ -34275,34 +34249,45 @@ |
| 34275 | 34249 | } |
| 34276 | 34250 | return SQLITE_NOTFOUND; |
| 34277 | 34251 | } |
| 34278 | 34252 | |
| 34279 | 34253 | /* |
| 34280 | | -** Return the sector size in bytes of the underlying block device for |
| 34281 | | -** the specified file. This is almost always 512 bytes, but may be |
| 34282 | | -** larger for some devices. |
| 34254 | +** If pFd->sectorSize is non-zero when this function is called, it is a |
| 34255 | +** no-op. Otherwise, the values of pFd->sectorSize and |
| 34256 | +** pFd->deviceCharacteristics are set according to the file-system |
| 34257 | +** characteristics. |
| 34283 | 34258 | ** |
| 34284 | | -** SQLite code assumes this function cannot fail. It also assumes that |
| 34285 | | -** if two files are created in the same file-system directory (i.e. |
| 34286 | | -** a database and its journal file) that the sector size will be the |
| 34287 | | -** same for both. |
| 34288 | | -*/ |
| 34289 | | -#ifndef __QNXNTO__ |
| 34290 | | -static int unixSectorSize(sqlite3_file *NotUsed){ |
| 34291 | | - UNUSED_PARAMETER(NotUsed); |
| 34292 | | - return SQLITE_DEFAULT_SECTOR_SIZE; |
| 34293 | | -} |
| 34294 | | -#endif |
| 34295 | | - |
| 34296 | | -/* |
| 34297 | | -** The following version of unixSectorSize() is optimized for QNX. |
| 34298 | | -*/ |
| 34299 | | -#ifdef __QNXNTO__ |
| 34259 | +** There are two versions of this function. One for QNX and one for all |
| 34260 | +** other systems. |
| 34261 | +*/ |
| 34262 | +#ifndef __QNXNTO__ |
| 34263 | +static void setDeviceCharacteristics(unixFile *pFd){ |
| 34264 | + assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 ); |
| 34265 | + if( pFd->sectorSize==0 ){ |
| 34266 | +#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 34267 | + int res; |
| 34268 | + u32 f = 0; |
| 34269 | + |
| 34270 | + /* Check for support for F2FS atomic batch writes. */ |
| 34271 | + res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f); |
| 34272 | + if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){ |
| 34273 | + pFd->deviceCharacteristics = SQLITE_IOCAP_BATCH_ATOMIC; |
| 34274 | + } |
| 34275 | +#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */ |
| 34276 | + |
| 34277 | + /* Set the POWERSAFE_OVERWRITE flag if requested. */ |
| 34278 | + if( pFd->ctrlFlags & UNIXFILE_PSOW ){ |
| 34279 | + pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE; |
| 34280 | + } |
| 34281 | + |
| 34282 | + pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; |
| 34283 | + } |
| 34284 | +} |
| 34285 | +#else |
| 34300 | 34286 | #include <sys/dcmd_blk.h> |
| 34301 | 34287 | #include <sys/statvfs.h> |
| 34302 | | -static int unixSectorSize(sqlite3_file *id){ |
| 34303 | | - unixFile *pFile = (unixFile*)id; |
| 34288 | +static void setDeviceCharacteristics(unixFile *pFile){ |
| 34304 | 34289 | if( pFile->sectorSize == 0 ){ |
| 34305 | 34290 | struct statvfs fsInfo; |
| 34306 | 34291 | |
| 34307 | 34292 | /* Set defaults for non-supported filesystems */ |
| 34308 | 34293 | pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; |
| | @@ -34367,13 +34352,28 @@ |
| 34367 | 34352 | ** then it isn't valid.*/ |
| 34368 | 34353 | if( pFile->sectorSize % 512 != 0 ){ |
| 34369 | 34354 | pFile->deviceCharacteristics = 0; |
| 34370 | 34355 | pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; |
| 34371 | 34356 | } |
| 34372 | | - return pFile->sectorSize; |
| 34373 | 34357 | } |
| 34374 | | -#endif /* __QNXNTO__ */ |
| 34358 | +#endif |
| 34359 | + |
| 34360 | +/* |
| 34361 | +** Return the sector size in bytes of the underlying block device for |
| 34362 | +** the specified file. This is almost always 512 bytes, but may be |
| 34363 | +** larger for some devices. |
| 34364 | +** |
| 34365 | +** SQLite code assumes this function cannot fail. It also assumes that |
| 34366 | +** if two files are created in the same file-system directory (i.e. |
| 34367 | +** a database and its journal file) that the sector size will be the |
| 34368 | +** same for both. |
| 34369 | +*/ |
| 34370 | +static int unixSectorSize(sqlite3_file *id){ |
| 34371 | + unixFile *pFd = (unixFile*)id; |
| 34372 | + setDeviceCharacteristics(pFd); |
| 34373 | + return pFd->sectorSize; |
| 34374 | +} |
| 34375 | 34375 | |
| 34376 | 34376 | /* |
| 34377 | 34377 | ** Return the device characteristics for the file. |
| 34378 | 34378 | ** |
| 34379 | 34379 | ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default. |
| | @@ -34385,20 +34385,13 @@ |
| 34385 | 34385 | ** of required I/O for journaling, since a lot of padding is eliminated. |
| 34386 | 34386 | ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control |
| 34387 | 34387 | ** available to turn it off and URI query parameter available to turn it off. |
| 34388 | 34388 | */ |
| 34389 | 34389 | static int unixDeviceCharacteristics(sqlite3_file *id){ |
| 34390 | | - unixFile *p = (unixFile*)id; |
| 34391 | | - int rc = 0; |
| 34392 | | -#ifdef __QNXNTO__ |
| 34393 | | - if( p->sectorSize==0 ) unixSectorSize(id); |
| 34394 | | - rc = p->deviceCharacteristics; |
| 34395 | | -#endif |
| 34396 | | - if( p->ctrlFlags & UNIXFILE_PSOW ){ |
| 34397 | | - rc |= SQLITE_IOCAP_POWERSAFE_OVERWRITE; |
| 34398 | | - } |
| 34399 | | - return rc; |
| 34390 | + unixFile *pFd = (unixFile*)id; |
| 34391 | + setDeviceCharacteristics(pFd); |
| 34392 | + return pFd->deviceCharacteristics; |
| 34400 | 34393 | } |
| 34401 | 34394 | |
| 34402 | 34395 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 34403 | 34396 | |
| 34404 | 34397 | /* |
| | @@ -35652,21 +35645,10 @@ |
| 35652 | 35645 | unixFile *pNew = (unixFile *)pId; |
| 35653 | 35646 | int rc = SQLITE_OK; |
| 35654 | 35647 | |
| 35655 | 35648 | assert( pNew->pInode==NULL ); |
| 35656 | 35649 | |
| 35657 | | - /* Usually the path zFilename should not be a relative pathname. The |
| 35658 | | - ** exception is when opening the proxy "conch" file in builds that |
| 35659 | | - ** include the special Apple locking styles. |
| 35660 | | - */ |
| 35661 | | -#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
| 35662 | | - assert( zFilename==0 || zFilename[0]=='/' |
| 35663 | | - || pVfs->pAppData==(void*)&autolockIoFinder ); |
| 35664 | | -#else |
| 35665 | | - assert( zFilename==0 || zFilename[0]=='/' ); |
| 35666 | | -#endif |
| 35667 | | - |
| 35668 | 35650 | /* No locking occurs in temporary files */ |
| 35669 | 35651 | assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); |
| 35670 | 35652 | |
| 35671 | 35653 | OSTRACE(("OPEN %-3d %s\n", h, zFilename)); |
| 35672 | 35654 | pNew->h = h; |
| | @@ -35920,23 +35902,24 @@ |
| 35920 | 35902 | ** but because no way to test it is currently available. It is better |
| 35921 | 35903 | ** not to risk breaking vxworks support for the sake of such an obscure |
| 35922 | 35904 | ** feature. */ |
| 35923 | 35905 | #if !OS_VXWORKS |
| 35924 | 35906 | struct stat sStat; /* Results of stat() call */ |
| 35907 | + |
| 35908 | + unixEnterMutex(); |
| 35925 | 35909 | |
| 35926 | 35910 | /* A stat() call may fail for various reasons. If this happens, it is |
| 35927 | 35911 | ** almost certain that an open() call on the same path will also fail. |
| 35928 | 35912 | ** For this reason, if an error occurs in the stat() call here, it is |
| 35929 | 35913 | ** ignored and -1 is returned. The caller will try to open a new file |
| 35930 | 35914 | ** descriptor on the same path, fail, and return an error to SQLite. |
| 35931 | 35915 | ** |
| 35932 | 35916 | ** Even if a subsequent open() call does succeed, the consequences of |
| 35933 | 35917 | ** not searching for a reusable file descriptor are not dire. */ |
| 35934 | | - if( 0==osStat(zPath, &sStat) ){ |
| 35918 | + if( nUnusedFd>0 && 0==osStat(zPath, &sStat) ){ |
| 35935 | 35919 | unixInodeInfo *pInode; |
| 35936 | 35920 | |
| 35937 | | - unixEnterMutex(); |
| 35938 | 35921 | pInode = inodeList; |
| 35939 | 35922 | while( pInode && (pInode->fileId.dev!=sStat.st_dev |
| 35940 | 35923 | || pInode->fileId.ino!=(u64)sStat.st_ino) ){ |
| 35941 | 35924 | pInode = pInode->pNext; |
| 35942 | 35925 | } |
| | @@ -35943,15 +35926,16 @@ |
| 35943 | 35926 | if( pInode ){ |
| 35944 | 35927 | UnixUnusedFd **pp; |
| 35945 | 35928 | for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext)); |
| 35946 | 35929 | pUnused = *pp; |
| 35947 | 35930 | if( pUnused ){ |
| 35931 | + nUnusedFd--; |
| 35948 | 35932 | *pp = pUnused->pNext; |
| 35949 | 35933 | } |
| 35950 | 35934 | } |
| 35951 | | - unixLeaveMutex(); |
| 35952 | 35935 | } |
| 35936 | + unixLeaveMutex(); |
| 35953 | 35937 | #endif /* if !OS_VXWORKS */ |
| 35954 | 35938 | return pUnused; |
| 35955 | 35939 | } |
| 35956 | 35940 | |
| 35957 | 35941 | /* |
| | @@ -36023,20 +36007,15 @@ |
| 36023 | 36007 | ** where NN is a decimal number. The NN naming schemes are |
| 36024 | 36008 | ** used by the test_multiplex.c module. |
| 36025 | 36009 | */ |
| 36026 | 36010 | nDb = sqlite3Strlen30(zPath) - 1; |
| 36027 | 36011 | while( zPath[nDb]!='-' ){ |
| 36028 | | -#ifndef SQLITE_ENABLE_8_3_NAMES |
| 36029 | | - /* In the normal case (8+3 filenames disabled) the journal filename |
| 36030 | | - ** is guaranteed to contain a '-' character. */ |
| 36031 | | - assert( nDb>0 ); |
| 36032 | | - assert( sqlite3Isalnum(zPath[nDb]) ); |
| 36033 | | -#else |
| 36034 | | - /* If 8+3 names are possible, then the journal file might not contain |
| 36035 | | - ** a '-' character. So check for that case and return early. */ |
| 36012 | + /* In normal operation, the journal file name will always contain |
| 36013 | + ** a '-' character. However in 8+3 filename mode, or if a corrupt |
| 36014 | + ** rollback journal specifies a master journal with a goofy name, then |
| 36015 | + ** the '-' might be missing. */ |
| 36036 | 36016 | if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; |
| 36037 | | -#endif |
| 36038 | 36017 | nDb--; |
| 36039 | 36018 | } |
| 36040 | 36019 | memcpy(zDb, zPath, nDb); |
| 36041 | 36020 | zDb[nDb] = '\0'; |
| 36042 | 36021 | |
| | @@ -36168,11 +36147,11 @@ |
| 36168 | 36147 | pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| 36169 | 36148 | if( !pUnused ){ |
| 36170 | 36149 | return SQLITE_NOMEM_BKPT; |
| 36171 | 36150 | } |
| 36172 | 36151 | } |
| 36173 | | - p->pUnused = pUnused; |
| 36152 | + p->pPreallocatedUnused = pUnused; |
| 36174 | 36153 | |
| 36175 | 36154 | /* Database filenames are double-zero terminated if they are not |
| 36176 | 36155 | ** URIs with parameters. Hence, they can always be passed into |
| 36177 | 36156 | ** sqlite3_uri_parameter(). */ |
| 36178 | 36157 | assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); |
| | @@ -36205,11 +36184,11 @@ |
| 36205 | 36184 | mode_t openMode; /* Permissions to create file with */ |
| 36206 | 36185 | uid_t uid; /* Userid for the file */ |
| 36207 | 36186 | gid_t gid; /* Groupid for the file */ |
| 36208 | 36187 | rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid); |
| 36209 | 36188 | if( rc!=SQLITE_OK ){ |
| 36210 | | - assert( !p->pUnused ); |
| 36189 | + assert( !p->pPreallocatedUnused ); |
| 36211 | 36190 | assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL ); |
| 36212 | 36191 | return rc; |
| 36213 | 36192 | } |
| 36214 | 36193 | fd = robust_open(zName, openFlags, openMode); |
| 36215 | 36194 | OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); |
| | @@ -36239,13 +36218,13 @@ |
| 36239 | 36218 | assert( fd>=0 ); |
| 36240 | 36219 | if( pOutFlags ){ |
| 36241 | 36220 | *pOutFlags = flags; |
| 36242 | 36221 | } |
| 36243 | 36222 | |
| 36244 | | - if( p->pUnused ){ |
| 36245 | | - p->pUnused->fd = fd; |
| 36246 | | - p->pUnused->flags = flags; |
| 36223 | + if( p->pPreallocatedUnused ){ |
| 36224 | + p->pPreallocatedUnused->fd = fd; |
| 36225 | + p->pPreallocatedUnused->flags = flags; |
| 36247 | 36226 | } |
| 36248 | 36227 | |
| 36249 | 36228 | if( isDelete ){ |
| 36250 | 36229 | #if OS_VXWORKS |
| 36251 | 36230 | zPath = zName; |
| | @@ -36318,15 +36297,18 @@ |
| 36318 | 36297 | goto open_finished; |
| 36319 | 36298 | } |
| 36320 | 36299 | } |
| 36321 | 36300 | #endif |
| 36322 | 36301 | |
| 36302 | + assert( zPath==0 || zPath[0]=='/' |
| 36303 | + || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 36304 | + ); |
| 36323 | 36305 | rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| 36324 | 36306 | |
| 36325 | 36307 | open_finished: |
| 36326 | 36308 | if( rc!=SQLITE_OK ){ |
| 36327 | | - sqlite3_free(p->pUnused); |
| 36309 | + sqlite3_free(p->pPreallocatedUnused); |
| 36328 | 36310 | } |
| 36329 | 36311 | return rc; |
| 36330 | 36312 | } |
| 36331 | 36313 | |
| 36332 | 36314 | |
| | @@ -37063,11 +37045,11 @@ |
| 37063 | 37045 | memset(&dummyVfs, 0, sizeof(dummyVfs)); |
| 37064 | 37046 | dummyVfs.pAppData = (void*)&autolockIoFinder; |
| 37065 | 37047 | dummyVfs.zName = "dummy"; |
| 37066 | 37048 | pUnused->fd = fd; |
| 37067 | 37049 | pUnused->flags = openFlags; |
| 37068 | | - pNew->pUnused = pUnused; |
| 37050 | + pNew->pPreallocatedUnused = pUnused; |
| 37069 | 37051 | |
| 37070 | 37052 | rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); |
| 37071 | 37053 | if( rc==SQLITE_OK ){ |
| 37072 | 37054 | *ppFile = pNew; |
| 37073 | 37055 | return SQLITE_OK; |
| | @@ -38013,11 +37995,11 @@ |
| 38013 | 37995 | }; |
| 38014 | 37996 | unsigned int i; /* Loop counter */ |
| 38015 | 37997 | |
| 38016 | 37998 | /* Double-check that the aSyscall[] array has been constructed |
| 38017 | 37999 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 38018 | | - assert( ArraySize(aSyscall)==28 ); |
| 38000 | + assert( ArraySize(aSyscall)==29 ); |
| 38019 | 38001 | |
| 38020 | 38002 | /* Register all VFSes defined in the aVfs[] array */ |
| 38021 | 38003 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 38022 | 38004 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 38023 | 38005 | } |
| | @@ -41796,10 +41778,18 @@ |
| 41796 | 41778 | i64 newLimit = *(i64*)pArg; |
| 41797 | 41779 | int rc = SQLITE_OK; |
| 41798 | 41780 | if( newLimit>sqlite3GlobalConfig.mxMmap ){ |
| 41799 | 41781 | newLimit = sqlite3GlobalConfig.mxMmap; |
| 41800 | 41782 | } |
| 41783 | + |
| 41784 | + /* The value of newLimit may be eventually cast to (SIZE_T) and passed |
| 41785 | + ** to MapViewOfFile(). Restrict its value to 2GB if (SIZE_T) is not at |
| 41786 | + ** least a 64-bit type. */ |
| 41787 | + if( newLimit>0 && sizeof(SIZE_T)<8 ){ |
| 41788 | + newLimit = (newLimit & 0x7FFFFFFF); |
| 41789 | + } |
| 41790 | + |
| 41801 | 41791 | *(i64*)pArg = pFile->mmapSizeMax; |
| 41802 | 41792 | if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ |
| 41803 | 41793 | pFile->mmapSizeMax = newLimit; |
| 41804 | 41794 | if( pFile->mmapSize>0 ){ |
| 41805 | 41795 | winUnmapfile(pFile); |
| | @@ -43925,13 +43915,10 @@ |
| 43925 | 43915 | return nBuf; |
| 43926 | 43916 | #else |
| 43927 | 43917 | EntropyGatherer e; |
| 43928 | 43918 | UNUSED_PARAMETER(pVfs); |
| 43929 | 43919 | memset(zBuf, 0, nBuf); |
| 43930 | | -#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE |
| 43931 | | - rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */ |
| 43932 | | -#endif /* defined(_MSC_VER) && _MSC_VER>=1400 */ |
| 43933 | 43920 | e.a = (unsigned char*)zBuf; |
| 43934 | 43921 | e.na = nBuf; |
| 43935 | 43922 | e.nXor = 0; |
| 43936 | 43923 | e.i = 0; |
| 43937 | 43924 | { |
| | @@ -44846,16 +44833,13 @@ |
| 44846 | 44833 | if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 44847 | 44834 | assert( p->bPurgeable==0 || p->eCreate==1 ); |
| 44848 | 44835 | p->eCreate = 2; |
| 44849 | 44836 | } |
| 44850 | 44837 | } |
| 44851 | | - pPage->pDirtyNext = 0; |
| 44852 | | - pPage->pDirtyPrev = 0; |
| 44853 | 44838 | } |
| 44854 | 44839 | if( addRemove & PCACHE_DIRTYLIST_ADD ){ |
| 44855 | | - assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage ); |
| 44856 | | - |
| 44840 | + pPage->pDirtyPrev = 0; |
| 44857 | 44841 | pPage->pDirtyNext = p->pDirty; |
| 44858 | 44842 | if( pPage->pDirtyNext ){ |
| 44859 | 44843 | assert( pPage->pDirtyNext->pDirtyPrev==0 ); |
| 44860 | 44844 | pPage->pDirtyNext->pDirtyPrev = pPage; |
| 44861 | 44845 | }else{ |
| | @@ -45168,15 +45152,11 @@ |
| 45168 | 45152 | assert( p->nRef>0 ); |
| 45169 | 45153 | p->pCache->nRefSum--; |
| 45170 | 45154 | if( (--p->nRef)==0 ){ |
| 45171 | 45155 | if( p->flags&PGHDR_CLEAN ){ |
| 45172 | 45156 | pcacheUnpin(p); |
| 45173 | | - }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45174 | | - /* Move the page to the head of the dirty list. If p->pDirtyPrev==0, |
| 45175 | | - ** then page p is already at the head of the dirty list and the |
| 45176 | | - ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE |
| 45177 | | - ** tag above. */ |
| 45157 | + }else{ |
| 45178 | 45158 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT); |
| 45179 | 45159 | } |
| 45180 | 45160 | } |
| 45181 | 45161 | } |
| 45182 | 45162 | |
| | @@ -45633,19 +45613,24 @@ |
| 45633 | 45613 | ** in memory. |
| 45634 | 45614 | */ |
| 45635 | 45615 | struct PgHdr1 { |
| 45636 | 45616 | sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */ |
| 45637 | 45617 | unsigned int iKey; /* Key value (page number) */ |
| 45638 | | - u8 isPinned; /* Page in use, not on the LRU list */ |
| 45639 | 45618 | u8 isBulkLocal; /* This page from bulk local storage */ |
| 45640 | 45619 | u8 isAnchor; /* This is the PGroup.lru element */ |
| 45641 | 45620 | PgHdr1 *pNext; /* Next in hash table chain */ |
| 45642 | 45621 | PCache1 *pCache; /* Cache that currently owns this page */ |
| 45643 | 45622 | PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ |
| 45644 | 45623 | PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */ |
| 45645 | 45624 | }; |
| 45646 | 45625 | |
| 45626 | +/* |
| 45627 | +** A page is pinned if it is no on the LRU list |
| 45628 | +*/ |
| 45629 | +#define PAGE_IS_PINNED(p) ((p)->pLruNext==0) |
| 45630 | +#define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0) |
| 45631 | + |
| 45647 | 45632 | /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set |
| 45648 | 45633 | ** of one or more PCaches that are able to recycle each other's unpinned |
| 45649 | 45634 | ** pages when they are under memory pressure. A PGroup is an instance of |
| 45650 | 45635 | ** the following object. |
| 45651 | 45636 | ** |
| | @@ -45669,11 +45654,11 @@ |
| 45669 | 45654 | struct PGroup { |
| 45670 | 45655 | sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */ |
| 45671 | 45656 | unsigned int nMaxPage; /* Sum of nMax for purgeable caches */ |
| 45672 | 45657 | unsigned int nMinPage; /* Sum of nMin for purgeable caches */ |
| 45673 | 45658 | unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */ |
| 45674 | | - unsigned int nCurrentPage; /* Number of purgeable pages allocated */ |
| 45659 | + unsigned int nPurgeable; /* Number of purgeable pages allocated */ |
| 45675 | 45660 | PgHdr1 lru; /* The beginning and end of the LRU list */ |
| 45676 | 45661 | }; |
| 45677 | 45662 | |
| 45678 | 45663 | /* Each page cache is an instance of the following object. Every |
| 45679 | 45664 | ** open database file (including each in-memory database and each |
| | @@ -45683,15 +45668,17 @@ |
| 45683 | 45668 | ** Pointers to structures of this type are cast and returned as |
| 45684 | 45669 | ** opaque sqlite3_pcache* handles. |
| 45685 | 45670 | */ |
| 45686 | 45671 | struct PCache1 { |
| 45687 | 45672 | /* Cache configuration parameters. Page size (szPage) and the purgeable |
| 45688 | | - ** flag (bPurgeable) are set when the cache is created. nMax may be |
| 45673 | + ** flag (bPurgeable) and the pnPurgeable pointer are all set when the |
| 45674 | + ** cache is created and are never changed thereafter. nMax may be |
| 45689 | 45675 | ** modified at any time by a call to the pcache1Cachesize() method. |
| 45690 | 45676 | ** The PGroup mutex must be held when accessing nMax. |
| 45691 | 45677 | */ |
| 45692 | 45678 | PGroup *pGroup; /* PGroup this cache belongs to */ |
| 45679 | + unsigned int *pnPurgeable; /* Pointer to pGroup->nPurgeable */ |
| 45693 | 45680 | int szPage; /* Size of database content section */ |
| 45694 | 45681 | int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */ |
| 45695 | 45682 | int szAlloc; /* Total size of one pcache line */ |
| 45696 | 45683 | int bPurgeable; /* True if cache is purgeable */ |
| 45697 | 45684 | unsigned int nMin; /* Minimum number of pages reserved */ |
| | @@ -45782,10 +45769,11 @@ |
| 45782 | 45769 | */ |
| 45783 | 45770 | SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ |
| 45784 | 45771 | if( pcache1.isInit ){ |
| 45785 | 45772 | PgFreeslot *p; |
| 45786 | 45773 | if( pBuf==0 ) sz = n = 0; |
| 45774 | + if( n==0 ) sz = 0; |
| 45787 | 45775 | sz = ROUNDDOWN8(sz); |
| 45788 | 45776 | pcache1.szSlot = sz; |
| 45789 | 45777 | pcache1.nSlot = pcache1.nFreeSlot = n; |
| 45790 | 45778 | pcache1.nReserve = n>90 ? 10 : (n/10 + 1); |
| 45791 | 45779 | pcache1.pStart = pBuf; |
| | @@ -45974,13 +45962,11 @@ |
| 45974 | 45962 | p->page.pBuf = pPg; |
| 45975 | 45963 | p->page.pExtra = &p[1]; |
| 45976 | 45964 | p->isBulkLocal = 0; |
| 45977 | 45965 | p->isAnchor = 0; |
| 45978 | 45966 | } |
| 45979 | | - if( pCache->bPurgeable ){ |
| 45980 | | - pCache->pGroup->nCurrentPage++; |
| 45981 | | - } |
| 45967 | + (*pCache->pnPurgeable)++; |
| 45982 | 45968 | return p; |
| 45983 | 45969 | } |
| 45984 | 45970 | |
| 45985 | 45971 | /* |
| 45986 | 45972 | ** Free a page object allocated by pcache1AllocPage(). |
| | @@ -45997,13 +45983,11 @@ |
| 45997 | 45983 | pcache1Free(p->page.pBuf); |
| 45998 | 45984 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 45999 | 45985 | sqlite3_free(p); |
| 46000 | 45986 | #endif |
| 46001 | 45987 | } |
| 46002 | | - if( pCache->bPurgeable ){ |
| 46003 | | - pCache->pGroup->nCurrentPage--; |
| 46004 | | - } |
| 45988 | + (*pCache->pnPurgeable)--; |
| 46005 | 45989 | } |
| 46006 | 45990 | |
| 46007 | 45991 | /* |
| 46008 | 45992 | ** Malloc function used by SQLite to obtain space from the buffer configured |
| 46009 | 45993 | ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer |
| | @@ -46094,26 +46078,22 @@ |
| 46094 | 46078 | ** LRU list, then this function is a no-op. |
| 46095 | 46079 | ** |
| 46096 | 46080 | ** The PGroup mutex must be held when this function is called. |
| 46097 | 46081 | */ |
| 46098 | 46082 | static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){ |
| 46099 | | - PCache1 *pCache; |
| 46100 | | - |
| 46101 | 46083 | assert( pPage!=0 ); |
| 46102 | | - assert( pPage->isPinned==0 ); |
| 46103 | | - pCache = pPage->pCache; |
| 46084 | + assert( PAGE_IS_UNPINNED(pPage) ); |
| 46104 | 46085 | assert( pPage->pLruNext ); |
| 46105 | 46086 | assert( pPage->pLruPrev ); |
| 46106 | | - assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); |
| 46087 | + assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) ); |
| 46107 | 46088 | pPage->pLruPrev->pLruNext = pPage->pLruNext; |
| 46108 | 46089 | pPage->pLruNext->pLruPrev = pPage->pLruPrev; |
| 46109 | 46090 | pPage->pLruNext = 0; |
| 46110 | 46091 | pPage->pLruPrev = 0; |
| 46111 | | - pPage->isPinned = 1; |
| 46112 | 46092 | assert( pPage->isAnchor==0 ); |
| 46113 | | - assert( pCache->pGroup->lru.isAnchor==1 ); |
| 46114 | | - pCache->nRecyclable--; |
| 46093 | + assert( pPage->pCache->pGroup->lru.isAnchor==1 ); |
| 46094 | + pPage->pCache->nRecyclable--; |
| 46115 | 46095 | return pPage; |
| 46116 | 46096 | } |
| 46117 | 46097 | |
| 46118 | 46098 | |
| 46119 | 46099 | /* |
| | @@ -46143,15 +46123,15 @@ |
| 46143 | 46123 | */ |
| 46144 | 46124 | static void pcache1EnforceMaxPage(PCache1 *pCache){ |
| 46145 | 46125 | PGroup *pGroup = pCache->pGroup; |
| 46146 | 46126 | PgHdr1 *p; |
| 46147 | 46127 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 46148 | | - while( pGroup->nCurrentPage>pGroup->nMaxPage |
| 46128 | + while( pGroup->nPurgeable>pGroup->nMaxPage |
| 46149 | 46129 | && (p=pGroup->lru.pLruPrev)->isAnchor==0 |
| 46150 | 46130 | ){ |
| 46151 | 46131 | assert( p->pCache->pGroup==pGroup ); |
| 46152 | | - assert( p->isPinned==0 ); |
| 46132 | + assert( PAGE_IS_UNPINNED(p) ); |
| 46153 | 46133 | pcache1PinPage(p); |
| 46154 | 46134 | pcache1RemoveFromHash(p, 1); |
| 46155 | 46135 | } |
| 46156 | 46136 | if( pCache->nPage==0 && pCache->pBulk ){ |
| 46157 | 46137 | sqlite3_free(pCache->pBulk); |
| | @@ -46196,11 +46176,11 @@ |
| 46196 | 46176 | pp = &pCache->apHash[h]; |
| 46197 | 46177 | while( (pPage = *pp)!=0 ){ |
| 46198 | 46178 | if( pPage->iKey>=iLimit ){ |
| 46199 | 46179 | pCache->nPage--; |
| 46200 | 46180 | *pp = pPage->pNext; |
| 46201 | | - if( !pPage->isPinned ) pcache1PinPage(pPage); |
| 46181 | + if( PAGE_IS_UNPINNED(pPage) ) pcache1PinPage(pPage); |
| 46202 | 46182 | pcache1FreePage(pPage); |
| 46203 | 46183 | }else{ |
| 46204 | 46184 | pp = &pPage->pNext; |
| 46205 | 46185 | TESTONLY( if( nPage>=0 ) nPage++; ) |
| 46206 | 46186 | } |
| | @@ -46314,10 +46294,14 @@ |
| 46314 | 46294 | pcache1ResizeHash(pCache); |
| 46315 | 46295 | if( bPurgeable ){ |
| 46316 | 46296 | pCache->nMin = 10; |
| 46317 | 46297 | pGroup->nMinPage += pCache->nMin; |
| 46318 | 46298 | pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; |
| 46299 | + pCache->pnPurgeable = &pGroup->nPurgeable; |
| 46300 | + }else{ |
| 46301 | + static unsigned int dummyCurrentPage; |
| 46302 | + pCache->pnPurgeable = &dummyCurrentPage; |
| 46319 | 46303 | } |
| 46320 | 46304 | pcache1LeaveMutex(pGroup); |
| 46321 | 46305 | if( pCache->nHash==0 ){ |
| 46322 | 46306 | pcache1Destroy((sqlite3_pcache*)pCache); |
| 46323 | 46307 | pCache = 0; |
| | @@ -46415,19 +46399,19 @@ |
| 46415 | 46399 | && !pGroup->lru.pLruPrev->isAnchor |
| 46416 | 46400 | && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache)) |
| 46417 | 46401 | ){ |
| 46418 | 46402 | PCache1 *pOther; |
| 46419 | 46403 | pPage = pGroup->lru.pLruPrev; |
| 46420 | | - assert( pPage->isPinned==0 ); |
| 46404 | + assert( PAGE_IS_UNPINNED(pPage) ); |
| 46421 | 46405 | pcache1RemoveFromHash(pPage, 0); |
| 46422 | 46406 | pcache1PinPage(pPage); |
| 46423 | 46407 | pOther = pPage->pCache; |
| 46424 | 46408 | if( pOther->szAlloc != pCache->szAlloc ){ |
| 46425 | 46409 | pcache1FreePage(pPage); |
| 46426 | 46410 | pPage = 0; |
| 46427 | 46411 | }else{ |
| 46428 | | - pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable); |
| 46412 | + pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable); |
| 46429 | 46413 | } |
| 46430 | 46414 | } |
| 46431 | 46415 | |
| 46432 | 46416 | /* Step 5. If a usable page buffer has still not been found, |
| 46433 | 46417 | ** attempt to allocate a new one. |
| | @@ -46442,11 +46426,10 @@ |
| 46442 | 46426 | pPage->iKey = iKey; |
| 46443 | 46427 | pPage->pNext = pCache->apHash[h]; |
| 46444 | 46428 | pPage->pCache = pCache; |
| 46445 | 46429 | pPage->pLruPrev = 0; |
| 46446 | 46430 | pPage->pLruNext = 0; |
| 46447 | | - pPage->isPinned = 1; |
| 46448 | 46431 | *(void **)pPage->page.pExtra = 0; |
| 46449 | 46432 | pCache->apHash[h] = pPage; |
| 46450 | 46433 | if( iKey>pCache->iMaxKey ){ |
| 46451 | 46434 | pCache->iMaxKey = iKey; |
| 46452 | 46435 | } |
| | @@ -46528,11 +46511,11 @@ |
| 46528 | 46511 | /* Step 2: If the page was found in the hash table, then return it. |
| 46529 | 46512 | ** If the page was not in the hash table and createFlag is 0, abort. |
| 46530 | 46513 | ** Otherwise (page not in hash and createFlag!=0) continue with |
| 46531 | 46514 | ** subsequent steps to try to create the page. */ |
| 46532 | 46515 | if( pPage ){ |
| 46533 | | - if( !pPage->isPinned ){ |
| 46516 | + if( PAGE_IS_UNPINNED(pPage) ){ |
| 46534 | 46517 | return pcache1PinPage(pPage); |
| 46535 | 46518 | }else{ |
| 46536 | 46519 | return pPage; |
| 46537 | 46520 | } |
| 46538 | 46521 | }else if( createFlag ){ |
| | @@ -46603,22 +46586,21 @@ |
| 46603 | 46586 | |
| 46604 | 46587 | /* It is an error to call this function if the page is already |
| 46605 | 46588 | ** part of the PGroup LRU list. |
| 46606 | 46589 | */ |
| 46607 | 46590 | assert( pPage->pLruPrev==0 && pPage->pLruNext==0 ); |
| 46608 | | - assert( pPage->isPinned==1 ); |
| 46591 | + assert( PAGE_IS_PINNED(pPage) ); |
| 46609 | 46592 | |
| 46610 | | - if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){ |
| 46593 | + if( reuseUnlikely || pGroup->nPurgeable>pGroup->nMaxPage ){ |
| 46611 | 46594 | pcache1RemoveFromHash(pPage, 1); |
| 46612 | 46595 | }else{ |
| 46613 | 46596 | /* Add the page to the PGroup LRU list. */ |
| 46614 | 46597 | PgHdr1 **ppFirst = &pGroup->lru.pLruNext; |
| 46615 | 46598 | pPage->pLruPrev = &pGroup->lru; |
| 46616 | 46599 | (pPage->pLruNext = *ppFirst)->pLruPrev = pPage; |
| 46617 | 46600 | *ppFirst = pPage; |
| 46618 | 46601 | pCache->nRecyclable++; |
| 46619 | | - pPage->isPinned = 0; |
| 46620 | 46602 | } |
| 46621 | 46603 | |
| 46622 | 46604 | pcache1LeaveMutex(pCache->pGroup); |
| 46623 | 46605 | } |
| 46624 | 46606 | |
| | @@ -46758,11 +46740,11 @@ |
| 46758 | 46740 | ){ |
| 46759 | 46741 | nFree += pcache1MemSize(p->page.pBuf); |
| 46760 | 46742 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 46761 | 46743 | nFree += sqlite3MemSize(p); |
| 46762 | 46744 | #endif |
| 46763 | | - assert( p->isPinned==0 ); |
| 46745 | + assert( PAGE_IS_UNPINNED(p) ); |
| 46764 | 46746 | pcache1PinPage(p); |
| 46765 | 46747 | pcache1RemoveFromHash(p, 1); |
| 46766 | 46748 | } |
| 46767 | 46749 | pcache1LeaveMutex(&pcache1.grp); |
| 46768 | 46750 | } |
| | @@ -46782,14 +46764,14 @@ |
| 46782 | 46764 | int *pnRecyclable /* OUT: Total number of pages available for recycling */ |
| 46783 | 46765 | ){ |
| 46784 | 46766 | PgHdr1 *p; |
| 46785 | 46767 | int nRecyclable = 0; |
| 46786 | 46768 | for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){ |
| 46787 | | - assert( p->isPinned==0 ); |
| 46769 | + assert( PAGE_IS_UNPINNED(p) ); |
| 46788 | 46770 | nRecyclable++; |
| 46789 | 46771 | } |
| 46790 | | - *pnCurrent = pcache1.grp.nCurrentPage; |
| 46772 | + *pnCurrent = pcache1.grp.nPurgeable; |
| 46791 | 46773 | *pnMax = (int)pcache1.grp.nMaxPage; |
| 46792 | 46774 | *pnMin = (int)pcache1.grp.nMinPage; |
| 46793 | 46775 | *pnRecyclable = nRecyclable; |
| 46794 | 46776 | } |
| 46795 | 46777 | #endif |
| | @@ -47340,15 +47322,15 @@ |
| 47340 | 47322 | #ifndef SQLITE_WAL_H |
| 47341 | 47323 | #define SQLITE_WAL_H |
| 47342 | 47324 | |
| 47343 | 47325 | /* #include "sqliteInt.h" */ |
| 47344 | 47326 | |
| 47345 | | -/* Additional values that can be added to the sync_flags argument of |
| 47346 | | -** sqlite3WalFrames(): |
| 47327 | +/* Macros for extracting appropriate sync flags for either transaction |
| 47328 | +** commits (WAL_SYNC_FLAGS(X)) or for checkpoint ops (CKPT_SYNC_FLAGS(X)): |
| 47347 | 47329 | */ |
| 47348 | | -#define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */ |
| 47349 | | -#define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */ |
| 47330 | +#define WAL_SYNC_FLAGS(X) ((X)&0x03) |
| 47331 | +#define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03) |
| 47350 | 47332 | |
| 47351 | 47333 | #ifdef SQLITE_OMIT_WAL |
| 47352 | 47334 | # define sqlite3WalOpen(x,y,z) 0 |
| 47353 | 47335 | # define sqlite3WalLimit(x,y) |
| 47354 | 47336 | # define sqlite3WalClose(v,w,x,y,z) 0 |
| | @@ -47577,12 +47559,12 @@ |
| 47577 | 47559 | ** |
| 47578 | 47560 | ** PAGERID() takes a pointer to a Pager struct as its argument. The |
| 47579 | 47561 | ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file |
| 47580 | 47562 | ** struct as its argument. |
| 47581 | 47563 | */ |
| 47582 | | -#define PAGERID(p) ((int)(p->fd)) |
| 47583 | | -#define FILEHANDLEID(fd) ((int)fd) |
| 47564 | +#define PAGERID(p) (SQLITE_PTR_TO_INT(p->fd)) |
| 47565 | +#define FILEHANDLEID(fd) (SQLITE_PTR_TO_INT(fd)) |
| 47584 | 47566 | |
| 47585 | 47567 | /* |
| 47586 | 47568 | ** The Pager.eState variable stores the current 'state' of a pager. A |
| 47587 | 47569 | ** pager may be in any one of the seven states shown in the following |
| 47588 | 47570 | ** state diagram. |
| | @@ -48065,22 +48047,33 @@ |
| 48065 | 48047 | ** |
| 48066 | 48048 | ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It |
| 48067 | 48049 | ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode |
| 48068 | 48050 | ** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX |
| 48069 | 48051 | ** sub-codes. |
| 48052 | +** |
| 48053 | +** syncFlags, walSyncFlags |
| 48054 | +** |
| 48055 | +** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03). |
| 48056 | +** syncFlags is used for rollback mode. walSyncFlags is used for WAL mode |
| 48057 | +** and contains the flags used to sync the checkpoint operations in the |
| 48058 | +** lower two bits, and sync flags used for transaction commits in the WAL |
| 48059 | +** file in bits 0x04 and 0x08. In other words, to get the correct sync flags |
| 48060 | +** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct |
| 48061 | +** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note |
| 48062 | +** that with synchronous=NORMAL in WAL mode, transaction commit is not synced |
| 48063 | +** meaning that the 0x04 and 0x08 bits are both zero. |
| 48070 | 48064 | */ |
| 48071 | 48065 | struct Pager { |
| 48072 | 48066 | sqlite3_vfs *pVfs; /* OS functions to use for IO */ |
| 48073 | 48067 | u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */ |
| 48074 | 48068 | u8 journalMode; /* One of the PAGER_JOURNALMODE_* values */ |
| 48075 | 48069 | u8 useJournal; /* Use a rollback journal on this file */ |
| 48076 | 48070 | u8 noSync; /* Do not sync the journal if true */ |
| 48077 | 48071 | u8 fullSync; /* Do extra syncs of the journal for robustness */ |
| 48078 | 48072 | u8 extraSync; /* sync directory after journal delete */ |
| 48079 | | - u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */ |
| 48080 | | - u8 walSyncFlags; /* SYNC_NORMAL or SYNC_FULL for wal writes */ |
| 48081 | 48073 | u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */ |
| 48074 | + u8 walSyncFlags; /* See description above */ |
| 48082 | 48075 | u8 tempFile; /* zFilename is a temporary or immutable file */ |
| 48083 | 48076 | u8 noLock; /* Do not lock (except in WAL mode) */ |
| 48084 | 48077 | u8 readOnly; /* True for a read-only database */ |
| 48085 | 48078 | u8 memDb; /* True to inhibit all file I/O */ |
| 48086 | 48079 | |
| | @@ -48396,10 +48389,11 @@ |
| 48396 | 48389 | assert( !pagerUseWal(pPager) ); |
| 48397 | 48390 | assert( p->eLock>=EXCLUSIVE_LOCK ); |
| 48398 | 48391 | assert( isOpen(p->jfd) |
| 48399 | 48392 | || p->journalMode==PAGER_JOURNALMODE_OFF |
| 48400 | 48393 | || p->journalMode==PAGER_JOURNALMODE_WAL |
| 48394 | + || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC) |
| 48401 | 48395 | ); |
| 48402 | 48396 | assert( pPager->dbOrigSize<=pPager->dbHintSize ); |
| 48403 | 48397 | break; |
| 48404 | 48398 | |
| 48405 | 48399 | case PAGER_WRITER_FINISHED: |
| | @@ -48407,10 +48401,11 @@ |
| 48407 | 48401 | assert( pPager->errCode==SQLITE_OK ); |
| 48408 | 48402 | assert( !pagerUseWal(pPager) ); |
| 48409 | 48403 | assert( isOpen(p->jfd) |
| 48410 | 48404 | || p->journalMode==PAGER_JOURNALMODE_OFF |
| 48411 | 48405 | || p->journalMode==PAGER_JOURNALMODE_WAL |
| 48406 | + || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC) |
| 48412 | 48407 | ); |
| 48413 | 48408 | break; |
| 48414 | 48409 | |
| 48415 | 48410 | case PAGER_ERROR: |
| 48416 | 48411 | /* There must be at least one outstanding reference to the pager if |
| | @@ -48617,51 +48612,62 @@ |
| 48617 | 48612 | } |
| 48618 | 48613 | return rc; |
| 48619 | 48614 | } |
| 48620 | 48615 | |
| 48621 | 48616 | /* |
| 48622 | | -** This function determines whether or not the atomic-write optimization |
| 48623 | | -** can be used with this pager. The optimization can be used if: |
| 48617 | +** This function determines whether or not the atomic-write or |
| 48618 | +** atomic-batch-write optimizations can be used with this pager. The |
| 48619 | +** atomic-write optimization can be used if: |
| 48624 | 48620 | ** |
| 48625 | 48621 | ** (a) the value returned by OsDeviceCharacteristics() indicates that |
| 48626 | 48622 | ** a database page may be written atomically, and |
| 48627 | 48623 | ** (b) the value returned by OsSectorSize() is less than or equal |
| 48628 | 48624 | ** to the page size. |
| 48629 | 48625 | ** |
| 48630 | | -** The optimization is also always enabled for temporary files. It is |
| 48631 | | -** an error to call this function if pPager is opened on an in-memory |
| 48632 | | -** database. |
| 48626 | +** If it can be used, then the value returned is the size of the journal |
| 48627 | +** file when it contains rollback data for exactly one page. |
| 48633 | 48628 | ** |
| 48634 | | -** If the optimization cannot be used, 0 is returned. If it can be used, |
| 48635 | | -** then the value returned is the size of the journal file when it |
| 48636 | | -** contains rollback data for exactly one page. |
| 48629 | +** The atomic-batch-write optimization can be used if OsDeviceCharacteristics() |
| 48630 | +** returns a value with the SQLITE_IOCAP_BATCH_ATOMIC bit set. -1 is |
| 48631 | +** returned in this case. |
| 48632 | +** |
| 48633 | +** If neither optimization can be used, 0 is returned. |
| 48637 | 48634 | */ |
| 48638 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 48639 | 48635 | static int jrnlBufferSize(Pager *pPager){ |
| 48640 | 48636 | assert( !MEMDB ); |
| 48641 | | - if( !pPager->tempFile ){ |
| 48642 | | - int dc; /* Device characteristics */ |
| 48643 | | - int nSector; /* Sector size */ |
| 48644 | | - int szPage; /* Page size */ |
| 48645 | | - |
| 48646 | | - assert( isOpen(pPager->fd) ); |
| 48647 | | - dc = sqlite3OsDeviceCharacteristics(pPager->fd); |
| 48648 | | - nSector = pPager->sectorSize; |
| 48649 | | - szPage = pPager->pageSize; |
| 48637 | + |
| 48638 | +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 48639 | + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 48640 | + int dc; /* Device characteristics */ |
| 48641 | + |
| 48642 | + assert( isOpen(pPager->fd) ); |
| 48643 | + dc = sqlite3OsDeviceCharacteristics(pPager->fd); |
| 48644 | +#endif |
| 48645 | + |
| 48646 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 48647 | + if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){ |
| 48648 | + return -1; |
| 48649 | + } |
| 48650 | +#endif |
| 48651 | + |
| 48652 | +#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 48653 | + { |
| 48654 | + int nSector = pPager->sectorSize; |
| 48655 | + int szPage = pPager->pageSize; |
| 48650 | 48656 | |
| 48651 | 48657 | assert(SQLITE_IOCAP_ATOMIC512==(512>>8)); |
| 48652 | 48658 | assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8)); |
| 48653 | 48659 | if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){ |
| 48654 | 48660 | return 0; |
| 48655 | 48661 | } |
| 48656 | 48662 | } |
| 48657 | 48663 | |
| 48658 | 48664 | return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager); |
| 48665 | +#endif |
| 48666 | + |
| 48667 | + return 0; |
| 48659 | 48668 | } |
| 48660 | | -#else |
| 48661 | | -# define jrnlBufferSize(x) 0 |
| 48662 | | -#endif |
| 48663 | 48669 | |
| 48664 | 48670 | /* |
| 48665 | 48671 | ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking |
| 48666 | 48672 | ** on the cache using a hash function. This is used for testing |
| 48667 | 48673 | ** and debugging only. |
| | @@ -48740,10 +48746,11 @@ |
| 48740 | 48746 | |
| 48741 | 48747 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 48742 | 48748 | || szJ<16 |
| 48743 | 48749 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 48744 | 48750 | || len>=nMaster |
| 48751 | + || len>szJ-16 |
| 48745 | 48752 | || len==0 |
| 48746 | 48753 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 48747 | 48754 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 48748 | 48755 | || memcmp(aMagic, aJournalMagic, 8) |
| 48749 | 48756 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| | @@ -49461,11 +49468,13 @@ |
| 49461 | 49468 | if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){ |
| 49462 | 49469 | return SQLITE_OK; |
| 49463 | 49470 | } |
| 49464 | 49471 | |
| 49465 | 49472 | releaseAllSavepoints(pPager); |
| 49466 | | - assert( isOpen(pPager->jfd) || pPager->pInJournal==0 ); |
| 49473 | + assert( isOpen(pPager->jfd) || pPager->pInJournal==0 |
| 49474 | + || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_BATCH_ATOMIC) |
| 49475 | + ); |
| 49467 | 49476 | if( isOpen(pPager->jfd) ){ |
| 49468 | 49477 | assert( !pagerUseWal(pPager) ); |
| 49469 | 49478 | |
| 49470 | 49479 | /* Finalize the journal file. */ |
| 49471 | 49480 | if( sqlite3JournalIsInMemory(pPager->jfd) ){ |
| | @@ -50229,10 +50238,11 @@ |
| 50229 | 50238 | int rc; /* Result code of a subroutine */ |
| 50230 | 50239 | int res = 1; /* Value returned by sqlite3OsAccess() */ |
| 50231 | 50240 | char *zMaster = 0; /* Name of master journal file if any */ |
| 50232 | 50241 | int needPagerReset; /* True to reset page prior to first page rollback */ |
| 50233 | 50242 | int nPlayback = 0; /* Total number of pages restored from journal */ |
| 50243 | + u32 savedPageSize = pPager->pageSize; |
| 50234 | 50244 | |
| 50235 | 50245 | /* Figure out how many records are in the journal. Abort early if |
| 50236 | 50246 | ** the journal is empty. |
| 50237 | 50247 | */ |
| 50238 | 50248 | assert( isOpen(pPager->jfd) ); |
| | @@ -50358,10 +50368,13 @@ |
| 50358 | 50368 | } |
| 50359 | 50369 | /*NOTREACHED*/ |
| 50360 | 50370 | assert( 0 ); |
| 50361 | 50371 | |
| 50362 | 50372 | end_playback: |
| 50373 | + if( rc==SQLITE_OK ){ |
| 50374 | + rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1); |
| 50375 | + } |
| 50363 | 50376 | /* Following a rollback, the database file should be back in its original |
| 50364 | 50377 | ** state prior to the start of the transaction, so invoke the |
| 50365 | 50378 | ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the |
| 50366 | 50379 | ** assertion that the transaction counter was modified. |
| 50367 | 50380 | */ |
| | @@ -50416,44 +50429,44 @@ |
| 50416 | 50429 | return rc; |
| 50417 | 50430 | } |
| 50418 | 50431 | |
| 50419 | 50432 | |
| 50420 | 50433 | /* |
| 50421 | | -** Read the content for page pPg out of the database file and into |
| 50434 | +** Read the content for page pPg out of the database file (or out of |
| 50435 | +** the WAL if that is where the most recent copy if found) into |
| 50422 | 50436 | ** pPg->pData. A shared lock or greater must be held on the database |
| 50423 | 50437 | ** file before this function is called. |
| 50424 | 50438 | ** |
| 50425 | 50439 | ** If page 1 is read, then the value of Pager.dbFileVers[] is set to |
| 50426 | 50440 | ** the value read from the database file. |
| 50427 | 50441 | ** |
| 50428 | 50442 | ** If an IO error occurs, then the IO error is returned to the caller. |
| 50429 | 50443 | ** Otherwise, SQLITE_OK is returned. |
| 50430 | 50444 | */ |
| 50431 | | -static int readDbPage(PgHdr *pPg, u32 iFrame){ |
| 50445 | +static int readDbPage(PgHdr *pPg){ |
| 50432 | 50446 | Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */ |
| 50433 | | - Pgno pgno = pPg->pgno; /* Page number to read */ |
| 50434 | 50447 | int rc = SQLITE_OK; /* Return code */ |
| 50435 | | - int pgsz = pPager->pageSize; /* Number of bytes to read */ |
| 50448 | + u32 iFrame = 0; /* Frame of WAL containing pgno */ |
| 50436 | 50449 | |
| 50437 | 50450 | assert( pPager->eState>=PAGER_READER && !MEMDB ); |
| 50438 | 50451 | assert( isOpen(pPager->fd) ); |
| 50439 | 50452 | |
| 50440 | | -#ifndef SQLITE_OMIT_WAL |
| 50453 | + if( pagerUseWal(pPager) ){ |
| 50454 | + rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame); |
| 50455 | + if( rc ) return rc; |
| 50456 | + } |
| 50441 | 50457 | if( iFrame ){ |
| 50442 | | - /* Try to pull the page from the write-ahead log. */ |
| 50443 | | - rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData); |
| 50444 | | - }else |
| 50445 | | -#endif |
| 50446 | | - { |
| 50447 | | - i64 iOffset = (pgno-1)*(i64)pPager->pageSize; |
| 50448 | | - rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset); |
| 50458 | + rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData); |
| 50459 | + }else{ |
| 50460 | + i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize; |
| 50461 | + rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset); |
| 50449 | 50462 | if( rc==SQLITE_IOERR_SHORT_READ ){ |
| 50450 | 50463 | rc = SQLITE_OK; |
| 50451 | 50464 | } |
| 50452 | 50465 | } |
| 50453 | 50466 | |
| 50454 | | - if( pgno==1 ){ |
| 50467 | + if( pPg->pgno==1 ){ |
| 50455 | 50468 | if( rc ){ |
| 50456 | 50469 | /* If the read is unsuccessful, set the dbFileVers[] to something |
| 50457 | 50470 | ** that will never be a valid file version. dbFileVers[] is a copy |
| 50458 | 50471 | ** of bytes 24..39 of the database. Bytes 28..31 should always be |
| 50459 | 50472 | ** zero or the size of the database in page. Bytes 32..35 and 35..39 |
| | @@ -50469,17 +50482,17 @@ |
| 50469 | 50482 | }else{ |
| 50470 | 50483 | u8 *dbFileVers = &((u8*)pPg->pData)[24]; |
| 50471 | 50484 | memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers)); |
| 50472 | 50485 | } |
| 50473 | 50486 | } |
| 50474 | | - CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM_BKPT); |
| 50487 | + CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT); |
| 50475 | 50488 | |
| 50476 | 50489 | PAGER_INCR(sqlite3_pager_readdb_count); |
| 50477 | 50490 | PAGER_INCR(pPager->nRead); |
| 50478 | | - IOTRACE(("PGIN %p %d\n", pPager, pgno)); |
| 50491 | + IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno)); |
| 50479 | 50492 | PAGERTRACE(("FETCH %d page %d hash(%08x)\n", |
| 50480 | | - PAGERID(pPager), pgno, pager_pagehash(pPg))); |
| 50493 | + PAGERID(pPager), pPg->pgno, pager_pagehash(pPg))); |
| 50481 | 50494 | |
| 50482 | 50495 | return rc; |
| 50483 | 50496 | } |
| 50484 | 50497 | |
| 50485 | 50498 | /* |
| | @@ -50526,15 +50539,11 @@ |
| 50526 | 50539 | pPg = sqlite3PagerLookup(pPager, iPg); |
| 50527 | 50540 | if( pPg ){ |
| 50528 | 50541 | if( sqlite3PcachePageRefcount(pPg)==1 ){ |
| 50529 | 50542 | sqlite3PcacheDrop(pPg); |
| 50530 | 50543 | }else{ |
| 50531 | | - u32 iFrame = 0; |
| 50532 | | - rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame); |
| 50533 | | - if( rc==SQLITE_OK ){ |
| 50534 | | - rc = readDbPage(pPg, iFrame); |
| 50535 | | - } |
| 50544 | + rc = readDbPage(pPg); |
| 50536 | 50545 | if( rc==SQLITE_OK ){ |
| 50537 | 50546 | pPager->xReiniter(pPg); |
| 50538 | 50547 | } |
| 50539 | 50548 | sqlite3PagerUnrefNotNull(pPg); |
| 50540 | 50549 | } |
| | @@ -51036,24 +51045,21 @@ |
| 51036 | 51045 | pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0; |
| 51037 | 51046 | pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0; |
| 51038 | 51047 | } |
| 51039 | 51048 | if( pPager->noSync ){ |
| 51040 | 51049 | pPager->syncFlags = 0; |
| 51041 | | - pPager->ckptSyncFlags = 0; |
| 51042 | 51050 | }else if( pgFlags & PAGER_FULLFSYNC ){ |
| 51043 | 51051 | pPager->syncFlags = SQLITE_SYNC_FULL; |
| 51044 | | - pPager->ckptSyncFlags = SQLITE_SYNC_FULL; |
| 51045 | | - }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){ |
| 51046 | | - pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 51047 | | - pPager->ckptSyncFlags = SQLITE_SYNC_FULL; |
| 51048 | 51052 | }else{ |
| 51049 | 51053 | pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 51050 | | - pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL; |
| 51051 | 51054 | } |
| 51052 | | - pPager->walSyncFlags = pPager->syncFlags; |
| 51055 | + pPager->walSyncFlags = (pPager->syncFlags<<2); |
| 51053 | 51056 | if( pPager->fullSync ){ |
| 51054 | | - pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS; |
| 51057 | + pPager->walSyncFlags |= pPager->syncFlags; |
| 51058 | + } |
| 51059 | + if( (pgFlags & PAGER_CKPT_FULLFSYNC) && !pPager->noSync ){ |
| 51060 | + pPager->walSyncFlags |= (SQLITE_SYNC_FULL<<2); |
| 51055 | 51061 | } |
| 51056 | 51062 | if( pgFlags & PAGER_CACHESPILL ){ |
| 51057 | 51063 | pPager->doNotSpill &= ~SPILLFLAG_OFF; |
| 51058 | 51064 | }else{ |
| 51059 | 51065 | pPager->doNotSpill |= SPILLFLAG_OFF; |
| | @@ -51548,11 +51554,11 @@ |
| 51548 | 51554 | pagerFreeMapHdrs(pPager); |
| 51549 | 51555 | /* pPager->errCode = 0; */ |
| 51550 | 51556 | pPager->exclusiveMode = 0; |
| 51551 | 51557 | #ifndef SQLITE_OMIT_WAL |
| 51552 | 51558 | assert( db || pPager->pWal==0 ); |
| 51553 | | - sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize, |
| 51559 | + sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize, |
| 51554 | 51560 | (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp) |
| 51555 | 51561 | ); |
| 51556 | 51562 | pPager->pWal = 0; |
| 51557 | 51563 | #endif |
| 51558 | 51564 | pager_reset(pPager); |
| | @@ -52016,10 +52022,17 @@ |
| 52016 | 52022 | rc = subjournalPageIfRequired(pPg); |
| 52017 | 52023 | if( rc==SQLITE_OK ){ |
| 52018 | 52024 | rc = pagerWalFrames(pPager, pPg, 0, 0); |
| 52019 | 52025 | } |
| 52020 | 52026 | }else{ |
| 52027 | + |
| 52028 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 52029 | + if( pPager->tempFile==0 ){ |
| 52030 | + rc = sqlite3JournalCreate(pPager->jfd); |
| 52031 | + if( rc!=SQLITE_OK ) return pager_error(pPager, rc); |
| 52032 | + } |
| 52033 | +#endif |
| 52021 | 52034 | |
| 52022 | 52035 | /* Sync the journal file if required. */ |
| 52023 | 52036 | if( pPg->flags&PGHDR_NEED_SYNC |
| 52024 | 52037 | || pPager->eState==PAGER_WRITER_CACHEMOD |
| 52025 | 52038 | ){ |
| | @@ -52349,17 +52362,15 @@ |
| 52349 | 52362 | if( pPager->noSync ){ |
| 52350 | 52363 | assert( pPager->fullSync==0 ); |
| 52351 | 52364 | assert( pPager->extraSync==0 ); |
| 52352 | 52365 | assert( pPager->syncFlags==0 ); |
| 52353 | 52366 | assert( pPager->walSyncFlags==0 ); |
| 52354 | | - assert( pPager->ckptSyncFlags==0 ); |
| 52355 | 52367 | }else{ |
| 52356 | 52368 | pPager->fullSync = 1; |
| 52357 | 52369 | pPager->extraSync = 0; |
| 52358 | 52370 | pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 52359 | | - pPager->walSyncFlags = SQLITE_SYNC_NORMAL | WAL_SYNC_TRANSACTIONS; |
| 52360 | | - pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL; |
| 52371 | + pPager->walSyncFlags = SQLITE_SYNC_NORMAL | (SQLITE_SYNC_NORMAL<<2); |
| 52361 | 52372 | } |
| 52362 | 52373 | /* pPager->pFirst = 0; */ |
| 52363 | 52374 | /* pPager->pFirstSynced = 0; */ |
| 52364 | 52375 | /* pPager->pLast = 0; */ |
| 52365 | 52376 | pPager->nExtra = (u16)nExtra; |
| | @@ -52775,11 +52786,12 @@ |
| 52775 | 52786 | ** Except, in locking_mode=EXCLUSIVE when there is nothing to in |
| 52776 | 52787 | ** the rollback journal, the unlock is not performed and there is |
| 52777 | 52788 | ** nothing to rollback, so this routine is a no-op. |
| 52778 | 52789 | */ |
| 52779 | 52790 | static void pagerUnlockIfUnused(Pager *pPager){ |
| 52780 | | - if( pPager->nMmapOut==0 && (sqlite3PcacheRefCount(pPager->pPCache)==0) ){ |
| 52791 | + if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){ |
| 52792 | + assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */ |
| 52781 | 52793 | pagerUnlockAndRollback(pPager); |
| 52782 | 52794 | } |
| 52783 | 52795 | } |
| 52784 | 52796 | |
| 52785 | 52797 | /* |
| | @@ -52916,18 +52928,13 @@ |
| 52916 | 52928 | sqlite3EndBenignMalloc(); |
| 52917 | 52929 | } |
| 52918 | 52930 | memset(pPg->pData, 0, pPager->pageSize); |
| 52919 | 52931 | IOTRACE(("ZERO %p %d\n", pPager, pgno)); |
| 52920 | 52932 | }else{ |
| 52921 | | - u32 iFrame = 0; /* Frame to read from WAL file */ |
| 52922 | | - if( pagerUseWal(pPager) ){ |
| 52923 | | - rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); |
| 52924 | | - if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| 52925 | | - } |
| 52926 | 52933 | assert( pPg->pPager==pPager ); |
| 52927 | 52934 | pPager->aStat[PAGER_STAT_MISS]++; |
| 52928 | | - rc = readDbPage(pPg, iFrame); |
| 52935 | + rc = readDbPage(pPg); |
| 52929 | 52936 | if( rc!=SQLITE_OK ){ |
| 52930 | 52937 | goto pager_acquire_err; |
| 52931 | 52938 | } |
| 52932 | 52939 | } |
| 52933 | 52940 | pager_set_pagehash(pPg); |
| | @@ -53066,28 +53073,42 @@ |
| 53066 | 53073 | } |
| 53067 | 53074 | |
| 53068 | 53075 | /* |
| 53069 | 53076 | ** Release a page reference. |
| 53070 | 53077 | ** |
| 53071 | | -** If the number of references to the page drop to zero, then the |
| 53072 | | -** page is added to the LRU list. When all references to all pages |
| 53073 | | -** are released, a rollback occurs and the lock on the database is |
| 53074 | | -** removed. |
| 53078 | +** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be |
| 53079 | +** used if we know that the page being released is not the last page. |
| 53080 | +** The btree layer always holds page1 open until the end, so these first |
| 53081 | +** to routines can be used to release any page other than BtShared.pPage1. |
| 53082 | +** |
| 53083 | +** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine |
| 53084 | +** checks the total number of outstanding pages and if the number of |
| 53085 | +** pages reaches zero it drops the database lock. |
| 53075 | 53086 | */ |
| 53076 | 53087 | SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){ |
| 53077 | | - Pager *pPager; |
| 53088 | + TESTONLY( Pager *pPager = pPg->pPager; ) |
| 53078 | 53089 | assert( pPg!=0 ); |
| 53079 | | - pPager = pPg->pPager; |
| 53080 | 53090 | if( pPg->flags & PGHDR_MMAP ){ |
| 53091 | + assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */ |
| 53081 | 53092 | pagerReleaseMapPage(pPg); |
| 53082 | 53093 | }else{ |
| 53083 | 53094 | sqlite3PcacheRelease(pPg); |
| 53084 | 53095 | } |
| 53085 | | - pagerUnlockIfUnused(pPager); |
| 53096 | + /* Do not use this routine to release the last reference to page1 */ |
| 53097 | + assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); |
| 53086 | 53098 | } |
| 53087 | 53099 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){ |
| 53088 | 53100 | if( pPg ) sqlite3PagerUnrefNotNull(pPg); |
| 53101 | +} |
| 53102 | +SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){ |
| 53103 | + Pager *pPager; |
| 53104 | + assert( pPg!=0 ); |
| 53105 | + assert( pPg->pgno==1 ); |
| 53106 | + assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */ |
| 53107 | + pPager = pPg->pPager; |
| 53108 | + sqlite3PcacheRelease(pPg); |
| 53109 | + pagerUnlockIfUnused(pPager); |
| 53089 | 53110 | } |
| 53090 | 53111 | |
| 53091 | 53112 | /* |
| 53092 | 53113 | ** This function is called at the start of every write transaction. |
| 53093 | 53114 | ** There must already be a RESERVED or EXCLUSIVE lock on the database |
| | @@ -53796,10 +53817,25 @@ |
| 53796 | 53817 | sqlite3PagerUnref(pPageOne); |
| 53797 | 53818 | if( rc==SQLITE_OK ){ |
| 53798 | 53819 | sqlite3PcacheCleanAll(pPager->pPCache); |
| 53799 | 53820 | } |
| 53800 | 53821 | }else{ |
| 53822 | + /* The bBatch boolean is true if the batch-atomic-write commit method |
| 53823 | + ** should be used. No rollback journal is created if batch-atomic-write |
| 53824 | + ** is enabled. |
| 53825 | + */ |
| 53826 | + sqlite3_file *fd = pPager->fd; |
| 53827 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 53828 | + const int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */ |
| 53829 | + && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC) |
| 53830 | + && !pPager->noSync |
| 53831 | + && sqlite3JournalIsInMemory(pPager->jfd); |
| 53832 | +#else |
| 53833 | +# define bBatch 0 |
| 53834 | +#endif |
| 53835 | + |
| 53836 | +#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 53801 | 53837 | /* The following block updates the change-counter. Exactly how it |
| 53802 | 53838 | ** does this depends on whether or not the atomic-update optimization |
| 53803 | 53839 | ** was enabled at compile time, and if this transaction meets the |
| 53804 | 53840 | ** runtime criteria to use the operation: |
| 53805 | 53841 | ** |
| | @@ -53819,37 +53855,44 @@ |
| 53819 | 53855 | ** Otherwise, if the optimization is both enabled and applicable, |
| 53820 | 53856 | ** then call pager_incr_changecounter() to update the change-counter |
| 53821 | 53857 | ** in 'direct' mode. In this case the journal file will never be |
| 53822 | 53858 | ** created for this transaction. |
| 53823 | 53859 | */ |
| 53824 | | - #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 53825 | | - PgHdr *pPg; |
| 53826 | | - assert( isOpen(pPager->jfd) |
| 53827 | | - || pPager->journalMode==PAGER_JOURNALMODE_OFF |
| 53828 | | - || pPager->journalMode==PAGER_JOURNALMODE_WAL |
| 53829 | | - ); |
| 53830 | | - if( !zMaster && isOpen(pPager->jfd) |
| 53831 | | - && pPager->journalOff==jrnlBufferSize(pPager) |
| 53832 | | - && pPager->dbSize>=pPager->dbOrigSize |
| 53833 | | - && (0==(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty) |
| 53834 | | - ){ |
| 53835 | | - /* Update the db file change counter via the direct-write method. The |
| 53836 | | - ** following call will modify the in-memory representation of page 1 |
| 53837 | | - ** to include the updated change counter and then write page 1 |
| 53838 | | - ** directly to the database file. Because of the atomic-write |
| 53839 | | - ** property of the host file-system, this is safe. |
| 53840 | | - */ |
| 53841 | | - rc = pager_incr_changecounter(pPager, 1); |
| 53842 | | - }else{ |
| 53860 | + if( bBatch==0 ){ |
| 53861 | + PgHdr *pPg; |
| 53862 | + assert( isOpen(pPager->jfd) |
| 53863 | + || pPager->journalMode==PAGER_JOURNALMODE_OFF |
| 53864 | + || pPager->journalMode==PAGER_JOURNALMODE_WAL |
| 53865 | + ); |
| 53866 | + if( !zMaster && isOpen(pPager->jfd) |
| 53867 | + && pPager->journalOff==jrnlBufferSize(pPager) |
| 53868 | + && pPager->dbSize>=pPager->dbOrigSize |
| 53869 | + && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty) |
| 53870 | + ){ |
| 53871 | + /* Update the db file change counter via the direct-write method. The |
| 53872 | + ** following call will modify the in-memory representation of page 1 |
| 53873 | + ** to include the updated change counter and then write page 1 |
| 53874 | + ** directly to the database file. Because of the atomic-write |
| 53875 | + ** property of the host file-system, this is safe. |
| 53876 | + */ |
| 53877 | + rc = pager_incr_changecounter(pPager, 1); |
| 53878 | + }else{ |
| 53879 | + rc = sqlite3JournalCreate(pPager->jfd); |
| 53880 | + if( rc==SQLITE_OK ){ |
| 53881 | + rc = pager_incr_changecounter(pPager, 0); |
| 53882 | + } |
| 53883 | + } |
| 53884 | + } |
| 53885 | +#else |
| 53886 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 53887 | + if( zMaster ){ |
| 53843 | 53888 | rc = sqlite3JournalCreate(pPager->jfd); |
| 53844 | | - if( rc==SQLITE_OK ){ |
| 53845 | | - rc = pager_incr_changecounter(pPager, 0); |
| 53846 | | - } |
| 53889 | + if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 53847 | 53890 | } |
| 53848 | | - #else |
| 53891 | +#endif |
| 53849 | 53892 | rc = pager_incr_changecounter(pPager, 0); |
| 53850 | | - #endif |
| 53893 | +#endif |
| 53851 | 53894 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 53852 | 53895 | |
| 53853 | 53896 | /* Write the master journal name into the journal file. If a master |
| 53854 | 53897 | ** journal file name has already been written to the journal file, |
| 53855 | 53898 | ** or if zMaster is NULL (no master journal), then this call is a no-op. |
| | @@ -53868,12 +53911,28 @@ |
| 53868 | 53911 | ** not the case. In this case it is likely enough that the redundant |
| 53869 | 53912 | ** xSync() call will be changed to a no-op by the OS anyhow. |
| 53870 | 53913 | */ |
| 53871 | 53914 | rc = syncJournal(pPager, 0); |
| 53872 | 53915 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 53873 | | - |
| 53916 | + |
| 53917 | + if( bBatch ){ |
| 53918 | + /* The pager is now in DBMOD state. But regardless of what happens |
| 53919 | + ** next, attempting to play the journal back into the database would |
| 53920 | + ** be unsafe. Close it now to make sure that does not happen. */ |
| 53921 | + sqlite3OsClose(pPager->jfd); |
| 53922 | + rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0); |
| 53923 | + if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 53924 | + } |
| 53874 | 53925 | rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache)); |
| 53926 | + if( bBatch ){ |
| 53927 | + if( rc==SQLITE_OK ){ |
| 53928 | + rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0); |
| 53929 | + }else{ |
| 53930 | + sqlite3OsFileControl(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0); |
| 53931 | + } |
| 53932 | + } |
| 53933 | + |
| 53875 | 53934 | if( rc!=SQLITE_OK ){ |
| 53876 | 53935 | assert( rc!=SQLITE_IOERR_BLOCKED ); |
| 53877 | 53936 | goto commit_phase_one_exit; |
| 53878 | 53937 | } |
| 53879 | 53938 | sqlite3PcacheCleanAll(pPager->pPCache); |
| | @@ -54770,11 +54829,11 @@ |
| 54770 | 54829 | int rc = SQLITE_OK; |
| 54771 | 54830 | if( pPager->pWal ){ |
| 54772 | 54831 | rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, |
| 54773 | 54832 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 54774 | 54833 | pPager->pBusyHandlerArg, |
| 54775 | | - pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 54834 | + pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 54776 | 54835 | pnLog, pnCkpt |
| 54777 | 54836 | ); |
| 54778 | 54837 | } |
| 54779 | 54838 | return rc; |
| 54780 | 54839 | } |
| | @@ -54927,11 +54986,11 @@ |
| 54927 | 54986 | ** the database file, the log and log-summary files will be deleted. |
| 54928 | 54987 | */ |
| 54929 | 54988 | if( rc==SQLITE_OK && pPager->pWal ){ |
| 54930 | 54989 | rc = pagerExclusiveLock(pPager); |
| 54931 | 54990 | if( rc==SQLITE_OK ){ |
| 54932 | | - rc = sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, |
| 54991 | + rc = sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, |
| 54933 | 54992 | pPager->pageSize, (u8*)pPager->pTmpSpace); |
| 54934 | 54993 | pPager->pWal = 0; |
| 54935 | 54994 | pagerFixMaplimit(pPager); |
| 54936 | 54995 | if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK); |
| 54937 | 54996 | } |
| | @@ -56799,13 +56858,11 @@ |
| 56799 | 56858 | u32 nBackfill = pInfo->nBackfill; |
| 56800 | 56859 | |
| 56801 | 56860 | pInfo->nBackfillAttempted = mxSafeFrame; |
| 56802 | 56861 | |
| 56803 | 56862 | /* Sync the WAL to disk */ |
| 56804 | | - if( sync_flags ){ |
| 56805 | | - rc = sqlite3OsSync(pWal->pWalFd, sync_flags); |
| 56806 | | - } |
| 56863 | + rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 56807 | 56864 | |
| 56808 | 56865 | /* If the database may grow as a result of this checkpoint, hint |
| 56809 | 56866 | ** about the eventual size of the db file to the VFS layer. |
| 56810 | 56867 | */ |
| 56811 | 56868 | if( rc==SQLITE_OK ){ |
| | @@ -56842,12 +56899,12 @@ |
| 56842 | 56899 | if( rc==SQLITE_OK ){ |
| 56843 | 56900 | if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){ |
| 56844 | 56901 | i64 szDb = pWal->hdr.nPage*(i64)szPage; |
| 56845 | 56902 | testcase( IS_BIG_INT(szDb) ); |
| 56846 | 56903 | rc = sqlite3OsTruncate(pWal->pDbFd, szDb); |
| 56847 | | - if( rc==SQLITE_OK && sync_flags ){ |
| 56848 | | - rc = sqlite3OsSync(pWal->pDbFd, sync_flags); |
| 56904 | + if( rc==SQLITE_OK ){ |
| 56905 | + rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 56849 | 56906 | } |
| 56850 | 56907 | } |
| 56851 | 56908 | if( rc==SQLITE_OK ){ |
| 56852 | 56909 | pInfo->nBackfill = mxSafeFrame; |
| 56853 | 56910 | } |
| | @@ -57949,12 +58006,12 @@ |
| 57949 | 58006 | rc = sqlite3OsWrite(p->pFd, pContent, iFirstAmt, iOffset); |
| 57950 | 58007 | if( rc ) return rc; |
| 57951 | 58008 | iOffset += iFirstAmt; |
| 57952 | 58009 | iAmt -= iFirstAmt; |
| 57953 | 58010 | pContent = (void*)(iFirstAmt + (char*)pContent); |
| 57954 | | - assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) ); |
| 57955 | | - rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK); |
| 58011 | + assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 ); |
| 58012 | + rc = sqlite3OsSync(p->pFd, WAL_SYNC_FLAGS(p->syncFlags)); |
| 57956 | 58013 | if( iAmt==0 || rc ) return rc; |
| 57957 | 58014 | } |
| 57958 | 58015 | rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset); |
| 57959 | 58016 | return rc; |
| 57960 | 58017 | } |
| | @@ -58120,14 +58177,14 @@ |
| 58120 | 58177 | /* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless |
| 58121 | 58178 | ** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise |
| 58122 | 58179 | ** an out-of-order write following a WAL restart could result in |
| 58123 | 58180 | ** database corruption. See the ticket: |
| 58124 | 58181 | ** |
| 58125 | | - ** http://localhost:591/sqlite/info/ff5be73dee |
| 58182 | + ** https://sqlite.org/src/info/ff5be73dee |
| 58126 | 58183 | */ |
| 58127 | | - if( pWal->syncHeader && sync_flags ){ |
| 58128 | | - rc = sqlite3OsSync(pWal->pWalFd, sync_flags & SQLITE_SYNC_MASK); |
| 58184 | + if( pWal->syncHeader ){ |
| 58185 | + rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 58129 | 58186 | if( rc ) return rc; |
| 58130 | 58187 | } |
| 58131 | 58188 | } |
| 58132 | 58189 | assert( (int)pWal->szPage==szPage ); |
| 58133 | 58190 | |
| | @@ -58198,11 +58255,11 @@ |
| 58198 | 58255 | ** final frame is repeated (with its commit mark) until the next sector |
| 58199 | 58256 | ** boundary is crossed. Only the part of the WAL prior to the last |
| 58200 | 58257 | ** sector boundary is synced; the part of the last frame that extends |
| 58201 | 58258 | ** past the sector boundary is written after the sync. |
| 58202 | 58259 | */ |
| 58203 | | - if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){ |
| 58260 | + if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){ |
| 58204 | 58261 | int bSync = 1; |
| 58205 | 58262 | if( pWal->padToSectorBoundary ){ |
| 58206 | 58263 | int sectorSize = sqlite3SectorSize(pWal->pWalFd); |
| 58207 | 58264 | w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize; |
| 58208 | 58265 | bSync = (w.iSyncPoint==iOffset); |
| | @@ -58214,11 +58271,11 @@ |
| 58214 | 58271 | nExtra++; |
| 58215 | 58272 | } |
| 58216 | 58273 | } |
| 58217 | 58274 | if( bSync ){ |
| 58218 | 58275 | assert( rc==SQLITE_OK ); |
| 58219 | | - rc = sqlite3OsSync(w.pFd, sync_flags & SQLITE_SYNC_MASK); |
| 58276 | + rc = sqlite3OsSync(w.pFd, WAL_SYNC_FLAGS(sync_flags)); |
| 58220 | 58277 | } |
| 58221 | 58278 | } |
| 58222 | 58279 | |
| 58223 | 58280 | /* If this frame set completes the first transaction in the WAL and |
| 58224 | 58281 | ** if PRAGMA journal_size_limit is set, then truncate the WAL to the |
| | @@ -59061,34 +59118,35 @@ |
| 59061 | 59118 | ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op. |
| 59062 | 59119 | ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op. |
| 59063 | 59120 | ** eState==FAULT: Cursor fault with skipNext as error code. |
| 59064 | 59121 | */ |
| 59065 | 59122 | struct BtCursor { |
| 59123 | + u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 59124 | + u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 59125 | + u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| 59126 | + u8 hints; /* As configured by CursorSetHints() */ |
| 59127 | + int nOvflAlloc; /* Allocated size of aOverflow[] array */ |
| 59066 | 59128 | Btree *pBtree; /* The Btree to which this cursor belongs */ |
| 59067 | 59129 | BtShared *pBt; /* The BtShared this cursor points to */ |
| 59068 | 59130 | BtCursor *pNext; /* Forms a linked list of all cursors */ |
| 59069 | 59131 | Pgno *aOverflow; /* Cache of overflow page locations */ |
| 59070 | 59132 | CellInfo info; /* A parse of the cell we are pointing at */ |
| 59071 | 59133 | i64 nKey; /* Size of pKey, or last integer key */ |
| 59072 | 59134 | void *pKey; /* Saved key that was cursor last known position */ |
| 59073 | 59135 | Pgno pgnoRoot; /* The root page of this tree */ |
| 59074 | | - int nOvflAlloc; /* Allocated size of aOverflow[] array */ |
| 59075 | 59136 | int skipNext; /* Prev() is noop if negative. Next() is noop if positive. |
| 59076 | 59137 | ** Error code if eState==CURSOR_FAULT */ |
| 59077 | | - u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 59078 | | - u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| 59079 | | - u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 59080 | | - u8 hints; /* As configured by CursorSetHints() */ |
| 59081 | 59138 | /* All fields above are zeroed when the cursor is allocated. See |
| 59082 | 59139 | ** sqlite3BtreeCursorZero(). Fields that follow must be manually |
| 59083 | 59140 | ** initialized. */ |
| 59084 | 59141 | i8 iPage; /* Index of current page in apPage */ |
| 59085 | 59142 | u8 curIntKey; /* Value of apPage[0]->intKey */ |
| 59086 | 59143 | u16 ix; /* Current index for apPage[iPage] */ |
| 59087 | 59144 | u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */ |
| 59088 | 59145 | struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */ |
| 59089 | | - MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */ |
| 59146 | + MemPage *pPage; /* Current page */ |
| 59147 | + MemPage *apPage[BTCURSOR_MAX_DEPTH-1]; /* Stack of parents of current page */ |
| 59090 | 59148 | }; |
| 59091 | 59149 | |
| 59092 | 59150 | /* |
| 59093 | 59151 | ** Legal values for BtCursor.curFlags |
| 59094 | 59152 | */ |
| | @@ -60000,11 +60058,13 @@ |
| 60000 | 60058 | } |
| 60001 | 60059 | } |
| 60002 | 60060 | |
| 60003 | 60061 | #endif /* SQLITE_OMIT_SHARED_CACHE */ |
| 60004 | 60062 | |
| 60005 | | -static void releasePage(MemPage *pPage); /* Forward reference */ |
| 60063 | +static void releasePage(MemPage *pPage); /* Forward reference */ |
| 60064 | +static void releasePageOne(MemPage *pPage); /* Forward reference */ |
| 60065 | +static void releasePageNotNull(MemPage *pPage); /* Forward reference */ |
| 60006 | 60066 | |
| 60007 | 60067 | /* |
| 60008 | 60068 | ***** This routine is used inside of assert() only **** |
| 60009 | 60069 | ** |
| 60010 | 60070 | ** Verify that the cursor holds the mutex on its BtShared |
| | @@ -60159,15 +60219,17 @@ |
| 60159 | 60219 | /* |
| 60160 | 60220 | ** Release all of the apPage[] pages for a cursor. |
| 60161 | 60221 | */ |
| 60162 | 60222 | static void btreeReleaseAllCursorPages(BtCursor *pCur){ |
| 60163 | 60223 | int i; |
| 60164 | | - for(i=0; i<=pCur->iPage; i++){ |
| 60165 | | - releasePage(pCur->apPage[i]); |
| 60166 | | - pCur->apPage[i] = 0; |
| 60224 | + if( pCur->iPage>=0 ){ |
| 60225 | + for(i=0; i<pCur->iPage; i++){ |
| 60226 | + releasePageNotNull(pCur->apPage[i]); |
| 60227 | + } |
| 60228 | + releasePageNotNull(pCur->pPage); |
| 60229 | + pCur->iPage = -1; |
| 60167 | 60230 | } |
| 60168 | | - pCur->iPage = -1; |
| 60169 | 60231 | } |
| 60170 | 60232 | |
| 60171 | 60233 | /* |
| 60172 | 60234 | ** The cursor passed as the only argument must point to a valid entry |
| 60173 | 60235 | ** when this function is called (i.e. have eState==CURSOR_VALID). This |
| | @@ -60292,11 +60354,11 @@ |
| 60292 | 60354 | int rc = saveCursorPosition(p); |
| 60293 | 60355 | if( SQLITE_OK!=rc ){ |
| 60294 | 60356 | return rc; |
| 60295 | 60357 | } |
| 60296 | 60358 | }else{ |
| 60297 | | - testcase( p->iPage>0 ); |
| 60359 | + testcase( p->iPage>=0 ); |
| 60298 | 60360 | btreeReleaseAllCursorPages(p); |
| 60299 | 60361 | } |
| 60300 | 60362 | } |
| 60301 | 60363 | p = p->pNext; |
| 60302 | 60364 | }while( p ); |
| | @@ -60332,11 +60394,11 @@ |
| 60332 | 60394 | assert( nKey==(i64)(int)nKey ); |
| 60333 | 60395 | pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo); |
| 60334 | 60396 | if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT; |
| 60335 | 60397 | sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey); |
| 60336 | 60398 | if( pIdxKey->nField==0 ){ |
| 60337 | | - rc = SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno); |
| 60399 | + rc = SQLITE_CORRUPT_BKPT; |
| 60338 | 60400 | goto moveto_done; |
| 60339 | 60401 | } |
| 60340 | 60402 | }else{ |
| 60341 | 60403 | pIdxKey = 0; |
| 60342 | 60404 | } |
| | @@ -60395,10 +60457,21 @@ |
| 60395 | 60457 | ** back to where it ought to be if this routine returns true. |
| 60396 | 60458 | */ |
| 60397 | 60459 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){ |
| 60398 | 60460 | return pCur->eState!=CURSOR_VALID; |
| 60399 | 60461 | } |
| 60462 | + |
| 60463 | +/* |
| 60464 | +** Return a pointer to a fake BtCursor object that will always answer |
| 60465 | +** false to the sqlite3BtreeCursorHasMoved() routine above. The fake |
| 60466 | +** cursor returned must not be used with any other Btree interface. |
| 60467 | +*/ |
| 60468 | +SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void){ |
| 60469 | + static u8 fakeCursor = CURSOR_VALID; |
| 60470 | + assert( offsetof(BtCursor, eState)==0 ); |
| 60471 | + return (BtCursor*)&fakeCursor; |
| 60472 | +} |
| 60400 | 60473 | |
| 60401 | 60474 | /* |
| 60402 | 60475 | ** This routine restores a cursor back to its original position after it |
| 60403 | 60476 | ** has been moved by some outside activity (such as a btree rebalance or |
| 60404 | 60477 | ** a row having been deleted out from under the cursor). |
| | @@ -60946,11 +61019,11 @@ |
| 60946 | 61019 | u8 *pAddr; |
| 60947 | 61020 | int sz2 = 0; |
| 60948 | 61021 | int sz = get2byte(&data[iFree+2]); |
| 60949 | 61022 | int top = get2byte(&data[hdr+5]); |
| 60950 | 61023 | if( iFree2 ){ |
| 60951 | | - if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61024 | + assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */ |
| 60952 | 61025 | sz2 = get2byte(&data[iFree2+2]); |
| 60953 | 61026 | assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize ); |
| 60954 | 61027 | memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 60955 | 61028 | sz += sz2; |
| 60956 | 61029 | } |
| | @@ -61035,28 +61108,22 @@ |
| 61035 | 61108 | u8 * const aData = pPg->aData; |
| 61036 | 61109 | int iAddr = hdr + 1; |
| 61037 | 61110 | int pc = get2byte(&aData[iAddr]); |
| 61038 | 61111 | int x; |
| 61039 | 61112 | int usableSize = pPg->pBt->usableSize; |
| 61113 | + int size; /* Size of the free slot */ |
| 61040 | 61114 | |
| 61041 | 61115 | assert( pc>0 ); |
| 61042 | | - do{ |
| 61043 | | - int size; /* Size of the free slot */ |
| 61044 | | - /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of |
| 61045 | | - ** increasing offset. */ |
| 61046 | | - if( pc>usableSize-4 || pc<iAddr+4 ){ |
| 61047 | | - *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); |
| 61048 | | - return 0; |
| 61049 | | - } |
| 61116 | + while( pc<=usableSize-4 ){ |
| 61050 | 61117 | /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each |
| 61051 | 61118 | ** freeblock form a big-endian integer which is the size of the freeblock |
| 61052 | 61119 | ** in bytes, including the 4-byte header. */ |
| 61053 | 61120 | size = get2byte(&aData[pc+2]); |
| 61054 | 61121 | if( (x = size - nByte)>=0 ){ |
| 61055 | 61122 | testcase( x==4 ); |
| 61056 | 61123 | testcase( x==3 ); |
| 61057 | | - if( pc < pPg->cellOffset+2*pPg->nCell || size+pc > usableSize ){ |
| 61124 | + if( size+pc > usableSize ){ |
| 61058 | 61125 | *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); |
| 61059 | 61126 | return 0; |
| 61060 | 61127 | }else if( x<4 ){ |
| 61061 | 61128 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| 61062 | 61129 | ** number of bytes in fragments may not exceed 60. */ |
| | @@ -61073,11 +61140,15 @@ |
| 61073 | 61140 | } |
| 61074 | 61141 | return &aData[pc + x]; |
| 61075 | 61142 | } |
| 61076 | 61143 | iAddr = pc; |
| 61077 | 61144 | pc = get2byte(&aData[pc]); |
| 61078 | | - }while( pc ); |
| 61145 | + if( pc<iAddr+size ) break; |
| 61146 | + } |
| 61147 | + if( pc ){ |
| 61148 | + *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); |
| 61149 | + } |
| 61079 | 61150 | |
| 61080 | 61151 | return 0; |
| 61081 | 61152 | } |
| 61082 | 61153 | |
| 61083 | 61154 | /* |
| | @@ -61187,27 +61258,21 @@ |
| 61187 | 61258 | u16 iPtr; /* Address of ptr to next freeblock */ |
| 61188 | 61259 | u16 iFreeBlk; /* Address of the next freeblock */ |
| 61189 | 61260 | u8 hdr; /* Page header size. 0 or 100 */ |
| 61190 | 61261 | u8 nFrag = 0; /* Reduction in fragmentation */ |
| 61191 | 61262 | u16 iOrigSize = iSize; /* Original value of iSize */ |
| 61192 | | - u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */ |
| 61263 | + u16 x; /* Offset to cell content area */ |
| 61193 | 61264 | u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ |
| 61194 | 61265 | unsigned char *data = pPage->aData; /* Page content */ |
| 61195 | 61266 | |
| 61196 | 61267 | assert( pPage->pBt!=0 ); |
| 61197 | 61268 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 61198 | 61269 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 61199 | 61270 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| 61200 | 61271 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 61201 | 61272 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 61202 | | - assert( iStart<=iLast ); |
| 61203 | | - |
| 61204 | | - /* Overwrite deleted information with zeros when the secure_delete |
| 61205 | | - ** option is enabled */ |
| 61206 | | - if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){ |
| 61207 | | - memset(&data[iStart], 0, iSize); |
| 61208 | | - } |
| 61273 | + assert( iStart<=pPage->pBt->usableSize-4 ); |
| 61209 | 61274 | |
| 61210 | 61275 | /* The list of freeblocks must be in ascending order. Find the |
| 61211 | 61276 | ** spot on the list where iStart should be inserted. |
| 61212 | 61277 | */ |
| 61213 | 61278 | hdr = pPage->hdrOffset; |
| | @@ -61220,11 +61285,13 @@ |
| 61220 | 61285 | if( iFreeBlk==0 ) break; |
| 61221 | 61286 | return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61222 | 61287 | } |
| 61223 | 61288 | iPtr = iFreeBlk; |
| 61224 | 61289 | } |
| 61225 | | - if( iFreeBlk>iLast ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61290 | + if( iFreeBlk>pPage->pBt->usableSize-4 ){ |
| 61291 | + return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61292 | + } |
| 61226 | 61293 | assert( iFreeBlk>iPtr || iFreeBlk==0 ); |
| 61227 | 61294 | |
| 61228 | 61295 | /* At this point: |
| 61229 | 61296 | ** iFreeBlk: First freeblock after iStart, or zero if none |
| 61230 | 61297 | ** iPtr: The address of a pointer to iFreeBlk |
| | @@ -61256,23 +61323,29 @@ |
| 61256 | 61323 | } |
| 61257 | 61324 | } |
| 61258 | 61325 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61259 | 61326 | data[hdr+7] -= nFrag; |
| 61260 | 61327 | } |
| 61261 | | - if( iStart==get2byte(&data[hdr+5]) ){ |
| 61328 | + x = get2byte(&data[hdr+5]); |
| 61329 | + if( iStart<=x ){ |
| 61262 | 61330 | /* The new freeblock is at the beginning of the cell content area, |
| 61263 | 61331 | ** so just extend the cell content area rather than create another |
| 61264 | 61332 | ** freelist entry */ |
| 61265 | | - if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61333 | + if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 61266 | 61334 | put2byte(&data[hdr+1], iFreeBlk); |
| 61267 | 61335 | put2byte(&data[hdr+5], iEnd); |
| 61268 | 61336 | }else{ |
| 61269 | 61337 | /* Insert the new freeblock into the freelist */ |
| 61270 | 61338 | put2byte(&data[iPtr], iStart); |
| 61271 | | - put2byte(&data[iStart], iFreeBlk); |
| 61272 | | - put2byte(&data[iStart+2], iSize); |
| 61273 | 61339 | } |
| 61340 | + if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){ |
| 61341 | + /* Overwrite deleted information with zeros when the secure_delete |
| 61342 | + ** option is enabled */ |
| 61343 | + memset(&data[iStart], 0, iSize); |
| 61344 | + } |
| 61345 | + put2byte(&data[iStart], iFreeBlk); |
| 61346 | + put2byte(&data[iStart+2], iSize); |
| 61274 | 61347 | pPage->nFree += iOrigSize; |
| 61275 | 61348 | return SQLITE_OK; |
| 61276 | 61349 | } |
| 61277 | 61350 | |
| 61278 | 61351 | /* |
| | @@ -61610,11 +61683,11 @@ |
| 61610 | 61683 | int bReadOnly /* True for a read-only page */ |
| 61611 | 61684 | ){ |
| 61612 | 61685 | int rc; |
| 61613 | 61686 | DbPage *pDbPage; |
| 61614 | 61687 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 61615 | | - assert( pCur==0 || ppPage==&pCur->apPage[pCur->iPage] ); |
| 61688 | + assert( pCur==0 || ppPage==&pCur->pPage ); |
| 61616 | 61689 | assert( pCur==0 || bReadOnly==pCur->curPagerFlags ); |
| 61617 | 61690 | assert( pCur==0 || pCur->iPage>0 ); |
| 61618 | 61691 | |
| 61619 | 61692 | if( pgno>btreePagecount(pBt) ){ |
| 61620 | 61693 | rc = SQLITE_CORRUPT_BKPT; |
| | @@ -61644,19 +61717,24 @@ |
| 61644 | 61717 | goto getAndInitPage_error; |
| 61645 | 61718 | } |
| 61646 | 61719 | return SQLITE_OK; |
| 61647 | 61720 | |
| 61648 | 61721 | getAndInitPage_error: |
| 61649 | | - if( pCur ) pCur->iPage--; |
| 61722 | + if( pCur ){ |
| 61723 | + pCur->iPage--; |
| 61724 | + pCur->pPage = pCur->apPage[pCur->iPage]; |
| 61725 | + } |
| 61650 | 61726 | testcase( pgno==0 ); |
| 61651 | 61727 | assert( pgno!=0 || rc==SQLITE_CORRUPT ); |
| 61652 | 61728 | return rc; |
| 61653 | 61729 | } |
| 61654 | 61730 | |
| 61655 | 61731 | /* |
| 61656 | 61732 | ** Release a MemPage. This should be called once for each prior |
| 61657 | 61733 | ** call to btreeGetPage. |
| 61734 | +** |
| 61735 | +** Page1 is a special case and must be released using releasePageOne(). |
| 61658 | 61736 | */ |
| 61659 | 61737 | static void releasePageNotNull(MemPage *pPage){ |
| 61660 | 61738 | assert( pPage->aData ); |
| 61661 | 61739 | assert( pPage->pBt ); |
| 61662 | 61740 | assert( pPage->pDbPage!=0 ); |
| | @@ -61665,10 +61743,20 @@ |
| 61665 | 61743 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 61666 | 61744 | sqlite3PagerUnrefNotNull(pPage->pDbPage); |
| 61667 | 61745 | } |
| 61668 | 61746 | static void releasePage(MemPage *pPage){ |
| 61669 | 61747 | if( pPage ) releasePageNotNull(pPage); |
| 61748 | +} |
| 61749 | +static void releasePageOne(MemPage *pPage){ |
| 61750 | + assert( pPage!=0 ); |
| 61751 | + assert( pPage->aData ); |
| 61752 | + assert( pPage->pBt ); |
| 61753 | + assert( pPage->pDbPage!=0 ); |
| 61754 | + assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 61755 | + assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData ); |
| 61756 | + assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 61757 | + sqlite3PagerUnrefPageOne(pPage->pDbPage); |
| 61670 | 61758 | } |
| 61671 | 61759 | |
| 61672 | 61760 | /* |
| 61673 | 61761 | ** Get an unused page. |
| 61674 | 61762 | ** |
| | @@ -62544,11 +62632,11 @@ |
| 62544 | 62632 | if( rc!=SQLITE_OK ){ |
| 62545 | 62633 | goto page1_init_failed; |
| 62546 | 62634 | }else{ |
| 62547 | 62635 | setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1); |
| 62548 | 62636 | if( isOpen==0 ){ |
| 62549 | | - releasePage(pPage1); |
| 62637 | + releasePageOne(pPage1); |
| 62550 | 62638 | return SQLITE_OK; |
| 62551 | 62639 | } |
| 62552 | 62640 | } |
| 62553 | 62641 | rc = SQLITE_NOTADB; |
| 62554 | 62642 | }else{ |
| | @@ -62591,11 +62679,11 @@ |
| 62591 | 62679 | ** of BtShared.pageSize, we have discovered that the page-size is |
| 62592 | 62680 | ** actually pageSize. Unlock the database, leave pBt->pPage1 at |
| 62593 | 62681 | ** zero and return SQLITE_OK. The caller will call this function |
| 62594 | 62682 | ** again with the correct page-size. |
| 62595 | 62683 | */ |
| 62596 | | - releasePage(pPage1); |
| 62684 | + releasePageOne(pPage1); |
| 62597 | 62685 | pBt->usableSize = usableSize; |
| 62598 | 62686 | pBt->pageSize = pageSize; |
| 62599 | 62687 | freeTempSpace(pBt); |
| 62600 | 62688 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 62601 | 62689 | pageSize-usableSize); |
| | @@ -62645,11 +62733,11 @@ |
| 62645 | 62733 | pBt->pPage1 = pPage1; |
| 62646 | 62734 | pBt->nPage = nPage; |
| 62647 | 62735 | return SQLITE_OK; |
| 62648 | 62736 | |
| 62649 | 62737 | page1_init_failed: |
| 62650 | | - releasePage(pPage1); |
| 62738 | + releasePageOne(pPage1); |
| 62651 | 62739 | pBt->pPage1 = 0; |
| 62652 | 62740 | return rc; |
| 62653 | 62741 | } |
| 62654 | 62742 | |
| 62655 | 62743 | #ifndef NDEBUG |
| | @@ -62690,11 +62778,11 @@ |
| 62690 | 62778 | if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){ |
| 62691 | 62779 | MemPage *pPage1 = pBt->pPage1; |
| 62692 | 62780 | assert( pPage1->aData ); |
| 62693 | 62781 | assert( sqlite3PagerRefcount(pBt->pPager)==1 ); |
| 62694 | 62782 | pBt->pPage1 = 0; |
| 62695 | | - releasePageNotNull(pPage1); |
| 62783 | + releasePageOne(pPage1); |
| 62696 | 62784 | } |
| 62697 | 62785 | } |
| 62698 | 62786 | |
| 62699 | 62787 | /* |
| 62700 | 62788 | ** If pBt points to an empty file then convert that empty file |
| | @@ -63542,11 +63630,10 @@ |
| 63542 | 63630 | |
| 63543 | 63631 | assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 ); |
| 63544 | 63632 | if( pBtree ){ |
| 63545 | 63633 | sqlite3BtreeEnter(pBtree); |
| 63546 | 63634 | for(p=pBtree->pBt->pCursor; p; p=p->pNext){ |
| 63547 | | - int i; |
| 63548 | 63635 | if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){ |
| 63549 | 63636 | if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ |
| 63550 | 63637 | rc = saveCursorPosition(p); |
| 63551 | 63638 | if( rc!=SQLITE_OK ){ |
| 63552 | 63639 | (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0); |
| | @@ -63556,14 +63643,11 @@ |
| 63556 | 63643 | }else{ |
| 63557 | 63644 | sqlite3BtreeClearCursor(p); |
| 63558 | 63645 | p->eState = CURSOR_FAULT; |
| 63559 | 63646 | p->skipNext = errCode; |
| 63560 | 63647 | } |
| 63561 | | - for(i=0; i<=p->iPage; i++){ |
| 63562 | | - releasePage(p->apPage[i]); |
| 63563 | | - p->apPage[i] = 0; |
| 63564 | | - } |
| 63648 | + btreeReleaseAllCursorPages(p); |
| 63565 | 63649 | } |
| 63566 | 63650 | sqlite3BtreeLeave(pBtree); |
| 63567 | 63651 | } |
| 63568 | 63652 | return rc; |
| 63569 | 63653 | } |
| | @@ -63616,11 +63700,11 @@ |
| 63616 | 63700 | int nPage = get4byte(28+(u8*)pPage1->aData); |
| 63617 | 63701 | testcase( nPage==0 ); |
| 63618 | 63702 | if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage); |
| 63619 | 63703 | testcase( pBt->nPage!=nPage ); |
| 63620 | 63704 | pBt->nPage = nPage; |
| 63621 | | - releasePage(pPage1); |
| 63705 | + releasePageOne(pPage1); |
| 63622 | 63706 | } |
| 63623 | 63707 | assert( countValidCursors(pBt, 1)==0 ); |
| 63624 | 63708 | pBt->inTransaction = TRANS_READ; |
| 63625 | 63709 | btreeClearHasContent(pBt); |
| 63626 | 63710 | } |
| | @@ -63858,14 +63942,12 @@ |
| 63858 | 63942 | ** when the last cursor is closed. |
| 63859 | 63943 | */ |
| 63860 | 63944 | SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){ |
| 63861 | 63945 | Btree *pBtree = pCur->pBtree; |
| 63862 | 63946 | if( pBtree ){ |
| 63863 | | - int i; |
| 63864 | 63947 | BtShared *pBt = pCur->pBt; |
| 63865 | 63948 | sqlite3BtreeEnter(pBtree); |
| 63866 | | - sqlite3BtreeClearCursor(pCur); |
| 63867 | 63949 | assert( pBt->pCursor!=0 ); |
| 63868 | 63950 | if( pBt->pCursor==pCur ){ |
| 63869 | 63951 | pBt->pCursor = pCur->pNext; |
| 63870 | 63952 | }else{ |
| 63871 | 63953 | BtCursor *pPrev = pBt->pCursor; |
| | @@ -63875,16 +63957,14 @@ |
| 63875 | 63957 | break; |
| 63876 | 63958 | } |
| 63877 | 63959 | pPrev = pPrev->pNext; |
| 63878 | 63960 | }while( ALWAYS(pPrev) ); |
| 63879 | 63961 | } |
| 63880 | | - for(i=0; i<=pCur->iPage; i++){ |
| 63881 | | - releasePage(pCur->apPage[i]); |
| 63882 | | - } |
| 63962 | + btreeReleaseAllCursorPages(pCur); |
| 63883 | 63963 | unlockBtreeIfUnused(pBt); |
| 63884 | 63964 | sqlite3_free(pCur->aOverflow); |
| 63885 | | - /* sqlite3_free(pCur); */ |
| 63965 | + sqlite3_free(pCur->pKey); |
| 63886 | 63966 | sqlite3BtreeLeave(pBtree); |
| 63887 | 63967 | } |
| 63888 | 63968 | return SQLITE_OK; |
| 63889 | 63969 | } |
| 63890 | 63970 | |
| | @@ -63897,23 +63977,21 @@ |
| 63897 | 63977 | ** Using this cache reduces the number of calls to btreeParseCell(). |
| 63898 | 63978 | */ |
| 63899 | 63979 | #ifndef NDEBUG |
| 63900 | 63980 | static void assertCellInfo(BtCursor *pCur){ |
| 63901 | 63981 | CellInfo info; |
| 63902 | | - int iPage = pCur->iPage; |
| 63903 | 63982 | memset(&info, 0, sizeof(info)); |
| 63904 | | - btreeParseCell(pCur->apPage[iPage], pCur->ix, &info); |
| 63983 | + btreeParseCell(pCur->pPage, pCur->ix, &info); |
| 63905 | 63984 | assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 ); |
| 63906 | 63985 | } |
| 63907 | 63986 | #else |
| 63908 | 63987 | #define assertCellInfo(x) |
| 63909 | 63988 | #endif |
| 63910 | 63989 | static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){ |
| 63911 | 63990 | if( pCur->info.nSize==0 ){ |
| 63912 | | - int iPage = pCur->iPage; |
| 63913 | 63991 | pCur->curFlags |= BTCF_ValidNKey; |
| 63914 | | - btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info); |
| 63992 | + btreeParseCell(pCur->pPage,pCur->ix,&pCur->info); |
| 63915 | 63993 | }else{ |
| 63916 | 63994 | assertCellInfo(pCur); |
| 63917 | 63995 | } |
| 63918 | 63996 | } |
| 63919 | 63997 | |
| | @@ -64107,11 +64185,11 @@ |
| 64107 | 64185 | int eOp /* zero to read. non-zero to write. */ |
| 64108 | 64186 | ){ |
| 64109 | 64187 | unsigned char *aPayload; |
| 64110 | 64188 | int rc = SQLITE_OK; |
| 64111 | 64189 | int iIdx = 0; |
| 64112 | | - MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */ |
| 64190 | + MemPage *pPage = pCur->pPage; /* Btree page of current entry */ |
| 64113 | 64191 | BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */ |
| 64114 | 64192 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 64115 | 64193 | unsigned char * const pBufStart = pBuf; /* Start of original out buffer */ |
| 64116 | 64194 | #endif |
| 64117 | 64195 | |
| | @@ -64303,12 +64381,12 @@ |
| 64303 | 64381 | ** the available payload. |
| 64304 | 64382 | */ |
| 64305 | 64383 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 64306 | 64384 | assert( cursorHoldsMutex(pCur) ); |
| 64307 | 64385 | assert( pCur->eState==CURSOR_VALID ); |
| 64308 | | - assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 64309 | | - assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell ); |
| 64386 | + assert( pCur->iPage>=0 && pCur->pPage ); |
| 64387 | + assert( pCur->ix<pCur->pPage->nCell ); |
| 64310 | 64388 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 64311 | 64389 | } |
| 64312 | 64390 | |
| 64313 | 64391 | /* |
| 64314 | 64392 | ** This variant of sqlite3BtreePayload() works even if the cursor has not |
| | @@ -64362,19 +64440,19 @@ |
| 64362 | 64440 | static const void *fetchPayload( |
| 64363 | 64441 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 64364 | 64442 | u32 *pAmt /* Write the number of available bytes here */ |
| 64365 | 64443 | ){ |
| 64366 | 64444 | u32 amt; |
| 64367 | | - assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 64445 | + assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage); |
| 64368 | 64446 | assert( pCur->eState==CURSOR_VALID ); |
| 64369 | 64447 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 64370 | 64448 | assert( cursorOwnsBtShared(pCur) ); |
| 64371 | | - assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell ); |
| 64449 | + assert( pCur->ix<pCur->pPage->nCell ); |
| 64372 | 64450 | assert( pCur->info.nSize>0 ); |
| 64373 | | - assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB ); |
| 64374 | | - assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB); |
| 64375 | | - amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload); |
| 64451 | + assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB ); |
| 64452 | + assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB); |
| 64453 | + amt = (int)(pCur->pPage->aDataEnd - pCur->info.pPayload); |
| 64376 | 64454 | if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal; |
| 64377 | 64455 | *pAmt = amt; |
| 64378 | 64456 | return (void*)pCur->info.pPayload; |
| 64379 | 64457 | } |
| 64380 | 64458 | |
| | @@ -64417,14 +64495,15 @@ |
| 64417 | 64495 | if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){ |
| 64418 | 64496 | return SQLITE_CORRUPT_BKPT; |
| 64419 | 64497 | } |
| 64420 | 64498 | pCur->info.nSize = 0; |
| 64421 | 64499 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 64422 | | - pCur->aiIdx[pCur->iPage++] = pCur->ix; |
| 64500 | + pCur->aiIdx[pCur->iPage] = pCur->ix; |
| 64501 | + pCur->apPage[pCur->iPage] = pCur->pPage; |
| 64423 | 64502 | pCur->ix = 0; |
| 64424 | | - return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage], |
| 64425 | | - pCur, pCur->curPagerFlags); |
| 64503 | + pCur->iPage++; |
| 64504 | + return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags); |
| 64426 | 64505 | } |
| 64427 | 64506 | |
| 64428 | 64507 | #ifdef SQLITE_DEBUG |
| 64429 | 64508 | /* |
| 64430 | 64509 | ** Page pParent is an internal (non-leaf) tree page. This function |
| | @@ -64454,24 +64533,27 @@ |
| 64454 | 64533 | ** to the page we are coming from. If we are coming from the |
| 64455 | 64534 | ** right-most child page then pCur->idx is set to one more than |
| 64456 | 64535 | ** the largest cell index. |
| 64457 | 64536 | */ |
| 64458 | 64537 | static void moveToParent(BtCursor *pCur){ |
| 64538 | + MemPage *pLeaf; |
| 64459 | 64539 | assert( cursorOwnsBtShared(pCur) ); |
| 64460 | 64540 | assert( pCur->eState==CURSOR_VALID ); |
| 64461 | 64541 | assert( pCur->iPage>0 ); |
| 64462 | | - assert( pCur->apPage[pCur->iPage] ); |
| 64542 | + assert( pCur->pPage ); |
| 64463 | 64543 | assertParentIndex( |
| 64464 | 64544 | pCur->apPage[pCur->iPage-1], |
| 64465 | 64545 | pCur->aiIdx[pCur->iPage-1], |
| 64466 | | - pCur->apPage[pCur->iPage]->pgno |
| 64546 | + pCur->pPage->pgno |
| 64467 | 64547 | ); |
| 64468 | 64548 | testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell ); |
| 64469 | 64549 | pCur->info.nSize = 0; |
| 64470 | 64550 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 64471 | 64551 | pCur->ix = pCur->aiIdx[pCur->iPage-1]; |
| 64472 | | - releasePageNotNull(pCur->apPage[pCur->iPage--]); |
| 64552 | + pLeaf = pCur->pPage; |
| 64553 | + pCur->pPage = pCur->apPage[--pCur->iPage]; |
| 64554 | + releasePageNotNull(pLeaf); |
| 64473 | 64555 | } |
| 64474 | 64556 | |
| 64475 | 64557 | /* |
| 64476 | 64558 | ** Move the cursor to point to the root page of its b-tree structure. |
| 64477 | 64559 | ** |
| | @@ -64479,13 +64561,13 @@ |
| 64479 | 64561 | ** to the virtual root page instead of the actual root page. A table has a |
| 64480 | 64562 | ** virtual root page when the actual root page contains no cells and a |
| 64481 | 64563 | ** single child page. This can only happen with the table rooted at page 1. |
| 64482 | 64564 | ** |
| 64483 | 64565 | ** If the b-tree structure is empty, the cursor state is set to |
| 64484 | | -** CURSOR_INVALID. Otherwise, the cursor is set to point to the first |
| 64485 | | -** cell located on the root (or virtual root) page and the cursor state |
| 64486 | | -** is set to CURSOR_VALID. |
| 64566 | +** CURSOR_INVALID and this routine returns SQLITE_EMPTY. Otherwise, |
| 64567 | +** the cursor is set to point to the first cell located on the root |
| 64568 | +** (or virtual root) page and the cursor state is set to CURSOR_VALID. |
| 64487 | 64569 | ** |
| 64488 | 64570 | ** If this function returns successfully, it may be assumed that the |
| 64489 | 64571 | ** page-header flags indicate that the [virtual] root-page is the expected |
| 64490 | 64572 | ** kind of b-tree page (i.e. if when opening the cursor the caller did not |
| 64491 | 64573 | ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D, |
| | @@ -64499,41 +64581,44 @@ |
| 64499 | 64581 | |
| 64500 | 64582 | assert( cursorOwnsBtShared(pCur) ); |
| 64501 | 64583 | assert( CURSOR_INVALID < CURSOR_REQUIRESEEK ); |
| 64502 | 64584 | assert( CURSOR_VALID < CURSOR_REQUIRESEEK ); |
| 64503 | 64585 | assert( CURSOR_FAULT > CURSOR_REQUIRESEEK ); |
| 64504 | | - if( pCur->eState>=CURSOR_REQUIRESEEK ){ |
| 64505 | | - if( pCur->eState==CURSOR_FAULT ){ |
| 64506 | | - assert( pCur->skipNext!=SQLITE_OK ); |
| 64507 | | - return pCur->skipNext; |
| 64508 | | - } |
| 64509 | | - sqlite3BtreeClearCursor(pCur); |
| 64510 | | - } |
| 64586 | + assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 ); |
| 64587 | + assert( pCur->pgnoRoot>0 || pCur->iPage<0 ); |
| 64511 | 64588 | |
| 64512 | 64589 | if( pCur->iPage>=0 ){ |
| 64513 | 64590 | if( pCur->iPage ){ |
| 64514 | | - do{ |
| 64515 | | - assert( pCur->apPage[pCur->iPage]!=0 ); |
| 64516 | | - releasePageNotNull(pCur->apPage[pCur->iPage--]); |
| 64517 | | - }while( pCur->iPage); |
| 64591 | + releasePageNotNull(pCur->pPage); |
| 64592 | + while( --pCur->iPage ){ |
| 64593 | + releasePageNotNull(pCur->apPage[pCur->iPage]); |
| 64594 | + } |
| 64595 | + pCur->pPage = pCur->apPage[0]; |
| 64518 | 64596 | goto skip_init; |
| 64519 | 64597 | } |
| 64520 | 64598 | }else if( pCur->pgnoRoot==0 ){ |
| 64521 | 64599 | pCur->eState = CURSOR_INVALID; |
| 64522 | | - return SQLITE_OK; |
| 64600 | + return SQLITE_EMPTY; |
| 64523 | 64601 | }else{ |
| 64524 | 64602 | assert( pCur->iPage==(-1) ); |
| 64525 | | - rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 64603 | + if( pCur->eState>=CURSOR_REQUIRESEEK ){ |
| 64604 | + if( pCur->eState==CURSOR_FAULT ){ |
| 64605 | + assert( pCur->skipNext!=SQLITE_OK ); |
| 64606 | + return pCur->skipNext; |
| 64607 | + } |
| 64608 | + sqlite3BtreeClearCursor(pCur); |
| 64609 | + } |
| 64610 | + rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage, |
| 64526 | 64611 | 0, pCur->curPagerFlags); |
| 64527 | 64612 | if( rc!=SQLITE_OK ){ |
| 64528 | 64613 | pCur->eState = CURSOR_INVALID; |
| 64529 | | - return rc; |
| 64614 | + return rc; |
| 64530 | 64615 | } |
| 64531 | 64616 | pCur->iPage = 0; |
| 64532 | | - pCur->curIntKey = pCur->apPage[0]->intKey; |
| 64617 | + pCur->curIntKey = pCur->pPage->intKey; |
| 64533 | 64618 | } |
| 64534 | | - pRoot = pCur->apPage[0]; |
| 64619 | + pRoot = pCur->pPage; |
| 64535 | 64620 | assert( pRoot->pgno==pCur->pgnoRoot ); |
| 64536 | 64621 | |
| 64537 | 64622 | /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor |
| 64538 | 64623 | ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is |
| 64539 | 64624 | ** NULL, the caller expects a table b-tree. If this is not the case, |
| | @@ -64544,19 +64629,19 @@ |
| 64544 | 64629 | ** if pCur->iPage>=0). But this is not so if the database is corrupted |
| 64545 | 64630 | ** in such a way that page pRoot is linked into a second b-tree table |
| 64546 | 64631 | ** (or the freelist). */ |
| 64547 | 64632 | assert( pRoot->intKey==1 || pRoot->intKey==0 ); |
| 64548 | 64633 | if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ |
| 64549 | | - return SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno); |
| 64634 | + return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno); |
| 64550 | 64635 | } |
| 64551 | 64636 | |
| 64552 | 64637 | skip_init: |
| 64553 | 64638 | pCur->ix = 0; |
| 64554 | 64639 | pCur->info.nSize = 0; |
| 64555 | 64640 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl); |
| 64556 | 64641 | |
| 64557 | | - pRoot = pCur->apPage[0]; |
| 64642 | + pRoot = pCur->pPage; |
| 64558 | 64643 | if( pRoot->nCell>0 ){ |
| 64559 | 64644 | pCur->eState = CURSOR_VALID; |
| 64560 | 64645 | }else if( !pRoot->leaf ){ |
| 64561 | 64646 | Pgno subpage; |
| 64562 | 64647 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| | @@ -64563,10 +64648,11 @@ |
| 64563 | 64648 | subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]); |
| 64564 | 64649 | pCur->eState = CURSOR_VALID; |
| 64565 | 64650 | rc = moveToChild(pCur, subpage); |
| 64566 | 64651 | }else{ |
| 64567 | 64652 | pCur->eState = CURSOR_INVALID; |
| 64653 | + rc = SQLITE_EMPTY; |
| 64568 | 64654 | } |
| 64569 | 64655 | return rc; |
| 64570 | 64656 | } |
| 64571 | 64657 | |
| 64572 | 64658 | /* |
| | @@ -64581,11 +64667,11 @@ |
| 64581 | 64667 | int rc = SQLITE_OK; |
| 64582 | 64668 | MemPage *pPage; |
| 64583 | 64669 | |
| 64584 | 64670 | assert( cursorOwnsBtShared(pCur) ); |
| 64585 | 64671 | assert( pCur->eState==CURSOR_VALID ); |
| 64586 | | - while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){ |
| 64672 | + while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){ |
| 64587 | 64673 | assert( pCur->ix<pPage->nCell ); |
| 64588 | 64674 | pgno = get4byte(findCell(pPage, pCur->ix)); |
| 64589 | 64675 | rc = moveToChild(pCur, pgno); |
| 64590 | 64676 | } |
| 64591 | 64677 | return rc; |
| | @@ -64606,11 +64692,11 @@ |
| 64606 | 64692 | int rc = SQLITE_OK; |
| 64607 | 64693 | MemPage *pPage = 0; |
| 64608 | 64694 | |
| 64609 | 64695 | assert( cursorOwnsBtShared(pCur) ); |
| 64610 | 64696 | assert( pCur->eState==CURSOR_VALID ); |
| 64611 | | - while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){ |
| 64697 | + while( !(pPage = pCur->pPage)->leaf ){ |
| 64612 | 64698 | pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]); |
| 64613 | 64699 | pCur->ix = pPage->nCell; |
| 64614 | 64700 | rc = moveToChild(pCur, pgno); |
| 64615 | 64701 | if( rc ) return rc; |
| 64616 | 64702 | } |
| | @@ -64629,18 +64715,17 @@ |
| 64629 | 64715 | |
| 64630 | 64716 | assert( cursorOwnsBtShared(pCur) ); |
| 64631 | 64717 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 64632 | 64718 | rc = moveToRoot(pCur); |
| 64633 | 64719 | if( rc==SQLITE_OK ){ |
| 64634 | | - if( pCur->eState==CURSOR_INVALID ){ |
| 64635 | | - assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 64636 | | - *pRes = 1; |
| 64637 | | - }else{ |
| 64638 | | - assert( pCur->apPage[pCur->iPage]->nCell>0 ); |
| 64639 | | - *pRes = 0; |
| 64640 | | - rc = moveToLeftmost(pCur); |
| 64641 | | - } |
| 64720 | + assert( pCur->pPage->nCell>0 ); |
| 64721 | + *pRes = 0; |
| 64722 | + rc = moveToLeftmost(pCur); |
| 64723 | + }else if( rc==SQLITE_EMPTY ){ |
| 64724 | + assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| 64725 | + *pRes = 1; |
| 64726 | + rc = SQLITE_OK; |
| 64642 | 64727 | } |
| 64643 | 64728 | return rc; |
| 64644 | 64729 | } |
| 64645 | 64730 | |
| 64646 | 64731 | /* Move the cursor to the last entry in the table. Return SQLITE_OK |
| | @@ -64660,32 +64745,30 @@ |
| 64660 | 64745 | ** to the last entry in the b-tree. */ |
| 64661 | 64746 | int ii; |
| 64662 | 64747 | for(ii=0; ii<pCur->iPage; ii++){ |
| 64663 | 64748 | assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell ); |
| 64664 | 64749 | } |
| 64665 | | - assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 ); |
| 64666 | | - assert( pCur->apPage[pCur->iPage]->leaf ); |
| 64750 | + assert( pCur->ix==pCur->pPage->nCell-1 ); |
| 64751 | + assert( pCur->pPage->leaf ); |
| 64667 | 64752 | #endif |
| 64668 | 64753 | return SQLITE_OK; |
| 64669 | 64754 | } |
| 64670 | 64755 | |
| 64671 | 64756 | rc = moveToRoot(pCur); |
| 64672 | 64757 | if( rc==SQLITE_OK ){ |
| 64673 | | - if( CURSOR_INVALID==pCur->eState ){ |
| 64674 | | - assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 64675 | | - *pRes = 1; |
| 64676 | | - }else{ |
| 64677 | | - assert( pCur->eState==CURSOR_VALID ); |
| 64678 | | - *pRes = 0; |
| 64679 | | - rc = moveToRightmost(pCur); |
| 64680 | | - if( rc==SQLITE_OK ){ |
| 64681 | | - pCur->curFlags |= BTCF_AtLast; |
| 64682 | | - }else{ |
| 64683 | | - pCur->curFlags &= ~BTCF_AtLast; |
| 64684 | | - } |
| 64685 | | - |
| 64686 | | - } |
| 64758 | + assert( pCur->eState==CURSOR_VALID ); |
| 64759 | + *pRes = 0; |
| 64760 | + rc = moveToRightmost(pCur); |
| 64761 | + if( rc==SQLITE_OK ){ |
| 64762 | + pCur->curFlags |= BTCF_AtLast; |
| 64763 | + }else{ |
| 64764 | + pCur->curFlags &= ~BTCF_AtLast; |
| 64765 | + } |
| 64766 | + }else if( rc==SQLITE_EMPTY ){ |
| 64767 | + assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| 64768 | + *pRes = 1; |
| 64769 | + rc = SQLITE_OK; |
| 64687 | 64770 | } |
| 64688 | 64771 | return rc; |
| 64689 | 64772 | } |
| 64690 | 64773 | |
| 64691 | 64774 | /* Move the cursor so that it points to an entry near the key |
| | @@ -64780,26 +64863,27 @@ |
| 64780 | 64863 | xRecordCompare = 0; /* All keys are integers */ |
| 64781 | 64864 | } |
| 64782 | 64865 | |
| 64783 | 64866 | rc = moveToRoot(pCur); |
| 64784 | 64867 | if( rc ){ |
| 64868 | + if( rc==SQLITE_EMPTY ){ |
| 64869 | + assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| 64870 | + *pRes = -1; |
| 64871 | + return SQLITE_OK; |
| 64872 | + } |
| 64785 | 64873 | return rc; |
| 64786 | 64874 | } |
| 64787 | | - assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] ); |
| 64788 | | - assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit ); |
| 64789 | | - assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 ); |
| 64790 | | - if( pCur->eState==CURSOR_INVALID ){ |
| 64791 | | - *pRes = -1; |
| 64792 | | - assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 ); |
| 64793 | | - return SQLITE_OK; |
| 64794 | | - } |
| 64795 | | - assert( pCur->apPage[0]->intKey==pCur->curIntKey ); |
| 64875 | + assert( pCur->pPage ); |
| 64876 | + assert( pCur->pPage->isInit ); |
| 64877 | + assert( pCur->eState==CURSOR_VALID ); |
| 64878 | + assert( pCur->pPage->nCell > 0 ); |
| 64879 | + assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); |
| 64796 | 64880 | assert( pCur->curIntKey || pIdxKey ); |
| 64797 | 64881 | for(;;){ |
| 64798 | 64882 | int lwr, upr, idx, c; |
| 64799 | 64883 | Pgno chldPg; |
| 64800 | | - MemPage *pPage = pCur->apPage[pCur->iPage]; |
| 64884 | + MemPage *pPage = pCur->pPage; |
| 64801 | 64885 | u8 *pCell; /* Pointer to current cell in pPage */ |
| 64802 | 64886 | |
| 64803 | 64887 | /* pPage->nCell must be greater than zero. If this is the root-page |
| 64804 | 64888 | ** the cursor would have been INVALID above and this for(;;) loop |
| 64805 | 64889 | ** not run. If this is not the root-page, then the moveToChild() routine |
| | @@ -64923,11 +65007,11 @@ |
| 64923 | 65007 | }else{ |
| 64924 | 65008 | assert( c==0 ); |
| 64925 | 65009 | *pRes = 0; |
| 64926 | 65010 | rc = SQLITE_OK; |
| 64927 | 65011 | pCur->ix = (u16)idx; |
| 64928 | | - if( pIdxKey->errCode ) rc = SQLITE_CORRUPT; |
| 65012 | + if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT; |
| 64929 | 65013 | goto moveto_finish; |
| 64930 | 65014 | } |
| 64931 | 65015 | if( lwr>upr ) break; |
| 64932 | 65016 | assert( lwr+upr>=0 ); |
| 64933 | 65017 | idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */ |
| | @@ -64934,11 +65018,11 @@ |
| 64934 | 65018 | } |
| 64935 | 65019 | } |
| 64936 | 65020 | assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) ); |
| 64937 | 65021 | assert( pPage->isInit ); |
| 64938 | 65022 | if( pPage->leaf ){ |
| 64939 | | - assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell ); |
| 65023 | + assert( pCur->ix<pCur->pPage->nCell ); |
| 64940 | 65024 | pCur->ix = (u16)idx; |
| 64941 | 65025 | *pRes = c; |
| 64942 | 65026 | rc = SQLITE_OK; |
| 64943 | 65027 | goto moveto_finish; |
| 64944 | 65028 | } |
| | @@ -64988,13 +65072,14 @@ |
| 64988 | 65072 | |
| 64989 | 65073 | /* Currently this interface is only called by the OP_IfSmaller |
| 64990 | 65074 | ** opcode, and it that case the cursor will always be valid and |
| 64991 | 65075 | ** will always point to a leaf node. */ |
| 64992 | 65076 | if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1; |
| 64993 | | - if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1; |
| 65077 | + if( NEVER(pCur->pPage->leaf==0) ) return -1; |
| 64994 | 65078 | |
| 64995 | | - for(n=1, i=0; i<=pCur->iPage; i++){ |
| 65079 | + n = pCur->pPage->nCell; |
| 65080 | + for(i=0; i<pCur->iPage; i++){ |
| 64996 | 65081 | n *= pCur->apPage[i]->nCell; |
| 64997 | 65082 | } |
| 64998 | 65083 | return n; |
| 64999 | 65084 | } |
| 65000 | 65085 | |
| | @@ -65043,11 +65128,11 @@ |
| 65043 | 65128 | } |
| 65044 | 65129 | pCur->skipNext = 0; |
| 65045 | 65130 | } |
| 65046 | 65131 | } |
| 65047 | 65132 | |
| 65048 | | - pPage = pCur->apPage[pCur->iPage]; |
| 65133 | + pPage = pCur->pPage; |
| 65049 | 65134 | idx = ++pCur->ix; |
| 65050 | 65135 | assert( pPage->isInit ); |
| 65051 | 65136 | |
| 65052 | 65137 | /* If the database file is corrupt, it is possible for the value of idx |
| 65053 | 65138 | ** to be invalid here. This can only occur if a second cursor modifies |
| | @@ -65066,11 +65151,11 @@ |
| 65066 | 65151 | if( pCur->iPage==0 ){ |
| 65067 | 65152 | pCur->eState = CURSOR_INVALID; |
| 65068 | 65153 | return SQLITE_DONE; |
| 65069 | 65154 | } |
| 65070 | 65155 | moveToParent(pCur); |
| 65071 | | - pPage = pCur->apPage[pCur->iPage]; |
| 65156 | + pPage = pCur->pPage; |
| 65072 | 65157 | }while( pCur->ix>=pPage->nCell ); |
| 65073 | 65158 | if( pPage->intKey ){ |
| 65074 | 65159 | return sqlite3BtreeNext(pCur, 0); |
| 65075 | 65160 | }else{ |
| 65076 | 65161 | return SQLITE_OK; |
| | @@ -65089,11 +65174,11 @@ |
| 65089 | 65174 | assert( flags==0 || flags==1 ); |
| 65090 | 65175 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 65091 | 65176 | pCur->info.nSize = 0; |
| 65092 | 65177 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 65093 | 65178 | if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur); |
| 65094 | | - pPage = pCur->apPage[pCur->iPage]; |
| 65179 | + pPage = pCur->pPage; |
| 65095 | 65180 | if( (++pCur->ix)>=pPage->nCell ){ |
| 65096 | 65181 | pCur->ix--; |
| 65097 | 65182 | return btreeNext(pCur); |
| 65098 | 65183 | } |
| 65099 | 65184 | if( pPage->leaf ){ |
| | @@ -65148,11 +65233,11 @@ |
| 65148 | 65233 | } |
| 65149 | 65234 | pCur->skipNext = 0; |
| 65150 | 65235 | } |
| 65151 | 65236 | } |
| 65152 | 65237 | |
| 65153 | | - pPage = pCur->apPage[pCur->iPage]; |
| 65238 | + pPage = pCur->pPage; |
| 65154 | 65239 | assert( pPage->isInit ); |
| 65155 | 65240 | if( !pPage->leaf ){ |
| 65156 | 65241 | int idx = pCur->ix; |
| 65157 | 65242 | rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); |
| 65158 | 65243 | if( rc ) return rc; |
| | @@ -65167,11 +65252,11 @@ |
| 65167 | 65252 | } |
| 65168 | 65253 | assert( pCur->info.nSize==0 ); |
| 65169 | 65254 | assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 ); |
| 65170 | 65255 | |
| 65171 | 65256 | pCur->ix--; |
| 65172 | | - pPage = pCur->apPage[pCur->iPage]; |
| 65257 | + pPage = pCur->pPage; |
| 65173 | 65258 | if( pPage->intKey && !pPage->leaf ){ |
| 65174 | 65259 | rc = sqlite3BtreePrevious(pCur, 0); |
| 65175 | 65260 | }else{ |
| 65176 | 65261 | rc = SQLITE_OK; |
| 65177 | 65262 | } |
| | @@ -65185,11 +65270,11 @@ |
| 65185 | 65270 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 65186 | 65271 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey); |
| 65187 | 65272 | pCur->info.nSize = 0; |
| 65188 | 65273 | if( pCur->eState!=CURSOR_VALID |
| 65189 | 65274 | || pCur->ix==0 |
| 65190 | | - || pCur->apPage[pCur->iPage]->leaf==0 |
| 65275 | + || pCur->pPage->leaf==0 |
| 65191 | 65276 | ){ |
| 65192 | 65277 | return btreePrevious(pCur); |
| 65193 | 65278 | } |
| 65194 | 65279 | pCur->ix--; |
| 65195 | 65280 | return SQLITE_OK; |
| | @@ -65681,11 +65766,11 @@ |
| 65681 | 65766 | static int clearCell( |
| 65682 | 65767 | MemPage *pPage, /* The page that contains the Cell */ |
| 65683 | 65768 | unsigned char *pCell, /* First byte of the Cell */ |
| 65684 | 65769 | CellInfo *pInfo /* Size information about the cell */ |
| 65685 | 65770 | ){ |
| 65686 | | - BtShared *pBt = pPage->pBt; |
| 65771 | + BtShared *pBt; |
| 65687 | 65772 | Pgno ovflPgno; |
| 65688 | 65773 | int rc; |
| 65689 | 65774 | int nOvfl; |
| 65690 | 65775 | u32 ovflPageSize; |
| 65691 | 65776 | |
| | @@ -65697,10 +65782,11 @@ |
| 65697 | 65782 | if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){ |
| 65698 | 65783 | /* Cell extends past end of page */ |
| 65699 | 65784 | return SQLITE_CORRUPT_PGNO(pPage->pgno); |
| 65700 | 65785 | } |
| 65701 | 65786 | ovflPgno = get4byte(pCell + pInfo->nSize - 4); |
| 65787 | + pBt = pPage->pBt; |
| 65702 | 65788 | assert( pBt->usableSize > 4 ); |
| 65703 | 65789 | ovflPageSize = pBt->usableSize - 4; |
| 65704 | 65790 | nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize; |
| 65705 | 65791 | assert( nOvfl>0 || |
| 65706 | 65792 | (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize) |
| | @@ -65764,25 +65850,24 @@ |
| 65764 | 65850 | const BtreePayload *pX, /* Payload with which to construct the cell */ |
| 65765 | 65851 | int *pnSize /* Write cell size here */ |
| 65766 | 65852 | ){ |
| 65767 | 65853 | int nPayload; |
| 65768 | 65854 | const u8 *pSrc; |
| 65769 | | - int nSrc, n, rc; |
| 65855 | + int nSrc, n, rc, mn; |
| 65770 | 65856 | int spaceLeft; |
| 65771 | | - MemPage *pOvfl = 0; |
| 65772 | | - MemPage *pToRelease = 0; |
| 65857 | + MemPage *pToRelease; |
| 65773 | 65858 | unsigned char *pPrior; |
| 65774 | 65859 | unsigned char *pPayload; |
| 65775 | | - BtShared *pBt = pPage->pBt; |
| 65776 | | - Pgno pgnoOvfl = 0; |
| 65860 | + BtShared *pBt; |
| 65861 | + Pgno pgnoOvfl; |
| 65777 | 65862 | int nHeader; |
| 65778 | 65863 | |
| 65779 | 65864 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 65780 | 65865 | |
| 65781 | 65866 | /* pPage is not necessarily writeable since pCell might be auxiliary |
| 65782 | 65867 | ** buffer space that is separate from the pPage buffer area */ |
| 65783 | | - assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize] |
| 65868 | + assert( pCell<pPage->aData || pCell>=&pPage->aData[pPage->pBt->pageSize] |
| 65784 | 65869 | || sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 65785 | 65870 | |
| 65786 | 65871 | /* Fill in the header. */ |
| 65787 | 65872 | nHeader = pPage->childPtrSize; |
| 65788 | 65873 | if( pPage->intKey ){ |
| | @@ -65798,29 +65883,40 @@ |
| 65798 | 65883 | pSrc = pX->pKey; |
| 65799 | 65884 | nHeader += putVarint32(&pCell[nHeader], nPayload); |
| 65800 | 65885 | } |
| 65801 | 65886 | |
| 65802 | 65887 | /* Fill in the payload */ |
| 65888 | + pPayload = &pCell[nHeader]; |
| 65803 | 65889 | if( nPayload<=pPage->maxLocal ){ |
| 65890 | + /* This is the common case where everything fits on the btree page |
| 65891 | + ** and no overflow pages are required. */ |
| 65804 | 65892 | n = nHeader + nPayload; |
| 65805 | 65893 | testcase( n==3 ); |
| 65806 | 65894 | testcase( n==4 ); |
| 65807 | 65895 | if( n<4 ) n = 4; |
| 65808 | 65896 | *pnSize = n; |
| 65809 | | - spaceLeft = nPayload; |
| 65810 | | - pPrior = pCell; |
| 65811 | | - }else{ |
| 65812 | | - int mn = pPage->minLocal; |
| 65813 | | - n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4); |
| 65814 | | - testcase( n==pPage->maxLocal ); |
| 65815 | | - testcase( n==pPage->maxLocal+1 ); |
| 65816 | | - if( n > pPage->maxLocal ) n = mn; |
| 65817 | | - spaceLeft = n; |
| 65818 | | - *pnSize = n + nHeader + 4; |
| 65819 | | - pPrior = &pCell[nHeader+n]; |
| 65820 | | - } |
| 65821 | | - pPayload = &pCell[nHeader]; |
| 65897 | + assert( nSrc<=nPayload ); |
| 65898 | + testcase( nSrc<nPayload ); |
| 65899 | + memcpy(pPayload, pSrc, nSrc); |
| 65900 | + memset(pPayload+nSrc, 0, nPayload-nSrc); |
| 65901 | + return SQLITE_OK; |
| 65902 | + } |
| 65903 | + |
| 65904 | + /* If we reach this point, it means that some of the content will need |
| 65905 | + ** to spill onto overflow pages. |
| 65906 | + */ |
| 65907 | + mn = pPage->minLocal; |
| 65908 | + n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4); |
| 65909 | + testcase( n==pPage->maxLocal ); |
| 65910 | + testcase( n==pPage->maxLocal+1 ); |
| 65911 | + if( n > pPage->maxLocal ) n = mn; |
| 65912 | + spaceLeft = n; |
| 65913 | + *pnSize = n + nHeader + 4; |
| 65914 | + pPrior = &pCell[nHeader+n]; |
| 65915 | + pToRelease = 0; |
| 65916 | + pgnoOvfl = 0; |
| 65917 | + pBt = pPage->pBt; |
| 65822 | 65918 | |
| 65823 | 65919 | /* At this point variables should be set as follows: |
| 65824 | 65920 | ** |
| 65825 | 65921 | ** nPayload Total payload size in bytes |
| 65826 | 65922 | ** pPayload Begin writing payload here |
| | @@ -65842,12 +65938,39 @@ |
| 65842 | 65938 | assert( spaceLeft == info.nLocal ); |
| 65843 | 65939 | } |
| 65844 | 65940 | #endif |
| 65845 | 65941 | |
| 65846 | 65942 | /* Write the payload into the local Cell and any extra into overflow pages */ |
| 65847 | | - while( nPayload>0 ){ |
| 65943 | + while( 1 ){ |
| 65944 | + n = nPayload; |
| 65945 | + if( n>spaceLeft ) n = spaceLeft; |
| 65946 | + |
| 65947 | + /* If pToRelease is not zero than pPayload points into the data area |
| 65948 | + ** of pToRelease. Make sure pToRelease is still writeable. */ |
| 65949 | + assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) ); |
| 65950 | + |
| 65951 | + /* If pPayload is part of the data area of pPage, then make sure pPage |
| 65952 | + ** is still writeable */ |
| 65953 | + assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize] |
| 65954 | + || sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 65955 | + |
| 65956 | + if( nSrc>=n ){ |
| 65957 | + memcpy(pPayload, pSrc, n); |
| 65958 | + }else if( nSrc>0 ){ |
| 65959 | + n = nSrc; |
| 65960 | + memcpy(pPayload, pSrc, n); |
| 65961 | + }else{ |
| 65962 | + memset(pPayload, 0, n); |
| 65963 | + } |
| 65964 | + nPayload -= n; |
| 65965 | + if( nPayload<=0 ) break; |
| 65966 | + pPayload += n; |
| 65967 | + pSrc += n; |
| 65968 | + nSrc -= n; |
| 65969 | + spaceLeft -= n; |
| 65848 | 65970 | if( spaceLeft==0 ){ |
| 65971 | + MemPage *pOvfl = 0; |
| 65849 | 65972 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 65850 | 65973 | Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */ |
| 65851 | 65974 | if( pBt->autoVacuum ){ |
| 65852 | 65975 | do{ |
| 65853 | 65976 | pgnoOvfl++; |
| | @@ -65896,34 +66019,10 @@ |
| 65896 | 66019 | pPrior = pOvfl->aData; |
| 65897 | 66020 | put4byte(pPrior, 0); |
| 65898 | 66021 | pPayload = &pOvfl->aData[4]; |
| 65899 | 66022 | spaceLeft = pBt->usableSize - 4; |
| 65900 | 66023 | } |
| 65901 | | - n = nPayload; |
| 65902 | | - if( n>spaceLeft ) n = spaceLeft; |
| 65903 | | - |
| 65904 | | - /* If pToRelease is not zero than pPayload points into the data area |
| 65905 | | - ** of pToRelease. Make sure pToRelease is still writeable. */ |
| 65906 | | - assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) ); |
| 65907 | | - |
| 65908 | | - /* If pPayload is part of the data area of pPage, then make sure pPage |
| 65909 | | - ** is still writeable */ |
| 65910 | | - assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize] |
| 65911 | | - || sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 65912 | | - |
| 65913 | | - if( nSrc>0 ){ |
| 65914 | | - if( n>nSrc ) n = nSrc; |
| 65915 | | - assert( pSrc ); |
| 65916 | | - memcpy(pPayload, pSrc, n); |
| 65917 | | - }else{ |
| 65918 | | - memset(pPayload, 0, n); |
| 65919 | | - } |
| 65920 | | - nPayload -= n; |
| 65921 | | - pPayload += n; |
| 65922 | | - pSrc += n; |
| 65923 | | - nSrc -= n; |
| 65924 | | - spaceLeft -= n; |
| 65925 | 66024 | } |
| 65926 | 66025 | releasePage(pToRelease); |
| 65927 | 66026 | return SQLITE_OK; |
| 65928 | 66027 | } |
| 65929 | 66028 | |
| | @@ -65951,11 +66050,11 @@ |
| 65951 | 66050 | ptr = &pPage->aCellIdx[2*idx]; |
| 65952 | 66051 | pc = get2byte(ptr); |
| 65953 | 66052 | hdr = pPage->hdrOffset; |
| 65954 | 66053 | testcase( pc==get2byte(&data[hdr+5]) ); |
| 65955 | 66054 | testcase( pc+sz==pPage->pBt->usableSize ); |
| 65956 | | - if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){ |
| 66055 | + if( pc+sz > pPage->pBt->usableSize ){ |
| 65957 | 66056 | *pRC = SQLITE_CORRUPT_BKPT; |
| 65958 | 66057 | return; |
| 65959 | 66058 | } |
| 65960 | 66059 | rc = freeSpace(pPage, pc, sz); |
| 65961 | 66060 | if( rc ){ |
| | @@ -66821,11 +66920,11 @@ |
| 66821 | 66920 | + pBt->pageSize; /* aSpace1 */ |
| 66822 | 66921 | |
| 66823 | 66922 | /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer |
| 66824 | 66923 | ** that is more than 6 times the database page size. */ |
| 66825 | 66924 | assert( szScratch<=6*(int)pBt->pageSize ); |
| 66826 | | - b.apCell = sqlite3ScratchMalloc( szScratch ); |
| 66925 | + b.apCell = sqlite3StackAllocRaw(0, szScratch ); |
| 66827 | 66926 | if( b.apCell==0 ){ |
| 66828 | 66927 | rc = SQLITE_NOMEM_BKPT; |
| 66829 | 66928 | goto balance_cleanup; |
| 66830 | 66929 | } |
| 66831 | 66930 | b.szCell = (u16*)&b.apCell[nMaxCells]; |
| | @@ -67399,11 +67498,11 @@ |
| 67399 | 67498 | |
| 67400 | 67499 | /* |
| 67401 | 67500 | ** Cleanup before returning. |
| 67402 | 67501 | */ |
| 67403 | 67502 | balance_cleanup: |
| 67404 | | - sqlite3ScratchFree(b.apCell); |
| 67503 | + sqlite3StackFree(0, b.apCell); |
| 67405 | 67504 | for(i=0; i<nOld; i++){ |
| 67406 | 67505 | releasePage(apOld[i]); |
| 67407 | 67506 | } |
| 67408 | 67507 | for(i=0; i<nNew; i++){ |
| 67409 | 67508 | releasePage(apNew[i]); |
| | @@ -67498,11 +67597,11 @@ |
| 67498 | 67597 | VVA_ONLY( int balance_quick_called = 0 ); |
| 67499 | 67598 | VVA_ONLY( int balance_deeper_called = 0 ); |
| 67500 | 67599 | |
| 67501 | 67600 | do { |
| 67502 | 67601 | int iPage = pCur->iPage; |
| 67503 | | - MemPage *pPage = pCur->apPage[iPage]; |
| 67602 | + MemPage *pPage = pCur->pPage; |
| 67504 | 67603 | |
| 67505 | 67604 | if( iPage==0 ){ |
| 67506 | 67605 | if( pPage->nOverflow ){ |
| 67507 | 67606 | /* The root page of the b-tree is overfull. In this case call the |
| 67508 | 67607 | ** balance_deeper() function to create a new child for the root-page |
| | @@ -67514,11 +67613,13 @@ |
| 67514 | 67613 | rc = balance_deeper(pPage, &pCur->apPage[1]); |
| 67515 | 67614 | if( rc==SQLITE_OK ){ |
| 67516 | 67615 | pCur->iPage = 1; |
| 67517 | 67616 | pCur->ix = 0; |
| 67518 | 67617 | pCur->aiIdx[0] = 0; |
| 67519 | | - assert( pCur->apPage[1]->nOverflow ); |
| 67618 | + pCur->apPage[0] = pPage; |
| 67619 | + pCur->pPage = pCur->apPage[1]; |
| 67620 | + assert( pCur->pPage->nOverflow ); |
| 67520 | 67621 | } |
| 67521 | 67622 | }else{ |
| 67522 | 67623 | break; |
| 67523 | 67624 | } |
| 67524 | 67625 | }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){ |
| | @@ -67594,10 +67695,11 @@ |
| 67594 | 67695 | |
| 67595 | 67696 | /* The next iteration of the do-loop balances the parent page. */ |
| 67596 | 67697 | releasePage(pPage); |
| 67597 | 67698 | pCur->iPage--; |
| 67598 | 67699 | assert( pCur->iPage>=0 ); |
| 67700 | + pCur->pPage = pCur->apPage[pCur->iPage]; |
| 67599 | 67701 | } |
| 67600 | 67702 | }while( rc==SQLITE_OK ); |
| 67601 | 67703 | |
| 67602 | 67704 | if( pFree ){ |
| 67603 | 67705 | sqlite3PageFree(pFree); |
| | @@ -67725,11 +67827,11 @@ |
| 67725 | 67827 | } |
| 67726 | 67828 | if( rc ) return rc; |
| 67727 | 67829 | } |
| 67728 | 67830 | assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); |
| 67729 | 67831 | |
| 67730 | | - pPage = pCur->apPage[pCur->iPage]; |
| 67832 | + pPage = pCur->pPage; |
| 67731 | 67833 | assert( pPage->intKey || pX->nKey>=0 ); |
| 67732 | 67834 | assert( pPage->leaf || !pPage->intKey ); |
| 67733 | 67835 | |
| 67734 | 67836 | TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n", |
| 67735 | 67837 | pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno, |
| | @@ -67812,14 +67914,14 @@ |
| 67812 | 67914 | |
| 67813 | 67915 | /* Must make sure nOverflow is reset to zero even if the balance() |
| 67814 | 67916 | ** fails. Internal data structure corruption will result otherwise. |
| 67815 | 67917 | ** Also, set the cursor state to invalid. This stops saveCursorPosition() |
| 67816 | 67918 | ** from trying to save the current position of the cursor. */ |
| 67817 | | - pCur->apPage[pCur->iPage]->nOverflow = 0; |
| 67919 | + pCur->pPage->nOverflow = 0; |
| 67818 | 67920 | pCur->eState = CURSOR_INVALID; |
| 67819 | 67921 | if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){ |
| 67820 | | - rc = moveToRoot(pCur); |
| 67922 | + btreeReleaseAllCursorPages(pCur); |
| 67821 | 67923 | if( pCur->pKeyInfo ){ |
| 67822 | 67924 | assert( pCur->pKey==0 ); |
| 67823 | 67925 | pCur->pKey = sqlite3Malloc( pX->nKey ); |
| 67824 | 67926 | if( pCur->pKey==0 ){ |
| 67825 | 67927 | rc = SQLITE_NOMEM; |
| | @@ -67829,11 +67931,11 @@ |
| 67829 | 67931 | } |
| 67830 | 67932 | pCur->eState = CURSOR_REQUIRESEEK; |
| 67831 | 67933 | pCur->nKey = pX->nKey; |
| 67832 | 67934 | } |
| 67833 | 67935 | } |
| 67834 | | - assert( pCur->apPage[pCur->iPage]->nOverflow==0 ); |
| 67936 | + assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 ); |
| 67835 | 67937 | |
| 67836 | 67938 | end_insert: |
| 67837 | 67939 | return rc; |
| 67838 | 67940 | } |
| 67839 | 67941 | |
| | @@ -67870,17 +67972,17 @@ |
| 67870 | 67972 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 67871 | 67973 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 67872 | 67974 | assert( pCur->curFlags & BTCF_WriteFlag ); |
| 67873 | 67975 | assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 67874 | 67976 | assert( !hasReadConflicts(p, pCur->pgnoRoot) ); |
| 67875 | | - assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell ); |
| 67977 | + assert( pCur->ix<pCur->pPage->nCell ); |
| 67876 | 67978 | assert( pCur->eState==CURSOR_VALID ); |
| 67877 | 67979 | assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); |
| 67878 | 67980 | |
| 67879 | 67981 | iCellDepth = pCur->iPage; |
| 67880 | 67982 | iCellIdx = pCur->ix; |
| 67881 | | - pPage = pCur->apPage[iCellDepth]; |
| 67983 | + pPage = pCur->pPage; |
| 67882 | 67984 | pCell = findCell(pPage, iCellIdx); |
| 67883 | 67985 | |
| 67884 | 67986 | /* If the bPreserve flag is set to true, then the cursor position must |
| 67885 | 67987 | ** be preserved following this delete operation. If the current delete |
| 67886 | 67988 | ** will cause a b-tree rebalance, then this is done by saving the cursor |
| | @@ -67942,15 +68044,20 @@ |
| 67942 | 68044 | ** is currently pointing to the largest entry in the sub-tree headed |
| 67943 | 68045 | ** by the child-page of the cell that was just deleted from an internal |
| 67944 | 68046 | ** node. The cell from the leaf node needs to be moved to the internal |
| 67945 | 68047 | ** node to replace the deleted cell. */ |
| 67946 | 68048 | if( !pPage->leaf ){ |
| 67947 | | - MemPage *pLeaf = pCur->apPage[pCur->iPage]; |
| 68049 | + MemPage *pLeaf = pCur->pPage; |
| 67948 | 68050 | int nCell; |
| 67949 | | - Pgno n = pCur->apPage[iCellDepth+1]->pgno; |
| 68051 | + Pgno n; |
| 67950 | 68052 | unsigned char *pTmp; |
| 67951 | 68053 | |
| 68054 | + if( iCellDepth<pCur->iPage-1 ){ |
| 68055 | + n = pCur->apPage[iCellDepth+1]->pgno; |
| 68056 | + }else{ |
| 68057 | + n = pCur->pPage->pgno; |
| 68058 | + } |
| 67952 | 68059 | pCell = findCell(pLeaf, pLeaf->nCell-1); |
| 67953 | 68060 | if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT; |
| 67954 | 68061 | nCell = pLeaf->xCellSize(pLeaf, pCell); |
| 67955 | 68062 | assert( MX_CELL_SIZE(pBt) >= nCell ); |
| 67956 | 68063 | pTmp = pBt->pTmpSpace; |
| | @@ -67978,20 +68085,23 @@ |
| 67978 | 68085 | ** been corrected, so be it. Otherwise, after balancing the leaf node, |
| 67979 | 68086 | ** walk the cursor up the tree to the internal node and balance it as |
| 67980 | 68087 | ** well. */ |
| 67981 | 68088 | rc = balance(pCur); |
| 67982 | 68089 | if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){ |
| 68090 | + releasePageNotNull(pCur->pPage); |
| 68091 | + pCur->iPage--; |
| 67983 | 68092 | while( pCur->iPage>iCellDepth ){ |
| 67984 | 68093 | releasePage(pCur->apPage[pCur->iPage--]); |
| 67985 | 68094 | } |
| 68095 | + pCur->pPage = pCur->apPage[pCur->iPage]; |
| 67986 | 68096 | rc = balance(pCur); |
| 67987 | 68097 | } |
| 67988 | 68098 | |
| 67989 | 68099 | if( rc==SQLITE_OK ){ |
| 67990 | 68100 | if( bSkipnext ){ |
| 67991 | 68101 | assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) ); |
| 67992 | | - assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB ); |
| 68102 | + assert( pPage==pCur->pPage || CORRUPT_DB ); |
| 67993 | 68103 | assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell ); |
| 67994 | 68104 | pCur->eState = CURSOR_SKIPNEXT; |
| 67995 | 68105 | if( iCellIdx>=pPage->nCell ){ |
| 67996 | 68106 | pCur->skipNext = -1; |
| 67997 | 68107 | pCur->ix = pPage->nCell-1; |
| | @@ -67999,12 +68109,14 @@ |
| 67999 | 68109 | pCur->skipNext = 1; |
| 68000 | 68110 | } |
| 68001 | 68111 | }else{ |
| 68002 | 68112 | rc = moveToRoot(pCur); |
| 68003 | 68113 | if( bPreserve ){ |
| 68114 | + btreeReleaseAllCursorPages(pCur); |
| 68004 | 68115 | pCur->eState = CURSOR_REQUIRESEEK; |
| 68005 | 68116 | } |
| 68117 | + if( rc==SQLITE_EMPTY ) rc = SQLITE_OK; |
| 68006 | 68118 | } |
| 68007 | 68119 | } |
| 68008 | 68120 | return rc; |
| 68009 | 68121 | } |
| 68010 | 68122 | |
| | @@ -68465,15 +68577,15 @@ |
| 68465 | 68577 | */ |
| 68466 | 68578 | SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){ |
| 68467 | 68579 | i64 nEntry = 0; /* Value to return in *pnEntry */ |
| 68468 | 68580 | int rc; /* Return code */ |
| 68469 | 68581 | |
| 68470 | | - if( pCur->pgnoRoot==0 ){ |
| 68582 | + rc = moveToRoot(pCur); |
| 68583 | + if( rc==SQLITE_EMPTY ){ |
| 68471 | 68584 | *pnEntry = 0; |
| 68472 | 68585 | return SQLITE_OK; |
| 68473 | 68586 | } |
| 68474 | | - rc = moveToRoot(pCur); |
| 68475 | 68587 | |
| 68476 | 68588 | /* Unless an error occurs, the following loop runs one iteration for each |
| 68477 | 68589 | ** page in the B-Tree structure (not including overflow pages). |
| 68478 | 68590 | */ |
| 68479 | 68591 | while( rc==SQLITE_OK ){ |
| | @@ -68482,11 +68594,11 @@ |
| 68482 | 68594 | |
| 68483 | 68595 | /* If this is a leaf page or the tree is not an int-key tree, then |
| 68484 | 68596 | ** this page contains countable entries. Increment the entry counter |
| 68485 | 68597 | ** accordingly. |
| 68486 | 68598 | */ |
| 68487 | | - pPage = pCur->apPage[pCur->iPage]; |
| 68599 | + pPage = pCur->pPage; |
| 68488 | 68600 | if( pPage->leaf || !pPage->intKey ){ |
| 68489 | 68601 | nEntry += pPage->nCell; |
| 68490 | 68602 | } |
| 68491 | 68603 | |
| 68492 | 68604 | /* pPage is a leaf node. This loop navigates the cursor so that it |
| | @@ -68505,14 +68617,14 @@ |
| 68505 | 68617 | /* All pages of the b-tree have been visited. Return successfully. */ |
| 68506 | 68618 | *pnEntry = nEntry; |
| 68507 | 68619 | return moveToRoot(pCur); |
| 68508 | 68620 | } |
| 68509 | 68621 | moveToParent(pCur); |
| 68510 | | - }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell ); |
| 68622 | + }while ( pCur->ix>=pCur->pPage->nCell ); |
| 68511 | 68623 | |
| 68512 | 68624 | pCur->ix++; |
| 68513 | | - pPage = pCur->apPage[pCur->iPage]; |
| 68625 | + pPage = pCur->pPage; |
| 68514 | 68626 | } |
| 68515 | 68627 | |
| 68516 | 68628 | /* Descend to the child node of the cell that the cursor currently |
| 68517 | 68629 | ** points at. This is the right-child if (iIdx==pPage->nCell). |
| 68518 | 68630 | */ |
| | @@ -69349,11 +69461,11 @@ |
| 69349 | 69461 | } |
| 69350 | 69462 | assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0 |
| 69351 | 69463 | && pCsr->pBt->inTransaction==TRANS_WRITE ); |
| 69352 | 69464 | assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) ); |
| 69353 | 69465 | assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) ); |
| 69354 | | - assert( pCsr->apPage[pCsr->iPage]->intKey ); |
| 69466 | + assert( pCsr->pPage->intKey ); |
| 69355 | 69467 | |
| 69356 | 69468 | return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1); |
| 69357 | 69469 | } |
| 69358 | 69470 | |
| 69359 | 69471 | /* |
| | @@ -70842,18 +70954,25 @@ |
| 70842 | 70954 | ** is a string that does not look completely like a number. Convert |
| 70843 | 70955 | ** as much of the string as we can and ignore the rest. |
| 70844 | 70956 | */ |
| 70845 | 70957 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){ |
| 70846 | 70958 | if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){ |
| 70959 | + int rc; |
| 70847 | 70960 | assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 ); |
| 70848 | 70961 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 70849 | | - if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){ |
| 70962 | + rc = sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc); |
| 70963 | + if( rc==0 ){ |
| 70850 | 70964 | MemSetTypeFlag(pMem, MEM_Int); |
| 70851 | 70965 | }else{ |
| 70852 | | - pMem->u.r = sqlite3VdbeRealValue(pMem); |
| 70853 | | - MemSetTypeFlag(pMem, MEM_Real); |
| 70854 | | - sqlite3VdbeIntegerAffinity(pMem); |
| 70966 | + i64 i = pMem->u.i; |
| 70967 | + sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc); |
| 70968 | + if( rc==1 && pMem->u.r==(double)i ){ |
| 70969 | + pMem->u.i = i; |
| 70970 | + MemSetTypeFlag(pMem, MEM_Int); |
| 70971 | + }else{ |
| 70972 | + MemSetTypeFlag(pMem, MEM_Real); |
| 70973 | + } |
| 70855 | 70974 | } |
| 70856 | 70975 | } |
| 70857 | 70976 | assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 ); |
| 70858 | 70977 | pMem->flags &= ~(MEM_Str|MEM_Blob|MEM_Zero); |
| 70859 | 70978 | return SQLITE_OK; |
| | @@ -71176,11 +71295,11 @@ |
| 71176 | 71295 | } |
| 71177 | 71296 | flags = (enc==0?MEM_Blob:MEM_Str); |
| 71178 | 71297 | if( nByte<0 ){ |
| 71179 | 71298 | assert( enc!=0 ); |
| 71180 | 71299 | if( enc==SQLITE_UTF8 ){ |
| 71181 | | - nByte = sqlite3Strlen30(z); |
| 71300 | + nByte = 0x7fffffff & (int)strlen(z); |
| 71182 | 71301 | if( nByte>iLimit ) nByte = iLimit+1; |
| 71183 | 71302 | }else{ |
| 71184 | 71303 | for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){} |
| 71185 | 71304 | } |
| 71186 | 71305 | flags |= MEM_Term; |
| | @@ -71408,11 +71527,11 @@ |
| 71408 | 71527 | nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord)); |
| 71409 | 71528 | pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte); |
| 71410 | 71529 | if( pRec ){ |
| 71411 | 71530 | pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx); |
| 71412 | 71531 | if( pRec->pKeyInfo ){ |
| 71413 | | - assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol ); |
| 71532 | + assert( pRec->pKeyInfo->nAllField==nCol ); |
| 71414 | 71533 | assert( pRec->pKeyInfo->enc==ENC(db) ); |
| 71415 | 71534 | pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord))); |
| 71416 | 71535 | for(i=0; i<nCol; i++){ |
| 71417 | 71536 | pRec->aMem[i].flags = MEM_Null; |
| 71418 | 71537 | pRec->aMem[i].db = db; |
| | @@ -71944,11 +72063,11 @@ |
| 71944 | 72063 | ** the object. |
| 71945 | 72064 | */ |
| 71946 | 72065 | SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){ |
| 71947 | 72066 | if( pRec ){ |
| 71948 | 72067 | int i; |
| 71949 | | - int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField; |
| 72068 | + int nCol = pRec->pKeyInfo->nAllField; |
| 71950 | 72069 | Mem *aMem = pRec->aMem; |
| 71951 | 72070 | sqlite3 *db = aMem[0].db; |
| 71952 | 72071 | for(i=0; i<nCol; i++){ |
| 71953 | 72072 | sqlite3VdbeMemRelease(&aMem[i]); |
| 71954 | 72073 | } |
| | @@ -72040,14 +72159,16 @@ |
| 72040 | 72159 | p->pNext = db->pVdbe; |
| 72041 | 72160 | p->pPrev = 0; |
| 72042 | 72161 | db->pVdbe = p; |
| 72043 | 72162 | p->magic = VDBE_MAGIC_INIT; |
| 72044 | 72163 | p->pParse = pParse; |
| 72164 | + pParse->pVdbe = p; |
| 72045 | 72165 | assert( pParse->aLabel==0 ); |
| 72046 | 72166 | assert( pParse->nLabel==0 ); |
| 72047 | 72167 | assert( pParse->nOpAlloc==0 ); |
| 72048 | 72168 | assert( pParse->szOpAlloc==0 ); |
| 72169 | + sqlite3VdbeAddOp2(p, OP_Init, 0, 1); |
| 72049 | 72170 | return p; |
| 72050 | 72171 | } |
| 72051 | 72172 | |
| 72052 | 72173 | /* |
| 72053 | 72174 | ** Change the error string stored in Vdbe.zErrMsg |
| | @@ -72497,11 +72618,12 @@ |
| 72497 | 72618 | ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort. |
| 72498 | 72619 | ** * OP_Destroy |
| 72499 | 72620 | ** * OP_VUpdate |
| 72500 | 72621 | ** * OP_VRename |
| 72501 | 72622 | ** * OP_FkCounter with P2==0 (immediate foreign key constraint) |
| 72502 | | -** * OP_CreateTable and OP_InitCoroutine (for CREATE TABLE AS SELECT ...) |
| 72623 | +** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine |
| 72624 | +** (for CREATE TABLE AS SELECT ...) |
| 72503 | 72625 | ** |
| 72504 | 72626 | ** Then check that the value of Parse.mayAbort is true if an |
| 72505 | 72627 | ** ABORT may be thrown, or false otherwise. Return true if it does |
| 72506 | 72628 | ** match, or false otherwise. This function is intended to be used as |
| 72507 | 72629 | ** part of an assert statement in the compiler. Similar to: |
| | @@ -72525,11 +72647,11 @@ |
| 72525 | 72647 | && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 72526 | 72648 | ){ |
| 72527 | 72649 | hasAbort = 1; |
| 72528 | 72650 | break; |
| 72529 | 72651 | } |
| 72530 | | - if( opcode==OP_CreateTable ) hasCreateTable = 1; |
| 72652 | + if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1; |
| 72531 | 72653 | if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1; |
| 72532 | 72654 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 72533 | 72655 | if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){ |
| 72534 | 72656 | hasFkCounter = 1; |
| 72535 | 72657 | } |
| | @@ -72603,10 +72725,31 @@ |
| 72603 | 72725 | case OP_Vacuum: |
| 72604 | 72726 | case OP_JournalMode: { |
| 72605 | 72727 | p->readOnly = 0; |
| 72606 | 72728 | p->bIsReader = 1; |
| 72607 | 72729 | break; |
| 72730 | + } |
| 72731 | + case OP_Next: |
| 72732 | + case OP_NextIfOpen: |
| 72733 | + case OP_SorterNext: { |
| 72734 | + pOp->p4.xAdvance = sqlite3BtreeNext; |
| 72735 | + pOp->p4type = P4_ADVANCE; |
| 72736 | + /* The code generator never codes any of these opcodes as a jump |
| 72737 | + ** to a label. They are always coded as a jump backwards to a |
| 72738 | + ** known address */ |
| 72739 | + assert( pOp->p2>=0 ); |
| 72740 | + break; |
| 72741 | + } |
| 72742 | + case OP_Prev: |
| 72743 | + case OP_PrevIfOpen: { |
| 72744 | + pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 72745 | + pOp->p4type = P4_ADVANCE; |
| 72746 | + /* The code generator never codes any of these opcodes as a jump |
| 72747 | + ** to a label. They are always coded as a jump backwards to a |
| 72748 | + ** known address */ |
| 72749 | + assert( pOp->p2>=0 ); |
| 72750 | + break; |
| 72608 | 72751 | } |
| 72609 | 72752 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 72610 | 72753 | case OP_VUpdate: { |
| 72611 | 72754 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 72612 | 72755 | break; |
| | @@ -72615,31 +72758,29 @@ |
| 72615 | 72758 | int n; |
| 72616 | 72759 | assert( (pOp - p->aOp) >= 3 ); |
| 72617 | 72760 | assert( pOp[-1].opcode==OP_Integer ); |
| 72618 | 72761 | n = pOp[-1].p1; |
| 72619 | 72762 | if( n>nMaxArgs ) nMaxArgs = n; |
| 72620 | | - break; |
| 72763 | + /* Fall through into the default case */ |
| 72621 | 72764 | } |
| 72622 | 72765 | #endif |
| 72623 | | - case OP_Next: |
| 72624 | | - case OP_NextIfOpen: |
| 72625 | | - case OP_SorterNext: { |
| 72626 | | - pOp->p4.xAdvance = sqlite3BtreeNext; |
| 72627 | | - pOp->p4type = P4_ADVANCE; |
| 72628 | | - break; |
| 72629 | | - } |
| 72630 | | - case OP_Prev: |
| 72631 | | - case OP_PrevIfOpen: { |
| 72632 | | - pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 72633 | | - pOp->p4type = P4_ADVANCE; |
| 72766 | + default: { |
| 72767 | + if( pOp->p2<0 ){ |
| 72768 | + /* The mkopcodeh.tcl script has so arranged things that the only |
| 72769 | + ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to |
| 72770 | + ** have non-negative values for P2. */ |
| 72771 | + assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ); |
| 72772 | + assert( ADDR(pOp->p2)<pParse->nLabel ); |
| 72773 | + pOp->p2 = aLabel[ADDR(pOp->p2)]; |
| 72774 | + } |
| 72634 | 72775 | break; |
| 72635 | 72776 | } |
| 72636 | 72777 | } |
| 72637 | | - if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 72638 | | - assert( ADDR(pOp->p2)<pParse->nLabel ); |
| 72639 | | - pOp->p2 = aLabel[ADDR(pOp->p2)]; |
| 72640 | | - } |
| 72778 | + /* The mkopcodeh.tcl script has so arranged things that the only |
| 72779 | + ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to |
| 72780 | + ** have non-negative values for P2. */ |
| 72781 | + assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0); |
| 72641 | 72782 | } |
| 72642 | 72783 | if( pOp==p->aOp ) break; |
| 72643 | 72784 | pOp--; |
| 72644 | 72785 | } |
| 72645 | 72786 | sqlite3DbFree(p->db, pParse->aLabel); |
| | @@ -73308,12 +73449,12 @@ |
| 73308 | 73449 | switch( pOp->p4type ){ |
| 73309 | 73450 | case P4_KEYINFO: { |
| 73310 | 73451 | int j; |
| 73311 | 73452 | KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; |
| 73312 | 73453 | assert( pKeyInfo->aSortOrder!=0 ); |
| 73313 | | - sqlite3XPrintf(&x, "k(%d", pKeyInfo->nField); |
| 73314 | | - for(j=0; j<pKeyInfo->nField; j++){ |
| 73454 | + sqlite3XPrintf(&x, "k(%d", pKeyInfo->nKeyField); |
| 73455 | + for(j=0; j<pKeyInfo->nKeyField; j++){ |
| 73315 | 73456 | CollSeq *pColl = pKeyInfo->aColl[j]; |
| 73316 | 73457 | const char *zColl = pColl ? pColl->zName : ""; |
| 73317 | 73458 | if( strcmp(zColl, "BINARY")==0 ) zColl = "B"; |
| 73318 | 73459 | sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl); |
| 73319 | 73460 | } |
| | @@ -74145,31 +74286,10 @@ |
| 74145 | 74286 | /* Delete any auxdata allocations made by the VM */ |
| 74146 | 74287 | if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0); |
| 74147 | 74288 | assert( p->pAuxData==0 ); |
| 74148 | 74289 | } |
| 74149 | 74290 | |
| 74150 | | -/* |
| 74151 | | -** Clean up the VM after a single run. |
| 74152 | | -*/ |
| 74153 | | -static void Cleanup(Vdbe *p){ |
| 74154 | | - sqlite3 *db = p->db; |
| 74155 | | - |
| 74156 | | -#ifdef SQLITE_DEBUG |
| 74157 | | - /* Execute assert() statements to ensure that the Vdbe.apCsr[] and |
| 74158 | | - ** Vdbe.aMem[] arrays have already been cleaned up. */ |
| 74159 | | - int i; |
| 74160 | | - if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 ); |
| 74161 | | - if( p->aMem ){ |
| 74162 | | - for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined ); |
| 74163 | | - } |
| 74164 | | -#endif |
| 74165 | | - |
| 74166 | | - sqlite3DbFree(db, p->zErrMsg); |
| 74167 | | - p->zErrMsg = 0; |
| 74168 | | - p->pResultSet = 0; |
| 74169 | | -} |
| 74170 | | - |
| 74171 | 74291 | /* |
| 74172 | 74292 | ** Set the number of result columns that will be returned by this SQL |
| 74173 | 74293 | ** statement. This is now set at compile time, rather than during |
| 74174 | 74294 | ** execution of the vdbe program so that sqlite3_column_count() can |
| 74175 | 74295 | ** be called on an SQL statement before sqlite3_step(). |
| | @@ -74891,26 +75011,33 @@ |
| 74891 | 75011 | ** instructions yet, leave the main database error information unchanged. |
| 74892 | 75012 | */ |
| 74893 | 75013 | if( p->pc>=0 ){ |
| 74894 | 75014 | vdbeInvokeSqllog(p); |
| 74895 | 75015 | sqlite3VdbeTransferError(p); |
| 74896 | | - sqlite3DbFree(db, p->zErrMsg); |
| 74897 | | - p->zErrMsg = 0; |
| 74898 | 75016 | if( p->runOnlyOnce ) p->expired = 1; |
| 74899 | 75017 | }else if( p->rc && p->expired ){ |
| 74900 | 75018 | /* The expired flag was set on the VDBE before the first call |
| 74901 | 75019 | ** to sqlite3_step(). For consistency (since sqlite3_step() was |
| 74902 | 75020 | ** called), set the database error in this case as well. |
| 74903 | 75021 | */ |
| 74904 | 75022 | sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); |
| 74905 | | - sqlite3DbFree(db, p->zErrMsg); |
| 74906 | | - p->zErrMsg = 0; |
| 74907 | 75023 | } |
| 74908 | 75024 | |
| 74909 | | - /* Reclaim all memory used by the VDBE |
| 75025 | + /* Reset register contents and reclaim error message memory. |
| 74910 | 75026 | */ |
| 74911 | | - Cleanup(p); |
| 75027 | +#ifdef SQLITE_DEBUG |
| 75028 | + /* Execute assert() statements to ensure that the Vdbe.apCsr[] and |
| 75029 | + ** Vdbe.aMem[] arrays have already been cleaned up. */ |
| 75030 | + int i; |
| 75031 | + if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 ); |
| 75032 | + if( p->aMem ){ |
| 75033 | + for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined ); |
| 75034 | + } |
| 75035 | +#endif |
| 75036 | + sqlite3DbFree(db, p->zErrMsg); |
| 75037 | + p->zErrMsg = 0; |
| 75038 | + p->pResultSet = 0; |
| 74912 | 75039 | |
| 74913 | 75040 | /* Save profiling information from this VDBE run. |
| 74914 | 75041 | */ |
| 74915 | 75042 | #ifdef VDBE_PROFILE |
| 74916 | 75043 | { |
| | @@ -75127,23 +75254,22 @@ |
| 75127 | 75254 | ** If the cursor is already pointing to the correct row and that row has |
| 75128 | 75255 | ** not been deleted out from under the cursor, then this routine is a no-op. |
| 75129 | 75256 | */ |
| 75130 | 75257 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ |
| 75131 | 75258 | VdbeCursor *p = *pp; |
| 75132 | | - if( p->eCurType==CURTYPE_BTREE ){ |
| 75133 | | - if( p->deferredMoveto ){ |
| 75134 | | - int iMap; |
| 75135 | | - if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ |
| 75136 | | - *pp = p->pAltCursor; |
| 75137 | | - *piCol = iMap - 1; |
| 75138 | | - return SQLITE_OK; |
| 75139 | | - } |
| 75140 | | - return handleDeferredMoveto(p); |
| 75141 | | - } |
| 75142 | | - if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 75143 | | - return handleMovedCursor(p); |
| 75144 | | - } |
| 75259 | + assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 75260 | + if( p->deferredMoveto ){ |
| 75261 | + int iMap; |
| 75262 | + if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ |
| 75263 | + *pp = p->pAltCursor; |
| 75264 | + *piCol = iMap - 1; |
| 75265 | + return SQLITE_OK; |
| 75266 | + } |
| 75267 | + return handleDeferredMoveto(p); |
| 75268 | + } |
| 75269 | + if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 75270 | + return handleMovedCursor(p); |
| 75145 | 75271 | } |
| 75146 | 75272 | return SQLITE_OK; |
| 75147 | 75273 | } |
| 75148 | 75274 | |
| 75149 | 75275 | /* |
| | @@ -75535,17 +75661,17 @@ |
| 75535 | 75661 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord( |
| 75536 | 75662 | KeyInfo *pKeyInfo /* Description of the record */ |
| 75537 | 75663 | ){ |
| 75538 | 75664 | UnpackedRecord *p; /* Unpacked record to return */ |
| 75539 | 75665 | int nByte; /* Number of bytes required for *p */ |
| 75540 | | - nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1); |
| 75666 | + nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1); |
| 75541 | 75667 | p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte); |
| 75542 | 75668 | if( !p ) return 0; |
| 75543 | 75669 | p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))]; |
| 75544 | 75670 | assert( pKeyInfo->aSortOrder!=0 ); |
| 75545 | 75671 | p->pKeyInfo = pKeyInfo; |
| 75546 | | - p->nField = pKeyInfo->nField + 1; |
| 75672 | + p->nField = pKeyInfo->nKeyField + 1; |
| 75547 | 75673 | return p; |
| 75548 | 75674 | } |
| 75549 | 75675 | |
| 75550 | 75676 | /* |
| 75551 | 75677 | ** Given the nKey-byte encoding of a record in pKey[], populate the |
| | @@ -75581,11 +75707,11 @@ |
| 75581 | 75707 | pMem->z = 0; |
| 75582 | 75708 | d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem); |
| 75583 | 75709 | pMem++; |
| 75584 | 75710 | if( (++u)>=p->nField ) break; |
| 75585 | 75711 | } |
| 75586 | | - assert( u<=pKeyInfo->nField + 1 ); |
| 75712 | + assert( u<=pKeyInfo->nKeyField + 1 ); |
| 75587 | 75713 | p->nField = u; |
| 75588 | 75714 | } |
| 75589 | 75715 | |
| 75590 | 75716 | #ifdef SQLITE_DEBUG |
| 75591 | 75717 | /* |
| | @@ -75630,13 +75756,13 @@ |
| 75630 | 75756 | /* mem1.u.i = 0; // not needed, here to silence compiler warning */ |
| 75631 | 75757 | |
| 75632 | 75758 | idx1 = getVarint32(aKey1, szHdr1); |
| 75633 | 75759 | if( szHdr1>98307 ) return SQLITE_CORRUPT; |
| 75634 | 75760 | d1 = szHdr1; |
| 75635 | | - assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB ); |
| 75761 | + assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB ); |
| 75636 | 75762 | assert( pKeyInfo->aSortOrder!=0 ); |
| 75637 | | - assert( pKeyInfo->nField>0 ); |
| 75763 | + assert( pKeyInfo->nKeyField>0 ); |
| 75638 | 75764 | assert( idx1<=szHdr1 || CORRUPT_DB ); |
| 75639 | 75765 | do{ |
| 75640 | 75766 | u32 serial_type1; |
| 75641 | 75767 | |
| 75642 | 75768 | /* Read the serial types for the next element in each key. */ |
| | @@ -75694,16 +75820,16 @@ |
| 75694 | 75820 | |
| 75695 | 75821 | #ifdef SQLITE_DEBUG |
| 75696 | 75822 | /* |
| 75697 | 75823 | ** Count the number of fields (a.k.a. columns) in the record given by |
| 75698 | 75824 | ** pKey,nKey. The verify that this count is less than or equal to the |
| 75699 | | -** limit given by pKeyInfo->nField + pKeyInfo->nXField. |
| 75825 | +** limit given by pKeyInfo->nAllField. |
| 75700 | 75826 | ** |
| 75701 | 75827 | ** If this constraint is not satisfied, it means that the high-speed |
| 75702 | 75828 | ** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will |
| 75703 | 75829 | ** not work correctly. If this assert() ever fires, it probably means |
| 75704 | | -** that the KeyInfo.nField or KeyInfo.nXField values were computed |
| 75830 | +** that the KeyInfo.nKeyField or KeyInfo.nAllField values were computed |
| 75705 | 75831 | ** incorrectly. |
| 75706 | 75832 | */ |
| 75707 | 75833 | static void vdbeAssertFieldCountWithinLimits( |
| 75708 | 75834 | int nKey, const void *pKey, /* The record to verify */ |
| 75709 | 75835 | const KeyInfo *pKeyInfo /* Compare size with this KeyInfo */ |
| | @@ -75720,11 +75846,11 @@ |
| 75720 | 75846 | assert( szHdr<=(u32)nKey ); |
| 75721 | 75847 | while( idx<szHdr ){ |
| 75722 | 75848 | idx += getVarint32(aKey+idx, notUsed); |
| 75723 | 75849 | nField++; |
| 75724 | 75850 | } |
| 75725 | | - assert( nField <= pKeyInfo->nField+pKeyInfo->nXField ); |
| 75851 | + assert( nField <= pKeyInfo->nAllField ); |
| 75726 | 75852 | } |
| 75727 | 75853 | #else |
| 75728 | 75854 | # define vdbeAssertFieldCountWithinLimits(A,B,C) |
| 75729 | 75855 | #endif |
| 75730 | 75856 | |
| | @@ -76025,14 +76151,14 @@ |
| 76025 | 76151 | } |
| 76026 | 76152 | i = 0; |
| 76027 | 76153 | } |
| 76028 | 76154 | |
| 76029 | 76155 | VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */ |
| 76030 | | - assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField |
| 76156 | + assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField |
| 76031 | 76157 | || CORRUPT_DB ); |
| 76032 | 76158 | assert( pPKey2->pKeyInfo->aSortOrder!=0 ); |
| 76033 | | - assert( pPKey2->pKeyInfo->nField>0 ); |
| 76159 | + assert( pPKey2->pKeyInfo->nKeyField>0 ); |
| 76034 | 76160 | assert( idx1<=szHdr1 || CORRUPT_DB ); |
| 76035 | 76161 | do{ |
| 76036 | 76162 | u32 serial_type; |
| 76037 | 76163 | |
| 76038 | 76164 | /* RHS is an integer */ |
| | @@ -76361,11 +76487,11 @@ |
| 76361 | 76487 | ** is an integer. |
| 76362 | 76488 | ** |
| 76363 | 76489 | ** The easiest way to enforce this limit is to consider only records with |
| 76364 | 76490 | ** 13 fields or less. If the first field is an integer, the maximum legal |
| 76365 | 76491 | ** header size is (12*5 + 1 + 1) bytes. */ |
| 76366 | | - if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){ |
| 76492 | + if( p->pKeyInfo->nAllField<=13 ){ |
| 76367 | 76493 | int flags = p->aMem[0].flags; |
| 76368 | 76494 | if( p->pKeyInfo->aSortOrder[0] ){ |
| 76369 | 76495 | p->r1 = 1; |
| 76370 | 76496 | p->r2 = -1; |
| 76371 | 76497 | }else{ |
| | @@ -76696,22 +76822,22 @@ |
| 76696 | 76822 | preupdate.pCsr = pCsr; |
| 76697 | 76823 | preupdate.op = op; |
| 76698 | 76824 | preupdate.iNewReg = iReg; |
| 76699 | 76825 | preupdate.keyinfo.db = db; |
| 76700 | 76826 | preupdate.keyinfo.enc = ENC(db); |
| 76701 | | - preupdate.keyinfo.nField = pTab->nCol; |
| 76827 | + preupdate.keyinfo.nKeyField = pTab->nCol; |
| 76702 | 76828 | preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder; |
| 76703 | 76829 | preupdate.iKey1 = iKey1; |
| 76704 | 76830 | preupdate.iKey2 = iKey2; |
| 76705 | 76831 | preupdate.pTab = pTab; |
| 76706 | 76832 | |
| 76707 | 76833 | db->pPreUpdate = &preupdate; |
| 76708 | 76834 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 76709 | 76835 | db->pPreUpdate = 0; |
| 76710 | 76836 | sqlite3DbFree(db, preupdate.aRecord); |
| 76711 | | - vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked); |
| 76712 | | - vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked); |
| 76837 | + vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pUnpacked); |
| 76838 | + vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pNewUnpacked); |
| 76713 | 76839 | if( preupdate.aNew ){ |
| 76714 | 76840 | int i; |
| 76715 | 76841 | for(i=0; i<pCsr->nField; i++){ |
| 76716 | 76842 | sqlite3VdbeMemRelease(&preupdate.aNew[i]); |
| 76717 | 76843 | } |
| | @@ -77246,11 +77372,11 @@ |
| 77246 | 77372 | if( pBt ){ |
| 77247 | 77373 | int nEntry; |
| 77248 | 77374 | sqlite3BtreeEnter(pBt); |
| 77249 | 77375 | nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); |
| 77250 | 77376 | sqlite3BtreeLeave(pBt); |
| 77251 | | - if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){ |
| 77377 | + if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){ |
| 77252 | 77378 | rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry); |
| 77253 | 77379 | } |
| 77254 | 77380 | } |
| 77255 | 77381 | } |
| 77256 | 77382 | #endif |
| | @@ -77356,11 +77482,11 @@ |
| 77356 | 77482 | #ifndef SQLITE_OMIT_TRACE |
| 77357 | 77483 | /* If the statement completed successfully, invoke the profile callback */ |
| 77358 | 77484 | if( rc!=SQLITE_ROW ) checkProfileCallback(db, p); |
| 77359 | 77485 | #endif |
| 77360 | 77486 | |
| 77361 | | - if( rc==SQLITE_DONE ){ |
| 77487 | + if( rc==SQLITE_DONE && db->autoCommit ){ |
| 77362 | 77488 | assert( p->rc==SQLITE_OK ); |
| 77363 | 77489 | p->rc = doWalCallbacks(db); |
| 77364 | 77490 | if( p->rc!=SQLITE_OK ){ |
| 77365 | 77491 | rc = SQLITE_ERROR; |
| 77366 | 77492 | } |
| | @@ -77400,11 +77526,10 @@ |
| 77400 | 77526 | ** sqlite3Step() to do most of the work. If a schema error occurs, |
| 77401 | 77527 | ** call sqlite3Reprepare() and try again. |
| 77402 | 77528 | */ |
| 77403 | 77529 | SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){ |
| 77404 | 77530 | int rc = SQLITE_OK; /* Result from sqlite3Step() */ |
| 77405 | | - int rc2 = SQLITE_OK; /* Result from sqlite3Reprepare() */ |
| 77406 | 77531 | Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */ |
| 77407 | 77532 | int cnt = 0; /* Counter to prevent infinite loop of reprepares */ |
| 77408 | 77533 | sqlite3 *db; /* The database connection */ |
| 77409 | 77534 | |
| 77410 | 77535 | if( vdbeSafetyNotNull(v) ){ |
| | @@ -77414,36 +77539,35 @@ |
| 77414 | 77539 | sqlite3_mutex_enter(db->mutex); |
| 77415 | 77540 | v->doingRerun = 0; |
| 77416 | 77541 | while( (rc = sqlite3Step(v))==SQLITE_SCHEMA |
| 77417 | 77542 | && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){ |
| 77418 | 77543 | int savedPc = v->pc; |
| 77419 | | - rc2 = rc = sqlite3Reprepare(v); |
| 77420 | | - if( rc!=SQLITE_OK) break; |
| 77544 | + rc = sqlite3Reprepare(v); |
| 77545 | + if( rc!=SQLITE_OK ){ |
| 77546 | + /* This case occurs after failing to recompile an sql statement. |
| 77547 | + ** The error message from the SQL compiler has already been loaded |
| 77548 | + ** into the database handle. This block copies the error message |
| 77549 | + ** from the database handle into the statement and sets the statement |
| 77550 | + ** program counter to 0 to ensure that when the statement is |
| 77551 | + ** finalized or reset the parser error message is available via |
| 77552 | + ** sqlite3_errmsg() and sqlite3_errcode(). |
| 77553 | + */ |
| 77554 | + const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 77555 | + sqlite3DbFree(db, v->zErrMsg); |
| 77556 | + if( !db->mallocFailed ){ |
| 77557 | + v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 77558 | + v->rc = rc = sqlite3ApiExit(db, rc); |
| 77559 | + } else { |
| 77560 | + v->zErrMsg = 0; |
| 77561 | + v->rc = rc = SQLITE_NOMEM_BKPT; |
| 77562 | + } |
| 77563 | + break; |
| 77564 | + } |
| 77421 | 77565 | sqlite3_reset(pStmt); |
| 77422 | 77566 | if( savedPc>=0 ) v->doingRerun = 1; |
| 77423 | 77567 | assert( v->expired==0 ); |
| 77424 | 77568 | } |
| 77425 | | - if( rc2!=SQLITE_OK ){ |
| 77426 | | - /* This case occurs after failing to recompile an sql statement. |
| 77427 | | - ** The error message from the SQL compiler has already been loaded |
| 77428 | | - ** into the database handle. This block copies the error message |
| 77429 | | - ** from the database handle into the statement and sets the statement |
| 77430 | | - ** program counter to 0 to ensure that when the statement is |
| 77431 | | - ** finalized or reset the parser error message is available via |
| 77432 | | - ** sqlite3_errmsg() and sqlite3_errcode(). |
| 77433 | | - */ |
| 77434 | | - const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 77435 | | - sqlite3DbFree(db, v->zErrMsg); |
| 77436 | | - if( !db->mallocFailed ){ |
| 77437 | | - v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 77438 | | - v->rc = rc2; |
| 77439 | | - } else { |
| 77440 | | - v->zErrMsg = 0; |
| 77441 | | - v->rc = rc = SQLITE_NOMEM_BKPT; |
| 77442 | | - } |
| 77443 | | - } |
| 77444 | | - rc = sqlite3ApiExit(db, rc); |
| 77445 | 77569 | sqlite3_mutex_leave(db->mutex); |
| 77446 | 77570 | return rc; |
| 77447 | 77571 | } |
| 77448 | 77572 | |
| 77449 | 77573 | |
| | @@ -78445,11 +78569,11 @@ |
| 78445 | 78569 | ){ |
| 78446 | 78570 | UnpackedRecord *pRet; /* Return value */ |
| 78447 | 78571 | |
| 78448 | 78572 | pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo); |
| 78449 | 78573 | if( pRet ){ |
| 78450 | | - memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1)); |
| 78574 | + memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1)); |
| 78451 | 78575 | sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet); |
| 78452 | 78576 | } |
| 78453 | 78577 | return pRet; |
| 78454 | 78578 | } |
| 78455 | 78579 | |
| | @@ -78518,11 +78642,11 @@ |
| 78518 | 78642 | ** This function is called from within a pre-update callback to retrieve |
| 78519 | 78643 | ** the number of columns in the row being updated, deleted or inserted. |
| 78520 | 78644 | */ |
| 78521 | 78645 | SQLITE_API int sqlite3_preupdate_count(sqlite3 *db){ |
| 78522 | 78646 | PreUpdate *p = db->pPreUpdate; |
| 78523 | | - return (p ? p->keyinfo.nField : 0); |
| 78647 | + return (p ? p->keyinfo.nKeyField : 0); |
| 78524 | 78648 | } |
| 78525 | 78649 | #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 78526 | 78650 | |
| 78527 | 78651 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 78528 | 78652 | /* |
| | @@ -78771,11 +78895,11 @@ |
| 78771 | 78895 | int nToken; /* Length of the parameter token */ |
| 78772 | 78896 | int i; /* Loop counter */ |
| 78773 | 78897 | Mem *pVar; /* Value of a host parameter */ |
| 78774 | 78898 | StrAccum out; /* Accumulate the output here */ |
| 78775 | 78899 | #ifndef SQLITE_OMIT_UTF16 |
| 78776 | | - Mem utf8; /* Used to convert UTF16 parameters into UTF8 for display */ |
| 78900 | + Mem utf8; /* Used to convert UTF16 into UTF8 for display */ |
| 78777 | 78901 | #endif |
| 78778 | 78902 | char zBase[100]; /* Initial working space */ |
| 78779 | 78903 | |
| 78780 | 78904 | db = p->db; |
| 78781 | 78905 | sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase), |
| | @@ -79240,11 +79364,11 @@ |
| 79240 | 79364 | assert( (pMem->flags & (MEM_Int|MEM_Real))==0 ); |
| 79241 | 79365 | assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ); |
| 79242 | 79366 | if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){ |
| 79243 | 79367 | return 0; |
| 79244 | 79368 | } |
| 79245 | | - if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){ |
| 79369 | + if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){ |
| 79246 | 79370 | return MEM_Int; |
| 79247 | 79371 | } |
| 79248 | 79372 | return MEM_Real; |
| 79249 | 79373 | } |
| 79250 | 79374 | |
| | @@ -80930,17 +81054,27 @@ |
| 80930 | 81054 | } |
| 80931 | 81055 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 80932 | 81056 | res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 80933 | 81057 | } |
| 80934 | 81058 | compare_op: |
| 80935 | | - switch( pOp->opcode ){ |
| 80936 | | - case OP_Eq: res2 = res==0; break; |
| 80937 | | - case OP_Ne: res2 = res; break; |
| 80938 | | - case OP_Lt: res2 = res<0; break; |
| 80939 | | - case OP_Le: res2 = res<=0; break; |
| 80940 | | - case OP_Gt: res2 = res>0; break; |
| 80941 | | - default: res2 = res>=0; break; |
| 81059 | + /* At this point, res is negative, zero, or positive if reg[P1] is |
| 81060 | + ** less than, equal to, or greater than reg[P3], respectively. Compute |
| 81061 | + ** the answer to this operator in res2, depending on what the comparison |
| 81062 | + ** operator actually is. The next block of code depends on the fact |
| 81063 | + ** that the 6 comparison operators are consecutive integers in this |
| 81064 | + ** order: NE, EQ, GT, LE, LT, GE */ |
| 81065 | + assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 ); |
| 81066 | + assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 ); |
| 81067 | + if( res<0 ){ /* ne, eq, gt, le, lt, ge */ |
| 81068 | + static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 }; |
| 81069 | + res2 = aLTb[pOp->opcode - OP_Ne]; |
| 81070 | + }else if( res==0 ){ |
| 81071 | + static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 }; |
| 81072 | + res2 = aEQb[pOp->opcode - OP_Ne]; |
| 81073 | + }else{ |
| 81074 | + static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 }; |
| 81075 | + res2 = aGTb[pOp->opcode - OP_Ne]; |
| 80942 | 81076 | } |
| 80943 | 81077 | |
| 80944 | 81078 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 80945 | 81079 | assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); |
| 80946 | 81080 | pIn1->flags = flags1; |
| | @@ -80948,11 +81082,10 @@ |
| 80948 | 81082 | pIn3->flags = flags3; |
| 80949 | 81083 | |
| 80950 | 81084 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 80951 | 81085 | pOut = &aMem[pOp->p2]; |
| 80952 | 81086 | iCompare = res; |
| 80953 | | - res2 = res2!=0; /* For this path res2 must be exactly 0 or 1 */ |
| 80954 | 81087 | if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){ |
| 80955 | 81088 | /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1 |
| 80956 | 81089 | ** and prevents OP_Ne from overwriting NULL with 0. This flag |
| 80957 | 81090 | ** is only used in contexts where either: |
| 80958 | 81091 | ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0) |
| | @@ -81079,11 +81212,11 @@ |
| 81079 | 81212 | idx = aPermute ? aPermute[i] : i; |
| 81080 | 81213 | assert( memIsValid(&aMem[p1+idx]) ); |
| 81081 | 81214 | assert( memIsValid(&aMem[p2+idx]) ); |
| 81082 | 81215 | REGISTER_TRACE(p1+idx, &aMem[p1+idx]); |
| 81083 | 81216 | REGISTER_TRACE(p2+idx, &aMem[p2+idx]); |
| 81084 | | - assert( i<pKeyInfo->nField ); |
| 81217 | + assert( i<pKeyInfo->nKeyField ); |
| 81085 | 81218 | pColl = pKeyInfo->aColl[i]; |
| 81086 | 81219 | bRev = pKeyInfo->aSortOrder[i]; |
| 81087 | 81220 | iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl); |
| 81088 | 81221 | if( iCompare ){ |
| 81089 | 81222 | if( bRev ) iCompare = -iCompare; |
| | @@ -81352,13 +81485,11 @@ |
| 81352 | 81485 | Mem *pDest; /* Where to write the extracted value */ |
| 81353 | 81486 | Mem sMem; /* For storing the record being decoded */ |
| 81354 | 81487 | const u8 *zData; /* Part of the record being decoded */ |
| 81355 | 81488 | const u8 *zHdr; /* Next unparsed byte of the header */ |
| 81356 | 81489 | const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 81357 | | - u32 offset; /* Offset into the data */ |
| 81358 | 81490 | u64 offset64; /* 64-bit offset */ |
| 81359 | | - u32 avail; /* Number of bytes of available data */ |
| 81360 | 81491 | u32 t; /* A type code from the record header */ |
| 81361 | 81492 | Mem *pReg; /* PseudoTable input register */ |
| 81362 | 81493 | |
| 81363 | 81494 | pC = p->apCsr[pOp->p1]; |
| 81364 | 81495 | p2 = pOp->p2; |
| | @@ -81381,15 +81512,17 @@ |
| 81381 | 81512 | assert( pC->eCurType!=CURTYPE_SORTER ); |
| 81382 | 81513 | |
| 81383 | 81514 | if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/ |
| 81384 | 81515 | if( pC->nullRow ){ |
| 81385 | 81516 | if( pC->eCurType==CURTYPE_PSEUDO ){ |
| 81386 | | - assert( pC->uc.pseudoTableReg>0 ); |
| 81387 | | - pReg = &aMem[pC->uc.pseudoTableReg]; |
| 81517 | + /* For the special case of as pseudo-cursor, the seekResult field |
| 81518 | + ** identifies the register that holds the record */ |
| 81519 | + assert( pC->seekResult>0 ); |
| 81520 | + pReg = &aMem[pC->seekResult]; |
| 81388 | 81521 | assert( pReg->flags & MEM_Blob ); |
| 81389 | 81522 | assert( memIsValid(pReg) ); |
| 81390 | | - pC->payloadSize = pC->szRow = avail = pReg->n; |
| 81523 | + pC->payloadSize = pC->szRow = pReg->n; |
| 81391 | 81524 | pC->aRow = (u8*)pReg->z; |
| 81392 | 81525 | }else{ |
| 81393 | 81526 | sqlite3VdbeMemSetNull(pDest); |
| 81394 | 81527 | goto op_column_out; |
| 81395 | 81528 | } |
| | @@ -81397,27 +81530,23 @@ |
| 81397 | 81530 | pCrsr = pC->uc.pCursor; |
| 81398 | 81531 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 81399 | 81532 | assert( pCrsr ); |
| 81400 | 81533 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 81401 | 81534 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 81402 | | - pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail); |
| 81403 | | - assert( avail<=65536 ); /* Maximum page size is 64KiB */ |
| 81404 | | - if( pC->payloadSize <= (u32)avail ){ |
| 81405 | | - pC->szRow = pC->payloadSize; |
| 81406 | | - }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 81535 | + pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); |
| 81536 | + assert( pC->szRow<=pC->payloadSize ); |
| 81537 | + assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ |
| 81538 | + if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 81407 | 81539 | goto too_big; |
| 81408 | | - }else{ |
| 81409 | | - pC->szRow = avail; |
| 81410 | 81540 | } |
| 81411 | 81541 | } |
| 81412 | 81542 | pC->cacheStatus = p->cacheCtr; |
| 81413 | | - pC->iHdrOffset = getVarint32(pC->aRow, offset); |
| 81543 | + pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); |
| 81414 | 81544 | pC->nHdrParsed = 0; |
| 81415 | | - aOffset[0] = offset; |
| 81416 | 81545 | |
| 81417 | 81546 | |
| 81418 | | - if( avail<offset ){ /*OPTIMIZATION-IF-FALSE*/ |
| 81547 | + if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 81419 | 81548 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 81420 | 81549 | ** need to cover the header of the record. If pC->aRow does not contain |
| 81421 | 81550 | ** the complete header, then set it to zero, forcing the header to be |
| 81422 | 81551 | ** dynamically allocated. */ |
| 81423 | 81552 | pC->aRow = 0; |
| | @@ -81430,21 +81559,30 @@ |
| 81430 | 81559 | ** types use so much data space that there can only be 4096 and 32 of |
| 81431 | 81560 | ** them, respectively. So the maximum header length results from a |
| 81432 | 81561 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 81433 | 81562 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 81434 | 81563 | */ |
| 81435 | | - if( offset > 98307 || offset > pC->payloadSize ){ |
| 81436 | | - rc = SQLITE_CORRUPT_BKPT; |
| 81437 | | - goto abort_due_to_error; |
| 81438 | | - } |
| 81439 | | - }else if( offset>0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 81440 | | - /* The following goto is an optimization. It can be omitted and |
| 81441 | | - ** everything will still work. But OP_Column is measurably faster |
| 81442 | | - ** by skipping the subsequent conditional, which is always true. |
| 81564 | + if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){ |
| 81565 | + goto op_column_corrupt; |
| 81566 | + } |
| 81567 | + }else{ |
| 81568 | + /* This is an optimization. By skipping over the first few tests |
| 81569 | + ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a |
| 81570 | + ** measurable performance gain. |
| 81571 | + ** |
| 81572 | + ** This branch is taken even if aOffset[0]==0. Such a record is never |
| 81573 | + ** generated by SQLite, and could be considered corruption, but we |
| 81574 | + ** accept it for historical reasons. When aOffset[0]==0, the code this |
| 81575 | + ** branch jumps to reads past the end of the record, but never more |
| 81576 | + ** than a few bytes. Even if the record occurs at the end of the page |
| 81577 | + ** content area, the "page header" comes after the page content and so |
| 81578 | + ** this overread is harmless. Similar overreads can occur for a corrupt |
| 81579 | + ** database file. |
| 81443 | 81580 | */ |
| 81444 | 81581 | zData = pC->aRow; |
| 81445 | 81582 | assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 81583 | + testcase( aOffset[0]==0 ); |
| 81446 | 81584 | goto op_column_read_header; |
| 81447 | 81585 | } |
| 81448 | 81586 | } |
| 81449 | 81587 | |
| 81450 | 81588 | /* Make sure at least the first p2+1 entries of the header have been |
| | @@ -81469,10 +81607,11 @@ |
| 81469 | 81607 | op_column_read_header: |
| 81470 | 81608 | i = pC->nHdrParsed; |
| 81471 | 81609 | offset64 = aOffset[i]; |
| 81472 | 81610 | zHdr = zData + pC->iHdrOffset; |
| 81473 | 81611 | zEndHdr = zData + aOffset[0]; |
| 81612 | + testcase( zHdr>=zEndHdr ); |
| 81474 | 81613 | do{ |
| 81475 | 81614 | if( (t = zHdr[0])<0x80 ){ |
| 81476 | 81615 | zHdr++; |
| 81477 | 81616 | offset64 += sqlite3VdbeOneByteSerialTypeLen(t); |
| 81478 | 81617 | }else{ |
| | @@ -81489,13 +81628,17 @@ |
| 81489 | 81628 | ** (3) the end of the data extends beyond the end of the record. |
| 81490 | 81629 | */ |
| 81491 | 81630 | if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize)) |
| 81492 | 81631 | || (offset64 > pC->payloadSize) |
| 81493 | 81632 | ){ |
| 81494 | | - if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem); |
| 81495 | | - rc = SQLITE_CORRUPT_BKPT; |
| 81496 | | - goto abort_due_to_error; |
| 81633 | + if( aOffset[0]==0 ){ |
| 81634 | + i = 0; |
| 81635 | + zHdr = zEndHdr; |
| 81636 | + }else{ |
| 81637 | + if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem); |
| 81638 | + goto op_column_corrupt; |
| 81639 | + } |
| 81497 | 81640 | } |
| 81498 | 81641 | |
| 81499 | 81642 | pC->nHdrParsed = i; |
| 81500 | 81643 | pC->iHdrOffset = (u32)(zHdr - zData); |
| 81501 | 81644 | if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem); |
| | @@ -81585,10 +81728,19 @@ |
| 81585 | 81728 | |
| 81586 | 81729 | op_column_out: |
| 81587 | 81730 | UPDATE_MAX_BLOBSIZE(pDest); |
| 81588 | 81731 | REGISTER_TRACE(pOp->p3, pDest); |
| 81589 | 81732 | break; |
| 81733 | + |
| 81734 | +op_column_corrupt: |
| 81735 | + if( aOp[0].p3>0 ){ |
| 81736 | + pOp = &aOp[aOp[0].p3-1]; |
| 81737 | + break; |
| 81738 | + }else{ |
| 81739 | + rc = SQLITE_CORRUPT_BKPT; |
| 81740 | + goto abort_due_to_error; |
| 81741 | + } |
| 81590 | 81742 | } |
| 81591 | 81743 | |
| 81592 | 81744 | /* Opcode: Affinity P1 P2 * P4 * |
| 81593 | 81745 | ** Synopsis: affinity(r[P1@P2]) |
| 81594 | 81746 | ** |
| | @@ -81925,11 +82077,11 @@ |
| 81925 | 82077 | rc = p->rc; |
| 81926 | 82078 | }else{ |
| 81927 | 82079 | int isSchemaChange; |
| 81928 | 82080 | iSavepoint = db->nSavepoint - iSavepoint - 1; |
| 81929 | 82081 | if( p1==SAVEPOINT_ROLLBACK ){ |
| 81930 | | - isSchemaChange = (db->flags & SQLITE_InternChanges)!=0; |
| 82082 | + isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0; |
| 81931 | 82083 | for(ii=0; ii<db->nDb; ii++){ |
| 81932 | 82084 | rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, |
| 81933 | 82085 | SQLITE_ABORT_ROLLBACK, |
| 81934 | 82086 | isSchemaChange==0); |
| 81935 | 82087 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| | @@ -81944,11 +82096,11 @@ |
| 81944 | 82096 | } |
| 81945 | 82097 | } |
| 81946 | 82098 | if( isSchemaChange ){ |
| 81947 | 82099 | sqlite3ExpirePreparedStatements(db); |
| 81948 | 82100 | sqlite3ResetAllSchemasOfConnection(db); |
| 81949 | | - db->flags = (db->flags | SQLITE_InternChanges); |
| 82101 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 81950 | 82102 | } |
| 81951 | 82103 | } |
| 81952 | 82104 | |
| 81953 | 82105 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| 81954 | 82106 | ** savepoints nested inside of the savepoint being operated on. */ |
| | @@ -82224,11 +82376,11 @@ |
| 82224 | 82376 | /* See note about index shifting on OP_ReadCookie */ |
| 82225 | 82377 | rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3); |
| 82226 | 82378 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| 82227 | 82379 | /* When the schema cookie changes, record the new cookie internally */ |
| 82228 | 82380 | pDb->pSchema->schema_cookie = pOp->p3; |
| 82229 | | - db->flags |= SQLITE_InternChanges; |
| 82381 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 82230 | 82382 | }else if( pOp->p2==BTREE_FILE_FORMAT ){ |
| 82231 | 82383 | /* Record changes in the file format */ |
| 82232 | 82384 | pDb->pSchema->file_format = pOp->p3; |
| 82233 | 82385 | } |
| 82234 | 82386 | if( pOp->p1==1 ){ |
| | @@ -82363,21 +82515,21 @@ |
| 82363 | 82515 | pIn2 = &aMem[p2]; |
| 82364 | 82516 | assert( memIsValid(pIn2) ); |
| 82365 | 82517 | assert( (pIn2->flags & MEM_Int)!=0 ); |
| 82366 | 82518 | sqlite3VdbeMemIntegerify(pIn2); |
| 82367 | 82519 | p2 = (int)pIn2->u.i; |
| 82368 | | - /* The p2 value always comes from a prior OP_CreateTable opcode and |
| 82520 | + /* The p2 value always comes from a prior OP_CreateBtree opcode and |
| 82369 | 82521 | ** that opcode will always set the p2 value to 2 or more or else fail. |
| 82370 | 82522 | ** If there were a failure, the prepared statement would have halted |
| 82371 | 82523 | ** before reaching this instruction. */ |
| 82372 | 82524 | assert( p2>=2 ); |
| 82373 | 82525 | } |
| 82374 | 82526 | if( pOp->p4type==P4_KEYINFO ){ |
| 82375 | 82527 | pKeyInfo = pOp->p4.pKeyInfo; |
| 82376 | 82528 | assert( pKeyInfo->enc==ENC(db) ); |
| 82377 | 82529 | assert( pKeyInfo->db==db ); |
| 82378 | | - nField = pKeyInfo->nField+pKeyInfo->nXField; |
| 82530 | + nField = pKeyInfo->nAllField; |
| 82379 | 82531 | }else if( pOp->p4type==P4_INT32 ){ |
| 82380 | 82532 | nField = pOp->p4.i; |
| 82381 | 82533 | } |
| 82382 | 82534 | assert( pOp->p1>=0 ); |
| 82383 | 82535 | assert( nField>=0 ); |
| | @@ -82584,12 +82736,17 @@ |
| 82584 | 82736 | assert( pOp->p1>=0 ); |
| 82585 | 82737 | assert( pOp->p3>=0 ); |
| 82586 | 82738 | pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO); |
| 82587 | 82739 | if( pCx==0 ) goto no_mem; |
| 82588 | 82740 | pCx->nullRow = 1; |
| 82589 | | - pCx->uc.pseudoTableReg = pOp->p2; |
| 82741 | + pCx->seekResult = pOp->p2; |
| 82590 | 82742 | pCx->isTable = 1; |
| 82743 | + /* Give this pseudo-cursor a fake BtCursor pointer so that pCx |
| 82744 | + ** can be safely passed to sqlite3VdbeCursorMoveto(). This avoids a test |
| 82745 | + ** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto() |
| 82746 | + ** which is a performance optimization */ |
| 82747 | + pCx->uc.pCursor = sqlite3BtreeFakeValidCursor(); |
| 82591 | 82748 | assert( pOp->p5==0 ); |
| 82592 | 82749 | break; |
| 82593 | 82750 | } |
| 82594 | 82751 | |
| 82595 | 82752 | /* Opcode: Close P1 * * * * |
| | @@ -83751,11 +83908,21 @@ |
| 83751 | 83908 | sqlite3BtreeClearCursor(pC->uc.pCursor); |
| 83752 | 83909 | } |
| 83753 | 83910 | break; |
| 83754 | 83911 | } |
| 83755 | 83912 | |
| 83756 | | -/* Opcode: Last P1 P2 P3 * * |
| 83913 | +/* Opcode: SeekEnd P1 * * * * |
| 83914 | +** |
| 83915 | +** Position cursor P1 at the end of the btree for the purpose of |
| 83916 | +** appending a new entry onto the btree. |
| 83917 | +** |
| 83918 | +** It is assumed that the cursor is used only for appending and so |
| 83919 | +** if the cursor is valid, then the cursor must already be pointing |
| 83920 | +** at the end of the btree and so no changes are made to |
| 83921 | +** the cursor. |
| 83922 | +*/ |
| 83923 | +/* Opcode: Last P1 P2 * * * |
| 83757 | 83924 | ** |
| 83758 | 83925 | ** The next use of the Rowid or Column or Prev instruction for P1 |
| 83759 | 83926 | ** will refer to the last entry in the database table or index. |
| 83760 | 83927 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 83761 | 83928 | ** If P2 is 0 or if the table or index is not empty, fall through |
| | @@ -83762,18 +83929,12 @@ |
| 83762 | 83929 | ** to the following instruction. |
| 83763 | 83930 | ** |
| 83764 | 83931 | ** This opcode leaves the cursor configured to move in reverse order, |
| 83765 | 83932 | ** from the end toward the beginning. In other words, the cursor is |
| 83766 | 83933 | ** configured to use Prev, not Next. |
| 83767 | | -** |
| 83768 | | -** If P3 is -1, then the cursor is positioned at the end of the btree |
| 83769 | | -** for the purpose of appending a new entry onto the btree. In that |
| 83770 | | -** case P2 must be 0. It is assumed that the cursor is used only for |
| 83771 | | -** appending and so if the cursor is valid, then the cursor must already |
| 83772 | | -** be pointing at the end of the btree and so no changes are made to |
| 83773 | | -** the cursor. |
| 83774 | 83934 | */ |
| 83935 | +case OP_SeekEnd: |
| 83775 | 83936 | case OP_Last: { /* jump */ |
| 83776 | 83937 | VdbeCursor *pC; |
| 83777 | 83938 | BtCursor *pCrsr; |
| 83778 | 83939 | int res; |
| 83779 | 83940 | |
| | @@ -83782,26 +83943,28 @@ |
| 83782 | 83943 | assert( pC!=0 ); |
| 83783 | 83944 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 83784 | 83945 | pCrsr = pC->uc.pCursor; |
| 83785 | 83946 | res = 0; |
| 83786 | 83947 | assert( pCrsr!=0 ); |
| 83787 | | - pC->seekResult = pOp->p3; |
| 83788 | 83948 | #ifdef SQLITE_DEBUG |
| 83789 | | - pC->seekOp = OP_Last; |
| 83949 | + pC->seekOp = pOp->opcode; |
| 83790 | 83950 | #endif |
| 83791 | | - if( pOp->p3==0 || !sqlite3BtreeCursorIsValidNN(pCrsr) ){ |
| 83792 | | - rc = sqlite3BtreeLast(pCrsr, &res); |
| 83793 | | - pC->nullRow = (u8)res; |
| 83794 | | - pC->deferredMoveto = 0; |
| 83795 | | - pC->cacheStatus = CACHE_STALE; |
| 83796 | | - if( rc ) goto abort_due_to_error; |
| 83797 | | - if( pOp->p2>0 ){ |
| 83798 | | - VdbeBranchTaken(res!=0,2); |
| 83799 | | - if( res ) goto jump_to_p2; |
| 83800 | | - } |
| 83801 | | - }else{ |
| 83951 | + if( pOp->opcode==OP_SeekEnd ){ |
| 83802 | 83952 | assert( pOp->p2==0 ); |
| 83953 | + pC->seekResult = -1; |
| 83954 | + if( sqlite3BtreeCursorIsValidNN(pCrsr) ){ |
| 83955 | + break; |
| 83956 | + } |
| 83957 | + } |
| 83958 | + rc = sqlite3BtreeLast(pCrsr, &res); |
| 83959 | + pC->nullRow = (u8)res; |
| 83960 | + pC->deferredMoveto = 0; |
| 83961 | + pC->cacheStatus = CACHE_STALE; |
| 83962 | + if( rc ) goto abort_due_to_error; |
| 83963 | + if( pOp->p2>0 ){ |
| 83964 | + VdbeBranchTaken(res!=0,2); |
| 83965 | + if( res ) goto jump_to_p2; |
| 83803 | 83966 | } |
| 83804 | 83967 | break; |
| 83805 | 83968 | } |
| 83806 | 83969 | |
| 83807 | 83970 | /* Opcode: IfSmaller P1 P2 P3 * * |
| | @@ -84426,54 +84589,32 @@ |
| 84426 | 84589 | if( rc ) goto abort_due_to_error; |
| 84427 | 84590 | } |
| 84428 | 84591 | break; |
| 84429 | 84592 | } |
| 84430 | 84593 | |
| 84431 | | -/* Opcode: CreateTable P1 P2 * * * |
| 84432 | | -** Synopsis: r[P2]=root iDb=P1 |
| 84433 | | -** |
| 84434 | | -** Allocate a new table in the main database file if P1==0 or in the |
| 84435 | | -** auxiliary database file if P1==1 or in an attached database if |
| 84436 | | -** P1>1. Write the root page number of the new table into |
| 84437 | | -** register P2 |
| 84438 | | -** |
| 84439 | | -** The difference between a table and an index is this: A table must |
| 84440 | | -** have a 4-byte integer key and can have arbitrary data. An index |
| 84441 | | -** has an arbitrary key but no data. |
| 84442 | | -** |
| 84443 | | -** See also: CreateIndex |
| 84444 | | -*/ |
| 84445 | | -/* Opcode: CreateIndex P1 P2 * * * |
| 84446 | | -** Synopsis: r[P2]=root iDb=P1 |
| 84447 | | -** |
| 84448 | | -** Allocate a new index in the main database file if P1==0 or in the |
| 84449 | | -** auxiliary database file if P1==1 or in an attached database if |
| 84450 | | -** P1>1. Write the root page number of the new table into |
| 84451 | | -** register P2. |
| 84452 | | -** |
| 84453 | | -** See documentation on OP_CreateTable for additional information. |
| 84454 | | -*/ |
| 84455 | | -case OP_CreateIndex: /* out2 */ |
| 84456 | | -case OP_CreateTable: { /* out2 */ |
| 84457 | | - int pgno; |
| 84458 | | - int flags; |
| 84594 | +/* Opcode: CreateBtree P1 P2 P3 * * |
| 84595 | +** Synopsis: r[P2]=root iDb=P1 flags=P3 |
| 84596 | +** |
| 84597 | +** Allocate a new b-tree in the main database file if P1==0 or in the |
| 84598 | +** TEMP database file if P1==1 or in an attached database if |
| 84599 | +** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table |
| 84600 | +** it must be 2 (BTREE_BLOBKEY) for a index or WITHOUT ROWID table. |
| 84601 | +** The root page number of the new b-tree is stored in register P2. |
| 84602 | +*/ |
| 84603 | +case OP_CreateBtree: { /* out2 */ |
| 84604 | + int pgno; |
| 84459 | 84605 | Db *pDb; |
| 84460 | 84606 | |
| 84461 | 84607 | pOut = out2Prerelease(p, pOp); |
| 84462 | 84608 | pgno = 0; |
| 84609 | + assert( pOp->p3==BTREE_INTKEY || pOp->p3==BTREE_BLOBKEY ); |
| 84463 | 84610 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 84464 | 84611 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 84465 | 84612 | assert( p->readOnly==0 ); |
| 84466 | 84613 | pDb = &db->aDb[pOp->p1]; |
| 84467 | 84614 | assert( pDb->pBt!=0 ); |
| 84468 | | - if( pOp->opcode==OP_CreateTable ){ |
| 84469 | | - /* flags = BTREE_INTKEY; */ |
| 84470 | | - flags = BTREE_INTKEY; |
| 84471 | | - }else{ |
| 84472 | | - flags = BTREE_BLOBKEY; |
| 84473 | | - } |
| 84474 | | - rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags); |
| 84615 | + rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, pOp->p3); |
| 84475 | 84616 | if( rc ) goto abort_due_to_error; |
| 84476 | 84617 | pOut->u.i = pgno; |
| 84477 | 84618 | break; |
| 84478 | 84619 | } |
| 84479 | 84620 | |
| | @@ -85980,11 +86121,11 @@ |
| 85980 | 86121 | UPDATE_MAX_BLOBSIZE(pOut); |
| 85981 | 86122 | break; |
| 85982 | 86123 | } |
| 85983 | 86124 | |
| 85984 | 86125 | |
| 85985 | | -/* Opcode: Init P1 P2 * P4 * |
| 86126 | +/* Opcode: Init P1 P2 P3 P4 * |
| 85986 | 86127 | ** Synopsis: Start at P2 |
| 85987 | 86128 | ** |
| 85988 | 86129 | ** Programs contain a single instance of this opcode as the very first |
| 85989 | 86130 | ** opcode. |
| 85990 | 86131 | ** |
| | @@ -85994,10 +86135,13 @@ |
| 85994 | 86135 | ** |
| 85995 | 86136 | ** If P2 is not zero, jump to instruction P2. |
| 85996 | 86137 | ** |
| 85997 | 86138 | ** Increment the value of P1 so that OP_Once opcodes will jump the |
| 85998 | 86139 | ** first time they are evaluated for this run. |
| 86140 | +** |
| 86141 | +** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT |
| 86142 | +** error is encountered. |
| 85999 | 86143 | */ |
| 86000 | 86144 | case OP_Init: { /* jump */ |
| 86001 | 86145 | char *zTrace; |
| 86002 | 86146 | int i; |
| 86003 | 86147 | |
| | @@ -86334,12 +86478,12 @@ |
| 86334 | 86478 | int nAttempt = 0; |
| 86335 | 86479 | int iCol; /* Index of zColumn in row-record */ |
| 86336 | 86480 | int rc = SQLITE_OK; |
| 86337 | 86481 | char *zErr = 0; |
| 86338 | 86482 | Table *pTab; |
| 86339 | | - Parse *pParse = 0; |
| 86340 | 86483 | Incrblob *pBlob = 0; |
| 86484 | + Parse sParse; |
| 86341 | 86485 | |
| 86342 | 86486 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 86343 | 86487 | if( ppBlob==0 ){ |
| 86344 | 86488 | return SQLITE_MISUSE_BKPT; |
| 86345 | 86489 | } |
| | @@ -86353,41 +86497,38 @@ |
| 86353 | 86497 | wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */ |
| 86354 | 86498 | |
| 86355 | 86499 | sqlite3_mutex_enter(db->mutex); |
| 86356 | 86500 | |
| 86357 | 86501 | pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); |
| 86358 | | - if( !pBlob ) goto blob_open_out; |
| 86359 | | - pParse = sqlite3StackAllocRaw(db, sizeof(*pParse)); |
| 86360 | | - if( !pParse ) goto blob_open_out; |
| 86361 | | - |
| 86362 | 86502 | do { |
| 86363 | | - memset(pParse, 0, sizeof(Parse)); |
| 86364 | | - pParse->db = db; |
| 86503 | + memset(&sParse, 0, sizeof(Parse)); |
| 86504 | + if( !pBlob ) goto blob_open_out; |
| 86505 | + sParse.db = db; |
| 86365 | 86506 | sqlite3DbFree(db, zErr); |
| 86366 | 86507 | zErr = 0; |
| 86367 | 86508 | |
| 86368 | 86509 | sqlite3BtreeEnterAll(db); |
| 86369 | | - pTab = sqlite3LocateTable(pParse, 0, zTable, zDb); |
| 86510 | + pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb); |
| 86370 | 86511 | if( pTab && IsVirtual(pTab) ){ |
| 86371 | 86512 | pTab = 0; |
| 86372 | | - sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable); |
| 86513 | + sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable); |
| 86373 | 86514 | } |
| 86374 | 86515 | if( pTab && !HasRowid(pTab) ){ |
| 86375 | 86516 | pTab = 0; |
| 86376 | | - sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable); |
| 86517 | + sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable); |
| 86377 | 86518 | } |
| 86378 | 86519 | #ifndef SQLITE_OMIT_VIEW |
| 86379 | 86520 | if( pTab && pTab->pSelect ){ |
| 86380 | 86521 | pTab = 0; |
| 86381 | | - sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable); |
| 86522 | + sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable); |
| 86382 | 86523 | } |
| 86383 | 86524 | #endif |
| 86384 | 86525 | if( !pTab ){ |
| 86385 | | - if( pParse->zErrMsg ){ |
| 86526 | + if( sParse.zErrMsg ){ |
| 86386 | 86527 | sqlite3DbFree(db, zErr); |
| 86387 | | - zErr = pParse->zErrMsg; |
| 86388 | | - pParse->zErrMsg = 0; |
| 86528 | + zErr = sParse.zErrMsg; |
| 86529 | + sParse.zErrMsg = 0; |
| 86389 | 86530 | } |
| 86390 | 86531 | rc = SQLITE_ERROR; |
| 86391 | 86532 | sqlite3BtreeLeaveAll(db); |
| 86392 | 86533 | goto blob_open_out; |
| 86393 | 86534 | } |
| | @@ -86447,11 +86588,11 @@ |
| 86447 | 86588 | sqlite3BtreeLeaveAll(db); |
| 86448 | 86589 | goto blob_open_out; |
| 86449 | 86590 | } |
| 86450 | 86591 | } |
| 86451 | 86592 | |
| 86452 | | - pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); |
| 86593 | + pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(&sParse); |
| 86453 | 86594 | assert( pBlob->pStmt || db->mallocFailed ); |
| 86454 | 86595 | if( pBlob->pStmt ){ |
| 86455 | 86596 | |
| 86456 | 86597 | /* This VDBE program seeks a btree cursor to the identified |
| 86457 | 86598 | ** db/table/row entry. The reason for using a vdbe program instead |
| | @@ -86483,11 +86624,12 @@ |
| 86483 | 86624 | VdbeOp *aOp; |
| 86484 | 86625 | |
| 86485 | 86626 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag, |
| 86486 | 86627 | pTab->pSchema->schema_cookie, |
| 86487 | 86628 | pTab->pSchema->iGeneration); |
| 86488 | | - sqlite3VdbeChangeP5(v, 1); |
| 86629 | + sqlite3VdbeChangeP5(v, 1); |
| 86630 | + assert( sqlite3VdbeCurrentAddr(v)==2 || db->mallocFailed ); |
| 86489 | 86631 | aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 86490 | 86632 | |
| 86491 | 86633 | /* Make sure a mutex is held on the table to be accessed */ |
| 86492 | 86634 | sqlite3VdbeUsesBtree(v, iDb); |
| 86493 | 86635 | |
| | @@ -86498,11 +86640,11 @@ |
| 86498 | 86640 | aOp[0].opcode = OP_Noop; |
| 86499 | 86641 | #else |
| 86500 | 86642 | aOp[0].p1 = iDb; |
| 86501 | 86643 | aOp[0].p2 = pTab->tnum; |
| 86502 | 86644 | aOp[0].p3 = wrFlag; |
| 86503 | | - sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 86645 | + sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT); |
| 86504 | 86646 | } |
| 86505 | 86647 | if( db->mallocFailed==0 ){ |
| 86506 | 86648 | #endif |
| 86507 | 86649 | |
| 86508 | 86650 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| | @@ -86520,14 +86662,14 @@ |
| 86520 | 86662 | */ |
| 86521 | 86663 | aOp[1].p4type = P4_INT32; |
| 86522 | 86664 | aOp[1].p4.i = pTab->nCol+1; |
| 86523 | 86665 | aOp[3].p2 = pTab->nCol; |
| 86524 | 86666 | |
| 86525 | | - pParse->nVar = 0; |
| 86526 | | - pParse->nMem = 1; |
| 86527 | | - pParse->nTab = 1; |
| 86528 | | - sqlite3VdbeMakeReady(v, pParse); |
| 86667 | + sParse.nVar = 0; |
| 86668 | + sParse.nMem = 1; |
| 86669 | + sParse.nTab = 1; |
| 86670 | + sqlite3VdbeMakeReady(v, &sParse); |
| 86529 | 86671 | } |
| 86530 | 86672 | } |
| 86531 | 86673 | |
| 86532 | 86674 | pBlob->iCol = iCol; |
| 86533 | 86675 | pBlob->db = db; |
| | @@ -86545,12 +86687,11 @@ |
| 86545 | 86687 | if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt); |
| 86546 | 86688 | sqlite3DbFree(db, pBlob); |
| 86547 | 86689 | } |
| 86548 | 86690 | sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); |
| 86549 | 86691 | sqlite3DbFree(db, zErr); |
| 86550 | | - sqlite3ParserReset(pParse); |
| 86551 | | - sqlite3StackFree(db, pParse); |
| 86692 | + sqlite3ParserReset(&sParse); |
| 86552 | 86693 | rc = sqlite3ApiExit(db, rc); |
| 86553 | 86694 | sqlite3_mutex_leave(db->mutex); |
| 86554 | 86695 | return rc; |
| 86555 | 86696 | } |
| 86556 | 86697 | |
| | @@ -87540,11 +87681,11 @@ |
| 87540 | 87681 | if( res==0 ){ |
| 87541 | 87682 | res = n1 - n2; |
| 87542 | 87683 | } |
| 87543 | 87684 | |
| 87544 | 87685 | if( res==0 ){ |
| 87545 | | - if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 87686 | + if( pTask->pSorter->pKeyInfo->nKeyField>1 ){ |
| 87546 | 87687 | res = vdbeSorterCompareTail( |
| 87547 | 87688 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 87548 | 87689 | ); |
| 87549 | 87690 | } |
| 87550 | 87691 | }else{ |
| | @@ -87609,11 +87750,11 @@ |
| 87609 | 87750 | if( *v2 & 0x80 ) res = +1; |
| 87610 | 87751 | } |
| 87611 | 87752 | } |
| 87612 | 87753 | |
| 87613 | 87754 | if( res==0 ){ |
| 87614 | | - if( pTask->pSorter->pKeyInfo->nField>1 ){ |
| 87755 | + if( pTask->pSorter->pKeyInfo->nKeyField>1 ){ |
| 87615 | 87756 | res = vdbeSorterCompareTail( |
| 87616 | 87757 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 87617 | 87758 | ); |
| 87618 | 87759 | } |
| 87619 | 87760 | }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ |
| | @@ -87624,11 +87765,11 @@ |
| 87624 | 87765 | } |
| 87625 | 87766 | |
| 87626 | 87767 | /* |
| 87627 | 87768 | ** Initialize the temporary index cursor just opened as a sorter cursor. |
| 87628 | 87769 | ** |
| 87629 | | -** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField) |
| 87770 | +** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nKeyField) |
| 87630 | 87771 | ** to determine the number of fields that should be compared from the |
| 87631 | 87772 | ** records being sorted. However, if the value passed as argument nField |
| 87632 | 87773 | ** is non-zero and the sorter is able to guarantee a stable sort, nField |
| 87633 | 87774 | ** is used instead. This is used when sorting records for a CREATE INDEX |
| 87634 | 87775 | ** statement. In this case, keys are always delivered to the sorter in |
| | @@ -87677,11 +87818,11 @@ |
| 87677 | 87818 | } |
| 87678 | 87819 | #endif |
| 87679 | 87820 | |
| 87680 | 87821 | assert( pCsr->pKeyInfo && pCsr->pBtx==0 ); |
| 87681 | 87822 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 87682 | | - szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*); |
| 87823 | + szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*); |
| 87683 | 87824 | sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask); |
| 87684 | 87825 | |
| 87685 | 87826 | pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); |
| 87686 | 87827 | pCsr->uc.pSorter = pSorter; |
| 87687 | 87828 | if( pSorter==0 ){ |
| | @@ -87689,12 +87830,11 @@ |
| 87689 | 87830 | }else{ |
| 87690 | 87831 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 87691 | 87832 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 87692 | 87833 | pKeyInfo->db = 0; |
| 87693 | 87834 | if( nField && nWorker==0 ){ |
| 87694 | | - pKeyInfo->nXField += (pKeyInfo->nField - nField); |
| 87695 | | - pKeyInfo->nField = nField; |
| 87835 | + pKeyInfo->nKeyField = nField; |
| 87696 | 87836 | } |
| 87697 | 87837 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 87698 | 87838 | pSorter->nTask = nWorker + 1; |
| 87699 | 87839 | pSorter->iPrev = (u8)(nWorker - 1); |
| 87700 | 87840 | pSorter->bUseThreads = (pSorter->nTask>1); |
| | @@ -87718,23 +87858,21 @@ |
| 87718 | 87858 | mxCache = mxCache * pgsz; |
| 87719 | 87859 | } |
| 87720 | 87860 | mxCache = MIN(mxCache, SQLITE_MAX_PMASZ); |
| 87721 | 87861 | pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache); |
| 87722 | 87862 | |
| 87723 | | - /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 87724 | | - ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 87725 | | - ** large heap allocations. |
| 87726 | | - */ |
| 87727 | | - if( sqlite3GlobalConfig.pScratch==0 ){ |
| 87863 | + /* Avoid large memory allocations if the application has requested |
| 87864 | + ** SQLITE_CONFIG_SMALL_MALLOC. */ |
| 87865 | + if( sqlite3GlobalConfig.bSmallMalloc==0 ){ |
| 87728 | 87866 | assert( pSorter->iMemory==0 ); |
| 87729 | 87867 | pSorter->nMemory = pgsz; |
| 87730 | 87868 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| 87731 | 87869 | if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT; |
| 87732 | 87870 | } |
| 87733 | 87871 | } |
| 87734 | 87872 | |
| 87735 | | - if( (pKeyInfo->nField+pKeyInfo->nXField)<13 |
| 87873 | + if( pKeyInfo->nAllField<13 |
| 87736 | 87874 | && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl) |
| 87737 | 87875 | ){ |
| 87738 | 87876 | pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; |
| 87739 | 87877 | } |
| 87740 | 87878 | } |
| | @@ -88045,11 +88183,11 @@ |
| 88045 | 88183 | */ |
| 88046 | 88184 | static int vdbeSortAllocUnpacked(SortSubtask *pTask){ |
| 88047 | 88185 | if( pTask->pUnpacked==0 ){ |
| 88048 | 88186 | pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo); |
| 88049 | 88187 | if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT; |
| 88050 | | - pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField; |
| 88188 | + pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nKeyField; |
| 88051 | 88189 | pTask->pUnpacked->errCode = 0; |
| 88052 | 88190 | } |
| 88053 | 88191 | return SQLITE_OK; |
| 88054 | 88192 | } |
| 88055 | 88193 | |
| | @@ -89569,11 +89707,12 @@ |
| 89569 | 89707 | u8 *zOut = zBuf; |
| 89570 | 89708 | int nRead = iAmt; |
| 89571 | 89709 | int iChunkOffset; |
| 89572 | 89710 | FileChunk *pChunk; |
| 89573 | 89711 | |
| 89574 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 89712 | +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 89713 | + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 89575 | 89714 | if( (iAmt+iOfst)>p->endpoint.iOffset ){ |
| 89576 | 89715 | return SQLITE_IOERR_SHORT_READ; |
| 89577 | 89716 | } |
| 89578 | 89717 | #endif |
| 89579 | 89718 | |
| | @@ -89688,11 +89827,12 @@ |
| 89688 | 89827 | ** access writes are not required. The only exception to this is when |
| 89689 | 89828 | ** the in-memory journal is being used by a connection using the |
| 89690 | 89829 | ** atomic-write optimization. In this case the first 28 bytes of the |
| 89691 | 89830 | ** journal file may be written as part of committing the transaction. */ |
| 89692 | 89831 | assert( iOfst==p->endpoint.iOffset || iOfst==0 ); |
| 89693 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 89832 | +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 89833 | + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 89694 | 89834 | if( iOfst==0 && p->pFirst ){ |
| 89695 | 89835 | assert( p->nChunkSize>iAmt ); |
| 89696 | 89836 | memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt); |
| 89697 | 89837 | }else |
| 89698 | 89838 | #else |
| | @@ -89857,21 +89997,35 @@ |
| 89857 | 89997 | */ |
| 89858 | 89998 | SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *pJfd){ |
| 89859 | 89999 | sqlite3JournalOpen(0, 0, pJfd, 0, -1); |
| 89860 | 90000 | } |
| 89861 | 90001 | |
| 89862 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 90002 | +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 90003 | + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 89863 | 90004 | /* |
| 89864 | 90005 | ** If the argument p points to a MemJournal structure that is not an |
| 89865 | 90006 | ** in-memory-only journal file (i.e. is one that was opened with a +ve |
| 89866 | | -** nSpill parameter), and the underlying file has not yet been created, |
| 89867 | | -** create it now. |
| 90007 | +** nSpill parameter or as SQLITE_OPEN_MAIN_JOURNAL), and the underlying |
| 90008 | +** file has not yet been created, create it now. |
| 89868 | 90009 | */ |
| 89869 | | -SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *p){ |
| 90010 | +SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){ |
| 89870 | 90011 | int rc = SQLITE_OK; |
| 89871 | | - if( p->pMethods==&MemJournalMethods && ((MemJournal*)p)->nSpill>0 ){ |
| 89872 | | - rc = memjrnlCreateFile((MemJournal*)p); |
| 90012 | + MemJournal *p = (MemJournal*)pJfd; |
| 90013 | + if( p->pMethod==&MemJournalMethods && ( |
| 90014 | +#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 90015 | + p->nSpill>0 |
| 90016 | +#else |
| 90017 | + /* While this appears to not be possible without ATOMIC_WRITE, the |
| 90018 | + ** paths are complex, so it seems prudent to leave the test in as |
| 90019 | + ** a NEVER(), in case our analysis is subtly flawed. */ |
| 90020 | + NEVER(p->nSpill>0) |
| 90021 | +#endif |
| 90022 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 90023 | + || (p->flags & SQLITE_OPEN_MAIN_JOURNAL) |
| 90024 | +#endif |
| 90025 | + )){ |
| 90026 | + rc = memjrnlCreateFile(p); |
| 89873 | 90027 | } |
| 89874 | 90028 | return rc; |
| 89875 | 90029 | } |
| 89876 | 90030 | #endif |
| 89877 | 90031 | |
| | @@ -89934,22 +90088,26 @@ |
| 89934 | 90088 | */ |
| 89935 | 90089 | static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){ |
| 89936 | 90090 | int rc; |
| 89937 | 90091 | testcase( ExprHasProperty(pExpr, EP_TokenOnly) ); |
| 89938 | 90092 | testcase( ExprHasProperty(pExpr, EP_Reduced) ); |
| 89939 | | - rc = pWalker->xExprCallback(pWalker, pExpr); |
| 89940 | | - if( rc ) return rc & WRC_Abort; |
| 89941 | | - if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){ |
| 89942 | | - if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; |
| 89943 | | - assert( pExpr->x.pList==0 || pExpr->pRight==0 ); |
| 89944 | | - if( pExpr->pRight ){ |
| 89945 | | - if( walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort; |
| 89946 | | - }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 89947 | | - if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; |
| 89948 | | - }else if( pExpr->x.pList ){ |
| 89949 | | - if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; |
| 89950 | | - } |
| 90093 | + while(1){ |
| 90094 | + rc = pWalker->xExprCallback(pWalker, pExpr); |
| 90095 | + if( rc ) return rc & WRC_Abort; |
| 90096 | + if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){ |
| 90097 | + if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; |
| 90098 | + assert( pExpr->x.pList==0 || pExpr->pRight==0 ); |
| 90099 | + if( pExpr->pRight ){ |
| 90100 | + pExpr = pExpr->pRight; |
| 90101 | + continue; |
| 90102 | + }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 90103 | + if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; |
| 90104 | + }else if( pExpr->x.pList ){ |
| 90105 | + if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; |
| 90106 | + } |
| 90107 | + } |
| 90108 | + break; |
| 89951 | 90109 | } |
| 89952 | 90110 | return WRC_Continue; |
| 89953 | 90111 | } |
| 89954 | 90112 | SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){ |
| 89955 | 90113 | return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue; |
| | @@ -92367,11 +92525,11 @@ |
| 92367 | 92525 | int op, /* Expression opcode */ |
| 92368 | 92526 | const char *zToken /* Token argument. Might be NULL */ |
| 92369 | 92527 | ){ |
| 92370 | 92528 | Token x; |
| 92371 | 92529 | x.z = zToken; |
| 92372 | | - x.n = zToken ? sqlite3Strlen30(zToken) : 0; |
| 92530 | + x.n = sqlite3Strlen30(zToken); |
| 92373 | 92531 | return sqlite3ExprAlloc(db, op, &x, 0); |
| 92374 | 92532 | } |
| 92375 | 92533 | |
| 92376 | 92534 | /* |
| 92377 | 92535 | ** Attach subtrees pLeft and pRight to the Expr node pRoot. |
| | @@ -92894,14 +93052,13 @@ |
| 92894 | 93052 | struct ExprList_item *pItem, *pOldItem; |
| 92895 | 93053 | int i; |
| 92896 | 93054 | Expr *pPriorSelectCol = 0; |
| 92897 | 93055 | assert( db!=0 ); |
| 92898 | 93056 | if( p==0 ) return 0; |
| 92899 | | - pNew = sqlite3DbMallocRawNN(db, |
| 92900 | | - sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) ); |
| 93057 | + pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p)); |
| 92901 | 93058 | if( pNew==0 ) return 0; |
| 92902 | | - pNew->nAlloc = pNew->nExpr = p->nExpr; |
| 93059 | + pNew->nExpr = p->nExpr; |
| 92903 | 93060 | pItem = pNew->a; |
| 92904 | 93061 | pOldItem = p->a; |
| 92905 | 93062 | for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){ |
| 92906 | 93063 | Expr *pOldExpr = pOldItem->pExpr; |
| 92907 | 93064 | Expr *pNewExpr; |
| | @@ -93051,10 +93208,17 @@ |
| 93051 | 93208 | |
| 93052 | 93209 | /* |
| 93053 | 93210 | ** Add a new element to the end of an expression list. If pList is |
| 93054 | 93211 | ** initially NULL, then create a new expression list. |
| 93055 | 93212 | ** |
| 93213 | +** The pList argument must be either NULL or a pointer to an ExprList |
| 93214 | +** obtained from a prior call to sqlite3ExprListAppend(). This routine |
| 93215 | +** may not be used with an ExprList obtained from sqlite3ExprListDup(). |
| 93216 | +** Reason: This routine assumes that the number of slots in pList->a[] |
| 93217 | +** is a power of two. That is true for sqlite3ExprListAppend() returns |
| 93218 | +** but is not necessarily true from the return value of sqlite3ExprListDup(). |
| 93219 | +** |
| 93056 | 93220 | ** If a memory allocation error occurs, the entire list is freed and |
| 93057 | 93221 | ** NULL is returned. If non-NULL is returned, then it is guaranteed |
| 93058 | 93222 | ** that the new entry was successfully appended. |
| 93059 | 93223 | */ |
| 93060 | 93224 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend( |
| | @@ -93069,20 +93233,18 @@ |
| 93069 | 93233 | pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) ); |
| 93070 | 93234 | if( pList==0 ){ |
| 93071 | 93235 | goto no_mem; |
| 93072 | 93236 | } |
| 93073 | 93237 | pList->nExpr = 0; |
| 93074 | | - pList->nAlloc = 1; |
| 93075 | | - }else if( pList->nExpr==pList->nAlloc ){ |
| 93238 | + }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 93076 | 93239 | ExprList *pNew; |
| 93077 | 93240 | pNew = sqlite3DbRealloc(db, pList, |
| 93078 | | - sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0])); |
| 93241 | + sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0])); |
| 93079 | 93242 | if( pNew==0 ){ |
| 93080 | 93243 | goto no_mem; |
| 93081 | 93244 | } |
| 93082 | 93245 | pList = pNew; |
| 93083 | | - pList->nAlloc *= 2; |
| 93084 | 93246 | } |
| 93085 | 93247 | pItem = &pList->a[pList->nExpr++]; |
| 93086 | 93248 | assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) ); |
| 93087 | 93249 | assert( offsetof(struct ExprList_item,pExpr)==0 ); |
| 93088 | 93250 | memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName)); |
| | @@ -93278,10 +93440,23 @@ |
| 93278 | 93440 | m |= pExpr->flags; |
| 93279 | 93441 | } |
| 93280 | 93442 | } |
| 93281 | 93443 | return m; |
| 93282 | 93444 | } |
| 93445 | + |
| 93446 | +/* |
| 93447 | +** This is a SELECT-node callback for the expression walker that |
| 93448 | +** always "fails". By "fail" in this case, we mean set |
| 93449 | +** pWalker->eCode to zero and abort. |
| 93450 | +** |
| 93451 | +** This callback is used by multiple expression walkers. |
| 93452 | +*/ |
| 93453 | +SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){ |
| 93454 | + UNUSED_PARAMETER(NotUsed); |
| 93455 | + pWalker->eCode = 0; |
| 93456 | + return WRC_Abort; |
| 93457 | +} |
| 93283 | 93458 | |
| 93284 | 93459 | /* |
| 93285 | 93460 | ** These routines are Walker callbacks used to check expressions to |
| 93286 | 93461 | ** see if they are "constant" for some definition of constant. The |
| 93287 | 93462 | ** Walker.eCode value determines the type of "constant" we are looking |
| | @@ -93355,25 +93530,20 @@ |
| 93355 | 93530 | pWalker->eCode = 0; |
| 93356 | 93531 | return WRC_Abort; |
| 93357 | 93532 | } |
| 93358 | 93533 | /* Fall through */ |
| 93359 | 93534 | default: |
| 93360 | | - testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */ |
| 93361 | | - testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */ |
| 93535 | + testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail will disallow */ |
| 93536 | + testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail will disallow */ |
| 93362 | 93537 | return WRC_Continue; |
| 93363 | 93538 | } |
| 93364 | 93539 | } |
| 93365 | | -static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){ |
| 93366 | | - UNUSED_PARAMETER(NotUsed); |
| 93367 | | - pWalker->eCode = 0; |
| 93368 | | - return WRC_Abort; |
| 93369 | | -} |
| 93370 | 93540 | static int exprIsConst(Expr *p, int initFlag, int iCur){ |
| 93371 | 93541 | Walker w; |
| 93372 | 93542 | w.eCode = initFlag; |
| 93373 | 93543 | w.xExprCallback = exprNodeIsConstant; |
| 93374 | | - w.xSelectCallback = selectNodeIsConstant; |
| 93544 | + w.xSelectCallback = sqlite3SelectWalkFail; |
| 93375 | 93545 | #ifdef SQLITE_DEBUG |
| 93376 | 93546 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 93377 | 93547 | #endif |
| 93378 | 93548 | w.u.iCur = iCur; |
| 93379 | 93549 | sqlite3WalkExpr(&w, p); |
| | @@ -93492,11 +93662,11 @@ |
| 93492 | 93662 | */ |
| 93493 | 93663 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){ |
| 93494 | 93664 | Walker w; |
| 93495 | 93665 | w.eCode = 1; |
| 93496 | 93666 | w.xExprCallback = sqlite3ExprWalkNoop; |
| 93497 | | - w.xSelectCallback = selectNodeIsConstant; |
| 93667 | + w.xSelectCallback = sqlite3SelectWalkFail; |
| 93498 | 93668 | #ifdef SQLITE_DEBUG |
| 93499 | 93669 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 93500 | 93670 | #endif |
| 93501 | 93671 | sqlite3WalkExpr(&w, p); |
| 93502 | 93672 | return w.eCode==0; |
| | @@ -93565,12 +93735,12 @@ |
| 93565 | 93735 | case TK_STRING: |
| 93566 | 93736 | case TK_FLOAT: |
| 93567 | 93737 | case TK_BLOB: |
| 93568 | 93738 | return 0; |
| 93569 | 93739 | case TK_COLUMN: |
| 93570 | | - assert( p->pTab!=0 ); |
| 93571 | 93740 | return ExprHasProperty(p, EP_CanBeNull) || |
| 93741 | + p->pTab==0 || /* Reference to column of index on expression */ |
| 93572 | 93742 | (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0); |
| 93573 | 93743 | default: |
| 93574 | 93744 | return 1; |
| 93575 | 93745 | } |
| 93576 | 93746 | } |
| | @@ -94656,11 +94826,11 @@ |
| 94656 | 94826 | int c; |
| 94657 | 94827 | i64 value; |
| 94658 | 94828 | const char *z = pExpr->u.zToken; |
| 94659 | 94829 | assert( z!=0 ); |
| 94660 | 94830 | c = sqlite3DecOrHexToI64(z, &value); |
| 94661 | | - if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){ |
| 94831 | + if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){ |
| 94662 | 94832 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 94663 | 94833 | sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| 94664 | 94834 | #else |
| 94665 | 94835 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 94666 | 94836 | if( sqlite3_strnicmp(z,"0x",2)==0 ){ |
| | @@ -94670,11 +94840,11 @@ |
| 94670 | 94840 | { |
| 94671 | 94841 | codeReal(v, z, negFlag, iMem); |
| 94672 | 94842 | } |
| 94673 | 94843 | #endif |
| 94674 | 94844 | }else{ |
| 94675 | | - if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } |
| 94845 | + if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; } |
| 94676 | 94846 | sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64); |
| 94677 | 94847 | } |
| 94678 | 94848 | } |
| 94679 | 94849 | } |
| 94680 | 94850 | |
| | @@ -95825,11 +95995,13 @@ |
| 95825 | 95995 | |
| 95826 | 95996 | /* |
| 95827 | 95997 | ** Generate code that pushes the value of every element of the given |
| 95828 | 95998 | ** expression list into a sequence of registers beginning at target. |
| 95829 | 95999 | ** |
| 95830 | | -** Return the number of elements evaluated. |
| 96000 | +** Return the number of elements evaluated. The number returned will |
| 96001 | +** usually be pList->nExpr but might be reduced if SQLITE_ECEL_OMITREF |
| 96002 | +** is defined. |
| 95831 | 96003 | ** |
| 95832 | 96004 | ** The SQLITE_ECEL_DUP flag prevents the arguments from being |
| 95833 | 96005 | ** filled using OP_SCopy. OP_Copy must be used instead. |
| 95834 | 96006 | ** |
| 95835 | 96007 | ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be |
| | @@ -95836,10 +96008,12 @@ |
| 95836 | 96008 | ** factored out into initialization code. |
| 95837 | 96009 | ** |
| 95838 | 96010 | ** The SQLITE_ECEL_REF flag means that expressions in the list with |
| 95839 | 96011 | ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored |
| 95840 | 96012 | ** in registers at srcReg, and so the value can be copied from there. |
| 96013 | +** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0 |
| 96014 | +** are simply omitted rather than being copied from srcReg. |
| 95841 | 96015 | */ |
| 95842 | 96016 | SQLITE_PRIVATE int sqlite3ExprCodeExprList( |
| 95843 | 96017 | Parse *pParse, /* Parsing context */ |
| 95844 | 96018 | ExprList *pList, /* The expression list to be coded */ |
| 95845 | 96019 | int target, /* Where to write results */ |
| | @@ -97269,22 +97443,22 @@ |
| 97269 | 97443 | Vdbe *v; |
| 97270 | 97444 | #ifndef SQLITE_OMIT_TRIGGER |
| 97271 | 97445 | char *zWhere = 0; /* Where clause to locate temp triggers */ |
| 97272 | 97446 | #endif |
| 97273 | 97447 | VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */ |
| 97274 | | - int savedDbFlags; /* Saved value of db->flags */ |
| 97448 | + u32 savedDbFlags; /* Saved value of db->mDbFlags */ |
| 97275 | 97449 | |
| 97276 | | - savedDbFlags = db->flags; |
| 97450 | + savedDbFlags = db->mDbFlags; |
| 97277 | 97451 | if( NEVER(db->mallocFailed) ) goto exit_rename_table; |
| 97278 | 97452 | assert( pSrc->nSrc==1 ); |
| 97279 | 97453 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 97280 | 97454 | |
| 97281 | 97455 | pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); |
| 97282 | 97456 | if( !pTab ) goto exit_rename_table; |
| 97283 | 97457 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 97284 | 97458 | zDb = db->aDb[iDb].zDbSName; |
| 97285 | | - db->flags |= SQLITE_PreferBuiltin; |
| 97459 | + db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 97286 | 97460 | |
| 97287 | 97461 | /* Get a NULL terminated version of the new table name. */ |
| 97288 | 97462 | zName = sqlite3NameFromToken(db, pName); |
| 97289 | 97463 | if( !zName ) goto exit_rename_table; |
| 97290 | 97464 | |
| | @@ -97445,11 +97619,11 @@ |
| 97445 | 97619 | reloadTableSchema(pParse, pTab, zName); |
| 97446 | 97620 | |
| 97447 | 97621 | exit_rename_table: |
| 97448 | 97622 | sqlite3SrcListDelete(db, pSrc); |
| 97449 | 97623 | sqlite3DbFree(db, zName); |
| 97450 | | - db->flags = savedDbFlags; |
| 97624 | + db->mDbFlags = savedDbFlags; |
| 97451 | 97625 | } |
| 97452 | 97626 | |
| 97453 | 97627 | /* |
| 97454 | 97628 | ** This function is called after an "ALTER TABLE ... ADD" statement |
| 97455 | 97629 | ** has been parsed. Argument pColDef contains the text of the new |
| | @@ -97546,24 +97720,24 @@ |
| 97546 | 97720 | |
| 97547 | 97721 | /* Modify the CREATE TABLE statement. */ |
| 97548 | 97722 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| 97549 | 97723 | if( zCol ){ |
| 97550 | 97724 | char *zEnd = &zCol[pColDef->n-1]; |
| 97551 | | - int savedDbFlags = db->flags; |
| 97725 | + u32 savedDbFlags = db->mDbFlags; |
| 97552 | 97726 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 97553 | 97727 | *zEnd-- = '\0'; |
| 97554 | 97728 | } |
| 97555 | | - db->flags |= SQLITE_PreferBuiltin; |
| 97729 | + db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 97556 | 97730 | sqlite3NestedParse(pParse, |
| 97557 | 97731 | "UPDATE \"%w\".%s SET " |
| 97558 | 97732 | "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) " |
| 97559 | 97733 | "WHERE type = 'table' AND name = %Q", |
| 97560 | 97734 | zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1, |
| 97561 | 97735 | zTab |
| 97562 | 97736 | ); |
| 97563 | 97737 | sqlite3DbFree(db, zCol); |
| 97564 | | - db->flags = savedDbFlags; |
| 97738 | + db->mDbFlags = savedDbFlags; |
| 97565 | 97739 | } |
| 97566 | 97740 | |
| 97567 | 97741 | /* Make sure the schema version is at least 3. But do not upgrade |
| 97568 | 97742 | ** from less than 3 to 4, as that will corrupt any preexisting DESC |
| 97569 | 97743 | ** index. |
| | @@ -99684,14 +99858,10 @@ |
| 99684 | 99858 | zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", |
| 99685 | 99859 | db->aLimit[SQLITE_LIMIT_ATTACHED] |
| 99686 | 99860 | ); |
| 99687 | 99861 | goto attach_error; |
| 99688 | 99862 | } |
| 99689 | | - if( !db->autoCommit ){ |
| 99690 | | - zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction"); |
| 99691 | | - goto attach_error; |
| 99692 | | - } |
| 99693 | 99863 | for(i=0; i<db->nDb; i++){ |
| 99694 | 99864 | char *z = db->aDb[i].zDbSName; |
| 99695 | 99865 | assert( z && zName ); |
| 99696 | 99866 | if( sqlite3StrICmp(z, zName)==0 ){ |
| 99697 | 99867 | zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); |
| | @@ -99879,15 +100049,10 @@ |
| 99879 | 100049 | } |
| 99880 | 100050 | if( i<2 ){ |
| 99881 | 100051 | sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName); |
| 99882 | 100052 | goto detach_error; |
| 99883 | 100053 | } |
| 99884 | | - if( !db->autoCommit ){ |
| 99885 | | - sqlite3_snprintf(sizeof(zErr), zErr, |
| 99886 | | - "cannot DETACH database within transaction"); |
| 99887 | | - goto detach_error; |
| 99888 | | - } |
| 99889 | 100054 | if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){ |
| 99890 | 100055 | sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); |
| 99891 | 100056 | goto detach_error; |
| 99892 | 100057 | } |
| 99893 | 100058 | |
| | @@ -100296,15 +100461,13 @@ |
| 100296 | 100461 | #ifdef SQLITE_USER_AUTHENTICATION |
| 100297 | 100462 | ,db->auth.zAuthUser |
| 100298 | 100463 | #endif |
| 100299 | 100464 | ); |
| 100300 | 100465 | if( rc==SQLITE_DENY ){ |
| 100301 | | - if( db->nDb>2 || iDb!=0 ){ |
| 100302 | | - sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol); |
| 100303 | | - }else{ |
| 100304 | | - sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol); |
| 100305 | | - } |
| 100466 | + char *z = sqlite3_mprintf("%s.%s", zTab, zCol); |
| 100467 | + if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z); |
| 100468 | + sqlite3ErrorMsg(pParse, "access to %z is prohibited", z); |
| 100306 | 100469 | pParse->rc = SQLITE_AUTH; |
| 100307 | 100470 | }else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){ |
| 100308 | 100471 | sqliteAuthBadReturnCode(pParse); |
| 100309 | 100472 | } |
| 100310 | 100473 | return rc; |
| | @@ -100933,11 +101096,11 @@ |
| 100933 | 101096 | p->pNext = pIndex->pNext; |
| 100934 | 101097 | } |
| 100935 | 101098 | } |
| 100936 | 101099 | freeIndex(db, pIndex); |
| 100937 | 101100 | } |
| 100938 | | - db->flags |= SQLITE_InternChanges; |
| 101101 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 100939 | 101102 | } |
| 100940 | 101103 | |
| 100941 | 101104 | /* |
| 100942 | 101105 | ** Look through the list of open database files in db->aDb[] and if |
| 100943 | 101106 | ** any have been closed, remove them from the list. Reallocate the |
| | @@ -100968,58 +101131,57 @@ |
| 100968 | 101131 | } |
| 100969 | 101132 | } |
| 100970 | 101133 | |
| 100971 | 101134 | /* |
| 100972 | 101135 | ** Reset the schema for the database at index iDb. Also reset the |
| 100973 | | -** TEMP schema. |
| 101136 | +** TEMP schema. The reset is deferred if db->nSchemaLock is not zero. |
| 101137 | +** Deferred resets may be run by calling with iDb<0. |
| 100974 | 101138 | */ |
| 100975 | 101139 | SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){ |
| 100976 | | - Db *pDb; |
| 101140 | + int i; |
| 100977 | 101141 | assert( iDb<db->nDb ); |
| 100978 | 101142 | |
| 100979 | | - /* Case 1: Reset the single schema identified by iDb */ |
| 100980 | | - pDb = &db->aDb[iDb]; |
| 100981 | | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 100982 | | - assert( pDb->pSchema!=0 ); |
| 100983 | | - sqlite3SchemaClear(pDb->pSchema); |
| 100984 | | - |
| 100985 | | - /* If any database other than TEMP is reset, then also reset TEMP |
| 100986 | | - ** since TEMP might be holding triggers that reference tables in the |
| 100987 | | - ** other database. |
| 100988 | | - */ |
| 100989 | | - if( iDb!=1 ){ |
| 100990 | | - pDb = &db->aDb[1]; |
| 100991 | | - assert( pDb->pSchema!=0 ); |
| 100992 | | - sqlite3SchemaClear(pDb->pSchema); |
| 100993 | | - } |
| 100994 | | - return; |
| 101143 | + if( iDb>=0 ){ |
| 101144 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 101145 | + DbSetProperty(db, iDb, DB_ResetWanted); |
| 101146 | + DbSetProperty(db, 1, DB_ResetWanted); |
| 101147 | + } |
| 101148 | + |
| 101149 | + if( db->nSchemaLock==0 ){ |
| 101150 | + for(i=0; i<db->nDb; i++){ |
| 101151 | + if( DbHasProperty(db, i, DB_ResetWanted) ){ |
| 101152 | + sqlite3SchemaClear(db->aDb[i].pSchema); |
| 101153 | + } |
| 101154 | + } |
| 101155 | + } |
| 100995 | 101156 | } |
| 100996 | 101157 | |
| 100997 | 101158 | /* |
| 100998 | 101159 | ** Erase all schema information from all attached databases (including |
| 100999 | 101160 | ** "main" and "temp") for a single database connection. |
| 101000 | 101161 | */ |
| 101001 | 101162 | SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){ |
| 101002 | 101163 | int i; |
| 101003 | 101164 | sqlite3BtreeEnterAll(db); |
| 101165 | + assert( db->nSchemaLock==0 ); |
| 101004 | 101166 | for(i=0; i<db->nDb; i++){ |
| 101005 | 101167 | Db *pDb = &db->aDb[i]; |
| 101006 | 101168 | if( pDb->pSchema ){ |
| 101007 | 101169 | sqlite3SchemaClear(pDb->pSchema); |
| 101008 | 101170 | } |
| 101009 | 101171 | } |
| 101010 | | - db->flags &= ~SQLITE_InternChanges; |
| 101172 | + db->mDbFlags &= ~DBFLAG_SchemaChange; |
| 101011 | 101173 | sqlite3VtabUnlockList(db); |
| 101012 | 101174 | sqlite3BtreeLeaveAll(db); |
| 101013 | 101175 | sqlite3CollapseDatabaseArray(db); |
| 101014 | 101176 | } |
| 101015 | 101177 | |
| 101016 | 101178 | /* |
| 101017 | 101179 | ** This routine is called when a commit occurs. |
| 101018 | 101180 | */ |
| 101019 | 101181 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ |
| 101020 | | - db->flags &= ~SQLITE_InternChanges; |
| 101182 | + db->mDbFlags &= ~DBFLAG_SchemaChange; |
| 101021 | 101183 | } |
| 101022 | 101184 | |
| 101023 | 101185 | /* |
| 101024 | 101186 | ** Delete memory allocated for the column names of a table or view (the |
| 101025 | 101187 | ** Table.aCol[] array). |
| | @@ -101053,17 +101215,20 @@ |
| 101053 | 101215 | ** db parameter can be used with db->pnBytesFreed to measure the memory |
| 101054 | 101216 | ** used by the Table object. |
| 101055 | 101217 | */ |
| 101056 | 101218 | static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){ |
| 101057 | 101219 | Index *pIndex, *pNext; |
| 101058 | | - TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */ |
| 101059 | 101220 | |
| 101221 | +#ifdef SQLITE_DEBUG |
| 101060 | 101222 | /* Record the number of outstanding lookaside allocations in schema Tables |
| 101061 | 101223 | ** prior to doing any free() operations. Since schema Tables do not use |
| 101062 | 101224 | ** lookaside, this number should not change. */ |
| 101063 | | - TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ? |
| 101064 | | - db->lookaside.nOut : 0 ); |
| 101225 | + int nLookaside = 0; |
| 101226 | + if( db && (pTable->tabFlags & TF_Ephemeral)==0 ){ |
| 101227 | + nLookaside = sqlite3LookasideUsed(db, 0); |
| 101228 | + } |
| 101229 | +#endif |
| 101065 | 101230 | |
| 101066 | 101231 | /* Delete all indices associated with this table. */ |
| 101067 | 101232 | for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){ |
| 101068 | 101233 | pNext = pIndex->pNext; |
| 101069 | 101234 | assert( pIndex->pSchema==pTable->pSchema |
| | @@ -101093,11 +101258,11 @@ |
| 101093 | 101258 | sqlite3VtabClear(db, pTable); |
| 101094 | 101259 | #endif |
| 101095 | 101260 | sqlite3DbFree(db, pTable); |
| 101096 | 101261 | |
| 101097 | 101262 | /* Verify that no lookaside memory was used by schema tables */ |
| 101098 | | - assert( nLookaside==0 || nLookaside==db->lookaside.nOut ); |
| 101263 | + assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) ); |
| 101099 | 101264 | } |
| 101100 | 101265 | SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ |
| 101101 | 101266 | /* Do not delete the table until the reference count reaches zero. */ |
| 101102 | 101267 | if( !pTable ) return; |
| 101103 | 101268 | if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return; |
| | @@ -101119,11 +101284,11 @@ |
| 101119 | 101284 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 101120 | 101285 | testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */ |
| 101121 | 101286 | pDb = &db->aDb[iDb]; |
| 101122 | 101287 | p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0); |
| 101123 | 101288 | sqlite3DeleteTable(db, p); |
| 101124 | | - db->flags |= SQLITE_InternChanges; |
| 101289 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 101125 | 101290 | } |
| 101126 | 101291 | |
| 101127 | 101292 | /* |
| 101128 | 101293 | ** Given a token, return a string that consists of the text of that |
| 101129 | 101294 | ** token. Space to hold the returned string |
| | @@ -101232,11 +101397,12 @@ |
| 101232 | 101397 | if( iDb<0 ){ |
| 101233 | 101398 | sqlite3ErrorMsg(pParse, "unknown database %T", pName1); |
| 101234 | 101399 | return -1; |
| 101235 | 101400 | } |
| 101236 | 101401 | }else{ |
| 101237 | | - assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0); |
| 101402 | + assert( db->init.iDb==0 || db->init.busy |
| 101403 | + || (db->mDbFlags & DBFLAG_Vacuum)!=0); |
| 101238 | 101404 | iDb = db->init.iDb; |
| 101239 | 101405 | *pUnqual = pName1; |
| 101240 | 101406 | } |
| 101241 | 101407 | return iDb; |
| 101242 | 101408 | } |
| | @@ -101464,11 +101630,12 @@ |
| 101464 | 101630 | if( isView || isVirtual ){ |
| 101465 | 101631 | sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2); |
| 101466 | 101632 | }else |
| 101467 | 101633 | #endif |
| 101468 | 101634 | { |
| 101469 | | - pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2); |
| 101635 | + pParse->addrCrTab = |
| 101636 | + sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 101470 | 101637 | } |
| 101471 | 101638 | sqlite3OpenMasterTable(pParse, iDb); |
| 101472 | 101639 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 101473 | 101640 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| 101474 | 101641 | sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1); |
| | @@ -102124,21 +102291,20 @@ |
| 102124 | 102291 | ** internal schema data structures and the generated VDBE code so that they |
| 102125 | 102292 | ** are appropriate for a WITHOUT ROWID table instead of a rowid table. |
| 102126 | 102293 | ** Changes include: |
| 102127 | 102294 | ** |
| 102128 | 102295 | ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL. |
| 102129 | | -** (2) Convert the OP_CreateTable into an OP_CreateIndex. There is |
| 102130 | | -** no rowid btree for a WITHOUT ROWID. Instead, the canonical |
| 102131 | | -** data storage is a covering index btree. |
| 102296 | +** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY |
| 102297 | +** into BTREE_BLOBKEY. |
| 102132 | 102298 | ** (3) Bypass the creation of the sqlite_master table entry |
| 102133 | 102299 | ** for the PRIMARY KEY as the primary key index is now |
| 102134 | 102300 | ** identified by the sqlite_master table entry of the table itself. |
| 102135 | 102301 | ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the |
| 102136 | 102302 | ** schema to the rootpage from the main table. |
| 102137 | 102303 | ** (5) Add all table columns to the PRIMARY KEY Index object |
| 102138 | 102304 | ** so that the PRIMARY KEY is a covering index. The surplus |
| 102139 | | -** columns are part of KeyInfo.nXField and are not used for |
| 102305 | +** columns are part of KeyInfo.nAllField and are not used for |
| 102140 | 102306 | ** sorting or lookup or uniqueness checks. |
| 102141 | 102307 | ** (6) Replace the rowid tail on all automatically generated UNIQUE |
| 102142 | 102308 | ** indices with the PRIMARY KEY columns. |
| 102143 | 102309 | ** |
| 102144 | 102310 | ** For virtual tables, only (1) is performed. |
| | @@ -102163,17 +102329,16 @@ |
| 102163 | 102329 | |
| 102164 | 102330 | /* The remaining transformations only apply to b-tree tables, not to |
| 102165 | 102331 | ** virtual tables */ |
| 102166 | 102332 | if( IN_DECLARE_VTAB ) return; |
| 102167 | 102333 | |
| 102168 | | - /* Convert the OP_CreateTable opcode that would normally create the |
| 102169 | | - ** root-page for the table into an OP_CreateIndex opcode. The index |
| 102170 | | - ** created will become the PRIMARY KEY index. |
| 102334 | + /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY |
| 102335 | + ** into BTREE_BLOBKEY. |
| 102171 | 102336 | */ |
| 102172 | 102337 | if( pParse->addrCrTab ){ |
| 102173 | 102338 | assert( v ); |
| 102174 | | - sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex); |
| 102339 | + sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY); |
| 102175 | 102340 | } |
| 102176 | 102341 | |
| 102177 | 102342 | /* Locate the PRIMARY KEY index. Or, if this table was originally |
| 102178 | 102343 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 102179 | 102344 | */ |
| | @@ -102509,11 +102674,11 @@ |
| 102509 | 102674 | assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 102510 | 102675 | sqlite3OomFault(db); |
| 102511 | 102676 | return; |
| 102512 | 102677 | } |
| 102513 | 102678 | pParse->pNewTable = 0; |
| 102514 | | - db->flags |= SQLITE_InternChanges; |
| 102679 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 102515 | 102680 | |
| 102516 | 102681 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 102517 | 102682 | if( !p->pSelect ){ |
| 102518 | 102683 | const char *zName = (const char *)pParse->sNameToken.z; |
| 102519 | 102684 | int nName; |
| | @@ -102608,19 +102773,25 @@ |
| 102608 | 102773 | Table *pSelTab; /* A fake table from which we get the result set */ |
| 102609 | 102774 | Select *pSel; /* Copy of the SELECT that implements the view */ |
| 102610 | 102775 | int nErr = 0; /* Number of errors encountered */ |
| 102611 | 102776 | int n; /* Temporarily holds the number of cursors assigned */ |
| 102612 | 102777 | sqlite3 *db = pParse->db; /* Database connection for malloc errors */ |
| 102778 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 102779 | + int rc; |
| 102780 | +#endif |
| 102613 | 102781 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 102614 | 102782 | sqlite3_xauth xAuth; /* Saved xAuth pointer */ |
| 102615 | 102783 | #endif |
| 102616 | 102784 | |
| 102617 | 102785 | assert( pTable ); |
| 102618 | 102786 | |
| 102619 | 102787 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 102620 | | - if( sqlite3VtabCallConnect(pParse, pTable) ){ |
| 102621 | | - return SQLITE_ERROR; |
| 102788 | + db->nSchemaLock++; |
| 102789 | + rc = sqlite3VtabCallConnect(pParse, pTable); |
| 102790 | + db->nSchemaLock--; |
| 102791 | + if( rc ){ |
| 102792 | + return 1; |
| 102622 | 102793 | } |
| 102623 | 102794 | if( IsVirtual(pTable) ) return 0; |
| 102624 | 102795 | #endif |
| 102625 | 102796 | |
| 102626 | 102797 | #ifndef SQLITE_OMIT_VIEW |
| | @@ -103289,11 +103460,11 @@ |
| 103289 | 103460 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 103290 | 103461 | }else{ |
| 103291 | 103462 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 103292 | 103463 | } |
| 103293 | 103464 | sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); |
| 103294 | | - sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1); |
| 103465 | + sqlite3VdbeAddOp1(v, OP_SeekEnd, iIdx); |
| 103295 | 103466 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord); |
| 103296 | 103467 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 103297 | 103468 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 103298 | 103469 | sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 103299 | 103470 | sqlite3VdbeJumpHere(v, addr1); |
| | @@ -103778,11 +103949,11 @@ |
| 103778 | 103949 | if( p ){ |
| 103779 | 103950 | assert( p==pIndex ); /* Malloc must have failed */ |
| 103780 | 103951 | sqlite3OomFault(db); |
| 103781 | 103952 | goto exit_create_index; |
| 103782 | 103953 | } |
| 103783 | | - db->flags |= SQLITE_InternChanges; |
| 103954 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 103784 | 103955 | if( pTblName!=0 ){ |
| 103785 | 103956 | pIndex->tnum = db->init.newTnum; |
| 103786 | 103957 | } |
| 103787 | 103958 | } |
| 103788 | 103959 | |
| | @@ -103814,11 +103985,11 @@ |
| 103814 | 103985 | ** Index.tnum. This is required in case this index is actually a |
| 103815 | 103986 | ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In |
| 103816 | 103987 | ** that case the convertToWithoutRowidTable() routine will replace |
| 103817 | 103988 | ** the Noop with a Goto to jump over the VDBE code generated below. */ |
| 103818 | 103989 | pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop); |
| 103819 | | - sqlite3VdbeAddOp2(v, OP_CreateIndex, iDb, iMem); |
| 103990 | + sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY); |
| 103820 | 103991 | |
| 103821 | 103992 | /* Gather the complete text of the CREATE INDEX statement into |
| 103822 | 103993 | ** the zStmt variable |
| 103823 | 103994 | */ |
| 103824 | 103995 | if( pStart ){ |
| | @@ -104336,22 +104507,24 @@ |
| 104336 | 104507 | ** Add an INDEXED BY or NOT INDEXED clause to the most recently added |
| 104337 | 104508 | ** element of the source-list passed as the second argument. |
| 104338 | 104509 | */ |
| 104339 | 104510 | SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){ |
| 104340 | 104511 | assert( pIndexedBy!=0 ); |
| 104341 | | - if( p && ALWAYS(p->nSrc>0) ){ |
| 104342 | | - struct SrcList_item *pItem = &p->a[p->nSrc-1]; |
| 104512 | + if( p && pIndexedBy->n>0 ){ |
| 104513 | + struct SrcList_item *pItem; |
| 104514 | + assert( p->nSrc>0 ); |
| 104515 | + pItem = &p->a[p->nSrc-1]; |
| 104343 | 104516 | assert( pItem->fg.notIndexed==0 ); |
| 104344 | 104517 | assert( pItem->fg.isIndexedBy==0 ); |
| 104345 | 104518 | assert( pItem->fg.isTabFunc==0 ); |
| 104346 | 104519 | if( pIndexedBy->n==1 && !pIndexedBy->z ){ |
| 104347 | 104520 | /* A "NOT INDEXED" clause was supplied. See parse.y |
| 104348 | 104521 | ** construct "indexed_opt" for details. */ |
| 104349 | 104522 | pItem->fg.notIndexed = 1; |
| 104350 | 104523 | }else{ |
| 104351 | 104524 | pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy); |
| 104352 | | - pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0); |
| 104525 | + pItem->fg.isIndexedBy = 1; |
| 104353 | 104526 | } |
| 104354 | 104527 | } |
| 104355 | 104528 | } |
| 104356 | 104529 | |
| 104357 | 104530 | /* |
| | @@ -105272,21 +105445,21 @@ |
| 105272 | 105445 | p = p->pNext; |
| 105273 | 105446 | } |
| 105274 | 105447 | |
| 105275 | 105448 | /* If no match is found, search the built-in functions. |
| 105276 | 105449 | ** |
| 105277 | | - ** If the SQLITE_PreferBuiltin flag is set, then search the built-in |
| 105450 | + ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in |
| 105278 | 105451 | ** functions even if a prior app-defined function was found. And give |
| 105279 | 105452 | ** priority to built-in functions. |
| 105280 | 105453 | ** |
| 105281 | 105454 | ** Except, if createFlag is true, that means that we are trying to |
| 105282 | 105455 | ** install a new function. Whatever FuncDef structure is returned it will |
| 105283 | 105456 | ** have fields overwritten with new information appropriate for the |
| 105284 | 105457 | ** new function. But the FuncDefs for built-in functions are read-only. |
| 105285 | 105458 | ** So we must not search for built-ins when creating a new function. |
| 105286 | 105459 | */ |
| 105287 | | - if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){ |
| 105460 | + if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){ |
| 105288 | 105461 | bestScore = 0; |
| 105289 | 105462 | h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % SQLITE_FUNC_HASH_SZ; |
| 105290 | 105463 | p = functionSearch(h, zName); |
| 105291 | 105464 | while( p ){ |
| 105292 | 105465 | int score = matchQuality(p, nArg, enc); |
| | @@ -105355,12 +105528,12 @@ |
| 105355 | 105528 | sqlite3HashClear(&temp1); |
| 105356 | 105529 | sqlite3HashClear(&pSchema->fkeyHash); |
| 105357 | 105530 | pSchema->pSeqTab = 0; |
| 105358 | 105531 | if( pSchema->schemaFlags & DB_SchemaLoaded ){ |
| 105359 | 105532 | pSchema->iGeneration++; |
| 105360 | | - pSchema->schemaFlags &= ~DB_SchemaLoaded; |
| 105361 | 105533 | } |
| 105534 | + pSchema->schemaFlags &= ~(DB_SchemaLoaded|DB_ResetWanted); |
| 105362 | 105535 | } |
| 105363 | 105536 | |
| 105364 | 105537 | /* |
| 105365 | 105538 | ** Find and return the schema associated with a BTree. Create |
| 105366 | 105539 | ** a new one if necessary. |
| | @@ -105888,11 +106061,15 @@ |
| 105888 | 106061 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 105889 | 106062 | VdbeCoverage(v); |
| 105890 | 106063 | } |
| 105891 | 106064 | }else if( pPk ){ |
| 105892 | 106065 | addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v); |
| 105893 | | - sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey); |
| 106066 | + if( IsVirtual(pTab) ){ |
| 106067 | + sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey); |
| 106068 | + }else{ |
| 106069 | + sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey); |
| 106070 | + } |
| 105894 | 106071 | assert( nKey==0 ); /* OP_Found will use a composite key */ |
| 105895 | 106072 | }else{ |
| 105896 | 106073 | addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey); |
| 105897 | 106074 | VdbeCoverage(v); |
| 105898 | 106075 | assert( nKey==1 ); |
| | @@ -107159,11 +107336,12 @@ |
| 107159 | 107336 | } |
| 107160 | 107337 | if( zA && zB ){ |
| 107161 | 107338 | #ifdef SQLITE_TEST |
| 107162 | 107339 | sqlite3_like_count++; |
| 107163 | 107340 | #endif |
| 107164 | | - sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH); |
| 107341 | + sqlite3_result_int(context, |
| 107342 | + patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH); |
| 107165 | 107343 | } |
| 107166 | 107344 | } |
| 107167 | 107345 | |
| 107168 | 107346 | /* |
| 107169 | 107347 | ** Implementation of the NULLIF(x,y) function. The result is the first |
| | @@ -108000,32 +108178,46 @@ |
| 108000 | 108178 | } |
| 108001 | 108179 | |
| 108002 | 108180 | /* |
| 108003 | 108181 | ** pExpr points to an expression which implements a function. If |
| 108004 | 108182 | ** it is appropriate to apply the LIKE optimization to that function |
| 108005 | | -** then set aWc[0] through aWc[2] to the wildcard characters and |
| 108006 | | -** return TRUE. If the function is not a LIKE-style function then |
| 108007 | | -** return FALSE. |
| 108183 | +** then set aWc[0] through aWc[2] to the wildcard characters and the |
| 108184 | +** escape character and then return TRUE. If the function is not a |
| 108185 | +** LIKE-style function then return FALSE. |
| 108186 | +** |
| 108187 | +** The expression "a LIKE b ESCAPE c" is only considered a valid LIKE |
| 108188 | +** operator if c is a string literal that is exactly one byte in length. |
| 108189 | +** That one byte is stored in aWc[3]. aWc[3] is set to zero if there is |
| 108190 | +** no ESCAPE clause. |
| 108008 | 108191 | ** |
| 108009 | 108192 | ** *pIsNocase is set to true if uppercase and lowercase are equivalent for |
| 108010 | 108193 | ** the function (default for LIKE). If the function makes the distinction |
| 108011 | 108194 | ** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to |
| 108012 | 108195 | ** false. |
| 108013 | 108196 | */ |
| 108014 | 108197 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ |
| 108015 | 108198 | FuncDef *pDef; |
| 108016 | | - if( pExpr->op!=TK_FUNCTION |
| 108017 | | - || !pExpr->x.pList |
| 108018 | | - || pExpr->x.pList->nExpr!=2 |
| 108019 | | - ){ |
| 108199 | + int nExpr; |
| 108200 | + if( pExpr->op!=TK_FUNCTION || !pExpr->x.pList ){ |
| 108020 | 108201 | return 0; |
| 108021 | 108202 | } |
| 108022 | 108203 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 108023 | | - pDef = sqlite3FindFunction(db, pExpr->u.zToken, 2, SQLITE_UTF8, 0); |
| 108204 | + nExpr = pExpr->x.pList->nExpr; |
| 108205 | + pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0); |
| 108024 | 108206 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ |
| 108025 | 108207 | return 0; |
| 108026 | 108208 | } |
| 108209 | + if( nExpr<3 ){ |
| 108210 | + aWc[3] = 0; |
| 108211 | + }else{ |
| 108212 | + Expr *pEscape = pExpr->x.pList->a[2].pExpr; |
| 108213 | + char *zEscape; |
| 108214 | + if( pEscape->op!=TK_STRING ) return 0; |
| 108215 | + zEscape = pEscape->u.zToken; |
| 108216 | + if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; |
| 108217 | + aWc[3] = zEscape[0]; |
| 108218 | + } |
| 108027 | 108219 | |
| 108028 | 108220 | /* The memcpy() statement assumes that the wildcard characters are |
| 108029 | 108221 | ** the first three statements in the compareInfo structure. The |
| 108030 | 108222 | ** asserts() that follow verify that assumption |
| 108031 | 108223 | */ |
| | @@ -109821,11 +110013,11 @@ |
| 109821 | 110013 | int iDb, /* Index of the database holding pTab */ |
| 109822 | 110014 | Table *pTab /* The table we are writing to */ |
| 109823 | 110015 | ){ |
| 109824 | 110016 | int memId = 0; /* Register holding maximum rowid */ |
| 109825 | 110017 | if( (pTab->tabFlags & TF_Autoincrement)!=0 |
| 109826 | | - && (pParse->db->flags & SQLITE_Vacuum)==0 |
| 110018 | + && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0 |
| 109827 | 110019 | ){ |
| 109828 | 110020 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 109829 | 110021 | AutoincInfo *pInfo; |
| 109830 | 110022 | |
| 109831 | 110023 | pInfo = pToplevel->pAinc; |
| | @@ -111654,11 +111846,11 @@ |
| 111654 | 111846 | } |
| 111655 | 111847 | for(i=0; i<pDest->nCol; i++){ |
| 111656 | 111848 | Column *pDestCol = &pDest->aCol[i]; |
| 111657 | 111849 | Column *pSrcCol = &pSrc->aCol[i]; |
| 111658 | 111850 | #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS |
| 111659 | | - if( (db->flags & SQLITE_Vacuum)==0 |
| 111851 | + if( (db->mDbFlags & DBFLAG_Vacuum)==0 |
| 111660 | 111852 | && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN |
| 111661 | 111853 | ){ |
| 111662 | 111854 | return 0; /* Neither table may have __hidden__ columns */ |
| 111663 | 111855 | } |
| 111664 | 111856 | #endif |
| | @@ -111730,19 +111922,19 @@ |
| 111730 | 111922 | regAutoinc = autoIncBegin(pParse, iDbDest, pDest); |
| 111731 | 111923 | regData = sqlite3GetTempReg(pParse); |
| 111732 | 111924 | regRowid = sqlite3GetTempReg(pParse); |
| 111733 | 111925 | sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); |
| 111734 | 111926 | assert( HasRowid(pDest) || destHasUniqueIdx ); |
| 111735 | | - if( (db->flags & SQLITE_Vacuum)==0 && ( |
| 111927 | + if( (db->mDbFlags & DBFLAG_Vacuum)==0 && ( |
| 111736 | 111928 | (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ |
| 111737 | 111929 | || destHasUniqueIdx /* (2) */ |
| 111738 | 111930 | || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ |
| 111739 | 111931 | )){ |
| 111740 | 111932 | /* In some circumstances, we are able to run the xfer optimization |
| 111741 | 111933 | ** only if the destination table is initially empty. Unless the |
| 111742 | | - ** SQLITE_Vacuum flag is set, this block generates code to make |
| 111743 | | - ** that determination. If SQLITE_Vacuum is set, then the destination |
| 111934 | + ** DBFLAG_Vacuum flag is set, this block generates code to make |
| 111935 | + ** that determination. If DBFLAG_Vacuum is set, then the destination |
| 111744 | 111936 | ** table is always empty. |
| 111745 | 111937 | ** |
| 111746 | 111938 | ** Conditions under which the destination must be empty: |
| 111747 | 111939 | ** |
| 111748 | 111940 | ** (1) There is no INTEGER PRIMARY KEY but there are indices. |
| | @@ -111774,12 +111966,12 @@ |
| 111774 | 111966 | }else{ |
| 111775 | 111967 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 111776 | 111968 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 111777 | 111969 | } |
| 111778 | 111970 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 111779 | | - if( db->flags & SQLITE_Vacuum ){ |
| 111780 | | - sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 111971 | + if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 111972 | + sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 111781 | 111973 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| |
| 111782 | 111974 | OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 111783 | 111975 | }else{ |
| 111784 | 111976 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND; |
| 111785 | 111977 | } |
| | @@ -111806,17 +111998,17 @@ |
| 111806 | 111998 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 111807 | 111999 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 111808 | 112000 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 111809 | 112001 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 111810 | 112002 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 111811 | | - if( db->flags & SQLITE_Vacuum ){ |
| 112003 | + if( db->mDbFlags & DBFLAG_Vacuum ){ |
| 111812 | 112004 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 111813 | 112005 | ** that the destination table is empty. If all indexed columns use |
| 111814 | 112006 | ** collation sequence BINARY, then it can also be assumed that the |
| 111815 | 112007 | ** index will be populated by inserting keys in strictly sorted |
| 111816 | 112008 | ** order. In this case, instead of seeking within the b-tree as part |
| 111817 | | - ** of every OP_IdxInsert opcode, an OP_Last is added before the |
| 112009 | + ** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the |
| 111818 | 112010 | ** OP_IdxInsert to seek to the point within the b-tree where each key |
| 111819 | 112011 | ** should be inserted. This is faster. |
| 111820 | 112012 | ** |
| 111821 | 112013 | ** If any of the indexed columns use a collation sequence other than |
| 111822 | 112014 | ** BINARY, this optimization is disabled. This is because the user |
| | @@ -111827,11 +112019,11 @@ |
| 111827 | 112019 | const char *zColl = pSrcIdx->azColl[i]; |
| 111828 | 112020 | if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break; |
| 111829 | 112021 | } |
| 111830 | 112022 | if( i==pSrcIdx->nColumn ){ |
| 111831 | 112023 | idxInsFlags = OPFLAG_USESEEKRESULT; |
| 111832 | | - sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 112024 | + sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest); |
| 111833 | 112025 | } |
| 111834 | 112026 | } |
| 111835 | 112027 | if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){ |
| 111836 | 112028 | idxInsFlags |= OPFLAG_NCHANGE; |
| 111837 | 112029 | } |
| | @@ -112270,11 +112462,11 @@ |
| 112270 | 112462 | int (*stmt_readonly)(sqlite3_stmt*); |
| 112271 | 112463 | int (*stricmp)(const char*,const char*); |
| 112272 | 112464 | int (*uri_boolean)(const char*,const char*,int); |
| 112273 | 112465 | sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); |
| 112274 | 112466 | const char *(*uri_parameter)(const char*,const char*); |
| 112275 | | - char *(*vsnprintf)(int,char*,const char*,va_list); |
| 112467 | + char *(*xvsnprintf)(int,char*,const char*,va_list); |
| 112276 | 112468 | int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); |
| 112277 | 112469 | /* Version 3.8.7 and later */ |
| 112278 | 112470 | int (*auto_extension)(void(*)(void)); |
| 112279 | 112471 | int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64, |
| 112280 | 112472 | void(*)(void*)); |
| | @@ -112466,11 +112658,11 @@ |
| 112466 | 112658 | #define sqlite3_value_text16 sqlite3_api->value_text16 |
| 112467 | 112659 | #define sqlite3_value_text16be sqlite3_api->value_text16be |
| 112468 | 112660 | #define sqlite3_value_text16le sqlite3_api->value_text16le |
| 112469 | 112661 | #define sqlite3_value_type sqlite3_api->value_type |
| 112470 | 112662 | #define sqlite3_vmprintf sqlite3_api->vmprintf |
| 112471 | | -#define sqlite3_vsnprintf sqlite3_api->vsnprintf |
| 112663 | +#define sqlite3_vsnprintf sqlite3_api->xvsnprintf |
| 112472 | 112664 | #define sqlite3_overload_function sqlite3_api->overload_function |
| 112473 | 112665 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 |
| 112474 | 112666 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 |
| 112475 | 112667 | #define sqlite3_clear_bindings sqlite3_api->clear_bindings |
| 112476 | 112668 | #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob |
| | @@ -112542,11 +112734,11 @@ |
| 112542 | 112734 | #define sqlite3_stmt_readonly sqlite3_api->stmt_readonly |
| 112543 | 112735 | #define sqlite3_stricmp sqlite3_api->stricmp |
| 112544 | 112736 | #define sqlite3_uri_boolean sqlite3_api->uri_boolean |
| 112545 | 112737 | #define sqlite3_uri_int64 sqlite3_api->uri_int64 |
| 112546 | 112738 | #define sqlite3_uri_parameter sqlite3_api->uri_parameter |
| 112547 | | -#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf |
| 112739 | +#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf |
| 112548 | 112740 | #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 |
| 112549 | 112741 | /* Version 3.8.7 and later */ |
| 112550 | 112742 | #define sqlite3_auto_extension sqlite3_api->auto_extension |
| 112551 | 112743 | #define sqlite3_bind_blob64 sqlite3_api->bind_blob64 |
| 112552 | 112744 | #define sqlite3_bind_text64 sqlite3_api->bind_text64 |
| | @@ -114337,20 +114529,20 @@ |
| 114337 | 114529 | } |
| 114338 | 114530 | |
| 114339 | 114531 | /* |
| 114340 | 114532 | ** Helper subroutine for PRAGMA integrity_check: |
| 114341 | 114533 | ** |
| 114342 | | -** Generate code to output a single-column result row with the result |
| 114343 | | -** held in register regResult. Decrement the result count and halt if |
| 114344 | | -** the maximum number of result rows have been issued. |
| 114534 | +** Generate code to output a single-column result row with a value of the |
| 114535 | +** string held in register 3. Decrement the result count in register 1 |
| 114536 | +** and halt if the maximum number of result rows have been issued. |
| 114345 | 114537 | */ |
| 114346 | | -static int integrityCheckResultRow(Vdbe *v, int regResult){ |
| 114538 | +static int integrityCheckResultRow(Vdbe *v){ |
| 114347 | 114539 | int addr; |
| 114348 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1); |
| 114540 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
| 114349 | 114541 | addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1); |
| 114350 | 114542 | VdbeCoverage(v); |
| 114351 | | - sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 114543 | + sqlite3VdbeAddOp0(v, OP_Halt); |
| 114352 | 114544 | return addr; |
| 114353 | 114545 | } |
| 114354 | 114546 | |
| 114355 | 114547 | /* |
| 114356 | 114548 | ** Process a pragma statement. |
| | @@ -115273,17 +115465,15 @@ |
| 115273 | 115465 | FuncDef *p; |
| 115274 | 115466 | pParse->nMem = 2; |
| 115275 | 115467 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 115276 | 115468 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){ |
| 115277 | 115469 | sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1); |
| 115278 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
| 115279 | 115470 | } |
| 115280 | 115471 | } |
| 115281 | 115472 | for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ |
| 115282 | 115473 | p = (FuncDef*)sqliteHashData(j); |
| 115283 | 115474 | sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0); |
| 115284 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
| 115285 | 115475 | } |
| 115286 | 115476 | } |
| 115287 | 115477 | break; |
| 115288 | 115478 | |
| 115289 | 115479 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -115291,21 +115481,19 @@ |
| 115291 | 115481 | HashElem *j; |
| 115292 | 115482 | pParse->nMem = 1; |
| 115293 | 115483 | for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){ |
| 115294 | 115484 | Module *pMod = (Module*)sqliteHashData(j); |
| 115295 | 115485 | sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName); |
| 115296 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 115297 | 115486 | } |
| 115298 | 115487 | } |
| 115299 | 115488 | break; |
| 115300 | 115489 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 115301 | 115490 | |
| 115302 | 115491 | case PragTyp_PRAGMA_LIST: { |
| 115303 | 115492 | int i; |
| 115304 | 115493 | for(i=0; i<ArraySize(aPragmaName); i++){ |
| 115305 | 115494 | sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName); |
| 115306 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 115307 | 115495 | } |
| 115308 | 115496 | } |
| 115309 | 115497 | break; |
| 115310 | 115498 | #endif /* SQLITE_INTROSPECTION_PRAGMAS */ |
| 115311 | 115499 | |
| | @@ -115527,16 +115715,15 @@ |
| 115527 | 115715 | } |
| 115528 | 115716 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */ |
| 115529 | 115717 | |
| 115530 | 115718 | /* Do an integrity check on each database file */ |
| 115531 | 115719 | for(i=0; i<db->nDb; i++){ |
| 115532 | | - HashElem *x; |
| 115533 | | - Hash *pTbls; |
| 115534 | | - int *aRoot; |
| 115535 | | - int cnt = 0; |
| 115536 | | - int mxIdx = 0; |
| 115537 | | - int nIdx; |
| 115720 | + HashElem *x; /* For looping over tables in the schema */ |
| 115721 | + Hash *pTbls; /* Set of all tables in the schema */ |
| 115722 | + int *aRoot; /* Array of root page numbers of all btrees */ |
| 115723 | + int cnt = 0; /* Number of entries in aRoot[] */ |
| 115724 | + int mxIdx = 0; /* Maximum number of indexes for any table */ |
| 115538 | 115725 | |
| 115539 | 115726 | if( OMIT_TEMPDB && i==1 ) continue; |
| 115540 | 115727 | if( iDb>=0 && i!=iDb ) continue; |
| 115541 | 115728 | |
| 115542 | 115729 | sqlite3CodeVerifySchema(pParse, i); |
| | @@ -115547,12 +115734,13 @@ |
| 115547 | 115734 | ** for all tables and indices in the database. |
| 115548 | 115735 | */ |
| 115549 | 115736 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
| 115550 | 115737 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 115551 | 115738 | for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 115552 | | - Table *pTab = sqliteHashData(x); |
| 115553 | | - Index *pIdx; |
| 115739 | + Table *pTab = sqliteHashData(x); /* Current table */ |
| 115740 | + Index *pIdx; /* An index on pTab */ |
| 115741 | + int nIdx; /* Number of indexes on pTab */ |
| 115554 | 115742 | if( HasRowid(pTab) ) cnt++; |
| 115555 | 115743 | for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; } |
| 115556 | 115744 | if( nIdx>mxIdx ) mxIdx = nIdx; |
| 115557 | 115745 | } |
| 115558 | 115746 | aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1)); |
| | @@ -115576,13 +115764,12 @@ |
| 115576 | 115764 | sqlite3VdbeChangeP5(v, (u8)i); |
| 115577 | 115765 | addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); |
| 115578 | 115766 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
| 115579 | 115767 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName), |
| 115580 | 115768 | P4_DYNAMIC); |
| 115581 | | - sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1); |
| 115582 | | - sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
| 115583 | | - integrityCheckResultRow(v, 2); |
| 115769 | + sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3); |
| 115770 | + integrityCheckResultRow(v); |
| 115584 | 115771 | sqlite3VdbeJumpHere(v, addr); |
| 115585 | 115772 | |
| 115586 | 115773 | /* Make sure all the indices are constructed correctly. |
| 115587 | 115774 | */ |
| 115588 | 115775 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| | @@ -115592,20 +115779,17 @@ |
| 115592 | 115779 | int loopTop; |
| 115593 | 115780 | int iDataCur, iIdxCur; |
| 115594 | 115781 | int r1 = -1; |
| 115595 | 115782 | |
| 115596 | 115783 | if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ |
| 115597 | | - if( pTab->pCheck==0 |
| 115598 | | - && (pTab->tabFlags & TF_HasNotNull)==0 |
| 115599 | | - && (pTab->pIndex==0 || isQuick) |
| 115600 | | - ){ |
| 115601 | | - continue; /* No additional checks needed for this table */ |
| 115602 | | - } |
| 115603 | 115784 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 115604 | 115785 | sqlite3ExprCacheClear(pParse); |
| 115605 | 115786 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
| 115606 | 115787 | 1, 0, &iDataCur, &iIdxCur); |
| 115788 | + /* reg[7] counts the number of entries in the table. |
| 115789 | + ** reg[8+i] counts the number of entries in the i-th index |
| 115790 | + */ |
| 115607 | 115791 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
| 115608 | 115792 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 115609 | 115793 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ |
| 115610 | 115794 | } |
| 115611 | 115795 | assert( pParse->nMem>=8+j ); |
| | @@ -115622,11 +115806,11 @@ |
| 115622 | 115806 | sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 115623 | 115807 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 115624 | 115808 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 115625 | 115809 | pTab->aCol[j].zName); |
| 115626 | 115810 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 115627 | | - integrityCheckResultRow(v, 3); |
| 115811 | + integrityCheckResultRow(v); |
| 115628 | 115812 | sqlite3VdbeJumpHere(v, jmp2); |
| 115629 | 115813 | } |
| 115630 | 115814 | /* Verify CHECK constraints */ |
| 115631 | 115815 | if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
| 115632 | 115816 | ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0); |
| | @@ -115645,61 +115829,66 @@ |
| 115645 | 115829 | sqlite3VdbeResolveLabel(v, addrCkFault); |
| 115646 | 115830 | pParse->iSelfTab = 0; |
| 115647 | 115831 | zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s", |
| 115648 | 115832 | pTab->zName); |
| 115649 | 115833 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 115650 | | - integrityCheckResultRow(v, 3); |
| 115834 | + integrityCheckResultRow(v); |
| 115651 | 115835 | sqlite3VdbeResolveLabel(v, addrCkOk); |
| 115652 | 115836 | sqlite3ExprCachePop(pParse); |
| 115653 | 115837 | } |
| 115654 | 115838 | sqlite3ExprListDelete(db, pCheck); |
| 115655 | 115839 | } |
| 115656 | | - /* Validate index entries for the current row */ |
| 115657 | | - for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){ |
| 115658 | | - int jmp2, jmp3, jmp4, jmp5; |
| 115659 | | - int ckUniq = sqlite3VdbeMakeLabel(v); |
| 115660 | | - if( pPk==pIdx ) continue; |
| 115661 | | - r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 115662 | | - pPrior, r1); |
| 115663 | | - pPrior = pIdx; |
| 115664 | | - sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ |
| 115665 | | - /* Verify that an index entry exists for the current table row */ |
| 115666 | | - jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, |
| 115667 | | - pIdx->nColumn); VdbeCoverage(v); |
| 115668 | | - sqlite3VdbeLoadString(v, 3, "row "); |
| 115669 | | - sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 115670 | | - sqlite3VdbeLoadString(v, 4, " missing from index "); |
| 115671 | | - sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 115672 | | - jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 115673 | | - sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 115674 | | - jmp4 = integrityCheckResultRow(v, 3); |
| 115675 | | - sqlite3VdbeJumpHere(v, jmp2); |
| 115676 | | - /* For UNIQUE indexes, verify that only one entry exists with the |
| 115677 | | - ** current key. The entry is unique if (1) any column is NULL |
| 115678 | | - ** or (2) the next entry has a different key */ |
| 115679 | | - if( IsUniqueIndex(pIdx) ){ |
| 115680 | | - int uniqOk = sqlite3VdbeMakeLabel(v); |
| 115681 | | - int jmp6; |
| 115682 | | - int kk; |
| 115683 | | - for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 115684 | | - int iCol = pIdx->aiColumn[kk]; |
| 115685 | | - assert( iCol!=XN_ROWID && iCol<pTab->nCol ); |
| 115686 | | - if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; |
| 115687 | | - sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); |
| 115688 | | - VdbeCoverage(v); |
| 115689 | | - } |
| 115690 | | - jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); |
| 115691 | | - sqlite3VdbeGoto(v, uniqOk); |
| 115692 | | - sqlite3VdbeJumpHere(v, jmp6); |
| 115693 | | - sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, |
| 115694 | | - pIdx->nKeyCol); VdbeCoverage(v); |
| 115695 | | - sqlite3VdbeLoadString(v, 3, "non-unique entry in index "); |
| 115696 | | - sqlite3VdbeGoto(v, jmp5); |
| 115697 | | - sqlite3VdbeResolveLabel(v, uniqOk); |
| 115698 | | - } |
| 115699 | | - sqlite3VdbeJumpHere(v, jmp4); |
| 115700 | | - sqlite3ResolvePartIdxLabel(pParse, jmp3); |
| 115840 | + if( !isQuick ){ /* Omit the remaining tests for quick_check */ |
| 115841 | + /* Sanity check on record header decoding */ |
| 115842 | + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3); |
| 115843 | + sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 115844 | + /* Validate index entries for the current row */ |
| 115845 | + for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 115846 | + int jmp2, jmp3, jmp4, jmp5; |
| 115847 | + int ckUniq = sqlite3VdbeMakeLabel(v); |
| 115848 | + if( pPk==pIdx ) continue; |
| 115849 | + r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 115850 | + pPrior, r1); |
| 115851 | + pPrior = pIdx; |
| 115852 | + sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */ |
| 115853 | + /* Verify that an index entry exists for the current table row */ |
| 115854 | + jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, |
| 115855 | + pIdx->nColumn); VdbeCoverage(v); |
| 115856 | + sqlite3VdbeLoadString(v, 3, "row "); |
| 115857 | + sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 115858 | + sqlite3VdbeLoadString(v, 4, " missing from index "); |
| 115859 | + sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 115860 | + jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 115861 | + sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 115862 | + jmp4 = integrityCheckResultRow(v); |
| 115863 | + sqlite3VdbeJumpHere(v, jmp2); |
| 115864 | + /* For UNIQUE indexes, verify that only one entry exists with the |
| 115865 | + ** current key. The entry is unique if (1) any column is NULL |
| 115866 | + ** or (2) the next entry has a different key */ |
| 115867 | + if( IsUniqueIndex(pIdx) ){ |
| 115868 | + int uniqOk = sqlite3VdbeMakeLabel(v); |
| 115869 | + int jmp6; |
| 115870 | + int kk; |
| 115871 | + for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 115872 | + int iCol = pIdx->aiColumn[kk]; |
| 115873 | + assert( iCol!=XN_ROWID && iCol<pTab->nCol ); |
| 115874 | + if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; |
| 115875 | + sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); |
| 115876 | + VdbeCoverage(v); |
| 115877 | + } |
| 115878 | + jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); |
| 115879 | + sqlite3VdbeGoto(v, uniqOk); |
| 115880 | + sqlite3VdbeJumpHere(v, jmp6); |
| 115881 | + sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, |
| 115882 | + pIdx->nKeyCol); VdbeCoverage(v); |
| 115883 | + sqlite3VdbeLoadString(v, 3, "non-unique entry in index "); |
| 115884 | + sqlite3VdbeGoto(v, jmp5); |
| 115885 | + sqlite3VdbeResolveLabel(v, uniqOk); |
| 115886 | + } |
| 115887 | + sqlite3VdbeJumpHere(v, jmp4); |
| 115888 | + sqlite3ResolvePartIdxLabel(pParse, jmp3); |
| 115889 | + } |
| 115701 | 115890 | } |
| 115702 | 115891 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
| 115703 | 115892 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 115704 | 115893 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 115705 | 115894 | if( !isQuick ){ |
| | @@ -115707,13 +115896,13 @@ |
| 115707 | 115896 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 115708 | 115897 | if( pPk==pIdx ) continue; |
| 115709 | 115898 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
| 115710 | 115899 | addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v); |
| 115711 | 115900 | sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 115712 | | - sqlite3VdbeLoadString(v, 3, pIdx->zName); |
| 115713 | | - sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 115714 | | - integrityCheckResultRow(v, 7); |
| 115901 | + sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 115902 | + sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); |
| 115903 | + integrityCheckResultRow(v); |
| 115715 | 115904 | sqlite3VdbeJumpHere(v, addr); |
| 115716 | 115905 | } |
| 115717 | 115906 | } |
| 115718 | 115907 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 115719 | 115908 | } |
| | @@ -115723,19 +115912,25 @@ |
| 115723 | 115912 | static const VdbeOpList endCode[] = { |
| 115724 | 115913 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 115725 | 115914 | { OP_IfNotZero, 1, 4, 0}, /* 1 */ |
| 115726 | 115915 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 115727 | 115916 | { OP_ResultRow, 3, 1, 0}, /* 3 */ |
| 115917 | + { OP_Halt, 0, 0, 0}, /* 4 */ |
| 115918 | + { OP_String8, 0, 3, 0}, /* 5 */ |
| 115919 | + { OP_Goto, 0, 3, 0}, /* 6 */ |
| 115728 | 115920 | }; |
| 115729 | 115921 | VdbeOp *aOp; |
| 115730 | 115922 | |
| 115731 | 115923 | aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 115732 | 115924 | if( aOp ){ |
| 115733 | 115925 | aOp[0].p2 = 1-mxErr; |
| 115734 | 115926 | aOp[2].p4type = P4_STATIC; |
| 115735 | 115927 | aOp[2].p4.z = "ok"; |
| 115928 | + aOp[5].p4type = P4_STATIC; |
| 115929 | + aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT); |
| 115736 | 115930 | } |
| 115931 | + sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2); |
| 115737 | 115932 | } |
| 115738 | 115933 | } |
| 115739 | 115934 | break; |
| 115740 | 115935 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 115741 | 115936 | |
| | @@ -116611,11 +116806,11 @@ |
| 116611 | 116806 | db->init.orphanTrigger = 0; |
| 116612 | 116807 | TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0); |
| 116613 | 116808 | rc = db->errCode; |
| 116614 | 116809 | assert( (rc&0xFF)==(rcp&0xFF) ); |
| 116615 | 116810 | db->init.iDb = saved_iDb; |
| 116616 | | - assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 ); |
| 116811 | + assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); |
| 116617 | 116812 | if( SQLITE_OK!=rc ){ |
| 116618 | 116813 | if( db->init.orphanTrigger ){ |
| 116619 | 116814 | assert( iDb==1 ); |
| 116620 | 116815 | }else{ |
| 116621 | 116816 | pData->rc = rc; |
| | @@ -116675,20 +116870,22 @@ |
| 116675 | 116870 | |
| 116676 | 116871 | assert( iDb>=0 && iDb<db->nDb ); |
| 116677 | 116872 | assert( db->aDb[iDb].pSchema ); |
| 116678 | 116873 | assert( sqlite3_mutex_held(db->mutex) ); |
| 116679 | 116874 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 116875 | + |
| 116876 | + db->init.busy = 1; |
| 116680 | 116877 | |
| 116681 | 116878 | /* Construct the in-memory representation schema tables (sqlite_master or |
| 116682 | 116879 | ** sqlite_temp_master) by invoking the parser directly. The appropriate |
| 116683 | 116880 | ** table name will be inserted automatically by the parser so we can just |
| 116684 | 116881 | ** use the abbreviation "x" here. The parser will also automatically tag |
| 116685 | 116882 | ** the schema table as read-only. */ |
| 116686 | 116883 | azArg[0] = zMasterName = SCHEMA_TABLE(iDb); |
| 116687 | 116884 | azArg[1] = "1"; |
| 116688 | 116885 | azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text," |
| 116689 | | - "rootpage integer,sql text)"; |
| 116886 | + "rootpage int,sql text)"; |
| 116690 | 116887 | azArg[3] = 0; |
| 116691 | 116888 | initData.db = db; |
| 116692 | 116889 | initData.iDb = iDb; |
| 116693 | 116890 | initData.rc = SQLITE_OK; |
| 116694 | 116891 | initData.pzErrMsg = pzErrMsg; |
| | @@ -116700,14 +116897,14 @@ |
| 116700 | 116897 | |
| 116701 | 116898 | /* Create a cursor to hold the database open |
| 116702 | 116899 | */ |
| 116703 | 116900 | pDb = &db->aDb[iDb]; |
| 116704 | 116901 | if( pDb->pBt==0 ){ |
| 116705 | | - if( !OMIT_TEMPDB && ALWAYS(iDb==1) ){ |
| 116706 | | - DbSetProperty(db, 1, DB_SchemaLoaded); |
| 116707 | | - } |
| 116708 | | - return SQLITE_OK; |
| 116902 | + assert( iDb==1 ); |
| 116903 | + DbSetProperty(db, 1, DB_SchemaLoaded); |
| 116904 | + rc = SQLITE_OK; |
| 116905 | + goto error_out; |
| 116709 | 116906 | } |
| 116710 | 116907 | |
| 116711 | 116908 | /* If there is not already a read-only (or read-write) transaction opened |
| 116712 | 116909 | ** on the b-tree database, open one now. If a transaction is opened, it |
| 116713 | 116910 | ** will be closed before this function returns. */ |
| | @@ -116862,13 +117059,17 @@ |
| 116862 | 117059 | sqlite3BtreeCommit(pDb->pBt); |
| 116863 | 117060 | } |
| 116864 | 117061 | sqlite3BtreeLeave(pDb->pBt); |
| 116865 | 117062 | |
| 116866 | 117063 | error_out: |
| 116867 | | - if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 116868 | | - sqlite3OomFault(db); |
| 117064 | + if( rc ){ |
| 117065 | + if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 117066 | + sqlite3OomFault(db); |
| 117067 | + } |
| 117068 | + sqlite3ResetOneSchema(db, iDb); |
| 116869 | 117069 | } |
| 117070 | + db->init.busy = 0; |
| 116870 | 117071 | return rc; |
| 116871 | 117072 | } |
| 116872 | 117073 | |
| 116873 | 117074 | /* |
| 116874 | 117075 | ** Initialize all database files - the main database file, the file |
| | @@ -116880,46 +117081,33 @@ |
| 116880 | 117081 | ** bit is set in the flags field of the Db structure. If the database |
| 116881 | 117082 | ** file was of zero-length, then the DB_Empty flag is also set. |
| 116882 | 117083 | */ |
| 116883 | 117084 | SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 116884 | 117085 | int i, rc; |
| 116885 | | - int commit_internal = !(db->flags&SQLITE_InternChanges); |
| 117086 | + int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange); |
| 116886 | 117087 | |
| 116887 | 117088 | assert( sqlite3_mutex_held(db->mutex) ); |
| 116888 | 117089 | assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) ); |
| 116889 | 117090 | assert( db->init.busy==0 ); |
| 116890 | | - rc = SQLITE_OK; |
| 116891 | | - db->init.busy = 1; |
| 116892 | 117091 | ENC(db) = SCHEMA_ENC(db); |
| 116893 | | - for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 116894 | | - if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
| 116895 | | - rc = sqlite3InitOne(db, i, pzErrMsg); |
| 116896 | | - if( rc ){ |
| 116897 | | - sqlite3ResetOneSchema(db, i); |
| 116898 | | - } |
| 116899 | | - } |
| 116900 | | - |
| 116901 | | - /* Once all the other databases have been initialized, load the schema |
| 116902 | | - ** for the TEMP database. This is loaded last, as the TEMP database |
| 116903 | | - ** schema may contain references to objects in other databases. |
| 116904 | | - */ |
| 116905 | | -#ifndef SQLITE_OMIT_TEMPDB |
| 116906 | | - assert( db->nDb>1 ); |
| 116907 | | - if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ |
| 116908 | | - rc = sqlite3InitOne(db, 1, pzErrMsg); |
| 116909 | | - if( rc ){ |
| 116910 | | - sqlite3ResetOneSchema(db, 1); |
| 116911 | | - } |
| 116912 | | - } |
| 116913 | | -#endif |
| 116914 | | - |
| 116915 | | - db->init.busy = 0; |
| 116916 | | - if( rc==SQLITE_OK && commit_internal ){ |
| 117092 | + assert( db->nDb>0 ); |
| 117093 | + /* Do the main schema first */ |
| 117094 | + if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){ |
| 117095 | + rc = sqlite3InitOne(db, 0, pzErrMsg); |
| 117096 | + if( rc ) return rc; |
| 117097 | + } |
| 117098 | + /* All other schemas after the main schema. The "temp" schema must be last */ |
| 117099 | + for(i=db->nDb-1; i>0; i--){ |
| 117100 | + if( !DbHasProperty(db, i, DB_SchemaLoaded) ){ |
| 117101 | + rc = sqlite3InitOne(db, i, pzErrMsg); |
| 117102 | + if( rc ) return rc; |
| 117103 | + } |
| 117104 | + } |
| 117105 | + if( commit_internal ){ |
| 116917 | 117106 | sqlite3CommitInternalChanges(db); |
| 116918 | 117107 | } |
| 116919 | | - |
| 116920 | | - return rc; |
| 117108 | + return SQLITE_OK; |
| 116921 | 117109 | } |
| 116922 | 117110 | |
| 116923 | 117111 | /* |
| 116924 | 117112 | ** This routine is a no-op if the database schema is already initialized. |
| 116925 | 117113 | ** Otherwise, the schema is loaded. An error code is returned. |
| | @@ -117020,20 +117208,18 @@ |
| 117020 | 117208 | |
| 117021 | 117209 | /* |
| 117022 | 117210 | ** Free all memory allocations in the pParse object |
| 117023 | 117211 | */ |
| 117024 | 117212 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 117025 | | - if( pParse ){ |
| 117026 | | - sqlite3 *db = pParse->db; |
| 117027 | | - sqlite3DbFree(db, pParse->aLabel); |
| 117028 | | - sqlite3ExprListDelete(db, pParse->pConstExpr); |
| 117029 | | - if( db ){ |
| 117030 | | - assert( db->lookaside.bDisable >= pParse->disableLookaside ); |
| 117031 | | - db->lookaside.bDisable -= pParse->disableLookaside; |
| 117032 | | - } |
| 117033 | | - pParse->disableLookaside = 0; |
| 117034 | | - } |
| 117213 | + sqlite3 *db = pParse->db; |
| 117214 | + sqlite3DbFree(db, pParse->aLabel); |
| 117215 | + sqlite3ExprListDelete(db, pParse->pConstExpr); |
| 117216 | + if( db ){ |
| 117217 | + assert( db->lookaside.bDisable >= pParse->disableLookaside ); |
| 117218 | + db->lookaside.bDisable -= pParse->disableLookaside; |
| 117219 | + } |
| 117220 | + pParse->disableLookaside = 0; |
| 117035 | 117221 | } |
| 117036 | 117222 | |
| 117037 | 117223 | /* |
| 117038 | 117224 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 117039 | 117225 | */ |
| | @@ -117215,10 +117401,11 @@ |
| 117215 | 117401 | } |
| 117216 | 117402 | sqlite3_mutex_enter(db->mutex); |
| 117217 | 117403 | sqlite3BtreeEnterAll(db); |
| 117218 | 117404 | rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 117219 | 117405 | if( rc==SQLITE_SCHEMA ){ |
| 117406 | + sqlite3ResetOneSchema(db, -1); |
| 117220 | 117407 | sqlite3_finalize(*ppStmt); |
| 117221 | 117408 | rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 117222 | 117409 | } |
| 117223 | 117410 | sqlite3BtreeLeaveAll(db); |
| 117224 | 117411 | sqlite3_mutex_leave(db->mutex); |
| | @@ -117995,15 +118182,15 @@ |
| 117995 | 118182 | sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat); |
| 117996 | 118183 | pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex); |
| 117997 | 118184 | if( pParse->db->mallocFailed ) return; |
| 117998 | 118185 | pOp->p2 = nKey + nData; |
| 117999 | 118186 | pKI = pOp->p4.pKeyInfo; |
| 118000 | | - memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */ |
| 118187 | + memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */ |
| 118001 | 118188 | sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO); |
| 118002 | | - testcase( pKI->nXField>2 ); |
| 118189 | + testcase( pKI->nAllField > pKI->nKeyField+2 ); |
| 118003 | 118190 | pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat, |
| 118004 | | - pKI->nXField-1); |
| 118191 | + pKI->nAllField-pKI->nKeyField-1); |
| 118005 | 118192 | addrJmp = sqlite3VdbeCurrentAddr(v); |
| 118006 | 118193 | sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v); |
| 118007 | 118194 | pSort->labelBkOut = sqlite3VdbeMakeLabel(v); |
| 118008 | 118195 | pSort->regReturn = ++pParse->nMem; |
| 118009 | 118196 | sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut); |
| | @@ -118097,20 +118284,19 @@ |
| 118097 | 118284 | |
| 118098 | 118285 | /* |
| 118099 | 118286 | ** This routine generates the code for the inside of the inner loop |
| 118100 | 118287 | ** of a SELECT. |
| 118101 | 118288 | ** |
| 118102 | | -** If srcTab is negative, then the pEList expressions |
| 118289 | +** If srcTab is negative, then the p->pEList expressions |
| 118103 | 118290 | ** are evaluated in order to get the data for this row. If srcTab is |
| 118104 | | -** zero or more, then data is pulled from srcTab and pEList is used only |
| 118291 | +** zero or more, then data is pulled from srcTab and p->pEList is used only |
| 118105 | 118292 | ** to get the number of columns and the collation sequence for each column. |
| 118106 | 118293 | */ |
| 118107 | 118294 | static void selectInnerLoop( |
| 118108 | 118295 | Parse *pParse, /* The parser context */ |
| 118109 | 118296 | Select *p, /* The complete select statement being coded */ |
| 118110 | | - ExprList *pEList, /* List of values being extracted */ |
| 118111 | | - int srcTab, /* Pull data from this table */ |
| 118297 | + int srcTab, /* Pull data from this table if non-negative */ |
| 118112 | 118298 | SortCtx *pSort, /* If not NULL, info on how to process ORDER BY */ |
| 118113 | 118299 | DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */ |
| 118114 | 118300 | SelectDest *pDest, /* How to dispose of the results */ |
| 118115 | 118301 | int iContinue, /* Jump here to continue with next row */ |
| 118116 | 118302 | int iBreak /* Jump here to break out of the inner loop */ |
| | @@ -118130,21 +118316,21 @@ |
| 118130 | 118316 | ** from this array. In this case regOrig is set to zero. */ |
| 118131 | 118317 | int regResult; /* Start of memory holding current results */ |
| 118132 | 118318 | int regOrig; /* Start of memory holding full result (or 0) */ |
| 118133 | 118319 | |
| 118134 | 118320 | assert( v ); |
| 118135 | | - assert( pEList!=0 ); |
| 118321 | + assert( p->pEList!=0 ); |
| 118136 | 118322 | hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP; |
| 118137 | 118323 | if( pSort && pSort->pOrderBy==0 ) pSort = 0; |
| 118138 | 118324 | if( pSort==0 && !hasDistinct ){ |
| 118139 | 118325 | assert( iContinue!=0 ); |
| 118140 | 118326 | codeOffset(v, p->iOffset, iContinue); |
| 118141 | 118327 | } |
| 118142 | 118328 | |
| 118143 | 118329 | /* Pull the requested columns. |
| 118144 | 118330 | */ |
| 118145 | | - nResultCol = pEList->nExpr; |
| 118331 | + nResultCol = p->pEList->nExpr; |
| 118146 | 118332 | |
| 118147 | 118333 | if( pDest->iSdst==0 ){ |
| 118148 | 118334 | if( pSort ){ |
| 118149 | 118335 | nPrefixReg = pSort->pOrderBy->nExpr; |
| 118150 | 118336 | if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++; |
| | @@ -118163,11 +118349,11 @@ |
| 118163 | 118349 | pDest->nSdst = nResultCol; |
| 118164 | 118350 | regOrig = regResult = pDest->iSdst; |
| 118165 | 118351 | if( srcTab>=0 ){ |
| 118166 | 118352 | for(i=0; i<nResultCol; i++){ |
| 118167 | 118353 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i); |
| 118168 | | - VdbeComment((v, "%s", pEList->a[i].zName)); |
| 118354 | + VdbeComment((v, "%s", p->pEList->a[i].zName)); |
| 118169 | 118355 | } |
| 118170 | 118356 | }else if( eDest!=SRT_Exists ){ |
| 118171 | 118357 | /* If the destination is an EXISTS(...) expression, the actual |
| 118172 | 118358 | ** values returned by the SELECT are not required. |
| 118173 | 118359 | */ |
| | @@ -118176,28 +118362,28 @@ |
| 118176 | 118362 | ecelFlags = SQLITE_ECEL_DUP; |
| 118177 | 118363 | }else{ |
| 118178 | 118364 | ecelFlags = 0; |
| 118179 | 118365 | } |
| 118180 | 118366 | if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){ |
| 118181 | | - /* For each expression in pEList that is a copy of an expression in |
| 118367 | + /* For each expression in p->pEList that is a copy of an expression in |
| 118182 | 118368 | ** the ORDER BY clause (pSort->pOrderBy), set the associated |
| 118183 | 118369 | ** iOrderByCol value to one more than the index of the ORDER BY |
| 118184 | 118370 | ** expression within the sort-key that pushOntoSorter() will generate. |
| 118185 | | - ** This allows the pEList field to be omitted from the sorted record, |
| 118371 | + ** This allows the p->pEList field to be omitted from the sorted record, |
| 118186 | 118372 | ** saving space and CPU cycles. */ |
| 118187 | 118373 | ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF); |
| 118188 | 118374 | for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){ |
| 118189 | 118375 | int j; |
| 118190 | 118376 | if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){ |
| 118191 | | - pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat; |
| 118377 | + p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat; |
| 118192 | 118378 | } |
| 118193 | 118379 | } |
| 118194 | 118380 | regOrig = 0; |
| 118195 | 118381 | assert( eDest==SRT_Set || eDest==SRT_Mem |
| 118196 | 118382 | || eDest==SRT_Coroutine || eDest==SRT_Output ); |
| 118197 | 118383 | } |
| 118198 | | - nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags); |
| 118384 | + nResultCol = sqlite3ExprCodeExprList(pParse,p->pEList,regResult,0,ecelFlags); |
| 118199 | 118385 | } |
| 118200 | 118386 | |
| 118201 | 118387 | /* If the DISTINCT keyword was present on the SELECT statement |
| 118202 | 118388 | ** and this row has been seen before, then do not make this row |
| 118203 | 118389 | ** part of the result. |
| | @@ -118225,11 +118411,11 @@ |
| 118225 | 118411 | pOp->p1 = 1; |
| 118226 | 118412 | pOp->p2 = regPrev; |
| 118227 | 118413 | |
| 118228 | 118414 | iJump = sqlite3VdbeCurrentAddr(v) + nResultCol; |
| 118229 | 118415 | for(i=0; i<nResultCol; i++){ |
| 118230 | | - CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr); |
| 118416 | + CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr); |
| 118231 | 118417 | if( i<nResultCol-1 ){ |
| 118232 | 118418 | sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i); |
| 118233 | 118419 | VdbeCoverage(v); |
| 118234 | 118420 | }else{ |
| 118235 | 118421 | sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i); |
| | @@ -118468,12 +118654,12 @@ |
| 118468 | 118654 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 118469 | 118655 | int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*); |
| 118470 | 118656 | KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra); |
| 118471 | 118657 | if( p ){ |
| 118472 | 118658 | p->aSortOrder = (u8*)&p->aColl[N+X]; |
| 118473 | | - p->nField = (u16)N; |
| 118474 | | - p->nXField = (u16)X; |
| 118659 | + p->nKeyField = (u16)N; |
| 118660 | + p->nAllField = (u16)(N+X); |
| 118475 | 118661 | p->enc = ENC(db); |
| 118476 | 118662 | p->db = db; |
| 118477 | 118663 | p->nRef = 1; |
| 118478 | 118664 | memset(&p[1], 0, nExtra); |
| 118479 | 118665 | }else{ |
| | @@ -119050,10 +119236,12 @@ |
| 119050 | 119236 | sqlite3VdbeSetNumCols(v, pEList->nExpr); |
| 119051 | 119237 | for(i=0; i<pEList->nExpr; i++){ |
| 119052 | 119238 | Expr *p = pEList->a[i].pExpr; |
| 119053 | 119239 | |
| 119054 | 119240 | assert( p!=0 ); |
| 119241 | + assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ |
| 119242 | + assert( p->op!=TK_COLUMN || p->pTab!=0 ); /* Covering indexes not yet coded */ |
| 119055 | 119243 | if( pEList->a[i].zName ){ |
| 119056 | 119244 | /* An AS clause always takes first priority */ |
| 119057 | 119245 | char *zName = pEList->a[i].zName; |
| 119058 | 119246 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 119059 | 119247 | }else if( srcName && p->op==TK_COLUMN ){ |
| | @@ -119143,11 +119331,13 @@ |
| 119143 | 119331 | Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr); |
| 119144 | 119332 | while( pColExpr->op==TK_DOT ){ |
| 119145 | 119333 | pColExpr = pColExpr->pRight; |
| 119146 | 119334 | assert( pColExpr!=0 ); |
| 119147 | 119335 | } |
| 119148 | | - if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){ |
| 119336 | + if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN) |
| 119337 | + && pColExpr->pTab!=0 |
| 119338 | + ){ |
| 119149 | 119339 | /* For columns use the column name name */ |
| 119150 | 119340 | int iCol = pColExpr->iColumn; |
| 119151 | 119341 | Table *pTab = pColExpr->pTab; |
| 119152 | 119342 | if( iCol<0 ) iCol = pTab->iPKey; |
| 119153 | 119343 | zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; |
| | @@ -119291,23 +119481,20 @@ |
| 119291 | 119481 | |
| 119292 | 119482 | /* |
| 119293 | 119483 | ** Get a VDBE for the given parser context. Create a new one if necessary. |
| 119294 | 119484 | ** If an error occurs, return NULL and leave a message in pParse. |
| 119295 | 119485 | */ |
| 119296 | | -static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){ |
| 119297 | | - Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse); |
| 119298 | | - if( v ) sqlite3VdbeAddOp2(v, OP_Init, 0, 1); |
| 119486 | +SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 119487 | + if( pParse->pVdbe ){ |
| 119488 | + return pParse->pVdbe; |
| 119489 | + } |
| 119299 | 119490 | if( pParse->pToplevel==0 |
| 119300 | 119491 | && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst) |
| 119301 | 119492 | ){ |
| 119302 | 119493 | pParse->okConstFactor = 1; |
| 119303 | 119494 | } |
| 119304 | | - return v; |
| 119305 | | -} |
| 119306 | | -SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 119307 | | - Vdbe *v = pParse->pVdbe; |
| 119308 | | - return v ? v : allocVdbe(pParse); |
| 119495 | + return sqlite3VdbeCreate(pParse); |
| 119309 | 119496 | } |
| 119310 | 119497 | |
| 119311 | 119498 | |
| 119312 | 119499 | /* |
| 119313 | 119500 | ** Compute the iLimit and iOffset fields of the SELECT based on the |
| | @@ -119576,11 +119763,11 @@ |
| 119576 | 119763 | sqlite3VdbeAddOp1(v, OP_Delete, iQueue); |
| 119577 | 119764 | |
| 119578 | 119765 | /* Output the single row in Current */ |
| 119579 | 119766 | addrCont = sqlite3VdbeMakeLabel(v); |
| 119580 | 119767 | codeOffset(v, regOffset, addrCont); |
| 119581 | | - selectInnerLoop(pParse, p, p->pEList, iCurrent, |
| 119768 | + selectInnerLoop(pParse, p, iCurrent, |
| 119582 | 119769 | 0, 0, pDest, addrCont, addrBreak); |
| 119583 | 119770 | if( regLimit ){ |
| 119584 | 119771 | sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak); |
| 119585 | 119772 | VdbeCoverage(v); |
| 119586 | 119773 | } |
| | @@ -119714,19 +119901,13 @@ |
| 119714 | 119901 | assert( p && p->pPrior ); /* Calling function guarantees this much */ |
| 119715 | 119902 | assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION ); |
| 119716 | 119903 | db = pParse->db; |
| 119717 | 119904 | pPrior = p->pPrior; |
| 119718 | 119905 | dest = *pDest; |
| 119719 | | - if( pPrior->pOrderBy ){ |
| 119720 | | - sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before", |
| 119721 | | - selectOpName(p->op)); |
| 119722 | | - rc = 1; |
| 119723 | | - goto multi_select_end; |
| 119724 | | - } |
| 119725 | | - if( pPrior->pLimit ){ |
| 119726 | | - sqlite3ErrorMsg(pParse,"LIMIT clause should come after %s not before", |
| 119727 | | - selectOpName(p->op)); |
| 119906 | + if( pPrior->pOrderBy || pPrior->pLimit ){ |
| 119907 | + sqlite3ErrorMsg(pParse,"%s clause should come after %s not before", |
| 119908 | + pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op)); |
| 119728 | 119909 | rc = 1; |
| 119729 | 119910 | goto multi_select_end; |
| 119730 | 119911 | } |
| 119731 | 119912 | |
| 119732 | 119913 | v = sqlite3GetVdbe(pParse); |
| | @@ -119895,11 +120076,11 @@ |
| 119895 | 120076 | iBreak = sqlite3VdbeMakeLabel(v); |
| 119896 | 120077 | iCont = sqlite3VdbeMakeLabel(v); |
| 119897 | 120078 | computeLimitRegisters(pParse, p, iBreak); |
| 119898 | 120079 | sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v); |
| 119899 | 120080 | iStart = sqlite3VdbeCurrentAddr(v); |
| 119900 | | - selectInnerLoop(pParse, p, p->pEList, unionTab, |
| 120081 | + selectInnerLoop(pParse, p, unionTab, |
| 119901 | 120082 | 0, 0, &dest, iCont, iBreak); |
| 119902 | 120083 | sqlite3VdbeResolveLabel(v, iCont); |
| 119903 | 120084 | sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v); |
| 119904 | 120085 | sqlite3VdbeResolveLabel(v, iBreak); |
| 119905 | 120086 | sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0); |
| | @@ -119968,11 +120149,11 @@ |
| 119968 | 120149 | sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| 119969 | 120150 | r1 = sqlite3GetTempReg(pParse); |
| 119970 | 120151 | iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1); |
| 119971 | 120152 | sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v); |
| 119972 | 120153 | sqlite3ReleaseTempReg(pParse, r1); |
| 119973 | | - selectInnerLoop(pParse, p, p->pEList, tab1, |
| 120154 | + selectInnerLoop(pParse, p, tab1, |
| 119974 | 120155 | 0, 0, &dest, iCont, iBreak); |
| 119975 | 120156 | sqlite3VdbeResolveLabel(v, iCont); |
| 119976 | 120157 | sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v); |
| 119977 | 120158 | sqlite3VdbeResolveLabel(v, iBreak); |
| 119978 | 120159 | sqlite3VdbeAddOp2(v, OP_Close, tab2, 0); |
| | @@ -122974,11 +123155,12 @@ |
| 122974 | 123155 | if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){ |
| 122975 | 123156 | sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex); |
| 122976 | 123157 | } |
| 122977 | 123158 | |
| 122978 | 123159 | /* Use the standard inner loop. */ |
| 122979 | | - selectInnerLoop(pParse, p, pEList, -1, &sSort, &sDistinct, pDest, |
| 123160 | + assert( p->pEList==pEList ); |
| 123161 | + selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest, |
| 122980 | 123162 | sqlite3WhereContinueLabel(pWInfo), |
| 122981 | 123163 | sqlite3WhereBreakLabel(pWInfo)); |
| 122982 | 123164 | |
| 122983 | 123165 | /* End the database scan loop. |
| 122984 | 123166 | */ |
| | @@ -123277,11 +123459,11 @@ |
| 123277 | 123459 | VdbeCoverage(v); |
| 123278 | 123460 | VdbeComment((v, "Groupby result generator entry point")); |
| 123279 | 123461 | sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); |
| 123280 | 123462 | finalizeAggFunctions(pParse, &sAggInfo); |
| 123281 | 123463 | sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL); |
| 123282 | | - selectInnerLoop(pParse, p, p->pEList, -1, &sSort, |
| 123464 | + selectInnerLoop(pParse, p, -1, &sSort, |
| 123283 | 123465 | &sDistinct, pDest, |
| 123284 | 123466 | addrOutputRow+1, addrSetAbort); |
| 123285 | 123467 | sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); |
| 123286 | 123468 | VdbeComment((v, "end groupby result generator")); |
| 123287 | 123469 | |
| | @@ -123421,11 +123603,11 @@ |
| 123421 | 123603 | finalizeAggFunctions(pParse, &sAggInfo); |
| 123422 | 123604 | } |
| 123423 | 123605 | |
| 123424 | 123606 | sSort.pOrderBy = 0; |
| 123425 | 123607 | sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL); |
| 123426 | | - selectInnerLoop(pParse, p, p->pEList, -1, 0, 0, |
| 123608 | + selectInnerLoop(pParse, p, -1, 0, 0, |
| 123427 | 123609 | pDest, addrEnd, addrEnd); |
| 123428 | 123610 | sqlite3ExprListDelete(db, pDel); |
| 123429 | 123611 | } |
| 123430 | 123612 | sqlite3VdbeResolveLabel(v, addrEnd); |
| 123431 | 123613 | |
| | @@ -124255,11 +124437,11 @@ |
| 124255 | 124437 | Trigger **pp; |
| 124256 | 124438 | for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext)); |
| 124257 | 124439 | *pp = (*pp)->pNext; |
| 124258 | 124440 | } |
| 124259 | 124441 | sqlite3DeleteTrigger(db, pTrigger); |
| 124260 | | - db->flags |= SQLITE_InternChanges; |
| 124442 | + db->mDbFlags |= DBFLAG_SchemaChange; |
| 124261 | 124443 | } |
| 124262 | 124444 | } |
| 124263 | 124445 | |
| 124264 | 124446 | /* |
| 124265 | 124447 | ** pEList is the SET clause of an UPDATE statement. Each entry |
| | @@ -125576,23 +125758,34 @@ |
| 125576 | 125758 | /* Start scanning the virtual table */ |
| 125577 | 125759 | pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0); |
| 125578 | 125760 | if( pWInfo==0 ) return; |
| 125579 | 125761 | |
| 125580 | 125762 | /* Populate the argument registers. */ |
| 125581 | | - sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg); |
| 125582 | | - if( pRowid ){ |
| 125583 | | - sqlite3ExprCode(pParse, pRowid, regArg+1); |
| 125584 | | - }else{ |
| 125585 | | - sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1); |
| 125586 | | - } |
| 125587 | 125763 | for(i=0; i<pTab->nCol; i++){ |
| 125588 | 125764 | if( aXRef[i]>=0 ){ |
| 125589 | 125765 | sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i); |
| 125590 | 125766 | }else{ |
| 125591 | 125767 | sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i); |
| 125592 | 125768 | } |
| 125593 | 125769 | } |
| 125770 | + if( HasRowid(pTab) ){ |
| 125771 | + sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg); |
| 125772 | + if( pRowid ){ |
| 125773 | + sqlite3ExprCode(pParse, pRowid, regArg+1); |
| 125774 | + }else{ |
| 125775 | + sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1); |
| 125776 | + } |
| 125777 | + }else{ |
| 125778 | + Index *pPk; /* PRIMARY KEY index */ |
| 125779 | + i16 iPk; /* PRIMARY KEY column */ |
| 125780 | + pPk = sqlite3PrimaryKeyIndex(pTab); |
| 125781 | + assert( pPk!=0 ); |
| 125782 | + assert( pPk->nKeyCol==1 ); |
| 125783 | + iPk = pPk->aiColumn[0]; |
| 125784 | + sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg); |
| 125785 | + sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1); |
| 125786 | + } |
| 125594 | 125787 | |
| 125595 | 125788 | bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy); |
| 125596 | 125789 | |
| 125597 | 125790 | if( bOnePass ){ |
| 125598 | 125791 | /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded |
| | @@ -125773,11 +125966,12 @@ |
| 125773 | 125966 | */ |
| 125774 | 125967 | SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){ |
| 125775 | 125968 | int rc = SQLITE_OK; /* Return code from service routines */ |
| 125776 | 125969 | Btree *pMain; /* The database being vacuumed */ |
| 125777 | 125970 | Btree *pTemp; /* The temporary database we vacuum into */ |
| 125778 | | - int saved_flags; /* Saved value of the db->flags */ |
| 125971 | + u16 saved_mDbFlags; /* Saved value of db->mDbFlags */ |
| 125972 | + u32 saved_flags; /* Saved value of db->flags */ |
| 125779 | 125973 | int saved_nChange; /* Saved value of db->nChange */ |
| 125780 | 125974 | int saved_nTotalChange; /* Saved value of db->nTotalChange */ |
| 125781 | 125975 | u8 saved_mTrace; /* Saved trace settings */ |
| 125782 | 125976 | Db *pDb = 0; /* Database to detach at end of vacuum */ |
| 125783 | 125977 | int isMemDb; /* True if vacuuming a :memory: database */ |
| | @@ -125796,15 +125990,16 @@ |
| 125796 | 125990 | |
| 125797 | 125991 | /* Save the current value of the database flags so that it can be |
| 125798 | 125992 | ** restored before returning. Then set the writable-schema flag, and |
| 125799 | 125993 | ** disable CHECK and foreign key constraints. */ |
| 125800 | 125994 | saved_flags = db->flags; |
| 125995 | + saved_mDbFlags = db->mDbFlags; |
| 125801 | 125996 | saved_nChange = db->nChange; |
| 125802 | 125997 | saved_nTotalChange = db->nTotalChange; |
| 125803 | 125998 | saved_mTrace = db->mTrace; |
| 125804 | | - db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks |
| 125805 | | - | SQLITE_PreferBuiltin | SQLITE_Vacuum); |
| 125999 | + db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; |
| 126000 | + db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum; |
| 125806 | 126001 | db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows); |
| 125807 | 126002 | db->mTrace = 0; |
| 125808 | 126003 | |
| 125809 | 126004 | zDbMain = db->aDb[iDb].zDbSName; |
| 125810 | 126005 | pMain = db->aDb[iDb].pBt; |
| | @@ -125911,12 +126106,12 @@ |
| 125911 | 126106 | "||' SELECT*FROM\"%w\".'||quote(name)" |
| 125912 | 126107 | "FROM vacuum_db.sqlite_master " |
| 125913 | 126108 | "WHERE type='table'AND coalesce(rootpage,1)>0", |
| 125914 | 126109 | zDbMain |
| 125915 | 126110 | ); |
| 125916 | | - assert( (db->flags & SQLITE_Vacuum)!=0 ); |
| 125917 | | - db->flags &= ~SQLITE_Vacuum; |
| 126111 | + assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 ); |
| 126112 | + db->mDbFlags &= ~DBFLAG_Vacuum; |
| 125918 | 126113 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 125919 | 126114 | |
| 125920 | 126115 | /* Copy the triggers, views, and virtual tables from the main database |
| 125921 | 126116 | ** over to the temporary database. None of these objects has any |
| 125922 | 126117 | ** associated storage, so all we have to do is copy their entries |
| | @@ -125980,10 +126175,11 @@ |
| 125980 | 126175 | rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1); |
| 125981 | 126176 | |
| 125982 | 126177 | end_of_vacuum: |
| 125983 | 126178 | /* Restore the original value of db->flags */ |
| 125984 | 126179 | db->init.iDb = 0; |
| 126180 | + db->mDbFlags = saved_mDbFlags; |
| 125985 | 126181 | db->flags = saved_flags; |
| 125986 | 126182 | db->nChange = saved_nChange; |
| 125987 | 126183 | db->nTotalChange = saved_nTotalChange; |
| 125988 | 126184 | db->mTrace = saved_mTrace; |
| 125989 | 126185 | sqlite3BtreeSetPageSize(pMain, -1, -1, 1); |
| | @@ -126658,10 +126854,11 @@ |
| 126658 | 126854 | }else{ |
| 126659 | 126855 | char *zErr = 0; |
| 126660 | 126856 | rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr); |
| 126661 | 126857 | if( rc!=SQLITE_OK ){ |
| 126662 | 126858 | sqlite3ErrorMsg(pParse, "%s", zErr); |
| 126859 | + pParse->rc = rc; |
| 126663 | 126860 | } |
| 126664 | 126861 | sqlite3DbFree(db, zErr); |
| 126665 | 126862 | } |
| 126666 | 126863 | |
| 126667 | 126864 | return rc; |
| | @@ -126747,14 +126944,14 @@ |
| 126747 | 126944 | ** valid to call this function from within the xCreate() or xConnect() of a |
| 126748 | 126945 | ** virtual table module. |
| 126749 | 126946 | */ |
| 126750 | 126947 | SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ |
| 126751 | 126948 | VtabCtx *pCtx; |
| 126752 | | - Parse *pParse; |
| 126753 | 126949 | int rc = SQLITE_OK; |
| 126754 | 126950 | Table *pTab; |
| 126755 | 126951 | char *zErr = 0; |
| 126952 | + Parse sParse; |
| 126756 | 126953 | |
| 126757 | 126954 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126758 | 126955 | if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ |
| 126759 | 126956 | return SQLITE_MISUSE_BKPT; |
| 126760 | 126957 | } |
| | @@ -126767,59 +126964,59 @@ |
| 126767 | 126964 | return SQLITE_MISUSE_BKPT; |
| 126768 | 126965 | } |
| 126769 | 126966 | pTab = pCtx->pTab; |
| 126770 | 126967 | assert( IsVirtual(pTab) ); |
| 126771 | 126968 | |
| 126772 | | - pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 126773 | | - if( pParse==0 ){ |
| 126774 | | - rc = SQLITE_NOMEM_BKPT; |
| 126775 | | - }else{ |
| 126776 | | - pParse->declareVtab = 1; |
| 126777 | | - pParse->db = db; |
| 126778 | | - pParse->nQueryLoop = 1; |
| 126779 | | - |
| 126780 | | - if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr) |
| 126781 | | - && pParse->pNewTable |
| 126782 | | - && !db->mallocFailed |
| 126783 | | - && !pParse->pNewTable->pSelect |
| 126784 | | - && !IsVirtual(pParse->pNewTable) |
| 126785 | | - ){ |
| 126786 | | - if( !pTab->aCol ){ |
| 126787 | | - Table *pNew = pParse->pNewTable; |
| 126788 | | - Index *pIdx; |
| 126789 | | - pTab->aCol = pNew->aCol; |
| 126790 | | - pTab->nCol = pNew->nCol; |
| 126791 | | - pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 126792 | | - pNew->nCol = 0; |
| 126793 | | - pNew->aCol = 0; |
| 126794 | | - assert( pTab->pIndex==0 ); |
| 126795 | | - if( !HasRowid(pNew) && pCtx->pVTable->pMod->pModule->xUpdate!=0 ){ |
| 126796 | | - rc = SQLITE_ERROR; |
| 126797 | | - } |
| 126798 | | - pIdx = pNew->pIndex; |
| 126799 | | - if( pIdx ){ |
| 126800 | | - assert( pIdx->pNext==0 ); |
| 126801 | | - pTab->pIndex = pIdx; |
| 126802 | | - pNew->pIndex = 0; |
| 126803 | | - pIdx->pTable = pTab; |
| 126804 | | - } |
| 126805 | | - } |
| 126806 | | - pCtx->bDeclared = 1; |
| 126807 | | - }else{ |
| 126808 | | - sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 126809 | | - sqlite3DbFree(db, zErr); |
| 126810 | | - rc = SQLITE_ERROR; |
| 126811 | | - } |
| 126812 | | - pParse->declareVtab = 0; |
| 126813 | | - |
| 126814 | | - if( pParse->pVdbe ){ |
| 126815 | | - sqlite3VdbeFinalize(pParse->pVdbe); |
| 126816 | | - } |
| 126817 | | - sqlite3DeleteTable(db, pParse->pNewTable); |
| 126818 | | - sqlite3ParserReset(pParse); |
| 126819 | | - sqlite3StackFree(db, pParse); |
| 126820 | | - } |
| 126969 | + memset(&sParse, 0, sizeof(sParse)); |
| 126970 | + sParse.declareVtab = 1; |
| 126971 | + sParse.db = db; |
| 126972 | + sParse.nQueryLoop = 1; |
| 126973 | + if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr) |
| 126974 | + && sParse.pNewTable |
| 126975 | + && !db->mallocFailed |
| 126976 | + && !sParse.pNewTable->pSelect |
| 126977 | + && !IsVirtual(sParse.pNewTable) |
| 126978 | + ){ |
| 126979 | + if( !pTab->aCol ){ |
| 126980 | + Table *pNew = sParse.pNewTable; |
| 126981 | + Index *pIdx; |
| 126982 | + pTab->aCol = pNew->aCol; |
| 126983 | + pTab->nCol = pNew->nCol; |
| 126984 | + pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 126985 | + pNew->nCol = 0; |
| 126986 | + pNew->aCol = 0; |
| 126987 | + assert( pTab->pIndex==0 ); |
| 126988 | + assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 ); |
| 126989 | + if( !HasRowid(pNew) |
| 126990 | + && pCtx->pVTable->pMod->pModule->xUpdate!=0 |
| 126991 | + && sqlite3PrimaryKeyIndex(pNew)->nKeyCol!=1 |
| 126992 | + ){ |
| 126993 | + /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0) |
| 126994 | + ** or else must have a single-column PRIMARY KEY */ |
| 126995 | + rc = SQLITE_ERROR; |
| 126996 | + } |
| 126997 | + pIdx = pNew->pIndex; |
| 126998 | + if( pIdx ){ |
| 126999 | + assert( pIdx->pNext==0 ); |
| 127000 | + pTab->pIndex = pIdx; |
| 127001 | + pNew->pIndex = 0; |
| 127002 | + pIdx->pTable = pTab; |
| 127003 | + } |
| 127004 | + } |
| 127005 | + pCtx->bDeclared = 1; |
| 127006 | + }else{ |
| 127007 | + sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 127008 | + sqlite3DbFree(db, zErr); |
| 127009 | + rc = SQLITE_ERROR; |
| 127010 | + } |
| 127011 | + sParse.declareVtab = 0; |
| 127012 | + |
| 127013 | + if( sParse.pVdbe ){ |
| 127014 | + sqlite3VdbeFinalize(sParse.pVdbe); |
| 127015 | + } |
| 127016 | + sqlite3DeleteTable(db, sParse.pNewTable); |
| 127017 | + sqlite3ParserReset(&sParse); |
| 126821 | 127018 | |
| 126822 | 127019 | assert( (rc&0xff)==rc ); |
| 126823 | 127020 | rc = sqlite3ApiExit(db, rc); |
| 126824 | 127021 | sqlite3_mutex_leave(db->mutex); |
| 126825 | 127022 | return rc; |
| | @@ -127793,19 +127990,18 @@ |
| 127793 | 127990 | ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ |
| 127794 | 127991 | ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT |
| 127795 | 127992 | ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE |
| 127796 | 127993 | ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT |
| 127797 | 127994 | ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE |
| 127798 | | -** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH |
| 127799 | 127995 | */ |
| 127800 | 127996 | #define WO_IN 0x0001 |
| 127801 | 127997 | #define WO_EQ 0x0002 |
| 127802 | 127998 | #define WO_LT (WO_EQ<<(TK_LT-TK_EQ)) |
| 127803 | 127999 | #define WO_LE (WO_EQ<<(TK_LE-TK_EQ)) |
| 127804 | 128000 | #define WO_GT (WO_EQ<<(TK_GT-TK_EQ)) |
| 127805 | 128001 | #define WO_GE (WO_EQ<<(TK_GE-TK_EQ)) |
| 127806 | | -#define WO_MATCH 0x0040 |
| 128002 | +#define WO_AUX 0x0040 /* Op useful to virtual tables only */ |
| 127807 | 128003 | #define WO_IS 0x0080 |
| 127808 | 128004 | #define WO_ISNULL 0x0100 |
| 127809 | 128005 | #define WO_OR 0x0200 /* Two or more OR-connected terms */ |
| 127810 | 128006 | #define WO_AND 0x0400 /* Two or more AND-connected terms */ |
| 127811 | 128007 | #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */ |
| | @@ -128614,11 +128810,11 @@ |
| 128614 | 128810 | || pExpr->op==TK_NOTNULL || pExpr->op==TK_CASE |
| 128615 | 128811 | ){ |
| 128616 | 128812 | pWalker->eCode = 1; |
| 128617 | 128813 | }else if( pExpr->op==TK_FUNCTION ){ |
| 128618 | 128814 | int d1; |
| 128619 | | - char d2[3]; |
| 128815 | + char d2[4]; |
| 128620 | 128816 | if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){ |
| 128621 | 128817 | pWalker->eCode = 1; |
| 128622 | 128818 | } |
| 128623 | 128819 | } |
| 128624 | 128820 | |
| | @@ -128837,11 +129033,11 @@ |
| 128837 | 129033 | ** this case, generate code to evaluate the expression and leave the |
| 128838 | 129034 | ** result in register iReg. |
| 128839 | 129035 | */ |
| 128840 | 129036 | static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){ |
| 128841 | 129037 | assert( nReg>0 ); |
| 128842 | | - if( sqlite3ExprIsVector(p) ){ |
| 129038 | + if( p && sqlite3ExprIsVector(p) ){ |
| 128843 | 129039 | #ifndef SQLITE_OMIT_SUBQUERY |
| 128844 | 129040 | if( (p->flags & EP_xIsSelect) ){ |
| 128845 | 129041 | Vdbe *v = pParse->pVdbe; |
| 128846 | 129042 | int iSelect = sqlite3CodeSubselect(pParse, p, 0, 0); |
| 128847 | 129043 | sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1); |
| | @@ -128890,13 +129086,13 @@ |
| 128890 | 129086 | return WRC_Continue; |
| 128891 | 129087 | } |
| 128892 | 129088 | } |
| 128893 | 129089 | |
| 128894 | 129090 | /* |
| 128895 | | -** For an indexes on expression X, locate every instance of expression X in pExpr |
| 128896 | | -** and change that subexpression into a reference to the appropriate column of |
| 128897 | | -** the index. |
| 129091 | +** For an indexes on expression X, locate every instance of expression X |
| 129092 | +** in pExpr and change that subexpression into a reference to the appropriate |
| 129093 | +** column of the index. |
| 128898 | 129094 | */ |
| 128899 | 129095 | static void whereIndexExprTrans( |
| 128900 | 129096 | Index *pIdx, /* The Index */ |
| 128901 | 129097 | int iTabCur, /* Cursor of the table that is being indexed */ |
| 128902 | 129098 | int iIdxCur, /* Cursor of the index itself */ |
| | @@ -130169,16 +130365,16 @@ |
| 130169 | 130365 | Expr *pExpr, /* Test this expression */ |
| 130170 | 130366 | Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */ |
| 130171 | 130367 | int *pisComplete, /* True if the only wildcard is % in the last character */ |
| 130172 | 130368 | int *pnoCase /* True if uppercase is equivalent to lowercase */ |
| 130173 | 130369 | ){ |
| 130174 | | - const char *z = 0; /* String on RHS of LIKE operator */ |
| 130370 | + const u8 *z = 0; /* String on RHS of LIKE operator */ |
| 130175 | 130371 | Expr *pRight, *pLeft; /* Right and left size of LIKE operator */ |
| 130176 | 130372 | ExprList *pList; /* List of operands to the LIKE operator */ |
| 130177 | 130373 | int c; /* One character in z[] */ |
| 130178 | 130374 | int cnt; /* Number of non-wildcard prefix characters */ |
| 130179 | | - char wc[3]; /* Wildcard characters */ |
| 130375 | + char wc[4]; /* Wildcard characters */ |
| 130180 | 130376 | sqlite3 *db = pParse->db; /* Database connection */ |
| 130181 | 130377 | sqlite3_value *pVal = 0; |
| 130182 | 130378 | int op; /* Opcode of pRight */ |
| 130183 | 130379 | int rc; /* Result code to return */ |
| 130184 | 130380 | |
| | @@ -130196,16 +130392,16 @@ |
| 130196 | 130392 | if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){ |
| 130197 | 130393 | Vdbe *pReprepare = pParse->pReprepare; |
| 130198 | 130394 | int iCol = pRight->iColumn; |
| 130199 | 130395 | pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB); |
| 130200 | 130396 | if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){ |
| 130201 | | - z = (char *)sqlite3_value_text(pVal); |
| 130397 | + z = sqlite3_value_text(pVal); |
| 130202 | 130398 | } |
| 130203 | 130399 | sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); |
| 130204 | 130400 | assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); |
| 130205 | 130401 | }else if( op==TK_STRING ){ |
| 130206 | | - z = pRight->u.zToken; |
| 130402 | + z = (u8*)pRight->u.zToken; |
| 130207 | 130403 | } |
| 130208 | 130404 | if( z ){ |
| 130209 | 130405 | |
| 130210 | 130406 | /* If the RHS begins with a digit or a minus sign, then the LHS must |
| 130211 | 130407 | ** be an ordinary column (not a virtual table column) with TEXT affinity. |
| | @@ -130221,20 +130417,46 @@ |
| 130221 | 130417 | ){ |
| 130222 | 130418 | sqlite3ValueFree(pVal); |
| 130223 | 130419 | return 0; |
| 130224 | 130420 | } |
| 130225 | 130421 | } |
| 130422 | + |
| 130423 | + /* Count the number of prefix characters prior to the first wildcard */ |
| 130226 | 130424 | cnt = 0; |
| 130227 | 130425 | while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ |
| 130228 | 130426 | cnt++; |
| 130427 | + if( c==wc[3] && z[cnt]!=0 ) cnt++; |
| 130229 | 130428 | } |
| 130429 | + |
| 130430 | + /* The optimization is possible only if (1) the pattern does not begin |
| 130431 | + ** with a wildcard and if (2) the non-wildcard prefix does not end with |
| 130432 | + ** an (illegal 0xff) character. The second condition is necessary so |
| 130433 | + ** that we can increment the prefix key to find an upper bound for the |
| 130434 | + ** range search. |
| 130435 | + */ |
| 130230 | 130436 | if( cnt!=0 && 255!=(u8)z[cnt-1] ){ |
| 130231 | 130437 | Expr *pPrefix; |
| 130438 | + |
| 130439 | + /* A "complete" match if the pattern ends with "*" or "%" */ |
| 130232 | 130440 | *pisComplete = c==wc[0] && z[cnt+1]==0; |
| 130233 | | - pPrefix = sqlite3Expr(db, TK_STRING, z); |
| 130234 | | - if( pPrefix ) pPrefix->u.zToken[cnt] = 0; |
| 130441 | + |
| 130442 | + /* Get the pattern prefix. Remove all escapes from the prefix. */ |
| 130443 | + pPrefix = sqlite3Expr(db, TK_STRING, (char*)z); |
| 130444 | + if( pPrefix ){ |
| 130445 | + int iFrom, iTo; |
| 130446 | + char *zNew = pPrefix->u.zToken; |
| 130447 | + zNew[cnt] = 0; |
| 130448 | + for(iFrom=iTo=0; iFrom<cnt; iFrom++){ |
| 130449 | + if( zNew[iFrom]==wc[3] ) iFrom++; |
| 130450 | + zNew[iTo++] = zNew[iFrom]; |
| 130451 | + } |
| 130452 | + zNew[iTo] = 0; |
| 130453 | + } |
| 130235 | 130454 | *ppPrefix = pPrefix; |
| 130455 | + |
| 130456 | + /* If the RHS pattern is a bound parameter, make arrangements to |
| 130457 | + ** reprepare the statement when that parameter is rebound */ |
| 130236 | 130458 | if( op==TK_VARIABLE ){ |
| 130237 | 130459 | Vdbe *v = pParse->pVdbe; |
| 130238 | 130460 | sqlite3VdbeSetVarmask(v, pRight->iColumn); |
| 130239 | 130461 | if( *pisComplete && pRight->u.zToken[1] ){ |
| 130240 | 130462 | /* If the rhs of the LIKE expression is a variable, and the current |
| | @@ -130261,52 +130483,88 @@ |
| 130261 | 130483 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 130262 | 130484 | |
| 130263 | 130485 | |
| 130264 | 130486 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 130265 | 130487 | /* |
| 130266 | | -** Check to see if the given expression is of the form |
| 130267 | | -** |
| 130268 | | -** column OP expr |
| 130269 | | -** |
| 130270 | | -** where OP is one of MATCH, GLOB, LIKE or REGEXP and "column" is a |
| 130271 | | -** column of a virtual table. |
| 130272 | | -** |
| 130273 | | -** If it is then return TRUE. If not, return FALSE. |
| 130274 | | -*/ |
| 130275 | | -static int isMatchOfColumn( |
| 130488 | +** Check to see if the pExpr expression is a form that needs to be passed |
| 130489 | +** to the xBestIndex method of virtual tables. Forms of interest include: |
| 130490 | +** |
| 130491 | +** Expression Virtual Table Operator |
| 130492 | +** ----------------------- --------------------------------- |
| 130493 | +** 1. column MATCH expr SQLITE_INDEX_CONSTRAINT_MATCH |
| 130494 | +** 2. column GLOB expr SQLITE_INDEX_CONSTRAINT_GLOB |
| 130495 | +** 3. column LIKE expr SQLITE_INDEX_CONSTRAINT_LIKE |
| 130496 | +** 4. column REGEXP expr SQLITE_INDEX_CONSTRAINT_REGEXP |
| 130497 | +** 5. column != expr SQLITE_INDEX_CONSTRAINT_NE |
| 130498 | +** 6. expr != column SQLITE_INDEX_CONSTRAINT_NE |
| 130499 | +** 7. column IS NOT expr SQLITE_INDEX_CONSTRAINT_ISNOT |
| 130500 | +** 8. expr IS NOT column SQLITE_INDEX_CONSTRAINT_ISNOT |
| 130501 | +** 9. column IS NOT NULL SQLITE_INDEX_CONSTRAINT_ISNOTNULL |
| 130502 | +** |
| 130503 | +** In every case, "column" must be a column of a virtual table. If there |
| 130504 | +** is a match, set *ppLeft to the "column" expression, set *ppRight to the |
| 130505 | +** "expr" expression (even though in forms (6) and (8) the column is on the |
| 130506 | +** right and the expression is on the left). Also set *peOp2 to the |
| 130507 | +** appropriate virtual table operator. The return value is 1 or 2 if there |
| 130508 | +** is a match. The usual return is 1, but if the RHS is also a column |
| 130509 | +** of virtual table in forms (5) or (7) then return 2. |
| 130510 | +** |
| 130511 | +** If the expression matches none of the patterns above, return 0. |
| 130512 | +*/ |
| 130513 | +static int isAuxiliaryVtabOperator( |
| 130276 | 130514 | Expr *pExpr, /* Test this expression */ |
| 130277 | | - unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */ |
| 130515 | + unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */ |
| 130516 | + Expr **ppLeft, /* Column expression to left of MATCH/op2 */ |
| 130517 | + Expr **ppRight /* Expression to left of MATCH/op2 */ |
| 130278 | 130518 | ){ |
| 130279 | | - static const struct Op2 { |
| 130280 | | - const char *zOp; |
| 130281 | | - unsigned char eOp2; |
| 130282 | | - } aOp[] = { |
| 130283 | | - { "match", SQLITE_INDEX_CONSTRAINT_MATCH }, |
| 130284 | | - { "glob", SQLITE_INDEX_CONSTRAINT_GLOB }, |
| 130285 | | - { "like", SQLITE_INDEX_CONSTRAINT_LIKE }, |
| 130286 | | - { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP } |
| 130287 | | - }; |
| 130288 | | - ExprList *pList; |
| 130289 | | - Expr *pCol; /* Column reference */ |
| 130290 | | - int i; |
| 130291 | | - |
| 130292 | | - if( pExpr->op!=TK_FUNCTION ){ |
| 130293 | | - return 0; |
| 130294 | | - } |
| 130295 | | - pList = pExpr->x.pList; |
| 130296 | | - if( pList==0 || pList->nExpr!=2 ){ |
| 130297 | | - return 0; |
| 130298 | | - } |
| 130299 | | - pCol = pList->a[1].pExpr; |
| 130300 | | - if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){ |
| 130301 | | - return 0; |
| 130302 | | - } |
| 130303 | | - for(i=0; i<ArraySize(aOp); i++){ |
| 130304 | | - if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 130305 | | - *peOp2 = aOp[i].eOp2; |
| 130306 | | - return 1; |
| 130307 | | - } |
| 130519 | + if( pExpr->op==TK_FUNCTION ){ |
| 130520 | + static const struct Op2 { |
| 130521 | + const char *zOp; |
| 130522 | + unsigned char eOp2; |
| 130523 | + } aOp[] = { |
| 130524 | + { "match", SQLITE_INDEX_CONSTRAINT_MATCH }, |
| 130525 | + { "glob", SQLITE_INDEX_CONSTRAINT_GLOB }, |
| 130526 | + { "like", SQLITE_INDEX_CONSTRAINT_LIKE }, |
| 130527 | + { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP } |
| 130528 | + }; |
| 130529 | + ExprList *pList; |
| 130530 | + Expr *pCol; /* Column reference */ |
| 130531 | + int i; |
| 130532 | + |
| 130533 | + pList = pExpr->x.pList; |
| 130534 | + if( pList==0 || pList->nExpr!=2 ){ |
| 130535 | + return 0; |
| 130536 | + } |
| 130537 | + pCol = pList->a[1].pExpr; |
| 130538 | + if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){ |
| 130539 | + return 0; |
| 130540 | + } |
| 130541 | + for(i=0; i<ArraySize(aOp); i++){ |
| 130542 | + if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 130543 | + *peOp2 = aOp[i].eOp2; |
| 130544 | + *ppRight = pList->a[0].pExpr; |
| 130545 | + *ppLeft = pCol; |
| 130546 | + return 1; |
| 130547 | + } |
| 130548 | + } |
| 130549 | + }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 130550 | + int res = 0; |
| 130551 | + Expr *pLeft = pExpr->pLeft; |
| 130552 | + Expr *pRight = pExpr->pRight; |
| 130553 | + if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->pTab) ){ |
| 130554 | + res++; |
| 130555 | + } |
| 130556 | + if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->pTab) ){ |
| 130557 | + res++; |
| 130558 | + SWAP(Expr*, pLeft, pRight); |
| 130559 | + } |
| 130560 | + *ppLeft = pLeft; |
| 130561 | + *ppRight = pRight; |
| 130562 | + if( pExpr->op==TK_NE ) *peOp2 = SQLITE_INDEX_CONSTRAINT_NE; |
| 130563 | + if( pExpr->op==TK_ISNOT ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOT; |
| 130564 | + if( pExpr->op==TK_NOTNULL ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOTNULL; |
| 130565 | + return res; |
| 130308 | 130566 | } |
| 130309 | 130567 | return 0; |
| 130310 | 130568 | } |
| 130311 | 130569 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 130312 | 130570 | |
| | @@ -130553,11 +130811,11 @@ |
| 130553 | 130811 | pAndWC->pOuter = pWC; |
| 130554 | 130812 | if( !db->mallocFailed ){ |
| 130555 | 130813 | for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){ |
| 130556 | 130814 | assert( pAndTerm->pExpr ); |
| 130557 | 130815 | if( allowedOp(pAndTerm->pExpr->op) |
| 130558 | | - || pAndTerm->eOperator==WO_MATCH |
| 130816 | + || pAndTerm->eOperator==WO_AUX |
| 130559 | 130817 | ){ |
| 130560 | 130818 | b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pAndTerm->leftCursor); |
| 130561 | 130819 | } |
| 130562 | 130820 | } |
| 130563 | 130821 | } |
| | @@ -131135,45 +131393,50 @@ |
| 131135 | 131393 | } |
| 131136 | 131394 | } |
| 131137 | 131395 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 131138 | 131396 | |
| 131139 | 131397 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 131140 | | - /* Add a WO_MATCH auxiliary term to the constraint set if the |
| 131141 | | - ** current expression is of the form: column MATCH expr. |
| 131398 | + /* Add a WO_AUX auxiliary term to the constraint set if the |
| 131399 | + ** current expression is of the form "column OP expr" where OP |
| 131400 | + ** is an operator that gets passed into virtual tables but which is |
| 131401 | + ** not normally optimized for ordinary tables. In other words, OP |
| 131402 | + ** is one of MATCH, LIKE, GLOB, REGEXP, !=, IS, IS NOT, or NOT NULL. |
| 131142 | 131403 | ** This information is used by the xBestIndex methods of |
| 131143 | 131404 | ** virtual tables. The native query optimizer does not attempt |
| 131144 | 131405 | ** to do anything with MATCH functions. |
| 131145 | 131406 | */ |
| 131146 | | - if( pWC->op==TK_AND && isMatchOfColumn(pExpr, &eOp2) ){ |
| 131147 | | - int idxNew; |
| 131407 | + if( pWC->op==TK_AND ){ |
| 131148 | 131408 | Expr *pRight, *pLeft; |
| 131149 | | - WhereTerm *pNewTerm; |
| 131150 | | - Bitmask prereqColumn, prereqExpr; |
| 131151 | | - |
| 131152 | | - pRight = pExpr->x.pList->a[0].pExpr; |
| 131153 | | - pLeft = pExpr->x.pList->a[1].pExpr; |
| 131154 | | - prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight); |
| 131155 | | - prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft); |
| 131156 | | - if( (prereqExpr & prereqColumn)==0 ){ |
| 131157 | | - Expr *pNewExpr; |
| 131158 | | - pNewExpr = sqlite3PExpr(pParse, TK_MATCH, |
| 131159 | | - 0, sqlite3ExprDup(db, pRight, 0)); |
| 131160 | | - if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ |
| 131161 | | - ExprSetProperty(pNewExpr, EP_FromJoin); |
| 131162 | | - } |
| 131163 | | - idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 131164 | | - testcase( idxNew==0 ); |
| 131165 | | - pNewTerm = &pWC->a[idxNew]; |
| 131166 | | - pNewTerm->prereqRight = prereqExpr; |
| 131167 | | - pNewTerm->leftCursor = pLeft->iTable; |
| 131168 | | - pNewTerm->u.leftColumn = pLeft->iColumn; |
| 131169 | | - pNewTerm->eOperator = WO_MATCH; |
| 131170 | | - pNewTerm->eMatchOp = eOp2; |
| 131171 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 131172 | | - pTerm = &pWC->a[idxTerm]; |
| 131173 | | - pTerm->wtFlags |= TERM_COPIED; |
| 131174 | | - pNewTerm->prereqAll = pTerm->prereqAll; |
| 131409 | + int res = isAuxiliaryVtabOperator(pExpr, &eOp2, &pLeft, &pRight); |
| 131410 | + while( res-- > 0 ){ |
| 131411 | + int idxNew; |
| 131412 | + WhereTerm *pNewTerm; |
| 131413 | + Bitmask prereqColumn, prereqExpr; |
| 131414 | + |
| 131415 | + prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight); |
| 131416 | + prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft); |
| 131417 | + if( (prereqExpr & prereqColumn)==0 ){ |
| 131418 | + Expr *pNewExpr; |
| 131419 | + pNewExpr = sqlite3PExpr(pParse, TK_MATCH, |
| 131420 | + 0, sqlite3ExprDup(db, pRight, 0)); |
| 131421 | + if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ |
| 131422 | + ExprSetProperty(pNewExpr, EP_FromJoin); |
| 131423 | + } |
| 131424 | + idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 131425 | + testcase( idxNew==0 ); |
| 131426 | + pNewTerm = &pWC->a[idxNew]; |
| 131427 | + pNewTerm->prereqRight = prereqExpr; |
| 131428 | + pNewTerm->leftCursor = pLeft->iTable; |
| 131429 | + pNewTerm->u.leftColumn = pLeft->iColumn; |
| 131430 | + pNewTerm->eOperator = WO_AUX; |
| 131431 | + pNewTerm->eMatchOp = eOp2; |
| 131432 | + markTermAsChild(pWC, idxNew, idxTerm); |
| 131433 | + pTerm = &pWC->a[idxTerm]; |
| 131434 | + pTerm->wtFlags |= TERM_COPIED; |
| 131435 | + pNewTerm->prereqAll = pTerm->prereqAll; |
| 131436 | + } |
| 131437 | + SWAP(Expr*, pLeft, pRight); |
| 131175 | 131438 | } |
| 131176 | 131439 | } |
| 131177 | 131440 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 131178 | 131441 | |
| 131179 | 131442 | /* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create |
| | @@ -132313,11 +132576,11 @@ |
| 132313 | 132576 | assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) ); |
| 132314 | 132577 | testcase( pTerm->eOperator & WO_IN ); |
| 132315 | 132578 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 132316 | 132579 | testcase( pTerm->eOperator & WO_IS ); |
| 132317 | 132580 | testcase( pTerm->eOperator & WO_ALL ); |
| 132318 | | - if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue; |
| 132581 | + if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 132319 | 132582 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 132320 | 132583 | assert( pTerm->u.leftColumn>=(-1) ); |
| 132321 | 132584 | nTerm++; |
| 132322 | 132585 | } |
| 132323 | 132586 | |
| | @@ -132361,46 +132624,52 @@ |
| 132361 | 132624 | *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy; |
| 132362 | 132625 | *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = |
| 132363 | 132626 | pUsage; |
| 132364 | 132627 | |
| 132365 | 132628 | for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 132366 | | - u8 op; |
| 132629 | + u16 op; |
| 132367 | 132630 | if( pTerm->leftCursor != pSrc->iCursor ) continue; |
| 132368 | 132631 | if( pTerm->prereqRight & mUnusable ) continue; |
| 132369 | 132632 | assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) ); |
| 132370 | 132633 | testcase( pTerm->eOperator & WO_IN ); |
| 132371 | 132634 | testcase( pTerm->eOperator & WO_IS ); |
| 132372 | 132635 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 132373 | 132636 | testcase( pTerm->eOperator & WO_ALL ); |
| 132374 | | - if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue; |
| 132637 | + if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 132375 | 132638 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 132376 | 132639 | assert( pTerm->u.leftColumn>=(-1) ); |
| 132377 | 132640 | pIdxCons[j].iColumn = pTerm->u.leftColumn; |
| 132378 | 132641 | pIdxCons[j].iTermOffset = i; |
| 132379 | | - op = (u8)pTerm->eOperator & WO_ALL; |
| 132642 | + op = pTerm->eOperator & WO_ALL; |
| 132380 | 132643 | if( op==WO_IN ) op = WO_EQ; |
| 132381 | | - if( op==WO_MATCH ){ |
| 132382 | | - op = pTerm->eMatchOp; |
| 132383 | | - } |
| 132384 | | - pIdxCons[j].op = op; |
| 132385 | | - /* The direct assignment in the previous line is possible only because |
| 132386 | | - ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The |
| 132387 | | - ** following asserts verify this fact. */ |
| 132388 | | - assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ ); |
| 132389 | | - assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT ); |
| 132390 | | - assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE ); |
| 132391 | | - assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT ); |
| 132392 | | - assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE ); |
| 132393 | | - assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH ); |
| 132394 | | - assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) ); |
| 132395 | | - |
| 132396 | | - if( op & (WO_LT|WO_LE|WO_GT|WO_GE) |
| 132397 | | - && sqlite3ExprIsVector(pTerm->pExpr->pRight) |
| 132398 | | - ){ |
| 132399 | | - if( i<16 ) mNoOmit |= (1 << i); |
| 132400 | | - if( op==WO_LT ) pIdxCons[j].op = WO_LE; |
| 132401 | | - if( op==WO_GT ) pIdxCons[j].op = WO_GE; |
| 132644 | + if( op==WO_AUX ){ |
| 132645 | + pIdxCons[j].op = pTerm->eMatchOp; |
| 132646 | + }else if( op & (WO_ISNULL|WO_IS) ){ |
| 132647 | + if( op==WO_ISNULL ){ |
| 132648 | + pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL; |
| 132649 | + }else{ |
| 132650 | + pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS; |
| 132651 | + } |
| 132652 | + }else{ |
| 132653 | + pIdxCons[j].op = (u8)op; |
| 132654 | + /* The direct assignment in the previous line is possible only because |
| 132655 | + ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The |
| 132656 | + ** following asserts verify this fact. */ |
| 132657 | + assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ ); |
| 132658 | + assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT ); |
| 132659 | + assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE ); |
| 132660 | + assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT ); |
| 132661 | + assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE ); |
| 132662 | + assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) ); |
| 132663 | + |
| 132664 | + if( op & (WO_LT|WO_LE|WO_GT|WO_GE) |
| 132665 | + && sqlite3ExprIsVector(pTerm->pExpr->pRight) |
| 132666 | + ){ |
| 132667 | + if( i<16 ) mNoOmit |= (1 << i); |
| 132668 | + if( op==WO_LT ) pIdxCons[j].op = WO_LE; |
| 132669 | + if( op==WO_GT ) pIdxCons[j].op = WO_GE; |
| 132670 | + } |
| 132402 | 132671 | } |
| 132403 | 132672 | |
| 132404 | 132673 | j++; |
| 132405 | 132674 | } |
| 132406 | 132675 | for(i=0; i<nOrderBy; i++){ |
| | @@ -135134,11 +135403,11 @@ |
| 135134 | 135403 | if( sqlite3ExprCompare(0, |
| 135135 | 135404 | pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){ |
| 135136 | 135405 | continue; |
| 135137 | 135406 | } |
| 135138 | 135407 | } |
| 135139 | | - if( iColumn>=0 ){ |
| 135408 | + if( iColumn!=XN_ROWID ){ |
| 135140 | 135409 | pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr); |
| 135141 | 135410 | if( !pColl ) pColl = db->pDfltColl; |
| 135142 | 135411 | if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue; |
| 135143 | 135412 | } |
| 135144 | 135413 | pLoop->u.btree.nIdxCol = j+1; |
| | @@ -135773,10 +136042,11 @@ |
| 135773 | 136042 | static int exprIsDeterministic(Expr *p){ |
| 135774 | 136043 | Walker w; |
| 135775 | 136044 | memset(&w, 0, sizeof(w)); |
| 135776 | 136045 | w.eCode = 1; |
| 135777 | 136046 | w.xExprCallback = exprNodeIsDeterministic; |
| 136047 | + w.xSelectCallback = sqlite3SelectWalkFail; |
| 135778 | 136048 | sqlite3WalkExpr(&w, p); |
| 135779 | 136049 | return w.eCode; |
| 135780 | 136050 | } |
| 135781 | 136051 | |
| 135782 | 136052 | /* |
| | @@ -135982,41 +136252,42 @@ |
| 135982 | 136252 | if( nTabList==0 ){ |
| 135983 | 136253 | if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr; |
| 135984 | 136254 | if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 135985 | 136255 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 135986 | 136256 | } |
| 135987 | | - } |
| 135988 | | - |
| 135989 | | - /* Assign a bit from the bitmask to every term in the FROM clause. |
| 135990 | | - ** |
| 135991 | | - ** The N-th term of the FROM clause is assigned a bitmask of 1<<N. |
| 135992 | | - ** |
| 135993 | | - ** The rule of the previous sentence ensures thta if X is the bitmask for |
| 135994 | | - ** a table T, then X-1 is the bitmask for all other tables to the left of T. |
| 135995 | | - ** Knowing the bitmask for all tables to the left of a left join is |
| 135996 | | - ** important. Ticket #3015. |
| 135997 | | - ** |
| 135998 | | - ** Note that bitmasks are created for all pTabList->nSrc tables in |
| 135999 | | - ** pTabList, not just the first nTabList tables. nTabList is normally |
| 136000 | | - ** equal to pTabList->nSrc but might be shortened to 1 if the |
| 136001 | | - ** WHERE_OR_SUBCLAUSE flag is set. |
| 136002 | | - */ |
| 136003 | | - for(ii=0; ii<pTabList->nSrc; ii++){ |
| 136004 | | - createMask(pMaskSet, pTabList->a[ii].iCursor); |
| 136005 | | - sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC); |
| 136006 | | - } |
| 136007 | | -#ifdef SQLITE_DEBUG |
| 136008 | | - { |
| 136009 | | - Bitmask mx = 0; |
| 136010 | | - for(ii=0; ii<pTabList->nSrc; ii++){ |
| 136011 | | - Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor); |
| 136012 | | - assert( m>=mx ); |
| 136013 | | - mx = m; |
| 136014 | | - } |
| 136015 | | - } |
| 136016 | | -#endif |
| 136017 | | - |
| 136257 | + }else{ |
| 136258 | + /* Assign a bit from the bitmask to every term in the FROM clause. |
| 136259 | + ** |
| 136260 | + ** The N-th term of the FROM clause is assigned a bitmask of 1<<N. |
| 136261 | + ** |
| 136262 | + ** The rule of the previous sentence ensures thta if X is the bitmask for |
| 136263 | + ** a table T, then X-1 is the bitmask for all other tables to the left of T. |
| 136264 | + ** Knowing the bitmask for all tables to the left of a left join is |
| 136265 | + ** important. Ticket #3015. |
| 136266 | + ** |
| 136267 | + ** Note that bitmasks are created for all pTabList->nSrc tables in |
| 136268 | + ** pTabList, not just the first nTabList tables. nTabList is normally |
| 136269 | + ** equal to pTabList->nSrc but might be shortened to 1 if the |
| 136270 | + ** WHERE_OR_SUBCLAUSE flag is set. |
| 136271 | + */ |
| 136272 | + ii = 0; |
| 136273 | + do{ |
| 136274 | + createMask(pMaskSet, pTabList->a[ii].iCursor); |
| 136275 | + sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC); |
| 136276 | + }while( (++ii)<pTabList->nSrc ); |
| 136277 | + #ifdef SQLITE_DEBUG |
| 136278 | + { |
| 136279 | + Bitmask mx = 0; |
| 136280 | + for(ii=0; ii<pTabList->nSrc; ii++){ |
| 136281 | + Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor); |
| 136282 | + assert( m>=mx ); |
| 136283 | + mx = m; |
| 136284 | + } |
| 136285 | + } |
| 136286 | + #endif |
| 136287 | + } |
| 136288 | + |
| 136018 | 136289 | /* Analyze all of the subexpressions. */ |
| 136019 | 136290 | sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); |
| 136020 | 136291 | if( db->mallocFailed ) goto whereBeginError; |
| 136021 | 136292 | |
| 136022 | 136293 | /* Special case: WHERE terms that do not refer to any tables in the join |
| | @@ -136235,11 +136506,11 @@ |
| 136235 | 136506 | } |
| 136236 | 136507 | if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 136237 | 136508 | Index *pIx = pLoop->u.btree.pIndex; |
| 136238 | 136509 | int iIndexCur; |
| 136239 | 136510 | int op = OP_OpenRead; |
| 136240 | | - /* iAuxArg is always set if to a positive value if ONEPASS is possible */ |
| 136511 | + /* iAuxArg is always set to a positive value if ONEPASS is possible */ |
| 136241 | 136512 | assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 ); |
| 136242 | 136513 | if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx) |
| 136243 | 136514 | && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 |
| 136244 | 136515 | ){ |
| 136245 | 136516 | /* This is one term of an OR-optimization using the PRIMARY KEY of a |
| | @@ -136828,11 +137099,11 @@ |
| 136828 | 137099 | #endif |
| 136829 | 137100 | /************* Begin control #defines *****************************************/ |
| 136830 | 137101 | #define YYCODETYPE unsigned char |
| 136831 | 137102 | #define YYNOCODE 252 |
| 136832 | 137103 | #define YYACTIONTYPE unsigned short int |
| 136833 | | -#define YYWILDCARD 69 |
| 137104 | +#define YYWILDCARD 83 |
| 136834 | 137105 | #define sqlite3ParserTOKENTYPE Token |
| 136835 | 137106 | typedef union { |
| 136836 | 137107 | int yyinit; |
| 136837 | 137108 | sqlite3ParserTOKENTYPE yy0; |
| 136838 | 137109 | Expr* yy72; |
| | @@ -136935,419 +137206,419 @@ |
| 136935 | 137206 | ** yy_reduce_ofst[] For each state, the offset into yy_action for |
| 136936 | 137207 | ** shifting non-terminals after a reduce. |
| 136937 | 137208 | ** yy_default[] Default action for each state. |
| 136938 | 137209 | ** |
| 136939 | 137210 | *********** Begin parsing tables **********************************************/ |
| 136940 | | -#define YY_ACTTAB_COUNT (1565) |
| 137211 | +#define YY_ACTTAB_COUNT (1566) |
| 136941 | 137212 | static const YYACTIONTYPE yy_action[] = { |
| 136942 | | - /* 0 */ 324, 410, 342, 747, 747, 203, 939, 353, 969, 98, |
| 136943 | | - /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95, |
| 136944 | | - /* 20 */ 94, 94, 94, 93, 350, 1323, 155, 155, 2, 808, |
| 136945 | | - /* 30 */ 971, 971, 98, 98, 98, 98, 20, 96, 96, 96, |
| 136946 | | - /* 40 */ 96, 95, 95, 94, 94, 94, 93, 350, 92, 89, |
| 136947 | | - /* 50 */ 178, 99, 100, 90, 847, 850, 839, 839, 97, 97, |
| 136948 | | - /* 60 */ 98, 98, 98, 98, 350, 96, 96, 96, 96, 95, |
| 136949 | | - /* 70 */ 95, 94, 94, 94, 93, 350, 324, 339, 969, 262, |
| 136950 | | - /* 80 */ 364, 251, 212, 169, 287, 404, 282, 403, 199, 786, |
| 136951 | | - /* 90 */ 242, 411, 21, 950, 378, 280, 93, 350, 787, 95, |
| 136952 | | - /* 100 */ 95, 94, 94, 94, 93, 350, 971, 971, 96, 96, |
| 136953 | | - /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 808, |
| 136954 | | - /* 120 */ 328, 242, 411, 1235, 826, 1235, 132, 99, 100, 90, |
| 136955 | | - /* 130 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, |
| 136956 | | - /* 140 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94, |
| 136957 | | - /* 150 */ 93, 350, 324, 819, 348, 347, 120, 818, 120, 75, |
| 136958 | | - /* 160 */ 52, 52, 950, 951, 952, 1084, 977, 146, 360, 262, |
| 136959 | | - /* 170 */ 369, 261, 950, 975, 954, 976, 92, 89, 178, 370, |
| 136960 | | - /* 180 */ 230, 370, 971, 971, 1141, 360, 359, 101, 818, 818, |
| 136961 | | - /* 190 */ 820, 383, 24, 1286, 380, 427, 412, 368, 978, 379, |
| 136962 | | - /* 200 */ 978, 1032, 324, 99, 100, 90, 847, 850, 839, 839, |
| 136963 | | - /* 210 */ 97, 97, 98, 98, 98, 98, 372, 96, 96, 96, |
| 136964 | | - /* 220 */ 96, 95, 95, 94, 94, 94, 93, 350, 950, 132, |
| 136965 | | - /* 230 */ 890, 449, 971, 971, 890, 60, 94, 94, 94, 93, |
| 136966 | | - /* 240 */ 350, 950, 951, 952, 954, 103, 360, 950, 384, 333, |
| 136967 | | - /* 250 */ 697, 52, 52, 99, 100, 90, 847, 850, 839, 839, |
| 136968 | | - /* 260 */ 97, 97, 98, 98, 98, 98, 1022, 96, 96, 96, |
| 136969 | | - /* 270 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 454, |
| 136970 | | - /* 280 */ 995, 449, 227, 61, 157, 243, 343, 114, 1025, 1211, |
| 136971 | | - /* 290 */ 147, 826, 950, 372, 1071, 950, 319, 950, 951, 952, |
| 136972 | | - /* 300 */ 194, 10, 10, 401, 398, 397, 1211, 1213, 971, 971, |
| 136973 | | - /* 310 */ 757, 171, 170, 157, 396, 336, 950, 951, 952, 697, |
| 136974 | | - /* 320 */ 819, 310, 153, 950, 818, 320, 82, 23, 80, 99, |
| 136975 | | - /* 330 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98, |
| 136976 | | - /* 340 */ 98, 98, 888, 96, 96, 96, 96, 95, 95, 94, |
| 136977 | | - /* 350 */ 94, 94, 93, 350, 324, 818, 818, 820, 277, 231, |
| 136978 | | - /* 360 */ 300, 950, 951, 952, 950, 951, 952, 1211, 194, 25, |
| 136979 | | - /* 370 */ 449, 401, 398, 397, 950, 354, 300, 449, 950, 74, |
| 136980 | | - /* 380 */ 449, 1, 396, 132, 971, 971, 950, 224, 224, 808, |
| 136981 | | - /* 390 */ 10, 10, 950, 951, 952, 1290, 132, 52, 52, 414, |
| 136982 | | - /* 400 */ 52, 52, 1063, 1063, 338, 99, 100, 90, 847, 850, |
| 136983 | | - /* 410 */ 839, 839, 97, 97, 98, 98, 98, 98, 1114, 96, |
| 136984 | | - /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350, |
| 136985 | | - /* 430 */ 324, 1113, 427, 417, 701, 427, 426, 1260, 1260, 262, |
| 136986 | | - /* 440 */ 369, 261, 950, 950, 951, 952, 752, 950, 951, 952, |
| 136987 | | - /* 450 */ 449, 751, 449, 1058, 1037, 950, 951, 952, 442, 706, |
| 136988 | | - /* 460 */ 971, 971, 1058, 393, 92, 89, 178, 446, 446, 446, |
| 136989 | | - /* 470 */ 51, 51, 52, 52, 438, 773, 1024, 92, 89, 178, |
| 136990 | | - /* 480 */ 172, 99, 100, 90, 847, 850, 839, 839, 97, 97, |
| 136991 | | - /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95, |
| 136992 | | - /* 500 */ 95, 94, 94, 94, 93, 350, 324, 427, 407, 909, |
| 136993 | | - /* 510 */ 694, 950, 951, 952, 92, 89, 178, 224, 224, 157, |
| 136994 | | - /* 520 */ 241, 221, 418, 299, 771, 910, 415, 374, 449, 414, |
| 136995 | | - /* 530 */ 58, 323, 1061, 1061, 1242, 378, 971, 971, 378, 772, |
| 136996 | | - /* 540 */ 448, 911, 362, 735, 296, 681, 9, 9, 52, 52, |
| 136997 | | - /* 550 */ 234, 329, 234, 256, 416, 736, 280, 99, 100, 90, |
| 136998 | | - /* 560 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, |
| 136999 | | - /* 570 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94, |
| 137000 | | - /* 580 */ 93, 350, 324, 422, 72, 449, 827, 120, 367, 449, |
| 137001 | | - /* 590 */ 10, 10, 5, 301, 203, 449, 177, 969, 253, 419, |
| 137002 | | - /* 600 */ 255, 771, 200, 175, 233, 10, 10, 836, 836, 36, |
| 137003 | | - /* 610 */ 36, 1289, 971, 971, 724, 37, 37, 348, 347, 424, |
| 137004 | | - /* 620 */ 203, 260, 771, 969, 232, 930, 1316, 870, 337, 1316, |
| 137005 | | - /* 630 */ 421, 848, 851, 99, 100, 90, 847, 850, 839, 839, |
| 137006 | | - /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96, |
| 137007 | | - /* 650 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 840, |
| 137008 | | - /* 660 */ 449, 978, 813, 978, 1200, 449, 909, 969, 715, 349, |
| 137009 | | - /* 670 */ 349, 349, 928, 177, 449, 930, 1317, 254, 198, 1317, |
| 137010 | | - /* 680 */ 12, 12, 910, 402, 449, 27, 27, 250, 971, 971, |
| 137011 | | - /* 690 */ 118, 716, 162, 969, 38, 38, 268, 176, 911, 771, |
| 137012 | | - /* 700 */ 432, 1265, 939, 353, 39, 39, 316, 991, 324, 99, |
| 137013 | | - /* 710 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98, |
| 137014 | | - /* 720 */ 98, 98, 928, 96, 96, 96, 96, 95, 95, 94, |
| 137015 | | - /* 730 */ 94, 94, 93, 350, 449, 329, 449, 357, 971, 971, |
| 137016 | | - /* 740 */ 1041, 316, 929, 340, 893, 893, 386, 669, 670, 671, |
| 137017 | | - /* 750 */ 275, 1318, 317, 992, 40, 40, 41, 41, 268, 99, |
| 137018 | | - /* 760 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98, |
| 137019 | | - /* 770 */ 98, 98, 449, 96, 96, 96, 96, 95, 95, 94, |
| 137020 | | - /* 780 */ 94, 94, 93, 350, 324, 449, 355, 449, 992, 449, |
| 137021 | | - /* 790 */ 1016, 330, 42, 42, 786, 270, 449, 273, 449, 228, |
| 137022 | | - /* 800 */ 449, 298, 449, 787, 449, 28, 28, 29, 29, 31, |
| 137023 | | - /* 810 */ 31, 449, 1141, 449, 971, 971, 43, 43, 44, 44, |
| 137024 | | - /* 820 */ 45, 45, 11, 11, 46, 46, 887, 78, 887, 268, |
| 137025 | | - /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 847, 850, |
| 137026 | | - /* 840 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 96, |
| 137027 | | - /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350, |
| 137028 | | - /* 860 */ 324, 449, 117, 449, 1073, 158, 449, 691, 48, 48, |
| 137029 | | - /* 870 */ 229, 1241, 449, 1250, 449, 414, 449, 334, 449, 245, |
| 137030 | | - /* 880 */ 449, 33, 33, 49, 49, 449, 50, 50, 246, 1141, |
| 137031 | | - /* 890 */ 971, 971, 34, 34, 122, 122, 123, 123, 124, 124, |
| 137032 | | - /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195, |
| 137033 | | - /* 910 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97, |
| 137034 | | - /* 920 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95, |
| 137035 | | - /* 930 */ 95, 94, 94, 94, 93, 350, 449, 691, 449, 1141, |
| 137036 | | - /* 940 */ 971, 971, 968, 1207, 106, 106, 268, 1209, 268, 1266, |
| 137037 | | - /* 950 */ 2, 886, 268, 886, 335, 1040, 53, 53, 107, 107, |
| 137038 | | - /* 960 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97, |
| 137039 | | - /* 970 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95, |
| 137040 | | - /* 980 */ 95, 94, 94, 94, 93, 350, 449, 1070, 449, 1066, |
| 137041 | | - /* 990 */ 971, 971, 1039, 267, 108, 108, 445, 330, 331, 133, |
| 137042 | | - /* 1000 */ 223, 175, 301, 225, 385, 1255, 104, 104, 121, 121, |
| 137043 | | - /* 1010 */ 324, 99, 88, 90, 847, 850, 839, 839, 97, 97, |
| 137044 | | - /* 1020 */ 98, 98, 98, 98, 1141, 96, 96, 96, 96, 95, |
| 137045 | | - /* 1030 */ 95, 94, 94, 94, 93, 350, 449, 346, 449, 167, |
| 137046 | | - /* 1040 */ 971, 971, 925, 810, 371, 318, 202, 202, 373, 263, |
| 137047 | | - /* 1050 */ 394, 202, 74, 208, 721, 722, 119, 119, 112, 112, |
| 137048 | | - /* 1060 */ 324, 406, 100, 90, 847, 850, 839, 839, 97, 97, |
| 137049 | | - /* 1070 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95, |
| 137050 | | - /* 1080 */ 95, 94, 94, 94, 93, 350, 449, 752, 449, 344, |
| 137051 | | - /* 1090 */ 971, 971, 751, 278, 111, 111, 74, 714, 713, 704, |
| 137052 | | - /* 1100 */ 286, 877, 749, 1279, 257, 77, 109, 109, 110, 110, |
| 137053 | | - /* 1110 */ 1230, 285, 1134, 90, 847, 850, 839, 839, 97, 97, |
| 137054 | | - /* 1120 */ 98, 98, 98, 98, 1233, 96, 96, 96, 96, 95, |
| 137055 | | - /* 1130 */ 95, 94, 94, 94, 93, 350, 86, 444, 449, 3, |
| 137056 | | - /* 1140 */ 1193, 449, 1069, 132, 351, 120, 1013, 86, 444, 780, |
| 137057 | | - /* 1150 */ 3, 1091, 202, 376, 447, 351, 1229, 120, 55, 55, |
| 137058 | | - /* 1160 */ 449, 57, 57, 822, 873, 447, 449, 208, 449, 704, |
| 137059 | | - /* 1170 */ 449, 877, 237, 433, 435, 120, 439, 428, 361, 120, |
| 137060 | | - /* 1180 */ 54, 54, 132, 449, 433, 826, 52, 52, 26, 26, |
| 137061 | | - /* 1190 */ 30, 30, 381, 132, 408, 443, 826, 689, 264, 389, |
| 137062 | | - /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120, |
| 137063 | | - /* 1210 */ 120, 276, 85, 351, 451, 450, 83, 84, 818, 1054, |
| 137064 | | - /* 1220 */ 1038, 427, 429, 85, 351, 451, 450, 120, 120, 818, |
| 137065 | | - /* 1230 */ 377, 218, 281, 822, 1107, 1140, 86, 444, 409, 3, |
| 137066 | | - /* 1240 */ 1087, 1098, 430, 431, 351, 302, 303, 1146, 1021, 818, |
| 137067 | | - /* 1250 */ 818, 820, 821, 19, 447, 1015, 1004, 1003, 1005, 1273, |
| 137068 | | - /* 1260 */ 818, 818, 820, 821, 19, 289, 159, 291, 293, 7, |
| 137069 | | - /* 1270 */ 315, 173, 259, 433, 1129, 363, 252, 1232, 375, 1037, |
| 137070 | | - /* 1280 */ 295, 434, 168, 986, 399, 826, 284, 1204, 1203, 205, |
| 137071 | | - /* 1290 */ 1276, 308, 1249, 86, 444, 983, 3, 1247, 332, 144, |
| 137072 | | - /* 1300 */ 130, 351, 72, 135, 59, 83, 84, 756, 137, 365, |
| 137073 | | - /* 1310 */ 1126, 447, 85, 351, 451, 450, 139, 226, 818, 140, |
| 137074 | | - /* 1320 */ 156, 62, 314, 314, 313, 215, 311, 366, 392, 678, |
| 137075 | | - /* 1330 */ 433, 185, 141, 1234, 142, 160, 148, 1136, 1198, 382, |
| 137076 | | - /* 1340 */ 189, 67, 826, 180, 388, 248, 1218, 1099, 219, 818, |
| 137077 | | - /* 1350 */ 818, 820, 821, 19, 247, 190, 266, 154, 390, 271, |
| 137078 | | - /* 1360 */ 191, 192, 83, 84, 1006, 405, 1057, 182, 321, 85, |
| 137079 | | - /* 1370 */ 351, 451, 450, 1056, 183, 818, 341, 132, 181, 706, |
| 137080 | | - /* 1380 */ 1055, 420, 76, 444, 1029, 3, 322, 1028, 283, 1048, |
| 137081 | | - /* 1390 */ 351, 1095, 1027, 1288, 1047, 71, 204, 6, 288, 290, |
| 137082 | | - /* 1400 */ 447, 1096, 1094, 1093, 79, 292, 818, 818, 820, 821, |
| 137083 | | - /* 1410 */ 19, 294, 297, 437, 345, 441, 102, 1184, 1077, 433, |
| 137084 | | - /* 1420 */ 238, 425, 73, 305, 239, 304, 325, 240, 423, 306, |
| 137085 | | - /* 1430 */ 307, 826, 213, 1012, 22, 945, 452, 214, 216, 217, |
| 137086 | | - /* 1440 */ 453, 1001, 115, 996, 125, 126, 235, 127, 665, 352, |
| 137087 | | - /* 1450 */ 326, 83, 84, 358, 166, 244, 179, 327, 85, 351, |
| 137088 | | - /* 1460 */ 451, 450, 134, 356, 818, 113, 885, 806, 883, 136, |
| 137089 | | - /* 1470 */ 128, 138, 738, 258, 184, 899, 143, 145, 63, 64, |
| 137090 | | - /* 1480 */ 65, 66, 129, 902, 187, 186, 898, 8, 13, 188, |
| 137091 | | - /* 1490 */ 265, 891, 149, 202, 980, 818, 818, 820, 821, 19, |
| 137092 | | - /* 1500 */ 150, 387, 161, 680, 285, 391, 151, 395, 400, 193, |
| 137093 | | - /* 1510 */ 68, 14, 236, 279, 15, 69, 717, 825, 131, 824, |
| 137094 | | - /* 1520 */ 853, 70, 746, 16, 413, 750, 4, 174, 220, 222, |
| 137095 | | - /* 1530 */ 152, 779, 857, 774, 201, 77, 74, 868, 17, 854, |
| 137096 | | - /* 1540 */ 852, 908, 18, 907, 207, 206, 934, 163, 436, 210, |
| 137097 | | - /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 690, 87, 211, |
| 137098 | | - /* 1560 */ 309, 312, 1281, 940, 1280, |
| 137213 | + /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93, |
| 137214 | + /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94, |
| 137215 | + /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847, |
| 137216 | + /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350, |
| 137217 | + /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94, |
| 137218 | + /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94, |
| 137219 | + /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95, |
| 137220 | + /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132, |
| 137221 | + /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950, |
| 137222 | + /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132, |
| 137223 | + /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99, |
| 137224 | + /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, |
| 137225 | + /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369, |
| 137226 | + /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398, |
| 137227 | + /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396, |
| 137228 | + /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 137229 | + /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839, |
| 137230 | + /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261, |
| 137231 | + /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324, |
| 137232 | + /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818, |
| 137233 | + /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94, |
| 137234 | + /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850, |
| 137235 | + /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372, |
| 137236 | + /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178, |
| 137237 | + /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52, |
| 137238 | + /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95, |
| 137239 | + /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971, |
| 137240 | + /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, |
| 137241 | + /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995, |
| 137242 | + /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347, |
| 137243 | + /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96, |
| 137244 | + /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90, |
| 137245 | + /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, |
| 137246 | + /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951, |
| 137247 | + /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701, |
| 137248 | + /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96, |
| 137249 | + /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99, |
| 137250 | + /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, |
| 137251 | + /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427, |
| 137252 | + /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058, |
| 137253 | + /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374, |
| 137254 | + /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 137255 | + /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839, |
| 137256 | + /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449, |
| 137257 | + /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324, |
| 137258 | + /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36, |
| 137259 | + /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94, |
| 137260 | + /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850, |
| 137261 | + /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316, |
| 137262 | + /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318, |
| 137263 | + /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950, |
| 137264 | + /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95, |
| 137265 | + /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971, |
| 137266 | + /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, |
| 137267 | + /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410, |
| 137268 | + /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771, |
| 137269 | + /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96, |
| 137270 | + /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90, |
| 137271 | + /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, |
| 137272 | + /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207, |
| 137273 | + /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298, |
| 137274 | + /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96, |
| 137275 | + /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697, |
| 137276 | + /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839, |
| 137277 | + /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120, |
| 137278 | + /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170, |
| 137279 | + /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268, |
| 137280 | + /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94, |
| 137281 | + /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90, |
| 137282 | + /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, |
| 137283 | + /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133, |
| 137284 | + /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333, |
| 137285 | + /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96, |
| 137286 | + /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99, |
| 137287 | + /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, |
| 137288 | + /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223, |
| 137289 | + /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246, |
| 137290 | + /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280, |
| 137291 | + /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 137292 | + /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839, |
| 137293 | + /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722, |
| 137294 | + /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202, |
| 137295 | + /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069, |
| 137296 | + /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94, |
| 137297 | + /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839, |
| 137298 | + /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232, |
| 137299 | + /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342, |
| 137300 | + /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202, |
| 137301 | + /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94, |
| 137302 | + /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839, |
| 137303 | + /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877, |
| 137304 | + /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689, |
| 137305 | + /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444, |
| 137306 | + /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94, |
| 137307 | + /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212, |
| 137308 | + /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419, |
| 137309 | + /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153, |
| 137310 | + /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433, |
| 137311 | + /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818, |
| 137312 | + /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86, |
| 137313 | + /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5, |
| 137314 | + /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140, |
| 137315 | + /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38, |
| 137316 | + /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351, |
| 137317 | + /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1, |
| 137318 | + /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449, |
| 137319 | + /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84, |
| 137320 | + /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10, |
| 137321 | + /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303, |
| 137322 | + /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447, |
| 137323 | + /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950, |
| 137324 | + /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447, |
| 137325 | + /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951, |
| 137326 | + /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291, |
| 137327 | + /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360, |
| 137328 | + /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351, |
| 137329 | + /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211, |
| 137330 | + /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351, |
| 137331 | + /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173, |
| 137332 | + /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19, |
| 137333 | + /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95, |
| 137334 | + /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19, |
| 137335 | + /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276, |
| 137336 | + /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247, |
| 137337 | + /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41, |
| 137338 | + /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31, |
| 137339 | + /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449, |
| 137340 | + /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137, |
| 137341 | + /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46, |
| 137342 | + /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48, |
| 137343 | + /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185, |
| 137344 | + /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449, |
| 137345 | + /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122, |
| 137346 | + /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35, |
| 137347 | + /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449, |
| 137348 | + /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449, |
| 137349 | + /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112, |
| 137350 | + /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55, |
| 137351 | + /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26, |
| 137352 | + /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006, |
| 137353 | + /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029, |
| 137354 | + /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204, |
| 137355 | + /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292, |
| 137356 | + /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22, |
| 137357 | + /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304, |
| 137358 | + /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235, |
| 137359 | + /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883, |
| 137360 | + /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899, |
| 137361 | + /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187, |
| 137362 | + /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387, |
| 137363 | + /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151, |
| 137364 | + /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825, |
| 137365 | + /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222, |
| 137366 | + /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852, |
| 137367 | + /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210, |
| 137368 | + /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87, |
| 137369 | + /* 1560 */ 211, 309, 1281, 940, 995, 1280, |
| 137099 | 137370 | }; |
| 137100 | 137371 | static const YYCODETYPE yy_lookahead[] = { |
| 137101 | | - /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79, |
| 137102 | | - /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, |
| 137103 | | - /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58, |
| 137104 | | - /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86, |
| 137105 | | - /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222, |
| 137106 | | - /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137107 | | - /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88, |
| 137108 | | - /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108, |
| 137109 | | - /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32, |
| 137110 | | - /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88, |
| 137111 | | - /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85, |
| 137112 | | - /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58, |
| 137113 | | - /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72, |
| 137114 | | - /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, |
| 137115 | | - /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 137116 | | - /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26, |
| 137117 | | - /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108, |
| 137118 | | - /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219, |
| 137119 | | - /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133, |
| 137120 | | - /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237, |
| 137121 | | - /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76, |
| 137122 | | - /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86, |
| 137123 | | - /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65, |
| 137124 | | - /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93, |
| 137125 | | - /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217, |
| 137126 | | - /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76, |
| 137127 | | - /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86, |
| 137128 | | - /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148, |
| 137129 | | - /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152, |
| 137130 | | - /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98, |
| 137131 | | - /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50, |
| 137132 | | - /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96, |
| 137133 | | - /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70, |
| 137134 | | - /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 137135 | | - /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90, |
| 137136 | | - /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218, |
| 137137 | | - /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22, |
| 137138 | | - /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26, |
| 137139 | | - /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58, |
| 137140 | | - /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206, |
| 137141 | | - /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74, |
| 137142 | | - /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84, |
| 137143 | | - /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, |
| 137144 | | - /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108, |
| 137145 | | - /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98, |
| 137146 | | - /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106, |
| 137147 | | - /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170, |
| 137148 | | - /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223, |
| 137149 | | - /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137150 | | - /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88, |
| 137151 | | - /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12, |
| 137152 | | - /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152, |
| 137153 | | - /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206, |
| 137154 | | - /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124, |
| 137155 | | - /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173, |
| 137156 | | - /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72, |
| 137157 | | - /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, |
| 137158 | | - /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 137159 | | - /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152, |
| 137160 | | - /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96, |
| 137161 | | - /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172, |
| 137162 | | - /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186, |
| 137163 | | - /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26, |
| 137164 | | - /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76, |
| 137165 | | - /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86, |
| 137166 | | - /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101, |
| 137167 | | - /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168, |
| 137168 | | - /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26, |
| 137169 | | - /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50, |
| 137170 | | - /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124, |
| 137171 | | - /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70, |
| 137172 | | - /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 137173 | | - /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90, |
| 137174 | | - /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50, |
| 137175 | | - /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9, |
| 137176 | | - /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70, |
| 137177 | | - /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 137178 | | - /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90, |
| 137179 | | - /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152, |
| 137180 | | - /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193, |
| 137181 | | - /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172, |
| 137182 | | - /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173, |
| 137183 | | - /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152, |
| 137184 | | - /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74, |
| 137185 | | - /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84, |
| 137186 | | - /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, |
| 137187 | | - /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173, |
| 137188 | | - /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152, |
| 137189 | | - /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152, |
| 137190 | | - /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173, |
| 137191 | | - /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110, |
| 137192 | | - /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137193 | | - /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88, |
| 137194 | | - /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152, |
| 137195 | | - /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146, |
| 137196 | | - /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173, |
| 137197 | | - /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137198 | | - /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88, |
| 137199 | | - /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193, |
| 137200 | | - /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246, |
| 137201 | | - /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173, |
| 137202 | | - /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137203 | | - /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88, |
| 137204 | | - /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123, |
| 137205 | | - /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23, |
| 137206 | | - /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173, |
| 137207 | | - /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78, |
| 137208 | | - /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88, |
| 137209 | | - /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217, |
| 137210 | | - /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27, |
| 137211 | | - /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173, |
| 137212 | | - /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78, |
| 137213 | | - /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88, |
| 137214 | | - /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22, |
| 137215 | | - /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23, |
| 137216 | | - /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173, |
| 137217 | | - /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97, |
| 137218 | | - /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196, |
| 137219 | | - /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173, |
| 137220 | | - /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234, |
| 137221 | | - /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196, |
| 137222 | | - /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152, |
| 137223 | | - /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101, |
| 137224 | | - /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22, |
| 137225 | | - /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132, |
| 137226 | | - /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152, |
| 137227 | | - /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198, |
| 137228 | | - /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180, |
| 137229 | | - /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122, |
| 137230 | | - /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22, |
| 137231 | | - /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18, |
| 137232 | | - /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192, |
| 137233 | | - /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17, |
| 137234 | | - /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159, |
| 137235 | | - /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132, |
| 137236 | | - /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159, |
| 137237 | | - /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95, |
| 137238 | | - /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106, |
| 137239 | | - /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182, |
| 137240 | | - /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215, |
| 137241 | | - /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135, |
| 137242 | | - /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56, |
| 137243 | | - /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202, |
| 137244 | | - /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6, |
| 137245 | | - /* 1440 */ 151, 151, 178, 151, 165, 165, 178, 165, 4, 3, |
| 137246 | | - /* 1450 */ 249, 88, 89, 141, 22, 142, 15, 249, 95, 96, |
| 137247 | | - /* 1460 */ 97, 98, 246, 67, 101, 16, 23, 120, 23, 131, |
| 137248 | | - /* 1470 */ 111, 123, 20, 16, 125, 1, 123, 131, 78, 78, |
| 137249 | | - /* 1480 */ 78, 78, 111, 96, 122, 35, 1, 5, 22, 107, |
| 137250 | | - /* 1490 */ 140, 53, 53, 26, 60, 132, 133, 134, 135, 136, |
| 137251 | | - /* 1500 */ 107, 43, 24, 20, 112, 19, 22, 52, 52, 105, |
| 137252 | | - /* 1510 */ 22, 22, 52, 23, 22, 22, 29, 23, 39, 23, |
| 137253 | | - /* 1520 */ 23, 26, 116, 22, 26, 23, 22, 122, 23, 23, |
| 137254 | | - /* 1530 */ 22, 96, 11, 124, 35, 26, 26, 23, 35, 23, |
| 137255 | | - /* 1540 */ 23, 23, 35, 23, 22, 26, 23, 22, 24, 122, |
| 137256 | | - /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 23, 22, 122, |
| 137257 | | - /* 1560 */ 23, 15, 122, 1, 122, |
| 137258 | | -}; |
| 137259 | | -#define YY_SHIFT_USE_DFLT (1565) |
| 137372 | + /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93, |
| 137373 | + /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91, |
| 137374 | + /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48, |
| 137375 | + /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94, |
| 137376 | + /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92, |
| 137377 | + /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90, |
| 137378 | + /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88, |
| 137379 | + /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79, |
| 137380 | + /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96, |
| 137381 | + /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79, |
| 137382 | + /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43, |
| 137383 | + /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 137384 | + /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109, |
| 137385 | + /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103, |
| 137386 | + /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113, |
| 137387 | + /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, |
| 137388 | + /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 137389 | + /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110, |
| 137390 | + /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19, |
| 137391 | + /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101, |
| 137392 | + /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91, |
| 137393 | + /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, |
| 137394 | + /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152, |
| 137395 | + /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223, |
| 137396 | + /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173, |
| 137397 | + /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89, |
| 137398 | + /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, |
| 137399 | + /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
| 137400 | + /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149, |
| 137401 | + /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89, |
| 137402 | + /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87, |
| 137403 | + /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, |
| 137404 | + /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
| 137405 | + /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97, |
| 137406 | + /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23, |
| 137407 | + /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85, |
| 137408 | + /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, |
| 137409 | + /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 137410 | + /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207, |
| 137411 | + /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179, |
| 137412 | + /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152, |
| 137413 | + /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, |
| 137414 | + /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 137415 | + /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152, |
| 137416 | + /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19, |
| 137417 | + /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172, |
| 137418 | + /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91, |
| 137419 | + /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, |
| 137420 | + /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22, |
| 137421 | + /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247, |
| 137422 | + /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59, |
| 137423 | + /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89, |
| 137424 | + /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, |
| 137425 | + /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
| 137426 | + /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115, |
| 137427 | + /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26, |
| 137428 | + /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87, |
| 137429 | + /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, |
| 137430 | + /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
| 137431 | + /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193, |
| 137432 | + /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152, |
| 137433 | + /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85, |
| 137434 | + /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59, |
| 137435 | + /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50, |
| 137436 | + /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196, |
| 137437 | + /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89, |
| 137438 | + /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152, |
| 137439 | + /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90, |
| 137440 | + /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45, |
| 137441 | + /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
| 137442 | + /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246, |
| 137443 | + /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217, |
| 137444 | + /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85, |
| 137445 | + /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, |
| 137446 | + /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 137447 | + /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211, |
| 137448 | + /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152, |
| 137449 | + /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112, |
| 137450 | + /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, |
| 137451 | + /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 137452 | + /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8, |
| 137453 | + /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26, |
| 137454 | + /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163, |
| 137455 | + /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91, |
| 137456 | + /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50, |
| 137457 | + /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238, |
| 137458 | + /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19, |
| 137459 | + /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26, |
| 137460 | + /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90, |
| 137461 | + /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50, |
| 137462 | + /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97, |
| 137463 | + /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23, |
| 137464 | + /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20, |
| 137465 | + /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90, |
| 137466 | + /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99, |
| 137467 | + /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96, |
| 137468 | + /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71, |
| 137469 | + /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70, |
| 137470 | + /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101, |
| 137471 | + /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19, |
| 137472 | + /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22, |
| 137473 | + /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152, |
| 137474 | + /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173, |
| 137475 | + /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59, |
| 137476 | + /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22, |
| 137477 | + /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152, |
| 137478 | + /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89, |
| 137479 | + /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172, |
| 137480 | + /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152, |
| 137481 | + /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36, |
| 137482 | + /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96, |
| 137483 | + /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36, |
| 137484 | + /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97, |
| 137485 | + /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210, |
| 137486 | + /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152, |
| 137487 | + /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96, |
| 137488 | + /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152, |
| 137489 | + /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96, |
| 137490 | + /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184, |
| 137491 | + /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136, |
| 137492 | + /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89, |
| 137493 | + /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136, |
| 137494 | + /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155, |
| 137495 | + /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159, |
| 137496 | + /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173, |
| 137497 | + /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173, |
| 137498 | + /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152, |
| 137499 | + /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189, |
| 137500 | + /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172, |
| 137501 | + /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173, |
| 137502 | + /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158, |
| 137503 | + /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152, |
| 137504 | + /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173, |
| 137505 | + /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172, |
| 137506 | + /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152, |
| 137507 | + /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152, |
| 137508 | + /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172, |
| 137509 | + /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172, |
| 137510 | + /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173, |
| 137511 | + /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159, |
| 137512 | + /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174, |
| 137513 | + /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159, |
| 137514 | + /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215, |
| 137515 | + /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26, |
| 137516 | + /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204, |
| 137517 | + /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178, |
| 137518 | + /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23, |
| 137519 | + /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1, |
| 137520 | + /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122, |
| 137521 | + /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41, |
| 137522 | + /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22, |
| 137523 | + /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23, |
| 137524 | + /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23, |
| 137525 | + /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23, |
| 137526 | + /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122, |
| 137527 | + /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22, |
| 137528 | + /* 1560 */ 122, 23, 122, 1, 251, 122, |
| 137529 | +}; |
| 137530 | +#define YY_SHIFT_USE_DFLT (1566) |
| 137260 | 137531 | #define YY_SHIFT_COUNT (454) |
| 137261 | | -#define YY_SHIFT_MIN (-114) |
| 137532 | +#define YY_SHIFT_MIN (-84) |
| 137262 | 137533 | #define YY_SHIFT_MAX (1562) |
| 137263 | 137534 | static const short yy_shift_ofst[] = { |
| 137264 | | - /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19, |
| 137265 | | - /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274, |
| 137266 | | - /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411, |
| 137267 | | - /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891, |
| 137268 | | - /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891, |
| 137269 | | - /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274, |
| 137270 | | - /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, |
| 137271 | | - /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, |
| 137272 | | - /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, |
| 137273 | | - /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, |
| 137274 | | - /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47, |
| 137275 | | - /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3, |
| 137276 | | - /* 120 */ 2, -30, 1565, 1565, 1565, -17, -17, -17, 145, 145, |
| 137277 | | - /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296, |
| 137278 | | - /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, |
| 137279 | | - /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2, |
| 137280 | | - /* 160 */ 164, 164, 164, 164, 164, 164, 1565, 1565, 1565, 223, |
| 137281 | | - /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296, |
| 137282 | | - /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, |
| 137283 | | - /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296, |
| 137284 | | - /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296, |
| 137285 | | - /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200, |
| 137286 | | - /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503, |
| 137287 | | - /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762, |
| 137288 | | - /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167, |
| 137289 | | - /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172, |
| 137290 | | - /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167, |
| 137291 | | - /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258, |
| 137292 | | - /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288, |
| 137293 | | - /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267, |
| 137294 | | - /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407, |
| 137295 | | - /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1565, 1565, 1565, 1565, |
| 137296 | | - /* 320 */ 1565, 1565, 1565, 1565, 558, 537, 684, 719, 734, 799, |
| 137297 | | - /* 330 */ 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070, 1072, |
| 137298 | | - /* 340 */ 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819, 1174, |
| 137299 | | - /* 350 */ 1136, 981, 1444, 1446, 1432, 1313, 1441, 1396, 1449, 1443, |
| 137300 | | - /* 360 */ 1445, 1347, 1338, 1359, 1348, 1452, 1349, 1457, 1474, 1353, |
| 137301 | | - /* 370 */ 1346, 1400, 1401, 1402, 1403, 1371, 1387, 1450, 1362, 1485, |
| 137302 | | - /* 380 */ 1482, 1466, 1382, 1350, 1438, 1467, 1439, 1434, 1458, 1393, |
| 137303 | | - /* 390 */ 1478, 1483, 1486, 1392, 1404, 1484, 1455, 1488, 1489, 1490, |
| 137304 | | - /* 400 */ 1492, 1456, 1487, 1493, 1460, 1479, 1494, 1496, 1497, 1495, |
| 137305 | | - /* 410 */ 1406, 1501, 1502, 1504, 1498, 1405, 1505, 1506, 1435, 1499, |
| 137306 | | - /* 420 */ 1508, 1409, 1509, 1503, 1510, 1507, 1514, 1509, 1516, 1517, |
| 137307 | | - /* 430 */ 1518, 1519, 1520, 1522, 1521, 1523, 1525, 1524, 1526, 1527, |
| 137308 | | - /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1534, 1536, 1427, 1437, |
| 137309 | | - /* 450 */ 1440, 1442, 1537, 1546, 1562, |
| 137535 | + /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19, |
| 137536 | + /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063, |
| 137537 | + /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326, |
| 137538 | + /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696, |
| 137539 | + /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696, |
| 137540 | + /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063, |
| 137541 | + /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, |
| 137542 | + /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, |
| 137543 | + /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, |
| 137544 | + /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, |
| 137545 | + /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120, |
| 137546 | + /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309, |
| 137547 | + /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626, |
| 137548 | + /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242, |
| 137549 | + /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, |
| 137550 | + /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336, |
| 137551 | + /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570, |
| 137552 | + /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242, |
| 137553 | + /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, |
| 137554 | + /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242, |
| 137555 | + /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242, |
| 137556 | + /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531, |
| 137557 | + /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863, |
| 137558 | + /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145, |
| 137559 | + /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119, |
| 137560 | + /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147, |
| 137561 | + /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119, |
| 137562 | + /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294, |
| 137563 | + /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306, |
| 137564 | + /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285, |
| 137565 | + /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412, |
| 137566 | + /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566, |
| 137567 | + /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497, |
| 137568 | + /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768, |
| 137569 | + /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896, |
| 137570 | + /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445, |
| 137571 | + /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357, |
| 137572 | + /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489, |
| 137573 | + /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393, |
| 137574 | + /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484, |
| 137575 | + /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499, |
| 137576 | + /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503, |
| 137577 | + /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516, |
| 137578 | + /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527, |
| 137579 | + /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438, |
| 137580 | + /* 450 */ 1440, 1443, 1538, 1542, 1562, |
| 137310 | 137581 | }; |
| 137311 | | -#define YY_REDUCE_USE_DFLT (-174) |
| 137582 | +#define YY_REDUCE_USE_DFLT (-144) |
| 137312 | 137583 | #define YY_REDUCE_COUNT (323) |
| 137313 | | -#define YY_REDUCE_MIN (-173) |
| 137314 | | -#define YY_REDUCE_MAX (1292) |
| 137584 | +#define YY_REDUCE_MIN (-143) |
| 137585 | +#define YY_REDUCE_MAX (1305) |
| 137315 | 137586 | static const short yy_reduce_ofst[] = { |
| 137316 | | - /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45, |
| 137317 | | - /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298, |
| 137318 | | - /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173, |
| 137319 | | - /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173, |
| 137320 | | - /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173, |
| 137321 | | - /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437, |
| 137322 | | - /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635, |
| 137323 | | - /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709, |
| 137324 | | - /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784, |
| 137325 | | - /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986, |
| 137326 | | - /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173, |
| 137327 | | - /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173, |
| 137328 | | - /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141, |
| 137329 | | - /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678, |
| 137330 | | - /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787, |
| 137331 | | - /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669, |
| 137332 | | - /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94, |
| 137333 | | - /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721, |
| 137334 | | - /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046, |
| 137335 | | - /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080, |
| 137336 | | - /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094, |
| 137337 | | - /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998, |
| 137338 | | - /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062, |
| 137339 | | - /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112, |
| 137340 | | - /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139, |
| 137341 | | - /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132, |
| 137342 | | - /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189, |
| 137343 | | - /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206, |
| 137344 | | - /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183, |
| 137345 | | - /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194, |
| 137346 | | - /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271, |
| 137347 | | - /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1201, 1208, 1216, 1279, |
| 137348 | | - /* 320 */ 1280, 1264, 1268, 1282, |
| 137587 | + /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25, |
| 137588 | + /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285, |
| 137589 | + /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171, |
| 137590 | + /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, |
| 137591 | + /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, |
| 137592 | + /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287, |
| 137593 | + /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084, |
| 137594 | + /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128, |
| 137595 | + /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172, |
| 137596 | + /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207, |
| 137597 | + /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171, |
| 137598 | + /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171, |
| 137599 | + /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77, |
| 137600 | + /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403, |
| 137601 | + /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553, |
| 137602 | + /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571, |
| 137603 | + /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28, |
| 137604 | + /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560, |
| 137605 | + /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813, |
| 137606 | + /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835, |
| 137607 | + /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937, |
| 137608 | + /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899, |
| 137609 | + /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969, |
| 137610 | + /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019, |
| 137611 | + /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109, |
| 137612 | + /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111, |
| 137613 | + /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234, |
| 137614 | + /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230, |
| 137615 | + /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201, |
| 137616 | + /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220, |
| 137617 | + /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276, |
| 137618 | + /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290, |
| 137619 | + /* 320 */ 1292, 1280, 1281, 1295, |
| 137349 | 137620 | }; |
| 137350 | 137621 | static const YYACTIONTYPE yy_default[] = { |
| 137351 | 137622 | /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088, |
| 137352 | 137623 | /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192, |
| 137353 | 137624 | /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322, |
| | @@ -137413,77 +137684,91 @@ |
| 137413 | 137684 | */ |
| 137414 | 137685 | #ifdef YYFALLBACK |
| 137415 | 137686 | static const YYCODETYPE yyFallback[] = { |
| 137416 | 137687 | 0, /* $ => nothing */ |
| 137417 | 137688 | 0, /* SEMI => nothing */ |
| 137418 | | - 27, /* EXPLAIN => ID */ |
| 137419 | | - 27, /* QUERY => ID */ |
| 137420 | | - 27, /* PLAN => ID */ |
| 137421 | | - 27, /* BEGIN => ID */ |
| 137689 | + 59, /* EXPLAIN => ID */ |
| 137690 | + 59, /* QUERY => ID */ |
| 137691 | + 59, /* PLAN => ID */ |
| 137692 | + 59, /* BEGIN => ID */ |
| 137422 | 137693 | 0, /* TRANSACTION => nothing */ |
| 137423 | | - 27, /* DEFERRED => ID */ |
| 137424 | | - 27, /* IMMEDIATE => ID */ |
| 137425 | | - 27, /* EXCLUSIVE => ID */ |
| 137694 | + 59, /* DEFERRED => ID */ |
| 137695 | + 59, /* IMMEDIATE => ID */ |
| 137696 | + 59, /* EXCLUSIVE => ID */ |
| 137426 | 137697 | 0, /* COMMIT => nothing */ |
| 137427 | | - 27, /* END => ID */ |
| 137428 | | - 27, /* ROLLBACK => ID */ |
| 137429 | | - 27, /* SAVEPOINT => ID */ |
| 137430 | | - 27, /* RELEASE => ID */ |
| 137698 | + 59, /* END => ID */ |
| 137699 | + 59, /* ROLLBACK => ID */ |
| 137700 | + 59, /* SAVEPOINT => ID */ |
| 137701 | + 59, /* RELEASE => ID */ |
| 137431 | 137702 | 0, /* TO => nothing */ |
| 137432 | 137703 | 0, /* TABLE => nothing */ |
| 137433 | 137704 | 0, /* CREATE => nothing */ |
| 137434 | | - 27, /* IF => ID */ |
| 137705 | + 59, /* IF => ID */ |
| 137435 | 137706 | 0, /* NOT => nothing */ |
| 137436 | 137707 | 0, /* EXISTS => nothing */ |
| 137437 | | - 27, /* TEMP => ID */ |
| 137708 | + 59, /* TEMP => ID */ |
| 137438 | 137709 | 0, /* LP => nothing */ |
| 137439 | 137710 | 0, /* RP => nothing */ |
| 137440 | 137711 | 0, /* AS => nothing */ |
| 137441 | | - 27, /* WITHOUT => ID */ |
| 137712 | + 59, /* WITHOUT => ID */ |
| 137442 | 137713 | 0, /* COMMA => nothing */ |
| 137714 | + 59, /* ABORT => ID */ |
| 137715 | + 59, /* ACTION => ID */ |
| 137716 | + 59, /* AFTER => ID */ |
| 137717 | + 59, /* ANALYZE => ID */ |
| 137718 | + 59, /* ASC => ID */ |
| 137719 | + 59, /* ATTACH => ID */ |
| 137720 | + 59, /* BEFORE => ID */ |
| 137721 | + 59, /* BY => ID */ |
| 137722 | + 59, /* CASCADE => ID */ |
| 137723 | + 59, /* CAST => ID */ |
| 137724 | + 59, /* CONFLICT => ID */ |
| 137725 | + 59, /* DATABASE => ID */ |
| 137726 | + 59, /* DESC => ID */ |
| 137727 | + 59, /* DETACH => ID */ |
| 137728 | + 59, /* EACH => ID */ |
| 137729 | + 59, /* FAIL => ID */ |
| 137730 | + 0, /* OR => nothing */ |
| 137731 | + 0, /* AND => nothing */ |
| 137732 | + 0, /* IS => nothing */ |
| 137733 | + 59, /* MATCH => ID */ |
| 137734 | + 59, /* LIKE_KW => ID */ |
| 137735 | + 0, /* BETWEEN => nothing */ |
| 137736 | + 0, /* IN => nothing */ |
| 137737 | + 0, /* ISNULL => nothing */ |
| 137738 | + 0, /* NOTNULL => nothing */ |
| 137739 | + 0, /* NE => nothing */ |
| 137740 | + 0, /* EQ => nothing */ |
| 137741 | + 0, /* GT => nothing */ |
| 137742 | + 0, /* LE => nothing */ |
| 137743 | + 0, /* LT => nothing */ |
| 137744 | + 0, /* GE => nothing */ |
| 137745 | + 0, /* ESCAPE => nothing */ |
| 137443 | 137746 | 0, /* ID => nothing */ |
| 137444 | | - 27, /* ABORT => ID */ |
| 137445 | | - 27, /* ACTION => ID */ |
| 137446 | | - 27, /* AFTER => ID */ |
| 137447 | | - 27, /* ANALYZE => ID */ |
| 137448 | | - 27, /* ASC => ID */ |
| 137449 | | - 27, /* ATTACH => ID */ |
| 137450 | | - 27, /* BEFORE => ID */ |
| 137451 | | - 27, /* BY => ID */ |
| 137452 | | - 27, /* CASCADE => ID */ |
| 137453 | | - 27, /* CAST => ID */ |
| 137454 | | - 27, /* COLUMNKW => ID */ |
| 137455 | | - 27, /* CONFLICT => ID */ |
| 137456 | | - 27, /* DATABASE => ID */ |
| 137457 | | - 27, /* DESC => ID */ |
| 137458 | | - 27, /* DETACH => ID */ |
| 137459 | | - 27, /* EACH => ID */ |
| 137460 | | - 27, /* FAIL => ID */ |
| 137461 | | - 27, /* FOR => ID */ |
| 137462 | | - 27, /* IGNORE => ID */ |
| 137463 | | - 27, /* INITIALLY => ID */ |
| 137464 | | - 27, /* INSTEAD => ID */ |
| 137465 | | - 27, /* LIKE_KW => ID */ |
| 137466 | | - 27, /* MATCH => ID */ |
| 137467 | | - 27, /* NO => ID */ |
| 137468 | | - 27, /* KEY => ID */ |
| 137469 | | - 27, /* OF => ID */ |
| 137470 | | - 27, /* OFFSET => ID */ |
| 137471 | | - 27, /* PRAGMA => ID */ |
| 137472 | | - 27, /* RAISE => ID */ |
| 137473 | | - 27, /* RECURSIVE => ID */ |
| 137474 | | - 27, /* REPLACE => ID */ |
| 137475 | | - 27, /* RESTRICT => ID */ |
| 137476 | | - 27, /* ROW => ID */ |
| 137477 | | - 27, /* TRIGGER => ID */ |
| 137478 | | - 27, /* VACUUM => ID */ |
| 137479 | | - 27, /* VIEW => ID */ |
| 137480 | | - 27, /* VIRTUAL => ID */ |
| 137481 | | - 27, /* WITH => ID */ |
| 137482 | | - 27, /* REINDEX => ID */ |
| 137483 | | - 27, /* RENAME => ID */ |
| 137484 | | - 27, /* CTIME_KW => ID */ |
| 137747 | + 59, /* COLUMNKW => ID */ |
| 137748 | + 59, /* FOR => ID */ |
| 137749 | + 59, /* IGNORE => ID */ |
| 137750 | + 59, /* INITIALLY => ID */ |
| 137751 | + 59, /* INSTEAD => ID */ |
| 137752 | + 59, /* NO => ID */ |
| 137753 | + 59, /* KEY => ID */ |
| 137754 | + 59, /* OF => ID */ |
| 137755 | + 59, /* OFFSET => ID */ |
| 137756 | + 59, /* PRAGMA => ID */ |
| 137757 | + 59, /* RAISE => ID */ |
| 137758 | + 59, /* RECURSIVE => ID */ |
| 137759 | + 59, /* REPLACE => ID */ |
| 137760 | + 59, /* RESTRICT => ID */ |
| 137761 | + 59, /* ROW => ID */ |
| 137762 | + 59, /* TRIGGER => ID */ |
| 137763 | + 59, /* VACUUM => ID */ |
| 137764 | + 59, /* VIEW => ID */ |
| 137765 | + 59, /* VIRTUAL => ID */ |
| 137766 | + 59, /* WITH => ID */ |
| 137767 | + 59, /* REINDEX => ID */ |
| 137768 | + 59, /* RENAME => ID */ |
| 137769 | + 59, /* CTIME_KW => ID */ |
| 137485 | 137770 | }; |
| 137486 | 137771 | #endif /* YYFALLBACK */ |
| 137487 | 137772 | |
| 137488 | 137773 | /* The following structure represents a single element of the |
| 137489 | 137774 | ** parser's stack. Information stored includes: |
| | @@ -137572,25 +137857,25 @@ |
| 137572 | 137857 | "PLAN", "BEGIN", "TRANSACTION", "DEFERRED", |
| 137573 | 137858 | "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", |
| 137574 | 137859 | "ROLLBACK", "SAVEPOINT", "RELEASE", "TO", |
| 137575 | 137860 | "TABLE", "CREATE", "IF", "NOT", |
| 137576 | 137861 | "EXISTS", "TEMP", "LP", "RP", |
| 137577 | | - "AS", "WITHOUT", "COMMA", "ID", |
| 137578 | | - "ABORT", "ACTION", "AFTER", "ANALYZE", |
| 137579 | | - "ASC", "ATTACH", "BEFORE", "BY", |
| 137580 | | - "CASCADE", "CAST", "COLUMNKW", "CONFLICT", |
| 137581 | | - "DATABASE", "DESC", "DETACH", "EACH", |
| 137582 | | - "FAIL", "FOR", "IGNORE", "INITIALLY", |
| 137583 | | - "INSTEAD", "LIKE_KW", "MATCH", "NO", |
| 137584 | | - "KEY", "OF", "OFFSET", "PRAGMA", |
| 137585 | | - "RAISE", "RECURSIVE", "REPLACE", "RESTRICT", |
| 137586 | | - "ROW", "TRIGGER", "VACUUM", "VIEW", |
| 137587 | | - "VIRTUAL", "WITH", "REINDEX", "RENAME", |
| 137588 | | - "CTIME_KW", "ANY", "OR", "AND", |
| 137589 | | - "IS", "BETWEEN", "IN", "ISNULL", |
| 137590 | | - "NOTNULL", "NE", "EQ", "GT", |
| 137591 | | - "LE", "LT", "GE", "ESCAPE", |
| 137862 | + "AS", "WITHOUT", "COMMA", "ABORT", |
| 137863 | + "ACTION", "AFTER", "ANALYZE", "ASC", |
| 137864 | + "ATTACH", "BEFORE", "BY", "CASCADE", |
| 137865 | + "CAST", "CONFLICT", "DATABASE", "DESC", |
| 137866 | + "DETACH", "EACH", "FAIL", "OR", |
| 137867 | + "AND", "IS", "MATCH", "LIKE_KW", |
| 137868 | + "BETWEEN", "IN", "ISNULL", "NOTNULL", |
| 137869 | + "NE", "EQ", "GT", "LE", |
| 137870 | + "LT", "GE", "ESCAPE", "ID", |
| 137871 | + "COLUMNKW", "FOR", "IGNORE", "INITIALLY", |
| 137872 | + "INSTEAD", "NO", "KEY", "OF", |
| 137873 | + "OFFSET", "PRAGMA", "RAISE", "RECURSIVE", |
| 137874 | + "REPLACE", "RESTRICT", "ROW", "TRIGGER", |
| 137875 | + "VACUUM", "VIEW", "VIRTUAL", "WITH", |
| 137876 | + "REINDEX", "RENAME", "CTIME_KW", "ANY", |
| 137592 | 137877 | "BITAND", "BITOR", "LSHIFT", "RSHIFT", |
| 137593 | 137878 | "PLUS", "MINUS", "STAR", "SLASH", |
| 137594 | 137879 | "REM", "CONCAT", "COLLATE", "BITNOT", |
| 137595 | 137880 | "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT", |
| 137596 | 137881 | "DEFAULT", "NULL", "PRIMARY", "UNIQUE", |
| | @@ -141643,11 +141928,11 @@ |
| 141643 | 141928 | |
| 141644 | 141929 | /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a |
| 141645 | 141930 | ** pointer to a string constant whose value is the same as the |
| 141646 | 141931 | ** SQLITE_SOURCE_ID C preprocessor macro. |
| 141647 | 141932 | */ |
| 141648 | | -SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 141933 | +/* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */ |
| 141649 | 141934 | |
| 141650 | 141935 | /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function |
| 141651 | 141936 | ** returns an integer equal to SQLITE_VERSION_NUMBER. |
| 141652 | 141937 | */ |
| 141653 | 141938 | SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } |
| | @@ -142028,18 +142313,12 @@ |
| 142028 | 142313 | ** single argument of type int, interpreted as a boolean, which enables |
| 142029 | 142314 | ** or disables the collection of memory allocation statistics. */ |
| 142030 | 142315 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 142031 | 142316 | break; |
| 142032 | 142317 | } |
| 142033 | | - case SQLITE_CONFIG_SCRATCH: { |
| 142034 | | - /* EVIDENCE-OF: R-08404-60887 There are three arguments to |
| 142035 | | - ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from |
| 142036 | | - ** which the scratch allocations will be drawn, the size of each scratch |
| 142037 | | - ** allocation (sz), and the maximum number of scratch allocations (N). */ |
| 142038 | | - sqlite3GlobalConfig.pScratch = va_arg(ap, void*); |
| 142039 | | - sqlite3GlobalConfig.szScratch = va_arg(ap, int); |
| 142040 | | - sqlite3GlobalConfig.nScratch = va_arg(ap, int); |
| 142318 | + case SQLITE_CONFIG_SMALL_MALLOC: { |
| 142319 | + sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int); |
| 142041 | 142320 | break; |
| 142042 | 142321 | } |
| 142043 | 142322 | case SQLITE_CONFIG_PAGECACHE: { |
| 142044 | 142323 | /* EVIDENCE-OF: R-18761-36601 There are three arguments to |
| 142045 | 142324 | ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem), |
| | @@ -142256,11 +142535,12 @@ |
| 142256 | 142535 | ** the lookaside memory. |
| 142257 | 142536 | */ |
| 142258 | 142537 | static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ |
| 142259 | 142538 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 142260 | 142539 | void *pStart; |
| 142261 | | - if( db->lookaside.nOut ){ |
| 142540 | + |
| 142541 | + if( sqlite3LookasideUsed(db,0)>0 ){ |
| 142262 | 142542 | return SQLITE_BUSY; |
| 142263 | 142543 | } |
| 142264 | 142544 | /* Free any existing lookaside buffer for this handle before |
| 142265 | 142545 | ** allocating a new one so we don't have to have space for |
| 142266 | 142546 | ** both at the same time. |
| | @@ -142284,20 +142564,22 @@ |
| 142284 | 142564 | if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; |
| 142285 | 142565 | }else{ |
| 142286 | 142566 | pStart = pBuf; |
| 142287 | 142567 | } |
| 142288 | 142568 | db->lookaside.pStart = pStart; |
| 142569 | + db->lookaside.pInit = 0; |
| 142289 | 142570 | db->lookaside.pFree = 0; |
| 142290 | 142571 | db->lookaside.sz = (u16)sz; |
| 142291 | 142572 | if( pStart ){ |
| 142292 | 142573 | int i; |
| 142293 | 142574 | LookasideSlot *p; |
| 142294 | 142575 | assert( sz > (int)sizeof(LookasideSlot*) ); |
| 142576 | + db->lookaside.nSlot = cnt; |
| 142295 | 142577 | p = (LookasideSlot*)pStart; |
| 142296 | 142578 | for(i=cnt-1; i>=0; i--){ |
| 142297 | | - p->pNext = db->lookaside.pFree; |
| 142298 | | - db->lookaside.pFree = p; |
| 142579 | + p->pNext = db->lookaside.pInit; |
| 142580 | + db->lookaside.pInit = p; |
| 142299 | 142581 | p = (LookasideSlot*)&((u8*)p)[sz]; |
| 142300 | 142582 | } |
| 142301 | 142583 | db->lookaside.pEnd = p; |
| 142302 | 142584 | db->lookaside.bDisable = 0; |
| 142303 | 142585 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| | @@ -142304,10 +142586,11 @@ |
| 142304 | 142586 | }else{ |
| 142305 | 142587 | db->lookaside.pStart = db; |
| 142306 | 142588 | db->lookaside.pEnd = db; |
| 142307 | 142589 | db->lookaside.bDisable = 1; |
| 142308 | 142590 | db->lookaside.bMalloced = 0; |
| 142591 | + db->lookaside.nSlot = 0; |
| 142309 | 142592 | } |
| 142310 | 142593 | #endif /* SQLITE_OMIT_LOOKASIDE */ |
| 142311 | 142594 | return SQLITE_OK; |
| 142312 | 142595 | } |
| 142313 | 142596 | |
| | @@ -142416,11 +142699,11 @@ |
| 142416 | 142699 | rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 142417 | 142700 | for(i=0; i<ArraySize(aFlagOp); i++){ |
| 142418 | 142701 | if( aFlagOp[i].op==op ){ |
| 142419 | 142702 | int onoff = va_arg(ap, int); |
| 142420 | 142703 | int *pRes = va_arg(ap, int*); |
| 142421 | | - int oldFlags = db->flags; |
| 142704 | + u32 oldFlags = db->flags; |
| 142422 | 142705 | if( onoff>0 ){ |
| 142423 | 142706 | db->flags |= aFlagOp[i].mask; |
| 142424 | 142707 | }else if( onoff==0 ){ |
| 142425 | 142708 | db->flags &= ~aFlagOp[i].mask; |
| 142426 | 142709 | } |
| | @@ -142823,11 +143106,11 @@ |
| 142823 | 143106 | */ |
| 142824 | 143107 | sqlite3DbFree(db, db->aDb[1].pSchema); |
| 142825 | 143108 | sqlite3_mutex_leave(db->mutex); |
| 142826 | 143109 | db->magic = SQLITE_MAGIC_CLOSED; |
| 142827 | 143110 | sqlite3_mutex_free(db->mutex); |
| 142828 | | - assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */ |
| 143111 | + assert( sqlite3LookasideUsed(db,0)==0 ); |
| 142829 | 143112 | if( db->lookaside.bMalloced ){ |
| 142830 | 143113 | sqlite3_free(db->lookaside.pStart); |
| 142831 | 143114 | } |
| 142832 | 143115 | sqlite3_free(db); |
| 142833 | 143116 | } |
| | @@ -142851,11 +143134,11 @@ |
| 142851 | 143134 | ** modified the database schema. If the b-tree mutexes are not taken |
| 142852 | 143135 | ** here, then another shared-cache connection might sneak in between |
| 142853 | 143136 | ** the database rollback and schema reset, which can cause false |
| 142854 | 143137 | ** corruption reports in some cases. */ |
| 142855 | 143138 | sqlite3BtreeEnterAll(db); |
| 142856 | | - schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0; |
| 143139 | + schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0; |
| 142857 | 143140 | |
| 142858 | 143141 | for(i=0; i<db->nDb; i++){ |
| 142859 | 143142 | Btree *p = db->aDb[i].pBt; |
| 142860 | 143143 | if( p ){ |
| 142861 | 143144 | if( sqlite3BtreeIsInTrans(p) ){ |
| | @@ -142865,11 +143148,11 @@ |
| 142865 | 143148 | } |
| 142866 | 143149 | } |
| 142867 | 143150 | sqlite3VtabRollback(db); |
| 142868 | 143151 | sqlite3EndBenignMalloc(); |
| 142869 | 143152 | |
| 142870 | | - if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){ |
| 143153 | + if( (db->mDbFlags&DBFLAG_SchemaChange)!=0 && db->init.busy==0 ){ |
| 142871 | 143154 | sqlite3ExpirePreparedStatements(db); |
| 142872 | 143155 | sqlite3ResetAllSchemasOfConnection(db); |
| 142873 | 143156 | } |
| 142874 | 143157 | sqlite3BtreeLeaveAll(db); |
| 142875 | 143158 | |
| | @@ -143767,11 +144050,12 @@ |
| 143767 | 144050 | ** |
| 143768 | 144051 | ** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are |
| 143769 | 144052 | ** checkpointed. If an error is encountered it is returned immediately - |
| 143770 | 144053 | ** no attempt is made to checkpoint any remaining databases. |
| 143771 | 144054 | ** |
| 143772 | | -** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART. |
| 144055 | +** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART |
| 144056 | +** or TRUNCATE. |
| 143773 | 144057 | */ |
| 143774 | 144058 | SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){ |
| 143775 | 144059 | int rc = SQLITE_OK; /* Return code */ |
| 143776 | 144060 | int i; /* Used to iterate through attached dbs */ |
| 143777 | 144061 | int bBusy = 0; /* True if SQLITE_BUSY has been encountered */ |
| | @@ -145394,26 +145678,10 @@ |
| 145394 | 145678 | rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0; |
| 145395 | 145679 | break; |
| 145396 | 145680 | } |
| 145397 | 145681 | #endif |
| 145398 | 145682 | |
| 145399 | | - /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree); |
| 145400 | | - ** |
| 145401 | | - ** Pass pFree into sqlite3ScratchFree(). |
| 145402 | | - ** If sz>0 then allocate a scratch buffer into pNew. |
| 145403 | | - */ |
| 145404 | | - case SQLITE_TESTCTRL_SCRATCHMALLOC: { |
| 145405 | | - void *pFree, **ppNew; |
| 145406 | | - int sz; |
| 145407 | | - sz = va_arg(ap, int); |
| 145408 | | - ppNew = va_arg(ap, void**); |
| 145409 | | - pFree = va_arg(ap, void*); |
| 145410 | | - if( sz ) *ppNew = sqlite3ScratchMalloc(sz); |
| 145411 | | - sqlite3ScratchFree(pFree); |
| 145412 | | - break; |
| 145413 | | - } |
| 145414 | | - |
| 145415 | 145683 | /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff); |
| 145416 | 145684 | ** |
| 145417 | 145685 | ** If parameter onoff is non-zero, configure the wrappers so that all |
| 145418 | 145686 | ** subsequent calls to localtime() and variants fail. If onoff is zero, |
| 145419 | 145687 | ** undo this setting. |
| | @@ -145551,11 +145819,11 @@ |
| 145551 | 145819 | const char *zParam, /* URI parameter sought */ |
| 145552 | 145820 | sqlite3_int64 bDflt /* return if parameter is missing */ |
| 145553 | 145821 | ){ |
| 145554 | 145822 | const char *z = sqlite3_uri_parameter(zFilename, zParam); |
| 145555 | 145823 | sqlite3_int64 v; |
| 145556 | | - if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){ |
| 145824 | + if( z && sqlite3DecOrHexToI64(z, &v)==0 ){ |
| 145557 | 145825 | bDflt = v; |
| 145558 | 145826 | } |
| 145559 | 145827 | return bDflt; |
| 145560 | 145828 | } |
| 145561 | 145829 | |
| | @@ -168669,11 +168937,11 @@ |
| 168669 | 168937 | ); |
| 168670 | 168938 | rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize); |
| 168671 | 168939 | if( rc!=SQLITE_OK ){ |
| 168672 | 168940 | *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db)); |
| 168673 | 168941 | }else if( pRtree->iNodeSize<(512-64) ){ |
| 168674 | | - rc = SQLITE_CORRUPT; |
| 168942 | + rc = SQLITE_CORRUPT_VTAB; |
| 168675 | 168943 | *pzErr = sqlite3_mprintf("undersize RTree blobs in \"%q_node\"", |
| 168676 | 168944 | pRtree->zName); |
| 168677 | 168945 | } |
| 168678 | 168946 | } |
| 168679 | 168947 | |
| | @@ -170291,10 +170559,32 @@ |
| 170291 | 170559 | SQLITE_API sqlite3rbu *sqlite3rbu_vacuum( |
| 170292 | 170560 | const char *zTarget, |
| 170293 | 170561 | const char *zState |
| 170294 | 170562 | ); |
| 170295 | 170563 | |
| 170564 | +/* |
| 170565 | +** Configure a limit for the amount of temp space that may be used by |
| 170566 | +** the RBU handle passed as the first argument. The new limit is specified |
| 170567 | +** in bytes by the second parameter. If it is positive, the limit is updated. |
| 170568 | +** If the second parameter to this function is passed zero, then the limit |
| 170569 | +** is removed entirely. If the second parameter is negative, the limit is |
| 170570 | +** not modified (this is useful for querying the current limit). |
| 170571 | +** |
| 170572 | +** In all cases the returned value is the current limit in bytes (zero |
| 170573 | +** indicates unlimited). |
| 170574 | +** |
| 170575 | +** If the temp space limit is exceeded during operation, an SQLITE_FULL |
| 170576 | +** error is returned. |
| 170577 | +*/ |
| 170578 | +SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu*, sqlite3_int64); |
| 170579 | + |
| 170580 | +/* |
| 170581 | +** Return the current amount of temp file space, in bytes, currently used by |
| 170582 | +** the RBU handle passed as the only argument. |
| 170583 | +*/ |
| 170584 | +SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*); |
| 170585 | + |
| 170296 | 170586 | /* |
| 170297 | 170587 | ** Internally, each RBU connection uses a separate SQLite database |
| 170298 | 170588 | ** connection to access the target and rbu update databases. This |
| 170299 | 170589 | ** API allows the application direct access to these database handles. |
| 170300 | 170590 | ** |
| | @@ -170417,11 +170707,11 @@ |
| 170417 | 170707 | ** permyriadage progress of the same stage. If the rbu_count table does |
| 170418 | 170708 | ** not exist, then (*pnOne) is set to -1 during stage 1. If the rbu_count |
| 170419 | 170709 | ** table exists but is not correctly populated, the value of the *pnOne |
| 170420 | 170710 | ** output variable during stage 1 is undefined. |
| 170421 | 170711 | */ |
| 170422 | | -SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int *pnTwo); |
| 170712 | +SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int*pnTwo); |
| 170423 | 170713 | |
| 170424 | 170714 | /* |
| 170425 | 170715 | ** Obtain an indication as to the current stage of an RBU update or vacuum. |
| 170426 | 170716 | ** This function always returns one of the SQLITE_RBU_STATE_XXX constants |
| 170427 | 170717 | ** defined in this file. Return values should be interpreted as follows: |
| | @@ -170802,35 +171092,47 @@ |
| 170802 | 171092 | int nFrameAlloc; /* Allocated size of aFrame[] array */ |
| 170803 | 171093 | RbuFrame *aFrame; |
| 170804 | 171094 | int pgsz; |
| 170805 | 171095 | u8 *aBuf; |
| 170806 | 171096 | i64 iWalCksum; |
| 171097 | + i64 szTemp; /* Current size of all temp files in use */ |
| 171098 | + i64 szTempLimit; /* Total size limit for temp files */ |
| 170807 | 171099 | |
| 170808 | 171100 | /* Used in RBU vacuum mode only */ |
| 170809 | 171101 | int nRbu; /* Number of RBU VFS in the stack */ |
| 170810 | 171102 | rbu_file *pRbuFd; /* Fd for main db of dbRbu */ |
| 170811 | 171103 | }; |
| 170812 | 171104 | |
| 170813 | 171105 | /* |
| 170814 | 171106 | ** An rbu VFS is implemented using an instance of this structure. |
| 171107 | +** |
| 171108 | +** Variable pRbu is only non-NULL for automatically created RBU VFS objects. |
| 171109 | +** It is NULL for RBU VFS objects created explicitly using |
| 171110 | +** sqlite3rbu_create_vfs(). It is used to track the total amount of temp |
| 171111 | +** space used by the RBU handle. |
| 170815 | 171112 | */ |
| 170816 | 171113 | struct rbu_vfs { |
| 170817 | 171114 | sqlite3_vfs base; /* rbu VFS shim methods */ |
| 170818 | 171115 | sqlite3_vfs *pRealVfs; /* Underlying VFS */ |
| 170819 | 171116 | sqlite3_mutex *mutex; /* Mutex to protect pMain */ |
| 171117 | + sqlite3rbu *pRbu; /* Owner RBU object */ |
| 170820 | 171118 | rbu_file *pMain; /* Linked list of main db files */ |
| 170821 | 171119 | }; |
| 170822 | 171120 | |
| 170823 | 171121 | /* |
| 170824 | 171122 | ** Each file opened by an rbu VFS is represented by an instance of |
| 170825 | 171123 | ** the following structure. |
| 171124 | +** |
| 171125 | +** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable |
| 171126 | +** "sz" is set to the current size of the database file. |
| 170826 | 171127 | */ |
| 170827 | 171128 | struct rbu_file { |
| 170828 | 171129 | sqlite3_file base; /* sqlite3_file methods */ |
| 170829 | 171130 | sqlite3_file *pReal; /* Underlying file handle */ |
| 170830 | 171131 | rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */ |
| 170831 | 171132 | sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */ |
| 171133 | + i64 sz; /* Size of file in bytes (temp only) */ |
| 170832 | 171134 | |
| 170833 | 171135 | int openFlags; /* Flags this file was opened with */ |
| 170834 | 171136 | u32 iCookie; /* Cookie value for main db files */ |
| 170835 | 171137 | u8 iWriteVer; /* "write-version" value for main db files */ |
| 170836 | 171138 | u8 bNolock; /* True to fail EXCLUSIVE locks */ |
| | @@ -173840,10 +174142,11 @@ |
| 173840 | 174142 | p->rc = sqlite3rbu_create_vfs(zRnd, 0); |
| 173841 | 174143 | if( p->rc==SQLITE_OK ){ |
| 173842 | 174144 | sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd); |
| 173843 | 174145 | assert( pVfs ); |
| 173844 | 174146 | p->zVfsName = pVfs->zName; |
| 174147 | + ((rbu_vfs*)pVfs)->pRbu = p; |
| 173845 | 174148 | } |
| 173846 | 174149 | } |
| 173847 | 174150 | |
| 173848 | 174151 | /* |
| 173849 | 174152 | ** Destroy the private VFS created for the rbu handle passed as the only |
| | @@ -174212,10 +174515,11 @@ |
| 174212 | 174515 | } |
| 174213 | 174516 | |
| 174214 | 174517 | /* Close the open database handle and VFS object. */ |
| 174215 | 174518 | sqlite3_close(p->dbRbu); |
| 174216 | 174519 | sqlite3_close(p->dbMain); |
| 174520 | + assert( p->szTemp==0 ); |
| 174217 | 174521 | rbuDeleteVfs(p); |
| 174218 | 174522 | sqlite3_free(p->aBuf); |
| 174219 | 174523 | sqlite3_free(p->aFrame); |
| 174220 | 174524 | |
| 174221 | 174525 | rbuEditErrmsg(p); |
| | @@ -174399,10 +174703,11 @@ |
| 174399 | 174703 | ** relinquished). Finally, calls to xSync() on the target database |
| 174400 | 174704 | ** file fail with SQLITE_INTERNAL errors. |
| 174401 | 174705 | */ |
| 174402 | 174706 | |
| 174403 | 174707 | static void rbuUnlockShm(rbu_file *p){ |
| 174708 | + assert( p->openFlags & SQLITE_OPEN_MAIN_DB ); |
| 174404 | 174709 | if( p->pRbu ){ |
| 174405 | 174710 | int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock; |
| 174406 | 174711 | int i; |
| 174407 | 174712 | for(i=0; i<SQLITE_SHM_NLOCK;i++){ |
| 174408 | 174713 | if( (1<<i) & p->pRbu->mLock ){ |
| | @@ -174410,10 +174715,22 @@ |
| 174410 | 174715 | } |
| 174411 | 174716 | } |
| 174412 | 174717 | p->pRbu->mLock = 0; |
| 174413 | 174718 | } |
| 174414 | 174719 | } |
| 174720 | + |
| 174721 | +/* |
| 174722 | +*/ |
| 174723 | +static int rbuUpdateTempSize(rbu_file *pFd, sqlite3_int64 nNew){ |
| 174724 | + sqlite3rbu *pRbu = pFd->pRbu; |
| 174725 | + i64 nDiff = nNew - pFd->sz; |
| 174726 | + pRbu->szTemp += nDiff; |
| 174727 | + pFd->sz = nNew; |
| 174728 | + assert( pRbu->szTemp>=0 ); |
| 174729 | + if( pRbu->szTempLimit && pRbu->szTemp>pRbu->szTempLimit ) return SQLITE_FULL; |
| 174730 | + return SQLITE_OK; |
| 174731 | +} |
| 174415 | 174732 | |
| 174416 | 174733 | /* |
| 174417 | 174734 | ** Close an rbu file. |
| 174418 | 174735 | */ |
| 174419 | 174736 | static int rbuVfsClose(sqlite3_file *pFile){ |
| | @@ -174435,10 +174752,13 @@ |
| 174435 | 174752 | for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); |
| 174436 | 174753 | *pp = p->pMainNext; |
| 174437 | 174754 | sqlite3_mutex_leave(p->pRbuVfs->mutex); |
| 174438 | 174755 | rbuUnlockShm(p); |
| 174439 | 174756 | p->pReal->pMethods->xShmUnmap(p->pReal, 0); |
| 174757 | + } |
| 174758 | + else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){ |
| 174759 | + rbuUpdateTempSize(p, 0); |
| 174440 | 174760 | } |
| 174441 | 174761 | |
| 174442 | 174762 | /* Close the underlying file handle */ |
| 174443 | 174763 | rc = p->pReal->pMethods->xClose(p->pReal); |
| 174444 | 174764 | return rc; |
| | @@ -174553,15 +174873,23 @@ |
| 174553 | 174873 | |
| 174554 | 174874 | if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){ |
| 174555 | 174875 | assert( p->openFlags & SQLITE_OPEN_MAIN_DB ); |
| 174556 | 174876 | rc = rbuCaptureDbWrite(p->pRbu, iOfst); |
| 174557 | 174877 | }else{ |
| 174558 | | - if( pRbu && pRbu->eStage==RBU_STAGE_OAL |
| 174559 | | - && (p->openFlags & SQLITE_OPEN_WAL) |
| 174560 | | - && iOfst>=pRbu->iOalSz |
| 174561 | | - ){ |
| 174562 | | - pRbu->iOalSz = iAmt + iOfst; |
| 174878 | + if( pRbu ){ |
| 174879 | + if( pRbu->eStage==RBU_STAGE_OAL |
| 174880 | + && (p->openFlags & SQLITE_OPEN_WAL) |
| 174881 | + && iOfst>=pRbu->iOalSz |
| 174882 | + ){ |
| 174883 | + pRbu->iOalSz = iAmt + iOfst; |
| 174884 | + }else if( p->openFlags & SQLITE_OPEN_DELETEONCLOSE ){ |
| 174885 | + i64 szNew = iAmt+iOfst; |
| 174886 | + if( szNew>p->sz ){ |
| 174887 | + rc = rbuUpdateTempSize(p, szNew); |
| 174888 | + if( rc!=SQLITE_OK ) return rc; |
| 174889 | + } |
| 174890 | + } |
| 174563 | 174891 | } |
| 174564 | 174892 | rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); |
| 174565 | 174893 | if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ |
| 174566 | 174894 | /* These look like magic numbers. But they are stable, as they are part |
| 174567 | 174895 | ** of the definition of the SQLite file format, which may not change. */ |
| | @@ -174576,10 +174904,14 @@ |
| 174576 | 174904 | /* |
| 174577 | 174905 | ** Truncate an rbuVfs-file. |
| 174578 | 174906 | */ |
| 174579 | 174907 | static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 174580 | 174908 | rbu_file *p = (rbu_file*)pFile; |
| 174909 | + if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){ |
| 174910 | + int rc = rbuUpdateTempSize(p, size); |
| 174911 | + if( rc!=SQLITE_OK ) return rc; |
| 174912 | + } |
| 174581 | 174913 | return p->pReal->pMethods->xTruncate(p->pReal, size); |
| 174582 | 174914 | } |
| 174583 | 174915 | |
| 174584 | 174916 | /* |
| 174585 | 174917 | ** Sync an rbuVfs-file. |
| | @@ -174965,10 +175297,12 @@ |
| 174965 | 175297 | pFd->pRbu = pDb->pRbu; |
| 174966 | 175298 | } |
| 174967 | 175299 | pDb->pWalFd = pFd; |
| 174968 | 175300 | } |
| 174969 | 175301 | } |
| 175302 | + }else{ |
| 175303 | + pFd->pRbu = pRbuVfs->pRbu; |
| 174970 | 175304 | } |
| 174971 | 175305 | |
| 174972 | 175306 | if( oflags & SQLITE_OPEN_MAIN_DB |
| 174973 | 175307 | && sqlite3_uri_boolean(zName, "rbu_memory", 0) |
| 174974 | 175308 | ){ |
| | @@ -175041,11 +175375,13 @@ |
| 175041 | 175375 | rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath); |
| 175042 | 175376 | if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 175043 | 175377 | if( *pResOut ){ |
| 175044 | 175378 | rc = SQLITE_CANTOPEN; |
| 175045 | 175379 | }else{ |
| 175046 | | - *pResOut = 1; |
| 175380 | + sqlite3_int64 sz = 0; |
| 175381 | + rc = rbuVfsFileSize(&pDb->base, &sz); |
| 175382 | + *pResOut = (sz>0); |
| 175047 | 175383 | } |
| 175048 | 175384 | } |
| 175049 | 175385 | } |
| 175050 | 175386 | |
| 175051 | 175387 | return rc; |
| | @@ -175229,10 +175565,24 @@ |
| 175229 | 175565 | } |
| 175230 | 175566 | } |
| 175231 | 175567 | |
| 175232 | 175568 | return rc; |
| 175233 | 175569 | } |
| 175570 | + |
| 175571 | +/* |
| 175572 | +** Configure the aggregate temp file size limit for this RBU handle. |
| 175573 | +*/ |
| 175574 | +SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu *pRbu, sqlite3_int64 n){ |
| 175575 | + if( n>=0 ){ |
| 175576 | + pRbu->szTempLimit = n; |
| 175577 | + } |
| 175578 | + return pRbu->szTempLimit; |
| 175579 | +} |
| 175580 | + |
| 175581 | +SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu *pRbu){ |
| 175582 | + return pRbu->szTemp; |
| 175583 | +} |
| 175234 | 175584 | |
| 175235 | 175585 | |
| 175236 | 175586 | /**************************************************************************/ |
| 175237 | 175587 | |
| 175238 | 175588 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */ |
| | @@ -200274,11 +200624,11 @@ |
| 200274 | 200624 | int nArg, /* Number of args */ |
| 200275 | 200625 | sqlite3_value **apUnused /* Function arguments */ |
| 200276 | 200626 | ){ |
| 200277 | 200627 | assert( nArg==0 ); |
| 200278 | 200628 | UNUSED_PARAM2(nArg, apUnused); |
| 200279 | | - sqlite3_result_text(pCtx, "fts5: 2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34", -1, SQLITE_TRANSIENT); |
| 200629 | + sqlite3_result_text(pCtx, "fts5: 2017-09-20 10:47:10 7f2bd4ff45fba29528c18cac6da983bd9b164303525d3965056f5b40f85dc83f", -1, SQLITE_TRANSIENT); |
| 200280 | 200630 | } |
| 200281 | 200631 | |
| 200282 | 200632 | static int fts5Init(sqlite3 *db){ |
| 200283 | 200633 | static const sqlite3_module fts5Mod = { |
| 200284 | 200634 | /* iVersion */ 2, |
| | @@ -203502,10 +203852,15 @@ |
| 203502 | 203852 | ** |
| 203503 | 203853 | ** One row for each term in the database. The value of $doc is set to |
| 203504 | 203854 | ** the number of fts5 rows that contain at least one instance of term |
| 203505 | 203855 | ** $term. Field $cnt is set to the total number of instances of term |
| 203506 | 203856 | ** $term in the database. |
| 203857 | +** |
| 203858 | +** instance: |
| 203859 | +** CREATE TABLE vocab(term, doc, col, offset, PRIMARY KEY(<all-fields>)); |
| 203860 | +** |
| 203861 | +** One row for each term instance in the database. |
| 203507 | 203862 | */ |
| 203508 | 203863 | |
| 203509 | 203864 | |
| 203510 | 203865 | /* #include "fts5Int.h" */ |
| 203511 | 203866 | |
| | @@ -203517,11 +203872,11 @@ |
| 203517 | 203872 | sqlite3_vtab base; |
| 203518 | 203873 | char *zFts5Tbl; /* Name of fts5 table */ |
| 203519 | 203874 | char *zFts5Db; /* Db containing fts5 table */ |
| 203520 | 203875 | sqlite3 *db; /* Database handle */ |
| 203521 | 203876 | Fts5Global *pGlobal; /* FTS5 global object for this database */ |
| 203522 | | - int eType; /* FTS5_VOCAB_COL or ROW */ |
| 203877 | + int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */ |
| 203523 | 203878 | }; |
| 203524 | 203879 | |
| 203525 | 203880 | struct Fts5VocabCursor { |
| 203526 | 203881 | sqlite3_vtab_cursor base; |
| 203527 | 203882 | sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */ |
| | @@ -203537,20 +203892,26 @@ |
| 203537 | 203892 | Fts5Config *pConfig; /* Fts5 table configuration */ |
| 203538 | 203893 | int iCol; |
| 203539 | 203894 | i64 *aCnt; |
| 203540 | 203895 | i64 *aDoc; |
| 203541 | 203896 | |
| 203542 | | - /* Output values used by 'row' and 'col' tables */ |
| 203897 | + /* Output values used by all tables. */ |
| 203543 | 203898 | i64 rowid; /* This table's current rowid value */ |
| 203544 | 203899 | Fts5Buffer term; /* Current value of 'term' column */ |
| 203900 | + |
| 203901 | + /* Output values Used by 'instance' tables only */ |
| 203902 | + i64 iInstPos; |
| 203903 | + int iInstOff; |
| 203545 | 203904 | }; |
| 203546 | 203905 | |
| 203547 | | -#define FTS5_VOCAB_COL 0 |
| 203548 | | -#define FTS5_VOCAB_ROW 1 |
| 203906 | +#define FTS5_VOCAB_COL 0 |
| 203907 | +#define FTS5_VOCAB_ROW 1 |
| 203908 | +#define FTS5_VOCAB_INSTANCE 2 |
| 203549 | 203909 | |
| 203550 | 203910 | #define FTS5_VOCAB_COL_SCHEMA "term, col, doc, cnt" |
| 203551 | 203911 | #define FTS5_VOCAB_ROW_SCHEMA "term, doc, cnt" |
| 203912 | +#define FTS5_VOCAB_INST_SCHEMA "term, doc, col, offset" |
| 203552 | 203913 | |
| 203553 | 203914 | /* |
| 203554 | 203915 | ** Bits for the mask used as the idxNum value by xBestIndex/xFilter. |
| 203555 | 203916 | */ |
| 203556 | 203917 | #define FTS5_VOCAB_TERM_EQ 0x01 |
| | @@ -203573,10 +203934,13 @@ |
| 203573 | 203934 | *peType = FTS5_VOCAB_COL; |
| 203574 | 203935 | }else |
| 203575 | 203936 | |
| 203576 | 203937 | if( sqlite3_stricmp(zCopy, "row")==0 ){ |
| 203577 | 203938 | *peType = FTS5_VOCAB_ROW; |
| 203939 | + }else |
| 203940 | + if( sqlite3_stricmp(zCopy, "instance")==0 ){ |
| 203941 | + *peType = FTS5_VOCAB_INSTANCE; |
| 203578 | 203942 | }else |
| 203579 | 203943 | { |
| 203580 | 203944 | *pzErr = sqlite3_mprintf("fts5vocab: unknown table type: %Q", zCopy); |
| 203581 | 203945 | rc = SQLITE_ERROR; |
| 203582 | 203946 | } |
| | @@ -203634,11 +203998,12 @@ |
| 203634 | 203998 | sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */ |
| 203635 | 203999 | char **pzErr /* Write any error message here */ |
| 203636 | 204000 | ){ |
| 203637 | 204001 | const char *azSchema[] = { |
| 203638 | 204002 | "CREATE TABlE vocab(" FTS5_VOCAB_COL_SCHEMA ")", |
| 203639 | | - "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")" |
| 204003 | + "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")", |
| 204004 | + "CREATE TABlE vocab(" FTS5_VOCAB_INST_SCHEMA ")" |
| 203640 | 204005 | }; |
| 203641 | 204006 | |
| 203642 | 204007 | Fts5VocabTable *pRet = 0; |
| 203643 | 204008 | int rc = SQLITE_OK; /* Return code */ |
| 203644 | 204009 | int bDb; |
| | @@ -203708,10 +204073,19 @@ |
| 203708 | 204073 | return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr); |
| 203709 | 204074 | } |
| 203710 | 204075 | |
| 203711 | 204076 | /* |
| 203712 | 204077 | ** Implementation of the xBestIndex method. |
| 204078 | +** |
| 204079 | +** Only constraints of the form: |
| 204080 | +** |
| 204081 | +** term <= ? |
| 204082 | +** term == ? |
| 204083 | +** term >= ? |
| 204084 | +** |
| 204085 | +** are interpreted. Less-than and less-than-or-equal are treated |
| 204086 | +** identically, as are greater-than and greater-than-or-equal. |
| 203713 | 204087 | */ |
| 203714 | 204088 | static int fts5VocabBestIndexMethod( |
| 203715 | 204089 | sqlite3_vtab *pUnused, |
| 203716 | 204090 | sqlite3_index_info *pInfo |
| 203717 | 204091 | ){ |
| | @@ -203851,10 +204225,58 @@ |
| 203851 | 204225 | sqlite3_finalize(pCsr->pStmt); |
| 203852 | 204226 | sqlite3_free(pCsr); |
| 203853 | 204227 | return SQLITE_OK; |
| 203854 | 204228 | } |
| 203855 | 204229 | |
| 204230 | +static int fts5VocabInstanceNewTerm(Fts5VocabCursor *pCsr){ |
| 204231 | + int rc = SQLITE_OK; |
| 204232 | + |
| 204233 | + if( sqlite3Fts5IterEof(pCsr->pIter) ){ |
| 204234 | + pCsr->bEof = 1; |
| 204235 | + }else{ |
| 204236 | + const char *zTerm; |
| 204237 | + int nTerm; |
| 204238 | + zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm); |
| 204239 | + if( pCsr->nLeTerm>=0 ){ |
| 204240 | + int nCmp = MIN(nTerm, pCsr->nLeTerm); |
| 204241 | + int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp); |
| 204242 | + if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){ |
| 204243 | + pCsr->bEof = 1; |
| 204244 | + } |
| 204245 | + } |
| 204246 | + |
| 204247 | + sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm); |
| 204248 | + } |
| 204249 | + return rc; |
| 204250 | +} |
| 204251 | + |
| 204252 | +static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){ |
| 204253 | + int eDetail = pCsr->pConfig->eDetail; |
| 204254 | + int rc = SQLITE_OK; |
| 204255 | + Fts5IndexIter *pIter = pCsr->pIter; |
| 204256 | + i64 *pp = &pCsr->iInstPos; |
| 204257 | + int *po = &pCsr->iInstOff; |
| 204258 | + |
| 204259 | + while( eDetail==FTS5_DETAIL_NONE |
| 204260 | + || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp) |
| 204261 | + ){ |
| 204262 | + pCsr->iInstPos = 0; |
| 204263 | + pCsr->iInstOff = 0; |
| 204264 | + |
| 204265 | + rc = sqlite3Fts5IterNextScan(pCsr->pIter); |
| 204266 | + if( rc==SQLITE_OK ){ |
| 204267 | + rc = fts5VocabInstanceNewTerm(pCsr); |
| 204268 | + if( eDetail==FTS5_DETAIL_NONE ) break; |
| 204269 | + } |
| 204270 | + if( rc ){ |
| 204271 | + pCsr->bEof = 1; |
| 204272 | + break; |
| 204273 | + } |
| 204274 | + } |
| 204275 | + |
| 204276 | + return rc; |
| 204277 | +} |
| 203856 | 204278 | |
| 203857 | 204279 | /* |
| 203858 | 204280 | ** Advance the cursor to the next row in the table. |
| 203859 | 204281 | */ |
| 203860 | 204282 | static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){ |
| | @@ -203862,18 +204284,22 @@ |
| 203862 | 204284 | Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab; |
| 203863 | 204285 | int rc = SQLITE_OK; |
| 203864 | 204286 | int nCol = pCsr->pConfig->nCol; |
| 203865 | 204287 | |
| 203866 | 204288 | pCsr->rowid++; |
| 204289 | + |
| 204290 | + if( pTab->eType==FTS5_VOCAB_INSTANCE ){ |
| 204291 | + return fts5VocabInstanceNext(pCsr); |
| 204292 | + } |
| 203867 | 204293 | |
| 203868 | 204294 | if( pTab->eType==FTS5_VOCAB_COL ){ |
| 203869 | 204295 | for(pCsr->iCol++; pCsr->iCol<nCol; pCsr->iCol++){ |
| 203870 | 204296 | if( pCsr->aDoc[pCsr->iCol] ) break; |
| 203871 | 204297 | } |
| 203872 | 204298 | } |
| 203873 | 204299 | |
| 203874 | | - if( pTab->eType==FTS5_VOCAB_ROW || pCsr->iCol>=nCol ){ |
| 204300 | + if( pTab->eType!=FTS5_VOCAB_COL || pCsr->iCol>=nCol ){ |
| 203875 | 204301 | if( sqlite3Fts5IterEof(pCsr->pIter) ){ |
| 203876 | 204302 | pCsr->bEof = 1; |
| 203877 | 204303 | }else{ |
| 203878 | 204304 | const char *zTerm; |
| 203879 | 204305 | int nTerm; |
| | @@ -203893,26 +204319,30 @@ |
| 203893 | 204319 | memset(pCsr->aDoc, 0, nCol * sizeof(i64)); |
| 203894 | 204320 | pCsr->iCol = 0; |
| 203895 | 204321 | |
| 203896 | 204322 | assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW ); |
| 203897 | 204323 | while( rc==SQLITE_OK ){ |
| 204324 | + int eDetail = pCsr->pConfig->eDetail; |
| 203898 | 204325 | const u8 *pPos; int nPos; /* Position list */ |
| 203899 | 204326 | i64 iPos = 0; /* 64-bit position read from poslist */ |
| 203900 | 204327 | int iOff = 0; /* Current offset within position list */ |
| 203901 | 204328 | |
| 203902 | 204329 | pPos = pCsr->pIter->pData; |
| 203903 | 204330 | nPos = pCsr->pIter->nData; |
| 203904 | | - switch( pCsr->pConfig->eDetail ){ |
| 203905 | | - case FTS5_DETAIL_FULL: |
| 203906 | | - pPos = pCsr->pIter->pData; |
| 203907 | | - nPos = pCsr->pIter->nData; |
| 203908 | | - if( pTab->eType==FTS5_VOCAB_ROW ){ |
| 204331 | + |
| 204332 | + switch( pTab->eType ){ |
| 204333 | + case FTS5_VOCAB_ROW: |
| 204334 | + if( eDetail==FTS5_DETAIL_FULL ){ |
| 203909 | 204335 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ |
| 203910 | 204336 | pCsr->aCnt[0]++; |
| 203911 | 204337 | } |
| 203912 | | - pCsr->aDoc[0]++; |
| 203913 | | - }else{ |
| 204338 | + } |
| 204339 | + pCsr->aDoc[0]++; |
| 204340 | + break; |
| 204341 | + |
| 204342 | + case FTS5_VOCAB_COL: |
| 204343 | + if( eDetail==FTS5_DETAIL_FULL ){ |
| 203914 | 204344 | int iCol = -1; |
| 203915 | 204345 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ |
| 203916 | 204346 | int ii = FTS5_POS2COLUMN(iPos); |
| 203917 | 204347 | pCsr->aCnt[ii]++; |
| 203918 | 204348 | if( iCol!=ii ){ |
| | @@ -203922,37 +204352,34 @@ |
| 203922 | 204352 | } |
| 203923 | 204353 | pCsr->aDoc[ii]++; |
| 203924 | 204354 | iCol = ii; |
| 203925 | 204355 | } |
| 203926 | 204356 | } |
| 203927 | | - } |
| 203928 | | - break; |
| 203929 | | - |
| 203930 | | - case FTS5_DETAIL_COLUMNS: |
| 203931 | | - if( pTab->eType==FTS5_VOCAB_ROW ){ |
| 203932 | | - pCsr->aDoc[0]++; |
| 203933 | | - }else{ |
| 204357 | + }else if( eDetail==FTS5_DETAIL_COLUMNS ){ |
| 203934 | 204358 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){ |
| 203935 | 204359 | assert_nc( iPos>=0 && iPos<nCol ); |
| 203936 | 204360 | if( iPos>=nCol ){ |
| 203937 | 204361 | rc = FTS5_CORRUPT; |
| 203938 | 204362 | break; |
| 203939 | 204363 | } |
| 203940 | 204364 | pCsr->aDoc[iPos]++; |
| 203941 | 204365 | } |
| 204366 | + }else{ |
| 204367 | + assert( eDetail==FTS5_DETAIL_NONE ); |
| 204368 | + pCsr->aDoc[0]++; |
| 203942 | 204369 | } |
| 203943 | 204370 | break; |
| 203944 | 204371 | |
| 203945 | | - default: |
| 203946 | | - assert( pCsr->pConfig->eDetail==FTS5_DETAIL_NONE ); |
| 203947 | | - pCsr->aDoc[0]++; |
| 204372 | + default: |
| 204373 | + assert( pTab->eType==FTS5_VOCAB_INSTANCE ); |
| 203948 | 204374 | break; |
| 203949 | 204375 | } |
| 203950 | 204376 | |
| 203951 | 204377 | if( rc==SQLITE_OK ){ |
| 203952 | 204378 | rc = sqlite3Fts5IterNextScan(pCsr->pIter); |
| 203953 | 204379 | } |
| 204380 | + if( pTab->eType==FTS5_VOCAB_INSTANCE ) break; |
| 203954 | 204381 | |
| 203955 | 204382 | if( rc==SQLITE_OK ){ |
| 203956 | 204383 | zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm); |
| 203957 | 204384 | if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){ |
| 203958 | 204385 | break; |
| | @@ -203978,11 +204405,13 @@ |
| 203978 | 204405 | int idxNum, /* Strategy index */ |
| 203979 | 204406 | const char *zUnused, /* Unused */ |
| 203980 | 204407 | int nUnused, /* Number of elements in apVal */ |
| 203981 | 204408 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 203982 | 204409 | ){ |
| 204410 | + Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab; |
| 203983 | 204411 | Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor; |
| 204412 | + int eType = pTab->eType; |
| 203984 | 204413 | int rc = SQLITE_OK; |
| 203985 | 204414 | |
| 203986 | 204415 | int iVal = 0; |
| 203987 | 204416 | int f = FTS5INDEX_QUERY_SCAN; |
| 203988 | 204417 | const char *zTerm = 0; |
| | @@ -204018,15 +204447,20 @@ |
| 204018 | 204447 | memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1); |
| 204019 | 204448 | } |
| 204020 | 204449 | } |
| 204021 | 204450 | } |
| 204022 | 204451 | |
| 204023 | | - |
| 204024 | 204452 | if( rc==SQLITE_OK ){ |
| 204025 | 204453 | rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter); |
| 204026 | 204454 | } |
| 204027 | | - if( rc==SQLITE_OK ){ |
| 204455 | + if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){ |
| 204456 | + rc = fts5VocabInstanceNewTerm(pCsr); |
| 204457 | + } |
| 204458 | + if( rc==SQLITE_OK |
| 204459 | + && !pCsr->bEof |
| 204460 | + && (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE) |
| 204461 | + ){ |
| 204028 | 204462 | rc = fts5VocabNextMethod(pCursor); |
| 204029 | 204463 | } |
| 204030 | 204464 | |
| 204031 | 204465 | return rc; |
| 204032 | 204466 | } |
| | @@ -204064,16 +204498,45 @@ |
| 204064 | 204498 | }else if( iCol==2 ){ |
| 204065 | 204499 | iVal = pCsr->aDoc[pCsr->iCol]; |
| 204066 | 204500 | }else{ |
| 204067 | 204501 | iVal = pCsr->aCnt[pCsr->iCol]; |
| 204068 | 204502 | } |
| 204069 | | - }else{ |
| 204503 | + }else if( eType==FTS5_VOCAB_ROW ){ |
| 204070 | 204504 | assert( iCol==1 || iCol==2 ); |
| 204071 | 204505 | if( iCol==1 ){ |
| 204072 | 204506 | iVal = pCsr->aDoc[0]; |
| 204073 | 204507 | }else{ |
| 204074 | 204508 | iVal = pCsr->aCnt[0]; |
| 204509 | + } |
| 204510 | + }else{ |
| 204511 | + int eDetail = pCsr->pConfig->eDetail; |
| 204512 | + assert( eType==FTS5_VOCAB_INSTANCE ); |
| 204513 | + switch( iCol ){ |
| 204514 | + case 1: |
| 204515 | + sqlite3_result_int64(pCtx, pCsr->pIter->iRowid); |
| 204516 | + break; |
| 204517 | + case 2: { |
| 204518 | + int ii = -1; |
| 204519 | + if( eDetail==FTS5_DETAIL_FULL ){ |
| 204520 | + ii = FTS5_POS2COLUMN(pCsr->iInstPos); |
| 204521 | + }else if( eDetail==FTS5_DETAIL_COLUMNS ){ |
| 204522 | + ii = pCsr->iInstPos; |
| 204523 | + } |
| 204524 | + if( ii>=0 && ii<pCsr->pConfig->nCol ){ |
| 204525 | + const char *z = pCsr->pConfig->azCol[ii]; |
| 204526 | + sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC); |
| 204527 | + } |
| 204528 | + break; |
| 204529 | + } |
| 204530 | + default: { |
| 204531 | + assert( iCol==3 ); |
| 204532 | + if( eDetail==FTS5_DETAIL_FULL ){ |
| 204533 | + int ii = FTS5_POS2OFFSET(pCsr->iInstPos); |
| 204534 | + sqlite3_result_int(pCtx, ii); |
| 204535 | + } |
| 204536 | + break; |
| 204537 | + } |
| 204075 | 204538 | } |
| 204076 | 204539 | } |
| 204077 | 204540 | |
| 204078 | 204541 | if( iVal>0 ) sqlite3_result_int64(pCtx, iVal); |
| 204079 | 204542 | return SQLITE_OK; |
| | @@ -204430,5 +204893,12 @@ |
| 204430 | 204893 | } |
| 204431 | 204894 | #endif /* SQLITE_CORE */ |
| 204432 | 204895 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 204433 | 204896 | |
| 204434 | 204897 | /************** End of stmt.c ************************************************/ |
| 204898 | +#if __LINE__!=204898 |
| 204899 | +#undef SQLITE_SOURCE_ID |
| 204900 | +#define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595alt2" |
| 204901 | +#endif |
| 204902 | +/* Return the source-id for this library */ |
| 204903 | +SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 204904 | +/************************** End of sqlite3.c ******************************/ |
| 204435 | 204905 | |