000001 /* 000002 ** 2001 September 15 000003 ** 000004 ** The author disclaims copyright to this source code. In place of 000005 ** a legal notice, here is a blessing: 000006 ** 000007 ** May you do good and not evil. 000008 ** May you find forgiveness for yourself and forgive others. 000009 ** May you share freely, never taking more than you give. 000010 ** 000011 ************************************************************************* 000012 ** Internal interface definitions for SQLite. 000013 ** 000014 */ 000015 #ifndef SQLITEINT_H 000016 #define SQLITEINT_H 000017 000018 /* Special Comments: 000019 ** 000020 ** Some comments have special meaning to the tools that measure test 000021 ** coverage: 000022 ** 000023 ** NO_TEST - The branches on this line are not 000024 ** measured by branch coverage. This is 000025 ** used on lines of code that actually 000026 ** implement parts of coverage testing. 000027 ** 000028 ** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false 000029 ** and the correct answer is still obtained, 000030 ** though perhaps more slowly. 000031 ** 000032 ** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true 000033 ** and the correct answer is still obtained, 000034 ** though perhaps more slowly. 000035 ** 000036 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread 000037 ** that would be harmless and undetectable 000038 ** if it did occur. 000039 ** 000040 ** In all cases, the special comment must be enclosed in the usual 000041 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the 000042 ** asterisks and the comment text. 000043 */ 000044 000045 /* 000046 ** Make sure the Tcl calling convention macro is defined. This macro is 000047 ** only used by test code and Tcl integration code. 000048 */ 000049 #ifndef SQLITE_TCLAPI 000050 # define SQLITE_TCLAPI 000051 #endif 000052 000053 /* 000054 ** Include the header file used to customize the compiler options for MSVC. 000055 ** This should be done first so that it can successfully prevent spurious 000056 ** compiler warnings due to subsequent content in this file and other files 000057 ** that are included by this file. 000058 */ 000059 #include "msvc.h" 000060 000061 /* 000062 ** Special setup for VxWorks 000063 */ 000064 #include "vxworks.h" 000065 000066 /* 000067 ** These #defines should enable >2GB file support on POSIX if the 000068 ** underlying operating system supports it. If the OS lacks 000069 ** large file support, or if the OS is windows, these should be no-ops. 000070 ** 000071 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any 000072 ** system #includes. Hence, this block of code must be the very first 000073 ** code in all source files. 000074 ** 000075 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch 000076 ** on the compiler command line. This is necessary if you are compiling 000077 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work 000078 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 000079 ** without this option, LFS is enable. But LFS does not exist in the kernel 000080 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary 000081 ** portability you should omit LFS. 000082 ** 000083 ** The previous paragraph was written in 2005. (This paragraph is written 000084 ** on 2008-11-28.) These days, all Linux kernels support large files, so 000085 ** you should probably leave LFS enabled. But some embedded platforms might 000086 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. 000087 ** 000088 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. 000089 */ 000090 #ifndef SQLITE_DISABLE_LFS 000091 # define _LARGE_FILE 1 000092 # ifndef _FILE_OFFSET_BITS 000093 # define _FILE_OFFSET_BITS 64 000094 # endif 000095 # define _LARGEFILE_SOURCE 1 000096 #endif 000097 000098 /* The GCC_VERSION and MSVC_VERSION macros are used to 000099 ** conditionally include optimizations for each of these compilers. A 000100 ** value of 0 means that compiler is not being used. The 000101 ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific 000102 ** optimizations, and hence set all compiler macros to 0 000103 ** 000104 ** There was once also a CLANG_VERSION macro. However, we learn that the 000105 ** version numbers in clang are for "marketing" only and are inconsistent 000106 ** and unreliable. Fortunately, all versions of clang also recognize the 000107 ** gcc version numbers and have reasonable settings for gcc version numbers, 000108 ** so the GCC_VERSION macro will be set to a correct non-zero value even 000109 ** when compiling with clang. 000110 */ 000111 #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) 000112 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) 000113 #else 000114 # define GCC_VERSION 0 000115 #endif 000116 #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) 000117 # define MSVC_VERSION _MSC_VER 000118 #else 000119 # define MSVC_VERSION 0 000120 #endif 000121 000122 /* 000123 ** Some C99 functions in "math.h" are only present for MSVC when its version 000124 ** is associated with Visual Studio 2013 or higher. 000125 */ 000126 #ifndef SQLITE_HAVE_C99_MATH_FUNCS 000127 # if MSVC_VERSION==0 || MSVC_VERSION>=1800 000128 # define SQLITE_HAVE_C99_MATH_FUNCS (1) 000129 # else 000130 # define SQLITE_HAVE_C99_MATH_FUNCS (0) 000131 # endif 000132 #endif 000133 000134 /* Needed for various definitions... */ 000135 #if defined(__GNUC__) && !defined(_GNU_SOURCE) 000136 # define _GNU_SOURCE 000137 #endif 000138 000139 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE) 000140 # define _BSD_SOURCE 000141 #endif 000142 000143 /* 000144 ** Macro to disable warnings about missing "break" at the end of a "case". 000145 */ 000146 #if GCC_VERSION>=7000000 000147 # define deliberate_fall_through __attribute__((fallthrough)); 000148 #else 000149 # define deliberate_fall_through 000150 #endif 000151 000152 /* 000153 ** For MinGW, check to see if we can include the header file containing its 000154 ** version information, among other things. Normally, this internal MinGW 000155 ** header file would [only] be included automatically by other MinGW header 000156 ** files; however, the contained version information is now required by this 000157 ** header file to work around binary compatibility issues (see below) and 000158 ** this is the only known way to reliably obtain it. This entire #if block 000159 ** would be completely unnecessary if there was any other way of detecting 000160 ** MinGW via their preprocessor (e.g. if they customized their GCC to define 000161 ** some MinGW-specific macros). When compiling for MinGW, either the 000162 ** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be 000163 ** defined; otherwise, detection of conditions specific to MinGW will be 000164 ** disabled. 000165 */ 000166 #if defined(_HAVE_MINGW_H) 000167 # include "mingw.h" 000168 #elif defined(_HAVE__MINGW_H) 000169 # include "_mingw.h" 000170 #endif 000171 000172 /* 000173 ** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T 000174 ** define is required to maintain binary compatibility with the MSVC runtime 000175 ** library in use (e.g. for Windows XP). 000176 */ 000177 #if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \ 000178 defined(_WIN32) && !defined(_WIN64) && \ 000179 defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ 000180 defined(__MSVCRT__) 000181 # define _USE_32BIT_TIME_T 000182 #endif 000183 000184 /* Optionally #include a user-defined header, whereby compilation options 000185 ** may be set prior to where they take effect, but after platform setup. 000186 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include 000187 ** file. 000188 */ 000189 #ifdef SQLITE_CUSTOM_INCLUDE 000190 # define INC_STRINGIFY_(f) #f 000191 # define INC_STRINGIFY(f) INC_STRINGIFY_(f) 000192 # include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE) 000193 #endif 000194 000195 /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear 000196 ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for 000197 ** MinGW. 000198 */ 000199 #include "sqlite3.h" 000200 000201 /* 000202 ** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory. 000203 */ 000204 #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1 000205 000206 /* 000207 ** Include the configuration header output by 'configure' if we're using the 000208 ** autoconf-based build 000209 */ 000210 #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) 000211 #include "sqlite_cfg.h" 000212 #define SQLITECONFIG_H 1 000213 #endif 000214 000215 #include "sqliteLimit.h" 000216 000217 /* Disable nuisance warnings on Borland compilers */ 000218 #if defined(__BORLANDC__) 000219 #pragma warn -rch /* unreachable code */ 000220 #pragma warn -ccc /* Condition is always true or false */ 000221 #pragma warn -aus /* Assigned value is never used */ 000222 #pragma warn -csu /* Comparing signed and unsigned */ 000223 #pragma warn -spa /* Suspicious pointer arithmetic */ 000224 #endif 000225 000226 /* 000227 ** A few places in the code require atomic load/store of aligned 000228 ** integer values. 000229 */ 000230 #ifndef __has_extension 000231 # define __has_extension(x) 0 /* compatibility with non-clang compilers */ 000232 #endif 000233 #if GCC_VERSION>=4007000 || __has_extension(c_atomic) 000234 # define SQLITE_ATOMIC_INTRINSICS 1 000235 # define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED) 000236 # define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED) 000237 #else 000238 # define SQLITE_ATOMIC_INTRINSICS 0 000239 # define AtomicLoad(PTR) (*(PTR)) 000240 # define AtomicStore(PTR,VAL) (*(PTR) = (VAL)) 000241 #endif 000242 000243 /* 000244 ** Include standard header files as necessary 000245 */ 000246 #ifdef HAVE_STDINT_H 000247 #include <stdint.h> 000248 #endif 000249 #ifdef HAVE_INTTYPES_H 000250 #include <inttypes.h> 000251 #endif 000252 000253 /* 000254 ** The following macros are used to cast pointers to integers and 000255 ** integers to pointers. The way you do this varies from one compiler 000256 ** to the next, so we have developed the following set of #if statements 000257 ** to generate appropriate macros for a wide range of compilers. 000258 ** 000259 ** The correct "ANSI" way to do this is to use the intptr_t type. 000260 ** Unfortunately, that typedef is not available on all compilers, or 000261 ** if it is available, it requires an #include of specific headers 000262 ** that vary from one machine to the next. 000263 ** 000264 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on 000265 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). 000266 ** So we have to define the macros in different ways depending on the 000267 ** compiler. 000268 */ 000269 #if defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ 000270 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) 000271 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) 000272 #elif defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ 000273 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) 000274 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) 000275 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ 000276 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) 000277 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) 000278 #else /* Generates a warning - but it always works */ 000279 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) 000280 # define SQLITE_PTR_TO_INT(X) ((int)(X)) 000281 #endif 000282 000283 /* 000284 ** Macros to hint to the compiler that a function should or should not be 000285 ** inlined. 000286 */ 000287 #if defined(__GNUC__) 000288 # define SQLITE_NOINLINE __attribute__((noinline)) 000289 # define SQLITE_INLINE __attribute__((always_inline)) inline 000290 #elif defined(_MSC_VER) && _MSC_VER>=1310 000291 # define SQLITE_NOINLINE __declspec(noinline) 000292 # define SQLITE_INLINE __forceinline 000293 #else 000294 # define SQLITE_NOINLINE 000295 # define SQLITE_INLINE 000296 #endif 000297 #if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__) 000298 # undef SQLITE_INLINE 000299 # define SQLITE_INLINE 000300 #endif 000301 000302 /* 000303 ** Make sure that the compiler intrinsics we desire are enabled when 000304 ** compiling with an appropriate version of MSVC unless prevented by 000305 ** the SQLITE_DISABLE_INTRINSIC define. 000306 */ 000307 #if !defined(SQLITE_DISABLE_INTRINSIC) 000308 # if defined(_MSC_VER) && _MSC_VER>=1400 000309 # if !defined(_WIN32_WCE) 000310 # include <intrin.h> 000311 # pragma intrinsic(_byteswap_ushort) 000312 # pragma intrinsic(_byteswap_ulong) 000313 # pragma intrinsic(_byteswap_uint64) 000314 # pragma intrinsic(_ReadWriteBarrier) 000315 # else 000316 # include <cmnintrin.h> 000317 # endif 000318 # endif 000319 #endif 000320 000321 /* 000322 ** Enable SQLITE_USE_SEH by default on MSVC builds. Only omit 000323 ** SEH support if the -DSQLITE_OMIT_SEH option is given. 000324 */ 000325 #if defined(_MSC_VER) && !defined(SQLITE_OMIT_SEH) 000326 # define SQLITE_USE_SEH 1 000327 #else 000328 # undef SQLITE_USE_SEH 000329 #endif 000330 000331 /* 000332 ** Enable SQLITE_DIRECT_OVERFLOW_READ, unless the build explicitly 000333 ** disables it using -DSQLITE_DIRECT_OVERFLOW_READ=0 000334 */ 000335 #if defined(SQLITE_DIRECT_OVERFLOW_READ) && SQLITE_DIRECT_OVERFLOW_READ+1==1 000336 /* Disable if -DSQLITE_DIRECT_OVERFLOW_READ=0 */ 000337 # undef SQLITE_DIRECT_OVERFLOW_READ 000338 #else 000339 /* In all other cases, enable */ 000340 # define SQLITE_DIRECT_OVERFLOW_READ 1 000341 #endif 000342 000343 000344 /* 000345 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. 000346 ** 0 means mutexes are permanently disable and the library is never 000347 ** threadsafe. 1 means the library is serialized which is the highest 000348 ** level of threadsafety. 2 means the library is multithreaded - multiple 000349 ** threads can use SQLite as long as no two threads try to use the same 000350 ** database connection at the same time. 000351 ** 000352 ** Older versions of SQLite used an optional THREADSAFE macro. 000353 ** We support that for legacy. 000354 ** 000355 ** To ensure that the correct value of "THREADSAFE" is reported when querying 000356 ** for compile-time options at runtime (e.g. "PRAGMA compile_options"), this 000357 ** logic is partially replicated in ctime.c. If it is updated here, it should 000358 ** also be updated there. 000359 */ 000360 #if !defined(SQLITE_THREADSAFE) 000361 # if defined(THREADSAFE) 000362 # define SQLITE_THREADSAFE THREADSAFE 000363 # else 000364 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ 000365 # endif 000366 #endif 000367 000368 /* 000369 ** Powersafe overwrite is on by default. But can be turned off using 000370 ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. 000371 */ 000372 #ifndef SQLITE_POWERSAFE_OVERWRITE 000373 # define SQLITE_POWERSAFE_OVERWRITE 1 000374 #endif 000375 000376 /* 000377 ** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by 000378 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in 000379 ** which case memory allocation statistics are disabled by default. 000380 */ 000381 #if !defined(SQLITE_DEFAULT_MEMSTATUS) 000382 # define SQLITE_DEFAULT_MEMSTATUS 1 000383 #endif 000384 000385 /* 000386 ** Exactly one of the following macros must be defined in order to 000387 ** specify which memory allocation subsystem to use. 000388 ** 000389 ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() 000390 ** SQLITE_WIN32_MALLOC // Use Win32 native heap API 000391 ** SQLITE_ZERO_MALLOC // Use a stub allocator that always fails 000392 ** SQLITE_MEMDEBUG // Debugging version of system malloc() 000393 ** 000394 ** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the 000395 ** assert() macro is enabled, each call into the Win32 native heap subsystem 000396 ** will cause HeapValidate to be called. If heap validation should fail, an 000397 ** assertion will be triggered. 000398 ** 000399 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as 000400 ** the default. 000401 */ 000402 #if defined(SQLITE_SYSTEM_MALLOC) \ 000403 + defined(SQLITE_WIN32_MALLOC) \ 000404 + defined(SQLITE_ZERO_MALLOC) \ 000405 + defined(SQLITE_MEMDEBUG)>1 000406 # error "Two or more of the following compile-time configuration options\ 000407 are defined but at most one is allowed:\ 000408 SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG,\ 000409 SQLITE_ZERO_MALLOC" 000410 #endif 000411 #if defined(SQLITE_SYSTEM_MALLOC) \ 000412 + defined(SQLITE_WIN32_MALLOC) \ 000413 + defined(SQLITE_ZERO_MALLOC) \ 000414 + defined(SQLITE_MEMDEBUG)==0 000415 # define SQLITE_SYSTEM_MALLOC 1 000416 #endif 000417 000418 /* 000419 ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the 000420 ** sizes of memory allocations below this value where possible. 000421 */ 000422 #if !defined(SQLITE_MALLOC_SOFT_LIMIT) 000423 # define SQLITE_MALLOC_SOFT_LIMIT 1024 000424 #endif 000425 000426 /* 000427 ** We need to define _XOPEN_SOURCE as follows in order to enable 000428 ** recursive mutexes on most Unix systems and fchmod() on OpenBSD. 000429 ** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit 000430 ** it. 000431 */ 000432 #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) 000433 # define _XOPEN_SOURCE 600 000434 #endif 000435 000436 /* 000437 ** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that 000438 ** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, 000439 ** make it true by defining or undefining NDEBUG. 000440 ** 000441 ** Setting NDEBUG makes the code smaller and faster by disabling the 000442 ** assert() statements in the code. So we want the default action 000443 ** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG 000444 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out 000445 ** feature. 000446 */ 000447 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 000448 # define NDEBUG 1 000449 #endif 000450 #if defined(NDEBUG) && defined(SQLITE_DEBUG) 000451 # undef NDEBUG 000452 #endif 000453 000454 /* 000455 ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. 000456 */ 000457 #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) 000458 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 000459 #endif 000460 000461 /* 000462 ** The testcase() macro is used to aid in coverage testing. When 000463 ** doing coverage testing, the condition inside the argument to 000464 ** testcase() must be evaluated both true and false in order to 000465 ** get full branch coverage. The testcase() macro is inserted 000466 ** to help ensure adequate test coverage in places where simple 000467 ** condition/decision coverage is inadequate. For example, testcase() 000468 ** can be used to make sure boundary values are tested. For 000469 ** bitmask tests, testcase() can be used to make sure each bit 000470 ** is significant and used at least once. On switch statements 000471 ** where multiple cases go to the same block of code, testcase() 000472 ** can insure that all cases are evaluated. 000473 */ 000474 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) 000475 # ifndef SQLITE_AMALGAMATION 000476 extern unsigned int sqlite3CoverageCounter; 000477 # endif 000478 # define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; } 000479 #else 000480 # define testcase(X) 000481 #endif 000482 000483 /* 000484 ** The TESTONLY macro is used to enclose variable declarations or 000485 ** other bits of code that are needed to support the arguments 000486 ** within testcase() and assert() macros. 000487 */ 000488 #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) 000489 # define TESTONLY(X) X 000490 #else 000491 # define TESTONLY(X) 000492 #endif 000493 000494 /* 000495 ** Sometimes we need a small amount of code such as a variable initialization 000496 ** to setup for a later assert() statement. We do not want this code to 000497 ** appear when assert() is disabled. The following macro is therefore 000498 ** used to contain that setup code. The "VVA" acronym stands for 000499 ** "Verification, Validation, and Accreditation". In other words, the 000500 ** code within VVA_ONLY() will only run during verification processes. 000501 */ 000502 #ifndef NDEBUG 000503 # define VVA_ONLY(X) X 000504 #else 000505 # define VVA_ONLY(X) 000506 #endif 000507 000508 /* 000509 ** Disable ALWAYS() and NEVER() (make them pass-throughs) for coverage 000510 ** and mutation testing 000511 */ 000512 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) 000513 # define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 000514 #endif 000515 000516 /* 000517 ** The ALWAYS and NEVER macros surround boolean expressions which 000518 ** are intended to always be true or false, respectively. Such 000519 ** expressions could be omitted from the code completely. But they 000520 ** are included in a few cases in order to enhance the resilience 000521 ** of SQLite to unexpected behavior - to make the code "self-healing" 000522 ** or "ductile" rather than being "brittle" and crashing at the first 000523 ** hint of unplanned behavior. 000524 ** 000525 ** In other words, ALWAYS and NEVER are added for defensive code. 000526 ** 000527 ** When doing coverage testing ALWAYS and NEVER are hard-coded to 000528 ** be true and false so that the unreachable code they specify will 000529 ** not be counted as untested code. 000530 */ 000531 #if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) 000532 # define ALWAYS(X) (1) 000533 # define NEVER(X) (0) 000534 #elif !defined(NDEBUG) 000535 # define ALWAYS(X) ((X)?1:(assert(0),0)) 000536 # define NEVER(X) ((X)?(assert(0),1):0) 000537 #else 000538 # define ALWAYS(X) (X) 000539 # define NEVER(X) (X) 000540 #endif 000541 000542 /* 000543 ** Some conditionals are optimizations only. In other words, if the 000544 ** conditionals are replaced with a constant 1 (true) or 0 (false) then 000545 ** the correct answer is still obtained, though perhaps not as quickly. 000546 ** 000547 ** The following macros mark these optimizations conditionals. 000548 */ 000549 #if defined(SQLITE_MUTATION_TEST) 000550 # define OK_IF_ALWAYS_TRUE(X) (1) 000551 # define OK_IF_ALWAYS_FALSE(X) (0) 000552 #else 000553 # define OK_IF_ALWAYS_TRUE(X) (X) 000554 # define OK_IF_ALWAYS_FALSE(X) (X) 000555 #endif 000556 000557 /* 000558 ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is 000559 ** defined. We need to defend against those failures when testing with 000560 ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches 000561 ** during a normal build. The following macro can be used to disable tests 000562 ** that are always false except when SQLITE_TEST_REALLOC_STRESS is set. 000563 */ 000564 #if defined(SQLITE_TEST_REALLOC_STRESS) 000565 # define ONLY_IF_REALLOC_STRESS(X) (X) 000566 #elif !defined(NDEBUG) 000567 # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0) 000568 #else 000569 # define ONLY_IF_REALLOC_STRESS(X) (0) 000570 #endif 000571 000572 /* 000573 ** Declarations used for tracing the operating system interfaces. 000574 */ 000575 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ 000576 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) 000577 extern int sqlite3OSTrace; 000578 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X 000579 # define SQLITE_HAVE_OS_TRACE 000580 #else 000581 # define OSTRACE(X) 000582 # undef SQLITE_HAVE_OS_TRACE 000583 #endif 000584 000585 /* 000586 ** Is the sqlite3ErrName() function needed in the build? Currently, 000587 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when 000588 ** OSTRACE is enabled), and by several "test*.c" files (which are 000589 ** compiled using SQLITE_TEST). 000590 */ 000591 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \ 000592 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) 000593 # define SQLITE_NEED_ERR_NAME 000594 #else 000595 # undef SQLITE_NEED_ERR_NAME 000596 #endif 000597 000598 /* 000599 ** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN 000600 */ 000601 #ifdef SQLITE_OMIT_EXPLAIN 000602 # undef SQLITE_ENABLE_EXPLAIN_COMMENTS 000603 #endif 000604 000605 /* 000606 ** SQLITE_OMIT_VIRTUALTABLE implies SQLITE_OMIT_ALTERTABLE 000607 */ 000608 #if defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_ALTERTABLE) 000609 # define SQLITE_OMIT_ALTERTABLE 000610 #endif 000611 000612 #define SQLITE_DIGIT_SEPARATOR '_' 000613 000614 /* 000615 ** Return true (non-zero) if the input is an integer that is too large 000616 ** to fit in 32-bits. This macro is used inside of various testcase() 000617 ** macros to verify that we have tested SQLite for large-file support. 000618 */ 000619 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) 000620 000621 /* 000622 ** The macro unlikely() is a hint that surrounds a boolean 000623 ** expression that is usually false. Macro likely() surrounds 000624 ** a boolean expression that is usually true. These hints could, 000625 ** in theory, be used by the compiler to generate better code, but 000626 ** currently they are just comments for human readers. 000627 */ 000628 #define likely(X) (X) 000629 #define unlikely(X) (X) 000630 000631 #include "hash.h" 000632 #include "parse.h" 000633 #include <stdio.h> 000634 #include <stdlib.h> 000635 #include <string.h> 000636 #include <assert.h> 000637 #include <stddef.h> 000638 000639 /* 000640 ** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY. 000641 ** This allows better measurements of where memcpy() is used when running 000642 ** cachegrind. But this macro version of memcpy() is very slow so it 000643 ** should not be used in production. This is a performance measurement 000644 ** hack only. 000645 */ 000646 #ifdef SQLITE_INLINE_MEMCPY 000647 # define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\ 000648 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);} 000649 #endif 000650 000651 /* 000652 ** If compiling for a processor that lacks floating point support, 000653 ** substitute integer for floating-point 000654 */ 000655 #ifdef SQLITE_OMIT_FLOATING_POINT 000656 # define double sqlite_int64 000657 # define float sqlite_int64 000658 # define LONGDOUBLE_TYPE sqlite_int64 000659 # ifndef SQLITE_BIG_DBL 000660 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) 000661 # endif 000662 # define SQLITE_OMIT_DATETIME_FUNCS 1 000663 # define SQLITE_OMIT_TRACE 1 000664 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT 000665 # undef SQLITE_HAVE_ISNAN 000666 #endif 000667 #ifndef SQLITE_BIG_DBL 000668 # define SQLITE_BIG_DBL (1e99) 000669 #endif 000670 000671 /* 000672 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 000673 ** afterward. Having this macro allows us to cause the C compiler 000674 ** to omit code used by TEMP tables without messy #ifndef statements. 000675 */ 000676 #ifdef SQLITE_OMIT_TEMPDB 000677 #define OMIT_TEMPDB 1 000678 #else 000679 #define OMIT_TEMPDB 0 000680 #endif 000681 000682 /* 000683 ** The "file format" number is an integer that is incremented whenever 000684 ** the VDBE-level file format changes. The following macros define the 000685 ** the default file format for new databases and the maximum file format 000686 ** that the library can read. 000687 */ 000688 #define SQLITE_MAX_FILE_FORMAT 4 000689 #ifndef SQLITE_DEFAULT_FILE_FORMAT 000690 # define SQLITE_DEFAULT_FILE_FORMAT 4 000691 #endif 000692 000693 /* 000694 ** Determine whether triggers are recursive by default. This can be 000695 ** changed at run-time using a pragma. 000696 */ 000697 #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS 000698 # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0 000699 #endif 000700 000701 /* 000702 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified 000703 ** on the command-line 000704 */ 000705 #ifndef SQLITE_TEMP_STORE 000706 # define SQLITE_TEMP_STORE 1 000707 #endif 000708 000709 /* 000710 ** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if 000711 ** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it 000712 ** to zero. 000713 */ 000714 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0 000715 # undef SQLITE_MAX_WORKER_THREADS 000716 # define SQLITE_MAX_WORKER_THREADS 0 000717 #endif 000718 #ifndef SQLITE_MAX_WORKER_THREADS 000719 # define SQLITE_MAX_WORKER_THREADS 8 000720 #endif 000721 #ifndef SQLITE_DEFAULT_WORKER_THREADS 000722 # define SQLITE_DEFAULT_WORKER_THREADS 0 000723 #endif 000724 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS 000725 # undef SQLITE_MAX_WORKER_THREADS 000726 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS 000727 #endif 000728 000729 /* 000730 ** The default initial allocation for the pagecache when using separate 000731 ** pagecaches for each database connection. A positive number is the 000732 ** number of pages. A negative number N translations means that a buffer 000733 ** of -1024*N bytes is allocated and used for as many pages as it will hold. 000734 ** 000735 ** The default value of "20" was chosen to minimize the run-time of the 000736 ** speedtest1 test program with options: --shrink-memory --reprepare 000737 */ 000738 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ 000739 # define SQLITE_DEFAULT_PCACHE_INITSZ 20 000740 #endif 000741 000742 /* 000743 ** Default value for the SQLITE_CONFIG_SORTERREF_SIZE option. 000744 */ 000745 #ifndef SQLITE_DEFAULT_SORTERREF_SIZE 000746 # define SQLITE_DEFAULT_SORTERREF_SIZE 0x7fffffff 000747 #endif 000748 000749 /* 000750 ** The compile-time options SQLITE_MMAP_READWRITE and 000751 ** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another. 000752 ** You must choose one or the other (or neither) but not both. 000753 */ 000754 #if defined(SQLITE_MMAP_READWRITE) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) 000755 #error Cannot use both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE 000756 #endif 000757 000758 /* 000759 ** GCC does not define the offsetof() macro so we'll have to do it 000760 ** ourselves. 000761 */ 000762 #ifndef offsetof 000763 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) 000764 #endif 000765 000766 /* 000767 ** Macros to compute minimum and maximum of two numbers. 000768 */ 000769 #ifndef MIN 000770 # define MIN(A,B) ((A)<(B)?(A):(B)) 000771 #endif 000772 #ifndef MAX 000773 # define MAX(A,B) ((A)>(B)?(A):(B)) 000774 #endif 000775 000776 /* 000777 ** Swap two objects of type TYPE. 000778 */ 000779 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} 000780 000781 /* 000782 ** Check to see if this machine uses EBCDIC. (Yes, believe it or 000783 ** not, there are still machines out there that use EBCDIC.) 000784 */ 000785 #if 'A' == '\301' 000786 # define SQLITE_EBCDIC 1 000787 #else 000788 # define SQLITE_ASCII 1 000789 #endif 000790 000791 /* 000792 ** Integers of known sizes. These typedefs might change for architectures 000793 ** where the sizes very. Preprocessor macros are available so that the 000794 ** types can be conveniently redefined at compile-type. Like this: 000795 ** 000796 ** cc '-DUINTPTR_TYPE=long long int' ... 000797 */ 000798 #ifndef UINT32_TYPE 000799 # ifdef HAVE_UINT32_T 000800 # define UINT32_TYPE uint32_t 000801 # else 000802 # define UINT32_TYPE unsigned int 000803 # endif 000804 #endif 000805 #ifndef UINT16_TYPE 000806 # ifdef HAVE_UINT16_T 000807 # define UINT16_TYPE uint16_t 000808 # else 000809 # define UINT16_TYPE unsigned short int 000810 # endif 000811 #endif 000812 #ifndef INT16_TYPE 000813 # ifdef HAVE_INT16_T 000814 # define INT16_TYPE int16_t 000815 # else 000816 # define INT16_TYPE short int 000817 # endif 000818 #endif 000819 #ifndef UINT8_TYPE 000820 # ifdef HAVE_UINT8_T 000821 # define UINT8_TYPE uint8_t 000822 # else 000823 # define UINT8_TYPE unsigned char 000824 # endif 000825 #endif 000826 #ifndef INT8_TYPE 000827 # ifdef HAVE_INT8_T 000828 # define INT8_TYPE int8_t 000829 # else 000830 # define INT8_TYPE signed char 000831 # endif 000832 #endif 000833 #ifndef LONGDOUBLE_TYPE 000834 # define LONGDOUBLE_TYPE long double 000835 #endif 000836 typedef sqlite_int64 i64; /* 8-byte signed integer */ 000837 typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ 000838 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ 000839 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ 000840 typedef INT16_TYPE i16; /* 2-byte signed integer */ 000841 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ 000842 typedef INT8_TYPE i8; /* 1-byte signed integer */ 000843 000844 /* 000845 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value 000846 ** that can be stored in a u32 without loss of data. The value 000847 ** is 0x00000000ffffffff. But because of quirks of some compilers, we 000848 ** have to specify the value in the less intuitive manner shown: 000849 */ 000850 #define SQLITE_MAX_U32 ((((u64)1)<<32)-1) 000851 000852 /* 000853 ** The datatype used to store estimates of the number of rows in a 000854 ** table or index. 000855 */ 000856 typedef u64 tRowcnt; 000857 000858 /* 000859 ** Estimated quantities used for query planning are stored as 16-bit 000860 ** logarithms. For quantity X, the value stored is 10*log2(X). This 000861 ** gives a possible range of values of approximately 1.0e986 to 1e-986. 000862 ** But the allowed values are "grainy". Not every value is representable. 000863 ** For example, quantities 16 and 17 are both represented by a LogEst 000864 ** of 40. However, since LogEst quantities are suppose to be estimates, 000865 ** not exact values, this imprecision is not a problem. 000866 ** 000867 ** "LogEst" is short for "Logarithmic Estimate". 000868 ** 000869 ** Examples: 000870 ** 1 -> 0 20 -> 43 10000 -> 132 000871 ** 2 -> 10 25 -> 46 25000 -> 146 000872 ** 3 -> 16 100 -> 66 1000000 -> 199 000873 ** 4 -> 20 1000 -> 99 1048576 -> 200 000874 ** 10 -> 33 1024 -> 100 4294967296 -> 320 000875 ** 000876 ** The LogEst can be negative to indicate fractional values. 000877 ** Examples: 000878 ** 000879 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40 000880 */ 000881 typedef INT16_TYPE LogEst; 000882 000883 /* 000884 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer 000885 */ 000886 #ifndef SQLITE_PTRSIZE 000887 # if defined(__SIZEOF_POINTER__) 000888 # define SQLITE_PTRSIZE __SIZEOF_POINTER__ 000889 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ 000890 defined(_M_ARM) || defined(__arm__) || defined(__x86) || \ 000891 (defined(__APPLE__) && defined(__ppc__)) || \ 000892 (defined(__TOS_AIX__) && !defined(__64BIT__)) 000893 # define SQLITE_PTRSIZE 4 000894 # else 000895 # define SQLITE_PTRSIZE 8 000896 # endif 000897 #endif 000898 000899 /* The uptr type is an unsigned integer large enough to hold a pointer 000900 */ 000901 #if defined(HAVE_STDINT_H) 000902 typedef uintptr_t uptr; 000903 #elif SQLITE_PTRSIZE==4 000904 typedef u32 uptr; 000905 #else 000906 typedef u64 uptr; 000907 #endif 000908 000909 /* 000910 ** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to 000911 ** something between S (inclusive) and E (exclusive). 000912 ** 000913 ** In other words, S is a buffer and E is a pointer to the first byte after 000914 ** the end of buffer S. This macro returns true if P points to something 000915 ** contained within the buffer S. 000916 */ 000917 #define SQLITE_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E))) 000918 000919 /* 000920 ** P is one byte past the end of a large buffer. Return true if a span of bytes 000921 ** between S..E crosses the end of that buffer. In other words, return true 000922 ** if the sub-buffer S..E-1 overflows the buffer whose last byte is P-1. 000923 ** 000924 ** S is the start of the span. E is one byte past the end of end of span. 000925 ** 000926 ** P 000927 ** |-----------------| FALSE 000928 ** |-------| 000929 ** S E 000930 ** 000931 ** P 000932 ** |-----------------| 000933 ** |-------| TRUE 000934 ** S E 000935 ** 000936 ** P 000937 ** |-----------------| 000938 ** |-------| FALSE 000939 ** S E 000940 */ 000941 #define SQLITE_OVERFLOW(P,S,E) (((uptr)(S)<(uptr)(P))&&((uptr)(E)>(uptr)(P))) 000942 000943 /* 000944 ** Macros to determine whether the machine is big or little endian, 000945 ** and whether or not that determination is run-time or compile-time. 000946 ** 000947 ** For best performance, an attempt is made to guess at the byte-order 000948 ** using C-preprocessor macros. If that is unsuccessful, or if 000949 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined 000950 ** at run-time. 000951 ** 000952 ** If you are building SQLite on some obscure platform for which the 000953 ** following ifdef magic does not work, you can always include either: 000954 ** 000955 ** -DSQLITE_BYTEORDER=1234 000956 ** 000957 ** or 000958 ** 000959 ** -DSQLITE_BYTEORDER=4321 000960 ** 000961 ** to cause the build to work for little-endian or big-endian processors, 000962 ** respectively. 000963 */ 000964 #ifndef SQLITE_BYTEORDER /* Replicate changes at tag-20230904a */ 000965 # if defined(__BYTE_ORDER__) && __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ 000966 # define SQLITE_BYTEORDER 4321 000967 # elif defined(__BYTE_ORDER__) && __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ 000968 # define SQLITE_BYTEORDER 1234 000969 # elif defined(__BIG_ENDIAN__) && __BIG_ENDIAN__==1 000970 # define SQLITE_BYTEORDER 4321 000971 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ 000972 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ 000973 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ 000974 defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64) 000975 # define SQLITE_BYTEORDER 1234 000976 # elif defined(sparc) || defined(__ARMEB__) || defined(__AARCH64EB__) 000977 # define SQLITE_BYTEORDER 4321 000978 # else 000979 # define SQLITE_BYTEORDER 0 000980 # endif 000981 #endif 000982 #if SQLITE_BYTEORDER==4321 000983 # define SQLITE_BIGENDIAN 1 000984 # define SQLITE_LITTLEENDIAN 0 000985 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE 000986 #elif SQLITE_BYTEORDER==1234 000987 # define SQLITE_BIGENDIAN 0 000988 # define SQLITE_LITTLEENDIAN 1 000989 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE 000990 #else 000991 # ifdef SQLITE_AMALGAMATION 000992 const int sqlite3one = 1; 000993 # else 000994 extern const int sqlite3one; 000995 # endif 000996 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) 000997 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) 000998 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) 000999 #endif 001000 001001 /* 001002 ** Constants for the largest and smallest possible 64-bit signed integers. 001003 ** These macros are designed to work correctly on both 32-bit and 64-bit 001004 ** compilers. 001005 */ 001006 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) 001007 #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32)) 001008 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) 001009 001010 /* 001011 ** Round up a number to the next larger multiple of 8. This is used 001012 ** to force 8-byte alignment on 64-bit architectures. 001013 ** 001014 ** ROUND8() always does the rounding, for any argument. 001015 ** 001016 ** ROUND8P() assumes that the argument is already an integer number of 001017 ** pointers in size, and so it is a no-op on systems where the pointer 001018 ** size is 8. 001019 */ 001020 #define ROUND8(x) (((x)+7)&~7) 001021 #if SQLITE_PTRSIZE==8 001022 # define ROUND8P(x) (x) 001023 #else 001024 # define ROUND8P(x) (((x)+7)&~7) 001025 #endif 001026 001027 /* 001028 ** Round down to the nearest multiple of 8 001029 */ 001030 #define ROUNDDOWN8(x) ((x)&~7) 001031 001032 /* 001033 ** Assert that the pointer X is aligned to an 8-byte boundary. This 001034 ** macro is used only within assert() to verify that the code gets 001035 ** all alignment restrictions correct. 001036 ** 001037 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the 001038 ** underlying malloc() implementation might return us 4-byte aligned 001039 ** pointers. In that case, only verify 4-byte alignment. 001040 */ 001041 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC 001042 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0) 001043 #else 001044 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0) 001045 #endif 001046 001047 /* 001048 ** Disable MMAP on platforms where it is known to not work 001049 */ 001050 #if defined(__OpenBSD__) || defined(__QNXNTO__) 001051 # undef SQLITE_MAX_MMAP_SIZE 001052 # define SQLITE_MAX_MMAP_SIZE 0 001053 #endif 001054 001055 /* 001056 ** Default maximum size of memory used by memory-mapped I/O in the VFS 001057 */ 001058 #ifdef __APPLE__ 001059 # include <TargetConditionals.h> 001060 #endif 001061 #ifndef SQLITE_MAX_MMAP_SIZE 001062 # if defined(__linux__) \ 001063 || defined(_WIN32) \ 001064 || (defined(__APPLE__) && defined(__MACH__)) \ 001065 || defined(__sun) \ 001066 || defined(__FreeBSD__) \ 001067 || defined(__DragonFly__) 001068 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */ 001069 # else 001070 # define SQLITE_MAX_MMAP_SIZE 0 001071 # endif 001072 #endif 001073 001074 /* 001075 ** The default MMAP_SIZE is zero on all platforms. Or, even if a larger 001076 ** default MMAP_SIZE is specified at compile-time, make sure that it does 001077 ** not exceed the maximum mmap size. 001078 */ 001079 #ifndef SQLITE_DEFAULT_MMAP_SIZE 001080 # define SQLITE_DEFAULT_MMAP_SIZE 0 001081 #endif 001082 #if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE 001083 # undef SQLITE_DEFAULT_MMAP_SIZE 001084 # define SQLITE_DEFAULT_MMAP_SIZE SQLITE_MAX_MMAP_SIZE 001085 #endif 001086 001087 /* 001088 ** TREETRACE_ENABLED will be either 1 or 0 depending on whether or not 001089 ** the Abstract Syntax Tree tracing logic is turned on. 001090 */ 001091 #if !defined(SQLITE_AMALGAMATION) 001092 extern u32 sqlite3TreeTrace; 001093 #endif 001094 #if defined(SQLITE_DEBUG) \ 001095 && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE) \ 001096 || defined(SQLITE_ENABLE_TREETRACE)) 001097 # define TREETRACE_ENABLED 1 001098 # define TREETRACE(K,P,S,X) \ 001099 if(sqlite3TreeTrace&(K)) \ 001100 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ 001101 sqlite3DebugPrintf X 001102 #else 001103 # define TREETRACE(K,P,S,X) 001104 # define TREETRACE_ENABLED 0 001105 #endif 001106 001107 /* TREETRACE flag meanings: 001108 ** 001109 ** 0x00000001 Beginning and end of SELECT processing 001110 ** 0x00000002 WHERE clause processing 001111 ** 0x00000004 Query flattener 001112 ** 0x00000008 Result-set wildcard expansion 001113 ** 0x00000010 Query name resolution 001114 ** 0x00000020 Aggregate analysis 001115 ** 0x00000040 Window functions 001116 ** 0x00000080 Generated column names 001117 ** 0x00000100 Move HAVING terms into WHERE 001118 ** 0x00000200 Count-of-view optimization 001119 ** 0x00000400 Compound SELECT processing 001120 ** 0x00000800 Drop superfluous ORDER BY 001121 ** 0x00001000 LEFT JOIN simplifies to JOIN 001122 ** 0x00002000 Constant propagation 001123 ** 0x00004000 Push-down optimization 001124 ** 0x00008000 After all FROM-clause analysis 001125 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing 001126 ** 0x00020000 Transform DISTINCT into GROUP BY 001127 ** 0x00040000 SELECT tree dump after all code has been generated 001128 ** 0x00080000 NOT NULL strength reduction 001129 */ 001130 001131 /* 001132 ** Macros for "wheretrace" 001133 */ 001134 extern u32 sqlite3WhereTrace; 001135 #if defined(SQLITE_DEBUG) \ 001136 && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_WHERETRACE)) 001137 # define WHERETRACE(K,X) if(sqlite3WhereTrace&(K)) sqlite3DebugPrintf X 001138 # define WHERETRACE_ENABLED 1 001139 #else 001140 # define WHERETRACE(K,X) 001141 #endif 001142 001143 /* 001144 ** Bits for the sqlite3WhereTrace mask: 001145 ** 001146 ** (---any--) Top-level block structure 001147 ** 0x-------F High-level debug messages 001148 ** 0x----FFF- More detail 001149 ** 0xFFFF---- Low-level debug messages 001150 ** 001151 ** 0x00000001 Code generation 001152 ** 0x00000002 Solver 001153 ** 0x00000004 Solver costs 001154 ** 0x00000008 WhereLoop inserts 001155 ** 001156 ** 0x00000010 Display sqlite3_index_info xBestIndex calls 001157 ** 0x00000020 Range an equality scan metrics 001158 ** 0x00000040 IN operator decisions 001159 ** 0x00000080 WhereLoop cost adjustments 001160 ** 0x00000100 001161 ** 0x00000200 Covering index decisions 001162 ** 0x00000400 OR optimization 001163 ** 0x00000800 Index scanner 001164 ** 0x00001000 More details associated with code generation 001165 ** 0x00002000 001166 ** 0x00004000 Show all WHERE terms at key points 001167 ** 0x00008000 Show the full SELECT statement at key places 001168 ** 001169 ** 0x00010000 Show more detail when printing WHERE terms 001170 ** 0x00020000 Show WHERE terms returned from whereScanNext() 001171 */ 001172 001173 001174 /* 001175 ** An instance of the following structure is used to store the busy-handler 001176 ** callback for a given sqlite handle. 001177 ** 001178 ** The sqlite.busyHandler member of the sqlite struct contains the busy 001179 ** callback for the database handle. Each pager opened via the sqlite 001180 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler 001181 ** callback is currently invoked only from within pager.c. 001182 */ 001183 typedef struct BusyHandler BusyHandler; 001184 struct BusyHandler { 001185 int (*xBusyHandler)(void *,int); /* The busy callback */ 001186 void *pBusyArg; /* First arg to busy callback */ 001187 int nBusy; /* Incremented with each busy call */ 001188 }; 001189 001190 /* 001191 ** Name of table that holds the database schema. 001192 ** 001193 ** The PREFERRED names are used wherever possible. But LEGACY is also 001194 ** used for backwards compatibility. 001195 ** 001196 ** 1. Queries can use either the PREFERRED or the LEGACY names 001197 ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name 001198 ** 3. The PRAGMA table_list statement uses the PREFERRED name 001199 ** 001200 ** The LEGACY names are stored in the internal symbol hash table 001201 ** in support of (2). Names are translated using sqlite3PreferredTableName() 001202 ** for (3). The sqlite3FindTable() function takes care of translating 001203 ** names for (1). 001204 ** 001205 ** Note that "sqlite_temp_schema" can also be called "temp.sqlite_schema". 001206 */ 001207 #define LEGACY_SCHEMA_TABLE "sqlite_master" 001208 #define LEGACY_TEMP_SCHEMA_TABLE "sqlite_temp_master" 001209 #define PREFERRED_SCHEMA_TABLE "sqlite_schema" 001210 #define PREFERRED_TEMP_SCHEMA_TABLE "sqlite_temp_schema" 001211 001212 001213 /* 001214 ** The root-page of the schema table. 001215 */ 001216 #define SCHEMA_ROOT 1 001217 001218 /* 001219 ** The name of the schema table. The name is different for TEMP. 001220 */ 001221 #define SCHEMA_TABLE(x) \ 001222 ((!OMIT_TEMPDB)&&(x==1)?LEGACY_TEMP_SCHEMA_TABLE:LEGACY_SCHEMA_TABLE) 001223 001224 /* 001225 ** A convenience macro that returns the number of elements in 001226 ** an array. 001227 */ 001228 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0]))) 001229 001230 /* 001231 ** Determine if the argument is a power of two 001232 */ 001233 #define IsPowerOfTwo(X) (((X)&((X)-1))==0) 001234 001235 /* 001236 ** The following value as a destructor means to use sqlite3DbFree(). 001237 ** The sqlite3DbFree() routine requires two parameters instead of the 001238 ** one parameter that destructors normally want. So we have to introduce 001239 ** this magic value that the code knows to handle differently. Any 001240 ** pointer will work here as long as it is distinct from SQLITE_STATIC 001241 ** and SQLITE_TRANSIENT. 001242 */ 001243 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear) 001244 001245 /* 001246 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does 001247 ** not support Writable Static Data (WSD) such as global and static variables. 001248 ** All variables must either be on the stack or dynamically allocated from 001249 ** the heap. When WSD is unsupported, the variable declarations scattered 001250 ** throughout the SQLite code must become constants instead. The SQLITE_WSD 001251 ** macro is used for this purpose. And instead of referencing the variable 001252 ** directly, we use its constant as a key to lookup the run-time allocated 001253 ** buffer that holds real variable. The constant is also the initializer 001254 ** for the run-time allocated buffer. 001255 ** 001256 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL 001257 ** macros become no-ops and have zero performance impact. 001258 */ 001259 #ifdef SQLITE_OMIT_WSD 001260 #define SQLITE_WSD const 001261 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) 001262 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) 001263 int sqlite3_wsd_init(int N, int J); 001264 void *sqlite3_wsd_find(void *K, int L); 001265 #else 001266 #define SQLITE_WSD 001267 #define GLOBAL(t,v) v 001268 #define sqlite3GlobalConfig sqlite3Config 001269 #endif 001270 001271 /* 001272 ** The following macros are used to suppress compiler warnings and to 001273 ** make it clear to human readers when a function parameter is deliberately 001274 ** left unused within the body of a function. This usually happens when 001275 ** a function is called via a function pointer. For example the 001276 ** implementation of an SQL aggregate step callback may not use the 001277 ** parameter indicating the number of arguments passed to the aggregate, 001278 ** if it knows that this is enforced elsewhere. 001279 ** 001280 ** When a function parameter is not used at all within the body of a function, 001281 ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer. 001282 ** However, these macros may also be used to suppress warnings related to 001283 ** parameters that may or may not be used depending on compilation options. 001284 ** For example those parameters only used in assert() statements. In these 001285 ** cases the parameters are named as per the usual conventions. 001286 */ 001287 #define UNUSED_PARAMETER(x) (void)(x) 001288 #define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y) 001289 001290 /* 001291 ** Forward references to structures 001292 */ 001293 typedef struct AggInfo AggInfo; 001294 typedef struct AuthContext AuthContext; 001295 typedef struct AutoincInfo AutoincInfo; 001296 typedef struct Bitvec Bitvec; 001297 typedef struct CollSeq CollSeq; 001298 typedef struct Column Column; 001299 typedef struct Cte Cte; 001300 typedef struct CteUse CteUse; 001301 typedef struct Db Db; 001302 typedef struct DbClientData DbClientData; 001303 typedef struct DbFixer DbFixer; 001304 typedef struct Schema Schema; 001305 typedef struct Expr Expr; 001306 typedef struct ExprList ExprList; 001307 typedef struct FKey FKey; 001308 typedef struct FpDecode FpDecode; 001309 typedef struct FuncDestructor FuncDestructor; 001310 typedef struct FuncDef FuncDef; 001311 typedef struct FuncDefHash FuncDefHash; 001312 typedef struct IdList IdList; 001313 typedef struct Index Index; 001314 typedef struct IndexedExpr IndexedExpr; 001315 typedef struct IndexSample IndexSample; 001316 typedef struct KeyClass KeyClass; 001317 typedef struct KeyInfo KeyInfo; 001318 typedef struct Lookaside Lookaside; 001319 typedef struct LookasideSlot LookasideSlot; 001320 typedef struct Module Module; 001321 typedef struct NameContext NameContext; 001322 typedef struct OnOrUsing OnOrUsing; 001323 typedef struct Parse Parse; 001324 typedef struct ParseCleanup ParseCleanup; 001325 typedef struct PreUpdate PreUpdate; 001326 typedef struct PrintfArguments PrintfArguments; 001327 typedef struct RCStr RCStr; 001328 typedef struct RenameToken RenameToken; 001329 typedef struct Returning Returning; 001330 typedef struct RowSet RowSet; 001331 typedef struct Savepoint Savepoint; 001332 typedef struct Select Select; 001333 typedef struct SQLiteThread SQLiteThread; 001334 typedef struct SelectDest SelectDest; 001335 typedef struct SrcItem SrcItem; 001336 typedef struct SrcList SrcList; 001337 typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */ 001338 typedef struct Table Table; 001339 typedef struct TableLock TableLock; 001340 typedef struct Token Token; 001341 typedef struct TreeView TreeView; 001342 typedef struct Trigger Trigger; 001343 typedef struct TriggerPrg TriggerPrg; 001344 typedef struct TriggerStep TriggerStep; 001345 typedef struct UnpackedRecord UnpackedRecord; 001346 typedef struct Upsert Upsert; 001347 typedef struct VTable VTable; 001348 typedef struct VtabCtx VtabCtx; 001349 typedef struct Walker Walker; 001350 typedef struct WhereInfo WhereInfo; 001351 typedef struct Window Window; 001352 typedef struct With With; 001353 001354 001355 /* 001356 ** The bitmask datatype defined below is used for various optimizations. 001357 ** 001358 ** Changing this from a 64-bit to a 32-bit type limits the number of 001359 ** tables in a join to 32 instead of 64. But it also reduces the size 001360 ** of the library by 738 bytes on ix86. 001361 */ 001362 #ifdef SQLITE_BITMASK_TYPE 001363 typedef SQLITE_BITMASK_TYPE Bitmask; 001364 #else 001365 typedef u64 Bitmask; 001366 #endif 001367 001368 /* 001369 ** The number of bits in a Bitmask. "BMS" means "BitMask Size". 001370 */ 001371 #define BMS ((int)(sizeof(Bitmask)*8)) 001372 001373 /* 001374 ** A bit in a Bitmask 001375 */ 001376 #define MASKBIT(n) (((Bitmask)1)<<(n)) 001377 #define MASKBIT64(n) (((u64)1)<<(n)) 001378 #define MASKBIT32(n) (((unsigned int)1)<<(n)) 001379 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0) 001380 #define ALLBITS ((Bitmask)-1) 001381 #define TOPBIT (((Bitmask)1)<<(BMS-1)) 001382 001383 /* A VList object records a mapping between parameters/variables/wildcards 001384 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer 001385 ** variable number associated with that parameter. See the format description 001386 ** on the sqlite3VListAdd() routine for more information. A VList is really 001387 ** just an array of integers. 001388 */ 001389 typedef int VList; 001390 001391 /* 001392 ** Defer sourcing vdbe.h and btree.h until after the "u8" and 001393 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque 001394 ** pointer types (i.e. FuncDef) defined above. 001395 */ 001396 #include "os.h" 001397 #include "pager.h" 001398 #include "btree.h" 001399 #include "vdbe.h" 001400 #include "pcache.h" 001401 #include "mutex.h" 001402 001403 /* The SQLITE_EXTRA_DURABLE compile-time option used to set the default 001404 ** synchronous setting to EXTRA. It is no longer supported. 001405 */ 001406 #ifdef SQLITE_EXTRA_DURABLE 001407 # warning Use SQLITE_DEFAULT_SYNCHRONOUS=3 instead of SQLITE_EXTRA_DURABLE 001408 # define SQLITE_DEFAULT_SYNCHRONOUS 3 001409 #endif 001410 001411 /* 001412 ** Default synchronous levels. 001413 ** 001414 ** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ 001415 ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. 001416 ** 001417 ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS 001418 ** OFF 1 0 001419 ** NORMAL 2 1 001420 ** FULL 3 2 001421 ** EXTRA 4 3 001422 ** 001423 ** The "PRAGMA synchronous" statement also uses the zero-based numbers. 001424 ** In other words, the zero-based numbers are used for all external interfaces 001425 ** and the one-based values are used internally. 001426 */ 001427 #ifndef SQLITE_DEFAULT_SYNCHRONOUS 001428 # define SQLITE_DEFAULT_SYNCHRONOUS 2 001429 #endif 001430 #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS 001431 # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS 001432 #endif 001433 001434 /* 001435 ** Each database file to be accessed by the system is an instance 001436 ** of the following structure. There are normally two of these structures 001437 ** in the sqlite.aDb[] array. aDb[0] is the main database file and 001438 ** aDb[1] is the database file used to hold temporary tables. Additional 001439 ** databases may be attached. 001440 */ 001441 struct Db { 001442 char *zDbSName; /* Name of this database. (schema name, not filename) */ 001443 Btree *pBt; /* The B*Tree structure for this database file */ 001444 u8 safety_level; /* How aggressive at syncing data to disk */ 001445 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */ 001446 Schema *pSchema; /* Pointer to database schema (possibly shared) */ 001447 }; 001448 001449 /* 001450 ** An instance of the following structure stores a database schema. 001451 ** 001452 ** Most Schema objects are associated with a Btree. The exception is 001453 ** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing. 001454 ** In shared cache mode, a single Schema object can be shared by multiple 001455 ** Btrees that refer to the same underlying BtShared object. 001456 ** 001457 ** Schema objects are automatically deallocated when the last Btree that 001458 ** references them is destroyed. The TEMP Schema is manually freed by 001459 ** sqlite3_close(). 001460 * 001461 ** A thread must be holding a mutex on the corresponding Btree in order 001462 ** to access Schema content. This implies that the thread must also be 001463 ** holding a mutex on the sqlite3 connection pointer that owns the Btree. 001464 ** For a TEMP Schema, only the connection mutex is required. 001465 */ 001466 struct Schema { 001467 int schema_cookie; /* Database schema version number for this file */ 001468 int iGeneration; /* Generation counter. Incremented with each change */ 001469 Hash tblHash; /* All tables indexed by name */ 001470 Hash idxHash; /* All (named) indices indexed by name */ 001471 Hash trigHash; /* All triggers indexed by name */ 001472 Hash fkeyHash; /* All foreign keys by referenced table name */ 001473 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ 001474 u8 file_format; /* Schema format version for this file */ 001475 u8 enc; /* Text encoding used by this database */ 001476 u16 schemaFlags; /* Flags associated with this schema */ 001477 int cache_size; /* Number of pages to use in the cache */ 001478 }; 001479 001480 /* 001481 ** These macros can be used to test, set, or clear bits in the 001482 ** Db.pSchema->flags field. 001483 */ 001484 #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))==(P)) 001485 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0) 001486 #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags|=(P) 001487 #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags&=~(P) 001488 001489 /* 001490 ** Allowed values for the DB.pSchema->flags field. 001491 ** 001492 ** The DB_SchemaLoaded flag is set after the database schema has been 001493 ** read into internal hash tables. 001494 ** 001495 ** DB_UnresetViews means that one or more views have column names that 001496 ** have been filled out. If the schema changes, these column names might 001497 ** changes and so the view will need to be reset. 001498 */ 001499 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ 001500 #define DB_UnresetViews 0x0002 /* Some views have defined column names */ 001501 #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */ 001502 001503 /* 001504 ** The number of different kinds of things that can be limited 001505 ** using the sqlite3_limit() interface. 001506 */ 001507 #define SQLITE_N_LIMIT (SQLITE_LIMIT_WORKER_THREADS+1) 001508 001509 /* 001510 ** Lookaside malloc is a set of fixed-size buffers that can be used 001511 ** to satisfy small transient memory allocation requests for objects 001512 ** associated with a particular database connection. The use of 001513 ** lookaside malloc provides a significant performance enhancement 001514 ** (approx 10%) by avoiding numerous malloc/free requests while parsing 001515 ** SQL statements. 001516 ** 001517 ** The Lookaside structure holds configuration information about the 001518 ** lookaside malloc subsystem. Each available memory allocation in 001519 ** the lookaside subsystem is stored on a linked list of LookasideSlot 001520 ** objects. 001521 ** 001522 ** Lookaside allocations are only allowed for objects that are associated 001523 ** with a particular database connection. Hence, schema information cannot 001524 ** be stored in lookaside because in shared cache mode the schema information 001525 ** is shared by multiple database connections. Therefore, while parsing 001526 ** schema information, the Lookaside.bEnabled flag is cleared so that 001527 ** lookaside allocations are not used to construct the schema objects. 001528 ** 001529 ** New lookaside allocations are only allowed if bDisable==0. When 001530 ** bDisable is greater than zero, sz is set to zero which effectively 001531 ** disables lookaside without adding a new test for the bDisable flag 001532 ** in a performance-critical path. sz should be set by to szTrue whenever 001533 ** bDisable changes back to zero. 001534 ** 001535 ** Lookaside buffers are initially held on the pInit list. As they are 001536 ** used and freed, they are added back to the pFree list. New allocations 001537 ** come off of pFree first, then pInit as a fallback. This dual-list 001538 ** allows use to compute a high-water mark - the maximum number of allocations 001539 ** outstanding at any point in the past - by subtracting the number of 001540 ** allocations on the pInit list from the total number of allocations. 001541 ** 001542 ** Enhancement on 2019-12-12: Two-size-lookaside 001543 ** The default lookaside configuration is 100 slots of 1200 bytes each. 001544 ** The larger slot sizes are important for performance, but they waste 001545 ** a lot of space, as most lookaside allocations are less than 128 bytes. 001546 ** The two-size-lookaside enhancement breaks up the lookaside allocation 001547 ** into two pools: One of 128-byte slots and the other of the default size 001548 ** (1200-byte) slots. Allocations are filled from the small-pool first, 001549 ** failing over to the full-size pool if that does not work. Thus more 001550 ** lookaside slots are available while also using less memory. 001551 ** This enhancement can be omitted by compiling with 001552 ** SQLITE_OMIT_TWOSIZE_LOOKASIDE. 001553 */ 001554 struct Lookaside { 001555 u32 bDisable; /* Only operate the lookaside when zero */ 001556 u16 sz; /* Size of each buffer in bytes */ 001557 u16 szTrue; /* True value of sz, even if disabled */ 001558 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ 001559 u32 nSlot; /* Number of lookaside slots allocated */ 001560 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ 001561 LookasideSlot *pInit; /* List of buffers not previously used */ 001562 LookasideSlot *pFree; /* List of available buffers */ 001563 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE 001564 LookasideSlot *pSmallInit; /* List of small buffers not previously used */ 001565 LookasideSlot *pSmallFree; /* List of available small buffers */ 001566 void *pMiddle; /* First byte past end of full-size buffers and 001567 ** the first byte of LOOKASIDE_SMALL buffers */ 001568 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ 001569 void *pStart; /* First byte of available memory space */ 001570 void *pEnd; /* First byte past end of available space */ 001571 void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */ 001572 }; 001573 struct LookasideSlot { 001574 LookasideSlot *pNext; /* Next buffer in the list of free buffers */ 001575 }; 001576 001577 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0 001578 #define EnableLookaside db->lookaside.bDisable--;\ 001579 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue 001580 001581 /* Size of the smaller allocations in two-size lookaside */ 001582 #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE 001583 # define LOOKASIDE_SMALL 0 001584 #else 001585 # define LOOKASIDE_SMALL 128 001586 #endif 001587 001588 /* 001589 ** A hash table for built-in function definitions. (Application-defined 001590 ** functions use a regular table table from hash.h.) 001591 ** 001592 ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots. 001593 ** Collisions are on the FuncDef.u.pHash chain. Use the SQLITE_FUNC_HASH() 001594 ** macro to compute a hash on the function name. 001595 */ 001596 #define SQLITE_FUNC_HASH_SZ 23 001597 struct FuncDefHash { 001598 FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */ 001599 }; 001600 #define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ) 001601 001602 #if defined(SQLITE_USER_AUTHENTICATION) 001603 # warning "The SQLITE_USER_AUTHENTICATION extension is deprecated. \ 001604 See ext/userauth/user-auth.txt for details." 001605 #endif 001606 #ifdef SQLITE_USER_AUTHENTICATION 001607 /* 001608 ** Information held in the "sqlite3" database connection object and used 001609 ** to manage user authentication. 001610 */ 001611 typedef struct sqlite3_userauth sqlite3_userauth; 001612 struct sqlite3_userauth { 001613 u8 authLevel; /* Current authentication level */ 001614 int nAuthPW; /* Size of the zAuthPW in bytes */ 001615 char *zAuthPW; /* Password used to authenticate */ 001616 char *zAuthUser; /* User name used to authenticate */ 001617 }; 001618 001619 /* Allowed values for sqlite3_userauth.authLevel */ 001620 #define UAUTH_Unknown 0 /* Authentication not yet checked */ 001621 #define UAUTH_Fail 1 /* User authentication failed */ 001622 #define UAUTH_User 2 /* Authenticated as a normal user */ 001623 #define UAUTH_Admin 3 /* Authenticated as an administrator */ 001624 001625 /* Functions used only by user authorization logic */ 001626 int sqlite3UserAuthTable(const char*); 001627 int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*); 001628 void sqlite3UserAuthInit(sqlite3*); 001629 void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**); 001630 001631 #endif /* SQLITE_USER_AUTHENTICATION */ 001632 001633 /* 001634 ** typedef for the authorization callback function. 001635 */ 001636 #ifdef SQLITE_USER_AUTHENTICATION 001637 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, 001638 const char*, const char*); 001639 #else 001640 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, 001641 const char*); 001642 #endif 001643 001644 #ifndef SQLITE_OMIT_DEPRECATED 001645 /* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing 001646 ** in the style of sqlite3_trace() 001647 */ 001648 #define SQLITE_TRACE_LEGACY 0x40 /* Use the legacy xTrace */ 001649 #define SQLITE_TRACE_XPROFILE 0x80 /* Use the legacy xProfile */ 001650 #else 001651 #define SQLITE_TRACE_LEGACY 0 001652 #define SQLITE_TRACE_XPROFILE 0 001653 #endif /* SQLITE_OMIT_DEPRECATED */ 001654 #define SQLITE_TRACE_NONLEGACY_MASK 0x0f /* Normal flags */ 001655 001656 /* 001657 ** Maximum number of sqlite3.aDb[] entries. This is the number of attached 001658 ** databases plus 2 for "main" and "temp". 001659 */ 001660 #define SQLITE_MAX_DB (SQLITE_MAX_ATTACHED+2) 001661 001662 /* 001663 ** Each database connection is an instance of the following structure. 001664 */ 001665 struct sqlite3 { 001666 sqlite3_vfs *pVfs; /* OS Interface */ 001667 struct Vdbe *pVdbe; /* List of active virtual machines */ 001668 CollSeq *pDfltColl; /* BINARY collseq for the database encoding */ 001669 sqlite3_mutex *mutex; /* Connection mutex */ 001670 Db *aDb; /* All backends */ 001671 int nDb; /* Number of backends currently in use */ 001672 u32 mDbFlags; /* flags recording internal state */ 001673 u64 flags; /* flags settable by pragmas. See below */ 001674 i64 lastRowid; /* ROWID of most recent insert (see above) */ 001675 i64 szMmap; /* Default mmap_size setting */ 001676 u32 nSchemaLock; /* Do not reset the schema when non-zero */ 001677 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ 001678 int errCode; /* Most recent error code (SQLITE_*) */ 001679 int errByteOffset; /* Byte offset of error in SQL statement */ 001680 int errMask; /* & result codes with this before returning */ 001681 int iSysErrno; /* Errno value from last system error */ 001682 u32 dbOptFlags; /* Flags to enable/disable optimizations */ 001683 u8 enc; /* Text encoding */ 001684 u8 autoCommit; /* The auto-commit flag. */ 001685 u8 temp_store; /* 1: file 2: memory 0: default */ 001686 u8 mallocFailed; /* True if we have seen a malloc failure */ 001687 u8 bBenignMalloc; /* Do not require OOMs if true */ 001688 u8 dfltLockMode; /* Default locking-mode for attached dbs */ 001689 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ 001690 u8 suppressErr; /* Do not issue error messages if true */ 001691 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ 001692 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ 001693 u8 mTrace; /* zero or more SQLITE_TRACE flags */ 001694 u8 noSharedCache; /* True if no shared-cache backends */ 001695 u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */ 001696 u8 eOpenState; /* Current condition of the connection */ 001697 int nextPagesize; /* Pagesize after VACUUM if >0 */ 001698 i64 nChange; /* Value returned by sqlite3_changes() */ 001699 i64 nTotalChange; /* Value returned by sqlite3_total_changes() */ 001700 int aLimit[SQLITE_N_LIMIT]; /* Limits */ 001701 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ 001702 struct sqlite3InitInfo { /* Information used during initialization */ 001703 Pgno newTnum; /* Rootpage of table being initialized */ 001704 u8 iDb; /* Which db file is being initialized */ 001705 u8 busy; /* TRUE if currently initializing */ 001706 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ 001707 unsigned imposterTable : 1; /* Building an imposter table */ 001708 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ 001709 const char **azInit; /* "type", "name", and "tbl_name" columns */ 001710 } init; 001711 int nVdbeActive; /* Number of VDBEs currently running */ 001712 int nVdbeRead; /* Number of active VDBEs that read or write */ 001713 int nVdbeWrite; /* Number of active VDBEs that read and write */ 001714 int nVdbeExec; /* Number of nested calls to VdbeExec() */ 001715 int nVDestroy; /* Number of active OP_VDestroy operations */ 001716 int nExtension; /* Number of loaded extensions */ 001717 void **aExtension; /* Array of shared library handles */ 001718 union { 001719 void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */ 001720 int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */ 001721 } trace; 001722 void *pTraceArg; /* Argument to the trace function */ 001723 #ifndef SQLITE_OMIT_DEPRECATED 001724 void (*xProfile)(void*,const char*,u64); /* Profiling function */ 001725 void *pProfileArg; /* Argument to profile function */ 001726 #endif 001727 void *pCommitArg; /* Argument to xCommitCallback() */ 001728 int (*xCommitCallback)(void*); /* Invoked at every commit. */ 001729 void *pRollbackArg; /* Argument to xRollbackCallback() */ 001730 void (*xRollbackCallback)(void*); /* Invoked at every commit. */ 001731 void *pUpdateArg; 001732 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); 001733 void *pAutovacPagesArg; /* Client argument to autovac_pages */ 001734 void (*xAutovacDestr)(void*); /* Destructor for pAutovacPAgesArg */ 001735 unsigned int (*xAutovacPages)(void*,const char*,u32,u32,u32); 001736 Parse *pParse; /* Current parse */ 001737 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK 001738 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */ 001739 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */ 001740 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64 001741 ); 001742 PreUpdate *pPreUpdate; /* Context for active pre-update callback */ 001743 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ 001744 #ifndef SQLITE_OMIT_WAL 001745 int (*xWalCallback)(void *, sqlite3 *, const char *, int); 001746 void *pWalArg; 001747 #endif 001748 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); 001749 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); 001750 void *pCollNeededArg; 001751 sqlite3_value *pErr; /* Most recent error message */ 001752 union { 001753 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ 001754 double notUsed1; /* Spacer */ 001755 } u1; 001756 Lookaside lookaside; /* Lookaside malloc configuration */ 001757 #ifndef SQLITE_OMIT_AUTHORIZATION 001758 sqlite3_xauth xAuth; /* Access authorization function */ 001759 void *pAuthArg; /* 1st argument to the access auth function */ 001760 #endif 001761 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK 001762 int (*xProgress)(void *); /* The progress callback */ 001763 void *pProgressArg; /* Argument to the progress callback */ 001764 unsigned nProgressOps; /* Number of opcodes for progress callback */ 001765 #endif 001766 #ifndef SQLITE_OMIT_VIRTUALTABLE 001767 int nVTrans; /* Allocated size of aVTrans */ 001768 Hash aModule; /* populated by sqlite3_create_module() */ 001769 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ 001770 VTable **aVTrans; /* Virtual tables with open transactions */ 001771 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ 001772 #endif 001773 Hash aFunc; /* Hash table of connection functions */ 001774 Hash aCollSeq; /* All collating sequences */ 001775 BusyHandler busyHandler; /* Busy callback */ 001776 Db aDbStatic[2]; /* Static space for the 2 default backends */ 001777 Savepoint *pSavepoint; /* List of active savepoints */ 001778 int nAnalysisLimit; /* Number of index rows to ANALYZE */ 001779 int busyTimeout; /* Busy handler timeout, in msec */ 001780 int nSavepoint; /* Number of non-transaction savepoints */ 001781 int nStatement; /* Number of nested statement-transactions */ 001782 i64 nDeferredCons; /* Net deferred constraints this transaction. */ 001783 i64 nDeferredImmCons; /* Net deferred immediate constraints */ 001784 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ 001785 DbClientData *pDbData; /* sqlite3_set_clientdata() content */ 001786 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY 001787 /* The following variables are all protected by the STATIC_MAIN 001788 ** mutex, not by sqlite3.mutex. They are used by code in notify.c. 001789 ** 001790 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to 001791 ** unlock so that it can proceed. 001792 ** 001793 ** When X.pBlockingConnection==Y, that means that something that X tried 001794 ** tried to do recently failed with an SQLITE_LOCKED error due to locks 001795 ** held by Y. 001796 */ 001797 sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */ 001798 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */ 001799 void *pUnlockArg; /* Argument to xUnlockNotify */ 001800 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */ 001801 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */ 001802 #endif 001803 #ifdef SQLITE_USER_AUTHENTICATION 001804 sqlite3_userauth auth; /* User authentication information */ 001805 #endif 001806 }; 001807 001808 /* 001809 ** A macro to discover the encoding of a database. 001810 */ 001811 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) 001812 #define ENC(db) ((db)->enc) 001813 001814 /* 001815 ** A u64 constant where the lower 32 bits are all zeros. Only the 001816 ** upper 32 bits are included in the argument. Necessary because some 001817 ** C-compilers still do not accept LL integer literals. 001818 */ 001819 #define HI(X) ((u64)(X)<<32) 001820 001821 /* 001822 ** Possible values for the sqlite3.flags. 001823 ** 001824 ** Value constraints (enforced via assert()): 001825 ** SQLITE_FullFSync == PAGER_FULLFSYNC 001826 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC 001827 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL 001828 */ 001829 #define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */ 001830 #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */ 001831 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ 001832 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */ 001833 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */ 001834 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */ 001835 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ 001836 #define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and 001837 ** vtabs in the schema definition */ 001838 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ 001839 /* result set is empty */ 001840 #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */ 001841 #define SQLITE_StmtScanStatus 0x00000400 /* Enable stmt_scanstats() counters */ 001842 #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */ 001843 #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */ 001844 #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */ 001845 #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */ 001846 #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */ 001847 #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */ 001848 #define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */ 001849 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */ 001850 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */ 001851 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */ 001852 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */ 001853 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */ 001854 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/ 001855 #define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */ 001856 #define SQLITE_ResetDatabase 0x02000000 /* Reset the database */ 001857 #define SQLITE_LegacyAlter 0x04000000 /* Legacy ALTER TABLE behaviour */ 001858 #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/ 001859 #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */ 001860 #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/ 001861 #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/ 001862 #define SQLITE_EnableView 0x80000000 /* Enable the use of views */ 001863 #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */ 001864 /* DELETE, or UPDATE and return */ 001865 /* the count using a callback. */ 001866 #define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */ 001867 #define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */ 001868 #define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */ 001869 001870 /* Flags used only if debugging */ 001871 #ifdef SQLITE_DEBUG 001872 #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */ 001873 #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */ 001874 #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */ 001875 #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */ 001876 #define SQLITE_VdbeEQP HI(0x1000000) /* Debug EXPLAIN QUERY PLAN */ 001877 #define SQLITE_ParserTrace HI(0x2000000) /* PRAGMA parser_trace=ON */ 001878 #endif 001879 001880 /* 001881 ** Allowed values for sqlite3.mDbFlags 001882 */ 001883 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */ 001884 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */ 001885 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */ 001886 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */ 001887 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */ 001888 #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */ 001889 #define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */ 001890 001891 /* 001892 ** Bits of the sqlite3.dbOptFlags field that are used by the 001893 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to 001894 ** selectively disable various optimizations. 001895 */ 001896 #define SQLITE_QueryFlattener 0x00000001 /* Query flattening */ 001897 #define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */ 001898 #define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */ 001899 #define SQLITE_FactorOutConst 0x00000008 /* Constant factoring */ 001900 #define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */ 001901 #define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */ 001902 #define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */ 001903 #define SQLITE_Transitive 0x00000080 /* Transitive constraints */ 001904 #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */ 001905 #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */ 001906 #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */ 001907 #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */ 001908 /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */ 001909 #define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */ 001910 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ 001911 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ 001912 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ 001913 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ 001914 #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ 001915 #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */ 001916 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */ 001917 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */ 001918 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ 001919 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */ 001920 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */ 001921 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */ 001922 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */ 001923 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */ 001924 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */ 001925 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */ 001926 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */ 001927 #define SQLITE_AllOpts 0xffffffff /* All optimizations */ 001928 001929 /* 001930 ** Macros for testing whether or not optimizations are enabled or disabled. 001931 */ 001932 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) 001933 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) 001934 001935 /* 001936 ** Return true if it OK to factor constant expressions into the initialization 001937 ** code. The argument is a Parse object for the code generator. 001938 */ 001939 #define ConstFactorOk(P) ((P)->okConstFactor) 001940 001941 /* Possible values for the sqlite3.eOpenState field. 001942 ** The numbers are randomly selected such that a minimum of three bits must 001943 ** change to convert any number to another or to zero 001944 */ 001945 #define SQLITE_STATE_OPEN 0x76 /* Database is open */ 001946 #define SQLITE_STATE_CLOSED 0xce /* Database is closed */ 001947 #define SQLITE_STATE_SICK 0xba /* Error and awaiting close */ 001948 #define SQLITE_STATE_BUSY 0x6d /* Database currently in use */ 001949 #define SQLITE_STATE_ERROR 0xd5 /* An SQLITE_MISUSE error occurred */ 001950 #define SQLITE_STATE_ZOMBIE 0xa7 /* Close with last statement close */ 001951 001952 /* 001953 ** Each SQL function is defined by an instance of the following 001954 ** structure. For global built-in functions (ex: substr(), max(), count()) 001955 ** a pointer to this structure is held in the sqlite3BuiltinFunctions object. 001956 ** For per-connection application-defined functions, a pointer to this 001957 ** structure is held in the db->aHash hash table. 001958 ** 001959 ** The u.pHash field is used by the global built-ins. The u.pDestructor 001960 ** field is used by per-connection app-def functions. 001961 */ 001962 struct FuncDef { 001963 i8 nArg; /* Number of arguments. -1 means unlimited */ 001964 u32 funcFlags; /* Some combination of SQLITE_FUNC_* */ 001965 void *pUserData; /* User data parameter */ 001966 FuncDef *pNext; /* Next function with same name */ 001967 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */ 001968 void (*xFinalize)(sqlite3_context*); /* Agg finalizer */ 001969 void (*xValue)(sqlite3_context*); /* Current agg value */ 001970 void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */ 001971 const char *zName; /* SQL name of the function. */ 001972 union { 001973 FuncDef *pHash; /* Next with a different name but the same hash */ 001974 FuncDestructor *pDestructor; /* Reference counted destructor function */ 001975 } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */ 001976 }; 001977 001978 /* 001979 ** This structure encapsulates a user-function destructor callback (as 001980 ** configured using create_function_v2()) and a reference counter. When 001981 ** create_function_v2() is called to create a function with a destructor, 001982 ** a single object of this type is allocated. FuncDestructor.nRef is set to 001983 ** the number of FuncDef objects created (either 1 or 3, depending on whether 001984 ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor 001985 ** member of each of the new FuncDef objects is set to point to the allocated 001986 ** FuncDestructor. 001987 ** 001988 ** Thereafter, when one of the FuncDef objects is deleted, the reference 001989 ** count on this object is decremented. When it reaches 0, the destructor 001990 ** is invoked and the FuncDestructor structure freed. 001991 */ 001992 struct FuncDestructor { 001993 int nRef; 001994 void (*xDestroy)(void *); 001995 void *pUserData; 001996 }; 001997 001998 /* 001999 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF 002000 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And 002001 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There 002002 ** are assert() statements in the code to verify this. 002003 ** 002004 ** Value constraints (enforced via assert()): 002005 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg 002006 ** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd 002007 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG 002008 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG 002009 ** SQLITE_FUNC_BYTELEN == OPFLAG_BYTELENARG 002010 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API 002011 ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API 002012 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!! 002013 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API 002014 ** 002015 ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the 002016 ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is 002017 ** used internally and if set means that the function has side effects. 002018 ** SQLITE_INNOCUOUS is used by application code and means "not unsafe". 002019 ** See multiple instances of tag-20230109-1. 002020 */ 002021 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ 002022 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ 002023 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ 002024 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ 002025 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/ 002026 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */ 002027 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ 002028 #define SQLITE_FUNC_BYTELEN 0x00c0 /* Built-in octet_length() function */ 002029 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ 002030 /* 0x0200 -- available for reuse */ 002031 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ 002032 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ 002033 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ 002034 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a 002035 ** single query - might change over time */ 002036 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */ 002037 #define SQLITE_FUNC_RUNONLY 0x8000 /* Cannot be used by valueFromFunction */ 002038 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */ 002039 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ 002040 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ 002041 /* SQLITE_SUBTYPE 0x00100000 // Consumer of subtypes */ 002042 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ 002043 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ 002044 #define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */ 002045 /* SQLITE_RESULT_SUBTYPE 0x01000000 // Generator of subtypes */ 002046 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */ 002047 002048 /* Identifier numbers for each in-line function */ 002049 #define INLINEFUNC_coalesce 0 002050 #define INLINEFUNC_implies_nonnull_row 1 002051 #define INLINEFUNC_expr_implies_expr 2 002052 #define INLINEFUNC_expr_compare 3 002053 #define INLINEFUNC_affinity 4 002054 #define INLINEFUNC_iif 5 002055 #define INLINEFUNC_sqlite_offset 6 002056 #define INLINEFUNC_unlikely 99 /* Default case */ 002057 002058 /* 002059 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are 002060 ** used to create the initializers for the FuncDef structures. 002061 ** 002062 ** FUNCTION(zName, nArg, iArg, bNC, xFunc) 002063 ** Used to create a scalar function definition of a function zName 002064 ** implemented by C function xFunc that accepts nArg arguments. The 002065 ** value passed as iArg is cast to a (void*) and made available 002066 ** as the user-data (sqlite3_user_data()) for the function. If 002067 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. 002068 ** 002069 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc) 002070 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. 002071 ** 002072 ** SFUNCTION(zName, nArg, iArg, bNC, xFunc) 002073 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and 002074 ** adds the SQLITE_DIRECTONLY flag. 002075 ** 002076 ** INLINE_FUNC(zName, nArg, iFuncId, mFlags) 002077 ** zName is the name of a function that is implemented by in-line 002078 ** byte code rather than by the usual callbacks. The iFuncId 002079 ** parameter determines the function id. The mFlags parameter is 002080 ** optional SQLITE_FUNC_ flags for this function. 002081 ** 002082 ** TEST_FUNC(zName, nArg, iFuncId, mFlags) 002083 ** zName is the name of a test-only function implemented by in-line 002084 ** byte code rather than by the usual callbacks. The iFuncId 002085 ** parameter determines the function id. The mFlags parameter is 002086 ** optional SQLITE_FUNC_ flags for this function. 002087 ** 002088 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc) 002089 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and 002090 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions 002091 ** and functions like sqlite_version() that can change, but not during 002092 ** a single query. The iArg is ignored. The user-data is always set 002093 ** to a NULL pointer. The bNC parameter is not used. 002094 ** 002095 ** MFUNCTION(zName, nArg, xPtr, xFunc) 002096 ** For math-library functions. xPtr is an arbitrary pointer. 002097 ** 002098 ** PURE_DATE(zName, nArg, iArg, bNC, xFunc) 002099 ** Used for "pure" date/time functions, this macro is like DFUNCTION 002100 ** except that it does set the SQLITE_FUNC_CONSTANT flags. iArg is 002101 ** ignored and the user-data for these functions is set to an 002102 ** arbitrary non-NULL pointer. The bNC parameter is not used. 002103 ** 002104 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) 002105 ** Used to create an aggregate function definition implemented by 002106 ** the C functions xStep and xFinal. The first four parameters 002107 ** are interpreted in the same way as the first 4 parameters to 002108 ** FUNCTION(). 002109 ** 002110 ** WAGGREGATE(zName, nArg, iArg, xStep, xFinal, xValue, xInverse) 002111 ** Used to create an aggregate function definition implemented by 002112 ** the C functions xStep and xFinal. The first four parameters 002113 ** are interpreted in the same way as the first 4 parameters to 002114 ** FUNCTION(). 002115 ** 002116 ** LIKEFUNC(zName, nArg, pArg, flags) 002117 ** Used to create a scalar function definition of a function zName 002118 ** that accepts nArg arguments and is implemented by a call to C 002119 ** function likeFunc. Argument pArg is cast to a (void *) and made 002120 ** available as the function user-data (sqlite3_user_data()). The 002121 ** FuncDef.flags variable is set to the value passed as the flags 002122 ** parameter. 002123 */ 002124 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ 002125 {nArg, SQLITE_FUNC_BUILTIN|\ 002126 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 002127 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } 002128 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ 002129 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 002130 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } 002131 #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \ 002132 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ 002133 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } 002134 #define MFUNCTION(zName, nArg, xPtr, xFunc) \ 002135 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ 002136 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} } 002137 #define JFUNCTION(zName, nArg, bUseCache, bWS, bRS, bJsonB, iArg, xFunc) \ 002138 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_FUNC_CONSTANT|\ 002139 SQLITE_UTF8|((bUseCache)*SQLITE_FUNC_RUNONLY)|\ 002140 ((bRS)*SQLITE_SUBTYPE)|((bWS)*SQLITE_RESULT_SUBTYPE), \ 002141 SQLITE_INT_TO_PTR(iArg|((bJsonB)*JSON_BLOB)),0,xFunc,0, 0, 0, #zName, {0} } 002142 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \ 002143 {nArg, SQLITE_FUNC_BUILTIN|\ 002144 SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ 002145 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } 002146 #define TEST_FUNC(zName, nArg, iArg, mFlags) \ 002147 {nArg, SQLITE_FUNC_BUILTIN|\ 002148 SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ 002149 SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ 002150 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } 002151 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ 002152 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ 002153 0, 0, xFunc, 0, 0, 0, #zName, {0} } 002154 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \ 002155 {nArg, SQLITE_FUNC_BUILTIN|\ 002156 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ 002157 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} } 002158 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ 002159 {nArg, SQLITE_FUNC_BUILTIN|\ 002160 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ 002161 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } 002162 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ 002163 {nArg, SQLITE_FUNC_BUILTIN|\ 002164 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 002165 pArg, 0, xFunc, 0, 0, 0, #zName, } 002166 #define LIKEFUNC(zName, nArg, arg, flags) \ 002167 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ 002168 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} } 002169 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \ 002170 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \ 002171 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}} 002172 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \ 002173 {nArg, SQLITE_FUNC_BUILTIN|\ 002174 SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ 002175 0, 0, xFunc, 0, 0, 0, #zName, {0} } 002176 002177 002178 /* 002179 ** All current savepoints are stored in a linked list starting at 002180 ** sqlite3.pSavepoint. The first element in the list is the most recently 002181 ** opened savepoint. Savepoints are added to the list by the vdbe 002182 ** OP_Savepoint instruction. 002183 */ 002184 struct Savepoint { 002185 char *zName; /* Savepoint name (nul-terminated) */ 002186 i64 nDeferredCons; /* Number of deferred fk violations */ 002187 i64 nDeferredImmCons; /* Number of deferred imm fk. */ 002188 Savepoint *pNext; /* Parent savepoint (if any) */ 002189 }; 002190 002191 /* 002192 ** The following are used as the second parameter to sqlite3Savepoint(), 002193 ** and as the P1 argument to the OP_Savepoint instruction. 002194 */ 002195 #define SAVEPOINT_BEGIN 0 002196 #define SAVEPOINT_RELEASE 1 002197 #define SAVEPOINT_ROLLBACK 2 002198 002199 002200 /* 002201 ** Each SQLite module (virtual table definition) is defined by an 002202 ** instance of the following structure, stored in the sqlite3.aModule 002203 ** hash table. 002204 */ 002205 struct Module { 002206 const sqlite3_module *pModule; /* Callback pointers */ 002207 const char *zName; /* Name passed to create_module() */ 002208 int nRefModule; /* Number of pointers to this object */ 002209 void *pAux; /* pAux passed to create_module() */ 002210 void (*xDestroy)(void *); /* Module destructor function */ 002211 Table *pEpoTab; /* Eponymous table for this module */ 002212 }; 002213 002214 /* 002215 ** Information about each column of an SQL table is held in an instance 002216 ** of the Column structure, in the Table.aCol[] array. 002217 ** 002218 ** Definitions: 002219 ** 002220 ** "table column index" This is the index of the column in the 002221 ** Table.aCol[] array, and also the index of 002222 ** the column in the original CREATE TABLE stmt. 002223 ** 002224 ** "storage column index" This is the index of the column in the 002225 ** record BLOB generated by the OP_MakeRecord 002226 ** opcode. The storage column index is less than 002227 ** or equal to the table column index. It is 002228 ** equal if and only if there are no VIRTUAL 002229 ** columns to the left. 002230 ** 002231 ** Notes on zCnName: 002232 ** The zCnName field stores the name of the column, the datatype of the 002233 ** column, and the collating sequence for the column, in that order, all in 002234 ** a single allocation. Each string is 0x00 terminated. The datatype 002235 ** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the 002236 ** collating sequence name is only included if the COLFLAG_HASCOLL bit is 002237 ** set. 002238 */ 002239 struct Column { 002240 char *zCnName; /* Name of this column */ 002241 unsigned notNull :4; /* An OE_ code for handling a NOT NULL constraint */ 002242 unsigned eCType :4; /* One of the standard types */ 002243 char affinity; /* One of the SQLITE_AFF_... values */ 002244 u8 szEst; /* Est size of value in this column. sizeof(INT)==1 */ 002245 u8 hName; /* Column name hash for faster lookup */ 002246 u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */ 002247 u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ 002248 }; 002249 002250 /* Allowed values for Column.eCType. 002251 ** 002252 ** Values must match entries in the global constant arrays 002253 ** sqlite3StdTypeLen[] and sqlite3StdType[]. Each value is one more 002254 ** than the offset into these arrays for the corresponding name. 002255 ** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. 002256 */ 002257 #define COLTYPE_CUSTOM 0 /* Type appended to zName */ 002258 #define COLTYPE_ANY 1 002259 #define COLTYPE_BLOB 2 002260 #define COLTYPE_INT 3 002261 #define COLTYPE_INTEGER 4 002262 #define COLTYPE_REAL 5 002263 #define COLTYPE_TEXT 6 002264 #define SQLITE_N_STDTYPE 6 /* Number of standard types */ 002265 002266 /* Allowed values for Column.colFlags. 002267 ** 002268 ** Constraints: 002269 ** TF_HasVirtual == COLFLAG_VIRTUAL 002270 ** TF_HasStored == COLFLAG_STORED 002271 ** TF_HasHidden == COLFLAG_HIDDEN 002272 */ 002273 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ 002274 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ 002275 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */ 002276 #define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */ 002277 #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */ 002278 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */ 002279 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */ 002280 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */ 002281 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */ 002282 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */ 002283 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */ 002284 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */ 002285 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ 002286 002287 /* 002288 ** A "Collating Sequence" is defined by an instance of the following 002289 ** structure. Conceptually, a collating sequence consists of a name and 002290 ** a comparison routine that defines the order of that sequence. 002291 ** 002292 ** If CollSeq.xCmp is NULL, it means that the 002293 ** collating sequence is undefined. Indices built on an undefined 002294 ** collating sequence may not be read or written. 002295 */ 002296 struct CollSeq { 002297 char *zName; /* Name of the collating sequence, UTF-8 encoded */ 002298 u8 enc; /* Text encoding handled by xCmp() */ 002299 void *pUser; /* First argument to xCmp() */ 002300 int (*xCmp)(void*,int, const void*, int, const void*); 002301 void (*xDel)(void*); /* Destructor for pUser */ 002302 }; 002303 002304 /* 002305 ** A sort order can be either ASC or DESC. 002306 */ 002307 #define SQLITE_SO_ASC 0 /* Sort in ascending order */ 002308 #define SQLITE_SO_DESC 1 /* Sort in ascending order */ 002309 #define SQLITE_SO_UNDEFINED -1 /* No sort order specified */ 002310 002311 /* 002312 ** Column affinity types. 002313 ** 002314 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and 002315 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve 002316 ** the speed a little by numbering the values consecutively. 002317 ** 002318 ** But rather than start with 0 or 1, we begin with 'A'. That way, 002319 ** when multiple affinity types are concatenated into a string and 002320 ** used as the P4 operand, they will be more readable. 002321 ** 002322 ** Note also that the numeric types are grouped together so that testing 002323 ** for a numeric type is a single comparison. And the BLOB type is first. 002324 */ 002325 #define SQLITE_AFF_NONE 0x40 /* '@' */ 002326 #define SQLITE_AFF_BLOB 0x41 /* 'A' */ 002327 #define SQLITE_AFF_TEXT 0x42 /* 'B' */ 002328 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */ 002329 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */ 002330 #define SQLITE_AFF_REAL 0x45 /* 'E' */ 002331 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */ 002332 002333 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) 002334 002335 /* 002336 ** The SQLITE_AFF_MASK values masks off the significant bits of an 002337 ** affinity value. 002338 */ 002339 #define SQLITE_AFF_MASK 0x47 002340 002341 /* 002342 ** Additional bit values that can be ORed with an affinity without 002343 ** changing the affinity. 002344 ** 002345 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. 002346 ** It causes an assert() to fire if either operand to a comparison 002347 ** operator is NULL. It is added to certain comparison operators to 002348 ** prove that the operands are always NOT NULL. 002349 */ 002350 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */ 002351 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ 002352 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */ 002353 002354 /* 002355 ** An object of this type is created for each virtual table present in 002356 ** the database schema. 002357 ** 002358 ** If the database schema is shared, then there is one instance of this 002359 ** structure for each database connection (sqlite3*) that uses the shared 002360 ** schema. This is because each database connection requires its own unique 002361 ** instance of the sqlite3_vtab* handle used to access the virtual table 002362 ** implementation. sqlite3_vtab* handles can not be shared between 002363 ** database connections, even when the rest of the in-memory database 002364 ** schema is shared, as the implementation often stores the database 002365 ** connection handle passed to it via the xConnect() or xCreate() method 002366 ** during initialization internally. This database connection handle may 002367 ** then be used by the virtual table implementation to access real tables 002368 ** within the database. So that they appear as part of the callers 002369 ** transaction, these accesses need to be made via the same database 002370 ** connection as that used to execute SQL operations on the virtual table. 002371 ** 002372 ** All VTable objects that correspond to a single table in a shared 002373 ** database schema are initially stored in a linked-list pointed to by 002374 ** the Table.pVTable member variable of the corresponding Table object. 002375 ** When an sqlite3_prepare() operation is required to access the virtual 002376 ** table, it searches the list for the VTable that corresponds to the 002377 ** database connection doing the preparing so as to use the correct 002378 ** sqlite3_vtab* handle in the compiled query. 002379 ** 002380 ** When an in-memory Table object is deleted (for example when the 002381 ** schema is being reloaded for some reason), the VTable objects are not 002382 ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed 002383 ** immediately. Instead, they are moved from the Table.pVTable list to 002384 ** another linked list headed by the sqlite3.pDisconnect member of the 002385 ** corresponding sqlite3 structure. They are then deleted/xDisconnected 002386 ** next time a statement is prepared using said sqlite3*. This is done 002387 ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes. 002388 ** Refer to comments above function sqlite3VtabUnlockList() for an 002389 ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect 002390 ** list without holding the corresponding sqlite3.mutex mutex. 002391 ** 002392 ** The memory for objects of this type is always allocated by 002393 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as 002394 ** the first argument. 002395 */ 002396 struct VTable { 002397 sqlite3 *db; /* Database connection associated with this table */ 002398 Module *pMod; /* Pointer to module implementation */ 002399 sqlite3_vtab *pVtab; /* Pointer to vtab instance */ 002400 int nRef; /* Number of pointers to this structure */ 002401 u8 bConstraint; /* True if constraints are supported */ 002402 u8 bAllSchemas; /* True if might use any attached schema */ 002403 u8 eVtabRisk; /* Riskiness of allowing hacker access */ 002404 int iSavepoint; /* Depth of the SAVEPOINT stack */ 002405 VTable *pNext; /* Next in linked list (see above) */ 002406 }; 002407 002408 /* Allowed values for VTable.eVtabRisk 002409 */ 002410 #define SQLITE_VTABRISK_Low 0 002411 #define SQLITE_VTABRISK_Normal 1 002412 #define SQLITE_VTABRISK_High 2 002413 002414 /* 002415 ** The schema for each SQL table, virtual table, and view is represented 002416 ** in memory by an instance of the following structure. 002417 */ 002418 struct Table { 002419 char *zName; /* Name of the table or view */ 002420 Column *aCol; /* Information about each column */ 002421 Index *pIndex; /* List of SQL indexes on this table. */ 002422 char *zColAff; /* String defining the affinity of each column */ 002423 ExprList *pCheck; /* All CHECK constraints */ 002424 /* ... also used as column name list in a VIEW */ 002425 Pgno tnum; /* Root BTree page for this table */ 002426 u32 nTabRef; /* Number of pointers to this Table */ 002427 u32 tabFlags; /* Mask of TF_* values */ 002428 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ 002429 i16 nCol; /* Number of columns in this table */ 002430 i16 nNVCol; /* Number of columns that are not VIRTUAL */ 002431 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ 002432 LogEst szTabRow; /* Estimated size of each table row in bytes */ 002433 #ifdef SQLITE_ENABLE_COSTMULT 002434 LogEst costMult; /* Cost multiplier for using this table */ 002435 #endif 002436 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ 002437 u8 eTabType; /* 0: normal, 1: virtual, 2: view */ 002438 union { 002439 struct { /* Used by ordinary tables: */ 002440 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ 002441 FKey *pFKey; /* Linked list of all foreign keys in this table */ 002442 ExprList *pDfltList; /* DEFAULT clauses on various columns. 002443 ** Or the AS clause for generated columns. */ 002444 } tab; 002445 struct { /* Used by views: */ 002446 Select *pSelect; /* View definition */ 002447 } view; 002448 struct { /* Used by virtual tables only: */ 002449 int nArg; /* Number of arguments to the module */ 002450 char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */ 002451 VTable *p; /* List of VTable objects. */ 002452 } vtab; 002453 } u; 002454 Trigger *pTrigger; /* List of triggers on this object */ 002455 Schema *pSchema; /* Schema that contains this table */ 002456 }; 002457 002458 /* 002459 ** Allowed values for Table.tabFlags. 002460 ** 002461 ** TF_OOOHidden applies to tables or view that have hidden columns that are 002462 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING 002463 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, 002464 ** the TF_OOOHidden attribute would apply in this case. Such tables require 002465 ** special handling during INSERT processing. The "OOO" means "Out Of Order". 002466 ** 002467 ** Constraints: 002468 ** 002469 ** TF_HasVirtual == COLFLAG_VIRTUAL 002470 ** TF_HasStored == COLFLAG_STORED 002471 ** TF_HasHidden == COLFLAG_HIDDEN 002472 */ 002473 #define TF_Readonly 0x00000001 /* Read-only system table */ 002474 #define TF_HasHidden 0x00000002 /* Has one or more hidden columns */ 002475 #define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */ 002476 #define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */ 002477 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */ 002478 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */ 002479 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */ 002480 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */ 002481 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */ 002482 #define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */ 002483 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */ 002484 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */ 002485 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */ 002486 #define TF_Shadow 0x00001000 /* True for a shadow table */ 002487 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */ 002488 #define TF_Ephemeral 0x00004000 /* An ephemeral table */ 002489 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */ 002490 #define TF_Strict 0x00010000 /* STRICT mode */ 002491 002492 /* 002493 ** Allowed values for Table.eTabType 002494 */ 002495 #define TABTYP_NORM 0 /* Ordinary table */ 002496 #define TABTYP_VTAB 1 /* Virtual table */ 002497 #define TABTYP_VIEW 2 /* A view */ 002498 002499 #define IsView(X) ((X)->eTabType==TABTYP_VIEW) 002500 #define IsOrdinaryTable(X) ((X)->eTabType==TABTYP_NORM) 002501 002502 /* 002503 ** Test to see whether or not a table is a virtual table. This is 002504 ** done as a macro so that it will be optimized out when virtual 002505 ** table support is omitted from the build. 002506 */ 002507 #ifndef SQLITE_OMIT_VIRTUALTABLE 002508 # define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB) 002509 # define ExprIsVtab(X) \ 002510 ((X)->op==TK_COLUMN && (X)->y.pTab->eTabType==TABTYP_VTAB) 002511 #else 002512 # define IsVirtual(X) 0 002513 # define ExprIsVtab(X) 0 002514 #endif 002515 002516 /* 002517 ** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() 002518 ** only works for non-virtual tables (ordinary tables and views) and is 002519 ** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The 002520 ** IsHiddenColumn() macro is general purpose. 002521 */ 002522 #if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) 002523 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 002524 # define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 002525 #elif !defined(SQLITE_OMIT_VIRTUALTABLE) 002526 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 002527 # define IsOrdinaryHiddenColumn(X) 0 002528 #else 002529 # define IsHiddenColumn(X) 0 002530 # define IsOrdinaryHiddenColumn(X) 0 002531 #endif 002532 002533 002534 /* Does the table have a rowid */ 002535 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) 002536 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) 002537 002538 /* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is 002539 ** available. By default, this macro is false 002540 */ 002541 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW 002542 # define ViewCanHaveRowid 0 002543 #else 002544 # define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0) 002545 #endif 002546 002547 /* 002548 ** Each foreign key constraint is an instance of the following structure. 002549 ** 002550 ** A foreign key is associated with two tables. The "from" table is 002551 ** the table that contains the REFERENCES clause that creates the foreign 002552 ** key. The "to" table is the table that is named in the REFERENCES clause. 002553 ** Consider this example: 002554 ** 002555 ** CREATE TABLE ex1( 002556 ** a INTEGER PRIMARY KEY, 002557 ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x) 002558 ** ); 002559 ** 002560 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". 002561 ** Equivalent names: 002562 ** 002563 ** from-table == child-table 002564 ** to-table == parent-table 002565 ** 002566 ** Each REFERENCES clause generates an instance of the following structure 002567 ** which is attached to the from-table. The to-table need not exist when 002568 ** the from-table is created. The existence of the to-table is not checked. 002569 ** 002570 ** The list of all parents for child Table X is held at X.pFKey. 002571 ** 002572 ** A list of all children for a table named Z (which might not even exist) 002573 ** is held in Schema.fkeyHash with a hash key of Z. 002574 */ 002575 struct FKey { 002576 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */ 002577 FKey *pNextFrom; /* Next FKey with the same in pFrom. Next parent of pFrom */ 002578 char *zTo; /* Name of table that the key points to (aka: Parent) */ 002579 FKey *pNextTo; /* Next with the same zTo. Next child of zTo. */ 002580 FKey *pPrevTo; /* Previous with the same zTo */ 002581 int nCol; /* Number of columns in this key */ 002582 /* EV: R-30323-21917 */ 002583 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */ 002584 u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */ 002585 Trigger *apTrigger[2];/* Triggers for aAction[] actions */ 002586 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */ 002587 int iFrom; /* Index of column in pFrom */ 002588 char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */ 002589 } aCol[1]; /* One entry for each of nCol columns */ 002590 }; 002591 002592 /* 002593 ** SQLite supports many different ways to resolve a constraint 002594 ** error. ROLLBACK processing means that a constraint violation 002595 ** causes the operation in process to fail and for the current transaction 002596 ** to be rolled back. ABORT processing means the operation in process 002597 ** fails and any prior changes from that one operation are backed out, 002598 ** but the transaction is not rolled back. FAIL processing means that 002599 ** the operation in progress stops and returns an error code. But prior 002600 ** changes due to the same operation are not backed out and no rollback 002601 ** occurs. IGNORE means that the particular row that caused the constraint 002602 ** error is not inserted or updated. Processing continues and no error 002603 ** is returned. REPLACE means that preexisting database rows that caused 002604 ** a UNIQUE constraint violation are removed so that the new insert or 002605 ** update can proceed. Processing continues and no error is reported. 002606 ** UPDATE applies to insert operations only and means that the insert 002607 ** is omitted and the DO UPDATE clause of an upsert is run instead. 002608 ** 002609 ** RESTRICT, SETNULL, SETDFLT, and CASCADE actions apply only to foreign keys. 002610 ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the 002611 ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign 002612 ** key is set to NULL. SETDFLT means that the foreign key is set 002613 ** to its default value. CASCADE means that a DELETE or UPDATE of the 002614 ** referenced table row is propagated into the row that holds the 002615 ** foreign key. 002616 ** 002617 ** The OE_Default value is a place holder that means to use whatever 002618 ** conflict resolution algorithm is required from context. 002619 ** 002620 ** The following symbolic values are used to record which type 002621 ** of conflict resolution action to take. 002622 */ 002623 #define OE_None 0 /* There is no constraint to check */ 002624 #define OE_Rollback 1 /* Fail the operation and rollback the transaction */ 002625 #define OE_Abort 2 /* Back out changes but do no rollback transaction */ 002626 #define OE_Fail 3 /* Stop the operation but leave all prior changes */ 002627 #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ 002628 #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ 002629 #define OE_Update 6 /* Process as a DO UPDATE in an upsert */ 002630 #define OE_Restrict 7 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ 002631 #define OE_SetNull 8 /* Set the foreign key value to NULL */ 002632 #define OE_SetDflt 9 /* Set the foreign key value to its default */ 002633 #define OE_Cascade 10 /* Cascade the changes */ 002634 #define OE_Default 11 /* Do whatever the default action is */ 002635 002636 002637 /* 002638 ** An instance of the following structure is passed as the first 002639 ** argument to sqlite3VdbeKeyCompare and is used to control the 002640 ** comparison of the two index keys. 002641 ** 002642 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There 002643 ** are nField slots for the columns of an index then one extra slot 002644 ** for the rowid at the end. 002645 */ 002646 struct KeyInfo { 002647 u32 nRef; /* Number of references to this KeyInfo object */ 002648 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */ 002649 u16 nKeyField; /* Number of key columns in the index */ 002650 u16 nAllField; /* Total columns, including key plus others */ 002651 sqlite3 *db; /* The database connection */ 002652 u8 *aSortFlags; /* Sort order for each column. */ 002653 CollSeq *aColl[1]; /* Collating sequence for each term of the key */ 002654 }; 002655 002656 /* 002657 ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array. 002658 */ 002659 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */ 002660 #define KEYINFO_ORDER_BIGNULL 0x02 /* NULL is larger than any other value */ 002661 002662 /* 002663 ** This object holds a record which has been parsed out into individual 002664 ** fields, for the purposes of doing a comparison. 002665 ** 002666 ** A record is an object that contains one or more fields of data. 002667 ** Records are used to store the content of a table row and to store 002668 ** the key of an index. A blob encoding of a record is created by 002669 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the 002670 ** OP_Column opcode. 002671 ** 002672 ** An instance of this object serves as a "key" for doing a search on 002673 ** an index b+tree. The goal of the search is to find the entry that 002674 ** is closed to the key described by this object. This object might hold 002675 ** just a prefix of the key. The number of fields is given by 002676 ** pKeyInfo->nField. 002677 ** 002678 ** The r1 and r2 fields are the values to return if this key is less than 002679 ** or greater than a key in the btree, respectively. These are normally 002680 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree 002681 ** is in DESC order. 002682 ** 002683 ** The key comparison functions actually return default_rc when they find 002684 ** an equals comparison. default_rc can be -1, 0, or +1. If there are 002685 ** multiple entries in the b-tree with the same key (when only looking 002686 ** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to 002687 ** cause the search to find the last match, or +1 to cause the search to 002688 ** find the first match. 002689 ** 002690 ** The key comparison functions will set eqSeen to true if they ever 002691 ** get and equal results when comparing this structure to a b-tree record. 002692 ** When default_rc!=0, the search might end up on the record immediately 002693 ** before the first match or immediately after the last match. The 002694 ** eqSeen field will indicate whether or not an exact match exists in the 002695 ** b-tree. 002696 */ 002697 struct UnpackedRecord { 002698 KeyInfo *pKeyInfo; /* Collation and sort-order information */ 002699 Mem *aMem; /* Values */ 002700 union { 002701 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ 002702 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ 002703 } u; 002704 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ 002705 u16 nField; /* Number of entries in apMem[] */ 002706 i8 default_rc; /* Comparison result if keys are equal */ 002707 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ 002708 i8 r1; /* Value to return if (lhs < rhs) */ 002709 i8 r2; /* Value to return if (lhs > rhs) */ 002710 u8 eqSeen; /* True if an equality comparison has been seen */ 002711 }; 002712 002713 002714 /* 002715 ** Each SQL index is represented in memory by an 002716 ** instance of the following structure. 002717 ** 002718 ** The columns of the table that are to be indexed are described 002719 ** by the aiColumn[] field of this structure. For example, suppose 002720 ** we have the following table and index: 002721 ** 002722 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text); 002723 ** CREATE INDEX Ex2 ON Ex1(c3,c1); 002724 ** 002725 ** In the Table structure describing Ex1, nCol==3 because there are 002726 ** three columns in the table. In the Index structure describing 002727 ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. 002728 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the 002729 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. 002730 ** The second column to be indexed (c1) has an index of 0 in 002731 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. 002732 ** 002733 ** The Index.onError field determines whether or not the indexed columns 002734 ** must be unique and what to do if they are not. When Index.onError=OE_None, 002735 ** it means this is not a unique index. Otherwise it is a unique index 002736 ** and the value of Index.onError indicates which conflict resolution 002737 ** algorithm to employ when an attempt is made to insert a non-unique 002738 ** element. 002739 ** 002740 ** The colNotIdxed bitmask is used in combination with SrcItem.colUsed 002741 ** for a fast test to see if an index can serve as a covering index. 002742 ** colNotIdxed has a 1 bit for every column of the original table that 002743 ** is *not* available in the index. Thus the expression 002744 ** "colUsed & colNotIdxed" will be non-zero if the index is not a 002745 ** covering index. The most significant bit of of colNotIdxed will always 002746 ** be true (note-20221022-a). If a column beyond the 63rd column of the 002747 ** table is used, the "colUsed & colNotIdxed" test will always be non-zero 002748 ** and we have to assume either that the index is not covering, or use 002749 ** an alternative (slower) algorithm to determine whether or not 002750 ** the index is covering. 002751 ** 002752 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to 002753 ** generate VDBE code (as opposed to parsing one read from an sqlite_schema 002754 ** table as part of parsing an existing database schema), transient instances 002755 ** of this structure may be created. In this case the Index.tnum variable is 002756 ** used to store the address of a VDBE instruction, not a database page 002757 ** number (it cannot - the database page is not allocated until the VDBE 002758 ** program is executed). See convertToWithoutRowidTable() for details. 002759 */ 002760 struct Index { 002761 char *zName; /* Name of this index */ 002762 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */ 002763 LogEst *aiRowLogEst; /* From ANALYZE: Est. rows selected by each column */ 002764 Table *pTable; /* The SQL table being indexed */ 002765 char *zColAff; /* String defining the affinity of each column */ 002766 Index *pNext; /* The next index associated with the same table */ 002767 Schema *pSchema; /* Schema containing this index */ 002768 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ 002769 const char **azColl; /* Array of collation sequence names for index */ 002770 Expr *pPartIdxWhere; /* WHERE clause for partial indices */ 002771 ExprList *aColExpr; /* Column expressions */ 002772 Pgno tnum; /* DB Page containing root of this index */ 002773 LogEst szIdxRow; /* Estimated average row size in bytes */ 002774 u16 nKeyCol; /* Number of columns forming the key */ 002775 u16 nColumn; /* Number of columns stored in the index */ 002776 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ 002777 unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */ 002778 unsigned bUnordered:1; /* Use this index for == or IN queries only */ 002779 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ 002780 unsigned isResized:1; /* True if resizeIndexObject() has been called */ 002781 unsigned isCovering:1; /* True if this is a covering index */ 002782 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ 002783 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */ 002784 unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */ 002785 unsigned bNoQuery:1; /* Do not use this index to optimize queries */ 002786 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */ 002787 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */ 002788 unsigned bHasExpr:1; /* Index contains an expression, either a literal 002789 ** expression, or a reference to a VIRTUAL column */ 002790 #ifdef SQLITE_ENABLE_STAT4 002791 int nSample; /* Number of elements in aSample[] */ 002792 int mxSample; /* Number of slots allocated to aSample[] */ 002793 int nSampleCol; /* Size of IndexSample.anEq[] and so on */ 002794 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ 002795 IndexSample *aSample; /* Samples of the left-most key */ 002796 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ 002797 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ 002798 #endif 002799 Bitmask colNotIdxed; /* Unindexed columns in pTab */ 002800 }; 002801 002802 /* 002803 ** Allowed values for Index.idxType 002804 */ 002805 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */ 002806 #define SQLITE_IDXTYPE_UNIQUE 1 /* Implements a UNIQUE constraint */ 002807 #define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */ 002808 #define SQLITE_IDXTYPE_IPK 3 /* INTEGER PRIMARY KEY index */ 002809 002810 /* Return true if index X is a PRIMARY KEY index */ 002811 #define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY) 002812 002813 /* Return true if index X is a UNIQUE index */ 002814 #define IsUniqueIndex(X) ((X)->onError!=OE_None) 002815 002816 /* The Index.aiColumn[] values are normally positive integer. But 002817 ** there are some negative values that have special meaning: 002818 */ 002819 #define XN_ROWID (-1) /* Indexed column is the rowid */ 002820 #define XN_EXPR (-2) /* Indexed column is an expression */ 002821 002822 /* 002823 ** Each sample stored in the sqlite_stat4 table is represented in memory 002824 ** using a structure of this type. See documentation at the top of the 002825 ** analyze.c source file for additional information. 002826 */ 002827 struct IndexSample { 002828 void *p; /* Pointer to sampled record */ 002829 int n; /* Size of record in bytes */ 002830 tRowcnt *anEq; /* Est. number of rows where the key equals this sample */ 002831 tRowcnt *anLt; /* Est. number of rows where key is less than this sample */ 002832 tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */ 002833 }; 002834 002835 /* 002836 ** Possible values to use within the flags argument to sqlite3GetToken(). 002837 */ 002838 #define SQLITE_TOKEN_QUOTED 0x1 /* Token is a quoted identifier. */ 002839 #define SQLITE_TOKEN_KEYWORD 0x2 /* Token is a keyword. */ 002840 002841 /* 002842 ** Each token coming out of the lexer is an instance of 002843 ** this structure. Tokens are also used as part of an expression. 002844 ** 002845 ** The memory that "z" points to is owned by other objects. Take care 002846 ** that the owner of the "z" string does not deallocate the string before 002847 ** the Token goes out of scope! Very often, the "z" points to some place 002848 ** in the middle of the Parse.zSql text. But it might also point to a 002849 ** static string. 002850 */ 002851 struct Token { 002852 const char *z; /* Text of the token. Not NULL-terminated! */ 002853 unsigned int n; /* Number of characters in this token */ 002854 }; 002855 002856 /* 002857 ** An instance of this structure contains information needed to generate 002858 ** code for a SELECT that contains aggregate functions. 002859 ** 002860 ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a 002861 ** pointer to this structure. The Expr.iAgg field is the index in 002862 ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate 002863 ** code for that node. 002864 ** 002865 ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the 002866 ** original Select structure that describes the SELECT statement. These 002867 ** fields do not need to be freed when deallocating the AggInfo structure. 002868 */ 002869 struct AggInfo { 002870 u8 directMode; /* Direct rendering mode means take data directly 002871 ** from source tables rather than from accumulators */ 002872 u8 useSortingIdx; /* In direct mode, reference the sorting index rather 002873 ** than the source table */ 002874 u16 nSortingColumn; /* Number of columns in the sorting index */ 002875 int sortingIdx; /* Cursor number of the sorting index */ 002876 int sortingIdxPTab; /* Cursor number of pseudo-table */ 002877 int iFirstReg; /* First register in range for aCol[] and aFunc[] */ 002878 ExprList *pGroupBy; /* The group by clause */ 002879 struct AggInfo_col { /* For each column used in source tables */ 002880 Table *pTab; /* Source table */ 002881 Expr *pCExpr; /* The original expression */ 002882 int iTable; /* Cursor number of the source table */ 002883 i16 iColumn; /* Column number within the source table */ 002884 i16 iSorterColumn; /* Column number in the sorting index */ 002885 } *aCol; 002886 int nColumn; /* Number of used entries in aCol[] */ 002887 int nAccumulator; /* Number of columns that show through to the output. 002888 ** Additional columns are used only as parameters to 002889 ** aggregate functions */ 002890 struct AggInfo_func { /* For each aggregate function */ 002891 Expr *pFExpr; /* Expression encoding the function */ 002892 FuncDef *pFunc; /* The aggregate function implementation */ 002893 int iDistinct; /* Ephemeral table used to enforce DISTINCT */ 002894 int iDistAddr; /* Address of OP_OpenEphemeral */ 002895 int iOBTab; /* Ephemeral table to implement ORDER BY */ 002896 u8 bOBPayload; /* iOBTab has payload columns separate from key */ 002897 u8 bOBUnique; /* Enforce uniqueness on iOBTab keys */ 002898 u8 bUseSubtype; /* Transfer subtype info through sorter */ 002899 } *aFunc; 002900 int nFunc; /* Number of entries in aFunc[] */ 002901 u32 selId; /* Select to which this AggInfo belongs */ 002902 #ifdef SQLITE_DEBUG 002903 Select *pSelect; /* SELECT statement that this AggInfo supports */ 002904 #endif 002905 }; 002906 002907 /* 002908 ** Macros to compute aCol[] and aFunc[] register numbers. 002909 ** 002910 ** These macros should not be used prior to the call to 002911 ** assignAggregateRegisters() that computes the value of pAggInfo->iFirstReg. 002912 ** The assert()s that are part of this macro verify that constraint. 002913 */ 002914 #define AggInfoColumnReg(A,I) (assert((A)->iFirstReg),(A)->iFirstReg+(I)) 002915 #define AggInfoFuncReg(A,I) \ 002916 (assert((A)->iFirstReg),(A)->iFirstReg+(A)->nColumn+(I)) 002917 002918 /* 002919 ** The datatype ynVar is a signed integer, either 16-bit or 32-bit. 002920 ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater 002921 ** than 32767 we have to make it 32-bit. 16-bit is preferred because 002922 ** it uses less memory in the Expr object, which is a big memory user 002923 ** in systems with lots of prepared statements. And few applications 002924 ** need more than about 10 or 20 variables. But some extreme users want 002925 ** to have prepared statements with over 32766 variables, and for them 002926 ** the option is available (at compile-time). 002927 */ 002928 #if SQLITE_MAX_VARIABLE_NUMBER<32767 002929 typedef i16 ynVar; 002930 #else 002931 typedef int ynVar; 002932 #endif 002933 002934 /* 002935 ** Each node of an expression in the parse tree is an instance 002936 ** of this structure. 002937 ** 002938 ** Expr.op is the opcode. The integer parser token codes are reused 002939 ** as opcodes here. For example, the parser defines TK_GE to be an integer 002940 ** code representing the ">=" operator. This same integer code is reused 002941 ** to represent the greater-than-or-equal-to operator in the expression 002942 ** tree. 002943 ** 002944 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB, 002945 ** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If 002946 ** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the 002947 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION), 002948 ** then Expr.u.zToken contains the name of the function. 002949 ** 002950 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a 002951 ** binary operator. Either or both may be NULL. 002952 ** 002953 ** Expr.x.pList is a list of arguments if the expression is an SQL function, 002954 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)". 002955 ** Expr.x.pSelect is used if the expression is a sub-select or an expression of 002956 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the 002957 ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is 002958 ** valid. 002959 ** 002960 ** An expression of the form ID or ID.ID refers to a column in a table. 002961 ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is 002962 ** the integer cursor number of a VDBE cursor pointing to that table and 002963 ** Expr.iColumn is the column number for the specific column. If the 002964 ** expression is used as a result in an aggregate SELECT, then the 002965 ** value is also stored in the Expr.iAgg column in the aggregate so that 002966 ** it can be accessed after all aggregates are computed. 002967 ** 002968 ** If the expression is an unbound variable marker (a question mark 002969 ** character '?' in the original SQL) then the Expr.iTable holds the index 002970 ** number for that variable. 002971 ** 002972 ** If the expression is a subquery then Expr.iColumn holds an integer 002973 ** register number containing the result of the subquery. If the 002974 ** subquery gives a constant result, then iTable is -1. If the subquery 002975 ** gives a different answer at different times during statement processing 002976 ** then iTable is the address of a subroutine that computes the subquery. 002977 ** 002978 ** If the Expr is of type OP_Column, and the table it is selecting from 002979 ** is a disk table or the "old.*" pseudo-table, then pTab points to the 002980 ** corresponding table definition. 002981 ** 002982 ** ALLOCATION NOTES: 002983 ** 002984 ** Expr objects can use a lot of memory space in database schema. To 002985 ** help reduce memory requirements, sometimes an Expr object will be 002986 ** truncated. And to reduce the number of memory allocations, sometimes 002987 ** two or more Expr objects will be stored in a single memory allocation, 002988 ** together with Expr.u.zToken strings. 002989 ** 002990 ** If the EP_Reduced and EP_TokenOnly flags are set when 002991 ** an Expr object is truncated. When EP_Reduced is set, then all 002992 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees 002993 ** are contained within the same memory allocation. Note, however, that 002994 ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately 002995 ** allocated, regardless of whether or not EP_Reduced is set. 002996 */ 002997 struct Expr { 002998 u8 op; /* Operation performed by this node */ 002999 char affExpr; /* affinity, or RAISE type */ 003000 u8 op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op 003001 ** TK_COLUMN: the value of p5 for OP_Column 003002 ** TK_AGG_FUNCTION: nesting depth 003003 ** TK_FUNCTION: NC_SelfRef flag if needs OP_PureFunc */ 003004 #ifdef SQLITE_DEBUG 003005 u8 vvaFlags; /* Verification flags. */ 003006 #endif 003007 u32 flags; /* Various flags. EP_* See below */ 003008 union { 003009 char *zToken; /* Token value. Zero terminated and dequoted */ 003010 int iValue; /* Non-negative integer value if EP_IntValue */ 003011 } u; 003012 003013 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no 003014 ** space is allocated for the fields below this point. An attempt to 003015 ** access them will result in a segfault or malfunction. 003016 *********************************************************************/ 003017 003018 Expr *pLeft; /* Left subnode */ 003019 Expr *pRight; /* Right subnode */ 003020 union { 003021 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */ 003022 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */ 003023 } x; 003024 003025 /* If the EP_Reduced flag is set in the Expr.flags mask, then no 003026 ** space is allocated for the fields below this point. An attempt to 003027 ** access them will result in a segfault or malfunction. 003028 *********************************************************************/ 003029 003030 #if SQLITE_MAX_EXPR_DEPTH>0 003031 int nHeight; /* Height of the tree headed by this node */ 003032 #endif 003033 int iTable; /* TK_COLUMN: cursor number of table holding column 003034 ** TK_REGISTER: register number 003035 ** TK_TRIGGER: 1 -> new, 0 -> old 003036 ** EP_Unlikely: 134217728 times likelihood 003037 ** TK_IN: ephemeral table holding RHS 003038 ** TK_SELECT_COLUMN: Number of columns on the LHS 003039 ** TK_SELECT: 1st register of result vector */ 003040 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. 003041 ** TK_VARIABLE: variable number (always >= 1). 003042 ** TK_SELECT_COLUMN: column of the result vector */ 003043 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ 003044 union { 003045 int iJoin; /* If EP_OuterON or EP_InnerON, the right table */ 003046 int iOfst; /* else: start of token from start of statement */ 003047 } w; 003048 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ 003049 union { 003050 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL 003051 ** for a column of an index on an expression */ 003052 Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */ 003053 struct { /* TK_IN, TK_SELECT, and TK_EXISTS */ 003054 int iAddr; /* Subroutine entry address */ 003055 int regReturn; /* Register used to hold return address */ 003056 } sub; 003057 } y; 003058 }; 003059 003060 /* The following are the meanings of bits in the Expr.flags field. 003061 ** Value restrictions: 003062 ** 003063 ** EP_Agg == NC_HasAgg == SF_HasAgg 003064 ** EP_Win == NC_HasWin 003065 */ 003066 #define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */ 003067 #define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */ 003068 #define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */ 003069 #define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */ 003070 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */ 003071 #define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */ 003072 #define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */ 003073 #define EP_DblQuoted 0x000080 /* token.z was originally in "..." */ 003074 #define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */ 003075 #define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */ 003076 #define EP_Commuted 0x000400 /* Comparison operator has been commuted */ 003077 #define EP_IntValue 0x000800 /* Integer value contained in u.iValue */ 003078 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */ 003079 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */ 003080 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ 003081 #define EP_Win 0x008000 /* Contains window functions */ 003082 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ 003083 #define EP_FullSize 0x020000 /* Expr structure must remain full sized */ 003084 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */ 003085 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */ 003086 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ 003087 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */ 003088 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */ 003089 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ 003090 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ 003091 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ 003092 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ 003093 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ 003094 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ 003095 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ 003096 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ 003097 /* 0x80000000 // Available */ 003098 003099 /* The EP_Propagate mask is a set of properties that automatically propagate 003100 ** upwards into parent nodes. 003101 */ 003102 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) 003103 003104 /* Macros can be used to test, set, or clear bits in the 003105 ** Expr.flags field. 003106 */ 003107 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) 003108 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) 003109 #define ExprSetProperty(E,P) (E)->flags|=(P) 003110 #define ExprClearProperty(E,P) (E)->flags&=~(P) 003111 #define ExprAlwaysTrue(E) (((E)->flags&(EP_OuterON|EP_IsTrue))==EP_IsTrue) 003112 #define ExprAlwaysFalse(E) (((E)->flags&(EP_OuterON|EP_IsFalse))==EP_IsFalse) 003113 #define ExprIsFullSize(E) (((E)->flags&(EP_Reduced|EP_TokenOnly))==0) 003114 003115 /* Macros used to ensure that the correct members of unions are accessed 003116 ** in Expr. 003117 */ 003118 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0) 003119 #define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0) 003120 #define ExprUseWOfst(E) (((E)->flags&(EP_InnerON|EP_OuterON))==0) 003121 #define ExprUseWJoin(E) (((E)->flags&(EP_InnerON|EP_OuterON))!=0) 003122 #define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0) 003123 #define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0) 003124 #define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0) 003125 #define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0) 003126 #define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0) 003127 003128 /* Flags for use with Expr.vvaFlags 003129 */ 003130 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ 003131 #define EP_Immutable 0x02 /* Do not change this Expr node */ 003132 003133 /* The ExprSetVVAProperty() macro is used for Verification, Validation, 003134 ** and Accreditation only. It works like ExprSetProperty() during VVA 003135 ** processes but is a no-op for delivery. 003136 */ 003137 #ifdef SQLITE_DEBUG 003138 # define ExprSetVVAProperty(E,P) (E)->vvaFlags|=(P) 003139 # define ExprHasVVAProperty(E,P) (((E)->vvaFlags&(P))!=0) 003140 # define ExprClearVVAProperties(E) (E)->vvaFlags = 0 003141 #else 003142 # define ExprSetVVAProperty(E,P) 003143 # define ExprHasVVAProperty(E,P) 0 003144 # define ExprClearVVAProperties(E) 003145 #endif 003146 003147 /* 003148 ** Macros to determine the number of bytes required by a normal Expr 003149 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags 003150 ** and an Expr struct with the EP_TokenOnly flag set. 003151 */ 003152 #define EXPR_FULLSIZE sizeof(Expr) /* Full size */ 003153 #define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */ 003154 #define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */ 003155 003156 /* 003157 ** Flags passed to the sqlite3ExprDup() function. See the header comment 003158 ** above sqlite3ExprDup() for details. 003159 */ 003160 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */ 003161 003162 /* 003163 ** True if the expression passed as an argument was a function with 003164 ** an OVER() clause (a window function). 003165 */ 003166 #ifdef SQLITE_OMIT_WINDOWFUNC 003167 # define IsWindowFunc(p) 0 003168 #else 003169 # define IsWindowFunc(p) ( \ 003170 ExprHasProperty((p), EP_WinFunc) && p->y.pWin->eFrmType!=TK_FILTER \ 003171 ) 003172 #endif 003173 003174 /* 003175 ** A list of expressions. Each expression may optionally have a 003176 ** name. An expr/name combination can be used in several ways, such 003177 ** as the list of "expr AS ID" fields following a "SELECT" or in the 003178 ** list of "ID = expr" items in an UPDATE. A list of expressions can 003179 ** also be used as the argument to a function, in which case the a.zName 003180 ** field is not used. 003181 ** 003182 ** In order to try to keep memory usage down, the Expr.a.zEName field 003183 ** is used for multiple purposes: 003184 ** 003185 ** eEName Usage 003186 ** ---------- ------------------------- 003187 ** ENAME_NAME (1) the AS of result set column 003188 ** (2) COLUMN= of an UPDATE 003189 ** 003190 ** ENAME_TAB DB.TABLE.NAME used to resolve names 003191 ** of subqueries 003192 ** 003193 ** ENAME_SPAN Text of the original result set 003194 ** expression. 003195 */ 003196 struct ExprList { 003197 int nExpr; /* Number of expressions on the list */ 003198 int nAlloc; /* Number of a[] slots allocated */ 003199 struct ExprList_item { /* For each expression in the list */ 003200 Expr *pExpr; /* The parse tree for this expression */ 003201 char *zEName; /* Token associated with this expression */ 003202 struct { 003203 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ 003204 unsigned eEName :2; /* Meaning of zEName */ 003205 unsigned done :1; /* Indicates when processing is finished */ 003206 unsigned reusable :1; /* Constant expression is reusable */ 003207 unsigned bSorterRef :1; /* Defer evaluation until after sorting */ 003208 unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */ 003209 unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */ 003210 unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */ 003211 unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should 003212 ** not be expanded by "*" in parent queries */ 003213 } fg; 003214 union { 003215 struct { /* Used by any ExprList other than Parse.pConsExpr */ 003216 u16 iOrderByCol; /* For ORDER BY, column number in result set */ 003217 u16 iAlias; /* Index into Parse.aAlias[] for zName */ 003218 } x; 003219 int iConstExprReg; /* Register in which Expr value is cached. Used only 003220 ** by Parse.pConstExpr */ 003221 } u; 003222 } a[1]; /* One slot for each expression in the list */ 003223 }; 003224 003225 /* 003226 ** Allowed values for Expr.a.eEName 003227 */ 003228 #define ENAME_NAME 0 /* The AS clause of a result set */ 003229 #define ENAME_SPAN 1 /* Complete text of the result set expression */ 003230 #define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */ 003231 #define ENAME_ROWID 3 /* "DB.TABLE._rowid_" for * expansion of rowid */ 003232 003233 /* 003234 ** An instance of this structure can hold a simple list of identifiers, 003235 ** such as the list "a,b,c" in the following statements: 003236 ** 003237 ** INSERT INTO t(a,b,c) VALUES ...; 003238 ** CREATE INDEX idx ON t(a,b,c); 003239 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...; 003240 ** 003241 ** The IdList.a.idx field is used when the IdList represents the list of 003242 ** column names after a table name in an INSERT statement. In the statement 003243 ** 003244 ** INSERT INTO t(a,b,c) ... 003245 ** 003246 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. 003247 */ 003248 struct IdList { 003249 int nId; /* Number of identifiers on the list */ 003250 u8 eU4; /* Which element of a.u4 is valid */ 003251 struct IdList_item { 003252 char *zName; /* Name of the identifier */ 003253 union { 003254 int idx; /* Index in some Table.aCol[] of a column named zName */ 003255 Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */ 003256 } u4; 003257 } a[1]; 003258 }; 003259 003260 /* 003261 ** Allowed values for IdList.eType, which determines which value of the a.u4 003262 ** is valid. 003263 */ 003264 #define EU4_NONE 0 /* Does not use IdList.a.u4 */ 003265 #define EU4_IDX 1 /* Uses IdList.a.u4.idx */ 003266 #define EU4_EXPR 2 /* Uses IdList.a.u4.pExpr -- NOT CURRENTLY USED */ 003267 003268 /* 003269 ** The SrcItem object represents a single term in the FROM clause of a query. 003270 ** The SrcList object is mostly an array of SrcItems. 003271 ** 003272 ** The jointype starts out showing the join type between the current table 003273 ** and the next table on the list. The parser builds the list this way. 003274 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each 003275 ** jointype expresses the join between the table and the previous table. 003276 ** 003277 ** In the colUsed field, the high-order bit (bit 63) is set if the table 003278 ** contains more than 63 columns and the 64-th or later column is used. 003279 ** 003280 ** Union member validity: 003281 ** 003282 ** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc 003283 ** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy 003284 ** u1.nRow !fg.isTabFunc && !fg.isIndexedBy 003285 ** 003286 ** u2.pIBIndex fg.isIndexedBy && !fg.isCte 003287 ** u2.pCteUse fg.isCte && !fg.isIndexedBy 003288 */ 003289 struct SrcItem { 003290 Schema *pSchema; /* Schema to which this item is fixed */ 003291 char *zDatabase; /* Name of database holding this table */ 003292 char *zName; /* Name of the table */ 003293 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 003294 Table *pTab; /* An SQL table corresponding to zName */ 003295 Select *pSelect; /* A SELECT statement used in place of a table name */ 003296 int addrFillSub; /* Address of subroutine to manifest a subquery */ 003297 int regReturn; /* Register holding return address of addrFillSub */ 003298 int regResult; /* Registers holding results of a co-routine */ 003299 struct { 003300 u8 jointype; /* Type of join between this table and the previous */ 003301 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */ 003302 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ 003303 unsigned isTabFunc :1; /* True if table-valued-function syntax */ 003304 unsigned isCorrelated :1; /* True if sub-query is correlated */ 003305 unsigned isMaterialized:1; /* This is a materialized view */ 003306 unsigned viaCoroutine :1; /* Implemented as a co-routine */ 003307 unsigned isRecursive :1; /* True for recursive reference in WITH */ 003308 unsigned fromDDL :1; /* Comes from sqlite_schema */ 003309 unsigned isCte :1; /* This is a CTE */ 003310 unsigned notCte :1; /* This item may not match a CTE */ 003311 unsigned isUsing :1; /* u3.pUsing is valid */ 003312 unsigned isOn :1; /* u3.pOn was once valid and non-NULL */ 003313 unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */ 003314 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */ 003315 unsigned rowidUsed :1; /* The ROWID of this table is referenced */ 003316 } fg; 003317 int iCursor; /* The VDBE cursor number used to access this table */ 003318 union { 003319 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */ 003320 IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */ 003321 } u3; 003322 Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */ 003323 union { 003324 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */ 003325 ExprList *pFuncArg; /* Arguments to table-valued-function */ 003326 u32 nRow; /* Number of rows in a VALUES clause */ 003327 } u1; 003328 union { 003329 Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */ 003330 CteUse *pCteUse; /* CTE Usage info when fg.isCte is true */ 003331 } u2; 003332 }; 003333 003334 /* 003335 ** The OnOrUsing object represents either an ON clause or a USING clause. 003336 ** It can never be both at the same time, but it can be neither. 003337 */ 003338 struct OnOrUsing { 003339 Expr *pOn; /* The ON clause of a join */ 003340 IdList *pUsing; /* The USING clause of a join */ 003341 }; 003342 003343 /* 003344 ** This object represents one or more tables that are the source of 003345 ** content for an SQL statement. For example, a single SrcList object 003346 ** is used to hold the FROM clause of a SELECT statement. SrcList also 003347 ** represents the target tables for DELETE, INSERT, and UPDATE statements. 003348 ** 003349 */ 003350 struct SrcList { 003351 int nSrc; /* Number of tables or subqueries in the FROM clause */ 003352 u32 nAlloc; /* Number of entries allocated in a[] below */ 003353 SrcItem a[1]; /* One entry for each identifier on the list */ 003354 }; 003355 003356 /* 003357 ** Permitted values of the SrcList.a.jointype field 003358 */ 003359 #define JT_INNER 0x01 /* Any kind of inner or cross join */ 003360 #define JT_CROSS 0x02 /* Explicit use of the CROSS keyword */ 003361 #define JT_NATURAL 0x04 /* True for a "natural" join */ 003362 #define JT_LEFT 0x08 /* Left outer join */ 003363 #define JT_RIGHT 0x10 /* Right outer join */ 003364 #define JT_OUTER 0x20 /* The "OUTER" keyword is present */ 003365 #define JT_LTORJ 0x40 /* One of the LEFT operands of a RIGHT JOIN 003366 ** Mnemonic: Left Table Of Right Join */ 003367 #define JT_ERROR 0x80 /* unknown or unsupported join type */ 003368 003369 /* 003370 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() 003371 ** and the WhereInfo.wctrlFlags member. 003372 ** 003373 ** Value constraints (enforced via assert()): 003374 ** WHERE_USE_LIMIT == SF_FixedLimit 003375 */ 003376 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */ 003377 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */ 003378 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */ 003379 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */ 003380 #define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */ 003381 #define WHERE_DUPLICATES_OK 0x0010 /* Ok to return a row more than once */ 003382 #define WHERE_OR_SUBCLAUSE 0x0020 /* Processing a sub-WHERE as part of 003383 ** the OR optimization */ 003384 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */ 003385 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ 003386 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ 003387 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ 003388 #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */ 003389 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ 003390 #define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */ 003391 #define WHERE_KEEP_ALL_JOINS 0x2000 /* Do not do the omit-noop-join opt */ 003392 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ 003393 /* 0x8000 not currently used */ 003394 003395 /* Allowed return values from sqlite3WhereIsDistinct() 003396 */ 003397 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ 003398 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ 003399 #define WHERE_DISTINCT_ORDERED 2 /* All duplicates are adjacent */ 003400 #define WHERE_DISTINCT_UNORDERED 3 /* Duplicates are scattered */ 003401 003402 /* 003403 ** A NameContext defines a context in which to resolve table and column 003404 ** names. The context consists of a list of tables (the pSrcList) field and 003405 ** a list of named expression (pEList). The named expression list may 003406 ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or 003407 ** to the table being operated on by INSERT, UPDATE, or DELETE. The 003408 ** pEList corresponds to the result set of a SELECT and is NULL for 003409 ** other statements. 003410 ** 003411 ** NameContexts can be nested. When resolving names, the inner-most 003412 ** context is searched first. If no match is found, the next outer 003413 ** context is checked. If there is still no match, the next context 003414 ** is checked. This process continues until either a match is found 003415 ** or all contexts are check. When a match is found, the nRef member of 003416 ** the context containing the match is incremented. 003417 ** 003418 ** Each subquery gets a new NameContext. The pNext field points to the 003419 ** NameContext in the parent query. Thus the process of scanning the 003420 ** NameContext list corresponds to searching through successively outer 003421 ** subqueries looking for a match. 003422 */ 003423 struct NameContext { 003424 Parse *pParse; /* The parser */ 003425 SrcList *pSrcList; /* One or more tables used to resolve names */ 003426 union { 003427 ExprList *pEList; /* Optional list of result-set columns */ 003428 AggInfo *pAggInfo; /* Information about aggregates at this level */ 003429 Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ 003430 int iBaseReg; /* For TK_REGISTER when parsing RETURNING */ 003431 } uNC; 003432 NameContext *pNext; /* Next outer name context. NULL for outermost */ 003433 int nRef; /* Number of names resolved by this context */ 003434 int nNcErr; /* Number of errors encountered while resolving names */ 003435 int ncFlags; /* Zero or more NC_* flags defined below */ 003436 u32 nNestedSelect; /* Number of nested selects using this NC */ 003437 Select *pWinSelect; /* SELECT statement for any window functions */ 003438 }; 003439 003440 /* 003441 ** Allowed values for the NameContext, ncFlags field. 003442 ** 003443 ** Value constraints (all checked via assert()): 003444 ** NC_HasAgg == SF_HasAgg == EP_Agg 003445 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX 003446 ** NC_OrderAgg == SF_OrderByReqd == SQLITE_FUNC_ANYORDER 003447 ** NC_HasWin == EP_Win 003448 ** 003449 */ 003450 #define NC_AllowAgg 0x000001 /* Aggregate functions are allowed here */ 003451 #define NC_PartIdx 0x000002 /* True if resolving a partial index WHERE */ 003452 #define NC_IsCheck 0x000004 /* True if resolving a CHECK constraint */ 003453 #define NC_GenCol 0x000008 /* True for a GENERATED ALWAYS AS clause */ 003454 #define NC_HasAgg 0x000010 /* One or more aggregate functions seen */ 003455 #define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */ 003456 #define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ 003457 #define NC_Subquery 0x000040 /* A subquery has been seen */ 003458 #define NC_UEList 0x000080 /* True if uNC.pEList is used */ 003459 #define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */ 003460 #define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */ 003461 #define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */ 003462 #define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */ 003463 #define NC_Complex 0x002000 /* True if a function or subquery seen */ 003464 #define NC_AllowWin 0x004000 /* Window functions are allowed here */ 003465 #define NC_HasWin 0x008000 /* One or more window functions seen */ 003466 #define NC_IsDDL 0x010000 /* Resolving names in a CREATE statement */ 003467 #define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */ 003468 #define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */ 003469 #define NC_NoSelect 0x080000 /* Do not descend into sub-selects */ 003470 #define NC_Where 0x100000 /* Processing WHERE clause of a SELECT */ 003471 #define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */ 003472 003473 /* 003474 ** An instance of the following object describes a single ON CONFLICT 003475 ** clause in an upsert. 003476 ** 003477 ** The pUpsertTarget field is only set if the ON CONFLICT clause includes 003478 ** conflict-target clause. (In "ON CONFLICT(a,b)" the "(a,b)" is the 003479 ** conflict-target clause.) The pUpsertTargetWhere is the optional 003480 ** WHERE clause used to identify partial unique indexes. 003481 ** 003482 ** pUpsertSet is the list of column=expr terms of the UPDATE statement. 003483 ** The pUpsertSet field is NULL for a ON CONFLICT DO NOTHING. The 003484 ** pUpsertWhere is the WHERE clause for the UPDATE and is NULL if the 003485 ** WHERE clause is omitted. 003486 */ 003487 struct Upsert { 003488 ExprList *pUpsertTarget; /* Optional description of conflict target */ 003489 Expr *pUpsertTargetWhere; /* WHERE clause for partial index targets */ 003490 ExprList *pUpsertSet; /* The SET clause from an ON CONFLICT UPDATE */ 003491 Expr *pUpsertWhere; /* WHERE clause for the ON CONFLICT UPDATE */ 003492 Upsert *pNextUpsert; /* Next ON CONFLICT clause in the list */ 003493 u8 isDoUpdate; /* True for DO UPDATE. False for DO NOTHING */ 003494 u8 isDup; /* True if 2nd or later with same pUpsertIdx */ 003495 /* Above this point is the parse tree for the ON CONFLICT clauses. 003496 ** The next group of fields stores intermediate data. */ 003497 void *pToFree; /* Free memory when deleting the Upsert object */ 003498 /* All fields above are owned by the Upsert object and must be freed 003499 ** when the Upsert is destroyed. The fields below are used to transfer 003500 ** information from the INSERT processing down into the UPDATE processing 003501 ** while generating code. The fields below are owned by the INSERT 003502 ** statement and will be freed by INSERT processing. */ 003503 Index *pUpsertIdx; /* UNIQUE constraint specified by pUpsertTarget */ 003504 SrcList *pUpsertSrc; /* Table to be updated */ 003505 int regData; /* First register holding array of VALUES */ 003506 int iDataCur; /* Index of the data cursor */ 003507 int iIdxCur; /* Index of the first index cursor */ 003508 }; 003509 003510 /* 003511 ** An instance of the following structure contains all information 003512 ** needed to generate code for a single SELECT statement. 003513 ** 003514 ** See the header comment on the computeLimitRegisters() routine for a 003515 ** detailed description of the meaning of the iLimit and iOffset fields. 003516 ** 003517 ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes. 003518 ** These addresses must be stored so that we can go back and fill in 003519 ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor 003520 ** the number of columns in P2 can be computed at the same time 003521 ** as the OP_OpenEphm instruction is coded because not 003522 ** enough information about the compound query is known at that point. 003523 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences 003524 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating 003525 ** sequences for the ORDER BY clause. 003526 */ 003527 struct Select { 003528 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ 003529 LogEst nSelectRow; /* Estimated number of result rows */ 003530 u32 selFlags; /* Various SF_* values */ 003531 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ 003532 u32 selId; /* Unique identifier number for this SELECT */ 003533 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */ 003534 ExprList *pEList; /* The fields of the result */ 003535 SrcList *pSrc; /* The FROM clause */ 003536 Expr *pWhere; /* The WHERE clause */ 003537 ExprList *pGroupBy; /* The GROUP BY clause */ 003538 Expr *pHaving; /* The HAVING clause */ 003539 ExprList *pOrderBy; /* The ORDER BY clause */ 003540 Select *pPrior; /* Prior select in a compound select statement */ 003541 Select *pNext; /* Next select to the left in a compound */ 003542 Expr *pLimit; /* LIMIT expression. NULL means not used. */ 003543 With *pWith; /* WITH clause attached to this select. Or NULL. */ 003544 #ifndef SQLITE_OMIT_WINDOWFUNC 003545 Window *pWin; /* List of window functions */ 003546 Window *pWinDefn; /* List of named window definitions */ 003547 #endif 003548 }; 003549 003550 /* 003551 ** Allowed values for Select.selFlags. The "SF" prefix stands for 003552 ** "Select Flag". 003553 ** 003554 ** Value constraints (all checked via assert()) 003555 ** SF_HasAgg == NC_HasAgg 003556 ** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX 003557 ** SF_OrderByReqd == NC_OrderAgg == SQLITE_FUNC_ANYORDER 003558 ** SF_FixedLimit == WHERE_USE_LIMIT 003559 */ 003560 #define SF_Distinct 0x0000001 /* Output should be DISTINCT */ 003561 #define SF_All 0x0000002 /* Includes the ALL keyword */ 003562 #define SF_Resolved 0x0000004 /* Identifiers have been resolved */ 003563 #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */ 003564 #define SF_HasAgg 0x0000010 /* Contains aggregate functions */ 003565 #define SF_UsesEphemeral 0x0000020 /* Uses the OpenEphemeral opcode */ 003566 #define SF_Expanded 0x0000040 /* sqlite3SelectExpand() called on this */ 003567 #define SF_HasTypeInfo 0x0000080 /* FROM subqueries have Table metadata */ 003568 #define SF_Compound 0x0000100 /* Part of a compound query */ 003569 #define SF_Values 0x0000200 /* Synthesized from VALUES clause */ 003570 #define SF_MultiValue 0x0000400 /* Single VALUES term with multiple rows */ 003571 #define SF_NestedFrom 0x0000800 /* Part of a parenthesized FROM clause */ 003572 #define SF_MinMaxAgg 0x0001000 /* Aggregate containing min() or max() */ 003573 #define SF_Recursive 0x0002000 /* The recursive part of a recursive CTE */ 003574 #define SF_FixedLimit 0x0004000 /* nSelectRow set by a constant LIMIT */ 003575 #define SF_MaybeConvert 0x0008000 /* Need convertCompoundSelectToSubquery() */ 003576 #define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */ 003577 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */ 003578 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */ 003579 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ 003580 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ 003581 #define SF_View 0x0200000 /* SELECT statement is a view */ 003582 #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ 003583 #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ 003584 #define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */ 003585 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ 003586 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ 003587 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ 003588 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ 003589 #define SF_Correlated 0x20000000 /* True if references the outer context */ 003590 003591 /* True if S exists and has SF_NestedFrom */ 003592 #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) 003593 003594 /* 003595 ** The results of a SELECT can be distributed in several ways, as defined 003596 ** by one of the following macros. The "SRT" prefix means "SELECT Result 003597 ** Type". 003598 ** 003599 ** SRT_Union Store results as a key in a temporary index 003600 ** identified by pDest->iSDParm. 003601 ** 003602 ** SRT_Except Remove results from the temporary index pDest->iSDParm. 003603 ** 003604 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result 003605 ** set is not empty. 003606 ** 003607 ** SRT_Discard Throw the results away. This is used by SELECT 003608 ** statements within triggers whose only purpose is 003609 ** the side-effects of functions. 003610 ** 003611 ** SRT_Output Generate a row of output (using the OP_ResultRow 003612 ** opcode) for each row in the result set. 003613 ** 003614 ** SRT_Mem Only valid if the result is a single column. 003615 ** Store the first column of the first result row 003616 ** in register pDest->iSDParm then abandon the rest 003617 ** of the query. This destination implies "LIMIT 1". 003618 ** 003619 ** SRT_Set The result must be a single column. Store each 003620 ** row of result as the key in table pDest->iSDParm. 003621 ** Apply the affinity pDest->affSdst before storing 003622 ** results. Used to implement "IN (SELECT ...)". 003623 ** 003624 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store 003625 ** the result there. The cursor is left open after 003626 ** returning. This is like SRT_Table except that 003627 ** this destination uses OP_OpenEphemeral to create 003628 ** the table first. 003629 ** 003630 ** SRT_Coroutine Generate a co-routine that returns a new row of 003631 ** results each time it is invoked. The entry point 003632 ** of the co-routine is stored in register pDest->iSDParm 003633 ** and the result row is stored in pDest->nDest registers 003634 ** starting with pDest->iSdst. 003635 ** 003636 ** SRT_Table Store results in temporary table pDest->iSDParm. 003637 ** SRT_Fifo This is like SRT_EphemTab except that the table 003638 ** is assumed to already be open. SRT_Fifo has 003639 ** the additional property of being able to ignore 003640 ** the ORDER BY clause. 003641 ** 003642 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm. 003643 ** But also use temporary table pDest->iSDParm+1 as 003644 ** a record of all prior results and ignore any duplicate 003645 ** rows. Name means: "Distinct Fifo". 003646 ** 003647 ** SRT_Queue Store results in priority queue pDest->iSDParm (really 003648 ** an index). Append a sequence number so that all entries 003649 ** are distinct. 003650 ** 003651 ** SRT_DistQueue Store results in priority queue pDest->iSDParm only if 003652 ** the same record has never been stored before. The 003653 ** index at pDest->iSDParm+1 hold all prior stores. 003654 ** 003655 ** SRT_Upfrom Store results in the temporary table already opened by 003656 ** pDest->iSDParm. If (pDest->iSDParm<0), then the temp 003657 ** table is an intkey table - in this case the first 003658 ** column returned by the SELECT is used as the integer 003659 ** key. If (pDest->iSDParm>0), then the table is an index 003660 ** table. (pDest->iSDParm) is the number of key columns in 003661 ** each index record in this case. 003662 */ 003663 #define SRT_Union 1 /* Store result as keys in an index */ 003664 #define SRT_Except 2 /* Remove result from a UNION index */ 003665 #define SRT_Exists 3 /* Store 1 if the result is not empty */ 003666 #define SRT_Discard 4 /* Do not save the results anywhere */ 003667 #define SRT_DistFifo 5 /* Like SRT_Fifo, but unique results only */ 003668 #define SRT_DistQueue 6 /* Like SRT_Queue, but unique results only */ 003669 003670 /* The DISTINCT clause is ignored for all of the above. Not that 003671 ** IgnorableDistinct() implies IgnorableOrderby() */ 003672 #define IgnorableDistinct(X) ((X->eDest)<=SRT_DistQueue) 003673 003674 #define SRT_Queue 7 /* Store result in an queue */ 003675 #define SRT_Fifo 8 /* Store result as data with an automatic rowid */ 003676 003677 /* The ORDER BY clause is ignored for all of the above */ 003678 #define IgnorableOrderby(X) ((X->eDest)<=SRT_Fifo) 003679 003680 #define SRT_Output 9 /* Output each row of result */ 003681 #define SRT_Mem 10 /* Store result in a memory cell */ 003682 #define SRT_Set 11 /* Store results as keys in an index */ 003683 #define SRT_EphemTab 12 /* Create transient tab and store like SRT_Table */ 003684 #define SRT_Coroutine 13 /* Generate a single row of result */ 003685 #define SRT_Table 14 /* Store result as data with an automatic rowid */ 003686 #define SRT_Upfrom 15 /* Store result as data with rowid */ 003687 003688 /* 003689 ** An instance of this object describes where to put of the results of 003690 ** a SELECT statement. 003691 */ 003692 struct SelectDest { 003693 u8 eDest; /* How to dispose of the results. One of SRT_* above. */ 003694 int iSDParm; /* A parameter used by the eDest disposal method */ 003695 int iSDParm2; /* A second parameter for the eDest disposal method */ 003696 int iSdst; /* Base register where results are written */ 003697 int nSdst; /* Number of registers allocated */ 003698 char *zAffSdst; /* Affinity used for SRT_Set */ 003699 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */ 003700 }; 003701 003702 /* 003703 ** During code generation of statements that do inserts into AUTOINCREMENT 003704 ** tables, the following information is attached to the Table.u.autoInc.p 003705 ** pointer of each autoincrement table to record some side information that 003706 ** the code generator needs. We have to keep per-table autoincrement 003707 ** information in case inserts are done within triggers. Triggers do not 003708 ** normally coordinate their activities, but we do need to coordinate the 003709 ** loading and saving of autoincrement information. 003710 */ 003711 struct AutoincInfo { 003712 AutoincInfo *pNext; /* Next info block in a list of them all */ 003713 Table *pTab; /* Table this info block refers to */ 003714 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */ 003715 int regCtr; /* Memory register holding the rowid counter */ 003716 }; 003717 003718 /* 003719 ** At least one instance of the following structure is created for each 003720 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE 003721 ** statement. All such objects are stored in the linked list headed at 003722 ** Parse.pTriggerPrg and deleted once statement compilation has been 003723 ** completed. 003724 ** 003725 ** A Vdbe sub-program that implements the body and WHEN clause of trigger 003726 ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of 003727 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable. 003728 ** The Parse.pTriggerPrg list never contains two entries with the same 003729 ** values for both pTrigger and orconf. 003730 ** 003731 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns 003732 ** accessed (or set to 0 for triggers fired as a result of INSERT 003733 ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to 003734 ** a mask of new.* columns used by the program. 003735 */ 003736 struct TriggerPrg { 003737 Trigger *pTrigger; /* Trigger this program was coded from */ 003738 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ 003739 SubProgram *pProgram; /* Program implementing pTrigger/orconf */ 003740 int orconf; /* Default ON CONFLICT policy */ 003741 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ 003742 }; 003743 003744 /* 003745 ** The yDbMask datatype for the bitmask of all attached databases. 003746 */ 003747 #if SQLITE_MAX_ATTACHED>30 003748 typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8]; 003749 # define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0) 003750 # define DbMaskZero(M) memset((M),0,sizeof(M)) 003751 # define DbMaskSet(M,I) (M)[(I)/8]|=(1<<((I)&7)) 003752 # define DbMaskAllZero(M) sqlite3DbMaskAllZero(M) 003753 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0) 003754 #else 003755 typedef unsigned int yDbMask; 003756 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0) 003757 # define DbMaskZero(M) ((M)=0) 003758 # define DbMaskSet(M,I) ((M)|=(((yDbMask)1)<<(I))) 003759 # define DbMaskAllZero(M) ((M)==0) 003760 # define DbMaskNonZero(M) ((M)!=0) 003761 #endif 003762 003763 /* 003764 ** For each index X that has as one of its arguments either an expression 003765 ** or the name of a virtual generated column, and if X is in scope such that 003766 ** the value of the expression can simply be read from the index, then 003767 ** there is an instance of this object on the Parse.pIdxExpr list. 003768 ** 003769 ** During code generation, while generating code to evaluate expressions, 003770 ** this list is consulted and if a matching expression is found, the value 003771 ** is read from the index rather than being recomputed. 003772 */ 003773 struct IndexedExpr { 003774 Expr *pExpr; /* The expression contained in the index */ 003775 int iDataCur; /* The data cursor associated with the index */ 003776 int iIdxCur; /* The index cursor */ 003777 int iIdxCol; /* The index column that contains value of pExpr */ 003778 u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */ 003779 u8 aff; /* Affinity of the pExpr expression */ 003780 IndexedExpr *pIENext; /* Next in a list of all indexed expressions */ 003781 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS 003782 const char *zIdxName; /* Name of index, used only for bytecode comments */ 003783 #endif 003784 }; 003785 003786 /* 003787 ** An instance of the ParseCleanup object specifies an operation that 003788 ** should be performed after parsing to deallocation resources obtained 003789 ** during the parse and which are no longer needed. 003790 */ 003791 struct ParseCleanup { 003792 ParseCleanup *pNext; /* Next cleanup task */ 003793 void *pPtr; /* Pointer to object to deallocate */ 003794 void (*xCleanup)(sqlite3*,void*); /* Deallocation routine */ 003795 }; 003796 003797 /* 003798 ** An SQL parser context. A copy of this structure is passed through 003799 ** the parser and down into all the parser action routine in order to 003800 ** carry around information that is global to the entire parse. 003801 ** 003802 ** The structure is divided into two parts. When the parser and code 003803 ** generate call themselves recursively, the first part of the structure 003804 ** is constant but the second part is reset at the beginning and end of 003805 ** each recursion. 003806 ** 003807 ** The nTableLock and aTableLock variables are only used if the shared-cache 003808 ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are 003809 ** used to store the set of table-locks required by the statement being 003810 ** compiled. Function sqlite3TableLock() is used to add entries to the 003811 ** list. 003812 */ 003813 struct Parse { 003814 sqlite3 *db; /* The main database structure */ 003815 char *zErrMsg; /* An error message */ 003816 Vdbe *pVdbe; /* An engine for executing database bytecode */ 003817 int rc; /* Return code from execution */ 003818 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ 003819 u8 checkSchema; /* Causes schema cookie check after an error */ 003820 u8 nested; /* Number of nested calls to the parser/code generator */ 003821 u8 nTempReg; /* Number of temporary registers in aTempReg[] */ 003822 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ 003823 u8 mayAbort; /* True if statement may throw an ABORT exception */ 003824 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ 003825 u8 okConstFactor; /* OK to factor out constants */ 003826 u8 disableLookaside; /* Number of times lookaside has been disabled */ 003827 u8 prepFlags; /* SQLITE_PREPARE_* flags */ 003828 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */ 003829 u8 bHasWith; /* True if statement contains WITH */ 003830 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) 003831 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */ 003832 #endif 003833 #ifdef SQLITE_DEBUG 003834 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */ 003835 #endif 003836 int nRangeReg; /* Size of the temporary register block */ 003837 int iRangeReg; /* First register in temporary register block */ 003838 int nErr; /* Number of errors seen */ 003839 int nTab; /* Number of previously allocated VDBE cursors */ 003840 int nMem; /* Number of memory cells used so far */ 003841 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ 003842 int iSelfTab; /* Table associated with an index on expr, or negative 003843 ** of the base register during check-constraint eval */ 003844 int nLabel; /* The *negative* of the number of labels used */ 003845 int nLabelAlloc; /* Number of slots in aLabel */ 003846 int *aLabel; /* Space to hold the labels */ 003847 ExprList *pConstExpr;/* Constant expressions */ 003848 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */ 003849 IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */ 003850 Token constraintName;/* Name of the constraint currently being parsed */ 003851 yDbMask writeMask; /* Start a write transaction on these databases */ 003852 yDbMask cookieMask; /* Bitmask of schema verified databases */ 003853 int regRowid; /* Register holding rowid of CREATE TABLE entry */ 003854 int regRoot; /* Register holding root page number for new objects */ 003855 int nMaxArg; /* Max args passed to user function by sub-program */ 003856 int nSelect; /* Number of SELECT stmts. Counter for Select.selId */ 003857 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK 003858 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */ 003859 #endif 003860 #ifndef SQLITE_OMIT_SHARED_CACHE 003861 int nTableLock; /* Number of locks in aTableLock */ 003862 TableLock *aTableLock; /* Required table locks for shared-cache mode */ 003863 #endif 003864 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ 003865 Parse *pToplevel; /* Parse structure for main program (or NULL) */ 003866 Table *pTriggerTab; /* Table triggers are being coded for */ 003867 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ 003868 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */ 003869 union { 003870 int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ 003871 Returning *pReturning; /* The RETURNING clause */ 003872 } u1; 003873 u32 oldmask; /* Mask of old.* columns referenced */ 003874 u32 newmask; /* Mask of new.* columns referenced */ 003875 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ 003876 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ 003877 u8 bReturning; /* Coding a RETURNING trigger */ 003878 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ 003879 u8 disableTriggers; /* True to disable triggers */ 003880 003881 /************************************************************************** 003882 ** Fields above must be initialized to zero. The fields that follow, 003883 ** down to the beginning of the recursive section, do not need to be 003884 ** initialized as they will be set before being used. The boundary is 003885 ** determined by offsetof(Parse,aTempReg). 003886 **************************************************************************/ 003887 003888 int aTempReg[8]; /* Holding area for temporary registers */ 003889 Parse *pOuterParse; /* Outer Parse object when nested */ 003890 Token sNameToken; /* Token with unqualified schema object name */ 003891 003892 /************************************************************************ 003893 ** Above is constant between recursions. Below is reset before and after 003894 ** each recursion. The boundary between these two regions is determined 003895 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the 003896 ** first field in the recursive region. 003897 ************************************************************************/ 003898 003899 Token sLastToken; /* The last token parsed */ 003900 ynVar nVar; /* Number of '?' variables seen in the SQL so far */ 003901 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ 003902 u8 explain; /* True if the EXPLAIN flag is found on the query */ 003903 u8 eParseMode; /* PARSE_MODE_XXX constant */ 003904 #ifndef SQLITE_OMIT_VIRTUALTABLE 003905 int nVtabLock; /* Number of virtual tables to lock */ 003906 #endif 003907 int nHeight; /* Expression tree height of current sub-select */ 003908 #ifndef SQLITE_OMIT_EXPLAIN 003909 int addrExplain; /* Address of current OP_Explain opcode */ 003910 #endif 003911 VList *pVList; /* Mapping between variable names and numbers */ 003912 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ 003913 const char *zTail; /* All SQL text past the last semicolon parsed */ 003914 Table *pNewTable; /* A table being constructed by CREATE TABLE */ 003915 Index *pNewIndex; /* An index being constructed by CREATE INDEX. 003916 ** Also used to hold redundant UNIQUE constraints 003917 ** during a RENAME COLUMN */ 003918 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ 003919 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ 003920 #ifndef SQLITE_OMIT_VIRTUALTABLE 003921 Token sArg; /* Complete text of a module argument */ 003922 Table **apVtabLock; /* Pointer to virtual tables needing locking */ 003923 #endif 003924 With *pWith; /* Current WITH clause, or NULL */ 003925 #ifndef SQLITE_OMIT_ALTERTABLE 003926 RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */ 003927 #endif 003928 }; 003929 003930 /* Allowed values for Parse.eParseMode 003931 */ 003932 #define PARSE_MODE_NORMAL 0 003933 #define PARSE_MODE_DECLARE_VTAB 1 003934 #define PARSE_MODE_RENAME 2 003935 #define PARSE_MODE_UNMAP 3 003936 003937 /* 003938 ** Sizes and pointers of various parts of the Parse object. 003939 */ 003940 #define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg)) 003941 #define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/ 003942 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */ 003943 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */ 003944 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */ 003945 003946 /* 003947 ** Return true if currently inside an sqlite3_declare_vtab() call. 003948 */ 003949 #ifdef SQLITE_OMIT_VIRTUALTABLE 003950 #define IN_DECLARE_VTAB 0 003951 #else 003952 #define IN_DECLARE_VTAB (pParse->eParseMode==PARSE_MODE_DECLARE_VTAB) 003953 #endif 003954 003955 #if defined(SQLITE_OMIT_ALTERTABLE) 003956 #define IN_RENAME_OBJECT 0 003957 #else 003958 #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME) 003959 #endif 003960 003961 #if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE) 003962 #define IN_SPECIAL_PARSE 0 003963 #else 003964 #define IN_SPECIAL_PARSE (pParse->eParseMode!=PARSE_MODE_NORMAL) 003965 #endif 003966 003967 /* 003968 ** An instance of the following structure can be declared on a stack and used 003969 ** to save the Parse.zAuthContext value so that it can be restored later. 003970 */ 003971 struct AuthContext { 003972 const char *zAuthContext; /* Put saved Parse.zAuthContext here */ 003973 Parse *pParse; /* The Parse structure */ 003974 }; 003975 003976 /* 003977 ** Bitfield flags for P5 value in various opcodes. 003978 ** 003979 ** Value constraints (enforced via assert()): 003980 ** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH 003981 ** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF 003982 ** OPFLAG_BULKCSR == BTREE_BULKLOAD 003983 ** OPFLAG_SEEKEQ == BTREE_SEEK_EQ 003984 ** OPFLAG_FORDELETE == BTREE_FORDELETE 003985 ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION 003986 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE 003987 */ 003988 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ 003989 /* Also used in P2 (not P5) of OP_Delete */ 003990 #define OPFLAG_NOCHNG 0x01 /* OP_VColumn nochange for UPDATE */ 003991 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ 003992 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */ 003993 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ 003994 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 003995 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 003996 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */ 003997 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 003998 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 003999 #define OPFLAG_BYTELENARG 0xc0 /* OP_Column only for octet_length() */ 004000 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ 004001 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ 004002 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ 004003 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ 004004 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ 004005 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */ 004006 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ 004007 #define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */ 004008 #define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */ 004009 004010 /* 004011 ** Each trigger present in the database schema is stored as an instance of 004012 ** struct Trigger. 004013 ** 004014 ** Pointers to instances of struct Trigger are stored in two ways. 004015 ** 1. In the "trigHash" hash table (part of the sqlite3* that represents the 004016 ** database). This allows Trigger structures to be retrieved by name. 004017 ** 2. All triggers associated with a single table form a linked list, using the 004018 ** pNext member of struct Trigger. A pointer to the first element of the 004019 ** linked list is stored as the "pTrigger" member of the associated 004020 ** struct Table. 004021 ** 004022 ** The "step_list" member points to the first element of a linked list 004023 ** containing the SQL statements specified as the trigger program. 004024 */ 004025 struct Trigger { 004026 char *zName; /* The name of the trigger */ 004027 char *table; /* The table or view to which the trigger applies */ 004028 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ 004029 u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ 004030 u8 bReturning; /* This trigger implements a RETURNING clause */ 004031 Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */ 004032 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, 004033 the <column-list> is stored here */ 004034 Schema *pSchema; /* Schema containing the trigger */ 004035 Schema *pTabSchema; /* Schema containing the table */ 004036 TriggerStep *step_list; /* Link list of trigger program steps */ 004037 Trigger *pNext; /* Next trigger associated with the table */ 004038 }; 004039 004040 /* 004041 ** A trigger is either a BEFORE or an AFTER trigger. The following constants 004042 ** determine which. 004043 ** 004044 ** If there are multiple triggers, you might of some BEFORE and some AFTER. 004045 ** In that cases, the constants below can be ORed together. 004046 */ 004047 #define TRIGGER_BEFORE 1 004048 #define TRIGGER_AFTER 2 004049 004050 /* 004051 ** An instance of struct TriggerStep is used to store a single SQL statement 004052 ** that is a part of a trigger-program. 004053 ** 004054 ** Instances of struct TriggerStep are stored in a singly linked list (linked 004055 ** using the "pNext" member) referenced by the "step_list" member of the 004056 ** associated struct Trigger instance. The first element of the linked list is 004057 ** the first step of the trigger-program. 004058 ** 004059 ** The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or 004060 ** "SELECT" statement. The meanings of the other members is determined by the 004061 ** value of "op" as follows: 004062 ** 004063 ** (op == TK_INSERT) 004064 ** orconf -> stores the ON CONFLICT algorithm 004065 ** pSelect -> The content to be inserted - either a SELECT statement or 004066 ** a VALUES clause. 004067 ** zTarget -> Dequoted name of the table to insert into. 004068 ** pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... 004069 ** statement, then this stores the column-names to be 004070 ** inserted into. 004071 ** pUpsert -> The ON CONFLICT clauses for an Upsert 004072 ** 004073 ** (op == TK_DELETE) 004074 ** zTarget -> Dequoted name of the table to delete from. 004075 ** pWhere -> The WHERE clause of the DELETE statement if one is specified. 004076 ** Otherwise NULL. 004077 ** 004078 ** (op == TK_UPDATE) 004079 ** zTarget -> Dequoted name of the table to update. 004080 ** pWhere -> The WHERE clause of the UPDATE statement if one is specified. 004081 ** Otherwise NULL. 004082 ** pExprList -> A list of the columns to update and the expressions to update 004083 ** them to. See sqlite3Update() documentation of "pChanges" 004084 ** argument. 004085 ** 004086 ** (op == TK_SELECT) 004087 ** pSelect -> The SELECT statement 004088 ** 004089 ** (op == TK_RETURNING) 004090 ** pExprList -> The list of expressions that follow the RETURNING keyword. 004091 ** 004092 */ 004093 struct TriggerStep { 004094 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT, 004095 ** or TK_RETURNING */ 004096 u8 orconf; /* OE_Rollback etc. */ 004097 Trigger *pTrig; /* The trigger that this step is a part of */ 004098 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ 004099 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ 004100 SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */ 004101 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ 004102 ExprList *pExprList; /* SET clause for UPDATE, or RETURNING clause */ 004103 IdList *pIdList; /* Column names for INSERT */ 004104 Upsert *pUpsert; /* Upsert clauses on an INSERT */ 004105 char *zSpan; /* Original SQL text of this command */ 004106 TriggerStep *pNext; /* Next in the link-list */ 004107 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ 004108 }; 004109 004110 /* 004111 ** Information about a RETURNING clause 004112 */ 004113 struct Returning { 004114 Parse *pParse; /* The parse that includes the RETURNING clause */ 004115 ExprList *pReturnEL; /* List of expressions to return */ 004116 Trigger retTrig; /* The transient trigger that implements RETURNING */ 004117 TriggerStep retTStep; /* The trigger step */ 004118 int iRetCur; /* Transient table holding RETURNING results */ 004119 int nRetCol; /* Number of in pReturnEL after expansion */ 004120 int iRetReg; /* Register array for holding a row of RETURNING */ 004121 char zName[40]; /* Name of trigger: "sqlite_returning_%p" */ 004122 }; 004123 004124 /* 004125 ** An objected used to accumulate the text of a string where we 004126 ** do not necessarily know how big the string will be in the end. 004127 */ 004128 struct sqlite3_str { 004129 sqlite3 *db; /* Optional database for lookaside. Can be NULL */ 004130 char *zText; /* The string collected so far */ 004131 u32 nAlloc; /* Amount of space allocated in zText */ 004132 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ 004133 u32 nChar; /* Length of the string so far */ 004134 u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */ 004135 u8 printfFlags; /* SQLITE_PRINTF flags below */ 004136 }; 004137 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */ 004138 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */ 004139 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */ 004140 004141 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0) 004142 004143 /* 004144 ** The following object is the header for an "RCStr" or "reference-counted 004145 ** string". An RCStr is passed around and used like any other char* 004146 ** that has been dynamically allocated. The important interface 004147 ** differences: 004148 ** 004149 ** 1. RCStr strings are reference counted. They are deallocated 004150 ** when the reference count reaches zero. 004151 ** 004152 ** 2. Use sqlite3RCStrUnref() to free an RCStr string rather than 004153 ** sqlite3_free() 004154 ** 004155 ** 3. Make a (read-only) copy of a read-only RCStr string using 004156 ** sqlite3RCStrRef(). 004157 ** 004158 ** "String" is in the name, but an RCStr object can also be used to hold 004159 ** binary data. 004160 */ 004161 struct RCStr { 004162 u64 nRCRef; /* Number of references */ 004163 /* Total structure size should be a multiple of 8 bytes for alignment */ 004164 }; 004165 004166 /* 004167 ** A pointer to this structure is used to communicate information 004168 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. 004169 */ 004170 typedef struct { 004171 sqlite3 *db; /* The database being initialized */ 004172 char **pzErrMsg; /* Error message stored here */ 004173 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ 004174 int rc; /* Result code stored here */ 004175 u32 mInitFlags; /* Flags controlling error messages */ 004176 u32 nInitRow; /* Number of rows processed */ 004177 Pgno mxPage; /* Maximum page number. 0 for no limit. */ 004178 } InitData; 004179 004180 /* 004181 ** Allowed values for mInitFlags 004182 */ 004183 #define INITFLAG_AlterMask 0x0003 /* Types of ALTER */ 004184 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ 004185 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ 004186 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ 004187 004188 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled 004189 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning 004190 ** parameters are for temporary use during development, to help find 004191 ** optimal values for parameters in the query planner. The should not 004192 ** be used on trunk check-ins. They are a temporary mechanism available 004193 ** for transient development builds only. 004194 ** 004195 ** Tuning parameters are numbered starting with 1. 004196 */ 004197 #define SQLITE_NTUNE 6 /* Should be zero for all trunk check-ins */ 004198 #ifdef SQLITE_DEBUG 004199 # define Tuning(X) (sqlite3Config.aTune[(X)-1]) 004200 #else 004201 # define Tuning(X) 0 004202 #endif 004203 004204 /* 004205 ** Structure containing global configuration data for the SQLite library. 004206 ** 004207 ** This structure also contains some state information. 004208 */ 004209 struct Sqlite3Config { 004210 int bMemstat; /* True to enable memory status */ 004211 u8 bCoreMutex; /* True to enable core mutexing */ 004212 u8 bFullMutex; /* True to enable full mutexing */ 004213 u8 bOpenUri; /* True to interpret filenames as URIs */ 004214 u8 bUseCis; /* Use covering indices for full-scans */ 004215 u8 bSmallMalloc; /* Avoid large memory allocations if true */ 004216 u8 bExtraSchemaChecks; /* Verify type,name,tbl_name in schema */ 004217 u8 bUseLongDouble; /* Make use of long double */ 004218 #ifdef SQLITE_DEBUG 004219 u8 bJsonSelfcheck; /* Double-check JSON parsing */ 004220 #endif 004221 int mxStrlen; /* Maximum string length */ 004222 int neverCorrupt; /* Database is always well-formed */ 004223 int szLookaside; /* Default lookaside buffer size */ 004224 int nLookaside; /* Default lookaside buffer count */ 004225 int nStmtSpill; /* Stmt-journal spill-to-disk threshold */ 004226 sqlite3_mem_methods m; /* Low-level memory allocation interface */ 004227 sqlite3_mutex_methods mutex; /* Low-level mutex interface */ 004228 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */ 004229 void *pHeap; /* Heap storage space */ 004230 int nHeap; /* Size of pHeap[] */ 004231 int mnReq, mxReq; /* Min and max heap requests sizes */ 004232 sqlite3_int64 szMmap; /* mmap() space per open file */ 004233 sqlite3_int64 mxMmap; /* Maximum value for szMmap */ 004234 void *pPage; /* Page cache memory */ 004235 int szPage; /* Size of each page in pPage[] */ 004236 int nPage; /* Number of pages in pPage[] */ 004237 int mxParserStack; /* maximum depth of the parser stack */ 004238 int sharedCacheEnabled; /* true if shared-cache mode enabled */ 004239 u32 szPma; /* Maximum Sorter PMA size */ 004240 /* The above might be initialized to non-zero. The following need to always 004241 ** initially be zero, however. */ 004242 int isInit; /* True after initialization has finished */ 004243 int inProgress; /* True while initialization in progress */ 004244 int isMutexInit; /* True after mutexes are initialized */ 004245 int isMallocInit; /* True after malloc is initialized */ 004246 int isPCacheInit; /* True after malloc is initialized */ 004247 int nRefInitMutex; /* Number of users of pInitMutex */ 004248 sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */ 004249 void (*xLog)(void*,int,const char*); /* Function for logging */ 004250 void *pLogArg; /* First argument to xLog() */ 004251 #ifdef SQLITE_ENABLE_SQLLOG 004252 void(*xSqllog)(void*,sqlite3*,const char*, int); 004253 void *pSqllogArg; 004254 #endif 004255 #ifdef SQLITE_VDBE_COVERAGE 004256 /* The following callback (if not NULL) is invoked on every VDBE branch 004257 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. 004258 */ 004259 void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */ 004260 void *pVdbeBranchArg; /* 1st argument */ 004261 #endif 004262 #ifndef SQLITE_OMIT_DESERIALIZE 004263 sqlite3_int64 mxMemdbSize; /* Default max memdb size */ 004264 #endif 004265 #ifndef SQLITE_UNTESTABLE 004266 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ 004267 #endif 004268 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW 004269 u32 mNoVisibleRowid; /* TF_NoVisibleRowid if the ROWID_IN_VIEW 004270 ** feature is disabled. 0 if rowids can 004271 ** occur in views. */ 004272 #endif 004273 int bLocaltimeFault; /* True to fail localtime() calls */ 004274 int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */ 004275 int iOnceResetThreshold; /* When to reset OP_Once counters */ 004276 u32 szSorterRef; /* Min size in bytes to use sorter-refs */ 004277 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */ 004278 /* vvvv--- must be last ---vvv */ 004279 #ifdef SQLITE_DEBUG 004280 sqlite3_int64 aTune[SQLITE_NTUNE]; /* Tuning parameters */ 004281 #endif 004282 }; 004283 004284 /* 004285 ** This macro is used inside of assert() statements to indicate that 004286 ** the assert is only valid on a well-formed database. Instead of: 004287 ** 004288 ** assert( X ); 004289 ** 004290 ** One writes: 004291 ** 004292 ** assert( X || CORRUPT_DB ); 004293 ** 004294 ** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate 004295 ** that the database is definitely corrupt, only that it might be corrupt. 004296 ** For most test cases, CORRUPT_DB is set to false using a special 004297 ** sqlite3_test_control(). This enables assert() statements to prove 004298 ** things that are always true for well-formed databases. 004299 */ 004300 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0) 004301 004302 /* 004303 ** Context pointer passed down through the tree-walk. 004304 */ 004305 struct Walker { 004306 Parse *pParse; /* Parser context. */ 004307 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ 004308 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ 004309 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ 004310 int walkerDepth; /* Number of subqueries */ 004311 u16 eCode; /* A small processing code */ 004312 u16 mWFlags; /* Use-dependent flags */ 004313 union { /* Extra data for callback */ 004314 NameContext *pNC; /* Naming context */ 004315 int n; /* A counter */ 004316 int iCur; /* A cursor number */ 004317 SrcList *pSrcList; /* FROM clause */ 004318 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ 004319 struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */ 004320 int *aiCol; /* array of column indexes */ 004321 struct IdxCover *pIdxCover; /* Check for index coverage */ 004322 ExprList *pGroupBy; /* GROUP BY clause */ 004323 Select *pSelect; /* HAVING to WHERE clause ctx */ 004324 struct WindowRewrite *pRewrite; /* Window rewrite context */ 004325 struct WhereConst *pConst; /* WHERE clause constants */ 004326 struct RenameCtx *pRename; /* RENAME COLUMN context */ 004327 struct Table *pTab; /* Table of generated column */ 004328 struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */ 004329 SrcItem *pSrcItem; /* A single FROM clause item */ 004330 DbFixer *pFix; /* See sqlite3FixSelect() */ 004331 Mem *aMem; /* See sqlite3BtreeCursorHint() */ 004332 } u; 004333 }; 004334 004335 /* 004336 ** The following structure contains information used by the sqliteFix... 004337 ** routines as they walk the parse tree to make database references 004338 ** explicit. 004339 */ 004340 struct DbFixer { 004341 Parse *pParse; /* The parsing context. Error messages written here */ 004342 Walker w; /* Walker object */ 004343 Schema *pSchema; /* Fix items to this schema */ 004344 u8 bTemp; /* True for TEMP schema entries */ 004345 const char *zDb; /* Make sure all objects are contained in this database */ 004346 const char *zType; /* Type of the container - used for error messages */ 004347 const Token *pName; /* Name of the container - used for error messages */ 004348 }; 004349 004350 /* Forward declarations */ 004351 int sqlite3WalkExpr(Walker*, Expr*); 004352 int sqlite3WalkExprNN(Walker*, Expr*); 004353 int sqlite3WalkExprList(Walker*, ExprList*); 004354 int sqlite3WalkSelect(Walker*, Select*); 004355 int sqlite3WalkSelectExpr(Walker*, Select*); 004356 int sqlite3WalkSelectFrom(Walker*, Select*); 004357 int sqlite3ExprWalkNoop(Walker*, Expr*); 004358 int sqlite3SelectWalkNoop(Walker*, Select*); 004359 int sqlite3SelectWalkFail(Walker*, Select*); 004360 int sqlite3WalkerDepthIncrease(Walker*,Select*); 004361 void sqlite3WalkerDepthDecrease(Walker*,Select*); 004362 void sqlite3WalkWinDefnDummyCallback(Walker*,Select*); 004363 004364 #ifdef SQLITE_DEBUG 004365 void sqlite3SelectWalkAssert2(Walker*, Select*); 004366 #endif 004367 004368 #ifndef SQLITE_OMIT_CTE 004369 void sqlite3SelectPopWith(Walker*, Select*); 004370 #else 004371 # define sqlite3SelectPopWith 0 004372 #endif 004373 004374 /* 004375 ** Return code from the parse-tree walking primitives and their 004376 ** callbacks. 004377 */ 004378 #define WRC_Continue 0 /* Continue down into children */ 004379 #define WRC_Prune 1 /* Omit children but continue walking siblings */ 004380 #define WRC_Abort 2 /* Abandon the tree walk */ 004381 004382 /* 004383 ** A single common table expression 004384 */ 004385 struct Cte { 004386 char *zName; /* Name of this CTE */ 004387 ExprList *pCols; /* List of explicit column names, or NULL */ 004388 Select *pSelect; /* The definition of this CTE */ 004389 const char *zCteErr; /* Error message for circular references */ 004390 CteUse *pUse; /* Usage information for this CTE */ 004391 u8 eM10d; /* The MATERIALIZED flag */ 004392 }; 004393 004394 /* 004395 ** Allowed values for the materialized flag (eM10d): 004396 */ 004397 #define M10d_Yes 0 /* AS MATERIALIZED */ 004398 #define M10d_Any 1 /* Not specified. Query planner's choice */ 004399 #define M10d_No 2 /* AS NOT MATERIALIZED */ 004400 004401 /* 004402 ** An instance of the With object represents a WITH clause containing 004403 ** one or more CTEs (common table expressions). 004404 */ 004405 struct With { 004406 int nCte; /* Number of CTEs in the WITH clause */ 004407 int bView; /* Belongs to the outermost Select of a view */ 004408 With *pOuter; /* Containing WITH clause, or NULL */ 004409 Cte a[1]; /* For each CTE in the WITH clause.... */ 004410 }; 004411 004412 /* 004413 ** The Cte object is not guaranteed to persist for the entire duration 004414 ** of code generation. (The query flattener or other parser tree 004415 ** edits might delete it.) The following object records information 004416 ** about each Common Table Expression that must be preserved for the 004417 ** duration of the parse. 004418 ** 004419 ** The CteUse objects are freed using sqlite3ParserAddCleanup() rather 004420 ** than sqlite3SelectDelete(), which is what enables them to persist 004421 ** until the end of code generation. 004422 */ 004423 struct CteUse { 004424 int nUse; /* Number of users of this CTE */ 004425 int addrM9e; /* Start of subroutine to compute materialization */ 004426 int regRtn; /* Return address register for addrM9e subroutine */ 004427 int iCur; /* Ephemeral table holding the materialization */ 004428 LogEst nRowEst; /* Estimated number of rows in the table */ 004429 u8 eM10d; /* The MATERIALIZED flag */ 004430 }; 004431 004432 004433 /* Client data associated with sqlite3_set_clientdata() and 004434 ** sqlite3_get_clientdata(). 004435 */ 004436 struct DbClientData { 004437 DbClientData *pNext; /* Next in a linked list */ 004438 void *pData; /* The data */ 004439 void (*xDestructor)(void*); /* Destructor. Might be NULL */ 004440 char zName[1]; /* Name of this client data. MUST BE LAST */ 004441 }; 004442 004443 #ifdef SQLITE_DEBUG 004444 /* 004445 ** An instance of the TreeView object is used for printing the content of 004446 ** data structures on sqlite3DebugPrintf() using a tree-like view. 004447 */ 004448 struct TreeView { 004449 int iLevel; /* Which level of the tree we are on */ 004450 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */ 004451 }; 004452 #endif /* SQLITE_DEBUG */ 004453 004454 /* 004455 ** This object is used in various ways, most (but not all) related to window 004456 ** functions. 004457 ** 004458 ** (1) A single instance of this structure is attached to the 004459 ** the Expr.y.pWin field for each window function in an expression tree. 004460 ** This object holds the information contained in the OVER clause, 004461 ** plus additional fields used during code generation. 004462 ** 004463 ** (2) All window functions in a single SELECT form a linked-list 004464 ** attached to Select.pWin. The Window.pFunc and Window.pExpr 004465 ** fields point back to the expression that is the window function. 004466 ** 004467 ** (3) The terms of the WINDOW clause of a SELECT are instances of this 004468 ** object on a linked list attached to Select.pWinDefn. 004469 ** 004470 ** (4) For an aggregate function with a FILTER clause, an instance 004471 ** of this object is stored in Expr.y.pWin with eFrmType set to 004472 ** TK_FILTER. In this case the only field used is Window.pFilter. 004473 ** 004474 ** The uses (1) and (2) are really the same Window object that just happens 004475 ** to be accessible in two different ways. Use case (3) are separate objects. 004476 */ 004477 struct Window { 004478 char *zName; /* Name of window (may be NULL) */ 004479 char *zBase; /* Name of base window for chaining (may be NULL) */ 004480 ExprList *pPartition; /* PARTITION BY clause */ 004481 ExprList *pOrderBy; /* ORDER BY clause */ 004482 u8 eFrmType; /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */ 004483 u8 eStart; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */ 004484 u8 eEnd; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */ 004485 u8 bImplicitFrame; /* True if frame was implicitly specified */ 004486 u8 eExclude; /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */ 004487 Expr *pStart; /* Expression for "<expr> PRECEDING" */ 004488 Expr *pEnd; /* Expression for "<expr> FOLLOWING" */ 004489 Window **ppThis; /* Pointer to this object in Select.pWin list */ 004490 Window *pNextWin; /* Next window function belonging to this SELECT */ 004491 Expr *pFilter; /* The FILTER expression */ 004492 FuncDef *pWFunc; /* The function */ 004493 int iEphCsr; /* Partition buffer or Peer buffer */ 004494 int regAccum; /* Accumulator */ 004495 int regResult; /* Interim result */ 004496 int csrApp; /* Function cursor (used by min/max) */ 004497 int regApp; /* Function register (also used by min/max) */ 004498 int regPart; /* Array of registers for PARTITION BY values */ 004499 Expr *pOwner; /* Expression object this window is attached to */ 004500 int nBufferCol; /* Number of columns in buffer table */ 004501 int iArgCol; /* Offset of first argument for this function */ 004502 int regOne; /* Register containing constant value 1 */ 004503 int regStartRowid; 004504 int regEndRowid; 004505 u8 bExprArgs; /* Defer evaluation of window function arguments 004506 ** due to the SQLITE_SUBTYPE flag */ 004507 }; 004508 004509 Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow); 004510 void sqlite3MultiValuesEnd(Parse *pParse, Select *pVal); 004511 004512 #ifndef SQLITE_OMIT_WINDOWFUNC 004513 void sqlite3WindowDelete(sqlite3*, Window*); 004514 void sqlite3WindowUnlinkFromSelect(Window*); 004515 void sqlite3WindowListDelete(sqlite3 *db, Window *p); 004516 Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8); 004517 void sqlite3WindowAttach(Parse*, Expr*, Window*); 004518 void sqlite3WindowLink(Select *pSel, Window *pWin); 004519 int sqlite3WindowCompare(const Parse*, const Window*, const Window*, int); 004520 void sqlite3WindowCodeInit(Parse*, Select*); 004521 void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int); 004522 int sqlite3WindowRewrite(Parse*, Select*); 004523 void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*); 004524 Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p); 004525 Window *sqlite3WindowListDup(sqlite3 *db, Window *p); 004526 void sqlite3WindowFunctions(void); 004527 void sqlite3WindowChain(Parse*, Window*, Window*); 004528 Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*); 004529 #else 004530 # define sqlite3WindowDelete(a,b) 004531 # define sqlite3WindowFunctions() 004532 # define sqlite3WindowAttach(a,b,c) 004533 #endif 004534 004535 /* 004536 ** Assuming zIn points to the first byte of a UTF-8 character, 004537 ** advance zIn to point to the first byte of the next UTF-8 character. 004538 */ 004539 #define SQLITE_SKIP_UTF8(zIn) { \ 004540 if( (*(zIn++))>=0xc0 ){ \ 004541 while( (*zIn & 0xc0)==0x80 ){ zIn++; } \ 004542 } \ 004543 } 004544 004545 /* 004546 ** The SQLITE_*_BKPT macros are substitutes for the error codes with 004547 ** the same name but without the _BKPT suffix. These macros invoke 004548 ** routines that report the line-number on which the error originated 004549 ** using sqlite3_log(). The routines also provide a convenient place 004550 ** to set a debugger breakpoint. 004551 */ 004552 int sqlite3ReportError(int iErr, int lineno, const char *zType); 004553 int sqlite3CorruptError(int); 004554 int sqlite3MisuseError(int); 004555 int sqlite3CantopenError(int); 004556 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__) 004557 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) 004558 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) 004559 #ifdef SQLITE_DEBUG 004560 int sqlite3NomemError(int); 004561 int sqlite3IoerrnomemError(int); 004562 # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__) 004563 # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__) 004564 #else 004565 # define SQLITE_NOMEM_BKPT SQLITE_NOMEM 004566 # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM 004567 #endif 004568 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_CORRUPT_PGNO) 004569 int sqlite3CorruptPgnoError(int,Pgno); 004570 # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P)) 004571 #else 004572 # define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptError(__LINE__) 004573 #endif 004574 004575 /* 004576 ** FTS3 and FTS4 both require virtual table support 004577 */ 004578 #if defined(SQLITE_OMIT_VIRTUALTABLE) 004579 # undef SQLITE_ENABLE_FTS3 004580 # undef SQLITE_ENABLE_FTS4 004581 #endif 004582 004583 /* 004584 ** FTS4 is really an extension for FTS3. It is enabled using the 004585 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call 004586 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. 004587 */ 004588 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) 004589 # define SQLITE_ENABLE_FTS3 1 004590 #endif 004591 004592 /* 004593 ** The ctype.h header is needed for non-ASCII systems. It is also 004594 ** needed by FTS3 when FTS3 is included in the amalgamation. 004595 */ 004596 #if !defined(SQLITE_ASCII) || \ 004597 (defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_AMALGAMATION)) 004598 # include <ctype.h> 004599 #endif 004600 004601 /* 004602 ** The following macros mimic the standard library functions toupper(), 004603 ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The 004604 ** sqlite versions only work for ASCII characters, regardless of locale. 004605 */ 004606 #ifdef SQLITE_ASCII 004607 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20)) 004608 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01) 004609 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06) 004610 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02) 004611 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04) 004612 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08) 004613 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)]) 004614 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80) 004615 # define sqlite3JsonId1(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x42) 004616 # define sqlite3JsonId2(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x46) 004617 #else 004618 # define sqlite3Toupper(x) toupper((unsigned char)(x)) 004619 # define sqlite3Isspace(x) isspace((unsigned char)(x)) 004620 # define sqlite3Isalnum(x) isalnum((unsigned char)(x)) 004621 # define sqlite3Isalpha(x) isalpha((unsigned char)(x)) 004622 # define sqlite3Isdigit(x) isdigit((unsigned char)(x)) 004623 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x)) 004624 # define sqlite3Tolower(x) tolower((unsigned char)(x)) 004625 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`') 004626 # define sqlite3JsonId1(x) (sqlite3IsIdChar(x)&&(x)<'0') 004627 # define sqlite3JsonId2(x) sqlite3IsIdChar(x) 004628 #endif 004629 int sqlite3IsIdChar(u8); 004630 004631 /* 004632 ** Internal function prototypes 004633 */ 004634 int sqlite3StrICmp(const char*,const char*); 004635 int sqlite3Strlen30(const char*); 004636 #define sqlite3Strlen30NN(C) (strlen(C)&0x3fffffff) 004637 char *sqlite3ColumnType(Column*,char*); 004638 #define sqlite3StrNICmp sqlite3_strnicmp 004639 004640 int sqlite3MallocInit(void); 004641 void sqlite3MallocEnd(void); 004642 void *sqlite3Malloc(u64); 004643 void *sqlite3MallocZero(u64); 004644 void *sqlite3DbMallocZero(sqlite3*, u64); 004645 void *sqlite3DbMallocRaw(sqlite3*, u64); 004646 void *sqlite3DbMallocRawNN(sqlite3*, u64); 004647 char *sqlite3DbStrDup(sqlite3*,const char*); 004648 char *sqlite3DbStrNDup(sqlite3*,const char*, u64); 004649 char *sqlite3DbSpanDup(sqlite3*,const char*,const char*); 004650 void *sqlite3Realloc(void*, u64); 004651 void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); 004652 void *sqlite3DbRealloc(sqlite3 *, void *, u64); 004653 void sqlite3DbFree(sqlite3*, void*); 004654 void sqlite3DbFreeNN(sqlite3*, void*); 004655 void sqlite3DbNNFreeNN(sqlite3*, void*); 004656 int sqlite3MallocSize(const void*); 004657 int sqlite3DbMallocSize(sqlite3*, const void*); 004658 void *sqlite3PageMalloc(int); 004659 void sqlite3PageFree(void*); 004660 void sqlite3MemSetDefault(void); 004661 #ifndef SQLITE_UNTESTABLE 004662 void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); 004663 #endif 004664 int sqlite3HeapNearlyFull(void); 004665 004666 /* 004667 ** On systems with ample stack space and that support alloca(), make 004668 ** use of alloca() to obtain space for large automatic objects. By default, 004669 ** obtain space from malloc(). 004670 ** 004671 ** The alloca() routine never returns NULL. This will cause code paths 004672 ** that deal with sqlite3StackAlloc() failures to be unreachable. 004673 */ 004674 #ifdef SQLITE_USE_ALLOCA 004675 # define sqlite3StackAllocRaw(D,N) alloca(N) 004676 # define sqlite3StackAllocRawNN(D,N) alloca(N) 004677 # define sqlite3StackFree(D,P) 004678 # define sqlite3StackFreeNN(D,P) 004679 #else 004680 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) 004681 # define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N) 004682 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) 004683 # define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P) 004684 #endif 004685 004686 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they 004687 ** are, disable MEMSYS3 004688 */ 004689 #ifdef SQLITE_ENABLE_MEMSYS5 004690 const sqlite3_mem_methods *sqlite3MemGetMemsys5(void); 004691 #undef SQLITE_ENABLE_MEMSYS3 004692 #endif 004693 #ifdef SQLITE_ENABLE_MEMSYS3 004694 const sqlite3_mem_methods *sqlite3MemGetMemsys3(void); 004695 #endif 004696 004697 004698 #ifndef SQLITE_MUTEX_OMIT 004699 sqlite3_mutex_methods const *sqlite3DefaultMutex(void); 004700 sqlite3_mutex_methods const *sqlite3NoopMutex(void); 004701 sqlite3_mutex *sqlite3MutexAlloc(int); 004702 int sqlite3MutexInit(void); 004703 int sqlite3MutexEnd(void); 004704 #endif 004705 #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) 004706 void sqlite3MemoryBarrier(void); 004707 #else 004708 # define sqlite3MemoryBarrier() 004709 #endif 004710 004711 sqlite3_int64 sqlite3StatusValue(int); 004712 void sqlite3StatusUp(int, int); 004713 void sqlite3StatusDown(int, int); 004714 void sqlite3StatusHighwater(int, int); 004715 int sqlite3LookasideUsed(sqlite3*,int*); 004716 004717 /* Access to mutexes used by sqlite3_status() */ 004718 sqlite3_mutex *sqlite3Pcache1Mutex(void); 004719 sqlite3_mutex *sqlite3MallocMutex(void); 004720 004721 #if defined(SQLITE_ENABLE_MULTITHREADED_CHECKS) && !defined(SQLITE_MUTEX_OMIT) 004722 void sqlite3MutexWarnOnContention(sqlite3_mutex*); 004723 #else 004724 # define sqlite3MutexWarnOnContention(x) 004725 #endif 004726 004727 #ifndef SQLITE_OMIT_FLOATING_POINT 004728 # define EXP754 (((u64)0x7ff)<<52) 004729 # define MAN754 ((((u64)1)<<52)-1) 004730 # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0) 004731 # define IsOvfl(X) (((X)&EXP754)==EXP754) 004732 int sqlite3IsNaN(double); 004733 int sqlite3IsOverflow(double); 004734 #else 004735 # define IsNaN(X) 0 004736 # define sqlite3IsNaN(X) 0 004737 # define sqlite3IsOVerflow(X) 0 004738 #endif 004739 004740 /* 004741 ** An instance of the following structure holds information about SQL 004742 ** functions arguments that are the parameters to the printf() function. 004743 */ 004744 struct PrintfArguments { 004745 int nArg; /* Total number of arguments */ 004746 int nUsed; /* Number of arguments used so far */ 004747 sqlite3_value **apArg; /* The argument values */ 004748 }; 004749 004750 /* 004751 ** An instance of this object receives the decoding of a floating point 004752 ** value into an approximate decimal representation. 004753 */ 004754 struct FpDecode { 004755 char sign; /* '+' or '-' */ 004756 char isSpecial; /* 1: Infinity 2: NaN */ 004757 int n; /* Significant digits in the decode */ 004758 int iDP; /* Location of the decimal point */ 004759 char *z; /* Start of significant digits */ 004760 char zBuf[24]; /* Storage for significant digits */ 004761 }; 004762 004763 void sqlite3FpDecode(FpDecode*,double,int,int); 004764 char *sqlite3MPrintf(sqlite3*,const char*, ...); 004765 char *sqlite3VMPrintf(sqlite3*,const char*, va_list); 004766 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) 004767 void sqlite3DebugPrintf(const char*, ...); 004768 #endif 004769 #if defined(SQLITE_TEST) 004770 void *sqlite3TestTextToPtr(const char*); 004771 #endif 004772 004773 #if defined(SQLITE_DEBUG) 004774 void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...); 004775 void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); 004776 void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*); 004777 void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); 004778 void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*); 004779 void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*); 004780 void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8); 004781 void sqlite3TreeViewSrcList(TreeView*, const SrcList*); 004782 void sqlite3TreeViewSelect(TreeView*, const Select*, u8); 004783 void sqlite3TreeViewWith(TreeView*, const With*, u8); 004784 void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8); 004785 #if TREETRACE_ENABLED 004786 void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*, 004787 const ExprList*,const Expr*, const Trigger*); 004788 void sqlite3TreeViewInsert(const With*, const SrcList*, 004789 const IdList*, const Select*, const ExprList*, 004790 int, const Upsert*, const Trigger*); 004791 void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*, 004792 const Expr*, int, const ExprList*, const Expr*, 004793 const Upsert*, const Trigger*); 004794 #endif 004795 #ifndef SQLITE_OMIT_TRIGGER 004796 void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8); 004797 void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8); 004798 #endif 004799 #ifndef SQLITE_OMIT_WINDOWFUNC 004800 void sqlite3TreeViewWindow(TreeView*, const Window*, u8); 004801 void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8); 004802 #endif 004803 void sqlite3ShowExpr(const Expr*); 004804 void sqlite3ShowExprList(const ExprList*); 004805 void sqlite3ShowIdList(const IdList*); 004806 void sqlite3ShowSrcList(const SrcList*); 004807 void sqlite3ShowSelect(const Select*); 004808 void sqlite3ShowWith(const With*); 004809 void sqlite3ShowUpsert(const Upsert*); 004810 #ifndef SQLITE_OMIT_TRIGGER 004811 void sqlite3ShowTriggerStep(const TriggerStep*); 004812 void sqlite3ShowTriggerStepList(const TriggerStep*); 004813 void sqlite3ShowTrigger(const Trigger*); 004814 void sqlite3ShowTriggerList(const Trigger*); 004815 #endif 004816 #ifndef SQLITE_OMIT_WINDOWFUNC 004817 void sqlite3ShowWindow(const Window*); 004818 void sqlite3ShowWinFunc(const Window*); 004819 #endif 004820 #endif 004821 004822 void sqlite3SetString(char **, sqlite3*, const char*); 004823 void sqlite3ProgressCheck(Parse*); 004824 void sqlite3ErrorMsg(Parse*, const char*, ...); 004825 int sqlite3ErrorToParser(sqlite3*,int); 004826 void sqlite3Dequote(char*); 004827 void sqlite3DequoteExpr(Expr*); 004828 void sqlite3DequoteToken(Token*); 004829 void sqlite3DequoteNumber(Parse*, Expr*); 004830 void sqlite3TokenInit(Token*,char*); 004831 int sqlite3KeywordCode(const unsigned char*, int); 004832 int sqlite3RunParser(Parse*, const char*); 004833 void sqlite3FinishCoding(Parse*); 004834 int sqlite3GetTempReg(Parse*); 004835 void sqlite3ReleaseTempReg(Parse*,int); 004836 int sqlite3GetTempRange(Parse*,int); 004837 void sqlite3ReleaseTempRange(Parse*,int,int); 004838 void sqlite3ClearTempRegCache(Parse*); 004839 void sqlite3TouchRegister(Parse*,int); 004840 #if defined(SQLITE_ENABLE_STAT4) || defined(SQLITE_DEBUG) 004841 int sqlite3FirstAvailableRegister(Parse*,int); 004842 #endif 004843 #ifdef SQLITE_DEBUG 004844 int sqlite3NoTempsInRange(Parse*,int,int); 004845 #endif 004846 Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); 004847 Expr *sqlite3Expr(sqlite3*,int,const char*); 004848 void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); 004849 Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*); 004850 void sqlite3PExprAddSelect(Parse*, Expr*, Select*); 004851 Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*); 004852 Expr *sqlite3ExprSimplifiedAndOr(Expr*); 004853 Expr *sqlite3ExprFunction(Parse*,ExprList*, const Token*, int); 004854 void sqlite3ExprAddFunctionOrderBy(Parse*,Expr*,ExprList*); 004855 void sqlite3ExprOrderByAggregateError(Parse*,Expr*); 004856 void sqlite3ExprFunctionUsable(Parse*,const Expr*,const FuncDef*); 004857 void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); 004858 void sqlite3ExprDelete(sqlite3*, Expr*); 004859 void sqlite3ExprDeleteGeneric(sqlite3*,void*); 004860 int sqlite3ExprDeferredDelete(Parse*, Expr*); 004861 void sqlite3ExprUnmapAndDelete(Parse*, Expr*); 004862 ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); 004863 ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); 004864 Select *sqlite3ExprListToValues(Parse*, int, ExprList*); 004865 void sqlite3ExprListSetSortOrder(ExprList*,int,int); 004866 void sqlite3ExprListSetName(Parse*,ExprList*,const Token*,int); 004867 void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); 004868 void sqlite3ExprListDelete(sqlite3*, ExprList*); 004869 void sqlite3ExprListDeleteGeneric(sqlite3*,void*); 004870 u32 sqlite3ExprListFlags(const ExprList*); 004871 int sqlite3IndexHasDuplicateRootPage(Index*); 004872 int sqlite3Init(sqlite3*, char**); 004873 int sqlite3InitCallback(void*, int, char**, char**); 004874 int sqlite3InitOne(sqlite3*, int, char**, u32); 004875 void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); 004876 #ifndef SQLITE_OMIT_VIRTUALTABLE 004877 Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName); 004878 #endif 004879 void sqlite3ResetAllSchemasOfConnection(sqlite3*); 004880 void sqlite3ResetOneSchema(sqlite3*,int); 004881 void sqlite3CollapseDatabaseArray(sqlite3*); 004882 void sqlite3CommitInternalChanges(sqlite3*); 004883 void sqlite3ColumnSetExpr(Parse*,Table*,Column*,Expr*); 004884 Expr *sqlite3ColumnExpr(Table*,Column*); 004885 void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl); 004886 const char *sqlite3ColumnColl(Column*); 004887 void sqlite3DeleteColumnNames(sqlite3*,Table*); 004888 void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect); 004889 int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); 004890 void sqlite3SubqueryColumnTypes(Parse*,Table*,Select*,char); 004891 Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); 004892 void sqlite3OpenSchemaTable(Parse *, int); 004893 Index *sqlite3PrimaryKeyIndex(Table*); 004894 i16 sqlite3TableColumnToIndex(Index*, i16); 004895 #ifdef SQLITE_OMIT_GENERATED_COLUMNS 004896 # define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */ 004897 # define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */ 004898 #else 004899 i16 sqlite3TableColumnToStorage(Table*, i16); 004900 i16 sqlite3StorageColumnToTable(Table*, i16); 004901 #endif 004902 void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); 004903 #if SQLITE_ENABLE_HIDDEN_COLUMNS 004904 void sqlite3ColumnPropertiesFromName(Table*, Column*); 004905 #else 004906 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ 004907 #endif 004908 void sqlite3AddColumn(Parse*,Token,Token); 004909 void sqlite3AddNotNull(Parse*, int); 004910 void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); 004911 void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*); 004912 void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); 004913 void sqlite3AddCollateType(Parse*, Token*); 004914 void sqlite3AddGenerated(Parse*,Expr*,Token*); 004915 void sqlite3EndTable(Parse*,Token*,Token*,u32,Select*); 004916 void sqlite3AddReturning(Parse*,ExprList*); 004917 int sqlite3ParseUri(const char*,const char*,unsigned int*, 004918 sqlite3_vfs**,char**,char **); 004919 #define sqlite3CodecQueryParameters(A,B,C) 0 004920 Btree *sqlite3DbNameToBtree(sqlite3*,const char*); 004921 004922 #ifdef SQLITE_UNTESTABLE 004923 # define sqlite3FaultSim(X) SQLITE_OK 004924 #else 004925 int sqlite3FaultSim(int); 004926 #endif 004927 004928 Bitvec *sqlite3BitvecCreate(u32); 004929 int sqlite3BitvecTest(Bitvec*, u32); 004930 int sqlite3BitvecTestNotNull(Bitvec*, u32); 004931 int sqlite3BitvecSet(Bitvec*, u32); 004932 void sqlite3BitvecClear(Bitvec*, u32, void*); 004933 void sqlite3BitvecDestroy(Bitvec*); 004934 u32 sqlite3BitvecSize(Bitvec*); 004935 #ifndef SQLITE_UNTESTABLE 004936 int sqlite3BitvecBuiltinTest(int,int*); 004937 #endif 004938 004939 RowSet *sqlite3RowSetInit(sqlite3*); 004940 void sqlite3RowSetDelete(void*); 004941 void sqlite3RowSetClear(void*); 004942 void sqlite3RowSetInsert(RowSet*, i64); 004943 int sqlite3RowSetTest(RowSet*, int iBatch, i64); 004944 int sqlite3RowSetNext(RowSet*, i64*); 004945 004946 void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int); 004947 004948 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) 004949 int sqlite3ViewGetColumnNames(Parse*,Table*); 004950 #else 004951 # define sqlite3ViewGetColumnNames(A,B) 0 004952 #endif 004953 004954 #if SQLITE_MAX_ATTACHED>30 004955 int sqlite3DbMaskAllZero(yDbMask); 004956 #endif 004957 void sqlite3DropTable(Parse*, SrcList*, int, int); 004958 void sqlite3CodeDropTable(Parse*, Table*, int, int); 004959 void sqlite3DeleteTable(sqlite3*, Table*); 004960 void sqlite3DeleteTableGeneric(sqlite3*, void*); 004961 void sqlite3FreeIndex(sqlite3*, Index*); 004962 #ifndef SQLITE_OMIT_AUTOINCREMENT 004963 void sqlite3AutoincrementBegin(Parse *pParse); 004964 void sqlite3AutoincrementEnd(Parse *pParse); 004965 #else 004966 # define sqlite3AutoincrementBegin(X) 004967 # define sqlite3AutoincrementEnd(X) 004968 #endif 004969 void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int, Upsert*); 004970 #ifndef SQLITE_OMIT_GENERATED_COLUMNS 004971 void sqlite3ComputeGeneratedColumns(Parse*, int, Table*); 004972 #endif 004973 void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*); 004974 IdList *sqlite3IdListAppend(Parse*, IdList*, Token*); 004975 int sqlite3IdListIndex(IdList*,const char*); 004976 SrcList *sqlite3SrcListEnlarge(Parse*, SrcList*, int, int); 004977 SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2); 004978 SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*); 004979 SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, 004980 Token*, Select*, OnOrUsing*); 004981 void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *); 004982 void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*); 004983 int sqlite3IndexedByLookup(Parse *, SrcItem *); 004984 void sqlite3SrcListShiftJoinType(Parse*,SrcList*); 004985 void sqlite3SrcListAssignCursors(Parse*, SrcList*); 004986 void sqlite3IdListDelete(sqlite3*, IdList*); 004987 void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*); 004988 void sqlite3SrcListDelete(sqlite3*, SrcList*); 004989 Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**); 004990 void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, 004991 Expr*, int, int, u8); 004992 void sqlite3DropIndex(Parse*, SrcList*, int); 004993 int sqlite3Select(Parse*, Select*, SelectDest*); 004994 Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, 004995 Expr*,ExprList*,u32,Expr*); 004996 void sqlite3SelectDelete(sqlite3*, Select*); 004997 void sqlite3SelectDeleteGeneric(sqlite3*,void*); 004998 Table *sqlite3SrcListLookup(Parse*, SrcList*); 004999 int sqlite3IsReadOnly(Parse*, Table*, Trigger*); 005000 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); 005001 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) 005002 Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*); 005003 #endif 005004 void sqlite3CodeChangeCount(Vdbe*,int,const char*); 005005 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*); 005006 void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*, 005007 Upsert*); 005008 WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*, 005009 ExprList*,Select*,u16,int); 005010 void sqlite3WhereEnd(WhereInfo*); 005011 LogEst sqlite3WhereOutputRowCount(WhereInfo*); 005012 int sqlite3WhereIsDistinct(WhereInfo*); 005013 int sqlite3WhereIsOrdered(WhereInfo*); 005014 int sqlite3WhereOrderByLimitOptLabel(WhereInfo*); 005015 void sqlite3WhereMinMaxOptEarlyOut(Vdbe*,WhereInfo*); 005016 int sqlite3WhereIsSorted(WhereInfo*); 005017 int sqlite3WhereContinueLabel(WhereInfo*); 005018 int sqlite3WhereBreakLabel(WhereInfo*); 005019 int sqlite3WhereOkOnePass(WhereInfo*, int*); 005020 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ 005021 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ 005022 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ 005023 int sqlite3WhereUsesDeferredSeek(WhereInfo*); 005024 void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); 005025 int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); 005026 void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); 005027 void sqlite3ExprCodeMove(Parse*, int, int, int); 005028 void sqlite3ExprCode(Parse*, Expr*, int); 005029 #ifndef SQLITE_OMIT_GENERATED_COLUMNS 005030 void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int); 005031 #endif 005032 void sqlite3ExprCodeCopy(Parse*, Expr*, int); 005033 void sqlite3ExprCodeFactorable(Parse*, Expr*, int); 005034 int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int); 005035 int sqlite3ExprCodeTemp(Parse*, Expr*, int*); 005036 int sqlite3ExprCodeTarget(Parse*, Expr*, int); 005037 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); 005038 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ 005039 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ 005040 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */ 005041 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */ 005042 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 005043 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 005044 void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); 005045 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 005046 #define LOCATE_VIEW 0x01 005047 #define LOCATE_NOERR 0x02 005048 Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*); 005049 const char *sqlite3PreferredTableName(const char*); 005050 Table *sqlite3LocateTableItem(Parse*,u32 flags,SrcItem *); 005051 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 005052 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 005053 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 005054 void sqlite3Vacuum(Parse*,Token*,Expr*); 005055 int sqlite3RunVacuum(char**, sqlite3*, int, sqlite3_value*); 005056 char *sqlite3NameFromToken(sqlite3*, const Token*); 005057 int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int); 005058 int sqlite3ExprCompareSkip(Expr*,Expr*,int); 005059 int sqlite3ExprListCompare(const ExprList*,const ExprList*, int); 005060 int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int); 005061 int sqlite3ExprImpliesNonNullRow(Expr*,int,int); 005062 void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); 005063 void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); 005064 void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); 005065 int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); 005066 int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); 005067 Vdbe *sqlite3GetVdbe(Parse*); 005068 #ifndef SQLITE_UNTESTABLE 005069 void sqlite3PrngSaveState(void); 005070 void sqlite3PrngRestoreState(void); 005071 #endif 005072 void sqlite3RollbackAll(sqlite3*,int); 005073 void sqlite3CodeVerifySchema(Parse*, int); 005074 void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); 005075 void sqlite3BeginTransaction(Parse*, int); 005076 void sqlite3EndTransaction(Parse*,int); 005077 void sqlite3Savepoint(Parse*, int, Token*); 005078 void sqlite3CloseSavepoints(sqlite3 *); 005079 void sqlite3LeaveMutexAndCloseZombie(sqlite3*); 005080 u32 sqlite3IsTrueOrFalse(const char*); 005081 int sqlite3ExprIdToTrueFalse(Expr*); 005082 int sqlite3ExprTruthValue(const Expr*); 005083 int sqlite3ExprIsConstant(Parse*,Expr*); 005084 int sqlite3ExprIsConstantOrFunction(Expr*, u8); 005085 int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); 005086 int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int); 005087 #ifdef SQLITE_ENABLE_CURSOR_HINTS 005088 int sqlite3ExprContainsSubquery(Expr*); 005089 #endif 005090 int sqlite3ExprIsInteger(const Expr*, int*); 005091 int sqlite3ExprCanBeNull(const Expr*); 005092 int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); 005093 int sqlite3IsRowid(const char*); 005094 const char *sqlite3RowidAlias(Table *pTab); 005095 void sqlite3GenerateRowDelete( 005096 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); 005097 void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); 005098 int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); 005099 void sqlite3ResolvePartIdxLabel(Parse*,int); 005100 int sqlite3ExprReferencesUpdatedColumn(Expr*,int*,int); 005101 void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, 005102 u8,u8,int,int*,int*,Upsert*); 005103 #ifdef SQLITE_ENABLE_NULL_TRIM 005104 void sqlite3SetMakeRecordP5(Vdbe*,Table*); 005105 #else 005106 # define sqlite3SetMakeRecordP5(A,B) 005107 #endif 005108 void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); 005109 int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); 005110 void sqlite3BeginWriteOperation(Parse*, int, int); 005111 void sqlite3MultiWrite(Parse*); 005112 void sqlite3MayAbort(Parse*); 005113 void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); 005114 void sqlite3UniqueConstraint(Parse*, int, Index*); 005115 void sqlite3RowidConstraint(Parse*, int, Table*); 005116 Expr *sqlite3ExprDup(sqlite3*,const Expr*,int); 005117 ExprList *sqlite3ExprListDup(sqlite3*,const ExprList*,int); 005118 SrcList *sqlite3SrcListDup(sqlite3*,const SrcList*,int); 005119 IdList *sqlite3IdListDup(sqlite3*,const IdList*); 005120 Select *sqlite3SelectDup(sqlite3*,const Select*,int); 005121 FuncDef *sqlite3FunctionSearch(int,const char*); 005122 void sqlite3InsertBuiltinFuncs(FuncDef*,int); 005123 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); 005124 void sqlite3QuoteValue(StrAccum*,sqlite3_value*); 005125 void sqlite3RegisterBuiltinFunctions(void); 005126 void sqlite3RegisterDateTimeFunctions(void); 005127 void sqlite3RegisterJsonFunctions(void); 005128 void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); 005129 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) 005130 int sqlite3JsonTableFunctions(sqlite3*); 005131 #endif 005132 int sqlite3SafetyCheckOk(sqlite3*); 005133 int sqlite3SafetyCheckSickOrOk(sqlite3*); 005134 void sqlite3ChangeCookie(Parse*, int); 005135 With *sqlite3WithDup(sqlite3 *db, With *p); 005136 005137 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) 005138 void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int); 005139 #endif 005140 005141 #ifndef SQLITE_OMIT_TRIGGER 005142 void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*, 005143 Expr*,int, int); 005144 void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*); 005145 void sqlite3DropTrigger(Parse*, SrcList*, int); 005146 void sqlite3DropTriggerPtr(Parse*, Trigger*); 005147 Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask); 005148 Trigger *sqlite3TriggerList(Parse *, Table *); 005149 void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *, 005150 int, int, int); 005151 void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int); 005152 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*); 005153 void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*); 005154 TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*, 005155 const char*,const char*); 005156 TriggerStep *sqlite3TriggerInsertStep(Parse*,Token*, IdList*, 005157 Select*,u8,Upsert*, 005158 const char*,const char*); 005159 TriggerStep *sqlite3TriggerUpdateStep(Parse*,Token*,SrcList*,ExprList*, 005160 Expr*, u8, const char*,const char*); 005161 TriggerStep *sqlite3TriggerDeleteStep(Parse*,Token*, Expr*, 005162 const char*,const char*); 005163 void sqlite3DeleteTrigger(sqlite3*, Trigger*); 005164 void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*); 005165 u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int); 005166 SrcList *sqlite3TriggerStepSrc(Parse*, TriggerStep*); 005167 # define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p)) 005168 # define sqlite3IsToplevel(p) ((p)->pToplevel==0) 005169 #else 005170 # define sqlite3TriggersExist(B,C,D,E,F) 0 005171 # define sqlite3DeleteTrigger(A,B) 005172 # define sqlite3DropTriggerPtr(A,B) 005173 # define sqlite3UnlinkAndDeleteTrigger(A,B,C) 005174 # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 005175 # define sqlite3CodeRowTriggerDirect(A,B,C,D,E,F) 005176 # define sqlite3TriggerList(X, Y) 0 005177 # define sqlite3ParseToplevel(p) p 005178 # define sqlite3IsToplevel(p) 1 005179 # define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0 005180 # define sqlite3TriggerStepSrc(A,B) 0 005181 #endif 005182 005183 int sqlite3JoinType(Parse*, Token*, Token*, Token*); 005184 int sqlite3ColumnIndex(Table *pTab, const char *zCol); 005185 void sqlite3SrcItemColumnUsed(SrcItem*,int); 005186 void sqlite3SetJoinExpr(Expr*,int,u32); 005187 void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int); 005188 void sqlite3DeferForeignKey(Parse*, int); 005189 #ifndef SQLITE_OMIT_AUTHORIZATION 005190 void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*); 005191 int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*); 005192 void sqlite3AuthContextPush(Parse*, AuthContext*, const char*); 005193 void sqlite3AuthContextPop(AuthContext*); 005194 int sqlite3AuthReadCol(Parse*, const char *, const char *, int); 005195 #else 005196 # define sqlite3AuthRead(a,b,c,d) 005197 # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK 005198 # define sqlite3AuthContextPush(a,b,c) 005199 # define sqlite3AuthContextPop(a) ((void)(a)) 005200 #endif 005201 int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName); 005202 void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); 005203 void sqlite3Detach(Parse*, Expr*); 005204 void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); 005205 int sqlite3FixSrcList(DbFixer*, SrcList*); 005206 int sqlite3FixSelect(DbFixer*, Select*); 005207 int sqlite3FixExpr(DbFixer*, Expr*); 005208 int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); 005209 005210 int sqlite3RealSameAsInt(double,sqlite3_int64); 005211 i64 sqlite3RealToI64(double); 005212 int sqlite3Int64ToText(i64,char*); 005213 int sqlite3AtoF(const char *z, double*, int, u8); 005214 int sqlite3GetInt32(const char *, int*); 005215 int sqlite3GetUInt32(const char*, u32*); 005216 int sqlite3Atoi(const char*); 005217 #ifndef SQLITE_OMIT_UTF16 005218 int sqlite3Utf16ByteLen(const void *pData, int nChar); 005219 #endif 005220 int sqlite3Utf8CharLen(const char *pData, int nByte); 005221 u32 sqlite3Utf8Read(const u8**); 005222 int sqlite3Utf8ReadLimited(const u8*, int, u32*); 005223 LogEst sqlite3LogEst(u64); 005224 LogEst sqlite3LogEstAdd(LogEst,LogEst); 005225 LogEst sqlite3LogEstFromDouble(double); 005226 u64 sqlite3LogEstToInt(LogEst); 005227 VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int); 005228 const char *sqlite3VListNumToName(VList*,int); 005229 int sqlite3VListNameToNum(VList*,const char*,int); 005230 005231 /* 005232 ** Routines to read and write variable-length integers. These used to 005233 ** be defined locally, but now we use the varint routines in the util.c 005234 ** file. 005235 */ 005236 int sqlite3PutVarint(unsigned char*, u64); 005237 u8 sqlite3GetVarint(const unsigned char *, u64 *); 005238 u8 sqlite3GetVarint32(const unsigned char *, u32 *); 005239 int sqlite3VarintLen(u64 v); 005240 005241 /* 005242 ** The common case is for a varint to be a single byte. They following 005243 ** macros handle the common case without a procedure call, but then call 005244 ** the procedure for larger varints. 005245 */ 005246 #define getVarint32(A,B) \ 005247 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) 005248 #define getVarint32NR(A,B) \ 005249 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B)) 005250 #define putVarint32(A,B) \ 005251 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ 005252 sqlite3PutVarint((A),(B))) 005253 #define getVarint sqlite3GetVarint 005254 #define putVarint sqlite3PutVarint 005255 005256 005257 const char *sqlite3IndexAffinityStr(sqlite3*, Index*); 005258 char *sqlite3TableAffinityStr(sqlite3*,const Table*); 005259 void sqlite3TableAffinity(Vdbe*, Table*, int); 005260 char sqlite3CompareAffinity(const Expr *pExpr, char aff2); 005261 int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity); 005262 char sqlite3TableColumnAffinity(const Table*,int); 005263 char sqlite3ExprAffinity(const Expr *pExpr); 005264 int sqlite3ExprDataType(const Expr *pExpr); 005265 int sqlite3Atoi64(const char*, i64*, int, u8); 005266 int sqlite3DecOrHexToI64(const char*, i64*); 005267 void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); 005268 void sqlite3Error(sqlite3*,int); 005269 void sqlite3ErrorClear(sqlite3*); 005270 void sqlite3SystemError(sqlite3*,int); 005271 #if !defined(SQLITE_OMIT_BLOB_LITERAL) 005272 void *sqlite3HexToBlob(sqlite3*, const char *z, int n); 005273 #endif 005274 u8 sqlite3HexToInt(int h); 005275 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); 005276 005277 #if defined(SQLITE_NEED_ERR_NAME) 005278 const char *sqlite3ErrName(int); 005279 #endif 005280 005281 #ifndef SQLITE_OMIT_DESERIALIZE 005282 int sqlite3MemdbInit(void); 005283 int sqlite3IsMemdb(const sqlite3_vfs*); 005284 #else 005285 # define sqlite3IsMemdb(X) 0 005286 #endif 005287 005288 const char *sqlite3ErrStr(int); 005289 int sqlite3ReadSchema(Parse *pParse); 005290 CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); 005291 int sqlite3IsBinary(const CollSeq*); 005292 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); 005293 void sqlite3SetTextEncoding(sqlite3 *db, u8); 005294 CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr); 005295 CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr); 005296 int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*); 005297 Expr *sqlite3ExprAddCollateToken(const Parse *pParse, Expr*, const Token*, int); 005298 Expr *sqlite3ExprAddCollateString(const Parse*,Expr*,const char*); 005299 Expr *sqlite3ExprSkipCollate(Expr*); 005300 Expr *sqlite3ExprSkipCollateAndLikely(Expr*); 005301 int sqlite3CheckCollSeq(Parse *, CollSeq *); 005302 int sqlite3WritableSchema(sqlite3*); 005303 int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*); 005304 void sqlite3VdbeSetChanges(sqlite3 *, i64); 005305 int sqlite3AddInt64(i64*,i64); 005306 int sqlite3SubInt64(i64*,i64); 005307 int sqlite3MulInt64(i64*,i64); 005308 int sqlite3AbsInt32(int); 005309 #ifdef SQLITE_ENABLE_8_3_NAMES 005310 void sqlite3FileSuffix3(const char*, char*); 005311 #else 005312 # define sqlite3FileSuffix3(X,Y) 005313 #endif 005314 u8 sqlite3GetBoolean(const char *z,u8); 005315 005316 const void *sqlite3ValueText(sqlite3_value*, u8); 005317 int sqlite3ValueIsOfClass(const sqlite3_value*, void(*)(void*)); 005318 int sqlite3ValueBytes(sqlite3_value*, u8); 005319 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 005320 void(*)(void*)); 005321 void sqlite3ValueSetNull(sqlite3_value*); 005322 void sqlite3ValueFree(sqlite3_value*); 005323 #ifndef SQLITE_UNTESTABLE 005324 void sqlite3ResultIntReal(sqlite3_context*); 005325 #endif 005326 sqlite3_value *sqlite3ValueNew(sqlite3 *); 005327 #ifndef SQLITE_OMIT_UTF16 005328 char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); 005329 #endif 005330 int sqlite3ValueFromExpr(sqlite3 *, const Expr *, u8, u8, sqlite3_value **); 005331 void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); 005332 #ifndef SQLITE_AMALGAMATION 005333 extern const unsigned char sqlite3OpcodeProperty[]; 005334 extern const char sqlite3StrBINARY[]; 005335 extern const unsigned char sqlite3StdTypeLen[]; 005336 extern const char sqlite3StdTypeAffinity[]; 005337 extern const char *sqlite3StdType[]; 005338 extern const unsigned char sqlite3UpperToLower[]; 005339 extern const unsigned char *sqlite3aLTb; 005340 extern const unsigned char *sqlite3aEQb; 005341 extern const unsigned char *sqlite3aGTb; 005342 extern const unsigned char sqlite3CtypeMap[]; 005343 extern SQLITE_WSD struct Sqlite3Config sqlite3Config; 005344 extern FuncDefHash sqlite3BuiltinFunctions; 005345 #ifndef SQLITE_OMIT_WSD 005346 extern int sqlite3PendingByte; 005347 #endif 005348 #endif /* SQLITE_AMALGAMATION */ 005349 #ifdef VDBE_PROFILE 005350 extern sqlite3_uint64 sqlite3NProfileCnt; 005351 #endif 005352 void sqlite3RootPageMoved(sqlite3*, int, Pgno, Pgno); 005353 void sqlite3Reindex(Parse*, Token*, Token*); 005354 void sqlite3AlterFunctions(void); 005355 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); 005356 void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); 005357 int sqlite3GetToken(const unsigned char *, int *); 005358 void sqlite3NestedParse(Parse*, const char*, ...); 005359 void sqlite3ExpirePreparedStatements(sqlite3*, int); 005360 void sqlite3CodeRhsOfIN(Parse*, Expr*, int); 005361 int sqlite3CodeSubselect(Parse*, Expr*); 005362 void sqlite3SelectPrep(Parse*, Select*, NameContext*); 005363 int sqlite3ExpandSubquery(Parse*, SrcItem*); 005364 void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); 005365 int sqlite3MatchEName( 005366 const struct ExprList_item*, 005367 const char*, 005368 const char*, 005369 const char*, 005370 int* 005371 ); 005372 Bitmask sqlite3ExprColUsed(Expr*); 005373 u8 sqlite3StrIHash(const char*); 005374 int sqlite3ResolveExprNames(NameContext*, Expr*); 005375 int sqlite3ResolveExprListNames(NameContext*, ExprList*); 005376 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); 005377 int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); 005378 int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); 005379 void sqlite3ColumnDefault(Vdbe *, Table *, int, int); 005380 void sqlite3AlterFinishAddColumn(Parse *, Token *); 005381 void sqlite3AlterBeginAddColumn(Parse *, SrcList *); 005382 void sqlite3AlterDropColumn(Parse*, SrcList*, const Token*); 005383 const void *sqlite3RenameTokenMap(Parse*, const void*, const Token*); 005384 void sqlite3RenameTokenRemap(Parse*, const void *pTo, const void *pFrom); 005385 void sqlite3RenameExprUnmap(Parse*, Expr*); 005386 void sqlite3RenameExprlistUnmap(Parse*, ExprList*); 005387 CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); 005388 char sqlite3AffinityType(const char*, Column*); 005389 void sqlite3Analyze(Parse*, Token*, Token*); 005390 int sqlite3InvokeBusyHandler(BusyHandler*); 005391 int sqlite3FindDb(sqlite3*, Token*); 005392 int sqlite3FindDbName(sqlite3 *, const char *); 005393 int sqlite3AnalysisLoad(sqlite3*,int iDB); 005394 void sqlite3DeleteIndexSamples(sqlite3*,Index*); 005395 void sqlite3DefaultRowEst(Index*); 005396 void sqlite3RegisterLikeFunctions(sqlite3*, int); 005397 int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); 005398 void sqlite3SchemaClear(void *); 005399 Schema *sqlite3SchemaGet(sqlite3 *, Btree *); 005400 int sqlite3SchemaToIndex(sqlite3 *db, Schema *); 005401 KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); 005402 void sqlite3KeyInfoUnref(KeyInfo*); 005403 KeyInfo *sqlite3KeyInfoRef(KeyInfo*); 005404 KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); 005405 KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int); 005406 const char *sqlite3SelectOpName(int); 005407 int sqlite3HasExplicitNulls(Parse*, ExprList*); 005408 005409 #ifdef SQLITE_DEBUG 005410 int sqlite3KeyInfoIsWriteable(KeyInfo*); 005411 #endif 005412 int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 005413 void (*)(sqlite3_context*,int,sqlite3_value **), 005414 void (*)(sqlite3_context*,int,sqlite3_value **), 005415 void (*)(sqlite3_context*), 005416 void (*)(sqlite3_context*), 005417 void (*)(sqlite3_context*,int,sqlite3_value **), 005418 FuncDestructor *pDestructor 005419 ); 005420 void sqlite3NoopDestructor(void*); 005421 void *sqlite3OomFault(sqlite3*); 005422 void sqlite3OomClear(sqlite3*); 005423 int sqlite3ApiExit(sqlite3 *db, int); 005424 int sqlite3OpenTempDatabase(Parse *); 005425 005426 char *sqlite3RCStrRef(char*); 005427 void sqlite3RCStrUnref(void*); 005428 char *sqlite3RCStrNew(u64); 005429 char *sqlite3RCStrResize(char*,u64); 005430 005431 void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); 005432 int sqlite3StrAccumEnlarge(StrAccum*, i64); 005433 char *sqlite3StrAccumFinish(StrAccum*); 005434 void sqlite3StrAccumSetError(StrAccum*, u8); 005435 void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); 005436 void sqlite3SelectDestInit(SelectDest*,int,int); 005437 Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); 005438 void sqlite3RecordErrorByteOffset(sqlite3*,const char*); 005439 void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*); 005440 005441 void sqlite3BackupRestart(sqlite3_backup *); 005442 void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); 005443 005444 #ifndef SQLITE_OMIT_SUBQUERY 005445 int sqlite3ExprCheckIN(Parse*, Expr*); 005446 #else 005447 # define sqlite3ExprCheckIN(x,y) SQLITE_OK 005448 #endif 005449 005450 #ifdef SQLITE_ENABLE_STAT4 005451 int sqlite3Stat4ProbeSetValue( 005452 Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*); 005453 int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**); 005454 void sqlite3Stat4ProbeFree(UnpackedRecord*); 005455 int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**); 005456 char sqlite3IndexColumnAffinity(sqlite3*, Index*, int); 005457 #endif 005458 005459 /* 005460 ** The interface to the LEMON-generated parser 005461 */ 005462 #ifndef SQLITE_AMALGAMATION 005463 void *sqlite3ParserAlloc(void*(*)(u64), Parse*); 005464 void sqlite3ParserFree(void*, void(*)(void*)); 005465 #endif 005466 void sqlite3Parser(void*, int, Token); 005467 int sqlite3ParserFallback(int); 005468 #ifdef YYTRACKMAXSTACKDEPTH 005469 int sqlite3ParserStackPeak(void*); 005470 #endif 005471 005472 void sqlite3AutoLoadExtensions(sqlite3*); 005473 #ifndef SQLITE_OMIT_LOAD_EXTENSION 005474 void sqlite3CloseExtensions(sqlite3*); 005475 #else 005476 # define sqlite3CloseExtensions(X) 005477 #endif 005478 005479 #ifndef SQLITE_OMIT_SHARED_CACHE 005480 void sqlite3TableLock(Parse *, int, Pgno, u8, const char *); 005481 #else 005482 #define sqlite3TableLock(v,w,x,y,z) 005483 #endif 005484 005485 #ifdef SQLITE_TEST 005486 int sqlite3Utf8To8(unsigned char*); 005487 #endif 005488 005489 #ifdef SQLITE_OMIT_VIRTUALTABLE 005490 # define sqlite3VtabClear(D,T) 005491 # define sqlite3VtabSync(X,Y) SQLITE_OK 005492 # define sqlite3VtabRollback(X) 005493 # define sqlite3VtabCommit(X) 005494 # define sqlite3VtabInSync(db) 0 005495 # define sqlite3VtabLock(X) 005496 # define sqlite3VtabUnlock(X) 005497 # define sqlite3VtabModuleUnref(D,X) 005498 # define sqlite3VtabUnlockList(X) 005499 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK 005500 # define sqlite3GetVTable(X,Y) ((VTable*)0) 005501 #else 005502 void sqlite3VtabClear(sqlite3 *db, Table*); 005503 void sqlite3VtabDisconnect(sqlite3 *db, Table *p); 005504 int sqlite3VtabSync(sqlite3 *db, Vdbe*); 005505 int sqlite3VtabRollback(sqlite3 *db); 005506 int sqlite3VtabCommit(sqlite3 *db); 005507 void sqlite3VtabLock(VTable *); 005508 void sqlite3VtabUnlock(VTable *); 005509 void sqlite3VtabModuleUnref(sqlite3*,Module*); 005510 void sqlite3VtabUnlockList(sqlite3*); 005511 int sqlite3VtabSavepoint(sqlite3 *, int, int); 005512 void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); 005513 VTable *sqlite3GetVTable(sqlite3*, Table*); 005514 Module *sqlite3VtabCreateModule( 005515 sqlite3*, 005516 const char*, 005517 const sqlite3_module*, 005518 void*, 005519 void(*)(void*) 005520 ); 005521 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) 005522 #endif 005523 int sqlite3ReadOnlyShadowTables(sqlite3 *db); 005524 #ifndef SQLITE_OMIT_VIRTUALTABLE 005525 int sqlite3ShadowTableName(sqlite3 *db, const char *zName); 005526 int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); 005527 void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*); 005528 #else 005529 # define sqlite3ShadowTableName(A,B) 0 005530 # define sqlite3IsShadowTableOf(A,B,C) 0 005531 # define sqlite3MarkAllShadowTablesOf(A,B) 005532 #endif 005533 int sqlite3VtabEponymousTableInit(Parse*,Module*); 005534 void sqlite3VtabEponymousTableClear(sqlite3*,Module*); 005535 void sqlite3VtabMakeWritable(Parse*,Table*); 005536 void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); 005537 void sqlite3VtabFinishParse(Parse*, Token*); 005538 void sqlite3VtabArgInit(Parse*); 005539 void sqlite3VtabArgExtend(Parse*, Token*); 005540 int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); 005541 int sqlite3VtabCallConnect(Parse*, Table*); 005542 int sqlite3VtabCallDestroy(sqlite3*, int, const char *); 005543 int sqlite3VtabBegin(sqlite3 *, VTable *); 005544 005545 FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); 005546 void sqlite3VtabUsesAllSchemas(Parse*); 005547 sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); 005548 int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); 005549 int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); 005550 void sqlite3ParseObjectInit(Parse*,sqlite3*); 005551 void sqlite3ParseObjectReset(Parse*); 005552 void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*); 005553 #ifdef SQLITE_ENABLE_NORMALIZE 005554 char *sqlite3Normalize(Vdbe*, const char*); 005555 #endif 005556 int sqlite3Reprepare(Vdbe*); 005557 void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); 005558 CollSeq *sqlite3ExprCompareCollSeq(Parse*,const Expr*); 005559 CollSeq *sqlite3BinaryCompareCollSeq(Parse *, const Expr*, const Expr*); 005560 int sqlite3TempInMemory(const sqlite3*); 005561 const char *sqlite3JournalModename(int); 005562 #ifndef SQLITE_OMIT_WAL 005563 int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); 005564 int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); 005565 #endif 005566 #ifndef SQLITE_OMIT_CTE 005567 Cte *sqlite3CteNew(Parse*,Token*,ExprList*,Select*,u8); 005568 void sqlite3CteDelete(sqlite3*,Cte*); 005569 With *sqlite3WithAdd(Parse*,With*,Cte*); 005570 void sqlite3WithDelete(sqlite3*,With*); 005571 void sqlite3WithDeleteGeneric(sqlite3*,void*); 005572 With *sqlite3WithPush(Parse*, With*, u8); 005573 #else 005574 # define sqlite3CteNew(P,T,E,S) ((void*)0) 005575 # define sqlite3CteDelete(D,C) 005576 # define sqlite3CteWithAdd(P,W,C) ((void*)0) 005577 # define sqlite3WithDelete(x,y) 005578 # define sqlite3WithPush(x,y,z) ((void*)0) 005579 #endif 005580 #ifndef SQLITE_OMIT_UPSERT 005581 Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*); 005582 void sqlite3UpsertDelete(sqlite3*,Upsert*); 005583 Upsert *sqlite3UpsertDup(sqlite3*,Upsert*); 005584 int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*,Upsert*); 005585 void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int); 005586 Upsert *sqlite3UpsertOfIndex(Upsert*,Index*); 005587 int sqlite3UpsertNextIsIPK(Upsert*); 005588 #else 005589 #define sqlite3UpsertNew(u,v,w,x,y,z) ((Upsert*)0) 005590 #define sqlite3UpsertDelete(x,y) 005591 #define sqlite3UpsertDup(x,y) ((Upsert*)0) 005592 #define sqlite3UpsertOfIndex(x,y) ((Upsert*)0) 005593 #define sqlite3UpsertNextIsIPK(x) 0 005594 #endif 005595 005596 005597 /* Declarations for functions in fkey.c. All of these are replaced by 005598 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign 005599 ** key functionality is available. If OMIT_TRIGGER is defined but 005600 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In 005601 ** this case foreign keys are parsed, but no other functionality is 005602 ** provided (enforcement of FK constraints requires the triggers sub-system). 005603 */ 005604 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) 005605 void sqlite3FkCheck(Parse*, Table*, int, int, int*, int); 005606 void sqlite3FkDropTable(Parse*, SrcList *, Table*); 005607 void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int); 005608 int sqlite3FkRequired(Parse*, Table*, int*, int); 005609 u32 sqlite3FkOldmask(Parse*, Table*); 005610 FKey *sqlite3FkReferences(Table *); 005611 void sqlite3FkClearTriggerCache(sqlite3*,int); 005612 #else 005613 #define sqlite3FkActions(a,b,c,d,e,f) 005614 #define sqlite3FkCheck(a,b,c,d,e,f) 005615 #define sqlite3FkDropTable(a,b,c) 005616 #define sqlite3FkOldmask(a,b) 0 005617 #define sqlite3FkRequired(a,b,c,d) 0 005618 #define sqlite3FkReferences(a) 0 005619 #define sqlite3FkClearTriggerCache(a,b) 005620 #endif 005621 #ifndef SQLITE_OMIT_FOREIGN_KEY 005622 void sqlite3FkDelete(sqlite3 *, Table*); 005623 int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); 005624 #else 005625 #define sqlite3FkDelete(a,b) 005626 #define sqlite3FkLocateIndex(a,b,c,d,e) 005627 #endif 005628 005629 005630 /* 005631 ** Available fault injectors. Should be numbered beginning with 0. 005632 */ 005633 #define SQLITE_FAULTINJECTOR_MALLOC 0 005634 #define SQLITE_FAULTINJECTOR_COUNT 1 005635 005636 /* 005637 ** The interface to the code in fault.c used for identifying "benign" 005638 ** malloc failures. This is only present if SQLITE_UNTESTABLE 005639 ** is not defined. 005640 */ 005641 #ifndef SQLITE_UNTESTABLE 005642 void sqlite3BeginBenignMalloc(void); 005643 void sqlite3EndBenignMalloc(void); 005644 #else 005645 #define sqlite3BeginBenignMalloc() 005646 #define sqlite3EndBenignMalloc() 005647 #endif 005648 005649 /* 005650 ** Allowed return values from sqlite3FindInIndex() 005651 */ 005652 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */ 005653 #define IN_INDEX_EPH 2 /* Search an ephemeral b-tree */ 005654 #define IN_INDEX_INDEX_ASC 3 /* Existing index ASCENDING */ 005655 #define IN_INDEX_INDEX_DESC 4 /* Existing index DESCENDING */ 005656 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */ 005657 /* 005658 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex(). 005659 */ 005660 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */ 005661 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */ 005662 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */ 005663 int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*); 005664 005665 int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); 005666 int sqlite3JournalSize(sqlite3_vfs *); 005667 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ 005668 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) 005669 int sqlite3JournalCreate(sqlite3_file *); 005670 #endif 005671 005672 int sqlite3JournalIsInMemory(sqlite3_file *p); 005673 void sqlite3MemJournalOpen(sqlite3_file *); 005674 005675 void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p); 005676 #if SQLITE_MAX_EXPR_DEPTH>0 005677 int sqlite3SelectExprHeight(const Select *); 005678 int sqlite3ExprCheckHeight(Parse*, int); 005679 #else 005680 #define sqlite3SelectExprHeight(x) 0 005681 #define sqlite3ExprCheckHeight(x,y) 005682 #endif 005683 void sqlite3ExprSetErrorOffset(Expr*,int); 005684 005685 u32 sqlite3Get4byte(const u8*); 005686 void sqlite3Put4byte(u8*, u32); 005687 005688 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY 005689 void sqlite3ConnectionBlocked(sqlite3 *, sqlite3 *); 005690 void sqlite3ConnectionUnlocked(sqlite3 *db); 005691 void sqlite3ConnectionClosed(sqlite3 *db); 005692 #else 005693 #define sqlite3ConnectionBlocked(x,y) 005694 #define sqlite3ConnectionUnlocked(x) 005695 #define sqlite3ConnectionClosed(x) 005696 #endif 005697 005698 #ifdef SQLITE_DEBUG 005699 void sqlite3ParserTrace(FILE*, char *); 005700 #endif 005701 #if defined(YYCOVERAGE) 005702 int sqlite3ParserCoverage(FILE*); 005703 #endif 005704 005705 /* 005706 ** If the SQLITE_ENABLE IOTRACE exists then the global variable 005707 ** sqlite3IoTrace is a pointer to a printf-like routine used to 005708 ** print I/O tracing messages. 005709 */ 005710 #ifdef SQLITE_ENABLE_IOTRACE 005711 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } 005712 void sqlite3VdbeIOTraceSql(Vdbe*); 005713 SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); 005714 #else 005715 # define IOTRACE(A) 005716 # define sqlite3VdbeIOTraceSql(X) 005717 #endif 005718 005719 /* 005720 ** These routines are available for the mem2.c debugging memory allocator 005721 ** only. They are used to verify that different "types" of memory 005722 ** allocations are properly tracked by the system. 005723 ** 005724 ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of 005725 ** the MEMTYPE_* macros defined below. The type must be a bitmask with 005726 ** a single bit set. 005727 ** 005728 ** sqlite3MemdebugHasType() returns true if any of the bits in its second 005729 ** argument match the type set by the previous sqlite3MemdebugSetType(). 005730 ** sqlite3MemdebugHasType() is intended for use inside assert() statements. 005731 ** 005732 ** sqlite3MemdebugNoType() returns true if none of the bits in its second 005733 ** argument match the type set by the previous sqlite3MemdebugSetType(). 005734 ** 005735 ** Perhaps the most important point is the difference between MEMTYPE_HEAP 005736 ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means 005737 ** it might have been allocated by lookaside, except the allocation was 005738 ** too large or lookaside was already full. It is important to verify 005739 ** that allocations that might have been satisfied by lookaside are not 005740 ** passed back to non-lookaside free() routines. Asserts such as the 005741 ** example above are placed on the non-lookaside free() routines to verify 005742 ** this constraint. 005743 ** 005744 ** All of this is no-op for a production build. It only comes into 005745 ** play when the SQLITE_MEMDEBUG compile-time option is used. 005746 */ 005747 #ifdef SQLITE_MEMDEBUG 005748 void sqlite3MemdebugSetType(void*,u8); 005749 int sqlite3MemdebugHasType(const void*,u8); 005750 int sqlite3MemdebugNoType(const void*,u8); 005751 #else 005752 # define sqlite3MemdebugSetType(X,Y) /* no-op */ 005753 # define sqlite3MemdebugHasType(X,Y) 1 005754 # define sqlite3MemdebugNoType(X,Y) 1 005755 #endif 005756 #define MEMTYPE_HEAP 0x01 /* General heap allocations */ 005757 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */ 005758 #define MEMTYPE_PCACHE 0x04 /* Page cache allocations */ 005759 005760 /* 005761 ** Threading interface 005762 */ 005763 #if SQLITE_MAX_WORKER_THREADS>0 005764 int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*); 005765 int sqlite3ThreadJoin(SQLiteThread*, void**); 005766 #endif 005767 005768 #if defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST) 005769 int sqlite3DbpageRegister(sqlite3*); 005770 #endif 005771 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST) 005772 int sqlite3DbstatRegister(sqlite3*); 005773 #endif 005774 005775 int sqlite3ExprVectorSize(const Expr *pExpr); 005776 int sqlite3ExprIsVector(const Expr *pExpr); 005777 Expr *sqlite3VectorFieldSubexpr(Expr*, int); 005778 Expr *sqlite3ExprForVectorField(Parse*,Expr*,int,int); 005779 void sqlite3VectorErrorMsg(Parse*, Expr*); 005780 005781 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 005782 const char **sqlite3CompileOptions(int *pnOpt); 005783 #endif 005784 005785 #if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL) 005786 int sqlite3KvvfsInit(void); 005787 #endif 005788 005789 #if defined(VDBE_PROFILE) \ 005790 || defined(SQLITE_PERFORMANCE_TRACE) \ 005791 || defined(SQLITE_ENABLE_STMT_SCANSTATUS) 005792 sqlite3_uint64 sqlite3Hwtime(void); 005793 #endif 005794 005795 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS 005796 # define IS_STMT_SCANSTATUS(db) (db->flags & SQLITE_StmtScanStatus) 005797 #else 005798 # define IS_STMT_SCANSTATUS(db) 0 005799 #endif 005800 005801 #endif /* SQLITEINT_H */