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