0000: 2f 2a 0a 2a 2a 20 32 30 30 31 20 53 65 70 74 65 /*.** 2001 Septe
0010: 6d 62 65 72 20 31 35 0a 2a 2a 0a 2a 2a 20 54 68 mber 15.**.** Th
0020: 65 20 61 75 74 68 6f 72 20 64 69 73 63 6c 61 69 e author disclai
0030: 6d 73 20 63 6f 70 79 72 69 67 68 74 20 74 6f 20 ms copyright to
0040: 74 68 69 73 20 73 6f 75 72 63 65 20 63 6f 64 65 this source code
0050: 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f 66 0a 2a . In place of.*
0060: 2a 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69 63 65 * a legal notice
0070: 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c 65 73 , here is a bles
0080: 73 69 6e 67 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 4d sing:.**.** M
0090: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61 ay you do good a
00a0: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 2a 2a 20 nd not evil..**
00b0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 May you find
00c0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 forgiveness for
00d0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 yourself and for
00e0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 2a 2a 20 give others..**
00f0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 May you share
0100: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 freely, never t
0110: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 aking more than
0120: 79 6f 75 20 67 69 76 65 2e 0a 2a 2a 0a 2a 2a 2a you give..**.***
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 2a 2a 2a 2a 0a 2a 2a 20 49 6e 74 65 72 6e ******.** Intern
0180: 61 6c 20 69 6e 74 65 72 66 61 63 65 20 64 65 66 al interface def
0190: 69 6e 69 74 69 6f 6e 73 20 66 6f 72 20 53 51 4c initions for SQL
01a0: 69 74 65 2e 0a 2a 2a 0a 2a 2f 0a 23 69 66 6e 64 ite..**.*/.#ifnd
01b0: 65 66 20 5f 53 51 4c 49 54 45 49 4e 54 5f 48 5f ef _SQLITEINT_H_
01c0: 0a 23 64 65 66 69 6e 65 20 5f 53 51 4c 49 54 45 .#define _SQLITE
01d0: 49 4e 54 5f 48 5f 0a 0a 2f 2a 0a 2a 2a 20 49 6e INT_H_../*.** In
01e0: 63 6c 75 64 65 20 74 68 65 20 68 65 61 64 65 72 clude the header
01f0: 20 66 69 6c 65 20 75 73 65 64 20 74 6f 20 63 75 file used to cu
0200: 73 74 6f 6d 69 7a 65 20 74 68 65 20 63 6f 6d 70 stomize the comp
0210: 69 6c 65 72 20 6f 70 74 69 6f 6e 73 20 66 6f 72 iler options for
0220: 20 4d 53 56 43 2e 0a 2a 2a 20 54 68 69 73 20 73 MSVC..** This s
0230: 68 6f 75 6c 64 20 62 65 20 64 6f 6e 65 20 66 69 hould be done fi
0240: 72 73 74 20 73 6f 20 74 68 61 74 20 69 74 20 63 rst so that it c
0250: 61 6e 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 an successfully
0260: 70 72 65 76 65 6e 74 20 73 70 75 72 69 6f 75 73 prevent spurious
0270: 0a 2a 2a 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 .** compiler war
0280: 6e 69 6e 67 73 20 64 75 65 20 74 6f 20 73 75 62 nings due to sub
0290: 73 65 71 75 65 6e 74 20 63 6f 6e 74 65 6e 74 20 sequent content
02a0: 69 6e 20 74 68 69 73 20 66 69 6c 65 20 61 6e 64 in this file and
02b0: 20 6f 74 68 65 72 20 66 69 6c 65 73 0a 2a 2a 20 other files.**
02c0: 74 68 61 74 20 61 72 65 20 69 6e 63 6c 75 64 65 that are include
02d0: 64 20 62 79 20 74 68 69 73 20 66 69 6c 65 2e 0a d by this file..
02e0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 6d 73 76 */.#include "msv
02f0: 63 2e 68 22 0a 0a 2f 2a 0a 2a 2a 20 53 70 65 63 c.h"../*.** Spec
0300: 69 61 6c 20 73 65 74 75 70 20 66 6f 72 20 56 78 ial setup for Vx
0310: 57 6f 72 6b 73 0a 2a 2f 0a 23 69 6e 63 6c 75 64 Works.*/.#includ
0320: 65 20 22 76 78 77 6f 72 6b 73 2e 68 22 0a 0a 2f e "vxworks.h"../
0330: 2a 0a 2a 2a 20 54 68 65 73 65 20 23 64 65 66 69 *.** These #defi
0340: 6e 65 73 20 73 68 6f 75 6c 64 20 65 6e 61 62 6c nes should enabl
0350: 65 20 3e 32 47 42 20 66 69 6c 65 20 73 75 70 70 e >2GB file supp
0360: 6f 72 74 20 6f 6e 20 50 4f 53 49 58 20 69 66 20 ort on POSIX if
0370: 74 68 65 0a 2a 2a 20 75 6e 64 65 72 6c 79 69 6e the.** underlyin
0380: 67 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 g operating syst
0390: 65 6d 20 73 75 70 70 6f 72 74 73 20 69 74 2e 20 em supports it.
03a0: 20 49 66 20 74 68 65 20 4f 53 20 6c 61 63 6b 73 If the OS lacks
03b0: 0a 2a 2a 20 6c 61 72 67 65 20 66 69 6c 65 20 73 .** large file s
03c0: 75 70 70 6f 72 74 2c 20 6f 72 20 69 66 20 74 68 upport, or if th
03d0: 65 20 4f 53 20 69 73 20 77 69 6e 64 6f 77 73 2c e OS is windows,
03e0: 20 74 68 65 73 65 20 73 68 6f 75 6c 64 20 62 65 these should be
03f0: 20 6e 6f 2d 6f 70 73 2e 0a 2a 2a 0a 2a 2a 20 54 no-ops..**.** T
0400: 69 63 6b 65 74 20 23 32 37 33 39 3a 20 20 54 68 icket #2739: Th
0410: 65 20 5f 4c 41 52 47 45 46 49 4c 45 5f 53 4f 55 e _LARGEFILE_SOU
0420: 52 43 45 20 6d 61 63 72 6f 20 6d 75 73 74 20 61 RCE macro must a
0430: 70 70 65 61 72 20 62 65 66 6f 72 65 20 61 6e 79 ppear before any
0440: 0a 2a 2a 20 73 79 73 74 65 6d 20 23 69 6e 63 6c .** system #incl
0450: 75 64 65 73 2e 20 20 48 65 6e 63 65 2c 20 74 68 udes. Hence, th
0460: 69 73 20 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 is block of code
0470: 20 6d 75 73 74 20 62 65 20 74 68 65 20 76 65 72 must be the ver
0480: 79 20 66 69 72 73 74 0a 2a 2a 20 63 6f 64 65 20 y first.** code
0490: 69 6e 20 61 6c 6c 20 73 6f 75 72 63 65 20 66 69 in all source fi
04a0: 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 4c 61 72 67 65 les..**.** Large
04b0: 20 66 69 6c 65 20 73 75 70 70 6f 72 74 20 63 61 file support ca
04c0: 6e 20 62 65 20 64 69 73 61 62 6c 65 64 20 75 73 n be disabled us
04d0: 69 6e 67 20 74 68 65 20 2d 44 53 51 4c 49 54 45 ing the -DSQLITE
04e0: 5f 44 49 53 41 42 4c 45 5f 4c 46 53 20 73 77 69 _DISABLE_LFS swi
04f0: 74 63 68 0a 2a 2a 20 6f 6e 20 74 68 65 20 63 6f tch.** on the co
0500: 6d 70 69 6c 65 72 20 63 6f 6d 6d 61 6e 64 20 6c mpiler command l
0510: 69 6e 65 2e 20 20 54 68 69 73 20 69 73 20 6e 65 ine. This is ne
0520: 63 65 73 73 61 72 79 20 69 66 20 79 6f 75 20 61 cessary if you a
0530: 72 65 20 63 6f 6d 70 69 6c 69 6e 67 0a 2a 2a 20 re compiling.**
0540: 6f 6e 20 61 20 72 65 63 65 6e 74 20 6d 61 63 68 on a recent mach
0550: 69 6e 65 20 28 65 78 3a 20 52 65 64 20 48 61 74 ine (ex: Red Hat
0560: 20 37 2e 32 29 20 62 75 74 20 79 6f 75 20 77 61 7.2) but you wa
0570: 6e 74 20 79 6f 75 72 20 63 6f 64 65 20 74 6f 20 nt your code to
0580: 77 6f 72 6b 0a 2a 2a 20 6f 6e 20 61 6e 20 6f 6c work.** on an ol
0590: 64 65 72 20 6d 61 63 68 69 6e 65 20 28 65 78 3a der machine (ex:
05a0: 20 52 65 64 20 48 61 74 20 36 2e 30 29 2e 20 20 Red Hat 6.0).
05b0: 49 66 20 79 6f 75 20 63 6f 6d 70 69 6c 65 20 6f If you compile o
05c0: 6e 20 52 65 64 20 48 61 74 20 37 2e 32 0a 2a 2a n Red Hat 7.2.**
05d0: 20 77 69 74 68 6f 75 74 20 74 68 69 73 20 6f 70 without this op
05e0: 74 69 6f 6e 2c 20 4c 46 53 20 69 73 20 65 6e 61 tion, LFS is ena
05f0: 62 6c 65 2e 20 20 42 75 74 20 4c 46 53 20 64 6f ble. But LFS do
0600: 65 73 20 6e 6f 74 20 65 78 69 73 74 20 69 6e 20 es not exist in
0610: 74 68 65 20 6b 65 72 6e 65 6c 0a 2a 2a 20 69 6e the kernel.** in
0620: 20 52 65 64 20 48 61 74 20 36 2e 30 2c 20 73 6f Red Hat 6.0, so
0630: 20 74 68 65 20 63 6f 64 65 20 77 6f 6e 27 74 20 the code won't
0640: 77 6f 72 6b 2e 20 20 48 65 6e 63 65 2c 20 66 6f work. Hence, fo
0650: 72 20 6d 61 78 69 6d 75 6d 20 62 69 6e 61 72 79 r maximum binary
0660: 0a 2a 2a 20 70 6f 72 74 61 62 69 6c 69 74 79 20 .** portability
0670: 79 6f 75 20 73 68 6f 75 6c 64 20 6f 6d 69 74 20 you should omit
0680: 4c 46 53 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 70 LFS..**.** The p
0690: 72 65 76 69 6f 75 73 20 70 61 72 61 67 72 61 70 revious paragrap
06a0: 68 20 77 61 73 20 77 72 69 74 74 65 6e 20 69 6e h was written in
06b0: 20 32 30 30 35 2e 20 20 28 54 68 69 73 20 70 61 2005. (This pa
06c0: 72 61 67 72 61 70 68 20 69 73 20 77 72 69 74 74 ragraph is writt
06d0: 65 6e 0a 2a 2a 20 6f 6e 20 32 30 30 38 2d 31 31 en.** on 2008-11
06e0: 2d 32 38 2e 29 20 54 68 65 73 65 20 64 61 79 73 -28.) These days
06f0: 2c 20 61 6c 6c 20 4c 69 6e 75 78 20 6b 65 72 6e , all Linux kern
0700: 65 6c 73 20 73 75 70 70 6f 72 74 20 6c 61 72 67 els support larg
0710: 65 20 66 69 6c 65 73 2c 20 73 6f 0a 2a 2a 20 79 e files, so.** y
0720: 6f 75 20 73 68 6f 75 6c 64 20 70 72 6f 62 61 62 ou should probab
0730: 6c 79 20 6c 65 61 76 65 20 4c 46 53 20 65 6e 61 ly leave LFS ena
0740: 62 6c 65 64 2e 20 20 42 75 74 20 73 6f 6d 65 20 bled. But some
0750: 65 6d 62 65 64 64 65 64 20 70 6c 61 74 66 6f 72 embedded platfor
0760: 6d 73 20 6d 69 67 68 74 0a 2a 2a 20 6c 61 63 6b ms might.** lack
0770: 20 4c 46 53 20 69 6e 20 77 68 69 63 68 20 63 61 LFS in which ca
0780: 73 65 20 74 68 65 20 53 51 4c 49 54 45 5f 44 49 se the SQLITE_DI
0790: 53 41 42 4c 45 5f 4c 46 53 20 6d 61 63 72 6f 20 SABLE_LFS macro
07a0: 6d 69 67 68 74 20 73 74 69 6c 6c 20 62 65 20 75 might still be u
07b0: 73 65 66 75 6c 2e 0a 2a 2a 0a 2a 2a 20 53 69 6d seful..**.** Sim
07c0: 69 6c 61 72 20 69 73 20 74 72 75 65 20 66 6f 72 ilar is true for
07d0: 20 4d 61 63 20 4f 53 20 58 2e 20 20 4c 46 53 20 Mac OS X. LFS
07e0: 69 73 20 6f 6e 6c 79 20 73 75 70 70 6f 72 74 65 is only supporte
07f0: 64 20 6f 6e 20 4d 61 63 20 4f 53 20 58 20 39 20 d on Mac OS X 9
0800: 61 6e 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 23 69 and later..*/.#i
0810: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 49 53 fndef SQLITE_DIS
0820: 41 42 4c 45 5f 4c 46 53 0a 23 20 64 65 66 69 6e ABLE_LFS.# defin
0830: 65 20 5f 4c 41 52 47 45 5f 46 49 4c 45 20 20 20 e _LARGE_FILE
0840: 20 20 20 20 31 0a 23 20 69 66 6e 64 65 66 20 5f 1.# ifndef _
0850: 46 49 4c 45 5f 4f 46 46 53 45 54 5f 42 49 54 53 FILE_OFFSET_BITS
0860: 0a 23 20 20 20 64 65 66 69 6e 65 20 5f 46 49 4c .# define _FIL
0870: 45 5f 4f 46 46 53 45 54 5f 42 49 54 53 20 36 34 E_OFFSET_BITS 64
0880: 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 66 69 6e .# endif.# defin
0890: 65 20 5f 4c 41 52 47 45 46 49 4c 45 5f 53 4f 55 e _LARGEFILE_SOU
08a0: 52 43 45 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a RCE 1.#endif../*
08b0: 20 57 68 61 74 20 76 65 72 73 69 6f 6e 20 6f 66 What version of
08c0: 20 47 43 43 20 69 73 20 62 65 69 6e 67 20 75 73 GCC is being us
08d0: 65 64 2e 20 20 30 20 6d 65 61 6e 73 20 47 43 43 ed. 0 means GCC
08e0: 20 69 73 20 6e 6f 74 20 62 65 69 6e 67 20 75 73 is not being us
08f0: 65 64 20 2a 2f 0a 23 69 66 64 65 66 20 5f 5f 47 ed */.#ifdef __G
0900: 4e 55 43 5f 5f 0a 23 20 64 65 66 69 6e 65 20 47 NUC__.# define G
0910: 43 43 5f 56 45 52 53 49 4f 4e 20 28 5f 5f 47 4e CC_VERSION (__GN
0920: 55 43 5f 5f 2a 31 30 30 30 30 30 30 2b 5f 5f 47 UC__*1000000+__G
0930: 4e 55 43 5f 4d 49 4e 4f 52 5f 5f 2a 31 30 30 30 NUC_MINOR__*1000
0940: 2b 5f 5f 47 4e 55 43 5f 50 41 54 43 48 4c 45 56 +__GNUC_PATCHLEV
0950: 45 4c 5f 5f 29 0a 23 65 6c 73 65 0a 23 20 64 65 EL__).#else.# de
0960: 66 69 6e 65 20 47 43 43 5f 56 45 52 53 49 4f 4e fine GCC_VERSION
0970: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 4e 65 0.#endif../* Ne
0980: 65 64 65 64 20 66 6f 72 20 76 61 72 69 6f 75 73 eded for various
0990: 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e 2e 2e 20 definitions...
09a0: 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f */.#if defined(_
09b0: 5f 47 4e 55 43 5f 5f 29 20 26 26 20 21 64 65 66 _GNUC__) && !def
09c0: 69 6e 65 64 28 5f 47 4e 55 5f 53 4f 55 52 43 45 ined(_GNU_SOURCE
09d0: 29 0a 23 20 64 65 66 69 6e 65 20 5f 47 4e 55 5f ).# define _GNU_
09e0: 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a 23 SOURCE.#endif..#
09f0: 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 65 if defined(__Ope
0a00: 6e 42 53 44 5f 5f 29 20 26 26 20 21 64 65 66 69 nBSD__) && !defi
0a10: 6e 65 64 28 5f 42 53 44 5f 53 4f 55 52 43 45 29 ned(_BSD_SOURCE)
0a20: 0a 23 20 64 65 66 69 6e 65 20 5f 42 53 44 5f 53 .# define _BSD_S
0a30: 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a OURCE.#endif../*
0a40: 0a 2a 2a 20 46 6f 72 20 4d 69 6e 47 57 2c 20 63 .** For MinGW, c
0a50: 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 77 heck to see if w
0a60: 65 20 63 61 6e 20 69 6e 63 6c 75 64 65 20 74 68 e can include th
0a70: 65 20 68 65 61 64 65 72 20 66 69 6c 65 20 63 6f e header file co
0a80: 6e 74 61 69 6e 69 6e 67 20 69 74 73 0a 2a 2a 20 ntaining its.**
0a90: 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 version informat
0aa0: 69 6f 6e 2c 20 61 6d 6f 6e 67 20 6f 74 68 65 72 ion, among other
0ab0: 20 74 68 69 6e 67 73 2e 20 20 4e 6f 72 6d 61 6c things. Normal
0ac0: 6c 79 2c 20 74 68 69 73 20 69 6e 74 65 72 6e 61 ly, this interna
0ad0: 6c 20 4d 69 6e 47 57 0a 2a 2a 20 68 65 61 64 65 l MinGW.** heade
0ae0: 72 20 66 69 6c 65 20 77 6f 75 6c 64 20 5b 6f 6e r file would [on
0af0: 6c 79 5d 20 62 65 20 69 6e 63 6c 75 64 65 64 20 ly] be included
0b00: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 62 79 automatically by
0b10: 20 6f 74 68 65 72 20 4d 69 6e 47 57 20 68 65 61 other MinGW hea
0b20: 64 65 72 0a 2a 2a 20 66 69 6c 65 73 3b 20 68 6f der.** files; ho
0b30: 77 65 76 65 72 2c 20 74 68 65 20 63 6f 6e 74 61 wever, the conta
0b40: 69 6e 65 64 20 76 65 72 73 69 6f 6e 20 69 6e 66 ined version inf
0b50: 6f 72 6d 61 74 69 6f 6e 20 69 73 20 6e 6f 77 20 ormation is now
0b60: 72 65 71 75 69 72 65 64 20 62 79 20 74 68 69 73 required by this
0b70: 0a 2a 2a 20 68 65 61 64 65 72 20 66 69 6c 65 20 .** header file
0b80: 74 6f 20 77 6f 72 6b 20 61 72 6f 75 6e 64 20 62 to work around b
0b90: 69 6e 61 72 79 20 63 6f 6d 70 61 74 69 62 69 6c inary compatibil
0ba0: 69 74 79 20 69 73 73 75 65 73 20 28 73 65 65 20 ity issues (see
0bb0: 62 65 6c 6f 77 29 20 61 6e 64 0a 2a 2a 20 74 68 below) and.** th
0bc0: 69 73 20 69 73 20 74 68 65 20 6f 6e 6c 79 20 6b is is the only k
0bd0: 6e 6f 77 6e 20 77 61 79 20 74 6f 20 72 65 6c 69 nown way to reli
0be0: 61 62 6c 79 20 6f 62 74 61 69 6e 20 69 74 2e 20 ably obtain it.
0bf0: 20 54 68 69 73 20 65 6e 74 69 72 65 20 23 69 66 This entire #if
0c00: 20 62 6c 6f 63 6b 0a 2a 2a 20 77 6f 75 6c 64 20 block.** would
0c10: 62 65 20 63 6f 6d 70 6c 65 74 65 6c 79 20 75 6e be completely un
0c20: 6e 65 63 65 73 73 61 72 79 20 69 66 20 74 68 65 necessary if the
0c30: 72 65 20 77 61 73 20 61 6e 79 20 6f 74 68 65 72 re was any other
0c40: 20 77 61 79 20 6f 66 20 64 65 74 65 63 74 69 6e way of detectin
0c50: 67 0a 2a 2a 20 4d 69 6e 47 57 20 76 69 61 20 74 g.** MinGW via t
0c60: 68 65 69 72 20 70 72 65 70 72 6f 63 65 73 73 6f heir preprocesso
0c70: 72 20 28 65 2e 67 2e 20 69 66 20 74 68 65 79 20 r (e.g. if they
0c80: 63 75 73 74 6f 6d 69 7a 65 64 20 74 68 65 69 72 customized their
0c90: 20 47 43 43 20 74 6f 20 64 65 66 69 6e 65 0a 2a GCC to define.*
0ca0: 2a 20 73 6f 6d 65 20 4d 69 6e 47 57 2d 73 70 65 * some MinGW-spe
0cb0: 63 69 66 69 63 20 6d 61 63 72 6f 73 29 2e 20 20 cific macros).
0cc0: 57 68 65 6e 20 63 6f 6d 70 69 6c 69 6e 67 20 66 When compiling f
0cd0: 6f 72 20 4d 69 6e 47 57 2c 20 65 69 74 68 65 72 or MinGW, either
0ce0: 20 74 68 65 0a 2a 2a 20 5f 48 41 56 45 5f 4d 49 the.** _HAVE_MI
0cf0: 4e 47 57 5f 48 20 6f 72 20 5f 48 41 56 45 5f 5f NGW_H or _HAVE__
0d00: 4d 49 4e 47 57 5f 48 20 28 6e 6f 74 65 20 74 68 MINGW_H (note th
0d10: 65 20 65 78 74 72 61 20 75 6e 64 65 72 73 63 6f e extra undersco
0d20: 72 65 29 20 6d 61 63 72 6f 20 6d 75 73 74 20 62 re) macro must b
0d30: 65 0a 2a 2a 20 64 65 66 69 6e 65 64 3b 20 6f 74 e.** defined; ot
0d40: 68 65 72 77 69 73 65 2c 20 64 65 74 65 63 74 69 herwise, detecti
0d50: 6f 6e 20 6f 66 20 63 6f 6e 64 69 74 69 6f 6e 73 on of conditions
0d60: 20 73 70 65 63 69 66 69 63 20 74 6f 20 4d 69 6e specific to Min
0d70: 47 57 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 64 69 GW will be.** di
0d80: 73 61 62 6c 65 64 2e 0a 2a 2f 0a 23 69 66 20 64 sabled..*/.#if d
0d90: 65 66 69 6e 65 64 28 5f 48 41 56 45 5f 4d 49 4e efined(_HAVE_MIN
0da0: 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 64 65 20 GW_H).# include
0db0: 22 6d 69 6e 67 77 2e 68 22 0a 23 65 6c 69 66 20 "mingw.h".#elif
0dc0: 64 65 66 69 6e 65 64 28 5f 48 41 56 45 5f 5f 4d defined(_HAVE__M
0dd0: 49 4e 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 64 INGW_H).# includ
0de0: 65 20 22 5f 6d 69 6e 67 77 2e 68 22 0a 23 65 6e e "_mingw.h".#en
0df0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 20 4d dif../*.** For M
0e00: 69 6e 47 57 20 76 65 72 73 69 6f 6e 20 34 2e 78 inGW version 4.x
0e10: 20 28 61 6e 64 20 68 69 67 68 65 72 29 2c 20 63 (and higher), c
0e20: 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 heck to see if t
0e30: 68 65 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 he _USE_32BIT_TI
0e40: 4d 45 5f 54 0a 2a 2a 20 64 65 66 69 6e 65 20 69 ME_T.** define i
0e50: 73 20 72 65 71 75 69 72 65 64 20 74 6f 20 6d 61 s required to ma
0e60: 69 6e 74 61 69 6e 20 62 69 6e 61 72 79 20 63 6f intain binary co
0e70: 6d 70 61 74 69 62 69 6c 69 74 79 20 77 69 74 68 mpatibility with
0e80: 20 74 68 65 20 4d 53 56 43 20 72 75 6e 74 69 6d the MSVC runtim
0e90: 65 0a 2a 2a 20 6c 69 62 72 61 72 79 20 69 6e 20 e.** library in
0ea0: 75 73 65 20 28 65 2e 67 2e 20 66 6f 72 20 57 69 use (e.g. for Wi
0eb0: 6e 64 6f 77 73 20 58 50 29 2e 0a 2a 2f 0a 23 69 ndows XP)..*/.#i
0ec0: 66 20 21 64 65 66 69 6e 65 64 28 5f 55 53 45 5f f !defined(_USE_
0ed0: 33 32 42 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 32BIT_TIME_T) &&
0ee0: 20 21 64 65 66 69 6e 65 64 28 5f 55 53 45 5f 36 !defined(_USE_6
0ef0: 34 42 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 20 4BIT_TIME_T) &&
0f00: 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 5f 57 \. defined(_W
0f10: 49 4e 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 IN32) && !define
0f20: 64 28 5f 57 49 4e 36 34 29 20 26 26 20 5c 0a 20 d(_WIN64) && \.
0f30: 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 4d 49 4e defined(__MIN
0f40: 47 57 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e GW_MAJOR_VERSION
0f50: 29 20 26 26 20 5f 5f 4d 49 4e 47 57 5f 4d 41 4a ) && __MINGW_MAJ
0f60: 4f 52 5f 56 45 52 53 49 4f 4e 20 3e 3d 20 34 20 OR_VERSION >= 4
0f70: 26 26 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 && \. defined
0f80: 28 5f 5f 4d 53 56 43 52 54 5f 5f 29 0a 23 20 64 (__MSVCRT__).# d
0f90: 65 66 69 6e 65 20 5f 55 53 45 5f 33 32 42 49 54 efine _USE_32BIT
0fa0: 5f 54 49 4d 45 5f 54 0a 23 65 6e 64 69 66 0a 0a _TIME_T.#endif..
0fb0: 2f 2a 20 54 68 65 20 70 75 62 6c 69 63 20 53 51 /* The public SQ
0fc0: 4c 69 74 65 20 69 6e 74 65 72 66 61 63 65 2e 20 Lite interface.
0fd0: 20 54 68 65 20 5f 46 49 4c 45 5f 4f 46 46 53 45 The _FILE_OFFSE
0fe0: 54 5f 42 49 54 53 20 6d 61 63 72 6f 20 6d 75 73 T_BITS macro mus
0ff0: 74 20 61 70 70 65 61 72 0a 2a 2a 20 66 69 72 73 t appear.** firs
1000: 74 20 69 6e 20 51 4e 58 2e 20 20 41 6c 73 6f 2c t in QNX. Also,
1010: 20 74 68 65 20 5f 55 53 45 5f 33 32 42 49 54 5f the _USE_32BIT_
1020: 54 49 4d 45 5f 54 20 6d 61 63 72 6f 20 6d 75 73 TIME_T macro mus
1030: 74 20 61 70 70 65 61 72 20 66 69 72 73 74 20 66 t appear first f
1040: 6f 72 0a 2a 2a 20 4d 69 6e 47 57 2e 0a 2a 2f 0a or.** MinGW..*/.
1050: 23 69 6e 63 6c 75 64 65 20 22 73 71 6c 69 74 65 #include "sqlite
1060: 33 2e 68 22 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 3.h"../*.** Incl
1070: 75 64 65 20 74 68 65 20 63 6f 6e 66 69 67 75 72 ude the configur
1080: 61 74 69 6f 6e 20 68 65 61 64 65 72 20 6f 75 74 ation header out
1090: 70 75 74 20 62 79 20 27 63 6f 6e 66 69 67 75 72 put by 'configur
10a0: 65 27 20 69 66 20 77 65 27 72 65 20 75 73 69 6e e' if we're usin
10b0: 67 20 74 68 65 0a 2a 2a 20 61 75 74 6f 63 6f 6e g the.** autocon
10c0: 66 2d 62 61 73 65 64 20 62 75 69 6c 64 0a 2a 2f f-based build.*/
10d0: 0a 23 69 66 64 65 66 20 5f 48 41 56 45 5f 53 51 .#ifdef _HAVE_SQ
10e0: 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 48 0a 23 69 LITE_CONFIG_H.#i
10f0: 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 nclude "config.h
1100: 22 0a 23 65 6e 64 69 66 0a 0a 23 69 6e 63 6c 75 ".#endif..#inclu
1110: 64 65 20 22 73 71 6c 69 74 65 4c 69 6d 69 74 2e de "sqliteLimit.
1120: 68 22 0a 0a 2f 2a 20 44 69 73 61 62 6c 65 20 6e h"../* Disable n
1130: 75 69 73 61 6e 63 65 20 77 61 72 6e 69 6e 67 73 uisance warnings
1140: 20 6f 6e 20 42 6f 72 6c 61 6e 64 20 63 6f 6d 70 on Borland comp
1150: 69 6c 65 72 73 20 2a 2f 0a 23 69 66 20 64 65 66 ilers */.#if def
1160: 69 6e 65 64 28 5f 5f 42 4f 52 4c 41 4e 44 43 5f ined(__BORLANDC_
1170: 5f 29 0a 23 70 72 61 67 6d 61 20 77 61 72 6e 20 _).#pragma warn
1180: 2d 72 63 68 20 2f 2a 20 75 6e 72 65 61 63 68 61 -rch /* unreacha
1190: 62 6c 65 20 63 6f 64 65 20 2a 2f 0a 23 70 72 61 ble code */.#pra
11a0: 67 6d 61 20 77 61 72 6e 20 2d 63 63 63 20 2f 2a gma warn -ccc /*
11b0: 20 43 6f 6e 64 69 74 69 6f 6e 20 69 73 20 61 6c Condition is al
11c0: 77 61 79 73 20 74 72 75 65 20 6f 72 20 66 61 6c ways true or fal
11d0: 73 65 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 se */.#pragma wa
11e0: 72 6e 20 2d 61 75 73 20 2f 2a 20 41 73 73 69 67 rn -aus /* Assig
11f0: 6e 65 64 20 76 61 6c 75 65 20 69 73 20 6e 65 76 ned value is nev
1200: 65 72 20 75 73 65 64 20 2a 2f 0a 23 70 72 61 67 er used */.#prag
1210: 6d 61 20 77 61 72 6e 20 2d 63 73 75 20 2f 2a 20 ma warn -csu /*
1220: 43 6f 6d 70 61 72 69 6e 67 20 73 69 67 6e 65 64 Comparing signed
1230: 20 61 6e 64 20 75 6e 73 69 67 6e 65 64 20 2a 2f and unsigned */
1240: 0a 23 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 73 .#pragma warn -s
1250: 70 61 20 2f 2a 20 53 75 73 70 69 63 69 6f 75 73 pa /* Suspicious
1260: 20 70 6f 69 6e 74 65 72 20 61 72 69 74 68 6d 65 pointer arithme
1270: 74 69 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f tic */.#endif../
1280: 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 73 74 61 *.** Include sta
1290: 6e 64 61 72 64 20 68 65 61 64 65 72 20 66 69 6c ndard header fil
12a0: 65 73 20 61 73 20 6e 65 63 65 73 73 61 72 79 0a es as necessary.
12b0: 2a 2f 0a 23 69 66 64 65 66 20 48 41 56 45 5f 53 */.#ifdef HAVE_S
12c0: 54 44 49 4e 54 5f 48 0a 23 69 6e 63 6c 75 64 65 TDINT_H.#include
12d0: 20 3c 73 74 64 69 6e 74 2e 68 3e 0a 23 65 6e 64 <stdint.h>.#end
12e0: 69 66 0a 23 69 66 64 65 66 20 48 41 56 45 5f 49 if.#ifdef HAVE_I
12f0: 4e 54 54 59 50 45 53 5f 48 0a 23 69 6e 63 6c 75 NTTYPES_H.#inclu
1300: 64 65 20 3c 69 6e 74 74 79 70 65 73 2e 68 3e 0a de <inttypes.h>.
1310: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 #endif../*.** Th
1320: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 e following macr
1330: 6f 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 63 os are used to c
1340: 61 73 74 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 ast pointers to
1350: 69 6e 74 65 67 65 72 73 20 61 6e 64 0a 2a 2a 20 integers and.**
1360: 69 6e 74 65 67 65 72 73 20 74 6f 20 70 6f 69 6e integers to poin
1370: 74 65 72 73 2e 20 20 54 68 65 20 77 61 79 20 79 ters. The way y
1380: 6f 75 20 64 6f 20 74 68 69 73 20 76 61 72 69 65 ou do this varie
1390: 73 20 66 72 6f 6d 20 6f 6e 65 20 63 6f 6d 70 69 s from one compi
13a0: 6c 65 72 0a 2a 2a 20 74 6f 20 74 68 65 20 6e 65 ler.** to the ne
13b0: 78 74 2c 20 73 6f 20 77 65 20 68 61 76 65 20 64 xt, so we have d
13c0: 65 76 65 6c 6f 70 65 64 20 74 68 65 20 66 6f 6c eveloped the fol
13d0: 6c 6f 77 69 6e 67 20 73 65 74 20 6f 66 20 23 69 lowing set of #i
13e0: 66 20 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a 20 f statements.**
13f0: 74 6f 20 67 65 6e 65 72 61 74 65 20 61 70 70 72 to generate appr
1400: 6f 70 72 69 61 74 65 20 6d 61 63 72 6f 73 20 66 opriate macros f
1410: 6f 72 20 61 20 77 69 64 65 20 72 61 6e 67 65 20 or a wide range
1420: 6f 66 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a 2a of compilers..**
1430: 0a 2a 2a 20 54 68 65 20 63 6f 72 72 65 63 74 20 .** The correct
1440: 22 41 4e 53 49 22 20 77 61 79 20 74 6f 20 64 6f "ANSI" way to do
1450: 20 74 68 69 73 20 69 73 20 74 6f 20 75 73 65 20 this is to use
1460: 74 68 65 20 69 6e 74 70 74 72 5f 74 20 74 79 70 the intptr_t typ
1470: 65 2e 20 0a 2a 2a 20 55 6e 66 6f 72 74 75 6e 61 e. .** Unfortuna
1480: 74 65 6c 79 2c 20 74 68 61 74 20 74 79 70 65 64 tely, that typed
1490: 65 66 20 69 73 20 6e 6f 74 20 61 76 61 69 6c 61 ef is not availa
14a0: 62 6c 65 20 6f 6e 20 61 6c 6c 20 63 6f 6d 70 69 ble on all compi
14b0: 6c 65 72 73 2c 20 6f 72 0a 2a 2a 20 69 66 20 69 lers, or.** if i
14c0: 74 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2c 20 t is available,
14d0: 69 74 20 72 65 71 75 69 72 65 73 20 61 6e 20 23 it requires an #
14e0: 69 6e 63 6c 75 64 65 20 6f 66 20 73 70 65 63 69 include of speci
14f0: 66 69 63 20 68 65 61 64 65 72 73 0a 2a 2a 20 74 fic headers.** t
1500: 68 61 74 20 76 61 72 79 20 66 72 6f 6d 20 6f 6e hat vary from on
1510: 65 20 6d 61 63 68 69 6e 65 20 74 6f 20 74 68 65 e machine to the
1520: 20 6e 65 78 74 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 next..**.** Tic
1530: 6b 65 74 20 23 33 38 36 30 3a 20 20 54 68 65 20 ket #3860: The
1540: 6c 6c 76 6d 2d 67 63 63 2d 34 2e 32 20 63 6f 6d llvm-gcc-4.2 com
1550: 70 69 6c 65 72 20 66 72 6f 6d 20 41 70 70 6c 65 piler from Apple
1560: 20 63 68 6f 6b 65 73 20 6f 6e 0a 2a 2a 20 74 68 chokes on.** th
1570: 65 20 28 28 76 6f 69 64 2a 29 26 28 28 63 68 61 e ((void*)&((cha
1580: 72 2a 29 30 29 5b 58 5d 29 20 63 6f 6e 73 74 72 r*)0)[X]) constr
1590: 75 63 74 2e 20 20 42 75 74 20 4d 53 56 43 20 63 uct. But MSVC c
15a0: 68 6f 6b 65 73 20 6f 6e 20 28 28 76 6f 69 64 2a hokes on ((void*
15b0: 29 28 58 29 29 2e 0a 2a 2a 20 53 6f 20 77 65 20 )(X))..** So we
15c0: 68 61 76 65 20 74 6f 20 64 65 66 69 6e 65 20 74 have to define t
15d0: 68 65 20 6d 61 63 72 6f 73 20 69 6e 20 64 69 66 he macros in dif
15e0: 66 65 72 65 6e 74 20 77 61 79 73 20 64 65 70 65 ferent ways depe
15f0: 6e 64 69 6e 67 20 6f 6e 20 74 68 65 0a 2a 2a 20 nding on the.**
1600: 63 6f 6d 70 69 6c 65 72 2e 0a 2a 2f 0a 23 69 66 compiler..*/.#if
1610: 20 64 65 66 69 6e 65 64 28 5f 5f 50 54 52 44 49 defined(__PTRDI
1620: 46 46 5f 54 59 50 45 5f 5f 29 20 20 2f 2a 20 54 FF_TYPE__) /* T
1630: 68 69 73 20 63 61 73 65 20 73 68 6f 75 6c 64 20 his case should
1640: 77 6f 72 6b 20 66 6f 72 20 47 43 43 20 2a 2f 0a work for GCC */.
1650: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
1660: 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 INT_TO_PTR(X) (
1670: 28 76 6f 69 64 2a 29 28 5f 5f 50 54 52 44 49 46 (void*)(__PTRDIF
1680: 46 5f 54 59 50 45 5f 5f 29 28 58 29 29 0a 23 20 F_TYPE__)(X)).#
1690: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 define SQLITE_PT
16a0: 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 28 69 R_TO_INT(X) ((i
16b0: 6e 74 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 nt)(__PTRDIFF_TY
16c0: 50 45 5f 5f 29 28 58 29 29 0a 23 65 6c 69 66 20 PE__)(X)).#elif
16d0: 21 64 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 5f !defined(__GNUC_
16e0: 5f 29 20 20 20 20 20 20 20 2f 2a 20 57 6f 72 6b _) /* Work
16f0: 73 20 66 6f 72 20 63 6f 6d 70 69 6c 65 72 73 20 s for compilers
1700: 6f 74 68 65 72 20 74 68 61 6e 20 4c 4c 56 4d 20 other than LLVM
1710: 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 */.# define SQLI
1720: 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 TE_INT_TO_PTR(X)
1730: 20 20 28 28 76 6f 69 64 2a 29 26 28 28 63 68 61 ((void*)&((cha
1740: 72 2a 29 30 29 5b 58 5d 29 0a 23 20 64 65 66 69 r*)0)[X]).# defi
1750: 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f ne SQLITE_PTR_TO
1760: 5f 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 _INT(X) ((int)(
1770: 28 28 63 68 61 72 2a 29 58 29 2d 28 63 68 61 72 ((char*)X)-(char
1780: 2a 29 30 29 29 0a 23 65 6c 69 66 20 64 65 66 69 *)0)).#elif defi
1790: 6e 65 64 28 48 41 56 45 5f 53 54 44 49 4e 54 5f ned(HAVE_STDINT_
17a0: 48 29 20 20 20 2f 2a 20 55 73 65 20 74 68 69 73 H) /* Use this
17b0: 20 63 61 73 65 20 69 66 20 77 65 20 68 61 76 65 case if we have
17c0: 20 41 4e 53 49 20 68 65 61 64 65 72 73 20 2a 2f ANSI headers */
17d0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
17e0: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 _INT_TO_PTR(X)
17f0: 28 28 76 6f 69 64 2a 29 28 69 6e 74 70 74 72 5f ((void*)(intptr_
1800: 74 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 20 t)(X)).# define
1810: 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e SQLITE_PTR_TO_IN
1820: 54 28 58 29 20 20 28 28 69 6e 74 29 28 69 6e 74 T(X) ((int)(int
1830: 70 74 72 5f 74 29 28 58 29 29 0a 23 65 6c 73 65 ptr_t)(X)).#else
1840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1850: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 47 65 6e /* Gen
1860: 65 72 61 74 65 73 20 61 20 77 61 72 6e 69 6e 67 erates a warning
1870: 20 2d 20 62 75 74 20 69 74 20 61 6c 77 61 79 73 - but it always
1880: 20 77 6f 72 6b 73 20 2a 2f 0a 23 20 64 65 66 69 works */.# defi
1890: 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f ne SQLITE_INT_TO
18a0: 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 2a _PTR(X) ((void*
18b0: 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 20 53 )(X)).# define S
18c0: 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 QLITE_PTR_TO_INT
18d0: 28 58 29 20 20 28 28 69 6e 74 29 28 58 29 29 0a (X) ((int)(X)).
18e0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 20 #endif../*.** A
18f0: 6d 61 63 72 6f 20 74 6f 20 68 69 6e 74 20 74 6f macro to hint to
1900: 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 74 68 the compiler th
1910: 61 74 20 61 20 66 75 6e 63 74 69 6f 6e 20 73 68 at a function sh
1920: 6f 75 6c 64 20 6e 6f 74 20 62 65 0a 2a 2a 20 69 ould not be.** i
1930: 6e 6c 69 6e 65 64 2e 0a 2a 2f 0a 23 69 66 20 64 nlined..*/.#if d
1940: 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 efined(__GNUC__)
1950: 0a 23 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 .# define SQLIT
1960: 45 5f 4e 4f 49 4e 4c 49 4e 45 20 20 5f 5f 61 74 E_NOINLINE __at
1970: 74 72 69 62 75 74 65 5f 5f 28 28 6e 6f 69 6e 6c tribute__((noinl
1980: 69 6e 65 29 29 0a 23 65 6c 69 66 20 64 65 66 69 ine)).#elif defi
1990: 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 ned(_MSC_VER) &&
19a0: 20 5f 4d 53 43 5f 56 45 52 3e 3d 31 33 31 30 0a _MSC_VER>=1310.
19b0: 23 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 # define SQLITE
19c0: 5f 4e 4f 49 4e 4c 49 4e 45 20 20 5f 5f 64 65 63 _NOINLINE __dec
19d0: 6c 73 70 65 63 28 6e 6f 69 6e 6c 69 6e 65 29 0a lspec(noinline).
19e0: 23 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 #else.# define
19f0: 53 51 4c 49 54 45 5f 4e 4f 49 4e 4c 49 4e 45 0a SQLITE_NOINLINE.
1a00: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 #endif../*.** Ma
1a10: 6b 65 20 73 75 72 65 20 74 68 61 74 20 74 68 65 ke sure that the
1a20: 20 63 6f 6d 70 69 6c 65 72 20 69 6e 74 72 69 6e compiler intrin
1a30: 73 69 63 73 20 77 65 20 64 65 73 69 72 65 20 61 sics we desire a
1a40: 72 65 20 65 6e 61 62 6c 65 64 20 77 68 65 6e 0a re enabled when.
1a50: 2a 2a 20 63 6f 6d 70 69 6c 69 6e 67 20 77 69 74 ** compiling wit
1a60: 68 20 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 h an appropriate
1a70: 20 76 65 72 73 69 6f 6e 20 6f 66 20 4d 53 56 43 version of MSVC
1a80: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
1a90: 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 20 5f 4d (_MSC_VER) && _M
1aa0: 53 43 5f 56 45 52 3e 3d 31 33 30 30 0a 23 20 20 SC_VER>=1300.#
1ab0: 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e if !defined(_WIN
1ac0: 33 32 5f 57 43 45 29 0a 23 20 20 20 20 69 6e 63 32_WCE).# inc
1ad0: 6c 75 64 65 20 3c 69 6e 74 72 69 6e 2e 68 3e 0a lude <intrin.h>.
1ae0: 23 20 20 20 20 70 72 61 67 6d 61 20 69 6e 74 72 # pragma intr
1af0: 69 6e 73 69 63 28 5f 62 79 74 65 73 77 61 70 5f insic(_byteswap_
1b00: 75 73 68 6f 72 74 29 0a 23 20 20 20 20 70 72 61 ushort).# pra
1b10: 67 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 5f 62 gma intrinsic(_b
1b20: 79 74 65 73 77 61 70 5f 75 6c 6f 6e 67 29 0a 23 yteswap_ulong).#
1b30: 20 20 65 6c 73 65 0a 23 20 20 20 20 69 6e 63 6c else.# incl
1b40: 75 64 65 20 3c 63 6d 6e 69 6e 74 72 69 6e 2e 68 ude <cmnintrin.h
1b50: 3e 0a 23 20 20 65 6e 64 69 66 0a 23 65 6e 64 69 >.# endif.#endi
1b60: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 4c f../*.** The SQL
1b70: 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 20 6d ITE_THREADSAFE m
1b80: 61 63 72 6f 20 6d 75 73 74 20 62 65 20 64 65 66 acro must be def
1b90: 69 6e 65 64 20 61 73 20 30 2c 20 31 2c 20 6f 72 ined as 0, 1, or
1ba0: 20 32 2e 0a 2a 2a 20 30 20 6d 65 61 6e 73 20 6d 2..** 0 means m
1bb0: 75 74 65 78 65 73 20 61 72 65 20 70 65 72 6d 61 utexes are perma
1bc0: 6e 65 6e 74 6c 79 20 64 69 73 61 62 6c 65 20 61 nently disable a
1bd0: 6e 64 20 74 68 65 20 6c 69 62 72 61 72 79 20 69 nd the library i
1be0: 73 20 6e 65 76 65 72 0a 2a 2a 20 74 68 72 65 61 s never.** threa
1bf0: 64 73 61 66 65 2e 20 20 31 20 6d 65 61 6e 73 20 dsafe. 1 means
1c00: 74 68 65 20 6c 69 62 72 61 72 79 20 69 73 20 73 the library is s
1c10: 65 72 69 61 6c 69 7a 65 64 20 77 68 69 63 68 20 erialized which
1c20: 69 73 20 74 68 65 20 68 69 67 68 65 73 74 0a 2a is the highest.*
1c30: 2a 20 6c 65 76 65 6c 20 6f 66 20 74 68 72 65 61 * level of threa
1c40: 64 73 61 66 65 74 79 2e 20 20 32 20 6d 65 61 6e dsafety. 2 mean
1c50: 73 20 74 68 65 20 6c 69 62 72 61 72 79 20 69 73 s the library is
1c60: 20 6d 75 6c 74 69 74 68 72 65 61 64 65 64 20 2d multithreaded -
1c70: 20 6d 75 6c 74 69 70 6c 65 0a 2a 2a 20 74 68 72 multiple.** thr
1c80: 65 61 64 73 20 63 61 6e 20 75 73 65 20 53 51 4c eads can use SQL
1c90: 69 74 65 20 61 73 20 6c 6f 6e 67 20 61 73 20 6e ite as long as n
1ca0: 6f 20 74 77 6f 20 74 68 72 65 61 64 73 20 74 72 o two threads tr
1cb0: 79 20 74 6f 20 75 73 65 20 74 68 65 20 73 61 6d y to use the sam
1cc0: 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 6f e.** database co
1cd0: 6e 6e 65 63 74 69 6f 6e 20 61 74 20 74 68 65 20 nnection at the
1ce0: 73 61 6d 65 20 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a same time..**.**
1cf0: 20 4f 6c 64 65 72 20 76 65 72 73 69 6f 6e 73 20 Older versions
1d00: 6f 66 20 53 51 4c 69 74 65 20 75 73 65 64 20 61 of SQLite used a
1d10: 6e 20 6f 70 74 69 6f 6e 61 6c 20 54 48 52 45 41 n optional THREA
1d20: 44 53 41 46 45 20 6d 61 63 72 6f 2e 0a 2a 2a 20 DSAFE macro..**
1d30: 57 65 20 73 75 70 70 6f 72 74 20 74 68 61 74 20 We support that
1d40: 66 6f 72 20 6c 65 67 61 63 79 2e 0a 2a 2f 0a 23 for legacy..*/.#
1d50: 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
1d60: 54 45 5f 54 48 52 45 41 44 53 41 46 45 29 0a 23 TE_THREADSAFE).#
1d70: 20 69 66 20 64 65 66 69 6e 65 64 28 54 48 52 45 if defined(THRE
1d80: 41 44 53 41 46 45 29 0a 23 20 20 20 64 65 66 69 ADSAFE).# defi
1d90: 6e 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 ne SQLITE_THREAD
1da0: 53 41 46 45 20 54 48 52 45 41 44 53 41 46 45 0a SAFE THREADSAFE.
1db0: 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e # else.# defin
1dc0: 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 53 e SQLITE_THREADS
1dd0: 41 46 45 20 31 20 2f 2a 20 49 4d 50 3a 20 52 2d AFE 1 /* IMP: R-
1de0: 30 37 32 37 32 2d 32 32 33 30 39 20 2a 2f 0a 23 07272-22309 */.#
1df0: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f endif.#endif../
1e00: 2a 0a 2a 2a 20 50 6f 77 65 72 73 61 66 65 20 6f *.** Powersafe o
1e10: 76 65 72 77 72 69 74 65 20 69 73 20 6f 6e 20 62 verwrite is on b
1e20: 79 20 64 65 66 61 75 6c 74 2e 20 20 42 75 74 20 y default. But
1e30: 63 61 6e 20 62 65 20 74 75 72 6e 65 64 20 6f 66 can be turned of
1e40: 66 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65 20 2d f using.** the -
1e50: 44 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 DSQLITE_POWERSAF
1e60: 45 5f 4f 56 45 52 57 52 49 54 45 3d 30 20 63 6f E_OVERWRITE=0 co
1e70: 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f mmand-line optio
1e80: 6e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 n..*/.#ifndef SQ
1e90: 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 45 5f 4f LITE_POWERSAFE_O
1ea0: 56 45 52 57 52 49 54 45 0a 23 20 64 65 66 69 6e VERWRITE.# defin
1eb0: 65 20 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 e SQLITE_POWERSA
1ec0: 46 45 5f 4f 56 45 52 57 52 49 54 45 20 31 0a 23 FE_OVERWRITE 1.#
1ed0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 56 49 endif../*.** EVI
1ee0: 44 45 4e 43 45 2d 4f 46 3a 20 52 2d 32 35 37 31 DENCE-OF: R-2571
1ef0: 35 2d 33 37 30 37 32 20 4d 65 6d 6f 72 79 20 61 5-37072 Memory a
1f00: 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 69 73 llocation statis
1f10: 74 69 63 73 20 61 72 65 20 65 6e 61 62 6c 65 64 tics are enabled
1f20: 20 62 79 0a 2a 2a 20 64 65 66 61 75 6c 74 20 75 by.** default u
1f30: 6e 6c 65 73 73 20 53 51 4c 69 74 65 20 69 73 20 nless SQLite is
1f40: 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 20 53 51 compiled with SQ
1f50: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d LITE_DEFAULT_MEM
1f60: 53 54 41 54 55 53 3d 30 20 69 6e 0a 2a 2a 20 77 STATUS=0 in.** w
1f70: 68 69 63 68 20 63 61 73 65 20 6d 65 6d 6f 72 79 hich case memory
1f80: 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 allocation stat
1f90: 69 73 74 69 63 73 20 61 72 65 20 64 69 73 61 62 istics are disab
1fa0: 6c 65 64 20 62 79 20 64 65 66 61 75 6c 74 2e 0a led by default..
1fb0: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
1fc0: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
1fd0: 45 4d 53 54 41 54 55 53 29 0a 23 20 64 65 66 69 EMSTATUS).# defi
1fe0: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
1ff0: 54 5f 4d 45 4d 53 54 41 54 55 53 20 31 0a 23 65 T_MEMSTATUS 1.#e
2000: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 78 61 63 ndif../*.** Exac
2010: 74 6c 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 tly one of the f
2020: 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 ollowing macros
2030: 6d 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 20 must be defined
2040: 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 73 in order to.** s
2050: 70 65 63 69 66 79 20 77 68 69 63 68 20 6d 65 6d pecify which mem
2060: 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 ory allocation s
2070: 75 62 73 79 73 74 65 6d 20 74 6f 20 75 73 65 2e ubsystem to use.
2080: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 .**.** SQLIT
2090: 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 E_SYSTEM_MALLOC
20a0: 20 20 20 20 20 20 20 20 20 2f 2f 20 55 73 65 20 // Use
20b0: 6e 6f 72 6d 61 6c 20 73 79 73 74 65 6d 20 6d 61 normal system ma
20c0: 6c 6c 6f 63 28 29 0a 2a 2a 20 20 20 20 20 53 51 lloc().** SQ
20d0: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
20e0: 43 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 55 C // U
20f0: 73 65 20 57 69 6e 33 32 20 6e 61 74 69 76 65 20 se Win32 native
2100: 68 65 61 70 20 41 50 49 0a 2a 2a 20 20 20 20 20 heap API.**
2110: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
2120: 4f 43 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f OC //
2130: 20 55 73 65 20 61 20 73 74 75 62 20 61 6c 6c 6f Use a stub allo
2140: 63 61 74 6f 72 20 74 68 61 74 20 61 6c 77 61 79 cator that alway
2150: 73 20 66 61 69 6c 73 0a 2a 2a 20 20 20 20 20 53 s fails.** S
2160: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 20 QLITE_MEMDEBUG
2170: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
2180: 44 65 62 75 67 67 69 6e 67 20 76 65 72 73 69 6f Debugging versio
2190: 6e 20 6f 66 20 73 79 73 74 65 6d 20 6d 61 6c 6c n of system mall
21a0: 6f 63 28 29 0a 2a 2a 0a 2a 2a 20 4f 6e 20 57 69 oc().**.** On Wi
21b0: 6e 64 6f 77 73 2c 20 69 66 20 74 68 65 20 53 51 ndows, if the SQ
21c0: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
21d0: 43 5f 56 41 4c 49 44 41 54 45 20 6d 61 63 72 6f C_VALIDATE macro
21e0: 20 69 73 20 64 65 66 69 6e 65 64 20 61 6e 64 20 is defined and
21f0: 74 68 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 the.** assert()
2200: 6d 61 63 72 6f 20 69 73 20 65 6e 61 62 6c 65 64 macro is enabled
2210: 2c 20 65 61 63 68 20 63 61 6c 6c 20 69 6e 74 6f , each call into
2220: 20 74 68 65 20 57 69 6e 33 32 20 6e 61 74 69 76 the Win32 nativ
2230: 65 20 68 65 61 70 20 73 75 62 73 79 73 74 65 6d e heap subsystem
2240: 0a 2a 2a 20 77 69 6c 6c 20 63 61 75 73 65 20 48 .** will cause H
2250: 65 61 70 56 61 6c 69 64 61 74 65 20 74 6f 20 62 eapValidate to b
2260: 65 20 63 61 6c 6c 65 64 2e 20 20 49 66 20 68 65 e called. If he
2270: 61 70 20 76 61 6c 69 64 61 74 69 6f 6e 20 73 68 ap validation sh
2280: 6f 75 6c 64 20 66 61 69 6c 2c 20 61 6e 0a 2a 2a ould fail, an.**
2290: 20 61 73 73 65 72 74 69 6f 6e 20 77 69 6c 6c 20 assertion will
22a0: 62 65 20 74 72 69 67 67 65 72 65 64 2e 0a 2a 2a be triggered..**
22b0: 0a 2a 2a 20 49 66 20 6e 6f 6e 65 20 6f 66 20 74 .** If none of t
22c0: 68 65 20 61 62 6f 76 65 20 61 72 65 20 64 65 66 he above are def
22d0: 69 6e 65 64 2c 20 74 68 65 6e 20 73 65 74 20 53 ined, then set S
22e0: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
22f0: 4c 4f 43 20 61 73 0a 2a 2a 20 74 68 65 20 64 65 LOC as.** the de
2300: 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 66 20 64 65 fault..*/.#if de
2310: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 53 fined(SQLITE_SYS
2320: 54 45 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 TEM_MALLOC) \.
2330: 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 + defined(SQLITE
2340: 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 5c _WIN32_MALLOC) \
2350: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
2360: 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 29 ITE_ZERO_MALLOC)
2370: 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 \. + defined(S
2380: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 3e QLITE_MEMDEBUG)>
2390: 31 0a 23 20 65 72 72 6f 72 20 22 54 77 6f 20 6f 1.# error "Two o
23a0: 72 20 6d 6f 72 65 20 6f 66 20 74 68 65 20 66 6f r more of the fo
23b0: 6c 6c 6f 77 69 6e 67 20 63 6f 6d 70 69 6c 65 2d llowing compile-
23c0: 74 69 6d 65 20 63 6f 6e 66 69 67 75 72 61 74 69 time configurati
23d0: 6f 6e 20 6f 70 74 69 6f 6e 73 5c 0a 20 61 72 65 on options\. are
23e0: 20 64 65 66 69 6e 65 64 20 62 75 74 20 61 74 20 defined but at
23f0: 6d 6f 73 74 20 6f 6e 65 20 69 73 20 61 6c 6c 6f most one is allo
2400: 77 65 64 3a 5c 0a 20 53 51 4c 49 54 45 5f 53 59 wed:\. SQLITE_SY
2410: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c STEM_MALLOC, SQL
2420: 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 ITE_WIN32_MALLOC
2430: 2c 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 , SQLITE_MEMDEBU
2440: 47 2c 5c 0a 20 53 51 4c 49 54 45 5f 5a 45 52 4f G,\. SQLITE_ZERO
2450: 5f 4d 41 4c 4c 4f 43 22 0a 23 65 6e 64 69 66 0a _MALLOC".#endif.
2460: 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
2470: 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 TE_SYSTEM_MALLOC
2480: 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 ) \. + defined(
2490: 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c SQLITE_WIN32_MAL
24a0: 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e LOC) \. + defin
24b0: 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d ed(SQLITE_ZERO_M
24c0: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
24d0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 45 4d 44 ined(SQLITE_MEMD
24e0: 45 42 55 47 29 3d 3d 30 0a 23 20 64 65 66 69 6e EBUG)==0.# defin
24f0: 65 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f e SQLITE_SYSTEM_
2500: 4d 41 4c 4c 4f 43 20 31 0a 23 65 6e 64 69 66 0a MALLOC 1.#endif.
2510: 0a 2f 2a 0a 2a 2a 20 49 66 20 53 51 4c 49 54 45 ./*.** If SQLITE
2520: 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d _MALLOC_SOFT_LIM
2530: 49 54 20 69 73 20 6e 6f 74 20 7a 65 72 6f 2c 20 IT is not zero,
2540: 74 68 65 6e 20 74 72 79 20 74 6f 20 6b 65 65 70 then try to keep
2550: 20 74 68 65 0a 2a 2a 20 73 69 7a 65 73 20 6f 66 the.** sizes of
2560: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
2570: 6f 6e 73 20 62 65 6c 6f 77 20 74 68 69 73 20 76 ons below this v
2580: 61 6c 75 65 20 77 68 65 72 65 20 70 6f 73 73 69 alue where possi
2590: 62 6c 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 ble..*/.#if !def
25a0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 41 4c 4c ined(SQLITE_MALL
25b0: 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 29 0a 23 OC_SOFT_LIMIT).#
25c0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
25d0: 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 ALLOC_SOFT_LIMIT
25e0: 20 31 30 32 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 1024.#endif../*
25f0: 0a 2a 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 64 .** We need to d
2600: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
2610: 52 43 45 20 61 73 20 66 6f 6c 6c 6f 77 73 20 69 RCE as follows i
2620: 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c n order to enabl
2630: 65 0a 2a 2a 20 72 65 63 75 72 73 69 76 65 20 6d e.** recursive m
2640: 75 74 65 78 65 73 20 6f 6e 20 6d 6f 73 74 20 55 utexes on most U
2650: 6e 69 78 20 73 79 73 74 65 6d 73 20 61 6e 64 20 nix systems and
2660: 66 63 68 6d 6f 64 28 29 20 6f 6e 20 4f 70 65 6e fchmod() on Open
2670: 42 53 44 2e 0a 2a 2a 20 42 75 74 20 5f 58 4f 50 BSD..** But _XOP
2680: 45 4e 5f 53 4f 55 52 43 45 20 64 65 66 69 6e 65 EN_SOURCE define
2690: 20 63 61 75 73 65 73 20 70 72 6f 62 6c 65 6d 73 causes problems
26a0: 20 66 6f 72 20 4d 61 63 20 4f 53 20 58 2c 20 73 for Mac OS X, s
26b0: 6f 20 6f 6d 69 74 0a 2a 2a 20 69 74 2e 0a 2a 2f o omit.** it..*/
26c0: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 58 .#if !defined(_X
26d0: 4f 50 45 4e 5f 53 4f 55 52 43 45 29 20 26 26 20 OPEN_SOURCE) &&
26e0: 21 64 65 66 69 6e 65 64 28 5f 5f 44 41 52 57 49 !defined(__DARWI
26f0: 4e 5f 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 N__) && !defined
2700: 28 5f 5f 41 50 50 4c 45 5f 5f 29 0a 23 20 20 64 (__APPLE__).# d
2710: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
2720: 52 43 45 20 36 30 30 0a 23 65 6e 64 69 66 0a 0a RCE 600.#endif..
2730: 2f 2a 0a 2a 2a 20 4e 44 45 42 55 47 20 61 6e 64 /*.** NDEBUG and
2740: 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 61 72 SQLITE_DEBUG ar
2750: 65 20 6f 70 70 6f 73 69 74 65 73 2e 20 20 49 74 e opposites. It
2760: 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 62 should always b
2770: 65 20 74 72 75 65 20 74 68 61 74 0a 2a 2a 20 64 e true that.** d
2780: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 3d 3d efined(NDEBUG)==
2790: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
27a0: 44 45 42 55 47 29 2e 20 20 49 66 20 74 68 69 73 DEBUG). If this
27b0: 20 69 73 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c is not currentl
27c0: 79 20 74 72 75 65 2c 0a 2a 2a 20 6d 61 6b 65 20 y true,.** make
27d0: 69 74 20 74 72 75 65 20 62 79 20 64 65 66 69 6e it true by defin
27e0: 69 6e 67 20 6f 72 20 75 6e 64 65 66 69 6e 69 6e ing or undefinin
27f0: 67 20 4e 44 45 42 55 47 2e 0a 2a 2a 0a 2a 2a 20 g NDEBUG..**.**
2800: 53 65 74 74 69 6e 67 20 4e 44 45 42 55 47 20 6d Setting NDEBUG m
2810: 61 6b 65 73 20 74 68 65 20 63 6f 64 65 20 73 6d akes the code sm
2820: 61 6c 6c 65 72 20 61 6e 64 20 66 61 73 74 65 72 aller and faster
2830: 20 62 79 20 64 69 73 61 62 6c 69 6e 67 20 74 68 by disabling th
2840: 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 73 74 e.** assert() st
2850: 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 atements in the
2860: 63 6f 64 65 2e 20 20 53 6f 20 77 65 20 77 61 6e code. So we wan
2870: 74 20 74 68 65 20 64 65 66 61 75 6c 74 20 61 63 t the default ac
2880: 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 66 6f tion.** to be fo
2890: 72 20 4e 44 45 42 55 47 20 74 6f 20 62 65 20 73 r NDEBUG to be s
28a0: 65 74 20 61 6e 64 20 4e 44 45 42 55 47 20 74 6f et and NDEBUG to
28b0: 20 62 65 20 75 6e 64 65 66 69 6e 65 64 20 6f 6e be undefined on
28c0: 6c 79 20 69 66 20 53 51 4c 49 54 45 5f 44 45 42 ly if SQLITE_DEB
28d0: 55 47 0a 2a 2a 20 69 73 20 73 65 74 2e 20 20 54 UG.** is set. T
28e0: 68 75 73 20 4e 44 45 42 55 47 20 62 65 63 6f 6d hus NDEBUG becom
28f0: 65 73 20 61 6e 20 6f 70 74 2d 69 6e 20 72 61 74 es an opt-in rat
2900: 68 65 72 20 74 68 61 6e 20 61 6e 20 6f 70 74 2d her than an opt-
2910: 6f 75 74 0a 2a 2a 20 66 65 61 74 75 72 65 2e 0a out.** feature..
2920: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
2930: 4e 44 45 42 55 47 29 20 26 26 20 21 64 65 66 69 NDEBUG) && !defi
2940: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
2950: 29 20 0a 23 20 64 65 66 69 6e 65 20 4e 44 45 42 ) .# define NDEB
2960: 55 47 20 31 0a 23 65 6e 64 69 66 0a 23 69 66 20 UG 1.#endif.#if
2970: 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 defined(NDEBUG)
2980: 26 26 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 && defined(SQLIT
2990: 45 5f 44 45 42 55 47 29 0a 23 20 75 6e 64 65 66 E_DEBUG).# undef
29a0: 20 4e 44 45 42 55 47 0a 23 65 6e 64 69 66 0a 0a NDEBUG.#endif..
29b0: 2f 2a 0a 2a 2a 20 45 6e 61 62 6c 65 20 53 51 4c /*.** Enable SQL
29c0: 49 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 ITE_ENABLE_EXPLA
29d0: 49 4e 5f 43 4f 4d 4d 45 4e 54 53 20 69 66 20 53 IN_COMMENTS if S
29e0: 51 4c 49 54 45 5f 44 45 42 55 47 20 69 73 20 74 QLITE_DEBUG is t
29f0: 75 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 69 66 urned on..*/.#if
2a00: 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
2a10: 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f _ENABLE_EXPLAIN_
2a20: 43 4f 4d 4d 45 4e 54 53 29 20 26 26 20 64 65 66 COMMENTS) && def
2a30: 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 ined(SQLITE_DEBU
2a40: 47 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 G).# define SQLI
2a50: 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 TE_ENABLE_EXPLAI
2a60: 4e 5f 43 4f 4d 4d 45 4e 54 53 20 31 0a 23 65 6e N_COMMENTS 1.#en
2a70: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 74 dif../*.** The t
2a80: 65 73 74 63 61 73 65 28 29 20 6d 61 63 72 6f 20 estcase() macro
2a90: 69 73 20 75 73 65 64 20 74 6f 20 61 69 64 20 69 is used to aid i
2aa0: 6e 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 n coverage testi
2ab0: 6e 67 2e 20 20 57 68 65 6e 20 0a 2a 2a 20 64 6f ng. When .** do
2ac0: 69 6e 67 20 63 6f 76 65 72 61 67 65 20 74 65 73 ing coverage tes
2ad0: 74 69 6e 67 2c 20 74 68 65 20 63 6f 6e 64 69 74 ting, the condit
2ae0: 69 6f 6e 20 69 6e 73 69 64 65 20 74 68 65 20 61 ion inside the a
2af0: 72 67 75 6d 65 6e 74 20 74 6f 0a 2a 2a 20 74 65 rgument to.** te
2b00: 73 74 63 61 73 65 28 29 20 6d 75 73 74 20 62 65 stcase() must be
2b10: 20 65 76 61 6c 75 61 74 65 64 20 62 6f 74 68 20 evaluated both
2b20: 74 72 75 65 20 61 6e 64 20 66 61 6c 73 65 20 69 true and false i
2b30: 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 65 n order to.** ge
2b40: 74 20 66 75 6c 6c 20 62 72 61 6e 63 68 20 63 6f t full branch co
2b50: 76 65 72 61 67 65 2e 20 20 54 68 65 20 74 65 73 verage. The tes
2b60: 74 63 61 73 65 28 29 20 6d 61 63 72 6f 20 69 73 tcase() macro is
2b70: 20 69 6e 73 65 72 74 65 64 0a 2a 2a 20 74 6f 20 inserted.** to
2b80: 68 65 6c 70 20 65 6e 73 75 72 65 20 61 64 65 71 help ensure adeq
2b90: 75 61 74 65 20 74 65 73 74 20 63 6f 76 65 72 61 uate test covera
2ba0: 67 65 20 69 6e 20 70 6c 61 63 65 73 20 77 68 65 ge in places whe
2bb0: 72 65 20 73 69 6d 70 6c 65 0a 2a 2a 20 63 6f 6e re simple.** con
2bc0: 64 69 74 69 6f 6e 2f 64 65 63 69 73 69 6f 6e 20 dition/decision
2bd0: 63 6f 76 65 72 61 67 65 20 69 73 20 69 6e 61 64 coverage is inad
2be0: 65 71 75 61 74 65 2e 20 20 46 6f 72 20 65 78 61 equate. For exa
2bf0: 6d 70 6c 65 2c 20 74 65 73 74 63 61 73 65 28 29 mple, testcase()
2c00: 0a 2a 2a 20 63 61 6e 20 62 65 20 75 73 65 64 20 .** can be used
2c10: 74 6f 20 6d 61 6b 65 20 73 75 72 65 20 62 6f 75 to make sure bou
2c20: 6e 64 61 72 79 20 76 61 6c 75 65 73 20 61 72 65 ndary values are
2c30: 20 74 65 73 74 65 64 2e 20 20 46 6f 72 0a 2a 2a tested. For.**
2c40: 20 62 69 74 6d 61 73 6b 20 74 65 73 74 73 2c 20 bitmask tests,
2c50: 74 65 73 74 63 61 73 65 28 29 20 63 61 6e 20 62 testcase() can b
2c60: 65 20 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 73 e used to make s
2c70: 75 72 65 20 65 61 63 68 20 62 69 74 0a 2a 2a 20 ure each bit.**
2c80: 69 73 20 73 69 67 6e 69 66 69 63 61 6e 74 20 61 is significant a
2c90: 6e 64 20 75 73 65 64 20 61 74 20 6c 65 61 73 74 nd used at least
2ca0: 20 6f 6e 63 65 2e 20 20 4f 6e 20 73 77 69 74 63 once. On switc
2cb0: 68 20 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a 20 h statements.**
2cc0: 77 68 65 72 65 20 6d 75 6c 74 69 70 6c 65 20 63 where multiple c
2cd0: 61 73 65 73 20 67 6f 20 74 6f 20 74 68 65 20 73 ases go to the s
2ce0: 61 6d 65 20 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 ame block of cod
2cf0: 65 2c 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a e, testcase().**
2d00: 20 63 61 6e 20 69 6e 73 75 72 65 20 74 68 61 74 can insure that
2d10: 20 61 6c 6c 20 63 61 73 65 73 20 61 72 65 20 65 all cases are e
2d20: 76 61 6c 75 61 74 65 64 2e 0a 2a 2a 0a 2a 2f 0a valuated..**.*/.
2d30: 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 43 4f #ifdef SQLITE_CO
2d40: 56 45 52 41 47 45 5f 54 45 53 54 0a 20 20 76 6f VERAGE_TEST. vo
2d50: 69 64 20 73 71 6c 69 74 65 33 43 6f 76 65 72 61 id sqlite3Covera
2d60: 67 65 28 69 6e 74 29 3b 0a 23 20 64 65 66 69 6e ge(int);.# defin
2d70: 65 20 74 65 73 74 63 61 73 65 28 58 29 20 20 69 e testcase(X) i
2d80: 66 28 20 58 20 29 7b 20 73 71 6c 69 74 65 33 43 f( X ){ sqlite3C
2d90: 6f 76 65 72 61 67 65 28 5f 5f 4c 49 4e 45 5f 5f overage(__LINE__
2da0: 29 3b 20 7d 0a 23 65 6c 73 65 0a 23 20 64 65 66 ); }.#else.# def
2db0: 69 6e 65 20 74 65 73 74 63 61 73 65 28 58 29 0a ine testcase(X).
2dc0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 #endif../*.** Th
2dd0: 65 20 54 45 53 54 4f 4e 4c 59 20 6d 61 63 72 6f e TESTONLY macro
2de0: 20 69 73 20 75 73 65 64 20 74 6f 20 65 6e 63 6c is used to encl
2df0: 6f 73 65 20 76 61 72 69 61 62 6c 65 20 64 65 63 ose variable dec
2e00: 6c 61 72 61 74 69 6f 6e 73 20 6f 72 0a 2a 2a 20 larations or.**
2e10: 6f 74 68 65 72 20 62 69 74 73 20 6f 66 20 63 6f other bits of co
2e20: 64 65 20 74 68 61 74 20 61 72 65 20 6e 65 65 64 de that are need
2e30: 65 64 20 74 6f 20 73 75 70 70 6f 72 74 20 74 68 ed to support th
2e40: 65 20 61 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 77 e arguments.** w
2e50: 69 74 68 69 6e 20 74 65 73 74 63 61 73 65 28 29 ithin testcase()
2e60: 20 61 6e 64 20 61 73 73 65 72 74 28 29 20 6d 61 and assert() ma
2e70: 63 72 6f 73 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 cros..*/.#if !de
2e80: 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 7c 7c fined(NDEBUG) ||
2e90: 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
2ea0: 43 4f 56 45 52 41 47 45 5f 54 45 53 54 29 0a 23 COVERAGE_TEST).#
2eb0: 20 64 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c 59 define TESTONLY
2ec0: 28 58 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 64 (X) X.#else.# d
2ed0: 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 efine TESTONLY(X
2ee0: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
2ef0: 53 6f 6d 65 74 69 6d 65 73 20 77 65 20 6e 65 65 Sometimes we nee
2f00: 64 20 61 20 73 6d 61 6c 6c 20 61 6d 6f 75 6e 74 d a small amount
2f10: 20 6f 66 20 63 6f 64 65 20 73 75 63 68 20 61 73 of code such as
2f20: 20 61 20 76 61 72 69 61 62 6c 65 20 69 6e 69 74 a variable init
2f30: 69 61 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 74 6f ialization.** to
2f40: 20 73 65 74 75 70 20 66 6f 72 20 61 20 6c 61 74 setup for a lat
2f50: 65 72 20 61 73 73 65 72 74 28 29 20 73 74 61 74 er assert() stat
2f60: 65 6d 65 6e 74 2e 20 20 57 65 20 64 6f 20 6e 6f ement. We do no
2f70: 74 20 77 61 6e 74 20 74 68 69 73 20 63 6f 64 65 t want this code
2f80: 20 74 6f 0a 2a 2a 20 61 70 70 65 61 72 20 77 68 to.** appear wh
2f90: 65 6e 20 61 73 73 65 72 74 28 29 20 69 73 20 64 en assert() is d
2fa0: 69 73 61 62 6c 65 64 2e 20 20 54 68 65 20 66 6f isabled. The fo
2fb0: 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 20 69 73 llowing macro is
2fc0: 20 74 68 65 72 65 66 6f 72 65 0a 2a 2a 20 75 73 therefore.** us
2fd0: 65 64 20 74 6f 20 63 6f 6e 74 61 69 6e 20 74 68 ed to contain th
2fe0: 61 74 20 73 65 74 75 70 20 63 6f 64 65 2e 20 20 at setup code.
2ff0: 54 68 65 20 22 56 56 41 22 20 61 63 72 6f 6e 79 The "VVA" acrony
3000: 6d 20 73 74 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 m stands for.**
3010: 22 56 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 56 "Verification, V
3020: 61 6c 69 64 61 74 69 6f 6e 2c 20 61 6e 64 20 41 alidation, and A
3030: 63 63 72 65 64 69 74 61 74 69 6f 6e 22 2e 20 20 ccreditation".
3040: 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 In other words,
3050: 74 68 65 0a 2a 2a 20 63 6f 64 65 20 77 69 74 68 the.** code with
3060: 69 6e 20 56 56 41 5f 4f 4e 4c 59 28 29 20 77 69 in VVA_ONLY() wi
3070: 6c 6c 20 6f 6e 6c 79 20 72 75 6e 20 64 75 72 69 ll only run duri
3080: 6e 67 20 76 65 72 69 66 69 63 61 74 69 6f 6e 20 ng verification
3090: 70 72 6f 63 65 73 73 65 73 2e 0a 2a 2f 0a 23 69 processes..*/.#i
30a0: 66 6e 64 65 66 20 4e 44 45 42 55 47 0a 23 20 64 fndef NDEBUG.# d
30b0: 65 66 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 58 efine VVA_ONLY(X
30c0: 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 ) X.#else.# def
30d0: 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 0a ine VVA_ONLY(X).
30e0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 #endif../*.** Th
30f0: 65 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 e ALWAYS and NEV
3100: 45 52 20 6d 61 63 72 6f 73 20 73 75 72 72 6f 75 ER macros surrou
3110: 6e 64 20 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 nd boolean expre
3120: 73 73 69 6f 6e 73 20 77 68 69 63 68 20 0a 2a 2a ssions which .**
3130: 20 61 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f are intended to
3140: 20 61 6c 77 61 79 73 20 62 65 20 74 72 75 65 20 always be true
3150: 6f 72 20 66 61 6c 73 65 2c 20 72 65 73 70 65 63 or false, respec
3160: 74 69 76 65 6c 79 2e 20 20 53 75 63 68 0a 2a 2a tively. Such.**
3170: 20 65 78 70 72 65 73 73 69 6f 6e 73 20 63 6f 75 expressions cou
3180: 6c 64 20 62 65 20 6f 6d 69 74 74 65 64 20 66 72 ld be omitted fr
3190: 6f 6d 20 74 68 65 20 63 6f 64 65 20 63 6f 6d 70 om the code comp
31a0: 6c 65 74 65 6c 79 2e 20 20 42 75 74 20 74 68 65 letely. But the
31b0: 79 0a 2a 2a 20 61 72 65 20 69 6e 63 6c 75 64 65 y.** are include
31c0: 64 20 69 6e 20 61 20 66 65 77 20 63 61 73 65 73 d in a few cases
31d0: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 68 in order to enh
31e0: 61 6e 63 65 20 74 68 65 20 72 65 73 69 6c 69 65 ance the resilie
31f0: 6e 63 65 0a 2a 2a 20 6f 66 20 53 51 4c 69 74 65 nce.** of SQLite
3200: 20 74 6f 20 75 6e 65 78 70 65 63 74 65 64 20 62 to unexpected b
3210: 65 68 61 76 69 6f 72 20 2d 20 74 6f 20 6d 61 6b ehavior - to mak
3220: 65 20 74 68 65 20 63 6f 64 65 20 22 73 65 6c 66 e the code "self
3230: 2d 68 65 61 6c 69 6e 67 22 0a 2a 2a 20 6f 72 20 -healing".** or
3240: 22 64 75 63 74 69 6c 65 22 20 72 61 74 68 65 72 "ductile" rather
3250: 20 74 68 61 6e 20 62 65 69 6e 67 20 22 62 72 69 than being "bri
3260: 74 74 6c 65 22 20 61 6e 64 20 63 72 61 73 68 69 ttle" and crashi
3270: 6e 67 20 61 74 20 74 68 65 20 66 69 72 73 74 0a ng at the first.
3280: 2a 2a 20 68 69 6e 74 20 6f 66 20 75 6e 70 6c 61 ** hint of unpla
3290: 6e 6e 65 64 20 62 65 68 61 76 69 6f 72 2e 0a 2a nned behavior..*
32a0: 2a 0a 2a 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f *.** In other wo
32b0: 72 64 73 2c 20 41 4c 57 41 59 53 20 61 6e 64 20 rds, ALWAYS and
32c0: 4e 45 56 45 52 20 61 72 65 20 61 64 64 65 64 20 NEVER are added
32d0: 66 6f 72 20 64 65 66 65 6e 73 69 76 65 20 63 6f for defensive co
32e0: 64 65 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 64 de..**.** When d
32f0: 6f 69 6e 67 20 63 6f 76 65 72 61 67 65 20 74 65 oing coverage te
3300: 73 74 69 6e 67 20 41 4c 57 41 59 53 20 61 6e 64 sting ALWAYS and
3310: 20 4e 45 56 45 52 20 61 72 65 20 68 61 72 64 2d NEVER are hard-
3320: 63 6f 64 65 64 20 74 6f 0a 2a 2a 20 62 65 20 74 coded to.** be t
3330: 72 75 65 20 61 6e 64 20 66 61 6c 73 65 20 73 6f rue and false so
3340: 20 74 68 61 74 20 74 68 65 20 75 6e 72 65 61 63 that the unreac
3350: 68 61 62 6c 65 20 63 6f 64 65 20 74 68 65 79 20 hable code they
3360: 73 70 65 63 69 66 79 20 77 69 6c 6c 0a 2a 2a 20 specify will.**
3370: 6e 6f 74 20 62 65 20 63 6f 75 6e 74 65 64 20 61 not be counted a
3380: 73 20 75 6e 74 65 73 74 65 64 20 63 6f 64 65 2e s untested code.
3390: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
33a0: 53 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 5f SQLITE_COVERAGE_
33b0: 54 45 53 54 29 0a 23 20 64 65 66 69 6e 65 20 41 TEST).# define A
33c0: 4c 57 41 59 53 28 58 29 20 20 20 20 20 20 28 31 LWAYS(X) (1
33d0: 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 ).# define NEVER
33e0: 28 58 29 20 20 20 20 20 20 20 28 30 29 0a 23 65 (X) (0).#e
33f0: 6c 69 66 20 21 64 65 66 69 6e 65 64 28 4e 44 45 lif !defined(NDE
3400: 42 55 47 29 0a 23 20 64 65 66 69 6e 65 20 41 4c BUG).# define AL
3410: 57 41 59 53 28 58 29 20 20 20 20 20 20 28 28 58 WAYS(X) ((X
3420: 29 3f 31 3a 28 61 73 73 65 72 74 28 30 29 2c 30 )?1:(assert(0),0
3430: 29 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 )).# define NEVE
3440: 52 28 58 29 20 20 20 20 20 20 20 28 28 58 29 3f R(X) ((X)?
3450: 28 61 73 73 65 72 74 28 30 29 2c 31 29 3a 30 29 (assert(0),1):0)
3460: 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
3470: 41 4c 57 41 59 53 28 58 29 20 20 20 20 20 20 28 ALWAYS(X) (
3480: 58 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 X).# define NEVE
3490: 52 28 58 29 20 20 20 20 20 20 20 28 58 29 0a 23 R(X) (X).#
34a0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 63 endif../*.** Dec
34b0: 6c 61 72 61 74 69 6f 6e 73 20 75 73 65 64 20 66 larations used f
34c0: 6f 72 20 74 72 61 63 69 6e 67 20 74 68 65 20 6f or tracing the o
34d0: 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d 20 perating system
34e0: 69 6e 74 65 72 66 61 63 65 73 2e 0a 2a 2f 0a 23 interfaces..*/.#
34f0: 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
3500: 45 5f 46 4f 52 43 45 5f 4f 53 5f 54 52 41 43 45 E_FORCE_OS_TRACE
3510: 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c ) || defined(SQL
3520: 49 54 45 5f 54 45 53 54 29 20 7c 7c 20 5c 0a 20 ITE_TEST) || \.
3530: 20 20 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 (defined(SQLI
3540: 54 45 5f 44 45 42 55 47 29 20 26 26 20 53 51 4c TE_DEBUG) && SQL
3550: 49 54 45 5f 4f 53 5f 57 49 4e 29 0a 20 20 65 78 ITE_OS_WIN). ex
3560: 74 65 72 6e 20 69 6e 74 20 73 71 6c 69 74 65 33 tern int sqlite3
3570: 4f 53 54 72 61 63 65 3b 0a 23 20 64 65 66 69 6e OSTrace;.# defin
3580: 65 20 4f 53 54 52 41 43 45 28 58 29 20 20 20 20 e OSTRACE(X)
3590: 20 20 20 20 20 20 69 66 28 20 73 71 6c 69 74 65 if( sqlite
35a0: 33 4f 53 54 72 61 63 65 20 29 20 73 71 6c 69 74 3OSTrace ) sqlit
35b0: 65 33 44 65 62 75 67 50 72 69 6e 74 66 20 58 0a e3DebugPrintf X.
35c0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
35d0: 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 0a 23 65 HAVE_OS_TRACE.#e
35e0: 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 4f 53 54 lse.# define OST
35f0: 52 41 43 45 28 58 29 0a 23 20 75 6e 64 65 66 20 RACE(X).# undef
3600: 20 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f SQLITE_HAVE_OS_
3610: 54 52 41 43 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a TRACE.#endif../*
3620: 0a 2a 2a 20 49 73 20 74 68 65 20 73 71 6c 69 74 .** Is the sqlit
3630: 65 33 45 72 72 4e 61 6d 65 28 29 20 66 75 6e 63 e3ErrName() func
3640: 74 69 6f 6e 20 6e 65 65 64 65 64 20 69 6e 20 74 tion needed in t
3650: 68 65 20 62 75 69 6c 64 3f 20 20 43 75 72 72 65 he build? Curre
3660: 6e 74 6c 79 2c 0a 2a 2a 20 69 74 20 69 73 20 6e ntly,.** it is n
3670: 65 65 64 65 64 20 62 79 20 22 6d 75 74 65 78 5f eeded by "mutex_
3680: 77 33 32 2e 63 22 20 28 77 68 65 6e 20 64 65 62 w32.c" (when deb
3690: 75 67 67 69 6e 67 29 2c 20 22 6f 73 5f 77 69 6e ugging), "os_win
36a0: 2e 63 22 20 28 77 68 65 6e 0a 2a 2a 20 4f 53 54 .c" (when.** OST
36b0: 52 41 43 45 20 69 73 20 65 6e 61 62 6c 65 64 29 RACE is enabled)
36c0: 2c 20 61 6e 64 20 62 79 20 73 65 76 65 72 61 6c , and by several
36d0: 20 22 74 65 73 74 2a 2e 63 22 20 66 69 6c 65 73 "test*.c" files
36e0: 20 28 77 68 69 63 68 20 61 72 65 0a 2a 2a 20 63 (which are.** c
36f0: 6f 6d 70 69 6c 65 64 20 75 73 69 6e 67 20 53 51 ompiled using SQ
3700: 4c 49 54 45 5f 54 45 53 54 29 2e 0a 2a 2f 0a 23 LITE_TEST)..*/.#
3710: 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
3720: 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 29 E_HAVE_OS_TRACE)
3730: 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 || defined(SQLI
3740: 54 45 5f 54 45 53 54 29 20 7c 7c 20 5c 0a 20 20 TE_TEST) || \.
3750: 20 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 (defined(SQLIT
3760: 45 5f 44 45 42 55 47 29 20 26 26 20 53 51 4c 49 E_DEBUG) && SQLI
3770: 54 45 5f 4f 53 5f 57 49 4e 29 0a 23 20 64 65 66 TE_OS_WIN).# def
3780: 69 6e 65 20 53 51 4c 49 54 45 5f 4e 45 45 44 5f ine SQLITE_NEED_
3790: 45 52 52 5f 4e 41 4d 45 0a 23 65 6c 73 65 0a 23 ERR_NAME.#else.#
37a0: 20 75 6e 64 65 66 20 20 53 51 4c 49 54 45 5f 4e undef SQLITE_N
37b0: 45 45 44 5f 45 52 52 5f 4e 41 4d 45 0a 23 65 6e EED_ERR_NAME.#en
37c0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 dif../*.** Retur
37d0: 6e 20 74 72 75 65 20 28 6e 6f 6e 2d 7a 65 72 6f n true (non-zero
37e0: 29 20 69 66 20 74 68 65 20 69 6e 70 75 74 20 69 ) if the input i
37f0: 73 20 61 6e 20 69 6e 74 65 67 65 72 20 74 68 61 s an integer tha
3800: 74 20 69 73 20 74 6f 6f 20 6c 61 72 67 65 0a 2a t is too large.*
3810: 2a 20 74 6f 20 66 69 74 20 69 6e 20 33 32 2d 62 * to fit in 32-b
3820: 69 74 73 2e 20 20 54 68 69 73 20 6d 61 63 72 6f its. This macro
3830: 20 69 73 20 75 73 65 64 20 69 6e 73 69 64 65 20 is used inside
3840: 6f 66 20 76 61 72 69 6f 75 73 20 74 65 73 74 63 of various testc
3850: 61 73 65 28 29 0a 2a 2a 20 6d 61 63 72 6f 73 20 ase().** macros
3860: 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 77 to verify that w
3870: 65 20 68 61 76 65 20 74 65 73 74 65 64 20 53 51 e have tested SQ
3880: 4c 69 74 65 20 66 6f 72 20 6c 61 72 67 65 2d 66 Lite for large-f
3890: 69 6c 65 20 73 75 70 70 6f 72 74 2e 0a 2a 2f 0a ile support..*/.
38a0: 23 64 65 66 69 6e 65 20 49 53 5f 42 49 47 5f 49 #define IS_BIG_I
38b0: 4e 54 28 58 29 20 20 28 28 28 58 29 26 7e 28 69 NT(X) (((X)&~(i
38c0: 36 34 29 30 78 66 66 66 66 66 66 66 66 29 21 3d 64)0xffffffff)!=
38d0: 30 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6d 61 0)../*.** The ma
38e0: 63 72 6f 20 75 6e 6c 69 6b 65 6c 79 28 29 20 69 cro unlikely() i
38f0: 73 20 61 20 68 69 6e 74 20 74 68 61 74 20 73 75 s a hint that su
3900: 72 72 6f 75 6e 64 73 20 61 20 62 6f 6f 6c 65 61 rrounds a boolea
3910: 6e 0a 2a 2a 20 65 78 70 72 65 73 73 69 6f 6e 20 n.** expression
3920: 74 68 61 74 20 69 73 20 75 73 75 61 6c 6c 79 20 that is usually
3930: 66 61 6c 73 65 2e 20 20 4d 61 63 72 6f 20 6c 69 false. Macro li
3940: 6b 65 6c 79 28 29 20 73 75 72 72 6f 75 6e 64 73 kely() surrounds
3950: 0a 2a 2a 20 61 20 62 6f 6f 6c 65 61 6e 20 65 78 .** a boolean ex
3960: 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 pression that is
3970: 20 75 73 75 61 6c 6c 79 20 74 72 75 65 2e 20 20 usually true.
3980: 54 68 65 73 65 20 68 69 6e 74 73 20 63 6f 75 6c These hints coul
3990: 64 2c 0a 2a 2a 20 69 6e 20 74 68 65 6f 72 79 2c d,.** in theory,
39a0: 20 62 65 20 75 73 65 64 20 62 79 20 74 68 65 20 be used by the
39b0: 63 6f 6d 70 69 6c 65 72 20 74 6f 20 67 65 6e 65 compiler to gene
39c0: 72 61 74 65 20 62 65 74 74 65 72 20 63 6f 64 65 rate better code
39d0: 2c 20 62 75 74 0a 2a 2a 20 63 75 72 72 65 6e 74 , but.** current
39e0: 6c 79 20 74 68 65 79 20 61 72 65 20 6a 75 73 74 ly they are just
39f0: 20 63 6f 6d 6d 65 6e 74 73 20 66 6f 72 20 68 75 comments for hu
3a00: 6d 61 6e 20 72 65 61 64 65 72 73 2e 0a 2a 2f 0a man readers..*/.
3a10: 23 64 65 66 69 6e 65 20 6c 69 6b 65 6c 79 28 58 #define likely(X
3a20: 29 20 20 20 20 28 58 29 0a 23 64 65 66 69 6e 65 ) (X).#define
3a30: 20 75 6e 6c 69 6b 65 6c 79 28 58 29 20 20 28 58 unlikely(X) (X
3a40: 29 0a 0a 23 69 6e 63 6c 75 64 65 20 22 68 61 73 )..#include "has
3a50: 68 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 h.h".#include "p
3a60: 61 72 73 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 arse.h".#include
3a70: 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c <stdio.h>.#incl
3a80: 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 ude <stdlib.h>.#
3a90: 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67 2e include <string.
3aa0: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 h>.#include <ass
3ab0: 65 72 74 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 ert.h>.#include
3ac0: 3c 73 74 64 64 65 66 2e 68 3e 0a 0a 2f 2a 0a 2a <stddef.h>../*.*
3ad0: 2a 20 49 66 20 63 6f 6d 70 69 6c 69 6e 67 20 66 * If compiling f
3ae0: 6f 72 20 61 20 70 72 6f 63 65 73 73 6f 72 20 74 or a processor t
3af0: 68 61 74 20 6c 61 63 6b 73 20 66 6c 6f 61 74 69 hat lacks floati
3b00: 6e 67 20 70 6f 69 6e 74 20 73 75 70 70 6f 72 74 ng point support
3b10: 2c 0a 2a 2a 20 73 75 62 73 74 69 74 75 74 65 20 ,.** substitute
3b20: 69 6e 74 65 67 65 72 20 66 6f 72 20 66 6c 6f 61 integer for floa
3b30: 74 69 6e 67 2d 70 6f 69 6e 74 0a 2a 2f 0a 23 69 ting-point.*/.#i
3b40: 66 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fdef SQLITE_OMIT
3b50: 5f 46 4c 4f 41 54 49 4e 47 5f 50 4f 49 4e 54 0a _FLOATING_POINT.
3b60: 23 20 64 65 66 69 6e 65 20 64 6f 75 62 6c 65 20 # define double
3b70: 73 71 6c 69 74 65 5f 69 6e 74 36 34 0a 23 20 64 sqlite_int64.# d
3b80: 65 66 69 6e 65 20 66 6c 6f 61 74 20 73 71 6c 69 efine float sqli
3b90: 74 65 5f 69 6e 74 36 34 0a 23 20 64 65 66 69 6e te_int64.# defin
3ba0: 65 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 e LONGDOUBLE_TYP
3bb0: 45 20 73 71 6c 69 74 65 5f 69 6e 74 36 34 0a 23 E sqlite_int64.#
3bc0: 20 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 42 ifndef SQLITE_B
3bd0: 49 47 5f 44 42 4c 0a 23 20 20 20 64 65 66 69 6e IG_DBL.# defin
3be0: 65 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c e SQLITE_BIG_DBL
3bf0: 20 28 28 28 73 71 6c 69 74 65 33 5f 69 6e 74 36 (((sqlite3_int6
3c00: 34 29 31 29 3c 3c 35 30 29 0a 23 20 65 6e 64 69 4)1)<<50).# endi
3c10: 66 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 f.# define SQLIT
3c20: 45 5f 4f 4d 49 54 5f 44 41 54 45 54 49 4d 45 5f E_OMIT_DATETIME_
3c30: 46 55 4e 43 53 20 31 0a 23 20 64 65 66 69 6e 65 FUNCS 1.# define
3c40: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 41 SQLITE_OMIT_TRA
3c50: 43 45 20 31 0a 23 20 75 6e 64 65 66 20 53 51 4c CE 1.# undef SQL
3c60: 49 54 45 5f 4d 49 58 45 44 5f 45 4e 44 49 41 4e ITE_MIXED_ENDIAN
3c70: 5f 36 34 42 49 54 5f 46 4c 4f 41 54 0a 23 20 75 _64BIT_FLOAT.# u
3c80: 6e 64 65 66 20 53 51 4c 49 54 45 5f 48 41 56 45 ndef SQLITE_HAVE
3c90: 5f 49 53 4e 41 4e 0a 23 65 6e 64 69 66 0a 23 69 _ISNAN.#endif.#i
3ca0: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 42 49 47 fndef SQLITE_BIG
3cb0: 5f 44 42 4c 0a 23 20 64 65 66 69 6e 65 20 53 51 _DBL.# define SQ
3cc0: 4c 49 54 45 5f 42 49 47 5f 44 42 4c 20 28 31 65 LITE_BIG_DBL (1e
3cd0: 39 39 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 99).#endif../*.*
3ce0: 2a 20 4f 4d 49 54 5f 54 45 4d 50 44 42 20 69 73 * OMIT_TEMPDB is
3cf0: 20 73 65 74 20 74 6f 20 31 20 69 66 20 53 51 4c set to 1 if SQL
3d00: 49 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 20 ITE_OMIT_TEMPDB
3d10: 69 73 20 64 65 66 69 6e 65 64 2c 20 6f 72 20 30 is defined, or 0
3d20: 0a 2a 2a 20 61 66 74 65 72 77 61 72 64 2e 20 48 .** afterward. H
3d30: 61 76 69 6e 67 20 74 68 69 73 20 6d 61 63 72 6f aving this macro
3d40: 20 61 6c 6c 6f 77 73 20 75 73 20 74 6f 20 63 61 allows us to ca
3d50: 75 73 65 20 74 68 65 20 43 20 63 6f 6d 70 69 6c use the C compil
3d60: 65 72 20 0a 2a 2a 20 74 6f 20 6f 6d 69 74 20 63 er .** to omit c
3d70: 6f 64 65 20 75 73 65 64 20 62 79 20 54 45 4d 50 ode used by TEMP
3d80: 20 74 61 62 6c 65 73 20 77 69 74 68 6f 75 74 20 tables without
3d90: 6d 65 73 73 79 20 23 69 66 6e 64 65 66 20 73 74 messy #ifndef st
3da0: 61 74 65 6d 65 6e 74 73 2e 0a 2a 2f 0a 23 69 66 atements..*/.#if
3db0: 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
3dc0: 54 45 4d 50 44 42 0a 23 64 65 66 69 6e 65 20 4f TEMPDB.#define O
3dd0: 4d 49 54 5f 54 45 4d 50 44 42 20 31 0a 23 65 6c MIT_TEMPDB 1.#el
3de0: 73 65 0a 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f se.#define OMIT_
3df0: 54 45 4d 50 44 42 20 30 0a 23 65 6e 64 69 66 0a TEMPDB 0.#endif.
3e00: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 22 66 69 6c 65 ./*.** The "file
3e10: 20 66 6f 72 6d 61 74 22 20 6e 75 6d 62 65 72 20 format" number
3e20: 69 73 20 61 6e 20 69 6e 74 65 67 65 72 20 74 68 is an integer th
3e30: 61 74 20 69 73 20 69 6e 63 72 65 6d 65 6e 74 65 at is incremente
3e40: 64 20 77 68 65 6e 65 76 65 72 0a 2a 2a 20 74 68 d whenever.** th
3e50: 65 20 56 44 42 45 2d 6c 65 76 65 6c 20 66 69 6c e VDBE-level fil
3e60: 65 20 66 6f 72 6d 61 74 20 63 68 61 6e 67 65 73 e format changes
3e70: 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 . The following
3e80: 20 6d 61 63 72 6f 73 20 64 65 66 69 6e 65 20 74 macros define t
3e90: 68 65 0a 2a 2a 20 74 68 65 20 64 65 66 61 75 6c he.** the defaul
3ea0: 74 20 66 69 6c 65 20 66 6f 72 6d 61 74 20 66 6f t file format fo
3eb0: 72 20 6e 65 77 20 64 61 74 61 62 61 73 65 73 20 r new databases
3ec0: 61 6e 64 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 and the maximum
3ed0: 66 69 6c 65 20 66 6f 72 6d 61 74 0a 2a 2a 20 74 file format.** t
3ee0: 68 61 74 20 74 68 65 20 6c 69 62 72 61 72 79 20 hat the library
3ef0: 63 61 6e 20 72 65 61 64 2e 0a 2a 2f 0a 23 64 65 can read..*/.#de
3f00: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
3f10: 46 49 4c 45 5f 46 4f 52 4d 41 54 20 34 0a 23 69 FILE_FORMAT 4.#i
3f20: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 fndef SQLITE_DEF
3f30: 41 55 4c 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 AULT_FILE_FORMAT
3f40: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
3f50: 5f 44 45 46 41 55 4c 54 5f 46 49 4c 45 5f 46 4f _DEFAULT_FILE_FO
3f60: 52 4d 41 54 20 34 0a 23 65 6e 64 69 66 0a 0a 2f RMAT 4.#endif../
3f70: 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 77 *.** Determine w
3f80: 68 65 74 68 65 72 20 74 72 69 67 67 65 72 73 20 hether triggers
3f90: 61 72 65 20 72 65 63 75 72 73 69 76 65 20 62 79 are recursive by
3fa0: 20 64 65 66 61 75 6c 74 2e 20 20 54 68 69 73 20 default. This
3fb0: 63 61 6e 20 62 65 0a 2a 2a 20 63 68 61 6e 67 65 can be.** change
3fc0: 64 20 61 74 20 72 75 6e 2d 74 69 6d 65 20 75 73 d at run-time us
3fd0: 69 6e 67 20 61 20 70 72 61 67 6d 61 2e 0a 2a 2f ing a pragma..*/
3fe0: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
3ff0: 44 45 46 41 55 4c 54 5f 52 45 43 55 52 53 49 56 DEFAULT_RECURSIV
4000: 45 5f 54 52 49 47 47 45 52 53 0a 23 20 64 65 66 E_TRIGGERS.# def
4010: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
4020: 4c 54 5f 52 45 43 55 52 53 49 56 45 5f 54 52 49 LT_RECURSIVE_TRI
4030: 47 47 45 52 53 20 30 0a 23 65 6e 64 69 66 0a 0a GGERS 0.#endif..
4040: 2f 2a 0a 2a 2a 20 50 72 6f 76 69 64 65 20 61 20 /*.** Provide a
4050: 64 65 66 61 75 6c 74 20 76 61 6c 75 65 20 66 6f default value fo
4060: 72 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 r SQLITE_TEMP_ST
4070: 4f 52 45 20 69 6e 20 63 61 73 65 20 69 74 20 69 ORE in case it i
4080: 73 20 6e 6f 74 20 73 70 65 63 69 66 69 65 64 0a s not specified.
4090: 2a 2a 20 6f 6e 20 74 68 65 20 63 6f 6d 6d 61 6e ** on the comman
40a0: 64 2d 6c 69 6e 65 0a 2a 2f 0a 23 69 66 6e 64 65 d-line.*/.#ifnde
40b0: 66 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 f SQLITE_TEMP_ST
40c0: 4f 52 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ORE.# define SQL
40d0: 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 31 ITE_TEMP_STORE 1
40e0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
40f0: 5f 54 45 4d 50 5f 53 54 4f 52 45 5f 78 63 20 31 _TEMP_STORE_xc 1
4100: 20 20 2f 2a 20 45 78 63 6c 75 64 65 20 66 72 6f /* Exclude fro
4110: 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 6e m ctime.c */.#en
4120: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 6e 6f dif../*.** If no
4130: 20 76 61 6c 75 65 20 68 61 73 20 62 65 65 6e 20 value has been
4140: 70 72 6f 76 69 64 65 64 20 66 6f 72 20 53 51 4c provided for SQL
4150: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
4160: 48 52 45 41 44 53 2c 20 6f 72 20 69 66 0a 2a 2a HREADS, or if.**
4170: 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f SQLITE_TEMP_STO
4180: 52 45 20 69 73 20 73 65 74 20 74 6f 20 33 20 28 RE is set to 3 (
4190: 6e 65 76 65 72 20 75 73 65 20 74 65 6d 70 6f 72 never use tempor
41a0: 61 72 79 20 66 69 6c 65 73 29 2c 20 73 65 74 20 ary files), set
41b0: 69 74 20 0a 2a 2a 20 74 6f 20 7a 65 72 6f 2e 0a it .** to zero..
41c0: 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 54 45 */.#if SQLITE_TE
41d0: 4d 50 5f 53 54 4f 52 45 3d 3d 33 20 7c 7c 20 53 MP_STORE==3 || S
41e0: 51 4c 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 QLITE_THREADSAFE
41f0: 3d 3d 30 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 ==0.# undef SQLI
4200: 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 TE_MAX_WORKER_TH
4210: 52 45 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 READS.# define S
4220: 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
4230: 5f 54 48 52 45 41 44 53 20 30 0a 23 65 6e 64 69 _THREADS 0.#endi
4240: 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 f.#ifndef SQLITE
4250: 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 _MAX_WORKER_THRE
4260: 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ADS.# define SQL
4270: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
4280: 48 52 45 41 44 53 20 38 0a 23 65 6e 64 69 66 0a HREADS 8.#endif.
4290: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 #ifndef SQLITE_D
42a0: 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 EFAULT_WORKER_TH
42b0: 52 45 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 READS.# define S
42c0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f QLITE_DEFAULT_WO
42d0: 52 4b 45 52 5f 54 48 52 45 41 44 53 20 30 0a 23 RKER_THREADS 0.#
42e0: 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 45 endif.#if SQLITE
42f0: 5f 44 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f _DEFAULT_WORKER_
4300: 54 48 52 45 41 44 53 3e 53 51 4c 49 54 45 5f 4d THREADS>SQLITE_M
4310: 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 AX_WORKER_THREAD
4320: 53 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 S.# undef SQLITE
4330: 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 _MAX_WORKER_THRE
4340: 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ADS.# define SQL
4350: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
4360: 48 52 45 41 44 53 20 53 51 4c 49 54 45 5f 44 45 HREADS SQLITE_DE
4370: 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 FAULT_WORKER_THR
4380: 45 41 44 53 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a EADS.#endif../*.
4390: 2a 2a 20 54 68 65 20 64 65 66 61 75 6c 74 20 69 ** The default i
43a0: 6e 69 74 69 61 6c 20 61 6c 6c 6f 63 61 74 69 6f nitial allocatio
43b0: 6e 20 66 6f 72 20 74 68 65 20 70 61 67 65 63 61 n for the pageca
43c0: 63 68 65 20 77 68 65 6e 20 75 73 69 6e 67 20 73 che when using s
43d0: 65 70 61 72 61 74 65 0a 2a 2a 20 70 61 67 65 63 eparate.** pagec
43e0: 61 63 68 65 73 20 66 6f 72 20 65 61 63 68 20 64 aches for each d
43f0: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
4400: 6f 6e 2e 20 20 41 20 70 6f 73 69 74 69 76 65 20 on. A positive
4410: 6e 75 6d 62 65 72 20 69 73 20 74 68 65 0a 2a 2a number is the.**
4420: 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 number of pages
4430: 2e 20 20 41 20 6e 65 67 61 74 69 76 65 20 6e 75 . A negative nu
4440: 6d 62 65 72 20 4e 20 74 72 61 6e 73 6c 61 74 69 mber N translati
4450: 6f 6e 73 20 6d 65 61 6e 73 20 74 68 61 74 20 61 ons means that a
4460: 20 62 75 66 66 65 72 0a 2a 2a 20 6f 66 20 2d 31 buffer.** of -1
4470: 30 32 34 2a 4e 20 62 79 74 65 73 20 69 73 20 61 024*N bytes is a
4480: 6c 6c 6f 63 61 74 65 64 20 61 6e 64 20 75 73 65 llocated and use
4490: 64 20 66 6f 72 20 61 73 20 6d 61 6e 79 20 70 61 d for as many pa
44a0: 67 65 73 20 61 73 20 69 74 20 77 69 6c 6c 20 68 ges as it will h
44b0: 6f 6c 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 old..*/.#ifndef
44c0: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 50 SQLITE_DEFAULT_P
44d0: 43 41 43 48 45 5f 49 4e 49 54 53 5a 0a 23 20 64 CACHE_INITSZ.# d
44e0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 efine SQLITE_DEF
44f0: 41 55 4c 54 5f 50 43 41 43 48 45 5f 49 4e 49 54 AULT_PCACHE_INIT
4500: 53 5a 20 31 30 30 0a 23 65 6e 64 69 66 0a 0a 0a SZ 100.#endif...
4510: 2f 2a 0a 2a 2a 20 47 43 43 20 64 6f 65 73 20 6e /*.** GCC does n
4520: 6f 74 20 64 65 66 69 6e 65 20 74 68 65 20 6f 66 ot define the of
4530: 66 73 65 74 6f 66 28 29 20 6d 61 63 72 6f 20 73 fsetof() macro s
4540: 6f 20 77 65 27 6c 6c 20 68 61 76 65 20 74 6f 20 o we'll have to
4550: 64 6f 20 69 74 0a 2a 2a 20 6f 75 72 73 65 6c 76 do it.** ourselv
4560: 65 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 6f es..*/.#ifndef o
4570: 66 66 73 65 74 6f 66 0a 23 64 65 66 69 6e 65 20 ffsetof.#define
4580: 6f 66 66 73 65 74 6f 66 28 53 54 52 55 43 54 55 offsetof(STRUCTU
4590: 52 45 2c 46 49 45 4c 44 29 20 28 28 69 6e 74 29 RE,FIELD) ((int)
45a0: 28 28 63 68 61 72 2a 29 26 28 28 53 54 52 55 43 ((char*)&((STRUC
45b0: 54 55 52 45 2a 29 30 29 2d 3e 46 49 45 4c 44 29 TURE*)0)->FIELD)
45c0: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
45d0: 4d 61 63 72 6f 73 20 74 6f 20 63 6f 6d 70 75 74 Macros to comput
45e0: 65 20 6d 69 6e 69 6d 75 6d 20 61 6e 64 20 6d 61 e minimum and ma
45f0: 78 69 6d 75 6d 20 6f 66 20 74 77 6f 20 6e 75 6d ximum of two num
4600: 62 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 bers..*/.#define
4610: 20 4d 49 4e 28 41 2c 42 29 20 28 28 41 29 3c 28 MIN(A,B) ((A)<(
4620: 42 29 3f 28 41 29 3a 28 42 29 29 0a 23 64 65 66 B)?(A):(B)).#def
4630: 69 6e 65 20 4d 41 58 28 41 2c 42 29 20 28 28 41 ine MAX(A,B) ((A
4640: 29 3e 28 42 29 3f 28 41 29 3a 28 42 29 29 0a 0a )>(B)?(A):(B))..
4650: 2f 2a 0a 2a 2a 20 53 77 61 70 20 74 77 6f 20 6f /*.** Swap two o
4660: 62 6a 65 63 74 73 20 6f 66 20 74 79 70 65 20 54 bjects of type T
4670: 59 50 45 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 YPE..*/.#define
4680: 53 57 41 50 28 54 59 50 45 2c 41 2c 42 29 20 7b SWAP(TYPE,A,B) {
4690: 54 59 50 45 20 74 3d 41 3b 20 41 3d 42 3b 20 42 TYPE t=A; A=B; B
46a0: 3d 74 3b 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63 =t;}../*.** Chec
46b0: 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68 69 73 k to see if this
46c0: 20 6d 61 63 68 69 6e 65 20 75 73 65 73 20 45 42 machine uses EB
46d0: 43 44 49 43 2e 20 20 28 59 65 73 2c 20 62 65 6c CDIC. (Yes, bel
46e0: 69 65 76 65 20 69 74 20 6f 72 0a 2a 2a 20 6e 6f ieve it or.** no
46f0: 74 2c 20 74 68 65 72 65 20 61 72 65 20 73 74 69 t, there are sti
4700: 6c 6c 20 6d 61 63 68 69 6e 65 73 20 6f 75 74 20 ll machines out
4710: 74 68 65 72 65 20 74 68 61 74 20 75 73 65 20 45 there that use E
4720: 42 43 44 49 43 2e 29 0a 2a 2f 0a 23 69 66 20 27 BCDIC.).*/.#if '
4730: 41 27 20 3d 3d 20 27 5c 33 30 31 27 0a 23 20 64 A' == '\301'.# d
4740: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 42 43 efine SQLITE_EBC
4750: 44 49 43 20 31 0a 23 65 6c 73 65 0a 23 20 64 65 DIC 1.#else.# de
4760: 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 53 43 49 fine SQLITE_ASCI
4770: 49 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a I 1.#endif../*.*
4780: 2a 20 49 6e 74 65 67 65 72 73 20 6f 66 20 6b 6e * Integers of kn
4790: 6f 77 6e 20 73 69 7a 65 73 2e 20 20 54 68 65 73 own sizes. Thes
47a0: 65 20 74 79 70 65 64 65 66 73 20 6d 69 67 68 74 e typedefs might
47b0: 20 63 68 61 6e 67 65 20 66 6f 72 20 61 72 63 68 change for arch
47c0: 69 74 65 63 74 75 72 65 73 0a 2a 2a 20 77 68 65 itectures.** whe
47d0: 72 65 20 74 68 65 20 73 69 7a 65 73 20 76 65 72 re the sizes ver
47e0: 79 2e 20 20 50 72 65 70 72 6f 63 65 73 73 6f 72 y. Preprocessor
47f0: 20 6d 61 63 72 6f 73 20 61 72 65 20 61 76 61 69 macros are avai
4800: 6c 61 62 6c 65 20 73 6f 20 74 68 61 74 20 74 68 lable so that th
4810: 65 0a 2a 2a 20 74 79 70 65 73 20 63 61 6e 20 62 e.** types can b
4820: 65 20 63 6f 6e 76 65 6e 69 65 6e 74 6c 79 20 72 e conveniently r
4830: 65 64 65 66 69 6e 65 64 20 61 74 20 63 6f 6d 70 edefined at comp
4840: 69 6c 65 2d 74 79 70 65 2e 20 20 4c 69 6b 65 20 ile-type. Like
4850: 74 68 69 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 this:.**.**
4860: 20 20 20 20 63 63 20 27 2d 44 55 49 4e 54 50 54 cc '-DUINTPT
4870: 52 5f 54 59 50 45 3d 6c 6f 6e 67 20 6c 6f 6e 67 R_TYPE=long long
4880: 20 69 6e 74 27 20 2e 2e 2e 0a 2a 2f 0a 23 69 66 int' ....*/.#if
4890: 6e 64 65 66 20 55 49 4e 54 33 32 5f 54 59 50 45 ndef UINT32_TYPE
48a0: 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f 55 49 .# ifdef HAVE_UI
48b0: 4e 54 33 32 5f 54 0a 23 20 20 64 65 66 69 6e 65 NT32_T.# define
48c0: 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 69 6e UINT32_TYPE uin
48d0: 74 33 32 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 t32_t.# else.#
48e0: 64 65 66 69 6e 65 20 55 49 4e 54 33 32 5f 54 59 define UINT32_TY
48f0: 50 45 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 0a PE unsigned int.
4900: 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 # endif.#endif.#
4910: 69 66 6e 64 65 66 20 55 49 4e 54 31 36 5f 54 59 ifndef UINT16_TY
4920: 50 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f PE.# ifdef HAVE_
4930: 55 49 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 69 UINT16_T.# defi
4940: 6e 65 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 ne UINT16_TYPE u
4950: 69 6e 74 31 36 5f 74 0a 23 20 65 6c 73 65 0a 23 int16_t.# else.#
4960: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 31 36 5f define UINT16_
4970: 54 59 50 45 20 75 6e 73 69 67 6e 65 64 20 73 68 TYPE unsigned sh
4980: 6f 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a ort int.# endif.
4990: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 #endif.#ifndef I
49a0: 4e 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 65 NT16_TYPE.# ifde
49b0: 66 20 48 41 56 45 5f 49 4e 54 31 36 5f 54 0a 23 f HAVE_INT16_T.#
49c0: 20 20 64 65 66 69 6e 65 20 49 4e 54 31 36 5f 54 define INT16_T
49d0: 59 50 45 20 69 6e 74 31 36 5f 74 0a 23 20 65 6c YPE int16_t.# el
49e0: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 se.# define INT
49f0: 31 36 5f 54 59 50 45 20 73 68 6f 72 74 20 69 6e 16_TYPE short in
4a00: 74 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 t.# endif.#endif
4a10: 0a 23 69 66 6e 64 65 66 20 55 49 4e 54 38 5f 54 .#ifndef UINT8_T
4a20: 59 50 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 YPE.# ifdef HAVE
4a30: 5f 55 49 4e 54 38 5f 54 0a 23 20 20 64 65 66 69 _UINT8_T.# defi
4a40: 6e 65 20 55 49 4e 54 38 5f 54 59 50 45 20 75 69 ne UINT8_TYPE ui
4a50: 6e 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 nt8_t.# else.#
4a60: 64 65 66 69 6e 65 20 55 49 4e 54 38 5f 54 59 50 define UINT8_TYP
4a70: 45 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 0a E unsigned char.
4a80: 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 # endif.#endif.#
4a90: 69 66 6e 64 65 66 20 49 4e 54 38 5f 54 59 50 45 ifndef INT8_TYPE
4aa0: 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 4e .# ifdef HAVE_IN
4ab0: 54 38 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 49 T8_T.# define I
4ac0: 4e 54 38 5f 54 59 50 45 20 69 6e 74 38 5f 74 0a NT8_TYPE int8_t.
4ad0: 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 # else.# define
4ae0: 20 49 4e 54 38 5f 54 59 50 45 20 73 69 67 6e 65 INT8_TYPE signe
4af0: 64 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a 23 d char.# endif.#
4b00: 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 4c 4f endif.#ifndef LO
4b10: 4e 47 44 4f 55 42 4c 45 5f 54 59 50 45 0a 23 20 NGDOUBLE_TYPE.#
4b20: 64 65 66 69 6e 65 20 4c 4f 4e 47 44 4f 55 42 4c define LONGDOUBL
4b30: 45 5f 54 59 50 45 20 6c 6f 6e 67 20 64 6f 75 62 E_TYPE long doub
4b40: 6c 65 0a 23 65 6e 64 69 66 0a 74 79 70 65 64 65 le.#endif.typede
4b50: 66 20 73 71 6c 69 74 65 5f 69 6e 74 36 34 20 69 f sqlite_int64 i
4b60: 36 34 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 64; /*
4b70: 38 2d 62 79 74 65 20 73 69 67 6e 65 64 20 69 6e 8-byte signed in
4b80: 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 teger */.typedef
4b90: 20 73 71 6c 69 74 65 5f 75 69 6e 74 36 34 20 75 sqlite_uint64 u
4ba0: 36 34 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 38 64; /* 8
4bb0: 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 69 -byte unsigned i
4bc0: 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 nteger */.typede
4bd0: 66 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 33 f UINT32_TYPE u3
4be0: 32 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 2; /*
4bf0: 34 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 4-byte unsigned
4c00: 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 integer */.typed
4c10: 65 66 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 ef UINT16_TYPE u
4c20: 31 36 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 16; /*
4c30: 20 32 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 2-byte unsigned
4c40: 20 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 integer */.type
4c50: 64 65 66 20 49 4e 54 31 36 5f 54 59 50 45 20 69 def INT16_TYPE i
4c60: 31 36 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 16; /
4c70: 2a 20 32 2d 62 79 74 65 20 73 69 67 6e 65 64 20 * 2-byte signed
4c80: 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 integer */.typed
4c90: 65 66 20 55 49 4e 54 38 5f 54 59 50 45 20 75 38 ef UINT8_TYPE u8
4ca0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
4cb0: 20 31 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 1-byte unsigned
4cc0: 20 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 integer */.type
4cd0: 64 65 66 20 49 4e 54 38 5f 54 59 50 45 20 69 38 def INT8_TYPE i8
4ce0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
4cf0: 2a 20 31 2d 62 79 74 65 20 73 69 67 6e 65 64 20 * 1-byte signed
4d00: 69 6e 74 65 67 65 72 20 2a 2f 0a 0a 2f 2a 0a 2a integer */../*.*
4d10: 2a 20 53 51 4c 49 54 45 5f 4d 41 58 5f 55 33 32 * SQLITE_MAX_U32
4d20: 20 69 73 20 61 20 75 36 34 20 63 6f 6e 73 74 61 is a u64 consta
4d30: 6e 74 20 74 68 61 74 20 69 73 20 74 68 65 20 6d nt that is the m
4d40: 61 78 69 6d 75 6d 20 75 36 34 20 76 61 6c 75 65 aximum u64 value
4d50: 0a 2a 2a 20 74 68 61 74 20 63 61 6e 20 62 65 20 .** that can be
4d60: 73 74 6f 72 65 64 20 69 6e 20 61 20 75 33 32 20 stored in a u32
4d70: 77 69 74 68 6f 75 74 20 6c 6f 73 73 20 6f 66 20 without loss of
4d80: 64 61 74 61 2e 20 20 54 68 65 20 76 61 6c 75 65 data. The value
4d90: 0a 2a 2a 20 69 73 20 30 78 30 30 30 30 30 30 30 .** is 0x0000000
4da0: 30 66 66 66 66 66 66 66 66 2e 20 20 42 75 74 20 0ffffffff. But
4db0: 62 65 63 61 75 73 65 20 6f 66 20 71 75 69 72 6b because of quirk
4dc0: 73 20 6f 66 20 73 6f 6d 65 20 63 6f 6d 70 69 6c s of some compil
4dd0: 65 72 73 2c 20 77 65 0a 2a 2a 20 68 61 76 65 20 ers, we.** have
4de0: 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 76 to specify the v
4df0: 61 6c 75 65 20 69 6e 20 74 68 65 20 6c 65 73 73 alue in the less
4e00: 20 69 6e 74 75 69 74 69 76 65 20 6d 61 6e 6e 65 intuitive manne
4e10: 72 20 73 68 6f 77 6e 3a 0a 2a 2f 0a 23 64 65 66 r shown:.*/.#def
4e20: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 55 ine SQLITE_MAX_U
4e30: 33 32 20 20 28 28 28 28 75 36 34 29 31 29 3c 3c 32 ((((u64)1)<<
4e40: 33 32 29 2d 31 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 32)-1)../*.** Th
4e50: 65 20 64 61 74 61 74 79 70 65 20 75 73 65 64 20 e datatype used
4e60: 74 6f 20 73 74 6f 72 65 20 65 73 74 69 6d 61 74 to store estimat
4e70: 65 73 20 6f 66 20 74 68 65 20 6e 75 6d 62 65 72 es of the number
4e80: 20 6f 66 20 72 6f 77 73 20 69 6e 20 61 0a 2a 2a of rows in a.**
4e90: 20 74 61 62 6c 65 20 6f 72 20 69 6e 64 65 78 2e table or index.
4ea0: 20 20 54 68 69 73 20 69 73 20 61 6e 20 75 6e 73 This is an uns
4eb0: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 74 79 igned integer ty
4ec0: 70 65 2e 20 20 46 6f 72 20 39 39 2e 39 25 20 6f pe. For 99.9% o
4ed0: 66 0a 2a 2a 20 74 68 65 20 77 6f 72 6c 64 2c 20 f.** the world,
4ee0: 61 20 33 32 2d 62 69 74 20 69 6e 74 65 67 65 72 a 32-bit integer
4ef0: 20 69 73 20 73 75 66 66 69 63 69 65 6e 74 2e 20 is sufficient.
4f00: 20 42 75 74 20 61 20 36 34 2d 62 69 74 20 69 6e But a 64-bit in
4f10: 74 65 67 65 72 0a 2a 2a 20 63 61 6e 20 62 65 20 teger.** can be
4f20: 75 73 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d used at compile-
4f30: 74 69 6d 65 20 69 66 20 64 65 73 69 72 65 64 2e time if desired.
4f40: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
4f50: 45 5f 36 34 42 49 54 5f 53 54 41 54 53 0a 20 74 E_64BIT_STATS. t
4f60: 79 70 65 64 65 66 20 75 36 34 20 74 52 6f 77 63 ypedef u64 tRowc
4f70: 6e 74 3b 20 20 20 20 2f 2a 20 36 34 2d 62 69 74 nt; /* 64-bit
4f80: 20 6f 6e 6c 79 20 69 66 20 72 65 71 75 65 73 74 only if request
4f90: 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 ed at compile-ti
4fa0: 6d 65 20 2a 2f 0a 23 65 6c 73 65 0a 20 74 79 70 me */.#else. typ
4fb0: 65 64 65 66 20 75 33 32 20 74 52 6f 77 63 6e 74 edef u32 tRowcnt
4fc0: 3b 20 20 20 20 2f 2a 20 33 32 2d 62 69 74 20 69 ; /* 32-bit i
4fd0: 73 20 74 68 65 20 64 65 66 61 75 6c 74 20 2a 2f s the default */
4fe0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 .#endif../*.** E
4ff0: 73 74 69 6d 61 74 65 64 20 71 75 61 6e 74 69 74 stimated quantit
5000: 69 65 73 20 75 73 65 64 20 66 6f 72 20 71 75 65 ies used for que
5010: 72 79 20 70 6c 61 6e 6e 69 6e 67 20 61 72 65 20 ry planning are
5020: 73 74 6f 72 65 64 20 61 73 20 31 36 2d 62 69 74 stored as 16-bit
5030: 0a 2a 2a 20 6c 6f 67 61 72 69 74 68 6d 73 2e 20 .** logarithms.
5040: 20 46 6f 72 20 71 75 61 6e 74 69 74 79 20 58 2c For quantity X,
5050: 20 74 68 65 20 76 61 6c 75 65 20 73 74 6f 72 65 the value store
5060: 64 20 69 73 20 31 30 2a 6c 6f 67 32 28 58 29 2e d is 10*log2(X).
5070: 20 20 54 68 69 73 0a 2a 2a 20 67 69 76 65 73 20 This.** gives
5080: 61 20 70 6f 73 73 69 62 6c 65 20 72 61 6e 67 65 a possible range
5090: 20 6f 66 20 76 61 6c 75 65 73 20 6f 66 20 61 70 of values of ap
50a0: 70 72 6f 78 69 6d 61 74 65 6c 79 20 31 2e 30 65 proximately 1.0e
50b0: 39 38 36 20 74 6f 20 31 65 2d 39 38 36 2e 0a 2a 986 to 1e-986..*
50c0: 2a 20 42 75 74 20 74 68 65 20 61 6c 6c 6f 77 65 * But the allowe
50d0: 64 20 76 61 6c 75 65 73 20 61 72 65 20 22 67 72 d values are "gr
50e0: 61 69 6e 79 22 2e 20 20 4e 6f 74 20 65 76 65 72 ainy". Not ever
50f0: 79 20 76 61 6c 75 65 20 69 73 20 72 65 70 72 65 y value is repre
5100: 73 65 6e 74 61 62 6c 65 2e 0a 2a 2a 20 46 6f 72 sentable..** For
5110: 20 65 78 61 6d 70 6c 65 2c 20 71 75 61 6e 74 69 example, quanti
5120: 74 69 65 73 20 31 36 20 61 6e 64 20 31 37 20 61 ties 16 and 17 a
5130: 72 65 20 62 6f 74 68 20 72 65 70 72 65 73 65 6e re both represen
5140: 74 65 64 20 62 79 20 61 20 4c 6f 67 45 73 74 0a ted by a LogEst.
5150: 2a 2a 20 6f 66 20 34 30 2e 20 20 48 6f 77 65 76 ** of 40. Howev
5160: 65 72 2c 20 73 69 6e 63 65 20 4c 6f 67 45 73 74 er, since LogEst
5170: 20 71 75 61 6e 74 69 74 69 65 73 20 61 72 65 20 quantities are
5180: 73 75 70 70 6f 73 65 20 74 6f 20 62 65 20 65 73 suppose to be es
5190: 74 69 6d 61 74 65 73 2c 0a 2a 2a 20 6e 6f 74 20 timates,.** not
51a0: 65 78 61 63 74 20 76 61 6c 75 65 73 2c 20 74 68 exact values, th
51b0: 69 73 20 69 6d 70 72 65 63 69 73 69 6f 6e 20 69 is imprecision i
51c0: 73 20 6e 6f 74 20 61 20 70 72 6f 62 6c 65 6d 2e s not a problem.
51d0: 0a 2a 2a 0a 2a 2a 20 22 4c 6f 67 45 73 74 22 20 .**.** "LogEst"
51e0: 69 73 20 73 68 6f 72 74 20 66 6f 72 20 22 4c 6f is short for "Lo
51f0: 67 61 72 69 74 68 6d 69 63 20 45 73 74 69 6d 61 garithmic Estima
5200: 74 65 22 2e 0a 2a 2a 0a 2a 2a 20 45 78 61 6d 70 te"..**.** Examp
5210: 6c 65 73 3a 0a 2a 2a 20 20 20 20 20 20 31 20 2d les:.** 1 -
5220: 3e 20 30 20 20 20 20 20 20 20 20 20 20 20 20 20 > 0
5230: 20 32 30 20 2d 3e 20 34 33 20 20 20 20 20 20 20 20 -> 43
5240: 20 20 20 31 30 30 30 30 20 2d 3e 20 31 33 32 0a 10000 -> 132.
5250: 2a 2a 20 20 20 20 20 20 32 20 2d 3e 20 31 30 20 ** 2 -> 10
5260: 20 20 20 20 20 20 20 20 20 20 20 20 32 35 20 2d 25 -
5270: 3e 20 34 36 20 20 20 20 20 20 20 20 20 20 32 35 > 46 25
5280: 30 30 30 20 2d 3e 20 31 34 36 0a 2a 2a 20 20 20 000 -> 146.**
5290: 20 20 20 33 20 2d 3e 20 31 36 20 20 20 20 20 20 3 -> 16
52a0: 20 20 20 20 20 20 31 30 30 20 2d 3e 20 36 36 20 100 -> 66
52b0: 20 20 20 20 20 20 20 31 30 30 30 30 30 30 20 2d 1000000 -
52c0: 3e 20 31 39 39 0a 2a 2a 20 20 20 20 20 20 34 20 > 199.** 4
52d0: 2d 3e 20 32 30 20 20 20 20 20 20 20 20 20 20 20 -> 20
52e0: 31 30 30 30 20 2d 3e 20 39 39 20 20 20 20 20 20 1000 -> 99
52f0: 20 20 31 30 34 38 35 37 36 20 2d 3e 20 32 30 30 1048576 -> 200
5300: 0a 2a 2a 20 20 20 20 20 31 30 20 2d 3e 20 33 33 .** 10 -> 33
5310: 20 20 20 20 20 20 20 20 20 20 20 31 30 32 34 20 1024
5320: 2d 3e 20 31 30 30 20 20 20 20 34 32 39 34 39 36 -> 100 429496
5330: 37 32 39 36 20 2d 3e 20 33 32 30 0a 2a 2a 0a 2a 7296 -> 320.**.*
5340: 2a 20 54 68 65 20 4c 6f 67 45 73 74 20 63 61 6e * The LogEst can
5350: 20 62 65 20 6e 65 67 61 74 69 76 65 20 74 6f 20 be negative to
5360: 69 6e 64 69 63 61 74 65 20 66 72 61 63 74 69 6f indicate fractio
5370: 6e 61 6c 20 76 61 6c 75 65 73 2e 20 0a 2a 2a 20 nal values. .**
5380: 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20 Examples:.**.**
5390: 20 20 20 30 2e 35 20 2d 3e 20 2d 31 30 20 20 20 0.5 -> -10
53a0: 20 20 20 20 20 20 20 20 30 2e 31 20 2d 3e 20 2d 0.1 -> -
53b0: 33 33 20 20 20 20 20 20 20 20 30 2e 30 36 32 35 33 0.0625
53c0: 20 2d 3e 20 2d 34 30 0a 2a 2f 0a 74 79 70 65 64 -> -40.*/.typed
53d0: 65 66 20 49 4e 54 31 36 5f 54 59 50 45 20 4c 6f ef INT16_TYPE Lo
53e0: 67 45 73 74 3b 0a 0a 2f 2a 0a 2a 2a 20 53 65 74 gEst;../*.** Set
53f0: 20 74 68 65 20 53 51 4c 49 54 45 5f 50 54 52 53 the SQLITE_PTRS
5400: 49 5a 45 20 6d 61 63 72 6f 20 74 6f 20 74 68 65 IZE macro to the
5410: 20 6e 75 6d 62 65 72 20 6f 66 20 62 79 74 65 73 number of bytes
5420: 20 69 6e 20 61 20 70 6f 69 6e 74 65 72 0a 2a 2f in a pointer.*/
5430: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
5440: 50 54 52 53 49 5a 45 0a 23 20 69 66 20 64 65 66 PTRSIZE.# if def
5450: 69 6e 65 64 28 5f 5f 53 49 5a 45 4f 46 5f 50 4f ined(__SIZEOF_PO
5460: 49 4e 54 45 52 5f 5f 29 0a 23 20 20 20 64 65 66 INTER__).# def
5470: 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 53 49 ine SQLITE_PTRSI
5480: 5a 45 20 5f 5f 53 49 5a 45 4f 46 5f 50 4f 49 4e ZE __SIZEOF_POIN
5490: 54 45 52 5f 5f 0a 23 20 65 6c 69 66 20 64 65 66 TER__.# elif def
54a0: 69 6e 65 64 28 69 33 38 36 29 20 20 20 20 20 7c ined(i386) |
54b0: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 69 33 38 36 | defined(__i386
54c0: 5f 5f 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 __) || defined
54d0: 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 20 20 20 (_M_IX86) ||
54e0: 5c 0a 20 20 20 20 20 20 20 64 65 66 69 6e 65 64 \. defined
54f0: 28 5f 4d 5f 41 52 4d 29 20 20 20 7c 7c 20 64 65 (_M_ARM) || de
5500: 66 69 6e 65 64 28 5f 5f 61 72 6d 5f 5f 29 20 20 fined(__arm__)
5510: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 78 || defined(__x
5520: 38 36 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 86).# define S
5530: 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 34 0a QLITE_PTRSIZE 4.
5540: 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e # else.# defin
5550: 65 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 e SQLITE_PTRSIZE
5560: 20 38 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 8.# endif.#endi
5570: 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 f../*.** Macros
5580: 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 77 68 65 to determine whe
5590: 74 68 65 72 20 74 68 65 20 6d 61 63 68 69 6e 65 ther the machine
55a0: 20 69 73 20 62 69 67 20 6f 72 20 6c 69 74 74 6c is big or littl
55b0: 65 20 65 6e 64 69 61 6e 2c 0a 2a 2a 20 61 6e 64 e endian,.** and
55c0: 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 whether or not
55d0: 74 68 61 74 20 64 65 74 65 72 6d 69 6e 61 74 69 that determinati
55e0: 6f 6e 20 69 73 20 72 75 6e 2d 74 69 6d 65 20 6f on is run-time o
55f0: 72 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 2e 0a r compile-time..
5600: 2a 2a 0a 2a 2a 20 46 6f 72 20 62 65 73 74 20 70 **.** For best p
5610: 65 72 66 6f 72 6d 61 6e 63 65 2c 20 61 6e 20 61 erformance, an a
5620: 74 74 65 6d 70 74 20 69 73 20 6d 61 64 65 20 74 ttempt is made t
5630: 6f 20 67 75 65 73 73 20 61 74 20 74 68 65 20 62 o guess at the b
5640: 79 74 65 2d 6f 72 64 65 72 0a 2a 2a 20 75 73 69 yte-order.** usi
5650: 6e 67 20 43 2d 70 72 65 70 72 6f 63 65 73 73 6f ng C-preprocesso
5660: 72 20 6d 61 63 72 6f 73 2e 20 20 49 66 20 74 68 r macros. If th
5670: 61 74 20 69 73 20 75 6e 73 75 63 63 65 73 73 66 at is unsuccessf
5680: 75 6c 2c 20 6f 72 20 69 66 0a 2a 2a 20 2d 44 53 ul, or if.** -DS
5690: 51 4c 49 54 45 5f 52 55 4e 54 49 4d 45 5f 42 59 QLITE_RUNTIME_BY
56a0: 54 45 4f 52 44 45 52 3d 31 20 69 73 20 73 65 74 TEORDER=1 is set
56b0: 2c 20 74 68 65 6e 20 62 79 74 65 2d 6f 72 64 65 , then byte-orde
56c0: 72 20 69 73 20 64 65 74 65 72 6d 69 6e 65 64 0a r is determined.
56d0: 2a 2a 20 61 74 20 72 75 6e 2d 74 69 6d 65 2e 0a ** at run-time..
56e0: 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
56f0: 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a 63 6f _AMALGAMATION.co
5700: 6e 73 74 20 69 6e 74 20 73 71 6c 69 74 65 33 6f nst int sqlite3o
5710: 6e 65 20 3d 20 31 3b 0a 23 65 6c 73 65 0a 65 78 ne = 1;.#else.ex
5720: 74 65 72 6e 20 63 6f 6e 73 74 20 69 6e 74 20 73 tern const int s
5730: 71 6c 69 74 65 33 6f 6e 65 3b 0a 23 65 6e 64 69 qlite3one;.#endi
5740: 66 0a 23 69 66 20 28 64 65 66 69 6e 65 64 28 69 f.#if (defined(i
5750: 33 38 36 29 20 20 20 20 20 7c 7c 20 64 65 66 69 386) || defi
5760: 6e 65 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 20 ned(__i386__)
5770: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 58 || defined(_M_IX
5780: 38 36 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 86) || \.
5790: 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 5f 36 defined(__x86_6
57a0: 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 4) || defined(__
57b0: 78 38 36 5f 36 34 5f 5f 29 20 7c 7c 20 64 65 66 x86_64__) || def
57c0: 69 6e 65 64 28 5f 4d 5f 58 36 34 29 20 20 7c 7c ined(_M_X64) ||
57d0: 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 6e \. defin
57e0: 65 64 28 5f 4d 5f 41 4d 44 36 34 29 20 7c 7c 20 ed(_M_AMD64) ||
57f0: 64 65 66 69 6e 65 64 28 5f 4d 5f 41 52 4d 29 20 defined(_M_ARM)
5800: 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f || defined(_
5810: 5f 78 38 36 29 20 20 20 7c 7c 20 20 20 20 5c 0a _x86) || \.
5820: 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 61 defined(__a
5830: 72 6d 5f 5f 29 29 20 26 26 20 21 64 65 66 69 6e rm__)) && !defin
5840: 65 64 28 53 51 4c 49 54 45 5f 52 55 4e 54 49 4d ed(SQLITE_RUNTIM
5850: 45 5f 42 59 54 45 4f 52 44 45 52 29 0a 23 20 64 E_BYTEORDER).# d
5860: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 59 54 efine SQLITE_BYT
5870: 45 4f 52 44 45 52 20 20 20 20 31 32 33 34 0a 23 EORDER 1234.#
5880: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 define SQLITE_B
5890: 49 47 45 4e 44 49 41 4e 20 20 20 20 30 0a 23 20 IGENDIAN 0.#
58a0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 49 define SQLITE_LI
58b0: 54 54 4c 45 45 4e 44 49 41 4e 20 31 0a 23 20 64 TTLEENDIAN 1.# d
58c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 55 54 46 efine SQLITE_UTF
58d0: 31 36 4e 41 54 49 56 45 20 20 53 51 4c 49 54 45 16NATIVE SQLITE
58e0: 5f 55 54 46 31 36 4c 45 0a 23 65 6e 64 69 66 0a _UTF16LE.#endif.
58f0: 23 69 66 20 28 64 65 66 69 6e 65 64 28 73 70 61 #if (defined(spa
5900: 72 63 29 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 rc) || define
5910: 64 28 5f 5f 70 70 63 5f 5f 29 29 20 20 5c 0a 20 d(__ppc__)) \.
5920: 20 20 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 && !defined(S
5930: 51 4c 49 54 45 5f 52 55 4e 54 49 4d 45 5f 42 59 QLITE_RUNTIME_BY
5940: 54 45 4f 52 44 45 52 29 0a 23 20 64 65 66 69 6e TEORDER).# defin
5950: 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 e SQLITE_BYTEORD
5960: 45 52 20 20 20 20 34 33 32 31 0a 23 20 64 65 66 ER 4321.# def
5970: 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 4e ine SQLITE_BIGEN
5980: 44 49 41 4e 20 20 20 20 31 0a 23 20 64 65 66 69 DIAN 1.# defi
5990: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
59a0: 45 4e 44 49 41 4e 20 30 0a 23 20 64 65 66 69 6e ENDIAN 0.# defin
59b0: 65 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 e SQLITE_UTF16NA
59c0: 54 49 56 45 20 20 53 51 4c 49 54 45 5f 55 54 46 TIVE SQLITE_UTF
59d0: 31 36 42 45 0a 23 65 6e 64 69 66 0a 23 69 66 20 16BE.#endif.#if
59e0: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
59f0: 42 59 54 45 4f 52 44 45 52 29 0a 23 20 64 65 66 BYTEORDER).# def
5a00: 69 6e 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f ine SQLITE_BYTEO
5a10: 52 44 45 52 20 20 20 20 30 20 20 20 20 20 2f 2a RDER 0 /*
5a20: 20 30 20 6d 65 61 6e 73 20 22 75 6e 6b 6e 6f 77 0 means "unknow
5a30: 6e 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d n at compile-tim
5a40: 65 22 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 e" */.# define S
5a50: 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 QLITE_BIGENDIAN
5a60: 20 20 20 28 2a 28 63 68 61 72 20 2a 29 28 26 73 (*(char *)(&s
5a70: 71 6c 69 74 65 33 6f 6e 65 29 3d 3d 30 29 0a 23 qlite3one)==0).#
5a80: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c define SQLITE_L
5a90: 49 54 54 4c 45 45 4e 44 49 41 4e 20 28 2a 28 63 ITTLEENDIAN (*(c
5aa0: 68 61 72 20 2a 29 28 26 73 71 6c 69 74 65 33 6f har *)(&sqlite3o
5ab0: 6e 65 29 3d 3d 31 29 0a 23 20 64 65 66 69 6e 65 ne)==1).# define
5ac0: 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 SQLITE_UTF16NAT
5ad0: 49 56 45 20 20 28 53 51 4c 49 54 45 5f 42 49 47 IVE (SQLITE_BIG
5ae0: 45 4e 44 49 41 4e 3f 53 51 4c 49 54 45 5f 55 54 ENDIAN?SQLITE_UT
5af0: 46 31 36 42 45 3a 53 51 4c 49 54 45 5f 55 54 46 F16BE:SQLITE_UTF
5b00: 31 36 4c 45 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 16LE).#endif../*
5b10: 0a 2a 2a 20 43 6f 6e 73 74 61 6e 74 73 20 66 6f .** Constants fo
5b20: 72 20 74 68 65 20 6c 61 72 67 65 73 74 20 61 6e r the largest an
5b30: 64 20 73 6d 61 6c 6c 65 73 74 20 70 6f 73 73 69 d smallest possi
5b40: 62 6c 65 20 36 34 2d 62 69 74 20 73 69 67 6e 65 ble 64-bit signe
5b50: 64 20 69 6e 74 65 67 65 72 73 2e 0a 2a 2a 20 54 d integers..** T
5b60: 68 65 73 65 20 6d 61 63 72 6f 73 20 61 72 65 20 hese macros are
5b70: 64 65 73 69 67 6e 65 64 20 74 6f 20 77 6f 72 6b designed to work
5b80: 20 63 6f 72 72 65 63 74 6c 79 20 6f 6e 20 62 6f correctly on bo
5b90: 74 68 20 33 32 2d 62 69 74 20 61 6e 64 20 36 34 th 32-bit and 64
5ba0: 2d 62 69 74 0a 2a 2a 20 63 6f 6d 70 69 6c 65 72 -bit.** compiler
5bb0: 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4c 41 s..*/.#define LA
5bc0: 52 47 45 53 54 5f 49 4e 54 36 34 20 20 28 30 78 RGEST_INT64 (0x
5bd0: 66 66 66 66 66 66 66 66 7c 28 28 28 69 36 34 29 ffffffff|(((i64)
5be0: 30 78 37 66 66 66 66 66 66 66 29 3c 3c 33 32 29 0x7fffffff)<<32)
5bf0: 29 0a 23 64 65 66 69 6e 65 20 53 4d 41 4c 4c 45 ).#define SMALLE
5c00: 53 54 5f 49 4e 54 36 34 20 28 28 28 69 36 34 29 ST_INT64 (((i64)
5c10: 2d 31 29 20 2d 20 4c 41 52 47 45 53 54 5f 49 4e -1) - LARGEST_IN
5c20: 54 36 34 29 0a 0a 2f 2a 20 0a 2a 2a 20 52 6f 75 T64)../* .** Rou
5c30: 6e 64 20 75 70 20 61 20 6e 75 6d 62 65 72 20 74 nd up a number t
5c40: 6f 20 74 68 65 20 6e 65 78 74 20 6c 61 72 67 65 o the next large
5c50: 72 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 38 2e r multiple of 8.
5c60: 20 20 54 68 69 73 20 69 73 20 75 73 65 64 0a 2a This is used.*
5c70: 2a 20 74 6f 20 66 6f 72 63 65 20 38 2d 62 79 74 * to force 8-byt
5c80: 65 20 61 6c 69 67 6e 6d 65 6e 74 20 6f 6e 20 36 e alignment on 6
5c90: 34 2d 62 69 74 20 61 72 63 68 69 74 65 63 74 75 4-bit architectu
5ca0: 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 res..*/.#define
5cb0: 52 4f 55 4e 44 38 28 78 29 20 20 20 20 20 28 28 ROUND8(x) ((
5cc0: 28 78 29 2b 37 29 26 7e 37 29 0a 0a 2f 2a 0a 2a (x)+7)&~7)../*.*
5cd0: 2a 20 52 6f 75 6e 64 20 64 6f 77 6e 20 74 6f 20 * Round down to
5ce0: 74 68 65 20 6e 65 61 72 65 73 74 20 6d 75 6c 74 the nearest mult
5cf0: 69 70 6c 65 20 6f 66 20 38 0a 2a 2f 0a 23 64 65 iple of 8.*/.#de
5d00: 66 69 6e 65 20 52 4f 55 4e 44 44 4f 57 4e 38 28 fine ROUNDDOWN8(
5d10: 78 29 20 28 28 78 29 26 7e 37 29 0a 0a 2f 2a 0a x) ((x)&~7)../*.
5d20: 2a 2a 20 41 73 73 65 72 74 20 74 68 61 74 20 74 ** Assert that t
5d30: 68 65 20 70 6f 69 6e 74 65 72 20 58 20 69 73 20 he pointer X is
5d40: 61 6c 69 67 6e 65 64 20 74 6f 20 61 6e 20 38 2d aligned to an 8-
5d50: 62 79 74 65 20 62 6f 75 6e 64 61 72 79 2e 20 20 byte boundary.
5d60: 54 68 69 73 0a 2a 2a 20 6d 61 63 72 6f 20 69 73 This.** macro is
5d70: 20 75 73 65 64 20 6f 6e 6c 79 20 77 69 74 68 69 used only withi
5d80: 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 76 65 n assert() to ve
5d90: 72 69 66 79 20 74 68 61 74 20 74 68 65 20 63 6f rify that the co
5da0: 64 65 20 67 65 74 73 0a 2a 2a 20 61 6c 6c 20 61 de gets.** all a
5db0: 6c 69 67 6e 6d 65 6e 74 20 72 65 73 74 72 69 63 lignment restric
5dc0: 74 69 6f 6e 73 20 63 6f 72 72 65 63 74 2e 0a 2a tions correct..*
5dd0: 2a 0a 2a 2a 20 45 78 63 65 70 74 2c 20 69 66 20 *.** Except, if
5de0: 53 51 4c 49 54 45 5f 34 5f 42 59 54 45 5f 41 4c SQLITE_4_BYTE_AL
5df0: 49 47 4e 45 44 5f 4d 41 4c 4c 4f 43 20 69 73 20 IGNED_MALLOC is
5e00: 64 65 66 69 6e 65 64 2c 20 74 68 65 6e 20 74 68 defined, then th
5e10: 65 0a 2a 2a 20 75 6e 64 65 72 6c 79 69 6e 67 20 e.** underlying
5e20: 6d 61 6c 6c 6f 63 28 29 20 69 6d 70 6c 65 6d 65 malloc() impleme
5e30: 6e 74 61 74 69 6f 6e 20 6d 69 67 68 74 20 72 65 ntation might re
5e40: 74 75 72 6e 20 75 73 20 34 2d 62 79 74 65 20 61 turn us 4-byte a
5e50: 6c 69 67 6e 65 64 0a 2a 2a 20 70 6f 69 6e 74 65 ligned.** pointe
5e60: 72 73 2e 20 20 49 6e 20 74 68 61 74 20 63 61 73 rs. In that cas
5e70: 65 2c 20 6f 6e 6c 79 20 76 65 72 69 66 79 20 34 e, only verify 4
5e80: 2d 62 79 74 65 20 61 6c 69 67 6e 6d 65 6e 74 2e -byte alignment.
5e90: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
5ea0: 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 E_4_BYTE_ALIGNED
5eb0: 5f 4d 41 4c 4c 4f 43 0a 23 20 64 65 66 69 6e 65 _MALLOC.# define
5ec0: 20 45 49 47 48 54 5f 42 59 54 45 5f 41 4c 49 47 EIGHT_BYTE_ALIG
5ed0: 4e 4d 45 4e 54 28 58 29 20 20 20 28 28 28 28 63 NMENT(X) ((((c
5ee0: 68 61 72 2a 29 28 58 29 20 2d 20 28 63 68 61 72 har*)(X) - (char
5ef0: 2a 29 30 29 26 33 29 3d 3d 30 29 0a 23 65 6c 73 *)0)&3)==0).#els
5f00: 65 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 54 e.# define EIGHT
5f10: 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 _BYTE_ALIGNMENT(
5f20: 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 28 X) ((((char*)(
5f30: 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 37 X) - (char*)0)&7
5f40: 29 3d 3d 30 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a )==0).#endif../*
5f50: 0a 2a 2a 20 44 69 73 61 62 6c 65 20 4d 4d 41 50 .** Disable MMAP
5f60: 20 6f 6e 20 70 6c 61 74 66 6f 72 6d 73 20 77 68 on platforms wh
5f70: 65 72 65 20 69 74 20 69 73 20 6b 6e 6f 77 6e 20 ere it is known
5f80: 74 6f 20 6e 6f 74 20 77 6f 72 6b 0a 2a 2f 0a 23 to not work.*/.#
5f90: 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 65 if defined(__Ope
5fa0: 6e 42 53 44 5f 5f 29 20 7c 7c 20 64 65 66 69 6e nBSD__) || defin
5fb0: 65 64 28 5f 5f 51 4e 58 4e 54 4f 5f 5f 29 0a 23 ed(__QNXNTO__).#
5fc0: 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 undef SQLITE_MA
5fd0: 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 X_MMAP_SIZE.# de
5fe0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
5ff0: 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 65 6e 64 MMAP_SIZE 0.#end
6000: 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 61 75 6c if../*.** Defaul
6010: 74 20 6d 61 78 69 6d 75 6d 20 73 69 7a 65 20 6f t maximum size o
6020: 66 20 6d 65 6d 6f 72 79 20 75 73 65 64 20 62 79 f memory used by
6030: 20 6d 65 6d 6f 72 79 2d 6d 61 70 70 65 64 20 49 memory-mapped I
6040: 2f 4f 20 69 6e 20 74 68 65 20 56 46 53 0a 2a 2f /O in the VFS.*/
6050: 0a 23 69 66 64 65 66 20 5f 5f 41 50 50 4c 45 5f .#ifdef __APPLE_
6060: 5f 0a 23 20 69 6e 63 6c 75 64 65 20 3c 54 61 72 _.# include <Tar
6070: 67 65 74 43 6f 6e 64 69 74 69 6f 6e 61 6c 73 2e getConditionals.
6080: 68 3e 0a 23 20 69 66 20 54 41 52 47 45 54 5f 4f h>.# if TARGET_O
6090: 53 5f 49 50 48 4f 4e 45 0a 23 20 20 20 75 6e 64 S_IPHONE.# und
60a0: 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ef SQLITE_MAX_MM
60b0: 41 50 5f 53 49 5a 45 0a 23 20 20 20 64 65 66 69 AP_SIZE.# defi
60c0: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ne SQLITE_MAX_MM
60d0: 41 50 5f 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 AP_SIZE 0.# endi
60e0: 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 f.#endif.#ifndef
60f0: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
6100: 5f 53 49 5a 45 0a 23 20 69 66 20 64 65 66 69 6e _SIZE.# if defin
6110: 65 64 28 5f 5f 6c 69 6e 75 78 5f 5f 29 20 5c 0a ed(__linux__) \.
6120: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 57 49 || defined(_WI
6130: 4e 33 32 29 20 5c 0a 20 20 7c 7c 20 28 64 65 66 N32) \. || (def
6140: 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 20 ined(__APPLE__)
6150: 26 26 20 64 65 66 69 6e 65 64 28 5f 5f 4d 41 43 && defined(__MAC
6160: 48 5f 5f 29 29 20 5c 0a 20 20 7c 7c 20 64 65 66 H__)) \. || def
6170: 69 6e 65 64 28 5f 5f 73 75 6e 29 20 5c 0a 20 20 ined(__sun) \.
6180: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 46 72 65 || defined(__Fre
6190: 65 42 53 44 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 eBSD__) \. || d
61a0: 65 66 69 6e 65 64 28 5f 5f 44 72 61 67 6f 6e 46 efined(__DragonF
61b0: 6c 79 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e 65 ly__).# define
61c0: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
61d0: 5f 53 49 5a 45 20 30 78 37 66 66 66 30 30 30 30 _SIZE 0x7fff0000
61e0: 20 20 2f 2a 20 32 31 34 37 34 31 38 31 31 32 20 /* 2147418112
61f0: 2a 2f 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 */.# else.# de
6200: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
6210: 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 65 6e MMAP_SIZE 0.# en
6220: 64 69 66 0a 23 20 64 65 66 69 6e 65 20 53 51 4c dif.# define SQL
6230: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
6240: 45 5f 78 63 20 31 20 2f 2a 20 65 78 63 6c 75 64 E_xc 1 /* exclud
6250: 65 20 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a e from ctime.c *
6260: 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 /.#endif../*.**
6270: 54 68 65 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 The default MMAP
6280: 5f 53 49 5a 45 20 69 73 20 7a 65 72 6f 20 6f 6e _SIZE is zero on
6290: 20 61 6c 6c 20 70 6c 61 74 66 6f 72 6d 73 2e 20 all platforms.
62a0: 20 4f 72 2c 20 65 76 65 6e 20 69 66 20 61 20 6c Or, even if a l
62b0: 61 72 67 65 72 0a 2a 2a 20 64 65 66 61 75 6c 74 arger.** default
62c0: 20 4d 4d 41 50 5f 53 49 5a 45 20 69 73 20 73 70 MMAP_SIZE is sp
62d0: 65 63 69 66 69 65 64 20 61 74 20 63 6f 6d 70 69 ecified at compi
62e0: 6c 65 2d 74 69 6d 65 2c 20 6d 61 6b 65 20 73 75 le-time, make su
62f0: 72 65 20 74 68 61 74 20 69 74 20 64 6f 65 73 0a re that it does.
6300: 2a 2a 20 6e 6f 74 20 65 78 63 65 65 64 20 74 68 ** not exceed th
6310: 65 20 6d 61 78 69 6d 75 6d 20 6d 6d 61 70 20 73 e maximum mmap s
6320: 69 7a 65 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 ize..*/.#ifndef
6330: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
6340: 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e MAP_SIZE.# defin
6350: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
6360: 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 64 _MMAP_SIZE 0.# d
6370: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 efine SQLITE_DEF
6380: 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 AULT_MMAP_SIZE_x
6390: 63 20 31 20 20 2f 2a 20 45 78 63 6c 75 64 65 20 c 1 /* Exclude
63a0: 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a from ctime.c */.
63b0: 23 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 #endif.#if SQLIT
63c0: 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 E_DEFAULT_MMAP_S
63d0: 49 5a 45 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 4d IZE>SQLITE_MAX_M
63e0: 4d 41 50 5f 53 49 5a 45 0a 23 20 75 6e 64 65 66 MAP_SIZE.# undef
63f0: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
6400: 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 MMAP_SIZE.# defi
6410: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
6420: 54 5f 4d 4d 41 50 5f 53 49 5a 45 20 53 51 4c 49 T_MMAP_SIZE SQLI
6430: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
6440: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f .#endif../*.** O
6450: 6e 6c 79 20 6f 6e 65 20 6f 66 20 53 51 4c 49 54 nly one of SQLIT
6460: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 20 6f E_ENABLE_STAT3 o
6470: 72 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f r SQLITE_ENABLE_
6480: 53 54 41 54 34 20 63 61 6e 20 62 65 20 64 65 66 STAT4 can be def
6490: 69 6e 65 64 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 ined..** Priorit
64a0: 79 20 69 73 20 67 69 76 65 6e 20 74 6f 20 53 51 y is given to SQ
64b0: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
64c0: 34 2e 20 20 49 66 20 65 69 74 68 65 72 20 61 72 4. If either ar
64d0: 65 20 64 65 66 69 6e 65 64 2c 20 61 6c 73 6f 0a e defined, also.
64e0: 2a 2a 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 ** define SQLITE
64f0: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
6500: 5f 53 54 41 54 34 0a 2a 2f 0a 23 69 66 64 65 66 _STAT4.*/.#ifdef
6510: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
6520: 54 41 54 34 0a 23 20 75 6e 64 65 66 20 53 51 4c TAT4.# undef SQL
6530: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
6540: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
6550: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
6560: 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 _STAT4 1.#elif S
6570: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 QLITE_ENABLE_STA
6580: 54 33 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 T3.# define SQLI
6590: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f TE_ENABLE_STAT3_
65a0: 4f 52 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 OR_STAT4 1.#elif
65b0: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
65c0: 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 20 TAT3_OR_STAT4.#
65d0: 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 undef SQLITE_ENA
65e0: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
65f0: 54 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a T4.#endif../*.**
6600: 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 SELECTTRACE_ENA
6610: 42 4c 45 44 20 77 69 6c 6c 20 62 65 20 65 69 74 BLED will be eit
6620: 68 65 72 20 31 20 6f 72 20 30 20 64 65 70 65 6e her 1 or 0 depen
6630: 64 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 20 ding on whether
6640: 6f 72 20 6e 6f 74 0a 2a 2a 20 74 68 65 20 53 65 or not.** the Se
6650: 6c 65 63 74 20 71 75 65 72 79 20 67 65 6e 65 72 lect query gener
6660: 61 74 6f 72 20 74 72 61 63 69 6e 67 20 6c 6f 67 ator tracing log
6670: 69 63 20 69 73 20 74 75 72 6e 65 64 20 6f 6e 2e ic is turned on.
6680: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
6690: 53 51 4c 49 54 45 5f 44 45 42 55 47 29 20 7c 7c SQLITE_DEBUG) ||
66a0: 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
66b0: 45 4e 41 42 4c 45 5f 53 45 4c 45 43 54 54 52 41 ENABLE_SELECTTRA
66c0: 43 45 29 0a 23 20 64 65 66 69 6e 65 20 53 45 4c CE).# define SEL
66d0: 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 ECTTRACE_ENABLED
66e0: 20 31 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 1.#else.# defin
66f0: 65 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e e SELECTTRACE_EN
6700: 41 42 4c 45 44 20 30 0a 23 65 6e 64 69 66 0a 0a ABLED 0.#endif..
6710: 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
6720: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
6730: 6e 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 ng structure is
6740: 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 used to store th
6750: 65 20 62 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a e busy-handler.*
6760: 2a 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 61 * callback for a
6770: 20 67 69 76 65 6e 20 73 71 6c 69 74 65 20 68 61 given sqlite ha
6780: 6e 64 6c 65 2e 20 0a 2a 2a 0a 2a 2a 20 54 68 65 ndle. .**.** The
6790: 20 73 71 6c 69 74 65 2e 62 75 73 79 48 61 6e 64 sqlite.busyHand
67a0: 6c 65 72 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 ler member of th
67b0: 65 20 73 71 6c 69 74 65 20 73 74 72 75 63 74 20 e sqlite struct
67c0: 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 62 75 73 contains the bus
67d0: 79 0a 2a 2a 20 63 61 6c 6c 62 61 63 6b 20 66 6f y.** callback fo
67e0: 72 20 74 68 65 20 64 61 74 61 62 61 73 65 20 68 r the database h
67f0: 61 6e 64 6c 65 2e 20 45 61 63 68 20 70 61 67 65 andle. Each page
6800: 72 20 6f 70 65 6e 65 64 20 76 69 61 20 74 68 65 r opened via the
6810: 20 73 71 6c 69 74 65 0a 2a 2a 20 68 61 6e 64 6c sqlite.** handl
6820: 65 20 69 73 20 70 61 73 73 65 64 20 61 20 70 6f e is passed a po
6830: 69 6e 74 65 72 20 74 6f 20 73 71 6c 69 74 65 2e inter to sqlite.
6840: 62 75 73 79 48 61 6e 64 6c 65 72 2e 20 54 68 65 busyHandler. The
6850: 20 62 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a busy-handler.**
6860: 20 63 61 6c 6c 62 61 63 6b 20 69 73 20 63 75 72 callback is cur
6870: 72 65 6e 74 6c 79 20 69 6e 76 6f 6b 65 64 20 6f rently invoked o
6880: 6e 6c 79 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 nly from within
6890: 70 61 67 65 72 2e 63 2e 0a 2a 2f 0a 74 79 70 65 pager.c..*/.type
68a0: 64 65 66 20 73 74 72 75 63 74 20 42 75 73 79 48 def struct BusyH
68b0: 61 6e 64 6c 65 72 20 42 75 73 79 48 61 6e 64 6c andler BusyHandl
68c0: 65 72 3b 0a 73 74 72 75 63 74 20 42 75 73 79 48 er;.struct BusyH
68d0: 61 6e 64 6c 65 72 20 7b 0a 20 20 69 6e 74 20 28 andler {. int (
68e0: 2a 78 46 75 6e 63 29 28 76 6f 69 64 20 2a 2c 69 *xFunc)(void *,i
68f0: 6e 74 29 3b 20 20 2f 2a 20 54 68 65 20 62 75 73 nt); /* The bus
6900: 79 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 y callback */.
6910: 76 6f 69 64 20 2a 70 41 72 67 3b 20 20 20 20 20 void *pArg;
6920: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 /* Fi
6930: 72 73 74 20 61 72 67 20 74 6f 20 62 75 73 79 20 rst arg to busy
6940: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 69 6e callback */. in
6950: 74 20 6e 42 75 73 79 3b 20 20 20 20 20 20 20 20 t nBusy;
6960: 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 63 72 /* Incr
6970: 65 6d 65 6e 74 65 64 20 77 69 74 68 20 65 61 63 emented with eac
6980: 68 20 62 75 73 79 20 63 61 6c 6c 20 2a 2f 0a 7d h busy call */.}
6990: 3b 0a 0a 2f 2a 0a 2a 2a 20 4e 61 6d 65 20 6f 66 ;../*.** Name of
69a0: 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 74 61 the master data
69b0: 62 61 73 65 20 74 61 62 6c 65 2e 20 20 54 68 65 base table. The
69c0: 20 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 master database
69d0: 20 74 61 62 6c 65 0a 2a 2a 20 69 73 20 61 20 73 table.** is a s
69e0: 70 65 63 69 61 6c 20 74 61 62 6c 65 20 74 68 61 pecial table tha
69f0: 74 20 68 6f 6c 64 73 20 74 68 65 20 6e 61 6d 65 t holds the name
6a00: 73 20 61 6e 64 20 61 74 74 72 69 62 75 74 65 73 s and attributes
6a10: 20 6f 66 20 61 6c 6c 0a 2a 2a 20 75 73 65 72 20 of all.** user
6a20: 74 61 62 6c 65 73 20 61 6e 64 20 69 6e 64 69 63 tables and indic
6a30: 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d es..*/.#define M
6a40: 41 53 54 45 52 5f 4e 41 4d 45 20 20 20 20 20 20 ASTER_NAME
6a50: 20 22 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 22 "sqlite_master"
6a60: 0a 23 64 65 66 69 6e 65 20 54 45 4d 50 5f 4d 41 .#define TEMP_MA
6a70: 53 54 45 52 5f 4e 41 4d 45 20 20 22 73 71 6c 69 STER_NAME "sqli
6a80: 74 65 5f 74 65 6d 70 5f 6d 61 73 74 65 72 22 0a te_temp_master".
6a90: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 72 6f 6f 74 2d ./*.** The root-
6aa0: 70 61 67 65 20 6f 66 20 74 68 65 20 6d 61 73 74 page of the mast
6ab0: 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 6c er database tabl
6ac0: 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 e..*/.#define MA
6ad0: 53 54 45 52 5f 52 4f 4f 54 20 20 20 20 20 20 20 STER_ROOT
6ae0: 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 61 6d 1../*.** The nam
6af0: 65 20 6f 66 20 74 68 65 20 73 63 68 65 6d 61 20 e of the schema
6b00: 74 61 62 6c 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e table..*/.#defin
6b10: 65 20 53 43 48 45 4d 41 5f 54 41 42 4c 45 28 78 e SCHEMA_TABLE(x
6b20: 29 20 20 28 28 21 4f 4d 49 54 5f 54 45 4d 50 44 ) ((!OMIT_TEMPD
6b30: 42 29 26 26 28 78 3d 3d 31 29 3f 54 45 4d 50 5f B)&&(x==1)?TEMP_
6b40: 4d 41 53 54 45 52 5f 4e 41 4d 45 3a 4d 41 53 54 MASTER_NAME:MAST
6b50: 45 52 5f 4e 41 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 ER_NAME)../*.**
6b60: 41 20 63 6f 6e 76 65 6e 69 65 6e 63 65 20 6d 61 A convenience ma
6b70: 63 72 6f 20 74 68 61 74 20 72 65 74 75 72 6e 73 cro that returns
6b80: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 65 the number of e
6b90: 6c 65 6d 65 6e 74 73 20 69 6e 0a 2a 2a 20 61 6e lements in.** an
6ba0: 20 61 72 72 61 79 2e 0a 2a 2f 0a 23 64 65 66 69 array..*/.#defi
6bb0: 6e 65 20 41 72 72 61 79 53 69 7a 65 28 58 29 20 ne ArraySize(X)
6bc0: 20 20 20 28 28 69 6e 74 29 28 73 69 7a 65 6f 66 ((int)(sizeof
6bd0: 28 58 29 2f 73 69 7a 65 6f 66 28 58 5b 30 5d 29 (X)/sizeof(X[0])
6be0: 29 29 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 65 72 6d ))../*.** Determ
6bf0: 69 6e 65 20 69 66 20 74 68 65 20 61 72 67 75 6d ine if the argum
6c00: 65 6e 74 20 69 73 20 61 20 70 6f 77 65 72 20 6f ent is a power o
6c10: 66 20 74 77 6f 0a 2a 2f 0a 23 64 65 66 69 6e 65 f two.*/.#define
6c20: 20 49 73 50 6f 77 65 72 4f 66 54 77 6f 28 58 29 IsPowerOfTwo(X)
6c30: 20 28 28 28 58 29 26 28 28 58 29 2d 31 29 29 3d (((X)&((X)-1))=
6c40: 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 =0)../*.** The f
6c50: 6f 6c 6c 6f 77 69 6e 67 20 76 61 6c 75 65 20 61 ollowing value a
6c60: 73 20 61 20 64 65 73 74 72 75 63 74 6f 72 20 6d s a destructor m
6c70: 65 61 6e 73 20 74 6f 20 75 73 65 20 73 71 6c 69 eans to use sqli
6c80: 74 65 33 44 62 46 72 65 65 28 29 2e 0a 2a 2a 20 te3DbFree()..**
6c90: 54 68 65 20 73 71 6c 69 74 65 33 44 62 46 72 65 The sqlite3DbFre
6ca0: 65 28 29 20 72 6f 75 74 69 6e 65 20 72 65 71 75 e() routine requ
6cb0: 69 72 65 73 20 74 77 6f 20 70 61 72 61 6d 65 74 ires two paramet
6cc0: 65 72 73 20 69 6e 73 74 65 61 64 20 6f 66 20 74 ers instead of t
6cd0: 68 65 20 0a 2a 2a 20 6f 6e 65 20 70 61 72 61 6d he .** one param
6ce0: 65 74 65 72 20 74 68 61 74 20 64 65 73 74 72 75 eter that destru
6cf0: 63 74 6f 72 73 20 6e 6f 72 6d 61 6c 6c 79 20 77 ctors normally w
6d00: 61 6e 74 2e 20 20 53 6f 20 77 65 20 68 61 76 65 ant. So we have
6d10: 20 74 6f 20 69 6e 74 72 6f 64 75 63 65 20 0a 2a to introduce .*
6d20: 2a 20 74 68 69 73 20 6d 61 67 69 63 20 76 61 6c * this magic val
6d30: 75 65 20 74 68 61 74 20 74 68 65 20 63 6f 64 65 ue that the code
6d40: 20 6b 6e 6f 77 73 20 74 6f 20 68 61 6e 64 6c 65 knows to handle
6d50: 20 64 69 66 66 65 72 65 6e 74 6c 79 2e 20 20 41 differently. A
6d60: 6e 79 20 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 77 ny .** pointer w
6d70: 69 6c 6c 20 77 6f 72 6b 20 68 65 72 65 20 61 73 ill work here as
6d80: 20 6c 6f 6e 67 20 61 73 20 69 74 20 69 73 20 64 long as it is d
6d90: 69 73 74 69 6e 63 74 20 66 72 6f 6d 20 53 51 4c istinct from SQL
6da0: 49 54 45 5f 53 54 41 54 49 43 0a 2a 2a 20 61 6e ITE_STATIC.** an
6db0: 64 20 53 51 4c 49 54 45 5f 54 52 41 4e 53 49 45 d SQLITE_TRANSIE
6dc0: 4e 54 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 NT..*/.#define S
6dd0: 51 4c 49 54 45 5f 44 59 4e 41 4d 49 43 20 20 20 QLITE_DYNAMIC
6de0: 28 28 73 71 6c 69 74 65 33 5f 64 65 73 74 72 75 ((sqlite3_destru
6df0: 63 74 6f 72 5f 74 79 70 65 29 73 71 6c 69 74 65 ctor_type)sqlite
6e00: 33 4d 61 6c 6c 6f 63 53 69 7a 65 29 0a 0a 2f 2a 3MallocSize)../*
6e10: 0a 2a 2a 20 57 68 65 6e 20 53 51 4c 49 54 45 5f .** When SQLITE_
6e20: 4f 4d 49 54 5f 57 53 44 20 69 73 20 64 65 66 69 OMIT_WSD is defi
6e30: 6e 65 64 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 ned, it means th
6e40: 61 74 20 74 68 65 20 74 61 72 67 65 74 20 70 6c at the target pl
6e50: 61 74 66 6f 72 6d 20 64 6f 65 73 0a 2a 2a 20 6e atform does.** n
6e60: 6f 74 20 73 75 70 70 6f 72 74 20 57 72 69 74 61 ot support Writa
6e70: 62 6c 65 20 53 74 61 74 69 63 20 44 61 74 61 20 ble Static Data
6e80: 28 57 53 44 29 20 73 75 63 68 20 61 73 20 67 6c (WSD) such as gl
6e90: 6f 62 61 6c 20 61 6e 64 20 73 74 61 74 69 63 20 obal and static
6ea0: 76 61 72 69 61 62 6c 65 73 2e 0a 2a 2a 20 41 6c variables..** Al
6eb0: 6c 20 76 61 72 69 61 62 6c 65 73 20 6d 75 73 74 l variables must
6ec0: 20 65 69 74 68 65 72 20 62 65 20 6f 6e 20 74 68 either be on th
6ed0: 65 20 73 74 61 63 6b 20 6f 72 20 64 79 6e 61 6d e stack or dynam
6ee0: 69 63 61 6c 6c 79 20 61 6c 6c 6f 63 61 74 65 64 ically allocated
6ef0: 20 66 72 6f 6d 0a 2a 2a 20 74 68 65 20 68 65 61 from.** the hea
6f00: 70 2e 20 20 57 68 65 6e 20 57 53 44 20 69 73 20 p. When WSD is
6f10: 75 6e 73 75 70 70 6f 72 74 65 64 2c 20 74 68 65 unsupported, the
6f20: 20 76 61 72 69 61 62 6c 65 20 64 65 63 6c 61 72 variable declar
6f30: 61 74 69 6f 6e 73 20 73 63 61 74 74 65 72 65 64 ations scattered
6f40: 0a 2a 2a 20 74 68 72 6f 75 67 68 6f 75 74 20 74 .** throughout t
6f50: 68 65 20 53 51 4c 69 74 65 20 63 6f 64 65 20 6d he SQLite code m
6f60: 75 73 74 20 62 65 63 6f 6d 65 20 63 6f 6e 73 74 ust become const
6f70: 61 6e 74 73 20 69 6e 73 74 65 61 64 2e 20 20 54 ants instead. T
6f80: 68 65 20 53 51 4c 49 54 45 5f 57 53 44 0a 2a 2a he SQLITE_WSD.**
6f90: 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 macro is used f
6fa0: 6f 72 20 74 68 69 73 20 70 75 72 70 6f 73 65 2e or this purpose.
6fb0: 20 20 41 6e 64 20 69 6e 73 74 65 61 64 20 6f 66 And instead of
6fc0: 20 72 65 66 65 72 65 6e 63 69 6e 67 20 74 68 65 referencing the
6fd0: 20 76 61 72 69 61 62 6c 65 0a 2a 2a 20 64 69 72 variable.** dir
6fe0: 65 63 74 6c 79 2c 20 77 65 20 75 73 65 20 69 74 ectly, we use it
6ff0: 73 20 63 6f 6e 73 74 61 6e 74 20 61 73 20 61 20 s constant as a
7000: 6b 65 79 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 key to lookup th
7010: 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 e run-time alloc
7020: 61 74 65 64 0a 2a 2a 20 62 75 66 66 65 72 20 74 ated.** buffer t
7030: 68 61 74 20 68 6f 6c 64 73 20 72 65 61 6c 20 76 hat holds real v
7040: 61 72 69 61 62 6c 65 2e 20 20 54 68 65 20 63 6f ariable. The co
7050: 6e 73 74 61 6e 74 20 69 73 20 61 6c 73 6f 20 74 nstant is also t
7060: 68 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 0a 2a he initializer.*
7070: 2a 20 66 6f 72 20 74 68 65 20 72 75 6e 2d 74 69 * for the run-ti
7080: 6d 65 20 61 6c 6c 6f 63 61 74 65 64 20 62 75 66 me allocated buf
7090: 66 65 72 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 fer..**.** In th
70a0: 65 20 75 73 75 61 6c 20 63 61 73 65 20 77 68 65 e usual case whe
70b0: 72 65 20 57 53 44 20 69 73 20 73 75 70 70 6f 72 re WSD is suppor
70c0: 74 65 64 2c 20 74 68 65 20 53 51 4c 49 54 45 5f ted, the SQLITE_
70d0: 57 53 44 20 61 6e 64 20 47 4c 4f 42 41 4c 0a 2a WSD and GLOBAL.*
70e0: 2a 20 6d 61 63 72 6f 73 20 62 65 63 6f 6d 65 20 * macros become
70f0: 6e 6f 2d 6f 70 73 20 61 6e 64 20 68 61 76 65 20 no-ops and have
7100: 7a 65 72 6f 20 70 65 72 66 6f 72 6d 61 6e 63 65 zero performance
7110: 20 69 6d 70 61 63 74 2e 0a 2a 2f 0a 23 69 66 64 impact..*/.#ifd
7120: 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 ef SQLITE_OMIT_W
7130: 53 44 0a 20 20 23 64 65 66 69 6e 65 20 53 51 4c SD. #define SQL
7140: 49 54 45 5f 57 53 44 20 63 6f 6e 73 74 0a 20 20 ITE_WSD const.
7150: 23 64 65 66 69 6e 65 20 47 4c 4f 42 41 4c 28 74 #define GLOBAL(t
7160: 2c 76 29 20 28 2a 28 74 2a 29 73 71 6c 69 74 65 ,v) (*(t*)sqlite
7170: 33 5f 77 73 64 5f 66 69 6e 64 28 28 76 6f 69 64 3_wsd_find((void
7180: 2a 29 26 28 76 29 2c 20 73 69 7a 65 6f 66 28 76 *)&(v), sizeof(v
7190: 29 29 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 ))). #define sq
71a0: 6c 69 74 65 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 lite3GlobalConfi
71b0: 67 20 47 4c 4f 42 41 4c 28 73 74 72 75 63 74 20 g GLOBAL(struct
71c0: 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 2c 20 73 Sqlite3Config, s
71d0: 71 6c 69 74 65 33 43 6f 6e 66 69 67 29 0a 20 20 qlite3Config).
71e0: 69 6e 74 20 73 71 6c 69 74 65 33 5f 77 73 64 5f int sqlite3_wsd_
71f0: 69 6e 69 74 28 69 6e 74 20 4e 2c 20 69 6e 74 20 init(int N, int
7200: 4a 29 3b 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 J);. void *sqli
7210: 74 65 33 5f 77 73 64 5f 66 69 6e 64 28 76 6f 69 te3_wsd_find(voi
7220: 64 20 2a 4b 2c 20 69 6e 74 20 4c 29 3b 0a 23 65 d *K, int L);.#e
7230: 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 53 51 lse. #define SQ
7240: 4c 49 54 45 5f 57 53 44 20 0a 20 20 23 64 65 66 LITE_WSD . #def
7250: 69 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 ine GLOBAL(t,v)
7260: 76 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 v. #define sqli
7270: 74 65 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 te3GlobalConfig
7280: 73 71 6c 69 74 65 33 43 6f 6e 66 69 67 0a 23 65 sqlite3Config.#e
7290: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
72a0: 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 following macros
72b0: 20 61 72 65 20 75 73 65 64 20 74 6f 20 73 75 70 are used to sup
72c0: 70 72 65 73 73 20 63 6f 6d 70 69 6c 65 72 20 77 press compiler w
72d0: 61 72 6e 69 6e 67 73 20 61 6e 64 20 74 6f 0a 2a arnings and to.*
72e0: 2a 20 6d 61 6b 65 20 69 74 20 63 6c 65 61 72 20 * make it clear
72f0: 74 6f 20 68 75 6d 61 6e 20 72 65 61 64 65 72 73 to human readers
7300: 20 77 68 65 6e 20 61 20 66 75 6e 63 74 69 6f 6e when a function
7310: 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 64 65 parameter is de
7320: 6c 69 62 65 72 61 74 65 6c 79 20 0a 2a 2a 20 6c liberately .** l
7330: 65 66 74 20 75 6e 75 73 65 64 20 77 69 74 68 69 eft unused withi
7340: 6e 20 74 68 65 20 62 6f 64 79 20 6f 66 20 61 20 n the body of a
7350: 66 75 6e 63 74 69 6f 6e 2e 20 54 68 69 73 20 75 function. This u
7360: 73 75 61 6c 6c 79 20 68 61 70 70 65 6e 73 20 77 sually happens w
7370: 68 65 6e 0a 2a 2a 20 61 20 66 75 6e 63 74 69 6f hen.** a functio
7380: 6e 20 69 73 20 63 61 6c 6c 65 64 20 76 69 61 20 n is called via
7390: 61 20 66 75 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 a function point
73a0: 65 72 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 20 er. For example
73b0: 74 68 65 20 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e the .** implemen
73c0: 74 61 74 69 6f 6e 20 6f 66 20 61 6e 20 53 51 4c tation of an SQL
73d0: 20 61 67 67 72 65 67 61 74 65 20 73 74 65 70 20 aggregate step
73e0: 63 61 6c 6c 62 61 63 6b 20 6d 61 79 20 6e 6f 74 callback may not
73f0: 20 75 73 65 20 74 68 65 0a 2a 2a 20 70 61 72 61 use the.** para
7400: 6d 65 74 65 72 20 69 6e 64 69 63 61 74 69 6e 67 meter indicating
7410: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 61 the number of a
7420: 72 67 75 6d 65 6e 74 73 20 70 61 73 73 65 64 20 rguments passed
7430: 74 6f 20 74 68 65 20 61 67 67 72 65 67 61 74 65 to the aggregate
7440: 2c 0a 2a 2a 20 69 66 20 69 74 20 6b 6e 6f 77 73 ,.** if it knows
7450: 20 74 68 61 74 20 74 68 69 73 20 69 73 20 65 6e that this is en
7460: 66 6f 72 63 65 64 20 65 6c 73 65 77 68 65 72 65 forced elsewhere
7470: 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 61 20 66 ..**.** When a f
7480: 75 6e 63 74 69 6f 6e 20 70 61 72 61 6d 65 74 65 unction paramete
7490: 72 20 69 73 20 6e 6f 74 20 75 73 65 64 20 61 74 r is not used at
74a0: 20 61 6c 6c 20 77 69 74 68 69 6e 20 74 68 65 20 all within the
74b0: 62 6f 64 79 20 6f 66 20 61 20 66 75 6e 63 74 69 body of a functi
74c0: 6f 6e 2c 0a 2a 2a 20 69 74 20 69 73 20 67 65 6e on,.** it is gen
74d0: 65 72 61 6c 6c 79 20 6e 61 6d 65 64 20 22 4e 6f erally named "No
74e0: 74 55 73 65 64 22 20 6f 72 20 22 4e 6f 74 55 73 tUsed" or "NotUs
74f0: 65 64 32 22 20 74 6f 20 6d 61 6b 65 20 74 68 69 ed2" to make thi
7500: 6e 67 73 20 65 76 65 6e 20 63 6c 65 61 72 65 72 ngs even clearer
7510: 2e 0a 2a 2a 20 48 6f 77 65 76 65 72 2c 20 74 68 ..** However, th
7520: 65 73 65 20 6d 61 63 72 6f 73 20 6d 61 79 20 61 ese macros may a
7530: 6c 73 6f 20 62 65 20 75 73 65 64 20 74 6f 20 73 lso be used to s
7540: 75 70 70 72 65 73 73 20 77 61 72 6e 69 6e 67 73 uppress warnings
7550: 20 72 65 6c 61 74 65 64 20 74 6f 0a 2a 2a 20 70 related to.** p
7560: 61 72 61 6d 65 74 65 72 73 20 74 68 61 74 20 6d arameters that m
7570: 61 79 20 6f 72 20 6d 61 79 20 6e 6f 74 20 62 65 ay or may not be
7580: 20 75 73 65 64 20 64 65 70 65 6e 64 69 6e 67 20 used depending
7590: 6f 6e 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 6f on compilation o
75a0: 70 74 69 6f 6e 73 2e 0a 2a 2a 20 46 6f 72 20 65 ptions..** For e
75b0: 78 61 6d 70 6c 65 20 74 68 6f 73 65 20 70 61 72 xample those par
75c0: 61 6d 65 74 65 72 73 20 6f 6e 6c 79 20 75 73 65 ameters only use
75d0: 64 20 69 6e 20 61 73 73 65 72 74 28 29 20 73 74 d in assert() st
75e0: 61 74 65 6d 65 6e 74 73 2e 20 49 6e 20 74 68 65 atements. In the
75f0: 73 65 0a 2a 2a 20 63 61 73 65 73 20 74 68 65 20 se.** cases the
7600: 70 61 72 61 6d 65 74 65 72 73 20 61 72 65 20 6e parameters are n
7610: 61 6d 65 64 20 61 73 20 70 65 72 20 74 68 65 20 amed as per the
7620: 75 73 75 61 6c 20 63 6f 6e 76 65 6e 74 69 6f 6e usual convention
7630: 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 55 4e s..*/.#define UN
7640: 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 28 78 USED_PARAMETER(x
7650: 29 20 28 76 6f 69 64 29 28 78 29 0a 23 64 65 66 ) (void)(x).#def
7660: 69 6e 65 20 55 4e 55 53 45 44 5f 50 41 52 41 4d ine UNUSED_PARAM
7670: 45 54 45 52 32 28 78 2c 79 29 20 55 4e 55 53 45 ETER2(x,y) UNUSE
7680: 44 5f 50 41 52 41 4d 45 54 45 52 28 78 29 2c 55 D_PARAMETER(x),U
7690: 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 28 NUSED_PARAMETER(
76a0: 79 29 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 77 61 72 y)../*.** Forwar
76b0: 64 20 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 d references to
76c0: 73 74 72 75 63 74 75 72 65 73 0a 2a 2f 0a 74 79 structures.*/.ty
76d0: 70 65 64 65 66 20 73 74 72 75 63 74 20 41 67 67 pedef struct Agg
76e0: 49 6e 66 6f 20 41 67 67 49 6e 66 6f 3b 0a 74 79 Info AggInfo;.ty
76f0: 70 65 64 65 66 20 73 74 72 75 63 74 20 41 75 74 pedef struct Aut
7700: 68 43 6f 6e 74 65 78 74 20 41 75 74 68 43 6f 6e hContext AuthCon
7710: 74 65 78 74 3b 0a 74 79 70 65 64 65 66 20 73 74 text;.typedef st
7720: 72 75 63 74 20 41 75 74 6f 69 6e 63 49 6e 66 6f ruct AutoincInfo
7730: 20 41 75 74 6f 69 6e 63 49 6e 66 6f 3b 0a 74 79 AutoincInfo;.ty
7740: 70 65 64 65 66 20 73 74 72 75 63 74 20 42 69 74 pedef struct Bit
7750: 76 65 63 20 42 69 74 76 65 63 3b 0a 74 79 70 65 vec Bitvec;.type
7760: 64 65 66 20 73 74 72 75 63 74 20 43 6f 6c 6c 53 def struct CollS
7770: 65 71 20 43 6f 6c 6c 53 65 71 3b 0a 74 79 70 65 eq CollSeq;.type
7780: 64 65 66 20 73 74 72 75 63 74 20 43 6f 6c 75 6d def struct Colum
7790: 6e 20 43 6f 6c 75 6d 6e 3b 0a 74 79 70 65 64 65 n Column;.typede
77a0: 66 20 73 74 72 75 63 74 20 44 62 20 44 62 3b 0a f struct Db Db;.
77b0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
77c0: 63 68 65 6d 61 20 53 63 68 65 6d 61 3b 0a 74 79 chema Schema;.ty
77d0: 70 65 64 65 66 20 73 74 72 75 63 74 20 45 78 70 pedef struct Exp
77e0: 72 20 45 78 70 72 3b 0a 74 79 70 65 64 65 66 20 r Expr;.typedef
77f0: 73 74 72 75 63 74 20 45 78 70 72 4c 69 73 74 20 struct ExprList
7800: 45 78 70 72 4c 69 73 74 3b 0a 74 79 70 65 64 65 ExprList;.typede
7810: 66 20 73 74 72 75 63 74 20 45 78 70 72 53 70 61 f struct ExprSpa
7820: 6e 20 45 78 70 72 53 70 61 6e 3b 0a 74 79 70 65 n ExprSpan;.type
7830: 64 65 66 20 73 74 72 75 63 74 20 46 4b 65 79 20 def struct FKey
7840: 46 4b 65 79 3b 0a 74 79 70 65 64 65 66 20 73 74 FKey;.typedef st
7850: 72 75 63 74 20 46 75 6e 63 44 65 73 74 72 75 63 ruct FuncDestruc
7860: 74 6f 72 20 46 75 6e 63 44 65 73 74 72 75 63 74 tor FuncDestruct
7870: 6f 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 or;.typedef stru
7880: 63 74 20 46 75 6e 63 44 65 66 20 46 75 6e 63 44 ct FuncDef FuncD
7890: 65 66 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ef;.typedef stru
78a0: 63 74 20 46 75 6e 63 44 65 66 48 61 73 68 20 46 ct FuncDefHash F
78b0: 75 6e 63 44 65 66 48 61 73 68 3b 0a 74 79 70 65 uncDefHash;.type
78c0: 64 65 66 20 73 74 72 75 63 74 20 49 64 4c 69 73 def struct IdLis
78d0: 74 20 49 64 4c 69 73 74 3b 0a 74 79 70 65 64 65 t IdList;.typede
78e0: 66 20 73 74 72 75 63 74 20 49 6e 64 65 78 20 49 f struct Index I
78f0: 6e 64 65 78 3b 0a 74 79 70 65 64 65 66 20 73 74 ndex;.typedef st
7900: 72 75 63 74 20 49 6e 64 65 78 53 61 6d 70 6c 65 ruct IndexSample
7910: 20 49 6e 64 65 78 53 61 6d 70 6c 65 3b 0a 74 79 IndexSample;.ty
7920: 70 65 64 65 66 20 73 74 72 75 63 74 20 4b 65 79 pedef struct Key
7930: 43 6c 61 73 73 20 4b 65 79 43 6c 61 73 73 3b 0a Class KeyClass;.
7940: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4b typedef struct K
7950: 65 79 49 6e 66 6f 20 4b 65 79 49 6e 66 6f 3b 0a eyInfo KeyInfo;.
7960: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4c typedef struct L
7970: 6f 6f 6b 61 73 69 64 65 20 4c 6f 6f 6b 61 73 69 ookaside Lookasi
7980: 64 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 de;.typedef stru
7990: 63 74 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 ct LookasideSlot
79a0: 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 3b 0a LookasideSlot;.
79b0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4d typedef struct M
79c0: 6f 64 75 6c 65 20 4d 6f 64 75 6c 65 3b 0a 74 79 odule Module;.ty
79d0: 70 65 64 65 66 20 73 74 72 75 63 74 20 4e 61 6d pedef struct Nam
79e0: 65 43 6f 6e 74 65 78 74 20 4e 61 6d 65 43 6f 6e eContext NameCon
79f0: 74 65 78 74 3b 0a 74 79 70 65 64 65 66 20 73 74 text;.typedef st
7a00: 72 75 63 74 20 50 61 72 73 65 20 50 61 72 73 65 ruct Parse Parse
7a10: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7a20: 20 50 72 65 55 70 64 61 74 65 20 50 72 65 55 70 PreUpdate PreUp
7a30: 64 61 74 65 3b 0a 74 79 70 65 64 65 66 20 73 74 date;.typedef st
7a40: 72 75 63 74 20 50 72 69 6e 74 66 41 72 67 75 6d ruct PrintfArgum
7a50: 65 6e 74 73 20 50 72 69 6e 74 66 41 72 67 75 6d ents PrintfArgum
7a60: 65 6e 74 73 3b 0a 74 79 70 65 64 65 66 20 73 74 ents;.typedef st
7a70: 72 75 63 74 20 52 6f 77 53 65 74 20 52 6f 77 53 ruct RowSet RowS
7a80: 65 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 et;.typedef stru
7a90: 63 74 20 53 61 76 65 70 6f 69 6e 74 20 53 61 76 ct Savepoint Sav
7aa0: 65 70 6f 69 6e 74 3b 0a 74 79 70 65 64 65 66 20 epoint;.typedef
7ab0: 73 74 72 75 63 74 20 53 65 6c 65 63 74 20 53 65 struct Select Se
7ac0: 6c 65 63 74 3b 0a 74 79 70 65 64 65 66 20 73 74 lect;.typedef st
7ad0: 72 75 63 74 20 53 51 4c 69 74 65 54 68 72 65 61 ruct SQLiteThrea
7ae0: 64 20 53 51 4c 69 74 65 54 68 72 65 61 64 3b 0a d SQLiteThread;.
7af0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
7b00: 65 6c 65 63 74 44 65 73 74 20 53 65 6c 65 63 74 electDest Select
7b10: 44 65 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 Dest;.typedef st
7b20: 72 75 63 74 20 53 72 63 4c 69 73 74 20 53 72 63 ruct SrcList Src
7b30: 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 List;.typedef st
7b40: 72 75 63 74 20 53 74 72 41 63 63 75 6d 20 53 74 ruct StrAccum St
7b50: 72 41 63 63 75 6d 3b 0a 74 79 70 65 64 65 66 20 rAccum;.typedef
7b60: 73 74 72 75 63 74 20 54 61 62 6c 65 20 54 61 62 struct Table Tab
7b70: 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 le;.typedef stru
7b80: 63 74 20 54 61 62 6c 65 4c 6f 63 6b 20 54 61 62 ct TableLock Tab
7b90: 6c 65 4c 6f 63 6b 3b 0a 74 79 70 65 64 65 66 20 leLock;.typedef
7ba0: 73 74 72 75 63 74 20 54 6f 6b 65 6e 20 54 6f 6b struct Token Tok
7bb0: 65 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 en;.typedef stru
7bc0: 63 74 20 54 72 65 65 56 69 65 77 20 54 72 65 65 ct TreeView Tree
7bd0: 56 69 65 77 3b 0a 74 79 70 65 64 65 66 20 73 74 View;.typedef st
7be0: 72 75 63 74 20 54 72 69 67 67 65 72 20 54 72 69 ruct Trigger Tri
7bf0: 67 67 65 72 3b 0a 74 79 70 65 64 65 66 20 73 74 gger;.typedef st
7c00: 72 75 63 74 20 54 72 69 67 67 65 72 50 72 67 20 ruct TriggerPrg
7c10: 54 72 69 67 67 65 72 50 72 67 3b 0a 74 79 70 65 TriggerPrg;.type
7c20: 64 65 66 20 73 74 72 75 63 74 20 54 72 69 67 67 def struct Trigg
7c30: 65 72 53 74 65 70 20 54 72 69 67 67 65 72 53 74 erStep TriggerSt
7c40: 65 70 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ep;.typedef stru
7c50: 63 74 20 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 ct UnpackedRecor
7c60: 64 20 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 d UnpackedRecord
7c70: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7c80: 20 56 54 61 62 6c 65 20 56 54 61 62 6c 65 3b 0a VTable VTable;.
7c90: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 56 typedef struct V
7ca0: 74 61 62 43 74 78 20 56 74 61 62 43 74 78 3b 0a tabCtx VtabCtx;.
7cb0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 57 typedef struct W
7cc0: 61 6c 6b 65 72 20 57 61 6c 6b 65 72 3b 0a 74 79 alker Walker;.ty
7cd0: 70 65 64 65 66 20 73 74 72 75 63 74 20 57 68 65 pedef struct Whe
7ce0: 72 65 49 6e 66 6f 20 57 68 65 72 65 49 6e 66 6f reInfo WhereInfo
7cf0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7d00: 20 57 69 74 68 20 57 69 74 68 3b 0a 0a 2f 2a 0a With With;../*.
7d10: 2a 2a 20 44 65 66 65 72 20 73 6f 75 72 63 69 6e ** Defer sourcin
7d20: 67 20 76 64 62 65 2e 68 20 61 6e 64 20 62 74 72 g vdbe.h and btr
7d30: 65 65 2e 68 20 75 6e 74 69 6c 20 61 66 74 65 72 ee.h until after
7d40: 20 74 68 65 20 22 75 38 22 20 61 6e 64 20 0a 2a the "u8" and .*
7d50: 2a 20 22 42 75 73 79 48 61 6e 64 6c 65 72 22 20 * "BusyHandler"
7d60: 74 79 70 65 64 65 66 73 2e 20 76 64 62 65 2e 68 typedefs. vdbe.h
7d70: 20 61 6c 73 6f 20 72 65 71 75 69 72 65 73 20 61 also requires a
7d80: 20 66 65 77 20 6f 66 20 74 68 65 20 6f 70 61 71 few of the opaq
7d90: 75 65 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 74 79 ue.** pointer ty
7da0: 70 65 73 20 28 69 2e 65 2e 20 46 75 6e 63 44 65 pes (i.e. FuncDe
7db0: 66 29 20 64 65 66 69 6e 65 64 20 61 62 6f 76 65 f) defined above
7dc0: 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 62 ..*/.#include "b
7dd0: 74 72 65 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 tree.h".#include
7de0: 20 22 76 64 62 65 2e 68 22 0a 23 69 6e 63 6c 75 "vdbe.h".#inclu
7df0: 64 65 20 22 70 61 67 65 72 2e 68 22 0a 23 69 6e de "pager.h".#in
7e00: 63 6c 75 64 65 20 22 70 63 61 63 68 65 2e 68 22 clude "pcache.h"
7e10: 0a 0a 23 69 6e 63 6c 75 64 65 20 22 6f 73 2e 68 ..#include "os.h
7e20: 22 0a 23 69 6e 63 6c 75 64 65 20 22 6d 75 74 65 ".#include "mute
7e30: 78 2e 68 22 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 x.h".../*.** Eac
7e40: 68 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 h database file
7e50: 74 6f 20 62 65 20 61 63 63 65 73 73 65 64 20 62 to be accessed b
7e60: 79 20 74 68 65 20 73 79 73 74 65 6d 20 69 73 20 y the system is
7e70: 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f an instance.** o
7e80: 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
7e90: 73 74 72 75 63 74 75 72 65 2e 20 20 54 68 65 72 structure. Ther
7ea0: 65 20 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 20 74 e are normally t
7eb0: 77 6f 20 6f 66 20 74 68 65 73 65 20 73 74 72 75 wo of these stru
7ec0: 63 74 75 72 65 73 0a 2a 2a 20 69 6e 20 74 68 65 ctures.** in the
7ed0: 20 73 71 6c 69 74 65 2e 61 44 62 5b 5d 20 61 72 sqlite.aDb[] ar
7ee0: 72 61 79 2e 20 20 61 44 62 5b 30 5d 20 69 73 20 ray. aDb[0] is
7ef0: 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 73 the main databas
7f00: 65 20 66 69 6c 65 20 61 6e 64 0a 2a 2a 20 61 44 e file and.** aD
7f10: 62 5b 31 5d 20 69 73 20 74 68 65 20 64 61 74 61 b[1] is the data
7f20: 62 61 73 65 20 66 69 6c 65 20 75 73 65 64 20 74 base file used t
7f30: 6f 20 68 6f 6c 64 20 74 65 6d 70 6f 72 61 72 79 o hold temporary
7f40: 20 74 61 62 6c 65 73 2e 20 20 41 64 64 69 74 69 tables. Additi
7f50: 6f 6e 61 6c 0a 2a 2a 20 64 61 74 61 62 61 73 65 onal.** database
7f60: 73 20 6d 61 79 20 62 65 20 61 74 74 61 63 68 65 s may be attache
7f70: 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 44 62 20 d..*/.struct Db
7f80: 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b {. char *zName;
7f90: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 /* Name
7fa0: 20 6f 66 20 74 68 69 73 20 64 61 74 61 62 61 73 of this databas
7fb0: 65 20 2a 2f 0a 20 20 42 74 72 65 65 20 2a 70 42 e */. Btree *pB
7fc0: 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 t; /* T
7fd0: 68 65 20 42 2a 54 72 65 65 20 73 74 72 75 63 74 he B*Tree struct
7fe0: 75 72 65 20 66 6f 72 20 74 68 69 73 20 64 61 74 ure for this dat
7ff0: 61 62 61 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 abase file */.
8000: 75 38 20 73 61 66 65 74 79 5f 6c 65 76 65 6c 3b u8 safety_level;
8010: 20 20 20 20 20 2f 2a 20 48 6f 77 20 61 67 67 72 /* How aggr
8020: 65 73 73 69 76 65 20 61 74 20 73 79 6e 63 69 6e essive at syncin
8030: 67 20 64 61 74 61 20 74 6f 20 64 69 73 6b 20 2a g data to disk *
8040: 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 /. Schema *pSch
8050: 65 6d 61 3b 20 20 20 20 20 2f 2a 20 50 6f 69 6e ema; /* Poin
8060: 74 65 72 20 74 6f 20 64 61 74 61 62 61 73 65 20 ter to database
8070: 73 63 68 65 6d 61 20 28 70 6f 73 73 69 62 6c 79 schema (possibly
8080: 20 73 68 61 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a shared) */.};..
8090: 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
80a0: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
80b0: 6e 67 20 73 74 72 75 63 74 75 72 65 20 73 74 6f ng structure sto
80c0: 72 65 73 20 61 20 64 61 74 61 62 61 73 65 20 73 res a database s
80d0: 63 68 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 chema..**.** Mos
80e0: 74 20 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 t Schema objects
80f0: 20 61 72 65 20 61 73 73 6f 63 69 61 74 65 64 20 are associated
8100: 77 69 74 68 20 61 20 42 74 72 65 65 2e 20 20 54 with a Btree. T
8110: 68 65 20 65 78 63 65 70 74 69 6f 6e 20 69 73 0a he exception is.
8120: 2a 2a 20 74 68 65 20 53 63 68 65 6d 61 20 66 6f ** the Schema fo
8130: 72 20 74 68 65 20 54 45 4d 50 20 64 61 74 61 62 r the TEMP datab
8140: 61 65 73 20 28 73 71 6c 69 74 65 33 2e 61 44 62 aes (sqlite3.aDb
8150: 5b 31 5d 29 20 77 68 69 63 68 20 69 73 20 66 72 [1]) which is fr
8160: 65 65 2d 73 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 ee-standing..**
8170: 49 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 20 In shared cache
8180: 6d 6f 64 65 2c 20 61 20 73 69 6e 67 6c 65 20 53 mode, a single S
8190: 63 68 65 6d 61 20 6f 62 6a 65 63 74 20 63 61 6e chema object can
81a0: 20 62 65 20 73 68 61 72 65 64 20 62 79 20 6d 75 be shared by mu
81b0: 6c 74 69 70 6c 65 0a 2a 2a 20 42 74 72 65 65 73 ltiple.** Btrees
81c0: 20 74 68 61 74 20 72 65 66 65 72 20 74 6f 20 74 that refer to t
81d0: 68 65 20 73 61 6d 65 20 75 6e 64 65 72 6c 79 69 he same underlyi
81e0: 6e 67 20 42 74 53 68 61 72 65 64 20 6f 62 6a 65 ng BtShared obje
81f0: 63 74 2e 0a 2a 2a 20 0a 2a 2a 20 53 63 68 65 6d ct..** .** Schem
8200: 61 20 6f 62 6a 65 63 74 73 20 61 72 65 20 61 75 a objects are au
8210: 74 6f 6d 61 74 69 63 61 6c 6c 79 20 64 65 61 6c tomatically deal
8220: 6c 6f 63 61 74 65 64 20 77 68 65 6e 20 74 68 65 located when the
8230: 20 6c 61 73 74 20 42 74 72 65 65 20 74 68 61 74 last Btree that
8240: 0a 2a 2a 20 72 65 66 65 72 65 6e 63 65 73 20 74 .** references t
8250: 68 65 6d 20 69 73 20 64 65 73 74 72 6f 79 65 64 hem is destroyed
8260: 2e 20 20 20 54 68 65 20 54 45 4d 50 20 53 63 68 . The TEMP Sch
8270: 65 6d 61 20 69 73 20 6d 61 6e 75 61 6c 6c 79 20 ema is manually
8280: 66 72 65 65 64 20 62 79 0a 2a 2a 20 73 71 6c 69 freed by.** sqli
8290: 74 65 33 5f 63 6c 6f 73 65 28 29 2e 0a 2a 0a 2a te3_close()..*.*
82a0: 2a 20 41 20 74 68 72 65 61 64 20 6d 75 73 74 20 * A thread must
82b0: 62 65 20 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 be holding a mut
82c0: 65 78 20 6f 6e 20 74 68 65 20 63 6f 72 72 65 73 ex on the corres
82d0: 70 6f 6e 64 69 6e 67 20 42 74 72 65 65 20 69 6e ponding Btree in
82e0: 20 6f 72 64 65 72 0a 2a 2a 20 74 6f 20 61 63 63 order.** to acc
82f0: 65 73 73 20 53 63 68 65 6d 61 20 63 6f 6e 74 65 ess Schema conte
8300: 6e 74 2e 20 20 54 68 69 73 20 69 6d 70 6c 69 65 nt. This implie
8310: 73 20 74 68 61 74 20 74 68 65 20 74 68 72 65 61 s that the threa
8320: 64 20 6d 75 73 74 20 61 6c 73 6f 20 62 65 0a 2a d must also be.*
8330: 2a 20 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 * holding a mute
8340: 78 20 6f 6e 20 74 68 65 20 73 71 6c 69 74 65 33 x on the sqlite3
8350: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 70 6f 69 6e connection poin
8360: 74 65 72 20 74 68 61 74 20 6f 77 6e 73 20 74 68 ter that owns th
8370: 65 20 42 74 72 65 65 2e 0a 2a 2a 20 46 6f 72 20 e Btree..** For
8380: 61 20 54 45 4d 50 20 53 63 68 65 6d 61 2c 20 6f a TEMP Schema, o
8390: 6e 6c 79 20 74 68 65 20 63 6f 6e 6e 65 63 74 69 nly the connecti
83a0: 6f 6e 20 6d 75 74 65 78 20 69 73 20 72 65 71 75 on mutex is requ
83b0: 69 72 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 ired..*/.struct
83c0: 53 63 68 65 6d 61 20 7b 0a 20 20 69 6e 74 20 73 Schema {. int s
83d0: 63 68 65 6d 61 5f 63 6f 6f 6b 69 65 3b 20 20 20 chema_cookie;
83e0: 2f 2a 20 44 61 74 61 62 61 73 65 20 73 63 68 65 /* Database sche
83f0: 6d 61 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 ma version numbe
8400: 72 20 66 6f 72 20 74 68 69 73 20 66 69 6c 65 20 r for this file
8410: 2a 2f 0a 20 20 69 6e 74 20 69 47 65 6e 65 72 61 */. int iGenera
8420: 74 69 6f 6e 3b 20 20 20 20 20 2f 2a 20 47 65 6e tion; /* Gen
8430: 65 72 61 74 69 6f 6e 20 63 6f 75 6e 74 65 72 2e eration counter.
8440: 20 20 49 6e 63 72 65 6d 65 6e 74 65 64 20 77 69 Incremented wi
8450: 74 68 20 65 61 63 68 20 63 68 61 6e 67 65 20 2a th each change *
8460: 2f 0a 20 20 48 61 73 68 20 74 62 6c 48 61 73 68 /. Hash tblHash
8470: 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 ; /* All
8480: 74 61 62 6c 65 73 20 69 6e 64 65 78 65 64 20 62 tables indexed b
8490: 79 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 y name */. Hash
84a0: 20 69 64 78 48 61 73 68 3b 20 20 20 20 20 20 20 idxHash;
84b0: 20 2f 2a 20 41 6c 6c 20 28 6e 61 6d 65 64 29 20 /* All (named)
84c0: 69 6e 64 69 63 65 73 20 69 6e 64 65 78 65 64 20 indices indexed
84d0: 62 79 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 by name */. Has
84e0: 68 20 74 72 69 67 48 61 73 68 3b 20 20 20 20 20 h trigHash;
84f0: 20 20 2f 2a 20 41 6c 6c 20 74 72 69 67 67 65 72 /* All trigger
8500: 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d s indexed by nam
8510: 65 20 2a 2f 0a 20 20 48 61 73 68 20 66 6b 65 79 e */. Hash fkey
8520: 48 61 73 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 Hash; /* A
8530: 6c 6c 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 ll foreign keys
8540: 62 79 20 72 65 66 65 72 65 6e 63 65 64 20 74 61 by referenced ta
8550: 62 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 61 ble name */. Ta
8560: 62 6c 65 20 2a 70 53 65 71 54 61 62 3b 20 20 20 ble *pSeqTab;
8570: 20 20 20 2f 2a 20 54 68 65 20 73 71 6c 69 74 65 /* The sqlite
8580: 5f 73 65 71 75 65 6e 63 65 20 74 61 62 6c 65 20 _sequence table
8590: 75 73 65 64 20 62 79 20 41 55 54 4f 49 4e 43 52 used by AUTOINCR
85a0: 45 4d 45 4e 54 20 2a 2f 0a 20 20 75 38 20 66 69 EMENT */. u8 fi
85b0: 6c 65 5f 66 6f 72 6d 61 74 3b 20 20 20 20 20 20 le_format;
85c0: 2f 2a 20 53 63 68 65 6d 61 20 66 6f 72 6d 61 74 /* Schema format
85d0: 20 76 65 72 73 69 6f 6e 20 66 6f 72 20 74 68 69 version for thi
85e0: 73 20 66 69 6c 65 20 2a 2f 0a 20 20 75 38 20 65 s file */. u8 e
85f0: 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
8600: 20 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e /* Text encodin
8610: 67 20 75 73 65 64 20 62 79 20 74 68 69 73 20 64 g used by this d
8620: 61 74 61 62 61 73 65 20 2a 2f 0a 20 20 75 31 36 atabase */. u16
8630: 20 73 63 68 65 6d 61 46 6c 61 67 73 3b 20 20 20 schemaFlags;
8640: 20 20 2f 2a 20 46 6c 61 67 73 20 61 73 73 6f 63 /* Flags assoc
8650: 69 61 74 65 64 20 77 69 74 68 20 74 68 69 73 20 iated with this
8660: 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 schema */. int
8670: 63 61 63 68 65 5f 73 69 7a 65 3b 20 20 20 20 20 cache_size;
8680: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 /* Number of pa
8690: 67 65 73 20 74 6f 20 75 73 65 20 69 6e 20 74 68 ges to use in th
86a0: 65 20 63 61 63 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f e cache */.};../
86b0: 2a 0a 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f *.** These macro
86c0: 73 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f s can be used to
86d0: 20 74 65 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 test, set, or c
86e0: 6c 65 61 72 20 62 69 74 73 20 69 6e 20 74 68 65 lear bits in the
86f0: 20 0a 2a 2a 20 44 62 2e 70 53 63 68 65 6d 61 2d .** Db.pSchema-
8700: 3e 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f >flags field..*/
8710: 0a 23 64 65 66 69 6e 65 20 44 62 48 61 73 50 72 .#define DbHasPr
8720: 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 20 operty(D,I,P)
8730: 20 20 28 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e (((D)->aDb[I].
8740: 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 pSchema->schemaF
8750: 6c 61 67 73 26 28 50 29 29 3d 3d 28 50 29 29 0a lags&(P))==(P)).
8760: 23 64 65 66 69 6e 65 20 44 62 48 61 73 41 6e 79 #define DbHasAny
8770: 50 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 Property(D,I,P)
8780: 20 28 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 (((D)->aDb[I].p
8790: 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c Schema->schemaFl
87a0: 61 67 73 26 28 50 29 29 21 3d 30 29 0a 23 64 65 ags&(P))!=0).#de
87b0: 66 69 6e 65 20 44 62 53 65 74 50 72 6f 70 65 72 fine DbSetProper
87c0: 74 79 28 44 2c 49 2c 50 29 20 20 20 20 20 28 44 ty(D,I,P) (D
87d0: 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d )->aDb[I].pSchem
87e0: 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 7c 3d a->schemaFlags|=
87f0: 28 50 29 0a 23 64 65 66 69 6e 65 20 44 62 43 6c (P).#define DbCl
8800: 65 61 72 50 72 6f 70 65 72 74 79 28 44 2c 49 2c earProperty(D,I,
8810: 50 29 20 20 20 28 44 29 2d 3e 61 44 62 5b 49 5d P) (D)->aDb[I]
8820: 2e 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 .pSchema->schema
8830: 46 6c 61 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 0a Flags&=~(P)../*.
8840: 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 ** Allowed value
8850: 73 20 66 6f 72 20 74 68 65 20 44 42 2e 70 53 63 s for the DB.pSc
8860: 68 65 6d 61 2d 3e 66 6c 61 67 73 20 66 69 65 6c hema->flags fiel
8870: 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 44 42 5f d..**.** The DB_
8880: 53 63 68 65 6d 61 4c 6f 61 64 65 64 20 66 6c 61 SchemaLoaded fla
8890: 67 20 69 73 20 73 65 74 20 61 66 74 65 72 20 74 g is set after t
88a0: 68 65 20 64 61 74 61 62 61 73 65 20 73 63 68 65 he database sche
88b0: 6d 61 20 68 61 73 20 62 65 65 6e 0a 2a 2a 20 72 ma has been.** r
88c0: 65 61 64 20 69 6e 74 6f 20 69 6e 74 65 72 6e 61 ead into interna
88d0: 6c 20 68 61 73 68 20 74 61 62 6c 65 73 2e 0a 2a l hash tables..*
88e0: 2a 0a 2a 2a 20 44 42 5f 55 6e 72 65 73 65 74 56 *.** DB_UnresetV
88f0: 69 65 77 73 20 6d 65 61 6e 73 20 74 68 61 74 20 iews means that
8900: 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 76 69 65 77 one or more view
8910: 73 20 68 61 76 65 20 63 6f 6c 75 6d 6e 20 6e 61 s have column na
8920: 6d 65 73 20 74 68 61 74 0a 2a 2a 20 68 61 76 65 mes that.** have
8930: 20 62 65 65 6e 20 66 69 6c 6c 65 64 20 6f 75 74 been filled out
8940: 2e 20 20 49 66 20 74 68 65 20 73 63 68 65 6d 61 . If the schema
8950: 20 63 68 61 6e 67 65 73 2c 20 74 68 65 73 65 20 changes, these
8960: 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6d 69 67 column names mig
8970: 68 74 0a 2a 2a 20 63 68 61 6e 67 65 73 20 61 6e ht.** changes an
8980: 64 20 73 6f 20 74 68 65 20 76 69 65 77 20 77 69 d so the view wi
8990: 6c 6c 20 6e 65 65 64 20 74 6f 20 62 65 20 72 65 ll need to be re
89a0: 73 65 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 set..*/.#define
89b0: 44 42 5f 53 63 68 65 6d 61 4c 6f 61 64 65 64 20 DB_SchemaLoaded
89c0: 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 54 68 0x0001 /* Th
89d0: 65 20 73 63 68 65 6d 61 20 68 61 73 20 62 65 65 e schema has bee
89e0: 6e 20 6c 6f 61 64 65 64 20 2a 2f 0a 23 64 65 66 n loaded */.#def
89f0: 69 6e 65 20 44 42 5f 55 6e 72 65 73 65 74 56 69 ine DB_UnresetVi
8a00: 65 77 73 20 20 20 20 30 78 30 30 30 32 20 20 2f ews 0x0002 /
8a10: 2a 20 53 6f 6d 65 20 76 69 65 77 73 20 68 61 76 * Some views hav
8a20: 65 20 64 65 66 69 6e 65 64 20 63 6f 6c 75 6d 6e e defined column
8a30: 20 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 6e names */.#defin
8a40: 65 20 44 42 5f 45 6d 70 74 79 20 20 20 20 20 20 e DB_Empty
8a50: 20 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 0x0004 /*
8a60: 54 68 65 20 66 69 6c 65 20 69 73 20 65 6d 70 74 The file is empt
8a70: 79 20 28 6c 65 6e 67 74 68 20 30 20 62 79 74 65 y (length 0 byte
8a80: 73 29 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 s) */../*.** The
8a90: 20 6e 75 6d 62 65 72 20 6f 66 20 64 69 66 66 65 number of diffe
8aa0: 72 65 6e 74 20 6b 69 6e 64 73 20 6f 66 20 74 68 rent kinds of th
8ab0: 69 6e 67 73 20 74 68 61 74 20 63 61 6e 20 62 65 ings that can be
8ac0: 20 6c 69 6d 69 74 65 64 0a 2a 2a 20 75 73 69 6e limited.** usin
8ad0: 67 20 74 68 65 20 73 71 6c 69 74 65 33 5f 6c 69 g the sqlite3_li
8ae0: 6d 69 74 28 29 20 69 6e 74 65 72 66 61 63 65 2e mit() interface.
8af0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
8b00: 54 45 5f 4e 5f 4c 49 4d 49 54 20 28 53 51 4c 49 TE_N_LIMIT (SQLI
8b10: 54 45 5f 4c 49 4d 49 54 5f 57 4f 52 4b 45 52 5f TE_LIMIT_WORKER_
8b20: 54 48 52 45 41 44 53 2b 31 29 0a 0a 2f 2a 0a 2a THREADS+1)../*.*
8b30: 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c * Lookaside mall
8b40: 6f 63 20 69 73 20 61 20 73 65 74 20 6f 66 20 66 oc is a set of f
8b50: 69 78 65 64 2d 73 69 7a 65 20 62 75 66 66 65 72 ixed-size buffer
8b60: 73 20 74 68 61 74 20 63 61 6e 20 62 65 20 75 73 s that can be us
8b70: 65 64 0a 2a 2a 20 74 6f 20 73 61 74 69 73 66 79 ed.** to satisfy
8b80: 20 73 6d 61 6c 6c 20 74 72 61 6e 73 69 65 6e 74 small transient
8b90: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
8ba0: 6f 6e 20 72 65 71 75 65 73 74 73 20 66 6f 72 20 on requests for
8bb0: 6f 62 6a 65 63 74 73 0a 2a 2a 20 61 73 73 6f 63 objects.** assoc
8bc0: 69 61 74 65 64 20 77 69 74 68 20 61 20 70 61 72 iated with a par
8bd0: 74 69 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 ticular database
8be0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 54 68 connection. Th
8bf0: 65 20 75 73 65 20 6f 66 0a 2a 2a 20 6c 6f 6f 6b e use of.** look
8c00: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 70 72 6f aside malloc pro
8c10: 76 69 64 65 73 20 61 20 73 69 67 6e 69 66 69 63 vides a signific
8c20: 61 6e 74 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 ant performance
8c30: 65 6e 68 61 6e 63 65 6d 65 6e 74 0a 2a 2a 20 28 enhancement.** (
8c40: 61 70 70 72 6f 78 20 31 30 25 29 20 62 79 20 61 approx 10%) by a
8c50: 76 6f 69 64 69 6e 67 20 6e 75 6d 65 72 6f 75 73 voiding numerous
8c60: 20 6d 61 6c 6c 6f 63 2f 66 72 65 65 20 72 65 71 malloc/free req
8c70: 75 65 73 74 73 20 77 68 69 6c 65 20 70 61 72 73 uests while pars
8c80: 69 6e 67 0a 2a 2a 20 53 51 4c 20 73 74 61 74 65 ing.** SQL state
8c90: 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 ments..**.** The
8ca0: 20 4c 6f 6f 6b 61 73 69 64 65 20 73 74 72 75 63 Lookaside struc
8cb0: 74 75 72 65 20 68 6f 6c 64 73 20 63 6f 6e 66 69 ture holds confi
8cc0: 67 75 72 61 74 69 6f 6e 20 69 6e 66 6f 72 6d 61 guration informa
8cd0: 74 69 6f 6e 20 61 62 6f 75 74 20 74 68 65 0a 2a tion about the.*
8ce0: 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c * lookaside mall
8cf0: 6f 63 20 73 75 62 73 79 73 74 65 6d 2e 20 20 45 oc subsystem. E
8d00: 61 63 68 20 61 76 61 69 6c 61 62 6c 65 20 6d 65 ach available me
8d10: 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 mory allocation
8d20: 69 6e 0a 2a 2a 20 74 68 65 20 6c 6f 6f 6b 61 73 in.** the lookas
8d30: 69 64 65 20 73 75 62 73 79 73 74 65 6d 20 69 73 ide subsystem is
8d40: 20 73 74 6f 72 65 64 20 6f 6e 20 61 20 6c 69 6e stored on a lin
8d50: 6b 65 64 20 6c 69 73 74 20 6f 66 20 4c 6f 6f 6b ked list of Look
8d60: 61 73 69 64 65 53 6c 6f 74 0a 2a 2a 20 6f 62 6a asideSlot.** obj
8d70: 65 63 74 73 2e 0a 2a 2a 0a 2a 2a 20 4c 6f 6f 6b ects..**.** Look
8d80: 61 73 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e aside allocation
8d90: 73 20 61 72 65 20 6f 6e 6c 79 20 61 6c 6c 6f 77 s are only allow
8da0: 65 64 20 66 6f 72 20 6f 62 6a 65 63 74 73 20 74 ed for objects t
8db0: 68 61 74 20 61 72 65 20 61 73 73 6f 63 69 61 74 hat are associat
8dc0: 65 64 0a 2a 2a 20 77 69 74 68 20 61 20 70 61 72 ed.** with a par
8dd0: 74 69 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 ticular database
8de0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 48 65 connection. He
8df0: 6e 63 65 2c 20 73 63 68 65 6d 61 20 69 6e 66 6f nce, schema info
8e00: 72 6d 61 74 69 6f 6e 20 63 61 6e 6e 6f 74 0a 2a rmation cannot.*
8e10: 2a 20 62 65 20 73 74 6f 72 65 64 20 69 6e 20 6c * be stored in l
8e20: 6f 6f 6b 61 73 69 64 65 20 62 65 63 61 75 73 65 ookaside because
8e30: 20 69 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 in shared cache
8e40: 20 6d 6f 64 65 20 74 68 65 20 73 63 68 65 6d 61 mode the schema
8e50: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 information.**
8e60: 69 73 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c is shared by mul
8e70: 74 69 70 6c 65 20 64 61 74 61 62 61 73 65 20 63 tiple database c
8e80: 6f 6e 6e 65 63 74 69 6f 6e 73 2e 20 20 54 68 65 onnections. The
8e90: 72 65 66 6f 72 65 2c 20 77 68 69 6c 65 20 70 61 refore, while pa
8ea0: 72 73 69 6e 67 0a 2a 2a 20 73 63 68 65 6d 61 20 rsing.** schema
8eb0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c 20 74 68 65 information, the
8ec0: 20 4c 6f 6f 6b 61 73 69 64 65 2e 62 45 6e 61 62 Lookaside.bEnab
8ed0: 6c 65 64 20 66 6c 61 67 20 69 73 20 63 6c 65 61 led flag is clea
8ee0: 72 65 64 20 73 6f 20 74 68 61 74 0a 2a 2a 20 6c red so that.** l
8ef0: 6f 6f 6b 61 73 69 64 65 20 61 6c 6c 6f 63 61 74 ookaside allocat
8f00: 69 6f 6e 73 20 61 72 65 20 6e 6f 74 20 75 73 65 ions are not use
8f10: 64 20 74 6f 20 63 6f 6e 73 74 72 75 63 74 20 74 d to construct t
8f20: 68 65 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 he schema object
8f30: 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4c 6f 6f s..*/.struct Loo
8f40: 6b 61 73 69 64 65 20 7b 0a 20 20 75 31 36 20 73 kaside {. u16 s
8f50: 7a 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 z;
8f60: 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 /* Size of ea
8f70: 63 68 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 ch buffer in byt
8f80: 65 73 20 2a 2f 0a 20 20 75 38 20 62 45 6e 61 62 es */. u8 bEnab
8f90: 6c 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 led;
8fa0: 2f 2a 20 46 61 6c 73 65 20 74 6f 20 64 69 73 61 /* False to disa
8fb0: 62 6c 65 20 6e 65 77 20 6c 6f 6f 6b 61 73 69 64 ble new lookasid
8fc0: 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f e allocations */
8fd0: 0a 20 20 75 38 20 62 4d 61 6c 6c 6f 63 65 64 3b . u8 bMalloced;
8fe0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
8ff0: 75 65 20 69 66 20 70 53 74 61 72 74 20 6f 62 74 ue if pStart obt
9000: 61 69 6e 65 64 20 66 72 6f 6d 20 73 71 6c 69 74 ained from sqlit
9010: 65 33 5f 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 20 e3_malloc() */.
9020: 20 69 6e 74 20 6e 4f 75 74 3b 20 20 20 20 20 20 int nOut;
9030: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
9040: 65 72 20 6f 66 20 62 75 66 66 65 72 73 20 63 75 er of buffers cu
9050: 72 72 65 6e 74 6c 79 20 63 68 65 63 6b 65 64 20 rrently checked
9060: 6f 75 74 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 4f out */. int mxO
9070: 75 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ut;
9080: 20 2f 2a 20 48 69 67 68 77 61 74 65 72 20 6d 61 /* Highwater ma
9090: 72 6b 20 66 6f 72 20 6e 4f 75 74 20 2a 2f 0a 20 rk for nOut */.
90a0: 20 69 6e 74 20 61 6e 53 74 61 74 5b 33 5d 3b 20 int anStat[3];
90b0: 20 20 20 20 20 20 20 20 20 2f 2a 20 30 3a 20 68 /* 0: h
90c0: 69 74 73 2e 20 20 31 3a 20 73 69 7a 65 20 6d 69 its. 1: size mi
90d0: 73 73 65 73 2e 20 20 32 3a 20 66 75 6c 6c 20 6d sses. 2: full m
90e0: 69 73 73 65 73 20 2a 2f 0a 20 20 4c 6f 6f 6b 61 isses */. Looka
90f0: 73 69 64 65 53 6c 6f 74 20 2a 70 46 72 65 65 3b sideSlot *pFree;
9100: 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 76 /* List of av
9110: 61 69 6c 61 62 6c 65 20 62 75 66 66 65 72 73 20 ailable buffers
9120: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 53 74 61 72 */. void *pStar
9130: 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
9140: 46 69 72 73 74 20 62 79 74 65 20 6f 66 20 61 76 First byte of av
9150: 61 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 ailable memory s
9160: 70 61 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a pace */. void *
9170: 70 45 6e 64 3b 20 20 20 20 20 20 20 20 20 20 20 pEnd;
9180: 20 20 2f 2a 20 46 69 72 73 74 20 62 79 74 65 20 /* First byte
9190: 70 61 73 74 20 65 6e 64 20 6f 66 20 61 76 61 69 past end of avai
91a0: 6c 61 62 6c 65 20 73 70 61 63 65 20 2a 2f 0a 7d lable space */.}
91b0: 3b 0a 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 ;.struct Lookasi
91c0: 64 65 53 6c 6f 74 20 7b 0a 20 20 4c 6f 6f 6b 61 deSlot {. Looka
91d0: 73 69 64 65 53 6c 6f 74 20 2a 70 4e 65 78 74 3b sideSlot *pNext;
91e0: 20 20 20 20 2f 2a 20 4e 65 78 74 20 62 75 66 66 /* Next buff
91f0: 65 72 20 69 6e 20 74 68 65 20 6c 69 73 74 20 6f er in the list o
9200: 66 20 66 72 65 65 20 62 75 66 66 65 72 73 20 2a f free buffers *
9210: 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 68 61 /.};../*.** A ha
9220: 73 68 20 74 61 62 6c 65 20 66 6f 72 20 66 75 6e sh table for fun
9230: 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e ction definition
9240: 73 2e 0a 2a 2a 0a 2a 2a 20 48 61 73 68 20 65 61 s..**.** Hash ea
9250: 63 68 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 ch FuncDef struc
9260: 74 75 72 65 20 69 6e 74 6f 20 6f 6e 65 20 6f 66 ture into one of
9270: 20 74 68 65 20 46 75 6e 63 44 65 66 48 61 73 68 the FuncDefHash
9280: 2e 61 5b 5d 20 73 6c 6f 74 73 2e 0a 2a 2a 20 43 .a[] slots..** C
9290: 6f 6c 6c 69 73 69 6f 6e 73 20 61 72 65 20 6f 6e ollisions are on
92a0: 20 74 68 65 20 46 75 6e 63 44 65 66 2e 70 48 61 the FuncDef.pHa
92b0: 73 68 20 63 68 61 69 6e 2e 0a 2a 2f 0a 73 74 72 sh chain..*/.str
92c0: 75 63 74 20 46 75 6e 63 44 65 66 48 61 73 68 20 uct FuncDefHash
92d0: 7b 0a 20 20 46 75 6e 63 44 65 66 20 2a 61 5b 32 {. FuncDef *a[2
92e0: 33 5d 3b 20 20 20 20 20 20 20 2f 2a 20 48 61 73 3]; /* Has
92f0: 68 20 74 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 h table for func
9300: 74 69 6f 6e 73 20 2a 2f 0a 7d 3b 0a 0a 23 69 66 tions */.};..#if
9310: 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 52 5f def SQLITE_USER_
9320: 41 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a 2f AUTHENTICATION./
9330: 2a 0a 2a 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e *.** Information
9340: 20 68 65 6c 64 20 69 6e 20 74 68 65 20 22 73 71 held in the "sq
9350: 6c 69 74 65 33 22 20 64 61 74 61 62 61 73 65 20 lite3" database
9360: 63 6f 6e 6e 65 63 74 69 6f 6e 20 6f 62 6a 65 63 connection objec
9370: 74 20 61 6e 64 20 75 73 65 64 0a 2a 2a 20 74 6f t and used.** to
9380: 20 6d 61 6e 61 67 65 20 75 73 65 72 20 61 75 74 manage user aut
9390: 68 65 6e 74 69 63 61 74 69 6f 6e 2e 0a 2a 2f 0a hentication..*/.
93a0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 73 typedef struct s
93b0: 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 20 qlite3_userauth
93c0: 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 sqlite3_userauth
93d0: 3b 0a 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 ;.struct sqlite3
93e0: 5f 75 73 65 72 61 75 74 68 20 7b 0a 20 20 75 38 _userauth {. u8
93f0: 20 61 75 74 68 4c 65 76 65 6c 3b 20 20 20 20 20 authLevel;
9400: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
9410: 75 72 72 65 6e 74 20 61 75 74 68 65 6e 74 69 63 urrent authentic
9420: 61 74 69 6f 6e 20 6c 65 76 65 6c 20 2a 2f 0a 20 ation level */.
9430: 20 69 6e 74 20 6e 41 75 74 68 50 57 3b 20 20 20 int nAuthPW;
9440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
9450: 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 20 7a 41 * Size of the zA
9460: 75 74 68 50 57 20 69 6e 20 62 79 74 65 73 20 2a uthPW in bytes *
9470: 2f 0a 20 20 63 68 61 72 20 2a 7a 41 75 74 68 50 /. char *zAuthP
9480: 57 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 W;
9490: 20 20 2f 2a 20 50 61 73 73 77 6f 72 64 20 75 73 /* Password us
94a0: 65 64 20 74 6f 20 61 75 74 68 65 6e 74 69 63 61 ed to authentica
94b0: 74 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 41 te */. char *zA
94c0: 75 74 68 55 73 65 72 3b 20 20 20 20 20 20 20 20 uthUser;
94d0: 20 20 20 20 20 20 2f 2a 20 55 73 65 72 20 6e 61 /* User na
94e0: 6d 65 20 75 73 65 64 20 74 6f 20 61 75 74 68 65 me used to authe
94f0: 6e 74 69 63 61 74 65 20 2a 2f 0a 7d 3b 0a 0a 2f nticate */.};../
9500: 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
9510: 20 66 6f 72 20 73 71 6c 69 74 65 33 5f 75 73 65 for sqlite3_use
9520: 72 61 75 74 68 2e 61 75 74 68 4c 65 76 65 6c 20 rauth.authLevel
9530: 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 */.#define UAUTH
9540: 5f 55 6e 6b 6e 6f 77 6e 20 20 20 20 20 30 20 20 _Unknown 0
9550: 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 /* Authentica
9560: 74 69 6f 6e 20 6e 6f 74 20 79 65 74 20 63 68 65 tion not yet che
9570: 63 6b 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 cked */.#define
9580: 55 41 55 54 48 5f 46 61 69 6c 20 20 20 20 20 20 UAUTH_Fail
9590: 20 20 31 20 20 20 20 20 2f 2a 20 55 73 65 72 20 1 /* User
95a0: 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 66 authentication f
95b0: 61 69 6c 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 ailed */.#define
95c0: 20 55 41 55 54 48 5f 55 73 65 72 20 20 20 20 20 UAUTH_User
95d0: 20 20 20 32 20 20 20 20 20 2f 2a 20 41 75 74 68 2 /* Auth
95e0: 65 6e 74 69 63 61 74 65 64 20 61 73 20 61 20 6e enticated as a n
95f0: 6f 72 6d 61 6c 20 75 73 65 72 20 2a 2f 0a 23 64 ormal user */.#d
9600: 65 66 69 6e 65 20 55 41 55 54 48 5f 41 64 6d 69 efine UAUTH_Admi
9610: 6e 20 20 20 20 20 20 20 33 20 20 20 20 20 2f 2a n 3 /*
9620: 20 41 75 74 68 65 6e 74 69 63 61 74 65 64 20 61 Authenticated a
9630: 73 20 61 6e 20 61 64 6d 69 6e 69 73 74 72 61 74 s an administrat
9640: 6f 72 20 2a 2f 0a 0a 2f 2a 20 46 75 6e 63 74 69 or */../* Functi
9650: 6f 6e 73 20 75 73 65 64 20 6f 6e 6c 79 20 62 79 ons used only by
9660: 20 75 73 65 72 20 61 75 74 68 6f 72 69 7a 61 74 user authorizat
9670: 69 6f 6e 20 6c 6f 67 69 63 20 2a 2f 0a 69 6e 74 ion logic */.int
9680: 20 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 sqlite3UserAuth
9690: 54 61 62 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 Table(const char
96a0: 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 *);.int sqlite3U
96b0: 73 65 72 41 75 74 68 43 68 65 63 6b 4c 6f 67 69 serAuthCheckLogi
96c0: 6e 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 n(sqlite3*,const
96d0: 20 63 68 61 72 2a 2c 75 38 2a 29 3b 0a 76 6f 69 char*,u8*);.voi
96e0: 64 20 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 d sqlite3UserAut
96f0: 68 49 6e 69 74 28 73 71 6c 69 74 65 33 2a 29 3b hInit(sqlite3*);
9700: 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 72 79 .void sqlite3Cry
9710: 70 74 46 75 6e 63 28 73 71 6c 69 74 65 33 5f 63 ptFunc(sqlite3_c
9720: 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 ontext*,int,sqli
9730: 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 0a 23 te3_value**);..#
9740: 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 54 45 5f endif /* SQLITE_
9750: 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 USER_AUTHENTICAT
9760: 49 4f 4e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 74 79 ION */../*.** ty
9770: 70 65 64 65 66 20 66 6f 72 20 74 68 65 20 61 75 pedef for the au
9780: 74 68 6f 72 69 7a 61 74 69 6f 6e 20 63 61 6c 6c thorization call
9790: 62 61 63 6b 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a back function..*
97a0: 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
97b0: 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 USER_AUTHENTICAT
97c0: 49 4f 4e 0a 20 20 74 79 70 65 64 65 66 20 69 6e ION. typedef in
97d0: 74 20 28 2a 73 71 6c 69 74 65 33 5f 78 61 75 74 t (*sqlite3_xaut
97e0: 68 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e h)(void*,int,con
97f0: 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 st char*,const c
9800: 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
9810: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
9820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9830: 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f const char*, co
9840: 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 nst char*);.#els
9850: 65 0a 20 20 74 79 70 65 64 65 66 20 69 6e 74 20 e. typedef int
9860: 28 2a 73 71 6c 69 74 65 33 5f 78 61 75 74 68 29 (*sqlite3_xauth)
9870: 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 (void*,int,const
9880: 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 char*,const cha
9890: 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 0a r*,const char*,.
98a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
98b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 c
98c0: 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e onst char*);.#en
98d0: 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 dif.../*.** Each
98e0: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
98f0: 74 69 6f 6e 20 69 73 20 61 6e 20 69 6e 73 74 61 tion is an insta
9900: 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
9910: 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e 0a wing structure..
9920: 2a 2f 0a 73 74 72 75 63 74 20 73 71 6c 69 74 65 */.struct sqlite
9930: 33 20 7b 0a 20 20 73 71 6c 69 74 65 33 5f 76 66 3 {. sqlite3_vf
9940: 73 20 2a 70 56 66 73 3b 20 20 20 20 20 20 20 20 s *pVfs;
9950: 20 20 20 20 2f 2a 20 4f 53 20 49 6e 74 65 72 66 /* OS Interf
9960: 61 63 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 ace */. struct
9970: 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 20 20 Vdbe *pVdbe;
9980: 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f /* List o
9990: 66 20 61 63 74 69 76 65 20 76 69 72 74 75 61 6c f active virtual
99a0: 20 6d 61 63 68 69 6e 65 73 20 2a 2f 0a 20 20 43 machines */. C
99b0: 6f 6c 6c 53 65 71 20 2a 70 44 66 6c 74 43 6f 6c ollSeq *pDfltCol
99c0: 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 l; /*
99d0: 54 68 65 20 64 65 66 61 75 6c 74 20 63 6f 6c 6c The default coll
99e0: 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 28 ating sequence (
99f0: 42 49 4e 41 52 59 29 20 2a 2f 0a 20 20 73 71 6c BINARY) */. sql
9a00: 69 74 65 33 5f 6d 75 74 65 78 20 2a 6d 75 74 65 ite3_mutex *mute
9a10: 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f x; /* Co
9a20: 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 65 78 20 2a nnection mutex *
9a30: 2f 0a 20 20 44 62 20 2a 61 44 62 3b 20 20 20 20 /. Db *aDb;
9a40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9a50: 20 20 2f 2a 20 41 6c 6c 20 62 61 63 6b 65 6e 64 /* All backend
9a60: 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 44 62 3b 20 s */. int nDb;
9a70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9a80: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
9a90: 66 20 62 61 63 6b 65 6e 64 73 20 63 75 72 72 65 f backends curre
9aa0: 6e 74 6c 79 20 69 6e 20 75 73 65 20 2a 2f 0a 20 ntly in use */.
9ab0: 20 69 6e 74 20 66 6c 61 67 73 3b 20 20 20 20 20 int flags;
9ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
9ad0: 2a 20 4d 69 73 63 65 6c 6c 61 6e 65 6f 75 73 20 * Miscellaneous
9ae0: 66 6c 61 67 73 2e 20 53 65 65 20 62 65 6c 6f 77 flags. See below
9af0: 20 2a 2f 0a 20 20 69 36 34 20 6c 61 73 74 52 6f */. i64 lastRo
9b00: 77 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 wid;
9b10: 20 20 20 20 2f 2a 20 52 4f 57 49 44 20 6f 66 20 /* ROWID of
9b20: 6d 6f 73 74 20 72 65 63 65 6e 74 20 69 6e 73 65 most recent inse
9b30: 72 74 20 28 73 65 65 20 61 62 6f 76 65 29 20 2a rt (see above) *
9b40: 2f 0a 20 20 69 36 34 20 73 7a 4d 6d 61 70 3b 20 /. i64 szMmap;
9b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9b60: 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 6d 6d 61 /* Default mma
9b70: 70 5f 73 69 7a 65 20 73 65 74 74 69 6e 67 20 2a p_size setting *
9b80: 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 /. unsigned int
9b90: 20 6f 70 65 6e 46 6c 61 67 73 3b 20 20 20 20 20 openFlags;
9ba0: 20 20 2f 2a 20 46 6c 61 67 73 20 70 61 73 73 65 /* Flags passe
9bb0: 64 20 74 6f 20 73 71 6c 69 74 65 33 5f 76 66 73 d to sqlite3_vfs
9bc0: 2e 78 4f 70 65 6e 28 29 20 2a 2f 0a 20 20 69 6e .xOpen() */. in
9bd0: 74 20 65 72 72 43 6f 64 65 3b 20 20 20 20 20 20 t errCode;
9be0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d /* M
9bf0: 6f 73 74 20 72 65 63 65 6e 74 20 65 72 72 6f 72 ost recent error
9c00: 20 63 6f 64 65 20 28 53 51 4c 49 54 45 5f 2a 29 code (SQLITE_*)
9c10: 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 4d 61 73 */. int errMas
9c20: 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 k;
9c30: 20 20 20 20 2f 2a 20 26 20 72 65 73 75 6c 74 20 /* & result
9c40: 63 6f 64 65 73 20 77 69 74 68 20 74 68 69 73 20 codes with this
9c50: 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 6e 67 before returning
9c60: 20 2a 2f 0a 20 20 75 31 36 20 64 62 4f 70 74 46 */. u16 dbOptF
9c70: 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 lags;
9c80: 20 20 20 20 2f 2a 20 46 6c 61 67 73 20 74 6f 20 /* Flags to
9c90: 65 6e 61 62 6c 65 2f 64 69 73 61 62 6c 65 20 6f enable/disable o
9ca0: 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 2a 2f 0a ptimizations */.
9cb0: 20 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 u8 enc;
9cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9cd0: 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 /* Text encoding
9ce0: 20 2a 2f 0a 20 20 75 38 20 61 75 74 6f 43 6f 6d */. u8 autoCom
9cf0: 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 mit;
9d00: 20 20 20 20 2f 2a 20 54 68 65 20 61 75 74 6f 2d /* The auto-
9d10: 63 6f 6d 6d 69 74 20 66 6c 61 67 2e 20 2a 2f 0a commit flag. */.
9d20: 20 20 75 38 20 74 65 6d 70 5f 73 74 6f 72 65 3b u8 temp_store;
9d30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9d40: 2f 2a 20 31 3a 20 66 69 6c 65 20 32 3a 20 6d 65 /* 1: file 2: me
9d50: 6d 6f 72 79 20 30 3a 20 64 65 66 61 75 6c 74 20 mory 0: default
9d60: 2a 2f 0a 20 20 75 38 20 6d 61 6c 6c 6f 63 46 61 */. u8 mallocFa
9d70: 69 6c 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 iled;
9d80: 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 77 65 /* True if we
9d90: 20 68 61 76 65 20 73 65 65 6e 20 61 20 6d 61 6c have seen a mal
9da0: 6c 6f 63 20 66 61 69 6c 75 72 65 20 2a 2f 0a 20 loc failure */.
9db0: 20 75 38 20 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 u8 dfltLockMode
9dc0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
9dd0: 2a 20 44 65 66 61 75 6c 74 20 6c 6f 63 6b 69 6e * Default lockin
9de0: 67 2d 6d 6f 64 65 20 66 6f 72 20 61 74 74 61 63 g-mode for attac
9df0: 68 65 64 20 64 62 73 20 2a 2f 0a 20 20 73 69 67 hed dbs */. sig
9e00: 6e 65 64 20 63 68 61 72 20 6e 65 78 74 41 75 74 ned char nextAut
9e10: 6f 76 61 63 3b 20 20 20 20 20 20 2f 2a 20 41 75 ovac; /* Au
9e20: 74 6f 76 61 63 20 73 65 74 74 69 6e 67 20 61 66 tovac setting af
9e30: 74 65 72 20 56 41 43 55 55 4d 20 69 66 20 3e 3d ter VACUUM if >=
9e40: 30 20 2a 2f 0a 20 20 75 38 20 73 75 70 70 72 65 0 */. u8 suppre
9e50: 73 73 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 ssErr;
9e60: 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 /* Do not i
9e70: 73 73 75 65 20 65 72 72 6f 72 20 6d 65 73 73 61 ssue error messa
9e80: 67 65 73 20 69 66 20 74 72 75 65 20 2a 2f 0a 20 ges if true */.
9e90: 20 75 38 20 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 u8 vtabOnConfli
9ea0: 63 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ct; /
9eb0: 2a 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 72 * Value to retur
9ec0: 6e 20 66 6f 72 20 73 33 5f 76 74 61 62 5f 6f 6e n for s3_vtab_on
9ed0: 5f 63 6f 6e 66 6c 69 63 74 28 29 20 2a 2f 0a 20 _conflict() */.
9ee0: 20 75 38 20 69 73 54 72 61 6e 73 61 63 74 69 6f u8 isTransactio
9ef0: 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 2f nSavepoint; /
9f00: 2a 20 54 72 75 65 20 69 66 20 74 68 65 20 6f 75 * True if the ou
9f10: 74 65 72 6d 6f 73 74 20 73 61 76 65 70 6f 69 6e termost savepoin
9f20: 74 20 69 73 20 61 20 54 53 20 2a 2f 0a 20 20 69 t is a TS */. i
9f30: 6e 74 20 6e 65 78 74 50 61 67 65 73 69 7a 65 3b nt nextPagesize;
9f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9f50: 50 61 67 65 73 69 7a 65 20 61 66 74 65 72 20 56 Pagesize after V
9f60: 41 43 55 55 4d 20 69 66 20 3e 30 20 2a 2f 0a 20 ACUUM if >0 */.
9f70: 20 75 33 32 20 6d 61 67 69 63 3b 20 20 20 20 20 u32 magic;
9f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
9f90: 2a 20 4d 61 67 69 63 20 6e 75 6d 62 65 72 20 66 * Magic number f
9fa0: 6f 72 20 64 65 74 65 63 74 20 6c 69 62 72 61 72 or detect librar
9fb0: 79 20 6d 69 73 75 73 65 20 2a 2f 0a 20 20 69 6e y misuse */. in
9fc0: 74 20 6e 43 68 61 6e 67 65 3b 20 20 20 20 20 20 t nChange;
9fd0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 /* V
9fe0: 61 6c 75 65 20 72 65 74 75 72 6e 65 64 20 62 79 alue returned by
9ff0: 20 73 71 6c 69 74 65 33 5f 63 68 61 6e 67 65 73 sqlite3_changes
a000: 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 6f 74 () */. int nTot
a010: 61 6c 43 68 61 6e 67 65 3b 20 20 20 20 20 20 20 alChange;
a020: 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 72 /* Value r
a030: 65 74 75 72 6e 65 64 20 62 79 20 73 71 6c 69 74 eturned by sqlit
a040: 65 33 5f 74 6f 74 61 6c 5f 63 68 61 6e 67 65 73 e3_total_changes
a050: 28 29 20 2a 2f 0a 20 20 69 6e 74 20 61 4c 69 6d () */. int aLim
a060: 69 74 5b 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 it[SQLITE_N_LIMI
a070: 54 5d 3b 20 20 20 2f 2a 20 4c 69 6d 69 74 73 20 T]; /* Limits
a080: 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 78 53 6f 72 */. int nMaxSor
a090: 74 65 72 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 terMmap;
a0a0: 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 73 69 /* Maximum si
a0b0: 7a 65 20 6f 66 20 72 65 67 69 6f 6e 73 20 6d 61 ze of regions ma
a0c0: 70 70 65 64 20 62 79 20 73 6f 72 74 65 72 20 2a pped by sorter *
a0d0: 2f 0a 20 20 73 74 72 75 63 74 20 73 71 6c 69 74 /. struct sqlit
a0e0: 65 33 49 6e 69 74 49 6e 66 6f 20 7b 20 20 20 20 e3InitInfo {
a0f0: 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e /* Information
a100: 20 75 73 65 64 20 64 75 72 69 6e 67 20 69 6e 69 used during ini
a110: 74 69 61 6c 69 7a 61 74 69 6f 6e 20 2a 2f 0a 20 tialization */.
a120: 20 20 20 69 6e 74 20 6e 65 77 54 6e 75 6d 3b 20 int newTnum;
a130: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
a140: 2a 20 52 6f 6f 74 70 61 67 65 20 6f 66 20 74 61 * Rootpage of ta
a150: 62 6c 65 20 62 65 69 6e 67 20 69 6e 69 74 69 61 ble being initia
a160: 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 20 75 38 20 lized */. u8
a170: 69 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 iDb;
a180: 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 69 63 /* Whic
a190: 68 20 64 62 20 66 69 6c 65 20 69 73 20 62 65 69 h db file is bei
a1a0: 6e 67 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a ng initialized *
a1b0: 2f 0a 20 20 20 20 75 38 20 62 75 73 79 3b 20 20 /. u8 busy;
a1c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a1d0: 20 20 2f 2a 20 54 52 55 45 20 69 66 20 63 75 72 /* TRUE if cur
a1e0: 72 65 6e 74 6c 79 20 69 6e 69 74 69 61 6c 69 7a rently initializ
a1f0: 69 6e 67 20 2a 2f 0a 20 20 20 20 75 38 20 6f 72 ing */. u8 or
a200: 70 68 61 6e 54 72 69 67 67 65 72 3b 20 20 20 20 phanTrigger;
a210: 20 20 20 20 20 20 20 2f 2a 20 4c 61 73 74 20 73 /* Last s
a220: 74 61 74 65 6d 65 6e 74 20 69 73 20 6f 72 70 68 tatement is orph
a230: 61 6e 65 64 20 54 45 4d 50 20 74 72 69 67 67 65 aned TEMP trigge
a240: 72 20 2a 2f 0a 20 20 20 20 75 38 20 69 6d 70 6f r */. u8 impo
a250: 73 74 65 72 54 61 62 6c 65 3b 20 20 20 20 20 20 sterTable;
a260: 20 20 20 20 20 2f 2a 20 42 75 69 6c 64 69 6e 67 /* Building
a270: 20 61 6e 20 69 6d 70 6f 73 74 65 72 20 74 61 62 an imposter tab
a280: 6c 65 20 2a 2f 0a 20 20 7d 20 69 6e 69 74 3b 0a le */. } init;.
a290: 20 20 69 6e 74 20 6e 56 64 62 65 41 63 74 69 76 int nVdbeActiv
a2a0: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
a2b0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 56 44 42 /* Number of VDB
a2c0: 45 73 20 63 75 72 72 65 6e 74 6c 79 20 72 75 6e Es currently run
a2d0: 6e 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 ning */. int nV
a2e0: 64 62 65 52 65 61 64 3b 20 20 20 20 20 20 20 20 dbeRead;
a2f0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
a300: 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 r of active VDBE
a310: 73 20 74 68 61 74 20 72 65 61 64 20 6f 72 20 77 s that read or w
a320: 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 rite */. int nV
a330: 64 62 65 57 72 69 74 65 3b 20 20 20 20 20 20 20 dbeWrite;
a340: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
a350: 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 r of active VDBE
a360: 73 20 74 68 61 74 20 72 65 61 64 20 61 6e 64 20 s that read and
a370: 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e write */. int n
a380: 56 64 62 65 45 78 65 63 3b 20 20 20 20 20 20 20 VdbeExec;
a390: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
a3a0: 65 72 20 6f 66 20 6e 65 73 74 65 64 20 63 61 6c er of nested cal
a3b0: 6c 73 20 74 6f 20 56 64 62 65 45 78 65 63 28 29 ls to VdbeExec()
a3c0: 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 44 65 73 74 */. int nVDest
a3d0: 72 6f 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 roy;
a3e0: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
a3f0: 20 61 63 74 69 76 65 20 4f 50 5f 56 44 65 73 74 active OP_VDest
a400: 72 6f 79 20 6f 70 65 72 61 74 69 6f 6e 73 20 2a roy operations *
a410: 2f 0a 20 20 69 6e 74 20 6e 45 78 74 65 6e 73 69 /. int nExtensi
a420: 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 on;
a430: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c /* Number of l
a440: 6f 61 64 65 64 20 65 78 74 65 6e 73 69 6f 6e 73 oaded extensions
a450: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 2a 61 45 78 */. void **aEx
a460: 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 20 20 20 tension;
a470: 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 /* Array of
a480: 73 68 61 72 65 64 20 6c 69 62 72 61 72 79 20 68 shared library h
a490: 61 6e 64 6c 65 73 20 2a 2f 0a 20 20 76 6f 69 64 andles */. void
a4a0: 20 28 2a 78 54 72 61 63 65 29 28 76 6f 69 64 2a (*xTrace)(void*
a4b0: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 20 20 ,const char*);
a4c0: 20 20 20 20 20 20 2f 2a 20 54 72 61 63 65 20 66 /* Trace f
a4d0: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 unction */. voi
a4e0: 64 20 2a 70 54 72 61 63 65 41 72 67 3b 20 20 20 d *pTraceArg;
a4f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a500: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
a510: 6e 74 20 74 6f 20 74 68 65 20 74 72 61 63 65 20 nt to the trace
a520: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f function */. vo
a530: 69 64 20 28 2a 78 50 72 6f 66 69 6c 65 29 28 76 id (*xProfile)(v
a540: 6f 69 64 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a oid*,const char*
a550: 2c 75 36 34 29 3b 20 20 2f 2a 20 50 72 6f 66 69 ,u64); /* Profi
a560: 6c 69 6e 67 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ling function */
a570: 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f 66 69 6c . void *pProfil
a580: 65 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 eArg;
a590: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
a5a0: 41 72 67 75 6d 65 6e 74 20 74 6f 20 70 72 6f 66 Argument to prof
a5b0: 69 6c 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a ile function */.
a5c0: 20 20 76 6f 69 64 20 2a 70 43 6f 6d 6d 69 74 41 void *pCommitA
a5d0: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
a5e0: 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 /* Argument
a5f0: 74 6f 20 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 to xCommitCallba
a600: 63 6b 28 29 20 2a 2f 20 20 20 0a 20 20 69 6e 74 ck() */ . int
a610: 20 28 2a 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 (*xCommitCallba
a620: 63 6b 29 28 76 6f 69 64 2a 29 3b 20 20 20 20 2f ck)(void*); /
a630: 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 * Invoked at eve
a640: 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 ry commit. */.
a650: 76 6f 69 64 20 2a 70 52 6f 6c 6c 62 61 63 6b 41 void *pRollbackA
a660: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
a670: 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f /* Argument to
a680: 20 78 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 xRollbackCallba
a690: 63 6b 28 29 20 2a 2f 20 20 20 0a 20 20 76 6f 69 ck() */ . voi
a6a0: 64 20 28 2a 78 52 6f 6c 6c 62 61 63 6b 43 61 6c d (*xRollbackCal
a6b0: 6c 62 61 63 6b 29 28 76 6f 69 64 2a 29 3b 20 2f lback)(void*); /
a6c0: 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 * Invoked at eve
a6d0: 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 ry commit. */.
a6e0: 76 6f 69 64 20 2a 70 55 70 64 61 74 65 41 72 67 void *pUpdateArg
a6f0: 3b 0a 20 20 76 6f 69 64 20 28 2a 78 55 70 64 61 ;. void (*xUpda
a700: 74 65 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 teCallback)(void
a710: 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 *,int, const cha
a720: 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 73 r*,const char*,s
a730: 71 6c 69 74 65 5f 69 6e 74 36 34 29 3b 0a 23 69 qlite_int64);.#i
a740: 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
a750: 4c 45 5f 50 52 45 55 50 44 41 54 45 5f 48 4f 4f LE_PREUPDATE_HOO
a760: 4b 0a 20 20 76 6f 69 64 20 2a 70 50 72 65 55 70 K. void *pPreUp
a770: 64 61 74 65 41 72 67 3b 20 20 20 20 20 20 20 20 dateArg;
a780: 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 75 6d /* First argum
a790: 65 6e 74 20 74 6f 20 78 50 72 65 55 70 64 61 74 ent to xPreUpdat
a7a0: 65 43 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 eCallback */. v
a7b0: 6f 69 64 20 28 2a 78 50 72 65 55 70 64 61 74 65 oid (*xPreUpdate
a7c0: 43 61 6c 6c 62 61 63 6b 29 28 20 20 20 2f 2a 20 Callback)( /*
a7d0: 52 65 67 69 73 74 65 72 65 64 20 75 73 69 6e 67 Registered using
a7e0: 20 73 71 6c 69 74 65 33 5f 70 72 65 75 70 64 61 sqlite3_preupda
a7f0: 74 65 5f 68 6f 6f 6b 28 29 20 2a 2f 0a 20 20 20 te_hook() */.
a800: 20 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c void*,sqlite3*,
a810: 69 6e 74 2c 63 68 61 72 20 63 6f 6e 73 74 2a 2c int,char const*,
a820: 63 68 61 72 20 63 6f 6e 73 74 2a 2c 73 71 6c 69 char const*,sqli
a830: 74 65 33 5f 69 6e 74 36 34 2c 73 71 6c 69 74 65 te3_int64,sqlite
a840: 33 5f 69 6e 74 36 34 0a 20 20 29 3b 0a 20 20 50 3_int64. );. P
a850: 72 65 55 70 64 61 74 65 20 2a 70 50 72 65 55 70 reUpdate *pPreUp
a860: 64 61 74 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 date; /*
a870: 43 6f 6e 74 65 78 74 20 66 6f 72 20 61 63 74 69 Context for acti
a880: 76 65 20 70 72 65 2d 75 70 64 61 74 65 20 63 61 ve pre-update ca
a890: 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 llback */.#endif
a8a0: 20 2f 2a 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c /* SQLITE_ENABL
a8b0: 45 5f 50 52 45 55 50 44 41 54 45 5f 48 4f 4f 4b E_PREUPDATE_HOOK
a8c0: 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
a8d0: 54 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e TE_OMIT_WAL. in
a8e0: 74 20 28 2a 78 57 61 6c 43 61 6c 6c 62 61 63 6b t (*xWalCallback
a8f0: 29 28 76 6f 69 64 20 2a 2c 20 73 71 6c 69 74 65 )(void *, sqlite
a900: 33 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 3 *, const char
a910: 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 *, int);. void
a920: 2a 70 57 61 6c 41 72 67 3b 0a 23 65 6e 64 69 66 *pWalArg;.#endif
a930: 0a 20 20 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 . void(*xCollNe
a940: 65 64 65 64 29 28 76 6f 69 64 2a 2c 73 71 6c 69 eded)(void*,sqli
a950: 74 65 33 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 te3*,int eTextRe
a960: 70 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a p,const char*);.
a970: 20 20 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 void(*xCollNee
a980: 64 65 64 31 36 29 28 76 6f 69 64 2a 2c 73 71 6c ded16)(void*,sql
a990: 69 74 65 33 2a 2c 69 6e 74 20 65 54 65 78 74 52 ite3*,int eTextR
a9a0: 65 70 2c 63 6f 6e 73 74 20 76 6f 69 64 2a 29 3b ep,const void*);
a9b0: 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6c 6c 4e 65 . void *pCollNe
a9c0: 65 64 65 64 41 72 67 3b 0a 20 20 73 71 6c 69 74 ededArg;. sqlit
a9d0: 65 33 5f 76 61 6c 75 65 20 2a 70 45 72 72 3b 20 e3_value *pErr;
a9e0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f 73 74 /* Most
a9f0: 20 72 65 63 65 6e 74 20 65 72 72 6f 72 20 6d 65 recent error me
aa00: 73 73 61 67 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e ssage */. union
aa10: 20 7b 0a 20 20 20 20 76 6f 6c 61 74 69 6c 65 20 {. volatile
aa20: 69 6e 74 20 69 73 49 6e 74 65 72 72 75 70 74 65 int isInterrupte
aa30: 64 3b 20 2f 2a 20 54 72 75 65 20 69 66 20 73 71 d; /* True if sq
aa40: 6c 69 74 65 33 5f 69 6e 74 65 72 72 75 70 74 20 lite3_interrupt
aa50: 68 61 73 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 has been called
aa60: 2a 2f 0a 20 20 20 20 64 6f 75 62 6c 65 20 6e 6f */. double no
aa70: 74 55 73 65 64 31 3b 20 20 20 20 20 20 20 20 20 tUsed1;
aa80: 20 20 20 2f 2a 20 53 70 61 63 65 72 20 2a 2f 0a /* Spacer */.
aa90: 20 20 7d 20 75 31 3b 0a 20 20 4c 6f 6f 6b 61 73 } u1;. Lookas
aaa0: 69 64 65 20 6c 6f 6f 6b 61 73 69 64 65 3b 20 20 ide lookaside;
aab0: 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 6b 61 /* Looka
aac0: 73 69 64 65 20 6d 61 6c 6c 6f 63 20 63 6f 6e 66 side malloc conf
aad0: 69 67 75 72 61 74 69 6f 6e 20 2a 2f 0a 23 69 66 iguration */.#if
aae0: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
aaf0: 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 _AUTHORIZATION.
ab00: 20 73 71 6c 69 74 65 33 5f 78 61 75 74 68 20 78 sqlite3_xauth x
ab10: 41 75 74 68 3b 20 20 20 20 20 20 20 20 20 20 2f Auth; /
ab20: 2a 20 41 63 63 65 73 73 20 61 75 74 68 6f 72 69 * Access authori
ab30: 7a 61 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 zation function
ab40: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 41 75 74 68 */. void *pAuth
ab50: 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Arg;
ab60: 20 20 20 2f 2a 20 31 73 74 20 61 72 67 75 6d 65 /* 1st argume
ab70: 6e 74 20 74 6f 20 74 68 65 20 61 63 63 65 73 73 nt to the access
ab80: 20 61 75 74 68 20 66 75 6e 63 74 69 6f 6e 20 2a auth function *
ab90: 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 /.#endif.#ifndef
aba0: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 50 52 4f SQLITE_OMIT_PRO
abb0: 47 52 45 53 53 5f 43 41 4c 4c 42 41 43 4b 0a 20 GRESS_CALLBACK.
abc0: 20 69 6e 74 20 28 2a 78 50 72 6f 67 72 65 73 73 int (*xProgress
abd0: 29 28 76 6f 69 64 20 2a 29 3b 20 20 20 20 20 2f )(void *); /
abe0: 2a 20 54 68 65 20 70 72 6f 67 72 65 73 73 20 63 * The progress c
abf0: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 allback */. voi
ac00: 64 20 2a 70 50 72 6f 67 72 65 73 73 41 72 67 3b d *pProgressArg;
ac10: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
ac20: 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 70 72 gument to the pr
ac30: 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 ogress callback
ac40: 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 6e 50 */. unsigned nP
ac50: 72 6f 67 72 65 73 73 4f 70 73 3b 20 20 20 20 20 rogressOps;
ac60: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
ac70: 6f 70 63 6f 64 65 73 20 66 6f 72 20 70 72 6f 67 opcodes for prog
ac80: 72 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f ress callback */
ac90: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
aca0: 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
acb0: 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 20 6e UALTABLE. int n
acc0: 56 54 72 61 6e 73 3b 20 20 20 20 20 20 20 20 20 VTrans;
acd0: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 6f /* Allo
ace0: 63 61 74 65 64 20 73 69 7a 65 20 6f 66 20 61 56 cated size of aV
acf0: 54 72 61 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 Trans */. Hash
ad00: 61 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 20 20 aModule;
ad10: 20 20 20 20 20 20 20 20 20 2f 2a 20 70 6f 70 75 /* popu
ad20: 6c 61 74 65 64 20 62 79 20 73 71 6c 69 74 65 33 lated by sqlite3
ad30: 5f 63 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 _create_module()
ad40: 20 2a 2f 0a 20 20 56 74 61 62 43 74 78 20 2a 70 */. VtabCtx *p
ad50: 56 74 61 62 43 74 78 3b 20 20 20 20 20 20 20 20 VtabCtx;
ad60: 20 20 20 20 2f 2a 20 43 6f 6e 74 65 78 74 20 66 /* Context f
ad70: 6f 72 20 61 63 74 69 76 65 20 76 74 61 62 20 63 or active vtab c
ad80: 6f 6e 6e 65 63 74 2f 63 72 65 61 74 65 20 2a 2f onnect/create */
ad90: 0a 20 20 56 54 61 62 6c 65 20 2a 2a 61 56 54 72 . VTable **aVTr
ada0: 61 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ans;
adb0: 20 2f 2a 20 56 69 72 74 75 61 6c 20 74 61 62 6c /* Virtual tabl
adc0: 65 73 20 77 69 74 68 20 6f 70 65 6e 20 74 72 61 es with open tra
add0: 6e 73 61 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 56 nsactions */. V
ade0: 54 61 62 6c 65 20 2a 70 44 69 73 63 6f 6e 6e 65 Table *pDisconne
adf0: 63 74 3b 20 20 20 20 2f 2a 20 44 69 73 63 6f 6e ct; /* Discon
ae00: 6e 65 63 74 20 74 68 65 73 65 20 69 6e 20 6e 65 nect these in ne
ae10: 78 74 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 xt sqlite3_prepa
ae20: 72 65 28 29 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 re() */.#endif.
ae30: 20 46 75 6e 63 44 65 66 48 61 73 68 20 61 46 75 FuncDefHash aFu
ae40: 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f nc; /
ae50: 2a 20 48 61 73 68 20 74 61 62 6c 65 20 6f 66 20 * Hash table of
ae60: 63 6f 6e 6e 65 63 74 69 6f 6e 20 66 75 6e 63 74 connection funct
ae70: 69 6f 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 61 ions */. Hash a
ae80: 43 6f 6c 6c 53 65 71 3b 20 20 20 20 20 20 20 20 CollSeq;
ae90: 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 63 /* All c
aea0: 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
aeb0: 65 73 20 2a 2f 0a 20 20 42 75 73 79 48 61 6e 64 es */. BusyHand
aec0: 6c 65 72 20 62 75 73 79 48 61 6e 64 6c 65 72 3b ler busyHandler;
aed0: 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 63 61 /* Busy ca
aee0: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 44 62 20 61 llback */. Db a
aef0: 44 62 53 74 61 74 69 63 5b 32 5d 3b 20 20 20 20 DbStatic[2];
af00: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 61 /* Sta
af10: 74 69 63 20 73 70 61 63 65 20 66 6f 72 20 74 68 tic space for th
af20: 65 20 32 20 64 65 66 61 75 6c 74 20 62 61 63 6b e 2 default back
af30: 65 6e 64 73 20 2a 2f 0a 20 20 53 61 76 65 70 6f ends */. Savepo
af40: 69 6e 74 20 2a 70 53 61 76 65 70 6f 69 6e 74 3b int *pSavepoint;
af50: 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 /* List
af60: 6f 66 20 61 63 74 69 76 65 20 73 61 76 65 70 6f of active savepo
af70: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 62 75 ints */. int bu
af80: 73 79 54 69 6d 65 6f 75 74 3b 20 20 20 20 20 20 syTimeout;
af90: 20 20 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 /* Busy
afa0: 68 61 6e 64 6c 65 72 20 74 69 6d 65 6f 75 74 2c handler timeout,
afb0: 20 69 6e 20 6d 73 65 63 20 2a 2f 0a 20 20 69 6e in msec */. in
afc0: 74 20 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 t nSavepoint;
afd0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
afe0: 75 6d 62 65 72 20 6f 66 20 6e 6f 6e 2d 74 72 61 umber of non-tra
aff0: 6e 73 61 63 74 69 6f 6e 20 73 61 76 65 70 6f 69 nsaction savepoi
b000: 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 nts */. int nSt
b010: 61 74 65 6d 65 6e 74 3b 20 20 20 20 20 20 20 20 atement;
b020: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
b030: 20 6f 66 20 6e 65 73 74 65 64 20 73 74 61 74 65 of nested state
b040: 6d 65 6e 74 2d 74 72 61 6e 73 61 63 74 69 6f 6e ment-transaction
b050: 73 20 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 s */. i64 nDef
b060: 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 erredCons;
b070: 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 66 /* Net def
b080: 65 72 72 65 64 20 63 6f 6e 73 74 72 61 69 6e 74 erred constraint
b090: 73 20 74 68 69 73 20 74 72 61 6e 73 61 63 74 69 s this transacti
b0a0: 6f 6e 2e 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 on. */. i64 nDe
b0b0: 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 ferredImmCons;
b0c0: 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 /* Net de
b0d0: 66 65 72 72 65 64 20 69 6d 6d 65 64 69 61 74 65 ferred immediate
b0e0: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
b0f0: 20 20 69 6e 74 20 2a 70 6e 42 79 74 65 73 46 72 int *pnBytesFr
b100: 65 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 eed;
b110: 2f 2a 20 49 66 20 6e 6f 74 20 4e 55 4c 4c 2c 20 /* If not NULL,
b120: 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 73 20 69 increment this i
b130: 6e 20 44 62 46 72 65 65 28 29 20 2a 2f 0a 23 69 n DbFree() */.#i
b140: 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
b150: 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 59 LE_UNLOCK_NOTIFY
b160: 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 . /* The follow
b170: 69 6e 67 20 76 61 72 69 61 62 6c 65 73 20 61 72 ing variables ar
b180: 65 20 61 6c 6c 20 70 72 6f 74 65 63 74 65 64 20 e all protected
b190: 62 79 20 74 68 65 20 53 54 41 54 49 43 5f 4d 41 by the STATIC_MA
b1a0: 53 54 45 52 20 0a 20 20 2a 2a 20 6d 75 74 65 78 STER . ** mutex
b1b0: 2c 20 6e 6f 74 20 62 79 20 73 71 6c 69 74 65 33 , not by sqlite3
b1c0: 2e 6d 75 74 65 78 2e 20 54 68 65 79 20 61 72 65 .mutex. They are
b1d0: 20 75 73 65 64 20 62 79 20 63 6f 64 65 20 69 6e used by code in
b1e0: 20 6e 6f 74 69 66 79 2e 63 2e 20 0a 20 20 2a 2a notify.c. . **
b1f0: 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 55 6e . ** When X.pUn
b200: 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d lockConnection==
b210: 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 68 Y, that means th
b220: 61 74 20 58 20 69 73 20 77 61 69 74 69 6e 67 20 at X is waiting
b230: 66 6f 72 20 59 20 74 6f 0a 20 20 2a 2a 20 75 6e for Y to. ** un
b240: 6c 6f 63 6b 20 73 6f 20 74 68 61 74 20 69 74 20 lock so that it
b250: 63 61 6e 20 70 72 6f 63 65 65 64 2e 0a 20 20 2a can proceed.. *
b260: 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 42 *. ** When X.pB
b270: 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 6f lockingConnectio
b280: 6e 3d 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 n==Y, that means
b290: 20 74 68 61 74 20 73 6f 6d 65 74 68 69 6e 67 20 that something
b2a0: 74 68 61 74 20 58 20 74 72 69 65 64 0a 20 20 2a that X tried. *
b2b0: 2a 20 74 72 69 65 64 20 74 6f 20 64 6f 20 72 65 * tried to do re
b2c0: 63 65 6e 74 6c 79 20 66 61 69 6c 65 64 20 77 69 cently failed wi
b2d0: 74 68 20 61 6e 20 53 51 4c 49 54 45 5f 4c 4f 43 th an SQLITE_LOC
b2e0: 4b 45 44 20 65 72 72 6f 72 20 64 75 65 20 74 6f KED error due to
b2f0: 20 6c 6f 63 6b 73 0a 20 20 2a 2a 20 68 65 6c 64 locks. ** held
b300: 20 62 79 20 59 2e 0a 20 20 2a 2f 0a 20 20 73 71 by Y.. */. sq
b310: 6c 69 74 65 33 20 2a 70 42 6c 6f 63 6b 69 6e 67 lite3 *pBlocking
b320: 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 2f 2a 20 43 Connection; /* C
b330: 6f 6e 6e 65 63 74 69 6f 6e 20 74 68 61 74 20 63 onnection that c
b340: 61 75 73 65 64 20 53 51 4c 49 54 45 5f 4c 4f 43 aused SQLITE_LOC
b350: 4b 45 44 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 KED */. sqlite3
b360: 20 2a 70 55 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 *pUnlockConnect
b370: 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 2f ion; /
b380: 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 * Connection to
b390: 77 61 74 63 68 20 66 6f 72 20 75 6e 6c 6f 63 6b watch for unlock
b3a0: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 6e 6c */. void *pUnl
b3b0: 6f 63 6b 41 72 67 3b 20 20 20 20 20 20 20 20 20 ockArg;
b3c0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 /* A
b3d0: 72 67 75 6d 65 6e 74 20 74 6f 20 78 55 6e 6c 6f rgument to xUnlo
b3e0: 63 6b 4e 6f 74 69 66 79 20 2a 2f 0a 20 20 76 6f ckNotify */. vo
b3f0: 69 64 20 28 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 69 id (*xUnlockNoti
b400: 66 79 29 28 76 6f 69 64 20 2a 2a 2c 20 69 6e 74 fy)(void **, int
b410: 29 3b 20 20 2f 2a 20 55 6e 6c 6f 63 6b 20 6e 6f ); /* Unlock no
b420: 74 69 66 79 20 63 61 6c 6c 62 61 63 6b 20 2a 2f tify callback */
b430: 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 4e 65 78 . sqlite3 *pNex
b440: 74 42 6c 6f 63 6b 65 64 3b 20 20 20 20 20 20 20 tBlocked;
b450: 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 73 74 /* Next in list
b460: 20 6f 66 20 61 6c 6c 20 62 6c 6f 63 6b 65 64 20 of all blocked
b470: 63 6f 6e 6e 65 63 74 69 6f 6e 73 20 2a 2f 0a 23 connections */.#
b480: 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c endif.#ifdef SQL
b490: 49 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 ITE_USER_AUTHENT
b4a0: 49 43 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 65 ICATION. sqlite
b4b0: 33 5f 75 73 65 72 61 75 74 68 20 61 75 74 68 3b 3_userauth auth;
b4c0: 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 72 20 /* User
b4d0: 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 69 authentication i
b4e0: 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 23 65 nformation */.#e
b4f0: 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 ndif.};../*.** A
b500: 20 6d 61 63 72 6f 20 74 6f 20 64 69 73 63 6f 76 macro to discov
b510: 65 72 20 74 68 65 20 65 6e 63 6f 64 69 6e 67 20 er the encoding
b520: 6f 66 20 61 20 64 61 74 61 62 61 73 65 2e 0a 2a of a database..*
b530: 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 45 4d 41 /.#define SCHEMA
b540: 5f 45 4e 43 28 64 62 29 20 28 28 64 62 29 2d 3e _ENC(db) ((db)->
b550: 61 44 62 5b 30 5d 2e 70 53 63 68 65 6d 61 2d 3e aDb[0].pSchema->
b560: 65 6e 63 29 0a 23 64 65 66 69 6e 65 20 45 4e 43 enc).#define ENC
b570: 28 64 62 29 20 20 20 20 20 20 20 20 28 28 64 62 (db) ((db
b580: 29 2d 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 )->enc)../*.** P
b590: 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 ossible values f
b5a0: 6f 72 20 74 68 65 20 73 71 6c 69 74 65 33 2e 66 or the sqlite3.f
b5b0: 6c 61 67 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 lags..*/.#define
b5c0: 20 53 51 4c 49 54 45 5f 56 64 62 65 54 72 61 63 SQLITE_VdbeTrac
b5d0: 65 20 20 20 20 20 20 30 78 30 30 30 30 30 30 30 e 0x0000000
b5e0: 31 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 74 72 1 /* True to tr
b5f0: 61 63 65 20 56 44 42 45 20 65 78 65 63 75 74 69 ace VDBE executi
b600: 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 on */.#define SQ
b610: 4c 49 54 45 5f 49 6e 74 65 72 6e 43 68 61 6e 67 LITE_InternChang
b620: 65 73 20 20 30 78 30 30 30 30 30 30 30 32 20 20 es 0x00000002
b630: 2f 2a 20 55 6e 63 6f 6d 6d 69 74 74 65 64 20 48 /* Uncommitted H
b640: 61 73 68 20 74 61 62 6c 65 20 63 68 61 6e 67 65 ash table change
b650: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
b660: 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 20 20 20 ITE_FullFSync
b670: 20 20 20 30 78 30 30 30 30 30 30 30 34 20 20 2f 0x00000004 /
b680: 2a 20 55 73 65 20 66 75 6c 6c 20 66 73 79 6e 63 * Use full fsync
b690: 20 6f 6e 20 74 68 65 20 62 61 63 6b 65 6e 64 20 on the backend
b6a0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b6b0: 45 5f 43 6b 70 74 46 75 6c 6c 46 53 79 6e 63 20 E_CkptFullFSync
b6c0: 20 30 78 30 30 30 30 30 30 30 38 20 20 2f 2a 20 0x00000008 /*
b6d0: 55 73 65 20 66 75 6c 6c 20 66 73 79 6e 63 20 66 Use full fsync f
b6e0: 6f 72 20 63 68 65 63 6b 70 6f 69 6e 74 20 2a 2f or checkpoint */
b6f0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b700: 43 61 63 68 65 53 70 69 6c 6c 20 20 20 20 20 30 CacheSpill 0
b710: 78 30 30 30 30 30 30 31 30 20 20 2f 2a 20 4f 4b x00000010 /* OK
b720: 20 74 6f 20 73 70 69 6c 6c 20 70 61 67 65 72 20 to spill pager
b730: 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 cache */.#define
b740: 20 53 51 4c 49 54 45 5f 46 75 6c 6c 43 6f 6c 4e SQLITE_FullColN
b750: 61 6d 65 73 20 20 20 30 78 30 30 30 30 30 30 32 ames 0x0000002
b760: 30 20 20 2f 2a 20 53 68 6f 77 20 66 75 6c 6c 20 0 /* Show full
b770: 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6f 6e 20 column names on
b780: 53 45 4c 45 43 54 20 2a 2f 0a 23 64 65 66 69 6e SELECT */.#defin
b790: 65 20 53 51 4c 49 54 45 5f 53 68 6f 72 74 43 6f e SQLITE_ShortCo
b7a0: 6c 4e 61 6d 65 73 20 20 30 78 30 30 30 30 30 30 lNames 0x000000
b7b0: 34 30 20 20 2f 2a 20 53 68 6f 77 20 73 68 6f 72 40 /* Show shor
b7c0: 74 20 63 6f 6c 75 6d 6e 73 20 6e 61 6d 65 73 20 t columns names
b7d0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b7e0: 45 5f 43 6f 75 6e 74 52 6f 77 73 20 20 20 20 20 E_CountRows
b7f0: 20 30 78 30 30 30 30 30 30 38 30 20 20 2f 2a 20 0x00000080 /*
b800: 43 6f 75 6e 74 20 72 6f 77 73 20 63 68 61 6e 67 Count rows chang
b810: 65 64 20 62 79 20 49 4e 53 45 52 54 2c 20 2a 2f ed by INSERT, */
b820: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
b830: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b840: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 /*
b850: 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 41 54 DELETE, or UPDAT
b860: 45 20 61 6e 64 20 72 65 74 75 72 6e 20 2a 2f 0a E and return */.
b870: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b880: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b890: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 74 /* t
b8a0: 68 65 20 63 6f 75 6e 74 20 75 73 69 6e 67 20 61 he count using a
b8b0: 20 63 61 6c 6c 62 61 63 6b 2e 20 2a 2f 0a 23 64 callback. */.#d
b8c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 75 6c efine SQLITE_Nul
b8d0: 6c 43 61 6c 6c 62 61 63 6b 20 20 20 30 78 30 30 lCallback 0x00
b8e0: 30 30 30 31 30 30 20 20 2f 2a 20 49 6e 76 6f 6b 000100 /* Invok
b8f0: 65 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 6f e the callback o
b900: 6e 63 65 20 69 66 20 74 68 65 20 2a 2f 0a 20 20 nce if the */.
b910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b920: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b930: 20 20 20 20 20 20 20 20 2f 2a 20 20 20 72 65 73 /* res
b940: 75 6c 74 20 73 65 74 20 69 73 20 65 6d 70 74 79 ult set is empty
b950: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b960: 54 45 5f 53 71 6c 54 72 61 63 65 20 20 20 20 20 TE_SqlTrace
b970: 20 20 30 78 30 30 30 30 30 32 30 30 20 20 2f 2a 0x00000200 /*
b980: 20 44 65 62 75 67 20 70 72 69 6e 74 20 53 51 4c Debug print SQL
b990: 20 61 73 20 69 74 20 65 78 65 63 75 74 65 73 20 as it executes
b9a0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b9b0: 45 5f 56 64 62 65 4c 69 73 74 69 6e 67 20 20 20 E_VdbeListing
b9c0: 20 30 78 30 30 30 30 30 34 30 30 20 20 2f 2a 20 0x00000400 /*
b9d0: 44 65 62 75 67 20 6c 69 73 74 69 6e 67 73 20 6f Debug listings o
b9e0: 66 20 56 44 42 45 20 70 72 6f 67 72 61 6d 73 20 f VDBE programs
b9f0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
ba00: 45 5f 57 72 69 74 65 53 63 68 65 6d 61 20 20 20 E_WriteSchema
ba10: 20 30 78 30 30 30 30 30 38 30 30 20 20 2f 2a 20 0x00000800 /*
ba20: 4f 4b 20 74 6f 20 75 70 64 61 74 65 20 53 51 4c OK to update SQL
ba30: 49 54 45 5f 4d 41 53 54 45 52 20 2a 2f 0a 23 64 ITE_MASTER */.#d
ba40: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 efine SQLITE_Vdb
ba50: 65 41 64 64 6f 70 54 72 61 63 65 20 30 78 30 30 eAddopTrace 0x00
ba60: 30 30 31 30 30 30 20 20 2f 2a 20 54 72 61 63 65 001000 /* Trace
ba70: 20 73 71 6c 69 74 65 33 56 64 62 65 41 64 64 4f sqlite3VdbeAddO
ba80: 70 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 23 64 65 p() calls */.#de
ba90: 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 67 6e 6f fine SQLITE_Igno
baa0: 72 65 43 68 65 63 6b 73 20 20 20 30 78 30 30 30 reChecks 0x000
bab0: 30 32 30 30 30 20 20 2f 2a 20 44 6f 20 6e 6f 74 02000 /* Do not
bac0: 20 65 6e 66 6f 72 63 65 20 63 68 65 63 6b 20 63 enforce check c
bad0: 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 onstraints */.#d
bae0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 61 efine SQLITE_Rea
baf0: 64 55 6e 63 6f 6d 6d 69 74 74 65 64 20 30 78 30 dUncommitted 0x0
bb00: 30 30 34 30 30 30 20 20 2f 2a 20 46 6f 72 20 73 004000 /* For s
bb10: 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 hared-cache mode
bb20: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bb30: 54 45 5f 4c 65 67 61 63 79 46 69 6c 65 46 6d 74 TE_LegacyFileFmt
bb40: 20 20 30 78 30 30 30 30 38 30 30 30 20 20 2f 2a 0x00008000 /*
bb50: 20 43 72 65 61 74 65 20 6e 65 77 20 64 61 74 61 Create new data
bb60: 62 61 73 65 73 20 69 6e 20 66 6f 72 6d 61 74 20 bases in format
bb70: 31 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 1 */.#define SQL
bb80: 49 54 45 5f 52 65 63 6f 76 65 72 79 4d 6f 64 65 ITE_RecoveryMode
bb90: 20 20 20 30 78 30 30 30 31 30 30 30 30 20 20 2f 0x00010000 /
bba0: 2a 20 49 67 6e 6f 72 65 20 73 63 68 65 6d 61 20 * Ignore schema
bbb0: 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e errors */.#defin
bbc0: 65 20 53 51 4c 49 54 45 5f 52 65 76 65 72 73 65 e SQLITE_Reverse
bbd0: 4f 72 64 65 72 20 20 20 30 78 30 30 30 32 30 30 Order 0x000200
bbe0: 30 30 20 20 2f 2a 20 52 65 76 65 72 73 65 20 75 00 /* Reverse u
bbf0: 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 43 54 73 nordered SELECTs
bc00: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bc10: 54 45 5f 52 65 63 54 72 69 67 67 65 72 73 20 20 TE_RecTriggers
bc20: 20 20 30 78 30 30 30 34 30 30 30 30 20 20 2f 2a 0x00040000 /*
bc30: 20 45 6e 61 62 6c 65 20 72 65 63 75 72 73 69 76 Enable recursiv
bc40: 65 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 23 64 e triggers */.#d
bc50: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 6f 72 efine SQLITE_For
bc60: 65 69 67 6e 4b 65 79 73 20 20 20 20 30 78 30 30 eignKeys 0x00
bc70: 30 38 30 30 30 30 20 20 2f 2a 20 45 6e 66 6f 72 080000 /* Enfor
bc80: 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 63 ce foreign key c
bc90: 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a 2f 0a 23 onstraints */.#
bca0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 75 define SQLITE_Au
bcb0: 74 6f 49 6e 64 65 78 20 20 20 20 20 20 30 78 30 toIndex 0x0
bcc0: 30 31 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 0100000 /* Enab
bcd0: 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 69 6e 64 le automatic ind
bce0: 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 exes */.#define
bcf0: 53 51 4c 49 54 45 5f 50 72 65 66 65 72 42 75 69 SQLITE_PreferBui
bd00: 6c 74 69 6e 20 20 30 78 30 30 32 30 30 30 30 30 ltin 0x00200000
bd10: 20 20 2f 2a 20 50 72 65 66 65 72 65 6e 63 65 20 /* Preference
bd20: 74 6f 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e 63 to built-in func
bd30: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
bd40: 49 54 45 5f 4c 6f 61 64 45 78 74 65 6e 73 69 6f ITE_LoadExtensio
bd50: 6e 20 20 30 78 30 30 34 30 30 30 30 30 20 20 2f n 0x00400000 /
bd60: 2a 20 45 6e 61 62 6c 65 20 6c 6f 61 64 5f 65 78 * Enable load_ex
bd70: 74 65 6e 73 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 tension */.#defi
bd80: 6e 65 20 53 51 4c 49 54 45 5f 45 6e 61 62 6c 65 ne SQLITE_Enable
bd90: 54 72 69 67 67 65 72 20 20 30 78 30 30 38 30 30 Trigger 0x00800
bda0: 30 30 30 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 000 /* True to
bdb0: 65 6e 61 62 6c 65 20 74 72 69 67 67 65 72 73 20 enable triggers
bdc0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
bdd0: 45 5f 44 65 66 65 72 46 4b 73 20 20 20 20 20 20 E_DeferFKs
bde0: 20 30 78 30 31 30 30 30 30 30 30 20 20 2f 2a 20 0x01000000 /*
bdf0: 44 65 66 65 72 20 61 6c 6c 20 46 4b 20 63 6f 6e Defer all FK con
be00: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 66 straints */.#def
be10: 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 72 79 ine SQLITE_Query
be20: 4f 6e 6c 79 20 20 20 20 20 20 30 78 30 32 30 30 Only 0x0200
be30: 30 30 30 30 20 20 2f 2a 20 44 69 73 61 62 6c 65 0000 /* Disable
be40: 20 64 61 74 61 62 61 73 65 20 63 68 61 6e 67 65 database change
be50: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
be60: 49 54 45 5f 56 64 62 65 45 51 50 20 20 20 20 20 ITE_VdbeEQP
be70: 20 20 20 30 78 30 34 30 30 30 30 30 30 20 20 2f 0x04000000 /
be80: 2a 20 44 65 62 75 67 20 45 58 50 4c 41 49 4e 20 * Debug EXPLAIN
be90: 51 55 45 52 59 20 50 4c 41 4e 20 2a 2f 0a 23 64 QUERY PLAN */.#d
bea0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 61 63 efine SQLITE_Vac
beb0: 75 75 6d 20 20 20 20 20 20 20 20 20 30 78 30 38 uum 0x08
bec0: 30 30 30 30 30 30 20 20 2f 2a 20 43 75 72 72 65 000000 /* Curre
bed0: 6e 74 6c 79 20 69 6e 20 61 20 56 41 43 55 55 4d ntly in a VACUUM
bee0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bef0: 54 45 5f 43 65 6c 6c 53 69 7a 65 43 6b 20 20 20 TE_CellSizeCk
bf00: 20 20 30 78 31 30 30 30 30 30 30 30 20 20 2f 2a 0x10000000 /*
bf10: 20 43 68 65 63 6b 20 62 74 72 65 65 20 63 65 6c Check btree cel
bf20: 6c 20 73 69 7a 65 73 20 6f 6e 20 6c 6f 61 64 20 l sizes on load
bf30: 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 73 20 */.../*.** Bits
bf40: 6f 66 20 74 68 65 20 73 71 6c 69 74 65 33 2e 64 of the sqlite3.d
bf50: 62 4f 70 74 46 6c 61 67 73 20 66 69 65 6c 64 20 bOptFlags field
bf60: 74 68 61 74 20 61 72 65 20 75 73 65 64 20 62 79 that are used by
bf70: 20 74 68 65 0a 2a 2a 20 73 71 6c 69 74 65 33 5f the.** sqlite3_
bf80: 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 53 51 4c test_control(SQL
bf90: 49 54 45 5f 54 45 53 54 43 54 52 4c 5f 4f 50 54 ITE_TESTCTRL_OPT
bfa0: 49 4d 49 5a 41 54 49 4f 4e 53 2c 2e 2e 2e 29 20 IMIZATIONS,...)
bfb0: 69 6e 74 65 72 66 61 63 65 20 74 6f 0a 2a 2a 20 interface to.**
bfc0: 73 65 6c 65 63 74 69 76 65 6c 79 20 64 69 73 61 selectively disa
bfd0: 62 6c 65 20 76 61 72 69 6f 75 73 20 6f 70 74 69 ble various opti
bfe0: 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 mizations..*/.#d
bff0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 efine SQLITE_Que
c000: 72 79 46 6c 61 74 74 65 6e 65 72 20 30 78 30 30 ryFlattener 0x00
c010: 30 31 20 20 20 2f 2a 20 51 75 65 72 79 20 66 6c 01 /* Query fl
c020: 61 74 74 65 6e 69 6e 67 20 2a 2f 0a 23 64 65 66 attening */.#def
c030: 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f 6c 75 6d ine SQLITE_Colum
c040: 6e 43 61 63 68 65 20 20 20 20 30 78 30 30 30 32 nCache 0x0002
c050: 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 63 61 63 /* Column cac
c060: 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 he */.#define SQ
c070: 4c 49 54 45 5f 47 72 6f 75 70 42 79 4f 72 64 65 LITE_GroupByOrde
c080: 72 20 20 20 30 78 30 30 30 34 20 20 20 2f 2a 20 r 0x0004 /*
c090: 47 52 4f 55 50 42 59 20 63 6f 76 65 72 20 6f 66 GROUPBY cover of
c0a0: 20 4f 52 44 45 52 42 59 20 2a 2f 0a 23 64 65 66 ORDERBY */.#def
c0b0: 69 6e 65 20 53 51 4c 49 54 45 5f 46 61 63 74 6f ine SQLITE_Facto
c0c0: 72 4f 75 74 43 6f 6e 73 74 20 30 78 30 30 30 38 rOutConst 0x0008
c0d0: 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 66 /* Constant f
c0e0: 61 63 74 6f 72 69 6e 67 20 2a 2f 0a 2f 2a 20 20 actoring */./*
c0f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6e 6f no
c100: 74 20 75 73 65 64 20 20 20 20 30 78 30 30 31 30 t used 0x0010
c110: 20 20 20 2f 2f 20 57 61 73 3a 20 53 51 4c 49 54 // Was: SQLIT
c120: 45 5f 49 64 78 52 65 61 6c 41 73 49 6e 74 20 2a E_IdxRealAsInt *
c130: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
c140: 5f 44 69 73 74 69 6e 63 74 4f 70 74 20 20 20 20 _DistinctOpt
c150: 30 78 30 30 32 30 20 20 20 2f 2a 20 44 49 53 54 0x0020 /* DIST
c160: 49 4e 43 54 20 75 73 69 6e 67 20 69 6e 64 65 78 INCT using index
c170: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
c180: 4c 49 54 45 5f 43 6f 76 65 72 49 64 78 53 63 61 LITE_CoverIdxSca
c190: 6e 20 20 20 30 78 30 30 34 30 20 20 20 2f 2a 20 n 0x0040 /*
c1a0: 43 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 73 Covering index s
c1b0: 63 61 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 cans */.#define
c1c0: 53 51 4c 49 54 45 5f 4f 72 64 65 72 42 79 49 64 SQLITE_OrderById
c1d0: 78 4a 6f 69 6e 20 30 78 30 30 38 30 20 20 20 2f xJoin 0x0080 /
c1e0: 2a 20 4f 52 44 45 52 20 42 59 20 6f 66 20 6a 6f * ORDER BY of jo
c1f0: 69 6e 73 20 76 69 61 20 69 6e 64 65 78 20 2a 2f ins via index */
c200: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
c210: 53 75 62 71 43 6f 72 6f 75 74 69 6e 65 20 20 30 SubqCoroutine 0
c220: 78 30 31 30 30 20 20 20 2f 2a 20 45 76 61 6c 75 x0100 /* Evalu
c230: 61 74 65 20 73 75 62 71 75 65 72 69 65 73 20 61 ate subqueries a
c240: 73 20 63 6f 72 6f 75 74 69 6e 65 73 20 2a 2f 0a s coroutines */.
c250: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 #define SQLITE_T
c260: 72 61 6e 73 69 74 69 76 65 20 20 20 20 20 30 78 ransitive 0x
c270: 30 32 30 30 20 20 20 2f 2a 20 54 72 61 6e 73 69 0200 /* Transi
c280: 74 69 76 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 tive constraints
c290: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
c2a0: 54 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f 69 6e 20 TE_OmitNoopJoin
c2b0: 20 20 30 78 30 34 30 30 20 20 20 2f 2a 20 4f 6d 0x0400 /* Om
c2c0: 69 74 20 75 6e 75 73 65 64 20 74 61 62 6c 65 73 it unused tables
c2d0: 20 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a 23 64 65 in joins */.#de
c2e0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 74 61 74 fine SQLITE_Stat
c2f0: 33 34 20 20 20 20 20 20 20 20 20 30 78 30 38 30 34 0x080
c300: 30 20 20 20 2f 2a 20 55 73 65 20 53 54 41 54 33 0 /* Use STAT3
c310: 20 6f 72 20 53 54 41 54 34 20 64 61 74 61 20 2a or STAT4 data *
c320: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
c330: 5f 41 6c 6c 4f 70 74 73 20 20 20 20 20 20 20 20 _AllOpts
c340: 30 78 66 66 66 66 20 20 20 2f 2a 20 41 6c 6c 20 0xffff /* All
c350: 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 2a 2f optimizations */
c360: 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 66 ../*.** Macros f
c370: 6f 72 20 74 65 73 74 69 6e 67 20 77 68 65 74 68 or testing wheth
c380: 65 72 20 6f 72 20 6e 6f 74 20 6f 70 74 69 6d 69 er or not optimi
c390: 7a 61 74 69 6f 6e 73 20 61 72 65 20 65 6e 61 62 zations are enab
c3a0: 6c 65 64 20 6f 72 20 64 69 73 61 62 6c 65 64 2e led or disabled.
c3b0: 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 .*/.#ifndef SQLI
c3c0: 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f TE_OMIT_BUILTIN_
c3d0: 54 45 53 54 0a 23 64 65 66 69 6e 65 20 4f 70 74 TEST.#define Opt
c3e0: 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 62 6c 65 imizationDisable
c3f0: 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 28 28 28 d(db, mask) (((
c400: 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 67 73 26 db)->dbOptFlags&
c410: 28 6d 61 73 6b 29 29 21 3d 30 29 0a 23 64 65 66 (mask))!=0).#def
c420: 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e ine Optimization
c430: 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b Enabled(db, mask
c440: 29 20 20 20 28 28 28 64 62 29 2d 3e 64 62 4f 70 ) (((db)->dbOp
c450: 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 3d 3d tFlags&(mask))==
c460: 30 29 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 0).#else.#define
c470: 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 69 73 OptimizationDis
c480: 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 abled(db, mask)
c490: 20 30 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 6d 0.#define Optim
c4a0: 69 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 64 28 64 izationEnabled(d
c4b0: 62 2c 20 6d 61 73 6b 29 20 20 20 31 0a 23 65 6e b, mask) 1.#en
c4c0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 dif../*.** Retur
c4d0: 6e 20 74 72 75 65 20 69 66 20 69 74 20 4f 4b 20 n true if it OK
c4e0: 74 6f 20 66 61 63 74 6f 72 20 63 6f 6e 73 74 61 to factor consta
c4f0: 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 73 20 69 nt expressions i
c500: 6e 74 6f 20 74 68 65 20 69 6e 69 74 69 61 6c 69 nto the initiali
c510: 7a 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 65 2e 20 zation.** code.
c520: 54 68 65 20 61 72 67 75 6d 65 6e 74 20 69 73 20 The argument is
c530: 61 20 50 61 72 73 65 20 6f 62 6a 65 63 74 20 66 a Parse object f
c540: 6f 72 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 or the code gene
c550: 72 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e rator..*/.#defin
c560: 65 20 43 6f 6e 73 74 46 61 63 74 6f 72 4f 6b 28 e ConstFactorOk(
c570: 50 29 20 28 28 50 29 2d 3e 6f 6b 43 6f 6e 73 74 P) ((P)->okConst
c580: 46 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a 2a 20 50 Factor)../*.** P
c590: 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 ossible values f
c5a0: 6f 72 20 74 68 65 20 73 71 6c 69 74 65 2e 6d 61 or the sqlite.ma
c5b0: 67 69 63 20 66 69 65 6c 64 2e 0a 2a 2a 20 54 68 gic field..** Th
c5c0: 65 20 6e 75 6d 62 65 72 73 20 61 72 65 20 6f 62 e numbers are ob
c5d0: 74 61 69 6e 65 64 20 61 74 20 72 61 6e 64 6f 6d tained at random
c5e0: 20 61 6e 64 20 68 61 76 65 20 6e 6f 20 73 70 65 and have no spe
c5f0: 63 69 61 6c 20 6d 65 61 6e 69 6e 67 2c 20 6f 74 cial meaning, ot
c600: 68 65 72 0a 2a 2a 20 74 68 61 6e 20 62 65 69 6e her.** than bein
c610: 67 20 64 69 73 74 69 6e 63 74 20 66 72 6f 6d 20 g distinct from
c620: 6f 6e 65 20 61 6e 6f 74 68 65 72 2e 0a 2a 2f 0a one another..*/.
c630: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
c640: 41 47 49 43 5f 4f 50 45 4e 20 20 20 20 20 30 78 AGIC_OPEN 0x
c650: 61 30 32 39 61 36 39 37 20 20 2f 2a 20 44 61 74 a029a697 /* Dat
c660: 61 62 61 73 65 20 69 73 20 6f 70 65 6e 20 2a 2f abase is open */
c670: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
c680: 4d 41 47 49 43 5f 43 4c 4f 53 45 44 20 20 20 30 MAGIC_CLOSED 0
c690: 78 39 66 33 63 32 64 33 33 20 20 2f 2a 20 44 61 x9f3c2d33 /* Da
c6a0: 74 61 62 61 73 65 20 69 73 20 63 6c 6f 73 65 64 tabase is closed
c6b0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
c6c0: 54 45 5f 4d 41 47 49 43 5f 53 49 43 4b 20 20 20 TE_MAGIC_SICK
c6d0: 20 20 30 78 34 62 37 37 31 32 39 30 20 20 2f 2a 0x4b771290 /*
c6e0: 20 45 72 72 6f 72 20 61 6e 64 20 61 77 61 69 74 Error and await
c6f0: 69 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a 23 64 65 ing close */.#de
c700: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 fine SQLITE_MAGI
c710: 43 5f 42 55 53 59 20 20 20 20 20 30 78 66 30 33 C_BUSY 0xf03
c720: 62 37 39 30 36 20 20 2f 2a 20 44 61 74 61 62 61 b7906 /* Databa
c730: 73 65 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 se currently in
c740: 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 use */.#define S
c750: 51 4c 49 54 45 5f 4d 41 47 49 43 5f 45 52 52 4f QLITE_MAGIC_ERRO
c760: 52 20 20 20 20 30 78 62 35 33 35 37 39 33 30 20 R 0xb5357930
c770: 20 2f 2a 20 41 6e 20 53 51 4c 49 54 45 5f 4d 49 /* An SQLITE_MI
c780: 53 55 53 45 20 65 72 72 6f 72 20 6f 63 63 75 72 SUSE error occur
c790: 72 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 red */.#define S
c7a0: 51 4c 49 54 45 5f 4d 41 47 49 43 5f 5a 4f 4d 42 QLITE_MAGIC_ZOMB
c7b0: 49 45 20 20 20 30 78 36 34 63 66 66 63 37 66 20 IE 0x64cffc7f
c7c0: 20 2f 2a 20 43 6c 6f 73 65 20 77 69 74 68 20 6c /* Close with l
c7d0: 61 73 74 20 73 74 61 74 65 6d 65 6e 74 20 63 6c ast statement cl
c7e0: 6f 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 ose */../*.** Ea
c7f0: 63 68 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 ch SQL function
c800: 69 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e is defined by an
c810: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
c820: 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 following.** st
c830: 72 75 63 74 75 72 65 2e 20 20 41 20 70 6f 69 6e ructure. A poin
c840: 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 ter to this stru
c850: 63 74 75 72 65 20 69 73 20 73 74 6f 72 65 64 20 cture is stored
c860: 69 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 46 in the sqlite.aF
c870: 75 6e 63 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c unc.** hash tabl
c880: 65 2e 20 20 57 68 65 6e 20 6d 75 6c 74 69 70 6c e. When multipl
c890: 65 20 66 75 6e 63 74 69 6f 6e 73 20 68 61 76 65 e functions have
c8a0: 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 2c 20 the same name,
c8b0: 74 68 65 20 68 61 73 68 20 74 61 62 6c 65 0a 2a the hash table.*
c8c0: 2a 20 70 6f 69 6e 74 73 20 74 6f 20 61 20 6c 69 * points to a li
c8d0: 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 74 68 65 nked list of the
c8e0: 73 65 20 73 74 72 75 63 74 75 72 65 73 2e 0a 2a se structures..*
c8f0: 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 65 66 /.struct FuncDef
c900: 20 7b 0a 20 20 69 31 36 20 6e 41 72 67 3b 20 20 {. i16 nArg;
c910: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
c920: 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
c930: 2e 20 20 2d 31 20 6d 65 61 6e 73 20 75 6e 6c 69 . -1 means unli
c940: 6d 69 74 65 64 20 2a 2f 0a 20 20 75 31 36 20 66 mited */. u16 f
c950: 75 6e 63 46 6c 61 67 73 3b 20 20 20 20 20 20 20 uncFlags;
c960: 2f 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 6e 61 74 /* Some combinat
c970: 69 6f 6e 20 6f 66 20 53 51 4c 49 54 45 5f 46 55 ion of SQLITE_FU
c980: 4e 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 64 20 2a NC_* */. void *
c990: 70 55 73 65 72 44 61 74 61 3b 20 20 20 20 20 2f pUserData; /
c9a0: 2a 20 55 73 65 72 20 64 61 74 61 20 70 61 72 61 * User data para
c9b0: 6d 65 74 65 72 20 2a 2f 0a 20 20 46 75 6e 63 44 meter */. FuncD
c9c0: 65 66 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 ef *pNext;
c9d0: 2f 2a 20 4e 65 78 74 20 66 75 6e 63 74 69 6f 6e /* Next function
c9e0: 20 77 69 74 68 20 73 61 6d 65 20 6e 61 6d 65 20 with same name
c9f0: 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 46 75 6e */. void (*xFun
ca00: 63 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 c)(sqlite3_conte
ca10: 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f xt*,int,sqlite3_
ca20: 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 52 65 67 value**); /* Reg
ca30: 75 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ular function */
ca40: 0a 20 20 76 6f 69 64 20 28 2a 78 53 74 65 70 29 . void (*xStep)
ca50: 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
ca60: 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 *,int,sqlite3_va
ca70: 6c 75 65 2a 2a 29 3b 20 2f 2a 20 41 67 67 72 65 lue**); /* Aggre
ca80: 67 61 74 65 20 73 74 65 70 20 2a 2f 0a 20 20 76 gate step */. v
ca90: 6f 69 64 20 28 2a 78 46 69 6e 61 6c 69 7a 65 29 oid (*xFinalize)
caa0: 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
cab0: 2a 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 *);
cac0: 20 20 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 /* Aggregate
cad0: 66 69 6e 61 6c 69 7a 65 72 20 2a 2f 0a 20 20 63 finalizer */. c
cae0: 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
caf0: 20 20 20 20 2f 2a 20 53 51 4c 20 6e 61 6d 65 20 /* SQL name
cb00: 6f 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 2e of the function.
cb10: 20 2a 2f 0a 20 20 46 75 6e 63 44 65 66 20 2a 70 */. FuncDef *p
cb20: 48 61 73 68 3b 20 20 20 20 20 20 2f 2a 20 4e 65 Hash; /* Ne
cb30: 78 74 20 77 69 74 68 20 61 20 64 69 66 66 65 72 xt with a differ
cb40: 65 6e 74 20 6e 61 6d 65 20 62 75 74 20 74 68 65 ent name but the
cb50: 20 73 61 6d 65 20 68 61 73 68 20 2a 2f 0a 20 20 same hash */.
cb60: 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 2a FuncDestructor *
cb70: 70 44 65 73 74 72 75 63 74 6f 72 3b 20 20 20 2f pDestructor; /
cb80: 2a 20 52 65 66 65 72 65 6e 63 65 20 63 6f 75 6e * Reference coun
cb90: 74 65 64 20 64 65 73 74 72 75 63 74 6f 72 20 66 ted destructor f
cba0: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a 2f unction */.};../
cbb0: 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 74 *.** This struct
cbc0: 75 72 65 20 65 6e 63 61 70 73 75 6c 61 74 65 73 ure encapsulates
cbd0: 20 61 20 75 73 65 72 2d 66 75 6e 63 74 69 6f 6e a user-function
cbe0: 20 64 65 73 74 72 75 63 74 6f 72 20 63 61 6c 6c destructor call
cbf0: 62 61 63 6b 20 28 61 73 0a 2a 2a 20 63 6f 6e 66 back (as.** conf
cc00: 69 67 75 72 65 64 20 75 73 69 6e 67 20 63 72 65 igured using cre
cc10: 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 ate_function_v2(
cc20: 29 29 20 61 6e 64 20 61 20 72 65 66 65 72 65 6e )) and a referen
cc30: 63 65 20 63 6f 75 6e 74 65 72 2e 20 57 68 65 6e ce counter. When
cc40: 0a 2a 2a 20 63 72 65 61 74 65 5f 66 75 6e 63 74 .** create_funct
cc50: 69 6f 6e 5f 76 32 28 29 20 69 73 20 63 61 6c 6c ion_v2() is call
cc60: 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 66 ed to create a f
cc70: 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 61 20 64 unction with a d
cc80: 65 73 74 72 75 63 74 6f 72 2c 0a 2a 2a 20 61 20 estructor,.** a
cc90: 73 69 6e 67 6c 65 20 6f 62 6a 65 63 74 20 6f 66 single object of
cca0: 20 74 68 69 73 20 74 79 70 65 20 69 73 20 61 6c this type is al
ccb0: 6c 6f 63 61 74 65 64 2e 20 46 75 6e 63 44 65 73 located. FuncDes
ccc0: 74 72 75 63 74 6f 72 2e 6e 52 65 66 20 69 73 20 tructor.nRef is
ccd0: 73 65 74 20 74 6f 20 0a 2a 2a 20 74 68 65 20 6e set to .** the n
cce0: 75 6d 62 65 72 20 6f 66 20 46 75 6e 63 44 65 66 umber of FuncDef
ccf0: 20 6f 62 6a 65 63 74 73 20 63 72 65 61 74 65 64 objects created
cd00: 20 28 65 69 74 68 65 72 20 31 20 6f 72 20 33 2c (either 1 or 3,
cd10: 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 77 68 depending on wh
cd20: 65 74 68 65 72 0a 2a 2a 20 6f 72 20 6e 6f 74 20 ether.** or not
cd30: 74 68 65 20 73 70 65 63 69 66 69 65 64 20 65 6e the specified en
cd40: 63 6f 64 69 6e 67 20 69 73 20 53 51 4c 49 54 45 coding is SQLITE
cd50: 5f 41 4e 59 29 2e 20 54 68 65 20 46 75 6e 63 44 _ANY). The FuncD
cd60: 65 66 2e 70 44 65 73 74 72 75 63 74 6f 72 0a 2a ef.pDestructor.*
cd70: 2a 20 6d 65 6d 62 65 72 20 6f 66 20 65 61 63 68 * member of each
cd80: 20 6f 66 20 74 68 65 20 6e 65 77 20 46 75 6e 63 of the new Func
cd90: 44 65 66 20 6f 62 6a 65 63 74 73 20 69 73 20 73 Def objects is s
cda0: 65 74 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 74 et to point to t
cdb0: 68 65 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 he allocated.**
cdc0: 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 2e 0a FuncDestructor..
cdd0: 2a 2a 0a 2a 2a 20 54 68 65 72 65 61 66 74 65 72 **.** Thereafter
cde0: 2c 20 77 68 65 6e 20 6f 6e 65 20 6f 66 20 74 68 , when one of th
cdf0: 65 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 e FuncDef object
ce00: 73 20 69 73 20 64 65 6c 65 74 65 64 2c 20 74 68 s is deleted, th
ce10: 65 20 72 65 66 65 72 65 6e 63 65 0a 2a 2a 20 63 e reference.** c
ce20: 6f 75 6e 74 20 6f 6e 20 74 68 69 73 20 6f 62 6a ount on this obj
ce30: 65 63 74 20 69 73 20 64 65 63 72 65 6d 65 6e 74 ect is decrement
ce40: 65 64 2e 20 57 68 65 6e 20 69 74 20 72 65 61 63 ed. When it reac
ce50: 68 65 73 20 30 2c 20 74 68 65 20 64 65 73 74 72 hes 0, the destr
ce60: 75 63 74 6f 72 0a 2a 2a 20 69 73 20 69 6e 76 6f uctor.** is invo
ce70: 6b 65 64 20 61 6e 64 20 74 68 65 20 46 75 6e 63 ked and the Func
ce80: 44 65 73 74 72 75 63 74 6f 72 20 73 74 72 75 63 Destructor struc
ce90: 74 75 72 65 20 66 72 65 65 64 2e 0a 2a 2f 0a 73 ture freed..*/.s
cea0: 74 72 75 63 74 20 46 75 6e 63 44 65 73 74 72 75 truct FuncDestru
ceb0: 63 74 6f 72 20 7b 0a 20 20 69 6e 74 20 6e 52 65 ctor {. int nRe
cec0: 66 3b 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 73 f;. void (*xDes
ced0: 74 72 6f 79 29 28 76 6f 69 64 20 2a 29 3b 0a 20 troy)(void *);.
cee0: 20 76 6f 69 64 20 2a 70 55 73 65 72 44 61 74 61 void *pUserData
cef0: 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 ;.};../*.** Poss
cf00: 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 ible values for
cf10: 46 75 6e 63 44 65 66 2e 66 6c 61 67 73 2e 20 20 FuncDef.flags.
cf20: 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20 5f 4c Note that the _L
cf30: 45 4e 47 54 48 20 61 6e 64 20 5f 54 59 50 45 4f ENGTH and _TYPEO
cf40: 46 0a 2a 2a 20 76 61 6c 75 65 73 20 6d 75 73 74 F.** values must
cf50: 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 4f correspond to O
cf60: 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 PFLAG_LENGTHARG
cf70: 61 6e 64 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f and OPFLAG_TYPEO
cf80: 46 41 52 47 2e 20 20 54 68 65 72 65 0a 2a 2a 20 FARG. There.**
cf90: 61 72 65 20 61 73 73 65 72 74 28 29 20 73 74 61 are assert() sta
cfa0: 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 63 tements in the c
cfb0: 6f 64 65 20 74 6f 20 76 65 72 69 66 79 20 74 68 ode to verify th
cfc0: 69 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 is..*/.#define S
cfd0: 51 4c 49 54 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 QLITE_FUNC_ENCMA
cfe0: 53 4b 20 20 30 78 30 30 33 20 2f 2a 20 53 51 4c SK 0x003 /* SQL
cff0: 49 54 45 5f 55 54 46 38 2c 20 53 51 4c 49 54 45 ITE_UTF8, SQLITE
d000: 5f 55 54 46 31 36 42 45 20 6f 72 20 55 54 46 31 _UTF16BE or UTF1
d010: 36 4c 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 6LE */.#define S
d020: 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 49 4b 45 20 QLITE_FUNC_LIKE
d030: 20 20 20 20 30 78 30 30 34 20 2f 2a 20 43 61 6e 0x004 /* Can
d040: 64 69 64 61 74 65 20 66 6f 72 20 74 68 65 20 4c didate for the L
d050: 49 4b 45 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e IKE optimization
d060: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
d070: 54 45 5f 46 55 4e 43 5f 43 41 53 45 20 20 20 20 TE_FUNC_CASE
d080: 20 30 78 30 30 38 20 2f 2a 20 43 61 73 65 2d 73 0x008 /* Case-s
d090: 65 6e 73 69 74 69 76 65 20 4c 49 4b 45 2d 74 79 ensitive LIKE-ty
d0a0: 70 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 pe function */.#
d0b0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
d0c0: 4e 43 5f 45 50 48 45 4d 20 20 20 20 30 78 30 31 NC_EPHEM 0x01
d0d0: 30 20 2f 2a 20 45 70 68 65 6d 65 72 61 6c 2e 20 0 /* Ephemeral.
d0e0: 20 44 65 6c 65 74 65 20 77 69 74 68 20 56 44 42 Delete with VDB
d0f0: 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c E */.#define SQL
d100: 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c ITE_FUNC_NEEDCOL
d110: 4c 20 30 78 30 32 30 20 2f 2a 20 73 71 6c 69 74 L 0x020 /* sqlit
d120: 65 33 47 65 74 46 75 6e 63 43 6f 6c 6c 53 65 71 e3GetFuncCollSeq
d130: 28 29 20 6d 69 67 68 74 20 62 65 20 63 61 6c 6c () might be call
d140: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ed */.#define SQ
d150: 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 LITE_FUNC_LENGTH
d160: 20 20 20 30 78 30 34 30 20 2f 2a 20 42 75 69 6c 0x040 /* Buil
d170: 74 2d 69 6e 20 6c 65 6e 67 74 68 28 29 20 66 75 t-in length() fu
d180: 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e nction */.#defin
d190: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 54 59 e SQLITE_FUNC_TY
d1a0: 50 45 4f 46 20 20 20 30 78 30 38 30 20 2f 2a 20 PEOF 0x080 /*
d1b0: 42 75 69 6c 74 2d 69 6e 20 74 79 70 65 6f 66 28 Built-in typeof(
d1c0: 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 ) function */.#d
d1d0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
d1e0: 43 5f 43 4f 55 4e 54 20 20 20 20 30 78 31 30 30 C_COUNT 0x100
d1f0: 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 63 6f 75 /* Built-in cou
d200: 6e 74 28 2a 29 20 61 67 67 72 65 67 61 74 65 20 nt(*) aggregate
d210: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
d220: 45 5f 46 55 4e 43 5f 43 4f 41 4c 45 53 43 45 20 E_FUNC_COALESCE
d230: 30 78 32 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 0x200 /* Built-i
d240: 6e 20 63 6f 61 6c 65 73 63 65 28 29 20 6f 72 20 n coalesce() or
d250: 69 66 6e 75 6c 6c 28 29 20 2a 2f 0a 23 64 65 66 ifnull() */.#def
d260: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
d270: 55 4e 4c 49 4b 45 4c 59 20 30 78 34 30 30 20 2f UNLIKELY 0x400 /
d280: 2a 20 42 75 69 6c 74 2d 69 6e 20 75 6e 6c 69 6b * Built-in unlik
d290: 65 6c 79 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a ely() function *
d2a0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
d2b0: 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 30 _FUNC_CONSTANT 0
d2c0: 78 38 30 30 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 x800 /* Constant
d2d0: 20 69 6e 70 75 74 73 20 67 69 76 65 20 61 20 63 inputs give a c
d2e0: 6f 6e 73 74 61 6e 74 20 6f 75 74 70 75 74 20 2a onstant output *
d2f0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
d300: 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 20 20 30 78 _FUNC_MINMAX 0x
d310: 31 30 30 30 20 2f 2a 20 54 72 75 65 20 66 6f 72 1000 /* True for
d320: 20 6d 69 6e 28 29 20 61 6e 64 20 6d 61 78 28 29 min() and max()
d330: 20 61 67 67 72 65 67 61 74 65 73 20 2a 2f 0a 0a aggregates */..
d340: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
d350: 69 6e 67 20 74 68 72 65 65 20 6d 61 63 72 6f 73 ing three macros
d360: 2c 20 46 55 4e 43 54 49 4f 4e 28 29 2c 20 4c 49 , FUNCTION(), LI
d370: 4b 45 46 55 4e 43 28 29 20 61 6e 64 20 41 47 47 KEFUNC() and AGG
d380: 52 45 47 41 54 45 28 29 20 61 72 65 0a 2a 2a 20 REGATE() are.**
d390: 75 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 74 used to create t
d3a0: 68 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 73 20 he initializers
d3b0: 66 6f 72 20 74 68 65 20 46 75 6e 63 44 65 66 20 for the FuncDef
d3c0: 73 74 72 75 63 74 75 72 65 73 2e 0a 2a 2a 0a 2a structures..**.*
d3d0: 2a 20 20 20 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 * FUNCTION(zNa
d3e0: 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 me, nArg, iArg,
d3f0: 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 bNC, xFunc).**
d400: 20 20 20 55 73 65 64 20 74 6f 20 63 72 65 61 74 Used to creat
d410: 65 20 61 20 73 63 61 6c 61 72 20 66 75 6e 63 74 e a scalar funct
d420: 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 20 6f ion definition o
d430: 66 20 61 20 66 75 6e 63 74 69 6f 6e 20 7a 4e 61 f a function zNa
d440: 6d 65 20 0a 2a 2a 20 20 20 20 20 69 6d 70 6c 65 me .** imple
d450: 6d 65 6e 74 65 64 20 62 79 20 43 20 66 75 6e 63 mented by C func
d460: 74 69 6f 6e 20 78 46 75 6e 63 20 74 68 61 74 20 tion xFunc that
d470: 61 63 63 65 70 74 73 20 6e 41 72 67 20 61 72 67 accepts nArg arg
d480: 75 6d 65 6e 74 73 2e 20 54 68 65 0a 2a 2a 20 20 uments. The.**
d490: 20 20 20 76 61 6c 75 65 20 70 61 73 73 65 64 20 value passed
d4a0: 61 73 20 69 41 72 67 20 69 73 20 63 61 73 74 20 as iArg is cast
d4b0: 74 6f 20 61 20 28 76 6f 69 64 2a 29 20 61 6e 64 to a (void*) and
d4c0: 20 6d 61 64 65 20 61 76 61 69 6c 61 62 6c 65 0a made available.
d4d0: 2a 2a 20 20 20 20 20 61 73 20 74 68 65 20 75 73 ** as the us
d4e0: 65 72 2d 64 61 74 61 20 28 73 71 6c 69 74 65 33 er-data (sqlite3
d4f0: 5f 75 73 65 72 5f 64 61 74 61 28 29 29 20 66 6f _user_data()) fo
d500: 72 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 2e 20 r the function.
d510: 49 66 20 0a 2a 2a 20 20 20 20 20 61 72 67 75 6d If .** argum
d520: 65 6e 74 20 62 4e 43 20 69 73 20 74 72 75 65 2c ent bNC is true,
d530: 20 74 68 65 6e 20 74 68 65 20 53 51 4c 49 54 45 then the SQLITE
d540: 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 20 66 _FUNC_NEEDCOLL f
d550: 6c 61 67 20 69 73 20 73 65 74 2e 0a 2a 2a 0a 2a lag is set..**.*
d560: 2a 20 20 20 56 46 55 4e 43 54 49 4f 4e 28 7a 4e * VFUNCTION(zN
d570: 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c ame, nArg, iArg,
d580: 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 bNC, xFunc).**
d590: 20 20 20 20 4c 69 6b 65 20 46 55 4e 43 54 49 4f Like FUNCTIO
d5a0: 4e 20 65 78 63 65 70 74 20 69 74 20 6f 6d 69 74 N except it omit
d5b0: 73 20 74 68 65 20 53 51 4c 49 54 45 5f 46 55 4e s the SQLITE_FUN
d5c0: 43 5f 43 4f 4e 53 54 41 4e 54 20 66 6c 61 67 2e C_CONSTANT flag.
d5d0: 0a 2a 2a 0a 2a 2a 20 20 20 41 47 47 52 45 47 41 .**.** AGGREGA
d5e0: 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 TE(zName, nArg,
d5f0: 69 41 72 67 2c 20 62 4e 43 2c 20 78 53 74 65 70 iArg, bNC, xStep
d600: 2c 20 78 46 69 6e 61 6c 29 0a 2a 2a 20 20 20 20 , xFinal).**
d610: 20 55 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 Used to create
d620: 61 6e 20 61 67 67 72 65 67 61 74 65 20 66 75 6e an aggregate fun
d630: 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e ction definition
d640: 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 0a implemented by.
d650: 2a 2a 20 20 20 20 20 74 68 65 20 43 20 66 75 6e ** the C fun
d660: 63 74 69 6f 6e 73 20 78 53 74 65 70 20 61 6e 64 ctions xStep and
d670: 20 78 46 69 6e 61 6c 2e 20 54 68 65 20 66 69 72 xFinal. The fir
d680: 73 74 20 66 6f 75 72 20 70 61 72 61 6d 65 74 65 st four paramete
d690: 72 73 0a 2a 2a 20 20 20 20 20 61 72 65 20 69 6e rs.** are in
d6a0: 74 65 72 70 72 65 74 65 64 20 69 6e 20 74 68 65 terpreted in the
d6b0: 20 73 61 6d 65 20 77 61 79 20 61 73 20 74 68 65 same way as the
d6c0: 20 66 69 72 73 74 20 34 20 70 61 72 61 6d 65 74 first 4 paramet
d6d0: 65 72 73 20 74 6f 0a 2a 2a 20 20 20 20 20 46 55 ers to.** FU
d6e0: 4e 43 54 49 4f 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 NCTION()..**.**
d6f0: 20 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 LIKEFUNC(zName
d700: 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 66 6c , nArg, pArg, fl
d710: 61 67 73 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 ags).** Used
d720: 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 61 to create a sca
d730: 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 lar function def
d740: 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e inition of a fun
d750: 63 74 69 6f 6e 20 7a 4e 61 6d 65 20 0a 2a 2a 20 ction zName .**
d760: 20 20 20 20 74 68 61 74 20 61 63 63 65 70 74 73 that accepts
d770: 20 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 20 nArg arguments
d780: 61 6e 64 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 and is implement
d790: 65 64 20 62 79 20 61 20 63 61 6c 6c 20 74 6f 20 ed by a call to
d7a0: 43 20 0a 2a 2a 20 20 20 20 20 66 75 6e 63 74 69 C .** functi
d7b0: 6f 6e 20 6c 69 6b 65 46 75 6e 63 2e 20 41 72 67 on likeFunc. Arg
d7c0: 75 6d 65 6e 74 20 70 41 72 67 20 69 73 20 63 61 ument pArg is ca
d7d0: 73 74 20 74 6f 20 61 20 28 76 6f 69 64 20 2a 29 st to a (void *)
d7e0: 20 61 6e 64 20 6d 61 64 65 0a 2a 2a 20 20 20 20 and made.**
d7f0: 20 61 76 61 69 6c 61 62 6c 65 20 61 73 20 74 68 available as th
d800: 65 20 66 75 6e 63 74 69 6f 6e 20 75 73 65 72 2d e function user-
d810: 64 61 74 61 20 28 73 71 6c 69 74 65 33 5f 75 73 data (sqlite3_us
d820: 65 72 5f 64 61 74 61 28 29 29 2e 20 54 68 65 0a er_data()). The.
d830: 2a 2a 20 20 20 20 20 46 75 6e 63 44 65 66 2e 66 ** FuncDef.f
d840: 6c 61 67 73 20 76 61 72 69 61 62 6c 65 20 69 73 lags variable is
d850: 20 73 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 set to the valu
d860: 65 20 70 61 73 73 65 64 20 61 73 20 74 68 65 20 e passed as the
d870: 66 6c 61 67 73 0a 2a 2a 20 20 20 20 20 70 61 72 flags.** par
d880: 61 6d 65 74 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 ameter..*/.#defi
d890: 6e 65 20 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d ne FUNCTION(zNam
d8a0: 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 e, nArg, iArg, b
d8b0: 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b NC, xFunc) \. {
d8c0: 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e nArg, SQLITE_FUN
d8d0: 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 C_CONSTANT|SQLIT
d8e0: 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 E_UTF8|(bNC*SQLI
d8f0: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
d900: 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 ), \. SQLITE_I
d910: 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c NT_TO_PTR(iArg),
d920: 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 0, xFunc, 0, 0,
d930: 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 #zName, 0, 0}.#
d940: 64 65 66 69 6e 65 20 56 46 55 4e 43 54 49 4f 4e define VFUNCTION
d950: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
d960: 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 rg, bNC, xFunc)
d970: 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 \. {nArg, SQLIT
d980: 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 E_UTF8|(bNC*SQLI
d990: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
d9a0: 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 ), \. SQLITE_I
d9b0: 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c NT_TO_PTR(iArg),
d9c0: 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 0, xFunc, 0, 0,
d9d0: 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 #zName, 0, 0}.#
d9e0: 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f 4e 32 define FUNCTION2
d9f0: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
da00: 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 2c 20 rg, bNC, xFunc,
da10: 65 78 74 72 61 46 6c 61 67 73 29 20 5c 0a 20 20 extraFlags) \.
da20: 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f 46 55 4e {nArg,SQLITE_FUN
da30: 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 C_CONSTANT|SQLIT
da40: 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 E_UTF8|(bNC*SQLI
da50: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
da60: 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 5c 0a 20 )|extraFlags,\.
da70: 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f SQLITE_INT_TO_
da80: 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 78 46 PTR(iArg), 0, xF
da90: 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 6d unc, 0, 0, #zNam
daa0: 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 6e 65 e, 0, 0}.#define
dab0: 20 53 54 52 5f 46 55 4e 43 54 49 4f 4e 28 7a 4e STR_FUNCTION(zN
dac0: 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c ame, nArg, pArg,
dad0: 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 bNC, xFunc) \.
dae0: 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 {nArg, SQLITE_F
daf0: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c UNC_CONSTANT|SQL
db00: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
db10: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
db20: 4c 4c 29 2c 20 5c 0a 20 20 20 70 41 72 67 2c 20 LL), \. pArg,
db30: 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 0, xFunc, 0, 0,
db40: 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 #zName, 0, 0}.#d
db50: 65 66 69 6e 65 20 4c 49 4b 45 46 55 4e 43 28 7a efine LIKEFUNC(z
db60: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 67 2c Name, nArg, arg,
db70: 20 66 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 flags) \. {nAr
db80: 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 g, SQLITE_FUNC_C
db90: 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f 55 ONSTANT|SQLITE_U
dba0: 54 46 38 7c 66 6c 61 67 73 2c 20 5c 0a 20 20 20 TF8|flags, \.
dbb0: 28 76 6f 69 64 20 2a 29 61 72 67 2c 20 30 2c 20 (void *)arg, 0,
dbc0: 6c 69 6b 65 46 75 6e 63 2c 20 30 2c 20 30 2c 20 likeFunc, 0, 0,
dbd0: 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 #zName, 0, 0}.#d
dbe0: 65 66 69 6e 65 20 41 47 47 52 45 47 41 54 45 28 efine AGGREGATE(
dbf0: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 67 zName, nArg, arg
dc00: 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 78 46 69 , nc, xStep, xFi
dc10: 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 nal) \. {nArg,
dc20: 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 6e 63 2a SQLITE_UTF8|(nc*
dc30: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 SQLITE_FUNC_NEED
dc40: 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 COLL), \. SQLI
dc50: 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 TE_INT_TO_PTR(ar
dc60: 67 29 2c 20 30 2c 20 30 2c 20 78 53 74 65 70 2c g), 0, 0, xStep,
dc70: 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 30 2c xFinal,#zName,0,
dc80: 30 7d 0a 23 64 65 66 69 6e 65 20 41 47 47 52 45 0}.#define AGGRE
dc90: 47 41 54 45 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 GATE2(zName, nAr
dca0: 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 g, arg, nc, xSte
dcb0: 70 2c 20 78 46 69 6e 61 6c 2c 20 65 78 74 72 61 p, xFinal, extra
dcc0: 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 67 Flags) \. {nArg
dcd0: 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 6e , SQLITE_UTF8|(n
dce0: 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 c*SQLITE_FUNC_NE
dcf0: 45 44 43 4f 4c 4c 29 7c 65 78 74 72 61 46 6c 61 EDCOLL)|extraFla
dd00: 67 73 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f gs, \. SQLITE_
dd10: 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 2c INT_TO_PTR(arg),
dd20: 20 30 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 69 0, 0, xStep,xFi
dd30: 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 30 2c 30 7d 0a nal,#zName,0,0}.
dd40: 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 72 72 65 ./*.** All curre
dd50: 6e 74 20 73 61 76 65 70 6f 69 6e 74 73 20 61 72 nt savepoints ar
dd60: 65 20 73 74 6f 72 65 64 20 69 6e 20 61 20 6c 69 e stored in a li
dd70: 6e 6b 65 64 20 6c 69 73 74 20 73 74 61 72 74 69 nked list starti
dd80: 6e 67 20 61 74 0a 2a 2a 20 73 71 6c 69 74 65 33 ng at.** sqlite3
dd90: 2e 70 53 61 76 65 70 6f 69 6e 74 2e 20 54 68 65 .pSavepoint. The
dda0: 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 69 first element i
ddb0: 6e 20 74 68 65 20 6c 69 73 74 20 69 73 20 74 68 n the list is th
ddc0: 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 6c 79 0a e most recently.
ddd0: 2a 2a 20 6f 70 65 6e 65 64 20 73 61 76 65 70 6f ** opened savepo
dde0: 69 6e 74 2e 20 53 61 76 65 70 6f 69 6e 74 73 20 int. Savepoints
ddf0: 61 72 65 20 61 64 64 65 64 20 74 6f 20 74 68 65 are added to the
de00: 20 6c 69 73 74 20 62 79 20 74 68 65 20 76 64 62 list by the vdb
de10: 65 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 6f 69 6e e.** OP_Savepoin
de20: 74 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 2a t instruction..*
de30: 2f 0a 73 74 72 75 63 74 20 53 61 76 65 70 6f 69 /.struct Savepoi
de40: 6e 74 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 nt {. char *zNa
de50: 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 me;
de60: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 61 /* Sa
de70: 76 65 70 6f 69 6e 74 20 6e 61 6d 65 20 28 6e 75 vepoint name (nu
de80: 6c 2d 74 65 72 6d 69 6e 61 74 65 64 29 20 2a 2f l-terminated) */
de90: 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 . i64 nDeferred
dea0: 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 Cons;
deb0: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
dec0: 20 6f 66 20 64 65 66 65 72 72 65 64 20 66 6b 20 of deferred fk
ded0: 76 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 violations */.
dee0: 69 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d 6d i64 nDeferredImm
def0: 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 Cons;
df00: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
df10: 20 64 65 66 65 72 72 65 64 20 69 6d 6d 20 66 6b deferred imm fk
df20: 2e 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e 74 . */. Savepoint
df30: 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 *pNext;
df40: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 /* Pa
df50: 72 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 20 28 rent savepoint (
df60: 69 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b 0a 0a 2f if any) */.};../
df70: 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 *.** The followi
df80: 6e 67 20 61 72 65 20 75 73 65 64 20 61 73 20 74 ng are used as t
df90: 68 65 20 73 65 63 6f 6e 64 20 70 61 72 61 6d 65 he second parame
dfa0: 74 65 72 20 74 6f 20 73 71 6c 69 74 65 33 53 61 ter to sqlite3Sa
dfb0: 76 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 20 61 6e vepoint(),.** an
dfc0: 64 20 61 73 20 74 68 65 20 50 31 20 61 72 67 75 d as the P1 argu
dfd0: 6d 65 6e 74 20 74 6f 20 74 68 65 20 4f 50 5f 53 ment to the OP_S
dfe0: 61 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 75 63 avepoint instruc
dff0: 74 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 tion..*/.#define
e000: 20 53 41 56 45 50 4f 49 4e 54 5f 42 45 47 49 4e SAVEPOINT_BEGIN
e010: 20 20 20 20 20 20 30 0a 23 64 65 66 69 6e 65 20 0.#define
e020: 53 41 56 45 50 4f 49 4e 54 5f 52 45 4c 45 41 53 SAVEPOINT_RELEAS
e030: 45 20 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 E 1.#define S
e040: 41 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c 42 41 43 AVEPOINT_ROLLBAC
e050: 4b 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 K 2.../*.** Ea
e060: 63 68 20 53 51 4c 69 74 65 20 6d 6f 64 75 6c 65 ch SQLite module
e070: 20 28 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 (virtual table
e080: 64 65 66 69 6e 69 74 69 6f 6e 29 20 69 73 20 64 definition) is d
e090: 65 66 69 6e 65 64 20 62 79 20 61 6e 0a 2a 2a 20 efined by an.**
e0a0: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
e0b0: 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
e0c0: 75 72 65 2c 20 73 74 6f 72 65 64 20 69 6e 20 74 ure, stored in t
e0d0: 68 65 20 73 71 6c 69 74 65 33 2e 61 4d 6f 64 75 he sqlite3.aModu
e0e0: 6c 65 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c 65 le.** hash table
e0f0: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4d 6f 64 75 ..*/.struct Modu
e100: 6c 65 20 7b 0a 20 20 63 6f 6e 73 74 20 73 71 6c le {. const sql
e110: 69 74 65 33 5f 6d 6f 64 75 6c 65 20 2a 70 4d 6f ite3_module *pMo
e120: 64 75 6c 65 3b 20 20 20 20 20 20 20 2f 2a 20 43 dule; /* C
e130: 61 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 65 72 73 allback pointers
e140: 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 */. const char
e150: 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 *zName;
e160: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 /* Na
e170: 6d 65 20 70 61 73 73 65 64 20 74 6f 20 63 72 65 me passed to cre
e180: 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a ate_module() */.
e190: 20 20 76 6f 69 64 20 2a 70 41 75 78 3b 20 20 20 void *pAux;
e1a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
e1b0: 20 20 20 20 20 20 20 2f 2a 20 70 41 75 78 20 70 /* pAux p
e1c0: 61 73 73 65 64 20 74 6f 20 63 72 65 61 74 65 5f assed to create_
e1d0: 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 76 6f module() */. vo
e1e0: 69 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 76 id (*xDestroy)(v
e1f0: 6f 69 64 20 2a 29 3b 20 20 20 20 20 20 20 20 20 oid *);
e200: 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 64 65 73 /* Module des
e210: 74 72 75 63 74 6f 72 20 66 75 6e 63 74 69 6f 6e tructor function
e220: 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e */.};../*.** in
e230: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
e240: 65 61 63 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 each column of a
e250: 6e 20 53 51 4c 20 74 61 62 6c 65 20 69 73 20 68 n SQL table is h
e260: 65 6c 64 20 69 6e 20 61 6e 20 69 6e 73 74 61 6e eld in an instan
e270: 63 65 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 ce.** of this st
e280: 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 ructure..*/.stru
e290: 63 74 20 43 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 ct Column {. ch
e2a0: 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 2f ar *zName; /
e2b0: 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 63 * Name of this c
e2c0: 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 78 70 72 20 olumn */. Expr
e2d0: 2a 70 44 66 6c 74 3b 20 20 20 20 20 2f 2a 20 44 *pDflt; /* D
e2e0: 65 66 61 75 6c 74 20 76 61 6c 75 65 20 6f 66 20 efault value of
e2f0: 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 this column */.
e300: 20 63 68 61 72 20 2a 7a 44 66 6c 74 3b 20 20 20 char *zDflt;
e310: 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 74 65 /* Original te
e320: 78 74 20 6f 66 20 74 68 65 20 64 65 66 61 75 6c xt of the defaul
e330: 74 20 76 61 6c 75 65 20 2a 2f 0a 20 20 63 68 61 t value */. cha
e340: 72 20 2a 7a 54 79 70 65 3b 20 20 20 20 20 2f 2a r *zType; /*
e350: 20 44 61 74 61 20 74 79 70 65 20 66 6f 72 20 74 Data type for t
e360: 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 his column */.
e370: 63 68 61 72 20 2a 7a 43 6f 6c 6c 3b 20 20 20 20 char *zColl;
e380: 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 73 65 /* Collating se
e390: 71 75 65 6e 63 65 2e 20 20 49 66 20 4e 55 4c 4c quence. If NULL
e3a0: 2c 20 75 73 65 20 74 68 65 20 64 65 66 61 75 6c , use the defaul
e3b0: 74 20 2a 2f 0a 20 20 75 38 20 6e 6f 74 4e 75 6c t */. u8 notNul
e3c0: 6c 3b 20 20 20 20 20 20 2f 2a 20 41 6e 20 4f 45 l; /* An OE
e3d0: 5f 20 63 6f 64 65 20 66 6f 72 20 68 61 6e 64 6c _ code for handl
e3e0: 69 6e 67 20 61 20 4e 4f 54 20 4e 55 4c 4c 20 63 ing a NOT NULL c
e3f0: 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 20 20 63 onstraint */. c
e400: 68 61 72 20 61 66 66 69 6e 69 74 79 3b 20 20 20 har affinity;
e410: 2f 2a 20 4f 6e 65 20 6f 66 20 74 68 65 20 53 51 /* One of the SQ
e420: 4c 49 54 45 5f 41 46 46 5f 2e 2e 2e 20 76 61 6c LITE_AFF_... val
e430: 75 65 73 20 2a 2f 0a 20 20 75 38 20 73 7a 45 73 ues */. u8 szEs
e440: 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 t; /* Est
e450: 69 6d 61 74 65 64 20 73 69 7a 65 20 6f 66 20 74 imated size of t
e460: 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 20 49 4e 54 his column. INT
e470: 3d 3d 31 20 2a 2f 0a 20 20 75 38 20 63 6f 6c 46 ==1 */. u8 colF
e480: 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 42 6f 6f lags; /* Boo
e490: 6c 65 61 6e 20 70 72 6f 70 65 72 74 69 65 73 2e lean properties.
e4a0: 20 20 53 65 65 20 43 4f 4c 46 4c 41 47 5f 20 64 See COLFLAG_ d
e4b0: 65 66 69 6e 65 73 20 62 65 6c 6f 77 20 2a 2f 0a efines below */.
e4c0: 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 76 };../* Allowed v
e4d0: 61 6c 75 65 73 20 66 6f 72 20 43 6f 6c 75 6d 6e alues for Column
e4e0: 2e 63 6f 6c 46 6c 61 67 73 3a 0a 2a 2f 0a 23 64 .colFlags:.*/.#d
e4f0: 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 50 52 efine COLFLAG_PR
e500: 49 4d 4b 45 59 20 20 30 78 30 30 30 31 20 20 20 IMKEY 0x0001
e510: 20 2f 2a 20 43 6f 6c 75 6d 6e 20 69 73 20 70 61 /* Column is pa
e520: 72 74 20 6f 66 20 74 68 65 20 70 72 69 6d 61 72 rt of the primar
e530: 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 6e 65 y key */.#define
e540: 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 45 4e 20 COLFLAG_HIDDEN
e550: 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a 20 41 0x0002 /* A
e560: 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 20 69 hidden column i
e570: 6e 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c n a virtual tabl
e580: 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 22 43 e */../*.** A "C
e590: 6f 6c 6c 61 74 69 6e 67 20 53 65 71 75 65 6e 63 ollating Sequenc
e5a0: 65 22 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 e" is defined by
e5b0: 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 an instance of
e5c0: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a the following.**
e5d0: 20 73 74 72 75 63 74 75 72 65 2e 20 43 6f 6e 63 structure. Conc
e5e0: 65 70 74 75 61 6c 6c 79 2c 20 61 20 63 6f 6c 6c eptually, a coll
e5f0: 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 63 ating sequence c
e600: 6f 6e 73 69 73 74 73 20 6f 66 20 61 20 6e 61 6d onsists of a nam
e610: 65 20 61 6e 64 0a 2a 2a 20 61 20 63 6f 6d 70 61 e and.** a compa
e620: 72 69 73 6f 6e 20 72 6f 75 74 69 6e 65 20 74 68 rison routine th
e630: 61 74 20 64 65 66 69 6e 65 73 20 74 68 65 20 6f at defines the o
e640: 72 64 65 72 20 6f 66 20 74 68 61 74 20 73 65 71 rder of that seq
e650: 75 65 6e 63 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 uence..**.** If
e660: 43 6f 6c 6c 53 65 71 2e 78 43 6d 70 20 69 73 20 CollSeq.xCmp is
e670: 4e 55 4c 4c 2c 20 69 74 20 6d 65 61 6e 73 20 74 NULL, it means t
e680: 68 61 74 20 74 68 65 0a 2a 2a 20 63 6f 6c 6c 61 hat the.** colla
e690: 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 69 73 ting sequence is
e6a0: 20 75 6e 64 65 66 69 6e 65 64 2e 20 20 49 6e 64 undefined. Ind
e6b0: 69 63 65 73 20 62 75 69 6c 74 20 6f 6e 20 61 6e ices built on an
e6c0: 20 75 6e 64 65 66 69 6e 65 64 0a 2a 2a 20 63 6f undefined.** co
e6d0: 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 llating sequence
e6e0: 20 6d 61 79 20 6e 6f 74 20 62 65 20 72 65 61 64 may not be read
e6f0: 20 6f 72 20 77 72 69 74 74 65 6e 2e 0a 2a 2f 0a or written..*/.
e700: 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 7b struct CollSeq {
e710: 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
e720: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 /* Name
e730: 20 6f 66 20 74 68 65 20 63 6f 6c 6c 61 74 69 6e of the collatin
e740: 67 20 73 65 71 75 65 6e 63 65 2c 20 55 54 46 2d g sequence, UTF-
e750: 38 20 65 6e 63 6f 64 65 64 20 2a 2f 0a 20 20 75 8 encoded */. u
e760: 38 20 65 6e 63 3b 20 20 20 20 20 20 20 20 20 20 8 enc;
e770: 20 20 20 20 20 2f 2a 20 54 65 78 74 20 65 6e 63 /* Text enc
e780: 6f 64 69 6e 67 20 68 61 6e 64 6c 65 64 20 62 79 oding handled by
e790: 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 76 6f 69 xCmp() */. voi
e7a0: 64 20 2a 70 55 73 65 72 3b 20 20 20 20 20 20 20 d *pUser;
e7b0: 20 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 75 /* First argu
e7c0: 6d 65 6e 74 20 74 6f 20 78 43 6d 70 28 29 20 2a ment to xCmp() *
e7d0: 2f 0a 20 20 69 6e 74 20 28 2a 78 43 6d 70 29 28 /. int (*xCmp)(
e7e0: 76 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 void*,int, const
e7f0: 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 63 6f 6e void*, int, con
e800: 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 st void*);. voi
e810: 64 20 28 2a 78 44 65 6c 29 28 76 6f 69 64 2a 29 d (*xDel)(void*)
e820: 3b 20 20 2f 2a 20 44 65 73 74 72 75 63 74 6f 72 ; /* Destructor
e830: 20 66 6f 72 20 70 55 73 65 72 20 2a 2f 0a 7d 3b for pUser */.};
e840: 0a 0a 2f 2a 0a 2a 2a 20 41 20 73 6f 72 74 20 6f ../*.** A sort o
e850: 72 64 65 72 20 63 61 6e 20 62 65 20 65 69 74 68 rder can be eith
e860: 65 72 20 41 53 43 20 6f 72 20 44 45 53 43 2e 0a er ASC or DESC..
e870: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e880: 45 5f 53 4f 5f 41 53 43 20 20 20 20 20 20 20 30 E_SO_ASC 0
e890: 20 20 2f 2a 20 53 6f 72 74 20 69 6e 20 61 73 63 /* Sort in asc
e8a0: 65 6e 64 69 6e 67 20 6f 72 64 65 72 20 2a 2f 0a ending order */.
e8b0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
e8c0: 4f 5f 44 45 53 43 20 20 20 20 20 20 31 20 20 2f O_DESC 1 /
e8d0: 2a 20 53 6f 72 74 20 69 6e 20 61 73 63 65 6e 64 * Sort in ascend
e8e0: 69 6e 67 20 6f 72 64 65 72 20 2a 2f 0a 0a 2f 2a ing order */../*
e8f0: 0a 2a 2a 20 43 6f 6c 75 6d 6e 20 61 66 66 69 6e .** Column affin
e900: 69 74 79 20 74 79 70 65 73 2e 0a 2a 2a 0a 2a 2a ity types..**.**
e910: 20 54 68 65 73 65 20 75 73 65 64 20 74 6f 20 68 These used to h
e920: 61 76 65 20 6d 6e 65 6d 6f 6e 69 63 20 6e 61 6d ave mnemonic nam
e930: 65 20 6c 69 6b 65 20 27 69 27 20 66 6f 72 20 53 e like 'i' for S
e940: 51 4c 49 54 45 5f 41 46 46 5f 49 4e 54 45 47 45 QLITE_AFF_INTEGE
e950: 52 20 61 6e 64 0a 2a 2a 20 27 74 27 20 66 6f 72 R and.** 't' for
e960: 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 45 58 54 SQLITE_AFF_TEXT
e970: 2e 20 20 42 75 74 20 77 65 20 63 61 6e 20 73 61 . But we can sa
e980: 76 65 20 61 20 6c 69 74 74 6c 65 20 73 70 61 63 ve a little spac
e990: 65 20 61 6e 64 20 69 6d 70 72 6f 76 65 0a 2a 2a e and improve.**
e9a0: 20 74 68 65 20 73 70 65 65 64 20 61 20 6c 69 74 the speed a lit
e9b0: 74 6c 65 20 62 79 20 6e 75 6d 62 65 72 69 6e 67 tle by numbering
e9c0: 20 74 68 65 20 76 61 6c 75 65 73 20 63 6f 6e 73 the values cons
e9d0: 65 63 75 74 69 76 65 6c 79 2e 20 20 0a 2a 2a 0a ecutively. .**.
e9e0: 2a 2a 20 42 75 74 20 72 61 74 68 65 72 20 74 68 ** But rather th
e9f0: 61 6e 20 73 74 61 72 74 20 77 69 74 68 20 30 20 an start with 0
ea00: 6f 72 20 31 2c 20 77 65 20 62 65 67 69 6e 20 77 or 1, we begin w
ea10: 69 74 68 20 27 41 27 2e 20 20 54 68 61 74 20 77 ith 'A'. That w
ea20: 61 79 2c 0a 2a 2a 20 77 68 65 6e 20 6d 75 6c 74 ay,.** when mult
ea30: 69 70 6c 65 20 61 66 66 69 6e 69 74 79 20 74 79 iple affinity ty
ea40: 70 65 73 20 61 72 65 20 63 6f 6e 63 61 74 65 6e pes are concaten
ea50: 61 74 65 64 20 69 6e 74 6f 20 61 20 73 74 72 69 ated into a stri
ea60: 6e 67 20 61 6e 64 0a 2a 2a 20 75 73 65 64 20 61 ng and.** used a
ea70: 73 20 74 68 65 20 50 34 20 6f 70 65 72 61 6e 64 s the P4 operand
ea80: 2c 20 74 68 65 79 20 77 69 6c 6c 20 62 65 20 6d , they will be m
ea90: 6f 72 65 20 72 65 61 64 61 62 6c 65 2e 0a 2a 2a ore readable..**
eaa0: 0a 2a 2a 20 4e 6f 74 65 20 61 6c 73 6f 20 74 68 .** Note also th
eab0: 61 74 20 74 68 65 20 6e 75 6d 65 72 69 63 20 74 at the numeric t
eac0: 79 70 65 73 20 61 72 65 20 67 72 6f 75 70 65 64 ypes are grouped
ead0: 20 74 6f 67 65 74 68 65 72 20 73 6f 20 74 68 61 together so tha
eae0: 74 20 74 65 73 74 69 6e 67 0a 2a 2a 20 66 6f 72 t testing.** for
eaf0: 20 61 20 6e 75 6d 65 72 69 63 20 74 79 70 65 20 a numeric type
eb00: 69 73 20 61 20 73 69 6e 67 6c 65 20 63 6f 6d 70 is a single comp
eb10: 61 72 69 73 6f 6e 2e 20 20 41 6e 64 20 74 68 65 arison. And the
eb20: 20 42 4c 4f 42 20 74 79 70 65 20 69 73 20 66 69 BLOB type is fi
eb30: 72 73 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 rst..*/.#define
eb40: 53 51 4c 49 54 45 5f 41 46 46 5f 42 4c 4f 42 20 SQLITE_AFF_BLOB
eb50: 20 20 20 20 27 41 27 0a 23 64 65 66 69 6e 65 20 'A'.#define
eb60: 53 51 4c 49 54 45 5f 41 46 46 5f 54 45 58 54 20 SQLITE_AFF_TEXT
eb70: 20 20 20 20 27 42 27 0a 23 64 65 66 69 6e 65 20 'B'.#define
eb80: 53 51 4c 49 54 45 5f 41 46 46 5f 4e 55 4d 45 52 SQLITE_AFF_NUMER
eb90: 49 43 20 20 27 43 27 0a 23 64 65 66 69 6e 65 20 IC 'C'.#define
eba0: 53 51 4c 49 54 45 5f 41 46 46 5f 49 4e 54 45 47 SQLITE_AFF_INTEG
ebb0: 45 52 20 20 27 44 27 0a 23 64 65 66 69 6e 65 20 ER 'D'.#define
ebc0: 53 51 4c 49 54 45 5f 41 46 46 5f 52 45 41 4c 20 SQLITE_AFF_REAL
ebd0: 20 20 20 20 27 45 27 0a 0a 23 64 65 66 69 6e 65 'E'..#define
ebe0: 20 73 71 6c 69 74 65 33 49 73 4e 75 6d 65 72 69 sqlite3IsNumeri
ebf0: 63 41 66 66 69 6e 69 74 79 28 58 29 20 20 28 28 cAffinity(X) ((
ec00: 58 29 3e 3d 53 51 4c 49 54 45 5f 41 46 46 5f 4e X)>=SQLITE_AFF_N
ec10: 55 4d 45 52 49 43 29 0a 0a 2f 2a 0a 2a 2a 20 54 UMERIC)../*.** T
ec20: 68 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4d 41 he SQLITE_AFF_MA
ec30: 53 4b 20 76 61 6c 75 65 73 20 6d 61 73 6b 73 20 SK values masks
ec40: 6f 66 66 20 74 68 65 20 73 69 67 6e 69 66 69 63 off the signific
ec50: 61 6e 74 20 62 69 74 73 20 6f 66 20 61 6e 0a 2a ant bits of an.*
ec60: 2a 20 61 66 66 69 6e 69 74 79 20 76 61 6c 75 65 * affinity value
ec70: 2e 20 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 . .*/.#define SQ
ec80: 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b 20 20 20 LITE_AFF_MASK
ec90: 20 20 30 78 34 37 0a 0a 2f 2a 0a 2a 2a 20 41 64 0x47../*.** Ad
eca0: 64 69 74 69 6f 6e 61 6c 20 62 69 74 20 76 61 6c ditional bit val
ecb0: 75 65 73 20 74 68 61 74 20 63 61 6e 20 62 65 20 ues that can be
ecc0: 4f 52 65 64 20 77 69 74 68 20 61 6e 20 61 66 66 ORed with an aff
ecd0: 69 6e 69 74 79 20 77 69 74 68 6f 75 74 0a 2a 2a inity without.**
ece0: 20 63 68 61 6e 67 69 6e 67 20 74 68 65 20 61 66 changing the af
ecf0: 66 69 6e 69 74 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 finity..**.** Th
ed00: 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c e SQLITE_NOTNULL
ed10: 20 66 6c 61 67 20 69 73 20 61 20 63 6f 6d 62 69 flag is a combi
ed20: 6e 61 74 69 6f 6e 20 6f 66 20 4e 55 4c 4c 45 51 nation of NULLEQ
ed30: 20 61 6e 64 20 4a 55 4d 50 49 46 4e 55 4c 4c 2e and JUMPIFNULL.
ed40: 0a 2a 2a 20 49 74 20 63 61 75 73 65 73 20 61 6e .** It causes an
ed50: 20 61 73 73 65 72 74 28 29 20 74 6f 20 66 69 72 assert() to fir
ed60: 65 20 69 66 20 65 69 74 68 65 72 20 6f 70 65 72 e if either oper
ed70: 61 6e 64 20 74 6f 20 61 20 63 6f 6d 70 61 72 69 and to a compari
ed80: 73 6f 6e 0a 2a 2a 20 6f 70 65 72 61 74 6f 72 20 son.** operator
ed90: 69 73 20 4e 55 4c 4c 2e 20 20 49 74 20 69 73 20 is NULL. It is
eda0: 61 64 64 65 64 20 74 6f 20 63 65 72 74 61 69 6e added to certain
edb0: 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 70 65 72 comparison oper
edc0: 61 74 6f 72 73 20 74 6f 0a 2a 2a 20 70 72 6f 76 ators to.** prov
edd0: 65 20 74 68 61 74 20 74 68 65 20 6f 70 65 72 61 e that the opera
ede0: 6e 64 73 20 61 72 65 20 61 6c 77 61 79 73 20 4e nds are always N
edf0: 4f 54 20 4e 55 4c 4c 2e 0a 2a 2f 0a 23 64 65 66 OT NULL..*/.#def
ee00: 69 6e 65 20 53 51 4c 49 54 45 5f 4a 55 4d 50 49 ine SQLITE_JUMPI
ee10: 46 4e 55 4c 4c 20 20 20 30 78 31 30 20 20 2f 2a FNULL 0x10 /*
ee20: 20 6a 75 6d 70 73 20 69 66 20 65 69 74 68 65 72 jumps if either
ee30: 20 6f 70 65 72 61 6e 64 20 69 73 20 4e 55 4c 4c operand is NULL
ee40: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
ee50: 54 45 5f 53 54 4f 52 45 50 32 20 20 20 20 20 20 TE_STOREP2
ee60: 30 78 32 30 20 20 2f 2a 20 53 74 6f 72 65 20 72 0x20 /* Store r
ee70: 65 73 75 6c 74 20 69 6e 20 72 65 67 5b 50 32 5d esult in reg[P2]
ee80: 20 72 61 74 68 65 72 20 74 68 61 6e 20 6a 75 6d rather than jum
ee90: 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c p */.#define SQL
eea0: 49 54 45 5f 4e 55 4c 4c 45 51 20 20 20 20 20 20 ITE_NULLEQ
eeb0: 20 30 78 38 30 20 20 2f 2a 20 4e 55 4c 4c 3d 4e 0x80 /* NULL=N
eec0: 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ULL */.#define S
eed0: 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c 20 20 20 QLITE_NOTNULL
eee0: 20 20 20 30 78 39 30 20 20 2f 2a 20 41 73 73 65 0x90 /* Asse
eef0: 72 74 20 74 68 61 74 20 6f 70 65 72 61 6e 64 73 rt that operands
ef00: 20 61 72 65 20 6e 65 76 65 72 20 4e 55 4c 4c 20 are never NULL
ef10: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a */../*.** An obj
ef20: 65 63 74 20 6f 66 20 74 68 69 73 20 74 79 70 65 ect of this type
ef30: 20 69 73 20 63 72 65 61 74 65 64 20 66 6f 72 20 is created for
ef40: 65 61 63 68 20 76 69 72 74 75 61 6c 20 74 61 62 each virtual tab
ef50: 6c 65 20 70 72 65 73 65 6e 74 20 69 6e 0a 2a 2a le present in.**
ef60: 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 63 the database sc
ef70: 68 65 6d 61 2e 20 0a 2a 2a 0a 2a 2a 20 49 66 20 hema. .**.** If
ef80: 74 68 65 20 64 61 74 61 62 61 73 65 20 73 63 68 the database sch
ef90: 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c 20 74 ema is shared, t
efa0: 68 65 6e 20 74 68 65 72 65 20 69 73 20 6f 6e 65 hen there is one
efb0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 instance of thi
efc0: 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 20 66 s.** structure f
efd0: 6f 72 20 65 61 63 68 20 64 61 74 61 62 61 73 65 or each database
efe0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 28 73 71 6c connection (sql
eff0: 69 74 65 33 2a 29 20 74 68 61 74 20 75 73 65 73 ite3*) that uses
f000: 20 74 68 65 20 73 68 61 72 65 64 0a 2a 2a 20 73 the shared.** s
f010: 63 68 65 6d 61 2e 20 54 68 69 73 20 69 73 20 62 chema. This is b
f020: 65 63 61 75 73 65 20 65 61 63 68 20 64 61 74 61 ecause each data
f030: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 base connection
f040: 72 65 71 75 69 72 65 73 20 69 74 73 20 6f 77 6e requires its own
f050: 20 75 6e 69 71 75 65 0a 2a 2a 20 69 6e 73 74 61 unique.** insta
f060: 6e 63 65 20 6f 66 20 74 68 65 20 73 71 6c 69 74 nce of the sqlit
f070: 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 20 e3_vtab* handle
f080: 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 20 74 used to access t
f090: 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 he virtual table
f0a0: 20 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 .** implementat
f0b0: 69 6f 6e 2e 20 73 71 6c 69 74 65 33 5f 76 74 61 ion. sqlite3_vta
f0c0: 62 2a 20 68 61 6e 64 6c 65 73 20 63 61 6e 20 6e b* handles can n
f0d0: 6f 74 20 62 65 20 73 68 61 72 65 64 20 62 65 74 ot be shared bet
f0e0: 77 65 65 6e 20 0a 2a 2a 20 64 61 74 61 62 61 73 ween .** databas
f0f0: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 2c 20 65 e connections, e
f100: 76 65 6e 20 77 68 65 6e 20 74 68 65 20 72 65 73 ven when the res
f110: 74 20 6f 66 20 74 68 65 20 69 6e 2d 6d 65 6d 6f t of the in-memo
f120: 72 79 20 64 61 74 61 62 61 73 65 20 0a 2a 2a 20 ry database .**
f130: 73 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 schema is shared
f140: 2c 20 61 73 20 74 68 65 20 69 6d 70 6c 65 6d 65 , as the impleme
f150: 6e 74 61 74 69 6f 6e 20 6f 66 74 65 6e 20 73 74 ntation often st
f160: 6f 72 65 73 20 74 68 65 20 64 61 74 61 62 61 73 ores the databas
f170: 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 e.** connection
f180: 68 61 6e 64 6c 65 20 70 61 73 73 65 64 20 74 6f handle passed to
f190: 20 69 74 20 76 69 61 20 74 68 65 20 78 43 6f 6e it via the xCon
f1a0: 6e 65 63 74 28 29 20 6f 72 20 78 43 72 65 61 74 nect() or xCreat
f1b0: 65 28 29 20 6d 65 74 68 6f 64 0a 2a 2a 20 64 75 e() method.** du
f1c0: 72 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 ring initializat
f1d0: 69 6f 6e 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 20 ion internally.
f1e0: 54 68 69 73 20 64 61 74 61 62 61 73 65 20 63 6f This database co
f1f0: 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 nnection handle
f200: 6d 61 79 0a 2a 2a 20 74 68 65 6e 20 62 65 20 75 may.** then be u
f210: 73 65 64 20 62 79 20 74 68 65 20 76 69 72 74 75 sed by the virtu
f220: 61 6c 20 74 61 62 6c 65 20 69 6d 70 6c 65 6d 65 al table impleme
f230: 6e 74 61 74 69 6f 6e 20 74 6f 20 61 63 63 65 73 ntation to acces
f240: 73 20 72 65 61 6c 20 74 61 62 6c 65 73 20 0a 2a s real tables .*
f250: 2a 20 77 69 74 68 69 6e 20 74 68 65 20 64 61 74 * within the dat
f260: 61 62 61 73 65 2e 20 53 6f 20 74 68 61 74 20 74 abase. So that t
f270: 68 65 79 20 61 70 70 65 61 72 20 61 73 20 70 61 hey appear as pa
f280: 72 74 20 6f 66 20 74 68 65 20 63 61 6c 6c 65 72 rt of the caller
f290: 73 20 0a 2a 2a 20 74 72 61 6e 73 61 63 74 69 6f s .** transactio
f2a0: 6e 2c 20 74 68 65 73 65 20 61 63 63 65 73 73 65 n, these accesse
f2b0: 73 20 6e 65 65 64 20 74 6f 20 62 65 20 6d 61 64 s need to be mad
f2c0: 65 20 76 69 61 20 74 68 65 20 73 61 6d 65 20 64 e via the same d
f2d0: 61 74 61 62 61 73 65 20 0a 2a 2a 20 63 6f 6e 6e atabase .** conn
f2e0: 65 63 74 69 6f 6e 20 61 73 20 74 68 61 74 20 75 ection as that u
f2f0: 73 65 64 20 74 6f 20 65 78 65 63 75 74 65 20 53 sed to execute S
f300: 51 4c 20 6f 70 65 72 61 74 69 6f 6e 73 20 6f 6e QL operations on
f310: 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 the virtual tab
f320: 6c 65 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 56 54 le..**.** All VT
f330: 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 68 61 able objects tha
f340: 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 t correspond to
f350: 61 20 73 69 6e 67 6c 65 20 74 61 62 6c 65 20 69 a single table i
f360: 6e 20 61 20 73 68 61 72 65 64 0a 2a 2a 20 64 61 n a shared.** da
f370: 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 61 72 tabase schema ar
f380: 65 20 69 6e 69 74 69 61 6c 6c 79 20 73 74 6f 72 e initially stor
f390: 65 64 20 69 6e 20 61 20 6c 69 6e 6b 65 64 2d 6c ed in a linked-l
f3a0: 69 73 74 20 70 6f 69 6e 74 65 64 20 74 6f 20 62 ist pointed to b
f3b0: 79 0a 2a 2a 20 74 68 65 20 54 61 62 6c 65 2e 70 y.** the Table.p
f3c0: 56 54 61 62 6c 65 20 6d 65 6d 62 65 72 20 76 61 VTable member va
f3d0: 72 69 61 62 6c 65 20 6f 66 20 74 68 65 20 63 6f riable of the co
f3e0: 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 61 62 6c rresponding Tabl
f3f0: 65 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 57 68 65 e object..** Whe
f400: 6e 20 61 6e 20 73 71 6c 69 74 65 33 5f 70 72 65 n an sqlite3_pre
f410: 70 61 72 65 28 29 20 6f 70 65 72 61 74 69 6f 6e pare() operation
f420: 20 69 73 20 72 65 71 75 69 72 65 64 20 74 6f 20 is required to
f430: 61 63 63 65 73 73 20 74 68 65 20 76 69 72 74 75 access the virtu
f440: 61 6c 0a 2a 2a 20 74 61 62 6c 65 2c 20 69 74 20 al.** table, it
f450: 73 65 61 72 63 68 65 73 20 74 68 65 20 6c 69 73 searches the lis
f460: 74 20 66 6f 72 20 74 68 65 20 56 54 61 62 6c 65 t for the VTable
f470: 20 74 68 61 74 20 63 6f 72 72 65 73 70 6f 6e 64 that correspond
f480: 73 20 74 6f 20 74 68 65 0a 2a 2a 20 64 61 74 61 s to the.** data
f490: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 base connection
f4a0: 64 6f 69 6e 67 20 74 68 65 20 70 72 65 70 61 72 doing the prepar
f4b0: 69 6e 67 20 73 6f 20 61 73 20 74 6f 20 75 73 65 ing so as to use
f4c0: 20 74 68 65 20 63 6f 72 72 65 63 74 0a 2a 2a 20 the correct.**
f4d0: 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 sqlite3_vtab* ha
f4e0: 6e 64 6c 65 20 69 6e 20 74 68 65 20 63 6f 6d 70 ndle in the comp
f4f0: 69 6c 65 64 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a iled query..**.*
f500: 2a 20 57 68 65 6e 20 61 6e 20 69 6e 2d 6d 65 6d * When an in-mem
f510: 6f 72 79 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 ory Table object
f520: 20 69 73 20 64 65 6c 65 74 65 64 20 28 66 6f 72 is deleted (for
f530: 20 65 78 61 6d 70 6c 65 20 77 68 65 6e 20 74 68 example when th
f540: 65 0a 2a 2a 20 73 63 68 65 6d 61 20 69 73 20 62 e.** schema is b
f550: 65 69 6e 67 20 72 65 6c 6f 61 64 65 64 20 66 6f eing reloaded fo
f560: 72 20 73 6f 6d 65 20 72 65 61 73 6f 6e 29 2c 20 r some reason),
f570: 74 68 65 20 56 54 61 62 6c 65 20 6f 62 6a 65 63 the VTable objec
f580: 74 73 20 61 72 65 20 6e 6f 74 20 0a 2a 2a 20 64 ts are not .** d
f590: 65 6c 65 74 65 64 20 61 6e 64 20 74 68 65 20 73 eleted and the s
f5a0: 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e qlite3_vtab* han
f5b0: 64 6c 65 73 20 61 72 65 20 6e 6f 74 20 78 44 69 dles are not xDi
f5c0: 73 63 6f 6e 6e 65 63 74 28 29 65 64 20 0a 2a 2a sconnect()ed .**
f5d0: 20 69 6d 6d 65 64 69 61 74 65 6c 79 2e 20 49 6e immediately. In
f5e0: 73 74 65 61 64 2c 20 74 68 65 79 20 61 72 65 20 stead, they are
f5f0: 6d 6f 76 65 64 20 66 72 6f 6d 20 74 68 65 20 54 moved from the T
f600: 61 62 6c 65 2e 70 56 54 61 62 6c 65 20 6c 69 73 able.pVTable lis
f610: 74 20 74 6f 0a 2a 2a 20 61 6e 6f 74 68 65 72 20 t to.** another
f620: 6c 69 6e 6b 65 64 20 6c 69 73 74 20 68 65 61 64 linked list head
f630: 65 64 20 62 79 20 74 68 65 20 73 71 6c 69 74 65 ed by the sqlite
f640: 33 2e 70 44 69 73 63 6f 6e 6e 65 63 74 20 6d 65 3.pDisconnect me
f650: 6d 62 65 72 20 6f 66 20 74 68 65 0a 2a 2a 20 63 mber of the.** c
f660: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 73 71 6c orresponding sql
f670: 69 74 65 33 20 73 74 72 75 63 74 75 72 65 2e 20 ite3 structure.
f680: 54 68 65 79 20 61 72 65 20 74 68 65 6e 20 64 65 They are then de
f690: 6c 65 74 65 64 2f 78 44 69 73 63 6f 6e 6e 65 63 leted/xDisconnec
f6a0: 74 65 64 20 0a 2a 2a 20 6e 65 78 74 20 74 69 6d ted .** next tim
f6b0: 65 20 61 20 73 74 61 74 65 6d 65 6e 74 20 69 73 e a statement is
f6c0: 20 70 72 65 70 61 72 65 64 20 75 73 69 6e 67 20 prepared using
f6d0: 73 61 69 64 20 73 71 6c 69 74 65 33 2a 2e 20 54 said sqlite3*. T
f6e0: 68 69 73 20 69 73 20 64 6f 6e 65 0a 2a 2a 20 74 his is done.** t
f6f0: 6f 20 61 76 6f 69 64 20 64 65 61 64 6c 6f 63 6b o avoid deadlock
f700: 20 69 73 73 75 65 73 20 69 6e 76 6f 6c 76 69 6e issues involvin
f710: 67 20 6d 75 6c 74 69 70 6c 65 20 73 71 6c 69 74 g multiple sqlit
f720: 65 33 2e 6d 75 74 65 78 20 6d 75 74 65 78 65 73 e3.mutex mutexes
f730: 2e 0a 2a 2a 20 52 65 66 65 72 20 74 6f 20 63 6f ..** Refer to co
f740: 6d 6d 65 6e 74 73 20 61 62 6f 76 65 20 66 75 6e mments above fun
f750: 63 74 69 6f 6e 20 73 71 6c 69 74 65 33 56 74 61 ction sqlite3Vta
f760: 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 29 20 66 6f bUnlockList() fo
f770: 72 20 61 6e 0a 2a 2a 20 65 78 70 6c 61 6e 61 74 r an.** explanat
f780: 69 6f 6e 20 61 73 20 74 6f 20 77 68 79 20 69 74 ion as to why it
f790: 20 69 73 20 73 61 66 65 20 74 6f 20 61 64 64 20 is safe to add
f7a0: 61 6e 20 65 6e 74 72 79 20 74 6f 20 61 6e 20 73 an entry to an s
f7b0: 71 6c 69 74 65 33 2e 70 44 69 73 63 6f 6e 6e 65 qlite3.pDisconne
f7c0: 63 74 0a 2a 2a 20 6c 69 73 74 20 77 69 74 68 6f ct.** list witho
f7d0: 75 74 20 68 6f 6c 64 69 6e 67 20 74 68 65 20 63 ut holding the c
f7e0: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 73 71 6c orresponding sql
f7f0: 69 74 65 33 2e 6d 75 74 65 78 20 6d 75 74 65 78 ite3.mutex mutex
f800: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6d 65 6d 6f ..**.** The memo
f810: 72 79 20 66 6f 72 20 6f 62 6a 65 63 74 73 20 6f ry for objects o
f820: 66 20 74 68 69 73 20 74 79 70 65 20 69 73 20 61 f this type is a
f830: 6c 77 61 79 73 20 61 6c 6c 6f 63 61 74 65 64 20 lways allocated
f840: 62 79 20 0a 2a 2a 20 73 71 6c 69 74 65 33 44 62 by .** sqlite3Db
f850: 4d 61 6c 6c 6f 63 28 29 2c 20 75 73 69 6e 67 20 Malloc(), using
f860: 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 the connection h
f870: 61 6e 64 6c 65 20 73 74 6f 72 65 64 20 69 6e 20 andle stored in
f880: 56 54 61 62 6c 65 2e 64 62 20 61 73 20 0a 2a 2a VTable.db as .**
f890: 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d the first argum
f8a0: 65 6e 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 56 ent..*/.struct V
f8b0: 54 61 62 6c 65 20 7b 0a 20 20 73 71 6c 69 74 65 Table {. sqlite
f8c0: 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 20 20 3 *db;
f8d0: 20 20 20 20 2f 2a 20 44 61 74 61 62 61 73 65 20 /* Database
f8e0: 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 73 73 6f 63 connection assoc
f8f0: 69 61 74 65 64 20 77 69 74 68 20 74 68 69 73 20 iated with this
f900: 74 61 62 6c 65 20 2a 2f 0a 20 20 4d 6f 64 75 6c table */. Modul
f910: 65 20 2a 70 4d 6f 64 3b 20 20 20 20 20 20 20 20 e *pMod;
f920: 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 /* Pointer
f930: 74 6f 20 6d 6f 64 75 6c 65 20 69 6d 70 6c 65 6d to module implem
f940: 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 73 71 entation */. sq
f950: 6c 69 74 65 33 5f 76 74 61 62 20 2a 70 56 74 61 lite3_vtab *pVta
f960: 62 3b 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 b; /* Point
f970: 65 72 20 74 6f 20 76 74 61 62 20 69 6e 73 74 61 er to vtab insta
f980: 6e 63 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 nce */. int nRe
f990: 66 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 f;
f9a0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
f9b0: 70 6f 69 6e 74 65 72 73 20 74 6f 20 74 68 69 73 pointers to this
f9c0: 20 73 74 72 75 63 74 75 72 65 20 2a 2f 0a 20 20 structure */.
f9d0: 75 38 20 62 43 6f 6e 73 74 72 61 69 6e 74 3b 20 u8 bConstraint;
f9e0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
f9f0: 65 20 69 66 20 63 6f 6e 73 74 72 61 69 6e 74 73 e if constraints
fa00: 20 61 72 65 20 73 75 70 70 6f 72 74 65 64 20 2a are supported *
fa10: 2f 0a 20 20 69 6e 74 20 69 53 61 76 65 70 6f 69 /. int iSavepoi
fa20: 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a nt; /*
fa30: 20 44 65 70 74 68 20 6f 66 20 74 68 65 20 53 41 Depth of the SA
fa40: 56 45 50 4f 49 4e 54 20 73 74 61 63 6b 20 2a 2f VEPOINT stack */
fa50: 0a 20 20 56 54 61 62 6c 65 20 2a 70 4e 65 78 74 . VTable *pNext
fa60: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
fa70: 4e 65 78 74 20 69 6e 20 6c 69 6e 6b 65 64 20 6c Next in linked l
fa80: 69 73 74 20 28 73 65 65 20 61 62 6f 76 65 29 20 ist (see above)
fa90: 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 */.};../*.** The
faa0: 20 73 63 68 65 6d 61 20 66 6f 72 20 65 61 63 68 schema for each
fab0: 20 53 51 4c 20 74 61 62 6c 65 20 61 6e 64 20 76 SQL table and v
fac0: 69 65 77 20 69 73 20 72 65 70 72 65 73 65 6e 74 iew is represent
fad0: 65 64 20 69 6e 20 6d 65 6d 6f 72 79 0a 2a 2a 20 ed in memory.**
fae0: 62 79 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f by an instance o
faf0: 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
fb00: 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 structure..*/.st
fb10: 72 75 63 74 20 54 61 62 6c 65 20 7b 0a 20 20 63 ruct Table {. c
fb20: 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
fb30: 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 /* Name of t
fb40: 68 65 20 74 61 62 6c 65 20 6f 72 20 76 69 65 77 he table or view
fb50: 20 2a 2f 0a 20 20 43 6f 6c 75 6d 6e 20 2a 61 43 */. Column *aC
fb60: 6f 6c 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 6e ol; /* In
fb70: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
fb80: 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 each column */.
fb90: 20 49 6e 64 65 78 20 2a 70 49 6e 64 65 78 3b 20 Index *pIndex;
fba0: 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 /* List of
fbb0: 20 53 51 4c 20 69 6e 64 65 78 65 73 20 6f 6e 20 SQL indexes on
fbc0: 74 68 69 73 20 74 61 62 6c 65 2e 20 2a 2f 0a 20 this table. */.
fbd0: 20 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 Select *pSelect
fbe0: 3b 20 20 20 20 20 2f 2a 20 4e 55 4c 4c 20 66 6f ; /* NULL fo
fbf0: 72 20 74 61 62 6c 65 73 2e 20 20 50 6f 69 6e 74 r tables. Point
fc00: 73 20 74 6f 20 64 65 66 69 6e 69 74 69 6f 6e 20 s to definition
fc10: 69 66 20 61 20 76 69 65 77 2e 20 2a 2f 0a 20 20 if a view. */.
fc20: 46 4b 65 79 20 2a 70 46 4b 65 79 3b 20 20 20 20 FKey *pFKey;
fc30: 20 20 20 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c /* Linked l
fc40: 69 73 74 20 6f 66 20 61 6c 6c 20 66 6f 72 65 69 ist of all forei
fc50: 67 6e 20 6b 65 79 73 20 69 6e 20 74 68 69 73 20 gn keys in this
fc60: 74 61 62 6c 65 20 2a 2f 0a 20 20 63 68 61 72 20 table */. char
fc70: 2a 7a 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 20 *zColAff;
fc80: 2f 2a 20 53 74 72 69 6e 67 20 64 65 66 69 6e 69 /* String defini
fc90: 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 79 20 ng the affinity
fca0: 6f 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a of each column *
fcb0: 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
fcc0: 5f 4f 4d 49 54 5f 43 48 45 43 4b 0a 20 20 45 78 _OMIT_CHECK. Ex
fcd0: 70 72 4c 69 73 74 20 2a 70 43 68 65 63 6b 3b 20 prList *pCheck;
fce0: 20 20 20 2f 2a 20 41 6c 6c 20 43 48 45 43 4b 20 /* All CHECK
fcf0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 constraints */.#
fd00: 65 6e 64 69 66 0a 20 20 69 6e 74 20 74 6e 75 6d endif. int tnum
fd10: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
fd20: 52 6f 6f 74 20 42 54 72 65 65 20 70 61 67 65 20 Root BTree page
fd30: 66 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 2a for this table *
fd40: 2f 0a 20 20 69 31 36 20 69 50 4b 65 79 3b 20 20 /. i16 iPKey;
fd50: 20 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e /* If n
fd60: 6f 74 20 6e 65 67 61 74 69 76 65 2c 20 75 73 65 ot negative, use
fd70: 20 61 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 73 20 aCol[iPKey] as
fd80: 74 68 65 20 72 6f 77 69 64 20 2a 2f 0a 20 20 69 the rowid */. i
fd90: 31 36 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 16 nCol;
fda0: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
fdb0: 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 columns in this
fdc0: 20 74 61 62 6c 65 20 2a 2f 0a 20 20 75 31 36 20 table */. u16
fdd0: 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 20 20 nRef;
fde0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 6f /* Number of po
fdf0: 69 6e 74 65 72 73 20 74 6f 20 74 68 69 73 20 54 inters to this T
fe00: 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 able */. LogEst
fe10: 20 6e 52 6f 77 4c 6f 67 45 73 74 3b 20 20 20 2f nRowLogEst; /
fe20: 2a 20 45 73 74 69 6d 61 74 65 64 20 72 6f 77 73 * Estimated rows
fe30: 20 69 6e 20 74 61 62 6c 65 20 2d 20 66 72 6f 6d in table - from
fe40: 20 73 71 6c 69 74 65 5f 73 74 61 74 31 20 74 61 sqlite_stat1 ta
fe50: 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 ble */. LogEst
fe60: 73 7a 54 61 62 52 6f 77 3b 20 20 20 20 20 2f 2a szTabRow; /*
fe70: 20 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 20 Estimated size
fe80: 6f 66 20 65 61 63 68 20 74 61 62 6c 65 20 72 6f of each table ro
fe90: 77 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 23 69 w in bytes */.#i
fea0: 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
feb0: 4c 45 5f 43 4f 53 54 4d 55 4c 54 0a 20 20 4c 6f LE_COSTMULT. Lo
fec0: 67 45 73 74 20 63 6f 73 74 4d 75 6c 74 3b 20 20 gEst costMult;
fed0: 20 20 20 2f 2a 20 43 6f 73 74 20 6d 75 6c 74 69 /* Cost multi
fee0: 70 6c 69 65 72 20 66 6f 72 20 75 73 69 6e 67 20 plier for using
fef0: 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 23 65 this table */.#e
ff00: 6e 64 69 66 0a 20 20 75 38 20 74 61 62 46 6c 61 ndif. u8 tabFla
ff10: 67 73 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4d gs; /* M
ff20: 61 73 6b 20 6f 66 20 54 46 5f 2a 20 76 61 6c 75 ask of TF_* valu
ff30: 65 73 20 2a 2f 0a 20 20 75 38 20 6b 65 79 43 6f es */. u8 keyCo
ff40: 6e 66 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 nf; /*
ff50: 57 68 61 74 20 74 6f 20 64 6f 20 69 6e 20 63 61 What to do in ca
ff60: 73 65 20 6f 66 20 75 6e 69 71 75 65 6e 65 73 73 se of uniqueness
ff70: 20 63 6f 6e 66 6c 69 63 74 20 6f 6e 20 69 50 4b conflict on iPK
ff80: 65 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 ey */.#ifndef SQ
ff90: 4c 49 54 45 5f 4f 4d 49 54 5f 41 4c 54 45 52 54 LITE_OMIT_ALTERT
ffa0: 41 42 4c 45 0a 20 20 69 6e 74 20 61 64 64 43 6f ABLE. int addCo
ffb0: 6c 4f 66 66 73 65 74 3b 20 20 20 20 2f 2a 20 4f lOffset; /* O
ffc0: 66 66 73 65 74 20 69 6e 20 43 52 45 41 54 45 20 ffset in CREATE
ffd0: 54 41 42 4c 45 20 73 74 6d 74 20 74 6f 20 61 64 TABLE stmt to ad
ffe0: 64 20 61 20 6e 65 77 20 63 6f 6c 75 6d 6e 20 2a d a new column *
fff0: 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 /.#endif.#ifndef
10000 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 SQLITE_OMIT_VIR
10010 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 20 TUALTABLE. int
10020 6e 4d 6f 64 75 6c 65 41 72 67 3b 20 20 20 20 20 nModuleArg;
10030 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 /* Number of ar
10040 67 75 6d 65 6e 74 73 20 74 6f 20 74 68 65 20 6d guments to the m
10050 6f 64 75 6c 65 20 2a 2f 0a 20 20 63 68 61 72 20 odule */. char
10060 2a 2a 61 7a 4d 6f 64 75 6c 65 41 72 67 3b 20 20 **azModuleArg;
10070 2f 2a 20 54 65 78 74 20 6f 66 20 61 6c 6c 20 6d /* Text of all m
10080 6f 64 75 6c 65 20 61 72 67 73 2e 20 5b 30 5d 20 odule args. [0]
10090 69 73 20 6d 6f 64 75 6c 65 20 6e 61 6d 65 20 2a is module name *
100a0 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 56 54 61 /. VTable *pVTa
100b0 62 6c 65 3b 20 20 20 20 20 2f 2a 20 4c 69 73 74 ble; /* List
100c0 20 6f 66 20 56 54 61 62 6c 65 20 6f 62 6a 65 63 of VTable objec
100d0 74 73 2e 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 ts. */.#endif.
100e0 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 65 Trigger *pTrigge
100f0 72 3b 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 r; /* List of
10100 74 72 69 67 67 65 72 73 20 73 74 6f 72 65 64 20 triggers stored
10110 69 6e 20 70 53 63 68 65 6d 61 20 2a 2f 0a 20 20 in pSchema */.
10120 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b Schema *pSchema;
10130 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 74 /* Schema t
10140 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 69 hat contains thi
10150 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 54 61 62 s table */. Tab
10160 6c 65 20 2a 70 4e 65 78 74 5a 6f 6d 62 69 65 3b le *pNextZombie;
10170 20 20 2f 2a 20 4e 65 78 74 20 6f 6e 20 74 68 65 /* Next on the
10180 20 50 61 72 73 65 2e 70 5a 6f 6d 62 69 65 54 61 Parse.pZombieTa
10190 62 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a b list */.};../*
101a0 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 .** Allowed valu
101b0 65 73 20 66 6f 72 20 54 61 62 6c 65 2e 74 61 62 es for Table.tab
101c0 46 6c 61 67 73 2e 0a 2a 2a 0a 2a 2a 20 54 46 5f Flags..**.** TF_
101d0 4f 4f 4f 48 69 64 64 65 6e 20 61 70 70 6c 69 65 OOOHidden applie
101e0 73 20 74 6f 20 76 69 72 74 75 61 6c 20 74 61 62 s to virtual tab
101f0 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 68 69 les that have hi
10200 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 74 68 61 dden columns tha
10210 74 20 61 72 65 0a 2a 2a 20 66 6f 6c 6c 6f 77 65 t are.** followe
10220 64 20 62 79 20 6e 6f 6e 2d 68 69 64 64 65 6e 20 d by non-hidden
10230 63 6f 6c 75 6d 6e 73 2e 20 20 45 78 61 6d 70 6c columns. Exampl
10240 65 3a 20 20 22 43 52 45 41 54 45 20 56 49 52 54 e: "CREATE VIRT
10250 55 41 4c 20 54 41 42 4c 45 20 78 20 55 53 49 4e UAL TABLE x USIN
10260 47 0a 2a 2a 20 76 74 61 62 31 28 61 20 48 49 44 G.** vtab1(a HID
10270 44 45 4e 2c 20 62 29 3b 22 2e 20 20 53 69 6e 63 DEN, b);". Sinc
10280 65 20 22 62 22 20 69 73 20 61 20 6e 6f 6e 2d 68 e "b" is a non-h
10290 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 20 62 75 74 idden column but
102a0 20 22 61 22 20 69 73 20 68 69 64 64 65 6e 2c 0a "a" is hidden,.
102b0 2a 2a 20 74 68 65 20 54 46 5f 4f 4f 4f 48 69 64 ** the TF_OOOHid
102c0 64 65 6e 20 61 74 74 72 69 62 75 74 65 20 77 6f den attribute wo
102d0 75 6c 64 20 61 70 70 6c 79 20 69 6e 20 74 68 69 uld apply in thi
102e0 73 20 63 61 73 65 2e 20 20 53 75 63 68 20 74 61 s case. Such ta
102f0 62 6c 65 73 20 72 65 71 75 69 72 65 0a 2a 2a 20 bles require.**
10300 73 70 65 63 69 61 6c 20 68 61 6e 64 6c 69 6e 67 special handling
10310 20 64 75 72 69 6e 67 20 49 4e 53 45 52 54 20 70 during INSERT p
10320 72 6f 63 65 73 73 69 6e 67 2e 0a 2a 2f 0a 23 64 rocessing..*/.#d
10330 65 66 69 6e 65 20 54 46 5f 52 65 61 64 6f 6e 6c efine TF_Readonl
10340 79 20 20 20 20 20 20 20 20 30 78 30 31 20 20 20 y 0x01
10350 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 79 20 73 79 /* Read-only sy
10360 73 74 65 6d 20 74 61 62 6c 65 20 2a 2f 0a 23 64 stem table */.#d
10370 65 66 69 6e 65 20 54 46 5f 45 70 68 65 6d 65 72 efine TF_Ephemer
10380 61 6c 20 20 20 20 20 20 20 30 78 30 32 20 20 20 al 0x02
10390 20 2f 2a 20 41 6e 20 65 70 68 65 6d 65 72 61 6c /* An ephemeral
103a0 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e table */.#defin
103b0 65 20 54 46 5f 48 61 73 50 72 69 6d 61 72 79 4b e TF_HasPrimaryK
103c0 65 79 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 ey 0x04 /*
103d0 54 61 62 6c 65 20 68 61 73 20 61 20 70 72 69 6d Table has a prim
103e0 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 ary key */.#defi
103f0 6e 65 20 54 46 5f 41 75 74 6f 69 6e 63 72 65 6d ne TF_Autoincrem
10400 65 6e 74 20 20 20 30 78 30 38 20 20 20 20 2f 2a ent 0x08 /*
10410 20 49 6e 74 65 67 65 72 20 70 72 69 6d 61 72 79 Integer primary
10420 20 6b 65 79 20 69 73 20 61 75 74 6f 69 6e 63 72 key is autoincr
10430 65 6d 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 ement */.#define
10440 20 54 46 5f 56 69 72 74 75 61 6c 20 20 20 20 20 TF_Virtual
10450 20 20 20 20 30 78 31 30 20 20 20 20 2f 2a 20 49 0x10 /* I
10460 73 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c s a virtual tabl
10470 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f e */.#define TF_
10480 57 69 74 68 6f 75 74 52 6f 77 69 64 20 20 20 20 WithoutRowid
10490 30 78 32 30 20 20 20 20 2f 2a 20 4e 6f 20 72 6f 0x20 /* No ro
104a0 77 69 64 2e 20 20 50 52 49 4d 41 52 59 20 4b 45 wid. PRIMARY KE
104b0 59 20 69 73 20 74 68 65 20 6b 65 79 20 2a 2f 0a Y is the key */.
104c0 23 64 65 66 69 6e 65 20 54 46 5f 4e 6f 56 69 73 #define TF_NoVis
104d0 69 62 6c 65 52 6f 77 69 64 20 20 30 78 34 30 20 ibleRowid 0x40
104e0 20 20 20 2f 2a 20 4e 6f 20 75 73 65 72 2d 76 69 /* No user-vi
104f0 73 69 62 6c 65 20 22 72 6f 77 69 64 22 20 63 6f sible "rowid" co
10500 6c 75 6d 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 lumn */.#define
10510 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 20 20 20 TF_OOOHidden
10520 20 20 20 30 78 38 30 20 20 20 20 2f 2a 20 4f 75 0x80 /* Ou
10530 74 2d 6f 66 2d 4f 72 64 65 72 20 68 69 64 64 65 t-of-Order hidde
10540 6e 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 0a 0a 2f n columns */.../
10550 2a 0a 2a 2a 20 54 65 73 74 20 74 6f 20 73 65 65 *.** Test to see
10560 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 whether or not
10570 61 20 74 61 62 6c 65 20 69 73 20 61 20 76 69 72 a table is a vir
10580 74 75 61 6c 20 74 61 62 6c 65 2e 20 20 54 68 69 tual table. Thi
10590 73 20 69 73 0a 2a 2a 20 64 6f 6e 65 20 61 73 20 s is.** done as
105a0 61 20 6d 61 63 72 6f 20 73 6f 20 74 68 61 74 20 a macro so that
105b0 69 74 20 77 69 6c 6c 20 62 65 20 6f 70 74 69 6d it will be optim
105c0 69 7a 65 64 20 6f 75 74 20 77 68 65 6e 20 76 69 ized out when vi
105d0 72 74 75 61 6c 0a 2a 2a 20 74 61 62 6c 65 20 73 rtual.** table s
105e0 75 70 70 6f 72 74 20 69 73 20 6f 6d 69 74 74 65 upport is omitte
105f0 64 20 66 72 6f 6d 20 74 68 65 20 62 75 69 6c 64 d from the build
10600 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c ..*/.#ifndef SQL
10610 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
10620 54 41 42 4c 45 0a 23 20 20 64 65 66 69 6e 65 20 TABLE.# define
10630 49 73 56 69 72 74 75 61 6c 28 58 29 20 20 20 20 IsVirtual(X)
10640 20 20 28 28 28 58 29 2d 3e 74 61 62 46 6c 61 67 (((X)->tabFlag
10650 73 20 26 20 54 46 5f 56 69 72 74 75 61 6c 29 21 s & TF_Virtual)!
10660 3d 30 29 0a 23 20 20 64 65 66 69 6e 65 20 49 73 =0).# define Is
10670 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 HiddenColumn(X)
10680 28 28 28 58 29 2d 3e 63 6f 6c 46 6c 61 67 73 20 (((X)->colFlags
10690 26 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 45 4e & COLFLAG_HIDDEN
106a0 29 21 3d 30 29 0a 23 65 6c 73 65 0a 23 20 20 64 )!=0).#else.# d
106b0 65 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 efine IsVirtual(
106c0 58 29 20 20 20 20 20 20 30 0a 23 20 20 64 65 66 X) 0.# def
106d0 69 6e 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 ine IsHiddenColu
106e0 6d 6e 28 58 29 20 30 0a 23 65 6e 64 69 66 0a 0a mn(X) 0.#endif..
106f0 2f 2a 20 44 6f 65 73 20 74 68 65 20 74 61 62 6c /* Does the tabl
10700 65 20 68 61 76 65 20 61 20 72 6f 77 69 64 20 2a e have a rowid *
10710 2f 0a 23 64 65 66 69 6e 65 20 48 61 73 52 6f 77 /.#define HasRow
10720 69 64 28 58 29 20 20 20 20 20 28 28 28 58 29 2d id(X) (((X)-
10730 3e 74 61 62 46 6c 61 67 73 20 26 20 54 46 5f 57 >tabFlags & TF_W
10740 69 74 68 6f 75 74 52 6f 77 69 64 29 3d 3d 30 29 ithoutRowid)==0)
10750 0a 23 64 65 66 69 6e 65 20 56 69 73 69 62 6c 65 .#define Visible
10760 52 6f 77 69 64 28 58 29 20 28 28 28 58 29 2d 3e Rowid(X) (((X)->
10770 74 61 62 46 6c 61 67 73 20 26 20 54 46 5f 4e 6f tabFlags & TF_No
10780 56 69 73 69 62 6c 65 52 6f 77 69 64 29 3d 3d 30 VisibleRowid)==0
10790 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 66 6f )../*.** Each fo
107a0 72 65 69 67 6e 20 6b 65 79 20 63 6f 6e 73 74 72 reign key constr
107b0 61 69 6e 74 20 69 73 20 61 6e 20 69 6e 73 74 61 aint is an insta
107c0 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
107d0 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e 0a wing structure..
107e0 2a 2a 0a 2a 2a 20 41 20 66 6f 72 65 69 67 6e 20 **.** A foreign
107f0 6b 65 79 20 69 73 20 61 73 73 6f 63 69 61 74 65 key is associate
10800 64 20 77 69 74 68 20 74 77 6f 20 74 61 62 6c 65 d with two table
10810 73 2e 20 20 54 68 65 20 22 66 72 6f 6d 22 20 74 s. The "from" t
10820 61 62 6c 65 20 69 73 0a 2a 2a 20 74 68 65 20 74 able is.** the t
10830 61 62 6c 65 20 74 68 61 74 20 63 6f 6e 74 61 69 able that contai
10840 6e 73 20 74 68 65 20 52 45 46 45 52 45 4e 43 45 ns the REFERENCE
10850 53 20 63 6c 61 75 73 65 20 74 68 61 74 20 63 72 S clause that cr
10860 65 61 74 65 73 20 74 68 65 20 66 6f 72 65 69 67 eates the foreig
10870 6e 0a 2a 2a 20 6b 65 79 2e 20 20 54 68 65 20 22 n.** key. The "
10880 74 6f 22 20 74 61 62 6c 65 20 69 73 20 74 68 65 to" table is the
10890 20 74 61 62 6c 65 20 74 68 61 74 20 69 73 20 6e table that is n
108a0 61 6d 65 64 20 69 6e 20 74 68 65 20 52 45 46 45 amed in the REFE
108b0 52 45 4e 43 45 53 20 63 6c 61 75 73 65 2e 0a 2a RENCES clause..*
108c0 2a 20 43 6f 6e 73 69 64 65 72 20 74 68 69 73 20 * Consider this
108d0 65 78 61 6d 70 6c 65 3a 0a 2a 2a 0a 2a 2a 20 20 example:.**.**
108e0 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 CREATE TABLE
108f0 65 78 31 28 0a 2a 2a 20 20 20 20 20 20 20 61 20 ex1(.** a
10900 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
10910 4b 45 59 2c 0a 2a 2a 20 20 20 20 20 20 20 62 20 KEY,.** b
10920 49 4e 54 45 47 45 52 20 43 4f 4e 53 54 52 41 49 INTEGER CONSTRAI
10930 4e 54 20 66 6b 31 20 52 45 46 45 52 45 4e 43 45 NT fk1 REFERENCE
10940 53 20 65 78 32 28 78 29 0a 2a 2a 20 20 20 20 20 S ex2(x).**
10950 29 3b 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 66 6f 72 );.**.** For for
10960 65 69 67 6e 20 6b 65 79 20 22 66 6b 31 22 2c 20 eign key "fk1",
10970 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 20 69 the from-table i
10980 73 20 22 65 78 31 22 20 61 6e 64 20 74 68 65 20 s "ex1" and the
10990 74 6f 2d 74 61 62 6c 65 20 69 73 20 22 65 78 32 to-table is "ex2
109a0 22 2e 0a 2a 2a 20 45 71 75 69 76 61 6c 65 6e 74 "..** Equivalent
109b0 20 6e 61 6d 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 names:.**.**
109c0 20 20 66 72 6f 6d 2d 74 61 62 6c 65 20 3d 3d 20 from-table ==
109d0 63 68 69 6c 64 2d 74 61 62 6c 65 0a 2a 2a 20 20 child-table.**
109e0 20 20 20 20 20 74 6f 2d 74 61 62 6c 65 20 3d 3d to-table ==
109f0 20 70 61 72 65 6e 74 2d 74 61 62 6c 65 0a 2a 2a parent-table.**
10a00 0a 2a 2a 20 45 61 63 68 20 52 45 46 45 52 45 4e .** Each REFEREN
10a10 43 45 53 20 63 6c 61 75 73 65 20 67 65 6e 65 72 CES clause gener
10a20 61 74 65 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 ates an instance
10a30 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
10a40 67 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 77 g structure.** w
10a50 68 69 63 68 20 69 73 20 61 74 74 61 63 68 65 64 hich is attached
10a60 20 74 6f 20 74 68 65 20 66 72 6f 6d 2d 74 61 62 to the from-tab
10a70 6c 65 2e 20 20 54 68 65 20 74 6f 2d 74 61 62 6c le. The to-tabl
10a80 65 20 6e 65 65 64 20 6e 6f 74 20 65 78 69 73 74 e need not exist
10a90 20 77 68 65 6e 0a 2a 2a 20 74 68 65 20 66 72 6f when.** the fro
10aa0 6d 2d 74 61 62 6c 65 20 69 73 20 63 72 65 61 74 m-table is creat
10ab0 65 64 2e 20 20 54 68 65 20 65 78 69 73 74 65 6e ed. The existen
10ac0 63 65 20 6f 66 20 74 68 65 20 74 6f 2d 74 61 62 ce of the to-tab
10ad0 6c 65 20 69 73 20 6e 6f 74 20 63 68 65 63 6b 65 le is not checke
10ae0 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6c 69 73 d..**.** The lis
10af0 74 20 6f 66 20 61 6c 6c 20 70 61 72 65 6e 74 73 t of all parents
10b00 20 66 6f 72 20 63 68 69 6c 64 20 54 61 62 6c 65 for child Table
10b10 20 58 20 69 73 20 68 65 6c 64 20 61 74 20 58 2e X is held at X.
10b20 70 46 4b 65 79 2e 0a 2a 2a 0a 2a 2a 20 41 20 6c pFKey..**.** A l
10b30 69 73 74 20 6f 66 20 61 6c 6c 20 63 68 69 6c 64 ist of all child
10b40 72 65 6e 20 66 6f 72 20 61 20 74 61 62 6c 65 20 ren for a table
10b50 6e 61 6d 65 64 20 5a 20 28 77 68 69 63 68 20 6d named Z (which m
10b60 69 67 68 74 20 6e 6f 74 20 65 76 65 6e 20 65 78 ight not even ex
10b70 69 73 74 29 0a 2a 2a 20 69 73 20 68 65 6c 64 20 ist).** is held
10b80 69 6e 20 53 63 68 65 6d 61 2e 66 6b 65 79 48 61 in Schema.fkeyHa
10b90 73 68 20 77 69 74 68 20 61 20 68 61 73 68 20 6b sh with a hash k
10ba0 65 79 20 6f 66 20 5a 2e 0a 2a 2f 0a 73 74 72 75 ey of Z..*/.stru
10bb0 63 74 20 46 4b 65 79 20 7b 0a 20 20 54 61 62 6c ct FKey {. Tabl
10bc0 65 20 2a 70 46 72 6f 6d 3b 20 20 20 20 20 2f 2a e *pFrom; /*
10bd0 20 54 61 62 6c 65 20 63 6f 6e 74 61 69 6e 69 6e Table containin
10be0 67 20 74 68 65 20 52 45 46 45 52 45 4e 43 45 53 g the REFERENCES
10bf0 20 63 6c 61 75 73 65 20 28 61 6b 61 3a 20 43 68 clause (aka: Ch
10c00 69 6c 64 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a ild) */. FKey *
10c10 70 4e 65 78 74 46 72 6f 6d 3b 20 20 2f 2a 20 4e pNextFrom; /* N
10c20 65 78 74 20 46 4b 65 79 20 77 69 74 68 20 74 68 ext FKey with th
10c30 65 20 73 61 6d 65 20 69 6e 20 70 46 72 6f 6d 2e e same in pFrom.
10c40 20 4e 65 78 74 20 70 61 72 65 6e 74 20 6f 66 20 Next parent of
10c50 70 46 72 6f 6d 20 2a 2f 0a 20 20 63 68 61 72 20 pFrom */. char
10c60 2a 7a 54 6f 3b 20 20 20 20 20 20 20 20 2f 2a 20 *zTo; /*
10c70 4e 61 6d 65 20 6f 66 20 74 61 62 6c 65 20 74 68 Name of table th
10c80 61 74 20 74 68 65 20 6b 65 79 20 70 6f 69 6e 74 at the key point
10c90 73 20 74 6f 20 28 61 6b 61 3a 20 50 61 72 65 6e s to (aka: Paren
10ca0 74 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e t) */. FKey *pN
10cb0 65 78 74 54 6f 3b 20 20 20 20 2f 2a 20 4e 65 78 extTo; /* Nex
10cc0 74 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 t with the same
10cd0 7a 54 6f 2e 20 4e 65 78 74 20 63 68 69 6c 64 20 zTo. Next child
10ce0 6f 66 20 7a 54 6f 2e 20 2a 2f 0a 20 20 46 4b 65 of zTo. */. FKe
10cf0 79 20 2a 70 50 72 65 76 54 6f 3b 20 20 20 20 2f y *pPrevTo; /
10d00 2a 20 50 72 65 76 69 6f 75 73 20 77 69 74 68 20 * Previous with
10d10 74 68 65 20 73 61 6d 65 20 7a 54 6f 20 2a 2f 0a the same zTo */.
10d20 20 20 69 6e 74 20 6e 43 6f 6c 3b 20 20 20 20 20 int nCol;
10d30 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
10d40 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 columns in this
10d50 20 6b 65 79 20 2a 2f 0a 20 20 2f 2a 20 45 56 3a key */. /* EV:
10d60 20 52 2d 33 30 33 32 33 2d 32 31 39 31 37 20 2a R-30323-21917 *
10d70 2f 0a 20 20 75 38 20 69 73 44 65 66 65 72 72 65 /. u8 isDeferre
10d80 64 3b 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 d; /* True
10d90 20 69 66 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 if constraint c
10da0 68 65 63 6b 69 6e 67 20 69 73 20 64 65 66 65 72 hecking is defer
10db0 72 65 64 20 74 69 6c 6c 20 43 4f 4d 4d 49 54 20 red till COMMIT
10dc0 2a 2f 0a 20 20 75 38 20 61 41 63 74 69 6f 6e 5b */. u8 aAction[
10dd0 32 5d 3b 20 20 20 20 20 20 20 20 2f 2a 20 4f 4e 2]; /* ON
10de0 20 44 45 4c 45 54 45 20 61 6e 64 20 4f 4e 20 55 DELETE and ON U
10df0 50 44 41 54 45 20 61 63 74 69 6f 6e 73 2c 20 72 PDATE actions, r
10e00 65 73 70 65 63 74 69 76 65 6c 79 20 2a 2f 0a 20 espectively */.
10e10 20 54 72 69 67 67 65 72 20 2a 61 70 54 72 69 67 Trigger *apTrig
10e20 67 65 72 5b 32 5d 3b 2f 2a 20 54 72 69 67 67 65 ger[2];/* Trigge
10e30 72 73 20 66 6f 72 20 61 41 63 74 69 6f 6e 5b 5d rs for aAction[]
10e40 20 61 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 actions */. st
10e50 72 75 63 74 20 73 43 6f 6c 4d 61 70 20 7b 20 20 ruct sColMap {
10e60 20 20 20 20 2f 2a 20 4d 61 70 70 69 6e 67 20 6f /* Mapping o
10e70 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 70 46 72 f columns in pFr
10e80 6f 6d 20 74 6f 20 63 6f 6c 75 6d 6e 73 20 69 6e om to columns in
10e90 20 7a 54 6f 20 2a 2f 0a 20 20 20 20 69 6e 74 20 zTo */. int
10ea0 69 46 72 6f 6d 3b 20 20 20 20 20 20 20 20 20 20 iFrom;
10eb0 20 20 2f 2a 20 49 6e 64 65 78 20 6f 66 20 63 6f /* Index of co
10ec0 6c 75 6d 6e 20 69 6e 20 70 46 72 6f 6d 20 2a 2f lumn in pFrom */
10ed0 0a 20 20 20 20 63 68 61 72 20 2a 7a 43 6f 6c 3b . char *zCol;
10ee0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 /* Na
10ef0 6d 65 20 6f 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 me of column in
10f00 7a 54 6f 2e 20 20 49 66 20 4e 55 4c 4c 20 75 73 zTo. If NULL us
10f10 65 20 50 52 49 4d 41 52 59 20 4b 45 59 20 2a 2f e PRIMARY KEY */
10f20 0a 20 20 7d 20 61 43 6f 6c 5b 31 5d 3b 20 20 20 . } aCol[1];
10f30 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 /* One
10f40 65 6e 74 72 79 20 66 6f 72 20 65 61 63 68 20 6f entry for each o
10f50 66 20 6e 43 6f 6c 20 63 6f 6c 75 6d 6e 73 20 2a f nCol columns *
10f60 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 69 /.};../*.** SQLi
10f70 74 65 20 73 75 70 70 6f 72 74 73 20 6d 61 6e 79 te supports many
10f80 20 64 69 66 66 65 72 65 6e 74 20 77 61 79 73 20 different ways
10f90 74 6f 20 72 65 73 6f 6c 76 65 20 61 20 63 6f 6e to resolve a con
10fa0 73 74 72 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 straint.** error
10fb0 2e 20 20 52 4f 4c 4c 42 41 43 4b 20 70 72 6f 63 . ROLLBACK proc
10fc0 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 61 essing means tha
10fd0 74 20 61 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 t a constraint v
10fe0 69 6f 6c 61 74 69 6f 6e 0a 2a 2a 20 63 61 75 73 iolation.** caus
10ff0 65 73 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e es the operation
11000 20 69 6e 20 70 72 6f 63 65 73 73 20 74 6f 20 66 in process to f
11010 61 69 6c 20 61 6e 64 20 66 6f 72 20 74 68 65 20 ail and for the
11020 63 75 72 72 65 6e 74 20 74 72 61 6e 73 61 63 74 current transact
11030 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 72 6f 6c ion.** to be rol
11040 6c 65 64 20 62 61 63 6b 2e 20 20 41 42 4f 52 54 led back. ABORT
11050 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e processing mean
11060 73 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 s the operation
11070 69 6e 20 70 72 6f 63 65 73 73 0a 2a 2a 20 66 61 in process.** fa
11080 69 6c 73 20 61 6e 64 20 61 6e 79 20 70 72 69 6f ils and any prio
11090 72 20 63 68 61 6e 67 65 73 20 66 72 6f 6d 20 74 r changes from t
110a0 68 61 74 20 6f 6e 65 20 6f 70 65 72 61 74 69 6f hat one operatio
110b0 6e 20 61 72 65 20 62 61 63 6b 65 64 20 6f 75 74 n are backed out
110c0 2c 0a 2a 2a 20 62 75 74 20 74 68 65 20 74 72 61 ,.** but the tra
110d0 6e 73 61 63 74 69 6f 6e 20 69 73 20 6e 6f 74 20 nsaction is not
110e0 72 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 46 41 rolled back. FA
110f0 49 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 IL processing me
11100 61 6e 73 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 ans that.** the
11110 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 72 6f operation in pro
11120 67 72 65 73 73 20 73 74 6f 70 73 20 61 6e 64 20 gress stops and
11130 72 65 74 75 72 6e 73 20 61 6e 20 65 72 72 6f 72 returns an error
11140 20 63 6f 64 65 2e 20 20 42 75 74 20 70 72 69 6f code. But prio
11150 72 0a 2a 2a 20 63 68 61 6e 67 65 73 20 64 75 65 r.** changes due
11160 20 74 6f 20 74 68 65 20 73 61 6d 65 20 6f 70 65 to the same ope
11170 72 61 74 69 6f 6e 20 61 72 65 20 6e 6f 74 20 62 ration are not b
11180 61 63 6b 65 64 20 6f 75 74 20 61 6e 64 20 6e 6f acked out and no
11190 20 72 6f 6c 6c 62 61 63 6b 0a 2a 2a 20 6f 63 63 rollback.** occ
111a0 75 72 73 2e 20 20 49 47 4e 4f 52 45 20 6d 65 61 urs. IGNORE mea
111b0 6e 73 20 74 68 61 74 20 74 68 65 20 70 61 72 74 ns that the part
111c0 69 63 75 6c 61 72 20 72 6f 77 20 74 68 61 74 20 icular row that
111d0 63 61 75 73 65 64 20 74 68 65 20 63 6f 6e 73 74 caused the const
111e0 72 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 20 69 raint.** error i
111f0 73 20 6e 6f 74 20 69 6e 73 65 72 74 65 64 20 6f s not inserted o
11200 72 20 75 70 64 61 74 65 64 2e 20 20 50 72 6f 63 r updated. Proc
11210 65 73 73 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 essing continues
11220 20 61 6e 64 20 6e 6f 20 65 72 72 6f 72 0a 2a 2a and no error.**
11230 20 69 73 20 72 65 74 75 72 6e 65 64 2e 20 20 52 is returned. R
11240 45 50 4c 41 43 45 20 6d 65 61 6e 73 20 74 68 61 EPLACE means tha
11250 74 20 70 72 65 65 78 69 73 74 69 6e 67 20 64 61 t preexisting da
11260 74 61 62 61 73 65 20 72 6f 77 73 20 74 68 61 74 tabase rows that
11270 20 63 61 75 73 65 64 0a 2a 2a 20 61 20 55 4e 49 caused.** a UNI
11280 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 QUE constraint v
11290 69 6f 6c 61 74 69 6f 6e 20 61 72 65 20 72 65 6d iolation are rem
112a0 6f 76 65 64 20 73 6f 20 74 68 61 74 20 74 68 65 oved so that the
112b0 20 6e 65 77 20 69 6e 73 65 72 74 20 6f 72 0a 2a new insert or.*
112c0 2a 20 75 70 64 61 74 65 20 63 61 6e 20 70 72 6f * update can pro
112d0 63 65 65 64 2e 20 20 50 72 6f 63 65 73 73 69 6e ceed. Processin
112e0 67 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e 64 20 g continues and
112f0 6e 6f 20 65 72 72 6f 72 20 69 73 20 72 65 70 6f no error is repo
11300 72 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 52 45 53 54 rted..**.** REST
11310 52 49 43 54 2c 20 53 45 54 4e 55 4c 4c 2c 20 61 RICT, SETNULL, a
11320 6e 64 20 43 41 53 43 41 44 45 20 61 63 74 69 6f nd CASCADE actio
11330 6e 73 20 61 70 70 6c 79 20 6f 6e 6c 79 20 74 6f ns apply only to
11340 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 2e 0a 2a foreign keys..*
11350 2a 20 52 45 53 54 52 49 43 54 20 69 73 20 74 68 * RESTRICT is th
11360 65 20 73 61 6d 65 20 61 73 20 41 42 4f 52 54 20 e same as ABORT
11370 66 6f 72 20 49 4d 4d 45 44 49 41 54 45 20 66 6f for IMMEDIATE fo
11380 72 65 69 67 6e 20 6b 65 79 73 20 61 6e 64 20 74 reign keys and t
11390 68 65 0a 2a 2a 20 73 61 6d 65 20 61 73 20 52 4f he.** same as RO
113a0 4c 4c 42 41 43 4b 20 66 6f 72 20 44 45 46 45 52 LLBACK for DEFER
113b0 52 45 44 20 6b 65 79 73 2e 20 20 53 45 54 4e 55 RED keys. SETNU
113c0 4c 4c 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 LL means that th
113d0 65 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 e foreign.** key
113e0 20 69 73 20 73 65 74 20 74 6f 20 4e 55 4c 4c 2e is set to NULL.
113f0 20 20 43 41 53 43 41 44 45 20 6d 65 61 6e 73 20 CASCADE means
11400 74 68 61 74 20 61 20 44 45 4c 45 54 45 20 6f 72 that a DELETE or
11410 20 55 50 44 41 54 45 20 6f 66 20 74 68 65 0a 2a UPDATE of the.*
11420 2a 20 72 65 66 65 72 65 6e 63 65 64 20 74 61 62 * referenced tab
11430 6c 65 20 72 6f 77 20 69 73 20 70 72 6f 70 61 67 le row is propag
11440 61 74 65 64 20 69 6e 74 6f 20 74 68 65 20 72 6f ated into the ro
11450 77 20 74 68 61 74 20 68 6f 6c 64 73 20 74 68 65 w that holds the
11460 0a 2a 2a 20 66 6f 72 65 69 67 6e 20 6b 65 79 2e .** foreign key.
11470 0a 2a 2a 20 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c .** .** The foll
11480 6f 77 69 6e 67 20 73 79 6d 62 6f 6c 69 63 20 76 owing symbolic v
11490 61 6c 75 65 73 20 61 72 65 20 75 73 65 64 20 74 alues are used t
114a0 6f 20 72 65 63 6f 72 64 20 77 68 69 63 68 20 74 o record which t
114b0 79 70 65 0a 2a 2a 20 6f 66 20 61 63 74 69 6f 6e ype.** of action
114c0 20 74 6f 20 74 61 6b 65 2e 0a 2a 2f 0a 23 64 65 to take..*/.#de
114d0 66 69 6e 65 20 4f 45 5f 4e 6f 6e 65 20 20 20 20 fine OE_None
114e0 20 30 20 20 20 2f 2a 20 54 68 65 72 65 20 69 73 0 /* There is
114f0 20 6e 6f 20 63 6f 6e 73 74 72 61 69 6e 74 20 74 no constraint t
11500 6f 20 63 68 65 63 6b 20 2a 2f 0a 23 64 65 66 69 o check */.#defi
11510 6e 65 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 31 ne OE_Rollback 1
11520 20 20 20 2f 2a 20 46 61 69 6c 20 74 68 65 20 6f /* Fail the o
11530 70 65 72 61 74 69 6f 6e 20 61 6e 64 20 72 6f 6c peration and rol
11540 6c 62 61 63 6b 20 74 68 65 20 74 72 61 6e 73 61 lback the transa
11550 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 ction */.#define
11560 20 4f 45 5f 41 62 6f 72 74 20 20 20 20 32 20 20 OE_Abort 2
11570 20 2f 2a 20 42 61 63 6b 20 6f 75 74 20 63 68 61 /* Back out cha
11580 6e 67 65 73 20 62 75 74 20 64 6f 20 6e 6f 20 72 nges but do no r
11590 6f 6c 6c 62 61 63 6b 20 74 72 61 6e 73 61 63 74 ollback transact
115a0 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ion */.#define O
115b0 45 5f 46 61 69 6c 20 20 20 20 20 33 20 20 20 2f E_Fail 3 /
115c0 2a 20 53 74 6f 70 20 74 68 65 20 6f 70 65 72 61 * Stop the opera
115d0 74 69 6f 6e 20 62 75 74 20 6c 65 61 76 65 20 61 tion but leave a
115e0 6c 6c 20 70 72 69 6f 72 20 63 68 61 6e 67 65 73 ll prior changes
115f0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 49 */.#define OE_I
11600 67 6e 6f 72 65 20 20 20 34 20 20 20 2f 2a 20 49 gnore 4 /* I
11610 67 6e 6f 72 65 20 74 68 65 20 65 72 72 6f 72 2e gnore the error.
11620 20 44 6f 20 6e 6f 74 20 64 6f 20 74 68 65 20 49 Do not do the I
11630 4e 53 45 52 54 20 6f 72 20 55 50 44 41 54 45 20 NSERT or UPDATE
11640 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 65 */.#define OE_Re
11650 70 6c 61 63 65 20 20 35 20 20 20 2f 2a 20 44 65 place 5 /* De
11660 6c 65 74 65 20 65 78 69 73 74 69 6e 67 20 72 65 lete existing re
11670 63 6f 72 64 2c 20 74 68 65 6e 20 64 6f 20 49 4e cord, then do IN
11680 53 45 52 54 20 6f 72 20 55 50 44 41 54 45 20 2a SERT or UPDATE *
11690 2f 0a 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 65 /..#define OE_Re
116a0 73 74 72 69 63 74 20 36 20 20 20 2f 2a 20 4f 45 strict 6 /* OE
116b0 5f 41 62 6f 72 74 20 66 6f 72 20 49 4d 4d 45 44 _Abort for IMMED
116c0 49 41 54 45 2c 20 4f 45 5f 52 6f 6c 6c 62 61 63 IATE, OE_Rollbac
116d0 6b 20 66 6f 72 20 44 45 46 45 52 52 45 44 20 2a k for DEFERRED *
116e0 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 /.#define OE_Set
116f0 4e 75 6c 6c 20 20 37 20 20 20 2f 2a 20 53 65 74 Null 7 /* Set
11700 20 74 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 the foreign key
11710 20 76 61 6c 75 65 20 74 6f 20 4e 55 4c 4c 20 2a value to NULL *
11720 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 /.#define OE_Set
11730 44 66 6c 74 20 20 38 20 20 20 2f 2a 20 53 65 74 Dflt 8 /* Set
11740 20 74 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 the foreign key
11750 20 76 61 6c 75 65 20 74 6f 20 69 74 73 20 64 65 value to its de
11760 66 61 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 fault */.#define
11770 20 4f 45 5f 43 61 73 63 61 64 65 20 20 39 20 20 OE_Cascade 9
11780 20 2f 2a 20 43 61 73 63 61 64 65 20 74 68 65 20 /* Cascade the
11790 63 68 61 6e 67 65 73 20 2a 2f 0a 0a 23 64 65 66 changes */..#def
117a0 69 6e 65 20 4f 45 5f 44 65 66 61 75 6c 74 20 20 ine OE_Default
117b0 31 30 20 20 2f 2a 20 44 6f 20 77 68 61 74 65 76 10 /* Do whatev
117c0 65 72 20 74 68 65 20 64 65 66 61 75 6c 74 20 61 er the default a
117d0 63 74 69 6f 6e 20 69 73 20 2a 2f 0a 0a 0a 2f 2a ction is */.../*
117e0 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
117f0 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
11800 20 73 74 72 75 63 74 75 72 65 20 69 73 20 70 61 structure is pa
11810 73 73 65 64 20 61 73 20 74 68 65 20 66 69 72 73 ssed as the firs
11820 74 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 74 6f t.** argument to
11830 20 73 71 6c 69 74 65 33 56 64 62 65 4b 65 79 43 sqlite3VdbeKeyC
11840 6f 6d 70 61 72 65 20 61 6e 64 20 69 73 20 75 73 ompare and is us
11850 65 64 20 74 6f 20 63 6f 6e 74 72 6f 6c 20 74 68 ed to control th
11860 65 20 0a 2a 2a 20 63 6f 6d 70 61 72 69 73 6f 6e e .** comparison
11870 20 6f 66 20 74 68 65 20 74 77 6f 20 69 6e 64 65 of the two inde
11880 78 20 6b 65 79 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f x keys..**.** No
11890 74 65 20 74 68 61 74 20 61 53 6f 72 74 4f 72 64 te that aSortOrd
118a0 65 72 5b 5d 20 61 6e 64 20 61 43 6f 6c 6c 5b 5d er[] and aColl[]
118b0 20 68 61 76 65 20 6e 46 69 65 6c 64 2b 31 20 73 have nField+1 s
118c0 6c 6f 74 73 2e 20 20 54 68 65 72 65 0a 2a 2a 20 lots. There.**
118d0 61 72 65 20 6e 46 69 65 6c 64 20 73 6c 6f 74 73 are nField slots
118e0 20 66 6f 72 20 74 68 65 20 63 6f 6c 75 6d 6e 73 for the columns
118f0 20 6f 66 20 61 6e 20 69 6e 64 65 78 20 74 68 65 of an index the
11900 6e 20 6f 6e 65 20 65 78 74 72 61 20 73 6c 6f 74 n one extra slot
11910 0a 2a 2a 20 66 6f 72 20 74 68 65 20 72 6f 77 69 .** for the rowi
11920 64 20 61 74 20 74 68 65 20 65 6e 64 2e 0a 2a 2f d at the end..*/
11930 0a 73 74 72 75 63 74 20 4b 65 79 49 6e 66 6f 20 .struct KeyInfo
11940 7b 0a 20 20 75 33 32 20 6e 52 65 66 3b 20 20 20 {. u32 nRef;
11950 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
11960 72 20 6f 66 20 72 65 66 65 72 65 6e 63 65 73 20 r of references
11970 74 6f 20 74 68 69 73 20 4b 65 79 49 6e 66 6f 20 to this KeyInfo
11980 6f 62 6a 65 63 74 20 2a 2f 0a 20 20 75 38 20 65 object */. u8 e
11990 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
119a0 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 /* Text encoding
119b0 20 2d 20 6f 6e 65 20 6f 66 20 74 68 65 20 53 51 - one of the SQ
119c0 4c 49 54 45 5f 55 54 46 2a 20 76 61 6c 75 65 73 LITE_UTF* values
119d0 20 2a 2f 0a 20 20 75 31 36 20 6e 46 69 65 6c 64 */. u16 nField
119e0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d ; /* Num
119f0 62 65 72 20 6f 66 20 6b 65 79 20 63 6f 6c 75 6d ber of key colum
11a00 6e 73 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 ns in the index
11a10 2a 2f 0a 20 20 75 31 36 20 6e 58 46 69 65 6c 64 */. u16 nXField
11a20 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 ; /* Numb
11a30 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 62 65 er of columns be
11a40 79 6f 6e 64 20 74 68 65 20 6b 65 79 20 63 6f 6c yond the key col
11a50 75 6d 6e 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 umns */. sqlite
11a60 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 3 *db; /*
11a70 20 54 68 65 20 64 61 74 61 62 61 73 65 20 63 6f The database co
11a80 6e 6e 65 63 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 nnection */. u8
11a90 20 2a 61 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 *aSortOrder;
11aa0 20 20 2f 2a 20 53 6f 72 74 20 6f 72 64 65 72 20 /* Sort order
11ab0 66 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 2e for each column.
11ac0 20 2a 2f 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 61 */. CollSeq *a
11ad0 43 6f 6c 6c 5b 31 5d 3b 20 20 2f 2a 20 43 6f 6c Coll[1]; /* Col
11ae0 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 lating sequence
11af0 66 6f 72 20 65 61 63 68 20 74 65 72 6d 20 6f 66 for each term of
11b00 20 74 68 65 20 6b 65 79 20 2a 2f 0a 7d 3b 0a 0a the key */.};..
11b10 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
11b20 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
11b30 6e 67 20 73 74 72 75 63 74 75 72 65 20 68 6f 6c ng structure hol
11b40 64 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 ds information a
11b50 62 6f 75 74 20 61 0a 2a 2a 20 73 69 6e 67 6c 65 bout a.** single
11b60 20 69 6e 64 65 78 20 72 65 63 6f 72 64 20 74 68 index record th
11b70 61 74 20 68 61 73 20 61 6c 72 65 61 64 79 20 62 at has already b
11b80 65 65 6e 20 70 61 72 73 65 64 20 6f 75 74 20 69 een parsed out i
11b90 6e 74 6f 20 69 6e 64 69 76 69 64 75 61 6c 0a 2a nto individual.*
11ba0 2a 20 76 61 6c 75 65 73 2e 0a 2a 2a 0a 2a 2a 20 * values..**.**
11bb0 41 20 72 65 63 6f 72 64 20 69 73 20 61 6e 20 6f A record is an o
11bc0 62 6a 65 63 74 20 74 68 61 74 20 63 6f 6e 74 61 bject that conta
11bd0 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 ins one or more
11be0 66 69 65 6c 64 73 20 6f 66 20 64 61 74 61 2e 0a fields of data..
11bf0 2a 2a 20 52 65 63 6f 72 64 73 20 61 72 65 20 75 ** Records are u
11c00 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 sed to store the
11c10 20 63 6f 6e 74 65 6e 74 20 6f 66 20 61 20 74 61 content of a ta
11c20 62 6c 65 20 72 6f 77 20 61 6e 64 20 74 6f 20 73 ble row and to s
11c30 74 6f 72 65 0a 2a 2a 20 74 68 65 20 6b 65 79 20 tore.** the key
11c40 6f 66 20 61 6e 20 69 6e 64 65 78 2e 20 20 41 20 of an index. A
11c50 62 6c 6f 62 20 65 6e 63 6f 64 69 6e 67 20 6f 66 blob encoding of
11c60 20 61 20 72 65 63 6f 72 64 20 69 73 20 63 72 65 a record is cre
11c70 61 74 65 64 20 62 79 0a 2a 2a 20 74 68 65 20 4f ated by.** the O
11c80 50 5f 4d 61 6b 65 52 65 63 6f 72 64 20 6f 70 63 P_MakeRecord opc
11c90 6f 64 65 20 6f 66 20 74 68 65 20 56 44 42 45 20 ode of the VDBE
11ca0 61 6e 64 20 69 73 20 64 69 73 61 73 73 65 6d 62 and is disassemb
11cb0 6c 65 64 20 62 79 20 74 68 65 0a 2a 2a 20 4f 50 led by the.** OP
11cc0 5f 43 6f 6c 75 6d 6e 20 6f 70 63 6f 64 65 2e 0a _Column opcode..
11cd0 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 **.** This struc
11ce0 74 75 72 65 20 68 6f 6c 64 73 20 61 20 72 65 63 ture holds a rec
11cf0 6f 72 64 20 74 68 61 74 20 68 61 73 20 61 6c 72 ord that has alr
11d00 65 61 64 79 20 62 65 65 6e 20 64 69 73 61 73 73 eady been disass
11d10 65 6d 62 6c 65 64 0a 2a 2a 20 69 6e 74 6f 20 69 embled.** into i
11d20 74 73 20 63 6f 6e 73 74 69 74 75 65 6e 74 20 66 ts constituent f
11d30 69 65 6c 64 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 ields..**.** The
11d40 20 72 31 20 61 6e 64 20 72 32 20 6d 65 6d 62 65 r1 and r2 membe
11d50 72 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 r variables are
11d60 6f 6e 6c 79 20 75 73 65 64 20 62 79 20 74 68 65 only used by the
11d70 20 6f 70 74 69 6d 69 7a 65 64 20 63 6f 6d 70 61 optimized compa
11d80 72 69 73 6f 6e 0a 2a 2a 20 66 75 6e 63 74 69 6f rison.** functio
11d90 6e 73 20 76 64 62 65 52 65 63 6f 72 64 43 6f 6d ns vdbeRecordCom
11da0 70 61 72 65 49 6e 74 28 29 20 61 6e 64 20 76 64 pareInt() and vd
11db0 62 65 52 65 63 6f 72 64 43 6f 6d 70 61 72 65 53 beRecordCompareS
11dc0 74 72 69 6e 67 28 29 2e 0a 2a 2f 0a 73 74 72 75 tring()..*/.stru
11dd0 63 74 20 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 ct UnpackedRecor
11de0 64 20 7b 0a 20 20 4b 65 79 49 6e 66 6f 20 2a 70 d {. KeyInfo *p
11df0 4b 65 79 49 6e 66 6f 3b 20 20 2f 2a 20 43 6f 6c KeyInfo; /* Col
11e00 6c 61 74 69 6f 6e 20 61 6e 64 20 73 6f 72 74 2d lation and sort-
11e10 6f 72 64 65 72 20 69 6e 66 6f 72 6d 61 74 69 6f order informatio
11e20 6e 20 2a 2f 0a 20 20 75 31 36 20 6e 46 69 65 6c n */. u16 nFiel
11e30 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 d; /* Nu
11e40 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 mber of entries
11e50 69 6e 20 61 70 4d 65 6d 5b 5d 20 2a 2f 0a 20 20 in apMem[] */.
11e60 69 38 20 64 65 66 61 75 6c 74 5f 72 63 3b 20 20 i8 default_rc;
11e70 20 20 20 20 2f 2a 20 43 6f 6d 70 61 72 69 73 6f /* Compariso
11e80 6e 20 72 65 73 75 6c 74 20 69 66 20 6b 65 79 73 n result if keys
11e90 20 61 72 65 20 65 71 75 61 6c 20 2a 2f 0a 20 20 are equal */.
11ea0 75 38 20 65 72 72 43 6f 64 65 3b 20 20 20 20 20 u8 errCode;
11eb0 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 64 65 74 /* Error det
11ec0 65 63 74 65 64 20 62 79 20 78 52 65 63 6f 72 64 ected by xRecord
11ed0 43 6f 6d 70 61 72 65 20 28 43 4f 52 52 55 50 54 Compare (CORRUPT
11ee0 20 6f 72 20 4e 4f 4d 45 4d 29 20 2a 2f 0a 20 20 or NOMEM) */.
11ef0 4d 65 6d 20 2a 61 4d 65 6d 3b 20 20 20 20 20 20 Mem *aMem;
11f00 20 20 20 20 2f 2a 20 56 61 6c 75 65 73 20 2a 2f /* Values */
11f10 0a 20 20 69 6e 74 20 72 31 3b 20 20 20 20 20 20 . int r1;
11f20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 /* Value
11f30 74 6f 20 72 65 74 75 72 6e 20 69 66 20 28 6c 68 to return if (lh
11f40 73 20 3e 20 72 68 73 29 20 2a 2f 0a 20 20 69 6e s > rhs) */. in
11f50 74 20 72 32 3b 20 20 20 20 20 20 20 20 20 20 20 t r2;
11f60 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 65 /* Value to re
11f70 74 75 72 6e 20 69 66 20 28 72 68 73 20 3c 20 6c turn if (rhs < l
11f80 68 73 29 20 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a hs) */.};.../*.*
11f90 2a 20 45 61 63 68 20 53 51 4c 20 69 6e 64 65 78 * Each SQL index
11fa0 20 69 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 is represented
11fb0 69 6e 20 6d 65 6d 6f 72 79 20 62 79 20 61 6e 0a in memory by an.
11fc0 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 ** instance of t
11fd0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
11fe0 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 ucture..**.** Th
11ff0 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 74 68 65 e columns of the
12000 20 74 61 62 6c 65 20 74 68 61 74 20 61 72 65 20 table that are
12010 74 6f 20 62 65 20 69 6e 64 65 78 65 64 20 61 72 to be indexed ar
12020 65 20 64 65 73 63 72 69 62 65 64 0a 2a 2a 20 62 e described.** b
12030 79 20 74 68 65 20 61 69 43 6f 6c 75 6d 6e 5b 5d y the aiColumn[]
12040 20 66 69 65 6c 64 20 6f 66 20 74 68 69 73 20 73 field of this s
12050 74 72 75 63 74 75 72 65 2e 20 20 46 6f 72 20 65 tructure. For e
12060 78 61 6d 70 6c 65 2c 20 73 75 70 70 6f 73 65 0a xample, suppose.
12070 2a 2a 20 77 65 20 68 61 76 65 20 74 68 65 20 66 ** we have the f
12080 6f 6c 6c 6f 77 69 6e 67 20 74 61 62 6c 65 20 61 ollowing table a
12090 6e 64 20 69 6e 64 65 78 3a 0a 2a 2a 0a 2a 2a 20 nd index:.**.**
120a0 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 CREATE TABLE
120b0 20 45 78 31 28 63 31 20 69 6e 74 2c 20 63 32 20 Ex1(c1 int, c2
120c0 69 6e 74 2c 20 63 33 20 74 65 78 74 29 3b 0a 2a int, c3 text);.*
120d0 2a 20 20 20 20 20 43 52 45 41 54 45 20 49 4e 44 * CREATE IND
120e0 45 58 20 45 78 32 20 4f 4e 20 45 78 31 28 63 33 EX Ex2 ON Ex1(c3
120f0 2c 63 31 29 3b 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 ,c1);.**.** In t
12100 68 65 20 54 61 62 6c 65 20 73 74 72 75 63 74 75 he Table structu
12110 72 65 20 64 65 73 63 72 69 62 69 6e 67 20 45 78 re describing Ex
12120 31 2c 20 6e 43 6f 6c 3d 3d 33 20 62 65 63 61 75 1, nCol==3 becau
12130 73 65 20 74 68 65 72 65 20 61 72 65 0a 2a 2a 20 se there are.**
12140 74 68 72 65 65 20 63 6f 6c 75 6d 6e 73 20 69 6e three columns in
12150 20 74 68 65 20 74 61 62 6c 65 2e 20 20 49 6e 20 the table. In
12160 74 68 65 20 49 6e 64 65 78 20 73 74 72 75 63 74 the Index struct
12170 75 72 65 20 64 65 73 63 72 69 62 69 6e 67 0a 2a ure describing.*
12180 2a 20 45 78 32 2c 20 6e 43 6f 6c 75 6d 6e 3d 3d * Ex2, nColumn==
12190 32 20 73 69 6e 63 65 20 32 20 6f 66 20 74 68 65 2 since 2 of the
121a0 20 33 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 45 78 3 columns of Ex
121b0 31 20 61 72 65 20 69 6e 64 65 78 65 64 2e 0a 2a 1 are indexed..*
121c0 2a 20 54 68 65 20 76 61 6c 75 65 20 6f 66 20 61 * The value of a
121d0 69 43 6f 6c 75 6d 6e 20 69 73 20 7b 32 2c 20 30 iColumn is {2, 0
121e0 7d 2e 20 20 61 69 43 6f 6c 75 6d 6e 5b 30 5d 3d }. aiColumn[0]=
121f0 3d 32 20 62 65 63 61 75 73 65 20 74 68 65 20 0a =2 because the .
12200 2a 2a 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 ** first column
12210 74 6f 20 62 65 20 69 6e 64 65 78 65 64 20 28 63 to be indexed (c
12220 33 29 20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 3) has an index
12230 6f 66 20 32 20 69 6e 20 45 78 31 2e 61 43 6f 6c of 2 in Ex1.aCol
12240 5b 5d 2e 0a 2a 2a 20 54 68 65 20 73 65 63 6f 6e []..** The secon
12250 64 20 63 6f 6c 75 6d 6e 20 74 6f 20 62 65 20 69 d column to be i
12260 6e 64 65 78 65 64 20 28 63 31 29 20 68 61 73 20 ndexed (c1) has
12270 61 6e 20 69 6e 64 65 78 20 6f 66 20 30 20 69 6e an index of 0 in
12280 0a 2a 2a 20 45 78 31 2e 61 43 6f 6c 5b 5d 2c 20 .** Ex1.aCol[],
12290 68 65 6e 63 65 20 45 78 32 2e 61 69 43 6f 6c 75 hence Ex2.aiColu
122a0 6d 6e 5b 31 5d 3d 3d 30 2e 0a 2a 2a 0a 2a 2a 20 mn[1]==0..**.**
122b0 54 68 65 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f The Index.onErro
122c0 72 20 66 69 65 6c 64 20 64 65 74 65 72 6d 69 6e r field determin
122d0 65 73 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f es whether or no
122e0 74 20 74 68 65 20 69 6e 64 65 78 65 64 20 63 6f t the indexed co
122f0 6c 75 6d 6e 73 0a 2a 2a 20 6d 75 73 74 20 62 65 lumns.** must be
12300 20 75 6e 69 71 75 65 20 61 6e 64 20 77 68 61 74 unique and what
12310 20 74 6f 20 64 6f 20 69 66 20 74 68 65 79 20 61 to do if they a
12320 72 65 20 6e 6f 74 2e 20 20 57 68 65 6e 20 49 6e re not. When In
12330 64 65 78 2e 6f 6e 45 72 72 6f 72 3d 4f 45 5f 4e dex.onError=OE_N
12340 6f 6e 65 2c 0a 2a 2a 20 69 74 20 6d 65 61 6e 73 one,.** it means
12350 20 74 68 69 73 20 69 73 20 6e 6f 74 20 61 20 75 this is not a u
12360 6e 69 71 75 65 20 69 6e 64 65 78 2e 20 20 4f 74 nique index. Ot
12370 68 65 72 77 69 73 65 20 69 74 20 69 73 20 61 20 herwise it is a
12380 75 6e 69 71 75 65 20 69 6e 64 65 78 0a 2a 2a 20 unique index.**
12390 61 6e 64 20 74 68 65 20 76 61 6c 75 65 20 6f 66 and the value of
123a0 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 69 Index.onError i
123b0 6e 64 69 63 61 74 65 20 74 68 65 20 77 68 69 63 ndicate the whic
123c0 68 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f 6c h conflict resol
123d0 75 74 69 6f 6e 20 0a 2a 2a 20 61 6c 67 6f 72 69 ution .** algori
123e0 74 68 6d 20 74 6f 20 65 6d 70 6c 6f 79 20 77 68 thm to employ wh
123f0 65 6e 65 76 65 72 20 61 6e 20 61 74 74 65 6d 70 enever an attemp
12400 74 20 69 73 20 6d 61 64 65 20 74 6f 20 69 6e 73 t is made to ins
12410 65 72 74 20 61 20 6e 6f 6e 2d 75 6e 69 71 75 65 ert a non-unique
12420 0a 2a 2a 20 65 6c 65 6d 65 6e 74 2e 0a 2a 2a 0a .** element..**.
12430 2a 2a 20 57 68 69 6c 65 20 70 61 72 73 69 6e 67 ** While parsing
12440 20 61 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 a CREATE TABLE
12450 6f 72 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 or CREATE INDEX
12460 73 74 61 74 65 6d 65 6e 74 20 69 6e 20 6f 72 64 statement in ord
12470 65 72 20 74 6f 0a 2a 2a 20 67 65 6e 65 72 61 74 er to.** generat
12480 65 20 56 44 42 45 20 63 6f 64 65 20 28 61 73 20 e VDBE code (as
12490 6f 70 70 6f 73 65 64 20 74 6f 20 70 61 72 73 69 opposed to parsi
124a0 6e 67 20 6f 6e 65 20 72 65 61 64 20 66 72 6f 6d ng one read from
124b0 20 61 6e 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 an sqlite_maste
124c0 72 0a 2a 2a 20 74 61 62 6c 65 20 61 73 20 70 61 r.** table as pa
124d0 72 74 20 6f 66 20 70 61 72 73 69 6e 67 20 61 6e rt of parsing an
124e0 20 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 existing databa
124f0 73 65 20 73 63 68 65 6d 61 29 2c 20 74 72 61 6e se schema), tran
12500 73 69 65 6e 74 20 69 6e 73 74 61 6e 63 65 73 0a sient instances.
12510 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ** of this struc
12520 74 75 72 65 20 6d 61 79 20 62 65 20 63 72 65 61 ture may be crea
12530 74 65 64 2e 20 49 6e 20 74 68 69 73 20 63 61 73 ted. In this cas
12540 65 20 74 68 65 20 49 6e 64 65 78 2e 74 6e 75 6d e the Index.tnum
12550 20 76 61 72 69 61 62 6c 65 20 69 73 0a 2a 2a 20 variable is.**
12560 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 used to store th
12570 65 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 56 e address of a V
12580 44 42 45 20 69 6e 73 74 72 75 63 74 69 6f 6e 2c DBE instruction,
12590 20 6e 6f 74 20 61 20 64 61 74 61 62 61 73 65 20 not a database
125a0 70 61 67 65 0a 2a 2a 20 6e 75 6d 62 65 72 20 28 page.** number (
125b0 69 74 20 63 61 6e 6e 6f 74 20 2d 20 74 68 65 20 it cannot - the
125c0 64 61 74 61 62 61 73 65 20 70 61 67 65 20 69 73 database page is
125d0 20 6e 6f 74 20 61 6c 6c 6f 63 61 74 65 64 20 75 not allocated u
125e0 6e 74 69 6c 20 74 68 65 20 56 44 42 45 0a 2a 2a ntil the VDBE.**
125f0 20 70 72 6f 67 72 61 6d 20 69 73 20 65 78 65 63 program is exec
12600 75 74 65 64 29 2e 20 53 65 65 20 63 6f 6e 76 65 uted). See conve
12610 72 74 54 6f 57 69 74 68 6f 75 74 52 6f 77 69 64 rtToWithoutRowid
12620 54 61 62 6c 65 28 29 20 66 6f 72 20 64 65 74 61 Table() for deta
12630 69 6c 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 ils..*/.struct I
12640 6e 64 65 78 20 7b 0a 20 20 63 68 61 72 20 2a 7a ndex {. char *z
12650 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 Name;
12660 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 /* Name of thi
12670 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 31 36 s index */. i16
12680 20 2a 61 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 *aiColumn;
12690 20 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 63 /* Which c
126a0 6f 6c 75 6d 6e 73 20 61 72 65 20 75 73 65 64 20 olumns are used
126b0 62 79 20 74 68 69 73 20 69 6e 64 65 78 2e 20 20 by this index.
126c0 31 73 74 20 69 73 20 30 20 2a 2f 0a 20 20 4c 6f 1st is 0 */. Lo
126d0 67 45 73 74 20 2a 61 69 52 6f 77 4c 6f 67 45 73 gEst *aiRowLogEs
126e0 74 3b 20 20 20 20 20 2f 2a 20 46 72 6f 6d 20 41 t; /* From A
126f0 4e 41 4c 59 5a 45 3a 20 45 73 74 2e 20 72 6f 77 NALYZE: Est. row
12700 73 20 73 65 6c 65 63 74 65 64 20 62 79 20 65 61 s selected by ea
12710 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 54 ch column */. T
12720 61 62 6c 65 20 2a 70 54 61 62 6c 65 3b 20 20 20 able *pTable;
12730 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 53 /* The S
12740 51 4c 20 74 61 62 6c 65 20 62 65 69 6e 67 20 69 QL table being i
12750 6e 64 65 78 65 64 20 2a 2f 0a 20 20 63 68 61 72 ndexed */. char
12760 20 2a 7a 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 *zColAff;
12770 20 20 20 20 20 2f 2a 20 53 74 72 69 6e 67 20 64 /* String d
12780 65 66 69 6e 69 6e 67 20 74 68 65 20 61 66 66 69 efining the affi
12790 6e 69 74 79 20 6f 66 20 65 61 63 68 20 63 6f 6c nity of each col
127a0 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a umn */. Index *
127b0 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 20 pNext;
127c0 20 20 2f 2a 20 54 68 65 20 6e 65 78 74 20 69 6e /* The next in
127d0 64 65 78 20 61 73 73 6f 63 69 61 74 65 64 20 77 dex associated w
127e0 69 74 68 20 74 68 65 20 73 61 6d 65 20 74 61 62 ith the same tab
127f0 6c 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a le */. Schema *
12800 70 53 63 68 65 6d 61 3b 20 20 20 20 20 20 20 20 pSchema;
12810 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 /* Schema conta
12820 69 6e 69 6e 67 20 74 68 69 73 20 69 6e 64 65 78 ining this index
12830 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f */. u8 *aSortO
12840 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f rder; /
12850 2a 20 66 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d * for each colum
12860 6e 3a 20 54 72 75 65 3d 3d 44 45 53 43 2c 20 46 n: True==DESC, F
12870 61 6c 73 65 3d 3d 41 53 43 20 2a 2f 0a 20 20 63 alse==ASC */. c
12880 68 61 72 20 2a 2a 61 7a 43 6f 6c 6c 3b 20 20 20 har **azColl;
12890 20 20 20 20 20 20 20 20 2f 2a 20 41 72 72 61 79 /* Array
128a0 20 6f 66 20 63 6f 6c 6c 61 74 69 6f 6e 20 73 65 of collation se
128b0 71 75 65 6e 63 65 20 6e 61 6d 65 73 20 66 6f 72 quence names for
128c0 20 69 6e 64 65 78 20 2a 2f 0a 20 20 45 78 70 72 index */. Expr
128d0 20 2a 70 50 61 72 74 49 64 78 57 68 65 72 65 3b *pPartIdxWhere;
128e0 20 20 20 20 20 2f 2a 20 57 48 45 52 45 20 63 6c /* WHERE cl
128f0 61 75 73 65 20 66 6f 72 20 70 61 72 74 69 61 6c ause for partial
12900 20 69 6e 64 69 63 65 73 20 2a 2f 0a 20 20 69 6e indices */. in
12910 74 20 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 t tnum;
12920 20 20 20 20 20 20 20 2f 2a 20 44 42 20 50 61 67 /* DB Pag
12930 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 72 6f 6f e containing roo
12940 74 20 6f 66 20 74 68 69 73 20 69 6e 64 65 78 20 t of this index
12950 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 73 7a 49 64 */. LogEst szId
12960 78 52 6f 77 3b 20 20 20 20 20 20 20 20 20 2f 2a xRow; /*
12970 20 45 73 74 69 6d 61 74 65 64 20 61 76 65 72 61 Estimated avera
12980 67 65 20 72 6f 77 20 73 69 7a 65 20 69 6e 20 62 ge row size in b
12990 79 74 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e 4b ytes */. u16 nK
129a0 65 79 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 eyCol;
129b0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
129c0 63 6f 6c 75 6d 6e 73 20 66 6f 72 6d 69 6e 67 20 columns forming
129d0 74 68 65 20 6b 65 79 20 2a 2f 0a 20 20 75 31 36 the key */. u16
129e0 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 nColumn;
129f0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
12a00 6f 66 20 63 6f 6c 75 6d 6e 73 20 73 74 6f 72 65 of columns store
12a10 64 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a d in the index *
12a20 2f 0a 20 20 75 38 20 6f 6e 45 72 72 6f 72 3b 20 /. u8 onError;
12a30 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
12a40 4f 45 5f 41 62 6f 72 74 2c 20 4f 45 5f 49 67 6e OE_Abort, OE_Ign
12a50 6f 72 65 2c 20 4f 45 5f 52 65 70 6c 61 63 65 2c ore, OE_Replace,
12a60 20 6f 72 20 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a 20 or OE_None */.
12a70 20 75 6e 73 69 67 6e 65 64 20 69 64 78 54 79 70 unsigned idxTyp
12a80 65 3a 32 3b 20 20 20 20 20 20 2f 2a 20 31 3d 3d e:2; /* 1==
12a90 55 4e 49 51 55 45 2c 20 32 3d 3d 50 52 49 4d 41 UNIQUE, 2==PRIMA
12aa0 52 59 20 4b 45 59 2c 20 30 3d 3d 43 52 45 41 54 RY KEY, 0==CREAT
12ab0 45 20 49 4e 44 45 58 20 2a 2f 0a 20 20 75 6e 73 E INDEX */. uns
12ac0 69 67 6e 65 64 20 62 55 6e 6f 72 64 65 72 65 64 igned bUnordered
12ad0 3a 31 3b 20 20 20 2f 2a 20 55 73 65 20 74 68 69 :1; /* Use thi
12ae0 73 20 69 6e 64 65 78 20 66 6f 72 20 3d 3d 20 6f s index for == o
12af0 72 20 49 4e 20 71 75 65 72 69 65 73 20 6f 6e 6c r IN queries onl
12b00 79 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 y */. unsigned
12b10 75 6e 69 71 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 20 uniqNotNull:1;
12b20 2f 2a 20 54 72 75 65 20 69 66 20 55 4e 49 51 55 /* True if UNIQU
12b30 45 20 61 6e 64 20 4e 4f 54 20 4e 55 4c 4c 20 66 E and NOT NULL f
12b40 6f 72 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 2a or all columns *
12b50 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 73 52 /. unsigned isR
12b60 65 73 69 7a 65 64 3a 31 3b 20 20 20 20 2f 2a 20 esized:1; /*
12b70 54 72 75 65 20 69 66 20 72 65 73 69 7a 65 49 6e True if resizeIn
12b80 64 65 78 4f 62 6a 65 63 74 28 29 20 68 61 73 20 dexObject() has
12b90 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 been called */.
12ba0 20 75 6e 73 69 67 6e 65 64 20 69 73 43 6f 76 65 unsigned isCove
12bb0 72 69 6e 67 3a 31 3b 20 20 20 2f 2a 20 54 72 75 ring:1; /* Tru
12bc0 65 20 69 66 20 74 68 69 73 20 69 73 20 61 20 63 e if this is a c
12bd0 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 2a 2f overing index */
12be0 0a 20 20 75 6e 73 69 67 6e 65 64 20 6e 6f 53 6b . unsigned noSk
12bf0 69 70 53 63 61 6e 3a 31 3b 20 20 20 2f 2a 20 44 ipScan:1; /* D
12c00 6f 20 6e 6f 74 20 74 72 79 20 74 6f 20 75 73 65 o not try to use
12c10 20 73 6b 69 70 2d 73 63 61 6e 20 69 66 20 74 72 skip-scan if tr
12c20 75 65 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c ue */.#ifdef SQL
12c30 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
12c40 5f 4f 52 5f 53 54 41 54 34 0a 20 20 69 6e 74 20 _OR_STAT4. int
12c50 6e 53 61 6d 70 6c 65 3b 20 20 20 20 20 20 20 20 nSample;
12c60 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
12c70 66 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61 53 f elements in aS
12c80 61 6d 70 6c 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 ample[] */. int
12c90 20 6e 53 61 6d 70 6c 65 43 6f 6c 3b 20 20 20 20 nSampleCol;
12ca0 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 /* Size of
12cb0 20 49 6e 64 65 78 53 61 6d 70 6c 65 2e 61 6e 45 IndexSample.anE
12cc0 71 5b 5d 20 61 6e 64 20 73 6f 20 6f 6e 20 2a 2f q[] and so on */
12cd0 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 41 76 67 . tRowcnt *aAvg
12ce0 45 71 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 Eq; /* A
12cf0 76 65 72 61 67 65 20 6e 45 71 20 76 61 6c 75 65 verage nEq value
12d00 73 20 66 6f 72 20 6b 65 79 73 20 6e 6f 74 20 69 s for keys not i
12d10 6e 20 61 53 61 6d 70 6c 65 20 2a 2f 0a 20 20 49 n aSample */. I
12d20 6e 64 65 78 53 61 6d 70 6c 65 20 2a 61 53 61 6d ndexSample *aSam
12d30 70 6c 65 3b 20 20 20 20 2f 2a 20 53 61 6d 70 6c ple; /* Sampl
12d40 65 73 20 6f 66 20 74 68 65 20 6c 65 66 74 2d 6d es of the left-m
12d50 6f 73 74 20 6b 65 79 20 2a 2f 0a 20 20 74 52 6f ost key */. tRo
12d60 77 63 6e 74 20 2a 61 69 52 6f 77 45 73 74 3b 20 wcnt *aiRowEst;
12d70 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 /* Non-log
12d80 61 72 69 74 68 6d 69 63 20 73 74 61 74 31 20 64 arithmic stat1 d
12d90 61 74 61 20 66 6f 72 20 74 68 69 73 20 69 6e 64 ata for this ind
12da0 65 78 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 ex */. tRowcnt
12db0 6e 52 6f 77 45 73 74 30 3b 20 20 20 20 20 20 20 nRowEst0;
12dc0 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 /* Non-logarith
12dd0 6d 69 63 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f mic number of ro
12de0 77 73 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 ws in the index
12df0 2a 2f 0a 23 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a */.#endif.};../*
12e00 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 .** Allowed valu
12e10 65 73 20 66 6f 72 20 49 6e 64 65 78 2e 69 64 78 es for Index.idx
12e20 54 79 70 65 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 Type.*/.#define
12e30 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 41 SQLITE_IDXTYPE_A
12e40 50 50 44 45 46 20 20 20 20 20 20 30 20 20 20 2f PPDEF 0 /
12e50 2a 20 43 72 65 61 74 65 64 20 75 73 69 6e 67 20 * Created using
12e60 43 52 45 41 54 45 20 49 4e 44 45 58 20 2a 2f 0a CREATE INDEX */.
12e70 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 #define SQLITE_I
12e80 44 58 54 59 50 45 5f 55 4e 49 51 55 45 20 20 20 DXTYPE_UNIQUE
12e90 20 20 20 31 20 20 20 2f 2a 20 49 6d 70 6c 65 6d 1 /* Implem
12ea0 65 6e 74 73 20 61 20 55 4e 49 51 55 45 20 63 6f ents a UNIQUE co
12eb0 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 nstraint */.#def
12ec0 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 ine SQLITE_IDXTY
12ed0 50 45 5f 50 52 49 4d 41 52 59 4b 45 59 20 20 32 PE_PRIMARYKEY 2
12ee0 20 20 20 2f 2a 20 49 73 20 74 68 65 20 50 52 49 /* Is the PRI
12ef0 4d 41 52 59 20 4b 45 59 20 66 6f 72 20 74 68 65 MARY KEY for the
12f00 20 74 61 62 6c 65 20 2a 2f 0a 0a 2f 2a 20 52 65 table */../* Re
12f10 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 6e 64 turn true if ind
12f20 65 78 20 58 20 69 73 20 61 20 50 52 49 4d 41 52 ex X is a PRIMAR
12f30 59 20 4b 45 59 20 69 6e 64 65 78 20 2a 2f 0a 23 Y KEY index */.#
12f40 64 65 66 69 6e 65 20 49 73 50 72 69 6d 61 72 79 define IsPrimary
12f50 4b 65 79 49 6e 64 65 78 28 58 29 20 20 28 28 58 KeyIndex(X) ((X
12f60 29 2d 3e 69 64 78 54 79 70 65 3d 3d 53 51 4c 49 )->idxType==SQLI
12f70 54 45 5f 49 44 58 54 59 50 45 5f 50 52 49 4d 41 TE_IDXTYPE_PRIMA
12f80 52 59 4b 45 59 29 0a 0a 2f 2a 20 52 65 74 75 72 RYKEY)../* Retur
12f90 6e 20 74 72 75 65 20 69 66 20 69 6e 64 65 78 20 n true if index
12fa0 58 20 69 73 20 61 20 55 4e 49 51 55 45 20 69 6e X is a UNIQUE in
12fb0 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 dex */.#define I
12fc0 73 55 6e 69 71 75 65 49 6e 64 65 78 28 58 29 20 sUniqueIndex(X)
12fd0 20 20 20 20 20 28 28 58 29 2d 3e 6f 6e 45 72 72 ((X)->onErr
12fe0 6f 72 21 3d 4f 45 5f 4e 6f 6e 65 29 0a 0a 2f 2a or!=OE_None)../*
12ff0 0a 2a 2a 20 45 61 63 68 20 73 61 6d 70 6c 65 20 .** Each sample
13000 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 73 71 stored in the sq
13010 6c 69 74 65 5f 73 74 61 74 33 20 74 61 62 6c 65 lite_stat3 table
13020 20 69 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 is represented
13030 69 6e 20 6d 65 6d 6f 72 79 20 0a 2a 2a 20 75 73 in memory .** us
13040 69 6e 67 20 61 20 73 74 72 75 63 74 75 72 65 20 ing a structure
13050 6f 66 20 74 68 69 73 20 74 79 70 65 2e 20 20 53 of this type. S
13060 65 65 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e ee documentation
13070 20 61 74 20 74 68 65 20 74 6f 70 20 6f 66 20 74 at the top of t
13080 68 65 0a 2a 2a 20 61 6e 61 6c 79 7a 65 2e 63 20 he.** analyze.c
13090 73 6f 75 72 63 65 20 66 69 6c 65 20 66 6f 72 20 source file for
130a0 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e 66 6f 72 additional infor
130b0 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 mation..*/.struc
130c0 74 20 49 6e 64 65 78 53 61 6d 70 6c 65 20 7b 0a t IndexSample {.
130d0 20 20 76 6f 69 64 20 2a 70 3b 20 20 20 20 20 20 void *p;
130e0 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 /* Pointer t
130f0 6f 20 73 61 6d 70 6c 65 64 20 72 65 63 6f 72 64 o sampled record
13100 20 2a 2f 0a 20 20 69 6e 74 20 6e 3b 20 20 20 20 */. int n;
13110 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
13120 6f 66 20 72 65 63 6f 72 64 20 69 6e 20 62 79 74 of record in byt
13130 65 73 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 es */. tRowcnt
13140 2a 61 6e 45 71 3b 20 20 20 20 2f 2a 20 45 73 74 *anEq; /* Est
13150 2e 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 . number of rows
13160 20 77 68 65 72 65 20 74 68 65 20 6b 65 79 20 65 where the key e
13170 71 75 61 6c 73 20 74 68 69 73 20 73 61 6d 70 6c quals this sampl
13180 65 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a e */. tRowcnt *
13190 61 6e 4c 74 3b 20 20 20 20 2f 2a 20 45 73 74 2e anLt; /* Est.
131a0 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 number of rows
131b0 77 68 65 72 65 20 6b 65 79 20 69 73 20 6c 65 73 where key is les
131c0 73 20 74 68 61 6e 20 74 68 69 73 20 73 61 6d 70 s than this samp
131d0 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 le */. tRowcnt
131e0 2a 61 6e 44 4c 74 3b 20 20 20 2f 2a 20 45 73 74 *anDLt; /* Est
131f0 2e 20 6e 75 6d 62 65 72 20 6f 66 20 64 69 73 74 . number of dist
13200 69 6e 63 74 20 6b 65 79 73 20 6c 65 73 73 20 74 inct keys less t
13210 68 61 6e 20 74 68 69 73 20 73 61 6d 70 6c 65 20 han this sample
13220 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 */.};../*.** Eac
13230 68 20 74 6f 6b 65 6e 20 63 6f 6d 69 6e 67 20 6f h token coming o
13240 75 74 20 6f 66 20 74 68 65 20 6c 65 78 65 72 20 ut of the lexer
13250 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f is an instance o
13260 66 0a 2a 2a 20 74 68 69 73 20 73 74 72 75 63 74 f.** this struct
13270 75 72 65 2e 20 20 54 6f 6b 65 6e 73 20 61 72 65 ure. Tokens are
13280 20 61 6c 73 6f 20 75 73 65 64 20 61 73 20 70 61 also used as pa
13290 72 74 20 6f 66 20 61 6e 20 65 78 70 72 65 73 73 rt of an express
132a0 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 ion..**.** Note
132b0 69 66 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 20 74 68 if Token.z==0 th
132c0 65 6e 20 54 6f 6b 65 6e 2e 64 79 6e 20 61 6e 64 en Token.dyn and
132d0 20 54 6f 6b 65 6e 2e 6e 20 61 72 65 20 75 6e 64 Token.n are und
132e0 65 66 69 6e 65 64 20 61 6e 64 0a 2a 2a 20 6d 61 efined and.** ma
132f0 79 20 63 6f 6e 74 61 69 6e 20 72 61 6e 64 6f 6d y contain random
13300 20 76 61 6c 75 65 73 2e 20 20 44 6f 20 6e 6f 74 values. Do not
13310 20 6d 61 6b 65 20 61 6e 79 20 61 73 73 75 6d 70 make any assump
13320 74 69 6f 6e 73 20 61 62 6f 75 74 20 54 6f 6b 65 tions about Toke
13330 6e 2e 64 79 6e 0a 2a 2a 20 61 6e 64 20 54 6f 6b n.dyn.** and Tok
13340 65 6e 2e 6e 20 77 68 65 6e 20 54 6f 6b 65 6e 2e en.n when Token.
13350 7a 3d 3d 30 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 z==0..*/.struct
13360 54 6f 6b 65 6e 20 7b 0a 20 20 63 6f 6e 73 74 20 Token {. const
13370 63 68 61 72 20 2a 7a 3b 20 20 20 20 20 2f 2a 20 char *z; /*
13380 54 65 78 74 20 6f 66 20 74 68 65 20 74 6f 6b 65 Text of the toke
13390 6e 2e 20 20 4e 6f 74 20 4e 55 4c 4c 2d 74 65 72 n. Not NULL-ter
133a0 6d 69 6e 61 74 65 64 21 20 2a 2f 0a 20 20 75 6e minated! */. un
133b0 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b 20 20 20 signed int n;
133c0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 68 /* Number of ch
133d0 61 72 61 63 74 65 72 73 20 69 6e 20 74 68 69 73 aracters in this
133e0 20 74 6f 6b 65 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a token */.};../*
133f0 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
13400 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 of this structur
13410 65 20 63 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 e contains infor
13420 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 20 74 6f mation needed to
13430 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 63 6f 64 generate.** cod
13440 65 20 66 6f 72 20 61 20 53 45 4c 45 43 54 20 74 e for a SELECT t
13450 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 61 67 67 hat contains agg
13460 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 regate functions
13470 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 45 78 70 72 2e ..**.** If Expr.
13480 6f 70 3d 3d 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d op==TK_AGG_COLUM
13490 4e 20 6f 72 20 54 4b 5f 41 47 47 5f 46 55 4e 43 N or TK_AGG_FUNC
134a0 54 49 4f 4e 20 74 68 65 6e 20 45 78 70 72 2e 70 TION then Expr.p
134b0 41 67 67 49 6e 66 6f 20 69 73 20 61 0a 2a 2a 20 AggInfo is a.**
134c0 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 pointer to this
134d0 73 74 72 75 63 74 75 72 65 2e 20 20 54 68 65 20 structure. The
134e0 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 66 69 65 Expr.iColumn fie
134f0 6c 64 20 69 73 20 74 68 65 20 69 6e 64 65 78 20 ld is the index
13500 69 6e 0a 2a 2a 20 41 67 67 49 6e 66 6f 2e 61 43 in.** AggInfo.aC
13510 6f 6c 5b 5d 20 6f 72 20 41 67 67 49 6e 66 6f 2e ol[] or AggInfo.
13520 61 46 75 6e 63 5b 5d 20 6f 66 20 69 6e 66 6f 72 aFunc[] of infor
13530 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 20 74 6f mation needed to
13540 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 63 6f 64 generate.** cod
13550 65 20 66 6f 72 20 74 68 61 74 20 6e 6f 64 65 2e e for that node.
13560 0a 2a 2a 0a 2a 2a 20 41 67 67 49 6e 66 6f 2e 70 .**.** AggInfo.p
13570 47 72 6f 75 70 42 79 20 61 6e 64 20 41 67 67 49 GroupBy and AggI
13580 6e 66 6f 2e 61 46 75 6e 63 2e 70 45 78 70 72 20 nfo.aFunc.pExpr
13590 70 6f 69 6e 74 20 74 6f 20 66 69 65 6c 64 73 20 point to fields
135a0 77 69 74 68 69 6e 20 74 68 65 0a 2a 2a 20 6f 72 within the.** or
135b0 69 67 69 6e 61 6c 20 53 65 6c 65 63 74 20 73 74 iginal Select st
135c0 72 75 63 74 75 72 65 20 74 68 61 74 20 64 65 73 ructure that des
135d0 63 72 69 62 65 73 20 74 68 65 20 53 45 4c 45 43 cribes the SELEC
135e0 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 54 68 T statement. Th
135f0 65 73 65 0a 2a 2a 20 66 69 65 6c 64 73 20 64 6f ese.** fields do
13600 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 62 65 20 not need to be
13610 66 72 65 65 64 20 77 68 65 6e 20 64 65 61 6c 6c freed when deall
13620 6f 63 61 74 69 6e 67 20 74 68 65 20 41 67 67 49 ocating the AggI
13630 6e 66 6f 20 73 74 72 75 63 74 75 72 65 2e 0a 2a nfo structure..*
13640 2f 0a 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f /.struct AggInfo
13650 20 7b 0a 20 20 75 38 20 64 69 72 65 63 74 4d 6f {. u8 directMo
13660 64 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 de; /*
13670 44 69 72 65 63 74 20 72 65 6e 64 65 72 69 6e 67 Direct rendering
13680 20 6d 6f 64 65 20 6d 65 61 6e 73 20 74 61 6b 65 mode means take
13690 20 64 61 74 61 20 64 69 72 65 63 74 6c 79 0a 20 data directly.
136a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
136b0 20 20 20 20 20 20 20 20 20 2a 2a 20 66 72 6f 6d ** from
136c0 20 73 6f 75 72 63 65 20 74 61 62 6c 65 73 20 72 source tables r
136d0 61 74 68 65 72 20 74 68 61 6e 20 66 72 6f 6d 20 ather than from
136e0 61 63 63 75 6d 75 6c 61 74 6f 72 73 20 2a 2f 0a accumulators */.
136f0 20 20 75 38 20 75 73 65 53 6f 72 74 69 6e 67 49 u8 useSortingI
13700 64 78 3b 20 20 20 20 20 20 20 2f 2a 20 49 6e 20 dx; /* In
13710 64 69 72 65 63 74 20 6d 6f 64 65 2c 20 72 65 66 direct mode, ref
13720 65 72 65 6e 63 65 20 74 68 65 20 73 6f 72 74 69 erence the sorti
13730 6e 67 20 69 6e 64 65 78 20 72 61 74 68 65 72 0a ng index rather.
13740 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13750 20 20 20 20 20 20 20 20 20 20 2a 2a 20 74 68 61 ** tha
13760 6e 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 62 n the source tab
13770 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 73 6f 72 74 le */. int sort
13780 69 6e 67 49 64 78 3b 20 20 20 20 20 20 20 20 20 ingIdx;
13790 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 /* Cursor number
137a0 20 6f 66 20 74 68 65 20 73 6f 72 74 69 6e 67 20 of the sorting
137b0 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e 74 20 73 index */. int s
137c0 6f 72 74 69 6e 67 49 64 78 50 54 61 62 3b 20 20 ortingIdxPTab;
137d0 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d /* Cursor num
137e0 62 65 72 20 6f 66 20 70 73 65 75 64 6f 2d 74 61 ber of pseudo-ta
137f0 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 6f ble */. int nSo
13800 72 74 69 6e 67 43 6f 6c 75 6d 6e 3b 20 20 20 20 rtingColumn;
13810 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f /* Number of co
13820 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 73 6f 72 lumns in the sor
13830 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 ting index */.
13840 69 6e 74 20 6d 6e 52 65 67 2c 20 6d 78 52 65 67 int mnReg, mxReg
13850 3b 20 20 20 20 20 20 20 2f 2a 20 52 61 6e 67 65 ; /* Range
13860 20 6f 66 20 72 65 67 69 73 74 65 72 73 20 61 6c of registers al
13870 6c 6f 63 61 74 65 64 20 66 6f 72 20 61 43 6f 6c located for aCol
13880 20 61 6e 64 20 61 46 75 6e 63 20 2a 2f 0a 20 20 and aFunc */.
13890 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 70 ExprList *pGroup
138a0 42 79 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 67 By; /* The g
138b0 72 6f 75 70 20 62 79 20 63 6c 61 75 73 65 20 2a roup by clause *
138c0 2f 0a 20 20 73 74 72 75 63 74 20 41 67 67 49 6e /. struct AggIn
138d0 66 6f 5f 63 6f 6c 20 7b 20 20 20 20 2f 2a 20 46 fo_col { /* F
138e0 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 75 or each column u
138f0 73 65 64 20 69 6e 20 73 6f 75 72 63 65 20 74 61 sed in source ta
13900 62 6c 65 73 20 2a 2f 0a 20 20 20 20 54 61 62 6c bles */. Tabl
13910 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 e *pTab;
13920 20 20 20 20 20 2f 2a 20 53 6f 75 72 63 65 20 74 /* Source t
13930 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 able */. int
13940 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 iTable;
13950 20 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e /* Cursor n
13960 75 6d 62 65 72 20 6f 66 20 74 68 65 20 73 6f 75 umber of the sou
13970 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 rce table */.
13980 20 69 6e 74 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 int iColumn;
13990 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6c /* Col
139a0 75 6d 6e 20 6e 75 6d 62 65 72 20 77 69 74 68 69 umn number withi
139b0 6e 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 62 n the source tab
139c0 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 53 le */. int iS
139d0 6f 72 74 65 72 43 6f 6c 75 6d 6e 3b 20 20 20 20 orterColumn;
139e0 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d /* Column num
139f0 62 65 72 20 69 6e 20 74 68 65 20 73 6f 72 74 69 ber in the sorti
13a00 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 20 20 ng index */.
13a10 69 6e 74 20 69 4d 65 6d 3b 20 20 20 20 20 20 20 int iMem;
13a20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 6d 6f /* Memo
13a30 72 79 20 6c 6f 63 61 74 69 6f 6e 20 74 68 61 74 ry location that
13a40 20 61 63 74 73 20 61 73 20 61 63 63 75 6d 75 6c acts as accumul
13a50 61 74 6f 72 20 2a 2f 0a 20 20 20 20 45 78 70 72 ator */. Expr
13a60 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 *pExpr;
13a70 20 20 20 20 20 2f 2a 20 54 68 65 20 6f 72 69 67 /* The orig
13a80 69 6e 61 6c 20 65 78 70 72 65 73 73 69 6f 6e 20 inal expression
13a90 2a 2f 0a 20 20 7d 20 2a 61 43 6f 6c 3b 0a 20 20 */. } *aCol;.
13aa0 69 6e 74 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 int nColumn;
13ab0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
13ac0 72 20 6f 66 20 75 73 65 64 20 65 6e 74 72 69 65 r of used entrie
13ad0 73 20 69 6e 20 61 43 6f 6c 5b 5d 20 2a 2f 0a 20 s in aCol[] */.
13ae0 20 69 6e 74 20 6e 41 63 63 75 6d 75 6c 61 74 6f int nAccumulato
13af0 72 3b 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 r; /* Numb
13b00 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 74 68 er of columns th
13b10 61 74 20 73 68 6f 77 20 74 68 72 6f 75 67 68 20 at show through
13b20 74 6f 20 74 68 65 20 6f 75 74 70 75 74 2e 0a 20 to the output..
13b30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13b40 20 20 20 20 20 20 20 20 20 2a 2a 20 41 64 64 69 ** Addi
13b50 74 69 6f 6e 61 6c 20 63 6f 6c 75 6d 6e 73 20 61 tional columns a
13b60 72 65 20 75 73 65 64 20 6f 6e 6c 79 20 61 73 20 re used only as
13b70 70 61 72 61 6d 65 74 65 72 73 20 74 6f 0a 20 20 parameters to.
13b80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13b90 20 20 20 20 20 20 20 20 2a 2a 20 61 67 67 72 65 ** aggre
13ba0 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a gate functions *
13bb0 2f 0a 20 20 73 74 72 75 63 74 20 41 67 67 49 6e /. struct AggIn
13bc0 66 6f 5f 66 75 6e 63 20 7b 20 20 20 2f 2a 20 46 fo_func { /* F
13bd0 6f 72 20 65 61 63 68 20 61 67 67 72 65 67 61 74 or each aggregat
13be0 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 e function */.
13bf0 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 Expr *pExpr;
13c00 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 78 /* Ex
13c10 70 72 65 73 73 69 6f 6e 20 65 6e 63 6f 64 69 6e pression encodin
13c20 67 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 2a g the function *
13c30 2f 0a 20 20 20 20 46 75 6e 63 44 65 66 20 2a 70 /. FuncDef *p
13c40 46 75 6e 63 3b 20 20 20 20 20 20 20 20 20 20 2f Func; /
13c50 2a 20 54 68 65 20 61 67 67 72 65 67 61 74 65 20 * The aggregate
13c60 66 75 6e 63 74 69 6f 6e 20 69 6d 70 6c 65 6d 65 function impleme
13c70 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 ntation */. i
13c80 6e 74 20 69 4d 65 6d 3b 20 20 20 20 20 20 20 20 nt iMem;
13c90 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 /* Memor
13ca0 79 20 6c 6f 63 61 74 69 6f 6e 20 74 68 61 74 20 y location that
13cb0 61 63 74 73 20 61 73 20 61 63 63 75 6d 75 6c 61 acts as accumula
13cc0 74 6f 72 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 tor */. int i
13cd0 44 69 73 74 69 6e 63 74 3b 20 20 20 20 20 20 20 Distinct;
13ce0 20 20 20 20 2f 2a 20 45 70 68 65 6d 65 72 61 6c /* Ephemeral
13cf0 20 74 61 62 6c 65 20 75 73 65 64 20 74 6f 20 65 table used to e
13d00 6e 66 6f 72 63 65 20 44 49 53 54 49 4e 43 54 20 nforce DISTINCT
13d10 2a 2f 0a 20 20 7d 20 2a 61 46 75 6e 63 3b 0a 20 */. } *aFunc;.
13d20 20 69 6e 74 20 6e 46 75 6e 63 3b 20 20 20 20 20 int nFunc;
13d30 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
13d40 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 69 6e er of entries in
13d50 20 61 46 75 6e 63 5b 5d 20 2a 2f 0a 7d 3b 0a 0a aFunc[] */.};..
13d60 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 79 /*.** The dataty
13d70 70 65 20 79 6e 56 61 72 20 69 73 20 61 20 73 69 pe ynVar is a si
13d80 67 6e 65 64 20 69 6e 74 65 67 65 72 2c 20 65 69 gned integer, ei
13d90 74 68 65 72 20 31 36 2d 62 69 74 20 6f 72 20 33 ther 16-bit or 3
13da0 32 2d 62 69 74 2e 0a 2a 2a 20 55 73 75 61 6c 6c 2-bit..** Usuall
13db0 79 20 69 74 20 69 73 20 31 36 2d 62 69 74 73 2e y it is 16-bits.
13dc0 20 20 42 75 74 20 69 66 20 53 51 4c 49 54 45 5f But if SQLITE_
13dd0 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f 4e 55 4d MAX_VARIABLE_NUM
13de0 42 45 52 20 69 73 20 67 72 65 61 74 65 72 0a 2a BER is greater.*
13df0 2a 20 74 68 61 6e 20 33 32 37 36 37 20 77 65 20 * than 32767 we
13e00 68 61 76 65 20 74 6f 20 6d 61 6b 65 20 69 74 20 have to make it
13e10 33 32 2d 62 69 74 2e 20 20 31 36 2d 62 69 74 20 32-bit. 16-bit
13e20 69 73 20 70 72 65 66 65 72 72 65 64 20 62 65 63 is preferred bec
13e30 61 75 73 65 0a 2a 2a 20 69 74 20 75 73 65 73 20 ause.** it uses
13e40 6c 65 73 73 20 6d 65 6d 6f 72 79 20 69 6e 20 74 less memory in t
13e50 68 65 20 45 78 70 72 20 6f 62 6a 65 63 74 2c 20 he Expr object,
13e60 77 68 69 63 68 20 69 73 20 61 20 62 69 67 20 6d which is a big m
13e70 65 6d 6f 72 79 20 75 73 65 72 0a 2a 2a 20 69 6e emory user.** in
13e80 20 73 79 73 74 65 6d 73 20 77 69 74 68 20 6c 6f systems with lo
13e90 74 73 20 6f 66 20 70 72 65 70 61 72 65 64 20 73 ts of prepared s
13ea0 74 61 74 65 6d 65 6e 74 73 2e 20 20 41 6e 64 20 tatements. And
13eb0 66 65 77 20 61 70 70 6c 69 63 61 74 69 6f 6e 73 few applications
13ec0 0a 2a 2a 20 6e 65 65 64 20 6d 6f 72 65 20 74 68 .** need more th
13ed0 61 6e 20 61 62 6f 75 74 20 31 30 20 6f 72 20 32 an about 10 or 2
13ee0 30 20 76 61 72 69 61 62 6c 65 73 2e 20 20 42 75 0 variables. Bu
13ef0 74 20 73 6f 6d 65 20 65 78 74 72 65 6d 65 20 75 t some extreme u
13f00 73 65 72 73 20 77 61 6e 74 0a 2a 2a 20 74 6f 20 sers want.** to
13f10 68 61 76 65 20 70 72 65 70 61 72 65 64 20 73 74 have prepared st
13f20 61 74 65 6d 65 6e 74 73 20 77 69 74 68 20 6f 76 atements with ov
13f30 65 72 20 33 32 37 36 37 20 76 61 72 69 61 62 6c er 32767 variabl
13f40 65 73 2c 20 61 6e 64 20 66 6f 72 20 74 68 65 6d es, and for them
13f50 0a 2a 2a 20 74 68 65 20 6f 70 74 69 6f 6e 20 69 .** the option i
13f60 73 20 61 76 61 69 6c 61 62 6c 65 20 28 61 74 20 s available (at
13f70 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 29 2e 0a 2a compile-time)..*
13f80 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 /.#if SQLITE_MAX
13f90 5f 56 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 _VARIABLE_NUMBER
13fa0 3c 3d 33 32 37 36 37 0a 74 79 70 65 64 65 66 20 <=32767.typedef
13fb0 69 31 36 20 79 6e 56 61 72 3b 0a 23 65 6c 73 65 i16 ynVar;.#else
13fc0 0a 74 79 70 65 64 65 66 20 69 6e 74 20 79 6e 56 .typedef int ynV
13fd0 61 72 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a ar;.#endif../*.*
13fe0 2a 20 45 61 63 68 20 6e 6f 64 65 20 6f 66 20 61 * Each node of a
13ff0 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e 20 n expression in
14000 74 68 65 20 70 61 72 73 65 20 74 72 65 65 20 69 the parse tree i
14010 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a 2a s an instance.**
14020 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 of this structu
14030 72 65 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 6f re..**.** Expr.o
14040 70 20 69 73 20 74 68 65 20 6f 70 63 6f 64 65 2e p is the opcode.
14050 20 54 68 65 20 69 6e 74 65 67 65 72 20 70 61 72 The integer par
14060 73 65 72 20 74 6f 6b 65 6e 20 63 6f 64 65 73 20 ser token codes
14070 61 72 65 20 72 65 75 73 65 64 0a 2a 2a 20 61 73 are reused.** as
14080 20 6f 70 63 6f 64 65 73 20 68 65 72 65 2e 20 46 opcodes here. F
14090 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 68 65 20 or example, the
140a0 70 61 72 73 65 72 20 64 65 66 69 6e 65 73 20 54 parser defines T
140b0 4b 5f 47 45 20 74 6f 20 62 65 20 61 6e 20 69 6e K_GE to be an in
140c0 74 65 67 65 72 0a 2a 2a 20 63 6f 64 65 20 72 65 teger.** code re
140d0 70 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20 22 presenting the "
140e0 3e 3d 22 20 6f 70 65 72 61 74 6f 72 2e 20 54 68 >=" operator. Th
140f0 69 73 20 73 61 6d 65 20 69 6e 74 65 67 65 72 20 is same integer
14100 63 6f 64 65 20 69 73 20 72 65 75 73 65 64 0a 2a code is reused.*
14110 2a 20 74 6f 20 72 65 70 72 65 73 65 6e 74 20 74 * to represent t
14120 68 65 20 67 72 65 61 74 65 72 2d 74 68 61 6e 2d he greater-than-
14130 6f 72 2d 65 71 75 61 6c 2d 74 6f 20 6f 70 65 72 or-equal-to oper
14140 61 74 6f 72 20 69 6e 20 74 68 65 20 65 78 70 72 ator in the expr
14150 65 73 73 69 6f 6e 0a 2a 2a 20 74 72 65 65 2e 0a ession.** tree..
14160 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 **.** If the exp
14170 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 51 ression is an SQ
14180 4c 20 6c 69 74 65 72 61 6c 20 28 54 4b 5f 49 4e L literal (TK_IN
14190 54 45 47 45 52 2c 20 54 4b 5f 46 4c 4f 41 54 2c TEGER, TK_FLOAT,
141a0 20 54 4b 5f 42 4c 4f 42 2c 20 0a 2a 2a 20 6f 72 TK_BLOB, .** or
141b0 20 54 4b 5f 53 54 52 49 4e 47 29 2c 20 74 68 65 TK_STRING), the
141c0 6e 20 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e n Expr.token con
141d0 74 61 69 6e 73 20 74 68 65 20 74 65 78 74 20 6f tains the text o
141e0 66 20 74 68 65 20 53 51 4c 20 6c 69 74 65 72 61 f the SQL litera
141f0 6c 2e 20 49 66 0a 2a 2a 20 74 68 65 20 65 78 70 l. If.** the exp
14200 72 65 73 73 69 6f 6e 20 69 73 20 61 20 76 61 72 ression is a var
14210 69 61 62 6c 65 20 28 54 4b 5f 56 41 52 49 41 42 iable (TK_VARIAB
14220 4c 45 29 2c 20 74 68 65 6e 20 45 78 70 72 2e 74 LE), then Expr.t
14230 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 oken contains th
14240 65 20 0a 2a 2a 20 76 61 72 69 61 62 6c 65 20 6e e .** variable n
14250 61 6d 65 2e 20 46 69 6e 61 6c 6c 79 2c 20 69 66 ame. Finally, if
14260 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 the expression
14270 69 73 20 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 is an SQL functi
14280 6f 6e 20 28 54 4b 5f 46 55 4e 43 54 49 4f 4e 29 on (TK_FUNCTION)
14290 2c 0a 2a 2a 20 74 68 65 6e 20 45 78 70 72 2e 74 ,.** then Expr.t
142a0 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 oken contains th
142b0 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 66 75 e name of the fu
142c0 6e 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 45 78 nction..**.** Ex
142d0 70 72 2e 70 52 69 67 68 74 20 61 6e 64 20 45 78 pr.pRight and Ex
142e0 70 72 2e 70 4c 65 66 74 20 61 72 65 20 74 68 65 pr.pLeft are the
142f0 20 6c 65 66 74 20 61 6e 64 20 72 69 67 68 74 20 left and right
14300 73 75 62 65 78 70 72 65 73 73 69 6f 6e 73 20 6f subexpressions o
14310 66 20 61 0a 2a 2a 20 62 69 6e 61 72 79 20 6f 70 f a.** binary op
14320 65 72 61 74 6f 72 2e 20 45 69 74 68 65 72 20 6f erator. Either o
14330 72 20 62 6f 74 68 20 6d 61 79 20 62 65 20 4e 55 r both may be NU
14340 4c 4c 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 78 LL..**.** Expr.x
14350 2e 70 4c 69 73 74 20 69 73 20 61 20 6c 69 73 74 .pList is a list
14360 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 69 66 of arguments if
14370 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 the expression
14380 69 73 20 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 is an SQL functi
14390 6f 6e 2c 0a 2a 2a 20 61 20 43 41 53 45 20 65 78 on,.** a CASE ex
143a0 70 72 65 73 73 69 6f 6e 20 6f 72 20 61 6e 20 49 pression or an I
143b0 4e 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 N expression of
143c0 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 the form "<lhs>
143d0 49 4e 20 28 3c 79 3e 2c 20 3c 7a 3e 2e 2e 2e 29 IN (<y>, <z>...)
143e0 22 2e 0a 2a 2a 20 45 78 70 72 2e 78 2e 70 53 65 "..** Expr.x.pSe
143f0 6c 65 63 74 20 69 73 20 75 73 65 64 20 69 66 20 lect is used if
14400 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 the expression i
14410 73 20 61 20 73 75 62 2d 73 65 6c 65 63 74 20 6f s a sub-select o
14420 72 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 r an expression
14430 6f 66 0a 2a 2a 20 74 68 65 20 66 6f 72 6d 20 22 of.** the form "
14440 3c 6c 68 73 3e 20 49 4e 20 28 53 45 4c 45 43 54 <lhs> IN (SELECT
14450 20 2e 2e 2e 29 22 2e 20 49 66 20 74 68 65 20 45 ...)". If the E
14460 50 5f 78 49 73 53 65 6c 65 63 74 20 62 69 74 20 P_xIsSelect bit
14470 69 73 20 73 65 74 20 69 6e 20 74 68 65 0a 2a 2a is set in the.**
14480 20 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b Expr.flags mask
14490 2c 20 74 68 65 6e 20 45 78 70 72 2e 78 2e 70 53 , then Expr.x.pS
144a0 65 6c 65 63 74 20 69 73 20 76 61 6c 69 64 2e 20 elect is valid.
144b0 4f 74 68 65 72 77 69 73 65 2c 20 45 78 70 72 2e Otherwise, Expr.
144c0 78 2e 70 4c 69 73 74 20 69 73 20 0a 2a 2a 20 76 x.pList is .** v
144d0 61 6c 69 64 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 65 alid..**.** An e
144e0 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 68 65 xpression of the
144f0 20 66 6f 72 6d 20 49 44 20 6f 72 20 49 44 2e 49 form ID or ID.I
14500 44 20 72 65 66 65 72 73 20 74 6f 20 61 20 63 6f D refers to a co
14510 6c 75 6d 6e 20 69 6e 20 61 20 74 61 62 6c 65 2e lumn in a table.
14520 0a 2a 2a 20 46 6f 72 20 73 75 63 68 20 65 78 70 .** For such exp
14530 72 65 73 73 69 6f 6e 73 2c 20 45 78 70 72 2e 6f ressions, Expr.o
14540 70 20 69 73 20 73 65 74 20 74 6f 20 54 4b 5f 43 p is set to TK_C
14550 4f 4c 55 4d 4e 20 61 6e 64 20 45 78 70 72 2e 69 OLUMN and Expr.i
14560 54 61 62 6c 65 20 69 73 0a 2a 2a 20 74 68 65 20 Table is.** the
14570 69 6e 74 65 67 65 72 20 63 75 72 73 6f 72 20 6e integer cursor n
14580 75 6d 62 65 72 20 6f 66 20 61 20 56 44 42 45 20 umber of a VDBE
14590 63 75 72 73 6f 72 20 70 6f 69 6e 74 69 6e 67 20 cursor pointing
145a0 74 6f 20 74 68 61 74 20 74 61 62 6c 65 20 61 6e to that table an
145b0 64 0a 2a 2a 20 45 78 70 72 2e 69 43 6f 6c 75 6d d.** Expr.iColum
145c0 6e 20 69 73 20 74 68 65 20 63 6f 6c 75 6d 6e 20 n is the column
145d0 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 65 20 73 number for the s
145e0 70 65 63 69 66 69 63 20 63 6f 6c 75 6d 6e 2e 20 pecific column.
145f0 20 49 66 20 74 68 65 0a 2a 2a 20 65 78 70 72 65 If the.** expre
14600 73 73 69 6f 6e 20 69 73 20 75 73 65 64 20 61 73 ssion is used as
14610 20 61 20 72 65 73 75 6c 74 20 69 6e 20 61 6e 20 a result in an
14620 61 67 67 72 65 67 61 74 65 20 53 45 4c 45 43 54 aggregate SELECT
14630 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 76 61 , then the.** va
14640 6c 75 65 20 69 73 20 61 6c 73 6f 20 73 74 6f 72 lue is also stor
14650 65 64 20 69 6e 20 74 68 65 20 45 78 70 72 2e 69 ed in the Expr.i
14660 41 67 67 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 Agg column in th
14670 65 20 61 67 67 72 65 67 61 74 65 20 73 6f 20 74 e aggregate so t
14680 68 61 74 0a 2a 2a 20 69 74 20 63 61 6e 20 62 65 hat.** it can be
14690 20 61 63 63 65 73 73 65 64 20 61 66 74 65 72 20 accessed after
146a0 61 6c 6c 20 61 67 67 72 65 67 61 74 65 73 20 61 all aggregates a
146b0 72 65 20 63 6f 6d 70 75 74 65 64 2e 0a 2a 2a 0a re computed..**.
146c0 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 73 ** If the expres
146d0 73 69 6f 6e 20 69 73 20 61 6e 20 75 6e 62 6f 75 sion is an unbou
146e0 6e 64 20 76 61 72 69 61 62 6c 65 20 6d 61 72 6b nd variable mark
146f0 65 72 20 28 61 20 71 75 65 73 74 69 6f 6e 20 6d er (a question m
14700 61 72 6b 20 0a 2a 2a 20 63 68 61 72 61 63 74 65 ark .** characte
14710 72 20 27 3f 27 20 69 6e 20 74 68 65 20 6f 72 69 r '?' in the ori
14720 67 69 6e 61 6c 20 53 51 4c 29 20 74 68 65 6e 20 ginal SQL) then
14730 74 68 65 20 45 78 70 72 2e 69 54 61 62 6c 65 20 the Expr.iTable
14740 68 6f 6c 64 73 20 74 68 65 20 69 6e 64 65 78 20 holds the index
14750 0a 2a 2a 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 .** number for t
14760 68 61 74 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a hat variable..**
14770 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 .** If the expre
14780 73 73 69 6f 6e 20 69 73 20 61 20 73 75 62 71 75 ssion is a subqu
14790 65 72 79 20 74 68 65 6e 20 45 78 70 72 2e 69 43 ery then Expr.iC
147a0 6f 6c 75 6d 6e 20 68 6f 6c 64 73 20 61 6e 20 69 olumn holds an i
147b0 6e 74 65 67 65 72 0a 2a 2a 20 72 65 67 69 73 74 nteger.** regist
147c0 65 72 20 6e 75 6d 62 65 72 20 63 6f 6e 74 61 69 er number contai
147d0 6e 69 6e 67 20 74 68 65 20 72 65 73 75 6c 74 20 ning the result
147e0 6f 66 20 74 68 65 20 73 75 62 71 75 65 72 79 2e of the subquery.
147f0 20 20 49 66 20 74 68 65 0a 2a 2a 20 73 75 62 71 If the.** subq
14800 75 65 72 79 20 67 69 76 65 73 20 61 20 63 6f 6e uery gives a con
14810 73 74 61 6e 74 20 72 65 73 75 6c 74 2c 20 74 68 stant result, th
14820 65 6e 20 69 54 61 62 6c 65 20 69 73 20 2d 31 2e en iTable is -1.
14830 20 20 49 66 20 74 68 65 20 73 75 62 71 75 65 72 If the subquer
14840 79 0a 2a 2a 20 67 69 76 65 73 20 61 20 64 69 66 y.** gives a dif
14850 66 65 72 65 6e 74 20 61 6e 73 77 65 72 20 61 74 ferent answer at
14860 20 64 69 66 66 65 72 65 6e 74 20 74 69 6d 65 73 different times
14870 20 64 75 72 69 6e 67 20 73 74 61 74 65 6d 65 6e during statemen
14880 74 20 70 72 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 t processing.**
14890 74 68 65 6e 20 69 54 61 62 6c 65 20 69 73 20 74 then iTable is t
148a0 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 he address of a
148b0 73 75 62 72 6f 75 74 69 6e 65 20 74 68 61 74 20 subroutine that
148c0 63 6f 6d 70 75 74 65 73 20 74 68 65 20 73 75 62 computes the sub
148d0 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 query..**.** If
148e0 74 68 65 20 45 78 70 72 20 69 73 20 6f 66 20 74 the Expr is of t
148f0 79 70 65 20 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 ype OP_Column, a
14900 6e 64 20 74 68 65 20 74 61 62 6c 65 20 69 74 20 nd the table it
14910 69 73 20 73 65 6c 65 63 74 69 6e 67 20 66 72 6f is selecting fro
14920 6d 0a 2a 2a 20 69 73 20 61 20 64 69 73 6b 20 74 m.** is a disk t
14930 61 62 6c 65 20 6f 72 20 74 68 65 20 22 6f 6c 64 able or the "old
14940 2e 2a 22 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 .*" pseudo-table
14950 2c 20 74 68 65 6e 20 70 54 61 62 20 70 6f 69 6e , then pTab poin
14960 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 ts to the.** cor
14970 72 65 73 70 6f 6e 64 69 6e 67 20 74 61 62 6c 65 responding table
14980 20 64 65 66 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a definition..**.
14990 2a 2a 20 41 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f ** ALLOCATION NO
149a0 54 45 53 3a 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 TES:.**.** Expr
149b0 6f 62 6a 65 63 74 73 20 63 61 6e 20 75 73 65 20 objects can use
149c0 61 20 6c 6f 74 20 6f 66 20 6d 65 6d 6f 72 79 20 a lot of memory
149d0 73 70 61 63 65 20 69 6e 20 64 61 74 61 62 61 73 space in databas
149e0 65 20 73 63 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a e schema. To.**
149f0 20 68 65 6c 70 20 72 65 64 75 63 65 20 6d 65 6d help reduce mem
14a00 6f 72 79 20 72 65 71 75 69 72 65 6d 65 6e 74 73 ory requirements
14a10 2c 20 73 6f 6d 65 74 69 6d 65 73 20 61 6e 20 45 , sometimes an E
14a20 78 70 72 20 6f 62 6a 65 63 74 20 77 69 6c 6c 20 xpr object will
14a30 62 65 0a 2a 2a 20 74 72 75 6e 63 61 74 65 64 2e be.** truncated.
14a40 20 20 41 6e 64 20 74 6f 20 72 65 64 75 63 65 20 And to reduce
14a50 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 6d 65 the number of me
14a60 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 mory allocations
14a70 2c 20 73 6f 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 , sometimes.** t
14a80 77 6f 20 6f 72 20 6d 6f 72 65 20 45 78 70 72 20 wo or more Expr
14a90 6f 62 6a 65 63 74 73 20 77 69 6c 6c 20 62 65 20 objects will be
14aa0 73 74 6f 72 65 64 20 69 6e 20 61 20 73 69 6e 67 stored in a sing
14ab0 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 le memory alloca
14ac0 74 69 6f 6e 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 tion,.** togethe
14ad0 72 20 77 69 74 68 20 45 78 70 72 2e 7a 54 6f 6b r with Expr.zTok
14ae0 65 6e 20 73 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a en strings..**.*
14af0 2a 20 49 66 20 74 68 65 20 45 50 5f 52 65 64 75 * If the EP_Redu
14b00 63 65 64 20 61 6e 64 20 45 50 5f 54 6f 6b 65 6e ced and EP_Token
14b10 4f 6e 6c 79 20 66 6c 61 67 73 20 61 72 65 20 73 Only flags are s
14b20 65 74 20 77 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 et when.** an Ex
14b30 70 72 20 6f 62 6a 65 63 74 20 69 73 20 74 72 75 pr object is tru
14b40 6e 63 61 74 65 64 2e 20 20 57 68 65 6e 20 45 50 ncated. When EP
14b50 5f 52 65 64 75 63 65 64 20 69 73 20 73 65 74 2c _Reduced is set,
14b60 20 74 68 65 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 then all.** the
14b70 20 63 68 69 6c 64 20 45 78 70 72 20 6f 62 6a 65 child Expr obje
14b80 63 74 73 20 69 6e 20 74 68 65 20 45 78 70 72 2e cts in the Expr.
14b90 70 4c 65 66 74 20 61 6e 64 20 45 78 70 72 2e 70 pLeft and Expr.p
14ba0 52 69 67 68 74 20 73 75 62 74 72 65 65 73 0a 2a Right subtrees.*
14bb0 2a 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 * are contained
14bc0 77 69 74 68 69 6e 20 74 68 65 20 73 61 6d 65 20 within the same
14bd0 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f memory allocatio
14be0 6e 2e 20 20 4e 6f 74 65 2c 20 68 6f 77 65 76 65 n. Note, howeve
14bf0 72 2c 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 73 r, that.** the s
14c00 75 62 74 72 65 65 73 20 69 6e 20 45 78 70 72 2e ubtrees in Expr.
14c10 78 2e 70 4c 69 73 74 20 6f 72 20 45 78 70 72 2e x.pList or Expr.
14c20 78 2e 70 53 65 6c 65 63 74 20 61 72 65 20 61 6c x.pSelect are al
14c30 77 61 79 73 20 73 65 70 61 72 61 74 65 6c 79 0a ways separately.
14c40 2a 2a 20 61 6c 6c 6f 63 61 74 65 64 2c 20 72 65 ** allocated, re
14c50 67 61 72 64 6c 65 73 73 20 6f 66 20 77 68 65 74 gardless of whet
14c60 68 65 72 20 6f 72 20 6e 6f 74 20 45 50 5f 52 65 her or not EP_Re
14c70 64 75 63 65 64 20 69 73 20 73 65 74 2e 0a 2a 2f duced is set..*/
14c80 0a 73 74 72 75 63 74 20 45 78 70 72 20 7b 0a 20 .struct Expr {.
14c90 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 u8 op;
14ca0 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 65 72 61 /* Opera
14cb0 74 69 6f 6e 20 70 65 72 66 6f 72 6d 65 64 20 62 tion performed b
14cc0 79 20 74 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 y this node */.
14cd0 20 63 68 61 72 20 61 66 66 69 6e 69 74 79 3b 20 char affinity;
14ce0 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 61 /* The a
14cf0 66 66 69 6e 69 74 79 20 6f 66 20 74 68 65 20 63 ffinity of the c
14d00 6f 6c 75 6d 6e 20 6f 72 20 30 20 69 66 20 6e 6f olumn or 0 if no
14d10 74 20 61 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 t a column */.
14d20 75 33 32 20 66 6c 61 67 73 3b 20 20 20 20 20 20 u32 flags;
14d30 20 20 20 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 /* Variou
14d40 73 20 66 6c 61 67 73 2e 20 20 45 50 5f 2a 20 53 s flags. EP_* S
14d50 65 65 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 75 6e ee below */. un
14d60 69 6f 6e 20 7b 0a 20 20 20 20 63 68 61 72 20 2a ion {. char *
14d70 7a 54 6f 6b 65 6e 3b 20 20 20 20 20 20 20 20 20 zToken;
14d80 20 2f 2a 20 54 6f 6b 65 6e 20 76 61 6c 75 65 2e /* Token value.
14d90 20 5a 65 72 6f 20 74 65 72 6d 69 6e 61 74 65 64 Zero terminated
14da0 20 61 6e 64 20 64 65 71 75 6f 74 65 64 20 2a 2f and dequoted */
14db0 0a 20 20 20 20 69 6e 74 20 69 56 61 6c 75 65 3b . int iValue;
14dc0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
14dd0 6f 6e 2d 6e 65 67 61 74 69 76 65 20 69 6e 74 65 on-negative inte
14de0 67 65 72 20 76 61 6c 75 65 20 69 66 20 45 50 5f ger value if EP_
14df0 49 6e 74 56 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 IntValue */. }
14e00 75 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 u;.. /* If the
14e10 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 EP_TokenOnly fla
14e20 67 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 20 g is set in the
14e30 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c Expr.flags mask,
14e40 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 then no. ** sp
14e50 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 ace is allocated
14e60 20 66 6f 72 20 74 68 65 20 66 69 65 6c 64 73 20 for the fields
14e70 62 65 6c 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 below this point
14e80 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a . An attempt to.
14e90 20 20 2a 2a 20 61 63 63 65 73 73 20 74 68 65 6d ** access them
14ea0 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 will result in
14eb0 61 20 73 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 a segfault or ma
14ec0 6c 66 75 6e 63 74 69 6f 6e 2e 20 0a 20 20 2a 2a lfunction. . **
14ed0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14ee0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14ef0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14f00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14f10 2a 2a 2a 2f 0a 0a 20 20 45 78 70 72 20 2a 70 4c ***/.. Expr *pL
14f20 65 66 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f eft; /
14f30 2a 20 4c 65 66 74 20 73 75 62 6e 6f 64 65 20 2a * Left subnode *
14f40 2f 0a 20 20 45 78 70 72 20 2a 70 52 69 67 68 74 /. Expr *pRight
14f50 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 69 ; /* Ri
14f60 67 68 74 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 ght subnode */.
14f70 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 45 78 70 union {. Exp
14f80 72 4c 69 73 74 20 2a 70 4c 69 73 74 3b 20 20 20 rList *pList;
14f90 20 20 2f 2a 20 6f 70 20 3d 20 49 4e 2c 20 45 58 /* op = IN, EX
14fa0 49 53 54 53 2c 20 53 45 4c 45 43 54 2c 20 43 41 ISTS, SELECT, CA
14fb0 53 45 2c 20 46 55 4e 43 54 49 4f 4e 2c 20 42 45 SE, FUNCTION, BE
14fc0 54 57 45 45 4e 20 2a 2f 0a 20 20 20 20 53 65 6c TWEEN */. Sel
14fd0 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 ect *pSelect;
14fe0 20 20 2f 2a 20 45 50 5f 78 49 73 53 65 6c 65 63 /* EP_xIsSelec
14ff0 74 20 61 6e 64 20 6f 70 20 3d 20 49 4e 2c 20 45 t and op = IN, E
15000 58 49 53 54 53 2c 20 53 45 4c 45 43 54 20 2a 2f XISTS, SELECT */
15010 0a 20 20 7d 20 78 3b 0a 0a 20 20 2f 2a 20 49 66 . } x;.. /* If
15020 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 the EP_Reduced
15030 66 6c 61 67 20 69 73 20 73 65 74 20 69 6e 20 74 flag is set in t
15040 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 he Expr.flags ma
15050 73 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a sk, then no. **
15060 20 73 70 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 space is alloca
15070 74 65 64 20 66 6f 72 20 74 68 65 20 66 69 65 6c ted for the fiel
15080 64 73 20 62 65 6c 6f 77 20 74 68 69 73 20 70 6f ds below this po
15090 69 6e 74 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 int. An attempt
150a0 74 6f 0a 20 20 2a 2a 20 61 63 63 65 73 73 20 74 to. ** access t
150b0 68 65 6d 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 hem will result
150c0 69 6e 20 61 20 73 65 67 66 61 75 6c 74 20 6f 72 in a segfault or
150d0 20 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 malfunction..
150e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
150f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15100 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15110 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15120 2a 2a 2a 2a 2a 2f 0a 0a 23 69 66 20 53 51 4c 49 *****/..#if SQLI
15130 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 TE_MAX_EXPR_DEPT
15140 48 3e 30 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 H>0. int nHeigh
15150 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
15160 48 65 69 67 68 74 20 6f 66 20 74 68 65 20 74 72 Height of the tr
15170 65 65 20 68 65 61 64 65 64 20 62 79 20 74 68 69 ee headed by thi
15180 73 20 6e 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 s node */.#endif
15190 0a 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 . int iTable;
151a0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f /* TK_
151b0 43 4f 4c 55 4d 4e 3a 20 63 75 72 73 6f 72 20 6e COLUMN: cursor n
151c0 75 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 20 68 umber of table h
151d0 6f 6c 64 69 6e 67 20 63 6f 6c 75 6d 6e 0a 20 20 olding column.
151e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
151f0 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 52 45 47 ** TK_REG
15200 49 53 54 45 52 3a 20 72 65 67 69 73 74 65 72 20 ISTER: register
15210 6e 75 6d 62 65 72 0a 20 20 20 20 20 20 20 20 20 number.
15220 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15230 2a 2a 20 54 4b 5f 54 52 49 47 47 45 52 3a 20 31 ** TK_TRIGGER: 1
15240 20 2d 3e 20 6e 65 77 2c 20 30 20 2d 3e 20 6f 6c -> new, 0 -> ol
15250 64 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 d.
15260 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 45 50 ** EP
15270 5f 55 6e 6c 69 6b 65 6c 79 3a 20 20 31 33 34 32 _Unlikely: 1342
15280 31 37 37 32 38 20 74 69 6d 65 73 20 6c 69 6b 65 17728 times like
15290 6c 69 68 6f 6f 64 20 2a 2f 0a 20 20 79 6e 56 61 lihood */. ynVa
152a0 72 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 r iColumn;
152b0 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a /* TK_COLUMN:
152c0 20 63 6f 6c 75 6d 6e 20 69 6e 64 65 78 2e 20 20 column index.
152d0 2d 31 20 66 6f 72 20 72 6f 77 69 64 2e 0a 20 20 -1 for rowid..
152e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
152f0 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 56 41 52 ** TK_VAR
15300 49 41 42 4c 45 3a 20 76 61 72 69 61 62 6c 65 20 IABLE: variable
15310 6e 75 6d 62 65 72 20 28 61 6c 77 61 79 73 20 3e number (always >
15320 3d 20 31 29 2e 20 2a 2f 0a 20 20 69 31 36 20 69 = 1). */. i16 i
15330 41 67 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Agg;
15340 20 20 2f 2a 20 57 68 69 63 68 20 65 6e 74 72 79 /* Which entry
15350 20 69 6e 20 70 41 67 67 49 6e 66 6f 2d 3e 61 43 in pAggInfo->aC
15360 6f 6c 5b 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 5b ol[] or ->aFunc[
15370 5d 20 2a 2f 0a 20 20 69 31 36 20 69 52 69 67 68 ] */. i16 iRigh
15380 74 4a 6f 69 6e 54 61 62 6c 65 3b 20 20 20 2f 2a tJoinTable; /*
15390 20 49 66 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 2c If EP_FromJoin,
153a0 20 74 68 65 20 72 69 67 68 74 20 74 61 62 6c 65 the right table
153b0 20 6f 66 20 74 68 65 20 6a 6f 69 6e 20 2a 2f 0a of the join */.
153c0 20 20 75 38 20 6f 70 32 3b 20 20 20 20 20 20 20 u8 op2;
153d0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 52 /* TK_R
153e0 45 47 49 53 54 45 52 3a 20 6f 72 69 67 69 6e 61 EGISTER: origina
153f0 6c 20 76 61 6c 75 65 20 6f 66 20 45 78 70 72 2e l value of Expr.
15400 6f 70 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 op.
15410 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 ** T
15420 4b 5f 43 4f 4c 55 4d 4e 3a 20 74 68 65 20 76 61 K_COLUMN: the va
15430 6c 75 65 20 6f 66 20 70 35 20 66 6f 72 20 4f 50 lue of p5 for OP
15440 5f 43 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 _Column.
15450 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15460 20 2a 2a 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 ** TK_AGG_FUNCT
15470 49 4f 4e 3a 20 6e 65 73 74 69 6e 67 20 64 65 70 ION: nesting dep
15480 74 68 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f 20 th */. AggInfo
15490 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 20 20 2f *pAggInfo; /
154a0 2a 20 55 73 65 64 20 62 79 20 54 4b 5f 41 47 47 * Used by TK_AGG
154b0 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 54 4b 5f 41 _COLUMN and TK_A
154c0 47 47 5f 46 55 4e 43 54 49 4f 4e 20 2a 2f 0a 20 GG_FUNCTION */.
154d0 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 Table *pTab;
154e0 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
154f0 20 66 6f 72 20 54 4b 5f 43 4f 4c 55 4d 4e 20 65 for TK_COLUMN e
15500 78 70 72 65 73 73 69 6f 6e 73 2e 20 2a 2f 0a 7d xpressions. */.}
15510 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c ;../*.** The fol
15520 6c 6f 77 69 6e 67 20 61 72 65 20 74 68 65 20 6d lowing are the m
15530 65 61 6e 69 6e 67 73 20 6f 66 20 62 69 74 73 20 eanings of bits
15540 69 6e 20 74 68 65 20 45 78 70 72 2e 66 6c 61 67 in the Expr.flag
15550 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 s field..*/.#def
15560 69 6e 65 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 ine EP_FromJoin
15570 20 30 78 30 30 30 30 30 31 20 2f 2a 20 4f 72 69 0x000001 /* Ori
15580 67 69 6e 61 74 65 73 20 69 6e 20 4f 4e 2f 55 53 ginates in ON/US
15590 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 6f 75 ING clause of ou
155a0 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 ter join */.#def
155b0 69 6e 65 20 45 50 5f 41 67 67 20 20 20 20 20 20 ine EP_Agg
155c0 20 30 78 30 30 30 30 30 32 20 2f 2a 20 43 6f 6e 0x000002 /* Con
155d0 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 tains one or mor
155e0 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 e aggregate func
155f0 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 tions */.#define
15600 20 45 50 5f 52 65 73 6f 6c 76 65 64 20 20 30 78 EP_Resolved 0x
15610 30 30 30 30 30 34 20 2f 2a 20 49 44 73 20 68 61 000004 /* IDs ha
15620 76 65 20 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 ve been resolved
15630 20 74 6f 20 43 4f 4c 55 4d 4e 73 20 2a 2f 0a 23 to COLUMNs */.#
15640 64 65 66 69 6e 65 20 45 50 5f 45 72 72 6f 72 20 define EP_Error
15650 20 20 20 20 30 78 30 30 30 30 30 38 20 2f 2a 20 0x000008 /*
15660 45 78 70 72 65 73 73 69 6f 6e 20 63 6f 6e 74 61 Expression conta
15670 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 ins one or more
15680 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e errors */.#defin
15690 65 20 45 50 5f 44 69 73 74 69 6e 63 74 20 20 30 e EP_Distinct 0
156a0 78 30 30 30 30 31 30 20 2f 2a 20 41 67 67 72 65 x000010 /* Aggre
156b0 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 gate function wi
156c0 74 68 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 th DISTINCT keyw
156d0 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ord */.#define E
156e0 50 5f 56 61 72 53 65 6c 65 63 74 20 30 78 30 30 P_VarSelect 0x00
156f0 30 30 32 30 20 2f 2a 20 70 53 65 6c 65 63 74 20 0020 /* pSelect
15700 69 73 20 63 6f 72 72 65 6c 61 74 65 64 2c 20 6e is correlated, n
15710 6f 74 20 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a 23 ot constant */.#
15720 64 65 66 69 6e 65 20 45 50 5f 44 62 6c 51 75 6f define EP_DblQuo
15730 74 65 64 20 30 78 30 30 30 30 34 30 20 2f 2a 20 ted 0x000040 /*
15740 74 6f 6b 65 6e 2e 7a 20 77 61 73 20 6f 72 69 67 token.z was orig
15750 69 6e 61 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 20 inally in "..."
15760 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 6e */.#define EP_In
15770 66 69 78 46 75 6e 63 20 30 78 30 30 30 30 38 30 fixFunc 0x000080
15780 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 6e 20 /* True for an
15790 69 6e 66 69 78 20 66 75 6e 63 74 69 6f 6e 3a 20 infix function:
157a0 4c 49 4b 45 2c 20 47 4c 4f 42 2c 20 65 74 63 20 LIKE, GLOB, etc
157b0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f */.#define EP_Co
157c0 6c 6c 61 74 65 20 20 20 30 78 30 30 30 31 30 30 llate 0x000100
157d0 20 2f 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 6e /* Tree contain
157e0 73 20 61 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 6f s a TK_COLLATE o
157f0 70 65 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 perator */.#defi
15800 6e 65 20 45 50 5f 47 65 6e 65 72 69 63 20 20 20 ne EP_Generic
15810 30 78 30 30 30 32 30 30 20 2f 2a 20 49 67 6e 6f 0x000200 /* Igno
15820 72 65 20 43 4f 4c 4c 41 54 45 20 6f 72 20 61 66 re COLLATE or af
15830 66 69 6e 69 74 79 20 6f 6e 20 74 68 69 73 20 74 finity on this t
15840 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ree */.#define E
15850 50 5f 49 6e 74 56 61 6c 75 65 20 20 30 78 30 30 P_IntValue 0x00
15860 30 34 30 30 20 2f 2a 20 49 6e 74 65 67 65 72 20 0400 /* Integer
15870 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 20 value contained
15880 69 6e 20 75 2e 69 56 61 6c 75 65 20 2a 2f 0a 23 in u.iValue */.#
15890 64 65 66 69 6e 65 20 45 50 5f 78 49 73 53 65 6c define EP_xIsSel
158a0 65 63 74 20 30 78 30 30 30 38 30 30 20 2f 2a 20 ect 0x000800 /*
158b0 78 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 6c x.pSelect is val
158c0 69 64 20 28 6f 74 68 65 72 77 69 73 65 20 78 2e id (otherwise x.
158d0 70 4c 69 73 74 20 69 73 29 20 2a 2f 0a 23 64 65 pList is) */.#de
158e0 66 69 6e 65 20 45 50 5f 53 6b 69 70 20 20 20 20 fine EP_Skip
158f0 20 20 30 78 30 30 31 30 30 30 20 2f 2a 20 43 4f 0x001000 /* CO
15900 4c 4c 41 54 45 2c 20 41 53 2c 20 6f 72 20 55 4e LLATE, AS, or UN
15910 4c 49 4b 45 4c 59 20 2a 2f 0a 23 64 65 66 69 6e LIKELY */.#defin
15920 65 20 45 50 5f 52 65 64 75 63 65 64 20 20 20 30 e EP_Reduced 0
15930 78 30 30 32 30 30 30 20 2f 2a 20 45 78 70 72 20 x002000 /* Expr
15940 73 74 72 75 63 74 20 45 58 50 52 5f 52 45 44 55 struct EXPR_REDU
15950 43 45 44 53 49 5a 45 20 62 79 74 65 73 20 6f 6e CEDSIZE bytes on
15960 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 ly */.#define EP
15970 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 34 _TokenOnly 0x004
15980 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 75 000 /* Expr stru
15990 63 74 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c ct EXPR_TOKENONL
159a0 59 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 YSIZE bytes only
159b0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 */.#define EP_S
159c0 74 61 74 69 63 20 20 20 20 30 78 30 30 38 30 30 tatic 0x00800
159d0 30 20 2f 2a 20 48 65 6c 64 20 69 6e 20 6d 65 6d 0 /* Held in mem
159e0 6f 72 79 20 6e 6f 74 20 6f 62 74 61 69 6e 65 64 ory not obtained
159f0 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 2a from malloc() *
15a00 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4d 65 6d /.#define EP_Mem
15a10 54 6f 6b 65 6e 20 20 30 78 30 31 30 30 30 30 20 Token 0x010000
15a20 2f 2a 20 4e 65 65 64 20 74 6f 20 73 71 6c 69 74 /* Need to sqlit
15a30 65 33 44 62 46 72 65 65 28 29 20 45 78 70 72 2e e3DbFree() Expr.
15a40 7a 54 6f 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 6e zToken */.#defin
15a50 65 20 45 50 5f 4e 6f 52 65 64 75 63 65 20 20 30 e EP_NoReduce 0
15a60 78 30 32 30 30 30 30 20 2f 2a 20 43 61 6e 6e 6f x020000 /* Canno
15a70 74 20 45 58 50 52 44 55 50 5f 52 45 44 55 43 45 t EXPRDUP_REDUCE
15a80 20 74 68 69 73 20 45 78 70 72 20 2a 2f 0a 23 64 this Expr */.#d
15a90 65 66 69 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 6c efine EP_Unlikel
15aa0 79 20 20 30 78 30 34 30 30 30 30 20 2f 2a 20 75 y 0x040000 /* u
15ab0 6e 6c 69 6b 65 6c 79 28 29 20 6f 72 20 6c 69 6b nlikely() or lik
15ac0 65 6c 69 68 6f 6f 64 28 29 20 66 75 6e 63 74 69 elihood() functi
15ad0 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 on */.#define EP
15ae0 5f 43 6f 6e 73 74 46 75 6e 63 20 30 78 30 38 30 _ConstFunc 0x080
15af0 30 30 30 20 2f 2a 20 4e 6f 64 65 20 69 73 20 61 000 /* Node is a
15b00 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e SQLITE_FUNC_CON
15b10 53 54 41 4e 54 20 66 75 6e 63 74 69 6f 6e 20 2a STANT function *
15b20 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 61 6e /.#define EP_Can
15b30 42 65 4e 75 6c 6c 20 30 78 31 30 30 30 30 30 20 BeNull 0x100000
15b40 2f 2a 20 43 61 6e 20 62 65 20 6e 75 6c 6c 20 64 /* Can be null d
15b50 65 73 70 69 74 65 20 4e 4f 54 20 4e 55 4c 4c 20 espite NOT NULL
15b60 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 constraint */.#d
15b70 65 66 69 6e 65 20 45 50 5f 53 75 62 71 75 65 72 efine EP_Subquer
15b80 79 20 20 30 78 32 30 30 30 30 30 20 2f 2a 20 54 y 0x200000 /* T
15b90 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 54 ree contains a T
15ba0 4b 5f 53 45 4c 45 43 54 20 6f 70 65 72 61 74 6f K_SELECT operato
15bb0 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6d 62 r */../*.** Comb
15bc0 69 6e 61 74 69 6f 6e 73 20 6f 66 20 74 77 6f 20 inations of two
15bd0 6f 72 20 6d 6f 72 65 20 45 50 5f 2a 20 66 6c 61 or more EP_* fla
15be0 67 73 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 gs.*/.#define EP
15bf0 5f 50 72 6f 70 61 67 61 74 65 20 28 45 50 5f 43 _Propagate (EP_C
15c00 6f 6c 6c 61 74 65 7c 45 50 5f 53 75 62 71 75 65 ollate|EP_Subque
15c10 72 79 29 20 2f 2a 20 50 72 6f 70 61 67 61 74 65 ry) /* Propagate
15c20 20 74 68 65 73 65 20 62 69 74 73 20 75 70 20 74 these bits up t
15c30 72 65 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 ree */../*.** Th
15c40 65 73 65 20 6d 61 63 72 6f 73 20 63 61 6e 20 62 ese macros can b
15c50 65 20 75 73 65 64 20 74 6f 20 74 65 73 74 2c 20 e used to test,
15c60 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 20 62 69 set, or clear bi
15c70 74 73 20 69 6e 20 74 68 65 20 0a 2a 2a 20 45 78 ts in the .** Ex
15c80 70 72 2e 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a pr.flags field..
15c90 2a 2f 0a 23 64 65 66 69 6e 65 20 45 78 70 72 48 */.#define ExprH
15ca0 61 73 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 asProperty(E,P)
15cb0 20 20 20 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 (((E)->flags
15cc0 26 28 50 29 29 21 3d 30 29 0a 23 64 65 66 69 6e &(P))!=0).#defin
15cd0 65 20 45 78 70 72 48 61 73 41 6c 6c 50 72 6f 70 e ExprHasAllProp
15ce0 65 72 74 79 28 45 2c 50 29 20 20 28 28 28 45 29 erty(E,P) (((E)
15cf0 2d 3e 66 6c 61 67 73 26 28 50 29 29 3d 3d 28 50 ->flags&(P))==(P
15d00 29 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 53 )).#define ExprS
15d10 65 74 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 etProperty(E,P)
15d20 20 20 20 20 28 45 29 2d 3e 66 6c 61 67 73 7c 3d (E)->flags|=
15d30 28 50 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 (P).#define Expr
15d40 43 6c 65 61 72 50 72 6f 70 65 72 74 79 28 45 2c ClearProperty(E,
15d50 50 29 20 20 20 28 45 29 2d 3e 66 6c 61 67 73 26 P) (E)->flags&
15d60 3d 7e 28 50 29 0a 0a 2f 2a 20 54 68 65 20 45 78 =~(P)../* The Ex
15d70 70 72 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 prSetVVAProperty
15d80 28 29 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 () macro is used
15d90 20 66 6f 72 20 56 65 72 69 66 69 63 61 74 69 6f for Verificatio
15da0 6e 2c 20 56 61 6c 69 64 61 74 69 6f 6e 2c 0a 2a n, Validation,.*
15db0 2a 20 61 6e 64 20 41 63 63 72 65 64 69 74 61 74 * and Accreditat
15dc0 69 6f 6e 20 6f 6e 6c 79 2e 20 20 49 74 20 77 6f ion only. It wo
15dd0 72 6b 73 20 6c 69 6b 65 20 45 78 70 72 53 65 74 rks like ExprSet
15de0 50 72 6f 70 65 72 74 79 28 29 20 64 75 72 69 6e Property() durin
15df0 67 20 56 56 41 0a 2a 2a 20 70 72 6f 63 65 73 73 g VVA.** process
15e00 65 73 20 62 75 74 20 69 73 20 61 20 6e 6f 2d 6f es but is a no-o
15e10 70 20 66 6f 72 20 64 65 6c 69 76 65 72 79 2e 0a p for delivery..
15e20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
15e30 5f 44 45 42 55 47 0a 23 20 64 65 66 69 6e 65 20 _DEBUG.# define
15e40 45 78 70 72 53 65 74 56 56 41 50 72 6f 70 65 72 ExprSetVVAProper
15e50 74 79 28 45 2c 50 29 20 20 28 45 29 2d 3e 66 6c ty(E,P) (E)->fl
15e60 61 67 73 7c 3d 28 50 29 0a 23 65 6c 73 65 0a 23 ags|=(P).#else.#
15e70 20 64 65 66 69 6e 65 20 45 78 70 72 53 65 74 56 define ExprSetV
15e80 56 41 50 72 6f 70 65 72 74 79 28 45 2c 50 29 0a VAProperty(E,P).
15e90 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 #endif../*.** Ma
15ea0 63 72 6f 73 20 74 6f 20 64 65 74 65 72 6d 69 6e cros to determin
15eb0 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 e the number of
15ec0 62 79 74 65 73 20 72 65 71 75 69 72 65 64 20 62 bytes required b
15ed0 79 20 61 20 6e 6f 72 6d 61 6c 20 45 78 70 72 20 y a normal Expr
15ee0 0a 2a 2a 20 73 74 72 75 63 74 2c 20 61 6e 20 45 .** struct, an E
15ef0 78 70 72 20 73 74 72 75 63 74 20 77 69 74 68 20 xpr struct with
15f00 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 66 the EP_Reduced f
15f10 6c 61 67 20 73 65 74 20 69 6e 20 45 78 70 72 2e lag set in Expr.
15f20 66 6c 61 67 73 20 0a 2a 2a 20 61 6e 64 20 61 6e flags .** and an
15f30 20 45 78 70 72 20 73 74 72 75 63 74 20 77 69 74 Expr struct wit
15f40 68 20 74 68 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e h the EP_TokenOn
15f50 6c 79 20 66 6c 61 67 20 73 65 74 2e 0a 2a 2f 0a ly flag set..*/.
15f60 23 64 65 66 69 6e 65 20 45 58 50 52 5f 46 55 4c #define EXPR_FUL
15f70 4c 53 49 5a 45 20 20 20 20 20 20 20 20 20 20 20 LSIZE
15f80 73 69 7a 65 6f 66 28 45 78 70 72 29 20 20 20 20 sizeof(Expr)
15f90 20 20 20 20 20 20 20 2f 2a 20 46 75 6c 6c 20 73 /* Full s
15fa0 69 7a 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ize */.#define E
15fb0 58 50 52 5f 52 45 44 55 43 45 44 53 49 5a 45 20 XPR_REDUCEDSIZE
15fc0 20 20 20 20 20 20 20 6f 66 66 73 65 74 6f 66 28 offsetof(
15fd0 45 78 70 72 2c 69 54 61 62 6c 65 29 20 20 2f 2a Expr,iTable) /*
15fe0 20 43 6f 6d 6d 6f 6e 20 66 65 61 74 75 72 65 73 Common features
15ff0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 */.#define EXPR
16000 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 5a 45 20 20 _TOKENONLYSIZE
16010 20 20 20 20 6f 66 66 73 65 74 6f 66 28 45 78 70 offsetof(Exp
16020 72 2c 70 4c 65 66 74 29 20 20 20 2f 2a 20 46 65 r,pLeft) /* Fe
16030 77 65 72 20 66 65 61 74 75 72 65 73 20 2a 2f 0a wer features */.
16040 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 73 20 70 61 73 ./*.** Flags pas
16050 73 65 64 20 74 6f 20 74 68 65 20 73 71 6c 69 74 sed to the sqlit
16060 65 33 45 78 70 72 44 75 70 28 29 20 66 75 6e 63 e3ExprDup() func
16070 74 69 6f 6e 2e 20 53 65 65 20 74 68 65 20 68 65 tion. See the he
16080 61 64 65 72 20 63 6f 6d 6d 65 6e 74 20 0a 2a 2a ader comment .**
16090 20 61 62 6f 76 65 20 73 71 6c 69 74 65 33 45 78 above sqlite3Ex
160a0 70 72 44 75 70 28 29 20 66 6f 72 20 64 65 74 61 prDup() for deta
160b0 69 6c 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ils..*/.#define
160c0 45 58 50 52 44 55 50 5f 52 45 44 55 43 45 20 20 EXPRDUP_REDUCE
160d0 20 20 20 20 20 20 20 30 78 30 30 30 31 20 20 2f 0x0001 /
160e0 2a 20 55 73 65 64 20 72 65 64 75 63 65 64 2d 73 * Used reduced-s
160f0 69 7a 65 20 45 78 70 72 20 6e 6f 64 65 73 20 2a ize Expr nodes *
16100 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 /../*.** A list
16110 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 2e 20 of expressions.
16120 20 45 61 63 68 20 65 78 70 72 65 73 73 69 6f 6e Each expression
16130 20 6d 61 79 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 may optionally
16140 68 61 76 65 20 61 0a 2a 2a 20 6e 61 6d 65 2e 20 have a.** name.
16150 20 41 6e 20 65 78 70 72 2f 6e 61 6d 65 20 63 6f An expr/name co
16160 6d 62 69 6e 61 74 69 6f 6e 20 63 61 6e 20 62 65 mbination can be
16170 20 75 73 65 64 20 69 6e 20 73 65 76 65 72 61 6c used in several
16180 20 77 61 79 73 2c 20 73 75 63 68 0a 2a 2a 20 61 ways, such.** a
16190 73 20 74 68 65 20 6c 69 73 74 20 6f 66 20 22 65 s the list of "e
161a0 78 70 72 20 41 53 20 49 44 22 20 66 69 65 6c 64 xpr AS ID" field
161b0 73 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 20 22 53 s following a "S
161c0 45 4c 45 43 54 22 20 6f 72 20 69 6e 20 74 68 65 ELECT" or in the
161d0 0a 2a 2a 20 6c 69 73 74 20 6f 66 20 22 49 44 20 .** list of "ID
161e0 3d 20 65 78 70 72 22 20 69 74 65 6d 73 20 69 6e = expr" items in
161f0 20 61 6e 20 55 50 44 41 54 45 2e 20 20 41 20 6c an UPDATE. A l
16200 69 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 6f ist of expressio
16210 6e 73 20 63 61 6e 0a 2a 2a 20 61 6c 73 6f 20 62 ns can.** also b
16220 65 20 75 73 65 64 20 61 73 20 74 68 65 20 61 72 e used as the ar
16230 67 75 6d 65 6e 74 20 74 6f 20 61 20 66 75 6e 63 gument to a func
16240 74 69 6f 6e 2c 20 69 6e 20 77 68 69 63 68 20 63 tion, in which c
16250 61 73 65 20 74 68 65 20 61 2e 7a 4e 61 6d 65 0a ase the a.zName.
16260 2a 2a 20 66 69 65 6c 64 20 69 73 20 6e 6f 74 20 ** field is not
16270 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 used..**.** By d
16280 65 66 61 75 6c 74 20 74 68 65 20 45 78 70 72 2e efault the Expr.
16290 7a 53 70 61 6e 20 66 69 65 6c 64 20 68 6f 6c 64 zSpan field hold
162a0 73 20 61 20 68 75 6d 61 6e 2d 72 65 61 64 61 62 s a human-readab
162b0 6c 65 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f le description o
162c0 66 0a 2a 2a 20 74 68 65 20 65 78 70 72 65 73 73 f.** the express
162d0 69 6f 6e 20 74 68 61 74 20 69 73 20 75 73 65 64 ion that is used
162e0 20 69 6e 20 74 68 65 20 67 65 6e 65 72 61 74 69 in the generati
162f0 6f 6e 20 6f 66 20 65 72 72 6f 72 20 6d 65 73 73 on of error mess
16300 61 67 65 73 20 61 6e 64 0a 2a 2a 20 63 6f 6c 75 ages and.** colu
16310 6d 6e 20 6c 61 62 65 6c 73 2e 20 20 49 6e 20 74 mn labels. In t
16320 68 69 73 20 63 61 73 65 2c 20 45 78 70 72 2e 7a his case, Expr.z
16330 53 70 61 6e 20 69 73 20 74 79 70 69 63 61 6c 6c Span is typicall
16340 79 20 74 68 65 20 74 65 78 74 20 6f 66 20 61 0a y the text of a.
16350 2a 2a 20 63 6f 6c 75 6d 6e 20 65 78 70 72 65 73 ** column expres
16360 73 69 6f 6e 20 61 73 20 69 74 20 65 78 69 73 74 sion as it exist
16370 73 20 69 6e 20 61 20 53 45 4c 45 43 54 20 73 74 s in a SELECT st
16380 61 74 65 6d 65 6e 74 2e 20 20 48 6f 77 65 76 65 atement. Howeve
16390 72 2c 20 69 66 0a 2a 2a 20 74 68 65 20 62 53 70 r, if.** the bSp
163a0 61 6e 49 73 54 61 62 20 66 6c 61 67 20 69 73 20 anIsTab flag is
163b0 73 65 74 2c 20 74 68 65 6e 20 7a 53 70 61 6e 20 set, then zSpan
163c0 69 73 20 6f 76 65 72 6c 6f 61 64 65 64 20 74 6f is overloaded to
163d0 20 6d 65 61 6e 20 74 68 65 20 6e 61 6d 65 0a 2a mean the name.*
163e0 2a 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 * of the result
163f0 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 20 66 6f column in the fo
16400 72 6d 3a 20 44 41 54 41 42 41 53 45 2e 54 41 42 rm: DATABASE.TAB
16410 4c 45 2e 43 4f 4c 55 4d 4e 2e 20 20 54 68 69 73 LE.COLUMN. This
16420 20 6c 61 74 65 72 0a 2a 2a 20 66 6f 72 6d 20 69 later.** form i
16430 73 20 75 73 65 64 20 66 6f 72 20 6e 61 6d 65 20 s used for name
16440 72 65 73 6f 6c 75 74 69 6f 6e 20 77 69 74 68 20 resolution with
16450 6e 65 73 74 65 64 20 46 52 4f 4d 20 63 6c 61 75 nested FROM clau
16460 73 65 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 45 ses..*/.struct E
16470 78 70 72 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 xprList {. int
16480 6e 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 nExpr;
16490 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
164a0 65 78 70 72 65 73 73 69 6f 6e 73 20 6f 6e 20 74 expressions on t
164b0 68 65 20 6c 69 73 74 20 2a 2f 0a 20 20 73 74 72 he list */. str
164c0 75 63 74 20 45 78 70 72 4c 69 73 74 5f 69 74 65 uct ExprList_ite
164d0 6d 20 7b 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 m { /* For each
164e0 65 78 70 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 expression in th
164f0 65 20 6c 69 73 74 20 2a 2f 0a 20 20 20 20 45 78 e list */. Ex
16500 70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 pr *pExpr;
16510 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6c 69 73 /* The lis
16520 74 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 t of expressions
16530 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e */. char *zN
16540 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
16550 2f 2a 20 54 6f 6b 65 6e 20 61 73 73 6f 63 69 61 /* Token associa
16560 74 65 64 20 77 69 74 68 20 74 68 69 73 20 65 78 ted with this ex
16570 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 pression */.
16580 63 68 61 72 20 2a 7a 53 70 61 6e 3b 20 20 20 20 char *zSpan;
16590 20 20 20 20 20 20 20 20 2f 2a 20 4f 72 69 67 69 /* Origi
165a0 6e 61 6c 20 74 65 78 74 20 6f 66 20 74 68 65 20 nal text of the
165b0 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 expression */.
165c0 20 20 75 38 20 73 6f 72 74 4f 72 64 65 72 3b 20 u8 sortOrder;
165d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 20 66 /* 1 f
165e0 6f 72 20 44 45 53 43 20 6f 72 20 30 20 66 6f 72 or DESC or 0 for
165f0 20 41 53 43 20 2a 2f 0a 20 20 20 20 75 6e 73 69 ASC */. unsi
16600 67 6e 65 64 20 64 6f 6e 65 20 3a 31 3b 20 20 20 gned done :1;
16610 20 20 20 20 2f 2a 20 41 20 66 6c 61 67 20 74 6f /* A flag to
16620 20 69 6e 64 69 63 61 74 65 20 77 68 65 6e 20 70 indicate when p
16630 72 6f 63 65 73 73 69 6e 67 20 69 73 20 66 69 6e rocessing is fin
16640 69 73 68 65 64 20 2a 2f 0a 20 20 20 20 75 6e 73 ished */. uns
16650 69 67 6e 65 64 20 62 53 70 61 6e 49 73 54 61 62 igned bSpanIsTab
16660 20 3a 31 3b 20 2f 2a 20 7a 53 70 61 6e 20 68 6f :1; /* zSpan ho
16670 6c 64 73 20 44 42 2e 54 41 42 4c 45 2e 43 4f 4c lds DB.TABLE.COL
16680 55 4d 4e 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 UMN */. unsig
16690 6e 65 64 20 72 65 75 73 61 62 6c 65 20 3a 31 3b ned reusable :1;
166a0 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 /* Constant e
166b0 78 70 72 65 73 73 69 6f 6e 20 69 73 20 72 65 75 xpression is reu
166c0 73 61 62 6c 65 20 2a 2f 0a 20 20 20 20 75 6e 69 sable */. uni
166d0 6f 6e 20 7b 0a 20 20 20 20 20 20 73 74 72 75 63 on {. struc
166e0 74 20 7b 0a 20 20 20 20 20 20 20 20 75 31 36 20 t {. u16
166f0 69 4f 72 64 65 72 42 79 43 6f 6c 3b 20 20 20 20 iOrderByCol;
16700 20 20 2f 2a 20 46 6f 72 20 4f 52 44 45 52 20 42 /* For ORDER B
16710 59 2c 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 Y, column number
16720 20 69 6e 20 72 65 73 75 6c 74 20 73 65 74 20 2a in result set *
16730 2f 0a 20 20 20 20 20 20 20 20 75 31 36 20 69 41 /. u16 iA
16740 6c 69 61 73 3b 20 20 20 20 20 20 20 20 20 20 20 lias;
16750 2f 2a 20 49 6e 64 65 78 20 69 6e 74 6f 20 50 61 /* Index into Pa
16760 72 73 65 2e 61 41 6c 69 61 73 5b 5d 20 66 6f 72 rse.aAlias[] for
16770 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 20 20 20 zName */.
16780 7d 20 78 3b 0a 20 20 20 20 20 20 69 6e 74 20 69 } x;. int i
16790 43 6f 6e 73 74 45 78 70 72 52 65 67 3b 20 20 20 ConstExprReg;
167a0 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 20 69 /* Register i
167b0 6e 20 77 68 69 63 68 20 45 78 70 72 20 76 61 6c n which Expr val
167c0 75 65 20 69 73 20 63 61 63 68 65 64 20 2a 2f 0a ue is cached */.
167d0 20 20 20 20 7d 20 75 3b 0a 20 20 7d 20 2a 61 3b } u;. } *a;
167e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
167f0 20 20 2f 2a 20 41 6c 6c 6f 63 20 61 20 70 6f 77 /* Alloc a pow
16800 65 72 20 6f 66 20 74 77 6f 20 67 72 65 61 74 65 er of two greate
16810 72 20 6f 72 20 65 71 75 61 6c 20 74 6f 20 6e 45 r or equal to nE
16820 78 70 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a xpr */.};../*.**
16830 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
16840 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 69 this structure i
16850 73 20 75 73 65 64 20 62 79 20 74 68 65 20 70 61 s used by the pa
16860 72 73 65 72 20 74 6f 20 72 65 63 6f 72 64 20 62 rser to record b
16870 6f 74 68 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 oth.** the parse
16880 20 74 72 65 65 20 66 6f 72 20 61 6e 20 65 78 70 tree for an exp
16890 72 65 73 73 69 6f 6e 20 61 6e 64 20 74 68 65 20 ression and the
168a0 73 70 61 6e 20 6f 66 20 69 6e 70 75 74 20 74 65 span of input te
168b0 78 74 20 66 6f 72 20 61 6e 0a 2a 2a 20 65 78 70 xt for an.** exp
168c0 72 65 73 73 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 ression..*/.stru
168d0 63 74 20 45 78 70 72 53 70 61 6e 20 7b 0a 20 20 ct ExprSpan {.
168e0 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 Expr *pExpr;
168f0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 65 78 70 /* The exp
16900 72 65 73 73 69 6f 6e 20 70 61 72 73 65 20 74 72 ression parse tr
16910 65 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 ee */. const ch
16920 61 72 20 2a 7a 53 74 61 72 74 3b 20 20 20 2f 2a ar *zStart; /*
16930 20 46 69 72 73 74 20 63 68 61 72 61 63 74 65 72 First character
16940 20 6f 66 20 69 6e 70 75 74 20 74 65 78 74 20 2a of input text *
16950 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
16960 7a 45 6e 64 3b 20 20 20 20 20 2f 2a 20 4f 6e 65 zEnd; /* One
16970 20 63 68 61 72 61 63 74 65 72 20 70 61 73 74 20 character past
16980 74 68 65 20 65 6e 64 20 6f 66 20 69 6e 70 75 74 the end of input
16990 20 74 65 78 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a text */.};../*.
169a0 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
169b0 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
169c0 20 63 61 6e 20 68 6f 6c 64 20 61 20 73 69 6d 70 can hold a simp
169d0 6c 65 20 6c 69 73 74 20 6f 66 20 69 64 65 6e 74 le list of ident
169e0 69 66 69 65 72 73 2c 0a 2a 2a 20 73 75 63 68 20 ifiers,.** such
169f0 61 73 20 74 68 65 20 6c 69 73 74 20 22 61 2c 62 as the list "a,b
16a00 2c 63 22 20 69 6e 20 74 68 65 20 66 6f 6c 6c 6f ,c" in the follo
16a10 77 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 73 3a wing statements:
16a20 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 49 4e 53 45 .**.** INSE
16a30 52 54 20 49 4e 54 4f 20 74 28 61 2c 62 2c 63 29 RT INTO t(a,b,c)
16a40 20 56 41 4c 55 45 53 20 2e 2e 2e 3b 0a 2a 2a 20 VALUES ...;.**
16a50 20 20 20 20 20 43 52 45 41 54 45 20 49 4e 44 45 CREATE INDE
16a60 58 20 69 64 78 20 4f 4e 20 74 28 61 2c 62 2c 63 X idx ON t(a,b,c
16a70 29 3b 0a 2a 2a 20 20 20 20 20 20 43 52 45 41 54 );.** CREAT
16a80 45 20 54 52 49 47 47 45 52 20 74 72 69 67 20 42 E TRIGGER trig B
16a90 45 46 4f 52 45 20 55 50 44 41 54 45 20 4f 4e 20 EFORE UPDATE ON
16aa0 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 3b 0a 2a 2a t(a,b,c) ...;.**
16ab0 0a 2a 2a 20 54 68 65 20 49 64 4c 69 73 74 2e 61 .** The IdList.a
16ac0 2e 69 64 78 20 66 69 65 6c 64 20 69 73 20 75 73 .idx field is us
16ad0 65 64 20 77 68 65 6e 20 74 68 65 20 49 64 4c 69 ed when the IdLi
16ae0 73 74 20 72 65 70 72 65 73 65 6e 74 73 20 74 68 st represents th
16af0 65 20 6c 69 73 74 20 6f 66 0a 2a 2a 20 63 6f 6c e list of.** col
16b00 75 6d 6e 20 6e 61 6d 65 73 20 61 66 74 65 72 20 umn names after
16b10 61 20 74 61 62 6c 65 20 6e 61 6d 65 20 69 6e 20 a table name in
16b20 61 6e 20 49 4e 53 45 52 54 20 73 74 61 74 65 6d an INSERT statem
16b30 65 6e 74 2e 20 20 49 6e 20 74 68 65 20 73 74 61 ent. In the sta
16b40 74 65 6d 65 6e 74 0a 2a 2a 0a 2a 2a 20 20 20 20 tement.**.**
16b50 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 INSERT INTO t(a
16b60 2c 62 2c 63 29 20 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 ,b,c) ....**.**
16b70 49 66 20 22 61 22 20 69 73 20 74 68 65 20 6b 2d If "a" is the k-
16b80 74 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 61 62 th column of tab
16b90 6c 65 20 22 74 22 2c 20 74 68 65 6e 20 49 64 4c le "t", then IdL
16ba0 69 73 74 2e 61 5b 30 5d 2e 69 64 78 3d 3d 6b 2e ist.a[0].idx==k.
16bb0 0a 2a 2f 0a 73 74 72 75 63 74 20 49 64 4c 69 73 .*/.struct IdLis
16bc0 74 20 7b 0a 20 20 73 74 72 75 63 74 20 49 64 4c t {. struct IdL
16bd0 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 20 20 63 ist_item {. c
16be0 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
16bf0 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 /* Name of the
16c00 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 identifier */.
16c10 20 20 69 6e 74 20 69 64 78 3b 20 20 20 20 20 20 int idx;
16c20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e 20 /* Index in
16c30 73 6f 6d 65 20 54 61 62 6c 65 2e 61 43 6f 6c 5b some Table.aCol[
16c40 5d 20 6f 66 20 61 20 63 6f 6c 75 6d 6e 20 6e 61 ] of a column na
16c50 6d 65 64 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 7d med zName */. }
16c60 20 2a 61 3b 0a 20 20 69 6e 74 20 6e 49 64 3b 20 *a;. int nId;
16c70 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
16c80 72 20 6f 66 20 69 64 65 6e 74 69 66 69 65 72 73 r of identifiers
16c90 20 6f 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a on the list */.
16ca0 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 62 69 };../*.** The bi
16cb0 74 6d 61 73 6b 20 64 61 74 61 74 79 70 65 20 64 tmask datatype d
16cc0 65 66 69 6e 65 64 20 62 65 6c 6f 77 20 69 73 20 efined below is
16cd0 75 73 65 64 20 66 6f 72 20 76 61 72 69 6f 75 73 used for various
16ce0 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a optimizations..
16cf0 2a 2a 0a 2a 2a 20 43 68 61 6e 67 69 6e 67 20 74 **.** Changing t
16d00 68 69 73 20 66 72 6f 6d 20 61 20 36 34 2d 62 69 his from a 64-bi
16d10 74 20 74 6f 20 61 20 33 32 2d 62 69 74 20 74 79 t to a 32-bit ty
16d20 70 65 20 6c 69 6d 69 74 73 20 74 68 65 20 6e 75 pe limits the nu
16d30 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 61 62 6c 65 mber of.** table
16d40 73 20 69 6e 20 61 20 6a 6f 69 6e 20 74 6f 20 33 s in a join to 3
16d50 32 20 69 6e 73 74 65 61 64 20 6f 66 20 36 34 2e 2 instead of 64.
16d60 20 20 42 75 74 20 69 74 20 61 6c 73 6f 20 72 65 But it also re
16d70 64 75 63 65 73 20 74 68 65 20 73 69 7a 65 0a 2a duces the size.*
16d80 2a 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72 79 * of the library
16d90 20 62 79 20 37 33 38 20 62 79 74 65 73 20 6f 6e by 738 bytes on
16da0 20 69 78 38 36 2e 0a 2a 2f 0a 74 79 70 65 64 65 ix86..*/.typede
16db0 66 20 75 36 34 20 42 69 74 6d 61 73 6b 3b 0a 0a f u64 Bitmask;..
16dc0 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 /*.** The number
16dd0 20 6f 66 20 62 69 74 73 20 69 6e 20 61 20 42 69 of bits in a Bi
16de0 74 6d 61 73 6b 2e 20 20 22 42 4d 53 22 20 6d 65 tmask. "BMS" me
16df0 61 6e 73 20 22 42 69 74 4d 61 73 6b 20 53 69 7a ans "BitMask Siz
16e00 65 22 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 42 e"..*/.#define B
16e10 4d 53 20 20 28 28 69 6e 74 29 28 73 69 7a 65 6f MS ((int)(sizeo
16e20 66 28 42 69 74 6d 61 73 6b 29 2a 38 29 29 0a 0a f(Bitmask)*8))..
16e30 2f 2a 0a 2a 2a 20 41 20 62 69 74 20 69 6e 20 61 /*.** A bit in a
16e40 20 42 69 74 6d 61 73 6b 0a 2a 2f 0a 23 64 65 66 Bitmask.*/.#def
16e50 69 6e 65 20 4d 41 53 4b 42 49 54 28 6e 29 20 20 ine MASKBIT(n)
16e60 20 28 28 28 42 69 74 6d 61 73 6b 29 31 29 3c 3c (((Bitmask)1)<<
16e70 28 6e 29 29 0a 23 64 65 66 69 6e 65 20 4d 41 53 (n)).#define MAS
16e80 4b 42 49 54 33 32 28 6e 29 20 28 28 28 75 6e 73 KBIT32(n) (((uns
16e90 69 67 6e 65 64 20 69 6e 74 29 31 29 3c 3c 28 6e igned int)1)<<(n
16ea0 29 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f ))../*.** The fo
16eb0 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
16ec0 65 20 64 65 73 63 72 69 62 65 73 20 74 68 65 20 e describes the
16ed0 46 52 4f 4d 20 63 6c 61 75 73 65 20 6f 66 20 61 FROM clause of a
16ee0 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e SELECT statemen
16ef0 74 2e 0a 2a 2a 20 45 61 63 68 20 74 61 62 6c 65 t..** Each table
16f00 20 6f 72 20 73 75 62 71 75 65 72 79 20 69 6e 20 or subquery in
16f10 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 the FROM clause
16f20 69 73 20 61 20 73 65 70 61 72 61 74 65 20 65 6c is a separate el
16f30 65 6d 65 6e 74 20 6f 66 0a 2a 2a 20 74 68 65 20 ement of.** the
16f40 53 72 63 4c 69 73 74 2e 61 5b 5d 20 61 72 72 61 SrcList.a[] arra
16f50 79 2e 0a 2a 2a 0a 2a 2a 20 57 69 74 68 20 74 68 y..**.** With th
16f60 65 20 61 64 64 69 74 69 6f 6e 20 6f 66 20 6d 75 e addition of mu
16f70 6c 74 69 70 6c 65 20 64 61 74 61 62 61 73 65 20 ltiple database
16f80 73 75 70 70 6f 72 74 2c 20 74 68 65 20 66 6f 6c support, the fol
16f90 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
16fa0 0a 2a 2a 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 .** can also be
16fb0 75 73 65 64 20 74 6f 20 64 65 73 63 72 69 62 65 used to describe
16fc0 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 74 61 a particular ta
16fd0 62 6c 65 20 73 75 63 68 20 61 73 20 74 68 65 20 ble such as the
16fe0 74 61 62 6c 65 20 74 68 61 74 0a 2a 2a 20 69 73 table that.** is
16ff0 20 6d 6f 64 69 66 69 65 64 20 62 79 20 61 6e 20 modified by an
17000 49 4e 53 45 52 54 2c 20 44 45 4c 45 54 45 2c 20 INSERT, DELETE,
17010 6f 72 20 55 50 44 41 54 45 20 73 74 61 74 65 6d or UPDATE statem
17020 65 6e 74 2e 20 20 49 6e 20 73 74 61 6e 64 61 72 ent. In standar
17030 64 20 53 51 4c 2c 0a 2a 2a 20 73 75 63 68 20 61 d SQL,.** such a
17040 20 74 61 62 6c 65 20 6d 75 73 74 20 62 65 20 61 table must be a
17050 20 73 69 6d 70 6c 65 20 6e 61 6d 65 3a 20 49 44 simple name: ID
17060 2e 20 20 42 75 74 20 69 6e 20 53 51 4c 69 74 65 . But in SQLite
17070 2c 20 74 68 65 20 74 61 62 6c 65 20 63 61 6e 0a , the table can.
17080 2a 2a 20 6e 6f 77 20 62 65 20 69 64 65 6e 74 69 ** now be identi
17090 66 69 65 64 20 62 79 20 61 20 64 61 74 61 62 61 fied by a databa
170a0 73 65 20 6e 61 6d 65 2c 20 61 20 64 6f 74 2c 20 se name, a dot,
170b0 74 68 65 6e 20 74 68 65 20 74 61 62 6c 65 20 6e then the table n
170c0 61 6d 65 3a 20 49 44 2e 49 44 2e 0a 2a 2a 0a 2a ame: ID.ID..**.*
170d0 2a 20 54 68 65 20 6a 6f 69 6e 74 79 70 65 20 73 * The jointype s
170e0 74 61 72 74 73 20 6f 75 74 20 73 68 6f 77 69 6e tarts out showin
170f0 67 20 74 68 65 20 6a 6f 69 6e 20 74 79 70 65 20 g the join type
17100 62 65 74 77 65 65 6e 20 74 68 65 20 63 75 72 72 between the curr
17110 65 6e 74 20 74 61 62 6c 65 0a 2a 2a 20 61 6e 64 ent table.** and
17120 20 74 68 65 20 6e 65 78 74 20 74 61 62 6c 65 20 the next table
17130 6f 6e 20 74 68 65 20 6c 69 73 74 2e 20 20 54 68 on the list. Th
17140 65 20 70 61 72 73 65 72 20 62 75 69 6c 64 73 20 e parser builds
17150 74 68 65 20 6c 69 73 74 20 74 68 69 73 20 77 61 the list this wa
17160 79 2e 0a 2a 2a 20 42 75 74 20 73 71 6c 69 74 65 y..** But sqlite
17170 33 53 72 63 4c 69 73 74 53 68 69 66 74 4a 6f 69 3SrcListShiftJoi
17180 6e 54 79 70 65 28 29 20 6c 61 74 65 72 20 73 68 nType() later sh
17190 69 66 74 73 20 74 68 65 20 6a 6f 69 6e 74 79 70 ifts the jointyp
171a0 65 73 20 73 6f 20 74 68 61 74 20 65 61 63 68 0a es so that each.
171b0 2a 2a 20 6a 6f 69 6e 74 79 70 65 20 65 78 70 72 ** jointype expr
171c0 65 73 73 65 73 20 74 68 65 20 6a 6f 69 6e 20 62 esses the join b
171d0 65 74 77 65 65 6e 20 74 68 65 20 74 61 62 6c 65 etween the table
171e0 20 61 6e 64 20 74 68 65 20 70 72 65 76 69 6f 75 and the previou
171f0 73 20 74 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 s table..**.** I
17200 6e 20 74 68 65 20 63 6f 6c 55 73 65 64 20 66 69 n the colUsed fi
17210 65 6c 64 2c 20 74 68 65 20 68 69 67 68 2d 6f 72 eld, the high-or
17220 64 65 72 20 62 69 74 20 28 62 69 74 20 36 33 29 der bit (bit 63)
17230 20 69 73 20 73 65 74 20 69 66 20 74 68 65 20 74 is set if the t
17240 61 62 6c 65 0a 2a 2a 20 63 6f 6e 74 61 69 6e 73 able.** contains
17250 20 6d 6f 72 65 20 74 68 61 6e 20 36 33 20 63 6f more than 63 co
17260 6c 75 6d 6e 73 20 61 6e 64 20 74 68 65 20 36 34 lumns and the 64
17270 2d 74 68 20 6f 72 20 6c 61 74 65 72 20 63 6f 6c -th or later col
17280 75 6d 6e 20 69 73 20 75 73 65 64 2e 0a 2a 2f 0a umn is used..*/.
17290 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 20 7b struct SrcList {
172a0 0a 20 20 69 6e 74 20 6e 53 72 63 3b 20 20 20 20 . int nSrc;
172b0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
172c0 20 74 61 62 6c 65 73 20 6f 72 20 73 75 62 71 75 tables or subqu
172d0 65 72 69 65 73 20 69 6e 20 74 68 65 20 46 52 4f eries in the FRO
172e0 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 75 33 M clause */. u3
172f0 32 20 6e 41 6c 6c 6f 63 3b 20 20 20 20 20 20 2f 2 nAlloc; /
17300 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 * Number of entr
17310 69 65 73 20 61 6c 6c 6f 63 61 74 65 64 20 69 6e ies allocated in
17320 20 61 5b 5d 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 a[] below */.
17330 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f 69 struct SrcList_i
17340 74 65 6d 20 7b 0a 20 20 20 20 53 63 68 65 6d 61 tem {. Schema
17350 20 2a 70 53 63 68 65 6d 61 3b 20 20 2f 2a 20 53 *pSchema; /* S
17360 63 68 65 6d 61 20 74 6f 20 77 68 69 63 68 20 74 chema to which t
17370 68 69 73 20 69 74 65 6d 20 69 73 20 66 69 78 65 his item is fixe
17380 64 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a d */. char *z
17390 44 61 74 61 62 61 73 65 3b 20 20 2f 2a 20 4e 61 Database; /* Na
173a0 6d 65 20 6f 66 20 64 61 74 61 62 61 73 65 20 68 me of database h
173b0 6f 6c 64 69 6e 67 20 74 68 69 73 20 74 61 62 6c olding this tabl
173c0 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a e */. char *z
173d0 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a 20 4e 61 Name; /* Na
173e0 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 me of the table
173f0 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 41 6c */. char *zAl
17400 69 61 73 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 ias; /* The
17410 22 42 22 20 70 61 72 74 20 6f 66 20 61 20 22 41 "B" part of a "A
17420 20 41 53 20 42 22 20 70 68 72 61 73 65 2e 20 20 AS B" phrase.
17430 7a 4e 61 6d 65 20 69 73 20 74 68 65 20 22 41 22 zName is the "A"
17440 20 2a 2f 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 */. Table *p
17450 54 61 62 3b 20 20 20 20 20 20 2f 2a 20 41 6e 20 Tab; /* An
17460 53 51 4c 20 74 61 62 6c 65 20 63 6f 72 72 65 73 SQL table corres
17470 70 6f 6e 64 69 6e 67 20 74 6f 20 7a 4e 61 6d 65 ponding to zName
17480 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a */. Select *
17490 70 53 65 6c 65 63 74 3b 20 20 2f 2a 20 41 20 53 pSelect; /* A S
174a0 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 20 ELECT statement
174b0 75 73 65 64 20 69 6e 20 70 6c 61 63 65 20 6f 66 used in place of
174c0 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 20 2a 2f a table name */
174d0 0a 20 20 20 20 69 6e 74 20 61 64 64 72 46 69 6c . int addrFil
174e0 6c 53 75 62 3b 20 20 2f 2a 20 41 64 64 72 65 73 lSub; /* Addres
174f0 73 20 6f 66 20 73 75 62 72 6f 75 74 69 6e 65 20 s of subroutine
17500 74 6f 20 6d 61 6e 69 66 65 73 74 20 61 20 73 75 to manifest a su
17510 62 71 75 65 72 79 20 2a 2f 0a 20 20 20 20 69 6e bquery */. in
17520 74 20 72 65 67 52 65 74 75 72 6e 3b 20 20 20 20 t regReturn;
17530 2f 2a 20 52 65 67 69 73 74 65 72 20 68 6f 6c 64 /* Register hold
17540 69 6e 67 20 72 65 74 75 72 6e 20 61 64 64 72 65 ing return addre
17550 73 73 20 6f 66 20 61 64 64 72 46 69 6c 6c 53 75 ss of addrFillSu
17560 62 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 65 67 b */. int reg
17570 52 65 73 75 6c 74 3b 20 20 20 20 2f 2a 20 52 65 Result; /* Re
17580 67 69 73 74 65 72 73 20 68 6f 6c 64 69 6e 67 20 gisters holding
17590 72 65 73 75 6c 74 73 20 6f 66 20 61 20 63 6f 2d results of a co-
175a0 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 20 20 75 routine */. u
175b0 38 20 6a 6f 69 6e 74 79 70 65 3b 20 20 20 20 20 8 jointype;
175c0 20 2f 2a 20 54 79 70 65 20 6f 66 20 6a 6f 69 6e /* Type of join
175d0 20 62 65 74 77 65 65 6e 20 74 68 69 73 20 61 62 between this ab
175e0 6c 65 20 61 6e 64 20 74 68 65 20 70 72 65 76 69 le and the previ
175f0 6f 75 73 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 ous */. unsig
17600 6e 65 64 20 6e 6f 74 49 6e 64 65 78 65 64 20 3a ned notIndexed :
17610 31 3b 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 1; /* True if
17620 20 74 68 65 72 65 20 69 73 20 61 20 4e 4f 54 20 there is a NOT
17630 49 4e 44 45 58 45 44 20 63 6c 61 75 73 65 20 2a INDEXED clause *
17640 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 /. unsigned i
17650 73 43 6f 72 72 65 6c 61 74 65 64 20 3a 31 3b 20 sCorrelated :1;
17660 20 2f 2a 20 54 72 75 65 20 69 66 20 73 75 62 2d /* True if sub-
17670 71 75 65 72 79 20 69 73 20 63 6f 72 72 65 6c 61 query is correla
17680 74 65 64 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 ted */. unsig
17690 6e 65 64 20 76 69 61 43 6f 72 6f 75 74 69 6e 65 ned viaCoroutine
176a0 20 3a 31 3b 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 :1; /* Impleme
176b0 6e 74 65 64 20 61 73 20 61 20 63 6f 2d 72 6f 75 nted as a co-rou
176c0 74 69 6e 65 20 2a 2f 0a 20 20 20 20 75 6e 73 69 tine */. unsi
176d0 67 6e 65 64 20 69 73 52 65 63 75 72 73 69 76 65 gned isRecursive
176e0 20 3a 31 3b 20 20 20 2f 2a 20 54 72 75 65 20 66 :1; /* True f
176f0 6f 72 20 72 65 63 75 72 73 69 76 65 20 72 65 66 or recursive ref
17700 65 72 65 6e 63 65 20 69 6e 20 57 49 54 48 20 2a erence in WITH *
17710 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
17720 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 20 20 _OMIT_EXPLAIN.
17730 20 20 75 38 20 69 53 65 6c 65 63 74 49 64 3b 20 u8 iSelectId;
17740 20 20 20 20 2f 2a 20 49 66 20 70 53 65 6c 65 63 /* If pSelec
17750 74 21 3d 30 2c 20 74 68 65 20 69 64 20 6f 66 20 t!=0, the id of
17760 74 68 65 20 73 75 62 2d 73 65 6c 65 63 74 20 69 the sub-select i
17770 6e 20 45 51 50 20 2a 2f 0a 23 65 6e 64 69 66 0a n EQP */.#endif.
17780 20 20 20 20 69 6e 74 20 69 43 75 72 73 6f 72 3b int iCursor;
17790 20 20 20 20 20 20 2f 2a 20 54 68 65 20 56 44 42 /* The VDB
177a0 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 E cursor number
177b0 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 20 74 used to access t
177c0 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 his table */.
177d0 20 45 78 70 72 20 2a 70 4f 6e 3b 20 20 20 20 20 Expr *pOn;
177e0 20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 63 6c 61 /* The ON cla
177f0 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e 20 2a 2f use of a join */
17800 0a 20 20 20 20 49 64 4c 69 73 74 20 2a 70 55 73 . IdList *pUs
17810 69 6e 67 3b 20 20 20 2f 2a 20 54 68 65 20 55 53 ing; /* The US
17820 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 61 20 ING clause of a
17830 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 69 74 6d join */. Bitm
17840 61 73 6b 20 63 6f 6c 55 73 65 64 3b 20 20 2f 2a ask colUsed; /*
17850 20 42 69 74 20 4e 20 28 31 3c 3c 4e 29 20 73 65 Bit N (1<<N) se
17860 74 20 69 66 20 63 6f 6c 75 6d 6e 20 4e 20 6f 66 t if column N of
17870 20 70 54 61 62 20 69 73 20 75 73 65 64 20 2a 2f pTab is used */
17880 0a 20 20 20 20 63 68 61 72 20 2a 7a 49 6e 64 65 . char *zInde
17890 78 65 64 42 79 3b 20 2f 2a 20 49 64 65 6e 74 69 xedBy; /* Identi
178a0 66 69 65 72 20 66 72 6f 6d 20 22 49 4e 44 45 58 fier from "INDEX
178b0 45 44 20 42 59 20 3c 7a 49 6e 64 65 78 3e 22 20 ED BY <zIndex>"
178c0 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 49 6e clause */. In
178d0 64 65 78 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 dex *pIndex;
178e0 2f 2a 20 49 6e 64 65 78 20 73 74 72 75 63 74 75 /* Index structu
178f0 72 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 re corresponding
17900 20 74 6f 20 7a 49 6e 64 65 78 2c 20 69 66 20 61 to zIndex, if a
17910 6e 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 ny */. } a[1];
17920 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
17930 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 61 63 ne entry for eac
17940 68 20 69 64 65 6e 74 69 66 69 65 72 20 6f 6e 20 h identifier on
17950 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a the list */.};..
17960 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 65 64 20 /*.** Permitted
17970 76 61 6c 75 65 73 20 6f 66 20 74 68 65 20 53 72 values of the Sr
17980 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 cList.a.jointype
17990 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e field.*/.#defin
179a0 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 20 20 30 e JT_INNER 0
179b0 78 30 30 30 31 20 20 20 20 2f 2a 20 41 6e 79 20 x0001 /* Any
179c0 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 20 6f 72 kind of inner or
179d0 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 cross join */.#
179e0 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f 53 53 20 define JT_CROSS
179f0 20 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a 0x0002 /*
17a00 20 45 78 70 6c 69 63 69 74 20 75 73 65 20 6f 66 Explicit use of
17a10 20 74 68 65 20 43 52 4f 53 53 20 6b 65 79 77 6f the CROSS keywo
17a20 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 rd */.#define JT
17a30 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 30 30 30 _NATURAL 0x000
17a40 34 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 4 /* True for
17a50 20 61 20 22 6e 61 74 75 72 61 6c 22 20 6a 6f 69 a "natural" joi
17a60 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f n */.#define JT_
17a70 4c 45 46 54 20 20 20 20 20 20 30 78 30 30 30 38 LEFT 0x0008
17a80 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 75 74 65 /* Left oute
17a90 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e r join */.#defin
17aa0 65 20 4a 54 5f 52 49 47 48 54 20 20 20 20 20 30 e JT_RIGHT 0
17ab0 78 30 30 31 30 20 20 20 20 2f 2a 20 52 69 67 68 x0010 /* Righ
17ac0 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a t outer join */.
17ad0 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 54 45 52 #define JT_OUTER
17ae0 20 20 20 20 20 30 78 30 30 32 30 20 20 20 20 2f 0x0020 /
17af0 2a 20 54 68 65 20 22 4f 55 54 45 52 22 20 6b 65 * The "OUTER" ke
17b00 79 77 6f 72 64 20 69 73 20 70 72 65 73 65 6e 74 yword is present
17b10 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 45 */.#define JT_E
17b20 52 52 4f 52 20 20 20 20 20 30 78 30 30 34 30 20 RROR 0x0040
17b30 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 /* unknown or
17b40 20 75 6e 73 75 70 70 6f 72 74 65 64 20 6a 6f 69 unsupported joi
17b50 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a n type */.../*.*
17b60 2a 20 46 6c 61 67 73 20 61 70 70 72 6f 70 72 69 * Flags appropri
17b70 61 74 65 20 66 6f 72 20 74 68 65 20 77 63 74 72 ate for the wctr
17b80 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 74 65 72 lFlags parameter
17b90 20 6f 66 20 73 71 6c 69 74 65 33 57 68 65 72 65 of sqlite3Where
17ba0 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 Begin().** and t
17bb0 68 65 20 57 68 65 72 65 49 6e 66 6f 2e 77 63 74 he WhereInfo.wct
17bc0 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 72 2e 0a rlFlags member..
17bd0 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
17be0 5f 4f 52 44 45 52 42 59 5f 4e 4f 52 4d 41 4c 20 _ORDERBY_NORMAL
17bf0 20 20 30 78 30 30 30 30 20 2f 2a 20 4e 6f 2d 6f 0x0000 /* No-o
17c00 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 p */.#define WHE
17c10 52 45 5f 4f 52 44 45 52 42 59 5f 4d 49 4e 20 20 RE_ORDERBY_MIN
17c20 20 20 20 20 30 78 30 30 30 31 20 2f 2a 20 4f 52 0x0001 /* OR
17c30 44 45 52 20 42 59 20 70 72 6f 63 65 73 73 69 6e DER BY processin
17c40 67 20 66 6f 72 20 6d 69 6e 28 29 20 66 75 6e 63 g for min() func
17c50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
17c60 45 5f 4f 52 44 45 52 42 59 5f 4d 41 58 20 20 20 E_ORDERBY_MAX
17c70 20 20 20 30 78 30 30 30 32 20 2f 2a 20 4f 52 44 0x0002 /* ORD
17c80 45 52 20 42 59 20 70 72 6f 63 65 73 73 69 6e 67 ER BY processing
17c90 20 66 6f 72 20 6d 61 78 28 29 20 66 75 6e 63 20 for max() func
17ca0 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
17cb0 5f 4f 4e 45 50 41 53 53 5f 44 45 53 49 52 45 44 _ONEPASS_DESIRED
17cc0 20 20 30 78 30 30 30 34 20 2f 2a 20 57 61 6e 74 0x0004 /* Want
17cd0 20 74 6f 20 64 6f 20 6f 6e 65 2d 70 61 73 73 20 to do one-pass
17ce0 55 50 44 41 54 45 2f 44 45 4c 45 54 45 20 2a 2f UPDATE/DELETE */
17cf0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 .#define WHERE_D
17d00 55 50 4c 49 43 41 54 45 53 5f 4f 4b 20 20 20 20 UPLICATES_OK
17d10 30 78 30 30 30 38 20 2f 2a 20 4f 6b 20 74 6f 20 0x0008 /* Ok to
17d20 72 65 74 75 72 6e 20 61 20 72 6f 77 20 6d 6f 72 return a row mor
17d30 65 20 74 68 61 6e 20 6f 6e 63 65 20 2a 2f 0a 23 e than once */.#
17d40 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4d 49 define WHERE_OMI
17d50 54 5f 4f 50 45 4e 5f 43 4c 4f 53 45 20 20 30 78 T_OPEN_CLOSE 0x
17d60 30 30 31 30 20 2f 2a 20 54 61 62 6c 65 20 63 75 0010 /* Table cu
17d70 72 73 6f 72 73 20 61 72 65 20 61 6c 72 65 61 64 rsors are alread
17d80 79 20 6f 70 65 6e 20 2a 2f 0a 23 64 65 66 69 6e y open */.#defin
17d90 65 20 57 48 45 52 45 5f 46 4f 52 43 45 5f 54 41 e WHERE_FORCE_TA
17da0 42 4c 45 20 20 20 20 20 20 30 78 30 30 32 30 20 BLE 0x0020
17db0 2f 2a 20 44 6f 20 6e 6f 74 20 75 73 65 20 61 6e /* Do not use an
17dc0 20 69 6e 64 65 78 2d 6f 6e 6c 79 20 73 65 61 72 index-only sear
17dd0 63 68 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 ch */.#define WH
17de0 45 52 45 5f 4f 4e 45 54 41 42 4c 45 5f 4f 4e 4c ERE_ONETABLE_ONL
17df0 59 20 20 20 20 30 78 30 30 34 30 20 2f 2a 20 4f Y 0x0040 /* O
17e00 6e 6c 79 20 63 6f 64 65 20 74 68 65 20 31 73 74 nly code the 1st
17e10 20 74 61 62 6c 65 20 69 6e 20 70 54 61 62 4c 69 table in pTabLi
17e20 73 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 st */.#define WH
17e30 45 52 45 5f 4e 4f 5f 41 55 54 4f 49 4e 44 45 58 ERE_NO_AUTOINDEX
17e40 20 20 20 20 20 30 78 30 30 38 30 20 2f 2a 20 44 0x0080 /* D
17e50 69 73 61 6c 6c 6f 77 20 61 75 74 6f 6d 61 74 69 isallow automati
17e60 63 20 69 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 c indexes */.#de
17e70 66 69 6e 65 20 57 48 45 52 45 5f 47 52 4f 55 50 fine WHERE_GROUP
17e80 42 59 20 20 20 20 20 20 20 20 20 20 30 78 30 31 BY 0x01
17e90 30 30 20 2f 2a 20 70 4f 72 64 65 72 42 79 20 69 00 /* pOrderBy i
17ea0 73 20 72 65 61 6c 6c 79 20 61 20 47 52 4f 55 50 s really a GROUP
17eb0 20 42 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 BY */.#define W
17ec0 48 45 52 45 5f 44 49 53 54 49 4e 43 54 42 59 20 HERE_DISTINCTBY
17ed0 20 20 20 20 20 20 30 78 30 32 30 30 20 2f 2a 20 0x0200 /*
17ee0 70 4f 72 64 65 72 62 79 20 69 73 20 72 65 61 6c pOrderby is real
17ef0 6c 79 20 61 20 44 49 53 54 49 4e 43 54 20 63 6c ly a DISTINCT cl
17f00 61 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ause */.#define
17f10 57 48 45 52 45 5f 57 41 4e 54 5f 44 49 53 54 49 WHERE_WANT_DISTI
17f20 4e 43 54 20 20 20 20 30 78 30 34 30 30 20 2f 2a NCT 0x0400 /*
17f30 20 41 6c 6c 20 6f 75 74 70 75 74 20 6e 65 65 64 All output need
17f40 73 20 74 6f 20 62 65 20 64 69 73 74 69 6e 63 74 s to be distinct
17f50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
17f60 45 5f 53 4f 52 54 42 59 47 52 4f 55 50 20 20 20 E_SORTBYGROUP
17f70 20 20 20 30 78 30 38 30 30 20 2f 2a 20 53 75 70 0x0800 /* Sup
17f80 70 6f 72 74 20 73 71 6c 69 74 65 33 57 68 65 72 port sqlite3Wher
17f90 65 49 73 53 6f 72 74 65 64 28 29 20 2a 2f 0a 23 eIsSorted() */.#
17fa0 64 65 66 69 6e 65 20 57 48 45 52 45 5f 52 45 4f define WHERE_REO
17fb0 50 45 4e 5f 49 44 58 20 20 20 20 20 20 20 30 78 PEN_IDX 0x
17fc0 31 30 30 30 20 2f 2a 20 54 72 79 20 74 6f 20 75 1000 /* Try to u
17fd0 73 65 20 4f 50 5f 52 65 6f 70 65 6e 49 64 78 20 se OP_ReopenIdx
17fe0 2a 2f 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 72 */../* Allowed r
17ff0 65 74 75 72 6e 20 76 61 6c 75 65 73 20 66 72 6f eturn values fro
18000 6d 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 m sqlite3WhereIs
18010 44 69 73 74 69 6e 63 74 28 29 0a 2a 2f 0a 23 64 Distinct().*/.#d
18020 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 efine WHERE_DIST
18030 49 4e 43 54 5f 4e 4f 4f 50 20 20 20 20 20 20 30 INCT_NOOP 0
18040 20 20 2f 2a 20 44 49 53 54 49 4e 43 54 20 6b 65 /* DISTINCT ke
18050 79 77 6f 72 64 20 6e 6f 74 20 75 73 65 64 20 2a yword not used *
18060 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
18070 44 49 53 54 49 4e 43 54 5f 55 4e 49 51 55 45 20 DISTINCT_UNIQUE
18080 20 20 20 31 20 20 2f 2a 20 4e 6f 20 64 75 70 6c 1 /* No dupl
18090 69 63 61 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e icates */.#defin
180a0 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 e WHERE_DISTINCT
180b0 5f 4f 52 44 45 52 45 44 20 20 20 32 20 20 2f 2a _ORDERED 2 /*
180c0 20 41 6c 6c 20 64 75 70 6c 69 63 61 74 65 73 20 All duplicates
180d0 61 72 65 20 61 64 6a 61 63 65 6e 74 20 2a 2f 0a are adjacent */.
180e0 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 #define WHERE_DI
180f0 53 54 49 4e 43 54 5f 55 4e 4f 52 44 45 52 45 44 STINCT_UNORDERED
18100 20 33 20 20 2f 2a 20 44 75 70 6c 69 63 61 74 65 3 /* Duplicate
18110 73 20 61 72 65 20 73 63 61 74 74 65 72 65 64 20 s are scattered
18120 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 4e 61 6d 65 */../*.** A Name
18130 43 6f 6e 74 65 78 74 20 64 65 66 69 6e 65 73 20 Context defines
18140 61 20 63 6f 6e 74 65 78 74 20 69 6e 20 77 68 69 a context in whi
18150 63 68 20 74 6f 20 72 65 73 6f 6c 76 65 20 74 61 ch to resolve ta
18160 62 6c 65 20 61 6e 64 20 63 6f 6c 75 6d 6e 0a 2a ble and column.*
18170 2a 20 6e 61 6d 65 73 2e 20 20 54 68 65 20 63 6f * names. The co
18180 6e 74 65 78 74 20 63 6f 6e 73 69 73 74 73 20 6f ntext consists o
18190 66 20 61 20 6c 69 73 74 20 6f 66 20 74 61 62 6c f a list of tabl
181a0 65 73 20 28 74 68 65 20 70 53 72 63 4c 69 73 74 es (the pSrcList
181b0 29 20 66 69 65 6c 64 20 61 6e 64 0a 2a 2a 20 61 ) field and.** a
181c0 20 6c 69 73 74 20 6f 66 20 6e 61 6d 65 64 20 65 list of named e
181d0 78 70 72 65 73 73 69 6f 6e 20 28 70 45 4c 69 73 xpression (pELis
181e0 74 29 2e 20 20 54 68 65 20 6e 61 6d 65 64 20 65 t). The named e
181f0 78 70 72 65 73 73 69 6f 6e 20 6c 69 73 74 20 6d xpression list m
18200 61 79 0a 2a 2a 20 62 65 20 4e 55 4c 4c 2e 20 20 ay.** be NULL.
18210 54 68 65 20 70 53 72 63 20 63 6f 72 72 65 73 70 The pSrc corresp
18220 6f 6e 64 73 20 74 6f 20 74 68 65 20 46 52 4f 4d onds to the FROM
18230 20 63 6c 61 75 73 65 20 6f 66 20 61 20 53 45 4c clause of a SEL
18240 45 43 54 20 6f 72 0a 2a 2a 20 74 6f 20 74 68 65 ECT or.** to the
18250 20 74 61 62 6c 65 20 62 65 69 6e 67 20 6f 70 65 table being ope
18260 72 61 74 65 64 20 6f 6e 20 62 79 20 49 4e 53 45 rated on by INSE
18270 52 54 2c 20 55 50 44 41 54 45 2c 20 6f 72 20 44 RT, UPDATE, or D
18280 45 4c 45 54 45 2e 20 20 54 68 65 0a 2a 2a 20 70 ELETE. The.** p
18290 45 4c 69 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 EList correspond
182a0 73 20 74 6f 20 74 68 65 20 72 65 73 75 6c 74 20 s to the result
182b0 73 65 74 20 6f 66 20 61 20 53 45 4c 45 43 54 20 set of a SELECT
182c0 61 6e 64 20 69 73 20 4e 55 4c 4c 20 66 6f 72 0a and is NULL for.
182d0 2a 2a 20 6f 74 68 65 72 20 73 74 61 74 65 6d 65 ** other stateme
182e0 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 4e 61 6d 65 43 nts..**.** NameC
182f0 6f 6e 74 65 78 74 73 20 63 61 6e 20 62 65 20 6e ontexts can be n
18300 65 73 74 65 64 2e 20 20 57 68 65 6e 20 72 65 73 ested. When res
18310 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 2c 20 74 68 olving names, th
18320 65 20 69 6e 6e 65 72 2d 6d 6f 73 74 20 0a 2a 2a e inner-most .**
18330 20 63 6f 6e 74 65 78 74 20 69 73 20 73 65 61 72 context is sear
18340 63 68 65 64 20 66 69 72 73 74 2e 20 20 49 66 20 ched first. If
18350 6e 6f 20 6d 61 74 63 68 20 69 73 20 66 6f 75 6e no match is foun
18360 64 2c 20 74 68 65 20 6e 65 78 74 20 6f 75 74 65 d, the next oute
18370 72 0a 2a 2a 20 63 6f 6e 74 65 78 74 20 69 73 20 r.** context is
18380 63 68 65 63 6b 65 64 2e 20 20 49 66 20 74 68 65 checked. If the
18390 72 65 20 69 73 20 73 74 69 6c 6c 20 6e 6f 20 6d re is still no m
183a0 61 74 63 68 2c 20 74 68 65 20 6e 65 78 74 20 63 atch, the next c
183b0 6f 6e 74 65 78 74 0a 2a 2a 20 69 73 20 63 68 65 ontext.** is che
183c0 63 6b 65 64 2e 20 20 54 68 69 73 20 70 72 6f 63 cked. This proc
183d0 65 73 73 20 63 6f 6e 74 69 6e 75 65 73 20 75 6e ess continues un
183e0 74 69 6c 20 65 69 74 68 65 72 20 61 20 6d 61 74 til either a mat
183f0 63 68 20 69 73 20 66 6f 75 6e 64 0a 2a 2a 20 6f ch is found.** o
18400 72 20 61 6c 6c 20 63 6f 6e 74 65 78 74 73 20 61 r all contexts a
18410 72 65 20 63 68 65 63 6b 2e 20 20 57 68 65 6e 20 re check. When
18420 61 20 6d 61 74 63 68 20 69 73 20 66 6f 75 6e 64 a match is found
18430 2c 20 74 68 65 20 6e 52 65 66 20 6d 65 6d 62 65 , the nRef membe
18440 72 20 6f 66 0a 2a 2a 20 74 68 65 20 63 6f 6e 74 r of.** the cont
18450 65 78 74 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 ext containing t
18460 68 65 20 6d 61 74 63 68 20 69 73 20 69 6e 63 72 he match is incr
18470 65 6d 65 6e 74 65 64 2e 20 0a 2a 2a 0a 2a 2a 20 emented. .**.**
18480 45 61 63 68 20 73 75 62 71 75 65 72 79 20 67 65 Each subquery ge
18490 74 73 20 61 20 6e 65 77 20 4e 61 6d 65 43 6f 6e ts a new NameCon
184a0 74 65 78 74 2e 20 20 54 68 65 20 70 4e 65 78 74 text. The pNext
184b0 20 66 69 65 6c 64 20 70 6f 69 6e 74 73 20 74 6f field points to
184c0 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 the.** NameCont
184d0 65 78 74 20 69 6e 20 74 68 65 20 70 61 72 65 6e ext in the paren
184e0 74 20 71 75 65 72 79 2e 20 20 54 68 75 73 20 74 t query. Thus t
184f0 68 65 20 70 72 6f 63 65 73 73 20 6f 66 20 73 63 he process of sc
18500 61 6e 6e 69 6e 67 20 74 68 65 0a 2a 2a 20 4e 61 anning the.** Na
18510 6d 65 43 6f 6e 74 65 78 74 20 6c 69 73 74 20 63 meContext list c
18520 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 73 65 orresponds to se
18530 61 72 63 68 69 6e 67 20 74 68 72 6f 75 67 68 20 arching through
18540 73 75 63 63 65 73 73 69 76 65 6c 79 20 6f 75 74 successively out
18550 65 72 0a 2a 2a 20 73 75 62 71 75 65 72 69 65 73 er.** subqueries
18560 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 61 20 6d looking for a m
18570 61 74 63 68 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 atch..*/.struct
18580 4e 61 6d 65 43 6f 6e 74 65 78 74 20 7b 0a 20 20 NameContext {.
18590 50 61 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 Parse *pParse;
185a0 20 20 20 20 20 2f 2a 20 54 68 65 20 70 61 72 73 /* The pars
185b0 65 72 20 2a 2f 0a 20 20 53 72 63 4c 69 73 74 20 er */. SrcList
185c0 2a 70 53 72 63 4c 69 73 74 3b 20 20 20 2f 2a 20 *pSrcList; /*
185d0 4f 6e 65 20 6f 72 20 6d 6f 72 65 20 74 61 62 6c One or more tabl
185e0 65 73 20 75 73 65 64 20 74 6f 20 72 65 73 6f 6c es used to resol
185f0 76 65 20 6e 61 6d 65 73 20 2a 2f 0a 20 20 45 78 ve names */. Ex
18600 70 72 4c 69 73 74 20 2a 70 45 4c 69 73 74 3b 20 prList *pEList;
18610 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 6c /* Optional l
18620 69 73 74 20 6f 66 20 72 65 73 75 6c 74 2d 73 65 ist of result-se
18630 74 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 41 t columns */. A
18640 67 67 49 6e 66 6f 20 2a 70 41 67 67 49 6e 66 6f ggInfo *pAggInfo
18650 3b 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 ; /* Informati
18660 6f 6e 20 61 62 6f 75 74 20 61 67 67 72 65 67 61 on about aggrega
18670 74 65 73 20 61 74 20 74 68 69 73 20 6c 65 76 65 tes at this leve
18680 6c 20 2a 2f 0a 20 20 4e 61 6d 65 43 6f 6e 74 65 l */. NameConte
18690 78 74 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e xt *pNext; /* N
186a0 65 78 74 20 6f 75 74 65 72 20 6e 61 6d 65 20 63 ext outer name c
186b0 6f 6e 74 65 78 74 2e 20 20 4e 55 4c 4c 20 66 6f ontext. NULL fo
186c0 72 20 6f 75 74 65 72 6d 6f 73 74 20 2a 2f 0a 20 r outermost */.
186d0 20 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 20 int nRef;
186e0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
186f0 6f 66 20 6e 61 6d 65 73 20 72 65 73 6f 6c 76 65 of names resolve
18700 64 20 62 79 20 74 68 69 73 20 63 6f 6e 74 65 78 d by this contex
18710 74 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b t */. int nErr;
18720 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
18730 75 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 20 umber of errors
18740 65 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 6c encountered whil
18750 65 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 e resolving name
18760 73 20 2a 2f 0a 20 20 75 31 36 20 6e 63 46 6c 61 s */. u16 ncFla
18770 67 73 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 5a gs; /* Z
18780 65 72 6f 20 6f 72 20 6d 6f 72 65 20 4e 43 5f 2a ero or more NC_*
18790 20 66 6c 61 67 73 20 64 65 66 69 6e 65 64 20 62 flags defined b
187a0 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a elow */.};../*.*
187b0 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
187c0 20 66 6f 72 20 74 68 65 20 4e 61 6d 65 43 6f 6e for the NameCon
187d0 74 65 78 74 2c 20 6e 63 46 6c 61 67 73 20 66 69 text, ncFlags fi
187e0 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 3a eld..**.** Note:
187f0 20 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 6d NC_MinMaxAgg m
18800 75 73 74 20 68 61 76 65 20 74 68 65 20 73 61 6d ust have the sam
18810 65 20 76 61 6c 75 65 20 61 73 20 53 46 5f 4d 69 e value as SF_Mi
18820 6e 4d 61 78 41 67 67 20 61 6e 64 0a 2a 2a 20 53 nMaxAgg and.** S
18830 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 QLITE_FUNC_MINMA
18840 58 2e 0a 2a 2a 20 0a 2a 2f 0a 23 64 65 66 69 6e X..** .*/.#defin
18850 65 20 4e 43 5f 41 6c 6c 6f 77 41 67 67 20 20 30 e NC_AllowAgg 0
18860 78 30 30 30 31 20 20 2f 2a 20 41 67 67 72 65 67 x0001 /* Aggreg
18870 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 ate functions ar
18880 65 20 61 6c 6c 6f 77 65 64 20 68 65 72 65 20 2a e allowed here *
18890 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 48 61 73 /.#define NC_Has
188a0 41 67 67 20 20 20 20 30 78 30 30 30 32 20 20 2f Agg 0x0002 /
188b0 2a 20 4f 6e 65 20 6f 72 20 6d 6f 72 65 20 61 67 * One or more ag
188c0 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
188d0 73 20 73 65 65 6e 20 2a 2f 0a 23 64 65 66 69 6e s seen */.#defin
188e0 65 20 4e 43 5f 49 73 43 68 65 63 6b 20 20 20 30 e NC_IsCheck 0
188f0 78 30 30 30 34 20 20 2f 2a 20 54 72 75 65 20 69 x0004 /* True i
18900 66 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 f resolving name
18910 73 20 69 6e 20 61 20 43 48 45 43 4b 20 63 6f 6e s in a CHECK con
18920 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 straint */.#defi
18930 6e 65 20 4e 43 5f 49 6e 41 67 67 46 75 6e 63 20 ne NC_InAggFunc
18940 30 78 30 30 30 38 20 20 2f 2a 20 54 72 75 65 20 0x0008 /* True
18950 69 66 20 61 6e 61 6c 79 7a 69 6e 67 20 61 72 67 if analyzing arg
18960 75 6d 65 6e 74 73 20 74 6f 20 61 6e 20 61 67 67 uments to an agg
18970 20 66 75 6e 63 20 2a 2f 0a 23 64 65 66 69 6e 65 func */.#define
18980 20 4e 43 5f 50 61 72 74 49 64 78 20 20 20 30 78 NC_PartIdx 0x
18990 30 30 31 30 20 20 2f 2a 20 54 72 75 65 20 69 66 0010 /* True if
189a0 20 72 65 73 6f 6c 76 69 6e 67 20 61 20 70 61 72 resolving a par
189b0 74 69 61 6c 20 69 6e 64 65 78 20 57 48 45 52 45 tial index WHERE
189c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 4d */.#define NC_M
189d0 69 6e 4d 61 78 41 67 67 20 30 78 31 30 30 30 20 inMaxAgg 0x1000
189e0 20 2f 2a 20 6d 69 6e 2f 6d 61 78 20 61 67 67 72 /* min/max aggr
189f0 65 67 61 74 65 73 20 73 65 65 6e 2e 20 20 53 65 egates seen. Se
18a00 65 20 6e 6f 74 65 20 61 62 6f 76 65 20 2a 2f 0a e note above */.
18a10 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
18a20 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ce of the follow
18a30 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 6f ing structure co
18a40 6e 74 61 69 6e 73 20 61 6c 6c 20 69 6e 66 6f 72 ntains all infor
18a50 6d 61 74 69 6f 6e 0a 2a 2a 20 6e 65 65 64 65 64 mation.** needed
18a60 20 74 6f 20 67 65 6e 65 72 61 74 65 20 63 6f 64 to generate cod
18a70 65 20 66 6f 72 20 61 20 73 69 6e 67 6c 65 20 53 e for a single S
18a80 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e ELECT statement.
18a90 0a 2a 2a 0a 2a 2a 20 6e 4c 69 6d 69 74 20 69 73 .**.** nLimit is
18aa0 20 73 65 74 20 74 6f 20 2d 31 20 69 66 20 74 68 set to -1 if th
18ab0 65 72 65 20 69 73 20 6e 6f 20 4c 49 4d 49 54 20 ere is no LIMIT
18ac0 63 6c 61 75 73 65 2e 20 20 6e 4f 66 66 73 65 74 clause. nOffset
18ad0 20 69 73 20 73 65 74 20 74 6f 20 30 2e 0a 2a 2a is set to 0..**
18ae0 20 49 66 20 74 68 65 72 65 20 69 73 20 61 20 4c If there is a L
18af0 49 4d 49 54 20 63 6c 61 75 73 65 2c 20 74 68 65 IMIT clause, the
18b00 20 70 61 72 73 65 72 20 73 65 74 73 20 6e 4c 69 parser sets nLi
18b10 6d 69 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 mit to the value
18b20 20 6f 66 20 74 68 65 0a 2a 2a 20 6c 69 6d 69 74 of the.** limit
18b30 20 61 6e 64 20 6e 4f 66 66 73 65 74 20 74 6f 20 and nOffset to
18b40 74 68 65 20 76 61 6c 75 65 20 6f 66 20 74 68 65 the value of the
18b50 20 6f 66 66 73 65 74 20 28 6f 72 20 30 20 69 66 offset (or 0 if
18b60 20 74 68 65 72 65 20 69 73 20 6e 6f 74 0a 2a 2a there is not.**
18b70 20 6f 66 66 73 65 74 29 2e 20 20 42 75 74 20 6c offset). But l
18b80 61 74 65 72 20 6f 6e 2c 20 6e 4c 69 6d 69 74 20 ater on, nLimit
18b90 61 6e 64 20 6e 4f 66 66 73 65 74 20 62 65 63 6f and nOffset beco
18ba0 6d 65 20 74 68 65 20 6d 65 6d 6f 72 79 20 6c 6f me the memory lo
18bb0 63 61 74 69 6f 6e 73 0a 2a 2a 20 69 6e 20 74 68 cations.** in th
18bc0 65 20 56 44 42 45 20 74 68 61 74 20 72 65 63 6f e VDBE that reco
18bd0 72 64 20 74 68 65 20 6c 69 6d 69 74 20 61 6e 64 rd the limit and
18be0 20 6f 66 66 73 65 74 20 63 6f 75 6e 74 65 72 73 offset counters
18bf0 2e 0a 2a 2a 0a 2a 2a 20 61 64 64 72 4f 70 65 6e ..**.** addrOpen
18c00 45 70 68 6d 5b 5d 20 65 6e 74 72 69 65 73 20 63 Ephm[] entries c
18c10 6f 6e 74 61 69 6e 20 74 68 65 20 61 64 64 72 65 ontain the addre
18c20 73 73 20 6f 66 20 4f 50 5f 4f 70 65 6e 45 70 68 ss of OP_OpenEph
18c30 65 6d 65 72 61 6c 20 6f 70 63 6f 64 65 73 2e 0a emeral opcodes..
18c40 2a 2a 20 54 68 65 73 65 20 61 64 64 72 65 73 73 ** These address
18c50 65 73 20 6d 75 73 74 20 62 65 20 73 74 6f 72 65 es must be store
18c60 64 20 73 6f 20 74 68 61 74 20 77 65 20 63 61 6e d so that we can
18c70 20 67 6f 20 62 61 63 6b 20 61 6e 64 20 66 69 6c go back and fil
18c80 6c 20 69 6e 0a 2a 2a 20 74 68 65 20 50 34 5f 4b l in.** the P4_K
18c90 45 59 49 4e 46 4f 20 61 6e 64 20 50 32 20 70 61 EYINFO and P2 pa
18ca0 72 61 6d 65 74 65 72 73 20 6c 61 74 65 72 2e 20 rameters later.
18cb0 20 4e 65 69 74 68 65 72 20 74 68 65 20 4b 65 79 Neither the Key
18cc0 49 6e 66 6f 20 6e 6f 72 0a 2a 2a 20 74 68 65 20 Info nor.** the
18cd0 6e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e number of column
18ce0 73 20 69 6e 20 50 32 20 63 61 6e 20 62 65 20 63 s in P2 can be c
18cf0 6f 6d 70 75 74 65 64 20 61 74 20 74 68 65 20 73 omputed at the s
18d00 61 6d 65 20 74 69 6d 65 0a 2a 2a 20 61 73 20 74 ame time.** as t
18d10 68 65 20 4f 50 5f 4f 70 65 6e 45 70 68 6d 20 69 he OP_OpenEphm i
18d20 6e 73 74 72 75 63 74 69 6f 6e 20 69 73 20 63 6f nstruction is co
18d30 64 65 64 20 62 65 63 61 75 73 65 20 6e 6f 74 0a ded because not.
18d40 2a 2a 20 65 6e 6f 75 67 68 20 69 6e 66 6f 72 6d ** enough inform
18d50 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 ation about the
18d60 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 79 20 69 compound query i
18d70 73 20 6b 6e 6f 77 6e 20 61 74 20 74 68 61 74 20 s known at that
18d80 70 6f 69 6e 74 2e 0a 2a 2a 20 54 68 65 20 4b 65 point..** The Ke
18d90 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 72 4f 70 yInfo for addrOp
18da0 65 6e 54 72 61 6e 5b 30 5d 20 61 6e 64 20 5b 31 enTran[0] and [1
18db0 5d 20 63 6f 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 ] contains colla
18dc0 74 69 6e 67 20 73 65 71 75 65 6e 63 65 73 0a 2a ting sequences.*
18dd0 2a 20 66 6f 72 20 74 68 65 20 72 65 73 75 6c 74 * for the result
18de0 20 73 65 74 2e 20 20 54 68 65 20 4b 65 79 49 6e set. The KeyIn
18df0 66 6f 20 66 6f 72 20 61 64 64 72 4f 70 65 6e 45 fo for addrOpenE
18e00 70 68 6d 5b 32 5d 20 63 6f 6e 74 61 69 6e 73 20 phm[2] contains
18e10 63 6f 6c 6c 61 74 69 6e 67 0a 2a 2a 20 73 65 71 collating.** seq
18e20 75 65 6e 63 65 73 20 66 6f 72 20 74 68 65 20 4f uences for the O
18e30 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a RDER BY clause..
18e40 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c 65 63 74 */.struct Select
18e50 20 7b 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 {. ExprList *p
18e60 45 4c 69 73 74 3b 20 20 20 20 20 20 2f 2a 20 54 EList; /* T
18e70 68 65 20 66 69 65 6c 64 73 20 6f 66 20 74 68 65 he fields of the
18e80 20 72 65 73 75 6c 74 20 2a 2f 0a 20 20 75 38 20 result */. u8
18e90 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 op;
18ea0 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 3a 20 54 /* One of: T
18eb0 4b 5f 55 4e 49 4f 4e 20 54 4b 5f 41 4c 4c 20 54 K_UNION TK_ALL T
18ec0 4b 5f 49 4e 54 45 52 53 45 43 54 20 54 4b 5f 45 K_INTERSECT TK_E
18ed0 58 43 45 50 54 20 2a 2f 0a 20 20 75 31 36 20 73 XCEPT */. u16 s
18ee0 65 6c 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 elFlags;
18ef0 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 53 46 5f /* Various SF_
18f00 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 69 6e * values */. in
18f10 74 20 69 4c 69 6d 69 74 2c 20 69 4f 66 66 73 65 t iLimit, iOffse
18f20 74 3b 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 72 t; /* Memory r
18f30 65 67 69 73 74 65 72 73 20 68 6f 6c 64 69 6e 67 egisters holding
18f40 20 4c 49 4d 49 54 20 26 20 4f 46 46 53 45 54 20 LIMIT & OFFSET
18f50 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 23 69 66 20 counters */.#if
18f60 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
18f70 4c 45 44 0a 20 20 63 68 61 72 20 7a 53 65 6c 4e LED. char zSelN
18f80 61 6d 65 5b 31 32 5d 3b 20 20 20 20 20 2f 2a 20 ame[12]; /*
18f90 53 79 6d 62 6f 6c 69 63 20 6e 61 6d 65 20 6f 66 Symbolic name of
18fa0 20 74 68 69 73 20 53 45 4c 45 43 54 20 75 73 65 this SELECT use
18fb0 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20 2a for debugging *
18fc0 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 61 /.#endif. int a
18fd0 64 64 72 4f 70 65 6e 45 70 68 6d 5b 32 5d 3b 20 ddrOpenEphm[2];
18fe0 20 20 2f 2a 20 4f 50 5f 4f 70 65 6e 45 70 68 65 /* OP_OpenEphe
18ff0 6d 20 6f 70 63 6f 64 65 73 20 72 65 6c 61 74 65 m opcodes relate
19000 64 20 74 6f 20 74 68 69 73 20 73 65 6c 65 63 74 d to this select
19010 20 2a 2f 0a 20 20 75 36 34 20 6e 53 65 6c 65 63 */. u64 nSelec
19020 74 52 6f 77 3b 20 20 20 20 20 20 20 20 2f 2a 20 tRow; /*
19030 45 73 74 69 6d 61 74 65 64 20 6e 75 6d 62 65 72 Estimated number
19040 20 6f 66 20 72 65 73 75 6c 74 20 72 6f 77 73 20 of result rows
19050 2a 2f 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 */. SrcList *pS
19060 72 63 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 rc; /* T
19070 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a he FROM clause *
19080 2f 0a 20 20 45 78 70 72 20 2a 70 57 68 65 72 65 /. Expr *pWhere
19090 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ; /* Th
190a0 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 2a e WHERE clause *
190b0 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 47 /. ExprList *pG
190c0 72 6f 75 70 42 79 3b 20 20 20 20 2f 2a 20 54 68 roupBy; /* Th
190d0 65 20 47 52 4f 55 50 20 42 59 20 63 6c 61 75 73 e GROUP BY claus
190e0 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 48 61 e */. Expr *pHa
190f0 76 69 6e 67 3b 20 20 20 20 20 20 20 20 20 2f 2a ving; /*
19100 20 54 68 65 20 48 41 56 49 4e 47 20 63 6c 61 75 The HAVING clau
19110 73 65 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 se */. ExprList
19120 20 2a 70 4f 72 64 65 72 42 79 3b 20 20 20 20 2f *pOrderBy; /
19130 2a 20 54 68 65 20 4f 52 44 45 52 20 42 59 20 63 * The ORDER BY c
19140 6c 61 75 73 65 20 2a 2f 0a 20 20 53 65 6c 65 63 lause */. Selec
19150 74 20 2a 70 50 72 69 6f 72 3b 20 20 20 20 20 20 t *pPrior;
19160 20 20 2f 2a 20 50 72 69 6f 72 20 73 65 6c 65 63 /* Prior selec
19170 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 6e 64 20 t in a compound
19180 73 65 6c 65 63 74 20 73 74 61 74 65 6d 65 6e 74 select statement
19190 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 4e */. Select *pN
191a0 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ext; /*
191b0 4e 65 78 74 20 73 65 6c 65 63 74 20 74 6f 20 74 Next select to t
191c0 68 65 20 6c 65 66 74 20 69 6e 20 61 20 63 6f 6d he left in a com
191d0 70 6f 75 6e 64 20 2a 2f 0a 20 20 45 78 70 72 20 pound */. Expr
191e0 2a 70 4c 69 6d 69 74 3b 20 20 20 20 20 20 20 20 *pLimit;
191f0 20 20 2f 2a 20 4c 49 4d 49 54 20 65 78 70 72 65 /* LIMIT expre
19200 73 73 69 6f 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e ssion. NULL mean
19210 73 20 6e 6f 74 20 75 73 65 64 2e 20 2a 2f 0a 20 s not used. */.
19220 20 45 78 70 72 20 2a 70 4f 66 66 73 65 74 3b 20 Expr *pOffset;
19230 20 20 20 20 20 20 20 20 2f 2a 20 4f 46 46 53 45 /* OFFSE
19240 54 20 65 78 70 72 65 73 73 69 6f 6e 2e 20 4e 55 T expression. NU
19250 4c 4c 20 6d 65 61 6e 73 20 6e 6f 74 20 75 73 65 LL means not use
19260 64 2e 20 2a 2f 0a 20 20 57 69 74 68 20 2a 70 57 d. */. With *pW
19270 69 74 68 3b 20 20 20 20 20 20 20 20 20 20 20 2f ith; /
19280 2a 20 57 49 54 48 20 63 6c 61 75 73 65 20 61 74 * WITH clause at
19290 74 61 63 68 65 64 20 74 6f 20 74 68 69 73 20 73 tached to this s
192a0 65 6c 65 63 74 2e 20 4f 72 20 4e 55 4c 4c 2e 20 elect. Or NULL.
192b0 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c */.};../*.** All
192c0 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 owed values for
192d0 53 65 6c 65 63 74 2e 73 65 6c 46 6c 61 67 73 2e Select.selFlags.
192e0 20 20 54 68 65 20 22 53 46 22 20 70 72 65 66 69 The "SF" prefi
192f0 78 20 73 74 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 x stands for.**
19300 22 53 65 6c 65 63 74 20 46 6c 61 67 22 2e 0a 2a "Select Flag"..*
19310 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 44 69 73 /.#define SF_Dis
19320 74 69 6e 63 74 20 20 20 20 20 20 20 20 30 78 30 tinct 0x0
19330 30 30 31 20 20 2f 2a 20 4f 75 74 70 75 74 20 73 001 /* Output s
19340 68 6f 75 6c 64 20 62 65 20 44 49 53 54 49 4e 43 hould be DISTINC
19350 54 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f T */.#define SF_
19360 41 6c 6c 20 20 20 20 20 20 20 20 20 20 20 20 20 All
19370 30 78 30 30 30 32 20 20 2f 2a 20 49 6e 63 6c 75 0x0002 /* Inclu
19380 64 65 73 20 74 68 65 20 41 4c 4c 20 6b 65 79 77 des the ALL keyw
19390 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ord */.#define S
193a0 46 5f 52 65 73 6f 6c 76 65 64 20 20 20 20 20 20 F_Resolved
193b0 20 20 30 78 30 30 30 34 20 20 2f 2a 20 49 64 65 0x0004 /* Ide
193c0 6e 74 69 66 69 65 72 73 20 68 61 76 65 20 62 65 ntifiers have be
193d0 65 6e 20 72 65 73 6f 6c 76 65 64 20 2a 2f 0a 23 en resolved */.#
193e0 64 65 66 69 6e 65 20 53 46 5f 41 67 67 72 65 67 define SF_Aggreg
193f0 61 74 65 20 20 20 20 20 20 20 30 78 30 30 30 38 ate 0x0008
19400 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 /* Contains ag
19410 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
19420 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f s */.#define SF_
19430 55 73 65 73 45 70 68 65 6d 65 72 61 6c 20 20 20 UsesEphemeral
19440 30 78 30 30 31 30 20 20 2f 2a 20 55 73 65 73 20 0x0010 /* Uses
19450 74 68 65 20 4f 70 65 6e 45 70 68 65 6d 65 72 61 the OpenEphemera
19460 6c 20 6f 70 63 6f 64 65 20 2a 2f 0a 23 64 65 66 l opcode */.#def
19470 69 6e 65 20 53 46 5f 45 78 70 61 6e 64 65 64 20 ine SF_Expanded
19480 20 20 20 20 20 20 20 30 78 30 30 32 30 20 20 2f 0x0020 /
19490 2a 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 45 * sqlite3SelectE
194a0 78 70 61 6e 64 28 29 20 63 61 6c 6c 65 64 20 6f xpand() called o
194b0 6e 20 74 68 69 73 20 2a 2f 0a 23 64 65 66 69 6e n this */.#defin
194c0 65 20 53 46 5f 48 61 73 54 79 70 65 49 6e 66 6f e SF_HasTypeInfo
194d0 20 20 20 20 20 30 78 30 30 34 30 20 20 2f 2a 20 0x0040 /*
194e0 46 52 4f 4d 20 73 75 62 71 75 65 72 69 65 73 20 FROM subqueries
194f0 68 61 76 65 20 54 61 62 6c 65 20 6d 65 74 61 64 have Table metad
19500 61 74 61 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ata */.#define S
19510 46 5f 43 6f 6d 70 6f 75 6e 64 20 20 20 20 20 20 F_Compound
19520 20 20 30 78 30 30 38 30 20 20 2f 2a 20 50 61 72 0x0080 /* Par
19530 74 20 6f 66 20 61 20 63 6f 6d 70 6f 75 6e 64 20 t of a compound
19540 71 75 65 72 79 20 2a 2f 0a 23 64 65 66 69 6e 65 query */.#define
19550 20 53 46 5f 56 61 6c 75 65 73 20 20 20 20 20 20 SF_Values
19560 20 20 20 20 30 78 30 31 30 30 20 20 2f 2a 20 53 0x0100 /* S
19570 79 6e 74 68 65 73 69 7a 65 64 20 66 72 6f 6d 20 ynthesized from
19580 56 41 4c 55 45 53 20 63 6c 61 75 73 65 20 2a 2f VALUES clause */
19590 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 75 6c 74 .#define SF_Mult
195a0 69 56 61 6c 75 65 20 20 20 20 20 20 30 78 30 32 iValue 0x02
195b0 30 30 20 20 2f 2a 20 53 69 6e 67 6c 65 20 56 41 00 /* Single VA
195c0 4c 55 45 53 20 74 65 72 6d 20 77 69 74 68 20 6d LUES term with m
195d0 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a ultiple rows */.
195e0 23 64 65 66 69 6e 65 20 53 46 5f 4e 65 73 74 65 #define SF_Neste
195f0 64 46 72 6f 6d 20 20 20 20 20 20 30 78 30 34 30 dFrom 0x040
19600 30 20 20 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 0 /* Part of a
19610 70 61 72 65 6e 74 68 65 73 69 7a 65 64 20 46 52 parenthesized FR
19620 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 OM clause */.#de
19630 66 69 6e 65 20 53 46 5f 4d 61 79 62 65 43 6f 6e fine SF_MaybeCon
19640 76 65 72 74 20 20 20 20 30 78 30 38 30 30 20 20 vert 0x0800
19650 2f 2a 20 4e 65 65 64 20 63 6f 6e 76 65 72 74 43 /* Need convertC
19660 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 74 54 6f 53 ompoundSelectToS
19670 75 62 71 75 65 72 79 28 29 20 2a 2f 0a 23 64 65 ubquery() */.#de
19680 66 69 6e 65 20 53 46 5f 4d 69 6e 4d 61 78 41 67 fine SF_MinMaxAg
19690 67 20 20 20 20 20 20 20 30 78 31 30 30 30 20 20 g 0x1000
196a0 2f 2a 20 41 67 67 72 65 67 61 74 65 20 63 6f 6e /* Aggregate con
196b0 74 61 69 6e 69 6e 67 20 6d 69 6e 28 29 20 6f 72 taining min() or
196c0 20 6d 61 78 28 29 20 2a 2f 0a 23 64 65 66 69 6e max() */.#defin
196d0 65 20 53 46 5f 52 65 63 75 72 73 69 76 65 20 20 e SF_Recursive
196e0 20 20 20 20 20 30 78 32 30 30 30 20 20 2f 2a 20 0x2000 /*
196f0 54 68 65 20 72 65 63 75 72 73 69 76 65 20 70 61 The recursive pa
19700 72 74 20 6f 66 20 61 20 72 65 63 75 72 73 69 76 rt of a recursiv
19710 65 20 43 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 e CTE */.#define
19720 20 53 46 5f 43 6f 6e 76 65 72 74 65 64 20 20 20 SF_Converted
19730 20 20 20 20 30 78 34 30 30 30 20 20 2f 2a 20 42 0x4000 /* B
19740 79 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e y convertCompoun
19750 64 53 65 6c 65 63 74 54 6f 53 75 62 71 75 65 72 dSelectToSubquer
19760 79 28 29 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 y() */.../*.** T
19770 68 65 20 72 65 73 75 6c 74 73 20 6f 66 20 61 20 he results of a
19780 53 45 4c 45 43 54 20 63 61 6e 20 62 65 20 64 69 SELECT can be di
19790 73 74 72 69 62 75 74 65 64 20 69 6e 20 73 65 76 stributed in sev
197a0 65 72 61 6c 20 77 61 79 73 2c 20 61 73 20 64 65 eral ways, as de
197b0 66 69 6e 65 64 0a 2a 2a 20 62 79 20 6f 6e 65 20 fined.** by one
197c0 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
197d0 20 6d 61 63 72 6f 73 2e 20 20 54 68 65 20 22 53 macros. The "S
197e0 52 54 22 20 70 72 65 66 69 78 20 6d 65 61 6e 73 RT" prefix means
197f0 20 22 53 45 4c 45 43 54 20 52 65 73 75 6c 74 0a "SELECT Result.
19800 2a 2a 20 54 79 70 65 22 2e 0a 2a 2a 0a 2a 2a 20 ** Type"..**.**
19810 20 20 20 20 53 52 54 5f 55 6e 69 6f 6e 20 20 20 SRT_Union
19820 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 Store result
19830 73 20 61 73 20 61 20 6b 65 79 20 69 6e 20 61 20 s as a key in a
19840 74 65 6d 70 6f 72 61 72 79 20 69 6e 64 65 78 20 temporary index
19850 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
19860 20 20 20 20 20 20 20 20 69 64 65 6e 74 69 66 69 identifi
19870 65 64 20 62 79 20 70 44 65 73 74 2d 3e 69 53 44 ed by pDest->iSD
19880 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 Parm..**.**
19890 53 52 54 5f 45 78 63 65 70 74 20 20 20 20 20 20 SRT_Except
198a0 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 73 20 66 Remove results f
198b0 72 6f 6d 20 74 68 65 20 74 65 6d 70 6f 72 61 72 rom the temporar
198c0 79 20 69 6e 64 65 78 20 70 44 65 73 74 2d 3e 69 y index pDest->i
198d0 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 SDParm..**.**
198e0 20 20 53 52 54 5f 45 78 69 73 74 73 20 20 20 20 SRT_Exists
198f0 20 20 53 74 6f 72 65 20 61 20 31 20 69 6e 20 6d Store a 1 in m
19900 65 6d 6f 72 79 20 63 65 6c 6c 20 70 44 65 73 74 emory cell pDest
19910 2d 3e 69 53 44 50 61 72 6d 20 69 66 20 74 68 65 ->iSDParm if the
19920 20 72 65 73 75 6c 74 0a 2a 2a 20 20 20 20 20 20 result.**
19930 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 s
19940 65 74 20 69 73 20 6e 6f 74 20 65 6d 70 74 79 2e et is not empty.
19950 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 .**.** SRT_D
19960 69 73 63 61 72 64 20 20 20 20 20 54 68 72 6f 77 iscard Throw
19970 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 77 61 the results awa
19980 79 2e 20 20 54 68 69 73 20 69 73 20 75 73 65 64 y. This is used
19990 20 62 79 20 53 45 4c 45 43 54 0a 2a 2a 20 20 20 by SELECT.**
199a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
199b0 20 20 73 74 61 74 65 6d 65 6e 74 73 20 77 69 74 statements wit
199c0 68 69 6e 20 74 72 69 67 67 65 72 73 20 77 68 6f hin triggers who
199d0 73 65 20 6f 6e 6c 79 20 70 75 72 70 6f 73 65 20 se only purpose
199e0 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 is.**
199f0 20 20 20 20 20 20 20 20 20 20 74 68 65 20 73 69 the si
19a00 64 65 2d 65 66 66 65 63 74 73 20 6f 66 20 66 75 de-effects of fu
19a10 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 41 nctions..**.** A
19a20 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 ll of the above
19a30 61 72 65 20 66 72 65 65 20 74 6f 20 69 67 6e 6f are free to igno
19a40 72 65 20 74 68 65 69 72 20 4f 52 44 45 52 20 42 re their ORDER B
19a50 59 20 63 6c 61 75 73 65 2e 20 54 68 6f 73 65 20 Y clause. Those
19a60 74 68 61 74 0a 2a 2a 20 66 6f 6c 6c 6f 77 20 6d that.** follow m
19a70 75 73 74 20 68 6f 6e 6f 72 20 74 68 65 20 4f 52 ust honor the OR
19a80 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a DER BY clause..*
19a90 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4f 75 74 *.** SRT_Out
19aa0 70 75 74 20 20 20 20 20 20 47 65 6e 65 72 61 74 put Generat
19ab0 65 20 61 20 72 6f 77 20 6f 66 20 6f 75 74 70 75 e a row of outpu
19ac0 74 20 28 75 73 69 6e 67 20 74 68 65 20 4f 50 5f t (using the OP_
19ad0 52 65 73 75 6c 74 52 6f 77 0a 2a 2a 20 20 20 20 ResultRow.**
19ae0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19af0 20 6f 70 63 6f 64 65 29 20 66 6f 72 20 65 61 63 opcode) for eac
19b00 68 20 72 6f 77 20 69 6e 20 74 68 65 20 72 65 73 h row in the res
19b10 75 6c 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 20 ult set..**.**
19b20 20 20 20 53 52 54 5f 4d 65 6d 20 20 20 20 20 20 SRT_Mem
19b30 20 20 20 4f 6e 6c 79 20 76 61 6c 69 64 20 69 66 Only valid if
19b40 20 74 68 65 20 72 65 73 75 6c 74 20 69 73 20 61 the result is a
19b50 20 73 69 6e 67 6c 65 20 63 6f 6c 75 6d 6e 2e 0a single column..
19b60 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
19b70 20 20 20 20 20 20 20 53 74 6f 72 65 20 74 68 65 Store the
19b80 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 6f 66 first column of
19b90 20 74 68 65 20 66 69 72 73 74 20 72 65 73 75 6c the first resul
19ba0 74 20 72 6f 77 0a 2a 2a 20 20 20 20 20 20 20 20 t row.**
19bb0 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 20 in
19bc0 72 65 67 69 73 74 65 72 20 70 44 65 73 74 2d 3e register pDest->
19bd0 69 53 44 50 61 72 6d 20 74 68 65 6e 20 61 62 61 iSDParm then aba
19be0 6e 64 6f 6e 20 74 68 65 20 72 65 73 74 0a 2a 2a ndon the rest.**
19bf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19c00 20 20 20 20 20 6f 66 20 74 68 65 20 71 75 65 72 of the quer
19c10 79 2e 20 20 54 68 69 73 20 64 65 73 74 69 6e 61 y. This destina
19c20 74 69 6f 6e 20 69 6d 70 6c 69 65 73 20 22 4c 49 tion implies "LI
19c30 4d 49 54 20 31 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 MIT 1"..**.**
19c40 20 20 53 52 54 5f 53 65 74 20 20 20 20 20 20 20 SRT_Set
19c50 20 20 54 68 65 20 72 65 73 75 6c 74 20 6d 75 73 The result mus
19c60 74 20 62 65 20 61 20 73 69 6e 67 6c 65 20 63 6f t be a single co
19c70 6c 75 6d 6e 2e 20 20 53 74 6f 72 65 20 65 61 63 lumn. Store eac
19c80 68 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 h.**
19c90 20 20 20 20 20 20 20 20 20 72 6f 77 20 6f 66 20 row of
19ca0 72 65 73 75 6c 74 20 61 73 20 74 68 65 20 6b 65 result as the ke
19cb0 79 20 69 6e 20 74 61 62 6c 65 20 70 44 65 73 74 y in table pDest
19cc0 2d 3e 69 53 44 50 61 72 6d 2e 20 0a 2a 2a 20 20 ->iSDParm. .**
19cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19ce0 20 20 20 41 70 70 6c 79 20 74 68 65 20 61 66 66 Apply the aff
19cf0 69 6e 69 74 79 20 70 44 65 73 74 2d 3e 61 66 66 inity pDest->aff
19d00 53 64 73 74 20 62 65 66 6f 72 65 20 73 74 6f 72 Sdst before stor
19d10 69 6e 67 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ing.**
19d20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 6c resul
19d30 74 73 2e 20 20 55 73 65 64 20 74 6f 20 69 6d 70 ts. Used to imp
19d40 6c 65 6d 65 6e 74 20 22 49 4e 20 28 53 45 4c 45 lement "IN (SELE
19d50 43 54 20 2e 2e 2e 29 22 2e 0a 2a 2a 0a 2a 2a 20 CT ...)"..**.**
19d60 20 20 20 20 53 52 54 5f 45 70 68 65 6d 54 61 62 SRT_EphemTab
19d70 20 20 20 20 43 72 65 61 74 65 20 61 6e 20 74 65 Create an te
19d80 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 mporary table pD
19d90 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 61 6e 64 est->iSDParm and
19da0 20 73 74 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 store.**
19db0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 th
19dc0 65 20 72 65 73 75 6c 74 20 74 68 65 72 65 2e 20 e result there.
19dd0 54 68 65 20 63 75 72 73 6f 72 20 69 73 20 6c 65 The cursor is le
19de0 66 74 20 6f 70 65 6e 20 61 66 74 65 72 0a 2a 2a ft open after.**
19df0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19e00 20 20 20 20 20 72 65 74 75 72 6e 69 6e 67 2e 20 returning.
19e10 20 54 68 69 73 20 69 73 20 6c 69 6b 65 20 53 52 This is like SR
19e20 54 5f 54 61 62 6c 65 20 65 78 63 65 70 74 20 74 T_Table except t
19e30 68 61 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 hat.**
19e40 20 20 20 20 20 20 20 20 20 20 20 74 68 69 73 20 this
19e50 64 65 73 74 69 6e 61 74 69 6f 6e 20 75 73 65 73 destination uses
19e60 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 61 OP_OpenEphemera
19e70 6c 20 74 6f 20 63 72 65 61 74 65 0a 2a 2a 20 20 l to create.**
19e80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19e90 20 20 20 74 68 65 20 74 61 62 6c 65 20 66 69 72 the table fir
19ea0 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 st..**.** SR
19eb0 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 20 47 65 T_Coroutine Ge
19ec0 6e 65 72 61 74 65 20 61 20 63 6f 2d 72 6f 75 74 nerate a co-rout
19ed0 69 6e 65 20 74 68 61 74 20 72 65 74 75 72 6e 73 ine that returns
19ee0 20 61 20 6e 65 77 20 72 6f 77 20 6f 66 0a 2a 2a a new row of.**
19ef0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19f00 20 20 20 20 20 72 65 73 75 6c 74 73 20 65 61 63 results eac
19f10 68 20 74 69 6d 65 20 69 74 20 69 73 20 69 6e 76 h time it is inv
19f20 6f 6b 65 64 2e 20 20 54 68 65 20 65 6e 74 72 79 oked. The entry
19f30 20 70 6f 69 6e 74 0a 2a 2a 20 20 20 20 20 20 20 point.**
19f40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 66 of
19f50 20 74 68 65 20 63 6f 2d 72 6f 75 74 69 6e 65 20 the co-routine
19f60 69 73 20 73 74 6f 72 65 64 20 69 6e 20 72 65 67 is stored in reg
19f70 69 73 74 65 72 20 70 44 65 73 74 2d 3e 69 53 44 ister pDest->iSD
19f80 50 61 72 6d 0a 2a 2a 20 20 20 20 20 20 20 20 20 Parm.**
19f90 20 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 20 and
19fa0 74 68 65 20 72 65 73 75 6c 74 20 72 6f 77 20 69 the result row i
19fb0 73 20 73 74 6f 72 65 64 20 69 6e 20 70 44 65 73 s stored in pDes
19fc0 74 2d 3e 6e 44 65 73 74 20 72 65 67 69 73 74 65 t->nDest registe
19fd0 72 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 rs.**
19fe0 20 20 20 20 20 20 20 20 20 20 73 74 61 72 74 69 starti
19ff0 6e 67 20 77 69 74 68 20 70 44 65 73 74 2d 3e 69 ng with pDest->i
1a000 53 64 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 Sdst..**.**
1a010 53 52 54 5f 54 61 62 6c 65 20 20 20 20 20 20 20 SRT_Table
1a020 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e Store results in
1a030 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 temporary table
1a040 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e pDest->iSDParm.
1a050 0a 2a 2a 20 20 20 20 20 53 52 54 5f 46 69 66 6f .** SRT_Fifo
1a060 20 20 20 20 20 20 20 20 54 68 69 73 20 69 73 20 This is
1a070 6c 69 6b 65 20 53 52 54 5f 45 70 68 65 6d 54 61 like SRT_EphemTa
1a080 62 20 65 78 63 65 70 74 20 74 68 61 74 20 74 68 b except that th
1a090 65 20 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 e table.**
1a0a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1a0b0 73 20 61 73 73 75 6d 65 64 20 74 6f 20 61 6c 72 s assumed to alr
1a0c0 65 61 64 79 20 62 65 20 6f 70 65 6e 2e 20 20 53 eady be open. S
1a0d0 52 54 5f 46 69 66 6f 20 68 61 73 0a 2a 2a 20 20 RT_Fifo has.**
1a0e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a0f0 20 20 20 74 68 65 20 61 64 64 69 74 69 6f 6e 61 the additiona
1a100 6c 20 70 72 6f 70 65 72 74 79 20 6f 66 20 62 65 l property of be
1a110 69 6e 67 20 61 62 6c 65 20 74 6f 20 69 67 6e 6f ing able to igno
1a120 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 re.**
1a130 20 20 20 20 20 20 20 20 20 20 74 68 65 20 4f 52 the OR
1a140 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a DER BY clause..*
1a150 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 73 *.** SRT_Dis
1a160 74 46 69 66 6f 20 20 20 20 53 74 6f 72 65 20 72 tFifo Store r
1a170 65 73 75 6c 74 73 20 69 6e 20 61 20 74 65 6d 70 esults in a temp
1a180 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 73 orary table pDes
1a190 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 20 t->iSDParm..**
1a1a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a1b0 20 20 20 42 75 74 20 61 6c 73 6f 20 75 73 65 20 But also use
1a1c0 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 temporary table
1a1d0 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 pDest->iSDParm+1
1a1e0 20 61 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 as.**
1a1f0 20 20 20 20 20 20 20 20 20 20 20 61 20 72 65 63 a rec
1a200 6f 72 64 20 6f 66 20 61 6c 6c 20 70 72 69 6f 72 ord of all prior
1a210 20 72 65 73 75 6c 74 73 20 61 6e 64 20 69 67 6e results and ign
1a220 6f 72 65 20 61 6e 79 20 64 75 70 6c 69 63 61 74 ore any duplicat
1a230 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 e.**
1a240 20 20 20 20 20 20 20 20 20 72 6f 77 73 2e 20 20 rows.
1a250 4e 61 6d 65 20 6d 65 61 6e 73 3a 20 20 22 44 69 Name means: "Di
1a260 73 74 69 6e 63 74 20 46 69 66 6f 22 2e 0a 2a 2a stinct Fifo"..**
1a270 0a 2a 2a 20 20 20 20 20 53 52 54 5f 51 75 65 75 .** SRT_Queu
1a280 65 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 e Store re
1a290 73 75 6c 74 73 20 69 6e 20 70 72 69 6f 72 69 74 sults in priorit
1a2a0 79 20 71 75 65 75 65 20 70 44 65 73 74 2d 3e 69 y queue pDest->i
1a2b0 53 44 50 61 72 6d 20 28 72 65 61 6c 6c 79 0a 2a SDParm (really.*
1a2c0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1a2d0 20 20 20 20 20 20 61 6e 20 69 6e 64 65 78 29 2e an index).
1a2e0 20 20 41 70 70 65 6e 64 20 61 20 73 65 71 75 65 Append a seque
1a2f0 6e 63 65 20 6e 75 6d 62 65 72 20 73 6f 20 74 68 nce number so th
1a300 61 74 20 61 6c 6c 20 65 6e 74 72 69 65 73 0a 2a at all entries.*
1a310 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1a320 20 20 20 20 20 20 61 72 65 20 64 69 73 74 69 6e are distin
1a330 63 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 ct..**.** SR
1a340 54 5f 44 69 73 74 51 75 65 75 65 20 20 20 53 74 T_DistQueue St
1a350 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 70 ore results in p
1a360 72 69 6f 72 69 74 79 20 71 75 65 75 65 20 70 44 riority queue pD
1a370 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 6f 6e 6c est->iSDParm onl
1a380 79 20 69 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 y if.**
1a390 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 the
1a3a0 73 61 6d 65 20 72 65 63 6f 72 64 20 68 61 73 20 same record has
1a3b0 6e 65 76 65 72 20 62 65 65 6e 20 73 74 6f 72 65 never been store
1a3c0 64 20 62 65 66 6f 72 65 2e 20 20 54 68 65 0a 2a d before. The.*
1a3d0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1a3e0 20 20 20 20 20 20 69 6e 64 65 78 20 61 74 20 70 index at p
1a3f0 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 20 Dest->iSDParm+1
1a400 68 6f 6c 64 20 61 6c 6c 20 70 72 69 6f 72 20 73 hold all prior s
1a410 74 6f 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e tores..*/.#defin
1a420 65 20 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 20 e SRT_Union
1a430 20 20 20 31 20 20 2f 2a 20 53 74 6f 72 65 20 72 1 /* Store r
1a440 65 73 75 6c 74 20 61 73 20 6b 65 79 73 20 69 6e esult as keys in
1a450 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 an index */.#de
1a460 66 69 6e 65 20 53 52 54 5f 45 78 63 65 70 74 20 fine SRT_Except
1a470 20 20 20 20 20 20 32 20 20 2f 2a 20 52 65 6d 6f 2 /* Remo
1a480 76 65 20 72 65 73 75 6c 74 20 66 72 6f 6d 20 61 ve result from a
1a490 20 55 4e 49 4f 4e 20 69 6e 64 65 78 20 2a 2f 0a UNION index */.
1a4a0 23 64 65 66 69 6e 65 20 53 52 54 5f 45 78 69 73 #define SRT_Exis
1a4b0 74 73 20 20 20 20 20 20 20 33 20 20 2f 2a 20 53 ts 3 /* S
1a4c0 74 6f 72 65 20 31 20 69 66 20 74 68 65 20 72 65 tore 1 if the re
1a4d0 73 75 6c 74 20 69 73 20 6e 6f 74 20 65 6d 70 74 sult is not empt
1a4e0 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 y */.#define SRT
1a4f0 5f 44 69 73 63 61 72 64 20 20 20 20 20 20 34 20 _Discard 4
1a500 20 2f 2a 20 44 6f 20 6e 6f 74 20 73 61 76 65 20 /* Do not save
1a510 74 68 65 20 72 65 73 75 6c 74 73 20 61 6e 79 77 the results anyw
1a520 68 65 72 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 here */.#define
1a530 53 52 54 5f 46 69 66 6f 20 20 20 20 20 20 20 20 SRT_Fifo
1a540 20 35 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 5 /* Store res
1a550 75 6c 74 20 61 73 20 64 61 74 61 20 77 69 74 68 ult as data with
1a560 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 6f an automatic ro
1a570 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 wid */.#define S
1a580 52 54 5f 44 69 73 74 46 69 66 6f 20 20 20 20 20 RT_DistFifo
1a590 36 20 20 2f 2a 20 4c 69 6b 65 20 53 52 54 5f 46 6 /* Like SRT_F
1a5a0 69 66 6f 2c 20 62 75 74 20 75 6e 69 71 75 65 20 ifo, but unique
1a5b0 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 2a 2f 0a results only */.
1a5c0 23 64 65 66 69 6e 65 20 53 52 54 5f 51 75 65 75 #define SRT_Queu
1a5d0 65 20 20 20 20 20 20 20 20 37 20 20 2f 2a 20 53 e 7 /* S
1a5e0 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e 20 61 tore result in a
1a5f0 6e 20 71 75 65 75 65 20 2a 2f 0a 23 64 65 66 69 n queue */.#defi
1a600 6e 65 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 ne SRT_DistQueue
1a610 20 20 20 20 38 20 20 2f 2a 20 4c 69 6b 65 20 53 8 /* Like S
1a620 52 54 5f 51 75 65 75 65 2c 20 62 75 74 20 75 6e RT_Queue, but un
1a630 69 71 75 65 20 72 65 73 75 6c 74 73 20 6f 6e 6c ique results onl
1a640 79 20 2a 2f 0a 0a 2f 2a 20 54 68 65 20 4f 52 44 y */../* The ORD
1a650 45 52 20 42 59 20 63 6c 61 75 73 65 20 69 73 20 ER BY clause is
1a660 69 67 6e 6f 72 65 64 20 66 6f 72 20 61 6c 6c 20 ignored for all
1a670 6f 66 20 74 68 65 20 61 62 6f 76 65 20 2a 2f 0a of the above */.
1a680 23 64 65 66 69 6e 65 20 49 67 6e 6f 72 61 62 6c #define Ignorabl
1a690 65 4f 72 64 65 72 62 79 28 58 29 20 28 28 58 2d eOrderby(X) ((X-
1a6a0 3e 65 44 65 73 74 29 3c 3d 53 52 54 5f 44 69 73 >eDest)<=SRT_Dis
1a6b0 74 51 75 65 75 65 29 0a 0a 23 64 65 66 69 6e 65 tQueue)..#define
1a6c0 20 53 52 54 5f 4f 75 74 70 75 74 20 20 20 20 20 SRT_Output
1a6d0 20 20 39 20 20 2f 2a 20 4f 75 74 70 75 74 20 65 9 /* Output e
1a6e0 61 63 68 20 72 6f 77 20 6f 66 20 72 65 73 75 6c ach row of resul
1a6f0 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 t */.#define SRT
1a700 5f 4d 65 6d 20 20 20 20 20 20 20 20 20 31 30 20 _Mem 10
1a710 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 /* Store result
1a720 20 69 6e 20 61 20 6d 65 6d 6f 72 79 20 63 65 6c in a memory cel
1a730 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 l */.#define SRT
1a740 5f 53 65 74 20 20 20 20 20 20 20 20 20 31 31 20 _Set 11
1a750 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 /* Store result
1a760 73 20 61 73 20 6b 65 79 73 20 69 6e 20 61 6e 20 s as keys in an
1a770 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 index */.#define
1a780 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 20 20 SRT_EphemTab
1a790 20 31 32 20 20 2f 2a 20 43 72 65 61 74 65 20 74 12 /* Create t
1a7a0 72 61 6e 73 69 65 6e 74 20 74 61 62 20 61 6e 64 ransient tab and
1a7b0 20 73 74 6f 72 65 20 6c 69 6b 65 20 53 52 54 5f store like SRT_
1a7c0 54 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 Table */.#define
1a7d0 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 SRT_Coroutine
1a7e0 20 31 33 20 20 2f 2a 20 47 65 6e 65 72 61 74 65 13 /* Generate
1a7f0 20 61 20 73 69 6e 67 6c 65 20 72 6f 77 20 6f 66 a single row of
1a800 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 69 result */.#defi
1a810 6e 65 20 53 52 54 5f 54 61 62 6c 65 20 20 20 20 ne SRT_Table
1a820 20 20 20 31 34 20 20 2f 2a 20 53 74 6f 72 65 20 14 /* Store
1a830 72 65 73 75 6c 74 20 61 73 20 64 61 74 61 20 77 result as data w
1a840 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 ith an automatic
1a850 20 72 6f 77 69 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a rowid */../*.**
1a860 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
1a870 74 68 69 73 20 6f 62 6a 65 63 74 20 64 65 73 63 this object desc
1a880 72 69 62 65 73 20 77 68 65 72 65 20 74 6f 20 70 ribes where to p
1a890 75 74 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 ut of the result
1a8a0 73 20 6f 66 0a 2a 2a 20 61 20 53 45 4c 45 43 54 s of.** a SELECT
1a8b0 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 statement..*/.s
1a8c0 74 72 75 63 74 20 53 65 6c 65 63 74 44 65 73 74 truct SelectDest
1a8d0 20 7b 0a 20 20 75 38 20 65 44 65 73 74 3b 20 20 {. u8 eDest;
1a8e0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 6f 77 /* How
1a8f0 20 74 6f 20 64 69 73 70 6f 73 65 20 6f 66 20 74 to dispose of t
1a900 68 65 20 72 65 73 75 6c 74 73 2e 20 20 4f 6e 20 he results. On
1a910 6f 66 20 53 52 54 5f 2a 20 61 62 6f 76 65 2e 20 of SRT_* above.
1a920 2a 2f 0a 20 20 63 68 61 72 20 61 66 66 53 64 73 */. char affSds
1a930 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 66 66 t; /* Aff
1a940 69 6e 69 74 79 20 75 73 65 64 20 77 68 65 6e 20 inity used when
1a950 65 44 65 73 74 3d 3d 53 52 54 5f 53 65 74 20 2a eDest==SRT_Set *
1a960 2f 0a 20 20 69 6e 74 20 69 53 44 50 61 72 6d 3b /. int iSDParm;
1a970 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 70 61 /* A pa
1a980 72 61 6d 65 74 65 72 20 75 73 65 64 20 62 79 20 rameter used by
1a990 74 68 65 20 65 44 65 73 74 20 64 69 73 70 6f 73 the eDest dispos
1a9a0 61 6c 20 6d 65 74 68 6f 64 20 2a 2f 0a 20 20 69 al method */. i
1a9b0 6e 74 20 69 53 64 73 74 3b 20 20 20 20 20 20 20 nt iSdst;
1a9c0 20 20 20 20 2f 2a 20 42 61 73 65 20 72 65 67 69 /* Base regi
1a9d0 73 74 65 72 20 77 68 65 72 65 20 72 65 73 75 6c ster where resul
1a9e0 74 73 20 61 72 65 20 77 72 69 74 74 65 6e 20 2a ts are written *
1a9f0 2f 0a 20 20 69 6e 74 20 6e 53 64 73 74 3b 20 20 /. int nSdst;
1aa00 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1aa10 65 72 20 6f 66 20 72 65 67 69 73 74 65 72 73 20 er of registers
1aa20 61 6c 6c 6f 63 61 74 65 64 20 2a 2f 0a 20 20 45 allocated */. E
1aa30 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 42 xprList *pOrderB
1aa40 79 3b 20 20 2f 2a 20 4b 65 79 20 63 6f 6c 75 6d y; /* Key colum
1aa50 6e 73 20 66 6f 72 20 53 52 54 5f 51 75 65 75 65 ns for SRT_Queue
1aa60 20 61 6e 64 20 53 52 54 5f 44 69 73 74 51 75 65 and SRT_DistQue
1aa70 75 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ue */.};../*.**
1aa80 44 75 72 69 6e 67 20 63 6f 64 65 20 67 65 6e 65 During code gene
1aa90 72 61 74 69 6f 6e 20 6f 66 20 73 74 61 74 65 6d ration of statem
1aaa0 65 6e 74 73 20 74 68 61 74 20 64 6f 20 69 6e 73 ents that do ins
1aab0 65 72 74 73 20 69 6e 74 6f 20 41 55 54 4f 49 4e erts into AUTOIN
1aac0 43 52 45 4d 45 4e 54 20 0a 2a 2a 20 74 61 62 6c CREMENT .** tabl
1aad0 65 73 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e es, the followin
1aae0 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 73 g information is
1aaf0 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 65 attached to the
1ab00 20 54 61 62 6c 65 2e 75 2e 61 75 74 6f 49 6e 63 Table.u.autoInc
1ab10 2e 70 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 6f 66 .p.** pointer of
1ab20 20 65 61 63 68 20 61 75 74 6f 69 6e 63 72 65 6d each autoincrem
1ab30 65 6e 74 20 74 61 62 6c 65 20 74 6f 20 72 65 63 ent table to rec
1ab40 6f 72 64 20 73 6f 6d 65 20 73 69 64 65 20 69 6e ord some side in
1ab50 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 74 0a 2a formation that.*
1ab60 2a 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 * the code gener
1ab70 61 74 6f 72 20 6e 65 65 64 73 2e 20 20 57 65 20 ator needs. We
1ab80 68 61 76 65 20 74 6f 20 6b 65 65 70 20 70 65 72 have to keep per
1ab90 2d 74 61 62 6c 65 20 61 75 74 6f 69 6e 63 72 65 -table autoincre
1aba0 6d 65 6e 74 0a 2a 2a 20 69 6e 66 6f 72 6d 61 74 ment.** informat
1abb0 69 6f 6e 20 69 6e 20 63 61 73 65 20 69 6e 73 65 ion in case inse
1abc0 72 74 73 20 61 72 65 20 64 6f 77 6e 20 77 69 74 rts are down wit
1abd0 68 69 6e 20 74 72 69 67 67 65 72 73 2e 20 20 54 hin triggers. T
1abe0 72 69 67 67 65 72 73 20 64 6f 20 6e 6f 74 0a 2a riggers do not.*
1abf0 2a 20 6e 6f 72 6d 61 6c 6c 79 20 63 6f 6f 72 64 * normally coord
1ac00 69 6e 61 74 65 20 74 68 65 69 72 20 61 63 74 69 inate their acti
1ac10 76 69 74 69 65 73 2c 20 62 75 74 20 77 65 20 64 vities, but we d
1ac20 6f 20 6e 65 65 64 20 74 6f 20 63 6f 6f 72 64 69 o need to coordi
1ac30 6e 61 74 65 20 74 68 65 0a 2a 2a 20 6c 6f 61 64 nate the.** load
1ac40 69 6e 67 20 61 6e 64 20 73 61 76 69 6e 67 20 6f ing and saving o
1ac50 66 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 f autoincrement
1ac60 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a information..*/.
1ac70 73 74 72 75 63 74 20 41 75 74 6f 69 6e 63 49 6e struct AutoincIn
1ac80 66 6f 20 7b 0a 20 20 41 75 74 6f 69 6e 63 49 6e fo {. AutoincIn
1ac90 66 6f 20 2a 70 4e 65 78 74 3b 20 20 20 2f 2a 20 fo *pNext; /*
1aca0 4e 65 78 74 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 Next info block
1acb0 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 74 68 65 in a list of the
1acc0 6d 20 61 6c 6c 20 2a 2f 0a 20 20 54 61 62 6c 65 m all */. Table
1acd0 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 *pTab;
1ace0 20 2f 2a 20 54 61 62 6c 65 20 74 68 69 73 20 69 /* Table this i
1acf0 6e 66 6f 20 62 6c 6f 63 6b 20 72 65 66 65 72 73 nfo block refers
1ad00 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 to */. int iDb
1ad10 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
1ad20 2a 20 49 6e 64 65 78 20 69 6e 20 73 71 6c 69 74 * Index in sqlit
1ad30 65 33 2e 61 44 62 5b 5d 20 6f 66 20 64 61 74 61 e3.aDb[] of data
1ad40 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 70 54 61 base holding pTa
1ad50 62 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 43 74 b */. int regCt
1ad60 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
1ad70 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 20 Memory register
1ad80 68 6f 6c 64 69 6e 67 20 74 68 65 20 72 6f 77 69 holding the rowi
1ad90 64 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 7d 3b 0a d counter */.};.
1ada0 0a 2f 2a 0a 2a 2a 20 53 69 7a 65 20 6f 66 20 74 ./*.** Size of t
1adb0 68 65 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 0a he column cache.
1adc0 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
1add0 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 0a 23 20 64 E_N_COLCACHE.# d
1ade0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 43 efine SQLITE_N_C
1adf0 4f 4c 43 41 43 48 45 20 31 30 0a 23 65 6e 64 69 OLCACHE 10.#endi
1ae00 66 0a 0a 2f 2a 0a 2a 2a 20 41 74 20 6c 65 61 73 f../*.** At leas
1ae10 74 20 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f t one instance o
1ae20 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
1ae30 73 74 72 75 63 74 75 72 65 20 69 73 20 63 72 65 structure is cre
1ae40 61 74 65 64 20 66 6f 72 20 65 61 63 68 20 0a 2a ated for each .*
1ae50 2a 20 74 72 69 67 67 65 72 20 74 68 61 74 20 6d * trigger that m
1ae60 61 79 20 62 65 20 66 69 72 65 64 20 77 68 69 6c ay be fired whil
1ae70 65 20 70 61 72 73 69 6e 67 20 61 6e 20 49 4e 53 e parsing an INS
1ae80 45 52 54 2c 20 55 50 44 41 54 45 20 6f 72 20 44 ERT, UPDATE or D
1ae90 45 4c 45 54 45 0a 2a 2a 20 73 74 61 74 65 6d 65 ELETE.** stateme
1aea0 6e 74 2e 20 41 6c 6c 20 73 75 63 68 20 6f 62 6a nt. All such obj
1aeb0 65 63 74 73 20 61 72 65 20 73 74 6f 72 65 64 20 ects are stored
1aec0 69 6e 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 in the linked li
1aed0 73 74 20 68 65 61 64 65 64 20 61 74 0a 2a 2a 20 st headed at.**
1aee0 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 Parse.pTriggerPr
1aef0 67 20 61 6e 64 20 64 65 6c 65 74 65 64 20 6f 6e g and deleted on
1af00 63 65 20 73 74 61 74 65 6d 65 6e 74 20 63 6f 6d ce statement com
1af10 70 69 6c 61 74 69 6f 6e 20 68 61 73 20 62 65 65 pilation has bee
1af20 6e 0a 2a 2a 20 63 6f 6d 70 6c 65 74 65 64 2e 0a n.** completed..
1af30 2a 2a 0a 2a 2a 20 41 20 56 64 62 65 20 73 75 62 **.** A Vdbe sub
1af40 2d 70 72 6f 67 72 61 6d 20 74 68 61 74 20 69 6d -program that im
1af50 70 6c 65 6d 65 6e 74 73 20 74 68 65 20 62 6f 64 plements the bod
1af60 79 20 61 6e 64 20 57 48 45 4e 20 63 6c 61 75 73 y and WHEN claus
1af70 65 20 6f 66 20 74 72 69 67 67 65 72 0a 2a 2a 20 e of trigger.**
1af80 54 72 69 67 67 65 72 50 72 67 2e 70 54 72 69 67 TriggerPrg.pTrig
1af90 67 65 72 2c 20 61 73 73 75 6d 69 6e 67 20 61 20 ger, assuming a
1afa0 64 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c default ON CONFL
1afb0 49 43 54 20 63 6c 61 75 73 65 20 6f 66 0a 2a 2a ICT clause of.**
1afc0 20 54 72 69 67 67 65 72 50 72 67 2e 6f 72 63 6f TriggerPrg.orco
1afd0 6e 66 2c 20 69 73 20 73 74 6f 72 65 64 20 69 6e nf, is stored in
1afe0 20 74 68 65 20 54 72 69 67 67 65 72 50 72 67 2e the TriggerPrg.
1aff0 70 50 72 6f 67 72 61 6d 20 76 61 72 69 61 62 6c pProgram variabl
1b000 65 2e 0a 2a 2a 20 54 68 65 20 50 61 72 73 65 2e e..** The Parse.
1b010 70 54 72 69 67 67 65 72 50 72 67 20 6c 69 73 74 pTriggerPrg list
1b020 20 6e 65 76 65 72 20 63 6f 6e 74 61 69 6e 73 20 never contains
1b030 74 77 6f 20 65 6e 74 72 69 65 73 20 77 69 74 68 two entries with
1b040 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 76 61 6c the same.** val
1b050 75 65 73 20 66 6f 72 20 62 6f 74 68 20 70 54 72 ues for both pTr
1b060 69 67 67 65 72 20 61 6e 64 20 6f 72 63 6f 6e 66 igger and orconf
1b070 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 54 72 69 67 ..**.** The Trig
1b080 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b gerPrg.aColmask[
1b090 30 5d 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 0] variable is s
1b0a0 65 74 20 74 6f 20 61 20 6d 61 73 6b 20 6f 66 20 et to a mask of
1b0b0 6f 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 0a 2a 2a old.* columns.**
1b0c0 20 61 63 63 65 73 73 65 64 20 28 6f 72 20 73 65 accessed (or se
1b0d0 74 20 74 6f 20 30 20 66 6f 72 20 74 72 69 67 67 t to 0 for trigg
1b0e0 65 72 73 20 66 69 72 65 64 20 61 73 20 61 20 72 ers fired as a r
1b0f0 65 73 75 6c 74 20 6f 66 20 49 4e 53 45 52 54 20 esult of INSERT
1b100 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 73 29 2e .** statements).
1b110 20 53 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65 20 Similarly, the
1b120 54 72 69 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d TriggerPrg.aColm
1b130 61 73 6b 5b 31 5d 20 76 61 72 69 61 62 6c 65 20 ask[1] variable
1b140 69 73 20 73 65 74 20 74 6f 0a 2a 2a 20 61 20 6d is set to.** a m
1b150 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c ask of new.* col
1b160 75 6d 6e 73 20 75 73 65 64 20 62 79 20 74 68 65 umns used by the
1b170 20 70 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 program..*/.str
1b180 75 63 74 20 54 72 69 67 67 65 72 50 72 67 20 7b uct TriggerPrg {
1b190 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 . Trigger *pTri
1b1a0 67 67 65 72 3b 20 20 20 20 20 20 2f 2a 20 54 72 gger; /* Tr
1b1b0 69 67 67 65 72 20 74 68 69 73 20 70 72 6f 67 72 igger this progr
1b1c0 61 6d 20 77 61 73 20 63 6f 64 65 64 20 66 72 6f am was coded fro
1b1d0 6d 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 72 m */. TriggerPr
1b1e0 67 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 2f g *pNext; /
1b1f0 2a 20 4e 65 78 74 20 65 6e 74 72 79 20 69 6e 20 * Next entry in
1b200 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 Parse.pTriggerPr
1b210 67 20 6c 69 73 74 20 2a 2f 0a 20 20 53 75 62 50 g list */. SubP
1b220 72 6f 67 72 61 6d 20 2a 70 50 72 6f 67 72 61 6d rogram *pProgram
1b230 3b 20 20 20 2f 2a 20 50 72 6f 67 72 61 6d 20 69 ; /* Program i
1b240 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 70 54 72 69 mplementing pTri
1b250 67 67 65 72 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 gger/orconf */.
1b260 20 69 6e 74 20 6f 72 63 6f 6e 66 3b 20 20 20 20 int orconf;
1b270 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 /* Defa
1b280 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 ult ON CONFLICT
1b290 70 6f 6c 69 63 79 20 2a 2f 0a 20 20 75 33 32 20 policy */. u32
1b2a0 61 43 6f 6c 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 aColmask[2];
1b2b0 20 20 20 20 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 /* Masks of
1b2c0 6f 6c 64 2e 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c old.*, new.* col
1b2d0 75 6d 6e 73 20 61 63 63 65 73 73 65 64 20 2a 2f umns accessed */
1b2e0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 .};../*.** The y
1b2f0 44 62 4d 61 73 6b 20 64 61 74 61 74 79 70 65 20 DbMask datatype
1b300 66 6f 72 20 74 68 65 20 62 69 74 6d 61 73 6b 20 for the bitmask
1b310 6f 66 20 61 6c 6c 20 61 74 74 61 63 68 65 64 20 of all attached
1b320 64 61 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 databases..*/.#i
1b330 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 f SQLITE_MAX_ATT
1b340 41 43 48 45 44 3e 33 30 0a 20 20 74 79 70 65 64 ACHED>30. typed
1b350 65 66 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 ef unsigned char
1b360 20 79 44 62 4d 61 73 6b 5b 28 53 51 4c 49 54 45 yDbMask[(SQLITE
1b370 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 2b 39 29 _MAX_ATTACHED+9)
1b380 2f 38 5d 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 /8];.# define Db
1b390 4d 61 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 MaskTest(M,I)
1b3a0 20 28 28 28 4d 29 5b 28 49 29 2f 38 5d 26 28 31 (((M)[(I)/8]&(1
1b3b0 3c 3c 28 28 49 29 26 37 29 29 29 21 3d 30 29 0a <<((I)&7)))!=0).
1b3c0 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a # define DbMaskZ
1b3d0 65 72 6f 28 4d 29 20 20 20 20 20 20 6d 65 6d 73 ero(M) mems
1b3e0 65 74 28 28 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 et((M),0,sizeof(
1b3f0 4d 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d M)).# define DbM
1b400 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 20 askSet(M,I)
1b410 28 4d 29 5b 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c (M)[(I)/8]|=(1<<
1b420 28 28 49 29 26 37 29 29 0a 23 20 64 65 66 69 6e ((I)&7)).# defin
1b430 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 e DbMaskAllZero(
1b440 4d 29 20 20 20 73 71 6c 69 74 65 33 44 62 4d 61 M) sqlite3DbMa
1b450 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 skAllZero(M).# d
1b460 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a efine DbMaskNonZ
1b470 65 72 6f 28 4d 29 20 20 20 28 73 71 6c 69 74 65 ero(M) (sqlite
1b480 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 3DbMaskAllZero(M
1b490 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 20 20 74 79 )==0).#else. ty
1b4a0 70 65 64 65 66 20 75 6e 73 69 67 6e 65 64 20 69 pedef unsigned i
1b4b0 6e 74 20 79 44 62 4d 61 73 6b 3b 0a 23 20 64 65 nt yDbMask;.# de
1b4c0 66 69 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 fine DbMaskTest(
1b4d0 4d 2c 49 29 20 20 20 20 28 28 28 4d 29 26 28 28 M,I) (((M)&((
1b4e0 28 79 44 62 4d 61 73 6b 29 31 29 3c 3c 28 49 29 (yDbMask)1)<<(I)
1b4f0 29 29 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 ))!=0).# define
1b500 44 62 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 DbMaskZero(M)
1b510 20 20 20 28 4d 29 3d 30 0a 23 20 64 65 66 69 6e (M)=0.# defin
1b520 65 20 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 29 e DbMaskSet(M,I)
1b530 20 20 20 20 20 28 4d 29 7c 3d 28 28 28 79 44 62 (M)|=(((yDb
1b540 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 0a 23 20 Mask)1)<<(I)).#
1b550 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c 6c define DbMaskAll
1b560 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 3d 3d 30 Zero(M) (M)==0
1b570 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b .# define DbMask
1b580 4e 6f 6e 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 NonZero(M) (M)
1b590 21 3d 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a !=0.#endif../*.*
1b5a0 2a 20 41 6e 20 53 51 4c 20 70 61 72 73 65 72 20 * An SQL parser
1b5b0 63 6f 6e 74 65 78 74 2e 20 20 41 20 63 6f 70 79 context. A copy
1b5c0 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 of this structu
1b5d0 72 65 20 69 73 20 70 61 73 73 65 64 20 74 68 72 re is passed thr
1b5e0 6f 75 67 68 0a 2a 2a 20 74 68 65 20 70 61 72 73 ough.** the pars
1b5f0 65 72 20 61 6e 64 20 64 6f 77 6e 20 69 6e 74 6f er and down into
1b600 20 61 6c 6c 20 74 68 65 20 70 61 72 73 65 72 20 all the parser
1b610 61 63 74 69 6f 6e 20 72 6f 75 74 69 6e 65 20 69 action routine i
1b620 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 63 61 n order to.** ca
1b630 72 72 79 20 61 72 6f 75 6e 64 20 69 6e 66 6f 72 rry around infor
1b640 6d 61 74 69 6f 6e 20 74 68 61 74 20 69 73 20 67 mation that is g
1b650 6c 6f 62 61 6c 20 74 6f 20 74 68 65 20 65 6e 74 lobal to the ent
1b660 69 72 65 20 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a ire parse..**.**
1b670 20 54 68 65 20 73 74 72 75 63 74 75 72 65 20 69 The structure i
1b680 73 20 64 69 76 69 64 65 64 20 69 6e 74 6f 20 74 s divided into t
1b690 77 6f 20 70 61 72 74 73 2e 20 20 57 68 65 6e 20 wo parts. When
1b6a0 74 68 65 20 70 61 72 73 65 72 20 61 6e 64 20 63 the parser and c
1b6b0 6f 64 65 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 ode.** generate
1b6c0 63 61 6c 6c 20 74 68 65 6d 73 65 6c 76 65 73 20 call themselves
1b6d0 72 65 63 75 72 73 69 76 65 6c 79 2c 20 74 68 65 recursively, the
1b6e0 20 66 69 72 73 74 20 70 61 72 74 20 6f 66 20 74 first part of t
1b6f0 68 65 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 he structure.**
1b700 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 75 74 20 is constant but
1b710 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 74 20 the second part
1b720 69 73 20 72 65 73 65 74 20 61 74 20 74 68 65 20 is reset at the
1b730 62 65 67 69 6e 6e 69 6e 67 20 61 6e 64 20 65 6e beginning and en
1b740 64 20 6f 66 0a 2a 2a 20 65 61 63 68 20 72 65 63 d of.** each rec
1b750 75 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 ursion..**.** Th
1b760 65 20 6e 54 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 e nTableLock and
1b770 20 61 54 61 62 6c 65 4c 6f 63 6b 20 76 61 72 69 aTableLock vari
1b780 61 62 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 75 ables are only u
1b790 73 65 64 20 69 66 20 74 68 65 20 73 68 61 72 65 sed if the share
1b7a0 64 2d 63 61 63 68 65 20 0a 2a 2a 20 66 65 61 74 d-cache .** feat
1b7b0 75 72 65 20 69 73 20 65 6e 61 62 6c 65 64 20 28 ure is enabled (
1b7c0 69 66 20 73 71 6c 69 74 65 33 54 73 64 28 29 2d if sqlite3Tsd()-
1b7d0 3e 75 73 65 53 68 61 72 65 64 44 61 74 61 20 69 >useSharedData i
1b7e0 73 20 74 72 75 65 29 2e 20 54 68 65 79 20 61 72 s true). They ar
1b7f0 65 0a 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f e.** used to sto
1b800 72 65 20 74 68 65 20 73 65 74 20 6f 66 20 74 61 re the set of ta
1b810 62 6c 65 2d 6c 6f 63 6b 73 20 72 65 71 75 69 72 ble-locks requir
1b820 65 64 20 62 79 20 74 68 65 20 73 74 61 74 65 6d ed by the statem
1b830 65 6e 74 20 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d ent being.** com
1b840 70 69 6c 65 64 2e 20 46 75 6e 63 74 69 6f 6e 20 piled. Function
1b850 73 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b sqlite3TableLock
1b860 28 29 20 69 73 20 75 73 65 64 20 74 6f 20 61 64 () is used to ad
1b870 64 20 65 6e 74 72 69 65 73 20 74 6f 20 74 68 65 d entries to the
1b880 0a 2a 2a 20 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 .** list..*/.str
1b890 75 63 74 20 50 61 72 73 65 20 7b 0a 20 20 73 71 uct Parse {. sq
1b8a0 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 lite3 *db;
1b8b0 20 20 20 2f 2a 20 54 68 65 20 6d 61 69 6e 20 64 /* The main d
1b8c0 61 74 61 62 61 73 65 20 73 74 72 75 63 74 75 72 atabase structur
1b8d0 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 45 72 e */. char *zEr
1b8e0 72 4d 73 67 3b 20 20 20 20 20 20 20 2f 2a 20 41 rMsg; /* A
1b8f0 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 n error message
1b900 2a 2f 0a 20 20 56 64 62 65 20 2a 70 56 64 62 65 */. Vdbe *pVdbe
1b910 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 ; /* An
1b920 65 6e 67 69 6e 65 20 66 6f 72 20 65 78 65 63 75 engine for execu
1b930 74 69 6e 67 20 64 61 74 61 62 61 73 65 20 62 79 ting database by
1b940 74 65 63 6f 64 65 20 2a 2f 0a 20 20 69 6e 74 20 tecode */. int
1b950 72 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rc;
1b960 20 2f 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 /* Return code
1b970 66 72 6f 6d 20 65 78 65 63 75 74 69 6f 6e 20 2a from execution *
1b980 2f 0a 20 20 75 38 20 63 6f 6c 4e 61 6d 65 73 53 /. u8 colNamesS
1b990 65 74 3b 20 20 20 20 20 20 2f 2a 20 54 52 55 45 et; /* TRUE
1b9a0 20 61 66 74 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e after OP_Column
1b9b0 4e 61 6d 65 20 68 61 73 20 62 65 65 6e 20 69 73 Name has been is
1b9c0 73 75 65 64 20 74 6f 20 70 56 64 62 65 20 2a 2f sued to pVdbe */
1b9d0 0a 20 20 75 38 20 63 68 65 63 6b 53 63 68 65 6d . u8 checkSchem
1b9e0 61 3b 20 20 20 20 20 20 2f 2a 20 43 61 75 73 65 a; /* Cause
1b9f0 73 20 73 63 68 65 6d 61 20 63 6f 6f 6b 69 65 20 s schema cookie
1ba00 63 68 65 63 6b 20 61 66 74 65 72 20 61 6e 20 65 check after an e
1ba10 72 72 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 65 73 rror */. u8 nes
1ba20 74 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f ted; /
1ba30 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 * Number of nest
1ba40 65 64 20 63 61 6c 6c 73 20 74 6f 20 74 68 65 20 ed calls to the
1ba50 70 61 72 73 65 72 2f 63 6f 64 65 20 67 65 6e 65 parser/code gene
1ba60 72 61 74 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 54 rator */. u8 nT
1ba70 65 6d 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 empReg;
1ba80 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 74 65 6d /* Number of tem
1ba90 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 73 porary registers
1baa0 20 69 6e 20 61 54 65 6d 70 52 65 67 5b 5d 20 2a in aTempReg[] *
1bab0 2f 0a 20 20 75 38 20 69 73 4d 75 6c 74 69 57 72 /. u8 isMultiWr
1bac0 69 74 65 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 ite; /* True
1bad0 20 69 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 if statement ma
1bae0 79 20 6d 6f 64 69 66 79 2f 69 6e 73 65 72 74 20 y modify/insert
1baf0 6d 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f multiple rows */
1bb00 0a 20 20 75 38 20 6d 61 79 41 62 6f 72 74 3b 20 . u8 mayAbort;
1bb10 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1bb20 69 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 if statement may
1bb30 20 74 68 72 6f 77 20 61 6e 20 41 42 4f 52 54 20 throw an ABORT
1bb40 65 78 63 65 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 exception */. u
1bb50 38 20 68 61 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 8 hasCompound;
1bb60 20 20 20 20 2f 2a 20 4e 65 65 64 20 74 6f 20 69 /* Need to i
1bb70 6e 76 6f 6b 65 20 63 6f 6e 76 65 72 74 43 6f 6d nvoke convertCom
1bb80 70 6f 75 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 poundSelectToSub
1bb90 71 75 65 72 79 28 29 20 2a 2f 0a 20 20 75 38 20 query() */. u8
1bba0 6f 6b 43 6f 6e 73 74 46 61 63 74 6f 72 3b 20 20 okConstFactor;
1bbb0 20 20 2f 2a 20 4f 4b 20 74 6f 20 66 61 63 74 6f /* OK to facto
1bbc0 72 20 6f 75 74 20 63 6f 6e 73 74 61 6e 74 73 20 r out constants
1bbd0 2a 2f 0a 20 20 69 6e 74 20 61 54 65 6d 70 52 65 */. int aTempRe
1bbe0 67 5b 38 5d 3b 20 20 20 20 20 2f 2a 20 48 6f 6c g[8]; /* Hol
1bbf0 64 69 6e 67 20 61 72 65 61 20 66 6f 72 20 74 65 ding area for te
1bc00 6d 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 mporary register
1bc10 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 61 6e 67 s */. int nRang
1bc20 65 52 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 53 eReg; /* S
1bc30 69 7a 65 20 6f 66 20 74 68 65 20 74 65 6d 70 6f ize of the tempo
1bc40 72 61 72 79 20 72 65 67 69 73 74 65 72 20 62 6c rary register bl
1bc50 6f 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 69 52 61 ock */. int iRa
1bc60 6e 67 65 52 65 67 3b 20 20 20 20 20 20 20 2f 2a ngeReg; /*
1bc70 20 46 69 72 73 74 20 72 65 67 69 73 74 65 72 20 First register
1bc80 69 6e 20 74 65 6d 70 6f 72 61 72 79 20 72 65 67 in temporary reg
1bc90 69 73 74 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 ister block */.
1bca0 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 20 20 20 int nErr;
1bcb0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1bcc0 6f 66 20 65 72 72 6f 72 73 20 73 65 65 6e 20 2a of errors seen *
1bcd0 2f 0a 20 20 69 6e 74 20 6e 54 61 62 3b 20 20 20 /. int nTab;
1bce0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1bcf0 65 72 20 6f 66 20 70 72 65 76 69 6f 75 73 6c 79 er of previously
1bd00 20 61 6c 6c 6f 63 61 74 65 64 20 56 44 42 45 20 allocated VDBE
1bd10 63 75 72 73 6f 72 73 20 2a 2f 0a 20 20 69 6e 74 cursors */. int
1bd20 20 6e 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 nMem;
1bd30 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6d /* Number of m
1bd40 65 6d 6f 72 79 20 63 65 6c 6c 73 20 75 73 65 64 emory cells used
1bd50 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 so far */. int
1bd60 20 6e 53 65 74 3b 20 20 20 20 20 20 20 20 20 20 nSet;
1bd70 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 /* Number of s
1bd80 65 74 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 ets used so far
1bd90 2a 2f 0a 20 20 69 6e 74 20 6e 4f 6e 63 65 3b 20 */. int nOnce;
1bda0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1bdb0 62 65 72 20 6f 66 20 4f 50 5f 4f 6e 63 65 20 69 ber of OP_Once i
1bdc0 6e 73 74 72 75 63 74 69 6f 6e 73 20 73 6f 20 66 nstructions so f
1bdd0 61 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 4f 70 41 ar */. int nOpA
1bde0 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 lloc; /*
1bdf0 4e 75 6d 62 65 72 20 6f 66 20 73 6c 6f 74 73 20 Number of slots
1be00 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 56 64 allocated for Vd
1be10 62 65 2e 61 4f 70 5b 5d 20 2a 2f 0a 20 20 69 6e be.aOp[] */. in
1be20 74 20 69 46 69 78 65 64 4f 70 3b 20 20 20 20 20 t iFixedOp;
1be30 20 20 20 2f 2a 20 4e 65 76 65 72 20 62 61 63 6b /* Never back
1be40 20 6f 75 74 20 6f 70 63 6f 64 65 73 20 69 46 69 out opcodes iFi
1be50 78 65 64 4f 70 2d 31 20 6f 72 20 65 61 72 6c 69 xedOp-1 or earli
1be60 65 72 20 2a 2f 0a 20 20 69 6e 74 20 63 6b 42 61 er */. int ckBa
1be70 73 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 se; /*
1be80 42 61 73 65 20 72 65 67 69 73 74 65 72 20 6f 66 Base register of
1be90 20 64 61 74 61 20 64 75 72 69 6e 67 20 63 68 65 data during che
1bea0 63 6b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a ck constraints *
1beb0 2f 0a 20 20 69 6e 74 20 69 50 61 72 74 49 64 78 /. int iPartIdx
1bec0 54 61 62 3b 20 20 20 20 20 2f 2a 20 54 61 62 6c Tab; /* Tabl
1bed0 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
1bee0 74 6f 20 61 20 70 61 72 74 69 61 6c 20 69 6e 64 to a partial ind
1bef0 65 78 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 ex */. int iCac
1bf00 68 65 4c 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 heLevel; /*
1bf10 43 6f 6c 43 61 63 68 65 20 76 61 6c 69 64 20 77 ColCache valid w
1bf20 68 65 6e 20 61 43 6f 6c 43 61 63 68 65 5b 5d 2e hen aColCache[].
1bf30 69 4c 65 76 65 6c 3c 3d 69 43 61 63 68 65 4c 65 iLevel<=iCacheLe
1bf40 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 vel */. int iCa
1bf50 63 68 65 43 6e 74 3b 20 20 20 20 20 20 20 2f 2a cheCnt; /*
1bf60 20 43 6f 75 6e 74 65 72 20 75 73 65 64 20 74 6f Counter used to
1bf70 20 67 65 6e 65 72 61 74 65 20 61 43 6f 6c 43 61 generate aColCa
1bf80 63 68 65 5b 5d 2e 6c 72 75 20 76 61 6c 75 65 73 che[].lru values
1bf90 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 61 62 65 6c */. int nLabel
1bfa0 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ; /* Nu
1bfb0 6d 62 65 72 20 6f 66 20 6c 61 62 65 6c 73 20 75 mber of labels u
1bfc0 73 65 64 20 2a 2f 0a 20 20 69 6e 74 20 2a 61 4c sed */. int *aL
1bfd0 61 62 65 6c 3b 20 20 20 20 20 20 20 20 20 2f 2a abel; /*
1bfe0 20 53 70 61 63 65 20 74 6f 20 68 6f 6c 64 20 74 Space to hold t
1bff0 68 65 20 6c 61 62 65 6c 73 20 2a 2f 0a 20 20 73 he labels */. s
1c000 74 72 75 63 74 20 79 43 6f 6c 43 61 63 68 65 20 truct yColCache
1c010 7b 0a 20 20 20 20 69 6e 74 20 69 54 61 62 6c 65 {. int iTable
1c020 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 ; /* T
1c030 61 62 6c 65 20 63 75 72 73 6f 72 20 6e 75 6d 62 able cursor numb
1c040 65 72 20 2a 2f 0a 20 20 20 20 69 31 36 20 69 43 er */. i16 iC
1c050 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 olumn;
1c060 2f 2a 20 54 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 /* Table column
1c070 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 20 20 75 38 number */. u8
1c080 20 74 65 6d 70 52 65 67 3b 20 20 20 20 20 20 20 tempReg;
1c090 20 20 20 20 2f 2a 20 69 52 65 67 20 69 73 20 61 /* iReg is a
1c0a0 20 74 65 6d 70 20 72 65 67 69 73 74 65 72 20 74 temp register t
1c0b0 68 61 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 hat needs to be
1c0c0 66 72 65 65 64 20 2a 2f 0a 20 20 20 20 69 6e 74 freed */. int
1c0d0 20 69 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 20 iLevel;
1c0e0 20 20 20 2f 2a 20 4e 65 73 74 69 6e 67 20 6c 65 /* Nesting le
1c0f0 76 65 6c 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 vel */. int i
1c100 52 65 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Reg;
1c110 20 2f 2a 20 52 65 67 20 77 69 74 68 20 76 61 6c /* Reg with val
1c120 75 65 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d ue of this colum
1c130 6e 2e 20 30 20 6d 65 61 6e 73 20 6e 6f 6e 65 2e n. 0 means none.
1c140 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6c 72 75 3b */. int lru;
1c150 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1c160 20 4c 65 61 73 74 20 72 65 63 65 6e 74 6c 79 20 Least recently
1c170 75 73 65 64 20 65 6e 74 72 79 20 68 61 73 20 74 used entry has t
1c180 68 65 20 73 6d 61 6c 6c 65 73 74 20 76 61 6c 75 he smallest valu
1c190 65 20 2a 2f 0a 20 20 7d 20 61 43 6f 6c 43 61 63 e */. } aColCac
1c1a0 68 65 5b 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 he[SQLITE_N_COLC
1c1b0 41 43 48 45 5d 3b 20 20 2f 2a 20 4f 6e 65 20 66 ACHE]; /* One f
1c1c0 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 63 or each column c
1c1d0 61 63 68 65 20 65 6e 74 72 79 20 2a 2f 0a 20 20 ache entry */.
1c1e0 45 78 70 72 4c 69 73 74 20 2a 70 43 6f 6e 73 74 ExprList *pConst
1c1f0 45 78 70 72 3b 2f 2a 20 43 6f 6e 73 74 61 6e 74 Expr;/* Constant
1c200 20 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a expressions */.
1c210 20 20 54 6f 6b 65 6e 20 63 6f 6e 73 74 72 61 69 Token constrai
1c220 6e 74 4e 61 6d 65 3b 2f 2a 20 4e 61 6d 65 20 6f ntName;/* Name o
1c230 66 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 f the constraint
1c240 20 63 75 72 72 65 6e 74 6c 79 20 62 65 69 6e 67 currently being
1c250 20 70 61 72 73 65 64 20 2a 2f 0a 20 20 79 44 62 parsed */. yDb
1c260 4d 61 73 6b 20 77 72 69 74 65 4d 61 73 6b 3b 20 Mask writeMask;
1c270 20 20 2f 2a 20 53 74 61 72 74 20 61 20 77 72 69 /* Start a wri
1c280 74 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 6f te transaction o
1c290 6e 20 74 68 65 73 65 20 64 61 74 61 62 61 73 65 n these database
1c2a0 73 20 2a 2f 0a 20 20 79 44 62 4d 61 73 6b 20 63 s */. yDbMask c
1c2b0 6f 6f 6b 69 65 4d 61 73 6b 3b 20 20 2f 2a 20 42 ookieMask; /* B
1c2c0 69 74 6d 61 73 6b 20 6f 66 20 73 63 68 65 6d 61 itmask of schema
1c2d0 20 76 65 72 69 66 69 65 64 20 64 61 74 61 62 61 verified databa
1c2e0 73 65 73 20 2a 2f 0a 20 20 69 6e 74 20 63 6f 6f ses */. int coo
1c2f0 6b 69 65 56 61 6c 75 65 5b 53 51 4c 49 54 45 5f kieValue[SQLITE_
1c300 4d 41 58 5f 41 54 54 41 43 48 45 44 2b 32 5d 3b MAX_ATTACHED+2];
1c310 20 20 2f 2a 20 56 61 6c 75 65 73 20 6f 66 20 63 /* Values of c
1c320 6f 6f 6b 69 65 73 20 74 6f 20 76 65 72 69 66 79 ookies to verify
1c330 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 52 6f 77 */. int regRow
1c340 69 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 52 65 id; /* Re
1c350 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 gister holding r
1c360 6f 77 69 64 20 6f 66 20 43 52 45 41 54 45 20 54 owid of CREATE T
1c370 41 42 4c 45 20 65 6e 74 72 79 20 2a 2f 0a 20 20 ABLE entry */.
1c380 69 6e 74 20 72 65 67 52 6f 6f 74 3b 20 20 20 20 int regRoot;
1c390 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 /* Register
1c3a0 20 68 6f 6c 64 69 6e 67 20 72 6f 6f 74 20 70 61 holding root pa
1c3b0 67 65 20 6e 75 6d 62 65 72 20 66 6f 72 20 6e 65 ge number for ne
1c3c0 77 20 6f 62 6a 65 63 74 73 20 2a 2f 0a 20 20 69 w objects */. i
1c3d0 6e 74 20 6e 4d 61 78 41 72 67 3b 20 20 20 20 20 nt nMaxArg;
1c3e0 20 20 20 20 2f 2a 20 4d 61 78 20 61 72 67 73 20 /* Max args
1c3f0 70 61 73 73 65 64 20 74 6f 20 75 73 65 72 20 66 passed to user f
1c400 75 6e 63 74 69 6f 6e 20 62 79 20 73 75 62 2d 70 unction by sub-p
1c410 72 6f 67 72 61 6d 20 2a 2f 0a 23 69 66 20 53 45 rogram */.#if SE
1c420 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 LECTTRACE_ENABLE
1c430 44 0a 20 20 69 6e 74 20 6e 53 65 6c 65 63 74 3b D. int nSelect;
1c440 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1c450 65 72 20 6f 66 20 53 45 4c 45 43 54 20 73 74 61 er of SELECT sta
1c460 74 65 6d 65 6e 74 73 20 73 65 65 6e 20 2a 2f 0a tements seen */.
1c470 20 20 69 6e 74 20 6e 53 65 6c 65 63 74 49 6e 64 int nSelectInd
1c480 65 6e 74 3b 20 20 20 2f 2a 20 48 6f 77 20 66 61 ent; /* How fa
1c490 72 20 74 6f 20 69 6e 64 65 6e 74 20 53 45 4c 45 r to indent SELE
1c4a0 43 54 54 52 41 43 45 28 29 20 6f 75 74 70 75 74 CTTRACE() output
1c4b0 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 */.#endif.#ifnd
1c4c0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 ef SQLITE_OMIT_S
1c4d0 48 41 52 45 44 5f 43 41 43 48 45 0a 20 20 69 6e HARED_CACHE. in
1c4e0 74 20 6e 54 61 62 6c 65 4c 6f 63 6b 3b 20 20 20 t nTableLock;
1c4f0 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1c500 66 20 6c 6f 63 6b 73 20 69 6e 20 61 54 61 62 6c f locks in aTabl
1c510 65 4c 6f 63 6b 20 2a 2f 0a 20 20 54 61 62 6c 65 eLock */. Table
1c520 4c 6f 63 6b 20 2a 61 54 61 62 6c 65 4c 6f 63 6b Lock *aTableLock
1c530 3b 20 2f 2a 20 52 65 71 75 69 72 65 64 20 74 61 ; /* Required ta
1c540 62 6c 65 20 6c 6f 63 6b 73 20 66 6f 72 20 73 68 ble locks for sh
1c550 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 ared-cache mode
1c560 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 41 75 74 6f */.#endif. Auto
1c570 69 6e 63 49 6e 66 6f 20 2a 70 41 69 6e 63 3b 20 incInfo *pAinc;
1c580 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 /* Information
1c590 61 62 6f 75 74 20 41 55 54 4f 49 4e 43 52 45 4d about AUTOINCREM
1c5a0 45 4e 54 20 63 6f 75 6e 74 65 72 73 20 2a 2f 0a ENT counters */.
1c5b0 0a 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f . /* Informatio
1c5c0 6e 20 75 73 65 64 20 77 68 69 6c 65 20 63 6f 64 n used while cod
1c5d0 69 6e 67 20 74 72 69 67 67 65 72 20 70 72 6f 67 ing trigger prog
1c5e0 72 61 6d 73 2e 20 2a 2f 0a 20 20 50 61 72 73 65 rams. */. Parse
1c5f0 20 2a 70 54 6f 70 6c 65 76 65 6c 3b 20 20 20 20 *pToplevel;
1c600 2f 2a 20 50 61 72 73 65 20 73 74 72 75 63 74 75 /* Parse structu
1c610 72 65 20 66 6f 72 20 6d 61 69 6e 20 70 72 6f 67 re for main prog
1c620 72 61 6d 20 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f ram (or NULL) */
1c630 0a 20 20 54 61 62 6c 65 20 2a 70 54 72 69 67 67 . Table *pTrigg
1c640 65 72 54 61 62 3b 20 20 2f 2a 20 54 61 62 6c 65 erTab; /* Table
1c650 20 74 72 69 67 67 65 72 73 20 61 72 65 20 62 65 triggers are be
1c660 69 6e 67 20 63 6f 64 65 64 20 66 6f 72 20 2a 2f ing coded for */
1c670 0a 20 20 69 6e 74 20 61 64 64 72 43 72 54 61 62 . int addrCrTab
1c680 3b 20 20 20 20 20 20 20 2f 2a 20 41 64 64 72 65 ; /* Addre
1c690 73 73 20 6f 66 20 4f 50 5f 43 72 65 61 74 65 54 ss of OP_CreateT
1c6a0 61 62 6c 65 20 6f 70 63 6f 64 65 20 6f 6e 20 43 able opcode on C
1c6b0 52 45 41 54 45 20 54 41 42 4c 45 20 2a 2f 0a 20 REATE TABLE */.
1c6c0 20 75 33 32 20 6e 51 75 65 72 79 4c 6f 6f 70 3b u32 nQueryLoop;
1c6d0 20 20 20 20 20 20 2f 2a 20 45 73 74 20 6e 75 6d /* Est num
1c6e0 62 65 72 20 6f 66 20 69 74 65 72 61 74 69 6f 6e ber of iteration
1c6f0 73 20 6f 66 20 61 20 71 75 65 72 79 20 28 31 30 s of a query (10
1c700 2a 6c 6f 67 32 28 4e 29 29 20 2a 2f 0a 20 20 75 *log2(N)) */. u
1c710 33 32 20 6f 6c 64 6d 61 73 6b 3b 20 20 20 20 20 32 oldmask;
1c720 20 20 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f /* Mask of o
1c730 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 ld.* columns ref
1c740 65 72 65 6e 63 65 64 20 2a 2f 0a 20 20 75 33 32 erenced */. u32
1c750 20 6e 65 77 6d 61 73 6b 3b 20 20 20 20 20 20 20 newmask;
1c760 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6e 65 77 /* Mask of new
1c770 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 .* columns refer
1c780 65 6e 63 65 64 20 2a 2f 0a 20 20 75 38 20 65 54 enced */. u8 eT
1c790 72 69 67 67 65 72 4f 70 3b 20 20 20 20 20 20 20 riggerOp;
1c7a0 2f 2a 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b /* TK_UPDATE, TK
1c7b0 5f 49 4e 53 45 52 54 20 6f 72 20 54 4b 5f 44 45 _INSERT or TK_DE
1c7c0 4c 45 54 45 20 2a 2f 0a 20 20 75 38 20 65 4f 72 LETE */. u8 eOr
1c7d0 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 20 2f conf; /
1c7e0 2a 20 44 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e * Default ON CON
1c7f0 46 4c 49 43 54 20 70 6f 6c 69 63 79 20 66 6f 72 FLICT policy for
1c800 20 74 72 69 67 67 65 72 20 73 74 65 70 73 20 2a trigger steps *
1c810 2f 0a 20 20 75 38 20 64 69 73 61 62 6c 65 54 72 /. u8 disableTr
1c820 69 67 67 65 72 73 3b 20 20 2f 2a 20 54 72 75 65 iggers; /* True
1c830 20 74 6f 20 64 69 73 61 62 6c 65 20 74 72 69 67 to disable trig
1c840 67 65 72 73 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a gers */.. /****
1c850 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c860 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c870 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c880 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c890 2a 2a 2a 2a 0a 20 20 2a 2a 20 41 62 6f 76 65 20 ****. ** Above
1c8a0 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 65 74 77 is constant betw
1c8b0 65 65 6e 20 72 65 63 75 72 73 69 6f 6e 73 2e 20 een recursions.
1c8c0 20 42 65 6c 6f 77 20 69 73 20 72 65 73 65 74 20 Below is reset
1c8d0 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 72 before and after
1c8e0 0a 20 20 2a 2a 20 65 61 63 68 20 72 65 63 75 72 . ** each recur
1c8f0 73 69 6f 6e 2e 20 20 54 68 65 20 62 6f 75 6e 64 sion. The bound
1c900 61 72 79 20 62 65 74 77 65 65 6e 20 74 68 65 73 ary between thes
1c910 65 20 74 77 6f 20 72 65 67 69 6f 6e 73 20 69 73 e two regions is
1c920 20 64 65 74 65 72 6d 69 6e 65 64 0a 20 20 2a 2a determined. **
1c930 20 75 73 69 6e 67 20 6f 66 66 73 65 74 6f 66 28 using offsetof(
1c940 50 61 72 73 65 2c 6e 56 61 72 29 20 73 6f 20 74 Parse,nVar) so t
1c950 68 65 20 6e 56 61 72 20 66 69 65 6c 64 20 6d 75 he nVar field mu
1c960 73 74 20 62 65 20 74 68 65 20 66 69 72 73 74 20 st be the first
1c970 66 69 65 6c 64 0a 20 20 2a 2a 20 69 6e 20 74 68 field. ** in th
1c980 65 20 72 65 63 75 72 73 69 76 65 20 72 65 67 69 e recursive regi
1c990 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a on.. **********
1c9a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c9b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c9c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c9d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a **************/.
1c9e0 0a 20 20 69 6e 74 20 6e 56 61 72 3b 20 20 20 20 . int nVar;
1c9f0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1ca00 4e 75 6d 62 65 72 20 6f 66 20 27 3f 27 20 76 61 Number of '?' va
1ca10 72 69 61 62 6c 65 73 20 73 65 65 6e 20 69 6e 20 riables seen in
1ca20 74 68 65 20 53 51 4c 20 73 6f 20 66 61 72 20 2a the SQL so far *
1ca30 2f 0a 20 20 69 6e 74 20 6e 7a 56 61 72 3b 20 20 /. int nzVar;
1ca40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1ca50 20 4e 75 6d 62 65 72 20 6f 66 20 61 76 61 69 6c Number of avail
1ca60 61 62 6c 65 20 73 6c 6f 74 73 20 69 6e 20 61 7a able slots in az
1ca70 56 61 72 5b 5d 20 2a 2f 0a 20 20 75 38 20 69 50 Var[] */. u8 iP
1ca80 6b 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 kSortOrder;
1ca90 20 20 20 20 20 2f 2a 20 41 53 43 20 6f 72 20 44 /* ASC or D
1caa0 45 53 43 20 66 6f 72 20 49 4e 54 45 47 45 52 20 ESC for INTEGER
1cab0 50 52 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 PRIMARY KEY */.
1cac0 20 75 38 20 62 46 72 65 65 57 69 74 68 3b 20 20 u8 bFreeWith;
1cad0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1cae0 75 65 20 69 66 20 70 57 69 74 68 20 73 68 6f 75 ue if pWith shou
1caf0 6c 64 20 62 65 20 66 72 65 65 64 20 77 69 74 68 ld be freed with
1cb00 20 70 61 72 73 65 72 20 2a 2f 0a 20 20 75 38 20 parser */. u8
1cb10 65 78 70 6c 61 69 6e 3b 20 20 20 20 20 20 20 20 explain;
1cb20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
1cb30 66 20 74 68 65 20 45 58 50 4c 41 49 4e 20 66 6c f the EXPLAIN fl
1cb40 61 67 20 69 73 20 66 6f 75 6e 64 20 6f 6e 20 74 ag is found on t
1cb50 68 65 20 71 75 65 72 79 20 2a 2f 0a 23 69 66 6e he query */.#ifn
1cb60 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
1cb70 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 75 VIRTUALTABLE. u
1cb80 38 20 64 65 63 6c 61 72 65 56 74 61 62 3b 20 20 8 declareVtab;
1cb90 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
1cba0 20 69 66 20 69 6e 73 69 64 65 20 73 71 6c 69 74 if inside sqlit
1cbb0 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 28 e3_declare_vtab(
1cbc0 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 74 61 62 ) */. int nVtab
1cbd0 4c 6f 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 Lock;
1cbe0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 76 69 /* Number of vi
1cbf0 72 74 75 61 6c 20 74 61 62 6c 65 73 20 74 6f 20 rtual tables to
1cc00 6c 6f 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 lock */.#endif.
1cc10 20 69 6e 74 20 6e 41 6c 69 61 73 3b 20 20 20 20 int nAlias;
1cc20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1cc30 6d 62 65 72 20 6f 66 20 61 6c 69 61 73 65 64 20 mber of aliased
1cc40 72 65 73 75 6c 74 20 73 65 74 20 63 6f 6c 75 6d result set colum
1cc50 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 69 ns */. int nHei
1cc60 67 68 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ght;
1cc70 20 20 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 /* Expression
1cc80 74 72 65 65 20 68 65 69 67 68 74 20 6f 66 20 63 tree height of c
1cc90 75 72 72 65 6e 74 20 73 75 62 2d 73 65 6c 65 63 urrent sub-selec
1cca0 74 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c t */.#ifndef SQL
1ccb0 49 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e ITE_OMIT_EXPLAIN
1ccc0 0a 20 20 69 6e 74 20 69 53 65 6c 65 63 74 49 64 . int iSelectId
1ccd0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1cce0 49 44 20 6f 66 20 63 75 72 72 65 6e 74 20 73 65 ID of current se
1ccf0 6c 65 63 74 20 66 6f 72 20 45 58 50 4c 41 49 4e lect for EXPLAIN
1cd00 20 6f 75 74 70 75 74 20 2a 2f 0a 20 20 69 6e 74 output */. int
1cd10 20 69 4e 65 78 74 53 65 6c 65 63 74 49 64 3b 20 iNextSelectId;
1cd20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 61 /* Next a
1cd30 76 61 69 6c 61 62 6c 65 20 73 65 6c 65 63 74 20 vailable select
1cd40 49 44 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f ID for EXPLAIN o
1cd50 75 74 70 75 74 20 2a 2f 0a 23 65 6e 64 69 66 0a utput */.#endif.
1cd60 20 20 63 68 61 72 20 2a 2a 61 7a 56 61 72 3b 20 char **azVar;
1cd70 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
1cd80 6f 69 6e 74 65 72 73 20 74 6f 20 6e 61 6d 65 73 ointers to names
1cd90 20 6f 66 20 70 61 72 61 6d 65 74 65 72 73 20 2a of parameters *
1cda0 2f 0a 20 20 56 64 62 65 20 2a 70 52 65 70 72 65 /. Vdbe *pRepre
1cdb0 70 61 72 65 3b 20 20 20 20 20 20 20 20 20 2f 2a pare; /*
1cdc0 20 56 4d 20 62 65 69 6e 67 20 72 65 70 72 65 70 VM being reprep
1cdd0 61 72 65 64 20 28 73 71 6c 69 74 65 33 52 65 70 ared (sqlite3Rep
1cde0 72 65 70 61 72 65 28 29 29 20 2a 2f 0a 20 20 63 repare()) */. c
1cdf0 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 61 69 6c onst char *zTail
1ce00 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 ; /* All
1ce10 53 51 4c 20 74 65 78 74 20 70 61 73 74 20 74 68 SQL text past th
1ce20 65 20 6c 61 73 74 20 73 65 6d 69 63 6f 6c 6f 6e e last semicolon
1ce30 20 70 61 72 73 65 64 20 2a 2f 0a 20 20 54 61 62 parsed */. Tab
1ce40 6c 65 20 2a 70 4e 65 77 54 61 62 6c 65 3b 20 20 le *pNewTable;
1ce50 20 20 20 20 20 20 20 2f 2a 20 41 20 74 61 62 6c /* A tabl
1ce60 65 20 62 65 69 6e 67 20 63 6f 6e 73 74 72 75 63 e being construc
1ce70 74 65 64 20 62 79 20 43 52 45 41 54 45 20 54 41 ted by CREATE TA
1ce80 42 4c 45 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 BLE */. Trigger
1ce90 20 2a 70 4e 65 77 54 72 69 67 67 65 72 3b 20 20 *pNewTrigger;
1cea0 20 20 20 2f 2a 20 54 72 69 67 67 65 72 20 75 6e /* Trigger un
1ceb0 64 65 72 20 63 6f 6e 73 74 72 75 63 74 20 62 79 der construct by
1cec0 20 61 20 43 52 45 41 54 45 20 54 52 49 47 47 45 a CREATE TRIGGE
1ced0 52 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 R */. const cha
1cee0 72 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b r *zAuthContext;
1cef0 20 2f 2a 20 54 68 65 20 36 74 68 20 70 61 72 61 /* The 6th para
1cf00 6d 65 74 65 72 20 74 6f 20 64 62 2d 3e 78 41 75 meter to db->xAu
1cf10 74 68 20 63 61 6c 6c 62 61 63 6b 73 20 2a 2f 0a th callbacks */.
1cf20 20 20 54 6f 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b Token sNameTok
1cf30 65 6e 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 en; /* T
1cf40 6f 6b 65 6e 20 77 69 74 68 20 75 6e 71 75 61 6c oken with unqual
1cf50 69 66 69 65 64 20 73 63 68 65 6d 61 20 6f 62 6a ified schema obj
1cf60 65 63 74 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 6f ect name */. To
1cf70 6b 65 6e 20 73 4c 61 73 74 54 6f 6b 65 6e 3b 20 ken sLastToken;
1cf80 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6c /* The l
1cf90 61 73 74 20 74 6f 6b 65 6e 20 70 61 72 73 65 64 ast token parsed
1cfa0 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
1cfb0 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
1cfc0 41 42 4c 45 0a 20 20 54 6f 6b 65 6e 20 73 41 72 ABLE. Token sAr
1cfd0 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
1cfe0 20 2f 2a 20 43 6f 6d 70 6c 65 74 65 20 74 65 78 /* Complete tex
1cff0 74 20 6f 66 20 61 20 6d 6f 64 75 6c 65 20 61 72 t of a module ar
1d000 67 75 6d 65 6e 74 20 2a 2f 0a 20 20 54 61 62 6c gument */. Tabl
1d010 65 20 2a 2a 61 70 56 74 61 62 4c 6f 63 6b 3b 20 e **apVtabLock;
1d020 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 /* Pointer
1d030 20 74 6f 20 76 69 72 74 75 61 6c 20 74 61 62 6c to virtual tabl
1d040 65 73 20 6e 65 65 64 69 6e 67 20 6c 6f 63 6b 69 es needing locki
1d050 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 54 ng */.#endif. T
1d060 61 62 6c 65 20 2a 70 5a 6f 6d 62 69 65 54 61 62 able *pZombieTab
1d070 3b 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 ; /* List
1d080 20 6f 66 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 of Table object
1d090 73 20 74 6f 20 64 65 6c 65 74 65 20 61 66 74 65 s to delete afte
1d0a0 72 20 63 6f 64 65 20 67 65 6e 20 2a 2f 0a 20 20 r code gen */.
1d0b0 54 72 69 67 67 65 72 50 72 67 20 2a 70 54 72 69 TriggerPrg *pTri
1d0c0 67 67 65 72 50 72 67 3b 20 20 2f 2a 20 4c 69 6e ggerPrg; /* Lin
1d0d0 6b 65 64 20 6c 69 73 74 20 6f 66 20 63 6f 64 65 ked list of code
1d0e0 64 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 20 20 d triggers */.
1d0f0 57 69 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 With *pWith;
1d100 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 /* Cur
1d110 72 65 6e 74 20 57 49 54 48 20 63 6c 61 75 73 65 rent WITH clause
1d120 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 7d 3b 0a , or NULL */.};.
1d130 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 ./*.** Return tr
1d140 75 65 20 69 66 20 63 75 72 72 65 6e 74 6c 79 20 ue if currently
1d150 69 6e 73 69 64 65 20 61 6e 20 73 71 6c 69 74 65 inside an sqlite
1d160 33 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 28 29 3_declare_vtab()
1d170 20 63 61 6c 6c 2e 0a 2a 2f 0a 23 69 66 64 65 66 call..*/.#ifdef
1d180 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 SQLITE_OMIT_VIR
1d190 54 55 41 4c 54 41 42 4c 45 0a 20 20 23 64 65 66 TUALTABLE. #def
1d1a0 69 6e 65 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 ine IN_DECLARE_V
1d1b0 54 41 42 20 30 0a 23 65 6c 73 65 0a 20 20 23 64 TAB 0.#else. #d
1d1c0 65 66 69 6e 65 20 49 4e 5f 44 45 43 4c 41 52 45 efine IN_DECLARE
1d1d0 5f 56 54 41 42 20 28 70 50 61 72 73 65 2d 3e 64 _VTAB (pParse->d
1d1e0 65 63 6c 61 72 65 56 74 61 62 29 0a 23 65 6e 64 eclareVtab).#end
1d1f0 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 if../*.** An ins
1d200 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
1d210 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
1d220 20 63 61 6e 20 62 65 20 64 65 63 6c 61 72 65 64 can be declared
1d230 20 6f 6e 20 61 20 73 74 61 63 6b 20 61 6e 64 20 on a stack and
1d240 75 73 65 64 0a 2a 2a 20 74 6f 20 73 61 76 65 20 used.** to save
1d250 74 68 65 20 50 61 72 73 65 2e 7a 41 75 74 68 43 the Parse.zAuthC
1d260 6f 6e 74 65 78 74 20 76 61 6c 75 65 20 73 6f 20 ontext value so
1d270 74 68 61 74 20 69 74 20 63 61 6e 20 62 65 20 72 that it can be r
1d280 65 73 74 6f 72 65 64 20 6c 61 74 65 72 2e 0a 2a estored later..*
1d290 2f 0a 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e /.struct AuthCon
1d2a0 74 65 78 74 20 7b 0a 20 20 63 6f 6e 73 74 20 63 text {. const c
1d2b0 68 61 72 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 har *zAuthContex
1d2c0 74 3b 20 20 20 2f 2a 20 50 75 74 20 73 61 76 65 t; /* Put save
1d2d0 64 20 50 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e d Parse.zAuthCon
1d2e0 74 65 78 74 20 68 65 72 65 20 2a 2f 0a 20 20 50 text here */. P
1d2f0 61 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 arse *pParse;
1d300 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
1d310 65 20 50 61 72 73 65 20 73 74 72 75 63 74 75 72 e Parse structur
1d320 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 42 e */.};../*.** B
1d330 69 74 66 69 65 6c 64 20 66 6c 61 67 73 20 66 6f itfield flags fo
1d340 72 20 50 35 20 76 61 6c 75 65 20 69 6e 20 76 61 r P5 value in va
1d350 72 69 6f 75 73 20 6f 70 63 6f 64 65 73 2e 0a 2a rious opcodes..*
1d360 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 61 74 20 74 *.** Note that t
1d370 68 65 20 76 61 6c 75 65 73 20 66 6f 72 20 49 53 he values for IS
1d380 4e 4f 4f 50 20 61 6e 64 20 4c 45 4e 47 54 48 41 NOOP and LENGTHA
1d390 52 47 20 61 72 65 20 74 68 65 20 73 61 6d 65 2e RG are the same.
1d3a0 20 20 42 75 74 20 61 73 20 0a 2a 2a 20 74 68 6f But as .** tho
1d3b0 73 65 20 62 69 74 73 20 61 72 65 20 6e 65 76 65 se bits are neve
1d3c0 72 20 75 73 65 64 20 6f 6e 20 74 68 65 20 73 61 r used on the sa
1d3d0 6d 65 20 6f 70 63 6f 64 65 2c 20 74 68 65 20 6f me opcode, the o
1d3e0 76 65 72 6c 61 70 20 69 73 20 68 61 72 6d 6c 65 verlap is harmle
1d3f0 73 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ss..*/.#define O
1d400 50 46 4c 41 47 5f 4e 43 48 41 4e 47 45 20 20 20 PFLAG_NCHANGE
1d410 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 53 0x01 /* S
1d420 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 2d et to update db-
1d430 3e 6e 43 68 61 6e 67 65 20 2a 2f 0a 23 64 65 66 >nChange */.#def
1d440 69 6e 65 20 4f 50 46 4c 41 47 5f 45 50 48 45 4d ine OPFLAG_EPHEM
1d450 20 20 20 20 20 20 20 20 20 30 78 30 31 20 20 20 0x01
1d460 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 3a 20 45 /* OP_Column: E
1d470 70 68 65 6d 65 72 61 6c 20 6f 75 74 70 75 74 20 phemeral output
1d480 69 73 20 6f 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 is ok */.#define
1d490 20 4f 50 46 4c 41 47 5f 4c 41 53 54 52 4f 57 49 OPFLAG_LASTROWI
1d4a0 44 20 20 20 20 20 30 78 30 32 20 20 20 20 2f 2a D 0x02 /*
1d4b0 20 53 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 Set to update d
1d4c0 62 2d 3e 6c 61 73 74 52 6f 77 69 64 20 2a 2f 0a b->lastRowid */.
1d4d0 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 49 #define OPFLAG_I
1d4e0 53 55 50 44 41 54 45 20 20 20 20 20 20 30 78 30 SUPDATE 0x0
1d4f0 34 20 20 20 20 2f 2a 20 54 68 69 73 20 4f 50 5f 4 /* This OP_
1d500 49 6e 73 65 72 74 20 69 73 20 61 6e 20 73 71 6c Insert is an sql
1d510 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 UPDATE */.#defi
1d520 6e 65 20 4f 50 46 4c 41 47 5f 41 50 50 45 4e 44 ne OPFLAG_APPEND
1d530 20 20 20 20 20 20 20 20 30 78 30 38 20 20 20 20 0x08
1d540 2f 2a 20 54 68 69 73 20 69 73 20 6c 69 6b 65 6c /* This is likel
1d550 79 20 74 6f 20 62 65 20 61 6e 20 61 70 70 65 6e y to be an appen
1d560 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 d */.#define OPF
1d570 4c 41 47 5f 55 53 45 53 45 45 4b 52 45 53 55 4c LAG_USESEEKRESUL
1d580 54 20 30 78 31 30 20 20 20 20 2f 2a 20 54 72 79 T 0x10 /* Try
1d590 20 74 6f 20 61 76 6f 69 64 20 61 20 73 65 65 6b to avoid a seek
1d5a0 20 69 6e 20 42 74 72 65 65 49 6e 73 65 72 74 28 in BtreeInsert(
1d5b0 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 ) */.#define OPF
1d5c0 4c 41 47 5f 49 53 4e 4f 4f 50 20 20 20 20 20 20 LAG_ISNOOP
1d5d0 20 20 30 78 34 30 20 20 20 20 2f 2a 20 4f 50 5f 0x40 /* OP_
1d5e0 44 65 6c 65 74 65 20 64 6f 65 73 20 70 72 65 2d Delete does pre-
1d5f0 75 70 64 61 74 65 2d 68 6f 6f 6b 20 6f 6e 6c 79 update-hook only
1d600 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1d610 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 20 20 20 AG_LENGTHARG
1d620 20 30 78 34 30 20 20 20 20 2f 2a 20 4f 50 5f 43 0x40 /* OP_C
1d630 6f 6c 75 6d 6e 20 6f 6e 6c 79 20 75 73 65 64 20 olumn only used
1d640 66 6f 72 20 6c 65 6e 67 74 68 28 29 20 2a 2f 0a for length() */.
1d650 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 54 #define OPFLAG_T
1d660 59 50 45 4f 46 41 52 47 20 20 20 20 20 30 78 38 YPEOFARG 0x8
1d670 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 0 /* OP_Colum
1d680 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 n only used for
1d690 74 79 70 65 6f 66 28 29 20 2a 2f 0a 23 64 65 66 typeof() */.#def
1d6a0 69 6e 65 20 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 ine OPFLAG_BULKC
1d6b0 53 52 20 20 20 20 20 20 20 30 78 30 31 20 20 20 SR 0x01
1d6c0 20 2f 2a 20 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 /* OP_Open** us
1d6d0 65 64 20 74 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 ed to open bulk
1d6e0 63 75 72 73 6f 72 20 2a 2f 0a 23 64 65 66 69 6e cursor */.#defin
1d6f0 65 20 4f 50 46 4c 41 47 5f 53 45 45 4b 45 51 20 e OPFLAG_SEEKEQ
1d700 20 20 20 20 20 20 20 30 78 30 32 20 20 20 20 2f 0x02 /
1d710 2a 20 4f 50 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 * OP_Open** curs
1d720 6f 72 20 75 73 65 73 20 45 51 20 73 65 65 6b 20 or uses EQ seek
1d730 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 only */.#define
1d740 4f 50 46 4c 41 47 5f 50 32 49 53 52 45 47 20 20 OPFLAG_P2ISREG
1d750 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 0x04 /*
1d760 50 32 20 74 6f 20 4f 50 5f 4f 70 65 6e 2a 2a 20 P2 to OP_Open**
1d770 69 73 20 61 20 72 65 67 69 73 74 65 72 20 6e 75 is a register nu
1d780 6d 62 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 mber */.#define
1d790 4f 50 46 4c 41 47 5f 50 45 52 4d 55 54 45 20 20 OPFLAG_PERMUTE
1d7a0 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
1d7b0 4f 50 5f 43 6f 6d 70 61 72 65 3a 20 75 73 65 20 OP_Compare: use
1d7c0 74 68 65 20 70 65 72 6d 75 74 61 74 69 6f 6e 20 the permutation
1d7d0 2a 2f 0a 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 74 */../*. * Each t
1d7e0 72 69 67 67 65 72 20 70 72 65 73 65 6e 74 20 69 rigger present i
1d7f0 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 n the database s
1d800 63 68 65 6d 61 20 69 73 20 73 74 6f 72 65 64 20 chema is stored
1d810 61 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f as an instance o
1d820 66 0a 20 2a 20 73 74 72 75 63 74 20 54 72 69 67 f. * struct Trig
1d830 67 65 72 2e 20 0a 20 2a 0a 20 2a 20 50 6f 69 6e ger. . *. * Poin
1d840 74 65 72 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 ters to instance
1d850 73 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 s of struct Trig
1d860 67 65 72 20 61 72 65 20 73 74 6f 72 65 64 20 69 ger are stored i
1d870 6e 20 74 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 n two ways.. * 1
1d880 2e 20 49 6e 20 74 68 65 20 22 74 72 69 67 48 61 . In the "trigHa
1d890 73 68 22 20 68 61 73 68 20 74 61 62 6c 65 20 28 sh" hash table (
1d8a0 70 61 72 74 20 6f 66 20 74 68 65 20 73 71 6c 69 part of the sqli
1d8b0 74 65 33 2a 20 74 68 61 74 20 72 65 70 72 65 73 te3* that repres
1d8c0 65 6e 74 73 20 74 68 65 20 0a 20 2a 20 20 20 20 ents the . *
1d8d0 64 61 74 61 62 61 73 65 29 2e 20 54 68 69 73 20 database). This
1d8e0 61 6c 6c 6f 77 73 20 54 72 69 67 67 65 72 20 73 allows Trigger s
1d8f0 74 72 75 63 74 75 72 65 73 20 74 6f 20 62 65 20 tructures to be
1d900 72 65 74 72 69 65 76 65 64 20 62 79 20 6e 61 6d retrieved by nam
1d910 65 2e 0a 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 e.. * 2. All tri
1d920 67 67 65 72 73 20 61 73 73 6f 63 69 61 74 65 64 ggers associated
1d930 20 77 69 74 68 20 61 20 73 69 6e 67 6c 65 20 74 with a single t
1d940 61 62 6c 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b able form a link
1d950 65 64 20 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 ed list, using t
1d960 68 65 0a 20 2a 20 20 20 20 70 4e 65 78 74 20 6d he. * pNext m
1d970 65 6d 62 65 72 20 6f 66 20 73 74 72 75 63 74 20 ember of struct
1d980 54 72 69 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 Trigger. A point
1d990 65 72 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 er to the first
1d9a0 65 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 element of the.
1d9b0 2a 20 20 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 * linked list
1d9c0 20 69 73 20 73 74 6f 72 65 64 20 61 73 20 74 68 is stored as th
1d9d0 65 20 22 70 54 72 69 67 67 65 72 22 20 6d 65 6d e "pTrigger" mem
1d9e0 62 65 72 20 6f 66 20 74 68 65 20 61 73 73 6f 63 ber of the assoc
1d9f0 69 61 74 65 64 0a 20 2a 20 20 20 20 73 74 72 75 iated. * stru
1da00 63 74 20 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 ct Table.. *. *
1da10 54 68 65 20 22 73 74 65 70 5f 6c 69 73 74 22 20 The "step_list"
1da20 6d 65 6d 62 65 72 20 70 6f 69 6e 74 73 20 74 6f member points to
1da30 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 the first eleme
1da40 6e 74 20 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c nt of a linked l
1da50 69 73 74 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e ist. * containin
1da60 67 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 6d g the SQL statem
1da70 65 6e 74 73 20 73 70 65 63 69 66 69 65 64 20 61 ents specified a
1da80 73 20 74 68 65 20 74 72 69 67 67 65 72 20 70 72 s the trigger pr
1da90 6f 67 72 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 ogram.. */.struc
1daa0 74 20 54 72 69 67 67 65 72 20 7b 0a 20 20 63 68 t Trigger {. ch
1dab0 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
1dac0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d /* The nam
1dad0 65 20 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 e of the trigger
1dae0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1daf0 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 */. cha
1db00 72 20 2a 74 61 62 6c 65 3b 20 20 20 20 20 20 20 r *table;
1db10 20 20 20 20 20 2f 2a 20 54 68 65 20 74 61 62 6c /* The tabl
1db20 65 20 6f 72 20 76 69 65 77 20 74 6f 20 77 68 69 e or view to whi
1db30 63 68 20 74 68 65 20 74 72 69 67 67 65 72 20 61 ch the trigger a
1db40 70 70 6c 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f pplies */. u8 o
1db50 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 p;
1db60 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b /* One of TK
1db70 5f 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 _DELETE, TK_UPDA
1db80 54 45 2c 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 TE, TK_INSERT
1db90 20 20 20 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 */. u8 tr
1dba0 5f 74 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 _tm;
1dbb0 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 /* One of TRI
1dbc0 47 47 45 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 GGER_BEFORE, TRI
1dbd0 47 47 45 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 GGER_AFTER */.
1dbe0 45 78 70 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 Expr *pWhen;
1dbf0 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 /* The W
1dc00 48 45 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 68 HEN clause of th
1dc10 65 20 65 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 e expression (ma
1dc20 79 20 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 y be NULL) */.
1dc30 49 64 4c 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 IdList *pColumns
1dc40 3b 20 20 20 20 20 20 20 2f 2a 20 49 66 20 74 68 ; /* If th
1dc50 69 73 20 69 73 20 61 6e 20 55 50 44 41 54 45 20 is is an UPDATE
1dc60 4f 46 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e OF <column-list>
1dc70 20 74 72 69 67 67 65 72 2c 0a 20 20 20 20 20 20 trigger,.
1dc80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1dc90 20 20 20 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 the <colu
1dca0 6d 6e 2d 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 mn-list> is stor
1dcb0 65 64 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 ed here */. Sch
1dcc0 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 ema *pSchema;
1dcd0 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 /* Schema c
1dce0 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74 72 ontaining the tr
1dcf0 69 67 67 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d igger */. Schem
1dd00 61 20 2a 70 54 61 62 53 63 68 65 6d 61 3b 20 20 a *pTabSchema;
1dd10 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e /* Schema con
1dd20 74 61 69 6e 69 6e 67 20 74 68 65 20 74 61 62 6c taining the tabl
1dd30 65 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 e */. TriggerSt
1dd40 65 70 20 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f ep *step_list; /
1dd50 2a 20 4c 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 * Link list of t
1dd60 72 69 67 67 65 72 20 70 72 6f 67 72 61 6d 20 73 rigger program s
1dd70 74 65 70 73 20 20 20 20 20 20 20 20 20 20 20 20 teps
1dd80 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 */. Trigger *p
1dd90 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a Next; /*
1dda0 20 4e 65 78 74 20 74 72 69 67 67 65 72 20 61 73 Next trigger as
1ddb0 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 sociated with th
1ddc0 65 20 74 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f e table */.};../
1ddd0 2a 0a 2a 2a 20 41 20 74 72 69 67 67 65 72 20 69 *.** A trigger i
1dde0 73 20 65 69 74 68 65 72 20 61 20 42 45 46 4f 52 s either a BEFOR
1ddf0 45 20 6f 72 20 61 6e 20 41 46 54 45 52 20 74 72 E or an AFTER tr
1de00 69 67 67 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c igger. The foll
1de10 6f 77 69 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a owing constants.
1de20 2a 2a 20 64 65 74 65 72 6d 69 6e 65 20 77 68 69 ** determine whi
1de30 63 68 2e 20 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 ch. .**.** If th
1de40 65 72 65 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 ere are multiple
1de50 20 74 72 69 67 67 65 72 73 2c 20 79 6f 75 20 6d triggers, you m
1de60 69 67 68 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 ight of some BEF
1de70 4f 52 45 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 ORE and some AFT
1de80 45 52 2e 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 ER..** In that c
1de90 61 73 65 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 ases, the consta
1dea0 6e 74 73 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 nts below can be
1deb0 20 4f 52 65 64 20 74 6f 67 65 74 68 65 72 2e 0a ORed together..
1dec0 2a 2f 0a 23 64 65 66 69 6e 65 20 54 52 49 47 47 */.#define TRIGG
1ded0 45 52 5f 42 45 46 4f 52 45 20 20 31 0a 23 64 65 ER_BEFORE 1.#de
1dee0 66 69 6e 65 20 54 52 49 47 47 45 52 5f 41 46 54 fine TRIGGER_AFT
1def0 45 52 20 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e ER 2../*. * An
1df00 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 73 74 72 instance of str
1df10 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 20 uct TriggerStep
1df20 69 73 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 is used to store
1df30 20 61 20 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 a single SQL st
1df40 61 74 65 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 atement. * that
1df50 69 73 20 61 20 70 61 72 74 20 6f 66 20 61 20 74 is a part of a t
1df60 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 20 rigger-program.
1df70 0a 20 2a 0a 20 2a 20 49 6e 73 74 61 6e 63 65 73 . *. * Instances
1df80 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 67 of struct Trigg
1df90 65 72 53 74 65 70 20 61 72 65 20 73 74 6f 72 65 erStep are store
1dfa0 64 20 69 6e 20 61 20 73 69 6e 67 6c 79 20 6c 69 d in a singly li
1dfb0 6e 6b 65 64 20 6c 69 73 74 20 28 6c 69 6e 6b 65 nked list (linke
1dfc0 64 0a 20 2a 20 75 73 69 6e 67 20 74 68 65 20 22 d. * using the "
1dfd0 70 4e 65 78 74 22 20 6d 65 6d 62 65 72 29 20 72 pNext" member) r
1dfe0 65 66 65 72 65 6e 63 65 64 20 62 79 20 74 68 65 eferenced by the
1dff0 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d "step_list" mem
1e000 62 65 72 20 6f 66 20 74 68 65 20 0a 20 2a 20 61 ber of the . * a
1e010 73 73 6f 63 69 61 74 65 64 20 73 74 72 75 63 74 ssociated struct
1e020 20 54 72 69 67 67 65 72 20 69 6e 73 74 61 6e 63 Trigger instanc
1e030 65 2e 20 54 68 65 20 66 69 72 73 74 20 65 6c 65 e. The first ele
1e040 6d 65 6e 74 20 6f 66 20 74 68 65 20 6c 69 6e 6b ment of the link
1e050 65 64 20 6c 69 73 74 20 69 73 0a 20 2a 20 74 68 ed list is. * th
1e060 65 20 66 69 72 73 74 20 73 74 65 70 20 6f 66 20 e first step of
1e070 74 68 65 20 74 72 69 67 67 65 72 2d 70 72 6f 67 the trigger-prog
1e080 72 61 6d 2e 0a 20 2a 20 0a 20 2a 20 54 68 65 20 ram.. * . * The
1e090 22 6f 70 22 20 6d 65 6d 62 65 72 20 69 6e 64 69 "op" member indi
1e0a0 63 61 74 65 73 20 77 68 65 74 68 65 72 20 74 68 cates whether th
1e0b0 69 73 20 69 73 20 61 20 22 44 45 4c 45 54 45 22 is is a "DELETE"
1e0c0 2c 20 22 49 4e 53 45 52 54 22 2c 20 22 55 50 44 , "INSERT", "UPD
1e0d0 41 54 45 22 20 6f 72 0a 20 2a 20 22 53 45 4c 45 ATE" or. * "SELE
1e0e0 43 54 22 20 73 74 61 74 65 6d 65 6e 74 2e 20 54 CT" statement. T
1e0f0 68 65 20 6d 65 61 6e 69 6e 67 73 20 6f 66 20 74 he meanings of t
1e100 68 65 20 6f 74 68 65 72 20 6d 65 6d 62 65 72 73 he other members
1e110 20 69 73 20 64 65 74 65 72 6d 69 6e 65 64 20 62 is determined b
1e120 79 20 74 68 65 20 0a 20 2a 20 76 61 6c 75 65 20 y the . * value
1e130 6f 66 20 22 6f 70 22 20 61 73 20 66 6f 6c 6c 6f of "op" as follo
1e140 77 73 3a 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d ws:. *. * (op ==
1e150 20 54 4b 5f 49 4e 53 45 52 54 29 0a 20 2a 20 6f TK_INSERT). * o
1e160 72 63 6f 6e 66 20 20 20 20 2d 3e 20 73 74 6f 72 rconf -> stor
1e170 65 73 20 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 es the ON CONFLI
1e180 43 54 20 61 6c 67 6f 72 69 74 68 6d 0a 20 2a 20 CT algorithm. *
1e190 70 53 65 6c 65 63 74 20 20 20 2d 3e 20 49 66 20 pSelect -> If
1e1a0 74 68 69 73 20 69 73 20 61 6e 20 49 4e 53 45 52 this is an INSER
1e1b0 54 20 49 4e 54 4f 20 2e 2e 2e 20 53 45 4c 45 43 T INTO ... SELEC
1e1c0 54 20 2e 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c T ... statement,
1e1d0 20 74 68 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 then. *
1e1e0 20 20 20 20 20 20 74 68 69 73 20 73 74 6f 72 65 this store
1e1f0 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 s a pointer to t
1e200 68 65 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d he SELECT statem
1e210 65 6e 74 2e 20 4f 74 68 65 72 77 69 73 65 20 4e ent. Otherwise N
1e220 55 4c 4c 2e 0a 20 2a 20 7a 54 61 72 67 65 74 20 ULL.. * zTarget
1e230 20 20 2d 3e 20 44 65 71 75 6f 74 65 64 20 6e 61 -> Dequoted na
1e240 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 me of the table
1e250 74 6f 20 69 6e 73 65 72 74 20 69 6e 74 6f 2e 0a to insert into..
1e260 20 2a 20 70 45 78 70 72 4c 69 73 74 20 2d 3e 20 * pExprList ->
1e270 49 66 20 74 68 69 73 20 69 73 20 61 6e 20 49 4e If this is an IN
1e280 53 45 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 56 41 SERT INTO ... VA
1e290 4c 55 45 53 20 2e 2e 2e 20 73 74 61 74 65 6d 65 LUES ... stateme
1e2a0 6e 74 2c 20 74 68 65 6e 0a 20 2a 20 20 20 20 20 nt, then. *
1e2b0 20 20 20 20 20 20 20 20 20 74 68 69 73 20 73 74 this st
1e2c0 6f 72 65 73 20 76 61 6c 75 65 73 20 74 6f 20 62 ores values to b
1e2d0 65 20 69 6e 73 65 72 74 65 64 2e 20 4f 74 68 65 e inserted. Othe
1e2e0 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a 20 70 rwise NULL.. * p
1e2f0 49 64 4c 69 73 74 20 20 20 2d 3e 20 49 66 20 74 IdList -> If t
1e300 68 69 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 his is an INSERT
1e310 20 49 4e 54 4f 20 2e 2e 2e 20 28 3c 63 6f 6c 75 INTO ... (<colu
1e320 6d 6e 2d 6e 61 6d 65 73 3e 29 20 56 41 4c 55 45 mn-names>) VALUE
1e330 53 20 2e 2e 2e 20 0a 20 2a 20 20 20 20 20 20 20 S ... . *
1e340 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 6e 74 statement
1e350 2c 20 74 68 65 6e 20 74 68 69 73 20 73 74 6f 72 , then this stor
1e360 65 73 20 74 68 65 20 63 6f 6c 75 6d 6e 2d 6e 61 es the column-na
1e370 6d 65 73 20 74 6f 20 62 65 0a 20 2a 20 20 20 20 mes to be. *
1e380 20 20 20 20 20 20 20 20 20 20 69 6e 73 65 72 74 insert
1e390 65 64 20 69 6e 74 6f 2e 0a 20 2a 0a 20 2a 20 28 ed into.. *. * (
1e3a0 6f 70 20 3d 3d 20 54 4b 5f 44 45 4c 45 54 45 29 op == TK_DELETE)
1e3b0 0a 20 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e . * zTarget ->
1e3c0 20 44 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f Dequoted name o
1e3d0 66 20 74 68 65 20 74 61 62 6c 65 20 74 6f 20 64 f the table to d
1e3e0 65 6c 65 74 65 20 66 72 6f 6d 2e 0a 20 2a 20 70 elete from.. * p
1e3f0 57 68 65 72 65 20 20 20 20 2d 3e 20 54 68 65 20 Where -> The
1e400 57 48 45 52 45 20 63 6c 61 75 73 65 20 6f 66 20 WHERE clause of
1e410 74 68 65 20 44 45 4c 45 54 45 20 73 74 61 74 65 the DELETE state
1e420 6d 65 6e 74 20 69 66 20 6f 6e 65 20 69 73 20 73 ment if one is s
1e430 70 65 63 69 66 69 65 64 2e 0a 20 2a 20 20 20 20 pecified.. *
1e440 20 20 20 20 20 20 20 20 20 20 4f 74 68 65 72 77 Otherw
1e450 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a 20 0a 20 2a ise NULL.. * . *
1e460 20 28 6f 70 20 3d 3d 20 54 4b 5f 55 50 44 41 54 (op == TK_UPDAT
1e470 45 29 0a 20 2a 20 7a 54 61 72 67 65 74 20 20 20 E). * zTarget
1e480 2d 3e 20 44 65 71 75 6f 74 65 64 20 6e 61 6d 65 -> Dequoted name
1e490 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 74 6f of the table to
1e4a0 20 75 70 64 61 74 65 2e 0a 20 2a 20 70 57 68 65 update.. * pWhe
1e4b0 72 65 20 20 20 20 2d 3e 20 54 68 65 20 57 48 45 re -> The WHE
1e4c0 52 45 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 RE clause of the
1e4d0 20 55 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e UPDATE statemen
1e4e0 74 20 69 66 20 6f 6e 65 20 69 73 20 73 70 65 63 t if one is spec
1e4f0 69 66 69 65 64 2e 0a 20 2a 20 20 20 20 20 20 20 ified.. *
1e500 20 20 20 20 20 20 20 4f 74 68 65 72 77 69 73 65 Otherwise
1e510 20 4e 55 4c 4c 2e 0a 20 2a 20 70 45 78 70 72 4c NULL.. * pExprL
1e520 69 73 74 20 2d 3e 20 41 20 6c 69 73 74 20 6f 66 ist -> A list of
1e530 20 74 68 65 20 63 6f 6c 75 6d 6e 73 20 74 6f 20 the columns to
1e540 75 70 64 61 74 65 20 61 6e 64 20 74 68 65 20 65 update and the e
1e550 78 70 72 65 73 73 69 6f 6e 73 20 74 6f 20 75 70 xpressions to up
1e560 64 61 74 65 0a 20 2a 20 20 20 20 20 20 20 20 20 date. *
1e570 20 20 20 20 20 74 68 65 6d 20 74 6f 2e 20 53 65 them to. Se
1e580 65 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 28 e sqlite3Update(
1e590 29 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 ) documentation
1e5a0 6f 66 20 22 70 43 68 61 6e 67 65 73 22 0a 20 2a of "pChanges". *
1e5b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 72 ar
1e5c0 67 75 6d 65 6e 74 2e 0a 20 2a 20 0a 20 2a 2f 0a gument.. * . */.
1e5d0 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 struct TriggerSt
1e5e0 65 70 20 7b 0a 20 20 75 38 20 6f 70 3b 20 20 20 ep {. u8 op;
1e5f0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
1e600 6e 65 20 6f 66 20 54 4b 5f 44 45 4c 45 54 45 2c ne of TK_DELETE,
1e610 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 TK_UPDATE, TK_I
1e620 4e 53 45 52 54 2c 20 54 4b 5f 53 45 4c 45 43 54 NSERT, TK_SELECT
1e630 20 2a 2f 0a 20 20 75 38 20 6f 72 63 6f 6e 66 3b */. u8 orconf;
1e640 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 /* OE
1e650 5f 52 6f 6c 6c 62 61 63 6b 20 65 74 63 2e 20 2a _Rollback etc. *
1e660 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 /. Trigger *pTr
1e670 69 67 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ig; /* The
1e680 74 72 69 67 67 65 72 20 74 68 61 74 20 74 68 69 trigger that thi
1e690 73 20 73 74 65 70 20 69 73 20 61 20 70 61 72 74 s step is a part
1e6a0 20 6f 66 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 of */. Select
1e6b0 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a *pSelect; /*
1e6c0 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e SELECT statemen
1e6d0 74 20 6f 72 20 52 48 53 20 6f 66 20 49 4e 53 45 t or RHS of INSE
1e6e0 52 54 20 49 4e 54 4f 20 53 45 4c 45 43 54 20 2e RT INTO SELECT .
1e6f0 2e 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 .. */. char *zT
1e700 61 72 67 65 74 3b 20 20 20 20 20 20 20 2f 2a 20 arget; /*
1e710 54 61 72 67 65 74 20 74 61 62 6c 65 20 66 6f 72 Target table for
1e720 20 44 45 4c 45 54 45 2c 20 55 50 44 41 54 45 2c DELETE, UPDATE,
1e730 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 45 78 70 INSERT */. Exp
1e740 72 20 2a 70 57 68 65 72 65 3b 20 20 20 20 20 20 r *pWhere;
1e750 20 20 2f 2a 20 54 68 65 20 57 48 45 52 45 20 63 /* The WHERE c
1e760 6c 61 75 73 65 20 66 6f 72 20 44 45 4c 45 54 45 lause for DELETE
1e770 20 6f 72 20 55 50 44 41 54 45 20 73 74 65 70 73 or UPDATE steps
1e780 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1e790 70 45 78 70 72 4c 69 73 74 3b 20 2f 2a 20 53 45 pExprList; /* SE
1e7a0 54 20 63 6c 61 75 73 65 20 66 6f 72 20 55 50 44 T clause for UPD
1e7b0 41 54 45 2e 20 2a 2f 0a 20 20 49 64 4c 69 73 74 ATE. */. IdList
1e7c0 20 2a 70 49 64 4c 69 73 74 3b 20 20 20 20 20 2f *pIdList; /
1e7d0 2a 20 43 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 66 * Column names f
1e7e0 6f 72 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 54 or INSERT */. T
1e7f0 72 69 67 67 65 72 53 74 65 70 20 2a 70 4e 65 78 riggerStep *pNex
1e800 74 3b 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 74 t; /* Next in t
1e810 68 65 20 6c 69 6e 6b 2d 6c 69 73 74 20 2a 2f 0a he link-list */.
1e820 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 70 TriggerStep *p
1e830 4c 61 73 74 3b 20 20 2f 2a 20 4c 61 73 74 20 65 Last; /* Last e
1e840 6c 65 6d 65 6e 74 20 69 6e 20 6c 69 6e 6b 2d 6c lement in link-l
1e850 69 73 74 2e 20 56 61 6c 69 64 20 66 6f 72 20 31 ist. Valid for 1
1e860 73 74 20 65 6c 65 6d 20 6f 6e 6c 79 20 2a 2f 0a st elem only */.
1e870 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f };../*.** The fo
1e880 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
1e890 65 20 63 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 e contains infor
1e8a0 6d 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 74 mation used by t
1e8b0 68 65 20 73 71 6c 69 74 65 46 69 78 2e 2e 2e 0a he sqliteFix....
1e8c0 2a 2a 20 72 6f 75 74 69 6e 65 73 20 61 73 20 74 ** routines as t
1e8d0 68 65 79 20 77 61 6c 6b 20 74 68 65 20 70 61 72 hey walk the par
1e8e0 73 65 20 74 72 65 65 20 74 6f 20 6d 61 6b 65 20 se tree to make
1e8f0 64 61 74 61 62 61 73 65 20 72 65 66 65 72 65 6e database referen
1e900 63 65 73 0a 2a 2a 20 65 78 70 6c 69 63 69 74 2e ces.** explicit.
1e910 20 20 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 .*/.typedef st
1e920 72 75 63 74 20 44 62 46 69 78 65 72 20 44 62 46 ruct DbFixer DbF
1e930 69 78 65 72 3b 0a 73 74 72 75 63 74 20 44 62 46 ixer;.struct DbF
1e940 69 78 65 72 20 7b 0a 20 20 50 61 72 73 65 20 2a ixer {. Parse *
1e950 70 50 61 72 73 65 3b 20 20 20 20 20 20 2f 2a 20 pParse; /*
1e960 54 68 65 20 70 61 72 73 69 6e 67 20 63 6f 6e 74 The parsing cont
1e970 65 78 74 2e 20 20 45 72 72 6f 72 20 6d 65 73 73 ext. Error mess
1e980 61 67 65 73 20 77 72 69 74 74 65 6e 20 68 65 72 ages written her
1e990 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 e */. Schema *p
1e9a0 53 63 68 65 6d 61 3b 20 20 20 20 2f 2a 20 46 69 Schema; /* Fi
1e9b0 78 20 69 74 65 6d 73 20 74 6f 20 74 68 69 73 20 x items to this
1e9c0 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 schema */. int
1e9d0 62 56 61 72 4f 6e 6c 79 3b 20 20 20 20 20 20 20 bVarOnly;
1e9e0 2f 2a 20 43 68 65 63 6b 20 66 6f 72 20 76 61 72 /* Check for var
1e9f0 69 61 62 6c 65 20 72 65 66 65 72 65 6e 63 65 73 iable references
1ea00 20 6f 6e 6c 79 20 2a 2f 0a 20 20 63 6f 6e 73 74 only */. const
1ea10 20 63 68 61 72 20 2a 7a 44 62 3b 20 20 20 20 2f char *zDb; /
1ea20 2a 20 4d 61 6b 65 20 73 75 72 65 20 61 6c 6c 20 * Make sure all
1ea30 6f 62 6a 65 63 74 73 20 61 72 65 20 63 6f 6e 74 objects are cont
1ea40 61 69 6e 65 64 20 69 6e 20 74 68 69 73 20 64 61 ained in this da
1ea50 74 61 62 61 73 65 20 2a 2f 0a 20 20 63 6f 6e 73 tabase */. cons
1ea60 74 20 63 68 61 72 20 2a 7a 54 79 70 65 3b 20 20 t char *zType;
1ea70 2f 2a 20 54 79 70 65 20 6f 66 20 74 68 65 20 63 /* Type of the c
1ea80 6f 6e 74 61 69 6e 65 72 20 2d 20 75 73 65 64 20 ontainer - used
1ea90 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 67 for error messag
1eaa0 65 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 54 6f es */. const To
1eab0 6b 65 6e 20 2a 70 4e 61 6d 65 3b 20 2f 2a 20 4e ken *pName; /* N
1eac0 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 ame of the conta
1ead0 69 6e 65 72 20 2d 20 75 73 65 64 20 66 6f 72 20 iner - used for
1eae0 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 2a error messages *
1eaf0 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f /.};../*.** An o
1eb00 62 6a 65 63 74 65 64 20 75 73 65 64 20 74 6f 20 bjected used to
1eb10 61 63 63 75 6d 75 6c 61 74 65 20 74 68 65 20 74 accumulate the t
1eb20 65 78 74 20 6f 66 20 61 20 73 74 72 69 6e 67 20 ext of a string
1eb30 77 68 65 72 65 20 77 65 0a 2a 2a 20 64 6f 20 6e where we.** do n
1eb40 6f 74 20 6e 65 63 65 73 73 61 72 69 6c 79 20 6b ot necessarily k
1eb50 6e 6f 77 20 68 6f 77 20 62 69 67 20 74 68 65 20 now how big the
1eb60 73 74 72 69 6e 67 20 77 69 6c 6c 20 62 65 20 69 string will be i
1eb70 6e 20 74 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 n the end..*/.st
1eb80 72 75 63 74 20 53 74 72 41 63 63 75 6d 20 7b 0a ruct StrAccum {.
1eb90 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 sqlite3 *db;
1eba0 20 20 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e /* Option
1ebb0 61 6c 20 64 61 74 61 62 61 73 65 20 66 6f 72 20 al database for
1ebc0 6c 6f 6f 6b 61 73 69 64 65 2e 20 20 43 61 6e 20 lookaside. Can
1ebd0 62 65 20 4e 55 4c 4c 20 2a 2f 0a 20 20 63 68 61 be NULL */. cha
1ebe0 72 20 2a 7a 42 61 73 65 3b 20 20 20 20 20 20 20 r *zBase;
1ebf0 20 20 2f 2a 20 41 20 62 61 73 65 20 61 6c 6c 6f /* A base allo
1ec00 63 61 74 69 6f 6e 2e 20 20 4e 6f 74 20 66 72 6f cation. Not fro
1ec10 6d 20 6d 61 6c 6c 6f 63 2e 20 2a 2f 0a 20 20 63 m malloc. */. c
1ec20 68 61 72 20 2a 7a 54 65 78 74 3b 20 20 20 20 20 har *zText;
1ec30 20 20 20 20 2f 2a 20 54 68 65 20 73 74 72 69 6e /* The strin
1ec40 67 20 63 6f 6c 6c 65 63 74 65 64 20 73 6f 20 66 g collected so f
1ec50 61 72 20 2a 2f 0a 20 20 69 6e 74 20 20 6e 43 68 ar */. int nCh
1ec60 61 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ar; /*
1ec70 4c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 73 74 Length of the st
1ec80 72 69 6e 67 20 73 6f 20 66 61 72 20 2a 2f 0a 20 ring so far */.
1ec90 20 69 6e 74 20 20 6e 41 6c 6c 6f 63 3b 20 20 20 int nAlloc;
1eca0 20 20 20 20 20 20 2f 2a 20 41 6d 6f 75 6e 74 20 /* Amount
1ecb0 6f 66 20 73 70 61 63 65 20 61 6c 6c 6f 63 61 74 of space allocat
1ecc0 65 64 20 69 6e 20 7a 54 65 78 74 20 2a 2f 0a 20 ed in zText */.
1ecd0 20 69 6e 74 20 20 6d 78 41 6c 6c 6f 63 3b 20 20 int mxAlloc;
1ece0 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d /* Maximum
1ecf0 20 61 6c 6c 6f 77 65 64 20 61 6c 6c 6f 63 61 74 allowed allocat
1ed00 69 6f 6e 2e 20 20 30 20 66 6f 72 20 6e 6f 20 6d ion. 0 for no m
1ed10 61 6c 6c 6f 63 20 75 73 61 67 65 20 2a 2f 0a 20 alloc usage */.
1ed20 20 75 38 20 20 20 61 63 63 45 72 72 6f 72 3b 20 u8 accError;
1ed30 20 20 20 20 20 20 2f 2a 20 53 54 52 41 43 43 55 /* STRACCU
1ed40 4d 5f 4e 4f 4d 45 4d 20 6f 72 20 53 54 52 41 43 M_NOMEM or STRAC
1ed50 43 55 4d 5f 54 4f 4f 42 49 47 20 2a 2f 0a 7d 3b CUM_TOOBIG */.};
1ed60 0a 23 64 65 66 69 6e 65 20 53 54 52 41 43 43 55 .#define STRACCU
1ed70 4d 5f 4e 4f 4d 45 4d 20 20 20 31 0a 23 64 65 66 M_NOMEM 1.#def
1ed80 69 6e 65 20 53 54 52 41 43 43 55 4d 5f 54 4f 4f ine STRACCUM_TOO
1ed90 42 49 47 20 20 32 0a 0a 2f 2a 0a 2a 2a 20 41 20 BIG 2../*.** A
1eda0 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 pointer to this
1edb0 73 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 structure is use
1edc0 64 20 74 6f 20 63 6f 6d 6d 75 6e 69 63 61 74 65 d to communicate
1edd0 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 information.**
1ede0 66 72 6f 6d 20 73 71 6c 69 74 65 33 49 6e 69 74 from sqlite3Init
1edf0 20 61 6e 64 20 4f 50 5f 50 61 72 73 65 53 63 68 and OP_ParseSch
1ee00 65 6d 61 20 69 6e 74 6f 20 74 68 65 20 73 71 6c ema into the sql
1ee10 69 74 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b ite3InitCallback
1ee20 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 ..*/.typedef str
1ee30 75 63 74 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 uct {. sqlite3
1ee40 2a 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 *db; /* T
1ee50 68 65 20 64 61 74 61 62 61 73 65 20 62 65 69 6e he database bein
1ee60 67 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f g initialized */
1ee70 0a 20 20 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d . char **pzErrM
1ee80 73 67 3b 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 sg; /* Error
1ee90 6d 65 73 73 61 67 65 20 73 74 6f 72 65 64 20 68 message stored h
1eea0 65 72 65 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 ere */. int iDb
1eeb0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1eec0 30 20 66 6f 72 20 6d 61 69 6e 20 64 61 74 61 62 0 for main datab
1eed0 61 73 65 2e 20 20 31 20 66 6f 72 20 54 45 4d 50 ase. 1 for TEMP
1eee0 2c 20 32 2e 2e 20 66 6f 72 20 41 54 54 41 43 48 , 2.. for ATTACH
1eef0 65 64 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 ed */. int rc;
1ef00 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 /* R
1ef10 65 73 75 6c 74 20 63 6f 64 65 20 73 74 6f 72 65 esult code store
1ef20 64 20 68 65 72 65 20 2a 2f 0a 7d 20 49 6e 69 74 d here */.} Init
1ef30 44 61 74 61 3b 0a 0a 2f 2a 0a 2a 2a 20 53 74 72 Data;../*.** Str
1ef40 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 69 6e ucture containin
1ef50 67 20 67 6c 6f 62 61 6c 20 63 6f 6e 66 69 67 75 g global configu
1ef60 72 61 74 69 6f 6e 20 64 61 74 61 20 66 6f 72 20 ration data for
1ef70 74 68 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 the SQLite libra
1ef80 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 ry..**.** This s
1ef90 74 72 75 63 74 75 72 65 20 61 6c 73 6f 20 63 6f tructure also co
1efa0 6e 74 61 69 6e 73 20 73 6f 6d 65 20 73 74 61 74 ntains some stat
1efb0 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a e information..*
1efc0 2f 0a 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 /.struct Sqlite3
1efd0 43 6f 6e 66 69 67 20 7b 0a 20 20 69 6e 74 20 62 Config {. int b
1efe0 4d 65 6d 73 74 61 74 3b 20 20 20 20 20 20 20 20 Memstat;
1eff0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f000 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 6d True to enable m
1f010 65 6d 6f 72 79 20 73 74 61 74 75 73 20 2a 2f 0a emory status */.
1f020 20 20 69 6e 74 20 62 43 6f 72 65 4d 75 74 65 78 int bCoreMutex
1f030 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1f040 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 /* True to e
1f050 6e 61 62 6c 65 20 63 6f 72 65 20 6d 75 74 65 78 nable core mutex
1f060 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 62 46 75 ing */. int bFu
1f070 6c 6c 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 llMutex;
1f080 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1f090 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 66 75 6c ue to enable ful
1f0a0 6c 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 20 l mutexing */.
1f0b0 69 6e 74 20 62 4f 70 65 6e 55 72 69 3b 20 20 20 int bOpenUri;
1f0c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f0d0 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 69 6e 74 /* True to int
1f0e0 65 72 70 72 65 74 20 66 69 6c 65 6e 61 6d 65 73 erpret filenames
1f0f0 20 61 73 20 55 52 49 73 20 2a 2f 0a 20 20 69 6e as URIs */. in
1f100 74 20 62 55 73 65 43 69 73 3b 20 20 20 20 20 20 t bUseCis;
1f110 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f120 2f 2a 20 55 73 65 20 63 6f 76 65 72 69 6e 67 20 /* Use covering
1f130 69 6e 64 69 63 65 73 20 66 6f 72 20 66 75 6c 6c indices for full
1f140 2d 73 63 61 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 -scans */. int
1f150 6d 78 53 74 72 6c 65 6e 3b 20 20 20 20 20 20 20 mxStrlen;
1f160 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1f170 20 4d 61 78 69 6d 75 6d 20 73 74 72 69 6e 67 20 Maximum string
1f180 6c 65 6e 67 74 68 20 2a 2f 0a 20 20 69 6e 74 20 length */. int
1f190 6e 65 76 65 72 43 6f 72 72 75 70 74 3b 20 20 20 neverCorrupt;
1f1a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1f1b0 20 44 61 74 61 62 61 73 65 20 69 73 20 61 6c 77 Database is alw
1f1c0 61 79 73 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 ays well-formed
1f1d0 2a 2f 0a 20 20 69 6e 74 20 73 7a 4c 6f 6f 6b 61 */. int szLooka
1f1e0 73 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 side;
1f1f0 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
1f200 74 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 t lookaside buff
1f210 65 72 20 73 69 7a 65 20 2a 2f 0a 20 20 69 6e 74 er size */. int
1f220 20 6e 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 nLookaside;
1f230 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1f240 2a 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 * Default lookas
1f250 69 64 65 20 62 75 66 66 65 72 20 63 6f 75 6e 74 ide buffer count
1f260 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 65 */. sqlite3_me
1f270 6d 5f 6d 65 74 68 6f 64 73 20 6d 3b 20 20 20 20 m_methods m;
1f280 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c /* Low-l
1f290 65 76 65 6c 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f evel memory allo
1f2a0 63 61 74 69 6f 6e 20 69 6e 74 65 72 66 61 63 65 cation interface
1f2b0 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 */. sqlite3_mu
1f2c0 74 65 78 5f 6d 65 74 68 6f 64 73 20 6d 75 74 65 tex_methods mute
1f2d0 78 3b 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c x; /* Low-l
1f2e0 65 76 65 6c 20 6d 75 74 65 78 20 69 6e 74 65 72 evel mutex inter
1f2f0 66 61 63 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 face */. sqlite
1f300 33 5f 70 63 61 63 68 65 5f 6d 65 74 68 6f 64 73 3_pcache_methods
1f310 32 20 70 63 61 63 68 65 32 3b 20 20 2f 2a 20 4c 2 pcache2; /* L
1f320 6f 77 2d 6c 65 76 65 6c 20 70 61 67 65 2d 63 61 ow-level page-ca
1f330 63 68 65 20 69 6e 74 65 72 66 61 63 65 20 2a 2f che interface */
1f340 0a 20 20 76 6f 69 64 20 2a 70 48 65 61 70 3b 20 . void *pHeap;
1f350 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f360 20 20 20 20 20 2f 2a 20 48 65 61 70 20 73 74 6f /* Heap sto
1f370 72 61 67 65 20 73 70 61 63 65 20 2a 2f 0a 20 20 rage space */.
1f380 69 6e 74 20 6e 48 65 61 70 3b 20 20 20 20 20 20 int nHeap;
1f390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f3a0 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 70 48 65 /* Size of pHe
1f3b0 61 70 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e ap[] */. int mn
1f3c0 52 65 71 2c 20 6d 78 52 65 71 3b 20 20 20 20 20 Req, mxReq;
1f3d0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d /* M
1f3e0 69 6e 20 61 6e 64 20 6d 61 78 20 68 65 61 70 20 in and max heap
1f3f0 72 65 71 75 65 73 74 73 20 73 69 7a 65 73 20 2a requests sizes *
1f400 2f 0a 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 /. sqlite3_int6
1f410 34 20 73 7a 4d 6d 61 70 3b 20 20 20 20 20 20 20 4 szMmap;
1f420 20 20 20 20 20 20 2f 2a 20 6d 6d 61 70 28 29 20 /* mmap()
1f430 73 70 61 63 65 20 70 65 72 20 6f 70 65 6e 20 66 space per open f
1f440 69 6c 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 ile */. sqlite3
1f450 5f 69 6e 74 36 34 20 6d 78 4d 6d 61 70 3b 20 20 _int64 mxMmap;
1f460 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 /* Ma
1f470 78 69 6d 75 6d 20 76 61 6c 75 65 20 66 6f 72 20 ximum value for
1f480 73 7a 4d 6d 61 70 20 2a 2f 0a 20 20 76 6f 69 64 szMmap */. void
1f490 20 2a 70 53 63 72 61 74 63 68 3b 20 20 20 20 20 *pScratch;
1f4a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1f4b0 20 53 63 72 61 74 63 68 20 6d 65 6d 6f 72 79 20 Scratch memory
1f4c0 2a 2f 0a 20 20 69 6e 74 20 73 7a 53 63 72 61 74 */. int szScrat
1f4d0 63 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ch;
1f4e0 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f /* Size o
1f4f0 66 20 65 61 63 68 20 73 63 72 61 74 63 68 20 62 f each scratch b
1f500 75 66 66 65 72 20 2a 2f 0a 20 20 69 6e 74 20 6e uffer */. int n
1f510 53 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 20 Scratch;
1f520 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f530 4e 75 6d 62 65 72 20 6f 66 20 73 63 72 61 74 63 Number of scratc
1f540 68 20 62 75 66 66 65 72 73 20 2a 2f 0a 20 20 76 h buffers */. v
1f550 6f 69 64 20 2a 70 50 61 67 65 3b 20 20 20 20 20 oid *pPage;
1f560 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f570 20 2f 2a 20 50 61 67 65 20 63 61 63 68 65 20 6d /* Page cache m
1f580 65 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e 74 20 73 emory */. int s
1f590 7a 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 zPage;
1f5a0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f5b0 53 69 7a 65 20 6f 66 20 65 61 63 68 20 70 61 67 Size of each pag
1f5c0 65 20 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f 0a e in pPage[] */.
1f5d0 20 20 69 6e 74 20 6e 50 61 67 65 3b 20 20 20 20 int nPage;
1f5e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f5f0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1f600 20 70 61 67 65 73 20 69 6e 20 70 50 61 67 65 5b pages in pPage[
1f610 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 50 61 72 ] */. int mxPar
1f620 73 65 72 53 74 61 63 6b 3b 20 20 20 20 20 20 20 serStack;
1f630 20 20 20 20 20 20 20 20 20 2f 2a 20 6d 61 78 69 /* maxi
1f640 6d 75 6d 20 64 65 70 74 68 20 6f 66 20 74 68 65 mum depth of the
1f650 20 70 61 72 73 65 72 20 73 74 61 63 6b 20 2a 2f parser stack */
1f660 0a 20 20 69 6e 74 20 73 68 61 72 65 64 43 61 63 . int sharedCac
1f670 68 65 45 6e 61 62 6c 65 64 3b 20 20 20 20 20 20 heEnabled;
1f680 20 20 20 20 20 2f 2a 20 74 72 75 65 20 69 66 20 /* true if
1f690 73 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 shared-cache mod
1f6a0 65 20 65 6e 61 62 6c 65 64 20 2a 2f 0a 20 20 75 e enabled */. u
1f6b0 33 32 20 73 7a 50 6d 61 3b 20 20 20 20 20 20 20 32 szPma;
1f6c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f6d0 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 53 6f 72 74 /* Maximum Sort
1f6e0 65 72 20 50 4d 41 20 73 69 7a 65 20 2a 2f 0a 20 er PMA size */.
1f6f0 20 2f 2a 20 54 68 65 20 61 62 6f 76 65 20 6d 69 /* The above mi
1f700 67 68 74 20 62 65 20 69 6e 69 74 69 61 6c 69 7a ght be initializ
1f710 65 64 20 74 6f 20 6e 6f 6e 2d 7a 65 72 6f 2e 20 ed to non-zero.
1f720 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6e The following n
1f730 65 65 64 20 74 6f 20 61 6c 77 61 79 73 0a 20 20 eed to always.
1f740 2a 2a 20 69 6e 69 74 69 61 6c 6c 79 20 62 65 20 ** initially be
1f750 7a 65 72 6f 2c 20 68 6f 77 65 76 65 72 2e 20 2a zero, however. *
1f760 2f 0a 20 20 69 6e 74 20 69 73 49 6e 69 74 3b 20 /. int isInit;
1f770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f780 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 /* True af
1f790 74 65 72 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ter initializati
1f7a0 6f 6e 20 68 61 73 20 66 69 6e 69 73 68 65 64 20 on has finished
1f7b0 2a 2f 0a 20 20 69 6e 74 20 69 6e 50 72 6f 67 72 */. int inProgr
1f7c0 65 73 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ess;
1f7d0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 77 /* True w
1f7e0 68 69 6c 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 hile initializat
1f7f0 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 73 73 20 ion in progress
1f800 2a 2f 0a 20 20 69 6e 74 20 69 73 4d 75 74 65 78 */. int isMutex
1f810 49 6e 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 Init;
1f820 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 /* True a
1f830 66 74 65 72 20 6d 75 74 65 78 65 73 20 61 72 65 fter mutexes are
1f840 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
1f850 20 20 69 6e 74 20 69 73 4d 61 6c 6c 6f 63 49 6e int isMallocIn
1f860 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 it;
1f870 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 /* True afte
1f880 72 20 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 r malloc is init
1f890 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 ialized */. int
1f8a0 20 69 73 50 43 61 63 68 65 49 6e 69 74 3b 20 20 isPCacheInit;
1f8b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1f8c0 2a 20 54 72 75 65 20 61 66 74 65 72 20 6d 61 6c * True after mal
1f8d0 6c 6f 63 20 69 73 20 69 6e 69 74 69 61 6c 69 7a loc is initializ
1f8e0 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 ed */. int nRef
1f8f0 49 6e 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 InitMutex;
1f900 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1f910 62 65 72 20 6f 66 20 75 73 65 72 73 20 6f 66 20 ber of users of
1f920 70 49 6e 69 74 4d 75 74 65 78 20 2a 2f 0a 20 20 pInitMutex */.
1f930 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 70 sqlite3_mutex *p
1f940 49 6e 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 InitMutex;
1f950 20 20 2f 2a 20 4d 75 74 65 78 20 75 73 65 64 20 /* Mutex used
1f960 62 79 20 73 71 6c 69 74 65 33 5f 69 6e 69 74 69 by sqlite3_initi
1f970 61 6c 69 7a 65 28 29 20 2a 2f 0a 20 20 76 6f 69 alize() */. voi
1f980 64 20 28 2a 78 4c 6f 67 29 28 76 6f 69 64 2a 2c d (*xLog)(void*,
1f990 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 int,const char*)
1f9a0 3b 20 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 66 6f ; /* Function fo
1f9b0 72 20 6c 6f 67 67 69 6e 67 20 2a 2f 0a 20 20 76 r logging */. v
1f9c0 6f 69 64 20 2a 70 4c 6f 67 41 72 67 3b 20 20 20 oid *pLogArg;
1f9d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f9e0 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 /* First arg
1f9f0 75 6d 65 6e 74 20 74 6f 20 78 4c 6f 67 28 29 20 ument to xLog()
1fa00 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
1fa10 5f 45 4e 41 42 4c 45 5f 53 51 4c 4c 4f 47 0a 20 _ENABLE_SQLLOG.
1fa20 20 76 6f 69 64 28 2a 78 53 71 6c 6c 6f 67 29 28 void(*xSqllog)(
1fa30 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 void*,sqlite3*,c
1fa40 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 29 onst char*, int)
1fa50 3b 0a 20 20 76 6f 69 64 20 2a 70 53 71 6c 6c 6f ;. void *pSqllo
1fa60 67 41 72 67 3b 0a 23 65 6e 64 69 66 0a 23 69 66 gArg;.#endif.#if
1fa70 64 65 66 20 53 51 4c 49 54 45 5f 56 44 42 45 5f def SQLITE_VDBE_
1fa80 43 4f 56 45 52 41 47 45 0a 20 20 2f 2a 20 54 68 COVERAGE. /* Th
1fa90 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 6c 6c e following call
1faa0 62 61 63 6b 20 28 69 66 20 6e 6f 74 20 4e 55 4c back (if not NUL
1fab0 4c 29 20 69 73 20 69 6e 76 6f 6b 65 64 20 6f 6e L) is invoked on
1fac0 20 65 76 65 72 79 20 56 44 42 45 20 62 72 61 6e every VDBE bran
1fad0 63 68 0a 20 20 2a 2a 20 6f 70 65 72 61 74 69 6f ch. ** operatio
1fae0 6e 2e 20 20 53 65 74 20 74 68 65 20 63 61 6c 6c n. Set the call
1faf0 62 61 63 6b 20 75 73 69 6e 67 20 53 51 4c 49 54 back using SQLIT
1fb00 45 5f 54 45 53 54 43 54 52 4c 5f 56 44 42 45 5f E_TESTCTRL_VDBE_
1fb10 43 4f 56 45 52 41 47 45 2e 0a 20 20 2a 2f 0a 20 COVERAGE.. */.
1fb20 20 76 6f 69 64 20 28 2a 78 56 64 62 65 42 72 61 void (*xVdbeBra
1fb30 6e 63 68 29 28 76 6f 69 64 2a 2c 69 6e 74 20 69 nch)(void*,int i
1fb40 53 72 63 4c 69 6e 65 2c 75 38 20 65 54 68 69 73 SrcLine,u8 eThis
1fb50 2c 75 38 20 65 4d 78 29 3b 20 20 2f 2a 20 43 61 ,u8 eMx); /* Ca
1fb60 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 llback */. void
1fb70 20 2a 70 56 64 62 65 42 72 61 6e 63 68 41 72 67 *pVdbeBranchArg
1fb80 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1fb90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fba0 20 20 20 20 20 20 2f 2a 20 31 73 74 20 61 72 67 /* 1st arg
1fbb0 75 6d 65 6e 74 20 2a 2f 0a 23 65 6e 64 69 66 0a ument */.#endif.
1fbc0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1fbd0 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 MIT_BUILTIN_TEST
1fbe0 0a 20 20 69 6e 74 20 28 2a 78 54 65 73 74 43 61 . int (*xTestCa
1fbf0 6c 6c 62 61 63 6b 29 28 69 6e 74 29 3b 20 20 20 llback)(int);
1fc00 20 20 20 20 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 /* Invoked
1fc10 62 79 20 73 71 6c 69 74 65 33 46 61 75 6c 74 53 by sqlite3FaultS
1fc20 69 6d 28 29 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 im() */.#endif.
1fc30 20 69 6e 74 20 62 4c 6f 63 61 6c 74 69 6d 65 46 int bLocaltimeF
1fc40 61 75 6c 74 3b 20 20 20 20 20 20 20 20 20 20 20 ault;
1fc50 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 66 61 /* True to fa
1fc60 69 6c 20 6c 6f 63 61 6c 74 69 6d 65 28 29 20 63 il localtime() c
1fc70 61 6c 6c 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a alls */.};../*.*
1fc80 2a 20 54 68 69 73 20 6d 61 63 72 6f 20 69 73 20 * This macro is
1fc90 75 73 65 64 20 69 6e 73 69 64 65 20 6f 66 20 61 used inside of a
1fca0 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e ssert() statemen
1fcb0 74 73 20 74 6f 20 69 6e 64 69 63 61 74 65 20 74 ts to indicate t
1fcc0 68 61 74 0a 2a 2a 20 74 68 65 20 61 73 73 65 72 hat.** the asser
1fcd0 74 20 69 73 20 6f 6e 6c 79 20 76 61 6c 69 64 20 t is only valid
1fce0 6f 6e 20 61 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 on a well-formed
1fcf0 20 64 61 74 61 62 61 73 65 2e 20 20 49 6e 73 74 database. Inst
1fd00 65 61 64 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 ead of:.**.**
1fd10 20 20 61 73 73 65 72 74 28 20 58 20 29 3b 0a 2a assert( X );.*
1fd20 2a 0a 2a 2a 20 4f 6e 65 20 77 72 69 74 65 73 3a *.** One writes:
1fd30 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 73 73 65 72 .**.** asser
1fd40 74 28 20 58 20 7c 7c 20 43 4f 52 52 55 50 54 5f t( X || CORRUPT_
1fd50 44 42 20 29 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 52 DB );.**.** CORR
1fd60 55 50 54 5f 44 42 20 69 73 20 74 72 75 65 20 64 UPT_DB is true d
1fd70 75 72 69 6e 67 20 6e 6f 72 6d 61 6c 20 6f 70 65 uring normal ope
1fd80 72 61 74 69 6f 6e 2e 20 20 43 4f 52 52 55 50 54 ration. CORRUPT
1fd90 5f 44 42 20 64 6f 65 73 20 6e 6f 74 20 69 6e 64 _DB does not ind
1fda0 69 63 61 74 65 0a 2a 2a 20 74 68 61 74 20 74 68 icate.** that th
1fdb0 65 20 64 61 74 61 62 61 73 65 20 69 73 20 64 65 e database is de
1fdc0 66 69 6e 69 74 65 6c 79 20 63 6f 72 72 75 70 74 finitely corrupt
1fdd0 2c 20 6f 6e 6c 79 20 74 68 61 74 20 69 74 20 6d , only that it m
1fde0 69 67 68 74 20 62 65 20 63 6f 72 72 75 70 74 2e ight be corrupt.
1fdf0 0a 2a 2a 20 46 6f 72 20 6d 6f 73 74 20 74 65 73 .** For most tes
1fe00 74 20 63 61 73 65 73 2c 20 43 4f 52 52 55 50 54 t cases, CORRUPT
1fe10 5f 44 42 20 69 73 20 73 65 74 20 74 6f 20 66 61 _DB is set to fa
1fe20 6c 73 65 20 75 73 69 6e 67 20 61 20 73 70 65 63 lse using a spec
1fe30 69 61 6c 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 ial.** sqlite3_t
1fe40 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 29 2e 20 20 est_control().
1fe50 54 68 69 73 20 65 6e 61 62 6c 65 73 20 61 73 73 This enables ass
1fe60 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
1fe70 20 74 6f 20 70 72 6f 76 65 0a 2a 2a 20 74 68 69 to prove.** thi
1fe80 6e 67 73 20 74 68 61 74 20 61 72 65 20 61 6c 77 ngs that are alw
1fe90 61 79 73 20 74 72 75 65 20 66 6f 72 20 77 65 6c ays true for wel
1fea0 6c 2d 66 6f 72 6d 65 64 20 64 61 74 61 62 61 73 l-formed databas
1feb0 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43 es..*/.#define C
1fec0 4f 52 52 55 50 54 5f 44 42 20 20 28 73 71 6c 69 ORRUPT_DB (sqli
1fed0 74 65 33 43 6f 6e 66 69 67 2e 6e 65 76 65 72 43 te3Config.neverC
1fee0 6f 72 72 75 70 74 3d 3d 30 29 0a 0a 2f 2a 0a 2a orrupt==0)../*.*
1fef0 2a 20 43 6f 6e 74 65 78 74 20 70 6f 69 6e 74 65 * Context pointe
1ff00 72 20 70 61 73 73 65 64 20 64 6f 77 6e 20 74 68 r passed down th
1ff10 72 6f 75 67 68 20 74 68 65 20 74 72 65 65 2d 77 rough the tree-w
1ff20 61 6c 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 alk..*/.struct W
1ff30 61 6c 6b 65 72 20 7b 0a 20 20 69 6e 74 20 28 2a alker {. int (*
1ff40 78 45 78 70 72 43 61 6c 6c 62 61 63 6b 29 28 57 xExprCallback)(W
1ff50 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a 29 3b 20 alker*, Expr*);
1ff60 20 20 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 /* Callback
1ff70 66 6f 72 20 65 78 70 72 65 73 73 69 6f 6e 73 20 for expressions
1ff80 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 53 65 6c 65 */. int (*xSele
1ff90 63 74 43 61 6c 6c 62 61 63 6b 29 28 57 61 6c 6b ctCallback)(Walk
1ffa0 65 72 2a 2c 53 65 6c 65 63 74 2a 29 3b 20 20 2f er*,Select*); /
1ffb0 2a 20 43 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 * Callback for S
1ffc0 45 4c 45 43 54 73 20 2a 2f 0a 20 20 76 6f 69 64 ELECTs */. void
1ffd0 20 28 2a 78 53 65 6c 65 63 74 43 61 6c 6c 62 61 (*xSelectCallba
1ffe0 63 6b 32 29 28 57 61 6c 6b 65 72 2a 2c 53 65 6c ck2)(Walker*,Sel
1fff0 65 63 74 2a 29 3b 2f 2a 20 53 65 63 6f 6e 64 20 ect*);/* Second
20000 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 45 4c callback for SEL
20010 45 43 54 73 20 2a 2f 0a 20 20 50 61 72 73 65 20 ECTs */. Parse
20020 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 20 *pParse;
20030 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20040 20 20 20 20 2f 2a 20 50 61 72 73 65 72 20 63 6f /* Parser co
20050 6e 74 65 78 74 2e 20 20 2a 2f 0a 20 20 69 6e 74 ntext. */. int
20060 20 77 61 6c 6b 65 72 44 65 70 74 68 3b 20 20 20 walkerDepth;
20070 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20080 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
20090 20 6f 66 20 73 75 62 71 75 65 72 69 65 73 20 2a of subqueries *
200a0 2f 0a 20 20 75 38 20 65 43 6f 64 65 3b 20 20 20 /. u8 eCode;
200b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
200c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
200d0 20 41 20 73 6d 61 6c 6c 20 70 72 6f 63 65 73 73 A small process
200e0 69 6e 67 20 63 6f 64 65 20 2a 2f 0a 20 20 75 6e ing code */. un
200f0 69 6f 6e 20 7b 20 20 20 20 20 20 20 20 20 20 20 ion {
20100 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20110 20 20 20 20 20 20 20 20 2f 2a 20 45 78 74 72 61 /* Extra
20120 20 64 61 74 61 20 66 6f 72 20 63 61 6c 6c 62 61 data for callba
20130 63 6b 20 2a 2f 0a 20 20 20 20 4e 61 6d 65 43 6f ck */. NameCo
20140 6e 74 65 78 74 20 2a 70 4e 43 3b 20 20 20 20 20 ntext *pNC;
20150 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20160 20 20 20 20 20 2f 2a 20 4e 61 6d 69 6e 67 20 63 /* Naming c
20170 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 20 20 69 6e ontext */. in
20180 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 t n;
20190 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
201a0 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 6f /* A co
201b0 75 6e 74 65 72 20 2a 2f 0a 20 20 20 20 69 6e 74 unter */. int
201c0 20 69 43 75 72 3b 20 20 20 20 20 20 20 20 20 20 iCur;
201d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
201e0 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 75 72 /* A cur
201f0 73 6f 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 sor number */.
20200 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 4c SrcList *pSrcL
20210 69 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ist;
20220 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
20230 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 FROM clause */.
20240 20 20 20 73 74 72 75 63 74 20 53 72 63 43 6f 75 struct SrcCou
20250 6e 74 20 2a 70 53 72 63 43 6f 75 6e 74 3b 20 20 nt *pSrcCount;
20260 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
20270 20 43 6f 75 6e 74 69 6e 67 20 63 6f 6c 75 6d 6e Counting column
20280 20 72 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 references */.
20290 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f 2a 20 46 6f 72 } u;.};../* For
202a0 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f 6e ward declaration
202b0 73 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 s */.int sqlite3
202c0 57 61 6c 6b 45 78 70 72 28 57 61 6c 6b 65 72 2a WalkExpr(Walker*
202d0 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 , Expr*);.int sq
202e0 6c 69 74 65 33 57 61 6c 6b 45 78 70 72 4c 69 73 lite3WalkExprLis
202f0 74 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 4c t(Walker*, ExprL
20300 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ist*);.int sqlit
20310 65 33 57 61 6c 6b 53 65 6c 65 63 74 28 57 61 6c e3WalkSelect(Wal
20320 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a ker*, Select*);.
20330 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 int sqlite3WalkS
20340 65 6c 65 63 74 45 78 70 72 28 57 61 6c 6b 65 72 electExpr(Walker
20350 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 *, Select*);.int
20360 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 65 6c 65 sqlite3WalkSele
20370 63 74 46 72 6f 6d 28 57 61 6c 6b 65 72 2a 2c 20 ctFrom(Walker*,
20380 53 65 6c 65 63 74 2a 29 3b 0a 0a 2f 2a 0a 2a 2a Select*);../*.**
20390 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 6f Return code fro
203a0 6d 20 74 68 65 20 70 61 72 73 65 2d 74 72 65 65 m the parse-tree
203b0 20 77 61 6c 6b 69 6e 67 20 70 72 69 6d 69 74 69 walking primiti
203c0 76 65 73 20 61 6e 64 20 74 68 65 69 72 0a 2a 2a ves and their.**
203d0 20 63 61 6c 6c 62 61 63 6b 73 2e 0a 2a 2f 0a 23 callbacks..*/.#
203e0 64 65 66 69 6e 65 20 57 52 43 5f 43 6f 6e 74 69 define WRC_Conti
203f0 6e 75 65 20 20 20 20 30 20 20 20 2f 2a 20 43 6f nue 0 /* Co
20400 6e 74 69 6e 75 65 20 64 6f 77 6e 20 69 6e 74 6f ntinue down into
20410 20 63 68 69 6c 64 72 65 6e 20 2a 2f 0a 23 64 65 children */.#de
20420 66 69 6e 65 20 57 52 43 5f 50 72 75 6e 65 20 20 fine WRC_Prune
20430 20 20 20 20 20 31 20 20 20 2f 2a 20 4f 6d 69 74 1 /* Omit
20440 20 63 68 69 6c 64 72 65 6e 20 62 75 74 20 63 6f children but co
20450 6e 74 69 6e 75 65 20 77 61 6c 6b 69 6e 67 20 73 ntinue walking s
20460 69 62 6c 69 6e 67 73 20 2a 2f 0a 23 64 65 66 69 iblings */.#defi
20470 6e 65 20 57 52 43 5f 41 62 6f 72 74 20 20 20 20 ne WRC_Abort
20480 20 20 20 32 20 20 20 2f 2a 20 41 62 61 6e 64 6f 2 /* Abando
20490 6e 20 74 68 65 20 74 72 65 65 20 77 61 6c 6b 20 n the tree walk
204a0 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 */../*.** An ins
204b0 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 tance of this st
204c0 72 75 63 74 75 72 65 20 72 65 70 72 65 73 65 6e ructure represen
204d0 74 73 20 61 20 73 65 74 20 6f 66 20 6f 6e 65 20 ts a set of one
204e0 6f 72 20 6d 6f 72 65 20 43 54 45 73 0a 2a 2a 20 or more CTEs.**
204f0 28 63 6f 6d 6d 6f 6e 20 74 61 62 6c 65 20 65 78 (common table ex
20500 70 72 65 73 73 69 6f 6e 73 29 20 63 72 65 61 74 pressions) creat
20510 65 64 20 62 79 20 61 20 73 69 6e 67 6c 65 20 57 ed by a single W
20520 49 54 48 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a 73 ITH clause..*/.s
20530 74 72 75 63 74 20 57 69 74 68 20 7b 0a 20 20 69 truct With {. i
20540 6e 74 20 6e 43 74 65 3b 20 20 20 20 20 20 20 20 nt nCte;
20550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
20560 2a 20 4e 75 6d 62 65 72 20 6f 66 20 43 54 45 73 * Number of CTEs
20570 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c 61 in the WITH cla
20580 75 73 65 20 2a 2f 0a 20 20 57 69 74 68 20 2a 70 use */. With *p
20590 4f 75 74 65 72 3b 20 20 20 20 20 20 20 20 20 20 Outer;
205a0 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 74 /* Cont
205b0 61 69 6e 69 6e 67 20 57 49 54 48 20 63 6c 61 75 aining WITH clau
205c0 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 20 se, or NULL */.
205d0 20 73 74 72 75 63 74 20 43 74 65 20 7b 20 20 20 struct Cte {
205e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
205f0 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 43 54 45 /* For each CTE
20600 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c 61 in the WITH cla
20610 75 73 65 2e 2e 2e 2e 20 2a 2f 0a 20 20 20 20 63 use.... */. c
20620 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
20630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
20640 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 43 * Name of this C
20650 54 45 20 2a 2f 0a 20 20 20 20 45 78 70 72 4c 69 TE */. ExprLi
20660 73 74 20 2a 70 43 6f 6c 73 3b 20 20 20 20 20 20 st *pCols;
20670 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 /* Lis
20680 74 20 6f 66 20 65 78 70 6c 69 63 69 74 20 63 6f t of explicit co
20690 6c 75 6d 6e 20 6e 61 6d 65 73 2c 20 6f 72 20 4e lumn names, or N
206a0 55 4c 4c 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 ULL */. Selec
206b0 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 t *pSelect;
206c0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
206d0 65 20 64 65 66 69 6e 69 74 69 6f 6e 20 6f 66 20 e definition of
206e0 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 20 20 20 this CTE */.
206f0 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 45 72 72 const char *zErr
20700 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
20710 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 67 65 /* Error message
20720 20 66 6f 72 20 63 69 72 63 75 6c 61 72 20 72 65 for circular re
20730 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 20 7d 20 ferences */. }
20740 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 69 66 64 65 66 a[1];.};..#ifdef
20750 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 2f 2a SQLITE_DEBUG./*
20760 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
20770 6f 66 20 74 68 65 20 54 72 65 65 56 69 65 77 20 of the TreeView
20780 6f 62 6a 65 63 74 20 69 73 20 75 73 65 64 20 66 object is used f
20790 6f 72 20 70 72 69 6e 74 69 6e 67 20 74 68 65 20 or printing the
207a0 63 6f 6e 74 65 6e 74 20 6f 66 0a 2a 2a 20 64 61 content of.** da
207b0 74 61 20 73 74 72 75 63 74 75 72 65 73 20 6f 6e ta structures on
207c0 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 69 sqlite3DebugPri
207d0 6e 74 66 28 29 20 75 73 69 6e 67 20 61 20 74 72 ntf() using a tr
207e0 65 65 2d 6c 69 6b 65 20 76 69 65 77 2e 0a 2a 2f ee-like view..*/
207f0 0a 73 74 72 75 63 74 20 54 72 65 65 56 69 65 77 .struct TreeView
20800 20 7b 0a 20 20 69 6e 74 20 69 4c 65 76 65 6c 3b {. int iLevel;
20810 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
20820 57 68 69 63 68 20 6c 65 76 65 6c 20 6f 66 20 74 Which level of t
20830 68 65 20 74 72 65 65 20 77 65 20 61 72 65 20 6f he tree we are o
20840 6e 20 2a 2f 0a 20 20 75 38 20 20 62 4c 69 6e 65 n */. u8 bLine
20850 5b 31 30 30 5d 3b 20 20 20 20 20 20 20 20 20 2f [100]; /
20860 2a 20 44 72 61 77 20 76 65 72 74 69 63 61 6c 20 * Draw vertical
20870 69 6e 20 63 6f 6c 75 6d 6e 20 69 20 69 66 20 62 in column i if b
20880 4c 69 6e 65 5b 69 5d 20 69 73 20 74 72 75 65 20 Line[i] is true
20890 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 66 20 2f 2a 20 */.};.#endif /*
208a0 53 51 4c 49 54 45 5f 44 45 42 55 47 20 2a 2f 0a SQLITE_DEBUG */.
208b0 0a 2f 2a 0a 2a 2a 20 41 73 73 75 6d 69 6e 67 20 ./*.** Assuming
208c0 7a 49 6e 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 zIn points to th
208d0 65 20 66 69 72 73 74 20 62 79 74 65 20 6f 66 20 e first byte of
208e0 61 20 55 54 46 2d 38 20 63 68 61 72 61 63 74 65 a UTF-8 characte
208f0 72 2c 0a 2a 2a 20 61 64 76 61 6e 63 65 20 7a 49 r,.** advance zI
20900 6e 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 74 68 n to point to th
20910 65 20 66 69 72 73 74 20 62 79 74 65 20 6f 66 20 e first byte of
20920 74 68 65 20 6e 65 78 74 20 55 54 46 2d 38 20 63 the next UTF-8 c
20930 68 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 23 64 65 haracter..*/.#de
20940 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4b 49 50 fine SQLITE_SKIP
20950 5f 55 54 46 38 28 7a 49 6e 29 20 7b 20 20 20 20 _UTF8(zIn) {
20960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20970 20 20 20 20 5c 0a 20 20 69 66 28 20 28 2a 28 7a \. if( (*(z
20980 49 6e 2b 2b 29 29 3e 3d 30 78 63 30 20 29 7b 20 In++))>=0xc0 ){
20990 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
209a0 20 20 20 20 20 20 20 20 20 20 20 20 20 5c 0a 20 \.
209b0 20 20 20 77 68 69 6c 65 28 20 28 2a 7a 49 6e 20 while( (*zIn
209c0 26 20 30 78 63 30 29 3d 3d 30 78 38 30 20 29 7b & 0xc0)==0x80 ){
209d0 20 7a 49 6e 2b 2b 3b 20 7d 20 20 20 20 20 20 20 zIn++; }
209e0 20 20 20 20 20 20 5c 0a 20 20 7d 20 20 20 20 20 \. }
209f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20a00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20a10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5c \
20a20 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 .}../*.** The SQ
20a30 4c 49 54 45 5f 2a 5f 42 4b 50 54 20 6d 61 63 72 LITE_*_BKPT macr
20a40 6f 73 20 61 72 65 20 73 75 62 73 74 69 74 75 74 os are substitut
20a50 65 73 20 66 6f 72 20 74 68 65 20 65 72 72 6f 72 es for the error
20a60 20 63 6f 64 65 73 20 77 69 74 68 0a 2a 2a 20 74 codes with.** t
20a70 68 65 20 73 61 6d 65 20 6e 61 6d 65 20 62 75 74 he same name but
20a80 20 77 69 74 68 6f 75 74 20 74 68 65 20 5f 42 4b without the _BK
20a90 50 54 20 73 75 66 66 69 78 2e 20 20 54 68 65 73 PT suffix. Thes
20aa0 65 20 6d 61 63 72 6f 73 20 69 6e 76 6f 6b 65 0a e macros invoke.
20ab0 2a 2a 20 72 6f 75 74 69 6e 65 73 20 74 68 61 74 ** routines that
20ac0 20 72 65 70 6f 72 74 20 74 68 65 20 6c 69 6e 65 report the line
20ad0 2d 6e 75 6d 62 65 72 20 6f 6e 20 77 68 69 63 68 -number on which
20ae0 20 74 68 65 20 65 72 72 6f 72 20 6f 72 69 67 69 the error origi
20af0 6e 61 74 65 64 0a 2a 2a 20 75 73 69 6e 67 20 73 nated.** using s
20b00 71 6c 69 74 65 33 5f 6c 6f 67 28 29 2e 20 20 54 qlite3_log(). T
20b10 68 65 20 72 6f 75 74 69 6e 65 73 20 61 6c 73 6f he routines also
20b20 20 70 72 6f 76 69 64 65 20 61 20 63 6f 6e 76 65 provide a conve
20b30 6e 69 65 6e 74 20 70 6c 61 63 65 0a 2a 2a 20 74 nient place.** t
20b40 6f 20 73 65 74 20 61 20 64 65 62 75 67 67 65 72 o set a debugger
20b50 20 62 72 65 61 6b 70 6f 69 6e 74 2e 0a 2a 2f 0a breakpoint..*/.
20b60 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 72 72 75 int sqlite3Corru
20b70 70 74 45 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e ptError(int);.in
20b80 74 20 73 71 6c 69 74 65 33 4d 69 73 75 73 65 45 t sqlite3MisuseE
20b90 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e 74 20 73 rror(int);.int s
20ba0 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e 45 72 qlite3CantopenEr
20bb0 72 6f 72 28 69 6e 74 29 3b 0a 23 64 65 66 69 6e ror(int);.#defin
20bc0 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 50 54 e SQLITE_CORRUPT
20bd0 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 43 6f 72 _BKPT sqlite3Cor
20be0 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 ruptError(__LINE
20bf0 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 __).#define SQLI
20c00 54 45 5f 4d 49 53 55 53 45 5f 42 4b 50 54 20 73 TE_MISUSE_BKPT s
20c10 71 6c 69 74 65 33 4d 69 73 75 73 65 45 72 72 6f qlite3MisuseErro
20c20 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 65 66 r(__LINE__).#def
20c30 69 6e 65 20 53 51 4c 49 54 45 5f 43 41 4e 54 4f ine SQLITE_CANTO
20c40 50 45 4e 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 PEN_BKPT sqlite3
20c50 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 5f 5f CantopenError(__
20c60 4c 49 4e 45 5f 5f 29 0a 0a 0a 2f 2a 0a 2a 2a 20 LINE__).../*.**
20c70 46 54 53 34 20 69 73 20 72 65 61 6c 6c 79 20 61 FTS4 is really a
20c80 6e 20 65 78 74 65 6e 73 69 6f 6e 20 66 6f 72 20 n extension for
20c90 46 54 53 33 2e 20 20 49 74 20 69 73 20 65 6e 61 FTS3. It is ena
20ca0 62 6c 65 64 20 75 73 69 6e 67 20 74 68 65 0a 2a bled using the.*
20cb0 2a 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f * SQLITE_ENABLE_
20cc0 46 54 53 33 20 6d 61 63 72 6f 2e 20 20 42 75 74 FTS3 macro. But
20cd0 20 74 6f 20 61 76 6f 69 64 20 63 6f 6e 66 75 73 to avoid confus
20ce0 69 6f 6e 20 77 65 20 61 6c 73 6f 20 63 61 6c 6c ion we also call
20cf0 0a 2a 2a 20 74 68 65 20 53 51 4c 49 54 45 5f 45 .** the SQLITE_E
20d00 4e 41 42 4c 45 5f 46 54 53 34 20 6d 61 63 72 6f NABLE_FTS4 macro
20d10 20 74 6f 20 73 65 72 76 65 20 61 73 20 61 6e 20 to serve as an
20d20 61 6c 69 61 73 20 66 6f 72 20 53 51 4c 49 54 45 alias for SQLITE
20d30 5f 45 4e 41 42 4c 45 5f 46 54 53 33 2e 0a 2a 2f _ENABLE_FTS3..*/
20d40 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c .#if defined(SQL
20d50 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 34 29 ITE_ENABLE_FTS4)
20d60 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c && !defined(SQL
20d70 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 29 ITE_ENABLE_FTS3)
20d80 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
20d90 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 31 0a 23 _ENABLE_FTS3 1.#
20da0 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
20db0 20 63 74 79 70 65 2e 68 20 68 65 61 64 65 72 20 ctype.h header
20dc0 69 73 20 6e 65 65 64 65 64 20 66 6f 72 20 6e 6f is needed for no
20dd0 6e 2d 41 53 43 49 49 20 73 79 73 74 65 6d 73 2e n-ASCII systems.
20de0 20 20 49 74 20 69 73 20 61 6c 73 6f 0a 2a 2a 20 It is also.**
20df0 6e 65 65 64 65 64 20 62 79 20 46 54 53 33 20 77 needed by FTS3 w
20e00 68 65 6e 20 46 54 53 33 20 69 73 20 69 6e 63 6c hen FTS3 is incl
20e10 75 64 65 64 20 69 6e 20 74 68 65 20 61 6d 61 6c uded in the amal
20e20 67 61 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 gamation..*/.#if
20e30 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
20e40 5f 41 53 43 49 49 29 20 7c 7c 20 5c 0a 20 20 20 _ASCII) || \.
20e50 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 (defined(SQLITE
20e60 5f 45 4e 41 42 4c 45 5f 46 54 53 33 29 20 26 26 _ENABLE_FTS3) &&
20e70 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
20e80 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 29 29 0a 23 AMALGAMATION)).#
20e90 20 69 6e 63 6c 75 64 65 20 3c 63 74 79 70 65 2e include <ctype.
20ea0 68 3e 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a h>.#endif../*.**
20eb0 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d The following m
20ec0 61 63 72 6f 73 20 6d 69 6d 69 63 20 74 68 65 20 acros mimic the
20ed0 73 74 61 6e 64 61 72 64 20 6c 69 62 72 61 72 79 standard library
20ee0 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f 75 70 70 functions toupp
20ef0 65 72 28 29 2c 0a 2a 2a 20 69 73 73 70 61 63 65 er(),.** isspace
20f00 28 29 2c 20 69 73 61 6c 6e 75 6d 28 29 2c 20 69 (), isalnum(), i
20f10 73 64 69 67 69 74 28 29 20 61 6e 64 20 69 73 78 sdigit() and isx
20f20 64 69 67 69 74 28 29 2c 20 72 65 73 70 65 63 74 digit(), respect
20f30 69 76 65 6c 79 2e 20 54 68 65 0a 2a 2a 20 73 71 ively. The.** sq
20f40 6c 69 74 65 20 76 65 72 73 69 6f 6e 73 20 6f 6e lite versions on
20f50 6c 79 20 77 6f 72 6b 20 66 6f 72 20 41 53 43 49 ly work for ASCI
20f60 49 20 63 68 61 72 61 63 74 65 72 73 2c 20 72 65 I characters, re
20f70 67 61 72 64 6c 65 73 73 20 6f 66 20 6c 6f 63 61 gardless of loca
20f80 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 le..*/.#ifdef SQ
20f90 4c 49 54 45 5f 41 53 43 49 49 0a 23 20 64 65 66 LITE_ASCII.# def
20fa0 69 6e 65 20 73 71 6c 69 74 65 33 54 6f 75 70 70 ine sqlite3Toupp
20fb0 65 72 28 78 29 20 20 28 28 78 29 26 7e 28 73 71 er(x) ((x)&~(sq
20fc0 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
20fd0 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
20fe0 5d 26 30 78 32 30 29 29 0a 23 20 64 65 66 69 6e ]&0x20)).# defin
20ff0 65 20 73 71 6c 69 74 65 33 49 73 73 70 61 63 65 e sqlite3Isspace
21000 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
21010 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
21020 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 31 29 char)(x)]&0x01)
21030 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
21040 33 49 73 61 6c 6e 75 6d 28 78 29 20 20 20 28 73 3Isalnum(x) (s
21050 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
21060 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
21070 29 5d 26 30 78 30 36 29 0a 23 20 64 65 66 69 6e )]&0x06).# defin
21080 65 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 e sqlite3Isalpha
21090 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
210a0 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
210b0 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 32 29 char)(x)]&0x02)
210c0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
210d0 33 49 73 64 69 67 69 74 28 78 29 20 20 20 28 73 3Isdigit(x) (s
210e0 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
210f0 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
21100 29 5d 26 30 78 30 34 29 0a 23 20 64 65 66 69 6e )]&0x04).# defin
21110 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 67 69 e sqlite3Isxdigi
21120 74 28 78 29 20 20 28 73 71 6c 69 74 65 33 43 74 t(x) (sqlite3Ct
21130 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
21140 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 38 29 char)(x)]&0x08)
21150 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
21160 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 20 28 73 3Tolower(x) (s
21170 71 6c 69 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 qlite3UpperToLow
21180 65 72 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er[(unsigned cha
21190 72 29 28 78 29 5d 29 0a 23 65 6c 73 65 0a 23 20 r)(x)]).#else.#
211a0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f define sqlite3To
211b0 75 70 70 65 72 28 78 29 20 20 20 74 6f 75 70 70 upper(x) toupp
211c0 65 72 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er((unsigned cha
211d0 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
211e0 73 71 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 sqlite3Isspace(x
211f0 29 20 20 20 69 73 73 70 61 63 65 28 28 75 6e 73 ) isspace((uns
21200 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
21210 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
21220 49 73 61 6c 6e 75 6d 28 78 29 20 20 20 69 73 61 Isalnum(x) isa
21230 6c 6e 75 6d 28 28 75 6e 73 69 67 6e 65 64 20 63 lnum((unsigned c
21240 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
21250 65 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 e sqlite3Isalpha
21260 28 78 29 20 20 20 69 73 61 6c 70 68 61 28 28 75 (x) isalpha((u
21270 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
21280 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
21290 65 33 49 73 64 69 67 69 74 28 78 29 20 20 20 69 e3Isdigit(x) i
212a0 73 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 sdigit((unsigned
212b0 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 char)(x)).# def
212c0 69 6e 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 ine sqlite3Isxdi
212d0 67 69 74 28 78 29 20 20 69 73 78 64 69 67 69 74 git(x) isxdigit
212e0 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
212f0 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
21300 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 lite3Tolower(x)
21310 20 20 74 6f 6c 6f 77 65 72 28 28 75 6e 73 69 67 tolower((unsig
21320 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 65 ned char)(x)).#e
21330 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
21340 49 54 45 5f 4f 4d 49 54 5f 43 4f 4d 50 49 4c 45 ITE_OMIT_COMPILE
21350 4f 50 54 49 4f 4e 5f 44 49 41 47 53 0a 69 6e 74 OPTION_DIAGS.int
21360 20 73 71 6c 69 74 65 33 49 73 49 64 43 68 61 72 sqlite3IsIdChar
21370 28 75 38 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a (u8);.#endif../*
21380 0a 2a 2a 20 49 6e 74 65 72 6e 61 6c 20 66 75 6e .** Internal fun
21390 63 74 69 6f 6e 20 70 72 6f 74 6f 74 79 70 65 73 ction prototypes
213a0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 .*/.#define sqli
213b0 74 65 33 53 74 72 49 43 6d 70 20 73 71 6c 69 74 te3StrICmp sqlit
213c0 65 33 5f 73 74 72 69 63 6d 70 0a 69 6e 74 20 73 e3_stricmp.int s
213d0 71 6c 69 74 65 33 53 74 72 6c 65 6e 33 30 28 63 qlite3Strlen30(c
213e0 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 64 65 onst char*);.#de
213f0 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 72 4e fine sqlite3StrN
21400 49 43 6d 70 20 73 71 6c 69 74 65 33 5f 73 74 72 ICmp sqlite3_str
21410 6e 69 63 6d 70 0a 0a 69 6e 74 20 73 71 6c 69 74 nicmp..int sqlit
21420 65 33 4d 61 6c 6c 6f 63 49 6e 69 74 28 76 6f 69 e3MallocInit(voi
21430 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 d);.void sqlite3
21440 4d 61 6c 6c 6f 63 45 6e 64 28 76 6f 69 64 29 3b MallocEnd(void);
21450 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 4d 61 .void *sqlite3Ma
21460 6c 6c 6f 63 28 75 36 34 29 3b 0a 76 6f 69 64 20 lloc(u64);.void
21470 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 5a 65 *sqlite3MallocZe
21480 72 6f 28 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 ro(u64);.void *s
21490 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 qlite3DbMallocZe
214a0 72 6f 28 73 71 6c 69 74 65 33 2a 2c 20 75 36 34 ro(sqlite3*, u64
214b0 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
214c0 44 62 4d 61 6c 6c 6f 63 52 61 77 28 73 71 6c 69 DbMallocRaw(sqli
214d0 74 65 33 2a 2c 20 75 36 34 29 3b 0a 63 68 61 72 te3*, u64);.char
214e0 20 2a 73 71 6c 69 74 65 33 44 62 53 74 72 44 75 *sqlite3DbStrDu
214f0 70 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 p(sqlite3*,const
21500 20 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 2a 73 char*);.char *s
21510 71 6c 69 74 65 33 44 62 53 74 72 4e 44 75 70 28 qlite3DbStrNDup(
21520 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
21530 68 61 72 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 har*, u64);.void
21540 20 2a 73 71 6c 69 74 65 33 52 65 61 6c 6c 6f 63 *sqlite3Realloc
21550 28 76 6f 69 64 2a 2c 20 75 36 34 29 3b 0a 76 6f (void*, u64);.vo
21560 69 64 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 id *sqlite3DbRea
21570 6c 6c 6f 63 4f 72 46 72 65 65 28 73 71 6c 69 74 llocOrFree(sqlit
21580 65 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 e3 *, void *, u6
21590 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 4);.void *sqlite
215a0 33 44 62 52 65 61 6c 6c 6f 63 28 73 71 6c 69 74 3DbRealloc(sqlit
215b0 65 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 e3 *, void *, u6
215c0 34 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4);.void sqlite3
215d0 44 62 46 72 65 65 28 73 71 6c 69 74 65 33 2a 2c DbFree(sqlite3*,
215e0 20 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c void*);.int sql
215f0 69 74 65 33 4d 61 6c 6c 6f 63 53 69 7a 65 28 76 ite3MallocSize(v
21600 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 oid*);.int sqlit
21610 65 33 44 62 4d 61 6c 6c 6f 63 53 69 7a 65 28 73 e3DbMallocSize(s
21620 71 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b qlite3*, void*);
21630 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 53 63 .void *sqlite3Sc
21640 72 61 74 63 68 4d 61 6c 6c 6f 63 28 69 6e 74 29 ratchMalloc(int)
21650 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 ;.void sqlite3Sc
21660 72 61 74 63 68 46 72 65 65 28 76 6f 69 64 2a 29 ratchFree(void*)
21670 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 50 ;.void *sqlite3P
21680 61 67 65 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a ageMalloc(int);.
21690 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 void sqlite3Page
216a0 46 72 65 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 Free(void*);.voi
216b0 64 20 73 71 6c 69 74 65 33 4d 65 6d 53 65 74 44 d sqlite3MemSetD
216c0 65 66 61 75 6c 74 28 76 6f 69 64 29 3b 0a 23 69 efault(void);.#i
216d0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
216e0 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 76 T_BUILTIN_TEST.v
216f0 6f 69 64 20 73 71 6c 69 74 65 33 42 65 6e 69 67 oid sqlite3Benig
21700 6e 4d 61 6c 6c 6f 63 48 6f 6f 6b 73 28 76 6f 69 nMallocHooks(voi
21710 64 20 28 2a 29 28 76 6f 69 64 29 2c 20 76 6f 69 d (*)(void), voi
21720 64 20 28 2a 29 28 76 6f 69 64 29 29 3b 0a 23 65 d (*)(void));.#e
21730 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 ndif.int sqlite3
21740 48 65 61 70 4e 65 61 72 6c 79 46 75 6c 6c 28 76 HeapNearlyFull(v
21750 6f 69 64 29 3b 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 20 oid);../*.** On
21760 73 79 73 74 65 6d 73 20 77 69 74 68 20 61 6d 70 systems with amp
21770 6c 65 20 73 74 61 63 6b 20 73 70 61 63 65 20 61 le stack space a
21780 6e 64 20 74 68 61 74 20 73 75 70 70 6f 72 74 20 nd that support
21790 61 6c 6c 6f 63 61 28 29 2c 20 6d 61 6b 65 0a 2a alloca(), make.*
217a0 2a 20 75 73 65 20 6f 66 20 61 6c 6c 6f 63 61 28 * use of alloca(
217b0 29 20 74 6f 20 6f 62 74 61 69 6e 20 73 70 61 63 ) to obtain spac
217c0 65 20 66 6f 72 20 6c 61 72 67 65 20 61 75 74 6f e for large auto
217d0 6d 61 74 69 63 20 6f 62 6a 65 63 74 73 2e 20 20 matic objects.
217e0 42 79 20 64 65 66 61 75 6c 74 2c 0a 2a 2a 20 6f By default,.** o
217f0 62 74 61 69 6e 20 73 70 61 63 65 20 66 72 6f 6d btain space from
21800 20 6d 61 6c 6c 6f 63 28 29 2e 0a 2a 2a 0a 2a 2a malloc()..**.**
21810 20 54 68 65 20 61 6c 6c 6f 63 61 28 29 20 72 6f The alloca() ro
21820 75 74 69 6e 65 20 6e 65 76 65 72 20 72 65 74 75 utine never retu
21830 72 6e 73 20 4e 55 4c 4c 2e 20 20 54 68 69 73 20 rns NULL. This
21840 77 69 6c 6c 20 63 61 75 73 65 20 63 6f 64 65 20 will cause code
21850 70 61 74 68 73 0a 2a 2a 20 74 68 61 74 20 64 65 paths.** that de
21860 61 6c 20 77 69 74 68 20 73 71 6c 69 74 65 33 53 al with sqlite3S
21870 74 61 63 6b 41 6c 6c 6f 63 28 29 20 66 61 69 6c tackAlloc() fail
21880 75 72 65 73 20 74 6f 20 62 65 20 75 6e 72 65 61 ures to be unrea
21890 63 68 61 62 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 chable..*/.#ifde
218a0 66 20 53 51 4c 49 54 45 5f 55 53 45 5f 41 4c 4c f SQLITE_USE_ALL
218b0 4f 43 41 0a 23 20 64 65 66 69 6e 65 20 73 71 6c OCA.# define sql
218c0 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 52 61 ite3StackAllocRa
218d0 77 28 44 2c 4e 29 20 20 20 61 6c 6c 6f 63 61 28 w(D,N) alloca(
218e0 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 N).# define sqli
218f0 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 5a 65 72 te3StackAllocZer
21900 6f 28 44 2c 4e 29 20 20 6d 65 6d 73 65 74 28 61 o(D,N) memset(a
21910 6c 6c 6f 63 61 28 4e 29 2c 20 30 2c 20 4e 29 0a lloca(N), 0, N).
21920 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
21930 53 74 61 63 6b 46 72 65 65 28 44 2c 50 29 20 20 StackFree(D,P)
21940 20 20 20 20 20 0a 23 65 6c 73 65 0a 23 20 64 65 .#else.# de
21950 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
21960 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 kAllocRaw(D,N)
21970 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 sqlite3DbMalloc
21980 52 61 77 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e Raw(D,N).# defin
21990 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c e sqlite3StackAl
219a0 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 73 71 locZero(D,N) sq
219b0 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 lite3DbMallocZer
219c0 6f 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 o(D,N).# define
219d0 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 65 sqlite3StackFree
219e0 28 44 2c 50 29 20 20 20 20 20 20 20 73 71 6c 69 (D,P) sqli
219f0 74 65 33 44 62 46 72 65 65 28 44 2c 50 29 0a 23 te3DbFree(D,P).#
21a00 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
21a10 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 LITE_ENABLE_MEMS
21a20 59 53 33 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 YS3.const sqlite
21a30 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 3_mem_methods *s
21a40 71 6c 69 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 qlite3MemGetMems
21a50 79 73 33 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 ys3(void);.#endi
21a60 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f f.#ifdef SQLITE_
21a70 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 35 0a 63 ENABLE_MEMSYS5.c
21a80 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 65 6d onst sqlite3_mem
21a90 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 74 65 _methods *sqlite
21aa0 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 35 28 76 3MemGetMemsys5(v
21ab0 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 23 oid);.#endif...#
21ac0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 55 ifndef SQLITE_MU
21ad0 54 45 58 5f 4f 4d 49 54 0a 20 20 73 71 6c 69 74 TEX_OMIT. sqlit
21ae0 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 e3_mutex_methods
21af0 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 33 44 const *sqlite3D
21b00 65 66 61 75 6c 74 4d 75 74 65 78 28 76 6f 69 64 efaultMutex(void
21b10 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 );. sqlite3_mut
21b20 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e 73 74 ex_methods const
21b30 20 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 4d 75 74 *sqlite3NoopMut
21b40 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 6c 69 ex(void);. sqli
21b50 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 te3_mutex *sqlit
21b60 65 33 4d 75 74 65 78 41 6c 6c 6f 63 28 69 6e 74 e3MutexAlloc(int
21b70 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
21b80 4d 75 74 65 78 49 6e 69 74 28 76 6f 69 64 29 3b MutexInit(void);
21b90 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 . int sqlite3Mu
21ba0 74 65 78 45 6e 64 28 76 6f 69 64 29 3b 0a 23 65 texEnd(void);.#e
21bb0 6e 64 69 66 0a 0a 73 71 6c 69 74 65 33 5f 69 6e ndif..sqlite3_in
21bc0 74 36 34 20 73 71 6c 69 74 65 33 53 74 61 74 75 t64 sqlite3Statu
21bd0 73 56 61 6c 75 65 28 69 6e 74 29 3b 0a 76 6f 69 sValue(int);.voi
21be0 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 55 d sqlite3StatusU
21bf0 70 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 p(int, int);.voi
21c00 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 44 d sqlite3StatusD
21c10 6f 77 6e 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 own(int, int);.v
21c20 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 oid sqlite3Statu
21c30 73 53 65 74 28 69 6e 74 2c 20 69 6e 74 29 3b 0a sSet(int, int);.
21c40 0a 2f 2a 20 41 63 63 65 73 73 20 74 6f 20 6d 75 ./* Access to mu
21c50 74 65 78 65 73 20 75 73 65 64 20 62 79 20 73 71 texes used by sq
21c60 6c 69 74 65 33 5f 73 74 61 74 75 73 28 29 20 2a lite3_status() *
21c70 2f 0a 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 /.sqlite3_mutex
21c80 2a 73 71 6c 69 74 65 33 50 63 61 63 68 65 31 4d *sqlite3Pcache1M
21c90 75 74 65 78 28 76 6f 69 64 29 3b 0a 73 71 6c 69 utex(void);.sqli
21ca0 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 te3_mutex *sqlit
21cb0 65 33 4d 61 6c 6c 6f 63 4d 75 74 65 78 28 76 6f e3MallocMutex(vo
21cc0 69 64 29 3b 0a 0a 23 69 66 6e 64 65 66 20 53 51 id);..#ifndef SQ
21cd0 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 LITE_OMIT_FLOATI
21ce0 4e 47 5f 50 4f 49 4e 54 0a 20 20 69 6e 74 20 73 NG_POINT. int s
21cf0 71 6c 69 74 65 33 49 73 4e 61 4e 28 64 6f 75 62 qlite3IsNaN(doub
21d00 6c 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 le);.#else.# def
21d10 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 61 4e ine sqlite3IsNaN
21d20 28 58 29 20 20 30 0a 23 65 6e 64 69 66 0a 0a 2f (X) 0.#endif../
21d30 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
21d40 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
21d50 67 20 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 g structure hold
21d60 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 s information ab
21d70 6f 75 74 20 53 51 4c 0a 2a 2a 20 66 75 6e 63 74 out SQL.** funct
21d80 69 6f 6e 73 20 61 72 67 75 6d 65 6e 74 73 20 74 ions arguments t
21d90 68 61 74 20 61 72 65 20 74 68 65 20 70 61 72 61 hat are the para
21da0 6d 65 74 65 72 73 20 74 6f 20 74 68 65 20 70 72 meters to the pr
21db0 69 6e 74 66 28 29 20 66 75 6e 63 74 69 6f 6e 2e intf() function.
21dc0 0a 2a 2f 0a 73 74 72 75 63 74 20 50 72 69 6e 74 .*/.struct Print
21dd0 66 41 72 67 75 6d 65 6e 74 73 20 7b 0a 20 20 69 fArguments {. i
21de0 6e 74 20 6e 41 72 67 3b 20 20 20 20 20 20 20 20 nt nArg;
21df0 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 74 61 6c /* Total
21e00 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d number of argum
21e10 65 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 55 ents */. int nU
21e20 73 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 sed;
21e30 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
21e40 61 72 67 75 6d 65 6e 74 73 20 75 73 65 64 20 73 arguments used s
21e50 6f 20 66 61 72 20 2a 2f 0a 20 20 73 71 6c 69 74 o far */. sqlit
21e60 65 33 5f 76 61 6c 75 65 20 2a 2a 61 70 41 72 67 e3_value **apArg
21e70 3b 20 20 20 2f 2a 20 54 68 65 20 61 72 67 75 6d ; /* The argum
21e80 65 6e 74 20 76 61 6c 75 65 73 20 2a 2f 0a 7d 3b ent values */.};
21e90 0a 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 ..#define SQLITE
21ea0 5f 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 4c _PRINTF_INTERNAL
21eb0 20 30 78 30 31 0a 23 64 65 66 69 6e 65 20 53 51 0x01.#define SQ
21ec0 4c 49 54 45 5f 50 52 49 4e 54 46 5f 53 51 4c 46 LITE_PRINTF_SQLF
21ed0 55 4e 43 20 20 30 78 30 32 0a 76 6f 69 64 20 73 UNC 0x02.void s
21ee0 71 6c 69 74 65 33 56 58 50 72 69 6e 74 66 28 53 qlite3VXPrintf(S
21ef0 74 72 41 63 63 75 6d 2a 2c 20 75 33 32 2c 20 63 trAccum*, u32, c
21f00 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 5f 6c onst char*, va_l
21f10 69 73 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ist);.void sqlit
21f20 65 33 58 50 72 69 6e 74 66 28 53 74 72 41 63 63 e3XPrintf(StrAcc
21f30 75 6d 2a 2c 20 75 33 32 2c 20 63 6f 6e 73 74 20 um*, u32, const
21f40 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 61 char*, ...);.cha
21f50 72 20 2a 73 71 6c 69 74 65 33 4d 50 72 69 6e 74 r *sqlite3MPrint
21f60 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 f(sqlite3*,const
21f70 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 char*, ...);.ch
21f80 61 72 20 2a 73 71 6c 69 74 65 33 56 4d 50 72 69 ar *sqlite3VMPri
21f90 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ntf(sqlite3*,con
21fa0 73 74 20 63 68 61 72 2a 2c 20 76 61 5f 6c 69 73 st char*, va_lis
21fb0 74 29 3b 0a 23 69 66 20 64 65 66 69 6e 65 64 28 t);.#if defined(
21fc0 53 51 4c 49 54 45 5f 44 45 42 55 47 29 20 7c 7c SQLITE_DEBUG) ||
21fd0 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
21fe0 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 29 0a 20 HAVE_OS_TRACE).
21ff0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 62 void sqlite3Deb
22000 75 67 50 72 69 6e 74 66 28 63 6f 6e 73 74 20 63 ugPrintf(const c
22010 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 23 65 6e 64 har*, ...);.#end
22020 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 if.#if defined(S
22030 51 4c 49 54 45 5f 54 45 53 54 29 0a 20 20 76 6f QLITE_TEST). vo
22040 69 64 20 2a 73 71 6c 69 74 65 33 54 65 73 74 54 id *sqlite3TestT
22050 65 78 74 54 6f 50 74 72 28 63 6f 6e 73 74 20 63 extToPtr(const c
22060 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 har*);.#endif..#
22070 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
22080 45 5f 44 45 42 55 47 29 0a 20 20 76 6f 69 64 20 E_DEBUG). void
22090 73 71 6c 69 74 65 33 54 72 65 65 56 69 65 77 45 sqlite3TreeViewE
220a0 78 70 72 28 54 72 65 65 56 69 65 77 2a 2c 20 63 xpr(TreeView*, c
220b0 6f 6e 73 74 20 45 78 70 72 2a 2c 20 75 38 29 3b onst Expr*, u8);
220c0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 . void sqlite3T
220d0 72 65 65 56 69 65 77 45 78 70 72 4c 69 73 74 28 reeViewExprList(
220e0 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 TreeView*, const
220f0 20 45 78 70 72 4c 69 73 74 2a 2c 20 75 38 2c 20 ExprList*, u8,
22100 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 const char*);.
22110 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 void sqlite3Tree
22120 56 69 65 77 53 65 6c 65 63 74 28 54 72 65 65 56 ViewSelect(TreeV
22130 69 65 77 2a 2c 20 63 6f 6e 73 74 20 53 65 6c 65 iew*, const Sele
22140 63 74 2a 2c 20 75 38 29 3b 0a 23 65 6e 64 69 66 ct*, u8);.#endif
22150 0a 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 ...void sqlite3S
22160 65 74 53 74 72 69 6e 67 28 63 68 61 72 20 2a 2a etString(char **
22170 2c 20 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 , sqlite3*, cons
22180 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 t char*);.void s
22190 71 6c 69 74 65 33 45 72 72 6f 72 4d 73 67 28 50 qlite3ErrorMsg(P
221a0 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 arse*, const cha
221b0 72 2a 2c 20 2e 2e 2e 29 3b 0a 69 6e 74 20 73 71 r*, ...);.int sq
221c0 6c 69 74 65 33 44 65 71 75 6f 74 65 28 63 68 61 lite3Dequote(cha
221d0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
221e0 4b 65 79 77 6f 72 64 43 6f 64 65 28 63 6f 6e 73 KeywordCode(cons
221f0 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a t unsigned char*
22200 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
22210 74 65 33 52 75 6e 50 61 72 73 65 72 28 50 61 72 te3RunParser(Par
22220 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a se*, const char*
22230 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 , char **);.void
22240 20 73 71 6c 69 74 65 33 46 69 6e 69 73 68 43 6f sqlite3FinishCo
22250 64 69 6e 67 28 50 61 72 73 65 2a 29 3b 0a 69 6e ding(Parse*);.in
22260 74 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d 70 t sqlite3GetTemp
22270 52 65 67 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 Reg(Parse*);.voi
22280 64 20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 65 d sqlite3Release
22290 54 65 6d 70 52 65 67 28 50 61 72 73 65 2a 2c 69 TempReg(Parse*,i
222a0 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
222b0 47 65 74 54 65 6d 70 52 61 6e 67 65 28 50 61 72 GetTempRange(Par
222c0 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 se*,int);.void s
222d0 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d qlite3ReleaseTem
222e0 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e pRange(Parse*,in
222f0 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c t,int);.void sql
22300 69 74 65 33 43 6c 65 61 72 54 65 6d 70 52 65 67 ite3ClearTempReg
22310 43 61 63 68 65 28 50 61 72 73 65 2a 29 3b 0a 45 Cache(Parse*);.E
22320 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 xpr *sqlite3Expr
22330 41 6c 6c 6f 63 28 73 71 6c 69 74 65 33 2a 2c 69 Alloc(sqlite3*,i
22340 6e 74 2c 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c nt,const Token*,
22350 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 int);.Expr *sqli
22360 74 65 33 45 78 70 72 28 73 71 6c 69 74 65 33 2a te3Expr(sqlite3*
22370 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
22380 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
22390 78 70 72 41 74 74 61 63 68 53 75 62 74 72 65 65 xprAttachSubtree
223a0 73 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a s(sqlite3*,Expr*
223b0 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 3b 0a 45 ,Expr*,Expr*);.E
223c0 78 70 72 20 2a 73 71 6c 69 74 65 33 50 45 78 70 xpr *sqlite3PExp
223d0 72 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 45 r(Parse*, int, E
223e0 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 63 6f 6e xpr*, Expr*, con
223f0 73 74 20 54 6f 6b 65 6e 2a 29 3b 0a 45 78 70 72 st Token*);.Expr
22400 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 6e 64 *sqlite3ExprAnd
22410 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c (sqlite3*,Expr*,
22420 20 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 Expr*);.Expr *s
22430 71 6c 69 74 65 33 45 78 70 72 46 75 6e 63 74 69 qlite3ExprFuncti
22440 6f 6e 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 on(Parse*,ExprLi
22450 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f st*, Token*);.vo
22460 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 41 73 id sqlite3ExprAs
22470 73 69 67 6e 56 61 72 4e 75 6d 62 65 72 28 50 61 signVarNumber(Pa
22480 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f rse*, Expr*);.vo
22490 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 44 65 id sqlite3ExprDe
224a0 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 45 lete(sqlite3*, E
224b0 78 70 72 2a 29 3b 0a 45 78 70 72 4c 69 73 74 20 xpr*);.ExprList
224c0 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 *sqlite3ExprList
224d0 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c 45 78 Append(Parse*,Ex
224e0 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 29 3b 0a prList*,Expr*);.
224f0 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
22500 4c 69 73 74 53 65 74 4e 61 6d 65 28 50 61 72 73 ListSetName(Pars
22510 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 54 6f 6b e*,ExprList*,Tok
22520 65 6e 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 en*,int);.void s
22530 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 qlite3ExprListSe
22540 74 53 70 61 6e 28 50 61 72 73 65 2a 2c 45 78 70 tSpan(Parse*,Exp
22550 72 4c 69 73 74 2a 2c 45 78 70 72 53 70 61 6e 2a rList*,ExprSpan*
22560 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
22570 78 70 72 4c 69 73 74 44 65 6c 65 74 65 28 73 71 xprListDelete(sq
22580 6c 69 74 65 33 2a 2c 20 45 78 70 72 4c 69 73 74 lite3*, ExprList
22590 2a 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 45 *);.u32 sqlite3E
225a0 78 70 72 4c 69 73 74 46 6c 61 67 73 28 63 6f 6e xprListFlags(con
225b0 73 74 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 69 st ExprList*);.i
225c0 6e 74 20 73 71 6c 69 74 65 33 49 6e 69 74 28 73 nt sqlite3Init(s
225d0 71 6c 69 74 65 33 2a 2c 20 63 68 61 72 2a 2a 29 qlite3*, char**)
225e0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 69 ;.int sqlite3Ini
225f0 74 43 61 6c 6c 62 61 63 6b 28 76 6f 69 64 2a 2c tCallback(void*,
22600 20 69 6e 74 2c 20 63 68 61 72 2a 2a 2c 20 63 68 int, char**, ch
22610 61 72 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ar**);.void sqli
22620 74 65 33 50 72 61 67 6d 61 28 50 61 72 73 65 2a te3Pragma(Parse*
22630 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 ,Token*,Token*,T
22640 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 oken*,int);.void
22650 20 73 71 6c 69 74 65 33 52 65 73 65 74 41 6c 6c sqlite3ResetAll
22660 53 63 68 65 6d 61 73 4f 66 43 6f 6e 6e 65 63 74 SchemasOfConnect
22670 69 6f 6e 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 ion(sqlite3*);.v
22680 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 65 74 oid sqlite3Reset
22690 4f 6e 65 53 63 68 65 6d 61 28 73 71 6c 69 74 65 OneSchema(sqlite
226a0 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 3*,int);.void sq
226b0 6c 69 74 65 33 43 6f 6c 6c 61 70 73 65 44 61 74 lite3CollapseDat
226c0 61 62 61 73 65 41 72 72 61 79 28 73 71 6c 69 74 abaseArray(sqlit
226d0 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 e3*);.void sqlit
226e0 65 33 42 65 67 69 6e 50 61 72 73 65 28 50 61 72 e3BeginParse(Par
226f0 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 se*,int);.void s
22700 71 6c 69 74 65 33 43 6f 6d 6d 69 74 49 6e 74 65 qlite3CommitInte
22710 72 6e 61 6c 43 68 61 6e 67 65 73 28 73 71 6c 69 rnalChanges(sqli
22720 74 65 33 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 te3*);.Table *sq
22730 6c 69 74 65 33 52 65 73 75 6c 74 53 65 74 4f 66 lite3ResultSetOf
22740 53 65 6c 65 63 74 28 50 61 72 73 65 2a 2c 53 65 Select(Parse*,Se
22750 6c 65 63 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c lect*);.void sql
22760 69 74 65 33 4f 70 65 6e 4d 61 73 74 65 72 54 61 ite3OpenMasterTa
22770 62 6c 65 28 50 61 72 73 65 20 2a 2c 20 69 6e 74 ble(Parse *, int
22780 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 74 65 );.Index *sqlite
22790 33 50 72 69 6d 61 72 79 4b 65 79 49 6e 64 65 78 3PrimaryKeyIndex
227a0 28 54 61 62 6c 65 2a 29 3b 0a 69 31 36 20 73 71 (Table*);.i16 sq
227b0 6c 69 74 65 33 43 6f 6c 75 6d 6e 4f 66 49 6e 64 lite3ColumnOfInd
227c0 65 78 28 49 6e 64 65 78 2a 2c 20 69 31 36 29 3b ex(Index*, i16);
227d0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 .void sqlite3Sta
227e0 72 74 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 54 rtTable(Parse*,T
227f0 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 oken*,Token*,int
22800 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a 76 ,int,int,int);.v
22810 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 43 6f oid sqlite3AddCo
22820 6c 75 6d 6e 28 50 61 72 73 65 2a 2c 54 6f 6b 65 lumn(Parse*,Toke
22830 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 n*);.void sqlite
22840 33 41 64 64 4e 6f 74 4e 75 6c 6c 28 50 61 72 73 3AddNotNull(Pars
22850 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 e*, int);.void s
22860 71 6c 69 74 65 33 41 64 64 50 72 69 6d 61 72 79 qlite3AddPrimary
22870 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Key(Parse*, Expr
22880 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c List*, int, int,
22890 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
228a0 74 65 33 41 64 64 43 68 65 63 6b 43 6f 6e 73 74 te3AddCheckConst
228b0 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 45 78 raint(Parse*, Ex
228c0 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 pr*);.void sqlit
228d0 65 33 41 64 64 43 6f 6c 75 6d 6e 54 79 70 65 28 e3AddColumnType(
228e0 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a Parse*,Token*);.
228f0 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 44 void sqlite3AddD
22900 65 66 61 75 6c 74 56 61 6c 75 65 28 50 61 72 73 efaultValue(Pars
22910 65 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 e*,ExprSpan*);.v
22920 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 43 6f oid sqlite3AddCo
22930 6c 6c 61 74 65 54 79 70 65 28 50 61 72 73 65 2a llateType(Parse*
22940 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
22950 73 71 6c 69 74 65 33 45 6e 64 54 61 62 6c 65 28 sqlite3EndTable(
22960 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f Parse*,Token*,To
22970 6b 65 6e 2a 2c 75 38 2c 53 65 6c 65 63 74 2a 29 ken*,u8,Select*)
22980 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 72 ;.int sqlite3Par
22990 73 65 55 72 69 28 63 6f 6e 73 74 20 63 68 61 72 seUri(const char
229a0 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 6e *,const char*,un
229b0 73 69 67 6e 65 64 20 69 6e 74 2a 2c 0a 20 20 20 signed int*,.
229c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
229d0 20 73 71 6c 69 74 65 33 5f 76 66 73 2a 2a 2c 63 sqlite3_vfs**,c
229e0 68 61 72 2a 2a 2c 63 68 61 72 20 2a 2a 29 3b 0a har**,char **);.
229f0 42 74 72 65 65 20 2a 73 71 6c 69 74 65 33 44 62 Btree *sqlite3Db
22a00 4e 61 6d 65 54 6f 42 74 72 65 65 28 73 71 6c 69 NameToBtree(sqli
22a10 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
22a20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f );.int sqlite3Co
22a30 64 65 4f 6e 63 65 28 50 61 72 73 65 20 2a 29 3b deOnce(Parse *);
22a40 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f ..#ifdef SQLITE_
22a50 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 OMIT_BUILTIN_TES
22a60 54 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 T.# define sqlit
22a70 65 33 46 61 75 6c 74 53 69 6d 28 58 29 20 53 51 e3FaultSim(X) SQ
22a80 4c 49 54 45 5f 4f 4b 0a 23 65 6c 73 65 0a 20 20 LITE_OK.#else.
22a90 69 6e 74 20 73 71 6c 69 74 65 33 46 61 75 6c 74 int sqlite3Fault
22aa0 53 69 6d 28 69 6e 74 29 3b 0a 23 65 6e 64 69 66 Sim(int);.#endif
22ab0 0a 0a 42 69 74 76 65 63 20 2a 73 71 6c 69 74 65 ..Bitvec *sqlite
22ac0 33 42 69 74 76 65 63 43 72 65 61 74 65 28 75 33 3BitvecCreate(u3
22ad0 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 2);.int sqlite3B
22ae0 69 74 76 65 63 54 65 73 74 28 42 69 74 76 65 63 itvecTest(Bitvec
22af0 2a 2c 20 75 33 32 29 3b 0a 69 6e 74 20 73 71 6c *, u32);.int sql
22b00 69 74 65 33 42 69 74 76 65 63 54 65 73 74 4e 6f ite3BitvecTestNo
22b10 74 4e 75 6c 6c 28 42 69 74 76 65 63 2a 2c 20 75 tNull(Bitvec*, u
22b20 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 32);.int sqlite3
22b30 42 69 74 76 65 63 53 65 74 28 42 69 74 76 65 63 BitvecSet(Bitvec
22b40 2a 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 71 *, u32);.void sq
22b50 6c 69 74 65 33 42 69 74 76 65 63 43 6c 65 61 72 lite3BitvecClear
22b60 28 42 69 74 76 65 63 2a 2c 20 75 33 32 2c 20 76 (Bitvec*, u32, v
22b70 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 oid*);.void sqli
22b80 74 65 33 42 69 74 76 65 63 44 65 73 74 72 6f 79 te3BitvecDestroy
22b90 28 42 69 74 76 65 63 2a 29 3b 0a 75 33 32 20 73 (Bitvec*);.u32 s
22ba0 71 6c 69 74 65 33 42 69 74 76 65 63 53 69 7a 65 qlite3BitvecSize
22bb0 28 42 69 74 76 65 63 2a 29 3b 0a 23 69 66 6e 64 (Bitvec*);.#ifnd
22bc0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 ef SQLITE_OMIT_B
22bd0 55 49 4c 54 49 4e 5f 54 45 53 54 0a 69 6e 74 20 UILTIN_TEST.int
22be0 73 71 6c 69 74 65 33 42 69 74 76 65 63 42 75 69 sqlite3BitvecBui
22bf0 6c 74 69 6e 54 65 73 74 28 69 6e 74 2c 69 6e 74 ltinTest(int,int
22c00 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 52 6f 77 53 *);.#endif..RowS
22c10 65 74 20 2a 73 71 6c 69 74 65 33 52 6f 77 53 65 et *sqlite3RowSe
22c20 74 49 6e 69 74 28 73 71 6c 69 74 65 33 2a 2c 20 tInit(sqlite3*,
22c30 76 6f 69 64 2a 2c 20 75 6e 73 69 67 6e 65 64 20 void*, unsigned
22c40 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22c50 65 33 52 6f 77 53 65 74 43 6c 65 61 72 28 52 6f e3RowSetClear(Ro
22c60 77 53 65 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c wSet*);.void sql
22c70 69 74 65 33 52 6f 77 53 65 74 49 6e 73 65 72 74 ite3RowSetInsert
22c80 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 29 3b 0a (RowSet*, i64);.
22c90 69 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 53 65 int sqlite3RowSe
22ca0 74 54 65 73 74 28 52 6f 77 53 65 74 2a 2c 20 69 tTest(RowSet*, i
22cb0 6e 74 20 69 42 61 74 63 68 2c 20 69 36 34 29 3b nt iBatch, i64);
22cc0 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 53 .int sqlite3RowS
22cd0 65 74 4e 65 78 74 28 52 6f 77 53 65 74 2a 2c 20 etNext(RowSet*,
22ce0 69 36 34 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c i64*);..void sql
22cf0 69 74 65 33 43 72 65 61 74 65 56 69 65 77 28 50 ite3CreateView(P
22d00 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b arse*,Token*,Tok
22d10 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 53 65 6c 65 63 en*,Token*,Selec
22d20 74 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 t*,int,int);..#i
22d30 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 f !defined(SQLIT
22d40 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 7c 7c 20 E_OMIT_VIEW) ||
22d50 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
22d60 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
22d70 45 29 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 E). int sqlite3
22d80 56 69 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d ViewGetColumnNam
22d90 65 73 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a es(Parse*,Table*
22da0 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e );.#else.# defin
22db0 65 20 73 71 6c 69 74 65 33 56 69 65 77 47 65 74 e sqlite3ViewGet
22dc0 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 ColumnNames(A,B)
22dd0 20 30 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 53 0.#endif..#if S
22de0 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 QLITE_MAX_ATTACH
22df0 45 44 3e 33 30 0a 20 20 69 6e 74 20 73 71 6c 69 ED>30. int sqli
22e00 74 65 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f te3DbMaskAllZero
22e10 28 79 44 62 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 (yDbMask);.#endi
22e20 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 f.void sqlite3Dr
22e30 6f 70 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 opTable(Parse*,
22e40 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 SrcList*, int, i
22e50 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22e60 33 43 6f 64 65 44 72 6f 70 54 61 62 6c 65 28 50 3CodeDropTable(P
22e70 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 arse*, Table*, i
22e80 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
22e90 71 6c 69 74 65 33 44 65 6c 65 74 65 54 61 62 6c qlite3DeleteTabl
22ea0 65 28 73 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c e(sqlite3*, Tabl
22eb0 65 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c e*);.#ifndef SQL
22ec0 49 54 45 5f 4f 4d 49 54 5f 41 55 54 4f 49 4e 43 ITE_OMIT_AUTOINC
22ed0 52 45 4d 45 4e 54 0a 20 20 76 6f 69 64 20 73 71 REMENT. void sq
22ee0 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 lite3Autoincreme
22ef0 6e 74 42 65 67 69 6e 28 50 61 72 73 65 20 2a 70 ntBegin(Parse *p
22f00 50 61 72 73 65 29 3b 0a 20 20 76 6f 69 64 20 73 Parse);. void s
22f10 71 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d qlite3Autoincrem
22f20 65 6e 74 45 6e 64 28 50 61 72 73 65 20 2a 70 50 entEnd(Parse *pP
22f30 61 72 73 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 arse);.#else.# d
22f40 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 efine sqlite3Aut
22f50 6f 69 6e 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 oincrementBegin(
22f60 58 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 X).# define sqli
22f70 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 te3Autoincrement
22f80 45 6e 64 28 58 29 0a 23 65 6e 64 69 66 0a 76 6f End(X).#endif.vo
22f90 69 64 20 73 71 6c 69 74 65 33 49 6e 73 65 72 74 id sqlite3Insert
22fa0 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
22fb0 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 49 64 4c 69 *, Select*, IdLi
22fc0 73 74 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 st*, int);.void
22fd0 2a 73 71 6c 69 74 65 33 41 72 72 61 79 41 6c 6c *sqlite3ArrayAll
22fe0 6f 63 61 74 65 28 73 71 6c 69 74 65 33 2a 2c 76 ocate(sqlite3*,v
22ff0 6f 69 64 2a 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e oid*,int,int*,in
23000 74 2a 29 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c t*);.IdList *sql
23010 69 74 65 33 49 64 4c 69 73 74 41 70 70 65 6e 64 ite3IdListAppend
23020 28 73 71 6c 69 74 65 33 2a 2c 20 49 64 4c 69 73 (sqlite3*, IdLis
23030 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 t*, Token*);.int
23040 20 73 71 6c 69 74 65 33 49 64 4c 69 73 74 49 6e sqlite3IdListIn
23050 64 65 78 28 49 64 4c 69 73 74 2a 2c 63 6f 6e 73 dex(IdList*,cons
23060 74 20 63 68 61 72 2a 29 3b 0a 53 72 63 4c 69 73 t char*);.SrcLis
23070 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 t *sqlite3SrcLis
23080 74 45 6e 6c 61 72 67 65 28 73 71 6c 69 74 65 33 tEnlarge(sqlite3
23090 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 *, SrcList*, int
230a0 2c 20 69 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 , int);.SrcList
230b0 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 41 *sqlite3SrcListA
230c0 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 ppend(sqlite3*,
230d0 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a SrcList*, Token*
230e0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 53 72 63 4c 69 , Token*);.SrcLi
230f0 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 st *sqlite3SrcLi
23100 73 74 41 70 70 65 6e 64 46 72 6f 6d 54 65 72 6d stAppendFromTerm
23110 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
23120 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e *, Token*, Token
23130 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 *,.
23140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23150 20 20 20 20 20 20 20 20 20 54 6f 6b 65 6e 2a 2c Token*,
23160 20 53 65 6c 65 63 74 2a 2c 20 45 78 70 72 2a 2c Select*, Expr*,
23170 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 IdList*);.void
23180 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 49 6e sqlite3SrcListIn
23190 64 65 78 65 64 42 79 28 50 61 72 73 65 20 2a 2c dexedBy(Parse *,
231a0 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 6f 6b 65 SrcList *, Toke
231b0 6e 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 n *);.int sqlite
231c0 33 49 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 3IndexedByLookup
231d0 28 50 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 (Parse *, struct
231e0 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 SrcList_item *)
231f0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 ;.void sqlite3Sr
23200 63 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 cListShiftJoinTy
23210 70 65 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f pe(SrcList*);.vo
23220 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 id sqlite3SrcLis
23230 74 41 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 tAssignCursors(P
23240 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 arse*, SrcList*)
23250 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 ;.void sqlite3Id
23260 4c 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 ListDelete(sqlit
23270 65 33 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 e3*, IdList*);.v
23280 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 oid sqlite3SrcLi
23290 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
232a0 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e *, SrcList*);.In
232b0 64 65 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f dex *sqlite3Allo
232c0 63 61 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 cateIndexObject(
232d0 73 71 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 sqlite3*,i16,int
232e0 2c 63 68 61 72 2a 2a 29 3b 0a 49 6e 64 65 78 20 ,char**);.Index
232f0 2a 73 71 6c 69 74 65 33 43 72 65 61 74 65 49 6e *sqlite3CreateIn
23300 64 65 78 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e dex(Parse*,Token
23310 2a 2c 54 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 *,Token*,SrcList
23320 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c *,ExprList*,int,
23330 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 Token*,.
23340 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23350 20 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e Expr*, int, in
23360 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
23370 44 72 6f 70 49 6e 64 65 78 28 50 61 72 73 65 2a DropIndex(Parse*
23380 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 , SrcList*, int)
23390 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c ;.int sqlite3Sel
233a0 65 63 74 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 ect(Parse*, Sele
233b0 63 74 2a 2c 20 53 65 6c 65 63 74 44 65 73 74 2a ct*, SelectDest*
233c0 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 74 );.Select *sqlit
233d0 65 33 53 65 6c 65 63 74 4e 65 77 28 50 61 72 73 e3SelectNew(Pars
233e0 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 72 63 e*,ExprList*,Src
233f0 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 List*,Expr*,Expr
23400 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 List*,.
23410 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23420 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c Expr*,ExprList*,
23430 75 31 36 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 u16,Expr*,Expr*)
23440 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 ;.void sqlite3Se
23450 6c 65 63 74 44 65 6c 65 74 65 28 73 71 6c 69 74 lectDelete(sqlit
23460 65 33 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 54 e3*, Select*);.T
23470 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 53 72 63 able *sqlite3Src
23480 4c 69 73 74 4c 6f 6f 6b 75 70 28 50 61 72 73 65 ListLookup(Parse
23490 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e *, SrcList*);.in
234a0 74 20 73 71 6c 69 74 65 33 49 73 52 65 61 64 4f t sqlite3IsReadO
234b0 6e 6c 79 28 50 61 72 73 65 2a 2c 20 54 61 62 6c nly(Parse*, Tabl
234c0 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 e*, int);.void s
234d0 71 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 28 qlite3OpenTable(
234e0 50 61 72 73 65 2a 2c 20 69 6e 74 20 69 43 75 72 Parse*, int iCur
234f0 2c 20 69 6e 74 20 69 44 62 2c 20 54 61 62 6c 65 , int iDb, Table
23500 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 20 64 65 66 *, int);.#if def
23510 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
23520 4c 45 5f 55 50 44 41 54 45 5f 44 45 4c 45 54 45 LE_UPDATE_DELETE
23530 5f 4c 49 4d 49 54 29 20 26 26 20 21 64 65 66 69 _LIMIT) && !defi
23540 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ned(SQLITE_OMIT_
23550 53 55 42 51 55 45 52 59 29 0a 45 78 70 72 20 2a SUBQUERY).Expr *
23560 73 71 6c 69 74 65 33 4c 69 6d 69 74 57 68 65 72 sqlite3LimitWher
23570 65 28 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 e(Parse*,SrcList
23580 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 *,Expr*,ExprList
23590 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 63 68 *,Expr*,Expr*,ch
235a0 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 ar*);.#endif.voi
235b0 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 46 d sqlite3DeleteF
235c0 72 6f 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 4c rom(Parse*, SrcL
235d0 69 73 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f ist*, Expr*);.vo
235e0 69 64 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 id sqlite3Update
235f0 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
23600 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 *, ExprList*, Ex
23610 70 72 2a 2c 20 69 6e 74 29 3b 0a 57 68 65 72 65 pr*, int);.Where
23620 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 57 68 65 Info *sqlite3Whe
23630 72 65 42 65 67 69 6e 28 50 61 72 73 65 2a 2c 53 reBegin(Parse*,S
23640 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 rcList*,Expr*,Ex
23650 70 72 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 prList*,ExprList
23660 2a 2c 75 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 64 *,u16,int);.void
23670 20 73 71 6c 69 74 65 33 57 68 65 72 65 45 6e 64 sqlite3WhereEnd
23680 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 75 36 (WhereInfo*);.u6
23690 34 20 73 71 6c 69 74 65 33 57 68 65 72 65 4f 75 4 sqlite3WhereOu
236a0 74 70 75 74 52 6f 77 43 6f 75 6e 74 28 57 68 65 tputRowCount(Whe
236b0 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 reInfo*);.int sq
236c0 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 74 lite3WhereIsDist
236d0 69 6e 63 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 inct(WhereInfo*)
236e0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
236f0 72 65 49 73 4f 72 64 65 72 65 64 28 57 68 65 72 reIsOrdered(Wher
23700 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23710 69 74 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 ite3WhereIsSorte
23720 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 d(WhereInfo*);.i
23730 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 43 nt sqlite3WhereC
23740 6f 6e 74 69 6e 75 65 4c 61 62 65 6c 28 57 68 65 ontinueLabel(Whe
23750 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 reInfo*);.int sq
23760 6c 69 74 65 33 57 68 65 72 65 42 72 65 61 6b 4c lite3WhereBreakL
23770 61 62 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 abel(WhereInfo*)
23780 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
23790 72 65 4f 6b 4f 6e 65 50 61 73 73 28 57 68 65 72 reOkOnePass(Wher
237a0 65 49 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b 0a 69 eInfo*, int*);.i
237b0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
237c0 64 65 47 65 74 43 6f 6c 75 6d 6e 28 50 61 72 73 deGetColumn(Pars
237d0 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
237e0 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a int, int, u8);.
237f0 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
23800 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 4f 66 54 CodeGetColumnOfT
23810 61 62 6c 65 28 56 64 62 65 2a 2c 20 54 61 62 6c able(Vdbe*, Tabl
23820 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e e*, int, int, in
23830 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
23840 45 78 70 72 43 6f 64 65 4d 6f 76 65 28 50 61 72 ExprCodeMove(Par
23850 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 se*, int, int, i
23860 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
23870 33 45 78 70 72 43 61 63 68 65 53 74 6f 72 65 28 3ExprCacheStore(
23880 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 Parse*, int, int
23890 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
238a0 69 74 65 33 45 78 70 72 43 61 63 68 65 50 75 73 ite3ExprCachePus
238b0 68 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 h(Parse*);.void
238c0 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 sqlite3ExprCache
238d0 50 6f 70 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 Pop(Parse*);.voi
238e0 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 d sqlite3ExprCac
238f0 68 65 52 65 6d 6f 76 65 28 50 61 72 73 65 2a 2c heRemove(Parse*,
23900 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
23910 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 sqlite3ExprCach
23920 65 43 6c 65 61 72 28 50 61 72 73 65 2a 29 3b 0a eClear(Parse*);.
23930 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
23940 43 61 63 68 65 41 66 66 69 6e 69 74 79 43 68 61 CacheAffinityCha
23950 6e 67 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c nge(Parse*, int,
23960 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
23970 74 65 33 45 78 70 72 43 6f 64 65 28 50 61 72 73 te3ExprCode(Pars
23980 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b e*, Expr*, int);
23990 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
239a0 72 43 6f 64 65 46 61 63 74 6f 72 61 62 6c 65 28 rCodeFactorable(
239b0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
239c0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
239d0 33 45 78 70 72 43 6f 64 65 41 74 49 6e 69 74 28 3ExprCodeAtInit(
239e0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
239f0 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c nt, u8);.int sql
23a00 69 74 65 33 45 78 70 72 43 6f 64 65 54 65 6d 70 ite3ExprCodeTemp
23a10 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
23a20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int*);.int sqlit
23a30 65 33 45 78 70 72 43 6f 64 65 54 61 72 67 65 74 e3ExprCodeTarget
23a40 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
23a50 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
23a60 65 33 45 78 70 72 43 6f 64 65 41 6e 64 43 61 63 e3ExprCodeAndCac
23a70 68 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a he(Parse*, Expr*
23a80 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
23a90 74 65 33 45 78 70 72 43 6f 64 65 45 78 70 72 4c te3ExprCodeExprL
23aa0 69 73 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 ist(Parse*, Expr
23ab0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 75 38 29 3b List*, int, u8);
23ac0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
23ad0 45 43 45 4c 5f 44 55 50 20 20 20 20 20 20 30 78 ECEL_DUP 0x
23ae0 30 31 20 20 2f 2a 20 44 65 65 70 2c 20 6e 6f 74 01 /* Deep, not
23af0 20 73 68 61 6c 6c 6f 77 20 63 6f 70 69 65 73 20 shallow copies
23b00 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
23b10 45 5f 45 43 45 4c 5f 46 41 43 54 4f 52 20 20 20 E_ECEL_FACTOR
23b20 30 78 30 32 20 20 2f 2a 20 46 61 63 74 6f 72 20 0x02 /* Factor
23b30 6f 75 74 20 63 6f 6e 73 74 61 6e 74 20 74 65 72 out constant ter
23b40 6d 73 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 ms */.void sqlit
23b50 65 33 45 78 70 72 49 66 54 72 75 65 28 50 61 72 e3ExprIfTrue(Par
23b60 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c se*, Expr*, int,
23b70 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
23b80 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 28 50 te3ExprIfFalse(P
23b90 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
23ba0 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
23bb0 6c 69 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 lite3ExprIfFalse
23bc0 44 75 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Dup(Parse*, Expr
23bd0 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 54 61 *, int, int);.Ta
23be0 62 6c 65 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 ble *sqlite3Find
23bf0 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 63 Table(sqlite3*,c
23c00 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
23c10 74 20 63 68 61 72 2a 29 3b 0a 54 61 62 6c 65 20 t char*);.Table
23c20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 *sqlite3LocateTa
23c30 62 6c 65 28 50 61 72 73 65 2a 2c 69 6e 74 20 69 ble(Parse*,int i
23c40 73 56 69 65 77 2c 63 6f 6e 73 74 20 63 68 61 72 sView,const char
23c50 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
23c60 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 4c .Table *sqlite3L
23c70 6f 63 61 74 65 54 61 62 6c 65 49 74 65 6d 28 50 ocateTableItem(P
23c80 61 72 73 65 2a 2c 69 6e 74 20 69 73 56 69 65 77 arse*,int isView
23c90 2c 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f ,struct SrcList_
23ca0 69 74 65 6d 20 2a 29 3b 0a 49 6e 64 65 78 20 2a item *);.Index *
23cb0 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 64 65 78 sqlite3FindIndex
23cc0 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 (sqlite3*,const
23cd0 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
23ce0 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
23cf0 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 3UnlinkAndDelete
23d00 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 69 Table(sqlite3*,i
23d10 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b nt,const char*);
23d20 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c .void sqlite3Unl
23d30 69 6e 6b 41 6e 64 44 65 6c 65 74 65 49 6e 64 65 inkAndDeleteInde
23d40 78 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 x(sqlite3*,int,c
23d50 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 onst char*);.voi
23d60 64 20 73 71 6c 69 74 65 33 56 61 63 75 75 6d 28 d sqlite3Vacuum(
23d70 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c Parse*);.int sql
23d80 69 74 65 33 52 75 6e 56 61 63 75 75 6d 28 63 68 ite3RunVacuum(ch
23d90 61 72 2a 2a 2c 20 73 71 6c 69 74 65 33 2a 29 3b ar**, sqlite3*);
23da0 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4e 61 .char *sqlite3Na
23db0 6d 65 46 72 6f 6d 54 6f 6b 65 6e 28 73 71 6c 69 meFromToken(sqli
23dc0 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 te3*, Token*);.i
23dd0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
23de0 6d 70 61 72 65 28 45 78 70 72 2a 2c 20 45 78 70 mpare(Expr*, Exp
23df0 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 r*, int);.int sq
23e00 6c 69 74 65 33 45 78 70 72 4c 69 73 74 43 6f 6d lite3ExprListCom
23e10 70 61 72 65 28 45 78 70 72 4c 69 73 74 2a 2c 20 pare(ExprList*,
23e20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b ExprList*, int);
23e30 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
23e40 49 6d 70 6c 69 65 73 45 78 70 72 28 45 78 70 72 ImpliesExpr(Expr
23e50 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
23e60 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
23e70 41 6e 61 6c 79 7a 65 41 67 67 72 65 67 61 74 65 AnalyzeAggregate
23e80 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 s(NameContext*,
23e90 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
23ea0 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a 65 41 ite3ExprAnalyzeA
23eb0 67 67 4c 69 73 74 28 4e 61 6d 65 43 6f 6e 74 65 ggList(NameConte
23ec0 78 74 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b 0a xt*,ExprList*);.
23ed0 69 6e 74 20 73 71 6c 69 74 65 33 46 75 6e 63 74 int sqlite3Funct
23ee0 69 6f 6e 55 73 65 73 54 68 69 73 53 72 63 28 45 ionUsesThisSrc(E
23ef0 78 70 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b xpr*, SrcList*);
23f00 0a 56 64 62 65 20 2a 73 71 6c 69 74 65 33 47 65 .Vdbe *sqlite3Ge
23f10 74 56 64 62 65 28 50 61 72 73 65 2a 29 3b 0a 23 tVdbe(Parse*);.#
23f20 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
23f30 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a IT_BUILTIN_TEST.
23f40 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e 67 void sqlite3Prng
23f50 53 61 76 65 53 74 61 74 65 28 76 6f 69 64 29 3b SaveState(void);
23f60 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e .void sqlite3Prn
23f70 67 52 65 73 74 6f 72 65 53 74 61 74 65 28 76 6f gRestoreState(vo
23f80 69 64 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 id);.#endif.void
23f90 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
23fa0 41 6c 6c 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 All(sqlite3*,int
23fb0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
23fc0 6f 64 65 56 65 72 69 66 79 53 63 68 65 6d 61 28 odeVerifySchema(
23fd0 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f Parse*, int);.vo
23fe0 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 id sqlite3CodeVe
23ff0 72 69 66 79 4e 61 6d 65 64 53 63 68 65 6d 61 28 rifyNamedSchema(
24000 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 Parse*, const ch
24010 61 72 20 2a 7a 44 62 29 3b 0a 76 6f 69 64 20 73 ar *zDb);.void s
24020 71 6c 69 74 65 33 42 65 67 69 6e 54 72 61 6e 73 qlite3BeginTrans
24030 61 63 74 69 6f 6e 28 50 61 72 73 65 2a 2c 20 69 action(Parse*, i
24040 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
24050 33 43 6f 6d 6d 69 74 54 72 61 6e 73 61 63 74 69 3CommitTransacti
24060 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 on(Parse*);.void
24070 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
24080 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 73 Transaction(Pars
24090 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
240a0 33 53 61 76 65 70 6f 69 6e 74 28 50 61 72 73 65 3Savepoint(Parse
240b0 2a 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a 29 3b *, int, Token*);
240c0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c 6f .void sqlite3Clo
240d0 73 65 53 61 76 65 70 6f 69 6e 74 73 28 73 71 6c seSavepoints(sql
240e0 69 74 65 33 20 2a 29 3b 0a 76 6f 69 64 20 73 71 ite3 *);.void sq
240f0 6c 69 74 65 33 4c 65 61 76 65 4d 75 74 65 78 41 lite3LeaveMutexA
24100 6e 64 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 73 71 ndCloseZombie(sq
24110 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c lite3*);.int sql
24120 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 61 ite3ExprIsConsta
24130 6e 74 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 nt(Expr*);.int s
24140 71 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 qlite3ExprIsCons
24150 74 61 6e 74 4e 6f 74 4a 6f 69 6e 28 45 78 70 72 tantNotJoin(Expr
24160 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
24170 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 46 xprIsConstantOrF
24180 75 6e 63 74 69 6f 6e 28 45 78 70 72 2a 2c 20 75 unction(Expr*, u
24190 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 8);.int sqlite3E
241a0 78 70 72 49 73 54 61 62 6c 65 43 6f 6e 73 74 61 xprIsTableConsta
241b0 6e 74 28 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 69 nt(Expr*,int);.i
241c0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 nt sqlite3ExprIs
241d0 49 6e 74 65 67 65 72 28 45 78 70 72 2a 2c 20 69 Integer(Expr*, i
241e0 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
241f0 33 45 78 70 72 43 61 6e 42 65 4e 75 6c 6c 28 63 3ExprCanBeNull(c
24200 6f 6e 73 74 20 45 78 70 72 2a 29 3b 0a 69 6e 74 onst Expr*);.int
24210 20 73 71 6c 69 74 65 33 45 78 70 72 4e 65 65 64 sqlite3ExprNeed
24220 73 4e 6f 41 66 66 69 6e 69 74 79 43 68 61 6e 67 sNoAffinityChang
24230 65 28 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 63 e(const Expr*, c
24240 68 61 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 har);.int sqlite
24250 33 49 73 52 6f 77 69 64 28 63 6f 6e 73 74 20 63 3IsRowid(const c
24260 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
24270 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 44 65 te3GenerateRowDe
24280 6c 65 74 65 28 50 61 72 73 65 2a 2c 54 61 62 6c lete(Parse*,Tabl
24290 65 2a 2c 54 72 69 67 67 65 72 2a 2c 69 6e 74 2c e*,Trigger*,int,
242a0 69 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 38 2c 75 int,int,i16,u8,u
242b0 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 8,u8);.void sqli
242c0 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 49 6e te3GenerateRowIn
242d0 64 65 78 44 65 6c 65 74 65 28 50 61 72 73 65 2a dexDelete(Parse*
242e0 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 , Table*, int, i
242f0 6e 74 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 nt, int*);.int s
24300 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 49 6e qlite3GenerateIn
24310 64 65 78 4b 65 79 28 50 61 72 73 65 2a 2c 20 49 dexKey(Parse*, I
24320 6e 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c ndex*, int, int,
24330 20 69 6e 74 2c 20 69 6e 74 2a 2c 49 6e 64 65 78 int, int*,Index
24340 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c *,int);.void sql
24350 69 74 65 33 52 65 73 6f 6c 76 65 50 61 72 74 49 ite3ResolvePartI
24360 64 78 4c 61 62 65 6c 28 50 61 72 73 65 2a 2c 69 dxLabel(Parse*,i
24370 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
24380 33 47 65 6e 65 72 61 74 65 43 6f 6e 73 74 72 61 3GenerateConstra
24390 69 6e 74 43 68 65 63 6b 73 28 50 61 72 73 65 2a intChecks(Parse*
243a0 2c 54 61 62 6c 65 2a 2c 69 6e 74 2a 2c 69 6e 74 ,Table*,int*,int
243b0 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 0a 20 20 ,int,int,int,.
243c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
243d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
243e0 20 20 20 75 38 2c 75 38 2c 69 6e 74 2c 69 6e 74 u8,u8,int,int
243f0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
24400 43 6f 6d 70 6c 65 74 65 49 6e 73 65 72 74 69 6f CompleteInsertio
24410 6e 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c n(Parse*,Table*,
24420 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2a int,int,int,int*
24430 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a 69 ,int,int,int);.i
24440 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 61 nt sqlite3OpenTa
24450 62 6c 65 41 6e 64 49 6e 64 69 63 65 73 28 50 61 bleAndIndices(Pa
24460 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e rse*, Table*, in
24470 74 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 69 6e 74 t, int, u8*, int
24480 2a 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 *, int*);.void s
24490 71 6c 69 74 65 33 42 65 67 69 6e 57 72 69 74 65 qlite3BeginWrite
244a0 4f 70 65 72 61 74 69 6f 6e 28 50 61 72 73 65 2a Operation(Parse*
244b0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
244c0 64 20 73 71 6c 69 74 65 33 4d 75 6c 74 69 57 72 d sqlite3MultiWr
244d0 69 74 65 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ite(Parse*);.voi
244e0 64 20 73 71 6c 69 74 65 33 4d 61 79 41 62 6f 72 d sqlite3MayAbor
244f0 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 t(Parse*);.void
24500 73 71 6c 69 74 65 33 48 61 6c 74 43 6f 6e 73 74 sqlite3HaltConst
24510 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e raint(Parse*, in
24520 74 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2c 20 69 t, int, char*, i
24530 38 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 8, u8);.void sql
24540 69 74 65 33 55 6e 69 71 75 65 43 6f 6e 73 74 72 ite3UniqueConstr
24550 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 aint(Parse*, int
24560 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 , Index*);.void
24570 73 71 6c 69 74 65 33 52 6f 77 69 64 43 6f 6e 73 sqlite3RowidCons
24580 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 traint(Parse*, i
24590 6e 74 2c 20 54 61 62 6c 65 2a 29 3b 0a 45 78 70 nt, Table*);.Exp
245a0 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 44 75 r *sqlite3ExprDu
245b0 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a p(sqlite3*,Expr*
245c0 2c 69 6e 74 29 3b 0a 45 78 70 72 4c 69 73 74 20 ,int);.ExprList
245d0 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 *sqlite3ExprList
245e0 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 Dup(sqlite3*,Exp
245f0 72 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 53 72 63 rList*,int);.Src
24600 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 List *sqlite3Src
24610 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a ListDup(sqlite3*
24620 2c 53 72 63 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a ,SrcList*,int);.
24630 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 49 IdList *sqlite3I
24640 64 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 dListDup(sqlite3
24650 2a 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 65 6c 65 *,IdList*);.Sele
24660 63 74 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 ct *sqlite3Selec
24670 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 tDup(sqlite3*,Se
24680 6c 65 63 74 2a 2c 69 6e 74 29 3b 0a 23 69 66 20 lect*,int);.#if
24690 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
246a0 4c 45 44 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 LED.void sqlite3
246b0 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 28 53 65 SelectSetName(Se
246c0 6c 65 63 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 lect*,const char
246d0 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
246e0 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 ne sqlite3Select
246f0 53 65 74 4e 61 6d 65 28 41 2c 42 29 0a 23 65 6e SetName(A,B).#en
24700 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
24710 46 75 6e 63 44 65 66 49 6e 73 65 72 74 28 46 75 FuncDefInsert(Fu
24720 6e 63 44 65 66 48 61 73 68 2a 2c 20 46 75 6e 63 ncDefHash*, Func
24730 44 65 66 2a 29 3b 0a 46 75 6e 63 44 65 66 20 2a Def*);.FuncDef *
24740 73 71 6c 69 74 65 33 46 69 6e 64 46 75 6e 63 74 sqlite3FindFunct
24750 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ion(sqlite3*,con
24760 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c 69 6e 74 st char*,int,int
24770 2c 75 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 ,u8,u8);.void sq
24780 6c 69 74 65 33 52 65 67 69 73 74 65 72 42 75 69 lite3RegisterBui
24790 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 73 28 73 71 ltinFunctions(sq
247a0 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
247b0 6c 69 74 65 33 52 65 67 69 73 74 65 72 44 61 74 lite3RegisterDat
247c0 65 54 69 6d 65 46 75 6e 63 74 69 6f 6e 73 28 76 eTimeFunctions(v
247d0 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 oid);.void sqlit
247e0 65 33 52 65 67 69 73 74 65 72 47 6c 6f 62 61 6c e3RegisterGlobal
247f0 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
24800 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 61 66 65 .int sqlite3Safe
24810 74 79 43 68 65 63 6b 4f 6b 28 73 71 6c 69 74 65 tyCheckOk(sqlite
24820 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 3*);.int sqlite3
24830 53 61 66 65 74 79 43 68 65 63 6b 53 69 63 6b 4f SafetyCheckSickO
24840 72 4f 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 rOk(sqlite3*);.v
24850 6f 69 64 20 73 71 6c 69 74 65 33 43 68 61 6e 67 oid sqlite3Chang
24860 65 43 6f 6f 6b 69 65 28 50 61 72 73 65 2a 2c 20 eCookie(Parse*,
24870 69 6e 74 29 3b 0a 0a 23 69 66 20 21 64 65 66 69 int);..#if !defi
24880 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ned(SQLITE_OMIT_
24890 56 49 45 57 29 20 26 26 20 21 64 65 66 69 6e 65 VIEW) && !define
248a0 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 d(SQLITE_OMIT_TR
248b0 49 47 47 45 52 29 0a 76 6f 69 64 20 73 71 6c 69 IGGER).void sqli
248c0 74 65 33 4d 61 74 65 72 69 61 6c 69 7a 65 56 69 te3MaterializeVi
248d0 65 77 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 ew(Parse*, Table
248e0 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
248f0 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 #endif..#ifndef
24900 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 SQLITE_OMIT_TRIG
24910 47 45 52 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 GER. void sqlit
24920 65 33 42 65 67 69 6e 54 72 69 67 67 65 72 28 50 e3BeginTrigger(P
24930 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 54 6f arse*, Token*,To
24940 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c 49 64 4c ken*,int,int,IdL
24950 69 73 74 2a 2c 53 72 63 4c 69 73 74 2a 2c 0a 20 ist*,SrcList*,.
24960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24970 20 20 20 20 20 20 20 20 20 20 45 78 70 72 2a 2c Expr*,
24980 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
24990 64 20 73 71 6c 69 74 65 33 46 69 6e 69 73 68 54 d sqlite3FinishT
249a0 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 54 rigger(Parse*, T
249b0 72 69 67 67 65 72 53 74 65 70 2a 2c 20 54 6f 6b riggerStep*, Tok
249c0 65 6e 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c en*);. void sql
249d0 69 74 65 33 44 72 6f 70 54 72 69 67 67 65 72 28 ite3DropTrigger(
249e0 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a Parse*, SrcList*
249f0 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 , int);. void s
24a00 71 6c 69 74 65 33 44 72 6f 70 54 72 69 67 67 65 qlite3DropTrigge
24a10 72 50 74 72 28 50 61 72 73 65 2a 2c 20 54 72 69 rPtr(Parse*, Tri
24a20 67 67 65 72 2a 29 3b 0a 20 20 54 72 69 67 67 65 gger*);. Trigge
24a30 72 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 r *sqlite3Trigge
24a40 72 73 45 78 69 73 74 28 50 61 72 73 65 20 2a 2c rsExist(Parse *,
24a50 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 45 78 Table*, int, Ex
24a60 70 72 4c 69 73 74 2a 2c 20 69 6e 74 20 2a 70 4d prList*, int *pM
24a70 61 73 6b 29 3b 0a 20 20 54 72 69 67 67 65 72 20 ask);. Trigger
24a80 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 4c *sqlite3TriggerL
24a90 69 73 74 28 50 61 72 73 65 20 2a 2c 20 54 61 62 ist(Parse *, Tab
24aa0 6c 65 20 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 le *);. void sq
24ab0 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 lite3CodeRowTrig
24ac0 67 65 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 ger(Parse*, Trig
24ad0 67 65 72 20 2a 2c 20 69 6e 74 2c 20 45 78 70 72 ger *, int, Expr
24ae0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 54 61 62 6c List*, int, Tabl
24af0 65 20 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 e *,.
24b00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24b10 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
24b20 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
24b30 6f 64 65 52 6f 77 54 72 69 67 67 65 72 44 69 72 odeRowTriggerDir
24b40 65 63 74 28 50 61 72 73 65 20 2a 2c 20 54 72 69 ect(Parse *, Tri
24b50 67 67 65 72 20 2a 2c 20 54 61 62 6c 65 20 2a 2c gger *, Table *,
24b60 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
24b70 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 56 69 . void sqliteVi
24b80 65 77 54 72 69 67 67 65 72 73 28 50 61 72 73 65 ewTriggers(Parse
24b90 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a *, Table*, Expr*
24ba0 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a , int, ExprList*
24bb0 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
24bc0 33 44 65 6c 65 74 65 54 72 69 67 67 65 72 53 74 3DeleteTriggerSt
24bd0 65 70 28 73 71 6c 69 74 65 33 2a 2c 20 54 72 69 ep(sqlite3*, Tri
24be0 67 67 65 72 53 74 65 70 2a 29 3b 0a 20 20 54 72 ggerStep*);. Tr
24bf0 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 74 iggerStep *sqlit
24c00 65 33 54 72 69 67 67 65 72 53 65 6c 65 63 74 53 e3TriggerSelectS
24c10 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 6c tep(sqlite3*,Sel
24c20 65 63 74 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 ect*);. Trigger
24c30 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 Step *sqlite3Tri
24c40 67 67 65 72 49 6e 73 65 72 74 53 74 65 70 28 73 ggerInsertStep(s
24c50 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 qlite3*,Token*,
24c60 49 64 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 IdList*,.
24c70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24c80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24c90 20 53 65 6c 65 63 74 2a 2c 75 38 29 3b 0a 20 20 Select*,u8);.
24ca0 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c TriggerStep *sql
24cb0 69 74 65 33 54 72 69 67 67 65 72 55 70 64 61 74 ite3TriggerUpdat
24cc0 65 53 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 eStep(sqlite3*,T
24cd0 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
24ce0 20 45 78 70 72 2a 2c 20 75 38 29 3b 0a 20 20 54 Expr*, u8);. T
24cf0 72 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 riggerStep *sqli
24d00 74 65 33 54 72 69 67 67 65 72 44 65 6c 65 74 65 te3TriggerDelete
24d10 53 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 6f Step(sqlite3*,To
24d20 6b 65 6e 2a 2c 20 45 78 70 72 2a 29 3b 0a 20 20 ken*, Expr*);.
24d30 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 void sqlite3Dele
24d40 74 65 54 72 69 67 67 65 72 28 73 71 6c 69 74 65 teTrigger(sqlite
24d50 33 2a 2c 20 54 72 69 67 67 65 72 2a 29 3b 0a 20 3*, Trigger*);.
24d60 20 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c void sqlite3Unl
24d70 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 72 69 67 inkAndDeleteTrig
24d80 67 65 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ger(sqlite3*,int
24d90 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 ,const char*);.
24da0 20 75 33 32 20 73 71 6c 69 74 65 33 54 72 69 67 u32 sqlite3Trig
24db0 67 65 72 43 6f 6c 6d 61 73 6b 28 50 61 72 73 65 gerColmask(Parse
24dc0 2a 2c 54 72 69 67 67 65 72 2a 2c 45 78 70 72 4c *,Trigger*,ExprL
24dd0 69 73 74 2a 2c 69 6e 74 2c 69 6e 74 2c 54 61 62 ist*,int,int,Tab
24de0 6c 65 2a 2c 69 6e 74 29 3b 0a 23 20 64 65 66 69 le*,int);.# defi
24df0 6e 65 20 73 71 6c 69 74 65 33 50 61 72 73 65 54 ne sqlite3ParseT
24e00 6f 70 6c 65 76 65 6c 28 70 29 20 28 28 70 29 2d oplevel(p) ((p)-
24e10 3e 70 54 6f 70 6c 65 76 65 6c 20 3f 20 28 70 29 >pToplevel ? (p)
24e20 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 3a 20 28 70 ->pToplevel : (p
24e30 29 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e )).#else.# defin
24e40 65 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 e sqlite3Trigger
24e50 73 45 78 69 73 74 28 42 2c 43 2c 44 2c 45 2c 46 sExist(B,C,D,E,F
24e60 29 20 30 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ) 0.# define sql
24e70 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 67 65 ite3DeleteTrigge
24e80 72 28 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 r(A,B).# define
24e90 73 71 6c 69 74 65 33 44 72 6f 70 54 72 69 67 67 sqlite3DropTrigg
24ea0 65 72 50 74 72 28 41 2c 42 29 0a 23 20 64 65 66 erPtr(A,B).# def
24eb0 69 6e 65 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e ine sqlite3Unlin
24ec0 6b 41 6e 64 44 65 6c 65 74 65 54 72 69 67 67 65 kAndDeleteTrigge
24ed0 72 28 41 2c 42 2c 43 29 0a 23 20 64 65 66 69 6e r(A,B,C).# defin
24ee0 65 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 e sqlite3CodeRow
24ef0 54 72 69 67 67 65 72 28 41 2c 42 2c 43 2c 44 2c Trigger(A,B,C,D,
24f00 45 2c 46 2c 47 2c 48 2c 49 29 0a 23 20 64 65 66 E,F,G,H,I).# def
24f10 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 64 65 52 ine sqlite3CodeR
24f20 6f 77 54 72 69 67 67 65 72 44 69 72 65 63 74 28 owTriggerDirect(
24f30 41 2c 42 2c 43 2c 44 2c 45 2c 46 29 0a 23 20 64 A,B,C,D,E,F).# d
24f40 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 69 efine sqlite3Tri
24f50 67 67 65 72 4c 69 73 74 28 58 2c 20 59 29 20 30 ggerList(X, Y) 0
24f60 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
24f70 33 50 61 72 73 65 54 6f 70 6c 65 76 65 6c 28 70 3ParseToplevel(p
24f80 29 20 70 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ) p.# define sql
24f90 69 74 65 33 54 72 69 67 67 65 72 43 6f 6c 6d 61 ite3TriggerColma
24fa0 73 6b 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 sk(A,B,C,D,E,F,G
24fb0 29 20 30 0a 23 65 6e 64 69 66 0a 0a 69 6e 74 20 ) 0.#endif..int
24fc0 73 71 6c 69 74 65 33 4a 6f 69 6e 54 79 70 65 28 sqlite3JoinType(
24fd0 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Parse*, Token*,
24fe0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b Token*, Token*);
24ff0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 72 65 .void sqlite3Cre
25000 61 74 65 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 ateForeignKey(Pa
25010 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c rse*, ExprList*,
25020 20 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 4c 69 73 Token*, ExprLis
25030 74 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 t*, int);.void s
25040 71 6c 69 74 65 33 44 65 66 65 72 46 6f 72 65 69 qlite3DeferForei
25050 67 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 69 6e gnKey(Parse*, in
25060 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 t);.#ifndef SQLI
25070 54 45 5f 4f 4d 49 54 5f 41 55 54 48 4f 52 49 5a TE_OMIT_AUTHORIZ
25080 41 54 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c ATION. void sql
25090 69 74 65 33 41 75 74 68 52 65 61 64 28 50 61 72 ite3AuthRead(Par
250a0 73 65 2a 2c 45 78 70 72 2a 2c 53 63 68 65 6d 61 se*,Expr*,Schema
250b0 2a 2c 53 72 63 4c 69 73 74 2a 29 3b 0a 20 20 69 *,SrcList*);. i
250c0 6e 74 20 73 71 6c 69 74 65 33 41 75 74 68 43 68 nt sqlite3AuthCh
250d0 65 63 6b 28 50 61 72 73 65 2a 2c 69 6e 74 2c 20 eck(Parse*,int,
250e0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
250f0 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
25100 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 char*);. void s
25110 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 65 78 qlite3AuthContex
25120 74 50 75 73 68 28 50 61 72 73 65 2a 2c 20 41 75 tPush(Parse*, Au
25130 74 68 43 6f 6e 74 65 78 74 2a 2c 20 63 6f 6e 73 thContext*, cons
25140 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 t char*);. void
25150 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 sqlite3AuthCont
25160 65 78 74 50 6f 70 28 41 75 74 68 43 6f 6e 74 65 extPop(AuthConte
25170 78 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 xt*);. int sqli
25180 74 65 33 41 75 74 68 52 65 61 64 43 6f 6c 28 50 te3AuthReadCol(P
25190 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 arse*, const cha
251a0 72 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 r *, const char
251b0 2a 2c 20 69 6e 74 29 3b 0a 23 65 6c 73 65 0a 23 *, int);.#else.#
251c0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 define sqlite3A
251d0 75 74 68 52 65 61 64 28 61 2c 62 2c 63 2c 64 29 uthRead(a,b,c,d)
251e0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
251f0 33 41 75 74 68 43 68 65 63 6b 28 61 2c 62 2c 63 3AuthCheck(a,b,c
25200 2c 64 2c 65 29 20 20 20 20 53 51 4c 49 54 45 5f ,d,e) SQLITE_
25210 4f 4b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 OK.# define sqli
25220 74 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 75 te3AuthContextPu
25230 73 68 28 61 2c 62 2c 63 29 0a 23 20 64 65 66 69 sh(a,b,c).# defi
25240 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f ne sqlite3AuthCo
25250 6e 74 65 78 74 50 6f 70 28 61 29 20 20 28 28 76 ntextPop(a) ((v
25260 6f 69 64 29 28 61 29 29 0a 23 65 6e 64 69 66 0a oid)(a)).#endif.
25270 76 6f 69 64 20 73 71 6c 69 74 65 33 41 74 74 61 void sqlite3Atta
25280 63 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a ch(Parse*, Expr*
25290 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 29 3b , Expr*, Expr*);
252a0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 74 .void sqlite3Det
252b0 61 63 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 ach(Parse*, Expr
252c0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
252d0 46 69 78 49 6e 69 74 28 44 62 46 69 78 65 72 2a FixInit(DbFixer*
252e0 2c 20 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 63 , Parse*, int, c
252f0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
25300 74 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 t Token*);.int s
25310 71 6c 69 74 65 33 46 69 78 53 72 63 4c 69 73 74 qlite3FixSrcList
25320 28 44 62 46 69 78 65 72 2a 2c 20 53 72 63 4c 69 (DbFixer*, SrcLi
25330 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 st*);.int sqlite
25340 33 46 69 78 53 65 6c 65 63 74 28 44 62 46 69 78 3FixSelect(DbFix
25350 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 er*, Select*);.i
25360 6e 74 20 73 71 6c 69 74 65 33 46 69 78 45 78 70 nt sqlite3FixExp
25370 72 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 r(DbFixer*, Expr
25380 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 *);.int sqlite3F
25390 69 78 45 78 70 72 4c 69 73 74 28 44 62 46 69 78 ixExprList(DbFix
253a0 65 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b er*, ExprList*);
253b0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 54 .int sqlite3FixT
253c0 72 69 67 67 65 72 53 74 65 70 28 44 62 46 69 78 riggerStep(DbFix
253d0 65 72 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 er*, TriggerStep
253e0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 *);.int sqlite3A
253f0 74 6f 46 28 63 6f 6e 73 74 20 63 68 61 72 20 2a toF(const char *
25400 7a 2c 20 64 6f 75 62 6c 65 2a 2c 20 69 6e 74 2c z, double*, int,
25410 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u8);.int sqlite
25420 33 47 65 74 49 6e 74 33 32 28 63 6f 6e 73 74 20 3GetInt32(const
25430 63 68 61 72 20 2a 2c 20 69 6e 74 2a 29 3b 0a 69 char *, int*);.i
25440 6e 74 20 73 71 6c 69 74 65 33 41 74 6f 69 28 63 nt sqlite3Atoi(c
25450 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 onst char*);.int
25460 20 73 71 6c 69 74 65 33 55 74 66 31 36 42 79 74 sqlite3Utf16Byt
25470 65 4c 65 6e 28 63 6f 6e 73 74 20 76 6f 69 64 20 eLen(const void
25480 2a 70 44 61 74 61 2c 20 69 6e 74 20 6e 43 68 61 *pData, int nCha
25490 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 r);.int sqlite3U
254a0 74 66 38 43 68 61 72 4c 65 6e 28 63 6f 6e 73 74 tf8CharLen(const
254b0 20 63 68 61 72 20 2a 70 44 61 74 61 2c 20 69 6e char *pData, in
254c0 74 20 6e 42 79 74 65 29 3b 0a 75 33 32 20 73 71 t nByte);.u32 sq
254d0 6c 69 74 65 33 55 74 66 38 52 65 61 64 28 63 6f lite3Utf8Read(co
254e0 6e 73 74 20 75 38 2a 2a 29 3b 0a 4c 6f 67 45 73 nst u8**);.LogEs
254f0 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 28 t sqlite3LogEst(
25500 75 36 34 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c u64);.LogEst sql
25510 69 74 65 33 4c 6f 67 45 73 74 41 64 64 28 4c 6f ite3LogEstAdd(Lo
25520 67 45 73 74 2c 4c 6f 67 45 73 74 29 3b 0a 23 69 gEst,LogEst);.#i
25530 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
25540 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 4c T_VIRTUALTABLE.L
25550 6f 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 ogEst sqlite3Log
25560 45 73 74 46 72 6f 6d 44 6f 75 62 6c 65 28 64 6f EstFromDouble(do
25570 75 62 6c 65 29 3b 0a 23 65 6e 64 69 66 0a 75 36 uble);.#endif.u6
25580 34 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 54 4 sqlite3LogEstT
25590 6f 49 6e 74 28 4c 6f 67 45 73 74 29 3b 0a 0a 2f oInt(LogEst);../
255a0 2a 0a 2a 2a 20 52 6f 75 74 69 6e 65 73 20 74 6f *.** Routines to
255b0 20 72 65 61 64 20 61 6e 64 20 77 72 69 74 65 20 read and write
255c0 76 61 72 69 61 62 6c 65 2d 6c 65 6e 67 74 68 20 variable-length
255d0 69 6e 74 65 67 65 72 73 2e 20 20 54 68 65 73 65 integers. These
255e0 20 75 73 65 64 20 74 6f 0a 2a 2a 20 62 65 20 64 used to.** be d
255f0 65 66 69 6e 65 64 20 6c 6f 63 61 6c 6c 79 2c 20 efined locally,
25600 62 75 74 20 6e 6f 77 20 77 65 20 75 73 65 20 74 but now we use t
25610 68 65 20 76 61 72 69 6e 74 20 72 6f 75 74 69 6e he varint routin
25620 65 73 20 69 6e 20 74 68 65 20 75 74 69 6c 2e 63 es in the util.c
25630 0a 2a 2a 20 66 69 6c 65 2e 0a 2a 2f 0a 69 6e 74 .** file..*/.int
25640 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 6e sqlite3PutVarin
25650 74 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a t(unsigned char*
25660 2c 20 75 36 34 29 3b 0a 75 38 20 73 71 6c 69 74 , u64);.u8 sqlit
25670 65 33 47 65 74 56 61 72 69 6e 74 28 63 6f 6e 73 e3GetVarint(cons
25680 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 t unsigned char
25690 2a 2c 20 75 36 34 20 2a 29 3b 0a 75 38 20 73 71 *, u64 *);.u8 sq
256a0 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 32 lite3GetVarint32
256b0 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 (const unsigned
256c0 63 68 61 72 20 2a 2c 20 75 33 32 20 2a 29 3b 0a char *, u32 *);.
256d0 69 6e 74 20 73 71 6c 69 74 65 33 56 61 72 69 6e int sqlite3Varin
256e0 74 4c 65 6e 28 75 36 34 20 76 29 3b 0a 0a 2f 2a tLen(u64 v);../*
256f0 0a 2a 2a 20 54 68 65 20 63 6f 6d 6d 6f 6e 20 63 .** The common c
25700 61 73 65 20 69 73 20 66 6f 72 20 61 20 76 61 72 ase is for a var
25710 69 6e 74 20 74 6f 20 62 65 20 61 20 73 69 6e 67 int to be a sing
25720 6c 65 20 62 79 74 65 2e 20 20 54 68 65 79 20 66 le byte. They f
25730 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 6d 61 63 72 ollowing.** macr
25740 6f 73 20 68 61 6e 64 6c 65 20 74 68 65 20 63 6f os handle the co
25750 6d 6d 6f 6e 20 63 61 73 65 20 77 69 74 68 6f 75 mmon case withou
25760 74 20 61 20 70 72 6f 63 65 64 75 72 65 20 63 61 t a procedure ca
25770 6c 6c 2c 20 62 75 74 20 74 68 65 6e 20 63 61 6c ll, but then cal
25780 6c 0a 2a 2a 20 74 68 65 20 70 72 6f 63 65 64 75 l.** the procedu
25790 72 65 20 66 6f 72 20 6c 61 72 67 65 72 20 76 61 re for larger va
257a0 72 69 6e 74 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e rints..*/.#defin
257b0 65 20 67 65 74 56 61 72 69 6e 74 33 32 28 41 2c e getVarint32(A,
257c0 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 2a 28 B) \. (u8)((*(
257d0 41 29 3c 28 75 38 29 30 78 38 30 29 3f 28 28 42 A)<(u8)0x80)?((B
257e0 29 3d 28 75 33 32 29 2a 28 41 29 29 2c 31 3a 73 )=(u32)*(A)),1:s
257f0 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 qlite3GetVarint3
25800 32 28 28 41 29 2c 28 75 33 32 20 2a 29 26 28 42 2((A),(u32 *)&(B
25810 29 29 29 0a 23 64 65 66 69 6e 65 20 70 75 74 56 ))).#define putV
25820 61 72 69 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a arint32(A,B) \.
25830 20 20 28 75 38 29 28 28 28 75 33 32 29 28 42 29 (u8)(((u32)(B)
25840 3c 28 75 33 32 29 30 78 38 30 29 3f 28 2a 28 41 <(u32)0x80)?(*(A
25850 29 3d 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 )=(unsigned char
25860 29 28 42 29 29 2c 31 3a 5c 0a 20 20 73 71 6c 69 )(B)),1:\. sqli
25870 74 65 33 50 75 74 56 61 72 69 6e 74 28 28 41 29 te3PutVarint((A)
25880 2c 28 42 29 29 29 0a 23 64 65 66 69 6e 65 20 67 ,(B))).#define g
25890 65 74 56 61 72 69 6e 74 20 20 20 20 73 71 6c 69 etVarint sqli
258a0 74 65 33 47 65 74 56 61 72 69 6e 74 0a 23 64 65 te3GetVarint.#de
258b0 66 69 6e 65 20 70 75 74 56 61 72 69 6e 74 20 20 fine putVarint
258c0 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 sqlite3PutVari
258d0 6e 74 0a 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 nt...const char
258e0 2a 73 71 6c 69 74 65 33 49 6e 64 65 78 41 66 66 *sqlite3IndexAff
258f0 69 6e 69 74 79 53 74 72 28 56 64 62 65 20 2a 2c inityStr(Vdbe *,
25900 20 49 6e 64 65 78 20 2a 29 3b 0a 76 6f 69 64 20 Index *);.void
25910 73 71 6c 69 74 65 33 54 61 62 6c 65 41 66 66 69 sqlite3TableAffi
25920 6e 69 74 79 28 56 64 62 65 2a 2c 20 54 61 62 6c nity(Vdbe*, Tabl
25930 65 2a 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 73 e*, int);.char s
25940 71 6c 69 74 65 33 43 6f 6d 70 61 72 65 41 66 66 qlite3CompareAff
25950 69 6e 69 74 79 28 45 78 70 72 20 2a 70 45 78 70 inity(Expr *pExp
25960 72 2c 20 63 68 61 72 20 61 66 66 32 29 3b 0a 69 r, char aff2);.i
25970 6e 74 20 73 71 6c 69 74 65 33 49 6e 64 65 78 41 nt sqlite3IndexA
25980 66 66 69 6e 69 74 79 4f 6b 28 45 78 70 72 20 2a ffinityOk(Expr *
25990 70 45 78 70 72 2c 20 63 68 61 72 20 69 64 78 5f pExpr, char idx_
259a0 61 66 66 69 6e 69 74 79 29 3b 0a 63 68 61 72 20 affinity);.char
259b0 73 71 6c 69 74 65 33 45 78 70 72 41 66 66 69 6e sqlite3ExprAffin
259c0 69 74 79 28 45 78 70 72 20 2a 70 45 78 70 72 29 ity(Expr *pExpr)
259d0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 74 6f ;.int sqlite3Ato
259e0 69 36 34 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c i64(const char*,
259f0 20 69 36 34 2a 2c 20 69 6e 74 2c 20 75 38 29 3b i64*, int, u8);
25a00 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 65 63 4f .int sqlite3DecO
25a10 72 48 65 78 54 6f 49 36 34 28 63 6f 6e 73 74 20 rHexToI64(const
25a20 63 68 61 72 2a 2c 20 69 36 34 2a 29 3b 0a 76 6f char*, i64*);.vo
25a30 69 64 20 73 71 6c 69 74 65 33 45 72 72 6f 72 57 id sqlite3ErrorW
25a40 69 74 68 4d 73 67 28 73 71 6c 69 74 65 33 2a 2c ithMsg(sqlite3*,
25a50 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 int, const char
25a60 2a 2c 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c *,...);.void sql
25a70 69 74 65 33 45 72 72 6f 72 28 73 71 6c 69 74 65 ite3Error(sqlite
25a80 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 3*,int);.void *s
25a90 71 6c 69 74 65 33 48 65 78 54 6f 42 6c 6f 62 28 qlite3HexToBlob(
25aa0 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 sqlite3*, const
25ab0 63 68 61 72 20 2a 7a 2c 20 69 6e 74 20 6e 29 3b char *z, int n);
25ac0 0a 75 38 20 73 71 6c 69 74 65 33 48 65 78 54 6f .u8 sqlite3HexTo
25ad0 49 6e 74 28 69 6e 74 20 68 29 3b 0a 69 6e 74 20 Int(int h);.int
25ae0 73 71 6c 69 74 65 33 54 77 6f 50 61 72 74 4e 61 sqlite3TwoPartNa
25af0 6d 65 28 50 61 72 73 65 20 2a 2c 20 54 6f 6b 65 me(Parse *, Toke
25b00 6e 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f n *, Token *, To
25b10 6b 65 6e 20 2a 2a 29 3b 0a 0a 23 69 66 20 64 65 ken **);..#if de
25b20 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4e 45 45 fined(SQLITE_NEE
25b30 44 5f 45 52 52 5f 4e 41 4d 45 29 0a 63 6f 6e 73 D_ERR_NAME).cons
25b40 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 45 t char *sqlite3E
25b50 72 72 4e 61 6d 65 28 69 6e 74 29 3b 0a 23 65 6e rrName(int);.#en
25b60 64 69 66 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 dif..const char
25b70 2a 73 71 6c 69 74 65 33 45 72 72 53 74 72 28 69 *sqlite3ErrStr(i
25b80 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
25b90 52 65 61 64 53 63 68 65 6d 61 28 50 61 72 73 65 ReadSchema(Parse
25ba0 20 2a 70 50 61 72 73 65 29 3b 0a 43 6f 6c 6c 53 *pParse);.CollS
25bb0 65 71 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 43 eq *sqlite3FindC
25bc0 6f 6c 6c 53 65 71 28 73 71 6c 69 74 65 33 2a 2c ollSeq(sqlite3*,
25bd0 75 38 20 65 6e 63 2c 20 63 6f 6e 73 74 20 63 68 u8 enc, const ch
25be0 61 72 2a 2c 69 6e 74 29 3b 0a 43 6f 6c 6c 53 65 ar*,int);.CollSe
25bf0 71 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 q *sqlite3Locate
25c00 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 CollSeq(Parse *p
25c10 50 61 72 73 65 2c 20 63 6f 6e 73 74 20 63 68 61 Parse, const cha
25c20 72 2a 7a 4e 61 6d 65 29 3b 0a 43 6f 6c 6c 53 65 r*zName);.CollSe
25c30 71 20 2a 73 71 6c 69 74 65 33 45 78 70 72 43 6f q *sqlite3ExprCo
25c40 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 50 61 llSeq(Parse *pPa
25c50 72 73 65 2c 20 45 78 70 72 20 2a 70 45 78 70 72 rse, Expr *pExpr
25c60 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
25c70 45 78 70 72 41 64 64 43 6f 6c 6c 61 74 65 54 6f ExprAddCollateTo
25c80 6b 65 6e 28 50 61 72 73 65 20 2a 70 50 61 72 73 ken(Parse *pPars
25c90 65 2c 20 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 e, Expr*, const
25ca0 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a 45 78 Token*, int);.Ex
25cb0 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 pr *sqlite3ExprA
25cc0 64 64 43 6f 6c 6c 61 74 65 53 74 72 69 6e 67 28 ddCollateString(
25cd0 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 63 6f 6e Parse*,Expr*,con
25ce0 73 74 20 63 68 61 72 2a 29 3b 0a 45 78 70 72 20 st char*);.Expr
25cf0 2a 73 71 6c 69 74 65 33 45 78 70 72 53 6b 69 70 *sqlite3ExprSkip
25d00 43 6f 6c 6c 61 74 65 28 45 78 70 72 2a 29 3b 0a Collate(Expr*);.
25d10 69 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 6b int sqlite3Check
25d20 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 2c CollSeq(Parse *,
25d30 20 43 6f 6c 6c 53 65 71 20 2a 29 3b 0a 69 6e 74 CollSeq *);.int
25d40 20 73 71 6c 69 74 65 33 43 68 65 63 6b 4f 62 6a sqlite3CheckObj
25d50 65 63 74 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c ectName(Parse *,
25d60 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a const char *);.
25d70 76 6f 69 64 20 73 71 6c 69 74 65 33 56 64 62 65 void sqlite3Vdbe
25d80 53 65 74 43 68 61 6e 67 65 73 28 73 71 6c 69 74 SetChanges(sqlit
25d90 65 33 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 e3 *, int);.int
25da0 73 71 6c 69 74 65 33 41 64 64 49 6e 74 36 34 28 sqlite3AddInt64(
25db0 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 i64*,i64);.int s
25dc0 71 6c 69 74 65 33 53 75 62 49 6e 74 36 34 28 69 qlite3SubInt64(i
25dd0 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 64*,i64);.int sq
25de0 6c 69 74 65 33 4d 75 6c 49 6e 74 36 34 28 69 36 lite3MulInt64(i6
25df0 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 4*,i64);.int sql
25e00 69 74 65 33 41 62 73 49 6e 74 33 32 28 69 6e 74 ite3AbsInt32(int
25e10 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 );.#ifdef SQLITE
25e20 5f 45 4e 41 42 4c 45 5f 38 5f 33 5f 4e 41 4d 45 _ENABLE_8_3_NAME
25e30 53 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 69 S.void sqlite3Fi
25e40 6c 65 53 75 66 66 69 78 33 28 63 6f 6e 73 74 20 leSuffix3(const
25e50 63 68 61 72 2a 2c 20 63 68 61 72 2a 29 3b 0a 23 char*, char*);.#
25e60 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
25e70 6c 69 74 65 33 46 69 6c 65 53 75 66 66 69 78 33 lite3FileSuffix3
25e80 28 58 2c 59 29 0a 23 65 6e 64 69 66 0a 75 38 20 (X,Y).#endif.u8
25e90 73 71 6c 69 74 65 33 47 65 74 42 6f 6f 6c 65 61 sqlite3GetBoolea
25ea0 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c n(const char *z,
25eb0 75 38 29 3b 0a 0a 63 6f 6e 73 74 20 76 6f 69 64 u8);..const void
25ec0 20 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 54 65 *sqlite3ValueTe
25ed0 78 74 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 xt(sqlite3_value
25ee0 2a 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 *, u8);.int sqli
25ef0 74 65 33 56 61 6c 75 65 42 79 74 65 73 28 73 71 te3ValueBytes(sq
25f00 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 38 lite3_value*, u8
25f10 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
25f20 61 6c 75 65 53 65 74 53 74 72 28 73 71 6c 69 74 alueSetStr(sqlit
25f30 65 33 5f 76 61 6c 75 65 2a 2c 20 69 6e 74 2c 20 e3_value*, int,
25f40 63 6f 6e 73 74 20 76 6f 69 64 20 2a 2c 75 38 2c const void *,u8,
25f50 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
25f60 20 20 20 20 20 20 20 20 20 20 76 6f 69 64 28 2a void(*
25f70 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f 69 64 20 )(void*));.void
25f80 73 71 6c 69 74 65 33 56 61 6c 75 65 53 65 74 4e sqlite3ValueSetN
25f90 75 6c 6c 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ull(sqlite3_valu
25fa0 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
25fb0 33 56 61 6c 75 65 46 72 65 65 28 73 71 6c 69 74 3ValueFree(sqlit
25fc0 65 33 5f 76 61 6c 75 65 2a 29 3b 0a 73 71 6c 69 e3_value*);.sqli
25fd0 74 65 33 5f 76 61 6c 75 65 20 2a 73 71 6c 69 74 te3_value *sqlit
25fe0 65 33 56 61 6c 75 65 4e 65 77 28 73 71 6c 69 74 e3ValueNew(sqlit
25ff0 65 33 20 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c e3 *);.char *sql
26000 69 74 65 33 55 74 66 31 36 74 6f 38 28 73 71 6c ite3Utf16to8(sql
26010 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 76 6f ite3 *, const vo
26020 69 64 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 id*, int, u8);.i
26030 6e 74 20 73 71 6c 69 74 65 33 56 61 6c 75 65 46 nt sqlite3ValueF
26040 72 6f 6d 45 78 70 72 28 73 71 6c 69 74 65 33 20 romExpr(sqlite3
26050 2a 2c 20 45 78 70 72 20 2a 2c 20 75 38 2c 20 75 *, Expr *, u8, u
26060 38 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 8, sqlite3_value
26070 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 **);.void sqlit
26080 65 33 56 61 6c 75 65 41 70 70 6c 79 41 66 66 69 e3ValueApplyAffi
26090 6e 69 74 79 28 73 71 6c 69 74 65 33 5f 76 61 6c nity(sqlite3_val
260a0 75 65 20 2a 2c 20 75 38 2c 20 75 38 29 3b 0a 23 ue *, u8, u8);.#
260b0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 41 4d ifndef SQLITE_AM
260c0 41 4c 47 41 4d 41 54 49 4f 4e 0a 65 78 74 65 72 ALGAMATION.exter
260d0 6e 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 n const unsigned
260e0 20 63 68 61 72 20 73 71 6c 69 74 65 33 4f 70 63 char sqlite3Opc
260f0 6f 64 65 50 72 6f 70 65 72 74 79 5b 5d 3b 0a 65 odeProperty[];.e
26100 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 69 xtern const unsi
26110 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 65 gned char sqlite
26120 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b 5d 3b 3UpperToLower[];
26130 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e .extern const un
26140 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 signed char sqli
26150 74 65 33 43 74 79 70 65 4d 61 70 5b 5d 3b 0a 65 te3CtypeMap[];.e
26160 78 74 65 72 6e 20 63 6f 6e 73 74 20 54 6f 6b 65 xtern const Toke
26170 6e 20 73 71 6c 69 74 65 33 49 6e 74 54 6f 6b 65 n sqlite3IntToke
26180 6e 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 51 4c ns[];.extern SQL
26190 49 54 45 5f 57 53 44 20 73 74 72 75 63 74 20 53 ITE_WSD struct S
261a0 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 73 71 6c qlite3Config sql
261b0 69 74 65 33 43 6f 6e 66 69 67 3b 0a 65 78 74 65 ite3Config;.exte
261c0 72 6e 20 53 51 4c 49 54 45 5f 57 53 44 20 46 75 rn SQLITE_WSD Fu
261d0 6e 63 44 65 66 48 61 73 68 20 73 71 6c 69 74 65 ncDefHash sqlite
261e0 33 47 6c 6f 62 61 6c 46 75 6e 63 74 69 6f 6e 73 3GlobalFunctions
261f0 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
26200 5f 4f 4d 49 54 5f 57 53 44 0a 65 78 74 65 72 6e _OMIT_WSD.extern
26210 20 69 6e 74 20 73 71 6c 69 74 65 33 50 65 6e 64 int sqlite3Pend
26220 69 6e 67 42 79 74 65 3b 0a 23 65 6e 64 69 66 0a ingByte;.#endif.
26230 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
26240 74 65 33 52 6f 6f 74 50 61 67 65 4d 6f 76 65 64 te3RootPageMoved
26250 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
26260 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
26270 73 71 6c 69 74 65 33 52 65 69 6e 64 65 78 28 50 sqlite3Reindex(P
26280 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
26290 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
262a0 69 74 65 33 41 6c 74 65 72 46 75 6e 63 74 69 6f ite3AlterFunctio
262b0 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 ns(void);.void s
262c0 71 6c 69 74 65 33 41 6c 74 65 72 52 65 6e 61 6d qlite3AlterRenam
262d0 65 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 eTable(Parse*, S
262e0 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 rcList*, Token*)
262f0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 ;.int sqlite3Get
26300 54 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 Token(const unsi
26310 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 69 6e 74 gned char *, int
26320 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
26330 33 4e 65 73 74 65 64 50 61 72 73 65 28 50 61 72 3NestedParse(Par
26340 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a se*, const char*
26350 2c 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c , ...);.void sql
26360 69 74 65 33 45 78 70 69 72 65 50 72 65 70 61 72 ite3ExpirePrepar
26370 65 64 53 74 61 74 65 6d 65 6e 74 73 28 73 71 6c edStatements(sql
26380 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ite3*);.int sqli
26390 74 65 33 43 6f 64 65 53 75 62 73 65 6c 65 63 74 te3CodeSubselect
263a0 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 2a (Parse *, Expr *
263b0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
263c0 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 50 d sqlite3SelectP
263d0 72 65 70 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 rep(Parse*, Sele
263e0 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 ct*, NameContext
263f0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
26400 53 65 6c 65 63 74 57 72 6f 6e 67 4e 75 6d 54 65 SelectWrongNumTe
26410 72 6d 73 45 72 72 6f 72 28 50 61 72 73 65 20 2a rmsError(Parse *
26420 70 50 61 72 73 65 2c 20 53 65 6c 65 63 74 20 2a pParse, Select *
26430 70 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d p);.int sqlite3M
26440 61 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e atchSpanName(con
26450 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
26460 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
26470 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
26480 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 ;.int sqlite3Res
26490 6f 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 olveExprNames(Na
264a0 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 meContext*, Expr
264b0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
264c0 52 65 73 6f 6c 76 65 53 65 6c 65 63 74 4e 61 6d ResolveSelectNam
264d0 65 73 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 es(Parse*, Selec
264e0 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a t*, NameContext*
264f0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
26500 65 73 6f 6c 76 65 53 65 6c 66 52 65 66 65 72 65 esolveSelfRefere
26510 6e 63 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 nce(Parse*,Table
26520 2a 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 78 70 72 *,int,Expr*,Expr
26530 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 List*);.int sqli
26540 74 65 33 52 65 73 6f 6c 76 65 4f 72 64 65 72 47 te3ResolveOrderG
26550 72 6f 75 70 42 79 28 50 61 72 73 65 2a 2c 20 53 roupBy(Parse*, S
26560 65 6c 65 63 74 2a 2c 20 45 78 70 72 4c 69 73 74 elect*, ExprList
26570 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
26580 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6c .void sqlite3Col
26590 75 6d 6e 44 65 66 61 75 6c 74 28 56 64 62 65 20 umnDefault(Vdbe
265a0 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c *, Table *, int,
265b0 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
265c0 74 65 33 41 6c 74 65 72 46 69 6e 69 73 68 41 64 te3AlterFinishAd
265d0 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 2a 2c dColumn(Parse *,
265e0 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 Token *);.void
265f0 73 71 6c 69 74 65 33 41 6c 74 65 72 42 65 67 69 sqlite3AlterBegi
26600 6e 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 nAddColumn(Parse
26610 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 29 3b 0a *, SrcList *);.
26620 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 CollSeq *sqlite3
26630 47 65 74 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 GetCollSeq(Parse
26640 2a 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 71 20 2a *, u8, CollSeq *
26650 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
26660 63 68 61 72 20 73 71 6c 69 74 65 33 41 66 66 69 char sqlite3Affi
26670 6e 69 74 79 54 79 70 65 28 63 6f 6e 73 74 20 63 nityType(const c
26680 68 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 6f 69 64 har*, u8*);.void
26690 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 28 sqlite3Analyze(
266a0 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Parse*, Token*,
266b0 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
266c0 69 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 48 61 ite3InvokeBusyHa
266d0 6e 64 6c 65 72 28 42 75 73 79 48 61 6e 64 6c 65 ndler(BusyHandle
266e0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
266f0 46 69 6e 64 44 62 28 73 71 6c 69 74 65 33 2a 2c FindDb(sqlite3*,
26700 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 Token*);.int sq
26710 6c 69 74 65 33 46 69 6e 64 44 62 4e 61 6d 65 28 lite3FindDbName(
26720 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 sqlite3 *, const
26730 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 char *);.int sq
26740 6c 69 74 65 33 41 6e 61 6c 79 73 69 73 4c 6f 61 lite3AnalysisLoa
26750 64 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 69 d(sqlite3*,int i
26760 44 42 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 DB);.void sqlite
26770 33 44 65 6c 65 74 65 49 6e 64 65 78 53 61 6d 70 3DeleteIndexSamp
26780 6c 65 73 28 73 71 6c 69 74 65 33 2a 2c 49 6e 64 les(sqlite3*,Ind
26790 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ex*);.void sqlit
267a0 65 33 44 65 66 61 75 6c 74 52 6f 77 45 73 74 28 e3DefaultRowEst(
267b0 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 Index*);.void sq
267c0 6c 69 74 65 33 52 65 67 69 73 74 65 72 4c 69 6b lite3RegisterLik
267d0 65 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 eFunctions(sqlit
267e0 65 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 e3*, int);.int s
267f0 71 6c 69 74 65 33 49 73 4c 69 6b 65 46 75 6e 63 qlite3IsLikeFunc
26800 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 45 78 tion(sqlite3*,Ex
26810 70 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a 29 3b pr*,int*,char*);
26820 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 69 6e .void sqlite3Min
26830 69 6d 75 6d 46 69 6c 65 46 6f 72 6d 61 74 28 50 imumFileFormat(P
26840 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 arse*, int, int)
26850 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 ;.void sqlite3Sc
26860 68 65 6d 61 43 6c 65 61 72 28 76 6f 69 64 20 2a hemaClear(void *
26870 29 3b 0a 53 63 68 65 6d 61 20 2a 73 71 6c 69 74 );.Schema *sqlit
26880 65 33 53 63 68 65 6d 61 47 65 74 28 73 71 6c 69 e3SchemaGet(sqli
26890 74 65 33 20 2a 2c 20 42 74 72 65 65 20 2a 29 3b te3 *, Btree *);
268a0 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 63 68 65 .int sqlite3Sche
268b0 6d 61 54 6f 49 6e 64 65 78 28 73 71 6c 69 74 65 maToIndex(sqlite
268c0 33 20 2a 64 62 2c 20 53 63 68 65 6d 61 20 2a 29 3 *db, Schema *)
268d0 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 ;.KeyInfo *sqlit
268e0 65 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f 63 28 73 e3KeyInfoAlloc(s
268f0 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 6e 74 29 qlite3*,int,int)
26900 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4b 65 ;.void sqlite3Ke
26910 79 49 6e 66 6f 55 6e 72 65 66 28 4b 65 79 49 6e yInfoUnref(KeyIn
26920 66 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 fo*);.KeyInfo *s
26930 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f 52 65 66 qlite3KeyInfoRef
26940 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 (KeyInfo*);.KeyI
26950 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 nfo *sqlite3KeyI
26960 6e 66 6f 4f 66 49 6e 64 65 78 28 50 61 72 73 65 nfoOfIndex(Parse
26970 2a 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 69 66 64 *, Index*);.#ifd
26980 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a ef SQLITE_DEBUG.
26990 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 49 6e int sqlite3KeyIn
269a0 66 6f 49 73 57 72 69 74 65 61 62 6c 65 28 4b 65 foIsWriteable(Ke
269b0 79 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 66 0a yInfo*);.#endif.
269c0 69 6e 74 20 73 71 6c 69 74 65 33 43 72 65 61 74 int sqlite3Creat
269d0 65 46 75 6e 63 28 73 71 6c 69 74 65 33 20 2a 2c eFunc(sqlite3 *,
269e0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 const char *, i
269f0 6e 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 2a 2c nt, int, void *,
26a00 20 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 71 6c . void (*)(sql
26a10 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e ite3_context*,in
26a20 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 t,sqlite3_value
26a30 2a 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 **),. void (*)(
26a40 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
26a50 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c ,int,sqlite3_val
26a60 75 65 20 2a 2a 29 2c 20 76 6f 69 64 20 28 2a 29 ue **), void (*)
26a70 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
26a80 2a 29 2c 0a 20 20 46 75 6e 63 44 65 73 74 72 75 *),. FuncDestru
26a90 63 74 6f 72 20 2a 70 44 65 73 74 72 75 63 74 6f ctor *pDestructo
26aa0 72 0a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r.);.int sqlite3
26ab0 41 70 69 45 78 69 74 28 73 71 6c 69 74 65 33 20 ApiExit(sqlite3
26ac0 2a 64 62 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 *db, int);.int s
26ad0 71 6c 69 74 65 33 4f 70 65 6e 54 65 6d 70 44 61 qlite3OpenTempDa
26ae0 74 61 62 61 73 65 28 50 61 72 73 65 20 2a 29 3b tabase(Parse *);
26af0 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ..void sqlite3St
26b00 72 41 63 63 75 6d 49 6e 69 74 28 53 74 72 41 63 rAccumInit(StrAc
26b10 63 75 6d 2a 2c 20 73 71 6c 69 74 65 33 2a 2c 20 cum*, sqlite3*,
26b20 63 68 61 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 char*, int, int)
26b30 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ;.void sqlite3St
26b40 72 41 63 63 75 6d 41 70 70 65 6e 64 28 53 74 72 rAccumAppend(Str
26b50 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 Accum*,const cha
26b60 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 r*,int);.void sq
26b70 6c 69 74 65 33 53 74 72 41 63 63 75 6d 41 70 70 lite3StrAccumApp
26b80 65 6e 64 41 6c 6c 28 53 74 72 41 63 63 75 6d 2a endAll(StrAccum*
26b90 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
26ba0 6f 69 64 20 73 71 6c 69 74 65 33 41 70 70 65 6e oid sqlite3Appen
26bb0 64 43 68 61 72 28 53 74 72 41 63 63 75 6d 2a 2c dChar(StrAccum*,
26bc0 69 6e 74 2c 63 68 61 72 29 3b 0a 63 68 61 72 20 int,char);.char
26bd0 2a 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d *sqlite3StrAccum
26be0 46 69 6e 69 73 68 28 53 74 72 41 63 63 75 6d 2a Finish(StrAccum*
26bf0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
26c00 74 72 41 63 63 75 6d 52 65 73 65 74 28 53 74 72 trAccumReset(Str
26c10 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 Accum*);.void sq
26c20 6c 69 74 65 33 53 65 6c 65 63 74 44 65 73 74 49 lite3SelectDestI
26c30 6e 69 74 28 53 65 6c 65 63 74 44 65 73 74 2a 2c nit(SelectDest*,
26c40 69 6e 74 2c 69 6e 74 29 3b 0a 45 78 70 72 20 2a int,int);.Expr *
26c50 73 71 6c 69 74 65 33 43 72 65 61 74 65 43 6f 6c sqlite3CreateCol
26c60 75 6d 6e 45 78 70 72 28 73 71 6c 69 74 65 33 20 umnExpr(sqlite3
26c70 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 69 6e *, SrcList *, in
26c80 74 2c 20 69 6e 74 29 3b 0a 0a 76 6f 69 64 20 73 t, int);..void s
26c90 71 6c 69 74 65 33 42 61 63 6b 75 70 52 65 73 74 qlite3BackupRest
26ca0 61 72 74 28 73 71 6c 69 74 65 33 5f 62 61 63 6b art(sqlite3_back
26cb0 75 70 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 up *);.void sqli
26cc0 74 65 33 42 61 63 6b 75 70 55 70 64 61 74 65 28 te3BackupUpdate(
26cd0 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 20 2a sqlite3_backup *
26ce0 2c 20 50 67 6e 6f 2c 20 63 6f 6e 73 74 20 75 38 , Pgno, const u8
26cf0 20 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c *);..#ifdef SQL
26d00 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
26d10 5f 4f 52 5f 53 54 41 54 34 0a 76 6f 69 64 20 73 _OR_STAT4.void s
26d20 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 46 75 6e qlite3AnalyzeFun
26d30 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 6e ctions(void);.in
26d40 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 50 72 t sqlite3Stat4Pr
26d50 6f 62 65 53 65 74 56 61 6c 75 65 28 50 61 72 73 obeSetValue(Pars
26d60 65 2a 2c 49 6e 64 65 78 2a 2c 55 6e 70 61 63 6b e*,Index*,Unpack
26d70 65 64 52 65 63 6f 72 64 2a 2a 2c 45 78 70 72 2a edRecord**,Expr*
26d80 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a 69 ,u8,int,int*);.i
26d90 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 56 nt sqlite3Stat4V
26da0 61 6c 75 65 46 72 6f 6d 45 78 70 72 28 50 61 72 alueFromExpr(Par
26db0 73 65 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c 20 se*, Expr*, u8,
26dc0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 sqlite3_value**)
26dd0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ;.void sqlite3St
26de0 61 74 34 50 72 6f 62 65 46 72 65 65 28 55 6e 70 at4ProbeFree(Unp
26df0 61 63 6b 65 64 52 65 63 6f 72 64 2a 29 3b 0a 69 ackedRecord*);.i
26e00 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 43 nt sqlite3Stat4C
26e10 6f 6c 75 6d 6e 28 73 71 6c 69 74 65 33 2a 2c 20 olumn(sqlite3*,
26e20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 const void*, int
26e30 2c 20 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f 76 , int, sqlite3_v
26e40 61 6c 75 65 2a 2a 29 3b 0a 23 65 6e 64 69 66 0a alue**);.#endif.
26e50 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 ./*.** The inter
26e60 66 61 63 65 20 74 6f 20 74 68 65 20 4c 45 4d 4f face to the LEMO
26e70 4e 2d 67 65 6e 65 72 61 74 65 64 20 70 61 72 73 N-generated pars
26e80 65 72 0a 2a 2f 0a 76 6f 69 64 20 2a 73 71 6c 69 er.*/.void *sqli
26e90 74 65 33 50 61 72 73 65 72 41 6c 6c 6f 63 28 76 te3ParserAlloc(v
26ea0 6f 69 64 2a 28 2a 29 28 75 36 34 29 29 3b 0a 76 oid*(*)(u64));.v
26eb0 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 oid sqlite3Parse
26ec0 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 76 6f 69 rFree(void*, voi
26ed0 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f d(*)(void*));.vo
26ee0 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 id sqlite3Parser
26ef0 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 54 6f 6b (void*, int, Tok
26f00 65 6e 2c 20 50 61 72 73 65 2a 29 3b 0a 23 69 66 en, Parse*);.#if
26f10 64 65 66 20 59 59 54 52 41 43 4b 4d 41 58 53 54 def YYTRACKMAXST
26f20 41 43 4b 44 45 50 54 48 0a 20 20 69 6e 74 20 73 ACKDEPTH. int s
26f30 71 6c 69 74 65 33 50 61 72 73 65 72 53 74 61 63 qlite3ParserStac
26f40 6b 50 65 61 6b 28 76 6f 69 64 2a 29 3b 0a 23 65 kPeak(void*);.#e
26f50 6e 64 69 66 0a 0a 76 6f 69 64 20 73 71 6c 69 74 ndif..void sqlit
26f60 65 33 41 75 74 6f 4c 6f 61 64 45 78 74 65 6e 73 e3AutoLoadExtens
26f70 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a ions(sqlite3*);.
26f80 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
26f90 4d 49 54 5f 4c 4f 41 44 5f 45 58 54 45 4e 53 49 MIT_LOAD_EXTENSI
26fa0 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 ON. void sqlite
26fb0 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 6f 6e 73 3CloseExtensions
26fc0 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 65 6c 73 (sqlite3*);.#els
26fd0 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
26fe0 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 6f 6e e3CloseExtension
26ff0 73 28 58 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 s(X).#endif..#if
27000 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
27010 5f 53 48 41 52 45 44 5f 43 41 43 48 45 0a 20 20 _SHARED_CACHE.
27020 76 6f 69 64 20 73 71 6c 69 74 65 33 54 61 62 6c void sqlite3Tabl
27030 65 4c 6f 63 6b 28 50 61 72 73 65 20 2a 2c 20 69 eLock(Parse *, i
27040 6e 74 2c 20 69 6e 74 2c 20 75 38 2c 20 63 6f 6e nt, int, u8, con
27050 73 74 20 63 68 61 72 20 2a 29 3b 0a 23 65 6c 73 st char *);.#els
27060 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 e. #define sqli
27070 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 76 2c 77 te3TableLock(v,w
27080 2c 78 2c 79 2c 7a 29 0a 23 65 6e 64 69 66 0a 0a ,x,y,z).#endif..
27090 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 54 45 #ifdef SQLITE_TE
270a0 53 54 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ST. int sqlite3
270b0 55 74 66 38 54 6f 38 28 75 6e 73 69 67 6e 65 64 Utf8To8(unsigned
270c0 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a char*);.#endif.
270d0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 4f .#ifdef SQLITE_O
270e0 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
270f0 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
27100 65 33 56 74 61 62 43 6c 65 61 72 28 59 29 0a 23 e3VtabClear(Y).#
27110 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
27120 56 74 61 62 53 79 6e 63 28 58 2c 59 29 20 53 51 VtabSync(X,Y) SQ
27130 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 65 66 69 6e LITE_OK.# defin
27140 65 20 73 71 6c 69 74 65 33 56 74 61 62 52 6f 6c e sqlite3VtabRol
27150 6c 62 61 63 6b 28 58 29 0a 23 20 20 64 65 66 69 lback(X).# defi
27160 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f ne sqlite3VtabCo
27170 6d 6d 69 74 28 58 29 0a 23 20 20 64 65 66 69 6e mmit(X).# defin
27180 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 6e 53 e sqlite3VtabInS
27190 79 6e 63 28 64 62 29 20 30 0a 23 20 20 64 65 66 ync(db) 0.# def
271a0 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 4c ine sqlite3VtabL
271b0 6f 63 6b 28 58 29 20 0a 23 20 20 64 65 66 69 6e ock(X) .# defin
271c0 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c e sqlite3VtabUnl
271d0 6f 63 6b 28 58 29 0a 23 20 20 64 65 66 69 6e 65 ock(X).# define
271e0 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
271f0 63 6b 4c 69 73 74 28 58 29 0a 23 20 20 64 65 66 ckList(X).# def
27200 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 53 ine sqlite3VtabS
27210 61 76 65 70 6f 69 6e 74 28 58 2c 20 59 2c 20 5a avepoint(X, Y, Z
27220 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 ) SQLITE_OK.# d
27230 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 65 74 efine sqlite3Get
27240 56 54 61 62 6c 65 28 58 2c 59 29 20 20 28 28 56 VTable(X,Y) ((V
27250 54 61 62 6c 65 2a 29 30 29 0a 23 65 6c 73 65 0a Table*)0).#else.
27260 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 void sqlite3V
27270 74 61 62 43 6c 65 61 72 28 73 71 6c 69 74 65 33 tabClear(sqlite3
27280 20 2a 64 62 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 *db, Table*);.
27290 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 void sqlite3Vt
272a0 61 62 44 69 73 63 6f 6e 6e 65 63 74 28 73 71 6c abDisconnect(sql
272b0 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 20 ite3 *db, Table
272c0 2a 70 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 *p);. int sqli
272d0 74 65 33 56 74 61 62 53 79 6e 63 28 73 71 6c 69 te3VtabSync(sqli
272e0 74 65 33 20 2a 64 62 2c 20 56 64 62 65 2a 29 3b te3 *db, Vdbe*);
272f0 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 . int sqlite3V
27300 74 61 62 52 6f 6c 6c 62 61 63 6b 28 73 71 6c 69 tabRollback(sqli
27310 74 65 33 20 2a 64 62 29 3b 0a 20 20 20 69 6e 74 te3 *db);. int
27320 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f 6d 6d sqlite3VtabComm
27330 69 74 28 73 71 6c 69 74 65 33 20 2a 64 62 29 3b it(sqlite3 *db);
27340 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
27350 56 74 61 62 4c 6f 63 6b 28 56 54 61 62 6c 65 20 VtabLock(VTable
27360 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 *);. void sqli
27370 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 28 56 54 te3VtabUnlock(VT
27380 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 able *);. void
27390 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
273a0 63 6b 4c 69 73 74 28 73 71 6c 69 74 65 33 2a 29 ckList(sqlite3*)
273b0 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ;. int sqlite3
273c0 56 74 61 62 53 61 76 65 70 6f 69 6e 74 28 73 71 VtabSavepoint(sq
273d0 6c 69 74 65 33 20 2a 2c 20 69 6e 74 2c 20 69 6e lite3 *, int, in
273e0 74 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 t);. void sqli
273f0 74 65 33 56 74 61 62 49 6d 70 6f 72 74 45 72 72 te3VtabImportErr
27400 6d 73 67 28 56 64 62 65 2a 2c 20 73 71 6c 69 74 msg(Vdbe*, sqlit
27410 65 33 5f 76 74 61 62 2a 29 3b 0a 20 20 20 56 54 e3_vtab*);. VT
27420 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 47 65 74 able *sqlite3Get
27430 56 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c VTable(sqlite3*,
27440 20 54 61 62 6c 65 2a 29 3b 0a 23 20 20 64 65 66 Table*);.# def
27450 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 ine sqlite3VtabI
27460 6e 53 79 6e 63 28 64 62 29 20 28 28 64 62 29 2d nSync(db) ((db)-
27470 3e 6e 56 54 72 61 6e 73 3e 30 20 26 26 20 28 64 >nVTrans>0 && (d
27480 62 29 2d 3e 61 56 54 72 61 6e 73 3d 3d 30 29 0a b)->aVTrans==0).
27490 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
274a0 74 65 33 56 74 61 62 4d 61 6b 65 57 72 69 74 61 te3VtabMakeWrita
274b0 62 6c 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 ble(Parse*,Table
274c0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
274d0 56 74 61 62 42 65 67 69 6e 50 61 72 73 65 28 50 VtabBeginParse(P
274e0 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
274f0 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 69 oken*, Token*, i
27500 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27510 33 56 74 61 62 46 69 6e 69 73 68 50 61 72 73 65 3VtabFinishParse
27520 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 (Parse*, Token*)
27530 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 ;.void sqlite3Vt
27540 61 62 41 72 67 49 6e 69 74 28 50 61 72 73 65 2a abArgInit(Parse*
27550 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
27560 74 61 62 41 72 67 45 78 74 65 6e 64 28 50 61 72 tabArgExtend(Par
27570 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e se*, Token*);.in
27580 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 61 6c t sqlite3VtabCal
27590 6c 43 72 65 61 74 65 28 73 71 6c 69 74 65 33 2a lCreate(sqlite3*
275a0 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 , int, const cha
275b0 72 20 2a 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 69 r *, char **);.i
275c0 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 61 nt sqlite3VtabCa
275d0 6c 6c 43 6f 6e 6e 65 63 74 28 50 61 72 73 65 2a llConnect(Parse*
275e0 2c 20 54 61 62 6c 65 2a 29 3b 0a 69 6e 74 20 73 , Table*);.int s
275f0 71 6c 69 74 65 33 56 74 61 62 43 61 6c 6c 44 65 qlite3VtabCallDe
27600 73 74 72 6f 79 28 73 71 6c 69 74 65 33 2a 2c 20 stroy(sqlite3*,
27610 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 int, const char
27620 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 *);.int sqlite3V
27630 74 61 62 42 65 67 69 6e 28 73 71 6c 69 74 65 33 tabBegin(sqlite3
27640 20 2a 2c 20 56 54 61 62 6c 65 20 2a 29 3b 0a 46 *, VTable *);.F
27650 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 65 33 56 uncDef *sqlite3V
27660 74 61 62 4f 76 65 72 6c 6f 61 64 46 75 6e 63 74 tabOverloadFunct
27670 69 6f 6e 28 73 71 6c 69 74 65 33 20 2a 2c 46 75 ion(sqlite3 *,Fu
27680 6e 63 44 65 66 2a 2c 20 69 6e 74 20 6e 41 72 67 ncDef*, int nArg
27690 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
276a0 71 6c 69 74 65 33 49 6e 76 61 6c 69 64 46 75 6e qlite3InvalidFun
276b0 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 5f 63 6f ction(sqlite3_co
276c0 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 ntext*,int,sqlit
276d0 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 73 71 6c e3_value**);.sql
276e0 69 74 65 33 5f 69 6e 74 36 34 20 73 71 6c 69 74 ite3_int64 sqlit
276f0 65 33 53 74 6d 74 43 75 72 72 65 6e 74 54 69 6d e3StmtCurrentTim
27700 65 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 e(sqlite3_contex
27710 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
27720 56 64 62 65 50 61 72 61 6d 65 74 65 72 49 6e 64 VdbeParameterInd
27730 65 78 28 56 64 62 65 2a 2c 20 63 6f 6e 73 74 20 ex(Vdbe*, const
27740 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 char*, int);.int
27750 20 73 71 6c 69 74 65 33 54 72 61 6e 73 66 65 72 sqlite3Transfer
27760 42 69 6e 64 69 6e 67 73 28 73 71 6c 69 74 65 33 Bindings(sqlite3
27770 5f 73 74 6d 74 20 2a 2c 20 73 71 6c 69 74 65 33 _stmt *, sqlite3
27780 5f 73 74 6d 74 20 2a 29 3b 0a 76 6f 69 64 20 73 _stmt *);.void s
27790 71 6c 69 74 65 33 50 61 72 73 65 72 52 65 73 65 qlite3ParserRese
277a0 74 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 t(Parse*);.int s
277b0 71 6c 69 74 65 33 52 65 70 72 65 70 61 72 65 28 qlite3Reprepare(
277c0 56 64 62 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Vdbe*);.void sql
277d0 69 74 65 33 45 78 70 72 4c 69 73 74 43 68 65 63 ite3ExprListChec
277e0 6b 4c 65 6e 67 74 68 28 50 61 72 73 65 2a 2c 20 kLength(Parse*,
277f0 45 78 70 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 74 ExprList*, const
27800 20 63 68 61 72 2a 29 3b 0a 43 6f 6c 6c 53 65 71 char*);.CollSeq
27810 20 2a 73 71 6c 69 74 65 33 42 69 6e 61 72 79 43 *sqlite3BinaryC
27820 6f 6d 70 61 72 65 43 6f 6c 6c 53 65 71 28 50 61 ompareCollSeq(Pa
27830 72 73 65 20 2a 2c 20 45 78 70 72 20 2a 2c 20 45 rse *, Expr *, E
27840 78 70 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 xpr *);.int sqli
27850 74 65 33 54 65 6d 70 49 6e 4d 65 6d 6f 72 79 28 te3TempInMemory(
27860 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 2a 29 3b const sqlite3*);
27870 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c .const char *sql
27880 69 74 65 33 4a 6f 75 72 6e 61 6c 4d 6f 64 65 6e ite3JournalModen
27890 61 6d 65 28 69 6e 74 29 3b 0a 23 69 66 6e 64 65 ame(int);.#ifnde
278a0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 41 f SQLITE_OMIT_WA
278b0 4c 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 43 L. int sqlite3C
278c0 68 65 63 6b 70 6f 69 6e 74 28 73 71 6c 69 74 65 heckpoint(sqlite
278d0 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 3*, int, int, in
278e0 74 2a 2c 20 69 6e 74 2a 29 3b 0a 20 20 69 6e 74 t*, int*);. int
278f0 20 73 71 6c 69 74 65 33 57 61 6c 44 65 66 61 75 sqlite3WalDefau
27900 6c 74 48 6f 6f 6b 28 76 6f 69 64 2a 2c 73 71 6c ltHook(void*,sql
27910 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 ite3*,const char
27920 2a 2c 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 23 *,int);.#endif.#
27930 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
27940 49 54 5f 43 54 45 0a 20 20 57 69 74 68 20 2a 73 IT_CTE. With *s
27950 71 6c 69 74 65 33 57 69 74 68 41 64 64 28 50 61 qlite3WithAdd(Pa
27960 72 73 65 2a 2c 57 69 74 68 2a 2c 54 6f 6b 65 6e rse*,With*,Token
27970 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 65 6c 65 *,ExprList*,Sele
27980 63 74 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c ct*);. void sql
27990 69 74 65 33 57 69 74 68 44 65 6c 65 74 65 28 73 ite3WithDelete(s
279a0 71 6c 69 74 65 33 2a 2c 57 69 74 68 2a 29 3b 0a qlite3*,With*);.
279b0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 void sqlite3Wi
279c0 74 68 50 75 73 68 28 50 61 72 73 65 2a 2c 20 57 thPush(Parse*, W
279d0 69 74 68 2a 2c 20 75 38 29 3b 0a 23 65 6c 73 65 ith*, u8);.#else
279e0 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 .#define sqlite3
279f0 57 69 74 68 50 75 73 68 28 78 2c 79 2c 7a 29 0a WithPush(x,y,z).
27a00 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 57 #define sqlite3W
27a10 69 74 68 44 65 6c 65 74 65 28 78 2c 79 29 0a 23 ithDelete(x,y).#
27a20 65 6e 64 69 66 0a 0a 2f 2a 20 44 65 63 6c 61 72 endif../* Declar
27a30 61 74 69 6f 6e 73 20 66 6f 72 20 66 75 6e 63 74 ations for funct
27a40 69 6f 6e 73 20 69 6e 20 66 6b 65 79 2e 63 2e 20 ions in fkey.c.
27a50 41 6c 6c 20 6f 66 20 74 68 65 73 65 20 61 72 65 All of these are
27a60 20 72 65 70 6c 61 63 65 64 20 62 79 0a 2a 2a 20 replaced by.**
27a70 6e 6f 2d 6f 70 20 6d 61 63 72 6f 73 20 69 66 20 no-op macros if
27a80 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 OMIT_FOREIGN_KEY
27a90 20 69 73 20 64 65 66 69 6e 65 64 2e 20 49 6e 20 is defined. In
27aa0 74 68 69 73 20 63 61 73 65 20 6e 6f 20 66 6f 72 this case no for
27ab0 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 66 75 6e 63 eign.** key func
27ac0 74 69 6f 6e 61 6c 69 74 79 20 69 73 20 61 76 61 tionality is ava
27ad0 69 6c 61 62 6c 65 2e 20 49 66 20 4f 4d 49 54 5f ilable. If OMIT_
27ae0 54 52 49 47 47 45 52 20 69 73 20 64 65 66 69 6e TRIGGER is defin
27af0 65 64 20 62 75 74 0a 2a 2a 20 4f 4d 49 54 5f 46 ed but.** OMIT_F
27b00 4f 52 45 49 47 4e 5f 4b 45 59 20 69 73 20 6e 6f OREIGN_KEY is no
27b10 74 2c 20 6f 6e 6c 79 20 73 6f 6d 65 20 6f 66 20 t, only some of
27b20 74 68 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 the functions ar
27b30 65 20 6e 6f 2d 6f 70 65 64 2e 20 49 6e 0a 2a 2a e no-oped. In.**
27b40 20 74 68 69 73 20 63 61 73 65 20 66 6f 72 65 69 this case forei
27b50 67 6e 20 6b 65 79 73 20 61 72 65 20 70 61 72 73 gn keys are pars
27b60 65 64 2c 20 62 75 74 20 6e 6f 20 6f 74 68 65 72 ed, but no other
27b70 20 66 75 6e 63 74 69 6f 6e 61 6c 69 74 79 20 69 functionality i
27b80 73 20 0a 2a 2a 20 70 72 6f 76 69 64 65 64 20 28 s .** provided (
27b90 65 6e 66 6f 72 63 65 6d 65 6e 74 20 6f 66 20 46 enforcement of F
27ba0 4b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 72 65 K constraints re
27bb0 71 75 69 72 65 73 20 74 68 65 20 74 72 69 67 67 quires the trigg
27bc0 65 72 73 20 73 75 62 2d 73 79 73 74 65 6d 29 2e ers sub-system).
27bd0 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 .*/.#if !defined
27be0 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 (SQLITE_OMIT_FOR
27bf0 45 49 47 4e 5f 4b 45 59 29 20 26 26 20 21 64 65 EIGN_KEY) && !de
27c00 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 fined(SQLITE_OMI
27c10 54 5f 54 52 49 47 47 45 52 29 0a 20 20 76 6f 69 T_TRIGGER). voi
27c20 64 20 73 71 6c 69 74 65 33 46 6b 43 68 65 63 6b d sqlite3FkCheck
27c30 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
27c40 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c int, int, int*,
27c50 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 int);. void sq
27c60 6c 69 74 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 lite3FkDropTable
27c70 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
27c80 20 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 76 *, Table*);. v
27c90 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 41 63 74 oid sqlite3FkAct
27ca0 69 6f 6e 73 28 50 61 72 73 65 2a 2c 20 54 61 62 ions(Parse*, Tab
27cb0 6c 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 le*, ExprList*,
27cc0 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b int, int*, int);
27cd0 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 6b . int sqlite3Fk
27ce0 52 65 71 75 69 72 65 64 28 50 61 72 73 65 2a 2c Required(Parse*,
27cf0 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2a 2c 20 69 Table*, int*, i
27d00 6e 74 29 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 nt);. u32 sqlit
27d10 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 50 61 72 73 e3FkOldmask(Pars
27d20 65 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 46 e*, Table*);. F
27d30 4b 65 79 20 2a 73 71 6c 69 74 65 33 46 6b 52 65 Key *sqlite3FkRe
27d40 66 65 72 65 6e 63 65 73 28 54 61 62 6c 65 20 2a ferences(Table *
27d50 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 );.#else. #defi
27d60 6e 65 20 73 71 6c 69 74 65 33 46 6b 41 63 74 69 ne sqlite3FkActi
27d70 6f 6e 73 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 ons(a,b,c,d,e,f)
27d80 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
27d90 65 33 46 6b 43 68 65 63 6b 28 61 2c 62 2c 63 2c e3FkCheck(a,b,c,
27da0 64 2c 65 2c 66 29 0a 20 20 23 64 65 66 69 6e 65 d,e,f). #define
27db0 20 73 71 6c 69 74 65 33 46 6b 44 72 6f 70 54 61 sqlite3FkDropTa
27dc0 62 6c 65 28 61 2c 62 2c 63 29 0a 20 20 23 64 65 ble(a,b,c). #de
27dd0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 4f 6c fine sqlite3FkOl
27de0 64 6d 61 73 6b 28 61 2c 62 29 20 20 20 20 20 20 dmask(a,b)
27df0 20 20 20 30 0a 20 20 23 64 65 66 69 6e 65 20 73 0. #define s
27e00 71 6c 69 74 65 33 46 6b 52 65 71 75 69 72 65 64 qlite3FkRequired
27e10 28 61 2c 62 2c 63 2c 64 29 20 20 20 20 30 0a 23 (a,b,c,d) 0.#
27e20 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 endif.#ifndef SQ
27e30 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 LITE_OMIT_FOREIG
27e40 4e 5f 4b 45 59 0a 20 20 76 6f 69 64 20 73 71 6c N_KEY. void sql
27e50 69 74 65 33 46 6b 44 65 6c 65 74 65 28 73 71 6c ite3FkDelete(sql
27e60 69 74 65 33 20 2a 2c 20 54 61 62 6c 65 2a 29 3b ite3 *, Table*);
27e70 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 6b . int sqlite3Fk
27e80 4c 6f 63 61 74 65 49 6e 64 65 78 28 50 61 72 73 LocateIndex(Pars
27e90 65 2a 2c 54 61 62 6c 65 2a 2c 46 4b 65 79 2a 2c e*,Table*,FKey*,
27ea0 49 6e 64 65 78 2a 2a 2c 69 6e 74 2a 2a 29 3b 0a Index**,int**);.
27eb0 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
27ec0 73 71 6c 69 74 65 33 46 6b 44 65 6c 65 74 65 28 sqlite3FkDelete(
27ed0 61 2c 62 29 0a 20 20 23 64 65 66 69 6e 65 20 73 a,b). #define s
27ee0 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e qlite3FkLocateIn
27ef0 64 65 78 28 61 2c 62 2c 63 2c 64 2c 65 29 0a 23 dex(a,b,c,d,e).#
27f00 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 41 76 endif.../*.** Av
27f10 61 69 6c 61 62 6c 65 20 66 61 75 6c 74 20 69 6e ailable fault in
27f20 6a 65 63 74 6f 72 73 2e 20 20 53 68 6f 75 6c 64 jectors. Should
27f30 20 62 65 20 6e 75 6d 62 65 72 65 64 20 62 65 67 be numbered beg
27f40 69 6e 6e 69 6e 67 20 77 69 74 68 20 30 2e 0a 2a inning with 0..*
27f50 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
27f60 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 4d _FAULTINJECTOR_M
27f70 41 4c 4c 4f 43 20 20 20 20 20 30 0a 23 64 65 66 ALLOC 0.#def
27f80 69 6e 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 ine SQLITE_FAULT
27f90 49 4e 4a 45 43 54 4f 52 5f 43 4f 55 4e 54 20 20 INJECTOR_COUNT
27fa0 20 20 20 20 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 1../*.** The
27fb0 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 74 68 interface to th
27fc0 65 20 63 6f 64 65 20 69 6e 20 66 61 75 6c 74 2e e code in fault.
27fd0 63 20 75 73 65 64 20 66 6f 72 20 69 64 65 6e 74 c used for ident
27fe0 69 66 79 69 6e 67 20 22 62 65 6e 69 67 6e 22 0a ifying "benign".
27ff0 2a 2a 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 ** malloc failur
28000 65 73 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 es. This is only
28010 20 70 72 65 73 65 6e 74 20 69 66 20 53 51 4c 49 present if SQLI
28020 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f TE_OMIT_BUILTIN_
28030 54 45 53 54 0a 2a 2a 20 69 73 20 6e 6f 74 20 64 TEST.** is not d
28040 65 66 69 6e 65 64 2e 0a 2a 2f 0a 23 69 66 6e 64 efined..*/.#ifnd
28050 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 ef SQLITE_OMIT_B
28060 55 49 4c 54 49 4e 5f 54 45 53 54 0a 20 20 76 6f UILTIN_TEST. vo
28070 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 6e 42 id sqlite3BeginB
28080 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 enignMalloc(void
28090 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
280a0 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3EndBenignMalloc
280b0 28 76 6f 69 64 29 3b 0a 23 65 6c 73 65 0a 20 20 (void);.#else.
280c0 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 42 #define sqlite3B
280d0 65 67 69 6e 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 eginBenignMalloc
280e0 28 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c (). #define sql
280f0 69 74 65 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c ite3EndBenignMal
28100 6c 6f 63 28 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a loc().#endif../*
28110 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 .** Allowed retu
28120 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 rn values from s
28130 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 qlite3FindInInde
28140 78 28 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 x().*/.#define I
28150 4e 5f 49 4e 44 45 58 5f 52 4f 57 49 44 20 20 20 N_INDEX_ROWID
28160 20 20 20 20 20 31 20 20 20 2f 2a 20 53 65 61 72 1 /* Sear
28170 63 68 20 74 68 65 20 72 6f 77 69 64 20 6f 66 20 ch the rowid of
28180 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 the table */.#de
28190 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 45 50 fine IN_INDEX_EP
281a0 48 20 20 20 20 20 20 20 20 20 20 32 20 20 20 2f H 2 /
281b0 2a 20 53 65 61 72 63 68 20 61 6e 20 65 70 68 65 * Search an ephe
281c0 6d 65 72 61 6c 20 62 2d 74 72 65 65 20 2a 2f 0a meral b-tree */.
281d0 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 #define IN_INDEX
281e0 5f 49 4e 44 45 58 5f 41 53 43 20 20 20 20 33 20 _INDEX_ASC 3
281f0 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 20 69 6e /* Existing in
28200 64 65 78 20 41 53 43 45 4e 44 49 4e 47 20 2a 2f dex ASCENDING */
28210 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 .#define IN_INDE
28220 58 5f 49 4e 44 45 58 5f 44 45 53 43 20 20 20 34 X_INDEX_DESC 4
28230 20 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 20 69 /* Existing i
28240 6e 64 65 78 20 44 45 53 43 45 4e 44 49 4e 47 20 ndex DESCENDING
28250 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
28260 44 45 58 5f 4e 4f 4f 50 20 20 20 20 20 20 20 20 DEX_NOOP
28270 20 35 20 20 20 2f 2a 20 4e 6f 20 74 61 62 6c 65 5 /* No table
28280 20 61 76 61 69 6c 61 62 6c 65 2e 20 55 73 65 20 available. Use
28290 63 6f 6d 70 61 72 69 73 6f 6e 73 20 2a 2f 0a 2f comparisons */./
282a0 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 66 6c 61 *.** Allowed fla
282b0 67 73 20 66 6f 72 20 74 68 65 20 33 72 64 20 70 gs for the 3rd p
282c0 61 72 61 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 arameter to sqli
282d0 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 te3FindInIndex()
282e0 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f ..*/.#define IN_
282f0 49 4e 44 45 58 5f 4e 4f 4f 50 5f 4f 4b 20 20 20 INDEX_NOOP_OK
28300 20 20 30 78 30 30 30 31 20 20 2f 2a 20 4f 4b 20 0x0001 /* OK
28310 74 6f 20 72 65 74 75 72 6e 20 49 4e 5f 49 4e 44 to return IN_IND
28320 45 58 5f 4e 4f 4f 50 20 2a 2f 0a 23 64 65 66 69 EX_NOOP */.#defi
28330 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4d 45 4d 42 ne IN_INDEX_MEMB
28340 45 52 53 48 49 50 20 20 30 78 30 30 30 32 20 20 ERSHIP 0x0002
28350 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 /* IN operator u
28360 73 65 64 20 66 6f 72 20 6d 65 6d 62 65 72 73 68 sed for membersh
28370 69 70 20 74 65 73 74 20 2a 2f 0a 23 64 65 66 69 ip test */.#defi
28380 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4c 4f 4f 50 ne IN_INDEX_LOOP
28390 20 20 20 20 20 20 20 20 30 78 30 30 30 34 20 20 0x0004
283a0 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 /* IN operator u
283b0 73 65 64 20 61 73 20 61 20 6c 6f 6f 70 20 2a 2f sed as a loop */
283c0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 6e 64 .int sqlite3Find
283d0 49 6e 49 6e 64 65 78 28 50 61 72 73 65 20 2a 2c InIndex(Parse *,
283e0 20 45 78 70 72 20 2a 2c 20 75 33 32 2c 20 69 6e Expr *, u32, in
283f0 74 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c t*);..#ifdef SQL
28400 49 54 45 5f 45 4e 41 42 4c 45 5f 41 54 4f 4d 49 ITE_ENABLE_ATOMI
28410 43 5f 57 52 49 54 45 0a 20 20 69 6e 74 20 73 71 C_WRITE. int sq
28420 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e lite3JournalOpen
28430 28 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 2c 20 (sqlite3_vfs *,
28440 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 73 71 const char *, sq
28450 6c 69 74 65 33 5f 66 69 6c 65 20 2a 2c 20 69 6e lite3_file *, in
28460 74 2c 20 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 t, int);. int s
28470 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 53 69 7a qlite3JournalSiz
28480 65 28 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 29 e(sqlite3_vfs *)
28490 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a ;. int sqlite3J
284a0 6f 75 72 6e 61 6c 43 72 65 61 74 65 28 73 71 6c ournalCreate(sql
284b0 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 20 20 ite3_file *);.
284c0 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e int sqlite3Journ
284d0 61 6c 45 78 69 73 74 73 28 73 71 6c 69 74 65 33 alExists(sqlite3
284e0 5f 66 69 6c 65 20 2a 70 29 3b 0a 23 65 6c 73 65 _file *p);.#else
284f0 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
28500 65 33 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 70 56 e3JournalSize(pV
28510 66 73 29 20 28 28 70 56 66 73 29 2d 3e 73 7a 4f fs) ((pVfs)->szO
28520 73 46 69 6c 65 29 0a 20 20 23 64 65 66 69 6e 65 sFile). #define
28530 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 45 sqlite3JournalE
28540 78 69 73 74 73 28 70 29 20 31 0a 23 65 6e 64 69 xists(p) 1.#endi
28550 66 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d f..void sqlite3M
28560 65 6d 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 emJournalOpen(sq
28570 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 69 lite3_file *);.i
28580 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 4a 6f 75 nt sqlite3MemJou
28590 72 6e 61 6c 53 69 7a 65 28 76 6f 69 64 29 3b 0a rnalSize(void);.
285a0 69 6e 74 20 73 71 6c 69 74 65 33 49 73 4d 65 6d int sqlite3IsMem
285b0 4a 6f 75 72 6e 61 6c 28 73 71 6c 69 74 65 33 5f Journal(sqlite3_
285c0 66 69 6c 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 file *);..void s
285d0 71 6c 69 74 65 33 45 78 70 72 53 65 74 48 65 69 qlite3ExprSetHei
285e0 67 68 74 41 6e 64 46 6c 61 67 73 28 50 61 72 73 ghtAndFlags(Pars
285f0 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 20 e *pParse, Expr
28600 2a 70 29 3b 0a 23 69 66 20 53 51 4c 49 54 45 5f *p);.#if SQLITE_
28610 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 MAX_EXPR_DEPTH>0
28620 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 53 65 . int sqlite3Se
28630 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 28 53 lectExprHeight(S
28640 65 6c 65 63 74 20 2a 29 3b 0a 20 20 69 6e 74 20 elect *);. int
28650 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b sqlite3ExprCheck
28660 48 65 69 67 68 74 28 50 61 72 73 65 2a 2c 20 69 Height(Parse*, i
28670 6e 74 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 nt);.#else. #de
28680 66 69 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 fine sqlite3Sele
28690 63 74 45 78 70 72 48 65 69 67 68 74 28 78 29 20 ctExprHeight(x)
286a0 30 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 0. #define sqli
286b0 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 69 67 te3ExprCheckHeig
286c0 68 74 28 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a ht(x,y).#endif..
286d0 75 33 32 20 73 71 6c 69 74 65 33 47 65 74 34 62 u32 sqlite3Get4b
286e0 79 74 65 28 63 6f 6e 73 74 20 75 38 2a 29 3b 0a yte(const u8*);.
286f0 76 6f 69 64 20 73 71 6c 69 74 65 33 50 75 74 34 void sqlite3Put4
28700 62 79 74 65 28 75 38 2a 2c 20 75 33 32 29 3b 0a byte(u8*, u32);.
28710 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
28720 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 NABLE_UNLOCK_NOT
28730 49 46 59 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 IFY. void sqlit
28740 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 e3ConnectionBloc
28750 6b 65 64 28 73 71 6c 69 74 65 33 20 2a 2c 20 73 ked(sqlite3 *, s
28760 71 6c 69 74 65 33 20 2a 29 3b 0a 20 20 76 6f 69 qlite3 *);. voi
28770 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 d sqlite3Connect
28780 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 73 71 6c 69 ionUnlocked(sqli
28790 74 65 33 20 2a 64 62 29 3b 0a 20 20 76 6f 69 64 te3 *db);. void
287a0 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 sqlite3Connecti
287b0 6f 6e 43 6c 6f 73 65 64 28 73 71 6c 69 74 65 33 onClosed(sqlite3
287c0 20 2a 64 62 29 3b 0a 23 65 6c 73 65 0a 20 20 23 *db);.#else. #
287d0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f define sqlite3Co
287e0 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 64 28 nnectionBlocked(
287f0 78 2c 79 29 0a 20 20 23 64 65 66 69 6e 65 20 73 x,y). #define s
28800 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
28810 55 6e 6c 6f 63 6b 65 64 28 78 29 0a 20 20 23 64 Unlocked(x). #d
28820 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e efine sqlite3Con
28830 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 78 29 nectionClosed(x)
28840 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
28850 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 20 76 SQLITE_DEBUG. v
28860 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 oid sqlite3Parse
28870 72 54 72 61 63 65 28 46 49 4c 45 2a 2c 20 63 68 rTrace(FILE*, ch
28880 61 72 20 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f ar *);.#endif../
28890 2a 0a 2a 2a 20 49 66 20 74 68 65 20 53 51 4c 49 *.** If the SQLI
288a0 54 45 5f 45 4e 41 42 4c 45 20 49 4f 54 52 41 43 TE_ENABLE IOTRAC
288b0 45 20 65 78 69 73 74 73 20 74 68 65 6e 20 74 68 E exists then th
288c0 65 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c e global variabl
288d0 65 0a 2a 2a 20 73 71 6c 69 74 65 33 49 6f 54 72 e.** sqlite3IoTr
288e0 61 63 65 20 69 73 20 61 20 70 6f 69 6e 74 65 72 ace is a pointer
288f0 20 74 6f 20 61 20 70 72 69 6e 74 66 2d 6c 69 6b to a printf-lik
28900 65 20 72 6f 75 74 69 6e 65 20 75 73 65 64 20 74 e routine used t
28910 6f 0a 2a 2a 20 70 72 69 6e 74 20 49 2f 4f 20 74 o.** print I/O t
28920 72 61 63 69 6e 67 20 6d 65 73 73 61 67 65 73 2e racing messages.
28930 20 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 .*/.#ifdef SQLI
28940 54 45 5f 45 4e 41 42 4c 45 5f 49 4f 54 52 41 43 TE_ENABLE_IOTRAC
28950 45 0a 23 20 64 65 66 69 6e 65 20 49 4f 54 52 41 E.# define IOTRA
28960 43 45 28 41 29 20 20 69 66 28 20 73 71 6c 69 74 CE(A) if( sqlit
28970 65 33 49 6f 54 72 61 63 65 20 29 7b 20 73 71 6c e3IoTrace ){ sql
28980 69 74 65 33 49 6f 54 72 61 63 65 20 41 3b 20 7d ite3IoTrace A; }
28990 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 . void sqlite3V
289a0 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 56 64 dbeIOTraceSql(Vd
289b0 62 65 2a 29 3b 0a 53 51 4c 49 54 45 5f 41 50 49 be*);.SQLITE_API
289c0 20 53 51 4c 49 54 45 5f 45 58 54 45 52 4e 20 76 SQLITE_EXTERN v
289d0 6f 69 64 20 28 53 51 4c 49 54 45 5f 43 44 45 43 oid (SQLITE_CDEC
289e0 4c 20 2a 73 71 6c 69 74 65 33 49 6f 54 72 61 63 L *sqlite3IoTrac
289f0 65 29 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e e)(const char*,.
28a00 2e 2e 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 ..);.#else.# def
28a10 69 6e 65 20 49 4f 54 52 41 43 45 28 41 29 0a 23 ine IOTRACE(A).#
28a20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
28a30 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 58 29 dbeIOTraceSql(X)
28a40 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
28a50 68 65 73 65 20 72 6f 75 74 69 6e 65 73 20 61 72 hese routines ar
28a60 65 20 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 e available for
28a70 74 68 65 20 6d 65 6d 32 2e 63 20 64 65 62 75 67 the mem2.c debug
28a80 67 69 6e 67 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f ging memory allo
28a90 63 61 74 6f 72 0a 2a 2a 20 6f 6e 6c 79 2e 20 20 cator.** only.
28aa0 54 68 65 79 20 61 72 65 20 75 73 65 64 20 74 6f They are used to
28ab0 20 76 65 72 69 66 79 20 74 68 61 74 20 64 69 66 verify that dif
28ac0 66 65 72 65 6e 74 20 22 74 79 70 65 73 22 20 6f ferent "types" o
28ad0 66 20 6d 65 6d 6f 72 79 0a 2a 2a 20 61 6c 6c 6f f memory.** allo
28ae0 63 61 74 69 6f 6e 73 20 61 72 65 20 70 72 6f 70 cations are prop
28af0 65 72 6c 79 20 74 72 61 63 6b 65 64 20 62 79 20 erly tracked by
28b00 74 68 65 20 73 79 73 74 65 6d 2e 0a 2a 2a 0a 2a the system..**.*
28b10 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 * sqlite3Memdebu
28b20 67 53 65 74 54 79 70 65 28 29 20 73 65 74 73 20 gSetType() sets
28b30 74 68 65 20 22 74 79 70 65 22 20 6f 66 20 61 6e the "type" of an
28b40 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 74 6f 20 6f allocation to o
28b50 6e 65 20 6f 66 0a 2a 2a 20 74 68 65 20 4d 45 4d ne of.** the MEM
28b60 54 59 50 45 5f 2a 20 6d 61 63 72 6f 73 20 64 65 TYPE_* macros de
28b70 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 20 54 68 fined below. Th
28b80 65 20 74 79 70 65 20 6d 75 73 74 20 62 65 20 61 e type must be a
28b90 20 62 69 74 6d 61 73 6b 20 77 69 74 68 0a 2a 2a bitmask with.**
28ba0 20 61 20 73 69 6e 67 6c 65 20 62 69 74 20 73 65 a single bit se
28bb0 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 t..**.** sqlite3
28bc0 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 MemdebugHasType(
28bd0 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 69 ) returns true i
28be0 66 20 61 6e 79 20 6f 66 20 74 68 65 20 62 69 74 f any of the bit
28bf0 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e 64 0a s in its second.
28c00 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 74 63 ** argument matc
28c10 68 20 74 68 65 20 74 79 70 65 20 73 65 74 20 62 h the type set b
28c20 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 73 y the previous s
28c30 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 qlite3MemdebugSe
28c40 74 54 79 70 65 28 29 2e 0a 2a 2a 20 73 71 6c 69 tType()..** sqli
28c50 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 te3MemdebugHasTy
28c60 70 65 28 29 20 69 73 20 69 6e 74 65 6e 64 65 64 pe() is intended
28c70 20 66 6f 72 20 75 73 65 20 69 6e 73 69 64 65 20 for use inside
28c80 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
28c90 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 nts..**.** sqlit
28ca0 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 e3MemdebugNoType
28cb0 28 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 () returns true
28cc0 69 66 20 6e 6f 6e 65 20 6f 66 20 74 68 65 20 62 if none of the b
28cd0 69 74 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e its in its secon
28ce0 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 d.** argument ma
28cf0 74 63 68 20 74 68 65 20 74 79 70 65 20 73 65 74 tch the type set
28d00 20 62 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 by the previous
28d10 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
28d20 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a 0a 2a 2a SetType()..**.**
28d30 20 50 65 72 68 61 70 73 20 74 68 65 20 6d 6f 73 Perhaps the mos
28d40 74 20 69 6d 70 6f 72 74 61 6e 74 20 70 6f 69 6e t important poin
28d50 74 20 69 73 20 74 68 65 20 64 69 66 66 65 72 65 t is the differe
28d60 6e 63 65 20 62 65 74 77 65 65 6e 20 4d 45 4d 54 nce between MEMT
28d70 59 50 45 5f 48 45 41 50 0a 2a 2a 20 61 6e 64 20 YPE_HEAP.** and
28d80 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 MEMTYPE_LOOKASID
28d90 45 2e 20 20 49 66 20 61 6e 20 61 6c 6c 6f 63 61 E. If an alloca
28da0 74 69 6f 6e 20 69 73 20 4d 45 4d 54 59 50 45 5f tion is MEMTYPE_
28db0 4c 4f 4f 4b 41 53 49 44 45 2c 20 74 68 61 74 20 LOOKASIDE, that
28dc0 6d 65 61 6e 73 0a 2a 2a 20 69 74 20 6d 69 67 68 means.** it migh
28dd0 74 20 68 61 76 65 20 62 65 65 6e 20 61 6c 6c 6f t have been allo
28de0 63 61 74 65 64 20 62 79 20 6c 6f 6f 6b 61 73 69 cated by lookasi
28df0 64 65 2c 20 65 78 63 65 70 74 20 74 68 65 20 61 de, except the a
28e00 6c 6c 6f 63 61 74 69 6f 6e 20 77 61 73 0a 2a 2a llocation was.**
28e10 20 74 6f 6f 20 6c 61 72 67 65 20 6f 72 20 6c 6f too large or lo
28e20 6f 6b 61 73 69 64 65 20 77 61 73 20 61 6c 72 65 okaside was alre
28e30 61 64 79 20 66 75 6c 6c 2e 20 20 49 74 20 69 73 ady full. It is
28e40 20 69 6d 70 6f 72 74 61 6e 74 20 74 6f 20 76 65 important to ve
28e50 72 69 66 79 0a 2a 2a 20 74 68 61 74 20 61 6c 6c rify.** that all
28e60 6f 63 61 74 69 6f 6e 73 20 74 68 61 74 20 6d 69 ocations that mi
28e70 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 73 61 ght have been sa
28e80 74 69 73 66 69 65 64 20 62 79 20 6c 6f 6f 6b 61 tisfied by looka
28e90 73 69 64 65 20 61 72 65 20 6e 6f 74 0a 2a 2a 20 side are not.**
28ea0 70 61 73 73 65 64 20 62 61 63 6b 20 74 6f 20 6e passed back to n
28eb0 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 66 72 65 on-lookaside fre
28ec0 65 28 29 20 72 6f 75 74 69 6e 65 73 2e 20 20 41 e() routines. A
28ed0 73 73 65 72 74 73 20 73 75 63 68 20 61 73 20 74 sserts such as t
28ee0 68 65 0a 2a 2a 20 65 78 61 6d 70 6c 65 20 61 62 he.** example ab
28ef0 6f 76 65 20 61 72 65 20 70 6c 61 63 65 64 20 6f ove are placed o
28f00 6e 20 74 68 65 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 n the non-lookas
28f10 69 64 65 20 66 72 65 65 28 29 20 72 6f 75 74 69 ide free() routi
28f20 6e 65 73 20 74 6f 20 76 65 72 69 66 79 0a 2a 2a nes to verify.**
28f30 20 74 68 69 73 20 63 6f 6e 73 74 72 61 69 6e 74 this constraint
28f40 2e 20 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 . .**.** All of
28f50 74 68 69 73 20 69 73 20 6e 6f 2d 6f 70 20 66 6f this is no-op fo
28f60 72 20 61 20 70 72 6f 64 75 63 74 69 6f 6e 20 62 r a production b
28f70 75 69 6c 64 2e 20 20 49 74 20 6f 6e 6c 79 20 63 uild. It only c
28f80 6f 6d 65 73 20 69 6e 74 6f 0a 2a 2a 20 70 6c 61 omes into.** pla
28f90 79 20 77 68 65 6e 20 74 68 65 20 53 51 4c 49 54 y when the SQLIT
28fa0 45 5f 4d 45 4d 44 45 42 55 47 20 63 6f 6d 70 69 E_MEMDEBUG compi
28fb0 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e 20 69 le-time option i
28fc0 73 20 75 73 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 s used..*/.#ifde
28fd0 66 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 f SQLITE_MEMDEBU
28fe0 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 G. void sqlite3
28ff0 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
29000 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 void*,u8);. int
29010 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
29020 48 61 73 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 HasType(void*,u8
29030 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
29040 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 28 76 MemdebugNoType(v
29050 6f 69 64 2a 2c 75 38 29 3b 0a 23 65 6c 73 65 0a oid*,u8);.#else.
29060 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
29070 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
29080 58 2c 59 29 20 20 2f 2a 20 6e 6f 2d 6f 70 20 2a X,Y) /* no-op *
29090 2f 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 /.# define sqlit
290a0 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 e3MemdebugHasTyp
290b0 65 28 58 2c 59 29 20 20 31 0a 23 20 64 65 66 69 e(X,Y) 1.# defi
290c0 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ne sqlite3Memdeb
290d0 75 67 4e 6f 54 79 70 65 28 58 2c 59 29 20 20 20 ugNoType(X,Y)
290e0 31 0a 23 65 6e 64 69 66 0a 23 64 65 66 69 6e 65 1.#endif.#define
290f0 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 20 20 20 MEMTYPE_HEAP
29100 20 20 20 20 30 78 30 31 20 20 2f 2a 20 47 65 6e 0x01 /* Gen
29110 65 72 61 6c 20 68 65 61 70 20 61 6c 6c 6f 63 61 eral heap alloca
29120 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 tions */.#define
29130 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 MEMTYPE_LOOKASI
29140 44 45 20 20 30 78 30 32 20 20 2f 2a 20 48 65 61 DE 0x02 /* Hea
29150 70 20 74 68 61 74 20 6d 69 67 68 74 20 68 61 76 p that might hav
29160 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 69 64 65 e been lookaside
29170 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 */.#define MEMT
29180 59 50 45 5f 53 43 52 41 54 43 48 20 20 20 20 30 YPE_SCRATCH 0
29190 78 30 34 20 20 2f 2a 20 53 63 72 61 74 63 68 20 x04 /* Scratch
291a0 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 allocations */.#
291b0 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 5f 50 define MEMTYPE_P
291c0 43 41 43 48 45 20 20 20 20 20 30 78 30 38 20 20 CACHE 0x08
291d0 2f 2a 20 50 61 67 65 20 63 61 63 68 65 20 61 6c /* Page cache al
291e0 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a locations */../*
291f0 0a 2a 2a 20 54 68 72 65 61 64 69 6e 67 20 69 6e .** Threading in
29200 74 65 72 66 61 63 65 0a 2a 2f 0a 23 69 66 20 53 terface.*/.#if S
29210 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
29220 5f 54 48 52 45 41 44 53 3e 30 0a 69 6e 74 20 73 _THREADS>0.int s
29230 71 6c 69 74 65 33 54 68 72 65 61 64 43 72 65 61 qlite3ThreadCrea
29240 74 65 28 53 51 4c 69 74 65 54 68 72 65 61 64 2a te(SQLiteThread*
29250 2a 2c 76 6f 69 64 2a 28 2a 29 28 76 6f 69 64 2a *,void*(*)(void*
29260 29 2c 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 ),void*);.int sq
29270 6c 69 74 65 33 54 68 72 65 61 64 4a 6f 69 6e 28 lite3ThreadJoin(
29280 53 51 4c 69 74 65 54 68 72 65 61 64 2a 2c 20 76 SQLiteThread*, v
29290 6f 69 64 2a 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a oid**);.#endif..
292a0 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
292b0 54 45 5f 45 4e 41 42 4c 45 5f 44 42 53 54 41 54 TE_ENABLE_DBSTAT
292c0 5f 56 54 41 42 29 20 7c 7c 20 64 65 66 69 6e 65 _VTAB) || define
292d0 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a 69 d(SQLITE_TEST).i
292e0 6e 74 20 73 71 6c 69 74 65 33 44 62 73 74 61 74 nt sqlite3Dbstat
292f0 52 65 67 69 73 74 65 72 28 73 71 6c 69 74 65 33 Register(sqlite3
29300 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 65 6e 64 *);.#endif..#end
29310 69 66 20 2f 2a 20 5f 53 51 4c 49 54 45 49 4e 54 if /* _SQLITEINT
29320 5f 48 5f 20 2a 2f 0a _H_ */.