Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: third_party/sqlite/src/src/sqliteInt.h

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/sqlite3ext.h ('k') | third_party/sqlite/src/src/sqliteLimit.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2001 September 15 2 ** 2001 September 15
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ************************************************************************* 11 *************************************************************************
12 ** Internal interface definitions for SQLite. 12 ** Internal interface definitions for SQLite.
13 ** 13 **
14 */ 14 */
15 #ifndef _SQLITEINT_H_ 15 #ifndef SQLITEINT_H
16 #define _SQLITEINT_H_ 16 #define SQLITEINT_H
17
18 /* Special Comments:
19 **
20 ** Some comments have special meaning to the tools that measure test
21 ** coverage:
22 **
23 ** NO_TEST - The branches on this line are not
24 ** measured by branch coverage. This is
25 ** used on lines of code that actually
26 ** implement parts of coverage testing.
27 **
28 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
29 ** and the correct answer is still obtained,
30 ** though perhaps more slowly.
31 **
32 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
33 ** and the correct answer is still obtained,
34 ** though perhaps more slowly.
35 **
36 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
37 ** that would be harmless and undetectable
38 ** if it did occur.
39 **
40 ** In all cases, the special comment must be enclosed in the usual
41 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the
42 ** asterisks and the comment text.
43 */
44
45 /*
46 ** Make sure the Tcl calling convention macro is defined. This macro is
47 ** only used by test code and Tcl integration code.
48 */
49 #ifndef SQLITE_TCLAPI
50 # define SQLITE_TCLAPI
51 #endif
52
53 /*
54 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
55 ** or higher.
56 */
57 #if defined(_MSC_VER) && _MSC_VER>=1400
58 /* TODO(shess): Already defined by build/config/win/BUILD.gn */
59 #ifndef _CRT_RAND_S
60 # define _CRT_RAND_S
61 #endif
62 #endif
17 63
18 /* 64 /*
19 ** Include the header file used to customize the compiler options for MSVC. 65 ** Include the header file used to customize the compiler options for MSVC.
20 ** This should be done first so that it can successfully prevent spurious 66 ** This should be done first so that it can successfully prevent spurious
21 ** compiler warnings due to subsequent content in this file and other files 67 ** compiler warnings due to subsequent content in this file and other files
22 ** that are included by this file. 68 ** that are included by this file.
23 */ 69 */
24 #include "msvc.h" 70 #include "msvc.h"
25 71
26 /* 72 /*
(...skipping 26 matching lines...) Expand all
53 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. 99 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
54 */ 100 */
55 #ifndef SQLITE_DISABLE_LFS 101 #ifndef SQLITE_DISABLE_LFS
56 # define _LARGE_FILE 1 102 # define _LARGE_FILE 1
57 # ifndef _FILE_OFFSET_BITS 103 # ifndef _FILE_OFFSET_BITS
58 # define _FILE_OFFSET_BITS 64 104 # define _FILE_OFFSET_BITS 64
59 # endif 105 # endif
60 # define _LARGEFILE_SOURCE 1 106 # define _LARGEFILE_SOURCE 1
61 #endif 107 #endif
62 108
63 /* What version of GCC is being used. 0 means GCC is not being used */ 109 /* The GCC_VERSION, CLANG_VERSION, and MSVC_VERSION macros are used to
64 #ifdef __GNUC__ 110 ** conditionally include optimizations for each of these compilers. A
111 ** value of 0 means that compiler is not being used. The
112 ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
113 ** optimizations, and hence set all compiler macros to 0
114 */
115 #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
65 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) 116 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
66 #else 117 #else
67 # define GCC_VERSION 0 118 # define GCC_VERSION 0
68 #endif 119 #endif
120 #if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC)
121 # define CLANG_VERSION \
122 (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__)
123 #else
124 # define CLANG_VERSION 0
125 #endif
126 #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
127 # define MSVC_VERSION _MSC_VER
128 #else
129 # define MSVC_VERSION 0
130 #endif
69 131
70 /* Needed for various definitions... */ 132 /* Needed for various definitions... */
71 #if defined(__GNUC__) && !defined(_GNU_SOURCE) 133 #if defined(__GNUC__) && !defined(_GNU_SOURCE)
72 # define _GNU_SOURCE 134 # define _GNU_SOURCE
73 #endif 135 #endif
74 136
75 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE) 137 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
76 # define _BSD_SOURCE 138 # define _BSD_SOURCE
77 #endif 139 #endif
78 140
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #ifdef HAVE_INTTYPES_H 204 #ifdef HAVE_INTTYPES_H
143 #include <inttypes.h> 205 #include <inttypes.h>
144 #endif 206 #endif
145 207
146 /* 208 /*
147 ** The following macros are used to cast pointers to integers and 209 ** The following macros are used to cast pointers to integers and
148 ** integers to pointers. The way you do this varies from one compiler 210 ** integers to pointers. The way you do this varies from one compiler
149 ** to the next, so we have developed the following set of #if statements 211 ** to the next, so we have developed the following set of #if statements
150 ** to generate appropriate macros for a wide range of compilers. 212 ** to generate appropriate macros for a wide range of compilers.
151 ** 213 **
152 ** The correct "ANSI" way to do this is to use the intptr_t type. 214 ** The correct "ANSI" way to do this is to use the intptr_t type.
153 ** Unfortunately, that typedef is not available on all compilers, or 215 ** Unfortunately, that typedef is not available on all compilers, or
154 ** if it is available, it requires an #include of specific headers 216 ** if it is available, it requires an #include of specific headers
155 ** that vary from one machine to the next. 217 ** that vary from one machine to the next.
156 ** 218 **
157 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on 219 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
158 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). 220 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
159 ** So we have to define the macros in different ways depending on the 221 ** So we have to define the macros in different ways depending on the
160 ** compiler. 222 ** compiler.
161 */ 223 */
162 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ 224 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
163 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) 225 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X))
164 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) 226 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
165 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ 227 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */
166 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) 228 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
167 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) 229 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
168 #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ 230 #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */
169 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) 231 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X))
170 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) 232 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X))
171 #else /* Generates a warning - but it always works */ 233 #else /* Generates a warning - but it always works */
172 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) 234 # define SQLITE_INT_TO_PTR(X) ((void*)(X))
173 # define SQLITE_PTR_TO_INT(X) ((int)(X)) 235 # define SQLITE_PTR_TO_INT(X) ((int)(X))
174 #endif 236 #endif
175 237
176 /* 238 /*
177 ** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
178 ** something between S (inclusive) and E (exclusive).
179 **
180 ** In other words, S is a buffer and E is a pointer to the first byte after
181 ** the end of buffer S. This macro returns true if P points to something
182 ** contained within the buffer S.
183 */
184 #if defined(HAVE_STDINT_H)
185 # define SQLITE_WITHIN(P,S,E) \
186 ((uintptr_t)(P)>=(uintptr_t)(S) && (uintptr_t)(P)<(uintptr_t)(E))
187 #else
188 # define SQLITE_WITHIN(P,S,E) ((P)>=(S) && (P)<(E))
189 #endif
190
191 /*
192 ** A macro to hint to the compiler that a function should not be 239 ** A macro to hint to the compiler that a function should not be
193 ** inlined. 240 ** inlined.
194 */ 241 */
195 #if defined(__GNUC__) 242 #if defined(__GNUC__)
196 # define SQLITE_NOINLINE __attribute__((noinline)) 243 # define SQLITE_NOINLINE __attribute__((noinline))
197 #elif defined(_MSC_VER) && _MSC_VER>=1310 244 #elif defined(_MSC_VER) && _MSC_VER>=1310
198 # define SQLITE_NOINLINE __declspec(noinline) 245 # define SQLITE_NOINLINE __declspec(noinline)
199 #else 246 #else
200 # define SQLITE_NOINLINE 247 # define SQLITE_NOINLINE
201 #endif 248 #endif
202 249
203 /* 250 /*
204 ** Make sure that the compiler intrinsics we desire are enabled when 251 ** Make sure that the compiler intrinsics we desire are enabled when
205 ** compiling with an appropriate version of MSVC unless prevented by 252 ** compiling with an appropriate version of MSVC unless prevented by
206 ** the SQLITE_DISABLE_INTRINSIC define. 253 ** the SQLITE_DISABLE_INTRINSIC define.
207 */ 254 */
208 #if !defined(SQLITE_DISABLE_INTRINSIC) 255 #if !defined(SQLITE_DISABLE_INTRINSIC)
209 # if defined(_MSC_VER) && _MSC_VER>=1300 256 # if defined(_MSC_VER) && _MSC_VER>=1400
210 # if !defined(_WIN32_WCE) 257 # if !defined(_WIN32_WCE)
211 # include <intrin.h> 258 # include <intrin.h>
212 # pragma intrinsic(_byteswap_ushort) 259 # pragma intrinsic(_byteswap_ushort)
213 # pragma intrinsic(_byteswap_ulong) 260 # pragma intrinsic(_byteswap_ulong)
261 # pragma intrinsic(_byteswap_uint64)
214 # pragma intrinsic(_ReadWriteBarrier) 262 # pragma intrinsic(_ReadWriteBarrier)
215 # else 263 # else
216 # include <cmnintrin.h> 264 # include <cmnintrin.h>
217 # endif 265 # endif
218 # endif 266 # endif
219 #endif 267 #endif
220 268
221 /* 269 /*
222 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. 270 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
223 ** 0 means mutexes are permanently disable and the library is never 271 ** 0 means mutexes are permanently disable and the library is never
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that 357 ** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that
310 ** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, 358 ** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true,
311 ** make it true by defining or undefining NDEBUG. 359 ** make it true by defining or undefining NDEBUG.
312 ** 360 **
313 ** Setting NDEBUG makes the code smaller and faster by disabling the 361 ** Setting NDEBUG makes the code smaller and faster by disabling the
314 ** assert() statements in the code. So we want the default action 362 ** assert() statements in the code. So we want the default action
315 ** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG 363 ** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG
316 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out 364 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
317 ** feature. 365 ** feature.
318 */ 366 */
319 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 367 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
320 # define NDEBUG 1 368 # define NDEBUG 1
321 #endif 369 #endif
322 #if defined(NDEBUG) && defined(SQLITE_DEBUG) 370 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
323 # undef NDEBUG 371 # undef NDEBUG
324 #endif 372 #endif
325 373
326 /* 374 /*
327 ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. 375 ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
328 */ 376 */
329 #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) 377 #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG)
330 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 378 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
331 #endif 379 #endif
332 380
333 /* 381 /*
334 ** The testcase() macro is used to aid in coverage testing. When 382 ** The testcase() macro is used to aid in coverage testing. When
335 ** doing coverage testing, the condition inside the argument to 383 ** doing coverage testing, the condition inside the argument to
336 ** testcase() must be evaluated both true and false in order to 384 ** testcase() must be evaluated both true and false in order to
337 ** get full branch coverage. The testcase() macro is inserted 385 ** get full branch coverage. The testcase() macro is inserted
338 ** to help ensure adequate test coverage in places where simple 386 ** to help ensure adequate test coverage in places where simple
339 ** condition/decision coverage is inadequate. For example, testcase() 387 ** condition/decision coverage is inadequate. For example, testcase()
340 ** can be used to make sure boundary values are tested. For 388 ** can be used to make sure boundary values are tested. For
341 ** bitmask tests, testcase() can be used to make sure each bit 389 ** bitmask tests, testcase() can be used to make sure each bit
342 ** is significant and used at least once. On switch statements 390 ** is significant and used at least once. On switch statements
343 ** where multiple cases go to the same block of code, testcase() 391 ** where multiple cases go to the same block of code, testcase()
344 ** can insure that all cases are evaluated. 392 ** can insure that all cases are evaluated.
(...skipping 25 matching lines...) Expand all
370 ** "Verification, Validation, and Accreditation". In other words, the 418 ** "Verification, Validation, and Accreditation". In other words, the
371 ** code within VVA_ONLY() will only run during verification processes. 419 ** code within VVA_ONLY() will only run during verification processes.
372 */ 420 */
373 #ifndef NDEBUG 421 #ifndef NDEBUG
374 # define VVA_ONLY(X) X 422 # define VVA_ONLY(X) X
375 #else 423 #else
376 # define VVA_ONLY(X) 424 # define VVA_ONLY(X)
377 #endif 425 #endif
378 426
379 /* 427 /*
380 ** The ALWAYS and NEVER macros surround boolean expressions which 428 ** The ALWAYS and NEVER macros surround boolean expressions which
381 ** are intended to always be true or false, respectively. Such 429 ** are intended to always be true or false, respectively. Such
382 ** expressions could be omitted from the code completely. But they 430 ** expressions could be omitted from the code completely. But they
383 ** are included in a few cases in order to enhance the resilience 431 ** are included in a few cases in order to enhance the resilience
384 ** of SQLite to unexpected behavior - to make the code "self-healing" 432 ** of SQLite to unexpected behavior - to make the code "self-healing"
385 ** or "ductile" rather than being "brittle" and crashing at the first 433 ** or "ductile" rather than being "brittle" and crashing at the first
386 ** hint of unplanned behavior. 434 ** hint of unplanned behavior.
387 ** 435 **
388 ** In other words, ALWAYS and NEVER are added for defensive code. 436 ** In other words, ALWAYS and NEVER are added for defensive code.
389 ** 437 **
390 ** When doing coverage testing ALWAYS and NEVER are hard-coded to 438 ** When doing coverage testing ALWAYS and NEVER are hard-coded to
391 ** be true and false so that the unreachable code they specify will 439 ** be true and false so that the unreachable code they specify will
392 ** not be counted as untested code. 440 ** not be counted as untested code.
393 */ 441 */
394 #if defined(SQLITE_COVERAGE_TEST) 442 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
395 # define ALWAYS(X) (1) 443 # define ALWAYS(X) (1)
396 # define NEVER(X) (0) 444 # define NEVER(X) (0)
397 #elif !defined(NDEBUG) 445 #elif !defined(NDEBUG)
398 # define ALWAYS(X) ((X)?1:(assert(0),0)) 446 # define ALWAYS(X) ((X)?1:(assert(0),0))
399 # define NEVER(X) ((X)?(assert(0),1):0) 447 # define NEVER(X) ((X)?(assert(0),1):0)
400 #else 448 #else
401 # define ALWAYS(X) (X) 449 # define ALWAYS(X) (X)
402 # define NEVER(X) (X) 450 # define NEVER(X) (X)
403 #endif 451 #endif
404 452
405 /* 453 /*
454 ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
455 ** defined. We need to defend against those failures when testing with
456 ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
457 ** during a normal build. The following macro can be used to disable tests
458 ** that are always false except when SQLITE_TEST_REALLOC_STRESS is set.
459 */
460 #if defined(SQLITE_TEST_REALLOC_STRESS)
461 # define ONLY_IF_REALLOC_STRESS(X) (X)
462 #elif !defined(NDEBUG)
463 # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0)
464 #else
465 # define ONLY_IF_REALLOC_STRESS(X) (0)
466 #endif
467
468 /*
406 ** Declarations used for tracing the operating system interfaces. 469 ** Declarations used for tracing the operating system interfaces.
407 */ 470 */
408 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ 471 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
409 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) 472 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
410 extern int sqlite3OSTrace; 473 extern int sqlite3OSTrace;
411 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X 474 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
412 # define SQLITE_HAVE_OS_TRACE 475 # define SQLITE_HAVE_OS_TRACE
413 #else 476 #else
414 # define OSTRACE(X) 477 # define OSTRACE(X)
415 # undef SQLITE_HAVE_OS_TRACE 478 # undef SQLITE_HAVE_OS_TRACE
416 #endif 479 #endif
417 480
418 /* 481 /*
419 ** Is the sqlite3ErrName() function needed in the build? Currently, 482 ** Is the sqlite3ErrName() function needed in the build? Currently,
420 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when 483 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
421 ** OSTRACE is enabled), and by several "test*.c" files (which are 484 ** OSTRACE is enabled), and by several "test*.c" files (which are
422 ** compiled using SQLITE_TEST). 485 ** compiled using SQLITE_TEST).
423 */ 486 */
424 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \ 487 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
425 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) 488 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
426 # define SQLITE_NEED_ERR_NAME 489 # define SQLITE_NEED_ERR_NAME
427 #else 490 #else
428 # undef SQLITE_NEED_ERR_NAME 491 # undef SQLITE_NEED_ERR_NAME
429 #endif 492 #endif
430 493
431 /* 494 /*
495 ** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN
496 */
497 #ifdef SQLITE_OMIT_EXPLAIN
498 # undef SQLITE_ENABLE_EXPLAIN_COMMENTS
499 #endif
500
501 /*
432 ** Return true (non-zero) if the input is an integer that is too large 502 ** Return true (non-zero) if the input is an integer that is too large
433 ** to fit in 32-bits. This macro is used inside of various testcase() 503 ** to fit in 32-bits. This macro is used inside of various testcase()
434 ** macros to verify that we have tested SQLite for large-file support. 504 ** macros to verify that we have tested SQLite for large-file support.
435 */ 505 */
436 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) 506 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
437 507
438 /* 508 /*
439 ** The macro unlikely() is a hint that surrounds a boolean 509 ** The macro unlikely() is a hint that surrounds a boolean
440 ** expression that is usually false. Macro likely() surrounds 510 ** expression that is usually false. Macro likely() surrounds
441 ** a boolean expression that is usually true. These hints could, 511 ** a boolean expression that is usually true. These hints could,
442 ** in theory, be used by the compiler to generate better code, but 512 ** in theory, be used by the compiler to generate better code, but
443 ** currently they are just comments for human readers. 513 ** currently they are just comments for human readers.
444 */ 514 */
445 #define likely(X) (X) 515 #define likely(X) (X)
446 #define unlikely(X) (X) 516 #define unlikely(X) (X)
447 517
448 #include "hash.h" 518 #include "hash.h"
449 #include "parse.h" 519 #include "parse.h"
450 #include <stdio.h> 520 #include <stdio.h>
451 #include <stdlib.h> 521 #include <stdlib.h>
452 #include <string.h> 522 #include <string.h>
453 #include <assert.h> 523 #include <assert.h>
454 #include <stddef.h> 524 #include <stddef.h>
455 525
456 /* 526 /*
527 ** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
528 ** This allows better measurements of where memcpy() is used when running
529 ** cachegrind. But this macro version of memcpy() is very slow so it
530 ** should not be used in production. This is a performance measurement
531 ** hack only.
532 */
533 #ifdef SQLITE_INLINE_MEMCPY
534 # define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
535 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
536 #endif
537
538 /*
457 ** If compiling for a processor that lacks floating point support, 539 ** If compiling for a processor that lacks floating point support,
458 ** substitute integer for floating-point 540 ** substitute integer for floating-point
459 */ 541 */
460 #ifdef SQLITE_OMIT_FLOATING_POINT 542 #ifdef SQLITE_OMIT_FLOATING_POINT
461 # define double sqlite_int64 543 # define double sqlite_int64
462 # define float sqlite_int64 544 # define float sqlite_int64
463 # define LONGDOUBLE_TYPE sqlite_int64 545 # define LONGDOUBLE_TYPE sqlite_int64
464 # ifndef SQLITE_BIG_DBL 546 # ifndef SQLITE_BIG_DBL
465 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) 547 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
466 # endif 548 # endif
467 # define SQLITE_OMIT_DATETIME_FUNCS 1 549 # define SQLITE_OMIT_DATETIME_FUNCS 1
468 # define SQLITE_OMIT_TRACE 1 550 # define SQLITE_OMIT_TRACE 1
469 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT 551 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
470 # undef SQLITE_HAVE_ISNAN 552 # undef SQLITE_HAVE_ISNAN
471 #endif 553 #endif
472 #ifndef SQLITE_BIG_DBL 554 #ifndef SQLITE_BIG_DBL
473 # define SQLITE_BIG_DBL (1e99) 555 # define SQLITE_BIG_DBL (1e99)
474 #endif 556 #endif
475 557
476 /* 558 /*
477 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 559 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
478 ** afterward. Having this macro allows us to cause the C compiler 560 ** afterward. Having this macro allows us to cause the C compiler
479 ** to omit code used by TEMP tables without messy #ifndef statements. 561 ** to omit code used by TEMP tables without messy #ifndef statements.
480 */ 562 */
481 #ifdef SQLITE_OMIT_TEMPDB 563 #ifdef SQLITE_OMIT_TEMPDB
482 #define OMIT_TEMPDB 1 564 #define OMIT_TEMPDB 1
483 #else 565 #else
484 #define OMIT_TEMPDB 0 566 #define OMIT_TEMPDB 0
485 #endif 567 #endif
486 568
487 /* 569 /*
488 ** The "file format" number is an integer that is incremented whenever 570 ** The "file format" number is an integer that is incremented whenever
(...skipping 18 matching lines...) Expand all
507 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified 589 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
508 ** on the command-line 590 ** on the command-line
509 */ 591 */
510 #ifndef SQLITE_TEMP_STORE 592 #ifndef SQLITE_TEMP_STORE
511 # define SQLITE_TEMP_STORE 1 593 # define SQLITE_TEMP_STORE 1
512 # define SQLITE_TEMP_STORE_xc 1 /* Exclude from ctime.c */ 594 # define SQLITE_TEMP_STORE_xc 1 /* Exclude from ctime.c */
513 #endif 595 #endif
514 596
515 /* 597 /*
516 ** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if 598 ** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if
517 ** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it 599 ** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it
518 ** to zero. 600 ** to zero.
519 */ 601 */
520 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0 602 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0
521 # undef SQLITE_MAX_WORKER_THREADS 603 # undef SQLITE_MAX_WORKER_THREADS
522 # define SQLITE_MAX_WORKER_THREADS 0 604 # define SQLITE_MAX_WORKER_THREADS 0
523 #endif 605 #endif
524 #ifndef SQLITE_MAX_WORKER_THREADS 606 #ifndef SQLITE_MAX_WORKER_THREADS
525 # define SQLITE_MAX_WORKER_THREADS 8 607 # define SQLITE_MAX_WORKER_THREADS 8
526 #endif 608 #endif
527 #ifndef SQLITE_DEFAULT_WORKER_THREADS 609 #ifndef SQLITE_DEFAULT_WORKER_THREADS
528 # define SQLITE_DEFAULT_WORKER_THREADS 0 610 # define SQLITE_DEFAULT_WORKER_THREADS 0
529 #endif 611 #endif
530 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS 612 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS
531 # undef SQLITE_MAX_WORKER_THREADS 613 # undef SQLITE_MAX_WORKER_THREADS
532 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS 614 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS
533 #endif 615 #endif
534 616
535 /* 617 /*
536 ** The default initial allocation for the pagecache when using separate 618 ** The default initial allocation for the pagecache when using separate
537 ** pagecaches for each database connection. A positive number is the 619 ** pagecaches for each database connection. A positive number is the
538 ** number of pages. A negative number N translations means that a buffer 620 ** number of pages. A negative number N translations means that a buffer
539 ** of -1024*N bytes is allocated and used for as many pages as it will hold. 621 ** of -1024*N bytes is allocated and used for as many pages as it will hold.
622 **
623 ** The default value of "20" was choosen to minimize the run-time of the
624 ** speedtest1 test program with options: --shrink-memory --reprepare
540 */ 625 */
541 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ 626 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
542 # define SQLITE_DEFAULT_PCACHE_INITSZ 100 627 # define SQLITE_DEFAULT_PCACHE_INITSZ 20
543 #endif 628 #endif
544 629
545 /* 630 /*
546 ** GCC does not define the offsetof() macro so we'll have to do it 631 ** GCC does not define the offsetof() macro so we'll have to do it
547 ** ourselves. 632 ** ourselves.
548 */ 633 */
549 #ifndef offsetof 634 #ifndef offsetof
550 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) 635 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
551 #endif 636 #endif
552 637
553 /* 638 /*
554 ** Macros to compute minimum and maximum of two numbers. 639 ** Macros to compute minimum and maximum of two numbers.
555 */ 640 */
556 #define MIN(A,B) ((A)<(B)?(A):(B)) 641 #ifndef MIN
557 #define MAX(A,B) ((A)>(B)?(A):(B)) 642 # define MIN(A,B) ((A)<(B)?(A):(B))
643 #endif
644 #ifndef MAX
645 # define MAX(A,B) ((A)>(B)?(A):(B))
646 #endif
558 647
559 /* 648 /*
560 ** Swap two objects of type TYPE. 649 ** Swap two objects of type TYPE.
561 */ 650 */
562 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} 651 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
563 652
564 /* 653 /*
565 ** Check to see if this machine uses EBCDIC. (Yes, believe it or 654 ** Check to see if this machine uses EBCDIC. (Yes, believe it or
566 ** not, there are still machines out there that use EBCDIC.) 655 ** not, there are still machines out there that use EBCDIC.)
567 */ 656 */
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 ** 744 **
656 ** "LogEst" is short for "Logarithmic Estimate". 745 ** "LogEst" is short for "Logarithmic Estimate".
657 ** 746 **
658 ** Examples: 747 ** Examples:
659 ** 1 -> 0 20 -> 43 10000 -> 132 748 ** 1 -> 0 20 -> 43 10000 -> 132
660 ** 2 -> 10 25 -> 46 25000 -> 146 749 ** 2 -> 10 25 -> 46 25000 -> 146
661 ** 3 -> 16 100 -> 66 1000000 -> 199 750 ** 3 -> 16 100 -> 66 1000000 -> 199
662 ** 4 -> 20 1000 -> 99 1048576 -> 200 751 ** 4 -> 20 1000 -> 99 1048576 -> 200
663 ** 10 -> 33 1024 -> 100 4294967296 -> 320 752 ** 10 -> 33 1024 -> 100 4294967296 -> 320
664 ** 753 **
665 ** The LogEst can be negative to indicate fractional values. 754 ** The LogEst can be negative to indicate fractional values.
666 ** Examples: 755 ** Examples:
667 ** 756 **
668 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40 757 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
669 */ 758 */
670 typedef INT16_TYPE LogEst; 759 typedef INT16_TYPE LogEst;
671 760
672 /* 761 /*
673 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer 762 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
674 */ 763 */
675 #ifndef SQLITE_PTRSIZE 764 #ifndef SQLITE_PTRSIZE
676 # if defined(__SIZEOF_POINTER__) 765 # if defined(__SIZEOF_POINTER__)
677 # define SQLITE_PTRSIZE __SIZEOF_POINTER__ 766 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
678 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ 767 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
679 defined(_M_ARM) || defined(__arm__) || defined(__x86) 768 defined(_M_ARM) || defined(__arm__) || defined(__x86)
680 # define SQLITE_PTRSIZE 4 769 # define SQLITE_PTRSIZE 4
681 # else 770 # else
682 # define SQLITE_PTRSIZE 8 771 # define SQLITE_PTRSIZE 8
683 # endif 772 # endif
684 #endif 773 #endif
685 774
775 /* The uptr type is an unsigned integer large enough to hold a pointer
776 */
777 #if defined(HAVE_STDINT_H)
778 typedef uintptr_t uptr;
779 #elif SQLITE_PTRSIZE==4
780 typedef u32 uptr;
781 #else
782 typedef u64 uptr;
783 #endif
784
785 /*
786 ** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
787 ** something between S (inclusive) and E (exclusive).
788 **
789 ** In other words, S is a buffer and E is a pointer to the first byte after
790 ** the end of buffer S. This macro returns true if P points to something
791 ** contained within the buffer S.
792 */
793 #define SQLITE_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))
794
795
686 /* 796 /*
687 ** Macros to determine whether the machine is big or little endian, 797 ** Macros to determine whether the machine is big or little endian,
688 ** and whether or not that determination is run-time or compile-time. 798 ** and whether or not that determination is run-time or compile-time.
689 ** 799 **
690 ** For best performance, an attempt is made to guess at the byte-order 800 ** For best performance, an attempt is made to guess at the byte-order
691 ** using C-preprocessor macros. If that is unsuccessful, or if 801 ** using C-preprocessor macros. If that is unsuccessful, or if
692 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined 802 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
693 ** at run-time. 803 ** at run-time.
694 */ 804 */
695 #if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \ 805 #ifndef SQLITE_BYTEORDER
806 # if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
696 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ 807 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
697 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ 808 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
698 defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER) 809 defined(__arm__)
699 # define SQLITE_BYTEORDER 1234 810 # define SQLITE_BYTEORDER 1234
811 # elif defined(sparc) || defined(__ppc__)
812 # define SQLITE_BYTEORDER 4321
813 # else
814 # define SQLITE_BYTEORDER 0
815 # endif
816 #endif
817 #if SQLITE_BYTEORDER==4321
818 # define SQLITE_BIGENDIAN 1
819 # define SQLITE_LITTLEENDIAN 0
820 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE
821 #elif SQLITE_BYTEORDER==1234
700 # define SQLITE_BIGENDIAN 0 822 # define SQLITE_BIGENDIAN 0
701 # define SQLITE_LITTLEENDIAN 1 823 # define SQLITE_LITTLEENDIAN 1
702 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE 824 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE
703 #endif 825 #else
704 #if (defined(sparc) || defined(__ppc__)) \
705 && !defined(SQLITE_RUNTIME_BYTEORDER)
706 # define SQLITE_BYTEORDER 4321
707 # define SQLITE_BIGENDIAN 1
708 # define SQLITE_LITTLEENDIAN 0
709 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE
710 #endif
711 #if !defined(SQLITE_BYTEORDER)
712 # ifdef SQLITE_AMALGAMATION 826 # ifdef SQLITE_AMALGAMATION
713 const int sqlite3one = 1; 827 const int sqlite3one = 1;
714 # else 828 # else
715 extern const int sqlite3one; 829 extern const int sqlite3one;
716 # endif 830 # endif
717 # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
718 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) 831 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
719 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) 832 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
720 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) 833 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
721 #endif 834 #endif
722 835
723 /* 836 /*
724 ** Constants for the largest and smallest possible 64-bit signed integers. 837 ** Constants for the largest and smallest possible 64-bit signed integers.
725 ** These macros are designed to work correctly on both 32-bit and 64-bit 838 ** These macros are designed to work correctly on both 32-bit and 64-bit
726 ** compilers. 839 ** compilers.
727 */ 840 */
728 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) 841 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
729 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) 842 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
730 843
731 /* 844 /*
732 ** Round up a number to the next larger multiple of 8. This is used 845 ** Round up a number to the next larger multiple of 8. This is used
733 ** to force 8-byte alignment on 64-bit architectures. 846 ** to force 8-byte alignment on 64-bit architectures.
734 */ 847 */
735 #define ROUND8(x) (((x)+7)&~7) 848 #define ROUND8(x) (((x)+7)&~7)
736 849
737 /* 850 /*
738 ** Round down to the nearest multiple of 8 851 ** Round down to the nearest multiple of 8
739 */ 852 */
740 #define ROUNDDOWN8(x) ((x)&~7) 853 #define ROUNDDOWN8(x) ((x)&~7)
741 854
(...skipping 18 matching lines...) Expand all
760 #if defined(__OpenBSD__) || defined(__QNXNTO__) 873 #if defined(__OpenBSD__) || defined(__QNXNTO__)
761 # undef SQLITE_MAX_MMAP_SIZE 874 # undef SQLITE_MAX_MMAP_SIZE
762 # define SQLITE_MAX_MMAP_SIZE 0 875 # define SQLITE_MAX_MMAP_SIZE 0
763 #endif 876 #endif
764 877
765 /* 878 /*
766 ** Default maximum size of memory used by memory-mapped I/O in the VFS 879 ** Default maximum size of memory used by memory-mapped I/O in the VFS
767 */ 880 */
768 #ifdef __APPLE__ 881 #ifdef __APPLE__
769 # include <TargetConditionals.h> 882 # include <TargetConditionals.h>
770 # if TARGET_OS_IPHONE
771 # undef SQLITE_MAX_MMAP_SIZE
772 # define SQLITE_MAX_MMAP_SIZE 0
773 # endif
774 #endif 883 #endif
775 #ifndef SQLITE_MAX_MMAP_SIZE 884 #ifndef SQLITE_MAX_MMAP_SIZE
776 # if defined(__linux__) \ 885 # if defined(__linux__) \
777 || defined(_WIN32) \ 886 || defined(_WIN32) \
778 || (defined(__APPLE__) && defined(__MACH__)) \ 887 || (defined(__APPLE__) && defined(__MACH__)) \
779 || defined(__sun) \ 888 || defined(__sun) \
780 || defined(__FreeBSD__) \ 889 || defined(__FreeBSD__) \
781 || defined(__DragonFly__) 890 || defined(__DragonFly__)
782 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */ 891 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
783 # else 892 # else
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 ** the Select query generator tracing logic is turned on. 928 ** the Select query generator tracing logic is turned on.
820 */ 929 */
821 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE) 930 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
822 # define SELECTTRACE_ENABLED 1 931 # define SELECTTRACE_ENABLED 1
823 #else 932 #else
824 # define SELECTTRACE_ENABLED 0 933 # define SELECTTRACE_ENABLED 0
825 #endif 934 #endif
826 935
827 /* 936 /*
828 ** An instance of the following structure is used to store the busy-handler 937 ** An instance of the following structure is used to store the busy-handler
829 ** callback for a given sqlite handle. 938 ** callback for a given sqlite handle.
830 ** 939 **
831 ** The sqlite.busyHandler member of the sqlite struct contains the busy 940 ** The sqlite.busyHandler member of the sqlite struct contains the busy
832 ** callback for the database handle. Each pager opened via the sqlite 941 ** callback for the database handle. Each pager opened via the sqlite
833 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler 942 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
834 ** callback is currently invoked only from within pager.c. 943 ** callback is currently invoked only from within pager.c.
835 */ 944 */
836 typedef struct BusyHandler BusyHandler; 945 typedef struct BusyHandler BusyHandler;
837 struct BusyHandler { 946 struct BusyHandler {
838 int (*xFunc)(void *,int); /* The busy callback */ 947 int (*xFunc)(void *,int); /* The busy callback */
839 void *pArg; /* First arg to busy callback */ 948 void *pArg; /* First arg to busy callback */
(...skipping 24 matching lines...) Expand all
864 */ 973 */
865 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0]))) 974 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
866 975
867 /* 976 /*
868 ** Determine if the argument is a power of two 977 ** Determine if the argument is a power of two
869 */ 978 */
870 #define IsPowerOfTwo(X) (((X)&((X)-1))==0) 979 #define IsPowerOfTwo(X) (((X)&((X)-1))==0)
871 980
872 /* 981 /*
873 ** The following value as a destructor means to use sqlite3DbFree(). 982 ** The following value as a destructor means to use sqlite3DbFree().
874 ** The sqlite3DbFree() routine requires two parameters instead of the 983 ** The sqlite3DbFree() routine requires two parameters instead of the
875 ** one parameter that destructors normally want. So we have to introduce 984 ** one parameter that destructors normally want. So we have to introduce
876 ** this magic value that the code knows to handle differently. Any 985 ** this magic value that the code knows to handle differently. Any
877 ** pointer will work here as long as it is distinct from SQLITE_STATIC 986 ** pointer will work here as long as it is distinct from SQLITE_STATIC
878 ** and SQLITE_TRANSIENT. 987 ** and SQLITE_TRANSIENT.
879 */ 988 */
880 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3MallocSize) 989 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3MallocSize)
881 990
882 /* 991 /*
883 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does 992 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
884 ** not support Writable Static Data (WSD) such as global and static variables. 993 ** not support Writable Static Data (WSD) such as global and static variables.
885 ** All variables must either be on the stack or dynamically allocated from 994 ** All variables must either be on the stack or dynamically allocated from
886 ** the heap. When WSD is unsupported, the variable declarations scattered 995 ** the heap. When WSD is unsupported, the variable declarations scattered
887 ** throughout the SQLite code must become constants instead. The SQLITE_WSD 996 ** throughout the SQLite code must become constants instead. The SQLITE_WSD
888 ** macro is used for this purpose. And instead of referencing the variable 997 ** macro is used for this purpose. And instead of referencing the variable
889 ** directly, we use its constant as a key to lookup the run-time allocated 998 ** directly, we use its constant as a key to lookup the run-time allocated
890 ** buffer that holds real variable. The constant is also the initializer 999 ** buffer that holds real variable. The constant is also the initializer
891 ** for the run-time allocated buffer. 1000 ** for the run-time allocated buffer.
892 ** 1001 **
893 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL 1002 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
894 ** macros become no-ops and have zero performance impact. 1003 ** macros become no-ops and have zero performance impact.
895 */ 1004 */
896 #ifdef SQLITE_OMIT_WSD 1005 #ifdef SQLITE_OMIT_WSD
897 #define SQLITE_WSD const 1006 #define SQLITE_WSD const
898 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) 1007 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
899 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) 1008 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
900 int sqlite3_wsd_init(int N, int J); 1009 int sqlite3_wsd_init(int N, int J);
901 void *sqlite3_wsd_find(void *K, int L); 1010 void *sqlite3_wsd_find(void *K, int L);
902 #else 1011 #else
903 #define SQLITE_WSD 1012 #define SQLITE_WSD
904 #define GLOBAL(t,v) v 1013 #define GLOBAL(t,v) v
905 #define sqlite3GlobalConfig sqlite3Config 1014 #define sqlite3GlobalConfig sqlite3Config
906 #endif 1015 #endif
907 1016
908 /* 1017 /*
909 ** The following macros are used to suppress compiler warnings and to 1018 ** The following macros are used to suppress compiler warnings and to
910 ** make it clear to human readers when a function parameter is deliberately 1019 ** make it clear to human readers when a function parameter is deliberately
911 ** left unused within the body of a function. This usually happens when 1020 ** left unused within the body of a function. This usually happens when
912 ** a function is called via a function pointer. For example the 1021 ** a function is called via a function pointer. For example the
913 ** implementation of an SQL aggregate step callback may not use the 1022 ** implementation of an SQL aggregate step callback may not use the
914 ** parameter indicating the number of arguments passed to the aggregate, 1023 ** parameter indicating the number of arguments passed to the aggregate,
915 ** if it knows that this is enforced elsewhere. 1024 ** if it knows that this is enforced elsewhere.
916 ** 1025 **
917 ** When a function parameter is not used at all within the body of a function, 1026 ** When a function parameter is not used at all within the body of a function,
918 ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer. 1027 ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
919 ** However, these macros may also be used to suppress warnings related to 1028 ** However, these macros may also be used to suppress warnings related to
920 ** parameters that may or may not be used depending on compilation options. 1029 ** parameters that may or may not be used depending on compilation options.
921 ** For example those parameters only used in assert() statements. In these 1030 ** For example those parameters only used in assert() statements. In these
922 ** cases the parameters are named as per the usual conventions. 1031 ** cases the parameters are named as per the usual conventions.
(...skipping 22 matching lines...) Expand all
945 typedef struct IdList IdList; 1054 typedef struct IdList IdList;
946 typedef struct Index Index; 1055 typedef struct Index Index;
947 typedef struct IndexSample IndexSample; 1056 typedef struct IndexSample IndexSample;
948 typedef struct KeyClass KeyClass; 1057 typedef struct KeyClass KeyClass;
949 typedef struct KeyInfo KeyInfo; 1058 typedef struct KeyInfo KeyInfo;
950 typedef struct Lookaside Lookaside; 1059 typedef struct Lookaside Lookaside;
951 typedef struct LookasideSlot LookasideSlot; 1060 typedef struct LookasideSlot LookasideSlot;
952 typedef struct Module Module; 1061 typedef struct Module Module;
953 typedef struct NameContext NameContext; 1062 typedef struct NameContext NameContext;
954 typedef struct Parse Parse; 1063 typedef struct Parse Parse;
1064 typedef struct PreUpdate PreUpdate;
955 typedef struct PrintfArguments PrintfArguments; 1065 typedef struct PrintfArguments PrintfArguments;
956 typedef struct RowSet RowSet; 1066 typedef struct RowSet RowSet;
957 typedef struct Savepoint Savepoint; 1067 typedef struct Savepoint Savepoint;
958 typedef struct Select Select; 1068 typedef struct Select Select;
959 typedef struct SQLiteThread SQLiteThread; 1069 typedef struct SQLiteThread SQLiteThread;
960 typedef struct SelectDest SelectDest; 1070 typedef struct SelectDest SelectDest;
961 typedef struct SrcList SrcList; 1071 typedef struct SrcList SrcList;
962 typedef struct StrAccum StrAccum; 1072 typedef struct StrAccum StrAccum;
963 typedef struct Table Table; 1073 typedef struct Table Table;
964 typedef struct TableLock TableLock; 1074 typedef struct TableLock TableLock;
965 typedef struct Token Token; 1075 typedef struct Token Token;
966 typedef struct TreeView TreeView; 1076 typedef struct TreeView TreeView;
967 typedef struct Trigger Trigger; 1077 typedef struct Trigger Trigger;
968 typedef struct TriggerPrg TriggerPrg; 1078 typedef struct TriggerPrg TriggerPrg;
969 typedef struct TriggerStep TriggerStep; 1079 typedef struct TriggerStep TriggerStep;
970 typedef struct UnpackedRecord UnpackedRecord; 1080 typedef struct UnpackedRecord UnpackedRecord;
971 typedef struct VTable VTable; 1081 typedef struct VTable VTable;
972 typedef struct VtabCtx VtabCtx; 1082 typedef struct VtabCtx VtabCtx;
973 typedef struct Walker Walker; 1083 typedef struct Walker Walker;
974 typedef struct WhereInfo WhereInfo; 1084 typedef struct WhereInfo WhereInfo;
975 typedef struct With With; 1085 typedef struct With With;
976 1086
1087 /* A VList object records a mapping between parameters/variables/wildcards
1088 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
1089 ** variable number associated with that parameter. See the format description
1090 ** on the sqlite3VListAdd() routine for more information. A VList is really
1091 ** just an array of integers.
1092 */
1093 typedef int VList;
1094
977 /* 1095 /*
978 ** Defer sourcing vdbe.h and btree.h until after the "u8" and 1096 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
979 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque 1097 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
980 ** pointer types (i.e. FuncDef) defined above. 1098 ** pointer types (i.e. FuncDef) defined above.
981 */ 1099 */
982 #include "btree.h" 1100 #include "btree.h"
983 #include "vdbe.h" 1101 #include "vdbe.h"
984 #include "pager.h" 1102 #include "pager.h"
985 #include "pcache.h" 1103 #include "pcache.h"
986
987 #include "os.h" 1104 #include "os.h"
988 #include "mutex.h" 1105 #include "mutex.h"
989 1106
1107 /* The SQLITE_EXTRA_DURABLE compile-time option used to set the default
1108 ** synchronous setting to EXTRA. It is no longer supported.
1109 */
1110 #ifdef SQLITE_EXTRA_DURABLE
1111 # warning Use SQLITE_DEFAULT_SYNCHRONOUS=3 instead of SQLITE_EXTRA_DURABLE
1112 # define SQLITE_DEFAULT_SYNCHRONOUS 3
1113 #endif
1114
1115 /*
1116 ** Default synchronous levels.
1117 **
1118 ** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ
1119 ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
1120 **
1121 ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS
1122 ** OFF 1 0
1123 ** NORMAL 2 1
1124 ** FULL 3 2
1125 ** EXTRA 4 3
1126 **
1127 ** The "PRAGMA synchronous" statement also uses the zero-based numbers.
1128 ** In other words, the zero-based numbers are used for all external interfaces
1129 ** and the one-based values are used internally.
1130 */
1131 #ifndef SQLITE_DEFAULT_SYNCHRONOUS
1132 # define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
1133 #endif
1134 #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
1135 # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
1136 #endif
990 1137
991 /* 1138 /*
992 ** Each database file to be accessed by the system is an instance 1139 ** Each database file to be accessed by the system is an instance
993 ** of the following structure. There are normally two of these structures 1140 ** of the following structure. There are normally two of these structures
994 ** in the sqlite.aDb[] array. aDb[0] is the main database file and 1141 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
995 ** aDb[1] is the database file used to hold temporary tables. Additional 1142 ** aDb[1] is the database file used to hold temporary tables. Additional
996 ** databases may be attached. 1143 ** databases may be attached.
997 */ 1144 */
998 struct Db { 1145 struct Db {
999 char *zName; /* Name of this database */ 1146 char *zDbSName; /* Name of this database. (schema name, not filename) */
1000 Btree *pBt; /* The B*Tree structure for this database file */ 1147 Btree *pBt; /* The B*Tree structure for this database file */
1001 u8 safety_level; /* How aggressive at syncing data to disk */ 1148 u8 safety_level; /* How aggressive at syncing data to disk */
1149 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */
1002 Schema *pSchema; /* Pointer to database schema (possibly shared) */ 1150 Schema *pSchema; /* Pointer to database schema (possibly shared) */
1003 }; 1151 };
1004 1152
1005 /* 1153 /*
1006 ** An instance of the following structure stores a database schema. 1154 ** An instance of the following structure stores a database schema.
1007 ** 1155 **
1008 ** Most Schema objects are associated with a Btree. The exception is 1156 ** Most Schema objects are associated with a Btree. The exception is
1009 ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. 1157 ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
1010 ** In shared cache mode, a single Schema object can be shared by multiple 1158 ** In shared cache mode, a single Schema object can be shared by multiple
1011 ** Btrees that refer to the same underlying BtShared object. 1159 ** Btrees that refer to the same underlying BtShared object.
1012 ** 1160 **
1013 ** Schema objects are automatically deallocated when the last Btree that 1161 ** Schema objects are automatically deallocated when the last Btree that
1014 ** references them is destroyed. The TEMP Schema is manually freed by 1162 ** references them is destroyed. The TEMP Schema is manually freed by
1015 ** sqlite3_close(). 1163 ** sqlite3_close().
1016 * 1164 *
1017 ** A thread must be holding a mutex on the corresponding Btree in order 1165 ** A thread must be holding a mutex on the corresponding Btree in order
1018 ** to access Schema content. This implies that the thread must also be 1166 ** to access Schema content. This implies that the thread must also be
1019 ** holding a mutex on the sqlite3 connection pointer that owns the Btree. 1167 ** holding a mutex on the sqlite3 connection pointer that owns the Btree.
1020 ** For a TEMP Schema, only the connection mutex is required. 1168 ** For a TEMP Schema, only the connection mutex is required.
1021 */ 1169 */
1022 struct Schema { 1170 struct Schema {
1023 int schema_cookie; /* Database schema version number for this file */ 1171 int schema_cookie; /* Database schema version number for this file */
1024 int iGeneration; /* Generation counter. Incremented with each change */ 1172 int iGeneration; /* Generation counter. Incremented with each change */
1025 Hash tblHash; /* All tables indexed by name */ 1173 Hash tblHash; /* All tables indexed by name */
1026 Hash idxHash; /* All (named) indices indexed by name */ 1174 Hash idxHash; /* All (named) indices indexed by name */
1027 Hash trigHash; /* All triggers indexed by name */ 1175 Hash trigHash; /* All triggers indexed by name */
1028 Hash fkeyHash; /* All foreign keys by referenced table name */ 1176 Hash fkeyHash; /* All foreign keys by referenced table name */
1029 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ 1177 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
1030 u8 file_format; /* Schema format version for this file */ 1178 u8 file_format; /* Schema format version for this file */
1031 u8 enc; /* Text encoding used by this database */ 1179 u8 enc; /* Text encoding used by this database */
1032 u16 schemaFlags; /* Flags associated with this schema */ 1180 u16 schemaFlags; /* Flags associated with this schema */
1033 int cache_size; /* Number of pages to use in the cache */ 1181 int cache_size; /* Number of pages to use in the cache */
1034 }; 1182 };
1035 1183
1036 /* 1184 /*
1037 ** These macros can be used to test, set, or clear bits in the 1185 ** These macros can be used to test, set, or clear bits in the
1038 ** Db.pSchema->flags field. 1186 ** Db.pSchema->flags field.
1039 */ 1187 */
1040 #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))==(P)) 1188 #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))==(P))
1041 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0) 1189 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0)
1042 #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags|=(P) 1190 #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags|=(P)
1043 #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags&=~(P) 1191 #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags&=~(P)
1044 1192
1045 /* 1193 /*
1046 ** Allowed values for the DB.pSchema->flags field. 1194 ** Allowed values for the DB.pSchema->flags field.
1047 ** 1195 **
(...skipping 28 matching lines...) Expand all
1076 ** objects. 1224 ** objects.
1077 ** 1225 **
1078 ** Lookaside allocations are only allowed for objects that are associated 1226 ** Lookaside allocations are only allowed for objects that are associated
1079 ** with a particular database connection. Hence, schema information cannot 1227 ** with a particular database connection. Hence, schema information cannot
1080 ** be stored in lookaside because in shared cache mode the schema information 1228 ** be stored in lookaside because in shared cache mode the schema information
1081 ** is shared by multiple database connections. Therefore, while parsing 1229 ** is shared by multiple database connections. Therefore, while parsing
1082 ** schema information, the Lookaside.bEnabled flag is cleared so that 1230 ** schema information, the Lookaside.bEnabled flag is cleared so that
1083 ** lookaside allocations are not used to construct the schema objects. 1231 ** lookaside allocations are not used to construct the schema objects.
1084 */ 1232 */
1085 struct Lookaside { 1233 struct Lookaside {
1234 u32 bDisable; /* Only operate the lookaside when zero */
1086 u16 sz; /* Size of each buffer in bytes */ 1235 u16 sz; /* Size of each buffer in bytes */
1087 u8 bEnabled; /* False to disable new lookaside allocations */
1088 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ 1236 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
1089 int nOut; /* Number of buffers currently checked out */ 1237 int nOut; /* Number of buffers currently checked out */
1090 int mxOut; /* Highwater mark for nOut */ 1238 int mxOut; /* Highwater mark for nOut */
1091 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ 1239 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
1092 LookasideSlot *pFree; /* List of available buffers */ 1240 LookasideSlot *pFree; /* List of available buffers */
1093 void *pStart; /* First byte of available memory space */ 1241 void *pStart; /* First byte of available memory space */
1094 void *pEnd; /* First byte past end of available space */ 1242 void *pEnd; /* First byte past end of available space */
1095 }; 1243 };
1096 struct LookasideSlot { 1244 struct LookasideSlot {
1097 LookasideSlot *pNext; /* Next buffer in the list of free buffers */ 1245 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
1098 }; 1246 };
1099 1247
1100 /* 1248 /*
1101 ** A hash table for function definitions. 1249 ** A hash table for built-in function definitions. (Application-defined
1250 ** functions use a regular table table from hash.h.)
1102 ** 1251 **
1103 ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots. 1252 ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
1104 ** Collisions are on the FuncDef.pHash chain. 1253 ** Collisions are on the FuncDef.u.pHash chain.
1105 */ 1254 */
1255 #define SQLITE_FUNC_HASH_SZ 23
1106 struct FuncDefHash { 1256 struct FuncDefHash {
1107 FuncDef *a[23]; /* Hash table for functions */ 1257 FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
1108 }; 1258 };
1109 1259
1110 #ifdef SQLITE_USER_AUTHENTICATION 1260 #ifdef SQLITE_USER_AUTHENTICATION
1111 /* 1261 /*
1112 ** Information held in the "sqlite3" database connection object and used 1262 ** Information held in the "sqlite3" database connection object and used
1113 ** to manage user authentication. 1263 ** to manage user authentication.
1114 */ 1264 */
1115 typedef struct sqlite3_userauth sqlite3_userauth; 1265 typedef struct sqlite3_userauth sqlite3_userauth;
1116 struct sqlite3_userauth { 1266 struct sqlite3_userauth {
1117 u8 authLevel; /* Current authentication level */ 1267 u8 authLevel; /* Current authentication level */
(...skipping 20 matching lines...) Expand all
1138 ** typedef for the authorization callback function. 1288 ** typedef for the authorization callback function.
1139 */ 1289 */
1140 #ifdef SQLITE_USER_AUTHENTICATION 1290 #ifdef SQLITE_USER_AUTHENTICATION
1141 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, 1291 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
1142 const char*, const char*); 1292 const char*, const char*);
1143 #else 1293 #else
1144 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, 1294 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
1145 const char*); 1295 const char*);
1146 #endif 1296 #endif
1147 1297
1298 #ifndef SQLITE_OMIT_DEPRECATED
1299 /* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
1300 ** in the style of sqlite3_trace()
1301 */
1302 #define SQLITE_TRACE_LEGACY 0x80
1303 #else
1304 #define SQLITE_TRACE_LEGACY 0
1305 #endif /* SQLITE_OMIT_DEPRECATED */
1306
1148 1307
1149 /* 1308 /*
1150 ** Each database connection is an instance of the following structure. 1309 ** Each database connection is an instance of the following structure.
1151 */ 1310 */
1152 struct sqlite3 { 1311 struct sqlite3 {
1153 sqlite3_vfs *pVfs; /* OS Interface */ 1312 sqlite3_vfs *pVfs; /* OS Interface */
1154 struct Vdbe *pVdbe; /* List of active virtual machines */ 1313 struct Vdbe *pVdbe; /* List of active virtual machines */
1155 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ 1314 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
1156 sqlite3_mutex *mutex; /* Connection mutex */ 1315 sqlite3_mutex *mutex; /* Connection mutex */
1157 Db *aDb; /* All backends */ 1316 Db *aDb; /* All backends */
1158 int nDb; /* Number of backends currently in use */ 1317 int nDb; /* Number of backends currently in use */
1159 int flags; /* Miscellaneous flags. See below */ 1318 int flags; /* Miscellaneous flags. See below */
1160 i64 lastRowid; /* ROWID of most recent insert (see above) */ 1319 i64 lastRowid; /* ROWID of most recent insert (see above) */
1161 i64 szMmap; /* Default mmap_size setting */ 1320 i64 szMmap; /* Default mmap_size setting */
1162 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ 1321 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
1163 int errCode; /* Most recent error code (SQLITE_*) */ 1322 int errCode; /* Most recent error code (SQLITE_*) */
1164 int errMask; /* & result codes with this before returning */ 1323 int errMask; /* & result codes with this before returning */
1324 int iSysErrno; /* Errno value from last system error */
1165 u16 dbOptFlags; /* Flags to enable/disable optimizations */ 1325 u16 dbOptFlags; /* Flags to enable/disable optimizations */
1166 u8 enc; /* Text encoding */ 1326 u8 enc; /* Text encoding */
1167 u8 autoCommit; /* The auto-commit flag. */ 1327 u8 autoCommit; /* The auto-commit flag. */
1168 u8 temp_store; /* 1: file 2: memory 0: default */ 1328 u8 temp_store; /* 1: file 2: memory 0: default */
1169 u8 mallocFailed; /* True if we have seen a malloc failure */ 1329 u8 mallocFailed; /* True if we have seen a malloc failure */
1330 u8 bBenignMalloc; /* Do not require OOMs if true */
1170 u8 dfltLockMode; /* Default locking-mode for attached dbs */ 1331 u8 dfltLockMode; /* Default locking-mode for attached dbs */
1171 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ 1332 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
1172 u8 suppressErr; /* Do not issue error messages if true */ 1333 u8 suppressErr; /* Do not issue error messages if true */
1173 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ 1334 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
1174 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ 1335 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
1336 u8 mTrace; /* zero or more SQLITE_TRACE flags */
1337 u8 skipBtreeMutex; /* True if no shared-cache backends */
1175 int nextPagesize; /* Pagesize after VACUUM if >0 */ 1338 int nextPagesize; /* Pagesize after VACUUM if >0 */
1176 u32 magic; /* Magic number for detect library misuse */ 1339 u32 magic; /* Magic number for detect library misuse */
1177 int nChange; /* Value returned by sqlite3_changes() */ 1340 int nChange; /* Value returned by sqlite3_changes() */
1178 int nTotalChange; /* Value returned by sqlite3_total_changes() */ 1341 int nTotalChange; /* Value returned by sqlite3_total_changes() */
1179 int aLimit[SQLITE_N_LIMIT]; /* Limits */ 1342 int aLimit[SQLITE_N_LIMIT]; /* Limits */
1180 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ 1343 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
1181 struct sqlite3InitInfo { /* Information used during initialization */ 1344 struct sqlite3InitInfo { /* Information used during initialization */
1182 int newTnum; /* Rootpage of table being initialized */ 1345 int newTnum; /* Rootpage of table being initialized */
1183 u8 iDb; /* Which db file is being initialized */ 1346 u8 iDb; /* Which db file is being initialized */
1184 u8 busy; /* TRUE if currently initializing */ 1347 u8 busy; /* TRUE if currently initializing */
1185 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ 1348 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
1186 u8 imposterTable; /* Building an imposter table */ 1349 u8 imposterTable; /* Building an imposter table */
1187 } init; 1350 } init;
1188 int nVdbeActive; /* Number of VDBEs currently running */ 1351 int nVdbeActive; /* Number of VDBEs currently running */
1189 int nVdbeRead; /* Number of active VDBEs that read or write */ 1352 int nVdbeRead; /* Number of active VDBEs that read or write */
1190 int nVdbeWrite; /* Number of active VDBEs that read and write */ 1353 int nVdbeWrite; /* Number of active VDBEs that read and write */
1191 int nVdbeExec; /* Number of nested calls to VdbeExec() */ 1354 int nVdbeExec; /* Number of nested calls to VdbeExec() */
1192 int nVDestroy; /* Number of active OP_VDestroy operations */ 1355 int nVDestroy; /* Number of active OP_VDestroy operations */
1193 int nExtension; /* Number of loaded extensions */ 1356 int nExtension; /* Number of loaded extensions */
1194 void **aExtension; /* Array of shared library handles */ 1357 void **aExtension; /* Array of shared library handles */
1195 void (*xTrace)(void*,const char*); /* Trace function */ 1358 int (*xTrace)(u32,void*,void*,void*); /* Trace function */
1196 void *pTraceArg; /* Argument to the trace function */ 1359 void *pTraceArg; /* Argument to the trace function */
1197 void (*xProfile)(void*,const char*,u64); /* Profiling function */ 1360 void (*xProfile)(void*,const char*,u64); /* Profiling function */
1198 void *pProfileArg; /* Argument to profile function */ 1361 void *pProfileArg; /* Argument to profile function */
1199 void *pCommitArg; /* Argument to xCommitCallback() */ 1362 void *pCommitArg; /* Argument to xCommitCallback() */
1200 int (*xCommitCallback)(void*); /* Invoked at every commit. */ 1363 int (*xCommitCallback)(void*); /* Invoked at every commit. */
1201 void *pRollbackArg; /* Argument to xRollbackCallback() */ 1364 void *pRollbackArg; /* Argument to xRollbackCallback() */
1202 void (*xRollbackCallback)(void*); /* Invoked at every commit. */ 1365 void (*xRollbackCallback)(void*); /* Invoked at every commit. */
1203 void *pUpdateArg; 1366 void *pUpdateArg;
1204 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); 1367 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
1368 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
1369 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
1370 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
1371 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
1372 );
1373 PreUpdate *pPreUpdate; /* Context for active pre-update callback */
1374 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
1205 #ifndef SQLITE_OMIT_WAL 1375 #ifndef SQLITE_OMIT_WAL
1206 int (*xWalCallback)(void *, sqlite3 *, const char *, int); 1376 int (*xWalCallback)(void *, sqlite3 *, const char *, int);
1207 void *pWalArg; 1377 void *pWalArg;
1208 #endif 1378 #endif
1209 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); 1379 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
1210 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); 1380 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
1211 void *pCollNeededArg; 1381 void *pCollNeededArg;
1212 sqlite3_value *pErr; /* Most recent error message */ 1382 sqlite3_value *pErr; /* Most recent error message */
1213 union { 1383 union {
1214 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ 1384 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
1215 double notUsed1; /* Spacer */ 1385 double notUsed1; /* Spacer */
1216 } u1; 1386 } u1;
1217 Lookaside lookaside; /* Lookaside malloc configuration */ 1387 Lookaside lookaside; /* Lookaside malloc configuration */
1218 #ifndef SQLITE_OMIT_AUTHORIZATION 1388 #ifndef SQLITE_OMIT_AUTHORIZATION
1219 sqlite3_xauth xAuth; /* Access authorization function */ 1389 sqlite3_xauth xAuth; /* Access authorization function */
1220 void *pAuthArg; /* 1st argument to the access auth function */ 1390 void *pAuthArg; /* 1st argument to the access auth function */
1221 #endif 1391 #endif
1222 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK 1392 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
1223 int (*xProgress)(void *); /* The progress callback */ 1393 int (*xProgress)(void *); /* The progress callback */
1224 void *pProgressArg; /* Argument to the progress callback */ 1394 void *pProgressArg; /* Argument to the progress callback */
1225 unsigned nProgressOps; /* Number of opcodes for progress callback */ 1395 unsigned nProgressOps; /* Number of opcodes for progress callback */
1226 #endif 1396 #endif
1227 #ifndef SQLITE_OMIT_VIRTUALTABLE 1397 #ifndef SQLITE_OMIT_VIRTUALTABLE
1228 int nVTrans; /* Allocated size of aVTrans */ 1398 int nVTrans; /* Allocated size of aVTrans */
1229 Hash aModule; /* populated by sqlite3_create_module() */ 1399 Hash aModule; /* populated by sqlite3_create_module() */
1230 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ 1400 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
1231 VTable **aVTrans; /* Virtual tables with open transactions */ 1401 VTable **aVTrans; /* Virtual tables with open transactions */
1232 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ 1402 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
1233 #endif 1403 #endif
1234 FuncDefHash aFunc; /* Hash table of connection functions */ 1404 Hash aFunc; /* Hash table of connection functions */
1235 Hash aCollSeq; /* All collating sequences */ 1405 Hash aCollSeq; /* All collating sequences */
1236 BusyHandler busyHandler; /* Busy callback */ 1406 BusyHandler busyHandler; /* Busy callback */
1237 Db aDbStatic[2]; /* Static space for the 2 default backends */ 1407 Db aDbStatic[2]; /* Static space for the 2 default backends */
1238 Savepoint *pSavepoint; /* List of active savepoints */ 1408 Savepoint *pSavepoint; /* List of active savepoints */
1239 int busyTimeout; /* Busy handler timeout, in msec */ 1409 int busyTimeout; /* Busy handler timeout, in msec */
1240 int nSavepoint; /* Number of non-transaction savepoints */ 1410 int nSavepoint; /* Number of non-transaction savepoints */
1241 int nStatement; /* Number of nested statement-transactions */ 1411 int nStatement; /* Number of nested statement-transactions */
1242 i64 nDeferredCons; /* Net deferred constraints this transaction. */ 1412 i64 nDeferredCons; /* Net deferred constraints this transaction. */
1243 i64 nDeferredImmCons; /* Net deferred immediate constraints */ 1413 i64 nDeferredImmCons; /* Net deferred immediate constraints */
1244 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ 1414 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
1245 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY 1415 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
1246 /* The following variables are all protected by the STATIC_MASTER 1416 /* The following variables are all protected by the STATIC_MASTER
1247 ** mutex, not by sqlite3.mutex. They are used by code in notify.c. 1417 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
1248 ** 1418 **
1249 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to 1419 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
1250 ** unlock so that it can proceed. 1420 ** unlock so that it can proceed.
1251 ** 1421 **
1252 ** When X.pBlockingConnection==Y, that means that something that X tried 1422 ** When X.pBlockingConnection==Y, that means that something that X tried
1253 ** tried to do recently failed with an SQLITE_LOCKED error due to locks 1423 ** tried to do recently failed with an SQLITE_LOCKED error due to locks
1254 ** held by Y. 1424 ** held by Y.
1255 */ 1425 */
1256 sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */ 1426 sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */
1257 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */ 1427 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
1258 void *pUnlockArg; /* Argument to xUnlockNotify */ 1428 void *pUnlockArg; /* Argument to xUnlockNotify */
1259 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */ 1429 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
1260 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */ 1430 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
1261 #endif 1431 #endif
1262 #ifdef SQLITE_USER_AUTHENTICATION 1432 #ifdef SQLITE_USER_AUTHENTICATION
1263 sqlite3_userauth auth; /* User authentication information */ 1433 sqlite3_userauth auth; /* User authentication information */
1264 #endif 1434 #endif
1265 }; 1435 };
1266 1436
1267 /* 1437 /*
1268 ** A macro to discover the encoding of a database. 1438 ** A macro to discover the encoding of a database.
1269 */ 1439 */
1270 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) 1440 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
1271 #define ENC(db) ((db)->enc) 1441 #define ENC(db) ((db)->enc)
1272 1442
1273 /* 1443 /*
1274 ** Possible values for the sqlite3.flags. 1444 ** Possible values for the sqlite3.flags.
1445 **
1446 ** Value constraints (enforced via assert()):
1447 ** SQLITE_FullFSync == PAGER_FULLFSYNC
1448 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
1449 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL
1275 */ 1450 */
1276 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ 1451 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
1277 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */ 1452 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
1278 #define SQLITE_FullFSync 0x00000004 /* Use full fsync on the backend */ 1453 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1279 #define SQLITE_CkptFullFSync 0x00000008 /* Use full fsync for checkpoint */ 1454 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
1280 #define SQLITE_CacheSpill 0x00000010 /* OK to spill pager cache */ 1455 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
1281 #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ 1456 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
1282 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ 1457 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
1283 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ 1458 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
1284 /* DELETE, or UPDATE and return */ 1459 /* DELETE, or UPDATE and return */
1285 /* the count using a callback. */ 1460 /* the count using a callback. */
1286 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ 1461 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
1287 /* result set is empty */ 1462 /* result set is empty */
1288 #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ 1463 #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
1289 #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ 1464 #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
1290 #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ 1465 #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
1291 #define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */ 1466 #define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */
1292 #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ 1467 #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */
1293 #define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */ 1468 #define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */
1294 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ 1469 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
1295 #define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */ 1470 #define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */
1296 #define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */ 1471 #define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */
1297 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ 1472 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
1298 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ 1473 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
1299 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ 1474 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
1300 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ 1475 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
1301 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ 1476 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1302 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ 1477 #define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */
1303 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ 1478 #define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */
1304 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ 1479 #define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */
1305 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ 1480 #define SQLITE_QueryOnly 0x04000000 /* Disable database changes */
1306 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ 1481 #define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */
1307 #define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */ 1482 #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
1483 #define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */
1484 #define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */
1485 #define SQLITE_NoCkptOnClose 0x80000000 /* No checkpoint on close()/DETACH */
1308 1486
1309 1487
1310 /* 1488 /*
1311 ** Bits of the sqlite3.dbOptFlags field that are used by the 1489 ** Bits of the sqlite3.dbOptFlags field that are used by the
1312 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to 1490 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1313 ** selectively disable various optimizations. 1491 ** selectively disable various optimizations.
1314 */ 1492 */
1315 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ 1493 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
1316 #define SQLITE_ColumnCache 0x0002 /* Column cache */ 1494 #define SQLITE_ColumnCache 0x0002 /* Column cache */
1317 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ 1495 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
1318 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ 1496 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
1319 /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ 1497 /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */
1320 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ 1498 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1321 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ 1499 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1322 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ 1500 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1323 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ 1501 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1324 #define SQLITE_Transitive 0x0200 /* Transitive constraints */ 1502 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
1325 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ 1503 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
1326 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ 1504 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
1327 #define SQLITE_CursorHints 0x2000 /* Add OP_CursorHint opcodes */ 1505 #define SQLITE_CursorHints 0x2000 /* Add OP_CursorHint opcodes */
1328 #define SQLITE_AllOpts 0xffff /* All optimizations */ 1506 #define SQLITE_AllOpts 0xffff /* All optimizations */
1329 1507
1330 /* 1508 /*
1331 ** Macros for testing whether or not optimizations are enabled or disabled. 1509 ** Macros for testing whether or not optimizations are enabled or disabled.
1332 */ 1510 */
1333 #ifndef SQLITE_OMIT_BUILTIN_TEST
1334 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) 1511 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
1335 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) 1512 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
1336 #else
1337 #define OptimizationDisabled(db, mask) 0
1338 #define OptimizationEnabled(db, mask) 1
1339 #endif
1340 1513
1341 /* 1514 /*
1342 ** Return true if it OK to factor constant expressions into the initialization 1515 ** Return true if it OK to factor constant expressions into the initialization
1343 ** code. The argument is a Parse object for the code generator. 1516 ** code. The argument is a Parse object for the code generator.
1344 */ 1517 */
1345 #define ConstFactorOk(P) ((P)->okConstFactor) 1518 #define ConstFactorOk(P) ((P)->okConstFactor)
1346 1519
1347 /* 1520 /*
1348 ** Possible values for the sqlite.magic field. 1521 ** Possible values for the sqlite.magic field.
1349 ** The numbers are obtained at random and have no special meaning, other 1522 ** The numbers are obtained at random and have no special meaning, other
1350 ** than being distinct from one another. 1523 ** than being distinct from one another.
1351 */ 1524 */
1352 #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */ 1525 #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
1353 #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */ 1526 #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
1354 #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */ 1527 #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
1355 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */ 1528 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
1356 #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */ 1529 #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
1357 #define SQLITE_MAGIC_ZOMBIE 0x64cffc7f /* Close with last statement close */ 1530 #define SQLITE_MAGIC_ZOMBIE 0x64cffc7f /* Close with last statement close */
1358 1531
1359 /* 1532 /*
1360 ** Each SQL function is defined by an instance of the following 1533 ** Each SQL function is defined by an instance of the following
1361 ** structure. A pointer to this structure is stored in the sqlite.aFunc 1534 ** structure. For global built-in functions (ex: substr(), max(), count())
1362 ** hash table. When multiple functions have the same name, the hash table 1535 ** a pointer to this structure is held in the sqlite3BuiltinFunctions object.
1363 ** points to a linked list of these structures. 1536 ** For per-connection application-defined functions, a pointer to this
1537 ** structure is held in the db->aHash hash table.
1538 **
1539 ** The u.pHash field is used by the global built-ins. The u.pDestructor
1540 ** field is used by per-connection app-def functions.
1364 */ 1541 */
1365 struct FuncDef { 1542 struct FuncDef {
1366 i16 nArg; /* Number of arguments. -1 means unlimited */ 1543 i8 nArg; /* Number of arguments. -1 means unlimited */
1367 u16 funcFlags; /* Some combination of SQLITE_FUNC_* */ 1544 u16 funcFlags; /* Some combination of SQLITE_FUNC_* */
1368 void *pUserData; /* User data parameter */ 1545 void *pUserData; /* User data parameter */
1369 FuncDef *pNext; /* Next function with same name */ 1546 FuncDef *pNext; /* Next function with same name */
1370 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ 1547 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */
1371 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ 1548 void (*xFinalize)(sqlite3_context*); /* Agg finalizer */
1372 void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */ 1549 const char *zName; /* SQL name of the function. */
1373 char *zName; /* SQL name of the function. */ 1550 union {
1374 FuncDef *pHash; /* Next with a different name but the same hash */ 1551 FuncDef *pHash; /* Next with a different name but the same hash */
1375 FuncDestructor *pDestructor; /* Reference counted destructor function */ 1552 FuncDestructor *pDestructor; /* Reference counted destructor function */
1553 } u;
1376 }; 1554 };
1377 1555
1378 /* 1556 /*
1379 ** This structure encapsulates a user-function destructor callback (as 1557 ** This structure encapsulates a user-function destructor callback (as
1380 ** configured using create_function_v2()) and a reference counter. When 1558 ** configured using create_function_v2()) and a reference counter. When
1381 ** create_function_v2() is called to create a function with a destructor, 1559 ** create_function_v2() is called to create a function with a destructor,
1382 ** a single object of this type is allocated. FuncDestructor.nRef is set to 1560 ** a single object of this type is allocated. FuncDestructor.nRef is set to
1383 ** the number of FuncDef objects created (either 1 or 3, depending on whether 1561 ** the number of FuncDef objects created (either 1 or 3, depending on whether
1384 ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor 1562 ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
1385 ** member of each of the new FuncDef objects is set to point to the allocated 1563 ** member of each of the new FuncDef objects is set to point to the allocated
1386 ** FuncDestructor. 1564 ** FuncDestructor.
1387 ** 1565 **
1388 ** Thereafter, when one of the FuncDef objects is deleted, the reference 1566 ** Thereafter, when one of the FuncDef objects is deleted, the reference
1389 ** count on this object is decremented. When it reaches 0, the destructor 1567 ** count on this object is decremented. When it reaches 0, the destructor
1390 ** is invoked and the FuncDestructor structure freed. 1568 ** is invoked and the FuncDestructor structure freed.
1391 */ 1569 */
1392 struct FuncDestructor { 1570 struct FuncDestructor {
1393 int nRef; 1571 int nRef;
1394 void (*xDestroy)(void *); 1572 void (*xDestroy)(void *);
1395 void *pUserData; 1573 void *pUserData;
1396 }; 1574 };
1397 1575
1398 /* 1576 /*
1399 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF 1577 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
1400 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And 1578 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
1401 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There 1579 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
1402 ** are assert() statements in the code to verify this. 1580 ** are assert() statements in the code to verify this.
1581 **
1582 ** Value constraints (enforced via assert()):
1583 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
1584 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
1585 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
1586 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
1587 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1403 */ 1588 */
1404 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ 1589 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1405 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ 1590 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1406 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ 1591 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
1407 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ 1592 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
1408 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/ 1593 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
1409 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */ 1594 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
1410 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ 1595 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
1411 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ 1596 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
1412 #define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */ 1597 #define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
1413 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ 1598 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
1414 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ 1599 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1415 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ 1600 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1416 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a 1601 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1417 ** single query - might change over time */ 1602 ** single query - might change over time */
1603 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
1418 1604
1419 /* 1605 /*
1420 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are 1606 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1421 ** used to create the initializers for the FuncDef structures. 1607 ** used to create the initializers for the FuncDef structures.
1422 ** 1608 **
1423 ** FUNCTION(zName, nArg, iArg, bNC, xFunc) 1609 ** FUNCTION(zName, nArg, iArg, bNC, xFunc)
1424 ** Used to create a scalar function definition of a function zName 1610 ** Used to create a scalar function definition of a function zName
1425 ** implemented by C function xFunc that accepts nArg arguments. The 1611 ** implemented by C function xFunc that accepts nArg arguments. The
1426 ** value passed as iArg is cast to a (void*) and made available 1612 ** value passed as iArg is cast to a (void*) and made available
1427 ** as the user-data (sqlite3_user_data()) for the function. If 1613 ** as the user-data (sqlite3_user_data()) for the function. If
1428 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. 1614 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1429 ** 1615 **
1430 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc) 1616 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
1431 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. 1617 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
1432 ** 1618 **
1433 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc) 1619 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
1434 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and 1620 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
1435 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions 1621 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
1436 ** and functions like sqlite_version() that can change, but not during 1622 ** and functions like sqlite_version() that can change, but not during
1437 ** a single query. 1623 ** a single query.
1438 ** 1624 **
1439 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) 1625 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
1440 ** Used to create an aggregate function definition implemented by 1626 ** Used to create an aggregate function definition implemented by
1441 ** the C functions xStep and xFinal. The first four parameters 1627 ** the C functions xStep and xFinal. The first four parameters
1442 ** are interpreted in the same way as the first 4 parameters to 1628 ** are interpreted in the same way as the first 4 parameters to
1443 ** FUNCTION(). 1629 ** FUNCTION().
1444 ** 1630 **
1445 ** LIKEFUNC(zName, nArg, pArg, flags) 1631 ** LIKEFUNC(zName, nArg, pArg, flags)
1446 ** Used to create a scalar function definition of a function zName 1632 ** Used to create a scalar function definition of a function zName
1447 ** that accepts nArg arguments and is implemented by a call to C 1633 ** that accepts nArg arguments and is implemented by a call to C
1448 ** function likeFunc. Argument pArg is cast to a (void *) and made 1634 ** function likeFunc. Argument pArg is cast to a (void *) and made
1449 ** available as the function user-data (sqlite3_user_data()). The 1635 ** available as the function user-data (sqlite3_user_data()). The
1450 ** FuncDef.flags variable is set to the value passed as the flags 1636 ** FuncDef.flags variable is set to the value passed as the flags
1451 ** parameter. 1637 ** parameter.
1452 */ 1638 */
1453 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ 1639 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
1454 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 1640 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1455 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 1641 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1456 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ 1642 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1457 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 1643 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1458 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 1644 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1459 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ 1645 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1460 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 1646 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1461 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 1647 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1462 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ 1648 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
1463 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ 1649 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1464 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} 1650 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1465 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ 1651 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
1466 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ 1652 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1467 pArg, 0, xFunc, 0, 0, #zName, 0, 0} 1653 pArg, 0, xFunc, 0, #zName, }
1468 #define LIKEFUNC(zName, nArg, arg, flags) \ 1654 #define LIKEFUNC(zName, nArg, arg, flags) \
1469 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ 1655 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1470 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} 1656 (void *)arg, 0, likeFunc, 0, #zName, {0} }
1471 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ 1657 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
1472 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ 1658 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
1473 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} 1659 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
1474 #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ 1660 #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
1475 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ 1661 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
1476 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} 1662 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
1477 1663
1478 /* 1664 /*
1479 ** All current savepoints are stored in a linked list starting at 1665 ** All current savepoints are stored in a linked list starting at
1480 ** sqlite3.pSavepoint. The first element in the list is the most recently 1666 ** sqlite3.pSavepoint. The first element in the list is the most recently
1481 ** opened savepoint. Savepoints are added to the list by the vdbe 1667 ** opened savepoint. Savepoints are added to the list by the vdbe
1482 ** OP_Savepoint instruction. 1668 ** OP_Savepoint instruction.
1483 */ 1669 */
1484 struct Savepoint { 1670 struct Savepoint {
1485 char *zName; /* Savepoint name (nul-terminated) */ 1671 char *zName; /* Savepoint name (nul-terminated) */
1486 i64 nDeferredCons; /* Number of deferred fk violations */ 1672 i64 nDeferredCons; /* Number of deferred fk violations */
(...skipping 21 matching lines...) Expand all
1508 void *pAux; /* pAux passed to create_module() */ 1694 void *pAux; /* pAux passed to create_module() */
1509 void (*xDestroy)(void *); /* Module destructor function */ 1695 void (*xDestroy)(void *); /* Module destructor function */
1510 Table *pEpoTab; /* Eponymous table for this module */ 1696 Table *pEpoTab; /* Eponymous table for this module */
1511 }; 1697 };
1512 1698
1513 /* 1699 /*
1514 ** information about each column of an SQL table is held in an instance 1700 ** information about each column of an SQL table is held in an instance
1515 ** of this structure. 1701 ** of this structure.
1516 */ 1702 */
1517 struct Column { 1703 struct Column {
1518 char *zName; /* Name of this column */ 1704 char *zName; /* Name of this column, \000, then the type */
1519 Expr *pDflt; /* Default value of this column */ 1705 Expr *pDflt; /* Default value of this column */
1520 char *zDflt; /* Original text of the default value */
1521 char *zType; /* Data type for this column */
1522 char *zColl; /* Collating sequence. If NULL, use the default */ 1706 char *zColl; /* Collating sequence. If NULL, use the default */
1523 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ 1707 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
1524 char affinity; /* One of the SQLITE_AFF_... values */ 1708 char affinity; /* One of the SQLITE_AFF_... values */
1525 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ 1709 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
1526 u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */ 1710 u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */
1527 }; 1711 };
1528 1712
1529 /* Allowed values for Column.colFlags: 1713 /* Allowed values for Column.colFlags:
1530 */ 1714 */
1531 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ 1715 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
1532 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ 1716 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
1717 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
1533 1718
1534 /* 1719 /*
1535 ** A "Collating Sequence" is defined by an instance of the following 1720 ** A "Collating Sequence" is defined by an instance of the following
1536 ** structure. Conceptually, a collating sequence consists of a name and 1721 ** structure. Conceptually, a collating sequence consists of a name and
1537 ** a comparison routine that defines the order of that sequence. 1722 ** a comparison routine that defines the order of that sequence.
1538 ** 1723 **
1539 ** If CollSeq.xCmp is NULL, it means that the 1724 ** If CollSeq.xCmp is NULL, it means that the
1540 ** collating sequence is undefined. Indices built on an undefined 1725 ** collating sequence is undefined. Indices built on an undefined
1541 ** collating sequence may not be read or written. 1726 ** collating sequence may not be read or written.
1542 */ 1727 */
(...skipping 10 matching lines...) Expand all
1553 */ 1738 */
1554 #define SQLITE_SO_ASC 0 /* Sort in ascending order */ 1739 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
1555 #define SQLITE_SO_DESC 1 /* Sort in ascending order */ 1740 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
1556 #define SQLITE_SO_UNDEFINED -1 /* No sort order specified */ 1741 #define SQLITE_SO_UNDEFINED -1 /* No sort order specified */
1557 1742
1558 /* 1743 /*
1559 ** Column affinity types. 1744 ** Column affinity types.
1560 ** 1745 **
1561 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and 1746 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
1562 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve 1747 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
1563 ** the speed a little by numbering the values consecutively. 1748 ** the speed a little by numbering the values consecutively.
1564 ** 1749 **
1565 ** But rather than start with 0 or 1, we begin with 'A'. That way, 1750 ** But rather than start with 0 or 1, we begin with 'A'. That way,
1566 ** when multiple affinity types are concatenated into a string and 1751 ** when multiple affinity types are concatenated into a string and
1567 ** used as the P4 operand, they will be more readable. 1752 ** used as the P4 operand, they will be more readable.
1568 ** 1753 **
1569 ** Note also that the numeric types are grouped together so that testing 1754 ** Note also that the numeric types are grouped together so that testing
1570 ** for a numeric type is a single comparison. And the BLOB type is first. 1755 ** for a numeric type is a single comparison. And the BLOB type is first.
1571 */ 1756 */
1572 #define SQLITE_AFF_BLOB 'A' 1757 #define SQLITE_AFF_BLOB 'A'
1573 #define SQLITE_AFF_TEXT 'B' 1758 #define SQLITE_AFF_TEXT 'B'
1574 #define SQLITE_AFF_NUMERIC 'C' 1759 #define SQLITE_AFF_NUMERIC 'C'
1575 #define SQLITE_AFF_INTEGER 'D' 1760 #define SQLITE_AFF_INTEGER 'D'
1576 #define SQLITE_AFF_REAL 'E' 1761 #define SQLITE_AFF_REAL 'E'
1577 1762
1578 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) 1763 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
1579 1764
1580 /* 1765 /*
1581 ** The SQLITE_AFF_MASK values masks off the significant bits of an 1766 ** The SQLITE_AFF_MASK values masks off the significant bits of an
1582 ** affinity value. 1767 ** affinity value.
1583 */ 1768 */
1584 #define SQLITE_AFF_MASK 0x47 1769 #define SQLITE_AFF_MASK 0x47
1585 1770
1586 /* 1771 /*
1587 ** Additional bit values that can be ORed with an affinity without 1772 ** Additional bit values that can be ORed with an affinity without
1588 ** changing the affinity. 1773 ** changing the affinity.
1589 ** 1774 **
1590 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. 1775 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
1591 ** It causes an assert() to fire if either operand to a comparison 1776 ** It causes an assert() to fire if either operand to a comparison
1592 ** operator is NULL. It is added to certain comparison operators to 1777 ** operator is NULL. It is added to certain comparison operators to
1593 ** prove that the operands are always NOT NULL. 1778 ** prove that the operands are always NOT NULL.
1594 */ 1779 */
1780 #define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */
1595 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */ 1781 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
1596 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */ 1782 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
1597 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ 1783 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
1598 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */ 1784 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
1599 1785
1600 /* 1786 /*
1601 ** An object of this type is created for each virtual table present in 1787 ** An object of this type is created for each virtual table present in
1602 ** the database schema. 1788 ** the database schema.
1603 ** 1789 **
1604 ** If the database schema is shared, then there is one instance of this 1790 ** If the database schema is shared, then there is one instance of this
1605 ** structure for each database connection (sqlite3*) that uses the shared 1791 ** structure for each database connection (sqlite3*) that uses the shared
1606 ** schema. This is because each database connection requires its own unique 1792 ** schema. This is because each database connection requires its own unique
1607 ** instance of the sqlite3_vtab* handle used to access the virtual table 1793 ** instance of the sqlite3_vtab* handle used to access the virtual table
1608 ** implementation. sqlite3_vtab* handles can not be shared between 1794 ** implementation. sqlite3_vtab* handles can not be shared between
1609 ** database connections, even when the rest of the in-memory database 1795 ** database connections, even when the rest of the in-memory database
1610 ** schema is shared, as the implementation often stores the database 1796 ** schema is shared, as the implementation often stores the database
1611 ** connection handle passed to it via the xConnect() or xCreate() method 1797 ** connection handle passed to it via the xConnect() or xCreate() method
1612 ** during initialization internally. This database connection handle may 1798 ** during initialization internally. This database connection handle may
1613 ** then be used by the virtual table implementation to access real tables 1799 ** then be used by the virtual table implementation to access real tables
1614 ** within the database. So that they appear as part of the callers 1800 ** within the database. So that they appear as part of the callers
1615 ** transaction, these accesses need to be made via the same database 1801 ** transaction, these accesses need to be made via the same database
1616 ** connection as that used to execute SQL operations on the virtual table. 1802 ** connection as that used to execute SQL operations on the virtual table.
1617 ** 1803 **
1618 ** All VTable objects that correspond to a single table in a shared 1804 ** All VTable objects that correspond to a single table in a shared
1619 ** database schema are initially stored in a linked-list pointed to by 1805 ** database schema are initially stored in a linked-list pointed to by
1620 ** the Table.pVTable member variable of the corresponding Table object. 1806 ** the Table.pVTable member variable of the corresponding Table object.
1621 ** When an sqlite3_prepare() operation is required to access the virtual 1807 ** When an sqlite3_prepare() operation is required to access the virtual
1622 ** table, it searches the list for the VTable that corresponds to the 1808 ** table, it searches the list for the VTable that corresponds to the
1623 ** database connection doing the preparing so as to use the correct 1809 ** database connection doing the preparing so as to use the correct
1624 ** sqlite3_vtab* handle in the compiled query. 1810 ** sqlite3_vtab* handle in the compiled query.
1625 ** 1811 **
1626 ** When an in-memory Table object is deleted (for example when the 1812 ** When an in-memory Table object is deleted (for example when the
1627 ** schema is being reloaded for some reason), the VTable objects are not 1813 ** schema is being reloaded for some reason), the VTable objects are not
1628 ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed 1814 ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
1629 ** immediately. Instead, they are moved from the Table.pVTable list to 1815 ** immediately. Instead, they are moved from the Table.pVTable list to
1630 ** another linked list headed by the sqlite3.pDisconnect member of the 1816 ** another linked list headed by the sqlite3.pDisconnect member of the
1631 ** corresponding sqlite3 structure. They are then deleted/xDisconnected 1817 ** corresponding sqlite3 structure. They are then deleted/xDisconnected
1632 ** next time a statement is prepared using said sqlite3*. This is done 1818 ** next time a statement is prepared using said sqlite3*. This is done
1633 ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes. 1819 ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
1634 ** Refer to comments above function sqlite3VtabUnlockList() for an 1820 ** Refer to comments above function sqlite3VtabUnlockList() for an
1635 ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect 1821 ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
1636 ** list without holding the corresponding sqlite3.mutex mutex. 1822 ** list without holding the corresponding sqlite3.mutex mutex.
1637 ** 1823 **
1638 ** The memory for objects of this type is always allocated by 1824 ** The memory for objects of this type is always allocated by
1639 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as 1825 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
1640 ** the first argument. 1826 ** the first argument.
1641 */ 1827 */
1642 struct VTable { 1828 struct VTable {
1643 sqlite3 *db; /* Database connection associated with this table */ 1829 sqlite3 *db; /* Database connection associated with this table */
1644 Module *pMod; /* Pointer to module implementation */ 1830 Module *pMod; /* Pointer to module implementation */
1645 sqlite3_vtab *pVtab; /* Pointer to vtab instance */ 1831 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
1646 int nRef; /* Number of pointers to this structure */ 1832 int nRef; /* Number of pointers to this structure */
1647 u8 bConstraint; /* True if constraints are supported */ 1833 u8 bConstraint; /* True if constraints are supported */
1648 int iSavepoint; /* Depth of the SAVEPOINT stack */ 1834 int iSavepoint; /* Depth of the SAVEPOINT stack */
1649 VTable *pNext; /* Next in linked list (see above) */ 1835 VTable *pNext; /* Next in linked list (see above) */
1650 }; 1836 };
1651 1837
1652 /* 1838 /*
1653 ** The schema for each SQL table and view is represented in memory 1839 ** The schema for each SQL table and view is represented in memory
1654 ** by an instance of the following structure. 1840 ** by an instance of the following structure.
1655 */ 1841 */
1656 struct Table { 1842 struct Table {
1657 char *zName; /* Name of the table or view */ 1843 char *zName; /* Name of the table or view */
1658 Column *aCol; /* Information about each column */ 1844 Column *aCol; /* Information about each column */
1659 Index *pIndex; /* List of SQL indexes on this table. */ 1845 Index *pIndex; /* List of SQL indexes on this table. */
1660 Select *pSelect; /* NULL for tables. Points to definition if a view. */ 1846 Select *pSelect; /* NULL for tables. Points to definition if a view. */
1661 FKey *pFKey; /* Linked list of all foreign keys in this table */ 1847 FKey *pFKey; /* Linked list of all foreign keys in this table */
1662 char *zColAff; /* String defining the affinity of each column */ 1848 char *zColAff; /* String defining the affinity of each column */
1663 ExprList *pCheck; /* All CHECK constraints */ 1849 ExprList *pCheck; /* All CHECK constraints */
1664 /* ... also used as column name list in a VIEW */ 1850 /* ... also used as column name list in a VIEW */
1665 int tnum; /* Root BTree page for this table */ 1851 int tnum; /* Root BTree page for this table */
1852 u32 nTabRef; /* Number of pointers to this Table */
1666 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ 1853 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1667 i16 nCol; /* Number of columns in this table */ 1854 i16 nCol; /* Number of columns in this table */
1668 u16 nRef; /* Number of pointers to this Table */
1669 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ 1855 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1670 LogEst szTabRow; /* Estimated size of each table row in bytes */ 1856 LogEst szTabRow; /* Estimated size of each table row in bytes */
1671 #ifdef SQLITE_ENABLE_COSTMULT 1857 #ifdef SQLITE_ENABLE_COSTMULT
1672 LogEst costMult; /* Cost multiplier for using this table */ 1858 LogEst costMult; /* Cost multiplier for using this table */
1673 #endif 1859 #endif
1674 u8 tabFlags; /* Mask of TF_* values */ 1860 u8 tabFlags; /* Mask of TF_* values */
1675 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ 1861 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
1676 #ifndef SQLITE_OMIT_ALTERTABLE 1862 #ifndef SQLITE_OMIT_ALTERTABLE
1677 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ 1863 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
1678 #endif 1864 #endif
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 ** is returned. REPLACE means that preexisting database rows that caused 1983 ** is returned. REPLACE means that preexisting database rows that caused
1798 ** a UNIQUE constraint violation are removed so that the new insert or 1984 ** a UNIQUE constraint violation are removed so that the new insert or
1799 ** update can proceed. Processing continues and no error is reported. 1985 ** update can proceed. Processing continues and no error is reported.
1800 ** 1986 **
1801 ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys. 1987 ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
1802 ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the 1988 ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
1803 ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign 1989 ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
1804 ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the 1990 ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
1805 ** referenced table row is propagated into the row that holds the 1991 ** referenced table row is propagated into the row that holds the
1806 ** foreign key. 1992 ** foreign key.
1807 ** 1993 **
1808 ** The following symbolic values are used to record which type 1994 ** The following symbolic values are used to record which type
1809 ** of action to take. 1995 ** of action to take.
1810 */ 1996 */
1811 #define OE_None 0 /* There is no constraint to check */ 1997 #define OE_None 0 /* There is no constraint to check */
1812 #define OE_Rollback 1 /* Fail the operation and rollback the transaction */ 1998 #define OE_Rollback 1 /* Fail the operation and rollback the transaction */
1813 #define OE_Abort 2 /* Back out changes but do no rollback transaction */ 1999 #define OE_Abort 2 /* Back out changes but do no rollback transaction */
1814 #define OE_Fail 3 /* Stop the operation but leave all prior changes */ 2000 #define OE_Fail 3 /* Stop the operation but leave all prior changes */
1815 #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ 2001 #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
1816 #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ 2002 #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
1817 2003
1818 #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ 2004 #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
1819 #define OE_SetNull 7 /* Set the foreign key value to NULL */ 2005 #define OE_SetNull 7 /* Set the foreign key value to NULL */
1820 #define OE_SetDflt 8 /* Set the foreign key value to its default */ 2006 #define OE_SetDflt 8 /* Set the foreign key value to its default */
1821 #define OE_Cascade 9 /* Cascade the changes */ 2007 #define OE_Cascade 9 /* Cascade the changes */
1822 2008
1823 #define OE_Default 10 /* Do whatever the default action is */ 2009 #define OE_Default 10 /* Do whatever the default action is */
1824 2010
1825 2011
1826 /* 2012 /*
1827 ** An instance of the following structure is passed as the first 2013 ** An instance of the following structure is passed as the first
1828 ** argument to sqlite3VdbeKeyCompare and is used to control the 2014 ** argument to sqlite3VdbeKeyCompare and is used to control the
1829 ** comparison of the two index keys. 2015 ** comparison of the two index keys.
1830 ** 2016 **
1831 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There 2017 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There
1832 ** are nField slots for the columns of an index then one extra slot 2018 ** are nField slots for the columns of an index then one extra slot
1833 ** for the rowid at the end. 2019 ** for the rowid at the end.
1834 */ 2020 */
1835 struct KeyInfo { 2021 struct KeyInfo {
1836 u32 nRef; /* Number of references to this KeyInfo object */ 2022 u32 nRef; /* Number of references to this KeyInfo object */
1837 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */ 2023 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
1838 u16 nField; /* Number of key columns in the index */ 2024 u16 nField; /* Number of key columns in the index */
(...skipping 20 matching lines...) Expand all
1859 ** pKeyInfo->nField. 2045 ** pKeyInfo->nField.
1860 ** 2046 **
1861 ** The r1 and r2 fields are the values to return if this key is less than 2047 ** The r1 and r2 fields are the values to return if this key is less than
1862 ** or greater than a key in the btree, respectively. These are normally 2048 ** or greater than a key in the btree, respectively. These are normally
1863 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree 2049 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
1864 ** is in DESC order. 2050 ** is in DESC order.
1865 ** 2051 **
1866 ** The key comparison functions actually return default_rc when they find 2052 ** The key comparison functions actually return default_rc when they find
1867 ** an equals comparison. default_rc can be -1, 0, or +1. If there are 2053 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
1868 ** multiple entries in the b-tree with the same key (when only looking 2054 ** multiple entries in the b-tree with the same key (when only looking
1869 ** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to 2055 ** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to
1870 ** cause the search to find the last match, or +1 to cause the search to 2056 ** cause the search to find the last match, or +1 to cause the search to
1871 ** find the first match. 2057 ** find the first match.
1872 ** 2058 **
1873 ** The key comparison functions will set eqSeen to true if they ever 2059 ** The key comparison functions will set eqSeen to true if they ever
1874 ** get and equal results when comparing this structure to a b-tree record. 2060 ** get and equal results when comparing this structure to a b-tree record.
1875 ** When default_rc!=0, the search might end up on the record immediately 2061 ** When default_rc!=0, the search might end up on the record immediately
1876 ** before the first match or immediately after the last match. The 2062 ** before the first match or immediately after the last match. The
1877 ** eqSeen field will indicate whether or not an exact match exists in the 2063 ** eqSeen field will indicate whether or not an exact match exists in the
1878 ** b-tree. 2064 ** b-tree.
1879 */ 2065 */
(...skipping 16 matching lines...) Expand all
1896 ** The columns of the table that are to be indexed are described 2082 ** The columns of the table that are to be indexed are described
1897 ** by the aiColumn[] field of this structure. For example, suppose 2083 ** by the aiColumn[] field of this structure. For example, suppose
1898 ** we have the following table and index: 2084 ** we have the following table and index:
1899 ** 2085 **
1900 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text); 2086 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
1901 ** CREATE INDEX Ex2 ON Ex1(c3,c1); 2087 ** CREATE INDEX Ex2 ON Ex1(c3,c1);
1902 ** 2088 **
1903 ** In the Table structure describing Ex1, nCol==3 because there are 2089 ** In the Table structure describing Ex1, nCol==3 because there are
1904 ** three columns in the table. In the Index structure describing 2090 ** three columns in the table. In the Index structure describing
1905 ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. 2091 ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
1906 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the 2092 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
1907 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. 2093 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
1908 ** The second column to be indexed (c1) has an index of 0 in 2094 ** The second column to be indexed (c1) has an index of 0 in
1909 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. 2095 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
1910 ** 2096 **
1911 ** The Index.onError field determines whether or not the indexed columns 2097 ** The Index.onError field determines whether or not the indexed columns
1912 ** must be unique and what to do if they are not. When Index.onError=OE_None, 2098 ** must be unique and what to do if they are not. When Index.onError=OE_None,
1913 ** it means this is not a unique index. Otherwise it is a unique index 2099 ** it means this is not a unique index. Otherwise it is a unique index
1914 ** and the value of Index.onError indicate the which conflict resolution 2100 ** and the value of Index.onError indicate the which conflict resolution
1915 ** algorithm to employ whenever an attempt is made to insert a non-unique 2101 ** algorithm to employ whenever an attempt is made to insert a non-unique
1916 ** element. 2102 ** element.
1917 ** 2103 **
1918 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to 2104 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to
1919 ** generate VDBE code (as opposed to parsing one read from an sqlite_master 2105 ** generate VDBE code (as opposed to parsing one read from an sqlite_master
1920 ** table as part of parsing an existing database schema), transient instances 2106 ** table as part of parsing an existing database schema), transient instances
1921 ** of this structure may be created. In this case the Index.tnum variable is 2107 ** of this structure may be created. In this case the Index.tnum variable is
1922 ** used to store the address of a VDBE instruction, not a database page 2108 ** used to store the address of a VDBE instruction, not a database page
1923 ** number (it cannot - the database page is not allocated until the VDBE 2109 ** number (it cannot - the database page is not allocated until the VDBE
1924 ** program is executed). See convertToWithoutRowidTable() for details. 2110 ** program is executed). See convertToWithoutRowidTable() for details.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 /* Return true if index X is a UNIQUE index */ 2155 /* Return true if index X is a UNIQUE index */
1970 #define IsUniqueIndex(X) ((X)->onError!=OE_None) 2156 #define IsUniqueIndex(X) ((X)->onError!=OE_None)
1971 2157
1972 /* The Index.aiColumn[] values are normally positive integer. But 2158 /* The Index.aiColumn[] values are normally positive integer. But
1973 ** there are some negative values that have special meaning: 2159 ** there are some negative values that have special meaning:
1974 */ 2160 */
1975 #define XN_ROWID (-1) /* Indexed column is the rowid */ 2161 #define XN_ROWID (-1) /* Indexed column is the rowid */
1976 #define XN_EXPR (-2) /* Indexed column is an expression */ 2162 #define XN_EXPR (-2) /* Indexed column is an expression */
1977 2163
1978 /* 2164 /*
1979 ** Each sample stored in the sqlite_stat3 table is represented in memory 2165 ** Each sample stored in the sqlite_stat3 table is represented in memory
1980 ** using a structure of this type. See documentation at the top of the 2166 ** using a structure of this type. See documentation at the top of the
1981 ** analyze.c source file for additional information. 2167 ** analyze.c source file for additional information.
1982 */ 2168 */
1983 struct IndexSample { 2169 struct IndexSample {
1984 void *p; /* Pointer to sampled record */ 2170 void *p; /* Pointer to sampled record */
1985 int n; /* Size of record in bytes */ 2171 int n; /* Size of record in bytes */
1986 tRowcnt *anEq; /* Est. number of rows where the key equals this sample */ 2172 tRowcnt *anEq; /* Est. number of rows where the key equals this sample */
1987 tRowcnt *anLt; /* Est. number of rows where key is less than this sample */ 2173 tRowcnt *anLt; /* Est. number of rows where key is less than this sample */
1988 tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */ 2174 tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */
1989 }; 2175 };
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 /* 2250 /*
2065 ** Each node of an expression in the parse tree is an instance 2251 ** Each node of an expression in the parse tree is an instance
2066 ** of this structure. 2252 ** of this structure.
2067 ** 2253 **
2068 ** Expr.op is the opcode. The integer parser token codes are reused 2254 ** Expr.op is the opcode. The integer parser token codes are reused
2069 ** as opcodes here. For example, the parser defines TK_GE to be an integer 2255 ** as opcodes here. For example, the parser defines TK_GE to be an integer
2070 ** code representing the ">=" operator. This same integer code is reused 2256 ** code representing the ">=" operator. This same integer code is reused
2071 ** to represent the greater-than-or-equal-to operator in the expression 2257 ** to represent the greater-than-or-equal-to operator in the expression
2072 ** tree. 2258 ** tree.
2073 ** 2259 **
2074 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB, 2260 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
2075 ** or TK_STRING), then Expr.token contains the text of the SQL literal. If 2261 ** or TK_STRING), then Expr.token contains the text of the SQL literal. If
2076 ** the expression is a variable (TK_VARIABLE), then Expr.token contains the 2262 ** the expression is a variable (TK_VARIABLE), then Expr.token contains the
2077 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION), 2263 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
2078 ** then Expr.token contains the name of the function. 2264 ** then Expr.token contains the name of the function.
2079 ** 2265 **
2080 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a 2266 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
2081 ** binary operator. Either or both may be NULL. 2267 ** binary operator. Either or both may be NULL.
2082 ** 2268 **
2083 ** Expr.x.pList is a list of arguments if the expression is an SQL function, 2269 ** Expr.x.pList is a list of arguments if the expression is an SQL function,
2084 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)". 2270 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
2085 ** Expr.x.pSelect is used if the expression is a sub-select or an expression of 2271 ** Expr.x.pSelect is used if the expression is a sub-select or an expression of
2086 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the 2272 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
2087 ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is 2273 ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
2088 ** valid. 2274 ** valid.
2089 ** 2275 **
2090 ** An expression of the form ID or ID.ID refers to a column in a table. 2276 ** An expression of the form ID or ID.ID refers to a column in a table.
2091 ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is 2277 ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
2092 ** the integer cursor number of a VDBE cursor pointing to that table and 2278 ** the integer cursor number of a VDBE cursor pointing to that table and
2093 ** Expr.iColumn is the column number for the specific column. If the 2279 ** Expr.iColumn is the column number for the specific column. If the
2094 ** expression is used as a result in an aggregate SELECT, then the 2280 ** expression is used as a result in an aggregate SELECT, then the
2095 ** value is also stored in the Expr.iAgg column in the aggregate so that 2281 ** value is also stored in the Expr.iAgg column in the aggregate so that
2096 ** it can be accessed after all aggregates are computed. 2282 ** it can be accessed after all aggregates are computed.
2097 ** 2283 **
2098 ** If the expression is an unbound variable marker (a question mark 2284 ** If the expression is an unbound variable marker (a question mark
2099 ** character '?' in the original SQL) then the Expr.iTable holds the index 2285 ** character '?' in the original SQL) then the Expr.iTable holds the index
2100 ** number for that variable. 2286 ** number for that variable.
2101 ** 2287 **
2102 ** If the expression is a subquery then Expr.iColumn holds an integer 2288 ** If the expression is a subquery then Expr.iColumn holds an integer
2103 ** register number containing the result of the subquery. If the 2289 ** register number containing the result of the subquery. If the
2104 ** subquery gives a constant result, then iTable is -1. If the subquery 2290 ** subquery gives a constant result, then iTable is -1. If the subquery
2105 ** gives a different answer at different times during statement processing 2291 ** gives a different answer at different times during statement processing
2106 ** then iTable is the address of a subroutine that computes the subquery. 2292 ** then iTable is the address of a subroutine that computes the subquery.
2107 ** 2293 **
2108 ** If the Expr is of type OP_Column, and the table it is selecting from 2294 ** If the Expr is of type OP_Column, and the table it is selecting from
2109 ** is a disk table or the "old.*" pseudo-table, then pTab points to the 2295 ** is a disk table or the "old.*" pseudo-table, then pTab points to the
(...skipping 18 matching lines...) Expand all
2128 u8 op; /* Operation performed by this node */ 2314 u8 op; /* Operation performed by this node */
2129 char affinity; /* The affinity of the column or 0 if not a column */ 2315 char affinity; /* The affinity of the column or 0 if not a column */
2130 u32 flags; /* Various flags. EP_* See below */ 2316 u32 flags; /* Various flags. EP_* See below */
2131 union { 2317 union {
2132 char *zToken; /* Token value. Zero terminated and dequoted */ 2318 char *zToken; /* Token value. Zero terminated and dequoted */
2133 int iValue; /* Non-negative integer value if EP_IntValue */ 2319 int iValue; /* Non-negative integer value if EP_IntValue */
2134 } u; 2320 } u;
2135 2321
2136 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no 2322 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
2137 ** space is allocated for the fields below this point. An attempt to 2323 ** space is allocated for the fields below this point. An attempt to
2138 ** access them will result in a segfault or malfunction. 2324 ** access them will result in a segfault or malfunction.
2139 *********************************************************************/ 2325 *********************************************************************/
2140 2326
2141 Expr *pLeft; /* Left subnode */ 2327 Expr *pLeft; /* Left subnode */
2142 Expr *pRight; /* Right subnode */ 2328 Expr *pRight; /* Right subnode */
2143 union { 2329 union {
2144 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */ 2330 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
2145 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */ 2331 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
2146 } x; 2332 } x;
2147 2333
2148 /* If the EP_Reduced flag is set in the Expr.flags mask, then no 2334 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
2149 ** space is allocated for the fields below this point. An attempt to 2335 ** space is allocated for the fields below this point. An attempt to
2150 ** access them will result in a segfault or malfunction. 2336 ** access them will result in a segfault or malfunction.
2151 *********************************************************************/ 2337 *********************************************************************/
2152 2338
2153 #if SQLITE_MAX_EXPR_DEPTH>0 2339 #if SQLITE_MAX_EXPR_DEPTH>0
2154 int nHeight; /* Height of the tree headed by this node */ 2340 int nHeight; /* Height of the tree headed by this node */
2155 #endif 2341 #endif
2156 int iTable; /* TK_COLUMN: cursor number of table holding column 2342 int iTable; /* TK_COLUMN: cursor number of table holding column
2157 ** TK_REGISTER: register number 2343 ** TK_REGISTER: register number
2158 ** TK_TRIGGER: 1 -> new, 0 -> old 2344 ** TK_TRIGGER: 1 -> new, 0 -> old
2159 ** EP_Unlikely: 134217728 times likelihood */ 2345 ** EP_Unlikely: 134217728 times likelihood
2346 ** TK_SELECT: 1st register of result vector */
2160 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. 2347 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
2161 ** TK_VARIABLE: variable number (always >= 1). */ 2348 ** TK_VARIABLE: variable number (always >= 1).
2349 ** TK_SELECT_COLUMN: column of the result vector */
2162 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ 2350 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
2163 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ 2351 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
2164 u8 op2; /* TK_REGISTER: original value of Expr.op 2352 u8 op2; /* TK_REGISTER: original value of Expr.op
2165 ** TK_COLUMN: the value of p5 for OP_Column 2353 ** TK_COLUMN: the value of p5 for OP_Column
2166 ** TK_AGG_FUNCTION: nesting depth */ 2354 ** TK_AGG_FUNCTION: nesting depth */
2167 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ 2355 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
2168 Table *pTab; /* Table for TK_COLUMN expressions. */ 2356 Table *pTab; /* Table for TK_COLUMN expressions. */
2169 }; 2357 };
2170 2358
2171 /* 2359 /*
(...skipping 15 matching lines...) Expand all
2187 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ 2375 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
2188 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ 2376 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
2189 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ 2377 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
2190 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ 2378 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
2191 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ 2379 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
2192 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ 2380 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
2193 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ 2381 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
2194 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ 2382 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
2195 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ 2383 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
2196 #define EP_Alias 0x400000 /* Is an alias for a result set column */ 2384 #define EP_Alias 0x400000 /* Is an alias for a result set column */
2385 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
2197 2386
2198 /* 2387 /*
2199 ** Combinations of two or more EP_* flags 2388 ** Combinations of two or more EP_* flags
2200 */ 2389 */
2201 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */ 2390 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
2202 2391
2203 /* 2392 /*
2204 ** These macros can be used to test, set, or clear bits in the 2393 ** These macros can be used to test, set, or clear bits in the
2205 ** Expr.flags field. 2394 ** Expr.flags field.
2206 */ 2395 */
2207 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) 2396 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
2208 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) 2397 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
2209 #define ExprSetProperty(E,P) (E)->flags|=(P) 2398 #define ExprSetProperty(E,P) (E)->flags|=(P)
2210 #define ExprClearProperty(E,P) (E)->flags&=~(P) 2399 #define ExprClearProperty(E,P) (E)->flags&=~(P)
2211 2400
2212 /* The ExprSetVVAProperty() macro is used for Verification, Validation, 2401 /* The ExprSetVVAProperty() macro is used for Verification, Validation,
2213 ** and Accreditation only. It works like ExprSetProperty() during VVA 2402 ** and Accreditation only. It works like ExprSetProperty() during VVA
2214 ** processes but is a no-op for delivery. 2403 ** processes but is a no-op for delivery.
2215 */ 2404 */
2216 #ifdef SQLITE_DEBUG 2405 #ifdef SQLITE_DEBUG
2217 # define ExprSetVVAProperty(E,P) (E)->flags|=(P) 2406 # define ExprSetVVAProperty(E,P) (E)->flags|=(P)
2218 #else 2407 #else
2219 # define ExprSetVVAProperty(E,P) 2408 # define ExprSetVVAProperty(E,P)
2220 #endif 2409 #endif
2221 2410
2222 /* 2411 /*
2223 ** Macros to determine the number of bytes required by a normal Expr 2412 ** Macros to determine the number of bytes required by a normal Expr
2224 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags 2413 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
2225 ** and an Expr struct with the EP_TokenOnly flag set. 2414 ** and an Expr struct with the EP_TokenOnly flag set.
2226 */ 2415 */
2227 #define EXPR_FULLSIZE sizeof(Expr) /* Full size */ 2416 #define EXPR_FULLSIZE sizeof(Expr) /* Full size */
2228 #define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */ 2417 #define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */
2229 #define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */ 2418 #define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */
2230 2419
2231 /* 2420 /*
2232 ** Flags passed to the sqlite3ExprDup() function. See the header comment 2421 ** Flags passed to the sqlite3ExprDup() function. See the header comment
2233 ** above sqlite3ExprDup() for details. 2422 ** above sqlite3ExprDup() for details.
2234 */ 2423 */
2235 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */ 2424 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
2236 2425
2237 /* 2426 /*
2238 ** A list of expressions. Each expression may optionally have a 2427 ** A list of expressions. Each expression may optionally have a
2239 ** name. An expr/name combination can be used in several ways, such 2428 ** name. An expr/name combination can be used in several ways, such
2240 ** as the list of "expr AS ID" fields following a "SELECT" or in the 2429 ** as the list of "expr AS ID" fields following a "SELECT" or in the
2241 ** list of "ID = expr" items in an UPDATE. A list of expressions can 2430 ** list of "ID = expr" items in an UPDATE. A list of expressions can
2242 ** also be used as the argument to a function, in which case the a.zName 2431 ** also be used as the argument to a function, in which case the a.zName
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 int nId; /* Number of identifiers on the list */ 2493 int nId; /* Number of identifiers on the list */
2305 }; 2494 };
2306 2495
2307 /* 2496 /*
2308 ** The bitmask datatype defined below is used for various optimizations. 2497 ** The bitmask datatype defined below is used for various optimizations.
2309 ** 2498 **
2310 ** Changing this from a 64-bit to a 32-bit type limits the number of 2499 ** Changing this from a 64-bit to a 32-bit type limits the number of
2311 ** tables in a join to 32 instead of 64. But it also reduces the size 2500 ** tables in a join to 32 instead of 64. But it also reduces the size
2312 ** of the library by 738 bytes on ix86. 2501 ** of the library by 738 bytes on ix86.
2313 */ 2502 */
2314 typedef u64 Bitmask; 2503 #ifdef SQLITE_BITMASK_TYPE
2504 typedef SQLITE_BITMASK_TYPE Bitmask;
2505 #else
2506 typedef u64 Bitmask;
2507 #endif
2315 2508
2316 /* 2509 /*
2317 ** The number of bits in a Bitmask. "BMS" means "BitMask Size". 2510 ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
2318 */ 2511 */
2319 #define BMS ((int)(sizeof(Bitmask)*8)) 2512 #define BMS ((int)(sizeof(Bitmask)*8))
2320 2513
2321 /* 2514 /*
2322 ** A bit in a Bitmask 2515 ** A bit in a Bitmask
2323 */ 2516 */
2324 #define MASKBIT(n) (((Bitmask)1)<<(n)) 2517 #define MASKBIT(n) (((Bitmask)1)<<(n))
2325 #define MASKBIT32(n) (((unsigned int)1)<<(n)) 2518 #define MASKBIT32(n) (((unsigned int)1)<<(n))
2519 #define ALLBITS ((Bitmask)-1)
2326 2520
2327 /* 2521 /*
2328 ** The following structure describes the FROM clause of a SELECT statement. 2522 ** The following structure describes the FROM clause of a SELECT statement.
2329 ** Each table or subquery in the FROM clause is a separate element of 2523 ** Each table or subquery in the FROM clause is a separate element of
2330 ** the SrcList.a[] array. 2524 ** the SrcList.a[] array.
2331 ** 2525 **
2332 ** With the addition of multiple database support, the following structure 2526 ** With the addition of multiple database support, the following structure
2333 ** can also be used to describe a particular table such as the table that 2527 ** can also be used to describe a particular table such as the table that
2334 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, 2528 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
2335 ** such a table must be a simple name: ID. But in SQLite, the table can 2529 ** such a table must be a simple name: ID. But in SQLite, the table can
(...skipping 14 matching lines...) Expand all
2350 Schema *pSchema; /* Schema to which this item is fixed */ 2544 Schema *pSchema; /* Schema to which this item is fixed */
2351 char *zDatabase; /* Name of database holding this table */ 2545 char *zDatabase; /* Name of database holding this table */
2352 char *zName; /* Name of the table */ 2546 char *zName; /* Name of the table */
2353 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 2547 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
2354 Table *pTab; /* An SQL table corresponding to zName */ 2548 Table *pTab; /* An SQL table corresponding to zName */
2355 Select *pSelect; /* A SELECT statement used in place of a table name */ 2549 Select *pSelect; /* A SELECT statement used in place of a table name */
2356 int addrFillSub; /* Address of subroutine to manifest a subquery */ 2550 int addrFillSub; /* Address of subroutine to manifest a subquery */
2357 int regReturn; /* Register holding return address of addrFillSub */ 2551 int regReturn; /* Register holding return address of addrFillSub */
2358 int regResult; /* Registers holding results of a co-routine */ 2552 int regResult; /* Registers holding results of a co-routine */
2359 struct { 2553 struct {
2360 u8 jointype; /* Type of join between this able and the previous */ 2554 u8 jointype; /* Type of join between this table and the previous */
2361 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */ 2555 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
2362 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ 2556 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
2363 unsigned isTabFunc :1; /* True if table-valued-function syntax */ 2557 unsigned isTabFunc :1; /* True if table-valued-function syntax */
2364 unsigned isCorrelated :1; /* True if sub-query is correlated */ 2558 unsigned isCorrelated :1; /* True if sub-query is correlated */
2365 unsigned viaCoroutine :1; /* Implemented as a co-routine */ 2559 unsigned viaCoroutine :1; /* Implemented as a co-routine */
2366 unsigned isRecursive :1; /* True for recursive reference in WITH */ 2560 unsigned isRecursive :1; /* True for recursive reference in WITH */
2367 } fg; 2561 } fg;
2368 #ifndef SQLITE_OMIT_EXPLAIN 2562 #ifndef SQLITE_OMIT_EXPLAIN
2369 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */ 2563 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
2370 #endif 2564 #endif
(...skipping 17 matching lines...) Expand all
2388 #define JT_NATURAL 0x0004 /* True for a "natural" join */ 2582 #define JT_NATURAL 0x0004 /* True for a "natural" join */
2389 #define JT_LEFT 0x0008 /* Left outer join */ 2583 #define JT_LEFT 0x0008 /* Left outer join */
2390 #define JT_RIGHT 0x0010 /* Right outer join */ 2584 #define JT_RIGHT 0x0010 /* Right outer join */
2391 #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */ 2585 #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
2392 #define JT_ERROR 0x0040 /* unknown or unsupported join type */ 2586 #define JT_ERROR 0x0040 /* unknown or unsupported join type */
2393 2587
2394 2588
2395 /* 2589 /*
2396 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() 2590 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
2397 ** and the WhereInfo.wctrlFlags member. 2591 ** and the WhereInfo.wctrlFlags member.
2592 **
2593 ** Value constraints (enforced via assert()):
2594 ** WHERE_USE_LIMIT == SF_FixedLimit
2398 */ 2595 */
2399 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */ 2596 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
2400 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */ 2597 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
2401 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */ 2598 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
2402 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */ 2599 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
2403 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */ 2600 #define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
2404 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */ 2601 #define WHERE_DUPLICATES_OK 0x0010 /* Ok to return a row more than once */
2405 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */ 2602 #define WHERE_OR_SUBCLAUSE 0x0020 /* Processing a sub-WHERE as part of
2406 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */ 2603 ** the OR optimization */
2407 #define WHERE_NO_AUTOINDEX 0x0080 /* Disallow automatic indexes */ 2604 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
2408 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */ 2605 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
2409 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ 2606 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
2410 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ 2607 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
2411 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ 2608 #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
2412 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ 2609 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
2413 #define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */ 2610 #define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
2611 /* 0x2000 not currently used */
2612 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
2613 /* 0x8000 not currently used */
2414 2614
2415 /* Allowed return values from sqlite3WhereIsDistinct() 2615 /* Allowed return values from sqlite3WhereIsDistinct()
2416 */ 2616 */
2417 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ 2617 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
2418 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ 2618 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
2419 #define WHERE_DISTINCT_ORDERED 2 /* All duplicates are adjacent */ 2619 #define WHERE_DISTINCT_ORDERED 2 /* All duplicates are adjacent */
2420 #define WHERE_DISTINCT_UNORDERED 3 /* Duplicates are scattered */ 2620 #define WHERE_DISTINCT_UNORDERED 3 /* Duplicates are scattered */
2421 2621
2422 /* 2622 /*
2423 ** A NameContext defines a context in which to resolve table and column 2623 ** A NameContext defines a context in which to resolve table and column
2424 ** names. The context consists of a list of tables (the pSrcList) field and 2624 ** names. The context consists of a list of tables (the pSrcList) field and
2425 ** a list of named expression (pEList). The named expression list may 2625 ** a list of named expression (pEList). The named expression list may
2426 ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or 2626 ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
2427 ** to the table being operated on by INSERT, UPDATE, or DELETE. The 2627 ** to the table being operated on by INSERT, UPDATE, or DELETE. The
2428 ** pEList corresponds to the result set of a SELECT and is NULL for 2628 ** pEList corresponds to the result set of a SELECT and is NULL for
2429 ** other statements. 2629 ** other statements.
2430 ** 2630 **
2431 ** NameContexts can be nested. When resolving names, the inner-most 2631 ** NameContexts can be nested. When resolving names, the inner-most
2432 ** context is searched first. If no match is found, the next outer 2632 ** context is searched first. If no match is found, the next outer
2433 ** context is checked. If there is still no match, the next context 2633 ** context is checked. If there is still no match, the next context
2434 ** is checked. This process continues until either a match is found 2634 ** is checked. This process continues until either a match is found
2435 ** or all contexts are check. When a match is found, the nRef member of 2635 ** or all contexts are check. When a match is found, the nRef member of
2436 ** the context containing the match is incremented. 2636 ** the context containing the match is incremented.
2437 ** 2637 **
2438 ** Each subquery gets a new NameContext. The pNext field points to the 2638 ** Each subquery gets a new NameContext. The pNext field points to the
2439 ** NameContext in the parent query. Thus the process of scanning the 2639 ** NameContext in the parent query. Thus the process of scanning the
2440 ** NameContext list corresponds to searching through successively outer 2640 ** NameContext list corresponds to searching through successively outer
2441 ** subqueries looking for a match. 2641 ** subqueries looking for a match.
2442 */ 2642 */
2443 struct NameContext { 2643 struct NameContext {
2444 Parse *pParse; /* The parser */ 2644 Parse *pParse; /* The parser */
2445 SrcList *pSrcList; /* One or more tables used to resolve names */ 2645 SrcList *pSrcList; /* One or more tables used to resolve names */
2446 ExprList *pEList; /* Optional list of result-set columns */ 2646 ExprList *pEList; /* Optional list of result-set columns */
2447 AggInfo *pAggInfo; /* Information about aggregates at this level */ 2647 AggInfo *pAggInfo; /* Information about aggregates at this level */
2448 NameContext *pNext; /* Next outer name context. NULL for outermost */ 2648 NameContext *pNext; /* Next outer name context. NULL for outermost */
2449 int nRef; /* Number of names resolved by this context */ 2649 int nRef; /* Number of names resolved by this context */
2450 int nErr; /* Number of errors encountered while resolving names */ 2650 int nErr; /* Number of errors encountered while resolving names */
2451 u16 ncFlags; /* Zero or more NC_* flags defined below */ 2651 u16 ncFlags; /* Zero or more NC_* flags defined below */
2452 }; 2652 };
2453 2653
2454 /* 2654 /*
2455 ** Allowed values for the NameContext, ncFlags field. 2655 ** Allowed values for the NameContext, ncFlags field.
2456 ** 2656 **
2457 ** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and 2657 ** Value constraints (all checked via assert()):
2458 ** SQLITE_FUNC_MINMAX. 2658 ** NC_HasAgg == SF_HasAgg
2459 ** 2659 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
2660 **
2460 */ 2661 */
2461 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */ 2662 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
2462 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */ 2663 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
2463 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */ 2664 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
2464 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */ 2665 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
2465 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */ 2666 #define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
2466 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */ 2667 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
2668 #define NC_VarSelect 0x0040 /* A correlated subquery has been seen */
2467 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ 2669 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
2468 2670
2469 /* 2671 /*
2470 ** An instance of the following structure contains all information 2672 ** An instance of the following structure contains all information
2471 ** needed to generate code for a single SELECT statement. 2673 ** needed to generate code for a single SELECT statement.
2472 ** 2674 **
2473 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. 2675 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
2474 ** If there is a LIMIT clause, the parser sets nLimit to the value of the 2676 ** If there is a LIMIT clause, the parser sets nLimit to the value of the
2475 ** limit and nOffset to the value of the offset (or 0 if there is not 2677 ** limit and nOffset to the value of the offset (or 0 if there is not
2476 ** offset). But later on, nLimit and nOffset become the memory locations 2678 ** offset). But later on, nLimit and nOffset become the memory locations
2477 ** in the VDBE that record the limit and offset counters. 2679 ** in the VDBE that record the limit and offset counters.
2478 ** 2680 **
2479 ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes. 2681 ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
2480 ** These addresses must be stored so that we can go back and fill in 2682 ** These addresses must be stored so that we can go back and fill in
2481 ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor 2683 ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor
2482 ** the number of columns in P2 can be computed at the same time 2684 ** the number of columns in P2 can be computed at the same time
2483 ** as the OP_OpenEphm instruction is coded because not 2685 ** as the OP_OpenEphm instruction is coded because not
2484 ** enough information about the compound query is known at that point. 2686 ** enough information about the compound query is known at that point.
2485 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences 2687 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
2486 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating 2688 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
2487 ** sequences for the ORDER BY clause. 2689 ** sequences for the ORDER BY clause.
2488 */ 2690 */
2489 struct Select { 2691 struct Select {
2490 ExprList *pEList; /* The fields of the result */ 2692 ExprList *pEList; /* The fields of the result */
2491 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ 2693 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
2492 u16 selFlags; /* Various SF_* values */ 2694 LogEst nSelectRow; /* Estimated number of result rows */
2695 u32 selFlags; /* Various SF_* values */
2493 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ 2696 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
2494 #if SELECTTRACE_ENABLED 2697 #if SELECTTRACE_ENABLED
2495 char zSelName[12]; /* Symbolic name of this SELECT use for debugging */ 2698 char zSelName[12]; /* Symbolic name of this SELECT use for debugging */
2496 #endif 2699 #endif
2497 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */ 2700 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
2498 u64 nSelectRow; /* Estimated number of result rows */
2499 SrcList *pSrc; /* The FROM clause */ 2701 SrcList *pSrc; /* The FROM clause */
2500 Expr *pWhere; /* The WHERE clause */ 2702 Expr *pWhere; /* The WHERE clause */
2501 ExprList *pGroupBy; /* The GROUP BY clause */ 2703 ExprList *pGroupBy; /* The GROUP BY clause */
2502 Expr *pHaving; /* The HAVING clause */ 2704 Expr *pHaving; /* The HAVING clause */
2503 ExprList *pOrderBy; /* The ORDER BY clause */ 2705 ExprList *pOrderBy; /* The ORDER BY clause */
2504 Select *pPrior; /* Prior select in a compound select statement */ 2706 Select *pPrior; /* Prior select in a compound select statement */
2505 Select *pNext; /* Next select to the left in a compound */ 2707 Select *pNext; /* Next select to the left in a compound */
2506 Expr *pLimit; /* LIMIT expression. NULL means not used. */ 2708 Expr *pLimit; /* LIMIT expression. NULL means not used. */
2507 Expr *pOffset; /* OFFSET expression. NULL means not used. */ 2709 Expr *pOffset; /* OFFSET expression. NULL means not used. */
2508 With *pWith; /* WITH clause attached to this select. Or NULL. */ 2710 With *pWith; /* WITH clause attached to this select. Or NULL. */
2509 }; 2711 };
2510 2712
2511 /* 2713 /*
2512 ** Allowed values for Select.selFlags. The "SF" prefix stands for 2714 ** Allowed values for Select.selFlags. The "SF" prefix stands for
2513 ** "Select Flag". 2715 ** "Select Flag".
2716 **
2717 ** Value constraints (all checked via assert())
2718 ** SF_HasAgg == NC_HasAgg
2719 ** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
2720 ** SF_FixedLimit == WHERE_USE_LIMIT
2514 */ 2721 */
2515 #define SF_Distinct 0x0001 /* Output should be DISTINCT */ 2722 #define SF_Distinct 0x00001 /* Output should be DISTINCT */
2516 #define SF_All 0x0002 /* Includes the ALL keyword */ 2723 #define SF_All 0x00002 /* Includes the ALL keyword */
2517 #define SF_Resolved 0x0004 /* Identifiers have been resolved */ 2724 #define SF_Resolved 0x00004 /* Identifiers have been resolved */
2518 #define SF_Aggregate 0x0008 /* Contains aggregate functions */ 2725 #define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
2519 #define SF_UsesEphemeral 0x0010 /* Uses the OpenEphemeral opcode */ 2726 #define SF_HasAgg 0x00010 /* Contains aggregate functions */
2520 #define SF_Expanded 0x0020 /* sqlite3SelectExpand() called on this */ 2727 #define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
2521 #define SF_HasTypeInfo 0x0040 /* FROM subqueries have Table metadata */ 2728 #define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
2522 #define SF_Compound 0x0080 /* Part of a compound query */ 2729 #define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
2523 #define SF_Values 0x0100 /* Synthesized from VALUES clause */ 2730 #define SF_Compound 0x00100 /* Part of a compound query */
2524 #define SF_MultiValue 0x0200 /* Single VALUES term with multiple rows */ 2731 #define SF_Values 0x00200 /* Synthesized from VALUES clause */
2525 #define SF_NestedFrom 0x0400 /* Part of a parenthesized FROM clause */ 2732 #define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
2526 #define SF_MaybeConvert 0x0800 /* Need convertCompoundSelectToSubquery() */ 2733 #define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
2527 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ 2734 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
2528 #define SF_Recursive 0x2000 /* The recursive part of a recursive CTE */ 2735 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
2529 #define SF_Converted 0x4000 /* By convertCompoundSelectToSubquery() */ 2736 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
2530 #define SF_IncludeHidden 0x8000 /* Include hidden columns in output */ 2737 #define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
2738 #define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
2739 #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
2531 2740
2532 2741
2533 /* 2742 /*
2534 ** The results of a SELECT can be distributed in several ways, as defined 2743 ** The results of a SELECT can be distributed in several ways, as defined
2535 ** by one of the following macros. The "SRT" prefix means "SELECT Result 2744 ** by one of the following macros. The "SRT" prefix means "SELECT Result
2536 ** Type". 2745 ** Type".
2537 ** 2746 **
2538 ** SRT_Union Store results as a key in a temporary index 2747 ** SRT_Union Store results as a key in a temporary index
2539 ** identified by pDest->iSDParm. 2748 ** identified by pDest->iSDParm.
2540 ** 2749 **
2541 ** SRT_Except Remove results from the temporary index pDest->iSDParm. 2750 ** SRT_Except Remove results from the temporary index pDest->iSDParm.
2542 ** 2751 **
2543 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result 2752 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
2544 ** set is not empty. 2753 ** set is not empty.
2545 ** 2754 **
2546 ** SRT_Discard Throw the results away. This is used by SELECT 2755 ** SRT_Discard Throw the results away. This is used by SELECT
2547 ** statements within triggers whose only purpose is 2756 ** statements within triggers whose only purpose is
2548 ** the side-effects of functions. 2757 ** the side-effects of functions.
2549 ** 2758 **
2550 ** All of the above are free to ignore their ORDER BY clause. Those that 2759 ** All of the above are free to ignore their ORDER BY clause. Those that
2551 ** follow must honor the ORDER BY clause. 2760 ** follow must honor the ORDER BY clause.
2552 ** 2761 **
2553 ** SRT_Output Generate a row of output (using the OP_ResultRow 2762 ** SRT_Output Generate a row of output (using the OP_ResultRow
2554 ** opcode) for each row in the result set. 2763 ** opcode) for each row in the result set.
2555 ** 2764 **
2556 ** SRT_Mem Only valid if the result is a single column. 2765 ** SRT_Mem Only valid if the result is a single column.
2557 ** Store the first column of the first result row 2766 ** Store the first column of the first result row
2558 ** in register pDest->iSDParm then abandon the rest 2767 ** in register pDest->iSDParm then abandon the rest
2559 ** of the query. This destination implies "LIMIT 1". 2768 ** of the query. This destination implies "LIMIT 1".
2560 ** 2769 **
2561 ** SRT_Set The result must be a single column. Store each 2770 ** SRT_Set The result must be a single column. Store each
2562 ** row of result as the key in table pDest->iSDParm. 2771 ** row of result as the key in table pDest->iSDParm.
2563 ** Apply the affinity pDest->affSdst before storing 2772 ** Apply the affinity pDest->affSdst before storing
2564 ** results. Used to implement "IN (SELECT ...)". 2773 ** results. Used to implement "IN (SELECT ...)".
2565 ** 2774 **
2566 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store 2775 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
2567 ** the result there. The cursor is left open after 2776 ** the result there. The cursor is left open after
2568 ** returning. This is like SRT_Table except that 2777 ** returning. This is like SRT_Table except that
2569 ** this destination uses OP_OpenEphemeral to create 2778 ** this destination uses OP_OpenEphemeral to create
2570 ** the table first. 2779 ** the table first.
2571 ** 2780 **
2572 ** SRT_Coroutine Generate a co-routine that returns a new row of 2781 ** SRT_Coroutine Generate a co-routine that returns a new row of
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 #define SRT_EphemTab 12 /* Create transient tab and store like SRT_Table */ 2821 #define SRT_EphemTab 12 /* Create transient tab and store like SRT_Table */
2613 #define SRT_Coroutine 13 /* Generate a single row of result */ 2822 #define SRT_Coroutine 13 /* Generate a single row of result */
2614 #define SRT_Table 14 /* Store result as data with an automatic rowid */ 2823 #define SRT_Table 14 /* Store result as data with an automatic rowid */
2615 2824
2616 /* 2825 /*
2617 ** An instance of this object describes where to put of the results of 2826 ** An instance of this object describes where to put of the results of
2618 ** a SELECT statement. 2827 ** a SELECT statement.
2619 */ 2828 */
2620 struct SelectDest { 2829 struct SelectDest {
2621 u8 eDest; /* How to dispose of the results. On of SRT_* above. */ 2830 u8 eDest; /* How to dispose of the results. On of SRT_* above. */
2622 char affSdst; /* Affinity used when eDest==SRT_Set */ 2831 char *zAffSdst; /* Affinity used when eDest==SRT_Set */
2623 int iSDParm; /* A parameter used by the eDest disposal method */ 2832 int iSDParm; /* A parameter used by the eDest disposal method */
2624 int iSdst; /* Base register where results are written */ 2833 int iSdst; /* Base register where results are written */
2625 int nSdst; /* Number of registers allocated */ 2834 int nSdst; /* Number of registers allocated */
2626 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */ 2835 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
2627 }; 2836 };
2628 2837
2629 /* 2838 /*
2630 ** During code generation of statements that do inserts into AUTOINCREMENT 2839 ** During code generation of statements that do inserts into AUTOINCREMENT
2631 ** tables, the following information is attached to the Table.u.autoInc.p 2840 ** tables, the following information is attached to the Table.u.autoInc.p
2632 ** pointer of each autoincrement table to record some side information that 2841 ** pointer of each autoincrement table to record some side information that
2633 ** the code generator needs. We have to keep per-table autoincrement 2842 ** the code generator needs. We have to keep per-table autoincrement
2634 ** information in case inserts are down within triggers. Triggers do not 2843 ** information in case inserts are done within triggers. Triggers do not
2635 ** normally coordinate their activities, but we do need to coordinate the 2844 ** normally coordinate their activities, but we do need to coordinate the
2636 ** loading and saving of autoincrement information. 2845 ** loading and saving of autoincrement information.
2637 */ 2846 */
2638 struct AutoincInfo { 2847 struct AutoincInfo {
2639 AutoincInfo *pNext; /* Next info block in a list of them all */ 2848 AutoincInfo *pNext; /* Next info block in a list of them all */
2640 Table *pTab; /* Table this info block refers to */ 2849 Table *pTab; /* Table this info block refers to */
2641 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */ 2850 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
2642 int regCtr; /* Memory register holding the rowid counter */ 2851 int regCtr; /* Memory register holding the rowid counter */
2643 }; 2852 };
2644 2853
2645 /* 2854 /*
2646 ** Size of the column cache 2855 ** Size of the column cache
2647 */ 2856 */
2648 #ifndef SQLITE_N_COLCACHE 2857 #ifndef SQLITE_N_COLCACHE
2649 # define SQLITE_N_COLCACHE 10 2858 # define SQLITE_N_COLCACHE 10
2650 #endif 2859 #endif
2651 2860
2652 /* 2861 /*
2653 ** At least one instance of the following structure is created for each 2862 ** At least one instance of the following structure is created for each
2654 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE 2863 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
2655 ** statement. All such objects are stored in the linked list headed at 2864 ** statement. All such objects are stored in the linked list headed at
2656 ** Parse.pTriggerPrg and deleted once statement compilation has been 2865 ** Parse.pTriggerPrg and deleted once statement compilation has been
2657 ** completed. 2866 ** completed.
2658 ** 2867 **
2659 ** A Vdbe sub-program that implements the body and WHEN clause of trigger 2868 ** A Vdbe sub-program that implements the body and WHEN clause of trigger
2660 ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of 2869 ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
2661 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable. 2870 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
2662 ** The Parse.pTriggerPrg list never contains two entries with the same 2871 ** The Parse.pTriggerPrg list never contains two entries with the same
2663 ** values for both pTrigger and orconf. 2872 ** values for both pTrigger and orconf.
2664 ** 2873 **
2665 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns 2874 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
2666 ** accessed (or set to 0 for triggers fired as a result of INSERT 2875 ** accessed (or set to 0 for triggers fired as a result of INSERT
2667 ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to 2876 ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
2668 ** a mask of new.* columns used by the program. 2877 ** a mask of new.* columns used by the program.
2669 */ 2878 */
2670 struct TriggerPrg { 2879 struct TriggerPrg {
2671 Trigger *pTrigger; /* Trigger this program was coded from */ 2880 Trigger *pTrigger; /* Trigger this program was coded from */
2672 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ 2881 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
2673 SubProgram *pProgram; /* Program implementing pTrigger/orconf */ 2882 SubProgram *pProgram; /* Program implementing pTrigger/orconf */
2674 int orconf; /* Default ON CONFLICT policy */ 2883 int orconf; /* Default ON CONFLICT policy */
2675 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ 2884 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */
2676 }; 2885 };
(...skipping 20 matching lines...) Expand all
2697 /* 2906 /*
2698 ** An SQL parser context. A copy of this structure is passed through 2907 ** An SQL parser context. A copy of this structure is passed through
2699 ** the parser and down into all the parser action routine in order to 2908 ** the parser and down into all the parser action routine in order to
2700 ** carry around information that is global to the entire parse. 2909 ** carry around information that is global to the entire parse.
2701 ** 2910 **
2702 ** The structure is divided into two parts. When the parser and code 2911 ** The structure is divided into two parts. When the parser and code
2703 ** generate call themselves recursively, the first part of the structure 2912 ** generate call themselves recursively, the first part of the structure
2704 ** is constant but the second part is reset at the beginning and end of 2913 ** is constant but the second part is reset at the beginning and end of
2705 ** each recursion. 2914 ** each recursion.
2706 ** 2915 **
2707 ** The nTableLock and aTableLock variables are only used if the shared-cache 2916 ** The nTableLock and aTableLock variables are only used if the shared-cache
2708 ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are 2917 ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
2709 ** used to store the set of table-locks required by the statement being 2918 ** used to store the set of table-locks required by the statement being
2710 ** compiled. Function sqlite3TableLock() is used to add entries to the 2919 ** compiled. Function sqlite3TableLock() is used to add entries to the
2711 ** list. 2920 ** list.
2712 */ 2921 */
2713 struct Parse { 2922 struct Parse {
2714 sqlite3 *db; /* The main database structure */ 2923 sqlite3 *db; /* The main database structure */
2715 char *zErrMsg; /* An error message */ 2924 char *zErrMsg; /* An error message */
2716 Vdbe *pVdbe; /* An engine for executing database bytecode */ 2925 Vdbe *pVdbe; /* An engine for executing database bytecode */
2717 int rc; /* Return code from execution */ 2926 int rc; /* Return code from execution */
2718 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ 2927 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
2719 u8 checkSchema; /* Causes schema cookie check after an error */ 2928 u8 checkSchema; /* Causes schema cookie check after an error */
2720 u8 nested; /* Number of nested calls to the parser/code generator */ 2929 u8 nested; /* Number of nested calls to the parser/code generator */
2721 u8 nTempReg; /* Number of temporary registers in aTempReg[] */ 2930 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
2722 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ 2931 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
2723 u8 mayAbort; /* True if statement may throw an ABORT exception */ 2932 u8 mayAbort; /* True if statement may throw an ABORT exception */
2724 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ 2933 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
2725 u8 okConstFactor; /* OK to factor out constants */ 2934 u8 okConstFactor; /* OK to factor out constants */
2726 int aTempReg[8]; /* Holding area for temporary registers */ 2935 u8 disableLookaside; /* Number of times lookaside has been disabled */
2936 u8 nColCache; /* Number of entries in aColCache[] */
2727 int nRangeReg; /* Size of the temporary register block */ 2937 int nRangeReg; /* Size of the temporary register block */
2728 int iRangeReg; /* First register in temporary register block */ 2938 int iRangeReg; /* First register in temporary register block */
2729 int nErr; /* Number of errors seen */ 2939 int nErr; /* Number of errors seen */
2730 int nTab; /* Number of previously allocated VDBE cursors */ 2940 int nTab; /* Number of previously allocated VDBE cursors */
2731 int nMem; /* Number of memory cells used so far */ 2941 int nMem; /* Number of memory cells used so far */
2732 int nSet; /* Number of sets used so far */
2733 int nOnce; /* Number of OP_Once instructions so far */
2734 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ 2942 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
2735 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ 2943 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
2736 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
2737 int ckBase; /* Base register of data during check constraints */ 2944 int ckBase; /* Base register of data during check constraints */
2738 int iSelfTab; /* Table of an index whose exprs are being coded */ 2945 int iSelfTab; /* Table of an index whose exprs are being coded */
2739 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ 2946 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
2740 int iCacheCnt; /* Counter used to generate aColCache[].lru values */ 2947 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
2741 int nLabel; /* Number of labels used */ 2948 int nLabel; /* Number of labels used */
2742 int *aLabel; /* Space to hold the labels */ 2949 int *aLabel; /* Space to hold the labels */
2743 struct yColCache {
2744 int iTable; /* Table cursor number */
2745 i16 iColumn; /* Table column number */
2746 u8 tempReg; /* iReg is a temp register that needs to be freed */
2747 int iLevel; /* Nesting level */
2748 int iReg; /* Reg with value of this column. 0 means none. */
2749 int lru; /* Least recently used entry has the smallest value */
2750 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
2751 ExprList *pConstExpr;/* Constant expressions */ 2950 ExprList *pConstExpr;/* Constant expressions */
2752 Token constraintName;/* Name of the constraint currently being parsed */ 2951 Token constraintName;/* Name of the constraint currently being parsed */
2753 yDbMask writeMask; /* Start a write transaction on these databases */ 2952 yDbMask writeMask; /* Start a write transaction on these databases */
2754 yDbMask cookieMask; /* Bitmask of schema verified databases */ 2953 yDbMask cookieMask; /* Bitmask of schema verified databases */
2755 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
2756 int regRowid; /* Register holding rowid of CREATE TABLE entry */ 2954 int regRowid; /* Register holding rowid of CREATE TABLE entry */
2757 int regRoot; /* Register holding root page number for new objects */ 2955 int regRoot; /* Register holding root page number for new objects */
2758 int nMaxArg; /* Max args passed to user function by sub-program */ 2956 int nMaxArg; /* Max args passed to user function by sub-program */
2759 #if SELECTTRACE_ENABLED 2957 #if SELECTTRACE_ENABLED
2760 int nSelect; /* Number of SELECT statements seen */ 2958 int nSelect; /* Number of SELECT statements seen */
2761 int nSelectIndent; /* How far to indent SELECTTRACE() output */ 2959 int nSelectIndent; /* How far to indent SELECTTRACE() output */
2762 #endif 2960 #endif
2763 #ifndef SQLITE_OMIT_SHARED_CACHE 2961 #ifndef SQLITE_OMIT_SHARED_CACHE
2764 int nTableLock; /* Number of locks in aTableLock */ 2962 int nTableLock; /* Number of locks in aTableLock */
2765 TableLock *aTableLock; /* Required table locks for shared-cache mode */ 2963 TableLock *aTableLock; /* Required table locks for shared-cache mode */
2766 #endif 2964 #endif
2767 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ 2965 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
2768
2769 /* Information used while coding trigger programs. */
2770 Parse *pToplevel; /* Parse structure for main program (or NULL) */ 2966 Parse *pToplevel; /* Parse structure for main program (or NULL) */
2771 Table *pTriggerTab; /* Table triggers are being coded for */ 2967 Table *pTriggerTab; /* Table triggers are being coded for */
2772 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */ 2968 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
2773 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ 2969 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
2774 u32 oldmask; /* Mask of old.* columns referenced */ 2970 u32 oldmask; /* Mask of old.* columns referenced */
2775 u32 newmask; /* Mask of new.* columns referenced */ 2971 u32 newmask; /* Mask of new.* columns referenced */
2776 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ 2972 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
2777 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ 2973 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
2778 u8 disableTriggers; /* True to disable triggers */ 2974 u8 disableTriggers; /* True to disable triggers */
2779 2975
2976 /**************************************************************************
2977 ** Fields above must be initialized to zero. The fields that follow,
2978 ** down to the beginning of the recursive section, do not need to be
2979 ** initialized as they will be set before being used. The boundary is
2980 ** determined by offsetof(Parse,aColCache).
2981 **************************************************************************/
2982
2983 struct yColCache {
2984 int iTable; /* Table cursor number */
2985 i16 iColumn; /* Table column number */
2986 u8 tempReg; /* iReg is a temp register that needs to be freed */
2987 int iLevel; /* Nesting level */
2988 int iReg; /* Reg with value of this column. 0 means none. */
2989 int lru; /* Least recently used entry has the smallest value */
2990 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
2991 int aTempReg[8]; /* Holding area for temporary registers */
2992 Token sNameToken; /* Token with unqualified schema object name */
2993
2780 /************************************************************************ 2994 /************************************************************************
2781 ** Above is constant between recursions. Below is reset before and after 2995 ** Above is constant between recursions. Below is reset before and after
2782 ** each recursion. The boundary between these two regions is determined 2996 ** each recursion. The boundary between these two regions is determined
2783 ** using offsetof(Parse,nVar) so the nVar field must be the first field 2997 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
2784 ** in the recursive region. 2998 ** first field in the recursive region.
2785 ************************************************************************/ 2999 ************************************************************************/
2786 3000
2787 int nVar; /* Number of '?' variables seen in the SQL so far */ 3001 Token sLastToken; /* The last token parsed */
2788 int nzVar; /* Number of available slots in azVar[] */ 3002 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
2789 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ 3003 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
2790 u8 explain; /* True if the EXPLAIN flag is found on the query */ 3004 u8 explain; /* True if the EXPLAIN flag is found on the query */
2791 #ifndef SQLITE_OMIT_VIRTUALTABLE 3005 #ifndef SQLITE_OMIT_VIRTUALTABLE
2792 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ 3006 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
2793 int nVtabLock; /* Number of virtual tables to lock */ 3007 int nVtabLock; /* Number of virtual tables to lock */
2794 #endif 3008 #endif
2795 int nAlias; /* Number of aliased result set columns */
2796 int nHeight; /* Expression tree height of current sub-select */ 3009 int nHeight; /* Expression tree height of current sub-select */
2797 #ifndef SQLITE_OMIT_EXPLAIN 3010 #ifndef SQLITE_OMIT_EXPLAIN
2798 int iSelectId; /* ID of current select for EXPLAIN output */ 3011 int iSelectId; /* ID of current select for EXPLAIN output */
2799 int iNextSelectId; /* Next available select ID for EXPLAIN output */ 3012 int iNextSelectId; /* Next available select ID for EXPLAIN output */
2800 #endif 3013 #endif
2801 char **azVar; /* Pointers to names of parameters */ 3014 VList *pVList; /* Mapping between variable names and numbers */
2802 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ 3015 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
2803 const char *zTail; /* All SQL text past the last semicolon parsed */ 3016 const char *zTail; /* All SQL text past the last semicolon parsed */
2804 Table *pNewTable; /* A table being constructed by CREATE TABLE */ 3017 Table *pNewTable; /* A table being constructed by CREATE TABLE */
2805 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ 3018 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
2806 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ 3019 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
2807 Token sNameToken; /* Token with unqualified schema object name */
2808 Token sLastToken; /* The last token parsed */
2809 #ifndef SQLITE_OMIT_VIRTUALTABLE 3020 #ifndef SQLITE_OMIT_VIRTUALTABLE
2810 Token sArg; /* Complete text of a module argument */ 3021 Token sArg; /* Complete text of a module argument */
2811 Table **apVtabLock; /* Pointer to virtual tables needing locking */ 3022 Table **apVtabLock; /* Pointer to virtual tables needing locking */
2812 #endif 3023 #endif
2813 Table *pZombieTab; /* List of Table objects to delete after code gen */ 3024 Table *pZombieTab; /* List of Table objects to delete after code gen */
2814 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ 3025 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
2815 With *pWith; /* Current WITH clause, or NULL */ 3026 With *pWith; /* Current WITH clause, or NULL */
2816 With *pWithToFree; /* Free this WITH object at the end of the parse */ 3027 With *pWithToFree; /* Free this WITH object at the end of the parse */
2817 }; 3028 };
2818 3029
2819 /* 3030 /*
3031 ** Sizes and pointers of various parts of the Parse object.
3032 */
3033 #define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
3034 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
3035 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
3036 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
3037
3038 /*
2820 ** Return true if currently inside an sqlite3_declare_vtab() call. 3039 ** Return true if currently inside an sqlite3_declare_vtab() call.
2821 */ 3040 */
2822 #ifdef SQLITE_OMIT_VIRTUALTABLE 3041 #ifdef SQLITE_OMIT_VIRTUALTABLE
2823 #define IN_DECLARE_VTAB 0 3042 #define IN_DECLARE_VTAB 0
2824 #else 3043 #else
2825 #define IN_DECLARE_VTAB (pParse->declareVtab) 3044 #define IN_DECLARE_VTAB (pParse->declareVtab)
2826 #endif 3045 #endif
2827 3046
2828 /* 3047 /*
2829 ** An instance of the following structure can be declared on a stack and used 3048 ** An instance of the following structure can be declared on a stack and used
2830 ** to save the Parse.zAuthContext value so that it can be restored later. 3049 ** to save the Parse.zAuthContext value so that it can be restored later.
2831 */ 3050 */
2832 struct AuthContext { 3051 struct AuthContext {
2833 const char *zAuthContext; /* Put saved Parse.zAuthContext here */ 3052 const char *zAuthContext; /* Put saved Parse.zAuthContext here */
2834 Parse *pParse; /* The Parse structure */ 3053 Parse *pParse; /* The Parse structure */
2835 }; 3054 };
2836 3055
2837 /* 3056 /*
2838 ** Bitfield flags for P5 value in various opcodes. 3057 ** Bitfield flags for P5 value in various opcodes.
3058 **
3059 ** Value constraints (enforced via assert()):
3060 ** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
3061 ** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
3062 ** OPFLAG_BULKCSR == BTREE_BULKLOAD
3063 ** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
3064 ** OPFLAG_FORDELETE == BTREE_FORDELETE
3065 ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
3066 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE
2839 */ 3067 */
2840 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */ 3068 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
3069 /* Also used in P2 (not P5) of OP_Delete */
2841 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ 3070 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
2842 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ 3071 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */
2843 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ 3072 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
2844 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 3073 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
2845 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 3074 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
3075 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
2846 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 3076 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
2847 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 3077 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
2848 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ 3078 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
2849 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ 3079 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
2850 #define OPFLAG_FORDELETE 0x08 /* OP_Open is opening for-delete csr */ 3080 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
2851 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ 3081 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
2852 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ 3082 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
3083 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
3084 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
2853 3085
2854 /* 3086 /*
2855 * Each trigger present in the database schema is stored as an instance of 3087 * Each trigger present in the database schema is stored as an instance of
2856 * struct Trigger. 3088 * struct Trigger.
2857 * 3089 *
2858 * Pointers to instances of struct Trigger are stored in two ways. 3090 * Pointers to instances of struct Trigger are stored in two ways.
2859 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 3091 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
2860 * database). This allows Trigger structures to be retrieved by name. 3092 * database). This allows Trigger structures to be retrieved by name.
2861 * 2. All triggers associated with a single table form a linked list, using the 3093 * 2. All triggers associated with a single table form a linked list, using the
2862 * pNext member of struct Trigger. A pointer to the first element of the 3094 * pNext member of struct Trigger. A pointer to the first element of the
2863 * linked list is stored as the "pTrigger" member of the associated 3095 * linked list is stored as the "pTrigger" member of the associated
2864 * struct Table. 3096 * struct Table.
2865 * 3097 *
2866 * The "step_list" member points to the first element of a linked list 3098 * The "step_list" member points to the first element of a linked list
2867 * containing the SQL statements specified as the trigger program. 3099 * containing the SQL statements specified as the trigger program.
2868 */ 3100 */
2869 struct Trigger { 3101 struct Trigger {
2870 char *zName; /* The name of the trigger */ 3102 char *zName; /* The name of the trigger */
2871 char *table; /* The table or view to which the trigger applies */ 3103 char *table; /* The table or view to which the trigger applies */
2872 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ 3104 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
2873 u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ 3105 u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
2874 Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */ 3106 Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */
2875 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, 3107 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
2876 the <column-list> is stored here */ 3108 the <column-list> is stored here */
2877 Schema *pSchema; /* Schema containing the trigger */ 3109 Schema *pSchema; /* Schema containing the trigger */
2878 Schema *pTabSchema; /* Schema containing the table */ 3110 Schema *pTabSchema; /* Schema containing the table */
2879 TriggerStep *step_list; /* Link list of trigger program steps */ 3111 TriggerStep *step_list; /* Link list of trigger program steps */
2880 Trigger *pNext; /* Next trigger associated with the table */ 3112 Trigger *pNext; /* Next trigger associated with the table */
2881 }; 3113 };
2882 3114
2883 /* 3115 /*
2884 ** A trigger is either a BEFORE or an AFTER trigger. The following constants 3116 ** A trigger is either a BEFORE or an AFTER trigger. The following constants
2885 ** determine which. 3117 ** determine which.
2886 ** 3118 **
2887 ** If there are multiple triggers, you might of some BEFORE and some AFTER. 3119 ** If there are multiple triggers, you might of some BEFORE and some AFTER.
2888 ** In that cases, the constants below can be ORed together. 3120 ** In that cases, the constants below can be ORed together.
2889 */ 3121 */
2890 #define TRIGGER_BEFORE 1 3122 #define TRIGGER_BEFORE 1
2891 #define TRIGGER_AFTER 2 3123 #define TRIGGER_AFTER 2
2892 3124
2893 /* 3125 /*
2894 * An instance of struct TriggerStep is used to store a single SQL statement 3126 * An instance of struct TriggerStep is used to store a single SQL statement
2895 * that is a part of a trigger-program. 3127 * that is a part of a trigger-program.
2896 * 3128 *
2897 * Instances of struct TriggerStep are stored in a singly linked list (linked 3129 * Instances of struct TriggerStep are stored in a singly linked list (linked
2898 * using the "pNext" member) referenced by the "step_list" member of the 3130 * using the "pNext" member) referenced by the "step_list" member of the
2899 * associated struct Trigger instance. The first element of the linked list is 3131 * associated struct Trigger instance. The first element of the linked list is
2900 * the first step of the trigger-program. 3132 * the first step of the trigger-program.
2901 * 3133 *
2902 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or 3134 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
2903 * "SELECT" statement. The meanings of the other members is determined by the 3135 * "SELECT" statement. The meanings of the other members is determined by the
2904 * value of "op" as follows: 3136 * value of "op" as follows:
2905 * 3137 *
2906 * (op == TK_INSERT) 3138 * (op == TK_INSERT)
2907 * orconf -> stores the ON CONFLICT algorithm 3139 * orconf -> stores the ON CONFLICT algorithm
2908 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then 3140 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
2909 * this stores a pointer to the SELECT statement. Otherwise NULL. 3141 * this stores a pointer to the SELECT statement. Otherwise NULL.
2910 * zTarget -> Dequoted name of the table to insert into. 3142 * zTarget -> Dequoted name of the table to insert into.
2911 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then 3143 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
2912 * this stores values to be inserted. Otherwise NULL. 3144 * this stores values to be inserted. Otherwise NULL.
2913 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... 3145 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
2914 * statement, then this stores the column-names to be 3146 * statement, then this stores the column-names to be
2915 * inserted into. 3147 * inserted into.
2916 * 3148 *
2917 * (op == TK_DELETE) 3149 * (op == TK_DELETE)
2918 * zTarget -> Dequoted name of the table to delete from. 3150 * zTarget -> Dequoted name of the table to delete from.
2919 * pWhere -> The WHERE clause of the DELETE statement if one is specified. 3151 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
2920 * Otherwise NULL. 3152 * Otherwise NULL.
2921 * 3153 *
2922 * (op == TK_UPDATE) 3154 * (op == TK_UPDATE)
2923 * zTarget -> Dequoted name of the table to update. 3155 * zTarget -> Dequoted name of the table to update.
2924 * pWhere -> The WHERE clause of the UPDATE statement if one is specified. 3156 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
2925 * Otherwise NULL. 3157 * Otherwise NULL.
2926 * pExprList -> A list of the columns to update and the expressions to update 3158 * pExprList -> A list of the columns to update and the expressions to update
2927 * them to. See sqlite3Update() documentation of "pChanges" 3159 * them to. See sqlite3Update() documentation of "pChanges"
2928 * argument. 3160 * argument.
2929 * 3161 *
2930 */ 3162 */
2931 struct TriggerStep { 3163 struct TriggerStep {
2932 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ 3164 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
2933 u8 orconf; /* OE_Rollback etc. */ 3165 u8 orconf; /* OE_Rollback etc. */
2934 Trigger *pTrig; /* The trigger that this step is a part of */ 3166 Trigger *pTrig; /* The trigger that this step is a part of */
2935 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ 3167 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
2936 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ 3168 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
2937 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ 3169 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
2938 ExprList *pExprList; /* SET clause for UPDATE. */ 3170 ExprList *pExprList; /* SET clause for UPDATE. */
2939 IdList *pIdList; /* Column names for INSERT */ 3171 IdList *pIdList; /* Column names for INSERT */
2940 TriggerStep *pNext; /* Next in the link-list */ 3172 TriggerStep *pNext; /* Next in the link-list */
2941 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ 3173 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
2942 }; 3174 };
2943 3175
2944 /* 3176 /*
2945 ** The following structure contains information used by the sqliteFix... 3177 ** The following structure contains information used by the sqliteFix...
2946 ** routines as they walk the parse tree to make database references 3178 ** routines as they walk the parse tree to make database references
2947 ** explicit. 3179 ** explicit.
2948 */ 3180 */
2949 typedef struct DbFixer DbFixer; 3181 typedef struct DbFixer DbFixer;
2950 struct DbFixer { 3182 struct DbFixer {
2951 Parse *pParse; /* The parsing context. Error messages written here */ 3183 Parse *pParse; /* The parsing context. Error messages written here */
2952 Schema *pSchema; /* Fix items to this schema */ 3184 Schema *pSchema; /* Fix items to this schema */
2953 int bVarOnly; /* Check for variable references only */ 3185 int bVarOnly; /* Check for variable references only */
2954 const char *zDb; /* Make sure all objects are contained in this database */ 3186 const char *zDb; /* Make sure all objects are contained in this database */
2955 const char *zType; /* Type of the container - used for error messages */ 3187 const char *zType; /* Type of the container - used for error messages */
2956 const Token *pName; /* Name of the container - used for error messages */ 3188 const Token *pName; /* Name of the container - used for error messages */
2957 }; 3189 };
2958 3190
2959 /* 3191 /*
2960 ** An objected used to accumulate the text of a string where we 3192 ** An objected used to accumulate the text of a string where we
2961 ** do not necessarily know how big the string will be in the end. 3193 ** do not necessarily know how big the string will be in the end.
2962 */ 3194 */
2963 struct StrAccum { 3195 struct StrAccum {
2964 sqlite3 *db; /* Optional database for lookaside. Can be NULL */ 3196 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
2965 char *zBase; /* A base allocation. Not from malloc. */ 3197 char *zBase; /* A base allocation. Not from malloc. */
2966 char *zText; /* The string collected so far */ 3198 char *zText; /* The string collected so far */
2967 u32 nChar; /* Length of the string so far */ 3199 u32 nChar; /* Length of the string so far */
2968 u32 nAlloc; /* Amount of space allocated in zText */ 3200 u32 nAlloc; /* Amount of space allocated in zText */
2969 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ 3201 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
2970 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ 3202 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
2971 u8 bMalloced; /* zText points to allocated space */ 3203 u8 printfFlags; /* SQLITE_PRINTF flags below */
2972 }; 3204 };
2973 #define STRACCUM_NOMEM 1 3205 #define STRACCUM_NOMEM 1
2974 #define STRACCUM_TOOBIG 2 3206 #define STRACCUM_TOOBIG 2
3207 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
3208 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
3209 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
3210
3211 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
3212
2975 3213
2976 /* 3214 /*
2977 ** A pointer to this structure is used to communicate information 3215 ** A pointer to this structure is used to communicate information
2978 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. 3216 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
2979 */ 3217 */
2980 typedef struct { 3218 typedef struct {
2981 sqlite3 *db; /* The database being initialized */ 3219 sqlite3 *db; /* The database being initialized */
2982 char **pzErrMsg; /* Error message stored here */ 3220 char **pzErrMsg; /* Error message stored here */
2983 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ 3221 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
2984 int rc; /* Result code stored here */ 3222 int rc; /* Result code stored here */
2985 } InitData; 3223 } InitData;
2986 3224
2987 /* 3225 /*
2988 ** Structure containing global configuration data for the SQLite library. 3226 ** Structure containing global configuration data for the SQLite library.
2989 ** 3227 **
2990 ** This structure also contains some state information. 3228 ** This structure also contains some state information.
2991 */ 3229 */
2992 struct Sqlite3Config { 3230 struct Sqlite3Config {
2993 int bMemstat; /* True to enable memory status */ 3231 int bMemstat; /* True to enable memory status */
2994 int bCoreMutex; /* True to enable core mutexing */ 3232 int bCoreMutex; /* True to enable core mutexing */
2995 int bFullMutex; /* True to enable full mutexing */ 3233 int bFullMutex; /* True to enable full mutexing */
2996 int bOpenUri; /* True to interpret filenames as URIs */ 3234 int bOpenUri; /* True to interpret filenames as URIs */
2997 int bUseCis; /* Use covering indices for full-scans */ 3235 int bUseCis; /* Use covering indices for full-scans */
2998 int mxStrlen; /* Maximum string length */ 3236 int mxStrlen; /* Maximum string length */
2999 int neverCorrupt; /* Database is always well-formed */ 3237 int neverCorrupt; /* Database is always well-formed */
3000 int szLookaside; /* Default lookaside buffer size */ 3238 int szLookaside; /* Default lookaside buffer size */
3001 int nLookaside; /* Default lookaside buffer count */ 3239 int nLookaside; /* Default lookaside buffer count */
3240 int nStmtSpill; /* Stmt-journal spill-to-disk threshold */
3002 sqlite3_mem_methods m; /* Low-level memory allocation interface */ 3241 sqlite3_mem_methods m; /* Low-level memory allocation interface */
3003 sqlite3_mutex_methods mutex; /* Low-level mutex interface */ 3242 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
3004 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */ 3243 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */
3005 void *pHeap; /* Heap storage space */ 3244 void *pHeap; /* Heap storage space */
3006 int nHeap; /* Size of pHeap[] */ 3245 int nHeap; /* Size of pHeap[] */
3007 int mnReq, mxReq; /* Min and max heap requests sizes */ 3246 int mnReq, mxReq; /* Min and max heap requests sizes */
3008 sqlite3_int64 szMmap; /* mmap() space per open file */ 3247 sqlite3_int64 szMmap; /* mmap() space per open file */
3009 sqlite3_int64 mxMmap; /* Maximum value for szMmap */ 3248 sqlite3_int64 mxMmap; /* Maximum value for szMmap */
3010 void *pScratch; /* Scratch memory */ 3249 void *pScratch; /* Scratch memory */
3011 int szScratch; /* Size of each scratch buffer */ 3250 int szScratch; /* Size of each scratch buffer */
(...skipping 19 matching lines...) Expand all
3031 void(*xSqllog)(void*,sqlite3*,const char*, int); 3270 void(*xSqllog)(void*,sqlite3*,const char*, int);
3032 void *pSqllogArg; 3271 void *pSqllogArg;
3033 #endif 3272 #endif
3034 #ifdef SQLITE_VDBE_COVERAGE 3273 #ifdef SQLITE_VDBE_COVERAGE
3035 /* The following callback (if not NULL) is invoked on every VDBE branch 3274 /* The following callback (if not NULL) is invoked on every VDBE branch
3036 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. 3275 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
3037 */ 3276 */
3038 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */ 3277 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
3039 void *pVdbeBranchArg; /* 1st argument */ 3278 void *pVdbeBranchArg; /* 1st argument */
3040 #endif 3279 #endif
3041 #ifndef SQLITE_OMIT_BUILTIN_TEST 3280 #ifndef SQLITE_UNTESTABLE
3042 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ 3281 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
3043 #endif 3282 #endif
3044 int bLocaltimeFault; /* True to fail localtime() calls */ 3283 int bLocaltimeFault; /* True to fail localtime() calls */
3284 int iOnceResetThreshold; /* When to reset OP_Once counters */
3045 }; 3285 };
3046 3286
3047 /* 3287 /*
3048 ** This macro is used inside of assert() statements to indicate that 3288 ** This macro is used inside of assert() statements to indicate that
3049 ** the assert is only valid on a well-formed database. Instead of: 3289 ** the assert is only valid on a well-formed database. Instead of:
3050 ** 3290 **
3051 ** assert( X ); 3291 ** assert( X );
3052 ** 3292 **
3053 ** One writes: 3293 ** One writes:
3054 ** 3294 **
3055 ** assert( X || CORRUPT_DB ); 3295 ** assert( X || CORRUPT_DB );
3056 ** 3296 **
3057 ** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate 3297 ** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate
3058 ** that the database is definitely corrupt, only that it might be corrupt. 3298 ** that the database is definitely corrupt, only that it might be corrupt.
3059 ** For most test cases, CORRUPT_DB is set to false using a special 3299 ** For most test cases, CORRUPT_DB is set to false using a special
3060 ** sqlite3_test_control(). This enables assert() statements to prove 3300 ** sqlite3_test_control(). This enables assert() statements to prove
3061 ** things that are always true for well-formed databases. 3301 ** things that are always true for well-formed databases.
3062 */ 3302 */
3063 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0) 3303 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0)
3064 3304
3065 /* 3305 /*
3066 ** Context pointer passed down through the tree-walk. 3306 ** Context pointer passed down through the tree-walk.
3067 */ 3307 */
3068 struct Walker { 3308 struct Walker {
3309 Parse *pParse; /* Parser context. */
3069 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ 3310 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
3070 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ 3311 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
3071 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ 3312 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
3072 Parse *pParse; /* Parser context. */
3073 int walkerDepth; /* Number of subqueries */ 3313 int walkerDepth; /* Number of subqueries */
3074 u8 eCode; /* A small processing code */ 3314 u8 eCode; /* A small processing code */
3075 union { /* Extra data for callback */ 3315 union { /* Extra data for callback */
3076 NameContext *pNC; /* Naming context */ 3316 NameContext *pNC; /* Naming context */
3077 int n; /* A counter */ 3317 int n; /* A counter */
3078 int iCur; /* A cursor number */ 3318 int iCur; /* A cursor number */
3079 SrcList *pSrcList; /* FROM clause */ 3319 SrcList *pSrcList; /* FROM clause */
3080 struct SrcCount *pSrcCount; /* Counting column references */ 3320 struct SrcCount *pSrcCount; /* Counting column references */
3081 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ 3321 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
3322 int *aiCol; /* array of column indexes */
3323 struct IdxCover *pIdxCover; /* Check for index coverage */
3082 } u; 3324 } u;
3083 }; 3325 };
3084 3326
3085 /* Forward declarations */ 3327 /* Forward declarations */
3086 int sqlite3WalkExpr(Walker*, Expr*); 3328 int sqlite3WalkExpr(Walker*, Expr*);
3087 int sqlite3WalkExprList(Walker*, ExprList*); 3329 int sqlite3WalkExprList(Walker*, ExprList*);
3088 int sqlite3WalkSelect(Walker*, Select*); 3330 int sqlite3WalkSelect(Walker*, Select*);
3089 int sqlite3WalkSelectExpr(Walker*, Select*); 3331 int sqlite3WalkSelectExpr(Walker*, Select*);
3090 int sqlite3WalkSelectFrom(Walker*, Select*); 3332 int sqlite3WalkSelectFrom(Walker*, Select*);
3091 int sqlite3ExprWalkNoop(Walker*, Expr*); 3333 int sqlite3ExprWalkNoop(Walker*, Expr*);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 ** routines that report the line-number on which the error originated 3382 ** routines that report the line-number on which the error originated
3141 ** using sqlite3_log(). The routines also provide a convenient place 3383 ** using sqlite3_log(). The routines also provide a convenient place
3142 ** to set a debugger breakpoint. 3384 ** to set a debugger breakpoint.
3143 */ 3385 */
3144 int sqlite3CorruptError(int); 3386 int sqlite3CorruptError(int);
3145 int sqlite3MisuseError(int); 3387 int sqlite3MisuseError(int);
3146 int sqlite3CantopenError(int); 3388 int sqlite3CantopenError(int);
3147 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__) 3389 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
3148 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) 3390 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
3149 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) 3391 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
3392 #ifdef SQLITE_DEBUG
3393 int sqlite3NomemError(int);
3394 int sqlite3IoerrnomemError(int);
3395 # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__)
3396 # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__)
3397 #else
3398 # define SQLITE_NOMEM_BKPT SQLITE_NOMEM
3399 # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM
3400 #endif
3150 3401
3402 /*
3403 ** FTS3 and FTS4 both require virtual table support
3404 */
3405 #if defined(SQLITE_OMIT_VIRTUALTABLE)
3406 # undef SQLITE_ENABLE_FTS3
3407 # undef SQLITE_ENABLE_FTS4
3408 #endif
3151 3409
3152 /* 3410 /*
3153 ** FTS4 is really an extension for FTS3. It is enabled using the 3411 ** FTS4 is really an extension for FTS3. It is enabled using the
3154 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call 3412 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
3155 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. 3413 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
3156 */ 3414 */
3157 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) 3415 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
3158 # define SQLITE_ENABLE_FTS3 1 3416 # define SQLITE_ENABLE_FTS3 1
3159 #endif 3417 #endif
3160 3418
(...skipping 12 matching lines...) Expand all
3173 ** sqlite versions only work for ASCII characters, regardless of locale. 3431 ** sqlite versions only work for ASCII characters, regardless of locale.
3174 */ 3432 */
3175 #ifdef SQLITE_ASCII 3433 #ifdef SQLITE_ASCII
3176 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20)) 3434 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
3177 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01) 3435 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
3178 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06) 3436 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
3179 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02) 3437 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
3180 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04) 3438 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
3181 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08) 3439 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
3182 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)]) 3440 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
3441 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
3183 #else 3442 #else
3184 # define sqlite3Toupper(x) toupper((unsigned char)(x)) 3443 # define sqlite3Toupper(x) toupper((unsigned char)(x))
3185 # define sqlite3Isspace(x) isspace((unsigned char)(x)) 3444 # define sqlite3Isspace(x) isspace((unsigned char)(x))
3186 # define sqlite3Isalnum(x) isalnum((unsigned char)(x)) 3445 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
3187 # define sqlite3Isalpha(x) isalpha((unsigned char)(x)) 3446 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
3188 # define sqlite3Isdigit(x) isdigit((unsigned char)(x)) 3447 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
3189 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x)) 3448 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
3190 # define sqlite3Tolower(x) tolower((unsigned char)(x)) 3449 # define sqlite3Tolower(x) tolower((unsigned char)(x))
3450 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
3191 #endif 3451 #endif
3192 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 3452 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
3193 int sqlite3IsIdChar(u8); 3453 int sqlite3IsIdChar(u8);
3194 #endif 3454 #endif
3195 3455
3196 /* 3456 /*
3197 ** Internal function prototypes 3457 ** Internal function prototypes
3198 */ 3458 */
3199 #define sqlite3StrICmp sqlite3_stricmp 3459 int sqlite3StrICmp(const char*,const char*);
3200 int sqlite3Strlen30(const char*); 3460 int sqlite3Strlen30(const char*);
3461 char *sqlite3ColumnType(Column*,char*);
3201 #define sqlite3StrNICmp sqlite3_strnicmp 3462 #define sqlite3StrNICmp sqlite3_strnicmp
3202 3463
3203 int sqlite3MallocInit(void); 3464 int sqlite3MallocInit(void);
3204 void sqlite3MallocEnd(void); 3465 void sqlite3MallocEnd(void);
3205 void *sqlite3Malloc(u64); 3466 void *sqlite3Malloc(u64);
3206 void *sqlite3MallocZero(u64); 3467 void *sqlite3MallocZero(u64);
3207 void *sqlite3DbMallocZero(sqlite3*, u64); 3468 void *sqlite3DbMallocZero(sqlite3*, u64);
3208 void *sqlite3DbMallocRaw(sqlite3*, u64); 3469 void *sqlite3DbMallocRaw(sqlite3*, u64);
3470 void *sqlite3DbMallocRawNN(sqlite3*, u64);
3209 char *sqlite3DbStrDup(sqlite3*,const char*); 3471 char *sqlite3DbStrDup(sqlite3*,const char*);
3210 char *sqlite3DbStrNDup(sqlite3*,const char*, u64); 3472 char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
3211 void *sqlite3Realloc(void*, u64); 3473 void *sqlite3Realloc(void*, u64);
3212 void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); 3474 void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
3213 void *sqlite3DbRealloc(sqlite3 *, void *, u64); 3475 void *sqlite3DbRealloc(sqlite3 *, void *, u64);
3214 void sqlite3DbFree(sqlite3*, void*); 3476 void sqlite3DbFree(sqlite3*, void*);
3215 int sqlite3MallocSize(void*); 3477 int sqlite3MallocSize(void*);
3216 int sqlite3DbMallocSize(sqlite3*, void*); 3478 int sqlite3DbMallocSize(sqlite3*, void*);
3217 void *sqlite3ScratchMalloc(int); 3479 void *sqlite3ScratchMalloc(int);
3218 void sqlite3ScratchFree(void*); 3480 void sqlite3ScratchFree(void*);
3219 void *sqlite3PageMalloc(int); 3481 void *sqlite3PageMalloc(int);
3220 void sqlite3PageFree(void*); 3482 void sqlite3PageFree(void*);
3221 void sqlite3MemSetDefault(void); 3483 void sqlite3MemSetDefault(void);
3222 #ifndef SQLITE_OMIT_BUILTIN_TEST 3484 #ifndef SQLITE_UNTESTABLE
3223 void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); 3485 void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
3224 #endif 3486 #endif
3225 int sqlite3HeapNearlyFull(void); 3487 int sqlite3HeapNearlyFull(void);
3226 3488
3227 /* 3489 /*
3228 ** On systems with ample stack space and that support alloca(), make 3490 ** On systems with ample stack space and that support alloca(), make
3229 ** use of alloca() to obtain space for large automatic objects. By default, 3491 ** use of alloca() to obtain space for large automatic objects. By default,
3230 ** obtain space from malloc(). 3492 ** obtain space from malloc().
3231 ** 3493 **
3232 ** The alloca() routine never returns NULL. This will cause code paths 3494 ** The alloca() routine never returns NULL. This will cause code paths
3233 ** that deal with sqlite3StackAlloc() failures to be unreachable. 3495 ** that deal with sqlite3StackAlloc() failures to be unreachable.
3234 */ 3496 */
3235 #ifdef SQLITE_USE_ALLOCA 3497 #ifdef SQLITE_USE_ALLOCA
3236 # define sqlite3StackAllocRaw(D,N) alloca(N) 3498 # define sqlite3StackAllocRaw(D,N) alloca(N)
3237 # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N) 3499 # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
3238 # define sqlite3StackFree(D,P) 3500 # define sqlite3StackFree(D,P)
3239 #else 3501 #else
3240 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) 3502 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
3241 # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N) 3503 # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
3242 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) 3504 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
3243 #endif 3505 #endif
3244 3506
3507 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
3508 ** are, disable MEMSYS3
3509 */
3510 #ifdef SQLITE_ENABLE_MEMSYS5
3511 const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
3512 #undef SQLITE_ENABLE_MEMSYS3
3513 #endif
3245 #ifdef SQLITE_ENABLE_MEMSYS3 3514 #ifdef SQLITE_ENABLE_MEMSYS3
3246 const sqlite3_mem_methods *sqlite3MemGetMemsys3(void); 3515 const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
3247 #endif 3516 #endif
3248 #ifdef SQLITE_ENABLE_MEMSYS5
3249 const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
3250 #endif
3251 3517
3252 3518
3253 #ifndef SQLITE_MUTEX_OMIT 3519 #ifndef SQLITE_MUTEX_OMIT
3254 sqlite3_mutex_methods const *sqlite3DefaultMutex(void); 3520 sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
3255 sqlite3_mutex_methods const *sqlite3NoopMutex(void); 3521 sqlite3_mutex_methods const *sqlite3NoopMutex(void);
3256 sqlite3_mutex *sqlite3MutexAlloc(int); 3522 sqlite3_mutex *sqlite3MutexAlloc(int);
3257 int sqlite3MutexInit(void); 3523 int sqlite3MutexInit(void);
3258 int sqlite3MutexEnd(void); 3524 int sqlite3MutexEnd(void);
3259 #endif 3525 #endif
3260 #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) 3526 #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP)
(...skipping 20 matching lines...) Expand all
3281 /* 3547 /*
3282 ** An instance of the following structure holds information about SQL 3548 ** An instance of the following structure holds information about SQL
3283 ** functions arguments that are the parameters to the printf() function. 3549 ** functions arguments that are the parameters to the printf() function.
3284 */ 3550 */
3285 struct PrintfArguments { 3551 struct PrintfArguments {
3286 int nArg; /* Total number of arguments */ 3552 int nArg; /* Total number of arguments */
3287 int nUsed; /* Number of arguments used so far */ 3553 int nUsed; /* Number of arguments used so far */
3288 sqlite3_value **apArg; /* The argument values */ 3554 sqlite3_value **apArg; /* The argument values */
3289 }; 3555 };
3290 3556
3291 #define SQLITE_PRINTF_INTERNAL 0x01 3557 void sqlite3VXPrintf(StrAccum*, const char*, va_list);
3292 #define SQLITE_PRINTF_SQLFUNC 0x02 3558 void sqlite3XPrintf(StrAccum*, const char*, ...);
3293 void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
3294 void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
3295 char *sqlite3MPrintf(sqlite3*,const char*, ...); 3559 char *sqlite3MPrintf(sqlite3*,const char*, ...);
3296 char *sqlite3VMPrintf(sqlite3*,const char*, va_list); 3560 char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
3297 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) 3561 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3298 void sqlite3DebugPrintf(const char*, ...); 3562 void sqlite3DebugPrintf(const char*, ...);
3299 #endif 3563 #endif
3300 #if defined(SQLITE_TEST) 3564 #if defined(SQLITE_TEST)
3301 void *sqlite3TestTextToPtr(const char*); 3565 void *sqlite3TestTextToPtr(const char*);
3302 #endif 3566 #endif
3303 3567
3304 #if defined(SQLITE_DEBUG) 3568 #if defined(SQLITE_DEBUG)
3305 void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); 3569 void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
3570 void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
3306 void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); 3571 void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
3307 void sqlite3TreeViewSelect(TreeView*, const Select*, u8); 3572 void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
3308 void sqlite3TreeViewWith(TreeView*, const With*, u8); 3573 void sqlite3TreeViewWith(TreeView*, const With*, u8);
3309 #endif 3574 #endif
3310 3575
3311 3576
3312 void sqlite3SetString(char **, sqlite3*, const char*); 3577 void sqlite3SetString(char **, sqlite3*, const char*);
3313 void sqlite3ErrorMsg(Parse*, const char*, ...); 3578 void sqlite3ErrorMsg(Parse*, const char*, ...);
3314 int sqlite3Dequote(char*); 3579 void sqlite3Dequote(char*);
3580 void sqlite3TokenInit(Token*,char*);
3315 int sqlite3KeywordCode(const unsigned char*, int); 3581 int sqlite3KeywordCode(const unsigned char*, int);
3316 int sqlite3RunParser(Parse*, const char*, char **); 3582 int sqlite3RunParser(Parse*, const char*, char **);
3317 void sqlite3FinishCoding(Parse*); 3583 void sqlite3FinishCoding(Parse*);
3318 int sqlite3GetTempReg(Parse*); 3584 int sqlite3GetTempReg(Parse*);
3319 void sqlite3ReleaseTempReg(Parse*,int); 3585 void sqlite3ReleaseTempReg(Parse*,int);
3320 int sqlite3GetTempRange(Parse*,int); 3586 int sqlite3GetTempRange(Parse*,int);
3321 void sqlite3ReleaseTempRange(Parse*,int,int); 3587 void sqlite3ReleaseTempRange(Parse*,int,int);
3322 void sqlite3ClearTempRegCache(Parse*); 3588 void sqlite3ClearTempRegCache(Parse*);
3589 #ifdef SQLITE_DEBUG
3590 int sqlite3NoTempsInRange(Parse*,int,int);
3591 #endif
3323 Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); 3592 Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
3324 Expr *sqlite3Expr(sqlite3*,int,const char*); 3593 Expr *sqlite3Expr(sqlite3*,int,const char*);
3325 void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); 3594 void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
3326 Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); 3595 Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
3596 void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
3327 Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); 3597 Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
3328 Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); 3598 Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
3329 void sqlite3ExprAssignVarNumber(Parse*, Expr*); 3599 void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
3330 void sqlite3ExprDelete(sqlite3*, Expr*); 3600 void sqlite3ExprDelete(sqlite3*, Expr*);
3331 ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); 3601 ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
3602 ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
3332 void sqlite3ExprListSetSortOrder(ExprList*,int); 3603 void sqlite3ExprListSetSortOrder(ExprList*,int);
3333 void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); 3604 void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
3334 void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); 3605 void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
3335 void sqlite3ExprListDelete(sqlite3*, ExprList*); 3606 void sqlite3ExprListDelete(sqlite3*, ExprList*);
3336 u32 sqlite3ExprListFlags(const ExprList*); 3607 u32 sqlite3ExprListFlags(const ExprList*);
3337 int sqlite3Init(sqlite3*, char**); 3608 int sqlite3Init(sqlite3*, char**);
3338 int sqlite3InitCallback(void*, int, char**, char**); 3609 int sqlite3InitCallback(void*, int, char**, char**);
3339 void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); 3610 void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
3611 #ifndef SQLITE_OMIT_VIRTUALTABLE
3612 Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
3613 #endif
3340 void sqlite3ResetAllSchemasOfConnection(sqlite3*); 3614 void sqlite3ResetAllSchemasOfConnection(sqlite3*);
3341 void sqlite3ResetOneSchema(sqlite3*,int); 3615 void sqlite3ResetOneSchema(sqlite3*,int);
3342 void sqlite3CollapseDatabaseArray(sqlite3*); 3616 void sqlite3CollapseDatabaseArray(sqlite3*);
3343 void sqlite3BeginParse(Parse*,int);
3344 void sqlite3CommitInternalChanges(sqlite3*); 3617 void sqlite3CommitInternalChanges(sqlite3*);
3345 void sqlite3DeleteColumnNames(sqlite3*,Table*); 3618 void sqlite3DeleteColumnNames(sqlite3*,Table*);
3346 int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); 3619 int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
3620 void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*);
3347 Table *sqlite3ResultSetOfSelect(Parse*,Select*); 3621 Table *sqlite3ResultSetOfSelect(Parse*,Select*);
3348 void sqlite3OpenMasterTable(Parse *, int); 3622 void sqlite3OpenMasterTable(Parse *, int);
3349 Index *sqlite3PrimaryKeyIndex(Table*); 3623 Index *sqlite3PrimaryKeyIndex(Table*);
3350 i16 sqlite3ColumnOfIndex(Index*, i16); 3624 i16 sqlite3ColumnOfIndex(Index*, i16);
3351 void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); 3625 void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
3352 #if SQLITE_ENABLE_HIDDEN_COLUMNS 3626 #if SQLITE_ENABLE_HIDDEN_COLUMNS
3353 void sqlite3ColumnPropertiesFromName(Table*, Column*); 3627 void sqlite3ColumnPropertiesFromName(Table*, Column*);
3354 #else 3628 #else
3355 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ 3629 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
3356 #endif 3630 #endif
3357 void sqlite3AddColumn(Parse*,Token*); 3631 void sqlite3AddColumn(Parse*,Token*,Token*);
3358 void sqlite3AddNotNull(Parse*, int); 3632 void sqlite3AddNotNull(Parse*, int);
3359 void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); 3633 void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
3360 void sqlite3AddCheckConstraint(Parse*, Expr*); 3634 void sqlite3AddCheckConstraint(Parse*, Expr*);
3361 void sqlite3AddColumnType(Parse*,Token*);
3362 void sqlite3AddDefaultValue(Parse*,ExprSpan*); 3635 void sqlite3AddDefaultValue(Parse*,ExprSpan*);
3363 void sqlite3AddCollateType(Parse*, Token*); 3636 void sqlite3AddCollateType(Parse*, Token*);
3364 void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); 3637 void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
3365 int sqlite3ParseUri(const char*,const char*,unsigned int*, 3638 int sqlite3ParseUri(const char*,const char*,unsigned int*,
3366 sqlite3_vfs**,char**,char **); 3639 sqlite3_vfs**,char**,char **);
3367 Btree *sqlite3DbNameToBtree(sqlite3*,const char*); 3640 Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
3368 int sqlite3CodeOnce(Parse *);
3369 3641
3370 #ifdef SQLITE_OMIT_BUILTIN_TEST 3642 #ifdef SQLITE_UNTESTABLE
3371 # define sqlite3FaultSim(X) SQLITE_OK 3643 # define sqlite3FaultSim(X) SQLITE_OK
3372 #else 3644 #else
3373 int sqlite3FaultSim(int); 3645 int sqlite3FaultSim(int);
3374 #endif 3646 #endif
3375 3647
3376 Bitvec *sqlite3BitvecCreate(u32); 3648 Bitvec *sqlite3BitvecCreate(u32);
3377 int sqlite3BitvecTest(Bitvec*, u32); 3649 int sqlite3BitvecTest(Bitvec*, u32);
3378 int sqlite3BitvecTestNotNull(Bitvec*, u32); 3650 int sqlite3BitvecTestNotNull(Bitvec*, u32);
3379 int sqlite3BitvecSet(Bitvec*, u32); 3651 int sqlite3BitvecSet(Bitvec*, u32);
3380 void sqlite3BitvecClear(Bitvec*, u32, void*); 3652 void sqlite3BitvecClear(Bitvec*, u32, void*);
3381 void sqlite3BitvecDestroy(Bitvec*); 3653 void sqlite3BitvecDestroy(Bitvec*);
3382 u32 sqlite3BitvecSize(Bitvec*); 3654 u32 sqlite3BitvecSize(Bitvec*);
3383 #ifndef SQLITE_OMIT_BUILTIN_TEST 3655 #ifndef SQLITE_UNTESTABLE
3384 int sqlite3BitvecBuiltinTest(int,int*); 3656 int sqlite3BitvecBuiltinTest(int,int*);
3385 #endif 3657 #endif
3386 3658
3387 RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int); 3659 RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
3388 void sqlite3RowSetClear(RowSet*); 3660 void sqlite3RowSetClear(RowSet*);
3389 void sqlite3RowSetInsert(RowSet*, i64); 3661 void sqlite3RowSetInsert(RowSet*, i64);
3390 int sqlite3RowSetTest(RowSet*, int iBatch, i64); 3662 int sqlite3RowSetTest(RowSet*, int iBatch, i64);
3391 int sqlite3RowSetNext(RowSet*, i64*); 3663 int sqlite3RowSetNext(RowSet*, i64*);
3392 3664
3393 void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int); 3665 void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int);
(...skipping 26 matching lines...) Expand all
3420 SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, 3692 SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
3421 Token*, Select*, Expr*, IdList*); 3693 Token*, Select*, Expr*, IdList*);
3422 void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *); 3694 void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
3423 void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*); 3695 void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
3424 int sqlite3IndexedByLookup(Parse *, struct SrcList_item *); 3696 int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
3425 void sqlite3SrcListShiftJoinType(SrcList*); 3697 void sqlite3SrcListShiftJoinType(SrcList*);
3426 void sqlite3SrcListAssignCursors(Parse*, SrcList*); 3698 void sqlite3SrcListAssignCursors(Parse*, SrcList*);
3427 void sqlite3IdListDelete(sqlite3*, IdList*); 3699 void sqlite3IdListDelete(sqlite3*, IdList*);
3428 void sqlite3SrcListDelete(sqlite3*, SrcList*); 3700 void sqlite3SrcListDelete(sqlite3*, SrcList*);
3429 Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**); 3701 Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
3430 Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, 3702 void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
3431 Expr*, int, int); 3703 Expr*, int, int, u8);
3432 void sqlite3DropIndex(Parse*, SrcList*, int); 3704 void sqlite3DropIndex(Parse*, SrcList*, int);
3433 int sqlite3Select(Parse*, Select*, SelectDest*); 3705 int sqlite3Select(Parse*, Select*, SelectDest*);
3434 Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, 3706 Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
3435 Expr*,ExprList*,u16,Expr*,Expr*); 3707 Expr*,ExprList*,u32,Expr*,Expr*);
3436 void sqlite3SelectDelete(sqlite3*, Select*); 3708 void sqlite3SelectDelete(sqlite3*, Select*);
3437 Table *sqlite3SrcListLookup(Parse*, SrcList*); 3709 Table *sqlite3SrcListLookup(Parse*, SrcList*);
3438 int sqlite3IsReadOnly(Parse*, Table*, int); 3710 int sqlite3IsReadOnly(Parse*, Table*, int);
3439 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); 3711 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
3440 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) 3712 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
3441 Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*); 3713 Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*);
3442 #endif 3714 #endif
3443 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); 3715 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
3444 void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); 3716 void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
3445 WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); 3717 WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
3446 void sqlite3WhereEnd(WhereInfo*); 3718 void sqlite3WhereEnd(WhereInfo*);
3447 u64 sqlite3WhereOutputRowCount(WhereInfo*); 3719 LogEst sqlite3WhereOutputRowCount(WhereInfo*);
3448 int sqlite3WhereIsDistinct(WhereInfo*); 3720 int sqlite3WhereIsDistinct(WhereInfo*);
3449 int sqlite3WhereIsOrdered(WhereInfo*); 3721 int sqlite3WhereIsOrdered(WhereInfo*);
3722 int sqlite3WhereOrderedInnerLoop(WhereInfo*);
3450 int sqlite3WhereIsSorted(WhereInfo*); 3723 int sqlite3WhereIsSorted(WhereInfo*);
3451 int sqlite3WhereContinueLabel(WhereInfo*); 3724 int sqlite3WhereContinueLabel(WhereInfo*);
3452 int sqlite3WhereBreakLabel(WhereInfo*); 3725 int sqlite3WhereBreakLabel(WhereInfo*);
3453 int sqlite3WhereOkOnePass(WhereInfo*, int*); 3726 int sqlite3WhereOkOnePass(WhereInfo*, int*);
3454 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ 3727 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */
3455 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ 3728 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */
3456 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ 3729 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */
3457 void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); 3730 void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
3458 int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); 3731 int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
3459 void sqlite3ExprCodeGetColumnToReg(Parse*, Table*, int, int, int); 3732 void sqlite3ExprCodeGetColumnToReg(Parse*, Table*, int, int, int);
3460 void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); 3733 void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
3461 void sqlite3ExprCodeMove(Parse*, int, int, int); 3734 void sqlite3ExprCodeMove(Parse*, int, int, int);
3462 void sqlite3ExprCacheStore(Parse*, int, int, int); 3735 void sqlite3ExprCacheStore(Parse*, int, int, int);
3463 void sqlite3ExprCachePush(Parse*); 3736 void sqlite3ExprCachePush(Parse*);
3464 void sqlite3ExprCachePop(Parse*); 3737 void sqlite3ExprCachePop(Parse*);
3465 void sqlite3ExprCacheRemove(Parse*, int, int); 3738 void sqlite3ExprCacheRemove(Parse*, int, int);
3466 void sqlite3ExprCacheClear(Parse*); 3739 void sqlite3ExprCacheClear(Parse*);
3467 void sqlite3ExprCacheAffinityChange(Parse*, int, int); 3740 void sqlite3ExprCacheAffinityChange(Parse*, int, int);
3468 void sqlite3ExprCode(Parse*, Expr*, int); 3741 void sqlite3ExprCode(Parse*, Expr*, int);
3469 void sqlite3ExprCodeCopy(Parse*, Expr*, int); 3742 void sqlite3ExprCodeCopy(Parse*, Expr*, int);
3470 void sqlite3ExprCodeFactorable(Parse*, Expr*, int); 3743 void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
3471 void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); 3744 int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
3472 int sqlite3ExprCodeTemp(Parse*, Expr*, int*); 3745 int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
3473 int sqlite3ExprCodeTarget(Parse*, Expr*, int); 3746 int sqlite3ExprCodeTarget(Parse*, Expr*, int);
3474 void sqlite3ExprCodeAndCache(Parse*, Expr*, int); 3747 void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
3475 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); 3748 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
3476 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ 3749 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
3477 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ 3750 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
3478 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */ 3751 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
3752 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
3479 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 3753 void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
3480 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 3754 void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
3481 void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); 3755 void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
3482 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 3756 Table *sqlite3FindTable(sqlite3*,const char*, const char*);
3483 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); 3757 #define LOCATE_VIEW 0x01
3484 Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); 3758 #define LOCATE_NOERR 0x02
3759 Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
3760 Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
3485 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 3761 Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
3486 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 3762 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
3487 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 3763 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
3488 void sqlite3Vacuum(Parse*); 3764 void sqlite3Vacuum(Parse*,Token*);
3489 int sqlite3RunVacuum(char**, sqlite3*); 3765 int sqlite3RunVacuum(char**, sqlite3*, int);
3490 char *sqlite3NameFromToken(sqlite3*, Token*); 3766 char *sqlite3NameFromToken(sqlite3*, Token*);
3491 int sqlite3ExprCompare(Expr*, Expr*, int); 3767 int sqlite3ExprCompare(Expr*, Expr*, int);
3492 int sqlite3ExprListCompare(ExprList*, ExprList*, int); 3768 int sqlite3ExprListCompare(ExprList*, ExprList*, int);
3493 int sqlite3ExprImpliesExpr(Expr*, Expr*, int); 3769 int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
3494 void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); 3770 void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
3495 void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); 3771 void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
3772 int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
3496 int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); 3773 int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
3497 Vdbe *sqlite3GetVdbe(Parse*); 3774 Vdbe *sqlite3GetVdbe(Parse*);
3498 #ifndef SQLITE_OMIT_BUILTIN_TEST 3775 #ifndef SQLITE_UNTESTABLE
3499 void sqlite3PrngSaveState(void); 3776 void sqlite3PrngSaveState(void);
3500 void sqlite3PrngRestoreState(void); 3777 void sqlite3PrngRestoreState(void);
3501 #endif 3778 #endif
3502 void sqlite3RollbackAll(sqlite3*,int); 3779 void sqlite3RollbackAll(sqlite3*,int);
3503 void sqlite3CodeVerifySchema(Parse*, int); 3780 void sqlite3CodeVerifySchema(Parse*, int);
3504 void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); 3781 void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
3505 void sqlite3BeginTransaction(Parse*, int); 3782 void sqlite3BeginTransaction(Parse*, int);
3506 void sqlite3CommitTransaction(Parse*); 3783 void sqlite3CommitTransaction(Parse*);
3507 void sqlite3RollbackTransaction(Parse*); 3784 void sqlite3RollbackTransaction(Parse*);
3508 void sqlite3Savepoint(Parse*, int, Token*); 3785 void sqlite3Savepoint(Parse*, int, Token*);
3509 void sqlite3CloseSavepoints(sqlite3 *); 3786 void sqlite3CloseSavepoints(sqlite3 *);
3510 void sqlite3LeaveMutexAndCloseZombie(sqlite3*); 3787 void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
3511 int sqlite3ExprIsConstant(Expr*); 3788 int sqlite3ExprIsConstant(Expr*);
3512 int sqlite3ExprIsConstantNotJoin(Expr*); 3789 int sqlite3ExprIsConstantNotJoin(Expr*);
3513 int sqlite3ExprIsConstantOrFunction(Expr*, u8); 3790 int sqlite3ExprIsConstantOrFunction(Expr*, u8);
3514 int sqlite3ExprIsTableConstant(Expr*,int); 3791 int sqlite3ExprIsTableConstant(Expr*,int);
3515 #ifdef SQLITE_ENABLE_CURSOR_HINTS 3792 #ifdef SQLITE_ENABLE_CURSOR_HINTS
3516 int sqlite3ExprContainsSubquery(Expr*); 3793 int sqlite3ExprContainsSubquery(Expr*);
3517 #endif 3794 #endif
3518 int sqlite3ExprIsInteger(Expr*, int*); 3795 int sqlite3ExprIsInteger(Expr*, int*);
3519 int sqlite3ExprCanBeNull(const Expr*); 3796 int sqlite3ExprCanBeNull(const Expr*);
3520 int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); 3797 int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
3521 int sqlite3IsRowid(const char*); 3798 int sqlite3IsRowid(const char*);
3522 void sqlite3GenerateRowDelete( 3799 void sqlite3GenerateRowDelete(
3523 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); 3800 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
3524 void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); 3801 void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
3525 int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); 3802 int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
3526 void sqlite3ResolvePartIdxLabel(Parse*,int); 3803 void sqlite3ResolvePartIdxLabel(Parse*,int);
3527 void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, 3804 void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
3528 u8,u8,int,int*); 3805 u8,u8,int,int*,int*);
3806 #ifdef SQLITE_ENABLE_NULL_TRIM
3807 void sqlite3SetMakeRecordP5(Vdbe*,Table*);
3808 #else
3809 # define sqlite3SetMakeRecordP5(A,B)
3810 #endif
3529 void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); 3811 void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
3530 int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); 3812 int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
3531 void sqlite3BeginWriteOperation(Parse*, int, int); 3813 void sqlite3BeginWriteOperation(Parse*, int, int);
3532 void sqlite3MultiWrite(Parse*); 3814 void sqlite3MultiWrite(Parse*);
3533 void sqlite3MayAbort(Parse*); 3815 void sqlite3MayAbort(Parse*);
3534 void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); 3816 void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
3535 void sqlite3UniqueConstraint(Parse*, int, Index*); 3817 void sqlite3UniqueConstraint(Parse*, int, Index*);
3536 void sqlite3RowidConstraint(Parse*, int, Table*); 3818 void sqlite3RowidConstraint(Parse*, int, Table*);
3537 Expr *sqlite3ExprDup(sqlite3*,Expr*,int); 3819 Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
3538 ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); 3820 ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
3539 SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); 3821 SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
3540 IdList *sqlite3IdListDup(sqlite3*,IdList*); 3822 IdList *sqlite3IdListDup(sqlite3*,IdList*);
3541 Select *sqlite3SelectDup(sqlite3*,Select*,int); 3823 Select *sqlite3SelectDup(sqlite3*,Select*,int);
3542 #if SELECTTRACE_ENABLED 3824 #if SELECTTRACE_ENABLED
3543 void sqlite3SelectSetName(Select*,const char*); 3825 void sqlite3SelectSetName(Select*,const char*);
3544 #else 3826 #else
3545 # define sqlite3SelectSetName(A,B) 3827 # define sqlite3SelectSetName(A,B)
3546 #endif 3828 #endif
3547 void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); 3829 void sqlite3InsertBuiltinFuncs(FuncDef*,int);
3548 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8); 3830 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
3549 void sqlite3RegisterBuiltinFunctions(sqlite3*); 3831 void sqlite3RegisterBuiltinFunctions(void);
3550 void sqlite3RegisterDateTimeFunctions(void); 3832 void sqlite3RegisterDateTimeFunctions(void);
3551 void sqlite3RegisterGlobalFunctions(void); 3833 void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
3552 int sqlite3SafetyCheckOk(sqlite3*); 3834 int sqlite3SafetyCheckOk(sqlite3*);
3553 int sqlite3SafetyCheckSickOrOk(sqlite3*); 3835 int sqlite3SafetyCheckSickOrOk(sqlite3*);
3554 void sqlite3ChangeCookie(Parse*, int); 3836 void sqlite3ChangeCookie(Parse*, int);
3555 3837
3556 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) 3838 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
3557 void sqlite3MaterializeView(Parse*, Table*, Expr*, int); 3839 void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
3558 #endif 3840 #endif
3559 3841
3560 #ifndef SQLITE_OMIT_TRIGGER 3842 #ifndef SQLITE_OMIT_TRIGGER
3561 void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*, 3843 void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 int sqlite3GetInt32(const char *, int*); 3902 int sqlite3GetInt32(const char *, int*);
3621 int sqlite3Atoi(const char*); 3903 int sqlite3Atoi(const char*);
3622 int sqlite3Utf16ByteLen(const void *pData, int nChar); 3904 int sqlite3Utf16ByteLen(const void *pData, int nChar);
3623 int sqlite3Utf8CharLen(const char *pData, int nByte); 3905 int sqlite3Utf8CharLen(const char *pData, int nByte);
3624 u32 sqlite3Utf8Read(const u8**); 3906 u32 sqlite3Utf8Read(const u8**);
3625 LogEst sqlite3LogEst(u64); 3907 LogEst sqlite3LogEst(u64);
3626 LogEst sqlite3LogEstAdd(LogEst,LogEst); 3908 LogEst sqlite3LogEstAdd(LogEst,LogEst);
3627 #ifndef SQLITE_OMIT_VIRTUALTABLE 3909 #ifndef SQLITE_OMIT_VIRTUALTABLE
3628 LogEst sqlite3LogEstFromDouble(double); 3910 LogEst sqlite3LogEstFromDouble(double);
3629 #endif 3911 #endif
3912 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
3913 defined(SQLITE_ENABLE_STAT3_OR_STAT4) || \
3914 defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
3630 u64 sqlite3LogEstToInt(LogEst); 3915 u64 sqlite3LogEstToInt(LogEst);
3916 #endif
3917 VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
3918 const char *sqlite3VListNumToName(VList*,int);
3919 int sqlite3VListNameToNum(VList*,const char*,int);
3631 3920
3632 /* 3921 /*
3633 ** Routines to read and write variable-length integers. These used to 3922 ** Routines to read and write variable-length integers. These used to
3634 ** be defined locally, but now we use the varint routines in the util.c 3923 ** be defined locally, but now we use the varint routines in the util.c
3635 ** file. 3924 ** file.
3636 */ 3925 */
3637 int sqlite3PutVarint(unsigned char*, u64); 3926 int sqlite3PutVarint(unsigned char*, u64);
3638 u8 sqlite3GetVarint(const unsigned char *, u64 *); 3927 u8 sqlite3GetVarint(const unsigned char *, u64 *);
3639 u8 sqlite3GetVarint32(const unsigned char *, u32 *); 3928 u8 sqlite3GetVarint32(const unsigned char *, u32 *);
3640 int sqlite3VarintLen(u64 v); 3929 int sqlite3VarintLen(u64 v);
3641 3930
3642 /* 3931 /*
3643 ** The common case is for a varint to be a single byte. They following 3932 ** The common case is for a varint to be a single byte. They following
3644 ** macros handle the common case without a procedure call, but then call 3933 ** macros handle the common case without a procedure call, but then call
3645 ** the procedure for larger varints. 3934 ** the procedure for larger varints.
3646 */ 3935 */
3647 #define getVarint32(A,B) \ 3936 #define getVarint32(A,B) \
3648 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) 3937 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
3649 #define putVarint32(A,B) \ 3938 #define putVarint32(A,B) \
3650 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ 3939 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
3651 sqlite3PutVarint((A),(B))) 3940 sqlite3PutVarint((A),(B)))
3652 #define getVarint sqlite3GetVarint 3941 #define getVarint sqlite3GetVarint
3653 #define putVarint sqlite3PutVarint 3942 #define putVarint sqlite3PutVarint
3654 3943
3655 3944
3656 const char *sqlite3IndexAffinityStr(sqlite3*, Index*); 3945 const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
3657 void sqlite3TableAffinity(Vdbe*, Table*, int); 3946 void sqlite3TableAffinity(Vdbe*, Table*, int);
3658 char sqlite3CompareAffinity(Expr *pExpr, char aff2); 3947 char sqlite3CompareAffinity(Expr *pExpr, char aff2);
3659 int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); 3948 int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
3949 char sqlite3TableColumnAffinity(Table*,int);
3660 char sqlite3ExprAffinity(Expr *pExpr); 3950 char sqlite3ExprAffinity(Expr *pExpr);
3661 int sqlite3Atoi64(const char*, i64*, int, u8); 3951 int sqlite3Atoi64(const char*, i64*, int, u8);
3662 int sqlite3DecOrHexToI64(const char*, i64*); 3952 int sqlite3DecOrHexToI64(const char*, i64*);
3663 void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); 3953 void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
3664 void sqlite3Error(sqlite3*,int); 3954 void sqlite3Error(sqlite3*,int);
3955 void sqlite3SystemError(sqlite3*,int);
3665 void *sqlite3HexToBlob(sqlite3*, const char *z, int n); 3956 void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
3666 u8 sqlite3HexToInt(int h); 3957 u8 sqlite3HexToInt(int h);
3667 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); 3958 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
3668 3959
3669 #if defined(SQLITE_NEED_ERR_NAME) 3960 #if defined(SQLITE_NEED_ERR_NAME)
3670 const char *sqlite3ErrName(int); 3961 const char *sqlite3ErrName(int);
3671 #endif 3962 #endif
3672 3963
3673 const char *sqlite3ErrStr(int); 3964 const char *sqlite3ErrStr(int);
3674 int sqlite3ReadSchema(Parse *pParse); 3965 int sqlite3ReadSchema(Parse *pParse);
(...skipping 12 matching lines...) Expand all
3687 int sqlite3AbsInt32(int); 3978 int sqlite3AbsInt32(int);
3688 #ifdef SQLITE_ENABLE_8_3_NAMES 3979 #ifdef SQLITE_ENABLE_8_3_NAMES
3689 void sqlite3FileSuffix3(const char*, char*); 3980 void sqlite3FileSuffix3(const char*, char*);
3690 #else 3981 #else
3691 # define sqlite3FileSuffix3(X,Y) 3982 # define sqlite3FileSuffix3(X,Y)
3692 #endif 3983 #endif
3693 u8 sqlite3GetBoolean(const char *z,u8); 3984 u8 sqlite3GetBoolean(const char *z,u8);
3694 3985
3695 const void *sqlite3ValueText(sqlite3_value*, u8); 3986 const void *sqlite3ValueText(sqlite3_value*, u8);
3696 int sqlite3ValueBytes(sqlite3_value*, u8); 3987 int sqlite3ValueBytes(sqlite3_value*, u8);
3697 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 3988 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
3698 void(*)(void*)); 3989 void(*)(void*));
3699 void sqlite3ValueSetNull(sqlite3_value*); 3990 void sqlite3ValueSetNull(sqlite3_value*);
3700 void sqlite3ValueFree(sqlite3_value*); 3991 void sqlite3ValueFree(sqlite3_value*);
3701 sqlite3_value *sqlite3ValueNew(sqlite3 *); 3992 sqlite3_value *sqlite3ValueNew(sqlite3 *);
3702 char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); 3993 char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
3703 int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); 3994 int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
3704 void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); 3995 void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
3705 #ifndef SQLITE_AMALGAMATION 3996 #ifndef SQLITE_AMALGAMATION
3706 extern const unsigned char sqlite3OpcodeProperty[]; 3997 extern const unsigned char sqlite3OpcodeProperty[];
3707 extern const char sqlite3StrBINARY[]; 3998 extern const char sqlite3StrBINARY[];
3708 extern const unsigned char sqlite3UpperToLower[]; 3999 extern const unsigned char sqlite3UpperToLower[];
3709 extern const unsigned char sqlite3CtypeMap[]; 4000 extern const unsigned char sqlite3CtypeMap[];
3710 extern const Token sqlite3IntTokens[]; 4001 extern const Token sqlite3IntTokens[];
3711 extern SQLITE_WSD struct Sqlite3Config sqlite3Config; 4002 extern SQLITE_WSD struct Sqlite3Config sqlite3Config;
3712 extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; 4003 extern FuncDefHash sqlite3BuiltinFunctions;
3713 #ifndef SQLITE_OMIT_WSD 4004 #ifndef SQLITE_OMIT_WSD
3714 extern int sqlite3PendingByte; 4005 extern int sqlite3PendingByte;
3715 #endif 4006 #endif
3716 #endif 4007 #endif
3717 void sqlite3RootPageMoved(sqlite3*, int, int, int); 4008 void sqlite3RootPageMoved(sqlite3*, int, int, int);
3718 void sqlite3Reindex(Parse*, Token*, Token*); 4009 void sqlite3Reindex(Parse*, Token*, Token*);
3719 void sqlite3AlterFunctions(void); 4010 void sqlite3AlterFunctions(void);
3720 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); 4011 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
3721 int sqlite3GetToken(const unsigned char *, int *); 4012 int sqlite3GetToken(const unsigned char *, int *);
3722 void sqlite3NestedParse(Parse*, const char*, ...); 4013 void sqlite3NestedParse(Parse*, const char*, ...);
3723 void sqlite3ExpirePreparedStatements(sqlite3*); 4014 void sqlite3ExpirePreparedStatements(sqlite3*);
3724 int sqlite3CodeSubselect(Parse *, Expr *, int, int); 4015 int sqlite3CodeSubselect(Parse*, Expr *, int, int);
3725 void sqlite3SelectPrep(Parse*, Select*, NameContext*); 4016 void sqlite3SelectPrep(Parse*, Select*, NameContext*);
3726 void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); 4017 void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
3727 int sqlite3MatchSpanName(const char*, const char*, const char*, const char*); 4018 int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
3728 int sqlite3ResolveExprNames(NameContext*, Expr*); 4019 int sqlite3ResolveExprNames(NameContext*, Expr*);
3729 int sqlite3ResolveExprListNames(NameContext*, ExprList*); 4020 int sqlite3ResolveExprListNames(NameContext*, ExprList*);
3730 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); 4021 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
3731 void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); 4022 void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
3732 int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); 4023 int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
3733 void sqlite3ColumnDefault(Vdbe *, Table *, int, int); 4024 void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
3734 void sqlite3AlterFinishAddColumn(Parse *, Token *); 4025 void sqlite3AlterFinishAddColumn(Parse *, Token *);
3735 void sqlite3AlterBeginAddColumn(Parse *, SrcList *); 4026 void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
3736 CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); 4027 CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
3737 char sqlite3AffinityType(const char*, u8*); 4028 char sqlite3AffinityType(const char*, u8*);
3738 void sqlite3Analyze(Parse*, Token*, Token*); 4029 void sqlite3Analyze(Parse*, Token*, Token*);
3739 int sqlite3InvokeBusyHandler(BusyHandler*); 4030 int sqlite3InvokeBusyHandler(BusyHandler*);
3740 int sqlite3FindDb(sqlite3*, Token*); 4031 int sqlite3FindDb(sqlite3*, Token*);
3741 int sqlite3FindDbName(sqlite3 *, const char *); 4032 int sqlite3FindDbName(sqlite3 *, const char *);
3742 int sqlite3AnalysisLoad(sqlite3*,int iDB); 4033 int sqlite3AnalysisLoad(sqlite3*,int iDB);
3743 void sqlite3DeleteIndexSamples(sqlite3*,Index*); 4034 void sqlite3DeleteIndexSamples(sqlite3*,Index*);
3744 void sqlite3DefaultRowEst(Index*); 4035 void sqlite3DefaultRowEst(Index*);
3745 void sqlite3RegisterLikeFunctions(sqlite3*, int); 4036 void sqlite3RegisterLikeFunctions(sqlite3*, int);
3746 int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); 4037 int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
3747 void sqlite3MinimumFileFormat(Parse*, int, int);
3748 void sqlite3SchemaClear(void *); 4038 void sqlite3SchemaClear(void *);
3749 Schema *sqlite3SchemaGet(sqlite3 *, Btree *); 4039 Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
3750 int sqlite3SchemaToIndex(sqlite3 *db, Schema *); 4040 int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
3751 KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); 4041 KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
3752 void sqlite3KeyInfoUnref(KeyInfo*); 4042 void sqlite3KeyInfoUnref(KeyInfo*);
3753 KeyInfo *sqlite3KeyInfoRef(KeyInfo*); 4043 KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
3754 KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); 4044 KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
3755 #ifdef SQLITE_DEBUG 4045 #ifdef SQLITE_DEBUG
3756 int sqlite3KeyInfoIsWriteable(KeyInfo*); 4046 int sqlite3KeyInfoIsWriteable(KeyInfo*);
3757 #endif 4047 #endif
3758 int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 4048 int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
3759 void (*)(sqlite3_context*,int,sqlite3_value **), 4049 void (*)(sqlite3_context*,int,sqlite3_value **),
3760 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*), 4050 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
3761 FuncDestructor *pDestructor 4051 FuncDestructor *pDestructor
3762 ); 4052 );
4053 void sqlite3OomFault(sqlite3*);
4054 void sqlite3OomClear(sqlite3*);
3763 int sqlite3ApiExit(sqlite3 *db, int); 4055 int sqlite3ApiExit(sqlite3 *db, int);
3764 int sqlite3OpenTempDatabase(Parse *); 4056 int sqlite3OpenTempDatabase(Parse *);
3765 4057
3766 void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); 4058 void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
3767 void sqlite3StrAccumAppend(StrAccum*,const char*,int); 4059 void sqlite3StrAccumAppend(StrAccum*,const char*,int);
3768 void sqlite3StrAccumAppendAll(StrAccum*,const char*); 4060 void sqlite3StrAccumAppendAll(StrAccum*,const char*);
3769 void sqlite3AppendChar(StrAccum*,int,char); 4061 void sqlite3AppendChar(StrAccum*,int,char);
3770 char *sqlite3StrAccumFinish(StrAccum*); 4062 char *sqlite3StrAccumFinish(StrAccum*);
3771 void sqlite3StrAccumReset(StrAccum*); 4063 void sqlite3StrAccumReset(StrAccum*);
3772 void sqlite3SelectDestInit(SelectDest*,int,int); 4064 void sqlite3SelectDestInit(SelectDest*,int,int);
3773 Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); 4065 Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
3774 4066
3775 void sqlite3BackupRestart(sqlite3_backup *); 4067 void sqlite3BackupRestart(sqlite3_backup *);
3776 void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); 4068 void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
3777 4069
4070 #ifndef SQLITE_OMIT_SUBQUERY
4071 int sqlite3ExprCheckIN(Parse*, Expr*);
4072 #else
4073 # define sqlite3ExprCheckIN(x,y) SQLITE_OK
4074 #endif
4075
3778 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 4076 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
3779 void sqlite3AnalyzeFunctions(void); 4077 void sqlite3AnalyzeFunctions(void);
3780 int sqlite3Stat4ProbeSetValue(Parse*,Index*,UnpackedRecord**,Expr*,u8,int,int*); 4078 int sqlite3Stat4ProbeSetValue(
4079 Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*);
3781 int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**); 4080 int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**);
3782 void sqlite3Stat4ProbeFree(UnpackedRecord*); 4081 void sqlite3Stat4ProbeFree(UnpackedRecord*);
3783 int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**); 4082 int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**);
4083 char sqlite3IndexColumnAffinity(sqlite3*, Index*, int);
3784 #endif 4084 #endif
3785 4085
3786 /* 4086 /*
3787 ** The interface to the LEMON-generated parser 4087 ** The interface to the LEMON-generated parser
3788 */ 4088 */
3789 void *sqlite3ParserAlloc(void*(*)(u64)); 4089 #ifndef SQLITE_AMALGAMATION
3790 void sqlite3ParserFree(void*, void(*)(void*)); 4090 void *sqlite3ParserAlloc(void*(*)(u64));
4091 void sqlite3ParserFree(void*, void(*)(void*));
4092 #endif
3791 void sqlite3Parser(void*, int, Token, Parse*); 4093 void sqlite3Parser(void*, int, Token, Parse*);
3792 #ifdef YYTRACKMAXSTACKDEPTH 4094 #ifdef YYTRACKMAXSTACKDEPTH
3793 int sqlite3ParserStackPeak(void*); 4095 int sqlite3ParserStackPeak(void*);
3794 #endif 4096 #endif
3795 4097
3796 void sqlite3AutoLoadExtensions(sqlite3*); 4098 void sqlite3AutoLoadExtensions(sqlite3*);
3797 #ifndef SQLITE_OMIT_LOAD_EXTENSION 4099 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3798 void sqlite3CloseExtensions(sqlite3*); 4100 void sqlite3CloseExtensions(sqlite3*);
3799 #else 4101 #else
3800 # define sqlite3CloseExtensions(X) 4102 # define sqlite3CloseExtensions(X)
3801 #endif 4103 #endif
3802 4104
3803 #ifndef SQLITE_OMIT_SHARED_CACHE 4105 #ifndef SQLITE_OMIT_SHARED_CACHE
3804 void sqlite3TableLock(Parse *, int, int, u8, const char *); 4106 void sqlite3TableLock(Parse *, int, int, u8, const char *);
3805 #else 4107 #else
3806 #define sqlite3TableLock(v,w,x,y,z) 4108 #define sqlite3TableLock(v,w,x,y,z)
3807 #endif 4109 #endif
3808 4110
3809 #ifdef SQLITE_TEST 4111 #ifdef SQLITE_TEST
3810 int sqlite3Utf8To8(unsigned char*); 4112 int sqlite3Utf8To8(unsigned char*);
3811 #endif 4113 #endif
3812 4114
3813 #ifdef SQLITE_OMIT_VIRTUALTABLE 4115 #ifdef SQLITE_OMIT_VIRTUALTABLE
3814 # define sqlite3VtabClear(Y) 4116 # define sqlite3VtabClear(Y)
3815 # define sqlite3VtabSync(X,Y) SQLITE_OK 4117 # define sqlite3VtabSync(X,Y) SQLITE_OK
3816 # define sqlite3VtabRollback(X) 4118 # define sqlite3VtabRollback(X)
3817 # define sqlite3VtabCommit(X) 4119 # define sqlite3VtabCommit(X)
3818 # define sqlite3VtabInSync(db) 0 4120 # define sqlite3VtabInSync(db) 0
3819 # define sqlite3VtabLock(X) 4121 # define sqlite3VtabLock(X)
3820 # define sqlite3VtabUnlock(X) 4122 # define sqlite3VtabUnlock(X)
3821 # define sqlite3VtabUnlockList(X) 4123 # define sqlite3VtabUnlockList(X)
3822 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK 4124 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
3823 # define sqlite3GetVTable(X,Y) ((VTable*)0) 4125 # define sqlite3GetVTable(X,Y) ((VTable*)0)
3824 #else 4126 #else
3825 void sqlite3VtabClear(sqlite3 *db, Table*); 4127 void sqlite3VtabClear(sqlite3 *db, Table*);
3826 void sqlite3VtabDisconnect(sqlite3 *db, Table *p); 4128 void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
3827 int sqlite3VtabSync(sqlite3 *db, Vdbe*); 4129 int sqlite3VtabSync(sqlite3 *db, Vdbe*);
3828 int sqlite3VtabRollback(sqlite3 *db); 4130 int sqlite3VtabRollback(sqlite3 *db);
3829 int sqlite3VtabCommit(sqlite3 *db); 4131 int sqlite3VtabCommit(sqlite3 *db);
3830 void sqlite3VtabLock(VTable *); 4132 void sqlite3VtabLock(VTable *);
3831 void sqlite3VtabUnlock(VTable *); 4133 void sqlite3VtabUnlock(VTable *);
3832 void sqlite3VtabUnlockList(sqlite3*); 4134 void sqlite3VtabUnlockList(sqlite3*);
3833 int sqlite3VtabSavepoint(sqlite3 *, int, int); 4135 int sqlite3VtabSavepoint(sqlite3 *, int, int);
3834 void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); 4136 void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
3835 VTable *sqlite3GetVTable(sqlite3*, Table*); 4137 VTable *sqlite3GetVTable(sqlite3*, Table*);
4138 Module *sqlite3VtabCreateModule(
4139 sqlite3*,
4140 const char*,
4141 const sqlite3_module*,
4142 void*,
4143 void(*)(void*)
4144 );
3836 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) 4145 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
3837 #endif 4146 #endif
3838 int sqlite3VtabEponymousTableInit(Parse*,Module*); 4147 int sqlite3VtabEponymousTableInit(Parse*,Module*);
3839 void sqlite3VtabEponymousTableClear(sqlite3*,Module*); 4148 void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
3840 void sqlite3VtabMakeWritable(Parse*,Table*); 4149 void sqlite3VtabMakeWritable(Parse*,Table*);
3841 void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); 4150 void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
3842 void sqlite3VtabFinishParse(Parse*, Token*); 4151 void sqlite3VtabFinishParse(Parse*, Token*);
3843 void sqlite3VtabArgInit(Parse*); 4152 void sqlite3VtabArgInit(Parse*);
3844 void sqlite3VtabArgExtend(Parse*, Token*); 4153 void sqlite3VtabArgExtend(Parse*, Token*);
3845 int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); 4154 int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
(...skipping 21 matching lines...) Expand all
3867 void sqlite3WithPush(Parse*, With*, u8); 4176 void sqlite3WithPush(Parse*, With*, u8);
3868 #else 4177 #else
3869 #define sqlite3WithPush(x,y,z) 4178 #define sqlite3WithPush(x,y,z)
3870 #define sqlite3WithDelete(x,y) 4179 #define sqlite3WithDelete(x,y)
3871 #endif 4180 #endif
3872 4181
3873 /* Declarations for functions in fkey.c. All of these are replaced by 4182 /* Declarations for functions in fkey.c. All of these are replaced by
3874 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign 4183 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
3875 ** key functionality is available. If OMIT_TRIGGER is defined but 4184 ** key functionality is available. If OMIT_TRIGGER is defined but
3876 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In 4185 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
3877 ** this case foreign keys are parsed, but no other functionality is 4186 ** this case foreign keys are parsed, but no other functionality is
3878 ** provided (enforcement of FK constraints requires the triggers sub-system). 4187 ** provided (enforcement of FK constraints requires the triggers sub-system).
3879 */ 4188 */
3880 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) 4189 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
3881 void sqlite3FkCheck(Parse*, Table*, int, int, int*, int); 4190 void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
3882 void sqlite3FkDropTable(Parse*, SrcList *, Table*); 4191 void sqlite3FkDropTable(Parse*, SrcList *, Table*);
3883 void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int); 4192 void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
3884 int sqlite3FkRequired(Parse*, Table*, int*, int); 4193 int sqlite3FkRequired(Parse*, Table*, int*, int);
3885 u32 sqlite3FkOldmask(Parse*, Table*); 4194 u32 sqlite3FkOldmask(Parse*, Table*);
3886 FKey *sqlite3FkReferences(Table *); 4195 FKey *sqlite3FkReferences(Table *);
3887 #else 4196 #else
3888 #define sqlite3FkActions(a,b,c,d,e,f) 4197 #define sqlite3FkActions(a,b,c,d,e,f)
3889 #define sqlite3FkCheck(a,b,c,d,e,f) 4198 #define sqlite3FkCheck(a,b,c,d,e,f)
3890 #define sqlite3FkDropTable(a,b,c) 4199 #define sqlite3FkDropTable(a,b,c)
3891 #define sqlite3FkOldmask(a,b) 0 4200 #define sqlite3FkOldmask(a,b) 0
3892 #define sqlite3FkRequired(a,b,c,d) 0 4201 #define sqlite3FkRequired(a,b,c,d) 0
4202 #define sqlite3FkReferences(a) 0
3893 #endif 4203 #endif
3894 #ifndef SQLITE_OMIT_FOREIGN_KEY 4204 #ifndef SQLITE_OMIT_FOREIGN_KEY
3895 void sqlite3FkDelete(sqlite3 *, Table*); 4205 void sqlite3FkDelete(sqlite3 *, Table*);
3896 int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); 4206 int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
3897 #else 4207 #else
3898 #define sqlite3FkDelete(a,b) 4208 #define sqlite3FkDelete(a,b)
3899 #define sqlite3FkLocateIndex(a,b,c,d,e) 4209 #define sqlite3FkLocateIndex(a,b,c,d,e)
3900 #endif 4210 #endif
3901 4211
3902 4212
3903 /* 4213 /*
3904 ** Available fault injectors. Should be numbered beginning with 0. 4214 ** Available fault injectors. Should be numbered beginning with 0.
3905 */ 4215 */
3906 #define SQLITE_FAULTINJECTOR_MALLOC 0 4216 #define SQLITE_FAULTINJECTOR_MALLOC 0
3907 #define SQLITE_FAULTINJECTOR_COUNT 1 4217 #define SQLITE_FAULTINJECTOR_COUNT 1
3908 4218
3909 /* 4219 /*
3910 ** The interface to the code in fault.c used for identifying "benign" 4220 ** The interface to the code in fault.c used for identifying "benign"
3911 ** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST 4221 ** malloc failures. This is only present if SQLITE_UNTESTABLE
3912 ** is not defined. 4222 ** is not defined.
3913 */ 4223 */
3914 #ifndef SQLITE_OMIT_BUILTIN_TEST 4224 #ifndef SQLITE_UNTESTABLE
3915 void sqlite3BeginBenignMalloc(void); 4225 void sqlite3BeginBenignMalloc(void);
3916 void sqlite3EndBenignMalloc(void); 4226 void sqlite3EndBenignMalloc(void);
3917 #else 4227 #else
3918 #define sqlite3BeginBenignMalloc() 4228 #define sqlite3BeginBenignMalloc()
3919 #define sqlite3EndBenignMalloc() 4229 #define sqlite3EndBenignMalloc()
3920 #endif 4230 #endif
3921 4231
3922 /* 4232 /*
3923 ** Allowed return values from sqlite3FindInIndex() 4233 ** Allowed return values from sqlite3FindInIndex()
3924 */ 4234 */
3925 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */ 4235 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */
3926 #define IN_INDEX_EPH 2 /* Search an ephemeral b-tree */ 4236 #define IN_INDEX_EPH 2 /* Search an ephemeral b-tree */
3927 #define IN_INDEX_INDEX_ASC 3 /* Existing index ASCENDING */ 4237 #define IN_INDEX_INDEX_ASC 3 /* Existing index ASCENDING */
3928 #define IN_INDEX_INDEX_DESC 4 /* Existing index DESCENDING */ 4238 #define IN_INDEX_INDEX_DESC 4 /* Existing index DESCENDING */
3929 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */ 4239 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */
3930 /* 4240 /*
3931 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex(). 4241 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
3932 */ 4242 */
3933 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */ 4243 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
3934 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */ 4244 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
3935 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */ 4245 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
3936 int sqlite3FindInIndex(Parse *, Expr *, u32, int*); 4246 int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
3937 4247
4248 int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
4249 int sqlite3JournalSize(sqlite3_vfs *);
3938 #ifdef SQLITE_ENABLE_ATOMIC_WRITE 4250 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
3939 int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
3940 int sqlite3JournalSize(sqlite3_vfs *);
3941 int sqlite3JournalCreate(sqlite3_file *); 4251 int sqlite3JournalCreate(sqlite3_file *);
3942 int sqlite3JournalExists(sqlite3_file *p);
3943 #else
3944 #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
3945 #define sqlite3JournalExists(p) 1
3946 #endif 4252 #endif
3947 4253
4254 int sqlite3JournalIsInMemory(sqlite3_file *p);
3948 void sqlite3MemJournalOpen(sqlite3_file *); 4255 void sqlite3MemJournalOpen(sqlite3_file *);
3949 int sqlite3MemJournalSize(void);
3950 int sqlite3IsMemJournal(sqlite3_file *);
3951 4256
3952 void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p); 4257 void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p);
3953 #if SQLITE_MAX_EXPR_DEPTH>0 4258 #if SQLITE_MAX_EXPR_DEPTH>0
3954 int sqlite3SelectExprHeight(Select *); 4259 int sqlite3SelectExprHeight(Select *);
3955 int sqlite3ExprCheckHeight(Parse*, int); 4260 int sqlite3ExprCheckHeight(Parse*, int);
3956 #else 4261 #else
3957 #define sqlite3SelectExprHeight(x) 0 4262 #define sqlite3SelectExprHeight(x) 0
3958 #define sqlite3ExprCheckHeight(x,y) 4263 #define sqlite3ExprCheckHeight(x,y)
3959 #endif 4264 #endif
3960 4265
(...skipping 10 matching lines...) Expand all
3971 #define sqlite3ConnectionClosed(x) 4276 #define sqlite3ConnectionClosed(x)
3972 #endif 4277 #endif
3973 4278
3974 #ifdef SQLITE_DEBUG 4279 #ifdef SQLITE_DEBUG
3975 void sqlite3ParserTrace(FILE*, char *); 4280 void sqlite3ParserTrace(FILE*, char *);
3976 #endif 4281 #endif
3977 4282
3978 /* 4283 /*
3979 ** If the SQLITE_ENABLE IOTRACE exists then the global variable 4284 ** If the SQLITE_ENABLE IOTRACE exists then the global variable
3980 ** sqlite3IoTrace is a pointer to a printf-like routine used to 4285 ** sqlite3IoTrace is a pointer to a printf-like routine used to
3981 ** print I/O tracing messages. 4286 ** print I/O tracing messages.
3982 */ 4287 */
3983 #ifdef SQLITE_ENABLE_IOTRACE 4288 #ifdef SQLITE_ENABLE_IOTRACE
3984 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } 4289 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
3985 void sqlite3VdbeIOTraceSql(Vdbe*); 4290 void sqlite3VdbeIOTraceSql(Vdbe*);
3986 SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); 4291 SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...);
3987 #else 4292 #else
3988 # define IOTRACE(A) 4293 # define IOTRACE(A)
3989 # define sqlite3VdbeIOTraceSql(X) 4294 # define sqlite3VdbeIOTraceSql(X)
3990 #endif 4295 #endif
3991 4296
(...skipping 13 matching lines...) Expand all
4005 ** sqlite3MemdebugNoType() returns true if none of the bits in its second 4310 ** sqlite3MemdebugNoType() returns true if none of the bits in its second
4006 ** argument match the type set by the previous sqlite3MemdebugSetType(). 4311 ** argument match the type set by the previous sqlite3MemdebugSetType().
4007 ** 4312 **
4008 ** Perhaps the most important point is the difference between MEMTYPE_HEAP 4313 ** Perhaps the most important point is the difference between MEMTYPE_HEAP
4009 ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means 4314 ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
4010 ** it might have been allocated by lookaside, except the allocation was 4315 ** it might have been allocated by lookaside, except the allocation was
4011 ** too large or lookaside was already full. It is important to verify 4316 ** too large or lookaside was already full. It is important to verify
4012 ** that allocations that might have been satisfied by lookaside are not 4317 ** that allocations that might have been satisfied by lookaside are not
4013 ** passed back to non-lookaside free() routines. Asserts such as the 4318 ** passed back to non-lookaside free() routines. Asserts such as the
4014 ** example above are placed on the non-lookaside free() routines to verify 4319 ** example above are placed on the non-lookaside free() routines to verify
4015 ** this constraint. 4320 ** this constraint.
4016 ** 4321 **
4017 ** All of this is no-op for a production build. It only comes into 4322 ** All of this is no-op for a production build. It only comes into
4018 ** play when the SQLITE_MEMDEBUG compile-time option is used. 4323 ** play when the SQLITE_MEMDEBUG compile-time option is used.
4019 */ 4324 */
4020 #ifdef SQLITE_MEMDEBUG 4325 #ifdef SQLITE_MEMDEBUG
4021 void sqlite3MemdebugSetType(void*,u8); 4326 void sqlite3MemdebugSetType(void*,u8);
4022 int sqlite3MemdebugHasType(void*,u8); 4327 int sqlite3MemdebugHasType(void*,u8);
4023 int sqlite3MemdebugNoType(void*,u8); 4328 int sqlite3MemdebugNoType(void*,u8);
4024 #else 4329 #else
4025 # define sqlite3MemdebugSetType(X,Y) /* no-op */ 4330 # define sqlite3MemdebugSetType(X,Y) /* no-op */
(...skipping 10 matching lines...) Expand all
4036 */ 4341 */
4037 #if SQLITE_MAX_WORKER_THREADS>0 4342 #if SQLITE_MAX_WORKER_THREADS>0
4038 int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*); 4343 int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
4039 int sqlite3ThreadJoin(SQLiteThread*, void**); 4344 int sqlite3ThreadJoin(SQLiteThread*, void**);
4040 #endif 4345 #endif
4041 4346
4042 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST) 4347 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
4043 int sqlite3DbstatRegister(sqlite3*); 4348 int sqlite3DbstatRegister(sqlite3*);
4044 #endif 4349 #endif
4045 4350
4046 #endif /* _SQLITEINT_H_ */ 4351 int sqlite3ExprVectorSize(Expr *pExpr);
4352 int sqlite3ExprIsVector(Expr *pExpr);
4353 Expr *sqlite3VectorFieldSubexpr(Expr*, int);
4354 Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
4355 void sqlite3VectorErrorMsg(Parse*, Expr*);
4356
4357 #endif /* SQLITEINT_H */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/sqlite3ext.h ('k') | third_party/sqlite/src/src/sqliteLimit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698